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] 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; }