From e86b5962afc95b4ac67a8bcb6db869d00a21b91f Mon Sep 17 00:00:00 2001 From: Kyrylo Riabov Date: Mon, 30 Oct 2023 15:45:33 +0200 Subject: [PATCH] UX improvements (#51) * Updated version * Deleted spaces form toJSON converter * Renamed misc to name * Fix. Used setAsDeployed * Fix setAsDeployed * Renamed misc to name * Deleted redundant 0 spaces --- package.json | 2 +- src/deployer/adapters/AbstractEthersAdapter.ts | 4 ++-- src/deployer/adapters/Adapter.ts | 6 +++--- src/deployer/adapters/EthersContractAdapter.ts | 8 ++++---- src/deployer/adapters/TruffleAdapter.ts | 17 ++++++++++------- src/types/deployer.ts | 4 ++-- src/utils.ts | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 70c8bae..a5bfc49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/hardhat-migrate", - "version": "2.0.0-alpha.7", + "version": "2.0.0-alpha.8", "description": "Automatic deployment and verification of smart contracts", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/deployer/adapters/AbstractEthersAdapter.ts b/src/deployer/adapters/AbstractEthersAdapter.ts index 250135d..64abf44 100644 --- a/src/deployer/adapters/AbstractEthersAdapter.ts +++ b/src/deployer/adapters/AbstractEthersAdapter.ts @@ -15,7 +15,7 @@ import "../../type-extensions"; import { bytecodeToString, fillParameters, getMethodString, getSignerHelper } from "../../utils"; -import { OverridesAndLibs, OverridesAndMisc } from "../../types/deployer"; +import { OverridesAndLibs, OverridesAndName } from "../../types/deployer"; import { KeyTransactionFields } from "../../types/tools"; import { EthersContract, BytecodeFactory } from "../../types/adapter"; @@ -31,7 +31,7 @@ export abstract class AbstractEthersAdapter extends Adapter { return bytecodeToString(instance.bytecode); } - public async fromInstance(instance: Factory, parameters: OverridesAndMisc): Promise { + public async fromInstance(instance: Factory, parameters: OverridesAndName): Promise { return new MinimalContract( this._config, this.getRawBytecode(instance), diff --git a/src/deployer/adapters/Adapter.ts b/src/deployer/adapters/Adapter.ts index 1953610..5a0cc5b 100644 --- a/src/deployer/adapters/Adapter.ts +++ b/src/deployer/adapters/Adapter.ts @@ -6,13 +6,13 @@ import { catchError } from "../../utils"; import { Instance } from "../../types/adapter"; import { MigrateConfig } from "../../types/migrations"; -import { OverridesAndLibs, OverridesAndMisc } from "../../types/deployer"; +import { OverridesAndLibs, OverridesAndName } from "../../types/deployer"; @catchError export abstract class Adapter { public constructor(protected _config: MigrateConfig) {} - public abstract fromInstance(instance: Instance, parameters: OverridesAndMisc): Promise; + public abstract fromInstance(instance: Instance, parameters: OverridesAndName): Promise; public abstract toInstance(instance: Instance, address: string, parameters: OverridesAndLibs): Promise; @@ -22,5 +22,5 @@ export abstract class Adapter { public abstract getRawBytecode(instance: Instance): string; - public abstract getContractName(instance: Instance, parameters: OverridesAndMisc): string; + public abstract getContractName(instance: Instance, parameters: OverridesAndName): string; } diff --git a/src/deployer/adapters/EthersContractAdapter.ts b/src/deployer/adapters/EthersContractAdapter.ts index 59af692..1da738f 100644 --- a/src/deployer/adapters/EthersContractAdapter.ts +++ b/src/deployer/adapters/EthersContractAdapter.ts @@ -5,7 +5,7 @@ import { AbstractEthersAdapter } from "./AbstractEthersAdapter"; import { catchError, getSignerHelper } from "../../utils"; import { EthersContract } from "../../types/adapter"; -import { OverridesAndMisc } from "../../types/deployer"; +import { OverridesAndName } from "../../types/deployer"; import { ArtifactProcessor } from "../../tools/storage/ArtifactProcessor"; @@ -19,9 +19,9 @@ export class EthersContractAdapter extends AbstractEthersAdapter { return instance.abi; } - public getContractName(instance: EthersContract, parameters: OverridesAndMisc): string { - if (parameters.misc) { - return parameters.misc; + public getContractName(instance: EthersContract, parameters: OverridesAndName): string { + if (parameters.name) { + return parameters.name; } try { diff --git a/src/deployer/adapters/TruffleAdapter.ts b/src/deployer/adapters/TruffleAdapter.ts index 7c4246b..63a5d09 100644 --- a/src/deployer/adapters/TruffleAdapter.ts +++ b/src/deployer/adapters/TruffleAdapter.ts @@ -14,7 +14,7 @@ import { EthersContract, Instance, TruffleFactory } from "../../types/adapter"; import { BaseTruffleMethod, OverridesAndLibs, - OverridesAndMisc, + OverridesAndName, TruffleTransactionResponse, } from "../../types/deployer"; import { KeyTransactionFields } from "../../types/tools"; @@ -32,7 +32,7 @@ export class TruffleAdapter extends Adapter { public async fromInstance( instance: EthersContract, - parameters: OverridesAndMisc, + parameters: OverridesAndName, ): Promise { return new MinimalContract( this._config, @@ -43,12 +43,15 @@ export class TruffleAdapter extends Adapter { } // eslint-disable-next-line @typescript-eslint/no-unused-vars - public async toInstance(instance: TruffleFactory, address: string, _: OverridesAndMisc): Promise { + public async toInstance(instance: TruffleFactory, address: string, _: OverridesAndName): Promise { const contract = this._hre.artifacts.require(instance.contractName!); await this._overrideConnectMethod(contract); - return contract.at(address); + const contractInstance = await contract.at(address); + (instance as any).setAsDeployed(contractInstance); + + return contractInstance; } public getInterface(instance: TruffleContract): Interface { @@ -63,9 +66,9 @@ export class TruffleAdapter extends Adapter { return bytecodeToString(instance.bytecode); } - public getContractName(instance: Instance, parameters: OverridesAndMisc): string { - if (parameters.misc) { - return parameters.misc; + public getContractName(instance: Instance, parameters: OverridesAndName): string { + if (parameters.name) { + return parameters.name; } try { diff --git a/src/types/deployer.ts b/src/types/deployer.ts index 9976ff1..f14f1eb 100644 --- a/src/types/deployer.ts +++ b/src/types/deployer.ts @@ -6,9 +6,9 @@ export type Bytecode = BytesLike; export type Args = Parameters; -export type OverridesAndMisc = Overrides & { misc?: string }; +export type OverridesAndName = Overrides & { name?: string }; -export type OverridesAndLibs = OverridesAndMisc & { libraries?: Libraries }; +export type OverridesAndLibs = OverridesAndName & { libraries?: Libraries }; export type ContractDeployTransactionWithContractName = ContractDeployTransaction & { contractName: string }; diff --git a/src/utils.ts b/src/utils.ts index d070cb1..d129240 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -67,7 +67,7 @@ export async function getChainId(): Promise { } export function toJSON(data: any): string { - return JSON.stringify(data, JSONConvertor, 2); + return JSON.stringify(data, JSONConvertor); } export function JSONConvertor(_key: any, value: any) {