@ensuro/core 2.7.0 → 2.8.0-beta2
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 -7
- 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 +10 -20
- package/contracts/PolicyPool.sol +110 -127
- package/contracts/PolicyPoolComponent.sol +9 -32
- package/contracts/PremiumsAccount.sol +41 -47
- package/contracts/Reserve.sol +10 -16
- package/contracts/RiskModule.sol +74 -83
- 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 +47 -42
- 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/IPolicyPool.sol +59 -3
- package/contracts/interfaces/IPremiumsAccount.sol +17 -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/InterfaceIdCalculator.sol +2 -0
- package/contracts/mocks/PolicyHolderMock.sol +3 -13
- package/contracts/mocks/PolicyPoolComponentMock.sol +1 -3
- package/contracts/mocks/PolicyPoolMock.sol +25 -25
- package/contracts/mocks/RiskModuleMock.sol +39 -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/TimeScaled.sol
CHANGED
|
@@ -35,11 +35,7 @@ library TimeScaled {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function getScale(ScaledAmount storage scaledAmount, uint256 interestRate)
|
|
39
|
-
internal
|
|
40
|
-
view
|
|
41
|
-
returns (uint256)
|
|
42
|
-
{
|
|
38
|
+
function getScale(ScaledAmount storage scaledAmount, uint256 interestRate) internal view returns (uint256) {
|
|
43
39
|
uint32 now_ = uint32(block.timestamp);
|
|
44
40
|
if (scaledAmount.lastUpdate >= now_) {
|
|
45
41
|
return scaledAmount.scale;
|
|
@@ -51,16 +47,8 @@ library TimeScaled {
|
|
|
51
47
|
);
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
function getScaledAmount(ScaledAmount storage scaledAmount, uint256 interestRate)
|
|
55
|
-
|
|
56
|
-
view
|
|
57
|
-
returns (uint256)
|
|
58
|
-
{
|
|
59
|
-
return
|
|
60
|
-
uint256(scaledAmount.amount)
|
|
61
|
-
.wadToRay()
|
|
62
|
-
.rayMul(getScale(scaledAmount, interestRate))
|
|
63
|
-
.rayToWad();
|
|
50
|
+
function getScaledAmount(ScaledAmount storage scaledAmount, uint256 interestRate) internal view returns (uint256) {
|
|
51
|
+
return uint256(scaledAmount.amount).wadToRay().rayMul(getScale(scaledAmount, interestRate)).rayToWad();
|
|
64
52
|
}
|
|
65
53
|
|
|
66
54
|
function init(ScaledAmount storage scaledAmount) internal {
|
|
@@ -69,11 +57,7 @@ library TimeScaled {
|
|
|
69
57
|
scaledAmount.lastUpdate = uint32(block.timestamp);
|
|
70
58
|
}
|
|
71
59
|
|
|
72
|
-
function scaleAmount(ScaledAmount storage scaledAmount, uint256 toScale)
|
|
73
|
-
internal
|
|
74
|
-
view
|
|
75
|
-
returns (uint256)
|
|
76
|
-
{
|
|
60
|
+
function scaleAmount(ScaledAmount storage scaledAmount, uint256 toScale) internal view returns (uint256) {
|
|
77
61
|
return toScale.wadToRay().rayDiv(uint256(scaledAmount.scale)).rayToWad();
|
|
78
62
|
}
|
|
79
63
|
|
|
@@ -85,22 +69,14 @@ library TimeScaled {
|
|
|
85
69
|
return toScale.wadToRay().rayDiv(getScale(scaledAmount, interestRate)).rayToWad();
|
|
86
70
|
}
|
|
87
71
|
|
|
88
|
-
function add(
|
|
89
|
-
ScaledAmount storage scaledAmount,
|
|
90
|
-
uint256 amount,
|
|
91
|
-
uint256 interestRate
|
|
92
|
-
) internal returns (uint256) {
|
|
72
|
+
function add(ScaledAmount storage scaledAmount, uint256 amount, uint256 interestRate) internal returns (uint256) {
|
|
93
73
|
updateScale(scaledAmount, interestRate);
|
|
94
74
|
uint256 scaledAdd = scaleAmount(scaledAmount, amount);
|
|
95
75
|
scaledAmount.amount += scaledAdd.toUint96();
|
|
96
76
|
return scaledAdd;
|
|
97
77
|
}
|
|
98
78
|
|
|
99
|
-
function sub(
|
|
100
|
-
ScaledAmount storage scaledAmount,
|
|
101
|
-
uint256 amount,
|
|
102
|
-
uint256 interestRate
|
|
103
|
-
) internal returns (uint256) {
|
|
79
|
+
function sub(ScaledAmount storage scaledAmount, uint256 amount, uint256 interestRate) internal returns (uint256) {
|
|
104
80
|
updateScale(scaledAmount, interestRate);
|
|
105
81
|
uint256 scaledSub = scaleAmount(scaledAmount, amount);
|
|
106
82
|
scaledAmount.amount -= scaledSub.toUint96();
|
|
@@ -111,21 +87,14 @@ library TimeScaled {
|
|
|
111
87
|
return scaledSub;
|
|
112
88
|
}
|
|
113
89
|
|
|
114
|
-
function discreteChange(
|
|
115
|
-
ScaledAmount storage scaledAmount,
|
|
116
|
-
int256 amount,
|
|
117
|
-
uint256 interestRate
|
|
118
|
-
) internal {
|
|
90
|
+
function discreteChange(ScaledAmount storage scaledAmount, int256 amount, uint256 interestRate) internal {
|
|
119
91
|
if (scaledAmount.amount == 0) {
|
|
120
92
|
add(scaledAmount, uint256(amount), interestRate);
|
|
121
93
|
return;
|
|
122
94
|
}
|
|
123
95
|
updateScale(scaledAmount, interestRate);
|
|
124
96
|
uint256 newScaledAmount = uint256(int256(getScaledAmount(scaledAmount, interestRate)) + amount);
|
|
125
|
-
scaledAmount.scale = newScaledAmount
|
|
126
|
-
.wadToRay()
|
|
127
|
-
.rayDiv(uint256(scaledAmount.amount).wadToRay())
|
|
128
|
-
.toUint112();
|
|
97
|
+
scaledAmount.scale = newScaledAmount.wadToRay().rayDiv(uint256(scaledAmount.amount).wadToRay()).toUint112();
|
|
129
98
|
require(scaledAmount.scale >= MIN_SCALE, "Scale too small, can lead to rounding errors");
|
|
130
99
|
}
|
|
131
100
|
|
|
@@ -5,6 +5,7 @@ import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
|
5
5
|
import {IPremiumsAccount} from "./interfaces/IPremiumsAccount.sol";
|
|
6
6
|
import {RiskModule} from "./RiskModule.sol";
|
|
7
7
|
import {Policy} from "./Policy.sol";
|
|
8
|
+
import {IERC721} from "@openzeppelin/contracts/interfaces/IERC721.sol";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @title Trustful Risk Module
|
|
@@ -17,12 +18,11 @@ import {Policy} from "./Policy.sol";
|
|
|
17
18
|
contract TrustfulRiskModule is RiskModule {
|
|
18
19
|
bytes32 public constant PRICER_ROLE = keccak256("PRICER_ROLE");
|
|
19
20
|
bytes32 public constant RESOLVER_ROLE = keccak256("RESOLVER_ROLE");
|
|
21
|
+
bytes32 public constant REPLACER_ROLE = keccak256("REPLACER_ROLE");
|
|
20
22
|
|
|
21
23
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
22
24
|
// solhint-disable-next-line no-empty-blocks
|
|
23
|
-
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
|
|
24
|
-
RiskModule(policyPool_, premiumsAccount_)
|
|
25
|
-
{} // solhint-disable-line no-empty-blocks
|
|
25
|
+
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_) RiskModule(policyPool_, premiumsAccount_) {}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @dev Initializes the RiskModule
|
|
@@ -43,15 +43,7 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
43
43
|
uint256 exposureLimit_,
|
|
44
44
|
address wallet_
|
|
45
45
|
) public initializer {
|
|
46
|
-
__RiskModule_init(
|
|
47
|
-
name_,
|
|
48
|
-
collRatio_,
|
|
49
|
-
ensuroPpFee_,
|
|
50
|
-
srRoc_,
|
|
51
|
-
maxPayoutPerPolicy_,
|
|
52
|
-
exposureLimit_,
|
|
53
|
-
wallet_
|
|
54
|
-
);
|
|
46
|
+
__RiskModule_init(name_, collRatio_, ensuroPpFee_, srRoc_, maxPayoutPerPolicy_, exposureLimit_, wallet_);
|
|
55
47
|
}
|
|
56
48
|
|
|
57
49
|
/**
|
|
@@ -79,16 +71,7 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
79
71
|
address onBehalfOf,
|
|
80
72
|
uint96 internalId
|
|
81
73
|
) external whenNotPaused onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
82
|
-
return
|
|
83
|
-
_newPolicy(
|
|
84
|
-
payout,
|
|
85
|
-
premium,
|
|
86
|
-
lossProb,
|
|
87
|
-
expiration,
|
|
88
|
-
_getPayer(onBehalfOf, premium),
|
|
89
|
-
onBehalfOf,
|
|
90
|
-
internalId
|
|
91
|
-
).id;
|
|
74
|
+
return _newPolicy(payout, premium, lossProb, expiration, _getPayer(onBehalfOf, premium), onBehalfOf, internalId).id;
|
|
92
75
|
}
|
|
93
76
|
|
|
94
77
|
/**
|
|
@@ -115,22 +98,46 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
115
98
|
uint40 expiration,
|
|
116
99
|
address onBehalfOf,
|
|
117
100
|
uint96 internalId
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
101
|
+
) external whenNotPaused onlyComponentRole(PRICER_ROLE) returns (Policy.PolicyData memory createdPolicy) {
|
|
102
|
+
return _newPolicy(payout, premium, lossProb, expiration, _getPayer(onBehalfOf, premium), onBehalfOf, internalId);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @dev Replace a policy with a new one, reusing the premium and the capital locked
|
|
107
|
+
*
|
|
108
|
+
* Requirements:
|
|
109
|
+
* - The caller has been granted componentRole(PRICER_ROLE)
|
|
110
|
+
*
|
|
111
|
+
* Emits:
|
|
112
|
+
* - {PolicyPool.PolicyReplaced}
|
|
113
|
+
*
|
|
114
|
+
* @param payout The exposure (maximum payout) of the policy
|
|
115
|
+
* @param premium The premium that will be paid by the policyHolder
|
|
116
|
+
* @param lossProb The probability of having to pay the maximum payout (wad)
|
|
117
|
+
* @param expiration The expiration of the policy (timestamp)
|
|
118
|
+
* @param internalId An id that's unique within this module and it will be used to identify the policy
|
|
119
|
+
* @return Returns the id of the created policy
|
|
120
|
+
*/
|
|
121
|
+
function replacePolicy(
|
|
122
|
+
Policy.PolicyData calldata oldPolicy,
|
|
123
|
+
uint256 payout,
|
|
124
|
+
uint256 premium,
|
|
125
|
+
uint256 lossProb,
|
|
126
|
+
uint40 expiration,
|
|
127
|
+
uint96 internalId
|
|
128
|
+
) external whenNotPaused onlyComponentRole(REPLACER_ROLE) returns (uint256) {
|
|
129
|
+
address onBehalfOf = IERC721(address(_policyPool)).ownerOf(oldPolicy.id);
|
|
124
130
|
return
|
|
125
|
-
|
|
131
|
+
_replacePolicy(
|
|
132
|
+
oldPolicy,
|
|
126
133
|
payout,
|
|
127
134
|
premium,
|
|
128
135
|
lossProb,
|
|
129
136
|
expiration,
|
|
130
137
|
_getPayer(onBehalfOf, premium),
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
);
|
|
138
|
+
internalId,
|
|
139
|
+
params()
|
|
140
|
+
).id;
|
|
134
141
|
}
|
|
135
142
|
|
|
136
143
|
function _getPayer(address onBehalfOf, uint256 premium) internal view returns (address payer) {
|
|
@@ -165,11 +172,10 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
165
172
|
* @param policy The policy previously created (from {NewPolicy} event)
|
|
166
173
|
* @param payout The payout to transfer to the policy holder
|
|
167
174
|
*/
|
|
168
|
-
function resolvePolicy(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
{
|
|
175
|
+
function resolvePolicy(
|
|
176
|
+
Policy.PolicyData calldata policy,
|
|
177
|
+
uint256 payout
|
|
178
|
+
) external onlyComponentRole(RESOLVER_ROLE) whenNotPaused {
|
|
173
179
|
_policyPool.resolvePolicy(policy, payout);
|
|
174
180
|
}
|
|
175
181
|
|
|
@@ -187,11 +193,10 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
187
193
|
* @param customerWon If true, policy.payout is transferred to the policy holder. If false, the policy is resolved
|
|
188
194
|
* without payout and can't be longer claimed.
|
|
189
195
|
*/
|
|
190
|
-
function resolvePolicyFullPayout(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
{
|
|
196
|
+
function resolvePolicyFullPayout(
|
|
197
|
+
Policy.PolicyData calldata policy,
|
|
198
|
+
bool customerWon
|
|
199
|
+
) external onlyComponentRole(RESOLVER_ROLE) whenNotPaused {
|
|
195
200
|
_policyPool.resolvePolicyFullPayout(policy, customerWon);
|
|
196
201
|
}
|
|
197
202
|
|
|
@@ -108,11 +108,7 @@ interface IAccessManager is IAccessControlUpgradeable {
|
|
|
108
108
|
* @param role2 Another role such as `keccak256("GUARDIAN_ROLE")` that's global
|
|
109
109
|
* @param account The user address for who we want to verify the permission
|
|
110
110
|
*/
|
|
111
|
-
function checkRole2(
|
|
112
|
-
bytes32 role1,
|
|
113
|
-
bytes32 role2,
|
|
114
|
-
address account
|
|
115
|
-
) external view;
|
|
111
|
+
function checkRole2(bytes32 role1, bytes32 role2, address account) external view;
|
|
116
112
|
|
|
117
113
|
/**
|
|
118
114
|
* @dev Checks if a user has been granted a given component role and reverts if it doesn't
|
|
@@ -122,12 +118,7 @@ interface IAccessManager is IAccessControlUpgradeable {
|
|
|
122
118
|
* @param alsoGlobal If true, it will accept not only the component role, but also the (global) `role` itself.
|
|
123
119
|
* If false, only the component role is accepted
|
|
124
120
|
*/
|
|
125
|
-
function checkComponentRole(
|
|
126
|
-
address component,
|
|
127
|
-
bytes32 role,
|
|
128
|
-
address account,
|
|
129
|
-
bool alsoGlobal
|
|
130
|
-
) external view;
|
|
121
|
+
function checkComponentRole(address component, bytes32 role, address account, bool alsoGlobal) external view;
|
|
131
122
|
|
|
132
123
|
/**
|
|
133
124
|
* @dev Checks if a user has been granted any of the two component roles specified and reverts if it doesn't
|
|
@@ -67,11 +67,7 @@ interface IEToken is IERC20 {
|
|
|
67
67
|
* @param policyInterestRate The annualized interest rate that was paid for the `scrAmount`, must be the same that was
|
|
68
68
|
* sent in `lockScr` call.
|
|
69
69
|
*/
|
|
70
|
-
function unlockScr(
|
|
71
|
-
uint256 scrAmount,
|
|
72
|
-
uint256 policyInterestRate,
|
|
73
|
-
int256 adjustment
|
|
74
|
-
) external;
|
|
70
|
+
function unlockScr(uint256 scrAmount, uint256 policyInterestRate, int256 adjustment) external;
|
|
75
71
|
|
|
76
72
|
/**
|
|
77
73
|
* @dev Registers a deposit of liquidity in the pool. Called from the PolicyPool, assumes the amount has already been
|
|
@@ -16,11 +16,7 @@ interface ILPWhitelist {
|
|
|
16
16
|
* @param amount The amount of the deposit
|
|
17
17
|
* @return true if `provider` deposit is accepted, false if not
|
|
18
18
|
*/
|
|
19
|
-
function acceptsDeposit(
|
|
20
|
-
IEToken etoken,
|
|
21
|
-
address provider,
|
|
22
|
-
uint256 amount
|
|
23
|
-
) external view returns (bool);
|
|
19
|
+
function acceptsDeposit(IEToken etoken, address provider, uint256 amount) external view returns (bool);
|
|
24
20
|
|
|
25
21
|
/**
|
|
26
22
|
* @dev Indicates whether or not the eTokens can be transferred from `providerFrom` to `providerTo`
|
|
@@ -46,9 +42,5 @@ interface ILPWhitelist {
|
|
|
46
42
|
* @param amount The amount of the withdrawal
|
|
47
43
|
* @return true if `provider` withdraw request is accepted, false if not
|
|
48
44
|
*/
|
|
49
|
-
function acceptsWithdrawal(
|
|
50
|
-
IEToken etoken,
|
|
51
|
-
address provider,
|
|
52
|
-
uint256 amount
|
|
53
|
-
) external view returns (bool);
|
|
45
|
+
function acceptsWithdrawal(IEToken etoken, address provider, uint256 amount) external view returns (bool);
|
|
54
46
|
}
|
|
@@ -18,11 +18,7 @@ interface IPolicyHolder is IERC721Receiver {
|
|
|
18
18
|
*
|
|
19
19
|
* The selector can be obtained in Solidity with `IPolicyPool.onPolicyExpired.selector`.
|
|
20
20
|
*/
|
|
21
|
-
function onPolicyExpired(
|
|
22
|
-
address operator,
|
|
23
|
-
address from,
|
|
24
|
-
uint256 policyId
|
|
25
|
-
) external returns (bytes4);
|
|
21
|
+
function onPolicyExpired(address operator, address from, uint256 policyId) external returns (bytes4);
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
24
|
* @dev Whenever an Policy is resolved with payout > 0, this function is called
|
|
@@ -33,10 +29,5 @@ interface IPolicyHolder is IERC721Receiver {
|
|
|
33
29
|
*
|
|
34
30
|
* The selector can be obtained in Solidity with `IPolicyPool.onPayoutReceived.selector`.
|
|
35
31
|
*/
|
|
36
|
-
function onPayoutReceived(
|
|
37
|
-
address operator,
|
|
38
|
-
address from,
|
|
39
|
-
uint256 policyId,
|
|
40
|
-
uint256 amount
|
|
41
|
-
) external returns (bytes4);
|
|
32
|
+
function onPayoutReceived(address operator, address from, uint256 policyId, uint256 amount) external returns (bytes4);
|
|
42
33
|
}
|
|
@@ -4,9 +4,39 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
5
5
|
import {Policy} from "../Policy.sol";
|
|
6
6
|
import {IEToken} from "./IEToken.sol";
|
|
7
|
+
import {IRiskModule} from "./IRiskModule.sol";
|
|
7
8
|
import {IAccessManager} from "./IAccessManager.sol";
|
|
8
9
|
|
|
9
10
|
interface IPolicyPool {
|
|
11
|
+
/**
|
|
12
|
+
* @dev Event emitted every time a new policy is added to the pool. Contains all the data about the policy that is
|
|
13
|
+
* later required for doing operations with the policy like resolution or expiration.
|
|
14
|
+
*
|
|
15
|
+
* @param riskModule The risk module that created the policy
|
|
16
|
+
* @param policy The {Policy-PolicyData} struct with all the immutable fields of the policy.
|
|
17
|
+
*/
|
|
18
|
+
event NewPolicy(IRiskModule indexed riskModule, Policy.PolicyData policy);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @dev Event emitted every time a new policy replaces an old Policy Contains all the data about the policy that is
|
|
22
|
+
* later required for doing operations with the policy like resolution or expiration.
|
|
23
|
+
*
|
|
24
|
+
* @param riskModule The risk module that created the policy
|
|
25
|
+
* @param oldPolicyId The id of the replaced policy.
|
|
26
|
+
* @param newPolicyId The id of the new policy.
|
|
27
|
+
*/
|
|
28
|
+
event PolicyReplaced(IRiskModule indexed riskModule, uint256 indexed oldPolicyId, uint256 indexed newPolicyId);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @dev Event emitted every time a policy is removed from the pool. If the policy expired, the `payout` is 0,
|
|
32
|
+
* otherwise is the amount transferred to the policyholder.
|
|
33
|
+
*
|
|
34
|
+
* @param riskModule The risk module where that created the policy initially.
|
|
35
|
+
* @param policyId The unique id of the policy
|
|
36
|
+
* @param payout The payout that has been paid to the policy holder. 0 when the policy expired.
|
|
37
|
+
*/
|
|
38
|
+
event PolicyResolved(IRiskModule indexed riskModule, uint256 indexed policyId, uint256 payout);
|
|
39
|
+
|
|
10
40
|
/**
|
|
11
41
|
* @dev Reference to the main currency (ERC20) used in the protocol
|
|
12
42
|
* @return The address of the currency (e.g. USDC) token used in the protocol
|
|
@@ -39,18 +69,44 @@ interface IPolicyPool {
|
|
|
39
69
|
* (see Premium Split in the docs)
|
|
40
70
|
*
|
|
41
71
|
* @param policy A policy created with {Policy-initialize}
|
|
42
|
-
* @param
|
|
43
|
-
* @param policyHolder The address of the policy holder
|
|
72
|
+
* @param payer The address that will pay for the premium
|
|
73
|
+
* @param policyHolder The address of the policy holder
|
|
44
74
|
* @param internalId A unique id within the RiskModule, that will be used to compute the policy id
|
|
45
75
|
* @return The policy id, identifying the NFT and the policy
|
|
46
76
|
*/
|
|
47
77
|
function newPolicy(
|
|
48
78
|
Policy.PolicyData memory policy,
|
|
49
|
-
address
|
|
79
|
+
address payer,
|
|
50
80
|
address policyHolder,
|
|
51
81
|
uint96 internalId
|
|
52
82
|
) external returns (uint256);
|
|
53
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @dev Replaces a policy with another. Must be called from an active RiskModule
|
|
86
|
+
*
|
|
87
|
+
* Requirements:
|
|
88
|
+
* - `msg.sender` must be an active RiskModule
|
|
89
|
+
* - `caller` approved the spending of `currency()` for at least `newPolicy_.premium - oldPolicy.premium`
|
|
90
|
+
* - `internalId` must be unique within `policy.riskModule` and not used before
|
|
91
|
+
*
|
|
92
|
+
* Events:
|
|
93
|
+
* - {PolicyPool-PolicyReplaced}: with all the details about the policy
|
|
94
|
+
* - {ERC20-Transfer}: does several transfers from caller address to the different receivers of the premium
|
|
95
|
+
* (see Premium Split in the docs)
|
|
96
|
+
*
|
|
97
|
+
* @param oldPolicy A policy created previously and not expired
|
|
98
|
+
* @param newPolicy_ A policy created with {Policy-initialize}
|
|
99
|
+
* @param payer The address that will pay for the premium
|
|
100
|
+
* @param internalId A unique id within the RiskModule, that will be used to compute the policy id
|
|
101
|
+
* @return The policy id, identifying the NFT and the policy
|
|
102
|
+
*/
|
|
103
|
+
function replacePolicy(
|
|
104
|
+
Policy.PolicyData memory oldPolicy,
|
|
105
|
+
Policy.PolicyData memory newPolicy_,
|
|
106
|
+
address payer,
|
|
107
|
+
uint96 internalId
|
|
108
|
+
) external returns (uint256);
|
|
109
|
+
|
|
54
110
|
/**
|
|
55
111
|
* @dev Resolves a policy with a payout. Must be called from an active RiskModule
|
|
56
112
|
*
|
|
@@ -24,6 +24,22 @@ interface IPremiumsAccount {
|
|
|
24
24
|
*/
|
|
25
25
|
function policyCreated(Policy.PolicyData memory policy) external;
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @dev Replaces a policy with another in PremiumsAccount. Stores the pure premiums difference and
|
|
29
|
+
* re-locks the aditional funds from junior and senior eTokens.
|
|
30
|
+
*
|
|
31
|
+
* Requirements:
|
|
32
|
+
* - Must be called by `policyPool()`
|
|
33
|
+
*
|
|
34
|
+
* Events:
|
|
35
|
+
* - {EToken-SCRUnlocked}
|
|
36
|
+
* - {EToken-SCRLocked}
|
|
37
|
+
*
|
|
38
|
+
* @param oldPolicy The policy to replace (created in a previous transaction)
|
|
39
|
+
* @param newPolicy The policy that will replace the old one (created in this transaction)
|
|
40
|
+
*/
|
|
41
|
+
function policyReplaced(Policy.PolicyData memory oldPolicy, Policy.PolicyData memory newPolicy) external;
|
|
42
|
+
|
|
27
43
|
/**
|
|
28
44
|
* @dev The PremiumsAccount is notified that the policy was resolved and issues the payout to the policyHolder.
|
|
29
45
|
*
|
|
@@ -39,11 +55,7 @@ interface IPremiumsAccount {
|
|
|
39
55
|
* @param policy The policy that was resolved
|
|
40
56
|
* @param payout The amount that has to be transferred to `policyHolder`
|
|
41
57
|
*/
|
|
42
|
-
function policyResolvedWithPayout(
|
|
43
|
-
address policyHolder,
|
|
44
|
-
Policy.PolicyData memory policy,
|
|
45
|
-
uint256 payout
|
|
46
|
-
) external;
|
|
58
|
+
function policyResolvedWithPayout(address policyHolder, Policy.PolicyData memory policy, uint256 payout) external;
|
|
47
59
|
|
|
48
60
|
/**
|
|
49
61
|
* @dev The PremiumsAccount is notified that the policy has expired, unlocks the SCR and earns the pure premium.
|
|
@@ -30,10 +30,7 @@ abstract contract LPManualWhitelistV20 is ILPWhitelist, PolicyPoolComponent {
|
|
|
30
30
|
__PolicyPoolComponent_init();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function whitelistAddress(address provider, bool whitelisted)
|
|
34
|
-
external
|
|
35
|
-
onlyComponentRole(LP_WHITELIST_ROLE)
|
|
36
|
-
{
|
|
33
|
+
function whitelistAddress(address provider, bool whitelisted) external onlyComponentRole(LP_WHITELIST_ROLE) {
|
|
37
34
|
if (_whitelisted[provider] != whitelisted) {
|
|
38
35
|
_whitelisted[provider] = whitelisted;
|
|
39
36
|
emit LPWhitelisted(provider, whitelisted);
|
|
@@ -47,20 +44,11 @@ abstract contract LPManualWhitelistV20 is ILPWhitelist, PolicyPoolComponent {
|
|
|
47
44
|
return super.supportsInterface(interfaceId) || interfaceId == type(ILPWhitelist).interfaceId;
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
function acceptsDeposit(
|
|
51
|
-
IEToken,
|
|
52
|
-
address provider,
|
|
53
|
-
uint256
|
|
54
|
-
) external view override returns (bool) {
|
|
47
|
+
function acceptsDeposit(IEToken, address provider, uint256) external view override returns (bool) {
|
|
55
48
|
return _whitelisted[provider];
|
|
56
49
|
}
|
|
57
50
|
|
|
58
|
-
function acceptsTransfer(
|
|
59
|
-
IEToken,
|
|
60
|
-
address,
|
|
61
|
-
address providerTo,
|
|
62
|
-
uint256
|
|
63
|
-
) external view override returns (bool) {
|
|
51
|
+
function acceptsTransfer(IEToken, address, address providerTo, uint256) external view override returns (bool) {
|
|
64
52
|
return _whitelisted[providerTo];
|
|
65
53
|
}
|
|
66
54
|
|
|
@@ -15,11 +15,7 @@ import {LPManualWhitelistV20} from "./LPManualWhitelistV20.sol";
|
|
|
15
15
|
contract LPManualWhitelistV20Upgraded is LPManualWhitelistV20 {
|
|
16
16
|
constructor(IPolicyPool policyPool_) LPManualWhitelistV20(policyPool_) {}
|
|
17
17
|
|
|
18
|
-
function acceptsWithdrawal(
|
|
19
|
-
IEToken etk,
|
|
20
|
-
address provider,
|
|
21
|
-
uint256 amount
|
|
22
|
-
) external view override returns (bool) {
|
|
18
|
+
function acceptsWithdrawal(IEToken etk, address provider, uint256 amount) external view override returns (bool) {
|
|
23
19
|
return this.acceptsDeposit(etk, provider, amount);
|
|
24
20
|
}
|
|
25
21
|
}
|
|
@@ -33,12 +33,7 @@ contract FixedRateVault is ERC4626 {
|
|
|
33
33
|
/**
|
|
34
34
|
* @dev Deposit/mint common workflow.
|
|
35
35
|
*/
|
|
36
|
-
function _deposit(
|
|
37
|
-
address caller,
|
|
38
|
-
address receiver,
|
|
39
|
-
uint256 assets,
|
|
40
|
-
uint256 shares
|
|
41
|
-
) internal virtual override {
|
|
36
|
+
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual override {
|
|
42
37
|
require(!_broken, "Vault is broken");
|
|
43
38
|
_totalAssets.add(assets, _interestRate);
|
|
44
39
|
super._deposit(caller, receiver, assets, shares);
|
|
@@ -10,6 +10,7 @@ import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
|
10
10
|
import {IPolicyPoolComponent} from "../interfaces/IPolicyPoolComponent.sol";
|
|
11
11
|
import {IEToken} from "../interfaces/IEToken.sol";
|
|
12
12
|
import {IRiskModule} from "../interfaces/IRiskModule.sol";
|
|
13
|
+
import {IPolicyHolder} from "../interfaces/IPolicyHolder.sol";
|
|
13
14
|
import {IPremiumsAccount} from "../interfaces/IPremiumsAccount.sol";
|
|
14
15
|
import {ILPWhitelist} from "../interfaces/ILPWhitelist.sol";
|
|
15
16
|
import {IAccessManager} from "../interfaces/IAccessManager.sol";
|
|
@@ -29,4 +30,5 @@ contract InterfaceIdCalculator {
|
|
|
29
30
|
bytes4 public constant ILPWHITELIST_INTERFACEID = type(ILPWhitelist).interfaceId;
|
|
30
31
|
bytes4 public constant IACCESSMANAGER_INTERFACEID = type(IAccessManager).interfaceId;
|
|
31
32
|
bytes4 public constant IASSETMANAGER_INTERFACEID = type(IAssetManager).interfaceId;
|
|
33
|
+
bytes4 public constant IPOLICYHOLDER_INTERFACEID = type(IPolicyHolder).interfaceId;
|
|
32
34
|
}
|
|
@@ -20,12 +20,7 @@ contract PolicyHolderMock is IPolicyHolder {
|
|
|
20
20
|
PolicyExpired
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
event NotificationReceived(
|
|
24
|
-
NotificationKind kind,
|
|
25
|
-
uint256 policyId,
|
|
26
|
-
address operator,
|
|
27
|
-
address from
|
|
28
|
-
);
|
|
23
|
+
event NotificationReceived(NotificationKind kind, uint256 policyId, address operator, address from);
|
|
29
24
|
|
|
30
25
|
constructor() {
|
|
31
26
|
fail = false;
|
|
@@ -65,8 +60,7 @@ contract PolicyHolderMock is IPolicyHolder {
|
|
|
65
60
|
revert(0, 0)
|
|
66
61
|
}
|
|
67
62
|
if (notImplemented) return false;
|
|
68
|
-
return
|
|
69
|
-
interfaceId == type(IPolicyHolder).interfaceId || interfaceId == type(IERC165).interfaceId;
|
|
63
|
+
return interfaceId == type(IPolicyHolder).interfaceId || interfaceId == type(IERC165).interfaceId;
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
function onERC721Received(
|
|
@@ -91,11 +85,7 @@ contract PolicyHolderMock is IPolicyHolder {
|
|
|
91
85
|
return IERC721Receiver.onERC721Received.selector;
|
|
92
86
|
}
|
|
93
87
|
|
|
94
|
-
function onPolicyExpired(
|
|
95
|
-
address operator,
|
|
96
|
-
address from,
|
|
97
|
-
uint256 policyId_
|
|
98
|
-
) external override returns (bytes4) {
|
|
88
|
+
function onPolicyExpired(address operator, address from, uint256 policyId_) external override returns (bytes4) {
|
|
99
89
|
if (fail)
|
|
100
90
|
if (emptyRevert)
|
|
101
91
|
assembly {
|
|
@@ -20,8 +20,6 @@ contract PolicyPoolComponentMock is IPolicyPoolComponent {
|
|
|
20
20
|
* @dev See {IERC165-supportsInterface}.
|
|
21
21
|
*/
|
|
22
22
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
23
|
-
return
|
|
24
|
-
interfaceId == type(IERC165).interfaceId ||
|
|
25
|
-
interfaceId == type(IPolicyPoolComponent).interfaceId;
|
|
23
|
+
return interfaceId == type(IERC165).interfaceId || interfaceId == type(IPolicyPoolComponent).interfaceId;
|
|
26
24
|
}
|
|
27
25
|
}
|