Skip to content

Commit

Permalink
UX improvements (#51)
Browse files Browse the repository at this point in the history
* Updated version

* Deleted spaces form toJSON converter

* Renamed misc to name

* Fix. Used setAsDeployed

* Fix setAsDeployed

* Renamed misc to name

* Deleted redundant 0 spaces
  • Loading branch information
KyrylR authored Oct 30, 2023
1 parent 3731d67 commit e86b596
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/deployer/adapters/AbstractEthersAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -31,7 +31,7 @@ export abstract class AbstractEthersAdapter extends Adapter {
return bytecodeToString(instance.bytecode);
}

public async fromInstance<A, I>(instance: Factory<A, I>, parameters: OverridesAndMisc): Promise<MinimalContract> {
public async fromInstance<A, I>(instance: Factory<A, I>, parameters: OverridesAndName): Promise<MinimalContract> {
return new MinimalContract(
this._config,
this.getRawBytecode(instance),
Expand Down
6 changes: 3 additions & 3 deletions src/deployer/adapters/Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<A, I>(instance: Instance<A, I>, parameters: OverridesAndMisc): Promise<MinimalContract>;
public abstract fromInstance<A, I>(instance: Instance<A, I>, parameters: OverridesAndName): Promise<MinimalContract>;

public abstract toInstance<A, I>(instance: Instance<A, I>, address: string, parameters: OverridesAndLibs): Promise<I>;

Expand All @@ -22,5 +22,5 @@ export abstract class Adapter {

public abstract getRawBytecode<A, I>(instance: Instance<A, I>): string;

public abstract getContractName<A, I>(instance: Instance<A, I>, parameters: OverridesAndMisc): string;
public abstract getContractName<A, I>(instance: Instance<A, I>, parameters: OverridesAndName): string;
}
8 changes: 4 additions & 4 deletions src/deployer/adapters/EthersContractAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -19,9 +19,9 @@ export class EthersContractAdapter extends AbstractEthersAdapter {
return instance.abi;
}

public getContractName<A, I>(instance: EthersContract<A, I>, parameters: OverridesAndMisc): string {
if (parameters.misc) {
return parameters.misc;
public getContractName<A, I>(instance: EthersContract<A, I>, parameters: OverridesAndName): string {
if (parameters.name) {
return parameters.name;
}

try {
Expand Down
17 changes: 10 additions & 7 deletions src/deployer/adapters/TruffleAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -32,7 +32,7 @@ export class TruffleAdapter extends Adapter {

public async fromInstance<A, I>(
instance: EthersContract<A, I>,
parameters: OverridesAndMisc,
parameters: OverridesAndName,
): Promise<MinimalContract> {
return new MinimalContract(
this._config,
Expand All @@ -43,12 +43,15 @@ export class TruffleAdapter extends Adapter {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async toInstance<I>(instance: TruffleFactory<I>, address: string, _: OverridesAndMisc): Promise<I> {
public async toInstance<I>(instance: TruffleFactory<I>, address: string, _: OverridesAndName): Promise<I> {
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 {
Expand All @@ -63,9 +66,9 @@ export class TruffleAdapter extends Adapter {
return bytecodeToString(instance.bytecode);
}

public getContractName<A, I>(instance: Instance<A, I>, parameters: OverridesAndMisc): string {
if (parameters.misc) {
return parameters.misc;
public getContractName<A, I>(instance: Instance<A, I>, parameters: OverridesAndName): string {
if (parameters.name) {
return parameters.name;
}

try {
Expand Down
4 changes: 2 additions & 2 deletions src/types/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export type Bytecode = BytesLike;

export type Args = Parameters<ContractFactory["getDeployTransaction"]>;

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

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function getChainId(): Promise<bigint> {
}

export function toJSON(data: any): string {
return JSON.stringify(data, JSONConvertor, 2);
return JSON.stringify(data, JSONConvertor);
}

export function JSONConvertor(_key: any, value: any) {
Expand Down

0 comments on commit e86b596

Please sign in to comment.