Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
fix: make ContractFactory generic
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion authored and danijelTxFusion committed Nov 1, 2023
1 parent d618316 commit a26e33a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
22 changes: 13 additions & 9 deletions src/contract.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
BytesLike,
Contract,
InterfaceAbi,
Interface,
ethers,
ContractRunner,
ContractTransaction,
BaseContract,
ContractTransactionResponse,
ContractDeployTransaction,
ContractMethodArgs,
} from "ethers";
import {
hashBytecode,
Expand All @@ -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<any> = Array<any>,
I = BaseContract,
> extends ethers.ContractFactory<A, I> {
readonly deploymentType: DeploymentType;

constructor(
Expand Down Expand Up @@ -73,7 +75,9 @@ export class ContractFactory extends ethers.ContractFactory {
}
}

override async getDeployTransaction(...args: any[]): Promise<ContractTransaction> {
override async getDeployTransaction(
...args: ContractMethodArgs<A>
): Promise<ContractDeployTransaction> {
let constructorArgs: any[];
let overrides: ethers.Overrides = {
customData: { factoryDeps: [], salt: ethers.ZeroHash },
Expand Down Expand Up @@ -129,7 +133,7 @@ export class ContractFactory extends ethers.ContractFactory {
* because **deploy** already waits for deployment to finish.
*
* @async
* @param {...Array<any>} 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.
*
*
Expand Down Expand Up @@ -160,10 +164,10 @@ export class ContractFactory extends ethers.ContractFactory {
* });
*/
override async deploy(
...args: Array<any>
...args: ContractMethodArgs<A>
): Promise<
BaseContract & { deploymentTransaction(): ContractTransactionResponse } & Omit<
BaseContract,
I,
keyof BaseContract
>
> {
Expand All @@ -183,7 +187,7 @@ export class ContractFactory extends ethers.ContractFactory {
contract.interface.fragments,
contract.runner,
) as BaseContract & { deploymentTransaction(): ContractTransactionResponse } & Omit<
BaseContract,
I,
keyof BaseContract
>;

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 5 additions & 3 deletions tests/integration/paymaster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a26e33a

Please sign in to comment.