Repository navigation
Expand file tree
/
Copy pathhardhat.config.ts
More file actions
251 lines (240 loc) · 8.76 KB
/
Copy pathhardhat.config.ts
File metadata and controls
251 lines (240 loc) · 8.76 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import '@nomicfoundation/hardhat-toolbox';
import 'dotenv/config';
import * as fs from 'fs';
import 'hardhat-abi-exporter';
import 'hardhat-dependency-compiler';
import 'hardhat-deploy';
import { HardhatUserConfig, task } from 'hardhat/config';
import {
HARDHAT_NETWORK_MNEMONIC,
defaultHardhatNetworkParams,
defaultLocalhostNetworkParams,
} from 'hardhat/internal/core/config/default-config';
import 'solidity-docgen';
import { cleanupDeployments, copyDeployments } from './scripts/tools/copy-deployments';
import chainConfig from './utils/config';
const isArbitrumSepoliaFork = chainConfig.isArbitrumSepoliaFork();
const isArbitrumFork = chainConfig.isArbitrumFork();
// Arbitrum Sepolia specific configuration
const arbitrumSepoliaBaseConfig = {
chainId: 421614,
blockGasLimit: 32_000_000,
};
// Arbitrum specific configuration
const arbitrumBaseConfig = {
chainId: 42161,
// https://docs.arbitrum.io/build-decentralized-apps/arbitrum-vs-ethereum/block-numbers-and-time#block-gas-limit
blockGasLimit: 32_000_000,
};
const settings = {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: { '*': { '*': ['storageLayout'] } },
};
const v8Settings = {
...settings,
/**
* Enable Intermediate Representation (IR) to reduce `Stack too deep` occurrences
* at compile time (e.g.: too many local variables in `matchOrdersBoost`).
* https://hardhat.org/hardhat-runner/docs/reference/solidity-support#support-for-ir-based-codegen
*/
viaIR: true,
optimizer: {
...settings.optimizer,
details: {
yul: true,
yulDetails: {
optimizerSteps: 'u',
},
},
},
};
const config: HardhatUserConfig = {
solidity: {
compilers: [
{ version: '0.8.21', settings: v8Settings }, // PoCo contracts
{ version: '0.6.12', settings }, // External dependencies (@amxx/factory)
{ version: '0.4.24', settings }, // RLC contracts
],
},
namedAccounts: {
deployer: {
default: 0,
arbitrum: chainConfig.chains['42161'].deployer,
arbitrumSepolia: chainConfig.chains['421614'].deployer,
},
owner: {
default: 0, // TODO change this to 1 and update admin tests.
arbitrum: chainConfig.chains['42161'].owner,
arbitrumSepolia: chainConfig.chains['421614'].owner,
},
},
networks: {
hardhat: {
accounts: {
mnemonic: process.env.MNEMONIC || HARDHAT_NETWORK_MNEMONIC,
},
...(isArbitrumSepoliaFork && {
forking: {
url:
process.env.ARBITRUM_SEPOLIA_RPC_URL ||
'https://sepolia-rollup.arbitrum.io/rpc',
blockNumber: process.env.ARBITRUM_SEPOLIA_BLOCK_NUMBER
? parseInt(process.env.ARBITRUM_SEPOLIA_BLOCK_NUMBER)
: undefined,
},
...arbitrumSepoliaBaseConfig,
}),
...(isArbitrumFork && {
forking: {
url: process.env.ARBITRUM_RPC_URL || 'https://arbitrum.gateway.tenderly.co',
},
...arbitrumBaseConfig,
}),
},
'external-hardhat': {
...defaultHardhatNetworkParams,
...defaultLocalhostNetworkParams,
accounts: {
mnemonic: process.env.MNEMONIC || HARDHAT_NETWORK_MNEMONIC,
},
...(isArbitrumSepoliaFork && {
accounts: 'remote', // Override defaults accounts for impersonation
...arbitrumSepoliaBaseConfig,
}),
...(isArbitrumFork && {
accounts: 'remote', // Override defaults accounts for impersonation
...arbitrumBaseConfig,
}),
},
arbitrum: {
url:
process.env.ARBITRUM_RPC_URL || // Used in local development
process.env.RPC_URL || // Defined in Github Actions environments
'https://arbitrum.gateway.tenderly.co',
accounts: _getPrivateKeys(),
...arbitrumBaseConfig,
},
arbitrumSepolia: {
url:
process.env.ARBITRUM_SEPOLIA_RPC_URL || // Used in local development
process.env.RPC_URL || // Defined in Github Actions environments
'https://sepolia-rollup.arbitrum.io/rpc',
accounts: _getPrivateKeys(),
...arbitrumSepoliaBaseConfig,
},
},
etherscan: {
// Using Etherscan V2 API for unified multichain support
apiKey: process.env.EXPLORER_API_KEY || '',
},
sourcify: {
enabled: true,
},
typechain: {
outDir: 'typechain',
},
dependencyCompiler: {
paths: [
'rlc-faucet-contract/contracts/RLC.sol',
// ERC-2535 Diamond
'@mudgen/diamond-1/contracts/facets/DiamondCutFacet.sol',
'@mudgen/diamond-1/contracts/facets/DiamondLoupeFacet.sol',
'@mudgen/diamond-1/contracts/facets/OwnershipFacet.sol',
'@mudgen/diamond-1/contracts/libraries/LibDiamond.sol',
'@mudgen/diamond-1/contracts/upgradeInitializers/DiamondInit.sol',
// Used as mock or fake in UTs
'@openzeppelin/contracts/interfaces/IERC1271.sol',
// Used in deployment
'@amxx/factory/contracts/v6/GenericFactory.sol',
'createx/src/ICreateX.sol',
],
keep: true, // Slither requires compiled dependencies
},
docgen: {
outputDir: 'docs/solidity',
templates: 'docs/solidity/templates',
exclude: [
'external/',
'facets/IexecAccessorsABILegacyFacet.sol', // not relevant
// TODO: put all events and soldoc inside interfaces and use them instead of contracts.
'interfaces/', // interesting for events but too much doc duplication if enabled
'libs/CommonLib.sol', // contains only internal/private
'tools/',
'Diamond.sol', // not relevant
],
},
mocha: { timeout: 300000 },
abiExporter: [
// ABIs of PoCo contracts for integration with other tools.
{
path: './abis/contracts',
format: 'json',
runOnCompile: true,
clear: true,
only: ['^contracts/'],
except: [
// !!! Update package.json#files if this is modified.
// TODO reorganize utility contracts.
'^contracts/tools/testing/',
'^contracts/tools/diagrams/',
],
rename: (sourceName, contractName) =>
`${sourceName.replace('contracts/', '').replace('.sol', '')}`,
},
// ABIs of all contracts in a human readable format for easier upgrade debugging.
{
path: './abis/human-readable-abis',
format: 'minimal',
runOnCompile: true,
clear: true,
},
],
};
/**
* Ignore doc generation of contracts compiled with solc@0.4 (unsupported by docgen).
*/
task('docgen').setAction(async (taskArgs, hre, runSuper) => {
const ignoredSuffix = '.docgen-ignored';
const ignoredPaths: string[] = [];
for (const path of await hre.artifacts.getBuildInfoPaths()) {
const solcVersion: string = JSON.parse(fs.readFileSync(path, 'utf8')).solcVersion;
if (solcVersion.startsWith('0.4')) {
fs.renameSync(path, path + ignoredSuffix); // mark as docgen ignored
ignoredPaths.push(path);
}
}
await runSuper(taskArgs).finally(() => {
for (const path of ignoredPaths) {
fs.renameSync(path + ignoredSuffix, path); // restore build info as before
}
});
});
/**
* Override `test` task to copy deployments of Arbitrum Sepolia if running tests on
* a forked Arbitrum Sepolia network and clean them up afterwards.
*/
task('test').setAction(async (taskArgs: any, hre, runSuper) => {
let deploymentsCopied = false;
let networkName = '';
try {
if (isArbitrumSepoliaFork) {
networkName = 'arbitrumSepolia';
deploymentsCopied = await copyDeployments(networkName);
}
await runSuper(taskArgs);
} finally {
if (deploymentsCopied && networkName) {
await cleanupDeployments(networkName);
}
}
});
function _getPrivateKeys() {
const ZERO_PRIVATE_KEY = '0x0000000000000000000000000000000000000000000000000000000000000000';
const deployerKey = process.env.DEPLOYER_PRIVATE_KEY || ZERO_PRIVATE_KEY;
const adminKey = process.env.ADMIN_PRIVATE_KEY || ZERO_PRIVATE_KEY;
return [deployerKey, adminKey];
}
export default config;