UNPKG

@api3/contracts

Version:

Contracts through which API3 services are delivered

83 lines 3.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEnvVariableNames = getEnvVariableNames; exports.etherscanApiKeyName = etherscanApiKeyName; exports.networkHttpRpcUrlName = networkHttpRpcUrlName; exports.etherscan = etherscan; exports.blockscout = blockscout; exports.networks = networks; const chains_1 = require("./generated/chains"); const strings_1 = require("./utils/strings"); function getEnvVariableNames() { const apiKeyEnvName = etherscanApiKeyName(); const networkRpcUrlNames = chains_1.CHAINS.map((chain) => networkHttpRpcUrlName(chain)); return ['MNEMONIC', 'KEYCARD_ACCOUNT', apiKeyEnvName, ...networkRpcUrlNames]; } function etherscanApiKeyName() { return `ETHERSCAN_API_KEY`; } function networkHttpRpcUrlName(chain) { // TODO: we might want to synchronise this with the way viemConfig.chains() sources // env level RPC values. i.e. replacing the "HARHDAT_" prefix with something more generic // Latest suggestion is "API3_CHAINS_" instead. // See thread: https://github.com/api3dao/chains/pull/125/files#r1384859991 return `HARDHAT_HTTP_RPC_URL_${(0, strings_1.toUpperSnakeCase)(chain.alias)}`; } // https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#multiple-api-keys-and-alternative-block-explorers function etherscan() { if (typeof window !== 'undefined') { // eslint-disable-next-line unicorn/prefer-type-error throw new Error('Cannot be called outside of a Node.js environment'); } return { apiKey: process.env[etherscanApiKeyName()] ?? '', customChains: chains_1.CHAINS.filter((chain) => chain.verificationApi?.type === 'etherscan').map((chain) => ({ network: chain.alias, chainId: Number(chain.id), urls: { apiURL: `https://api.etherscan.io/v2/api?chainid=${chain.id}`, browserURL: chain.blockExplorerUrl, }, })), }; } function blockscout() { if (typeof window !== 'undefined') { // eslint-disable-next-line unicorn/prefer-type-error throw new Error('Cannot be called outside of a Node.js environment'); } return { enabled: true, customChains: chains_1.CHAINS.filter((chain) => chain.verificationApi?.type === 'blockscout' || chain.verificationApi?.type === 'other').map((chain) => ({ network: chain.alias, chainId: Number(chain.id), urls: { apiURL: chain.verificationApi?.type === 'blockscout' || chain.verificationApi?.type === 'other' ? chain.verificationApi?.url : '', browserURL: chain.blockExplorerUrl, }, })), }; } function networks() { if (typeof window !== 'undefined') { // eslint-disable-next-line unicorn/prefer-type-error throw new Error('Cannot be called outside of a Node.js environment'); } const credentials = process.env.KEYCARD_ACCOUNT ? { keycardAccount: process.env.KEYCARD_ACCOUNT } : { accounts: { mnemonic: process.env.MNEMONIC ?? '' } }; return chains_1.CHAINS.reduce((networks, chain) => { const defaultProvider = chain.providers.find((p) => p.alias === 'default'); const overrides = chain.hardhatConfigOverrides?.networks ?? {}; networks[chain.alias] = { ...credentials, chainId: Number(chain.id), url: process.env[networkHttpRpcUrlName(chain)] ?? defaultProvider.rpcUrl, ...overrides, }; return networks; }, {}); } //# sourceMappingURL=hardhat-config.js.map