From 68207ff8fd80b91dabeb48d8b6a51d55dd8c06db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 20 Jan 2026 23:55:43 +0100 Subject: [PATCH 1/3] fix: update deployContract to use generics for constructor args Fixes type mismatch when passing arrays (e.g., readonly number[]) to deployContract constructor parameters. Implemented Solution B using generics with Abi type parameter to align with ContractFactory.deploy types. The function now accepts arrays and complex types in constructor parameters, resolving the issue where Array didn't match ContractFactory.deploy(...args: ContractMethodArgs). Related Issues: #208 --- src/utils.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 0444116b..2f10aa6f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,7 +3,7 @@ import hre, { ethers } from 'hardhat'; import { time } from '@nomicfoundation/hardhat-network-helpers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import fetch from 'node-fetch'; -import { BaseContract, BigNumberish, BytesLike, Contract, ContractTransactionReceipt, ContractTransactionResponse, isBytesLike, JsonRpcProvider, Signer, TransactionReceipt, Wallet } from 'ethers'; +import { Abi, BaseContract, BigNumberish, BytesLike, Contract, ContractFactory, ContractTransactionReceipt, ContractTransactionResponse, isBytesLike, JsonRpcProvider, Signer, TransactionReceipt, Wallet } from 'ethers'; import { DeployOptions, DeployResult, Deployment, DeploymentsExtension, Receipt } from 'hardhat-deploy/types'; import { constants } from './prelude'; @@ -252,16 +252,34 @@ export async function timeIncreaseTo(seconds: number | string): Promise { await time.increaseTo(seconds); } +/** + * Helper type for constructor parameters that allows arrays and complex types. + * This type is compatible with ContractFactory.deploy's expected arguments. + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type DeployContractParameters = readonly any[]; + +/** + * Helper type for the return type of deployContract. + */ +type DeployContractReturn = BaseContract; + /** * @category utils * Deploys a contract given a name and optional constructor parameters. + * Supports arrays and other complex types in constructor parameters (e.g., readonly number[]). * @param name The contract name. * @param parameters Constructor parameters for the contract. * @returns The deployed contract instance. */ -export async function deployContract(name: string, parameters: Array = []) : Promise { - const ContractFactory = await ethers.getContractFactory(name); - const instance = await ContractFactory.deploy(...parameters); +export async function deployContract( + name: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + parameters: DeployContractParameters = [] as any +): Promise> { + const ContractFactoryInstance = await ethers.getContractFactory(name); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const instance = await ContractFactoryInstance.deploy(...(parameters as any)); await instance.waitForDeployment(); return instance; } From 53aa5c06d1a57952cdf71acb35a4af9f595c044d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20I=2E=20O=2E?= <30682875+jose-blockchain@users.noreply.github.com> Date: Thu, 5 Mar 2026 07:18:05 +0100 Subject: [PATCH 2/3] Update src/utils.ts removing `ContractFactory` import, unused Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 2f10aa6f..6e3c66ba 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,7 +3,7 @@ import hre, { ethers } from 'hardhat'; import { time } from '@nomicfoundation/hardhat-network-helpers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import fetch from 'node-fetch'; -import { Abi, BaseContract, BigNumberish, BytesLike, Contract, ContractFactory, ContractTransactionReceipt, ContractTransactionResponse, isBytesLike, JsonRpcProvider, Signer, TransactionReceipt, Wallet } from 'ethers'; +import { Abi, BaseContract, BigNumberish, BytesLike, Contract, ContractTransactionReceipt, ContractTransactionResponse, isBytesLike, JsonRpcProvider, Signer, TransactionReceipt, Wallet } from 'ethers'; import { DeployOptions, DeployResult, Deployment, DeploymentsExtension, Receipt } from 'hardhat-deploy/types'; import { constants } from './prelude'; From 9823d849a86b98bba51c50d9120fc965ac1df6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Thu, 5 Mar 2026 14:14:29 +0100 Subject: [PATCH 3/3] fix: remove unused abi generic from DeployContractParameters and DeployContractReturn --- src/utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 6e3c66ba..6de8f165 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -257,12 +257,12 @@ export async function timeIncreaseTo(seconds: number | string): Promise { * This type is compatible with ContractFactory.deploy's expected arguments. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -type DeployContractParameters = readonly any[]; +type DeployContractParameters = readonly any[]; /** * Helper type for the return type of deployContract. */ -type DeployContractReturn = BaseContract; +type DeployContractReturn = BaseContract; /** * @category utils @@ -275,8 +275,8 @@ type DeployContractReturn = BaseContract; export async function deployContract( name: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any - parameters: DeployContractParameters = [] as any -): Promise> { + parameters: DeployContractParameters = [] as any +): Promise { const ContractFactoryInstance = await ethers.getContractFactory(name); // eslint-disable-next-line @typescript-eslint/no-explicit-any const instance = await ContractFactoryInstance.deploy(...(parameters as any));