-
Notifications
You must be signed in to change notification settings - Fork 61
fix: update deployContract to use generics for constructor args with arrays #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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'; | ||||||
|
|
@@ -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<abi extends Abi = Abi> = readonly any[]; | ||||||
|
|
||||||
| /** | ||||||
| * Helper type for the return type of deployContract. | ||||||
| */ | ||||||
| type DeployContractReturn<abi extends Abi = Abi> = 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
|
||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||
| parameters: DeployContractParameters<abi> = [] as any | ||||||
|
||||||
| parameters: DeployContractParameters<abi> = [] as any | |
| parameters: DeployContractParameters<abi> = [] |
Uh oh!
There was an error while loading. Please reload this page.