This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-core.ts
249 lines (209 loc) · 6.66 KB
/
deploy-core.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
import { network, ethers } from 'hardhat';
import { ParamType, keccak256 } from 'ethers/lib/utils';
import {
DAI,
ORACLE_START_DATE,
TREASURY_START_DATE,
UNI_FACTORY,
} from '../deploy.config';
import OLD from '../deployments/4.json';
import { encodeParameters, wait } from './utils';
const MINUTE = 60;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
async function main() {
if (network.name !== 'mainnet') {
throw new Error('wrong network');
}
const { provider } = ethers;
const [operator] = await ethers.getSigners();
const estimateGasPrice = await provider.getGasPrice();
const gasPrice = estimateGasPrice.mul(3).div(2);
console.log(`Gas Price: ${ethers.utils.formatUnits(gasPrice, 'gwei')} gwei`);
const override = { gasPrice };
// Fetch existing contracts
// === token
const cash = await ethers.getContractAt('ARTH', OLD.ARTH);
const bond = await ethers.getContractAt('ARTHB', OLD.ARTHB);
const share = await ethers.getContractAt('Share', OLD.Share);
// === core
const seigniorageOracle = await ethers.getContractAt('Oracle', OLD.Oracle);
const timelock = await ethers.getContractAt('Timelock', OLD.Timelock);
const treasury = await ethers.getContractAt('Treasury', OLD.Treasury);
const boardroom = await ethers.getContractAt('Boardroom', OLD.Boardroom);
console.log('Deployments');
console.log(JSON.stringify(OLD, null, 2));
if (operator.address !== (await timelock.admin())) {
throw new Error(`Invalid admin ${operator.address}`);
}
console.log(`Admin verified ${operator.address}`);
const Oracle = await ethers.getContractFactory('Oracle');
const MAHADAIARTHLPTokenPool = await ethers.getContractFactory('MAHADAIARTHLPTokenPool');
// const Boardroom = await ethers.getContractFactory('Boardroom');
const SimpleFund = await ethers.getContractFactory('SimpleERCFund');
let tx;
console.log('\n===================================================\n');
console.log('=> Deploy\n');
const simpleFund = await SimpleFund.connect(operator).deploy();
await wait(
ethers,
simpleFund.deployTransaction.hash,
`\nDeploy fund contract => ${simpleFund.address}`
);
const bondOracle = await Oracle.connect(operator).deploy(
UNI_FACTORY,
cash.address,
DAI,
HOUR,
ORACLE_START_DATE,
override
);
await wait(
ethers,
bondOracle.deployTransaction.hash,
`\nDeploy new Oracle => ${bondOracle.address}`
);
// const newBoardroom = await Boardroom.connect(operator).deploy(
// cash.address,
// share.address,
// override
// );
// await wait(
// ethers,
// newBoardroom.deployTransaction.hash,
// `\nDeploy new Boardroom => ${newBoardroom.address}`
// );
const newTreasury = await Treasury.connect(operator).deploy(
cash.address,
bond.address,
share.address,
bondOracle.address,
seigniorageOracle.address,
boardroom.address,
simpleFund.address,
TREASURY_START_DATE,
override
);
await wait(
ethers,
newTreasury.deployTransaction.hash,
`\nDeploy new Treasury => ${newTreasury.address}`
);
console.log('\n===================================================\n');
console.log('=> RBAC\n');
// tx = await newBoardroom
// .connect(operator)
// .transferOperator(newTreasury.address, override);
// await wait(tx.hash, 'boardroom.transferOperator');
// tx = await newBoardroom
// .connect(operator)
// .transferOwnership(timelock.address, override);
// await wait(tx.hash, 'boardroom.transferOwnership');
tx = await simpleFund
.connect(operator)
.transferOperator(timelock.address, override);
await wait(ethers, tx.hash, 'fund.transferOperator');
tx = await simpleFund
.connect(operator)
.transferOwnership(timelock.address, override);
await wait(ethers, tx.hash, 'fund.transferOwnership');
tx = await newTreasury
.connect(operator)
.transferOperator(timelock.address, override);
await wait(ethers, tx.hash, 'treasury.transferOperator');
tx = await newTreasury
.connect(operator)
.transferOwnership(timelock.address, override);
await wait(ethers, tx.hash, 'treasury.transferOwnership');
console.log('\n===================================================\n');
console.log('=> Migration\n');
let eta;
let calldata;
let txHash;
// 1. transfer operator to old treasury
eta = Math.round(new Date().getTime() / 1000) + 2 * DAY + 60;
calldata = [
boardroom.address,
0,
'transferOperator(address)',
encodeParameters(ethers, ['address'], [treasury.address]),
eta,
];
txHash = keccak256(
encodeParameters(
ethers,
['address', 'uint256', 'string', 'bytes', 'uint256'],
calldata
)
);
tx = await timelock.connect(operator).queueTransaction(...calldata, override);
await wait(
ethers,
tx.hash,
`\n1. timelock.queueTransaction (boardroom.transferOperator) => txHash: ${txHash}`
);
console.log(`Tx execution ETA: ${eta}`);
if (!(await timelock.connect(operator).queuedTransactions(txHash))) {
throw new Error('wtf');
}
// 2. migrate treasury
eta = Math.round(new Date().getTime() / 1000) + 2 * DAY + 60;
calldata = [
treasury.address,
0,
'migrate(address)',
encodeParameters(ethers, ['address'], [newTreasury.address]),
eta,
];
txHash = keccak256(
encodeParameters(
ethers,
['address', 'uint256', 'string', 'bytes', 'uint256'],
calldata
)
);
tx = await timelock.connect(operator).queueTransaction(...calldata, override);
await wait(
ethers,
tx.hash,
`\n2. timelock.queueTransaction (treasury.migrate) => txHash: ${txHash}`
);
console.log(`Tx execution ETA: ${eta}`);
if (!(await timelock.connect(operator).queuedTransactions(txHash))) {
throw new Error('wtf');
}
// 3. transfer operator to new treasury
eta = Math.round(new Date().getTime() / 1000) + 2 * DAY + 60;
calldata = [
boardroom.address,
0,
'transferOperator(address)',
encodeParameters(ethers, ['address'], [newTreasury.address]),
eta,
];
txHash = keccak256(
encodeParameters(
ethers,
['address', 'uint256', 'string', 'bytes', 'uint256'],
calldata
)
);
tx = await timelock.connect(operator).queueTransaction(...calldata, override);
await wait(
ethers,
tx.hash,
`\n3. timelock.queueTransaction (boardroom.transferOperator) => txHash: ${txHash}`
);
console.log(`Tx execution ETA: ${eta}`);
if (!(await timelock.connect(operator).queuedTransactions(txHash))) {
throw new Error('wtf');
}
console.log('OK!');
console.log('\n===================================================\n');
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});