Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, ContractTransactionReceipt, ContractTransactionResponse, isBytesLike, JsonRpcProvider, Signer, TransactionReceipt, Wallet } from 'ethers';
import { DeployOptions, DeployResult, Deployment, DeploymentsExtension, Receipt } from 'hardhat-deploy/types';

import { constants } from './prelude';
Expand Down Expand Up @@ -252,16 +252,34 @@ export async function timeIncreaseTo(seconds: number | string): Promise<void> {
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<BigNumberish> = []) : Promise<BaseContract> {
const ContractFactory = await ethers.getContractFactory(name);
const instance = await ContractFactory.deploy(...parameters);
export async function deployContract<abi extends Abi = Abi>(
name: string,
Comment on lines +275 to +276
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic type parameter name abi is lowercase, which makes it easy to confuse with a runtime value and is inconsistent with other generics in this file (e.g., T). Consider renaming it to something like TAbi/TContractAbi for clarity.

Copilot uses AI. Check for mistakes.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
parameters: DeployContractParameters = [] as any
): Promise<DeployContractReturn> {
const ContractFactoryInstance = await ethers.getContractFactory<abi>(name);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const instance = await ContractFactoryInstance.deploy(...(parameters as any));
await instance.waitForDeployment();
return instance;
}
Expand Down
Loading