@ensuro/core 2.0.0-beta10 → 2.0.0-beta11
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 +13 -0
- package/build/contracts/AccessManager.sol/AccessManager.json +7 -2
- package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +21 -2
- package/build/contracts/EToken.sol/EToken.json +21 -2
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +21 -2
- package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +19 -0
- package/build/contracts/Policy.sol/Policy.json +2 -2
- package/build/contracts/PolicyPool.sol/PolicyPool.json +2 -2
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +19 -0
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +21 -2
- package/build/contracts/Reserve.sol/Reserve.json +19 -0
- package/build/contracts/RiskModule.sol/RiskModule.json +19 -0
- package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +21 -2
- package/build/contracts/TimeScaled.sol/TimeScaled.json +2 -2
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +21 -2
- package/build/contracts/dependencies/WadRayMath.sol/WadRayMath.json +2 -2
- package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +19 -0
- package/build/contracts/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +19 -0
- package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +2 -2
- package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +2 -2
- package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +180 -0
- package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +2 -2
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +21 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +2 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +2 -2
- package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +21 -2
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +2 -2
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +2 -2
- package/contracts/AccessManager.sol +30 -1
- package/contracts/ERC4626AssetManager.sol +3 -0
- package/contracts/EToken.sol +89 -19
- package/contracts/LPManualWhitelist.sol +18 -2
- package/contracts/LiquidityThresholdAssetManager.sol +17 -2
- package/contracts/Policy.sol +4 -2
- package/contracts/PolicyPool.sol +58 -11
- package/contracts/PolicyPoolComponent.sol +25 -3
- package/contracts/PremiumsAccount.sol +55 -23
- package/contracts/Reserve.sol +19 -3
- package/contracts/RiskModule.sol +37 -13
- package/contracts/SignedQuoteRiskModule.sol +7 -0
- package/contracts/TrustfulRiskModule.sol +7 -0
- package/contracts/interfaces/IAssetManager.sol +8 -3
- package/contracts/interfaces/IPolicyPool.sol +1 -1
- package/contracts/interfaces/IPolicyPoolComponent.sol +2 -1
- package/contracts/mocks/InterfaceIdCalculator.sol +32 -0
- package/contracts/mocks/PolicyPoolComponentMock.sol +10 -0
- package/js/deploy.js +704 -0
- package/js/test-utils.js +139 -37
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@ import {IAssetManager} from "./interfaces/IAssetManager.sol";
|
|
|
22
22
|
* (_activePurePremiums) and the surplus or deficit generated by the finalized policies (pure premiums collected -
|
|
23
23
|
* losses).
|
|
24
24
|
*
|
|
25
|
-
* Collaborates with a junior {EToken} and a senior {EToken} that act as lenders when the premiums aren't
|
|
25
|
+
* Collaborates with a junior {EToken} and a senior {EToken} that act as lenders when the premiums aren't enough to
|
|
26
26
|
* cover the losses.
|
|
27
27
|
*
|
|
28
28
|
* @custom:security-contact security@ensuro.co
|
|
@@ -35,6 +35,8 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
35
35
|
using SafeCast for uint256;
|
|
36
36
|
|
|
37
37
|
bytes32 public constant WITHDRAW_WON_PREMIUMS_ROLE = keccak256("WITHDRAW_WON_PREMIUMS_ROLE");
|
|
38
|
+
uint256 internal constant FOUR_DECIMAL_TO_WAD = 1e14;
|
|
39
|
+
uint16 internal constant HUNDRED_PERCENT = 1e4;
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* @dev The Junior eToken is the first {EToken} to which the PremiumsAccount will go for credit when it runs out of
|
|
@@ -106,29 +108,31 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
106
108
|
* @dev Initializes the PremiumsAccount (to be called by subclasses)
|
|
107
109
|
*/
|
|
108
110
|
// solhint-disable-next-line func-name-mixedcase
|
|
109
|
-
function __PremiumsAccount_init() internal
|
|
110
|
-
|
|
111
|
+
function __PremiumsAccount_init() internal onlyInitializing {
|
|
112
|
+
__Reserve_init();
|
|
111
113
|
__PremiumsAccount_init_unchained();
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
/**
|
|
115
|
-
* @dev In the initialization, besides settings the parameters, we approve the spending of funds by the eTokens
|
|
116
|
-
* so we don't need to do it on every repayment operation
|
|
117
|
-
*/
|
|
118
116
|
// solhint-disable-next-line func-name-mixedcase
|
|
119
|
-
function __PremiumsAccount_init_unchained() internal
|
|
117
|
+
function __PremiumsAccount_init_unchained() internal onlyInitializing {
|
|
120
118
|
/*
|
|
121
119
|
_activePurePremiums = 0;
|
|
122
120
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
_params = PackedParams({deficitRatio: 1e4, assetManager: IAssetManager(address(0))});
|
|
121
|
+
_params = PackedParams({
|
|
122
|
+
deficitRatio: HUNDRED_PERCENT,
|
|
123
|
+
assetManager: IAssetManager(address(0))
|
|
124
|
+
});
|
|
129
125
|
_validateParameters();
|
|
130
126
|
}
|
|
131
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @dev See {IERC165-supportsInterface}.
|
|
130
|
+
*/
|
|
131
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
132
|
+
return
|
|
133
|
+
super.supportsInterface(interfaceId) || interfaceId == type(IPremiumsAccount).interfaceId;
|
|
134
|
+
}
|
|
135
|
+
|
|
132
136
|
function assetManager() public view override returns (IAssetManager) {
|
|
133
137
|
return _params.assetManager;
|
|
134
138
|
}
|
|
@@ -141,7 +145,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
141
145
|
* @dev This is called by the {Reserve} base class to record the earnings generated by the asset management.
|
|
142
146
|
*
|
|
143
147
|
* @param earningsOrLosses Indicates the amount earned since last time earnings where recorded.
|
|
144
|
-
* - If positive, repays the
|
|
148
|
+
* - If positive, repays the loans and accumulates the rest in the surplus.
|
|
145
149
|
* - If negative (losses) substracts it from surplus. It never can exceed _maxDeficit and doesn't takes
|
|
146
150
|
* loans to cover asset losses.
|
|
147
151
|
*/
|
|
@@ -158,7 +162,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
158
162
|
|
|
159
163
|
function _validateParameters() internal view override {
|
|
160
164
|
require(
|
|
161
|
-
_params.deficitRatio <=
|
|
165
|
+
_params.deficitRatio <= HUNDRED_PERCENT && _params.deficitRatio >= 0,
|
|
162
166
|
"Validation: deficitRatio must be <= 1"
|
|
163
167
|
);
|
|
164
168
|
}
|
|
@@ -227,7 +231,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
227
231
|
* @dev Returns the percentage of the active pure premiums that can be used to cover losses of finalized policies.
|
|
228
232
|
*/
|
|
229
233
|
function deficitRatio() public view returns (uint256) {
|
|
230
|
-
return uint256(_params.deficitRatio) *
|
|
234
|
+
return uint256(_params.deficitRatio) * FOUR_DECIMAL_TO_WAD; // 4 -> 18 decimals
|
|
231
235
|
}
|
|
232
236
|
|
|
233
237
|
/**
|
|
@@ -239,7 +243,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
239
243
|
* Events:
|
|
240
244
|
* - Emits GovernanceAction with action = setDeficitRatio or setDeficitRatioWithAdjustment if an adjustment was made.
|
|
241
245
|
*
|
|
242
|
-
* @param adjustment If true and the new ratio leaves `_surplus < -_maxDeficit()`,
|
|
246
|
+
* @param adjustment If true and the new ratio leaves `_surplus < -_maxDeficit()`, it adjusts the _surplus to the new
|
|
243
247
|
* `_maxDeficit()` and borrows the difference from the eTokens.
|
|
244
248
|
* If false and the new ratio leaves `_surplus < -_maxDeficit()`, the operation is reverted.
|
|
245
249
|
*/
|
|
@@ -247,9 +251,17 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
247
251
|
external
|
|
248
252
|
onlyComponentRole(LEVEL2_ROLE)
|
|
249
253
|
{
|
|
250
|
-
require(newRatio <= 1e18
|
|
254
|
+
require(newRatio <= 1e18, "Validation: deficitRatio must be <= 1");
|
|
255
|
+
|
|
256
|
+
uint16 truncatedRatio = (newRatio / FOUR_DECIMAL_TO_WAD).toUint16();
|
|
257
|
+
require(
|
|
258
|
+
uint256(truncatedRatio) * FOUR_DECIMAL_TO_WAD == newRatio,
|
|
259
|
+
"Validation: only up to 4 decimals allowed"
|
|
260
|
+
);
|
|
261
|
+
|
|
251
262
|
int256 maxDeficit = _maxDeficit(newRatio);
|
|
252
263
|
require(adjustment || _surplus >= maxDeficit, "Validation: surplus must be >= maxDeficit");
|
|
264
|
+
|
|
253
265
|
IAccessManager.GovernanceActions action = IAccessManager.GovernanceActions.setDeficitRatio;
|
|
254
266
|
if (_surplus < maxDeficit) {
|
|
255
267
|
// Do the adjustment
|
|
@@ -258,12 +270,12 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
258
270
|
_borrowFromEtk(borrow, address(this), address(_juniorEtk) != address(0));
|
|
259
271
|
action = IAccessManager.GovernanceActions.setDeficitRatioWithAdjustment;
|
|
260
272
|
}
|
|
261
|
-
_params.deficitRatio =
|
|
273
|
+
_params.deficitRatio = truncatedRatio;
|
|
262
274
|
_parameterChanged(action, newRatio, false);
|
|
263
275
|
}
|
|
264
276
|
|
|
265
277
|
/**
|
|
266
|
-
* @dev Internal function called when money in the PremiumsAccount is not
|
|
278
|
+
* @dev Internal function called when money in the PremiumsAccount is not enough and we need to borrow from the
|
|
267
279
|
* eTokens.
|
|
268
280
|
*
|
|
269
281
|
* @param borrow The amount to borrow.
|
|
@@ -276,6 +288,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
276
288
|
address receiver,
|
|
277
289
|
bool jrEtk
|
|
278
290
|
) internal {
|
|
291
|
+
require(receiver != address(0), "PremiumsAccount: receiver cannot be the zero address");
|
|
279
292
|
uint256 left;
|
|
280
293
|
if (jrEtk) {
|
|
281
294
|
// Consume Junior Pool until exhausted
|
|
@@ -334,9 +347,9 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
334
347
|
* @param amount The amount to be transferred.
|
|
335
348
|
*/
|
|
336
349
|
function receiveGrant(uint256 amount) external {
|
|
337
|
-
currency().safeTransferFrom(_msgSender(), address(this), amount);
|
|
338
350
|
_storePurePremiumWon(amount);
|
|
339
351
|
emit WonPremiumsInOut(true, amount);
|
|
352
|
+
currency().safeTransferFrom(_msgSender(), address(this), amount);
|
|
340
353
|
}
|
|
341
354
|
|
|
342
355
|
/**
|
|
@@ -362,6 +375,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
362
375
|
onlyGlobalOrComponentRole(WITHDRAW_WON_PREMIUMS_ROLE)
|
|
363
376
|
returns (uint256)
|
|
364
377
|
{
|
|
378
|
+
require(destination != address(0), "PremiumsAccount: destination cannot be the zero address");
|
|
365
379
|
if (_surplus <= 0) {
|
|
366
380
|
amount = 0;
|
|
367
381
|
} else {
|
|
@@ -445,10 +459,21 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
445
459
|
if (borrowedFromEtk == 0) return purePremiumWon;
|
|
446
460
|
uint256 repayAmount = Math.min(purePremiumWon, borrowedFromEtk);
|
|
447
461
|
|
|
448
|
-
// If not
|
|
462
|
+
// If not enough liquidity, it deinvests from the asset manager
|
|
449
463
|
if (currency().balanceOf(address(this)) < repayAmount) {
|
|
464
|
+
/**
|
|
465
|
+
* I send `repayAmount` because the IAssetManager expects the full amount that's needed, not the missing one.
|
|
466
|
+
* It uses the value of the full amount to optimize the deinvestment leaving more liquidity if possible to avoid
|
|
467
|
+
* future deinvestment. It will only fail if it can't refill `repayAmount - currency().balanceOf(address(this))`
|
|
468
|
+
*/
|
|
450
469
|
_refillWallet(repayAmount);
|
|
451
470
|
}
|
|
471
|
+
// Checks the allowance before repayment
|
|
472
|
+
if (currency().allowance(address(this), address(etk)) < repayAmount) {
|
|
473
|
+
// If I have to approve, I approve for all the pending debt (not just repayAmount), this way I avoid some
|
|
474
|
+
// future approvals.
|
|
475
|
+
currency().approve(address(etk), borrowedFromEtk);
|
|
476
|
+
}
|
|
452
477
|
etk.repayLoan(repayAmount, address(this));
|
|
453
478
|
return purePremiumWon - repayAmount;
|
|
454
479
|
}
|
|
@@ -477,4 +502,11 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
477
502
|
_storePurePremiumWon(purePremiumWon);
|
|
478
503
|
_unlockScr(policy);
|
|
479
504
|
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* @dev This empty reserved space is put in place to allow future versions to add new
|
|
508
|
+
* variables without shifting down storage in the inheritance chain.
|
|
509
|
+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
510
|
+
*/
|
|
511
|
+
uint256[47] private __gap;
|
|
480
512
|
}
|
package/contracts/Reserve.sol
CHANGED
|
@@ -39,6 +39,14 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
39
39
|
NEGLIGIBLE_AMOUNT = 10**(policyPool_.currency().decimals() / 2);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @dev Initializes the Reserve (to be called by subclasses)
|
|
44
|
+
*/
|
|
45
|
+
// solhint-disable-next-line func-name-mixedcase
|
|
46
|
+
function __Reserve_init() internal onlyInitializing {
|
|
47
|
+
__PolicyPoolComponent_init();
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
/**
|
|
43
51
|
* @dev Refills the reserve's balance, deinvesting from the asset manager to be able to make a payment
|
|
44
52
|
*
|
|
@@ -62,12 +70,13 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
62
70
|
|
|
63
71
|
/**
|
|
64
72
|
* @dev Internal function that transfers money to a destination. It might need to call `_refillWallet` to deinvest
|
|
65
|
-
* some money to have
|
|
73
|
+
* some money to have enough liquidity for the payment.
|
|
66
74
|
*
|
|
67
75
|
* @param destination The destination of the transfer.
|
|
68
76
|
* @param amount The amount to be transferred.
|
|
69
77
|
*/
|
|
70
78
|
function _transferTo(address destination, uint256 amount) internal {
|
|
79
|
+
require(destination != address(0), "Reserve: transfer to the zero address");
|
|
71
80
|
if (amount == 0) return;
|
|
72
81
|
uint256 balance = currency().balanceOf(address(this));
|
|
73
82
|
if (balance < amount) {
|
|
@@ -126,8 +135,8 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
126
135
|
onlyGlobalOrComponentRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
|
|
127
136
|
{
|
|
128
137
|
require(
|
|
129
|
-
address(newAM) == address(0) ||
|
|
130
|
-
"
|
|
138
|
+
address(newAM) == address(0) || newAM.supportsInterface(type(IAssetManager).interfaceId),
|
|
139
|
+
"Reserve: asset manager doesn't implements the required interface"
|
|
131
140
|
);
|
|
132
141
|
address am = address(assetManager());
|
|
133
142
|
IAccessManager.GovernanceActions action = IAccessManager.GovernanceActions.setAssetManager;
|
|
@@ -210,4 +219,11 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
210
219
|
{
|
|
211
220
|
return address(assetManager()).functionDelegateCall(functionCall);
|
|
212
221
|
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @dev This empty reserved space is put in place to allow future versions to add new
|
|
225
|
+
* variables without shifting down storage in the inheritance chain.
|
|
226
|
+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
227
|
+
*/
|
|
228
|
+
uint256[50] private __gap;
|
|
213
229
|
}
|
package/contracts/RiskModule.sol
CHANGED
|
@@ -22,6 +22,12 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
22
22
|
using SafeCast for uint256;
|
|
23
23
|
|
|
24
24
|
uint256 internal constant SECONDS_IN_YEAR_WAD = 31536000e18; /* 365 * 24 * 3600 * 10e18 */
|
|
25
|
+
uint16 internal constant HOURS_PER_YEAR = 8760; /* 24 * 365 */
|
|
26
|
+
|
|
27
|
+
uint256 internal constant FOUR_DECIMAL_TO_WAD = 1e14;
|
|
28
|
+
uint16 internal constant HUNDRED_PERCENT = 1e4;
|
|
29
|
+
uint16 internal constant MIN_MOC = 5e3;
|
|
30
|
+
uint16 internal constant MAX_MOC = 4e4;
|
|
25
31
|
|
|
26
32
|
// For parameters that can be changed by the risk module provider
|
|
27
33
|
bytes32 public constant RM_PROVIDER_ROLE = keccak256("RM_PROVIDER_ROLE");
|
|
@@ -80,7 +86,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
80
86
|
uint256 maxPayoutPerPolicy_,
|
|
81
87
|
uint256 exposureLimit_,
|
|
82
88
|
address wallet_
|
|
83
|
-
) internal
|
|
89
|
+
) internal onlyInitializing {
|
|
84
90
|
__PolicyPoolComponent_init();
|
|
85
91
|
__RiskModule_init_unchained(
|
|
86
92
|
name_,
|
|
@@ -102,10 +108,10 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
102
108
|
uint256 maxPayoutPerPolicy_,
|
|
103
109
|
uint256 exposureLimit_,
|
|
104
110
|
address wallet_
|
|
105
|
-
) internal
|
|
111
|
+
) internal onlyInitializing {
|
|
106
112
|
_name = name_;
|
|
107
113
|
_params = PackedParams({
|
|
108
|
-
moc:
|
|
114
|
+
moc: HUNDRED_PERCENT,
|
|
109
115
|
jrCollRatio: 0,
|
|
110
116
|
collRatio: _wadTo4(collRatio_),
|
|
111
117
|
ensuroPpFee: _wadTo4(ensuroPpFee_),
|
|
@@ -114,23 +120,33 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
114
120
|
srRoc: _wadTo4(srRoc_),
|
|
115
121
|
maxPayoutPerPolicy: _amountToX(2, maxPayoutPerPolicy_),
|
|
116
122
|
exposureLimit: _amountToX(0, exposureLimit_),
|
|
117
|
-
maxDuration:
|
|
123
|
+
maxDuration: HOURS_PER_YEAR
|
|
118
124
|
});
|
|
119
125
|
_activeExposure = 0;
|
|
120
126
|
_wallet = wallet_;
|
|
121
127
|
_validateParameters();
|
|
122
128
|
}
|
|
123
129
|
|
|
130
|
+
/**
|
|
131
|
+
* @dev See {IERC165-supportsInterface}.
|
|
132
|
+
*/
|
|
133
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
134
|
+
return super.supportsInterface(interfaceId) || interfaceId == type(IRiskModule).interfaceId;
|
|
135
|
+
}
|
|
136
|
+
|
|
124
137
|
// runs validation on RiskModule parameters
|
|
125
138
|
function _validateParameters() internal view override {
|
|
126
|
-
require(_params.jrCollRatio <=
|
|
127
|
-
require(
|
|
139
|
+
require(_params.jrCollRatio <= HUNDRED_PERCENT, "Validation: jrCollRatio must be <=1");
|
|
140
|
+
require(
|
|
141
|
+
_params.collRatio <= HUNDRED_PERCENT && _params.collRatio > 0,
|
|
142
|
+
"Validation: collRatio must be <=1"
|
|
143
|
+
);
|
|
128
144
|
require(_params.collRatio >= _params.jrCollRatio, "Validation: collRatio >= jrCollRatio");
|
|
129
|
-
require(_params.moc <=
|
|
130
|
-
require(_params.ensuroPpFee <=
|
|
131
|
-
require(_params.ensuroCocFee <=
|
|
132
|
-
require(_params.srRoc <=
|
|
133
|
-
require(_params.jrRoc <=
|
|
145
|
+
require(_params.moc <= MAX_MOC && _params.moc >= MIN_MOC, "Validation: moc must be [0.5, 4]");
|
|
146
|
+
require(_params.ensuroPpFee <= HUNDRED_PERCENT, "Validation: ensuroPpFee must be <= 1");
|
|
147
|
+
require(_params.ensuroCocFee <= HUNDRED_PERCENT, "Validation: ensuroCocFee must be <= 1");
|
|
148
|
+
require(_params.srRoc <= HUNDRED_PERCENT, "Validation: srRoc must be <= 1 (100%)");
|
|
149
|
+
require(_params.jrRoc <= HUNDRED_PERCENT, "Validation: jrRoc must be <= 1 (100%)");
|
|
134
150
|
// _maxPayoutPerPolicy no limits
|
|
135
151
|
require(
|
|
136
152
|
exposureLimit() >= _activeExposure,
|
|
@@ -150,12 +166,12 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
150
166
|
// solhint-disable-next-line func-name-mixedcase
|
|
151
167
|
function _4toWad(uint16 value) internal pure returns (uint256) {
|
|
152
168
|
// 4 decimals to Wad (18 decimals)
|
|
153
|
-
return uint256(value) *
|
|
169
|
+
return uint256(value) * FOUR_DECIMAL_TO_WAD;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
function _wadTo4(uint256 value) internal pure returns (uint16) {
|
|
157
173
|
// Wad to 4 decimals
|
|
158
|
-
return (value /
|
|
174
|
+
return (value / FOUR_DECIMAL_TO_WAD).toUint16();
|
|
159
175
|
}
|
|
160
176
|
|
|
161
177
|
// solhint-disable-next-line func-name-mixedcase
|
|
@@ -262,6 +278,7 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
262
278
|
}
|
|
263
279
|
|
|
264
280
|
function setWallet(address wallet_) external onlyComponentRole(RM_PROVIDER_ROLE) {
|
|
281
|
+
require(wallet_ != address(0), "RiskModule: wallet cannot be the zero address");
|
|
265
282
|
_wallet = wallet_;
|
|
266
283
|
_parameterChanged(IAccessManager.GovernanceActions.setWallet, uint256(uint160(wallet_)), false);
|
|
267
284
|
}
|
|
@@ -358,4 +375,11 @@ abstract contract RiskModule is IRiskModule, PolicyPoolComponent {
|
|
|
358
375
|
function premiumsAccount() external view override returns (IPremiumsAccount) {
|
|
359
376
|
return _premiumsAccount;
|
|
360
377
|
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* @dev This empty reserved space is put in place to allow future versions to add new
|
|
381
|
+
* variables without shifting down storage in the inheritance chain.
|
|
382
|
+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
383
|
+
*/
|
|
384
|
+
uint256[46] private __gap;
|
|
361
385
|
}
|
|
@@ -238,4 +238,11 @@ contract SignedQuoteRiskModule is RiskModule {
|
|
|
238
238
|
{
|
|
239
239
|
_policyPool.resolvePolicyFullPayout(policy, customerWon);
|
|
240
240
|
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @dev This empty reserved space is put in place to allow future versions to add new
|
|
244
|
+
* variables without shifting down storage in the inheritance chain.
|
|
245
|
+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
246
|
+
*/
|
|
247
|
+
uint256[50] private __gap;
|
|
241
248
|
}
|
|
@@ -140,4 +140,11 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
140
140
|
{
|
|
141
141
|
_policyPool.resolvePolicyFullPayout(policy, customerWon);
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @dev This empty reserved space is put in place to allow future versions to add new
|
|
146
|
+
* variables without shifting down storage in the inheritance chain.
|
|
147
|
+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
148
|
+
*/
|
|
149
|
+
uint256[50] private __gap;
|
|
143
150
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @title IAssetManager - Interface of the asset management strategy that's plugged into the reserves
|
|
6
8
|
* @dev The asset manager is a contract that's plugged and called with `delegatecall` (operates in the context of the
|
|
7
9
|
* reserve - see {Reserve}). The asset manager contract applies a strategy to invest the reserve funds and
|
|
8
10
|
* get additional yields.
|
|
11
|
+
*
|
|
12
|
+
* All implementations of this contract should use the Diamond Storage pattern to avoid overwriting the calling contract's state.
|
|
13
|
+
* See https://eips.ethereum.org/EIPS/eip-2535#storage
|
|
9
14
|
* @author Ensuro
|
|
10
15
|
*/
|
|
11
|
-
interface IAssetManager {
|
|
16
|
+
interface IAssetManager is IERC165 {
|
|
12
17
|
/**
|
|
13
18
|
* @dev Event emitted when funds are removed from Reserve liquidity and invested in the investment strategy,
|
|
14
19
|
* @param amount The amount invested
|
|
@@ -57,8 +62,8 @@ interface IAssetManager {
|
|
|
57
62
|
function recordEarnings() external returns (int256);
|
|
58
63
|
|
|
59
64
|
/**
|
|
60
|
-
* @dev Refills the reserve balance with
|
|
61
|
-
* to be made and there's no
|
|
65
|
+
* @dev Refills the reserve balance with enough money to do a payment. Called from the reserve when a payment needs
|
|
66
|
+
* to be made and there's no enough liquid balance (`currency().balanceOf(reserve) < paymentAmount`)
|
|
62
67
|
*
|
|
63
68
|
* Events:
|
|
64
69
|
* - Emits {MoneyDeinvested} with the amount transferred to the liquid balance.
|
|
@@ -137,7 +137,7 @@ interface IPolicyPool {
|
|
|
137
137
|
*
|
|
138
138
|
* @param eToken The address of the eToken from where the user wants to withdraw liquidity
|
|
139
139
|
* @param amount The amount to withdraw. If equal to type(uint256).max, means full withdrawal.
|
|
140
|
-
* If the balance is not
|
|
140
|
+
* If the balance is not enough or can't be withdrawn (locked as SCR), it withdraws
|
|
141
141
|
* as much as it can, but doesn't fails.
|
|
142
142
|
* @return Returns the actual amount withdrawn.
|
|
143
143
|
*/
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
import {IPolicyPool} from "./IPolicyPool.sol";
|
|
5
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title IPolicyPoolComponent interface
|
|
8
9
|
* @dev Interface for Contracts linked (owned) by a PolicyPool. Useful to avoid cyclic dependencies
|
|
9
10
|
* @author Ensuro
|
|
10
11
|
*/
|
|
11
|
-
interface IPolicyPoolComponent {
|
|
12
|
+
interface IPolicyPoolComponent is IERC165 {
|
|
12
13
|
/**
|
|
13
14
|
* @dev Returns the address of the PolicyPool (see {PolicyPool}) where this component belongs.
|
|
14
15
|
*/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
6
|
+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
7
|
+
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
8
|
+
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
9
|
+
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
10
|
+
import {IPolicyPoolComponent} from "../interfaces/IPolicyPoolComponent.sol";
|
|
11
|
+
import {IEToken} from "../interfaces/IEToken.sol";
|
|
12
|
+
import {IRiskModule} from "../interfaces/IRiskModule.sol";
|
|
13
|
+
import {IPremiumsAccount} from "../interfaces/IPremiumsAccount.sol";
|
|
14
|
+
import {ILPWhitelist} from "../interfaces/ILPWhitelist.sol";
|
|
15
|
+
import {IAccessManager} from "../interfaces/IAccessManager.sol";
|
|
16
|
+
import {IAssetManager} from "../interfaces/IAssetManager.sol";
|
|
17
|
+
|
|
18
|
+
contract InterfaceIdCalculator {
|
|
19
|
+
bytes4 public constant IERC165_INTERFACEID = type(IERC165).interfaceId;
|
|
20
|
+
bytes4 public constant IERC20_INTERFACEID = type(IERC20).interfaceId;
|
|
21
|
+
bytes4 public constant IERC20METADATA_INTERFACEID = type(IERC20Metadata).interfaceId;
|
|
22
|
+
bytes4 public constant IERC721_INTERFACEID = type(IERC721).interfaceId;
|
|
23
|
+
bytes4 public constant IACCESSCONTROL_INTERFACEID = type(IAccessControl).interfaceId;
|
|
24
|
+
bytes4 public constant IPOLICYPOOL_INTERFACEID = type(IPolicyPool).interfaceId;
|
|
25
|
+
bytes4 public constant IPOLICYPOOLCOMPONENT_INTERFACEID = type(IPolicyPoolComponent).interfaceId;
|
|
26
|
+
bytes4 public constant IETOKEN_INTERFACEID = type(IEToken).interfaceId;
|
|
27
|
+
bytes4 public constant IRISKMODULE_INTERFACEID = type(IRiskModule).interfaceId;
|
|
28
|
+
bytes4 public constant IPREMIUMSACCOUNT_INTERFACEID = type(IPremiumsAccount).interfaceId;
|
|
29
|
+
bytes4 public constant ILPWHITELIST_INTERFACEID = type(ILPWhitelist).interfaceId;
|
|
30
|
+
bytes4 public constant IACCESSMANAGER_INTERFACEID = type(IAccessManager).interfaceId;
|
|
31
|
+
bytes4 public constant IASSETMANAGER_INTERFACEID = type(IAssetManager).interfaceId;
|
|
32
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
4
5
|
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
5
6
|
import {IPolicyPoolComponent} from "../interfaces/IPolicyPoolComponent.sol";
|
|
6
7
|
|
|
@@ -14,4 +15,13 @@ contract PolicyPoolComponentMock is IPolicyPoolComponent {
|
|
|
14
15
|
function policyPool() external view override returns (IPolicyPool) {
|
|
15
16
|
return _policyPool;
|
|
16
17
|
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @dev See {IERC165-supportsInterface}.
|
|
21
|
+
*/
|
|
22
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
23
|
+
return
|
|
24
|
+
interfaceId == type(IERC165).interfaceId ||
|
|
25
|
+
interfaceId == type(IPolicyPoolComponent).interfaceId;
|
|
26
|
+
}
|
|
17
27
|
}
|