@matterlabs/hardhat-zksync-verify
Version:
Hardhat plugin to verify smart contracts for the ZKsync network
124 lines • 6.25 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.printVerificationErrors = exports.extractQueryParams = exports.normalizeCompilerVersions = exports.getZkVmNormalizedVersion = exports.extractModule = exports.parseWrongConstructorArgumentsError = exports.retrieveContractBytecode = exports.nextAttemptDelay = exports.encodeArguments = exports.delay = exports.handleAxiosError = void 0;
const axios_1 = __importDefault(require("axios"));
const chalk_1 = __importDefault(require("chalk"));
const errors_1 = require("./errors");
const constants_1 = require("./constants");
const config_normalizer_1 = require("./config-normalizer");
function handleAxiosError(error) {
if (axios_1.default.isAxiosError(error)) {
throw new Error(`Axios error (code: ${error.code}) during the contract verification request\n Reason: ${error.response?.data}`);
}
else {
throw new errors_1.ZkSyncVerifyPluginError(`Failed to send contract verification request\n Reason: ${error}`);
}
}
exports.handleAxiosError = handleAxiosError;
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
exports.delay = delay;
async function encodeArguments(abi, constructorArgs) {
const { Interface } = await Promise.resolve().then(() => __importStar(require('@ethersproject/abi')));
const contractInterface = new Interface(abi);
let deployArgumentsEncoded;
try {
deployArgumentsEncoded = contractInterface.encodeDeploy(constructorArgs).replace('0x', '');
}
catch (error) {
const errorMessage = error.message.includes(constants_1.WRONG_CONSTRUCTOR_ARGUMENTS)
? parseWrongConstructorArgumentsError(error.message)
: error.message;
throw new errors_1.ZkSyncVerifyPluginError(errorMessage);
}
return deployArgumentsEncoded;
}
exports.encodeArguments = encodeArguments;
function nextAttemptDelay(currentAttempt, baseDelay, baseNumberOfAttempts) {
if (currentAttempt < baseNumberOfAttempts) {
return baseDelay;
}
return baseDelay * 2 ** (currentAttempt - baseNumberOfAttempts);
}
exports.nextAttemptDelay = nextAttemptDelay;
async function retrieveContractBytecode(address, hre) {
const provider = hre.network.provider;
const bytecodeString = (await provider.send('eth_getCode', [address, 'latest']));
const deployedBytecode = bytecodeString.startsWith('0x') ? bytecodeString.slice(2) : bytecodeString;
if (deployedBytecode.length === 0) {
throw new errors_1.ZkSyncVerifyPluginError(`The address ${address} has no bytecode. Is the contract deployed to this network?
The selected network is ${hre.network.name}.`);
}
return deployedBytecode;
}
exports.retrieveContractBytecode = retrieveContractBytecode;
function parseWrongConstructorArgumentsError(string) {
// extract the values of the "types" and "values" keys from the string
const data = JSON.parse(string.split('count=')[1].split(', value=')[0]);
return `The number of constructor arguments you provided (${data.values}) does not match the number of constructor arguments the contract has been deployed with (${data.types}).`;
}
exports.parseWrongConstructorArgumentsError = parseWrongConstructorArgumentsError;
async function extractModule(constructorArgsModulePath) {
const constructorArguments = (await Promise.resolve(`${constructorArgsModulePath}`).then(s => __importStar(require(s)))).default;
return constructorArguments;
}
exports.extractModule = extractModule;
function getZkVmNormalizedVersion(solcVersion, zkVmSolcVersion) {
return `zkVM-${solcVersion}-${zkVmSolcVersion}`;
}
exports.getZkVmNormalizedVersion = getZkVmNormalizedVersion;
function normalizeCompilerVersions(solcConfigData, zkSolcConfig, latestEraVersion, userConfigCompilers) {
const noramlizers = [
new config_normalizer_1.OverrideCompilerSolcUserConfigNormalizer(),
new config_normalizer_1.CompilerSolcUserConfigNormalizer(),
];
const compiler = solcConfigData.compiler;
return noramlizers
.find((normalize) => normalize.suituble(userConfigCompilers, solcConfigData.file))
?.normalize(compiler, zkSolcConfig, latestEraVersion, userConfigCompilers, solcConfigData.file);
}
exports.normalizeCompilerVersions = normalizeCompilerVersions;
function extractQueryParams(url) {
const parsedURL = new URL(url);
const searchParams = new URLSearchParams(parsedURL.search);
const params = Object.fromEntries(searchParams);
const newURL = parsedURL.origin + parsedURL.pathname;
return [newURL, params];
}
exports.extractQueryParams = extractQueryParams;
function printVerificationErrors(errors) {
let errorMessage = 'hardhat-zksync-verify found one or more errors during the verification process:\n\n';
for (const [subtaskLabel, error] of Object.entries(errors)) {
errorMessage += `${subtaskLabel}:\n${error.message}\n\n`;
}
console.error(chalk_1.default.red(errorMessage));
}
exports.printVerificationErrors = printVerificationErrors;
//# sourceMappingURL=utils.js.map