From 8fda9a629e73cba2c09531233de309c5fde301c5 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Sat, 21 Oct 2023 16:25:59 +0300 Subject: [PATCH] Cleaned up. Added more utils. --- src/types/verifier.ts | 1 - src/utils.ts | 47 ++++++++++++++++++++++++++++++++++++++-- src/verifier/Verifier.ts | 7 +++--- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/types/verifier.ts b/src/types/verifier.ts index 38620d3..eb237ad 100644 --- a/src/types/verifier.ts +++ b/src/types/verifier.ts @@ -47,7 +47,6 @@ export const predefinedChains: Record = { shortName: "eth", chainId: 1337, networkId: 1337, - slip44: 60, ens: { registry: "0x0000000000000000000000000000000000000000", }, diff --git a/src/utils.ts b/src/utils.ts index 3b41a33..f076aff 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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"; @@ -26,6 +25,22 @@ export async function getSignerHelper( return hre.ethers.getSigner(address as string); } +export async function fillParameters(hre: HardhatRuntimeEnvironment, parameters: Overrides): Promise { + 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`; } @@ -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)); @@ -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)); @@ -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((resolve) => { hre.ethers.provider.on("block", (blockNumber) => { @@ -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; @@ -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; diff --git a/src/verifier/Verifier.ts b/src/verifier/Verifier.ts index 6f6f97c..e7c1908 100644 --- a/src/verifier/Verifier.ts +++ b/src/verifier/Verifier.ts @@ -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"; @@ -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 {