Skip to content

Commit

Permalink
Merge branch 'master' into beroburny/improve-js-docs
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/plugin/src/types.ts
  • Loading branch information
BeroBurny committed Jan 23, 2024
2 parents 26904db + 9c4b7b1 commit 1b08239
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Web3, {
utils,
PayableCallOptions,
} from "web3";
import { vars } from "hardhat/config";
import {
getConfigEnvironmentVariable,
getNetworkChainId,
Expand All @@ -26,7 +27,10 @@ export class MultichainHardhatRuntimeEnvironmentField {
this.web3 = new Web3(provider);
}

public ADAPTER_ADDRESS = "0x85d62ad850b322152bf4ad9147bfbf097da42217";
public ADAPTER_ADDRESS = vars.get(
"ADAPTER_ADDRESS",
"0x85d62ad850b322152bf4ad9147bfbf097da42217"
);

//current Sygma hardcoded gasLimit
private gasLimit = 1000000;
Expand Down Expand Up @@ -143,7 +147,6 @@ export class MultichainHardhatRuntimeEnvironmentField {
);

const { constructorArgs, initDatas, deployDomainIDs } = mapNetworkArgs(
contractBytecode,
contractAbi,
networkArgs,
this.domains
Expand Down
2 changes: 0 additions & 2 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
MultichainConfig,
} from "hardhat/types";
import { Environment } from "@buildwithsygma/sygma-sdk-core";

import { MultichainHardhatRuntimeEnvironmentField } from "./MultichainHardhatRuntimeEnvironmentField";

import "./type-extensions";

extendConfig(
Expand Down
55 changes: 32 additions & 23 deletions packages/plugin/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Domain, Environment } from "@buildwithsygma/sygma-sdk-core";
import {
Bytes,
Contract,
ContractAbi,
ContractConstructorArgs,
FMT_BYTES,
FMT_NUMBER,
HttpProvider,
Numbers,
Web3,
eth,
utils,
} from "web3";
import { HardhatPluginError } from "hardhat/plugins";
import { NetworkArguments } from "./types";

export function getConfigEnvironmentVariable(
hre: HardhatRuntimeEnvironment
Expand Down Expand Up @@ -50,24 +50,15 @@ export function sumedFees(fees: Numbers[]): string {
}

export function mapNetworkArgs<Abi extends ContractAbi = any>(
contractBytecode: string,
contractAbi: Abi,
networkArgs: Record<
string,
{
args: ContractConstructorArgs<Abi>;
initData?: Bytes;
}
>,
networkArgs: NetworkArguments<Abi>,
domains: Domain[]
): {
deployDomainIDs: bigint[];
constructorArgs: string[];
initDatas: Bytes[];
} {
const { bytesToHex, hexToBytes } = utils;
const contract = new Contract(contractAbi);

const { hexToBytes } = utils;
const deployDomainIDs: bigint[] = [];
const constructorArgs: string[] = [];
const initDatas: Bytes[] = [];
Expand All @@ -90,18 +81,36 @@ export function mapNetworkArgs<Abi extends ContractAbi = any>(
);
}

const encodedDeployMethod = contract
.deploy({
data: contractBytecode,
arguments: networkArgs[networkName].args,
})
.encodeABI();
const constructorAbi = contractAbi.filter(
(f) => f.type === "constructor"
)[0].inputs;
const networkConstructorArgs = networkArgs[networkName].args;

const argsInBytes = bytesToHex(
hexToBytes(encodedDeployMethod).slice(hexToBytes(contractBytecode).length)
);
if (constructorAbi) {
//throws if user did not provide constructor args for network
if (!networkConstructorArgs)
throw new HardhatPluginError(
"@chainsafe/hardhat-plugin-multichain-deploy",
`Contract ABI provided required constructor arguments for ${networkName}`
);

constructorArgs.push(argsInBytes);
const argsInBytes = eth.abi.encodeParameters(
constructorAbi,
networkConstructorArgs
);
//provided constructorAbi with args
constructorArgs.push(argsInBytes);
} else {
//throws if user provides args and none are in abi
if (networkConstructorArgs)
throw new HardhatPluginError(
"@chainsafe/hardhat-plugin-multichain-deploy",
`Contract ABI provided doesn't contain a constructor definition.
If provided contract should't have constructor, do not provide args parameter for ${networkName}.`
);
//no constructorAbi and no args
constructorArgs.push("0x");
}

if (networkArgs[networkName].initData) {
initDatas.push(networkArgs[networkName].initData as Bytes);
Expand Down

0 comments on commit 1b08239

Please sign in to comment.