50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
// @ts-ignore
|
|
import { HardhatNetworkForkingUserConfig } from 'hardhat/types';
|
|
import { eEthereumNetwork, iParamsPerNetwork } from './helpers/types';
|
|
|
|
require('dotenv').config();
|
|
|
|
const INFURA_KEY = process.env.INFURA_KEY || '';
|
|
const ALCHEMY_KEY = process.env.ALCHEMY_KEY || '';
|
|
const FORK = process.env.FORK || '';
|
|
const FORK_BLOCK_NUMBER = process.env.FORK_BLOCK_NUMBER
|
|
? parseInt(process.env.FORK_BLOCK_NUMBER)
|
|
: 0;
|
|
|
|
const GWEI = 1000 * 1000 * 1000;
|
|
|
|
export const buildForkConfig = (): HardhatNetworkForkingUserConfig | undefined => {
|
|
let forkMode: HardhatNetworkForkingUserConfig | undefined;
|
|
if (FORK) {
|
|
forkMode = {
|
|
url: NETWORKS_RPC_URL[FORK],
|
|
};
|
|
if (FORK_BLOCK_NUMBER || BLOCK_TO_FORK[FORK]) {
|
|
forkMode.blockNumber = FORK_BLOCK_NUMBER || BLOCK_TO_FORK[FORK];
|
|
}
|
|
}
|
|
return forkMode;
|
|
};
|
|
|
|
export const NETWORKS_RPC_URL: iParamsPerNetwork<string> = {
|
|
[eEthereumNetwork.kovan]: ALCHEMY_KEY
|
|
? `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_KEY}`
|
|
: `https://kovan.infura.io/v3/${INFURA_KEY}`,
|
|
[eEthereumNetwork.ropsten]: ALCHEMY_KEY
|
|
? `https://eth-ropsten.alchemyapi.io/v2/${ALCHEMY_KEY}`
|
|
: `https://ropsten.infura.io/v3/${INFURA_KEY}`,
|
|
[eEthereumNetwork.main]: ALCHEMY_KEY
|
|
? `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}`
|
|
: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
|
|
[eEthereumNetwork.coverage]: 'http://localhost:8555',
|
|
[eEthereumNetwork.hardhat]: 'http://localhost:8545',
|
|
};
|
|
|
|
export const BLOCK_TO_FORK: iParamsPerNetwork<number | undefined> = {
|
|
[eEthereumNetwork.main]: 12406069,
|
|
[eEthereumNetwork.kovan]: undefined,
|
|
[eEthereumNetwork.ropsten]: undefined,
|
|
[eEthereumNetwork.coverage]: undefined,
|
|
[eEthereumNetwork.hardhat]: undefined,
|
|
};
|