forked from ampleforth/token-geyser-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardhat.config.ts
554 lines (504 loc) · 19 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-etherscan';
import '@nomiclabs/hardhat-waffle';
import '@openzeppelin/hardhat-upgrades';
import 'hardhat-gas-reporter';
import 'solidity-coverage';
import { getAdminAddress, getImplementationAddress } from '@openzeppelin/upgrades-core';
import { Contract, Signer, Wallet, BigNumber } from 'ethers';
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
import { HardhatUserConfig, task } from 'hardhat/config';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address';
import { parseUnits } from 'ethers/lib/utils';
const SDK_PATH = './sdk';
// Loads env variables from .env file
import * as dotenv from 'dotenv';
dotenv.config();
async function deployContract(
name: string,
getContractFactory: Function,
signer: Signer,
args: Array<any> = [],
): Promise<Contract> {
const factory = await getContractFactory(name, signer);
const contract = await factory.deploy(...args);
console.log('Deploying', name);
console.log(' to', contract.address);
console.log(' in', contract.deployTransaction.hash);
return contract.deployed();
}
async function deployMockAmpl(
admin: SignerWithAddress,
getContractFactory: Function,
deployProxy: Function,
): Promise<Contract> {
const factory = await getContractFactory('MockAmpl');
const ampl = await deployProxy(factory, [admin.address], {
initializer: 'initialize(address)',
});
await ampl.connect(admin).setMonetaryPolicy(admin.address);
const amplInitialSupply = (await ampl.balanceOf(admin.address)) as BigNumber;
console.log('Deploying MockAmpl');
console.log(' to', ampl.address);
console.log(' in', ampl.deployTransaction.hash);
console.log('Initial Ample Supply: ', amplInitialSupply.toString());
return ampl;
}
async function createInstance(
instanceName: string,
factory: Contract,
getContractAt: Function,
signer: Signer,
args: string = '0x',
) {
// get contract class
const instance = await getContractAt(instanceName, await factory.connect(signer).callStatic['create(bytes)'](args));
// deploy vault
const tx = await factory.connect(signer)['create(bytes)'](args);
// return contract class
console.log('Deploying', instanceName);
console.log(' to', instance.address);
console.log(' in', tx.hash);
return instance;
}
task('deploy', 'deploy full set of factory contracts')
.addFlag('mock')
.setAction(async ({ mock }, { ethers, run, network, upgrades }) => {
await run('compile');
const signer = (await ethers.getSigners())[0];
console.log('Signer', signer.address);
const timestamp = (await signer.provider?.getBlock('latest'))?.timestamp;
const PowerSwitchFactory = await deployContract('PowerSwitchFactory', ethers.getContractFactory, signer);
const RewardPoolFactory = await deployContract('RewardPoolFactory', ethers.getContractFactory, signer);
const UniversalVault = await deployContract('UniversalVault', ethers.getContractFactory, signer);
const VaultFactory = await deployContract('VaultFactory', ethers.getContractFactory, signer, [
UniversalVault.address,
]);
const GeyserRegistry = await deployContract('GeyserRegistry', ethers.getContractFactory, signer);
const RouterV1 = await deployContract('RouterV1', ethers.getContractFactory, signer);
if (mock) {
const totalSupply = parseUnits('10');
await deployContract('MockERC20', ethers.getContractFactory, signer, [signer.address, totalSupply]);
await deployContract('MockBAL', ethers.getContractFactory, signer, [signer.address, totalSupply]);
await deployMockAmpl(signer, ethers.getContractFactory, upgrades.deployProxy);
}
console.log('Locking template');
await UniversalVault.initializeLock();
const path = `${SDK_PATH}/deployments/${network.name}/`;
const file = `factories-${timestamp}.json`;
const latest = `factories-latest.json`;
console.log('Saving config to', path + file);
const blob = JSON.stringify({
PowerSwitchFactory: {
address: PowerSwitchFactory.address,
abi: PowerSwitchFactory.interface.format(),
},
RewardPoolFactory: {
address: RewardPoolFactory.address,
abi: RewardPoolFactory.interface.format(),
},
VaultTemplate: {
address: UniversalVault.address,
abi: UniversalVault.interface.format(),
},
VaultFactory: {
address: VaultFactory.address,
abi: VaultFactory.interface.format(),
},
GeyserRegistry: {
address: GeyserRegistry.address,
abi: GeyserRegistry.interface.format(),
},
GeyserTemplate: {
abi: (await ethers.getContractAt('Geyser', ethers.constants.AddressZero)).interface.format(),
},
RouterV1: {
address: RouterV1.address,
abi: RouterV1.interface.format(),
},
});
mkdirSync(path, { recursive: true });
writeFileSync(path + file, blob);
writeFileSync(path + latest, blob);
});
task('verify-factories', 'verfires the deployed factories')
.addOptionalParam('factoryVersion', 'the factory version', 'latest')
.setAction(async ({ factoryVersion }, { ethers, run, network }) => {
const { PowerSwitchFactory, RewardPoolFactory, VaultFactory, GeyserRegistry, VaultTemplate } = JSON.parse(
readFileSync(`${SDK_PATH}/deployments/${network.name}/factories-${factoryVersion}.json`).toString(),
);
console.log('Verifying source on etherscan');
try {
await run('verify:verify', {
address: PowerSwitchFactory.address,
});
console.log('Done verifying PowerSwitchFactory');
} catch (e) {
console.error('Failed to verify PowerSwitchFactory', e);
}
try {
await run('verify:verify', {
address: RewardPoolFactory.address,
});
console.log('Done verifying RewardPoolFactory');
} catch (e) {}
try {
await run('verify:verify', {
address: VaultTemplate.address,
});
console.log('Done verifying VaultTemplate');
} catch (e) {}
try {
await run('verify:verify', {
address: VaultFactory.address,
constructorArguments: [VaultTemplate.address],
});
console.log('Done verifying VaultFactory');
} catch (e) {}
try {
await run('verify:verify', {
address: GeyserRegistry.address,
});
console.log('Done verifying GeyserRegistry');
} catch (e) {}
});
task('create-vault', 'deploy an instance of UniversalVault')
.addOptionalPositionalParam('factoryVersion', 'the factory version', 'latest')
.setAction(async ({ factoryVersion }, { ethers, run, network }) => {
await run('compile');
const signer = (await ethers.getSigners())[0];
console.log('Signer', signer.address);
const { VaultFactory } = JSON.parse(
readFileSync(`${SDK_PATH}/deployments/${network.name}/factories-${factoryVersion}.json`).toString(),
);
const vaultFactory = await ethers.getContractAt('VaultFactory', VaultFactory.address, signer);
await createInstance('UniversalVault', vaultFactory, ethers.getContractAt, signer);
});
task('create-geyser', 'deploy an instance of Geyser')
.addParam('stakingToken', 'the staking token')
.addParam('rewardToken', 'the reward token')
.addParam('floor', 'the floor of reward scaling')
.addParam('ceiling', 'the ceiling of reward scaling')
.addParam('time', 'the time of reward scaling in seconds')
.addOptionalParam('finalOwner', 'the address of the final owner', '0x')
.addOptionalParam('factoryVersion', 'the factory version', 'latest')
.setAction(
async (
{ factoryVersion, stakingToken, rewardToken, floor, ceiling, time, finalOwner },
{ ethers, run, upgrades, network },
) => {
await run('compile');
const signer = (await ethers.getSigners())[0];
console.log('Signer', signer.address);
const { PowerSwitchFactory, RewardPoolFactory, VaultFactory, GeyserRegistry } = JSON.parse(
readFileSync(`${SDK_PATH}/deployments/${network.name}/factories-${factoryVersion}.json`).toString(),
);
console.log({ PowerSwitchFactory, RewardPoolFactory, VaultFactory, GeyserRegistry });
const factory = await ethers.getContractFactory('Geyser', signer);
const geyser = await upgrades.deployProxy(factory, undefined, {
initializer: false,
});
await geyser.deployTransaction.wait(1);
const implementation = await getImplementationAddress(ethers.provider, geyser.address);
const proxyAdminAddress = await getAdminAddress(ethers.provider, geyser.address);
console.log('Deploying Geyser');
console.log(' to proxy', geyser.address);
console.log(' to implementation', implementation);
console.log(' with upgreadability admin', proxyAdminAddress);
console.log(' in', geyser.deployTransaction.hash);
console.log(' staking token', stakingToken);
console.log(' reward token', rewardToken);
console.log(' reward floor', floor);
console.log(' reward ceiling', ceiling);
// CRITICAL: The ordering of the following transaction can't change for the subgraph to be indexed
// Note: geyser registry is owned by the ecofund multisig
// this script will fail here
// the following need to be executed manually
console.log('Register Geyser Instance');
const geyserRegistry = await ethers.getContractAt('GeyserRegistry', GeyserRegistry.address, signer);
await (await geyserRegistry.register(geyser.address)).wait(1);
console.log('initialize geyser');
await (
await geyser.initialize(
signer.address,
RewardPoolFactory.address,
PowerSwitchFactory.address,
stakingToken,
rewardToken,
[floor, ceiling, time],
)
).wait(1);
console.log('Register Vault Factory');
await (await geyser.registerVaultFactory(VaultFactory.address)).wait(1);
if (finalOwner !== '0x') {
console.log('Transfer ownership');
const powerSwitch = await ethers.getContractAt(
'@openzeppelin/contracts/access/Ownable.sol:Ownable',
await geyser.getPowerSwitch(),
);
const proxyAdmin = await ethers.getContractAt(
'@openzeppelin/contracts/access/Ownable.sol:Ownable',
proxyAdminAddress,
);
await (await powerSwitch.transferOwnership(finalOwner)).wait(1);
await (await geyser.transferOwnership(finalOwner)).wait(1);
await (await proxyAdmin.transferOwnership(finalOwner)).wait(1);
}
},
);
task('fund-geyser', 'fund an instance of Geyser')
.addParam('geyser', 'address of geyser')
.addParam('amount', 'amount as raw integer')
.addParam('duration', 'time in seconds the program lasts')
.addOptionalParam('factoryVersion', 'the factory version', 'latest')
.setAction(async ({ geyser, amount, duration }, { ethers }) => {
const signer = (await ethers.getSigners())[0];
const geyserContract = await ethers.getContractAt('Geyser', geyser, signer);
const data = await geyserContract.getGeyserData();
const { rewardToken: rewardTokenAddress } = data;
const rewardToken = await ethers.getContractAt('MockAmpl', rewardTokenAddress, signer);
const amt = parseUnits(amount, 0);
await rewardToken.approve(geyser, amt);
await geyserContract.connect(signer).fundGeyser(amt, duration);
});
// currently need to manually run verify command
// ie) the implementation address of the deployed proxy through create-geyser
// can automate after this issue is closed: https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/290
task('verify-geyser', 'verify and lock the Geyser template')
.addPositionalParam('geysertemplate', 'the geyser template address')
.setAction(async ({ geysertemplate }, { ethers, run, upgrades, network }) => {
await run('compile');
const signer = (await ethers.getSigners())[0];
console.log('Signer', signer.address);
const contract = await ethers.getContractAt('Geyser', geysertemplate, signer);
console.log('Locking template');
await contract.initializeLock();
console.log('Verifying source on etherscan');
await run('verify:verify', {
address: contract.address,
});
// TODO: verify reward pool
});
task('register-vault-factory', 'register a vault factory instance with a Geyser')
.addParam('geyser', 'address of geyser')
.addParam('vaultFactory', 'address of vault factory')
.setAction(async ({ geyser, vaultFactory }, { ethers }) => {
const signer = (await ethers.getSigners())[0];
const geyserContract = await ethers.getContractAt('Geyser', geyser, signer);
const res = await geyserContract.connect(signer).registerVaultFactory(vaultFactory);
console.log(`Transaction hash: ${res.hash}`);
});
task('lookup-proxy-admin', 'gets the proxy admin of the given contract')
.addPositionalParam('address', 'the proxy contract address')
.setAction(async ({ address }, { ethers, run, upgrades, network }) => {
console.log('Proxy Admin:', await getAdminAddress(ethers.provider, address));
});
task('transfer-ownership', 'transfers a contract that implements Ownable to a new owner')
.addParam('contract', 'address of Ownable contract')
.addParam('owner', 'address of new owner')
.setAction(async ({ contract, owner }, { ethers }) => {
const ownable = await ethers.getContractAt('@openzeppelin/contracts/access/Ownable.sol:Ownable', contract);
const res = await ownable.transferOwnership(owner);
console.log(`Transaction hash: ${res.hash}`);
});
const getEtherscanAPIKey = () => {
switch (process.env.HARDHAT_NETWORK) {
case 'mainnet' || 'kovan' || 'goerli' || 'sepolia': {
console.log('Using etherscan api key');
return process.env.ETHERSCAN_API_KEY;
}
case 'avalanche' || 'avalanche_fiji': {
console.log('Using snowtrace API key');
return process.env.SNOWTRACE_API_KEY;
}
case 'arbitrum': {
console.log('Using arbiscan API key');
return process.env.ARBISCAN_API_KEY;
}
case 'optimisticEthereum': {
console.log('Using optimistic-etherscan API key');
return process.env.OPTIMISTIC_ETHERSCAN_API_KEY;
}
case 'base-mainnet': {
console.log('Using base API key');
return process.env.BASE_API_KEY;
}
case 'base-goerli' || 'base-mainnet': {
console.log('Using base API key');
return process.env.BASE_API_KEY;
}
case 'sei-devnet': {
console.log('Using sei-trace API key');
return process.env.SEITRACE_API_KEY;
}
case 'polygon': {
console.log('Using polygon-scan API key');
return process.env.POLYGONSCAN_API_KEY;
}
default:
return '';
}
};
// When using a local network, MetaMask assumes a chainId of 1337, even though the default chainId of HardHat is 31337
// https://github.com/MetaMask/metamask-extension/issues/10290
export default {
networks: {
hardhat: {
allowUnlimitedContractSize: true,
chainId: 1337,
},
ganache: {
url: 'http://127.0.0.1:8545',
chainId: 1337,
},
goerli: {
url: `https://goerli.infura.io/v3/${process.env.INFURA_SECRET}`,
accounts: process.env.DEV_PKEY
? [process.env.DEV_PKEY]
: {
mnemonic: process.env.DEV_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
gasMultiplier: 1.03,
allowUnlimitedContractSize: true,
},
mainnet: {
url: `https://mainnet.infura.io/v3/${process.env.INFURA_SECRET}`,
accounts: process.env.PROD_PKEY
? [process.env.PROD_PKEY]
: {
mnemonic: process.env.PROD_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
gasMultiplier: 1.03,
},
'base-mainnet': {
url: 'https://mainnet.base.org',
accounts: process.env.PROD_PKEY
? [process.env.PROD_PKEY]
: {
mnemonic: process.env.PROD_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
urls: {
apiURL: 'https://api.basescan.org/api',
browserURL: 'https://basescan.org',
},
gasMultiplier: 1.03,
},
'base-goerli': {
url: 'https://goerli.base.org',
accounts: process.env.DEV_PKEY
? [process.env.DEV_PKEY]
: {
mnemonic: process.env.DEV_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
urls: {
apiURL: 'https://api.basescan.org/api',
browserURL: 'https://basescan.org',
},
gasMultiplier: 1.03,
},
avalanche: {
url: 'https://api.avax.network/ext/bc/C/rpc',
accounts: process.env.PROD_PKEY
? [process.env.PROD_PKEY]
: {
mnemonic: process.env.PROD_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
gasMultiplier: 1.03,
chainId: 43114,
},
arbitrum: {
url: 'https://arb1.arbitrum.io/rpc',
accounts: process.env.PROD_PKEY
? [process.env.PROD_PKEY]
: {
mnemonic: process.env.PROD_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
gasMultiplier: 1.03,
chainId: 42161,
},
optimisticEthereum: {
url: 'https://mainnet.optimism.io',
accounts: process.env.PROD_PKEY
? [process.env.PROD_PKEY]
: {
mnemonic: process.env.PROD_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
gasMultiplier: 1.03,
chainId: 10,
},
'sei-devnet': {
url: 'https://evm-rpc.arctic-1.seinetwork.io',
accounts: process.env.DEV_PKEY
? [process.env.DEV_PKEY]
: {
mnemonic: process.env.DEV_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
chainId: 713715,
},
sepolia: {
url: `https://sepolia.infura.io/v3/${process.env.INFURA_SECRET}`,
accounts: process.env.DEV_PKEY
? [process.env.DEV_PKEY]
: {
mnemonic: process.env.DEV_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
gasMultiplier: 1.03,
allowUnlimitedContractSize: true,
},
polygon: {
url: `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_SECRET}`,
accounts: process.env.PROD_PKEY
? [process.env.PROD_PKEY]
: {
mnemonic: process.env.PROD_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
gasMultiplier: 1.03,
allowUnlimitedContractSize: true,
},
},
solidity: {
compilers: [
{
version: '0.4.24',
},
{
version: '0.7.6',
settings: {
optimizer: {
enabled: true,
runs: 1000,
},
},
},
],
},
etherscan: {
apiKey: getEtherscanAPIKey(),
customChains: [
{
network: 'base-mainnet',
chainId: 8453,
urls: {
apiURL: 'https://api.basescan.org/api',
browserURL: 'https://basescan.org',
},
},
{
network: 'base-goerli',
chainId: 84531,
urls: {
apiURL: 'https://api-goerli.basescan.org/api',
browserURL: 'https://goerli.basescan.org',
},
},
],
},
mocha: {
timeout: 100000,
},
gasReporter: {
currency: 'USD',
enabled: process.env.REPORT_GAS ? true : false,
excludeContracts: ['Mock/'],
},
} as HardhatUserConfig;