@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/PolicyPool.sol
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
5
4
|
import {AddressUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
|
|
6
|
-
import {
|
|
5
|
+
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
7
6
|
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
|
|
7
|
+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
8
|
+
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
|
|
8
9
|
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
10
|
+
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
11
|
+
|
|
9
12
|
import {IAccessManager} from "./interfaces/IAccessManager.sol";
|
|
10
|
-
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
|
|
11
|
-
import {IPremiumsAccount} from "./interfaces/IPremiumsAccount.sol";
|
|
12
|
-
import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
13
|
-
import {IRiskModule} from "./interfaces/IRiskModule.sol";
|
|
14
|
-
import {IPolicyPoolComponent} from "./interfaces/IPolicyPoolComponent.sol";
|
|
15
13
|
import {IEToken} from "./interfaces/IEToken.sol";
|
|
16
14
|
import {IPolicyHolder} from "./interfaces/IPolicyHolder.sol";
|
|
15
|
+
import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
16
|
+
import {IPolicyPoolComponent} from "./interfaces/IPolicyPoolComponent.sol";
|
|
17
|
+
import {IPremiumsAccount} from "./interfaces/IPremiumsAccount.sol";
|
|
18
|
+
import {IRiskModule} from "./interfaces/IRiskModule.sol";
|
|
17
19
|
import {Policy} from "./Policy.sol";
|
|
20
|
+
|
|
18
21
|
import {WadRayMath} from "./dependencies/WadRayMath.sol";
|
|
19
22
|
|
|
20
23
|
/**
|
|
@@ -156,11 +159,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
156
159
|
* @param kind Value indicating the kind of component. See {ComponentKind}
|
|
157
160
|
* @param newStatus The status of the component after the operation. See {ComponentStatus}
|
|
158
161
|
*/
|
|
159
|
-
event ComponentStatusChanged(
|
|
160
|
-
IPolicyPoolComponent indexed component,
|
|
161
|
-
ComponentKind kind,
|
|
162
|
-
ComponentStatus newStatus
|
|
163
|
-
);
|
|
162
|
+
event ComponentStatusChanged(IPolicyPoolComponent indexed component, ComponentKind kind, ComponentStatus newStatus);
|
|
164
163
|
|
|
165
164
|
/**
|
|
166
165
|
* @dev Modifier that checks the caller has a given role
|
|
@@ -201,11 +200,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
201
200
|
* @param symbol_ The symbol of the ERC721 token.
|
|
202
201
|
* @param treasury_ The address of the treasury that will receive the protocol fees.
|
|
203
202
|
*/
|
|
204
|
-
function initialize(
|
|
205
|
-
string memory name_,
|
|
206
|
-
string memory symbol_,
|
|
207
|
-
address treasury_
|
|
208
|
-
) public initializer {
|
|
203
|
+
function initialize(string memory name_, string memory symbol_, address treasury_) public initializer {
|
|
209
204
|
require(bytes(name_).length > 0, "PolicyPool: name cannot be empty");
|
|
210
205
|
require(bytes(symbol_).length > 0, "PolicyPool: symbol cannot be empty");
|
|
211
206
|
__UUPSUpgradeable_init();
|
|
@@ -226,12 +221,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
226
221
|
_setTreasury(treasury_);
|
|
227
222
|
}
|
|
228
223
|
|
|
229
|
-
function _authorizeUpgrade(address newImpl)
|
|
230
|
-
internal
|
|
231
|
-
view
|
|
232
|
-
override
|
|
233
|
-
onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
|
|
234
|
-
{
|
|
224
|
+
function _authorizeUpgrade(address newImpl) internal view override onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
|
|
235
225
|
IPolicyPool newPool = IPolicyPool(newImpl);
|
|
236
226
|
require(newPool.access() == _access, "Can't upgrade changing the access manager");
|
|
237
227
|
require(newPool.currency() == _currency, "Can't upgrade changing the currency");
|
|
@@ -307,20 +297,15 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
307
297
|
* to this specific {PolicyPool} and matching the `kind` specified in the next paramter.
|
|
308
298
|
* @param kind The type of component to be added.
|
|
309
299
|
*/
|
|
310
|
-
function addComponent(IPolicyPoolComponent component, ComponentKind kind)
|
|
311
|
-
external
|
|
312
|
-
onlyRole(LEVEL1_ROLE)
|
|
313
|
-
{
|
|
300
|
+
function addComponent(IPolicyPoolComponent component, ComponentKind kind) external onlyRole(LEVEL1_ROLE) {
|
|
314
301
|
Component storage comp = _components[component];
|
|
315
302
|
require(comp.status == ComponentStatus.inactive, "Component already in the pool");
|
|
316
303
|
require(component.policyPool() == this, "Component not linked to this pool");
|
|
317
304
|
|
|
318
305
|
require(
|
|
319
306
|
(kind == ComponentKind.eToken && component.supportsInterface(type(IEToken).interfaceId)) ||
|
|
320
|
-
(kind == ComponentKind.premiumsAccount &&
|
|
321
|
-
|
|
322
|
-
(kind == ComponentKind.riskModule &&
|
|
323
|
-
component.supportsInterface(type(IRiskModule).interfaceId)),
|
|
307
|
+
(kind == ComponentKind.premiumsAccount && component.supportsInterface(type(IPremiumsAccount).interfaceId)) ||
|
|
308
|
+
(kind == ComponentKind.riskModule && component.supportsInterface(type(IRiskModule).interfaceId)),
|
|
324
309
|
"PolicyPool: Not the right kind"
|
|
325
310
|
);
|
|
326
311
|
|
|
@@ -357,15 +342,9 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
357
342
|
Component storage comp = _components[component];
|
|
358
343
|
require(comp.status == ComponentStatus.deprecated, "Component not deprecated");
|
|
359
344
|
if (comp.kind == ComponentKind.eToken) {
|
|
360
|
-
require(
|
|
361
|
-
IEToken(address(component)).totalSupply() == 0,
|
|
362
|
-
"EToken has liquidity, can't be removed"
|
|
363
|
-
);
|
|
345
|
+
require(IEToken(address(component)).totalSupply() == 0, "EToken has liquidity, can't be removed");
|
|
364
346
|
} else if (comp.kind == ComponentKind.riskModule) {
|
|
365
|
-
require(
|
|
366
|
-
IRiskModule(address(component)).activeExposure() == 0,
|
|
367
|
-
"Can't remove a module with active policies"
|
|
368
|
-
);
|
|
347
|
+
require(IRiskModule(address(component)).activeExposure() == 0, "Can't remove a module with active policies");
|
|
369
348
|
} else if (comp.kind == ComponentKind.premiumsAccount) {
|
|
370
349
|
IPremiumsAccount pa = IPremiumsAccount(address(component));
|
|
371
350
|
require(pa.purePremiums() == 0, "Can't remove a PremiumsAccount with premiums");
|
|
@@ -395,10 +374,10 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
395
374
|
* @param component The address of component contract. Must be a component added before.
|
|
396
375
|
* @param newStatus The new status, must be either `active`, `deprecated` or `suspended`.
|
|
397
376
|
*/
|
|
398
|
-
function changeComponentStatus(
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
{
|
|
377
|
+
function changeComponentStatus(
|
|
378
|
+
IPolicyPoolComponent component,
|
|
379
|
+
ComponentStatus newStatus
|
|
380
|
+
) external onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
|
|
402
381
|
Component storage comp = _components[component];
|
|
403
382
|
require(comp.status != ComponentStatus.inactive, "Component not found");
|
|
404
383
|
require(
|
|
@@ -417,11 +396,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
417
396
|
* @param component The address of the component
|
|
418
397
|
* @return The status of the component. See {ComponentStatus}
|
|
419
398
|
*/
|
|
420
|
-
function getComponentStatus(IPolicyPoolComponent component)
|
|
421
|
-
external
|
|
422
|
-
view
|
|
423
|
-
returns (ComponentStatus)
|
|
424
|
-
{
|
|
399
|
+
function getComponentStatus(IPolicyPoolComponent component) external view returns (ComponentStatus) {
|
|
425
400
|
return _components[component].status;
|
|
426
401
|
}
|
|
427
402
|
|
|
@@ -450,12 +425,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
450
425
|
eToken.deposit(_msgSender(), _currency.balanceOf(address(eToken)) - balanceBefore);
|
|
451
426
|
}
|
|
452
427
|
|
|
453
|
-
function withdraw(IEToken eToken, uint256 amount)
|
|
454
|
-
external
|
|
455
|
-
override
|
|
456
|
-
whenNotPaused
|
|
457
|
-
returns (uint256)
|
|
458
|
-
{
|
|
428
|
+
function withdraw(IEToken eToken, uint256 amount) external override whenNotPaused returns (uint256) {
|
|
459
429
|
ComponentStatus etkStatus = _etkStatus(eToken);
|
|
460
430
|
require(
|
|
461
431
|
etkStatus == ComponentStatus.active || etkStatus == ComponentStatus.deprecated,
|
|
@@ -520,19 +490,14 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
520
490
|
}
|
|
521
491
|
}
|
|
522
492
|
|
|
523
|
-
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
|
|
524
|
-
external
|
|
525
|
-
override
|
|
526
|
-
whenNotPaused
|
|
527
|
-
{
|
|
493
|
+
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout) external override whenNotPaused {
|
|
528
494
|
return _resolvePolicy(policy, payout, false);
|
|
529
495
|
}
|
|
530
496
|
|
|
531
|
-
function resolvePolicyFullPayout(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
{
|
|
497
|
+
function resolvePolicyFullPayout(
|
|
498
|
+
Policy.PolicyData calldata policy,
|
|
499
|
+
bool customerWon
|
|
500
|
+
) external override whenNotPaused {
|
|
536
501
|
return _resolvePolicy(policy, customerWon ? policy.payout : 0, false);
|
|
537
502
|
}
|
|
538
503
|
|
|
@@ -555,11 +520,7 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
555
520
|
* @param payout The amount to paid to the policyholder
|
|
556
521
|
* @param expired True for expiration resolution (`payout` must be 0)
|
|
557
522
|
*/
|
|
558
|
-
function _resolvePolicy(
|
|
559
|
-
Policy.PolicyData memory policy,
|
|
560
|
-
uint256 payout,
|
|
561
|
-
bool expired
|
|
562
|
-
) internal {
|
|
523
|
+
function _resolvePolicy(Policy.PolicyData memory policy, uint256 payout, bool expired) internal {
|
|
563
524
|
// Checks
|
|
564
525
|
_validatePolicy(policy);
|
|
565
526
|
IRiskModule rm = policy.riskModule;
|
|
@@ -601,29 +562,16 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
601
562
|
}
|
|
602
563
|
|
|
603
564
|
/**
|
|
604
|
-
* @dev Notifies the payout with a callback if the policyholder is a contract
|
|
605
|
-
* contract explicitly reverts
|
|
565
|
+
* @dev Notifies the payout with a callback if the policyholder is a contract and implementes the IPolicyHolder interface.
|
|
566
|
+
* Only reverts if the policyholder contract explicitly reverts or it doesn't return the IPolicyHolder.onPayoutReceived selector.
|
|
606
567
|
*/
|
|
607
568
|
function _notifyPayout(uint256 policyId, uint256 payout) internal {
|
|
608
569
|
address customer = ownerOf(policyId);
|
|
609
570
|
if (!AddressUpgradeable.isContract(customer)) return;
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
retval == IPolicyHolder.onPayoutReceived.selector,
|
|
615
|
-
"Invalid return value from Policy Holder"
|
|
616
|
-
);
|
|
617
|
-
} catch (bytes memory reason) {
|
|
618
|
-
if (reason.length == 0) {
|
|
619
|
-
return; // Not implemented, it's fine
|
|
620
|
-
} else {
|
|
621
|
-
// solhint-disable-next-line no-inline-assembly
|
|
622
|
-
assembly {
|
|
623
|
-
revert(add(32, reason), mload(reason))
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
571
|
+
if (!ERC165Checker.supportsInterface(customer, type(IPolicyHolder).interfaceId)) return;
|
|
572
|
+
|
|
573
|
+
bytes4 retval = IPolicyHolder(customer).onPayoutReceived(_msgSender(), address(this), policyId, payout);
|
|
574
|
+
require(retval == IPolicyHolder.onPayoutReceived.selector, "PolicyPool: Invalid return value from IPolicyHolder");
|
|
627
575
|
}
|
|
628
576
|
|
|
629
577
|
/**
|
|
@@ -632,9 +580,9 @@ contract PolicyPool is IPolicyPool, PausableUpgradeable, UUPSUpgradeable, ERC721
|
|
|
632
580
|
function _notifyExpiration(uint256 policyId) internal {
|
|
633
581
|
address customer = ownerOf(policyId);
|
|
634
582
|
if (!AddressUpgradeable.isContract(customer)) return;
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
) {
|
|
583
|
+
if (!ERC165Checker.supportsInterface(customer, type(IPolicyHolder).interfaceId)) return;
|
|
584
|
+
|
|
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
|
|