Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initLocalEnvironment #47

Merged
merged 11 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ import {
transferStatusInterval,
mapNetworkArgs,
} from "./utils";
import { AdapterABI } from "./adapterABI";
import {
AdapterABI,
AdapterBytecode,
CreateXABI,
CreateXBytecode,
} from "./adapterABI";
import { DeployOptions, DeploymentInfo, NetworkArguments } from "./types";

export class MultichainHardhatRuntimeEnvironmentField {
private isInitiated: boolean = false;
private domains: Domain[] = [];
private readonly web3: Web3 | null;
private readonly web3: Web3;

public constructor(private readonly hre: HardhatRuntimeEnvironment) {
const provider = this.hre.network.provider;
Expand All @@ -31,6 +36,7 @@ export class MultichainHardhatRuntimeEnvironmentField {
"ADAPTER_ADDRESS",
"0x85d62ad850b322152bf4ad9147bfbf097da42217"
);
public LOCAL_ADAPTER_ADDRESS = "";

//current Sygma hardcoded gasLimit
private gasLimit = 1000000;
Expand All @@ -50,6 +56,42 @@ export class MultichainHardhatRuntimeEnvironmentField {
this.isInitiated;
}

public async initLocalEnvironment(): Promise<void> {
const [deployer] = await this.web3.eth.getAccounts();
BeroBurny marked this conversation as resolved.
Show resolved Hide resolved

const gasMultiplier = this.hre.network.name.includes("arbi") ? 10 : 1;
mpetrunic marked this conversation as resolved.
Show resolved Hide resolved
const txOptionsAdapter = { gasLimit: 1900000 * gasMultiplier };
const txOptionsCreateX = { gasLimit: 2700000 * gasMultiplier };

const createX = new this.web3.eth.Contract(CreateXABI);
const response = await createX
.deploy({
data: CreateXBytecode,
})
.send({ from: deployer, ...txOptionsCreateX });
console.log(`CreateX locally deployed: ${response.options.address!}`);

const deployerSalt = this.web3.utils.encodePacked(
["bytes", "bytes", "bytes"],
[deployer, "0x00", "0x0000000000000000000000"]
);

const receipt = await createX.methods
.deployCreate3(deployerSalt, AdapterBytecode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you need to submit createX address to adapter constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I follow logic from /contacts/hardhat.config.js for deployment
there param on createX.deployCreate3 method is bytecode from CrosschainDeployAdapter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested this. I'm pretty sure contract deploy won't work as adapter will have wrong createx address

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to append custom constructor args to the bytecode

.send({ from: deployer, ...txOptionsAdapter });

const adapterAddress = receipt.events!.ContractCreation.returnValues
.newContract as string;

this.LOCAL_ADAPTER_ADDRESS = adapterAddress;

console.log(
`Adapter locally deployed: ${adapterAddress}` +
"\n" +
"Local environment initiated"
);
}

/**
* Deploys a contract to multiple blockchain networks.
*
Expand Down Expand Up @@ -80,7 +122,7 @@ export class MultichainHardhatRuntimeEnvironmentField {
): Promise<{
deploymentInfo: DeploymentInfo[];
receipt: Transaction;
} | void> {
}> {
const artifact = this.hre.artifacts.readArtifactSync(contractName);

return this.deployMultichainBytecode(
Expand Down Expand Up @@ -126,9 +168,8 @@ export class MultichainHardhatRuntimeEnvironmentField {
): Promise<{
deploymentInfo: DeploymentInfo[];
receipt: Transaction;
} | void> {
}> {
if (!this.isInitiated) await this.initConfig();
if (!this.web3) return;

//optional params
const salt = options?.salt ?? utils.randomBytes(32);
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin/src/adapterABI.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import CrosschainDeployAdapter from "@chainsafe/hardhat-plugin-multichain-deploy-contracts/artifacts/contracts/CrosschainDeployAdapter.sol/CrosschainDeployAdapter";
import CreateX from "@chainsafe/hardhat-plugin-multichain-deploy-contracts/artifacts/contracts/deps/CreateX.sol/CreateX";

export const AdapterABI = CrosschainDeployAdapter.abi;
export const AdapterBytecode = CrosschainDeployAdapter.bytecode;

export const CreateXABI = CreateX.abi;
export const CreateXBytecode = CreateX.bytecode;
Loading