From 52e87fec520ab64a4d2a34473c7174b650c39d47 Mon Sep 17 00:00:00 2001 From: irubido Date: Wed, 24 Jan 2024 11:02:38 +0100 Subject: [PATCH] encodeInitData --- ...ultichainHardhatRuntimeEnvironmentField.ts | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts b/packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts index 74e71d8..0c03cc5 100644 --- a/packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts +++ b/packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts @@ -6,8 +6,11 @@ import Web3, { Bytes, utils, PayableCallOptions, + ContractMethodInputParameters, + AbiFunctionFragment, } from "web3"; import { vars } from "hardhat/config"; +import { HardhatPluginError } from "hardhat/internal/core/errors"; import { getConfigEnvironmentVariable, getNetworkChainId, @@ -47,19 +50,28 @@ export class MultichainHardhatRuntimeEnvironmentField { this.domains = config.getDomains(); - this.isValidated = true; + this.isValidated; } - public static encodeInitData( + public encodeInitData( artifact: Artifact, initMethodName: string, - initMethodArgs: string[] + initMethodArgs: ContractMethodInputParameters ): Bytes { - //TODO - // const contract = new Contract(artifact.abi); - // const encodedInitMethod = contract.methods[initMethodName](initMethodArgs).encodeABI(); - console.log(artifact, initMethodArgs, initMethodName); - return utils.hexToBytes("0x"); + const initMethodAbiFragment: AbiFunctionFragment | undefined = + artifact.abi.find( + (fragment: AbiFunctionFragment) => fragment.name === initMethodName + ) as AbiFunctionFragment | undefined; + if (!initMethodAbiFragment) + throw new HardhatPluginError( + "@chainsafe/hardhat-plugin-multichain-deploy", + `InitMethod ${initMethodName} not foud in ABI` + ); + + return this.web3!.eth.abi.encodeFunctionCall( + initMethodAbiFragment, + initMethodArgs + ); } /**