UNPKG

@matterlabs/hardhat-zksync-verify

Version:
117 lines 5.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZkSyncBlockExplorerVerificationIdResponse = exports.getProvidedChainConfig = exports.ZkSyncExplorerService = void 0; const axios_1 = __importDefault(require("axios")); const utils_1 = require("../../utils"); const service_1 = require("../service"); const errors_1 = require("../../errors"); const constants_1 = require("../../constants"); const errors_2 = require("../errors"); const verification_status_response_1 = require("./verification-status-response"); const chain_config_1 = require("./chain-config"); class ZkSyncExplorerService extends service_1.VerificationService { static async fromChainConfig(hre, chainConfig) { const apiUrl = chainConfig.urls.apiURL; const browserUrl = chainConfig.urls.browserURL ? chainConfig.urls.browserURL.trim().replace(/\/$/, '') : undefined; return new ZkSyncExplorerService(hre, apiUrl, browserUrl); } async getVerificationStatus(verificationId, contractInformation) { try { const [verifyURL, params] = (0, utils_1.extractQueryParams)(this.verifyUrl); const response = await axios_1.default.get(`${verifyURL}/${verificationId}`, { params }); if (response.status !== 200) { throw new errors_2.ZksyncContractVerificationInvalidStatusCodeError(this.verifyUrl, response.status, response.data); } const verificationStatusResponse = new verification_status_response_1.ZksyncBlockExplorerResponse(response); if (verificationStatusResponse.isPending()) { return verificationStatusResponse; } if (verificationStatusResponse.isFailure()) { if (verificationStatusResponse.getError() !== constants_1.NO_MATCHING_CONTRACT && constants_1.COMPILATION_ERRORS.filter((compilationError) => compilationError.pattern.test(verificationStatusResponse.getError())).length === 0) { throw new errors_1.ZkSyncVerifyPluginError(verificationStatusResponse.getError()); } return verificationStatusResponse; } if (!verificationStatusResponse.isOk()) { throw new errors_1.ZkSyncVerifyPluginError(verificationStatusResponse.getError()); } if (verificationStatusResponse.isSuccess()) { console.log(`Successfully verified contract ${contractInformation.contractName} on the block explorer. ${this.getContractBorwserUrl(contractInformation.contractAddress)} `); } return verificationStatusResponse; } catch (error) { (0, utils_1.handleAxiosError)(error); } } generateRequest(initialRequest) { return initialRequest; } async getVerificationId(req) { try { const [verifyUrl, params] = (0, utils_1.extractQueryParams)(this.verifyUrl); const request = this.generateRequest(req); const response = await axios_1.default.post(verifyUrl, request, { params }); const zkSyncBlockExplorerResponse = new ZkSyncBlockExplorerVerificationIdResponse(response); if (!zkSyncBlockExplorerResponse.isOk()) { throw new errors_1.ZkSyncVerifyPluginError(zkSyncBlockExplorerResponse.message); } return parseInt(zkSyncBlockExplorerResponse.message, 10); } catch (error) { (0, utils_1.handleAxiosError)(error); } } async getSupportedCompilerVersions() { try { const [verifyUrl, params] = (0, utils_1.extractQueryParams)(this.verifyUrl); const response = await axios_1.default.get(`${verifyUrl}/solc_versions`, { params }); return response.data; } catch (error) { (0, utils_1.handleAxiosError)(error); } } async getSolcVersion(contractInformation) { return contractInformation.solcVersion; } getContractBorwserUrl(address) { return this.browserUrl || this.browserUrl === '' ? `${this.browserUrl}/address/${address}#contract` : ''; } } exports.ZkSyncExplorerService = ZkSyncExplorerService; async function getProvidedChainConfig(hre) { const currentChainId = parseInt(await hre.network.provider.send('eth_chainId'), 16); return hre.network.config.verifyURL ? { network: hre.network.name, chainId: currentChainId, urls: { apiURL: hre.network.config.verifyURL, browserURL: hre.network.config.browserVerifyURL ?? chain_config_1.builtinChains.find((b) => b.chainId === currentChainId)?.urls.browserURL ?? '', }, } : undefined; } exports.getProvidedChainConfig = getProvidedChainConfig; class ZkSyncBlockExplorerVerificationIdResponse { constructor(response) { this.status = parseInt(response.status, 10); this.message = response.data; } isOk() { return this.status === 200; } } exports.ZkSyncBlockExplorerVerificationIdResponse = ZkSyncBlockExplorerVerificationIdResponse; //# sourceMappingURL=service.js.map