UNPKG

@api3/contracts

Version:

Contracts through which API3 services are delivered

71 lines 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEnvVariableNames = getEnvVariableNames; exports.etherscanApiKeyName = etherscanApiKeyName; exports.networkHttpRpcUrlName = networkHttpRpcUrlName; exports.etherscan = etherscan; exports.networks = networks; const chains_1 = require("./generated/chains"); const strings_1 = require("./utils/strings"); function getEnvVariableNames() { const apiKeyEnvNames = chains_1.CHAINS.filter((chain) => chain.explorer?.api?.key?.required).map((chain) => etherscanApiKeyName(chain)); const networkRpcUrlNames = chains_1.CHAINS.map((chain) => networkHttpRpcUrlName(chain)); return ['MNEMONIC', ...apiKeyEnvNames, ...networkRpcUrlNames]; } function etherscanApiKeyName(chain) { return `ETHERSCAN_API_KEY_${(0, strings_1.toUpperSnakeCase)(chain.alias)}`; } 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 chains_1.CHAINS.reduce((etherscan, chain) => { if (!chain.explorer || !chain.explorer.api) { return etherscan; } const apiKey = chain.explorer.api.key; const apiKeyEnvName = etherscanApiKeyName(chain); const apiKeyValue = apiKey.required ? (process.env[apiKeyEnvName] ?? 'NOT_FOUND') : 'DUMMY_VALUE'; if (apiKey.hardhatEtherscanAlias) { etherscan.apiKey[apiKey.hardhatEtherscanAlias] = apiKeyValue; return etherscan; } etherscan.customChains.push({ network: chain.alias, chainId: Number(chain.id), urls: { apiURL: chain.explorer.api.url, browserURL: chain.explorer.browserUrl, }, }); etherscan.apiKey[chain.alias] = apiKeyValue; return etherscan; }, { apiKey: {}, customChains: [] }); } 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'); } return chains_1.CHAINS.reduce((networks, chain) => { const defaultProvider = chain.providers.find((p) => p.alias === 'default'); const overrides = chain.hardhatConfigOverrides?.networks ?? {}; networks[chain.alias] = { accounts: { mnemonic: process.env.MNEMONIC ?? '' }, chainId: Number(chain.id), url: process.env[networkHttpRpcUrlName(chain)] ?? defaultProvider.rpcUrl, ...overrides, }; return networks; }, {}); } //# sourceMappingURL=hardhat-config.js.map