@ensuro/core 2.0.0-beta11 → 2.0.0-beta13
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/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +2 -2
- package/build/contracts/EToken.sol/EToken.json +2 -2
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +2 -2
- package/build/contracts/PolicyPool.sol/PolicyPool.json +21 -2
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +2 -2
- package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +133 -2
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +118 -2
- package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +19 -0
- package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +2 -2
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +2 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +21 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +2 -2
- package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +2 -2
- package/contracts/PolicyPool.sol +14 -2
- package/contracts/PolicyPoolComponent.sol +4 -0
- package/contracts/PremiumsAccount.sol +13 -0
- package/contracts/RiskModule.sol +9 -0
- package/contracts/SignedQuoteRiskModule.sol +113 -48
- package/contracts/TrustfulRiskModule.sol +52 -3
- package/contracts/interfaces/IPolicyPool.sol +14 -3
- package/contracts/mocks/PolicyPoolMock.sol +4 -0
- package/package.json +4 -2
- package/scripts/change-pragma.sh +19 -0
- package/scripts/deploySmokeTest-fork.sh +53 -0
- package/scripts/deploySmokeTest.sh +51 -0
- package/scripts/storageLayout.js +33 -0
- package/scripts/utils.sh +48 -0
|
@@ -22,6 +22,12 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
22
22
|
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
23
23
|
bool internal immutable _creationIsOpen;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @dev Event emitted every time a new policy is created. It allows to link the policyData with a particular policy
|
|
27
|
+
*
|
|
28
|
+
* @param policyId The id of the policy
|
|
29
|
+
* @param policyData The value sent in `policyData` parameter that's the hash of the off-chain stored data.
|
|
30
|
+
*/
|
|
25
31
|
event NewSignedPolicy(uint256 indexed policyId, bytes32 policyData);
|
|
26
32
|
|
|
27
33
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
@@ -74,7 +80,7 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
74
80
|
uint40 quoteValidUntil,
|
|
75
81
|
address payer,
|
|
76
82
|
address onBehalfOf
|
|
77
|
-
) internal returns (
|
|
83
|
+
) internal returns (Policy.PolicyData memory createdPolicy) {
|
|
78
84
|
if (!_creationIsOpen)
|
|
79
85
|
_policyPool.access().checkComponentRole(
|
|
80
86
|
address(this),
|
|
@@ -108,33 +114,92 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
108
114
|
_policyPool.access().checkComponentRole(address(this), PRICER_ROLE, signer, false);
|
|
109
115
|
uint96 internalId = uint96(uint256(policyData) % 2**96);
|
|
110
116
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
createdPolicy = _newPolicy(
|
|
118
|
+
payout,
|
|
119
|
+
premium,
|
|
120
|
+
lossProb,
|
|
121
|
+
expiration,
|
|
122
|
+
payer,
|
|
123
|
+
onBehalfOf,
|
|
124
|
+
internalId
|
|
125
|
+
);
|
|
126
|
+
emit NewSignedPolicy(createdPolicy.id, policyData);
|
|
127
|
+
return createdPolicy;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
 * @dev Creates a new Policy using a signed quote. The caller is the payer of the policy. Returns all the struct, not
|
|
132
|
+
* just the id.
|
|
133
|
+
*
|
|
134
|
+
* Same as {newPolicy} but returns all the PolicyData struct, usefull if the PolicyData needs to be stored on-chain.
|
|
135
|
+
 *
|
|
136
|
+
 * Requirements:
|
|
137
|
+
 * - The caller approved the spending of the premium to the PolicyPool
|
|
138
|
+
 * - The quote has been signed by an address with the component role PRICER_ROLE
|
|
139
|
+
 *
|
|
140
|
+
 * Emits:
|
|
141
|
+
 * - {PolicyPool.NewPolicy}
|
|
142
|
+
 * - {NewSignedPolicy}
|
|
143
|
+
 *
|
|
144
|
+
 * @param payout The exposure (maximum payout) of the policy
|
|
145
|
+
 * @param premium The premium that will be paid by the payer
|
|
146
|
+
 * @param lossProb The probability of having to pay the maximum payout (wad)
|
|
147
|
+
 * @param expiration The expiration of the policy (timestamp)
|
|
148
|
+
 * @param onBehalfOf The policy holder
|
|
149
|
+
 * @param policyData A hash of the private details of the policy. The last 96 bits will be used as internalId
|
|
150
|
+
 * @param quoteSignatureR The signature of the quote. R component (EIP-2098 signature)
|
|
151
|
+
 * @param quoteSignatureVS The signature of the quote. VS component (EIP-2098 signature)
|
|
152
|
+
 * @param quoteValidUntil The expiration of the quote
|
|
153
|
+
 * @return createdPolicy Returns the created policy
|
|
154
|
+
 */
|
|
155
|
+
function newPolicyFull(
|
|
156
|
+
uint256 payout,
|
|
157
|
+
uint256 premium,
|
|
158
|
+
uint256 lossProb,
|
|
159
|
+
uint40 expiration,
|
|
160
|
+
address onBehalfOf,
|
|
161
|
+
bytes32 policyData,
|
|
162
|
+
bytes32 quoteSignatureR,
|
|
163
|
+
bytes32 quoteSignatureVS,
|
|
164
|
+
uint40 quoteValidUntil
|
|
165
|
+
) external returns (Policy.PolicyData memory createdPolicy) {
|
|
166
|
+
return
|
|
167
|
+
_newPolicySigned(
|
|
168
|
+
payout,
|
|
169
|
+
premium,
|
|
170
|
+
lossProb,
|
|
171
|
+
expiration,
|
|
172
|
+
policyData,
|
|
173
|
+
quoteSignatureR,
|
|
174
|
+
quoteSignatureVS,
|
|
175
|
+
quoteValidUntil,
|
|
176
|
+
_msgSender(),
|
|
177
|
+
onBehalfOf
|
|
178
|
+
);
|
|
114
179
|
}
|
|
115
180
|
|
|
116
181
|
/**
|
|
117
|
-

|
|
118
|
-

|
|
119
|
-

|
|
120
|
-

|
|
121
|
-

|
|
122
|
-

|
|
123
|
-

|
|
124
|
-

|
|
125
|
-

|
|
126
|
-

|
|
127
|
-

|
|
128
|
-

|
|
129
|
-

|
|
130
|
-

|
|
131
|
-

|
|
132
|
-

|
|
133
|
-

|
|
134
|
-

|
|
135
|
-

|
|
136
|
-

|
|
137
|
-

|
|
182
|
+
 * @dev Creates a new Policy using a signed quote. The caller is the payer of the policy.
|
|
183
|
+
 *
|
|
184
|
+
 * Requirements:
|
|
185
|
+
 * - The caller approved the spending of the premium to the PolicyPool
|
|
186
|
+
 * - The quote has been signed by an address with the component role PRICER_ROLE
|
|
187
|
+
 *
|
|
188
|
+
 * Emits:
|
|
189
|
+
 * - {PolicyPool.NewPolicy}
|
|
190
|
+
 * - {NewSignedPolicy}
|
|
191
|
+
 *
|
|
192
|
+
 * @param payout The exposure (maximum payout) of the policy
|
|
193
|
+
 * @param premium The premium that will be paid by the payer
|
|
194
|
+
 * @param lossProb The probability of having to pay the maximum payout (wad)
|
|
195
|
+
 * @param expiration The expiration of the policy (timestamp)
|
|
196
|
+
 * @param onBehalfOf The policy holder
|
|
197
|
+
 * @param policyData A hash of the private details of the policy. The last 96 bits will be used as internalId
|
|
198
|
+
 * @param quoteSignatureR The signature of the quote. R component (EIP-2098 signature)
|
|
199
|
+
 * @param quoteSignatureVS The signature of the quote. VS component (EIP-2098 signature)
|
|
200
|
+
 * @param quoteValidUntil The expiration of the quote
|
|
201
|
+
 * @return Returns the id of the created policy
|
|
202
|
+
 */
|
|
138
203
|
function newPolicy(
|
|
139
204
|
uint256 payout,
|
|
140
205
|
uint256 premium,
|
|
@@ -158,31 +223,31 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
158
223
|
quoteValidUntil,
|
|
159
224
|
_msgSender(),
|
|
160
225
|
onBehalfOf
|
|
161
|
-
);
|
|
226
|
+
).id;
|
|
162
227
|
}
|
|
163
228
|
|
|
164
229
|
/**
|
|
165
|
-

|
|
166
|
-

|
|
167
|
-

|
|
168
|
-

|
|
169
|
-

|
|
170
|
-

|
|
171
|
-

|
|
172
|
-

|
|
173
|
-

|
|
174
|
-

|
|
175
|
-

|
|
176
|
-

|
|
177
|
-

|
|
178
|
-

|
|
179
|
-

|
|
180
|
-

|
|
181
|
-

|
|
182
|
-

|
|
183
|
-

|
|
184
|
-

|
|
185
|
-

|
|
230
|
+
 * @dev Creates a new Policy using a signed quote. The payer is the policy holder
|
|
231
|
+
 *
|
|
232
|
+
 * Requirements:
|
|
233
|
+
 * - currency().allowance(onBehalfOf, _msgSender()) > 0
|
|
234
|
+
 * - The quote has been signed by an address with the component role PRICER_ROLE
|
|
235
|
+
 *
|
|
236
|
+
 * Emits:
|
|
237
|
+
 * - {PolicyPool.NewPolicy}
|
|
238
|
+
 * - {NewSignedPolicy}
|
|
239
|
+
 *
|
|
240
|
+
 * @param payout The exposure (maximum payout) of the policy
|
|
241
|
+
 * @param premium The premium that will be paid by the payer
|
|
242
|
+
 * @param lossProb The probability of having to pay the maximum payout (wad)
|
|
243
|
+
 * @param expiration The expiration of the policy (timestamp)
|
|
244
|
+
 * @param onBehalfOf The policy holder
|
|
245
|
+
 * @param policyData A hash of the private details of the policy. The last 96 bits will be used as internalId
|
|
246
|
+
 * @param quoteSignatureR The signature of the quote. R component (EIP-2098 signature)
|
|
247
|
+
 * @param quoteSignatureVS The signature of the quote. VS component (EIP-2098 signature)
|
|
248
|
+
 * @param quoteValidUntil The expiration of the quote
|
|
249
|
+
 * @return Returns the id of the created policy
|
|
250
|
+
 */
|
|
186
251
|
function newPolicyPaidByHolder(
|
|
187
252
|
uint256 payout,
|
|
188
253
|
uint256 premium,
|
|
@@ -220,7 +285,7 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
220
285
|
quoteValidUntil,
|
|
221
286
|
onBehalfOf,
|
|
222
287
|
onBehalfOf
|
|
223
|
-
);
|
|
288
|
+
).id;
|
|
224
289
|
}
|
|
225
290
|
|
|
226
291
|
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
|
|
@@ -79,7 +79,57 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
79
79
|
address onBehalfOf,
|
|
80
80
|
uint96 internalId
|
|
81
81
|
) external onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
82
|
-
|
|
82
|
+
return
|
|
83
|
+
_newPolicy(
|
|
84
|
+
payout,
|
|
85
|
+
premium,
|
|
86
|
+
lossProb,
|
|
87
|
+
expiration,
|
|
88
|
+
_getPayer(onBehalfOf, premium),
|
|
89
|
+
onBehalfOf,
|
|
90
|
+
internalId
|
|
91
|
+
).id;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @dev Creates a new Policy. Version that returns all the PolicyData struct, not just the id.
|
|
96
|
+
*
|
|
97
|
+
* Requirements:
|
|
98
|
+
* - The caller has been granted componentRole(PRICER_ROLE)
|
|
99
|
+
*
|
|
100
|
+
* Emits:
|
|
101
|
+
* - {PolicyPool.NewPolicy}
|
|
102
|
+
*
|
|
103
|
+
* @param payout The exposure (maximum payout) of the policy
|
|
104
|
+
* @param premium The premium that will be paid by the policyHolder
|
|
105
|
+
* @param lossProb The probability of having to pay the maximum payout (wad)
|
|
106
|
+
* @param expiration The expiration of the policy (timestamp)
|
|
107
|
+
* @param onBehalfOf The policy holder
|
|
108
|
+
* @param internalId An id that's unique within this module and it will be used to identify the policy
|
|
109
|
+
* @return createdPolicy Returns the id of the created policy
|
|
110
|
+
*/
|
|
111
|
+
function newPolicyFull(
|
|
112
|
+
uint256 payout,
|
|
113
|
+
uint256 premium,
|
|
114
|
+
uint256 lossProb,
|
|
115
|
+
uint40 expiration,
|
|
116
|
+
address onBehalfOf,
|
|
117
|
+
uint96 internalId
|
|
118
|
+
) external onlyComponentRole(PRICER_ROLE) returns (Policy.PolicyData memory createdPolicy) {
|
|
119
|
+
return
|
|
120
|
+
_newPolicy(
|
|
121
|
+
payout,
|
|
122
|
+
premium,
|
|
123
|
+
lossProb,
|
|
124
|
+
expiration,
|
|
125
|
+
_getPayer(onBehalfOf, premium),
|
|
126
|
+
onBehalfOf,
|
|
127
|
+
internalId
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function _getPayer(address onBehalfOf, uint256 premium) internal returns (address payer) {
|
|
132
|
+
payer = onBehalfOf;
|
|
83
133
|
if (payer != _msgSender() && _policyPool.currency().allowance(payer, _msgSender()) < premium)
|
|
84
134
|
/**
|
|
85
135
|
* The standard is the payer should be the _msgSender() but usually, in this type of module,
|
|
@@ -93,8 +143,7 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
93
143
|
* premium even for multiple policies.
|
|
94
144
|
*/
|
|
95
145
|
payer = _msgSender();
|
|
96
|
-
|
|
97
|
-
return _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId).id;
|
|
146
|
+
return payer;
|
|
98
147
|
}
|
|
99
148
|
|
|
100
149
|
/**
|
|
@@ -101,12 +101,23 @@ interface IPolicyPool {
|
|
|
101
101
|
function expirePolicy(Policy.PolicyData calldata policy) external;
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
-
* @dev Returns whether
|
|
105
|
-
*
|
|
106
|
-
*
|
|
104
|
+
* @dev Returns whether a policy is active, i.e., it's still in the PolicyPool, not yet resolved or expired.
|
|
105
|
+
* Be aware that a policy might be active but the `block.timestamp` might be after the expiration date, so it
|
|
106
|
+
* can't be triggered with a payout.
|
|
107
|
+
*
|
|
108
|
+
* @param policyId The id of the policy queried
|
|
109
|
+
* @return Whether the policy is active or not
|
|
107
110
|
*/
|
|
108
111
|
function isActive(uint256 policyId) external view returns (bool);
|
|
109
112
|
|
|
113
|
+
/**
|
|
114
|
+
* @dev Returns the stored hash of the policy. It's `bytes32(0)` is the policy isn't active.
|
|
115
|
+
*
|
|
116
|
+
* @param policyId The id of the policy queried
|
|
117
|
+
* @return Returns the hash of a given policy id
|
|
118
|
+
*/
|
|
119
|
+
function getPolicyHash(uint256 policyId) external view returns (bytes32);
|
|
120
|
+
|
|
110
121
|
/**
|
|
111
122
|
* @dev Deposits liquidity into an eToken. Forwards the call to {EToken-deposit}, after transferring the funds.
|
|
112
123
|
* The user will receive etokens for the same amount deposited.
|
|
@@ -85,6 +85,10 @@ contract PolicyPoolMock is IPolicyPool {
|
|
|
85
85
|
return policyHashes[policyId] != bytes32(0);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
function getPolicyHash(uint256 policyId) external view override returns (bytes32) {
|
|
89
|
+
return policyHashes[policyId];
|
|
90
|
+
}
|
|
91
|
+
|
|
88
92
|
function deposit(IEToken, uint256) external pure override {
|
|
89
93
|
revert("Not Implemented deposit");
|
|
90
94
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ensuro/core",
|
|
3
3
|
"description": "Ensuro - Decentralized insurance protocol",
|
|
4
|
-
"version": "2.0.0-
|
|
4
|
+
"version": "2.0.0-beta13",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.sol",
|
|
7
7
|
"/build/contracts/*.json",
|
|
8
8
|
"/build/interfaces/*.json",
|
|
9
|
-
"/js/*.js"
|
|
9
|
+
"/js/*.js",
|
|
10
|
+
"/scripts/*.sh",
|
|
11
|
+
"/scripts/*.js"
|
|
10
12
|
],
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
if [ $# -ne 2 ]; then
|
|
4
|
+
echo "Usage $0 <contracts-dir> <new-pragma>"
|
|
5
|
+
exit 1
|
|
6
|
+
fi
|
|
7
|
+
|
|
8
|
+
CONTRACTS_DIR=$1
|
|
9
|
+
NEW_PRAGMA=$2
|
|
10
|
+
|
|
11
|
+
MD5S=`mktemp`
|
|
12
|
+
|
|
13
|
+
md5sum `find $CONTRACTS_DIR -name "*.sol"` > $MD5S
|
|
14
|
+
|
|
15
|
+
for SOLFILE in `find $CONTRACTS_DIR -name "*.sol"`; do
|
|
16
|
+
sed -i -r "s/^pragma solidity [0-9^~.]+;/pragma solidity $NEW_PRAGMA;/g" $SOLFILE
|
|
17
|
+
done
|
|
18
|
+
|
|
19
|
+
md5sum --check $MD5S | sed 's/: OK/: UNCHANGED/g' | sed 's/: FAILED/: MODIFIED/g' | grep -v "md5sum: "
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
source `dirname $0`/utils.sh
|
|
4
|
+
|
|
5
|
+
export DEPLOY_AMOUNT_DECIMALS=6
|
|
6
|
+
|
|
7
|
+
resetAddresses
|
|
8
|
+
|
|
9
|
+
if [ -z $ALCHEMY_URL ]; then
|
|
10
|
+
echo "Must set environment variable $ALCHEMY_URL"
|
|
11
|
+
exit 1
|
|
12
|
+
fi
|
|
13
|
+
|
|
14
|
+
startHHNode --fork $ALCHEMY_URL
|
|
15
|
+
|
|
16
|
+
USDC=0x2791bca1f2de4661ed88a30c99a7a9449aa84174
|
|
17
|
+
AAVE_ADDR_PROV=0xd05e3E715d945B59290df0ae8eF85c1BdB684744 # Polygon Aave
|
|
18
|
+
SWAP_ROUTER=0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506 # Polygon SushiSwap
|
|
19
|
+
PRICE_ORACLE=0x0229f777b0fab107f9591a41d5f02e4e98db6f2d # Polygon Price Oracle of AAVE
|
|
20
|
+
ENSURO_TREASURY=0xFDa400f51aD6490542Bc6336Ea14b2D8bf7b0c34
|
|
21
|
+
|
|
22
|
+
npx hardhat --network $NETWORK deploy $VERIFY --currency-address $USDC \
|
|
23
|
+
--treasury-address $ENSURO_TREASURY || die "Error deploying pool"
|
|
24
|
+
|
|
25
|
+
POOL=`readAddress POOL`
|
|
26
|
+
ACCESSMANAGER=`readAddress ACCESSMANAGER`
|
|
27
|
+
echo "PolicyPool = $POOL / AccessManager = $ACCESSMANAGER"
|
|
28
|
+
|
|
29
|
+
for ROLE in LEVEL1 LEVEL2 LEVEL3; do
|
|
30
|
+
npx hardhat --network $NETWORK ens:grantRole --contract-address $ACCESSMANAGER \
|
|
31
|
+
--role ${ROLE}_ROLE || die "Error granting ${ROLE}_ROLE"
|
|
32
|
+
done
|
|
33
|
+
|
|
34
|
+
npx hardhat --network $NETWORK deploy:eToken \
|
|
35
|
+
--etk-name "Junior ETK" --etk-symbol "eUSDJr" --save-addr JRETK \
|
|
36
|
+
--pool-address $POOL $VERIFY || die "Error deploying eToken"
|
|
37
|
+
|
|
38
|
+
npx hardhat --network $NETWORK deploy:eToken \
|
|
39
|
+
--etk-name "Senior ETK" --etk-symbol "eUSDSr" --save-addr SRETK \
|
|
40
|
+
--pool-address $POOL $VERIFY || die "Error deploying eToken"
|
|
41
|
+
|
|
42
|
+
JRETK=`readAddress JRETK`
|
|
43
|
+
SRETK=`readAddress SRETK`
|
|
44
|
+
|
|
45
|
+
npx hardhat --network $NETWORK deploy:premiumsAccount $VERIFY \
|
|
46
|
+
--junior-etk $JRETK --senior-etk $SRETK \
|
|
47
|
+
--pool-address $POOL || die "Error deploying PremiumsAccount"
|
|
48
|
+
|
|
49
|
+
PREMIUMS_ACCOUNT=`readAddress PA`
|
|
50
|
+
|
|
51
|
+
echo "PremiumsAccount = $PREMIUMS_ACCOUNT"
|
|
52
|
+
|
|
53
|
+
killPID $HHNODE_PID
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
source `dirname $0`/utils.sh
|
|
4
|
+
|
|
5
|
+
export DEPLOY_AMOUNT_DECIMALS=6
|
|
6
|
+
|
|
7
|
+
resetAddresses
|
|
8
|
+
|
|
9
|
+
startHHNode
|
|
10
|
+
|
|
11
|
+
ENSURO_TREASURY=0xFDa400f51aD6490542Bc6336Ea14b2D8bf7b0c34
|
|
12
|
+
|
|
13
|
+
npx hardhat --network $NETWORK deploy $VERIFY \
|
|
14
|
+
--treasury-address $ENSURO_TREASURY || die "Error deploying pool"
|
|
15
|
+
|
|
16
|
+
POOL=`readAddress POOL`
|
|
17
|
+
ACCESSMANAGER=`readAddress ACCESSMANAGER`
|
|
18
|
+
echo "PolicyPool = $POOL / AccessManager = $ACCESSMANAGER"
|
|
19
|
+
|
|
20
|
+
for ROLE in LEVEL1 LEVEL2 LEVEL3; do
|
|
21
|
+
npx hardhat --network $NETWORK ens:grantRole --contract-address $ACCESSMANAGER \
|
|
22
|
+
--role ${ROLE}_ROLE || die "Error granting ${ROLE}_ROLE"
|
|
23
|
+
done
|
|
24
|
+
|
|
25
|
+
npx hardhat --network $NETWORK deploy:eToken \
|
|
26
|
+
--etk-name "Junior ETK" --etk-symbol "eUSDJr" --save-addr JRETK \
|
|
27
|
+
--pool-address $POOL $VERIFY || die "Error deploying eToken"
|
|
28
|
+
|
|
29
|
+
npx hardhat --network $NETWORK deploy:eToken \
|
|
30
|
+
--etk-name "Senior ETK" --etk-symbol "eUSDSr" --save-addr SRETK \
|
|
31
|
+
--pool-address $POOL $VERIFY || die "Error deploying eToken"
|
|
32
|
+
|
|
33
|
+
JRETK=`readAddress JRETK`
|
|
34
|
+
SRETK=`readAddress SRETK`
|
|
35
|
+
|
|
36
|
+
npx hardhat --network $NETWORK deploy:premiumsAccount $VERIFY --pool-address $POOL \
|
|
37
|
+
--junior-etk $JRETK --senior-etk $SRETK || die "Error deploying Premiums Account"
|
|
38
|
+
|
|
39
|
+
PREMIUMS_ACCOUNT=`readAddress PA`
|
|
40
|
+
|
|
41
|
+
echo "PremiumsAccount = $PREMIUMS_ACCOUNT"
|
|
42
|
+
|
|
43
|
+
npx hardhat --network $NETWORK deploy:riskModule $VERIFY --pool-address $POOL \
|
|
44
|
+
--pa-address $PREMIUMS_ACCOUNT \
|
|
45
|
+
--wallet 0x951B9B8a7b0e3701E757c015F43df9F2F867B824 || die "Error deploying riskModule"
|
|
46
|
+
|
|
47
|
+
# Whitelist
|
|
48
|
+
npx hardhat --network $NETWORK deploy:whitelist $VERIFY \
|
|
49
|
+
--pool-address $POOL --e-token $SRETK || die "Error deploying Whitelist"
|
|
50
|
+
|
|
51
|
+
killPID $HHNODE_PID
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const hre = require("hardhat");
|
|
2
|
+
const { artifacts } = require("hardhat");
|
|
3
|
+
const { findAll } = require("solidity-ast/utils");
|
|
4
|
+
const { getStorageLayout } = require("../test/test-utils");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Script to print a contracts storage layout as a table.
|
|
8
|
+
*
|
|
9
|
+
* Example usage: node scripts/storageLayout.js EToken
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
//
|
|
13
|
+
|
|
14
|
+
async function main(contractSrc, contractName) {
|
|
15
|
+
await hre.run("compile");
|
|
16
|
+
const layout = await getStorageLayout(contractSrc, contractName);
|
|
17
|
+
|
|
18
|
+
const summary = layout.storage.map((item) => ({
|
|
19
|
+
slot: parseInt(item.slot),
|
|
20
|
+
label: item.label,
|
|
21
|
+
type: item.type,
|
|
22
|
+
numberOfBytes: parseInt(layout.types[item.type].numberOfBytes),
|
|
23
|
+
endSlot: parseInt(item.slot) + Math.floor(parseInt(layout.types[item.type].numberOfBytes) / 32),
|
|
24
|
+
}));
|
|
25
|
+
console.table(summary);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const [contractSrc, contractName] = [`contracts/${process.argv[2]}.sol`, process.argv[2]];
|
|
29
|
+
|
|
30
|
+
console.log(`Storage layout for ${contractSrc}:${contractName}`);
|
|
31
|
+
main(contractSrc, contractName).then(() => {
|
|
32
|
+
process.exit(0);
|
|
33
|
+
});
|
package/scripts/utils.sh
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
die() {
|
|
2
|
+
printf "ERROR: %s\n" "$*"
|
|
3
|
+
exit 1
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
dieOnError() {
|
|
7
|
+
if [ $? -ne 0 ]; then
|
|
8
|
+
die $1
|
|
9
|
+
fi
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export DEPLOY_AMOUNT_DECIMALS=6
|
|
13
|
+
|
|
14
|
+
NETWORK=${NETWORK:-localhost}
|
|
15
|
+
|
|
16
|
+
startHHNode() {
|
|
17
|
+
if [ $NETWORK == "localhost" ]; then
|
|
18
|
+
HHNODE_RUNNING=`ps aux | grep "/.bin/hardhat node" | grep -v grep | cut -c10-15`
|
|
19
|
+
if [ -z $HHNODE_RUNNING ]; then
|
|
20
|
+
START_HHNODE=1
|
|
21
|
+
fi
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
if [ ! -z $START_HHNODE ]; then
|
|
25
|
+
echo "Starting hardhat node"
|
|
26
|
+
# npx hardhat node $* >/dev/null &
|
|
27
|
+
node_modules/.bin/hardhat node $* >/dev/null &
|
|
28
|
+
|
|
29
|
+
HHNODE_PID=$!
|
|
30
|
+
sleep 5
|
|
31
|
+
kill -0 $HHNODE_PID || die "Error launching hardhat node localhost"
|
|
32
|
+
fi
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
readAddress() {
|
|
36
|
+
python -c "import json; print(json.load(open('.addresses.json'))['$1'])"
|
|
37
|
+
exit $?
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
resetAddresses() {
|
|
41
|
+
python -c "open('.addresses.json', 'wt').write('{}')"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
killPID() {
|
|
45
|
+
if [ ! -z $1 ]; then
|
|
46
|
+
kill $1
|
|
47
|
+
fi
|
|
48
|
+
}
|