2020-11-18 18:18:02 +00:00
|
|
|
import { task } from 'hardhat/config';
|
2021-01-15 15:48:54 +00:00
|
|
|
import { DRE, setDRE } from '../../helpers/misc-utils';
|
|
|
|
import { HardhatRuntimeEnvironment } from 'hardhat/types';
|
2020-05-29 14:55:31 +00:00
|
|
|
|
2020-11-05 12:44:20 +00:00
|
|
|
task(`set-DRE`, `Inits the DRE, to have access to all the plugins' objects`).setAction(
|
|
|
|
async (_, _DRE) => {
|
2021-01-15 15:48:54 +00:00
|
|
|
if (DRE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
(_DRE as HardhatRuntimeEnvironment).network.name.includes('tenderly') ||
|
|
|
|
process.env.TENDERLY === 'true'
|
|
|
|
) {
|
|
|
|
console.log('- Setting up Tenderly provider');
|
2021-05-18 07:59:05 +00:00
|
|
|
const net = _DRE.tenderly.network();
|
|
|
|
|
2021-03-03 11:25:10 +00:00
|
|
|
if (process.env.TENDERLY_FORK_ID && process.env.TENDERLY_HEAD_ID) {
|
|
|
|
console.log('- Connecting to a Tenderly Fork');
|
2021-05-18 07:59:05 +00:00
|
|
|
await net.setFork(process.env.TENDERLY_FORK_ID);
|
|
|
|
await net.setHead(process.env.TENDERLY_HEAD_ID);
|
2021-03-03 11:25:10 +00:00
|
|
|
} else {
|
|
|
|
console.log('- Creating a new Tenderly Fork');
|
2021-05-18 07:59:05 +00:00
|
|
|
await net.initializeFork();
|
2021-03-03 11:25:10 +00:00
|
|
|
}
|
2021-05-18 07:59:05 +00:00
|
|
|
const provider = new _DRE.ethers.providers.Web3Provider(net);
|
2021-01-15 15:48:54 +00:00
|
|
|
_DRE.ethers.provider = provider;
|
2021-03-03 11:25:10 +00:00
|
|
|
console.log('- Initialized Tenderly fork:');
|
2021-05-18 07:59:05 +00:00
|
|
|
console.log(' - Fork: ', net.getFork());
|
|
|
|
console.log(' - Head: ', net.getHead());
|
2021-01-15 15:48:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 13:34:31 +00:00
|
|
|
console.log('- Enviroment');
|
|
|
|
if (process.env.FORK) {
|
|
|
|
console.log(' - Fork Mode activated at network: ', process.env.FORK);
|
|
|
|
if (_DRE?.config?.networks?.hardhat?.forking?.url) {
|
|
|
|
console.log(' - Provider URL:', _DRE.config.networks.hardhat.forking?.url?.split('/')[2]);
|
|
|
|
} else {
|
|
|
|
console.error(
|
|
|
|
`[FORK][Error], missing Provider URL for "${_DRE.network.name}" network. Fill the URL at './helper-hardhat-config.ts' file`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(' - Network :', _DRE.network.name);
|
2021-05-18 07:59:05 +00:00
|
|
|
|
2020-11-05 12:44:20 +00:00
|
|
|
setDRE(_DRE);
|
|
|
|
return _DRE;
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
);
|