@ensuro/core 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/deploy.js +67 -22
- package/package.json +1 -1
package/js/deploy.js
CHANGED
|
@@ -7,14 +7,28 @@ const _BN = ethers.BigNumber.from;
|
|
|
7
7
|
const WAD = _BN(1e10).mul(_BN(1e8)); // 1e10*1e8=1e18
|
|
8
8
|
const RAY = WAD.mul(_BN(1e9)); // 1e18*1e9=1e27
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Creates a fixed-point conversion function for the desired number of decimals
|
|
12
|
+
* @param decimals The number of decimals. Must be >= 6.
|
|
13
|
+
* @returns The amount function created. The function can receive strings (recommended),
|
|
14
|
+
* floats/doubles (not recommended) and integers.
|
|
15
|
+
*
|
|
16
|
+
* Floats will be rounded to 6 decimal before scaling.
|
|
17
|
+
*/
|
|
18
|
+
function amountFunction(decimals) {
|
|
19
|
+
return function (value) {
|
|
20
|
+
if (value === undefined) return undefined;
|
|
21
|
+
|
|
22
|
+
if (typeof value === "string" || value instanceof String) {
|
|
23
|
+
return hre.ethers.utils.parseUnits(value, decimals);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!Number.isInteger(value)) {
|
|
27
|
+
return _BN(Math.round(value * 1e6)).mul(_BN(Math.pow(10, decimals - 6)));
|
|
28
|
+
}
|
|
14
29
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return _BN(value).mul(RAY);
|
|
30
|
+
return _BN(value).mul(_BN(10).pow(decimals));
|
|
31
|
+
};
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
function amountDecimals() {
|
|
@@ -23,13 +37,25 @@ function amountDecimals() {
|
|
|
23
37
|
return decimals;
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
const GWei = amountFunction(9);
|
|
41
|
+
const _W = amountFunction(18);
|
|
42
|
+
const _R = amountFunction(27);
|
|
43
|
+
const _A = amountFunction(amountDecimals());
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Transaction overrides using env variables because hardhat-ethers ignores hardhat config
|
|
47
|
+
* See: https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-ethers#gas-transaction-parameters-in--hardhat.config--are-not-used
|
|
48
|
+
*/
|
|
49
|
+
function txOverrides() {
|
|
50
|
+
const ret = {};
|
|
51
|
+
if (process.env.OVERRIDE_GAS_PRICE !== undefined) {
|
|
52
|
+
ret.gasPrice = GWei(parseFloat(process.env.OVERRIDE_GAS_PRICE));
|
|
32
53
|
}
|
|
54
|
+
|
|
55
|
+
if (process.env.OVERRIDE_GAS_LIMIT !== undefined) {
|
|
56
|
+
ret.gasLimit = parseInt(process.env.OVERRIDE_GAS_LIMIT);
|
|
57
|
+
}
|
|
58
|
+
return ret || undefined;
|
|
33
59
|
}
|
|
34
60
|
|
|
35
61
|
function saveAddress(name, address) {
|
|
@@ -94,7 +120,7 @@ async function verifyContract(hre, contract, isProxy, constructorArguments) {
|
|
|
94
120
|
|
|
95
121
|
async function deployContract({ saveAddr, verify, contractClass, constructorArgs }, hre) {
|
|
96
122
|
const ContractFactory = await hre.ethers.getContractFactory(contractClass);
|
|
97
|
-
const contract = await ContractFactory.deploy(...constructorArgs);
|
|
123
|
+
const contract = await ContractFactory.deploy(...constructorArgs, txOverrides());
|
|
98
124
|
if (verify) {
|
|
99
125
|
// From https://ethereum.stackexchange.com/a/119622/79726
|
|
100
126
|
await contract.deployTransaction.wait(6);
|
|
@@ -126,6 +152,14 @@ async function deployProxyContract({ saveAddr, verify, contractClass, constructo
|
|
|
126
152
|
return { ContractFactory, contract };
|
|
127
153
|
}
|
|
128
154
|
|
|
155
|
+
function parseRole(role) {
|
|
156
|
+
if (role.startsWith("0x"))
|
|
157
|
+
return role;
|
|
158
|
+
if (role === "DEFAULT_ADMIN_ROLE")
|
|
159
|
+
return ethers.constants.HashZero;
|
|
160
|
+
return ethers.utils.keccak256(ethers.utils.toUtf8Bytes(role));
|
|
161
|
+
}
|
|
162
|
+
|
|
129
163
|
async function grantComponentRole(hre, contract, component, role, user) {
|
|
130
164
|
let userAddress;
|
|
131
165
|
if (user === undefined) {
|
|
@@ -134,11 +168,11 @@ async function grantComponentRole(hre, contract, component, role, user) {
|
|
|
134
168
|
} else {
|
|
135
169
|
userAddress = user;
|
|
136
170
|
}
|
|
137
|
-
const roleHex =
|
|
171
|
+
const roleHex = parseRole(role);
|
|
138
172
|
const componentAddress = component.address || component;
|
|
139
173
|
const componentRole = await contract.getComponentRole(componentAddress, roleHex);
|
|
140
174
|
if (!(await contract.hasRole(componentRole, userAddress))) {
|
|
141
|
-
await contract.grantComponentRole(componentAddress, roleHex, userAddress);
|
|
175
|
+
await contract.grantComponentRole(componentAddress, roleHex, userAddress, txOverrides());
|
|
142
176
|
console.log(`Role ${role} (${roleHex}) Component ${componentAddress} granted to ${userAddress}`);
|
|
143
177
|
} else {
|
|
144
178
|
console.log(`Role ${role} (${roleHex}) Component ${componentAddress} already granted to ${userAddress}`);
|
|
@@ -153,9 +187,9 @@ async function grantRole(hre, contract, role, user) {
|
|
|
153
187
|
} else {
|
|
154
188
|
userAddress = user;
|
|
155
189
|
}
|
|
156
|
-
const roleHex =
|
|
190
|
+
const roleHex = parseRole(role);
|
|
157
191
|
if (!(await contract.hasRole(roleHex, userAddress))) {
|
|
158
|
-
await contract.grantRole(roleHex, userAddress);
|
|
192
|
+
await contract.grantRole(roleHex, userAddress, txOverrides());
|
|
159
193
|
console.log(`Role ${role} (${roleHex}) granted to ${userAddress}`);
|
|
160
194
|
} else {
|
|
161
195
|
console.log(`Role ${role} (${roleHex}) already granted to ${userAddress}`);
|
|
@@ -221,7 +255,8 @@ async function deployEToken(
|
|
|
221
255
|
hre
|
|
222
256
|
);
|
|
223
257
|
const policyPool = await hre.ethers.getContractAt("PolicyPool", poolAddress);
|
|
224
|
-
|
|
258
|
+
if (opts.addComponent)
|
|
259
|
+
await policyPool.addComponent(contract.address, 1);
|
|
225
260
|
return contract.address;
|
|
226
261
|
}
|
|
227
262
|
|
|
@@ -236,7 +271,8 @@ async function deployPremiumsAccount({ poolAddress, juniorEtk, seniorEtk, ...opt
|
|
|
236
271
|
hre
|
|
237
272
|
);
|
|
238
273
|
const policyPool = await hre.ethers.getContractAt("PolicyPool", poolAddress);
|
|
239
|
-
|
|
274
|
+
if (opts.addComponent)
|
|
275
|
+
await policyPool.addComponent(contract.address, 3);
|
|
240
276
|
return contract.address;
|
|
241
277
|
}
|
|
242
278
|
|
|
@@ -305,7 +341,8 @@ async function deployRiskModule(
|
|
|
305
341
|
await rm.setParam(9, ensuroCocFee);
|
|
306
342
|
}
|
|
307
343
|
const policyPool = await hre.ethers.getContractAt("PolicyPool", poolAddress);
|
|
308
|
-
|
|
344
|
+
if (opts.addComponent)
|
|
345
|
+
await policyPool.addComponent(contract.address, 2);
|
|
309
346
|
return contract.address;
|
|
310
347
|
}
|
|
311
348
|
|
|
@@ -331,7 +368,7 @@ async function deploySignedQuoteRM(opts, hre) {
|
|
|
331
368
|
|
|
332
369
|
async function setAssetManager({ reserve, amAddress, liquidityMin, liquidityMiddle, liquidityMax }, hre) {
|
|
333
370
|
const reserveContract = await hre.ethers.getContractAt("Reserve", reserve);
|
|
334
|
-
await reserveContract.setAssetManager(amAddress, false);
|
|
371
|
+
const tx = await reserveContract.setAssetManager(amAddress, false);
|
|
335
372
|
console.log(`Asset Manager ${amAddress} set to reserve ${reserve}`);
|
|
336
373
|
if (liquidityMin !== undefined || liquidityMiddle !== undefined || liquidityMax !== undefined) {
|
|
337
374
|
liquidityMin = liquidityMin === undefined ? ethers.constants.MaxUint256 : _A(liquidityMin);
|
|
@@ -341,6 +378,9 @@ async function setAssetManager({ reserve, amAddress, liquidityMin, liquidityMidd
|
|
|
341
378
|
"ERC4626AssetManager", // Not relevant if it's ERC4626AssetManager, only need setLiquidityThresholds
|
|
342
379
|
amAddress
|
|
343
380
|
);
|
|
381
|
+
|
|
382
|
+
// To make sure the setAssetManager was executed - wait 2 confirmations
|
|
383
|
+
await tx.wait(process.env.NETWORK !== "localhost" ? 2 : undefined);
|
|
344
384
|
await reserveContract.forwardToAssetManager(
|
|
345
385
|
amContract.interface.encodeFunctionData("setLiquidityThresholds", [liquidityMin, liquidityMiddle, liquidityMax])
|
|
346
386
|
);
|
|
@@ -549,6 +589,7 @@ function add_task() {
|
|
|
549
589
|
task("deploy:eToken", "Deploy an EToken and adds it to the pool")
|
|
550
590
|
.addOptionalParam("verify", "Verify contract in Etherscan", false, types.boolean)
|
|
551
591
|
.addOptionalParam("saveAddr", "Save created contract address", "ETOKEN", types.str)
|
|
592
|
+
.addOptionalParam("addComponent", "Adds the new component to the pool", true, types.boolean)
|
|
552
593
|
.addParam("poolAddress", "PolicyPool Address", types.address)
|
|
553
594
|
.addParam("etkName", "Name of EToken", types.str)
|
|
554
595
|
.addParam("etkSymbol", "Symbol of EToken", types.str)
|
|
@@ -559,6 +600,7 @@ function add_task() {
|
|
|
559
600
|
task("deploy:premiumsAccount", "Deploy a premiums account")
|
|
560
601
|
.addOptionalParam("verify", "Verify contract in Etherscan", false, types.boolean)
|
|
561
602
|
.addOptionalParam("saveAddr", "Save created contract address", "PA", types.str)
|
|
603
|
+
.addOptionalParam("addComponent", "Adds the new component to the pool", true, types.boolean)
|
|
562
604
|
.addParam("poolAddress", "PolicyPool Address", types.address)
|
|
563
605
|
.addParam("juniorEtk", "Junior EToken Address", types.address)
|
|
564
606
|
.addParam("seniorEtk", "Senior EToken Address", types.address)
|
|
@@ -567,6 +609,7 @@ function add_task() {
|
|
|
567
609
|
task("deploy:riskModule", "Deploys a RiskModule and adds it to the pool")
|
|
568
610
|
.addOptionalParam("verify", "Verify contract in Etherscan", false, types.boolean)
|
|
569
611
|
.addOptionalParam("saveAddr", "Save created contract address", "RM", types.str)
|
|
612
|
+
.addOptionalParam("addComponent", "Adds the new component to the pool", true, types.boolean)
|
|
570
613
|
.addParam("poolAddress", "PolicyPool Address", types.address)
|
|
571
614
|
.addParam("paAddress", "PremiumsAccount Address", types.address)
|
|
572
615
|
.addOptionalParam("rmClass", "RiskModule contract", "TrustfulRiskModule", types.str)
|
|
@@ -587,6 +630,7 @@ function add_task() {
|
|
|
587
630
|
task("deploy:signedQuoteRiskModule", "Deploys a RiskModule and adds it to the pool")
|
|
588
631
|
.addOptionalParam("verify", "Verify contract in Etherscan", false, types.boolean)
|
|
589
632
|
.addOptionalParam("saveAddr", "Save created contract address", "RM", types.str)
|
|
633
|
+
.addOptionalParam("addComponent", "Adds the new component to the pool", true, types.boolean)
|
|
590
634
|
.addParam("poolAddress", "PolicyPool Address", types.address)
|
|
591
635
|
.addParam("paAddress", "PremiumsAccount Address", types.address)
|
|
592
636
|
.addOptionalParam("rmClass", "RiskModule contract", "SignedQuoteRiskModule", types.str)
|
|
@@ -608,6 +652,7 @@ function add_task() {
|
|
|
608
652
|
task("deploy:priceRiskModule", "Deploys and injects a Price RiskModule")
|
|
609
653
|
.addOptionalParam("verify", "Verify contract in Etherscan", false, types.boolean)
|
|
610
654
|
.addOptionalParam("saveAddr", "Save created contract address", "RM", types.str)
|
|
655
|
+
.addOptionalParam("addComponent", "Adds the new component to the pool", true, types.boolean)
|
|
611
656
|
.addParam("poolAddress", "PolicyPool Address", types.address)
|
|
612
657
|
.addParam("paAddress", "PremiumsAccount Address", types.address)
|
|
613
658
|
.addOptionalParam("rmClass", "RiskModule contract", "PriceRiskModule", types.str)
|