@tenderly/hardhat-integration
Version:
Hardhat plugin for integration with Tenderly
56 lines • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VerificationService = void 0;
const api_client_1 = require("@tenderly/api-client");
const errors_1 = require("../errors");
const util_1 = require("../utils/util");
const utils_1 = require("../utils");
const errors_2 = require("./errors");
class VerificationService {
constructor(tenderlyService, tenderlyNetwork) {
this.tenderlyService = tenderlyService;
this.tenderlyNetwork = tenderlyNetwork;
}
async verifyContractABI(hre, address, contractName) {
await (0, errors_1.throwIfUsernameOrProjectNotSet)(hre);
const authRequest = await this.makeVerifyContractABIRequest(hre, address, contractName);
// if the verificationType is on project,
// add the contract to the project, first so ABI verification doesn't break because of that.
if (authRequest.verificationType === api_client_1.VERIFICATION_TYPES.PRIVATE || api_client_1.VERIFICATION_TYPES.PUBLIC) {
await this.tenderlyService.addContractToProject(authRequest.username, authRequest.project, {
network_id: authRequest.request.networkId,
address: authRequest.request.address,
display_name: authRequest.request.contractName,
});
}
return this.tenderlyService.verifyContractABI(authRequest.username, authRequest.project, authRequest.verificationType, authRequest.request);
}
async makeVerifyContractABIRequest(hre, address, contractName) {
const verificationType = await (0, utils_1.getVerificationType)(hre, this.tenderlyNetwork);
if (verificationType === api_client_1.VERIFICATION_TYPES.DEVNET) {
throw new errors_2.VerifyContractABIOnDevnetNotSupportedError();
}
let networkId = (await (0, util_1.getChainId)(hre)).toString();
if (await (0, utils_1.isVerificationOnVnet)(verificationType)) {
networkId = this.tenderlyNetwork.forkID;
}
const abi = (await hre.artifacts.readArtifact(contractName)).abi;
const abiString = JSON.stringify(abi);
const request = {
networkId: networkId.toString(),
address: address,
contractName: contractName,
abi: abiString,
};
const username = hre.config.tenderly.username;
const project = hre.config.tenderly.project;
return {
username,
project,
verificationType,
request,
};
}
}
exports.VerificationService = VerificationService;
//# sourceMappingURL=service.js.map