@ensuro/core 2.6.2 → 2.8.0-beta1
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/README.md +11 -5
- package/contracts/AccessManager.sol +3 -13
- package/contracts/EToken.sol +29 -95
- package/contracts/LPManualWhitelist.sol +11 -26
- package/contracts/LiquidityThresholdAssetManager.sol +10 -21
- package/contracts/Policy.sol +6 -17
- package/contracts/PolicyPool.sol +39 -91
- package/contracts/PolicyPoolComponent.sol +9 -32
- package/contracts/PremiumsAccount.sol +16 -47
- package/contracts/Reserve.sol +10 -16
- package/contracts/RiskModule.sol +22 -80
- package/contracts/SignedBucketRiskModule.sol +18 -80
- package/contracts/SignedQuoteRiskModule.sol +13 -44
- package/contracts/TieredSignedQuoteRiskModule.sol +7 -13
- package/contracts/TimeScaled.sol +8 -39
- package/contracts/TrustfulRiskModule.sol +13 -48
- package/contracts/interfaces/IAccessManager.sol +2 -11
- package/contracts/interfaces/IEToken.sol +1 -5
- package/contracts/interfaces/ILPWhitelist.sol +2 -10
- package/contracts/interfaces/IPolicyHolder.sol +2 -11
- package/contracts/interfaces/IPremiumsAccount.sol +1 -5
- package/contracts/migration/LPManualWhitelistV20.sol +3 -15
- package/contracts/migration/LPManualWhitelistV20Upgraded.sol +1 -5
- package/contracts/mocks/FixedRateVault.sol +1 -6
- package/contracts/mocks/PolicyHolderMock.sol +73 -29
- package/contracts/mocks/PolicyPoolComponentMock.sol +1 -3
- package/contracts/mocks/PolicyPoolMock.sol +8 -28
- package/contracts/mocks/RiskModuleMock.sol +3 -16
- package/contracts/mocks/TestNFT.sol +1 -1
- package/js/constants.js +8 -2
- package/js/deploy.js +65 -62
- package/js/enums.js +26 -8
- package/js/test-utils.js +105 -23
- package/js/utils.js +78 -28
- package/package.json +1 -1
- package/scripts/utils.sh +23 -12
- package/build/contracts/AccessManager.sol/AccessManager.json +0 -618
- package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +0 -238
- package/build/contracts/EToken.sol/EToken.json +0 -1277
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +0 -647
- package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +0 -222
- package/build/contracts/Policy.sol/Policy.json +0 -10
- package/build/contracts/PolicyPool.sol/PolicyPool.json +0 -1416
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +0 -332
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +0 -970
- package/build/contracts/Reserve.sol/Reserve.json +0 -403
- package/build/contracts/RiskModule.sol/RiskModule.json +0 -559
- package/build/contracts/SignedBucketRiskModule.sol/SignedBucketRiskModule.json +0 -1262
- package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +0 -1110
- package/build/contracts/TieredSignedQuoteRiskModule.sol/TieredSignedQuoteRiskModule.json +0 -1316
- package/build/contracts/TimeScaled.sol/TimeScaled.json +0 -10
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +0 -984
- package/build/contracts/dependencies/ERC1967Proxy.sol/ERC1967Proxy.json +0 -64
- package/build/contracts/dependencies/IERC20Metadata.sol/IERC20Metadata.json +0 -233
- package/build/contracts/dependencies/WadRayMath.sol/WadRayMath.json +0 -10
- package/build/contracts/interfaces/IAccessManager.sol/IAccessManager.json +0 -343
- package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +0 -128
- package/build/contracts/interfaces/IEToken.sol/IEToken.json +0 -460
- package/build/contracts/interfaces/ILPWhitelist.sol/ILPWhitelist.json +0 -103
- package/build/contracts/interfaces/IPolicyHolder.sol/IPolicyHolder.json +0 -108
- package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +0 -501
- package/build/contracts/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +0 -43
- package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +0 -315
- package/build/contracts/interfaces/IRiskModule.sol/IRiskModule.json +0 -165
- package/build/contracts/migration/LPManualWhitelistV20.sol/LPManualWhitelistV20.json +0 -481
- package/build/contracts/migration/LPManualWhitelistV20Upgraded.sol/LPManualWhitelistV20Upgraded.json +0 -492
- package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +0 -736
- package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +0 -43
- package/build/contracts/mocks/IMintableERC20.sol/IMintableERC20.json +0 -47
- package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +0 -180
- package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +0 -228
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +0 -54
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +0 -721
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +0 -92
- package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +0 -783
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +0 -343
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +0 -388
- package/contracts/dependencies/ERC1967Proxy.sol +0 -19
- package/contracts/dependencies/IERC20Metadata.sol +0 -19
package/contracts/RiskModule.sol
CHANGED
|
@@ -57,9 +57,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
57
57
|
address internal _wallet; // Address of the RiskModule provider
|
|
58
58
|
|
|
59
59
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
60
|
-
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
|
|
61
|
-
PolicyPoolComponent(policyPool_)
|
|
62
|
-
{
|
|
60
|
+
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_) PolicyPoolComponent(policyPool_) {
|
|
63
61
|
require(
|
|
64
62
|
PolicyPoolComponent(address(premiumsAccount_)).policyPool() == policyPool_,
|
|
65
63
|
"The PremiumsAccount must be part of the Pool"
|
|
@@ -88,15 +86,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
88
86
|
address wallet_
|
|
89
87
|
) internal onlyInitializing {
|
|
90
88
|
__PolicyPoolComponent_init();
|
|
91
|
-
__RiskModule_init_unchained(
|
|
92
|
-
name_,
|
|
93
|
-
collRatio_,
|
|
94
|
-
ensuroPpFee_,
|
|
95
|
-
srRoc_,
|
|
96
|
-
maxPayoutPerPolicy_,
|
|
97
|
-
exposureLimit_,
|
|
98
|
-
wallet_
|
|
99
|
-
);
|
|
89
|
+
__RiskModule_init_unchained(name_, collRatio_, ensuroPpFee_, srRoc_, maxPayoutPerPolicy_, exposureLimit_, wallet_);
|
|
100
90
|
}
|
|
101
91
|
|
|
102
92
|
// solhint-disable-next-line func-name-mixedcase
|
|
@@ -130,10 +120,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
130
120
|
function _upgradeValidations(address newImpl) internal view virtual override {
|
|
131
121
|
super._upgradeValidations(newImpl);
|
|
132
122
|
IRiskModule newRM = IRiskModule(newImpl);
|
|
133
|
-
require(
|
|
134
|
-
newRM.premiumsAccount() == _premiumsAccount,
|
|
135
|
-
"Can't upgrade changing the PremiumsAccount"
|
|
136
|
-
);
|
|
123
|
+
require(newRM.premiumsAccount() == _premiumsAccount, "Can't upgrade changing the PremiumsAccount");
|
|
137
124
|
}
|
|
138
125
|
|
|
139
126
|
/**
|
|
@@ -146,30 +133,21 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
146
133
|
// runs validation on RiskModule parameters
|
|
147
134
|
function _validateParameters() internal view virtual override {
|
|
148
135
|
// _maxPayoutPerPolicy no limits
|
|
149
|
-
require(
|
|
150
|
-
exposureLimit() >= _activeExposure,
|
|
151
|
-
"Validation: exposureLimit can't be less than actual activeExposure"
|
|
152
|
-
);
|
|
136
|
+
require(exposureLimit() >= _activeExposure, "Validation: exposureLimit can't be less than actual activeExposure");
|
|
153
137
|
require(_wallet != address(0), "Validation: Wallet can't be zero address");
|
|
154
138
|
_validatePackedParams(_params);
|
|
155
139
|
}
|
|
156
140
|
|
|
157
141
|
function _validatePackedParams(PackedParams storage params_) internal view {
|
|
158
142
|
require(params_.jrCollRatio <= HUNDRED_PERCENT, "Validation: jrCollRatio must be <=1");
|
|
159
|
-
require(
|
|
160
|
-
params_.collRatio <= HUNDRED_PERCENT && params_.collRatio > 0,
|
|
161
|
-
"Validation: collRatio must be <=1"
|
|
162
|
-
);
|
|
143
|
+
require(params_.collRatio <= HUNDRED_PERCENT && params_.collRatio > 0, "Validation: collRatio must be <=1");
|
|
163
144
|
require(params_.collRatio >= params_.jrCollRatio, "Validation: collRatio >= jrCollRatio");
|
|
164
145
|
require(params_.moc <= MAX_MOC && params_.moc >= MIN_MOC, "Validation: moc must be [0.5, 4]");
|
|
165
146
|
require(params_.ensuroPpFee <= HUNDRED_PERCENT, "Validation: ensuroPpFee must be <= 1");
|
|
166
147
|
require(params_.ensuroCocFee <= HUNDRED_PERCENT, "Validation: ensuroCocFee must be <= 1");
|
|
167
148
|
require(params_.srRoc <= HUNDRED_PERCENT, "Validation: srRoc must be <= 1 (100%)");
|
|
168
149
|
require(params_.jrRoc <= HUNDRED_PERCENT, "Validation: jrRoc must be <= 1 (100%)");
|
|
169
|
-
require(
|
|
170
|
-
params_.exposureLimit > 0 && params_.maxPayoutPerPolicy > 0,
|
|
171
|
-
"Exposure and MaxPayout must be >0"
|
|
172
|
-
);
|
|
150
|
+
require(params_.exposureLimit > 0 && params_.maxPayoutPerPolicy > 0, "Exposure and MaxPayout must be >0");
|
|
173
151
|
}
|
|
174
152
|
|
|
175
153
|
function name() public view override returns (string memory) {
|
|
@@ -190,12 +168,12 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
190
168
|
// solhint-disable-next-line func-name-mixedcase
|
|
191
169
|
function _XtoAmount(uint8 decimals, uint32 value) internal view returns (uint256) {
|
|
192
170
|
// X decimals to currency decimals (6 for USDC)
|
|
193
|
-
return uint256(value) * 10**(currency().decimals() - decimals);
|
|
171
|
+
return uint256(value) * 10 ** (currency().decimals() - decimals);
|
|
194
172
|
}
|
|
195
173
|
|
|
196
174
|
function _amountToX(uint8 decimals, uint256 value) internal view returns (uint32) {
|
|
197
175
|
// currency decimals to X decimals (assuming X < currency decimals)
|
|
198
|
-
return (value / 10**(currency().decimals() - decimals)).toUint32();
|
|
176
|
+
return (value / 10 ** (currency().decimals() - decimals)).toUint32();
|
|
199
177
|
}
|
|
200
178
|
|
|
201
179
|
function maxPayoutPerPolicy() public view override returns (uint256) {
|
|
@@ -218,34 +196,25 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
218
196
|
return _wallet;
|
|
219
197
|
}
|
|
220
198
|
|
|
221
|
-
function setParam(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
{
|
|
199
|
+
function setParam(
|
|
200
|
+
Parameter param,
|
|
201
|
+
uint256 newValue
|
|
202
|
+
) external onlyGlobalOrComponentRole3(LEVEL1_ROLE, LEVEL2_ROLE, LEVEL3_ROLE) {
|
|
225
203
|
bool tweak = !hasPoolRole(LEVEL2_ROLE) && !hasPoolRole(LEVEL1_ROLE);
|
|
226
204
|
if (param == Parameter.moc) {
|
|
227
205
|
require(!tweak || _isTweakWad(_4toWad(_params.moc), newValue, 1e17), "Tweak exceeded");
|
|
228
206
|
_params.moc = _wadTo4(newValue);
|
|
229
207
|
} else if (param == Parameter.jrCollRatio) {
|
|
230
|
-
require(
|
|
231
|
-
!tweak || _isTweakWad(_4toWad(_params.jrCollRatio), newValue, 1e17),
|
|
232
|
-
"Tweak exceeded"
|
|
233
|
-
);
|
|
208
|
+
require(!tweak || _isTweakWad(_4toWad(_params.jrCollRatio), newValue, 1e17), "Tweak exceeded");
|
|
234
209
|
_params.jrCollRatio = _wadTo4(newValue);
|
|
235
210
|
} else if (param == Parameter.collRatio) {
|
|
236
211
|
require(!tweak || _isTweakWad(_4toWad(_params.collRatio), newValue, 1e17), "Tweak exceeded");
|
|
237
212
|
_params.collRatio = _wadTo4(newValue);
|
|
238
213
|
} else if (param == Parameter.ensuroPpFee) {
|
|
239
|
-
require(
|
|
240
|
-
!tweak || _isTweakWad(_4toWad(_params.ensuroPpFee), newValue, 1e17),
|
|
241
|
-
"Tweak exceeded"
|
|
242
|
-
);
|
|
214
|
+
require(!tweak || _isTweakWad(_4toWad(_params.ensuroPpFee), newValue, 1e17), "Tweak exceeded");
|
|
243
215
|
_params.ensuroPpFee = _wadTo4(newValue);
|
|
244
216
|
} else if (param == Parameter.ensuroCocFee) {
|
|
245
|
-
require(
|
|
246
|
-
!tweak || _isTweakWad(_4toWad(_params.ensuroCocFee), newValue, 1e17),
|
|
247
|
-
"Tweak exceeded"
|
|
248
|
-
);
|
|
217
|
+
require(!tweak || _isTweakWad(_4toWad(_params.ensuroCocFee), newValue, 1e17), "Tweak exceeded");
|
|
249
218
|
_params.ensuroCocFee = _wadTo4(newValue);
|
|
250
219
|
} else if (param == Parameter.jrRoc) {
|
|
251
220
|
require(!tweak || _isTweakWad(_4toWad(_params.jrRoc), newValue, 1e17), "Tweak exceeded");
|
|
@@ -259,19 +228,14 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
259
228
|
} else if (param == Parameter.exposureLimit) {
|
|
260
229
|
require(newValue >= _activeExposure, "Can't set exposureLimit less than active exposure");
|
|
261
230
|
require(!tweak || _isTweakWad(exposureLimit(), newValue, 1e17), "Tweak exceeded");
|
|
262
|
-
require(
|
|
263
|
-
newValue <= exposureLimit() || hasPoolRole(LEVEL1_ROLE),
|
|
264
|
-
"Tweak exceeded: Increase requires LEVEL1_ROLE"
|
|
265
|
-
);
|
|
231
|
+
require(newValue <= exposureLimit() || hasPoolRole(LEVEL1_ROLE), "Tweak exceeded: Increase requires LEVEL1_ROLE");
|
|
266
232
|
_params.exposureLimit = _amountToX(0, newValue);
|
|
267
233
|
} else if (param == Parameter.maxDuration) {
|
|
268
234
|
require(!tweak, "Tweak exceeded");
|
|
269
235
|
_params.maxDuration = newValue.toUint16();
|
|
270
236
|
}
|
|
271
237
|
_parameterChanged(
|
|
272
|
-
IAccessManager.GovernanceActions(
|
|
273
|
-
uint256(IAccessManager.GovernanceActions.setMoc) + uint256(param)
|
|
274
|
-
),
|
|
238
|
+
IAccessManager.GovernanceActions(uint256(IAccessManager.GovernanceActions.setMoc) + uint256(param)),
|
|
275
239
|
newValue,
|
|
276
240
|
tweak
|
|
277
241
|
);
|
|
@@ -327,14 +291,9 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
327
291
|
} else {
|
|
328
292
|
srScr = 0;
|
|
329
293
|
}
|
|
330
|
-
uint256 jrCoc = jrScr.wadMul(
|
|
331
|
-
|
|
332
|
-
);
|
|
333
|
-
uint256 srCoc = srScr.wadMul(
|
|
334
|
-
(p.srRoc * (expiration - block.timestamp)).wadDiv(SECONDS_IN_YEAR_WAD)
|
|
335
|
-
);
|
|
336
|
-
uint256 ensuroCommission = purePremium.wadMul(p.ensuroPpFee) +
|
|
337
|
-
(jrCoc + srCoc).wadMul(p.ensuroCocFee);
|
|
294
|
+
uint256 jrCoc = jrScr.wadMul((p.jrRoc * (expiration - block.timestamp)).wadDiv(SECONDS_IN_YEAR_WAD));
|
|
295
|
+
uint256 srCoc = srScr.wadMul((p.srRoc * (expiration - block.timestamp)).wadDiv(SECONDS_IN_YEAR_WAD));
|
|
296
|
+
uint256 ensuroCommission = purePremium.wadMul(p.ensuroPpFee) + (jrCoc + srCoc).wadMul(p.ensuroCocFee);
|
|
338
297
|
return purePremium + ensuroCommission + (jrCoc + srCoc);
|
|
339
298
|
}
|
|
340
299
|
|
|
@@ -359,17 +318,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
359
318
|
address onBehalfOf,
|
|
360
319
|
uint96 internalId
|
|
361
320
|
) internal virtual returns (Policy.PolicyData memory) {
|
|
362
|
-
return
|
|
363
|
-
_newPolicyWithParams(
|
|
364
|
-
payout,
|
|
365
|
-
premium,
|
|
366
|
-
lossProb,
|
|
367
|
-
expiration,
|
|
368
|
-
payer,
|
|
369
|
-
onBehalfOf,
|
|
370
|
-
internalId,
|
|
371
|
-
params()
|
|
372
|
-
);
|
|
321
|
+
return _newPolicyWithParams(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId, params());
|
|
373
322
|
}
|
|
374
323
|
|
|
375
324
|
/**
|
|
@@ -402,14 +351,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
402
351
|
"Payer must allow caller to transfer the premium"
|
|
403
352
|
);
|
|
404
353
|
require(payout <= maxPayoutPerPolicy(), "RiskModule: Payout is more than maximum per policy");
|
|
405
|
-
Policy.PolicyData memory policy = Policy.initialize(
|
|
406
|
-
this,
|
|
407
|
-
params_,
|
|
408
|
-
premium,
|
|
409
|
-
payout,
|
|
410
|
-
lossProb,
|
|
411
|
-
expiration
|
|
412
|
-
);
|
|
354
|
+
Policy.PolicyData memory policy = Policy.initialize(this, params_, premium, payout, lossProb, expiration);
|
|
413
355
|
_activeExposure += policy.payout;
|
|
414
356
|
require(_activeExposure <= exposureLimit(), "RiskModule: Exposure limit exceeded");
|
|
415
357
|
uint256 policyId = _policyPool.newPolicy(policy, payer, onBehalfOf, internalId);
|
|
@@ -75,15 +75,7 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
75
75
|
uint256 exposureLimit_,
|
|
76
76
|
address wallet_
|
|
77
77
|
) public initializer {
|
|
78
|
-
__RiskModule_init(
|
|
79
|
-
name_,
|
|
80
|
-
collRatio_,
|
|
81
|
-
ensuroPpFee_,
|
|
82
|
-
srRoc_,
|
|
83
|
-
maxPayoutPerPolicy_,
|
|
84
|
-
exposureLimit_,
|
|
85
|
-
wallet_
|
|
86
|
-
);
|
|
78
|
+
__RiskModule_init(name_, collRatio_, ensuroPpFee_, srRoc_, maxPayoutPerPolicy_, exposureLimit_, wallet_);
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
function _checkSignature(
|
|
@@ -98,12 +90,7 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
98
90
|
uint40 quoteValidUntil
|
|
99
91
|
) internal view {
|
|
100
92
|
if (!_creationIsOpen)
|
|
101
|
-
_policyPool.access().checkComponentRole(
|
|
102
|
-
address(this),
|
|
103
|
-
POLICY_CREATOR_ROLE,
|
|
104
|
-
_msgSender(),
|
|
105
|
-
false
|
|
106
|
-
);
|
|
93
|
+
_policyPool.access().checkComponentRole(address(this), POLICY_CREATOR_ROLE, _msgSender(), false);
|
|
107
94
|
require(quoteValidUntil >= block.timestamp, "Quote expired");
|
|
108
95
|
|
|
109
96
|
/**
|
|
@@ -116,16 +103,7 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
116
103
|
* - quoteValidUntil: the maximum validity of the quote
|
|
117
104
|
*/
|
|
118
105
|
bytes32 quoteHash = ECDSA.toEthSignedMessageHash(
|
|
119
|
-
abi.encodePacked(
|
|
120
|
-
address(this),
|
|
121
|
-
payout,
|
|
122
|
-
premium,
|
|
123
|
-
lossProb,
|
|
124
|
-
expiration,
|
|
125
|
-
policyData,
|
|
126
|
-
bucketId,
|
|
127
|
-
quoteValidUntil
|
|
128
|
-
)
|
|
106
|
+
abi.encodePacked(address(this), payout, premium, lossProb, expiration, policyData, bucketId, quoteValidUntil)
|
|
129
107
|
);
|
|
130
108
|
address signer = ECDSA.recover(quoteHash, quoteSignatureR, quoteSignatureVS);
|
|
131
109
|
_policyPool.access().checkComponentRole(address(this), PRICER_ROLE, signer, false);
|
|
@@ -141,7 +119,7 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
141
119
|
address payer,
|
|
142
120
|
address onBehalfOf
|
|
143
121
|
) internal returns (Policy.PolicyData memory createdPolicy) {
|
|
144
|
-
uint96 internalId = uint96(uint256(policyData) % 2**96);
|
|
122
|
+
uint96 internalId = uint96(uint256(policyData) % 2 ** 96);
|
|
145
123
|
createdPolicy = _newPolicyWithParams(
|
|
146
124
|
payout,
|
|
147
125
|
premium,
|
|
@@ -202,17 +180,7 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
202
180
|
quoteSignatureVS,
|
|
203
181
|
quoteValidUntil
|
|
204
182
|
);
|
|
205
|
-
return
|
|
206
|
-
_newPolicySigned(
|
|
207
|
-
payout,
|
|
208
|
-
premium,
|
|
209
|
-
lossProb,
|
|
210
|
-
expiration,
|
|
211
|
-
policyData,
|
|
212
|
-
bucketId,
|
|
213
|
-
_msgSender(),
|
|
214
|
-
onBehalfOf
|
|
215
|
-
);
|
|
183
|
+
return _newPolicySigned(payout, premium, lossProb, expiration, policyData, bucketId, _msgSender(), onBehalfOf);
|
|
216
184
|
}
|
|
217
185
|
|
|
218
186
|
/**
|
|
@@ -261,17 +229,7 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
261
229
|
quoteSignatureVS,
|
|
262
230
|
quoteValidUntil
|
|
263
231
|
);
|
|
264
|
-
return
|
|
265
|
-
_newPolicySigned(
|
|
266
|
-
payout,
|
|
267
|
-
premium,
|
|
268
|
-
lossProb,
|
|
269
|
-
expiration,
|
|
270
|
-
policyData,
|
|
271
|
-
bucketId,
|
|
272
|
-
_msgSender(),
|
|
273
|
-
onBehalfOf
|
|
274
|
-
).id;
|
|
232
|
+
return _newPolicySigned(payout, premium, lossProb, expiration, policyData, bucketId, _msgSender(), onBehalfOf).id;
|
|
275
233
|
}
|
|
276
234
|
|
|
277
235
|
/**
|
|
@@ -334,24 +292,13 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
334
292
|
quoteSignatureVS,
|
|
335
293
|
quoteValidUntil
|
|
336
294
|
);
|
|
337
|
-
return
|
|
338
|
-
_newPolicySigned(
|
|
339
|
-
payout,
|
|
340
|
-
premium,
|
|
341
|
-
lossProb,
|
|
342
|
-
expiration,
|
|
343
|
-
policyData,
|
|
344
|
-
bucketId,
|
|
345
|
-
onBehalfOf,
|
|
346
|
-
onBehalfOf
|
|
347
|
-
).id;
|
|
295
|
+
return _newPolicySigned(payout, premium, lossProb, expiration, policyData, bucketId, onBehalfOf, onBehalfOf).id;
|
|
348
296
|
}
|
|
349
297
|
|
|
350
|
-
function resolvePolicy(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
{
|
|
298
|
+
function resolvePolicy(
|
|
299
|
+
Policy.PolicyData calldata policy,
|
|
300
|
+
uint256 payout
|
|
301
|
+
) external onlyComponentRole(RESOLVER_ROLE) whenNotPaused {
|
|
355
302
|
_policyPool.resolvePolicy(policy, payout);
|
|
356
303
|
}
|
|
357
304
|
|
|
@@ -365,14 +312,11 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
365
312
|
* @param bucketId Group identifier for the policies that will have these parameters
|
|
366
313
|
* @param params_ The parameters of the new bucket.
|
|
367
314
|
*/
|
|
368
|
-
function setBucketParams(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
{
|
|
372
|
-
require(
|
|
373
|
-
bucketId != 0,
|
|
374
|
-
"SignedBucketRiskModule: bucketId can't be zero, set default RM parameters"
|
|
375
|
-
);
|
|
315
|
+
function setBucketParams(
|
|
316
|
+
uint256 bucketId,
|
|
317
|
+
Params calldata params_
|
|
318
|
+
) external onlyGlobalOrComponentRole2(LEVEL1_ROLE, LEVEL2_ROLE) {
|
|
319
|
+
require(bucketId != 0, "SignedBucketRiskModule: bucketId can't be zero, set default RM parameters");
|
|
376
320
|
_buckets[bucketId] = PackedParams({
|
|
377
321
|
moc: _wadTo4(params_.moc),
|
|
378
322
|
jrCollRatio: _wadTo4(params_.jrCollRatio),
|
|
@@ -398,14 +342,8 @@ contract SignedBucketRiskModule is RiskModule {
|
|
|
398
342
|
*
|
|
399
343
|
* @param bucketId Group identifier for the policies that will have these parameters
|
|
400
344
|
*/
|
|
401
|
-
function deleteBucket(uint256 bucketId)
|
|
402
|
-
|
|
403
|
-
onlyGlobalOrComponentRole2(LEVEL1_ROLE, LEVEL2_ROLE)
|
|
404
|
-
{
|
|
405
|
-
require(
|
|
406
|
-
bucketId != 0,
|
|
407
|
-
"SignedBucketRiskModule: bucketId can't be zero, set default RM parameters"
|
|
408
|
-
);
|
|
345
|
+
function deleteBucket(uint256 bucketId) external onlyGlobalOrComponentRole2(LEVEL1_ROLE, LEVEL2_ROLE) {
|
|
346
|
+
require(bucketId != 0, "SignedBucketRiskModule: bucketId can't be zero, set default RM parameters");
|
|
409
347
|
delete _buckets[bucketId];
|
|
410
348
|
emit BucketDeleted(bucketId);
|
|
411
349
|
}
|
|
@@ -58,15 +58,7 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
58
58
|
uint256 exposureLimit_,
|
|
59
59
|
address wallet_
|
|
60
60
|
) public initializer {
|
|
61
|
-
__RiskModule_init(
|
|
62
|
-
name_,
|
|
63
|
-
collRatio_,
|
|
64
|
-
ensuroPpFee_,
|
|
65
|
-
srRoc_,
|
|
66
|
-
maxPayoutPerPolicy_,
|
|
67
|
-
exposureLimit_,
|
|
68
|
-
wallet_
|
|
69
|
-
);
|
|
61
|
+
__RiskModule_init(name_, collRatio_, ensuroPpFee_, srRoc_, maxPayoutPerPolicy_, exposureLimit_, wallet_);
|
|
70
62
|
}
|
|
71
63
|
|
|
72
64
|
function _newPolicySigned(
|
|
@@ -82,12 +74,7 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
82
74
|
address onBehalfOf
|
|
83
75
|
) internal returns (Policy.PolicyData memory createdPolicy) {
|
|
84
76
|
if (!_creationIsOpen)
|
|
85
|
-
_policyPool.access().checkComponentRole(
|
|
86
|
-
address(this),
|
|
87
|
-
POLICY_CREATOR_ROLE,
|
|
88
|
-
_msgSender(),
|
|
89
|
-
false
|
|
90
|
-
);
|
|
77
|
+
_policyPool.access().checkComponentRole(address(this), POLICY_CREATOR_ROLE, _msgSender(), false);
|
|
91
78
|
require(quoteValidUntil >= block.timestamp, "Quote expired");
|
|
92
79
|
|
|
93
80
|
/**
|
|
@@ -100,29 +87,13 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
100
87
|
* - quoteValidUntil: the maximum validity of the quote
|
|
101
88
|
*/
|
|
102
89
|
bytes32 quoteHash = ECDSA.toEthSignedMessageHash(
|
|
103
|
-
abi.encodePacked(
|
|
104
|
-
address(this),
|
|
105
|
-
payout,
|
|
106
|
-
premium,
|
|
107
|
-
lossProb,
|
|
108
|
-
expiration,
|
|
109
|
-
policyData,
|
|
110
|
-
quoteValidUntil
|
|
111
|
-
)
|
|
90
|
+
abi.encodePacked(address(this), payout, premium, lossProb, expiration, policyData, quoteValidUntil)
|
|
112
91
|
);
|
|
113
92
|
address signer = ECDSA.recover(quoteHash, quoteSignatureR, quoteSignatureVS);
|
|
114
93
|
_policyPool.access().checkComponentRole(address(this), PRICER_ROLE, signer, false);
|
|
115
|
-
uint96 internalId = uint96(uint256(policyData) % 2**96);
|
|
94
|
+
uint96 internalId = uint96(uint256(policyData) % 2 ** 96);
|
|
116
95
|
|
|
117
|
-
createdPolicy = _newPolicy(
|
|
118
|
-
payout,
|
|
119
|
-
premium,
|
|
120
|
-
lossProb,
|
|
121
|
-
expiration,
|
|
122
|
-
payer,
|
|
123
|
-
onBehalfOf,
|
|
124
|
-
internalId
|
|
125
|
-
);
|
|
96
|
+
createdPolicy = _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId);
|
|
126
97
|
emit NewSignedPolicy(createdPolicy.id, policyData);
|
|
127
98
|
return createdPolicy;
|
|
128
99
|
}
|
|
@@ -285,19 +256,17 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
285
256
|
).id;
|
|
286
257
|
}
|
|
287
258
|
|
|
288
|
-
function resolvePolicy(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
{
|
|
259
|
+
function resolvePolicy(
|
|
260
|
+
Policy.PolicyData calldata policy,
|
|
261
|
+
uint256 payout
|
|
262
|
+
) external onlyComponentRole(RESOLVER_ROLE) whenNotPaused {
|
|
293
263
|
_policyPool.resolvePolicy(policy, payout);
|
|
294
264
|
}
|
|
295
265
|
|
|
296
|
-
function resolvePolicyFullPayout(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
{
|
|
266
|
+
function resolvePolicyFullPayout(
|
|
267
|
+
Policy.PolicyData calldata policy,
|
|
268
|
+
bool customerWon
|
|
269
|
+
) external onlyComponentRole(RESOLVER_ROLE) whenNotPaused {
|
|
301
270
|
_policyPool.resolvePolicyFullPayout(policy, customerWon);
|
|
302
271
|
}
|
|
303
272
|
|
|
@@ -62,22 +62,16 @@ contract TieredSignedQuoteRiskModule is SignedQuoteRiskModule {
|
|
|
62
62
|
* @param lossProb The loss probability of the new bucket.
|
|
63
63
|
* @param params_ The parameters of the new bucket.
|
|
64
64
|
*/
|
|
65
|
-
function pushBucket(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{
|
|
65
|
+
function pushBucket(
|
|
66
|
+
uint256 lossProb,
|
|
67
|
+
Params calldata params_
|
|
68
|
+
) external onlyGlobalOrComponentRole2(LEVEL1_ROLE, LEVEL2_ROLE) {
|
|
69
69
|
uint256 newBucket = 0;
|
|
70
70
|
if (_buckets.lossProbs[0] != 0) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
newBucket < MAX_BUCKETS && _buckets.lossProbs[newBucket] != 0;
|
|
74
|
-
newBucket++
|
|
75
|
-
) {} // solhint-disable-line no-empty-blocks
|
|
71
|
+
// solhint-disable-next-line no-empty-blocks
|
|
72
|
+
for (newBucket = 1; newBucket < MAX_BUCKETS && _buckets.lossProbs[newBucket] != 0; newBucket++) {}
|
|
76
73
|
require(newBucket < MAX_BUCKETS, "No more than 4 buckets accepted");
|
|
77
|
-
require(
|
|
78
|
-
lossProb > uint256(_buckets.lossProbs[newBucket - 1]),
|
|
79
|
-
"lossProb <= last lossProb - reset instead"
|
|
80
|
-
);
|
|
74
|
+
require(lossProb > uint256(_buckets.lossProbs[newBucket - 1]), "lossProb <= last lossProb - reset instead");
|
|
81
75
|
}
|
|
82
76
|
_buckets.lossProbs[newBucket] = lossProb.toUint64();
|
|
83
77
|
_bucketParams[newBucket] = PackedParams({
|
package/contracts/TimeScaled.sol
CHANGED
|
@@ -35,11 +35,7 @@ library TimeScaled {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function getScale(ScaledAmount storage scaledAmount, uint256 interestRate)
|
|
39
|
-
internal
|
|
40
|
-
view
|
|
41
|
-
returns (uint256)
|
|
42
|
-
{
|
|
38
|
+
function getScale(ScaledAmount storage scaledAmount, uint256 interestRate) internal view returns (uint256) {
|
|
43
39
|
uint32 now_ = uint32(block.timestamp);
|
|
44
40
|
if (scaledAmount.lastUpdate >= now_) {
|
|
45
41
|
return scaledAmount.scale;
|
|
@@ -51,16 +47,8 @@ library TimeScaled {
|
|
|
51
47
|
);
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
function getScaledAmount(ScaledAmount storage scaledAmount, uint256 interestRate)
|
|
55
|
-
|
|
56
|
-
view
|
|
57
|
-
returns (uint256)
|
|
58
|
-
{
|
|
59
|
-
return
|
|
60
|
-
uint256(scaledAmount.amount)
|
|
61
|
-
.wadToRay()
|
|
62
|
-
.rayMul(getScale(scaledAmount, interestRate))
|
|
63
|
-
.rayToWad();
|
|
50
|
+
function getScaledAmount(ScaledAmount storage scaledAmount, uint256 interestRate) internal view returns (uint256) {
|
|
51
|
+
return uint256(scaledAmount.amount).wadToRay().rayMul(getScale(scaledAmount, interestRate)).rayToWad();
|
|
64
52
|
}
|
|
65
53
|
|
|
66
54
|
function init(ScaledAmount storage scaledAmount) internal {
|
|
@@ -69,11 +57,7 @@ library TimeScaled {
|
|
|
69
57
|
scaledAmount.lastUpdate = uint32(block.timestamp);
|
|
70
58
|
}
|
|
71
59
|
|
|
72
|
-
function scaleAmount(ScaledAmount storage scaledAmount, uint256 toScale)
|
|
73
|
-
internal
|
|
74
|
-
view
|
|
75
|
-
returns (uint256)
|
|
76
|
-
{
|
|
60
|
+
function scaleAmount(ScaledAmount storage scaledAmount, uint256 toScale) internal view returns (uint256) {
|
|
77
61
|
return toScale.wadToRay().rayDiv(uint256(scaledAmount.scale)).rayToWad();
|
|
78
62
|
}
|
|
79
63
|
|
|
@@ -85,22 +69,14 @@ library TimeScaled {
|
|
|
85
69
|
return toScale.wadToRay().rayDiv(getScale(scaledAmount, interestRate)).rayToWad();
|
|
86
70
|
}
|
|
87
71
|
|
|
88
|
-
function add(
|
|
89
|
-
ScaledAmount storage scaledAmount,
|
|
90
|
-
uint256 amount,
|
|
91
|
-
uint256 interestRate
|
|
92
|
-
) internal returns (uint256) {
|
|
72
|
+
function add(ScaledAmount storage scaledAmount, uint256 amount, uint256 interestRate) internal returns (uint256) {
|
|
93
73
|
updateScale(scaledAmount, interestRate);
|
|
94
74
|
uint256 scaledAdd = scaleAmount(scaledAmount, amount);
|
|
95
75
|
scaledAmount.amount += scaledAdd.toUint96();
|
|
96
76
|
return scaledAdd;
|
|
97
77
|
}
|
|
98
78
|
|
|
99
|
-
function sub(
|
|
100
|
-
ScaledAmount storage scaledAmount,
|
|
101
|
-
uint256 amount,
|
|
102
|
-
uint256 interestRate
|
|
103
|
-
) internal returns (uint256) {
|
|
79
|
+
function sub(ScaledAmount storage scaledAmount, uint256 amount, uint256 interestRate) internal returns (uint256) {
|
|
104
80
|
updateScale(scaledAmount, interestRate);
|
|
105
81
|
uint256 scaledSub = scaleAmount(scaledAmount, amount);
|
|
106
82
|
scaledAmount.amount -= scaledSub.toUint96();
|
|
@@ -111,21 +87,14 @@ library TimeScaled {
|
|
|
111
87
|
return scaledSub;
|
|
112
88
|
}
|
|
113
89
|
|
|
114
|
-
function discreteChange(
|
|
115
|
-
ScaledAmount storage scaledAmount,
|
|
116
|
-
int256 amount,
|
|
117
|
-
uint256 interestRate
|
|
118
|
-
) internal {
|
|
90
|
+
function discreteChange(ScaledAmount storage scaledAmount, int256 amount, uint256 interestRate) internal {
|
|
119
91
|
if (scaledAmount.amount == 0) {
|
|
120
92
|
add(scaledAmount, uint256(amount), interestRate);
|
|
121
93
|
return;
|
|
122
94
|
}
|
|
123
95
|
updateScale(scaledAmount, interestRate);
|
|
124
96
|
uint256 newScaledAmount = uint256(int256(getScaledAmount(scaledAmount, interestRate)) + amount);
|
|
125
|
-
scaledAmount.scale = newScaledAmount
|
|
126
|
-
.wadToRay()
|
|
127
|
-
.rayDiv(uint256(scaledAmount.amount).wadToRay())
|
|
128
|
-
.toUint112();
|
|
97
|
+
scaledAmount.scale = newScaledAmount.wadToRay().rayDiv(uint256(scaledAmount.amount).wadToRay()).toUint112();
|
|
129
98
|
require(scaledAmount.scale >= MIN_SCALE, "Scale too small, can lead to rounding errors");
|
|
130
99
|
}
|
|
131
100
|
|
|
@@ -20,9 +20,7 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
20
20
|
|
|
21
21
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
22
22
|
// solhint-disable-next-line no-empty-blocks
|
|
23
|
-
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
|
|
24
|
-
RiskModule(policyPool_, premiumsAccount_)
|
|
25
|
-
{} // solhint-disable-line no-empty-blocks
|
|
23
|
+
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_) RiskModule(policyPool_, premiumsAccount_) {}
|
|
26
24
|
|
|
27
25
|
/**
|
|
28
26
|
* @dev Initializes the RiskModule
|
|
@@ -43,15 +41,7 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
43
41
|
uint256 exposureLimit_,
|
|
44
42
|
address wallet_
|
|
45
43
|
) public initializer {
|
|
46
|
-
__RiskModule_init(
|
|
47
|
-
name_,
|
|
48
|
-
collRatio_,
|
|
49
|
-
ensuroPpFee_,
|
|
50
|
-
srRoc_,
|
|
51
|
-
maxPayoutPerPolicy_,
|
|
52
|
-
exposureLimit_,
|
|
53
|
-
wallet_
|
|
54
|
-
);
|
|
44
|
+
__RiskModule_init(name_, collRatio_, ensuroPpFee_, srRoc_, maxPayoutPerPolicy_, exposureLimit_, wallet_);
|
|
55
45
|
}
|
|
56
46
|
|
|
57
47
|
/**
|
|
@@ -79,16 +69,7 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
79
69
|
address onBehalfOf,
|
|
80
70
|
uint96 internalId
|
|
81
71
|
) external whenNotPaused onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
82
|
-
return
|
|
83
|
-
_newPolicy(
|
|
84
|
-
payout,
|
|
85
|
-
premium,
|
|
86
|
-
lossProb,
|
|
87
|
-
expiration,
|
|
88
|
-
_getPayer(onBehalfOf, premium),
|
|
89
|
-
onBehalfOf,
|
|
90
|
-
internalId
|
|
91
|
-
).id;
|
|
72
|
+
return _newPolicy(payout, premium, lossProb, expiration, _getPayer(onBehalfOf, premium), onBehalfOf, internalId).id;
|
|
92
73
|
}
|
|
93
74
|
|
|
94
75
|
/**
|
|
@@ -115,22 +96,8 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
115
96
|
uint40 expiration,
|
|
116
97
|
address onBehalfOf,
|
|
117
98
|
uint96 internalId
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
whenNotPaused
|
|
121
|
-
onlyComponentRole(PRICER_ROLE)
|
|
122
|
-
returns (Policy.PolicyData memory createdPolicy)
|
|
123
|
-
{
|
|
124
|
-
return
|
|
125
|
-
_newPolicy(
|
|
126
|
-
payout,
|
|
127
|
-
premium,
|
|
128
|
-
lossProb,
|
|
129
|
-
expiration,
|
|
130
|
-
_getPayer(onBehalfOf, premium),
|
|
131
|
-
onBehalfOf,
|
|
132
|
-
internalId
|
|
133
|
-
);
|
|
99
|
+
) external whenNotPaused onlyComponentRole(PRICER_ROLE) returns (Policy.PolicyData memory createdPolicy) {
|
|
100
|
+
return _newPolicy(payout, premium, lossProb, expiration, _getPayer(onBehalfOf, premium), onBehalfOf, internalId);
|
|
134
101
|
}
|
|
135
102
|
|
|
136
103
|
function _getPayer(address onBehalfOf, uint256 premium) internal view returns (address payer) {
|
|
@@ -165,11 +132,10 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
165
132
|
* @param policy The policy previously created (from {NewPolicy} event)
|
|
166
133
|
* @param payout The payout to transfer to the policy holder
|
|
167
134
|
*/
|
|
168
|
-
function resolvePolicy(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
{
|
|
135
|
+
function resolvePolicy(
|
|
136
|
+
Policy.PolicyData calldata policy,
|
|
137
|
+
uint256 payout
|
|
138
|
+
) external onlyComponentRole(RESOLVER_ROLE) whenNotPaused {
|
|
173
139
|
_policyPool.resolvePolicy(policy, payout);
|
|
174
140
|
}
|
|
175
141
|
|
|
@@ -187,11 +153,10 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
187
153
|
* @param customerWon If true, policy.payout is transferred to the policy holder. If false, the policy is resolved
|
|
188
154
|
* without payout and can't be longer claimed.
|
|
189
155
|
*/
|
|
190
|
-
function resolvePolicyFullPayout(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
{
|
|
156
|
+
function resolvePolicyFullPayout(
|
|
157
|
+
Policy.PolicyData calldata policy,
|
|
158
|
+
bool customerWon
|
|
159
|
+
) external onlyComponentRole(RESOLVER_ROLE) whenNotPaused {
|
|
195
160
|
_policyPool.resolvePolicyFullPayout(policy, customerWon);
|
|
196
161
|
}
|
|
197
162
|
|