Skip to content

Commit

Permalink
Cleaned up. Added more utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Oct 21, 2023
1 parent 3bdc55d commit 8fda9a6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/types/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const predefinedChains: Record<number, ChainRecord> = {
shortName: "eth",
chainId: 1337,
networkId: 1337,
slip44: 60,
ens: {
registry: "0x0000000000000000000000000000000000000000",
},
Expand Down
47 changes: 45 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
import { join } from "path";
import { realpathSync, existsSync } from "fs";
import { AddressLike, hexlify, id, toBigInt } from "ethers";
import { AddressLike, FunctionFragment, hexlify, id, Overrides, toBigInt } from "ethers";

import { isBytes } from "@ethersproject/bytes";
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
Expand All @@ -26,6 +25,22 @@ export async function getSignerHelper(
return hre.ethers.getSigner(address as string);
}

export async function fillParameters(hre: HardhatRuntimeEnvironment, parameters: Overrides): Promise<Overrides> {
if (parameters.from === undefined) {
parameters.from = await (await hre.ethers.provider.getSigner()).getAddress();
}

if (parameters.chainId === undefined) {
parameters.chainId = await getChainId(hre);
}

if (parameters.value === undefined) {
parameters.value = 0;
}

return parameters;
}

export function underline(str: string): string {
return `\u001b[4m${str}\u001b[0m`;
}
Expand Down Expand Up @@ -63,6 +78,7 @@ export function createKeyDeploymentFieldsHash(keyTxFields: KeyDeploymentFields):
data: keyTxFields.data,
from: keyTxFields.from,
chainId: keyTxFields.chainId,
value: keyTxFields.value,
};

return id(toJSON(obj));
Expand All @@ -74,6 +90,7 @@ export function createKeyTxFieldsHash(keyTxFields: KeyTransactionFields): string
from: keyTxFields.from,
chainId: keyTxFields.chainId,
to: keyTxFields.to,
value: keyTxFields.value,
};

return id(toJSON(obj));
Expand Down Expand Up @@ -102,6 +119,30 @@ export function bytecodeToString(bytecode: Bytecode): string {
return bytecodeHex;
}

export function getMethodString(
contractName: string,
methodName: string,
methodFragment: FunctionFragment = {} as FunctionFragment,
args: any[] = [],
): string {
if (methodFragment.inputs === undefined) {
return `${contractName}.${methodName}`;
}

let argsString = "";
for (let i = 0; i < args.length; i++) {
argsString += `${methodFragment.inputs[i].name}:${args[i]}${i === args.length - 1 ? "" : ", "}`;
}

const methodSting = `${contractName}.${methodName}(${argsString})`;

if (methodSting.length > 60) {
return `${contractName}.${methodName}(${args.length} arguments)`;
}

return `${contractName}.${methodName}(${argsString})`;
}

export async function waitForBlock(hre: HardhatRuntimeEnvironment, desiredBlock: number) {
return new Promise<void>((resolve) => {
hre.ethers.provider.on("block", (blockNumber) => {
Expand Down Expand Up @@ -132,6 +173,7 @@ export function catchError(target: any, propertyName?: string, descriptor?: Prop
}
}

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

Expand All @@ -149,6 +191,7 @@ export function suppressLogs(target: any, propertyKey: string, descriptor: Prope

return descriptor;
}
/* eslint-enable no-console */

function _generateDescriptor(propertyName: string, descriptor: PropertyDescriptor): PropertyDescriptor {
const method = descriptor.value;
Expand Down
7 changes: 4 additions & 3 deletions src/verifier/Verifier.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { Etherscan } from "@nomicfoundation/hardhat-verify/etherscan";
import { EtherscanConfig } from "@nomicfoundation/hardhat-verify/types";

import { catchError, suppressLogs } from "../utils";

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

export class Verifier {
private _etherscanConfig: any;
private _config: MigrateConfig;
private readonly _config: MigrateConfig;
private readonly _etherscanConfig: EtherscanConfig;

constructor(private _hre: HardhatRuntimeEnvironment) {
this._etherscanConfig = (_hre.config as any).etherscan;
this._config = _hre.config.migrate;
this._etherscanConfig = (_hre.config as any).etherscan;
}

public async processVerification(verifierArgs: VerifierArgs): Promise<void> {
Expand Down

0 comments on commit 8fda9a6

Please sign in to comment.