@ensuro/core 2.7.0 → 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 +23 -75
- 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 +3 -13
- 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/deploy.js +44 -39
- package/js/test-utils.js +30 -19
- package/js/utils.js +62 -29
- 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 -319
- 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/PolicyPool.sol
CHANGED
|
@@ -159,11 +159,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
159
159
|
* @param kind Value indicating the kind of component. See {ComponentKind}
|
|
160
160
|
* @param newStatus The status of the component after the operation. See {ComponentStatus}
|
|
161
161
|
*/
|
|
162
|
-
event ComponentStatusChanged(
|
|
163
|
-
IPolicyPoolComponent indexed component,
|
|
164
|
-
ComponentKind kind,
|
|
165
|
-
ComponentStatus newStatus
|
|
166
|
-
);
|
|
162
|
+
event ComponentStatusChanged(IPolicyPoolComponent indexed component, ComponentKind kind, ComponentStatus newStatus);
|
|
167
163
|
|
|
168
164
|
/**
|
|
169
165
|
* @dev Modifier that checks the caller has a given role
|
|
@@ -204,11 +200,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
204
200
|
* @param symbol_ The symbol of the ERC721 token.
|
|
205
201
|
* @param treasury_ The address of the treasury that will receive the protocol fees.
|
|
206
202
|
*/
|
|
207
|
-
function initialize(
|
|
208
|
-
string memory name_,
|
|
209
|
-
string memory symbol_,
|
|
210
|
-
address treasury_
|
|
211
|
-
) public initializer {
|
|
203
|
+
function initialize(string memory name_, string memory symbol_, address treasury_) public initializer {
|
|
212
204
|
require(bytes(name_).length > 0, "PolicyPool: name cannot be empty");
|
|
213
205
|
require(bytes(symbol_).length > 0, "PolicyPool: symbol cannot be empty");
|
|
214
206
|
__UUPSUpgradeable_init();
|
|
@@ -229,12 +221,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
229
221
|
_setTreasury(treasury_);
|
|
230
222
|
}
|
|
231
223
|
|
|
232
|
-
function _authorizeUpgrade(address newImpl)
|
|
233
|
-
internal
|
|
234
|
-
view
|
|
235
|
-
override
|
|
236
|
-
onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
|
|
237
|
-
{
|
|
224
|
+
function _authorizeUpgrade(address newImpl) internal view override onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
|
|
238
225
|
IPolicyPool newPool = IPolicyPool(newImpl);
|
|
239
226
|
require(newPool.access() == _access, "Can't upgrade changing the access manager");
|
|
240
227
|
require(newPool.currency() == _currency, "Can't upgrade changing the currency");
|
|
@@ -310,20 +297,15 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
310
297
|
* to this specific {PolicyPool} and matching the `kind` specified in the next paramter.
|
|
311
298
|
* @param kind The type of component to be added.
|
|
312
299
|
*/
|
|
313
|
-
function addComponent(IPolicyPoolComponent component, ComponentKind kind)
|
|
314
|
-
external
|
|
315
|
-
onlyRole(LEVEL1_ROLE)
|
|
316
|
-
{
|
|
300
|
+
function addComponent(IPolicyPoolComponent component, ComponentKind kind) external onlyRole(LEVEL1_ROLE) {
|
|
317
301
|
Component storage comp = _components[component];
|
|
318
302
|
require(comp.status == ComponentStatus.inactive, "Component already in the pool");
|
|
319
303
|
require(component.policyPool() == this, "Component not linked to this pool");
|
|
320
304
|
|
|
321
305
|
require(
|
|
322
306
|
(kind == ComponentKind.eToken && component.supportsInterface(type(IEToken).interfaceId)) ||
|
|
323
|
-
(kind == ComponentKind.premiumsAccount &&
|
|
324
|
-
|
|
325
|
-
(kind == ComponentKind.riskModule &&
|
|
326
|
-
component.supportsInterface(type(IRiskModule).interfaceId)),
|
|
307
|
+
(kind == ComponentKind.premiumsAccount && component.supportsInterface(type(IPremiumsAccount).interfaceId)) ||
|
|
308
|
+
(kind == ComponentKind.riskModule && component.supportsInterface(type(IRiskModule).interfaceId)),
|
|
327
309
|
"PolicyPool: Not the right kind"
|
|
328
310
|
);
|
|
329
311
|
|
|
@@ -360,15 +342,9 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
360
342
|
Component storage comp = _components[component];
|
|
361
343
|
require(comp.status == ComponentStatus.deprecated, "Component not deprecated");
|
|
362
344
|
if (comp.kind == ComponentKind.eToken) {
|
|
363
|
-
require(
|
|
364
|
-
IEToken(address(component)).totalSupply() == 0,
|
|
365
|
-
"EToken has liquidity, can't be removed"
|
|
366
|
-
);
|
|
345
|
+
require(IEToken(address(component)).totalSupply() == 0, "EToken has liquidity, can't be removed");
|
|
367
346
|
} else if (comp.kind == ComponentKind.riskModule) {
|
|
368
|
-
require(
|
|
369
|
-
IRiskModule(address(component)).activeExposure() == 0,
|
|
370
|
-
"Can't remove a module with active policies"
|
|
371
|
-
);
|
|
347
|
+
require(IRiskModule(address(component)).activeExposure() == 0, "Can't remove a module with active policies");
|
|
372
348
|
} else if (comp.kind == ComponentKind.premiumsAccount) {
|
|
373
349
|
IPremiumsAccount pa = IPremiumsAccount(address(component));
|
|
374
350
|
require(pa.purePremiums() == 0, "Can't remove a PremiumsAccount with premiums");
|
|
@@ -398,10 +374,10 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
398
374
|
* @param component The address of component contract. Must be a component added before.
|
|
399
375
|
* @param newStatus The new status, must be either `active`, `deprecated` or `suspended`.
|
|
400
376
|
*/
|
|
401
|
-
function changeComponentStatus(
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
{
|
|
377
|
+
function changeComponentStatus(
|
|
378
|
+
IPolicyPoolComponent component,
|
|
379
|
+
ComponentStatus newStatus
|
|
380
|
+
) external onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
|
|
405
381
|
Component storage comp = _components[component];
|
|
406
382
|
require(comp.status != ComponentStatus.inactive, "Component not found");
|
|
407
383
|
require(
|
|
@@ -420,11 +396,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
420
396
|
* @param component The address of the component
|
|
421
397
|
* @return The status of the component. See {ComponentStatus}
|
|
422
398
|
*/
|
|
423
|
-
function getComponentStatus(IPolicyPoolComponent component)
|
|
424
|
-
external
|
|
425
|
-
view
|
|
426
|
-
returns (ComponentStatus)
|
|
427
|
-
{
|
|
399
|
+
function getComponentStatus(IPolicyPoolComponent component) external view returns (ComponentStatus) {
|
|
428
400
|
return _components[component].status;
|
|
429
401
|
}
|
|
430
402
|
|
|
@@ -453,12 +425,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
453
425
|
eToken.deposit(_msgSender(), _currency.balanceOf(address(eToken)) - balanceBefore);
|
|
454
426
|
}
|
|
455
427
|
|
|
456
|
-
function withdraw(IEToken eToken, uint256 amount)
|
|
457
|
-
external
|
|
458
|
-
override
|
|
459
|
-
whenNotPaused
|
|
460
|
-
returns (uint256)
|
|
461
|
-
{
|
|
428
|
+
function withdraw(IEToken eToken, uint256 amount) external override whenNotPaused returns (uint256) {
|
|
462
429
|
ComponentStatus etkStatus = _etkStatus(eToken);
|
|
463
430
|
require(
|
|
464
431
|
etkStatus == ComponentStatus.active || etkStatus == ComponentStatus.deprecated,
|
|
@@ -523,19 +490,14 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
523
490
|
}
|
|
524
491
|
}
|
|
525
492
|
|
|
526
|
-
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
|
|
527
|
-
external
|
|
528
|
-
override
|
|
529
|
-
whenNotPaused
|
|
530
|
-
{
|
|
493
|
+
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout) external override whenNotPaused {
|
|
531
494
|
return _resolvePolicy(policy, payout, false);
|
|
532
495
|
}
|
|
533
496
|
|
|
534
|
-
function resolvePolicyFullPayout(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
{
|
|
497
|
+
function resolvePolicyFullPayout(
|
|
498
|
+
Policy.PolicyData calldata policy,
|
|
499
|
+
bool customerWon
|
|
500
|
+
) external override whenNotPaused {
|
|
539
501
|
return _resolvePolicy(policy, customerWon ? policy.payout : 0, false);
|
|
540
502
|
}
|
|
541
503
|
|
|
@@ -558,11 +520,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
558
520
|
* @param payout The amount to paid to the policyholder
|
|
559
521
|
* @param expired True for expiration resolution (`payout` must be 0)
|
|
560
522
|
*/
|
|
561
|
-
function _resolvePolicy(
|
|
562
|
-
Policy.PolicyData memory policy,
|
|
563
|
-
uint256 payout,
|
|
564
|
-
bool expired
|
|
565
|
-
) internal {
|
|
523
|
+
function _resolvePolicy(Policy.PolicyData memory policy, uint256 payout, bool expired) internal {
|
|
566
524
|
// Checks
|
|
567
525
|
_validatePolicy(policy);
|
|
568
526
|
IRiskModule rm = policy.riskModule;
|
|
@@ -612,16 +570,8 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
612
570
|
if (!AddressUpgradeable.isContract(customer)) return;
|
|
613
571
|
if (!ERC165Checker.supportsInterface(customer, type(IPolicyHolder).interfaceId)) return;
|
|
614
572
|
|
|
615
|
-
bytes4 retval = IPolicyHolder(customer).onPayoutReceived(
|
|
616
|
-
|
|
617
|
-
address(this),
|
|
618
|
-
policyId,
|
|
619
|
-
payout
|
|
620
|
-
);
|
|
621
|
-
require(
|
|
622
|
-
retval == IPolicyHolder.onPayoutReceived.selector,
|
|
623
|
-
"PolicyPool: Invalid return value from IPolicyHolder"
|
|
624
|
-
);
|
|
573
|
+
bytes4 retval = IPolicyHolder(customer).onPayoutReceived(_msgSender(), address(this), policyId, payout);
|
|
574
|
+
require(retval == IPolicyHolder.onPayoutReceived.selector, "PolicyPool: Invalid return value from IPolicyHolder");
|
|
625
575
|
}
|
|
626
576
|
|
|
627
577
|
/**
|
|
@@ -632,9 +582,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
632
582
|
if (!AddressUpgradeable.isContract(customer)) return;
|
|
633
583
|
if (!ERC165Checker.supportsInterface(customer, type(IPolicyHolder).interfaceId)) return;
|
|
634
584
|
|
|
635
|
-
try IPolicyHolder(customer).onPolicyExpired(_msgSender(), address(this), policyId) returns (
|
|
636
|
-
bytes4
|
|
637
|
-
) {
|
|
585
|
+
try IPolicyHolder(customer).onPolicyExpired(_msgSender(), address(this), policyId) returns (bytes4) {
|
|
638
586
|
return;
|
|
639
587
|
} catch {
|
|
640
588
|
return;
|
|
@@ -24,11 +24,7 @@ import {WadRayMath} from "./dependencies/WadRayMath.sol";
|
|
|
24
24
|
* @custom:security-contact security@ensuro.co
|
|
25
25
|
* @author Ensuro
|
|
26
26
|
*/
|
|
27
|
-
abstract contract PolicyPoolComponent is
|
|
28
|
-
UUPSUpgradeable,
|
|
29
|
-
PausableUpgradeable,
|
|
30
|
-
IPolicyPoolComponent
|
|
31
|
-
{
|
|
27
|
+
abstract contract PolicyPoolComponent is UUPSUpgradeable, PausableUpgradeable, IPolicyPoolComponent {
|
|
32
28
|
using WadRayMath for uint256;
|
|
33
29
|
|
|
34
30
|
bytes32 public constant GUARDIAN_ROLE = keccak256("GUARDIAN_ROLE");
|
|
@@ -80,10 +76,7 @@ abstract contract PolicyPoolComponent is
|
|
|
80
76
|
|
|
81
77
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
82
78
|
constructor(IPolicyPool policyPool_) {
|
|
83
|
-
require(
|
|
84
|
-
address(policyPool_) != address(0),
|
|
85
|
-
"PolicyPoolComponent: policyPool cannot be zero address"
|
|
86
|
-
);
|
|
79
|
+
require(address(policyPool_) != address(0), "PolicyPoolComponent: policyPool cannot be zero address");
|
|
87
80
|
_disableInitializers();
|
|
88
81
|
_policyPool = policyPool_;
|
|
89
82
|
}
|
|
@@ -94,29 +87,21 @@ abstract contract PolicyPoolComponent is
|
|
|
94
87
|
__Pausable_init();
|
|
95
88
|
}
|
|
96
89
|
|
|
97
|
-
function _authorizeUpgrade(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
override
|
|
101
|
-
onlyGlobalOrComponentRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
|
|
102
|
-
{
|
|
90
|
+
function _authorizeUpgrade(
|
|
91
|
+
address newImpl
|
|
92
|
+
) internal view override onlyGlobalOrComponentRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
|
|
103
93
|
_upgradeValidations(newImpl);
|
|
104
94
|
}
|
|
105
95
|
|
|
106
96
|
function _upgradeValidations(address newImpl) internal view virtual {
|
|
107
|
-
require(
|
|
108
|
-
IPolicyPoolComponent(newImpl).policyPool() == _policyPool,
|
|
109
|
-
"Can't upgrade changing the PolicyPool!"
|
|
110
|
-
);
|
|
97
|
+
require(IPolicyPoolComponent(newImpl).policyPool() == _policyPool, "Can't upgrade changing the PolicyPool!");
|
|
111
98
|
}
|
|
112
99
|
|
|
113
100
|
/**
|
|
114
101
|
* @dev See {IERC165-supportsInterface}.
|
|
115
102
|
*/
|
|
116
103
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
117
|
-
return
|
|
118
|
-
interfaceId == type(IERC165).interfaceId ||
|
|
119
|
-
interfaceId == type(IPolicyPoolComponent).interfaceId;
|
|
104
|
+
return interfaceId == type(IERC165).interfaceId || interfaceId == type(IPolicyPoolComponent).interfaceId;
|
|
120
105
|
}
|
|
121
106
|
|
|
122
107
|
function pause() public onlyGlobalOrComponentRole(GUARDIAN_ROLE) {
|
|
@@ -139,11 +124,7 @@ abstract contract PolicyPoolComponent is
|
|
|
139
124
|
return _policyPool.access().hasComponentRole(address(this), role, _msgSender(), true);
|
|
140
125
|
}
|
|
141
126
|
|
|
142
|
-
function _isTweakWad(
|
|
143
|
-
uint256 oldValue,
|
|
144
|
-
uint256 newValue,
|
|
145
|
-
uint256 maxTweak
|
|
146
|
-
) internal pure returns (bool) {
|
|
127
|
+
function _isTweakWad(uint256 oldValue, uint256 newValue, uint256 maxTweak) internal pure returns (bool) {
|
|
147
128
|
if (oldValue == newValue) return true;
|
|
148
129
|
if (oldValue == 0) return maxTweak >= WadRayMath.WAD;
|
|
149
130
|
if (newValue == 0) return false;
|
|
@@ -157,11 +138,7 @@ abstract contract PolicyPoolComponent is
|
|
|
157
138
|
// solhint-disable-next-line no-empty-blocks
|
|
158
139
|
function _validateParameters() internal view virtual {} // Must be reimplemented with specific validations
|
|
159
140
|
|
|
160
|
-
function _parameterChanged(
|
|
161
|
-
IAccessManager.GovernanceActions action,
|
|
162
|
-
uint256 value,
|
|
163
|
-
bool tweak
|
|
164
|
-
) internal {
|
|
141
|
+
function _parameterChanged(IAccessManager.GovernanceActions action, uint256 value, bool tweak) internal {
|
|
165
142
|
_validateParameters();
|
|
166
143
|
if (tweak) _registerTweak(action);
|
|
167
144
|
emit GovernanceAction(action, value);
|
|
@@ -113,11 +113,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
113
113
|
* @param seniorEtk_ Address of the Senior EToken (2nd loss lender). `address(0)` if not present.
|
|
114
114
|
*/
|
|
115
115
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
116
|
-
constructor(
|
|
117
|
-
IPolicyPool policyPool_,
|
|
118
|
-
IEToken juniorEtk_,
|
|
119
|
-
IEToken seniorEtk_
|
|
120
|
-
) Reserve(policyPool_) {
|
|
116
|
+
constructor(IPolicyPool policyPool_, IEToken juniorEtk_, IEToken seniorEtk_) Reserve(policyPool_) {
|
|
121
117
|
_juniorEtk = juniorEtk_;
|
|
122
118
|
_seniorEtk = seniorEtk_;
|
|
123
119
|
}
|
|
@@ -169,8 +165,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
169
165
|
* @dev See {IERC165-supportsInterface}.
|
|
170
166
|
*/
|
|
171
167
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
172
|
-
return
|
|
173
|
-
super.supportsInterface(interfaceId) || interfaceId == type(IPremiumsAccount).interfaceId;
|
|
168
|
+
return super.supportsInterface(interfaceId) || interfaceId == type(IPremiumsAccount).interfaceId;
|
|
174
169
|
}
|
|
175
170
|
|
|
176
171
|
function assetManager() public view override returns (IAssetManager) {
|
|
@@ -274,12 +269,12 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
274
269
|
|
|
275
270
|
function _toAmount(uint32 value) internal view returns (uint256) {
|
|
276
271
|
// 0 decimals to amount decimals
|
|
277
|
-
return uint256(value) * 10**currency().decimals();
|
|
272
|
+
return uint256(value) * 10 ** currency().decimals();
|
|
278
273
|
}
|
|
279
274
|
|
|
280
275
|
function _toZeroDecimals(uint256 amount) internal view returns (uint32) {
|
|
281
276
|
// Removes the decimals from the amount
|
|
282
|
-
return (amount / 10**currency().decimals()).toUint32();
|
|
277
|
+
return (amount / 10 ** currency().decimals()).toUint32();
|
|
283
278
|
}
|
|
284
279
|
|
|
285
280
|
/**
|
|
@@ -316,15 +311,9 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
316
311
|
* `_maxDeficit()` and borrows the difference from the eTokens.
|
|
317
312
|
* If false and the new ratio leaves `_surplus < -_maxDeficit()`, the operation is reverted.
|
|
318
313
|
*/
|
|
319
|
-
function setDeficitRatio(uint256 newRatio, bool adjustment)
|
|
320
|
-
external
|
|
321
|
-
onlyGlobalOrComponentRole(LEVEL2_ROLE)
|
|
322
|
-
{
|
|
314
|
+
function setDeficitRatio(uint256 newRatio, bool adjustment) external onlyGlobalOrComponentRole(LEVEL2_ROLE) {
|
|
323
315
|
uint16 truncatedRatio = (newRatio / FOUR_DECIMAL_TO_WAD).toUint16();
|
|
324
|
-
require(
|
|
325
|
-
uint256(truncatedRatio) * FOUR_DECIMAL_TO_WAD == newRatio,
|
|
326
|
-
"Validation: only up to 4 decimals allowed"
|
|
327
|
-
);
|
|
316
|
+
require(uint256(truncatedRatio) * FOUR_DECIMAL_TO_WAD == newRatio, "Validation: only up to 4 decimals allowed");
|
|
328
317
|
|
|
329
318
|
int256 maxDeficit = _maxDeficit(newRatio);
|
|
330
319
|
require(adjustment || _surplus >= maxDeficit, "Validation: surplus must be >= maxDeficit");
|
|
@@ -356,10 +345,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
356
345
|
* @param newLimitSr The new limit to be set for the loans taken from the Senior eToken.
|
|
357
346
|
If newLimitSr == MAX_UINT, it's ignored. If == 0, means the loans are unbounded.
|
|
358
347
|
*/
|
|
359
|
-
function setLoanLimits(uint256 newLimitJr, uint256 newLimitSr)
|
|
360
|
-
external
|
|
361
|
-
onlyGlobalOrComponentRole(LEVEL2_ROLE)
|
|
362
|
-
{
|
|
348
|
+
function setLoanLimits(uint256 newLimitJr, uint256 newLimitSr) external onlyGlobalOrComponentRole(LEVEL2_ROLE) {
|
|
363
349
|
if (newLimitJr != type(uint256).max) {
|
|
364
350
|
_params.jrLoanLimit = _toZeroDecimals(newLimitJr);
|
|
365
351
|
require(_toAmount(_params.jrLoanLimit) == newLimitJr, "Validation: no decimals allowed");
|
|
@@ -381,11 +367,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
381
367
|
* in the context of a policy payout.
|
|
382
368
|
* @param jrEtk If true it indicates that the loan is asked first from the junior eToken.
|
|
383
369
|
*/
|
|
384
|
-
function _borrowFromEtk(
|
|
385
|
-
uint256 borrow,
|
|
386
|
-
address receiver,
|
|
387
|
-
bool jrEtk
|
|
388
|
-
) internal {
|
|
370
|
+
function _borrowFromEtk(uint256 borrow, address receiver, bool jrEtk) internal {
|
|
389
371
|
uint256 left = borrow;
|
|
390
372
|
if (jrEtk) {
|
|
391
373
|
if (_juniorEtk.getLoan(address(this)) + borrow <= jrLoanLimit()) {
|
|
@@ -471,11 +453,10 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
471
453
|
* @param destination The address that will receive the transferred funds.
|
|
472
454
|
* @return Returns the actual amount withdrawn.
|
|
473
455
|
*/
|
|
474
|
-
function withdrawWonPremiums(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
{
|
|
456
|
+
function withdrawWonPremiums(
|
|
457
|
+
uint256 amount,
|
|
458
|
+
address destination
|
|
459
|
+
) external onlyGlobalOrComponentRole(WITHDRAW_WON_PREMIUMS_ROLE) returns (uint256) {
|
|
479
460
|
require(destination != address(0), "PremiumsAccount: destination cannot be the zero address");
|
|
480
461
|
if (_surplus <= 0) {
|
|
481
462
|
amount = 0;
|
|
@@ -489,12 +470,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
489
470
|
return amount;
|
|
490
471
|
}
|
|
491
472
|
|
|
492
|
-
function policyCreated(Policy.PolicyData memory policy)
|
|
493
|
-
external
|
|
494
|
-
override
|
|
495
|
-
onlyPolicyPool
|
|
496
|
-
whenNotPaused
|
|
497
|
-
{
|
|
473
|
+
function policyCreated(Policy.PolicyData memory policy) external override onlyPolicyPool whenNotPaused {
|
|
498
474
|
_activePurePremiums += policy.purePremium;
|
|
499
475
|
if (policy.jrScr > 0) _juniorEtk.lockScr(policy.jrScr, policy.jrInterestRate());
|
|
500
476
|
if (policy.srScr > 0) _seniorEtk.lockScr(policy.srScr, policy.srInterestRate());
|
|
@@ -550,10 +526,8 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
550
526
|
returns (uint256 available)
|
|
551
527
|
{
|
|
552
528
|
available = fundsAvailable();
|
|
553
|
-
if (available != 0 && address(_seniorEtk) != address(0))
|
|
554
|
-
|
|
555
|
-
if (available != 0 && address(_juniorEtk) != address(0))
|
|
556
|
-
available = _repayLoan(available, _juniorEtk);
|
|
529
|
+
if (available != 0 && address(_seniorEtk) != address(0)) available = _repayLoan(available, _seniorEtk);
|
|
530
|
+
if (available != 0 && address(_juniorEtk) != address(0)) available = _repayLoan(available, _juniorEtk);
|
|
557
531
|
return available;
|
|
558
532
|
}
|
|
559
533
|
|
|
@@ -589,12 +563,7 @@ contract PremiumsAccount is IPremiumsAccount, Reserve {
|
|
|
589
563
|
return fundsAvailable_ - repayAmount;
|
|
590
564
|
}
|
|
591
565
|
|
|
592
|
-
function policyExpired(Policy.PolicyData memory policy)
|
|
593
|
-
external
|
|
594
|
-
override
|
|
595
|
-
onlyPolicyPool
|
|
596
|
-
whenNotPaused
|
|
597
|
-
{
|
|
566
|
+
function policyExpired(Policy.PolicyData memory policy) external override onlyPolicyPool whenNotPaused {
|
|
598
567
|
_activePurePremiums -= policy.purePremium;
|
|
599
568
|
_storePurePremiumWon(policy.purePremium);
|
|
600
569
|
_unlockScr(policy);
|
package/contracts/Reserve.sol
CHANGED
|
@@ -36,7 +36,7 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
36
36
|
*/
|
|
37
37
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
38
38
|
constructor(IPolicyPool policyPool_) PolicyPoolComponent(policyPool_) {
|
|
39
|
-
NEGLIGIBLE_AMOUNT = 10**(policyPool_.currency().decimals() / 2);
|
|
39
|
+
NEGLIGIBLE_AMOUNT = 10 ** (policyPool_.currency().decimals() / 2);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -130,10 +130,10 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
130
130
|
* `force` is true, an error in the deinvestAll() operation is ignored. When `force` is false, if `deinvestAll()`
|
|
131
131
|
* fails, it reverts.
|
|
132
132
|
*/
|
|
133
|
-
function setAssetManager(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
{
|
|
133
|
+
function setAssetManager(
|
|
134
|
+
IAssetManager newAM,
|
|
135
|
+
bool force
|
|
136
|
+
) external onlyGlobalOrComponentRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
|
|
137
137
|
require(
|
|
138
138
|
address(newAM) == address(0) || newAM.supportsInterface(type(IAssetManager).interfaceId),
|
|
139
139
|
"Reserve: asset manager doesn't implements the required interface"
|
|
@@ -158,9 +158,7 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
158
158
|
* the storage in the connect() method (as it is the recommended practice in normal changes of AM).
|
|
159
159
|
*/
|
|
160
160
|
} else {
|
|
161
|
-
bytes memory result = am.functionDelegateCall(
|
|
162
|
-
abi.encodeWithSelector(IAssetManager.deinvestAll.selector)
|
|
163
|
-
);
|
|
161
|
+
bytes memory result = am.functionDelegateCall(abi.encodeWithSelector(IAssetManager.deinvestAll.selector));
|
|
164
162
|
_assetEarnings(abi.decode(result, (int256)));
|
|
165
163
|
}
|
|
166
164
|
}
|
|
@@ -179,9 +177,7 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
179
177
|
* - Emits {IAssetManager-MoneyInvested} or {IAssetManager-MoneyDeinvested}
|
|
180
178
|
*/
|
|
181
179
|
function rebalance() public whenNotPaused {
|
|
182
|
-
address(assetManager()).functionDelegateCall(
|
|
183
|
-
abi.encodeWithSelector(IAssetManager.rebalance.selector)
|
|
184
|
-
);
|
|
180
|
+
address(assetManager()).functionDelegateCall(abi.encodeWithSelector(IAssetManager.rebalance.selector));
|
|
185
181
|
}
|
|
186
182
|
|
|
187
183
|
/**
|
|
@@ -217,11 +213,9 @@ abstract contract Reserve is PolicyPoolComponent {
|
|
|
217
213
|
* @param functionCall Abi encoded function call to make.
|
|
218
214
|
* @return Returns the return value of the function called, to be decoded by the receiver.
|
|
219
215
|
*/
|
|
220
|
-
function forwardToAssetManager(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
returns (bytes memory)
|
|
224
|
-
{
|
|
216
|
+
function forwardToAssetManager(
|
|
217
|
+
bytes memory functionCall
|
|
218
|
+
) external onlyGlobalOrComponentRole(LEVEL2_ROLE) returns (bytes memory) {
|
|
225
219
|
return address(assetManager()).functionDelegateCall(functionCall);
|
|
226
220
|
}
|
|
227
221
|
|
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);
|