From a26e33a4df2319196a51c73e94e441451c9f02b8 Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Wed, 1 Nov 2023 23:28:34 +0100 Subject: [PATCH] fix: make `ContractFactory` generic --- src/contract.ts | 22 +++++++++++++--------- src/index.ts | 2 +- tests/integration/paymaster.test.ts | 8 +++++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/contract.ts b/src/contract.ts index 1e6015e..7c5c9d0 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -1,13 +1,13 @@ import { BytesLike, - Contract, InterfaceAbi, Interface, ethers, ContractRunner, - ContractTransaction, BaseContract, ContractTransactionResponse, + ContractDeployTransaction, + ContractMethodArgs, } from "ethers"; import { hashBytecode, @@ -18,9 +18,11 @@ import { DEFAULT_GAS_PER_PUBDATA_LIMIT, } from "./utils"; import { AccountAbstractionVersion, DeploymentType } from "./types"; -export { Contract } from "ethers"; -export class ContractFactory extends ethers.ContractFactory { +export class ContractFactory< + A extends Array = Array, + I = BaseContract, +> extends ethers.ContractFactory { readonly deploymentType: DeploymentType; constructor( @@ -73,7 +75,9 @@ export class ContractFactory extends ethers.ContractFactory { } } - override async getDeployTransaction(...args: any[]): Promise { + override async getDeployTransaction( + ...args: ContractMethodArgs + ): Promise { let constructorArgs: any[]; let overrides: ethers.Overrides = { customData: { factoryDeps: [], salt: ethers.ZeroHash }, @@ -129,7 +133,7 @@ export class ContractFactory extends ethers.ContractFactory { * because **deploy** already waits for deployment to finish. * * @async - * @param {...Array} args - Constructor arguments for the contract followed by optional + * @param {...ContractMethodArgs} args - Constructor arguments for the contract followed by optional * {@link ethers.Overrides|overrides}. When deploying with CREATE2 opcode slat must be present in overrides. * * @@ -160,10 +164,10 @@ export class ContractFactory extends ethers.ContractFactory { * }); */ override async deploy( - ...args: Array + ...args: ContractMethodArgs ): Promise< BaseContract & { deploymentTransaction(): ContractTransactionResponse } & Omit< - BaseContract, + I, keyof BaseContract > > { @@ -183,7 +187,7 @@ export class ContractFactory extends ethers.ContractFactory { contract.interface.fragments, contract.runner, ) as BaseContract & { deploymentTransaction(): ContractTransactionResponse } & Omit< - BaseContract, + I, keyof BaseContract >; diff --git a/src/index.ts b/src/index.ts index 6b9974f..60edaac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,4 +3,4 @@ export * as types from "./types"; export { EIP712Signer, Signer, L1Signer } from "./signer"; export { Wallet } from "./wallet"; export { BrowserProvider, Provider } from "./provider"; -export { ContractFactory, Contract } from "./contract"; +export { ContractFactory } from "./contract"; diff --git a/tests/integration/paymaster.test.ts b/tests/integration/paymaster.test.ts index 0a0e58f..e1341e8 100644 --- a/tests/integration/paymaster.test.ts +++ b/tests/integration/paymaster.test.ts @@ -23,12 +23,14 @@ describe("Paymaster", () => { const abi = require(tokenPath).abi; const bytecode: string = require(tokenPath).bytecode; const factory = new ContractFactory(abi, bytecode, wallet); - const tokenContract = await factory.deploy("Ducat", "Ducat", 18); + const tokenContract = (await factory.deploy("Ducat", "Ducat", 18)) as Contract; const tokenAddress = await tokenContract.getAddress(); - const token = new Contract(tokenAddress, abi, wallet); // mint tokens to wallet, so it could pay fee with tokens - await token.mint(Typed.address(await wallet.getAddress()), Typed.uint256(INIT_MINT_AMOUNT)); + await tokenContract.mint( + Typed.address(await wallet.getAddress()), + Typed.uint256(INIT_MINT_AMOUNT), + ); const paymasterAbi = require(paymasterPath).abi; const paymasterBytecode = require(paymasterPath).bytecode;