-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhardhat.config.ts
257 lines (245 loc) · 8.07 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
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
252
253
254
255
256
257
import { task, subtask } from 'hardhat/config';
import { TASK_COMPILE_SOLIDITY_EMIT_ARTIFACTS } from 'hardhat/builtin-tasks/task-names';
import { join } from 'path';
import { writeFile, mkdir, readFile } from 'fs/promises';
import { inspect } from 'util';
import '@nomicfoundation/hardhat-chai-matchers';
import 'hardhat-diamond-abi';
import '@nomicfoundation/hardhat-toolbox';
import 'hardhat-abi-exporter';
import { toSignature, isIncluded } from './scripts/diamond';
import { cutFacets, replaceFacet } from './scripts/libraries/diamond';
import 'hardhat-gas-reporter';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';
import 'hardhat-tracer';
import 'solidity-docgen';
// import './playbook';
import getSuperInterface from './scripts/getSuperInterface';
import { ErrorFragment, EventFragment, FunctionFragment } from '@ethersproject/abi';
import './scripts/generateSelectorDocs';
type ContractMap = Record<string, { abi: object }>;
subtask(TASK_COMPILE_SOLIDITY_EMIT_ARTIFACTS).setAction(async (args, env, next) => {
const output = await next();
const promises = Object.entries(args.output.contracts).map(async ([sourceName, contract]) => {
// Extract the contract name from the full path
const contractName = sourceName.split('/').pop()?.replace('.sol', '') || '';
const dirPath = join('./abi', sourceName);
await mkdir(dirPath, { recursive: true });
const file = join(dirPath, `${contractName}.ts`);
const { abi } = Object.values(contract as ContractMap)[0];
if (JSON.stringify(abi).length > 2) {
const data = `export const abi = ${inspect(abi, false, null)} as const; export default abi;`;
await writeFile(file, data);
}
});
await Promise.all(promises);
return output;
});
task('diamond-abi-viem-export', 'Generates the rankify diamond viem abi file').setAction(async (_, hre) => {
try {
const diamondDirpath = join('./abi/hardhat-diamond-abi/HardhatDiamondABI.sol');
await mkdir(diamondDirpath, { recursive: true });
const diamondAbiPath = join(diamondDirpath, 'RankifyDiamondInstance.json');
const diamondAbiContent = await readFile(diamondAbiPath, 'utf-8');
const abi = JSON.parse(diamondAbiContent);
if (abi) {
const data = `export const abi = ${inspect(abi, false, null)} as const; export default abi;`;
await writeFile(join(diamondDirpath, 'RankifyDiamondInstance.ts'), data);
}
} catch (error) {
console.warn('Failed to generate diamond ABI:', error);
}
});
task('defaultDistributionId', 'Prints the default distribution id', async (taskArgs, hre) => {
const id = hre.ethers.utils.formatBytes32String(process.env.DEFAULT_DISTRIBUTION_NAME ?? 'MAO Distribution');
if (taskArgs.print) console.log(id);
return id;
}).addFlag('print', 'Prints the default distribution id');
task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
task('getSuperInterface', 'Prints the super interface of a contract').setAction(async (taskArgs, hre) => {
const su = getSuperInterface();
let return_value: {
functions: Record<string, FunctionFragment>;
events: Record<string, EventFragment>;
errors: Record<string, ErrorFragment>;
} = {
functions: {},
events: {},
errors: {},
};
Object.values(su.functions).forEach(x => {
return_value['functions'][su.getSighash(x)] = x;
});
Object.values(su.events).forEach(x => {
return_value['events'][su.getEventTopic(x)] = x;
});
Object.values(su.errors).forEach(x => {
return_value['errors'][su.getSighash(x)] = x;
});
console.log(JSON.stringify(return_value, null, 2));
});
task('replaceFacet', 'Upgrades facet')
.addParam('facet', 'facet')
.addParam('address', 'contract address')
.setAction(async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
const response = await replaceFacet(taskArgs.address, taskArgs.facet, accounts[0]);
});
task('addFacet', 'adds a facet')
.addParam('facet', 'facet')
.addParam('address', 'contract address')
.setAction(async (taskArgs, hre) => {
const Facet = await hre.ethers.getContractFactory(taskArgs.facet);
const accounts = await hre.ethers.getSigners();
const facet = await Facet.deploy();
await facet.deployed();
const response = await cutFacets({
facets: [facet],
diamondAddress: taskArgs.address,
signer: accounts[0],
});
});
// task("PublishIPNS", "Publishes IPNS with new pointer")
// .addParam("value")
// .setAction(async (taskArgs) => {
// await ipfsUtils.publish(`${taskArgs.value}`);
// });
export default {
docgen: {
outputDir: './docs/contracts',
pages: 'files',
templates: 'docs/templates',
sourcesDir: './src',
pageExtension: '.md',
exclude: ['mocks', 'initializers', 'vendor', 'modifiers', 'fixtures'],
},
gasReporter: {
currency: 'EUR',
gasPrice: 21,
token: 'MATIC',
gasPriceApi: 'https://api.polygonscan.com/api?module=proxy&action=eth_gasPrice',
enabled: false,
coinmarketcap: process.env.COINMARKETCAP_KEY,
},
namedAccounts: {
deployer: {
hardhat: '0xF52E5dF676f51E410c456CC34360cA6F27959420',
anvil: '0x6Cf8d74C7875de8C2FfB09228F4bf2A21b25e583',
default: '0xF52E5dF676f51E410c456CC34360cA6F27959420', //TODO this must be set for networks
},
owner: {
default: '0x520E00225C4a43B6c55474Db44a4a44199b4c3eE',
anvil: '0x507c2d32185667156de5B4C440FEEf3800078bDb',
},
gameMaster: {
localhost: '0xaA63aA2D921F23f204B6Bcb43c2844Fb83c82eb9',
},
defaultPlayer: {
localhost: '0xF52E5dF676f51E410c456CC34360cA6F27959420',
},
DAO: {
default: '0x520E00225C4a43B6c55474Db44a4a44199b4c3eE',
},
},
mocha: {
timeout: 400000,
},
defaultNetwork: 'hardhat',
networks: {
hardhat: {
accounts: {
mnemonic: 'casual vacant letter raw trend tool vacant opera buzz jaguar bridge myself',
}, // ONLY LOCAL
forking: {
url: process.env.FORK_RPC_URL ?? '',
blockNumber: 257223284, // works for arbitrum, change for others
},
},
localhost: {
url: 'http://127.0.0.1:8545',
accounts: {
mnemonic: 'casual vacant letter raw trend tool vacant opera buzz jaguar bridge myself',
}, // ONLY LOCAL
},
anvil: {
url: process.env.ANVIL_RPC_URL ?? '',
accounts: {
mnemonic: process.env.ANVIL_MNEMONIC ?? 'x',
},
},
},
paths: {
sources: './src',
},
solidity: {
compilers: [
{
version: '0.8.28',
settings: {
optimizer: {
enabled: true,
runs: 2000,
},
},
},
{
version: '0.8.20',
settings: {
optimizer: {
enabled: true,
runs: 2000,
},
},
},
{
version: '0.8.17',
settings: {
optimizer: {
enabled: true,
runs: 2000,
},
},
},
],
},
diamondAbi: [
{
name: 'RankifyDiamondInstance',
include: [
'DiamondLoupeFacet',
'EIP712InspectorFacet',
'OwnershipFacet',
'RankifyInstanceMainFacet',
'RankifyInstanceRequirementsFacet',
'RankifyInstanceGameMastersFacet',
],
strict: false,
filter(abiElement: unknown, index: number, abi: unknown[], fullyQualifiedName: string) {
const signature = toSignature(abiElement);
return isIncluded(fullyQualifiedName, signature);
},
},
],
typechain: {
outDir: 'types',
target: 'ethers-v5',
alwaysGenerateOverloads: true, // should overloads with full signatures like deposit(uint256) be generated always, even if there are no overloads?
// externalArtifacts: ["externalArtifacts/*.json"], // optional array of glob patterns with external artifacts to process (for example external libs from node_modules)
},
abiExporter: {
path: './abi',
runOnCompile: true,
clear: true,
format: 'json',
// flat: true,
// only: [":ERC20$"],
spacing: 2,
pretty: false,
},
};