From f711ba90e0cf8f45a800193ca146fda93451e8c6 Mon Sep 17 00:00:00 2001 From: 0xmad <0xmad@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:36:04 -0500 Subject: [PATCH] chore(contracts): extend ids for contract storage and deployment --- .../tasks/helpers/ContractStorage.ts | 19 ++++++++++--------- .../contracts/tasks/helpers/Deployment.ts | 12 ++++++++---- packages/contracts/tasks/helpers/types.ts | 8 ++++---- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/contracts/tasks/helpers/ContractStorage.ts b/packages/contracts/tasks/helpers/ContractStorage.ts index 1ee9d9f73..da889cc3a 100644 --- a/packages/contracts/tasks/helpers/ContractStorage.ts +++ b/packages/contracts/tasks/helpers/ContractStorage.ts @@ -67,12 +67,13 @@ export class ContractStorage { * * @param {IRegisterContract} args - register arguments */ - async register({ id, key, contract, network, args, name }: IRegisterContract): Promise { + async register({ id, key, contract, network, args, name }: IRegisterContract): Promise { const contractAddress = await contract.getAddress(); const deploymentTx = contract.deploymentTransaction(); + const contractId = String(id); - console.log(`*** ${id} ***\n`); + console.log(`*** ${contractId} ***\n`); console.log(`Network: ${network}`); console.log(`contract address: ${contractAddress}`); @@ -87,7 +88,7 @@ export class ContractStorage { console.log(); const logEntry: IStorageInstanceEntry = { - id, + id: contractId, deploymentTxHash: deploymentTx?.hash, }; @@ -100,12 +101,12 @@ export class ContractStorage { this.db.set(`${network}.instance.${contractAddress}`, logEntry).write(); - const namedEntry = this.db.get(`${network}.named.${id}${key !== undefined ? `.${key}` : ""}`).value() as + const namedEntry = this.db.get(`${network}.named.${contractId}${key !== undefined ? `.${key}` : ""}`).value() as | IStorageNamedEntry | undefined; const count = namedEntry?.count ?? 0; this.db - .set(`${network}.named.${id}${key !== undefined ? `.${key}` : ""}`, { + .set(`${network}.named.${contractId}${key !== undefined ? `.${key}` : ""}`, { address: contractAddress, count: count + 1, }) @@ -155,7 +156,7 @@ export class ContractStorage { * @param key - contract key * @returns deployment arguments */ - getContractArgs(id: EContracts, network: string, key?: string): string[] | undefined { + getContractArgs(id: ID, network: string, key?: string): string[] | undefined { const address = this.getAddress(id, network, key); const collection = this.db.get(`${network}.instance.${address}`); @@ -175,7 +176,7 @@ export class ContractStorage { * @param network - selected network * @returns contract address */ - getAddress(id: EContracts, network: string, key?: string): string | undefined { + getAddress(id: ID, network: string, key?: string): string | undefined { const collection = this.db.get(`${network}.named.${id}${key !== undefined ? `.${key}` : ""}`); const namedEntry = collection.value() as IStorageNamedEntry | undefined; @@ -190,7 +191,7 @@ export class ContractStorage { * @throws {Error} if there is no address the error will be thrown * @returns contract address */ - mustGetAddress(id: EContracts, network: string, key?: string): string { + mustGetAddress(id: ID, network: string, key?: string): string { const address = this.getAddress(id, network, key); if (!address) { @@ -203,7 +204,7 @@ export class ContractStorage { /** * Get Contract Deployment Transaction Hash */ - getDeploymentTxHash(id: EContracts, network: string, address: string): string | undefined { + getDeploymentTxHash(id: ID, network: string, address: string): string | undefined { const collection = this.db.get(`${network}.instance.${address}`); const instanceEntry = collection.value() as IStorageInstanceEntry | undefined; diff --git a/packages/contracts/tasks/helpers/Deployment.ts b/packages/contracts/tasks/helpers/Deployment.ts index e161a04c3..f0619b31a 100644 --- a/packages/contracts/tasks/helpers/Deployment.ts +++ b/packages/contracts/tasks/helpers/Deployment.ts @@ -315,15 +315,15 @@ export class Deployment { * @param args - constructor arguments * @returns deployed contract */ - async deployContract( - { name, abi, bytecode, signer }: IDeployContractParams, + async deployContract( + { name, abi, bytecode, signer }: IDeployContractParams, ...args: unknown[] ): Promise { const deployer = signer || (await this.getDeployer()); const contractFactory = abi && bytecode ? new ContractFactory(abi, bytecode, deployer) - : await import("hardhat").then(({ ethers }) => ethers.getContractFactory(name, deployer)); + : await import("hardhat").then(({ ethers }) => ethers.getContractFactory(String(name), deployer)); const feeData = await deployer.provider?.getFeeData(); const contract = await contractFactory.deploy(...args, { @@ -380,7 +380,11 @@ export class Deployment { * @param field - config field key * @returns config field value or null */ - getDeployConfigField(id: EContracts, field: string, mustGet = false): T { + getDeployConfigField( + id: ID, + field: string, + mustGet = false, + ): T { this.checkHre(); const value = this.config.get(`${this.hre!.network.name}.${id}.${field}`).value() as T; diff --git a/packages/contracts/tasks/helpers/types.ts b/packages/contracts/tasks/helpers/types.ts index 98a60ed23..0c8c0f7a6 100644 --- a/packages/contracts/tasks/helpers/types.ts +++ b/packages/contracts/tasks/helpers/types.ts @@ -503,11 +503,11 @@ export interface IStorageInstanceEntry { /** * Interface that represents register contract arguments */ -export interface IRegisterContract { +export interface IRegisterContract { /** * Contract enum identifier */ - id: EContracts; + id: ID; /** * Contract instance @@ -749,11 +749,11 @@ export type TAbi = string | readonly (string | Fragment | JsonFragment)[]; /** * Interface that represents deploy params */ -export interface IDeployContractParams { +export interface IDeployContractParams { /** * Contract name */ - name: EContracts; + name: ID; /** * Contract abi