hardhat-ignition icon indicating copy to clipboard operation
hardhat-ignition copied to clipboard

Add function to encode function call args

Open zoeyTM opened this issue 9 months ago • 0 comments

m.encodeFunctionCall<
  ContractNameT extends string,
  FunctionNameT extends string
>(
  contract: CallableContractFuture<ContractNameT>,
  functionName: FunctionNameT,
  args: ArgumentType[]
): EncodeFunctionCallFuture

interface EncodeFunctionCallFuture<
  ContractNameT extends string,
  FunctionNameT extends string
> {
  type: FutureType.ENCODE_FUNCTION_CALL;
  id: string;
  module: IgnitionModule;
  dependencies: Set<Future>;
  contract: ContractFuture<ContractNameT>;
  functionName: FunctionNameT;
  args: ArgumentType[];
}

args should accept the same types as m.call

EncodeFunctionCallFuture should be able to be passed as an arg to:

  • contract constructors

  • m.call args

  • m.staticCall args

  • m.send data

Validations and reconciliations should be same as for m.call , minus things they don’t have in common like value and from

Usage:

example using proxy initialization function

const proxyAdminOwner = m.getAccount(0);

const contract = m.contract("Contract");

const data = m.encodeFunctionCall(contract, "initialize", [proxyAdminOwner])

const proxy = m.contract("TransparentUpgradeableProxy", [..., data]);

// etc.

zoeyTM avatar May 15 '24 00:05 zoeyTM