@ensuro/core 2.8.2 → 2.9.0

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.
Files changed (46) hide show
  1. package/README.md +2 -3
  2. package/build/contracts/AccessManager.sol/AccessManager.json +2 -15
  3. package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +2 -2
  4. package/build/contracts/ERC4626PlusVaultAssetManager.sol/ERC4626PlusVaultAssetManager.json +269 -0
  5. package/build/contracts/EToken.sol/EToken.json +7 -85
  6. package/build/contracts/FullSignedBucketRiskModule.sol/FullSignedBucketRiskModule.json +1484 -0
  7. package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +7 -85
  8. package/build/contracts/Policy.sol/Policy.json +2 -2
  9. package/build/contracts/PolicyPool.sol/PolicyPool.json +2 -15
  10. package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +5 -83
  11. package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +7 -85
  12. package/build/contracts/Reserve.sol/Reserve.json +5 -83
  13. package/build/contracts/RiskModule.sol/RiskModule.json +5 -96
  14. package/build/contracts/SignedBucketRiskModule.sol/SignedBucketRiskModule.json +7 -150
  15. package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +7 -98
  16. package/build/contracts/TimeScaled.sol/TimeScaled.json +2 -2
  17. package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +7 -98
  18. package/build/contracts/dependencies/WadRayMath.sol/WadRayMath.json +2 -2
  19. package/build/contracts/migration/LPManualWhitelistV20.sol/LPManualWhitelistV20.json +5 -83
  20. package/build/contracts/migration/LPManualWhitelistV20Upgraded.sol/LPManualWhitelistV20Upgraded.json +7 -85
  21. package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +2 -2
  22. package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +2 -2
  23. package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +2 -2
  24. package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +2 -2
  25. package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +2 -2
  26. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +2 -2
  27. package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +2 -2
  28. package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +7 -98
  29. package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +2 -2
  30. package/build/contracts/mocks/TestNFT.sol/TestNFT.json +2 -2
  31. package/contracts/AccessManager.sol +0 -1
  32. package/contracts/ERC4626AssetManager.sol +6 -5
  33. package/contracts/ERC4626PlusVaultAssetManager.sol +105 -0
  34. package/contracts/EToken.sol +2 -20
  35. package/contracts/FullSignedBucketRiskModule.sol +204 -0
  36. package/contracts/PolicyPool.sol +0 -1
  37. package/contracts/PolicyPoolComponent.sol +7 -44
  38. package/contracts/PremiumsAccount.sol +3 -3
  39. package/contracts/RiskModule.sol +10 -21
  40. package/contracts/SignedBucketRiskModule.sol +15 -9
  41. package/contracts/SignedQuoteRiskModule.sol +7 -4
  42. package/js/test-utils.js +1 -2
  43. package/js/utils.js +65 -0
  44. package/package.json +1 -1
  45. package/scripts/deploySmokeTest-fork.sh +1 -1
  46. package/scripts/deploySmokeTest.sh +1 -1
@@ -30,7 +30,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
30
30
  uint16 internal constant MAX_MOC = 4e4; // 400%
31
31
 
32
32
  // For parameters that can be changed by the risk module provider
33
- bytes32 public constant RM_PROVIDER_ROLE = keccak256("RM_PROVIDER_ROLE");
33
+ bytes32 internal constant RM_PROVIDER_ROLE = keccak256("RM_PROVIDER_ROLE");
34
34
 
35
35
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
36
36
  IPremiumsAccount internal immutable _premiumsAccount;
@@ -206,48 +206,33 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
206
206
  return _wallet;
207
207
  }
208
208
 
209
- function setParam(
210
- Parameter param,
211
- uint256 newValue
212
- ) external onlyGlobalOrComponentRole3(LEVEL1_ROLE, LEVEL2_ROLE, LEVEL3_ROLE) {
213
- bool tweak = !hasPoolRole(LEVEL2_ROLE) && !hasPoolRole(LEVEL1_ROLE);
209
+ function setParam(Parameter param, uint256 newValue) external onlyGlobalOrComponentRole2(LEVEL1_ROLE, LEVEL2_ROLE) {
214
210
  if (param == Parameter.moc) {
215
- require(!tweak || _isTweakWad(_4toWad(_params.moc), newValue, 1e17), "Tweak exceeded");
216
211
  _params.moc = _wadTo4(newValue);
217
212
  } else if (param == Parameter.jrCollRatio) {
218
- require(!tweak || _isTweakWad(_4toWad(_params.jrCollRatio), newValue, 1e17), "Tweak exceeded");
219
213
  _params.jrCollRatio = _wadTo4(newValue);
220
214
  } else if (param == Parameter.collRatio) {
221
- require(!tweak || _isTweakWad(_4toWad(_params.collRatio), newValue, 1e17), "Tweak exceeded");
222
215
  _params.collRatio = _wadTo4(newValue);
223
216
  } else if (param == Parameter.ensuroPpFee) {
224
- require(!tweak || _isTweakWad(_4toWad(_params.ensuroPpFee), newValue, 1e17), "Tweak exceeded");
225
217
  _params.ensuroPpFee = _wadTo4(newValue);
226
218
  } else if (param == Parameter.ensuroCocFee) {
227
- require(!tweak || _isTweakWad(_4toWad(_params.ensuroCocFee), newValue, 1e17), "Tweak exceeded");
228
219
  _params.ensuroCocFee = _wadTo4(newValue);
229
220
  } else if (param == Parameter.jrRoc) {
230
- require(!tweak || _isTweakWad(_4toWad(_params.jrRoc), newValue, 1e17), "Tweak exceeded");
231
221
  _params.jrRoc = _wadTo4(newValue);
232
222
  } else if (param == Parameter.srRoc) {
233
- require(!tweak || _isTweakWad(_4toWad(_params.srRoc), newValue, 1e17), "Tweak exceeded");
234
223
  _params.srRoc = _wadTo4(newValue);
235
224
  } else if (param == Parameter.maxPayoutPerPolicy) {
236
- require(!tweak || _isTweakWad(maxPayoutPerPolicy(), newValue, 1e17), "Tweak exceeded");
237
225
  _params.maxPayoutPerPolicy = _amountToX(2, newValue);
238
226
  } else if (param == Parameter.exposureLimit) {
239
227
  require(newValue >= _activeExposure, "Can't set exposureLimit less than active exposure");
240
- require(!tweak || _isTweakWad(exposureLimit(), newValue, 1e17), "Tweak exceeded");
241
- require(newValue <= exposureLimit() || hasPoolRole(LEVEL1_ROLE), "Tweak exceeded: Increase requires LEVEL1_ROLE");
228
+ require(newValue <= exposureLimit() || hasPoolRole(LEVEL1_ROLE), "Increase requires LEVEL1_ROLE");
242
229
  _params.exposureLimit = _amountToX(0, newValue);
243
230
  } else if (param == Parameter.maxDuration) {
244
- require(!tweak, "Tweak exceeded");
245
231
  _params.maxDuration = newValue.toUint16();
246
232
  }
247
233
  _parameterChanged(
248
234
  IAccessManager.GovernanceActions(uint256(IAccessManager.GovernanceActions.setMoc) + uint256(param)),
249
- newValue,
250
- tweak
235
+ newValue
251
236
  );
252
237
  }
253
238
 
@@ -255,7 +240,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
255
240
  return _unpackParams(_params);
256
241
  }
257
242
 
258
- function _unpackParams(PackedParams storage params_) internal view returns (Params memory ret) {
243
+ function _unpackParams(PackedParams memory params_) internal pure returns (Params memory ret) {
259
244
  return
260
245
  Params({
261
246
  moc: _4toWad(params_.moc),
@@ -268,12 +253,16 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
268
253
  });
269
254
  }
270
255
 
256
+ function _makeInternalId(bytes32 policyData) internal pure returns (uint96) {
257
+ return uint96(uint256(policyData) % 2 ** 96);
258
+ }
259
+
271
260
  function setWallet(address wallet_) external onlyComponentRole(RM_PROVIDER_ROLE) {
272
261
  if (wallet_ == address(0)) {
273
262
  revert NoZeroWallet();
274
263
  }
275
264
  _wallet = wallet_;
276
- _parameterChanged(IAccessManager.GovernanceActions.setWallet, uint256(uint160(wallet_)), false);
265
+ _parameterChanged(IAccessManager.GovernanceActions.setWallet, uint256(uint160(wallet_)));
277
266
  }
278
267
 
279
268
  function getMinimumPremium(
@@ -18,10 +18,10 @@ import {RiskModule} from "./RiskModule.sol";
18
18
  * @author Ensuro
19
19
  */
20
20
  contract SignedBucketRiskModule is RiskModule {
21
- bytes32 public constant POLICY_CREATOR_ROLE = keccak256("POLICY_CREATOR_ROLE");
22
- bytes32 public constant REPLACER_ROLE = keccak256("REPLACER_ROLE");
23
- bytes32 public constant PRICER_ROLE = keccak256("PRICER_ROLE");
24
- bytes32 public constant RESOLVER_ROLE = keccak256("RESOLVER_ROLE");
21
+ bytes32 internal constant POLICY_CREATOR_ROLE = keccak256("POLICY_CREATOR_ROLE");
22
+ bytes32 internal constant REPLACER_ROLE = keccak256("REPLACER_ROLE");
23
+ bytes32 internal constant PRICER_ROLE = keccak256("PRICER_ROLE");
24
+ bytes32 internal constant RESOLVER_ROLE = keccak256("RESOLVER_ROLE");
25
25
 
26
26
  mapping(uint256 => PackedParams) internal _buckets;
27
27
 
@@ -114,7 +114,6 @@ contract SignedBucketRiskModule is RiskModule {
114
114
  address payer,
115
115
  address onBehalfOf
116
116
  ) internal returns (Policy.PolicyData memory createdPolicy) {
117
- uint96 internalId = uint96(uint256(policyData) % 2 ** 96);
118
117
  createdPolicy = _newPolicyWithParams(
119
118
  payout,
120
119
  premium,
@@ -122,7 +121,7 @@ contract SignedBucketRiskModule is RiskModule {
122
121
  expiration,
123
122
  payer,
124
123
  onBehalfOf,
125
- internalId,
124
+ _makeInternalId(policyData),
126
125
  bucketParams(bucketId)
127
126
  );
128
127
  emit NewSignedPolicy(createdPolicy.id, policyData);
@@ -225,10 +224,17 @@ contract SignedBucketRiskModule is RiskModule {
225
224
  quoteSignatureVS,
226
225
  quoteValidUntil
227
226
  );
228
- uint96 internalId = uint96(uint256(policyData) % 2 ** 96);
229
227
  return
230
- _replacePolicy(oldPolicy, payout, premium, lossProb, expiration, _msgSender(), internalId, bucketParams(bucketId))
231
- .id;
228
+ _replacePolicy(
229
+ oldPolicy,
230
+ payout,
231
+ premium,
232
+ lossProb,
233
+ expiration,
234
+ _msgSender(),
235
+ _makeInternalId(policyData),
236
+ bucketParams(bucketId)
237
+ ).id;
232
238
  }
233
239
 
234
240
  function resolvePolicy(
@@ -91,11 +91,14 @@ contract SignedQuoteRiskModule is RiskModule {
91
91
  bytes32 quoteHash = ECDSA.toEthSignedMessageHash(
92
92
  abi.encodePacked(address(this), payout, premium, lossProb, expiration, policyData, quoteValidUntil)
93
93
  );
94
- address signer = ECDSA.recover(quoteHash, quoteSignatureR, quoteSignatureVS);
95
- _policyPool.access().checkComponentRole(address(this), PRICER_ROLE, signer, false);
96
- uint96 internalId = uint96(uint256(policyData) % 2 ** 96);
94
+ _policyPool.access().checkComponentRole(
95
+ address(this),
96
+ PRICER_ROLE,
97
+ ECDSA.recover(quoteHash, quoteSignatureR, quoteSignatureVS),
98
+ false
99
+ );
97
100
 
98
- createdPolicy = _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId);
101
+ createdPolicy = _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, _makeInternalId(policyData));
99
102
  emit NewSignedPolicy(createdPolicy.id, policyData);
100
103
  return createdPolicy;
101
104
  }
package/js/test-utils.js CHANGED
@@ -227,7 +227,6 @@ async function deployPool(options) {
227
227
  if (options.dontGrantL123Roles === undefined) {
228
228
  await grantRole(hre, accessManager, "LEVEL1_ROLE");
229
229
  await grantRole(hre, accessManager, "LEVEL2_ROLE");
230
- await grantRole(hre, accessManager, "LEVEL3_ROLE");
231
230
  }
232
231
 
233
232
  return policyPool;
@@ -304,7 +303,7 @@ const fork = {
304
303
  },
305
304
  };
306
305
 
307
- if (process.env.ENABLE_HH_WARNINGS !== "yes") hre.upgrades.silenceWarnings();
306
+ if (process.env.ENABLE_HH_WARNINGS !== "yes" && hre.upgrades !== undefined) hre.upgrades.silenceWarnings();
308
307
 
309
308
  module.exports = {
310
309
  addEToken,
package/js/utils.js CHANGED
@@ -203,6 +203,31 @@ function makeQuoteMessage({ rmAddress, payout, premium, lossProb, expiration, po
203
203
  );
204
204
  }
205
205
 
206
+ function paramsAsUint256(params) {
207
+ /* eslint no-bitwise: "off" */
208
+ return (
209
+ (params.moc << 240n) |
210
+ (params.jrCollRatio << 224n) |
211
+ (params.collRatio << 208n) |
212
+ (params.ensuroPpFee << 192n) |
213
+ (params.ensuroCocFee << 176n) |
214
+ (params.jrRoc << 160n) |
215
+ (params.srRoc << 144n)
216
+ );
217
+ }
218
+
219
+ /**
220
+ * Create a packed quote message for later signing or hashing.
221
+ *
222
+ * Mimics the behaviour of the FullSignedBucketRiskModule._checkFullSignature method.
223
+ */
224
+ function makeFullQuoteMessage({ rmAddress, payout, premium, lossProb, expiration, policyData, params, validUntil }) {
225
+ return ethers.solidityPacked(
226
+ ["address", "uint256", "uint256", "uint256", "uint40", "bytes32", "uint256", "uint40"],
227
+ [rmAddress, payout, premium, lossProb, expiration, policyData, paramsAsUint256(params), validUntil]
228
+ );
229
+ }
230
+
206
231
  /**
207
232
  * Create a packed quote message for later signing or hashing.
208
233
  *
@@ -263,6 +288,42 @@ async function defaultPolicyParams(
263
288
  };
264
289
  }
265
290
 
291
+ async function defaultPolicyParamsWithBucket(opts, _A = amountFunction(6)) {
292
+ const ret = await defaultPolicyParams(opts, _A);
293
+ return { bucketId: opts.bucketId || 0, ...ret };
294
+ }
295
+
296
+ async function defaultPolicyParamsWithParams(opts, _A = amountFunction(6)) {
297
+ const ret = await defaultPolicyParams(opts, _A);
298
+ // struct PackedParams {
299
+ // uint16 moc; // Margin Of Conservativism - factor that multiplies lossProb - 4 decimals
300
+ // uint16 jrCollRatio; // Collateralization Ratio to compute Junior solvency as % of payout - 4 decimals
301
+ // uint16 collRatio; // Collateralization Ratio to compute solvency requirement as % of payout - 4 decimals
302
+ // uint16 ensuroPpFee; // % of pure premium that will go for Ensuro treasury - 4 decimals
303
+ // uint16 ensuroCocFee; // % of CoC that will go for Ensuro treasury - 4 decimals
304
+ // uint16 jrRoc; // Return on Capital paid to Junior LPs - Annualized Percentage - 4 decimals
305
+ // uint16 srRoc; // Return on Capital paid to Senior LPs - Annualized Percentage - 4 decimals
306
+ // uint32 maxPayoutPerPolicy; // Max Payout per Policy - 2 decimals
307
+ // uint32 exposureLimit; // Max exposure (sum of payouts) to be allocated to this module - 0 decimals
308
+ // uint16 maxDuration; // Max policy duration (in hours)
309
+ // }
310
+ const optsParams = opts.params || {};
311
+ const wadTo4Decimals = 10n ** 14n;
312
+ const params = {
313
+ moc: (optsParams.moc || _W(1)) / wadTo4Decimals,
314
+ jrCollRatio: (optsParams.jrCollRatio || 0n) / wadTo4Decimals,
315
+ collRatio: (optsParams.collRatio || _W(1)) / wadTo4Decimals,
316
+ ensuroPpFee: (optsParams.ensuroPpFee || 0n) / wadTo4Decimals,
317
+ ensuroCocFee: (optsParams.ensuroCocFee || 0n) / wadTo4Decimals,
318
+ jrRoc: (optsParams.jrRoc || 0n) / wadTo4Decimals,
319
+ srRoc: (optsParams.srRoc || _W("0.1")) / wadTo4Decimals, // 10%
320
+ maxPayoutPerPolicy: 0n, // Not used
321
+ exposureLimit: 0n, // Not used
322
+ maxDuration: 0n, // Not used
323
+ };
324
+ return { params, ...ret };
325
+ }
326
+
266
327
  function defaultBucketParams({ moc, jrCollRatio, collRatio, ensuroPpFee, ensuroCocFee, jrRoc, srRoc }) {
267
328
  return {
268
329
  moc: moc !== undefined ? moc : _W("1.1"),
@@ -299,6 +360,8 @@ module.exports = {
299
360
  accessControlMessage,
300
361
  amountFunction,
301
362
  defaultPolicyParams,
363
+ defaultPolicyParamsWithBucket,
364
+ defaultPolicyParamsWithParams,
302
365
  defaultBucketParams,
303
366
  getAddress,
304
367
  getComponentRole,
@@ -309,6 +372,8 @@ module.exports = {
309
372
  grantComponentRole,
310
373
  grantRole,
311
374
  makeBucketQuoteMessage,
375
+ makeFullQuoteMessage,
376
+ paramsAsUint256,
312
377
  makePolicyId,
313
378
  makeQuoteMessage,
314
379
  makeSignedQuote,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ensuro/core",
3
3
  "description": "Ensuro - Decentralized insurance protocol",
4
- "version": "2.8.2",
4
+ "version": "2.9.0",
5
5
  "files": [
6
6
  "**/*.sol",
7
7
  "/build",
@@ -26,7 +26,7 @@ POOL=`readAddress POOL`
26
26
  ACCESSMANAGER=`readAddress ACCESSMANAGER`
27
27
  echo "PolicyPool = $POOL / AccessManager = $ACCESSMANAGER"
28
28
 
29
- for ROLE in LEVEL1 LEVEL2 LEVEL3; do
29
+ for ROLE in LEVEL1 LEVEL2; do
30
30
  npx hardhat --network $NETWORK ens:grantRole --contract-address $ACCESSMANAGER \
31
31
  --role ${ROLE}_ROLE || die "Error granting ${ROLE}_ROLE"
32
32
  done
@@ -17,7 +17,7 @@ POOL=`readAddress POOL`
17
17
  ACCESSMANAGER=`readAddress ACCESSMANAGER`
18
18
  echo "PolicyPool = $POOL / AccessManager = $ACCESSMANAGER"
19
19
 
20
- for ROLE in LEVEL1 LEVEL2 LEVEL3; do
20
+ for ROLE in LEVEL1 LEVEL2; do
21
21
  npx hardhat --network $NETWORK ens:grantRole --contract-address $ACCESSMANAGER \
22
22
  --role ${ROLE}_ROLE || die "Error granting ${ROLE}_ROLE"
23
23
  done