Skip to content
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

Tried to fix ethers issue #50

Merged
merged 19 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
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
18,298 changes: 12,121 additions & 6,177 deletions package-lock.json

Large diffs are not rendered by default.

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.6",
"version": "2.0.0-alpha.7",
"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/Linker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Interface, isAddress, resolveAddress } from "ethers";
import { isAddress, resolveAddress } from "ethers";

import { Artifact, Libraries } from "hardhat/types";

Expand Down Expand Up @@ -168,7 +168,7 @@ export class Linker {

// https://github.com/ethers-io/ethers.js/issues/2431
// https://github.com/ethers-io/ethers.js/issues/1126
const core = new MinimalContract(this._config, artifact.bytecode, Interface.from(artifact.abi), libraryName);
const core = new MinimalContract(this._config, artifact.bytecode, artifact.abi, libraryName);

Reporter.notifyDeploymentOfMissingLibrary(libraryName);

Expand Down
10 changes: 7 additions & 3 deletions src/deployer/MinimalContract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ethers, Interface, Overrides, Signer } from "ethers";
import { ethers, InterfaceAbi, Overrides, Signer } from "ethers";

import { Linker } from "./Linker";

import { catchError, fillParameters, getChainId, getSignerHelper } from "../utils";
import { catchError, fillParameters, getChainId, getInterfaceOnlyWithConstructor, getSignerHelper } from "../utils";

import { MigrateError } from "../errors";

Expand All @@ -16,12 +16,16 @@ import { VerificationProcessor } from "../tools/storage/VerificationProcessor";

@catchError
export class MinimalContract {
private readonly _interface;

constructor(
private readonly _config: MigrateConfig,
private _bytecode: string,
private readonly _interface: Interface,
private readonly _abi: InterfaceAbi,
private readonly _contractName: string = "",
) {
this._interface = getInterfaceOnlyWithConstructor(this._abi);

if (_contractName === "") {
try {
this._contractName = ArtifactProcessor.tryGetContractName(_bytecode);
Expand Down
2 changes: 1 addition & 1 deletion src/deployer/adapters/AbstractEthersAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export abstract class AbstractEthersAdapter extends Adapter {
return new MinimalContract(
this._config,
this.getRawBytecode(instance),
this.getInterface(instance),
this.getRawAbi(instance),
this.getContractName(instance, parameters),
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/deployer/adapters/Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export abstract class Adapter {

public abstract getInterface<A, I>(instance: Instance<A, I>): Interface;

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

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

public abstract getContractName<A, I>(instance: Instance<A, I>, parameters: OverridesAndMisc): string;
Expand Down
4 changes: 4 additions & 0 deletions src/deployer/adapters/BytecodeAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class BytecodeAdapter extends AbstractEthersAdapter {
return Interface.from(instance.abi);
}

public getRawAbi(instance: BytecodeFactory): string {
return instance.abi as string;
}

public getContractName(instance: BytecodeFactory): string {
return instance.contractName;
}
Expand Down
4 changes: 4 additions & 0 deletions src/deployer/adapters/EthersContractAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class EthersContractAdapter extends AbstractEthersAdapter {
return Interface.from(instance.abi);
}

public getRawAbi<A, I>(instance: EthersContract<A, I>): string {
return instance.abi;
}

public getContractName<A, I>(instance: EthersContract<A, I>, parameters: OverridesAndMisc): string {
if (parameters.misc) {
return parameters.misc;
Expand Down
4 changes: 4 additions & 0 deletions src/deployer/adapters/EthersFactoryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class EthersFactoryAdapter extends AbstractEthersAdapter {
return instance.interface;
}

public getRawAbi(instance: ContractFactory): string {
return JSON.stringify(instance.interface.fragments);
}

public getContractName(instance: ContractFactory): string {
try {
return ArtifactProcessor.tryGetContractName(this.getRawBytecode(instance));
Expand Down
6 changes: 5 additions & 1 deletion src/deployer/adapters/TruffleAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TruffleAdapter extends Adapter {
return new MinimalContract(
this._config,
this.getRawBytecode(instance),
this.getInterface(instance),
this.getRawAbi(instance),
this.getContractName(instance, parameters),
);
}
Expand All @@ -55,6 +55,10 @@ export class TruffleAdapter extends Adapter {
return Interface.from(instance.abi);
}

public getRawAbi(instance: TruffleContract): string {
return instance.abi;
}

public getRawBytecode(instance: TruffleContract): string {
return bytecodeToString(instance.bytecode);
}
Expand Down
32 changes: 31 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { join } from "path";
import { realpathSync, existsSync } from "fs";
import { AddressLike, ethers, FunctionFragment, hexlify, id, Overrides, toBigInt } from "ethers";
import {
id,
hexlify,
toBigInt,
ethers,
Overrides,
Interface,
Fragment,
AddressLike,
InterfaceAbi,
JsonFragment,
FunctionFragment,
ConstructorFragment,
} from "ethers";

import { isBytes } from "@ethersproject/bytes";
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
Expand Down Expand Up @@ -169,6 +182,23 @@ export function catchError(target: any, propertyName?: string, descriptor?: Prop
}
}

export function getInterfaceOnlyWithConstructor(fragments: InterfaceAbi): Interface {
let abi: ReadonlyArray<Fragment | JsonFragment | string>;
if (typeof fragments === "string") {
abi = JSON.parse(fragments);
} else {
abi = fragments;
}

const fragment = abi.find((a: any) => a.type === "constructor");

if (fragment !== undefined) {
return Interface.from([fragment]);
}

return new Interface([ConstructorFragment.from("constructor()")]);
}

/* eslint-disable no-console */
export function suppressLogs(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
Expand Down