forked from ampleforth/token-geyser-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.ts
324 lines (278 loc) · 10.6 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
import '@nomiclabs/hardhat-ethers'
import '@nomiclabs/hardhat-etherscan'
import '@nomiclabs/hardhat-waffle'
import '@openzeppelin/hardhat-upgrades'
import 'hardhat-gas-reporter'
import 'solidity-coverage'
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'
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('noVerify')
.addFlag('mock')
.setAction(async ({ noVerify, 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)
if (!noVerify) {
console.log('Verifying source on etherscan')
await run('verify:verify', {
address: PowerSwitchFactory.address,
})
await run('verify:verify', {
address: RewardPoolFactory.address,
})
await run('verify:verify', {
address: UniversalVault.address,
})
await run('verify:verify', {
address: VaultFactory.address,
constructorArguments: [UniversalVault.address],
})
await run('verify:verify', {
address: GeyserRegistry.address,
})
}
})
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('factoryVersion', 'the factory version', 'latest')
.setAction(
async ({ factoryVersion, stakingToken, rewardToken, floor, ceiling, time }, { 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(),
)
const factory = await ethers.getContractFactory('Geyser', signer)
const geyser = await upgrades.deployProxy(factory, undefined, {
initializer: false,
})
console.log('Deploying Geyser')
console.log(' to', geyser.address)
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)
console.log(' reward time', stakingToken)
console.log('Register Geyser Instance')
const geyserRegistry = await ethers.getContractAt('GeyserRegistry', GeyserRegistry.address, signer)
await geyserRegistry.register(geyser.address)
await geyser.initialize(
signer.address,
RewardPoolFactory.address,
PowerSwitchFactory.address,
stakingToken,
rewardToken,
[floor, ceiling, time],
)
console.log('Register Vault Factory')
await geyser.registerVaultFactory(VaultFactory.address)
},
)
task('fund-geyser', 'fund an instance of Geyser')
.addParam('geyser', 'address of geyser')
.addParam('amount', 'amount')
.addOptionalParam('factoryVersion', 'the factory version', 'latest')
.setAction(async ({ geyser, amount }, { 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, 9)
await rewardToken.approve(geyser, amt)
await geyserContract.connect(signer).fundGeyser(amt, 10000)
})
// currently need to manually run verify command
// 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,
})
})
// 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,
},
goerli: {
url: 'https://goerli.infura.io/v3/' + process.env.INFURA_ID,
accounts: {
mnemonic: process.env.DEV_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
},
kovan: {
url: 'https://kovan.infura.io/v3/' + process.env.INFURA_ID,
accounts: {
mnemonic: process.env.DEV_MNEMONIC || Wallet.createRandom().mnemonic.phrase,
},
},
mainnet: {
url: 'https://mainnet.infura.io/v3/' + process.env.INFURA_ID,
accounts: {
mnemonic: process.env.PROD_MNEMONIC,
},
},
},
solidity: {
compilers: [
{
version: '0.4.24',
},
{
version: '0.7.6',
settings: {
optimizer: {
enabled: true,
runs: 1000,
},
},
},
],
},
etherscan: {
apiKey: process.env.ETHERSCAN_APIKEY,
},
mocha: {
timeout: 100000,
},
gasReporter: {
currency: 'USD',
enabled: process.env.REPORT_GAS ? true : false,
excludeContracts: ['Mock/'],
},
} as HardhatUserConfig