-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardhat.config.ts
129 lines (120 loc) · 3.37 KB
/
hardhat.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import "@typechain/hardhat";
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import 'dotenv/config';
// Constants
const FRONTRUNNING_MINING_INTERVAL = 10000; // 10 seconds
const MAINNET_FORK_BLOCK_NUMBER = 15969633;
const MAINNET_FORK_BLOCK_NUMBER_MONEY_MARKET = 16776127;
const GOERLI_FORK_BLOCK_NUMBER = 8660077;
const AVAX_C_CHAIN_BLOCK_GAS_LIMIT = 8_000_000;
const MAINNET_URL = process.env.MAINNET;
if (!MAINNET_URL) console.log('Warning: MAINNET not found in .env\n');
const GOERLI_URL = process.env.GOERLI;
if (!GOERLI_URL) console.log('Warning: GOERLI not found in .env\n');
// Dynamically get the test mode from environment variables
const testMode = process.env.TEST_MODE || '';
const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: '0.8.24',
},
],
overrides: {
'contracts/unchecked-return-3/USDC.sol': {
version: '0.6.12',
settings: {},
},
'contracts/unchecked-return-3/DAI.sol': {
version: '0.5.12',
settings: {},
},
'contracts/unchecked-return-3/UST.sol': {
version: '0.4.17',
settings: {},
},
},
},
};
let scriptName;
if (process.argv[3] != undefined) {
scriptName = process.argv[3];
} else {
scriptName = '';
}
if (
scriptName.includes('dex-1') ||
scriptName.includes('dex-2') ||
scriptName.includes('flash-loan-3') ||
scriptName.includes('flash-loan-2') ||
scriptName.includes('oracle-manipulation-2') ||
scriptName.includes('oracle-manipulation-3') ||
scriptName.includes('optimizer-vault-2')
) {
console.log(`Forking Mainnet Block Height ${MAINNET_FORK_BLOCK_NUMBER}`);
config.networks = {
hardhat: {
forking: {
url: MAINNET_URL!,
blockNumber: MAINNET_FORK_BLOCK_NUMBER,
},
},
};
} else if (scriptName.includes('front-running') || scriptName.includes('optimizer-vault-1')) {
// Frontrunning exercises are with "hardhat node mode", mining interval is 10 seconds
console.log(`Forking Mainnet Block Height ${MAINNET_FORK_BLOCK_NUMBER}, Manual Mining Mode`);
config.networks = {
hardhat: {
forking: {
url: MAINNET_URL!,
blockNumber: MAINNET_FORK_BLOCK_NUMBER,
},
mining: {
auto: false,
interval: FRONTRUNNING_MINING_INTERVAL,
},
gas: 'auto',
},
};
} else if (scriptName.includes('money-market')) {
console.log(`Forking Mainnet Block Height ${MAINNET_FORK_BLOCK_NUMBER_MONEY_MARKET}`);
config.networks = {
hardhat: {
forking: {
url: MAINNET_URL!,
blockNumber: MAINNET_FORK_BLOCK_NUMBER_MONEY_MARKET,
},
},
};
} else if (scriptName.includes('sensitive-on-chain-data-1') || scriptName.includes('sensitive-on-chain-data-2')) {
console.log(`Forking Goerli Block Height ${GOERLI_FORK_BLOCK_NUMBER}`);
config.networks = {
hardhat: {
forking: {
url: GOERLI_URL!,
blockNumber: GOERLI_FORK_BLOCK_NUMBER,
},
},
};
} else if (scriptName.includes('gas-manipulation-1')) {
config.networks = {
hardhat: {
forking: {
url: MAINNET_URL!,
blockNumber: MAINNET_FORK_BLOCK_NUMBER,
},
gas: AVAX_C_CHAIN_BLOCK_GAS_LIMIT,
},
};
} else {
config.networks = {
hardhat: {
// loggingEnabled: true
},
goerli: {
url: process.env.GOERLI,
},
};
}
export default config;