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: encodeInitData #30

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Changes from 1 commit
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
28 changes: 20 additions & 8 deletions packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -47,19 +50,28 @@ export class MultichainHardhatRuntimeEnvironmentField {

this.domains = config.getDomains();

this.isValidated = true;
this.isValidated;
}

public static encodeInitData(
public encodeInitData<Abi extends ContractAbi = any>(
artifact: Artifact,
initMethodName: string,
initMethodArgs: string[]
initMethodArgs: ContractMethodInputParameters<Abi>
Copy link
Member

Choose a reason for hiding this comment

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

this is not the right type. Is it okay if I push to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you can, I only changed it to be a part of deploy funciton,
initData?: { initMethodName: string; initMethodArgs: ContractMethodInputParameters<Abi>; };

): 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
);
}

/**
Expand Down
Loading