@ensuro/core 2.0.0-beta1 → 2.0.0-beta10
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 +23 -14
- package/build/contracts/AccessManager.sol/AccessManager.json +559 -0
- package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +219 -0
- package/build/contracts/EToken.sol/EToken.json +134 -52
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +4 -4
- package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +203 -0
- package/build/contracts/Policy.sol/Policy.json +2 -2
- package/build/contracts/PolicyPool.sol/PolicyPool.json +437 -61
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +2 -2
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +123 -16
- package/build/contracts/Reserve.sol/Reserve.json +66 -8
- package/build/contracts/RiskModule.sol/RiskModule.json +2 -2
- package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +960 -0
- package/build/contracts/TimeScaled.sol/TimeScaled.json +3 -17
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +5 -5
- package/build/contracts/{WadRayMath.sol → dependencies/WadRayMath.sol}/WadRayMath.json +3 -3
- package/build/contracts/interfaces/{IPolicyPoolConfig.sol/IPolicyPoolConfig.json → IAccessManager.sol/IAccessManager.json} +77 -59
- package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +109 -0
- package/build/contracts/interfaces/IEToken.sol/IEToken.json +13 -0
- package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +40 -16
- package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +13 -0
- package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +736 -0
- package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +2 -2
- package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +28 -2
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +2 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +118 -19
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +6 -6
- package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +764 -0
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +2 -2
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +2 -2
- package/contracts/AccessManager.sol +103 -0
- package/contracts/ERC4626AssetManager.sol +52 -0
- package/contracts/EToken.sol +123 -87
- package/contracts/LPManualWhitelist.sol +1 -1
- package/contracts/LiquidityThresholdAssetManager.sol +160 -0
- package/contracts/Policy.sol +1 -1
- package/contracts/PolicyPool.sol +333 -115
- package/contracts/PolicyPoolComponent.sol +36 -41
- package/contracts/PremiumsAccount.sol +285 -79
- package/contracts/Reserve.sol +183 -4
- package/contracts/RiskModule.sol +26 -19
- package/contracts/SignedQuoteRiskModule.sol +241 -0
- package/contracts/TimeScaled.sol +19 -15
- package/contracts/TrustfulRiskModule.sol +62 -2
- package/contracts/dependencies/WadRayMath.sol +126 -0
- package/contracts/interfaces/IAccessManager.sol +148 -0
- package/contracts/interfaces/IAssetManager.sol +84 -0
- package/contracts/interfaces/IEToken.sol +25 -2
- package/contracts/interfaces/ILPWhitelist.sol +17 -0
- package/contracts/interfaces/IPolicyPool.sol +20 -13
- package/contracts/interfaces/IPolicyPoolComponent.sol +3 -0
- package/contracts/interfaces/IPremiumsAccount.sol +5 -0
- package/contracts/interfaces/IRiskModule.sol +67 -4
- package/contracts/mocks/FixedRateVault.sol +85 -0
- package/contracts/mocks/PolicyHolderMock.sol +21 -0
- package/contracts/mocks/PolicyPoolMock.sol +41 -15
- package/contracts/mocks/RiskModuleMock.sol +75 -0
- package/js/test-utils.js +227 -149
- package/package.json +1 -1
- package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +0 -890
- package/build/contracts/PolicyNFT.sol/PolicyNFT.json +0 -583
- package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +0 -691
- package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +0 -63
- package/build/contracts/interfaces/IPolicyNFT.sol/IPolicyNFT.json +0 -321
- package/build/contracts/mocks/LinkTokenMock.sol/LinkTokenMock.json +0 -370
- package/build/contracts/mocks/TestCurrencyUUPS.sol/TestCurrencyUUPS.json +0 -353
- package/build/contracts/upgraded/IPolicyNFTv1.sol/IPolicyNFTv1.json +0 -322
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +0 -584
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +0 -615
- package/contracts/FlightDelayRiskModule.sol +0 -217
- package/contracts/PolicyNFT.sol +0 -96
- package/contracts/PolicyPoolConfig.sol +0 -204
- package/contracts/WadRayMath.sol +0 -135
- package/contracts/dependencies/ChainlinkClientUpgradeable.sol +0 -371
- package/contracts/interfaces/IPolicyNFT.sol +0 -15
- package/contracts/interfaces/IPolicyPoolConfig.sol +0 -96
- package/contracts/mocks/LinkTokenMock.sol +0 -30
- package/contracts/upgraded/IPolicyNFTv1.sol +0 -15
- package/contracts/upgraded/PolicyNFTv1.sol +0 -126
|
@@ -54,17 +54,63 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @dev Creates a new Policy
|
|
59
|
+
*
|
|
60
|
+
* Requirements:
|
|
61
|
+
* - The caller has been granted componentRole(PRICER_ROLE)
|
|
62
|
+
*
|
|
63
|
+
* Emits:
|
|
64
|
+
* - {PolicyPool.NewPolicy}
|
|
65
|
+
*
|
|
66
|
+
* @param payout The exposure (maximum payout) of the policy
|
|
67
|
+
* @param premium The premium that will be paid by the policyHolder
|
|
68
|
+
* @param lossProb The probability of having to pay the maximum payout (wad)
|
|
69
|
+
* @param expiration The expiration of the policy (timestamp)
|
|
70
|
+
* @param onBehalfOf The policy holder
|
|
71
|
+
* @param internalId An id that's unique within this module and it will be used to identify the policy
|
|
72
|
+
* @return Returns the id of the created policy
|
|
73
|
+
*/
|
|
57
74
|
function newPolicy(
|
|
58
75
|
uint256 payout,
|
|
59
76
|
uint256 premium,
|
|
60
77
|
uint256 lossProb,
|
|
61
78
|
uint40 expiration,
|
|
62
|
-
address
|
|
79
|
+
address onBehalfOf,
|
|
63
80
|
uint96 internalId
|
|
64
81
|
) external onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
65
|
-
|
|
82
|
+
address payer = onBehalfOf;
|
|
83
|
+
if (payer != _msgSender() && _policyPool.currency().allowance(payer, _msgSender()) < premium)
|
|
84
|
+
/**
|
|
85
|
+
* The standard is the payer should be the _msgSender() but usually, in this type of module,
|
|
86
|
+
* the sender is an operative account managed by software, where the onBehalfOf is a more
|
|
87
|
+
* secure account (hardware wallet) that does the cash movements.
|
|
88
|
+
* This non standard behaviour allows for a more secure setup, where the sender never manages
|
|
89
|
+
* cash.
|
|
90
|
+
* We leverage the currency's allowance mechanism to allow the sender access to the payer's
|
|
91
|
+
* funds.
|
|
92
|
+
* Note that this allowance won't be spent, so it can be set as the maximum amount of a single
|
|
93
|
+
* premium even for multiple policies.
|
|
94
|
+
*/
|
|
95
|
+
payer = _msgSender();
|
|
96
|
+
|
|
97
|
+
return _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId).id;
|
|
66
98
|
}
|
|
67
99
|
|
|
100
|
+
/**
|
|
101
|
+
* @dev Resolves a policy, if payout > 0, it pays to the policy holder.
|
|
102
|
+
*
|
|
103
|
+
* Requirements:
|
|
104
|
+
* - The caller has been granted componentRole(RESOLVER_ROLE)
|
|
105
|
+
* - payout <= policy.payout
|
|
106
|
+
* - block.timestamp >= policy.expiration
|
|
107
|
+
*
|
|
108
|
+
* Emits:
|
|
109
|
+
* - {PolicyPool.PolicyResolved}
|
|
110
|
+
*
|
|
111
|
+
* @param policy The policy previously created (from {NewPolicy} event)
|
|
112
|
+
* @param payout The payout to transfer to the policy holder
|
|
113
|
+
*/
|
|
68
114
|
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
|
|
69
115
|
external
|
|
70
116
|
onlyComponentRole(RESOLVER_ROLE)
|
|
@@ -73,6 +119,20 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
73
119
|
_policyPool.resolvePolicy(policy, payout);
|
|
74
120
|
}
|
|
75
121
|
|
|
122
|
+
/**
|
|
123
|
+
* @dev Resolves a policy with full payout (policy.payout) if customerWon == true
|
|
124
|
+
*
|
|
125
|
+
* Requirements:
|
|
126
|
+
* - The caller has been granted componentRole(RESOLVER_ROLE)
|
|
127
|
+
* - block.timestamp >= policy.expiration
|
|
128
|
+
*
|
|
129
|
+
* Emits:
|
|
130
|
+
* - {PolicyPool.PolicyResolved}
|
|
131
|
+
*
|
|
132
|
+
* @param policy The policy previously created (from {NewPolicy} event)
|
|
133
|
+
* @param customerWon If true, policy.payout is transferred to the policy holder. If false, the policy is resolved
|
|
134
|
+
* without payout and can't be longer claimed.
|
|
135
|
+
*/
|
|
76
136
|
function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon)
|
|
77
137
|
external
|
|
78
138
|
onlyComponentRole(RESOLVER_ROLE)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title WadRayMath library
|
|
6
|
+
* @author Aave
|
|
7
|
+
* @notice Provides functions to perform calculations with Wad and Ray units
|
|
8
|
+
* @dev Provides mul and div function for wads (decimal numbers with 18 digits of precision) and rays (decimal numbers
|
|
9
|
+
* with 27 digits of precision)
|
|
10
|
+
* @dev Operations are rounded. If a value is >=.5, will be rounded up, otherwise rounded down.
|
|
11
|
+
**/
|
|
12
|
+
library WadRayMath {
|
|
13
|
+
// HALF_WAD and HALF_RAY expressed with extended notation as constant with operations are not supported in Yul assembly
|
|
14
|
+
uint256 internal constant WAD = 1e18;
|
|
15
|
+
uint256 internal constant HALF_WAD = 0.5e18;
|
|
16
|
+
|
|
17
|
+
uint256 internal constant RAY = 1e27;
|
|
18
|
+
uint256 internal constant HALF_RAY = 0.5e27;
|
|
19
|
+
|
|
20
|
+
uint256 internal constant WAD_RAY_RATIO = 1e9;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @dev Multiplies two wad, rounding half up to the nearest wad
|
|
24
|
+
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
|
|
25
|
+
* @param a Wad
|
|
26
|
+
* @param b Wad
|
|
27
|
+
* @return c = a*b, in wad
|
|
28
|
+
**/
|
|
29
|
+
function wadMul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
|
30
|
+
// to avoid overflow, a <= (type(uint256).max - HALF_WAD) / b
|
|
31
|
+
assembly {
|
|
32
|
+
if iszero(or(iszero(b), iszero(gt(a, div(sub(not(0), HALF_WAD), b))))) {
|
|
33
|
+
revert(0, 0)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
c := div(add(mul(a, b), HALF_WAD), WAD)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @dev Divides two wad, rounding half up to the nearest wad
|
|
42
|
+
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
|
|
43
|
+
* @param a Wad
|
|
44
|
+
* @param b Wad
|
|
45
|
+
* @return c = a/b, in wad
|
|
46
|
+
**/
|
|
47
|
+
function wadDiv(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
|
48
|
+
// to avoid overflow, a <= (type(uint256).max - halfB) / WAD
|
|
49
|
+
assembly {
|
|
50
|
+
if or(iszero(b), iszero(iszero(gt(a, div(sub(not(0), div(b, 2)), WAD))))) {
|
|
51
|
+
revert(0, 0)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
c := div(add(mul(a, WAD), div(b, 2)), b)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @notice Multiplies two ray, rounding half up to the nearest ray
|
|
60
|
+
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
|
|
61
|
+
* @param a Ray
|
|
62
|
+
* @param b Ray
|
|
63
|
+
* @return c = a raymul b
|
|
64
|
+
**/
|
|
65
|
+
function rayMul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
|
66
|
+
// to avoid overflow, a <= (type(uint256).max - HALF_RAY) / b
|
|
67
|
+
assembly {
|
|
68
|
+
if iszero(or(iszero(b), iszero(gt(a, div(sub(not(0), HALF_RAY), b))))) {
|
|
69
|
+
revert(0, 0)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
c := div(add(mul(a, b), HALF_RAY), RAY)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @notice Divides two ray, rounding half up to the nearest ray
|
|
78
|
+
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
|
|
79
|
+
* @param a Ray
|
|
80
|
+
* @param b Ray
|
|
81
|
+
* @return c = a raydiv b
|
|
82
|
+
**/
|
|
83
|
+
function rayDiv(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
|
84
|
+
// to avoid overflow, a <= (type(uint256).max - halfB) / RAY
|
|
85
|
+
assembly {
|
|
86
|
+
if or(iszero(b), iszero(iszero(gt(a, div(sub(not(0), div(b, 2)), RAY))))) {
|
|
87
|
+
revert(0, 0)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
c := div(add(mul(a, RAY), div(b, 2)), b)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @dev Casts ray down to wad
|
|
96
|
+
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
|
|
97
|
+
* @param a Ray
|
|
98
|
+
* @return b = a converted to wad, rounded half up to the nearest wad
|
|
99
|
+
**/
|
|
100
|
+
function rayToWad(uint256 a) internal pure returns (uint256 b) {
|
|
101
|
+
assembly {
|
|
102
|
+
b := div(a, WAD_RAY_RATIO)
|
|
103
|
+
let remainder := mod(a, WAD_RAY_RATIO)
|
|
104
|
+
if iszero(lt(remainder, div(WAD_RAY_RATIO, 2))) {
|
|
105
|
+
b := add(b, 1)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @dev Converts wad up to ray
|
|
112
|
+
* @dev assembly optimized for improved gas savings, see https://twitter.com/transmissions11/status/1451131036377571328
|
|
113
|
+
* @param a Wad
|
|
114
|
+
* @return b = a converted in ray
|
|
115
|
+
**/
|
|
116
|
+
function wadToRay(uint256 a) internal pure returns (uint256 b) {
|
|
117
|
+
// to avoid overflow, b/WAD_RAY_RATIO == a
|
|
118
|
+
assembly {
|
|
119
|
+
b := mul(a, WAD_RAY_RATIO)
|
|
120
|
+
|
|
121
|
+
if iszero(eq(div(b, WAD_RAY_RATIO), a)) {
|
|
122
|
+
revert(0, 0)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IAccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title IAccessManager - Interface for the contract that handles roles for the PolicyPool and components
|
|
8
|
+
* @dev Interface for the contract that handles roles for the PolicyPool and components
|
|
9
|
+
* @author Ensuro
|
|
10
|
+
*/
|
|
11
|
+
interface IAccessManager is IAccessControlUpgradeable {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Enum with the different governance actions supported in the protocol.
|
|
14
|
+
* It's good to keep actions of the same component consecutive, parts of the code relay on that,
|
|
15
|
+
* so we put some fillers in case new actions are added.
|
|
16
|
+
*/
|
|
17
|
+
enum GovernanceActions {
|
|
18
|
+
none,
|
|
19
|
+
setTreasury, // Changes PolicyPool treasury address
|
|
20
|
+
setAssetManager, // Change in the asset manager strategy of a reserve
|
|
21
|
+
setAssetManagerForced, // Change in the asset manager strategy of a reserve, forced (deinvest failed)
|
|
22
|
+
ppFiller1, // Reserve space for future PolicyPool or AccessManager actions
|
|
23
|
+
ppFiller2, // Reserve space for future PolicyPool or AccessManager actions
|
|
24
|
+
ppFiller3, // Reserve space for future PolicyPool or AccessManager actions
|
|
25
|
+
ppFiller4, // Reserve space for future PolicyPool or AccessManager actions
|
|
26
|
+
// RiskModule Governance Actions
|
|
27
|
+
setMoc,
|
|
28
|
+
setJrCollRatio,
|
|
29
|
+
setCollRatio,
|
|
30
|
+
setEnsuroPpFee,
|
|
31
|
+
setEnsuroCocFee,
|
|
32
|
+
setJrRoc,
|
|
33
|
+
setSrRoc,
|
|
34
|
+
setMaxPayoutPerPolicy,
|
|
35
|
+
setExposureLimit,
|
|
36
|
+
setMaxDuration,
|
|
37
|
+
setWallet,
|
|
38
|
+
rmFiller1, // Reserve space for future RM actions
|
|
39
|
+
rmFiller2, // Reserve space for future RM actions
|
|
40
|
+
rmFiller3, // Reserve space for future RM actions
|
|
41
|
+
rmFiller4, // Reserve space for future RM actions
|
|
42
|
+
// EToken Governance Actions
|
|
43
|
+
setLPWhitelist, // Changes EToken Liquidity Providers Whitelist
|
|
44
|
+
setLiquidityRequirement,
|
|
45
|
+
setMinUtilizationRate,
|
|
46
|
+
setMaxUtilizationRate,
|
|
47
|
+
setInternalLoanInterestRate,
|
|
48
|
+
etkFiller1, // Reserve space for future EToken actions
|
|
49
|
+
etkFiller2, // Reserve space for future EToken actions
|
|
50
|
+
etkFiller3, // Reserve space for future EToken actions
|
|
51
|
+
etkFiller4, // Reserve space for future EToken actions
|
|
52
|
+
// PremiumsAccount Governance Actions
|
|
53
|
+
setDeficitRatio,
|
|
54
|
+
setDeficitRatioWithAdjustment,
|
|
55
|
+
paFiller1,
|
|
56
|
+
paFiller2,
|
|
57
|
+
paFiller3,
|
|
58
|
+
paFiller4,
|
|
59
|
+
// AssetManager Governance Actions
|
|
60
|
+
setLiquidityMin,
|
|
61
|
+
setLiquidityMiddle,
|
|
62
|
+
setLiquidityMax,
|
|
63
|
+
amFiller1, // Reserve space for future Asset Manager actions
|
|
64
|
+
amFiller2, // Reserve space for future Asset Manager actions
|
|
65
|
+
amFiller3, // Reserve space for future Asset Manager actions
|
|
66
|
+
amFiller4, // Reserve space for future Asset Manager actions
|
|
67
|
+
last
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @dev Gets a role identifier mixing the hash of the global role and the address of the component
|
|
72
|
+
*
|
|
73
|
+
* @param component The component where this role will apply
|
|
74
|
+
* @param role A role such as `keccak256("LEVEL1_ROLE")` that's global
|
|
75
|
+
* @return A new role, mixing (XOR) the component address and the role.
|
|
76
|
+
*/
|
|
77
|
+
function getComponentRole(address component, bytes32 role) external view returns (bytes32);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @dev Tells if a user has been granted a given role for a component
|
|
81
|
+
*
|
|
82
|
+
* @param component The component where this role will apply
|
|
83
|
+
* @param role A role such as `keccak256("LEVEL1_ROLE")` that's global
|
|
84
|
+
* @param account The user address for who we want to verify the permission
|
|
85
|
+
* @param alsoGlobal If true, it will return if the users has either the component role, or the role itself.
|
|
86
|
+
* If false, only the component role is accepted
|
|
87
|
+
* @return Whether the user has or not any of the roles
|
|
88
|
+
*/
|
|
89
|
+
function hasComponentRole(
|
|
90
|
+
address component,
|
|
91
|
+
bytes32 role,
|
|
92
|
+
address account,
|
|
93
|
+
bool alsoGlobal
|
|
94
|
+
) external view returns (bool);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @dev Checks if a user has been granted a given role and reverts if it doesn't
|
|
98
|
+
*
|
|
99
|
+
* @param role A role such as `keccak256("LEVEL1_ROLE")` that's global
|
|
100
|
+
* @param account The user address for who we want to verify the permission
|
|
101
|
+
*/
|
|
102
|
+
function checkRole(bytes32 role, address account) external view;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @dev Checks if a user has been granted any of the two roles specified and reverts if it doesn't
|
|
106
|
+
*
|
|
107
|
+
* @param role1 A role such as `keccak256("LEVEL1_ROLE")` that's global
|
|
108
|
+
* @param role2 Another role such as `keccak256("GUARDIAN_ROLE")` that's global
|
|
109
|
+
* @param account The user address for who we want to verify the permission
|
|
110
|
+
*/
|
|
111
|
+
function checkRole2(
|
|
112
|
+
bytes32 role1,
|
|
113
|
+
bytes32 role2,
|
|
114
|
+
address account
|
|
115
|
+
) external view;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @dev Checks if a user has been granted a given component role and reverts if it doesn't
|
|
119
|
+
*
|
|
120
|
+
* @param role A role such as `keccak256("LEVEL1_ROLE")` that's global
|
|
121
|
+
* @param account The user address for who we want to verify the permission
|
|
122
|
+
* @param alsoGlobal If true, it will accept not only the component role, but also the (global) `role` itself.
|
|
123
|
+
* If false, only the component role is accepted
|
|
124
|
+
*/
|
|
125
|
+
function checkComponentRole(
|
|
126
|
+
address component,
|
|
127
|
+
bytes32 role,
|
|
128
|
+
address account,
|
|
129
|
+
bool alsoGlobal
|
|
130
|
+
) external view;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @dev Checks if a user has been granted any of the two component roles specified and reverts if it doesn't
|
|
134
|
+
*
|
|
135
|
+
* @param role1 A role such as `keccak256("LEVEL1_ROLE")` that's global
|
|
136
|
+
* @param role2 Another role such as `keccak256("GUARDIAN_ROLE")` that's global
|
|
137
|
+
* @param account The user address for who we want to verify the permission
|
|
138
|
+
* @param alsoGlobal If true, it will accept not only the component roles, but also the global ones.
|
|
139
|
+
* If false, only the component roles are accepted
|
|
140
|
+
*/
|
|
141
|
+
function checkComponentRole2(
|
|
142
|
+
address component,
|
|
143
|
+
bytes32 role1,
|
|
144
|
+
bytes32 role2,
|
|
145
|
+
address account,
|
|
146
|
+
bool alsoGlobal
|
|
147
|
+
) external view;
|
|
148
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title IAssetManager - Interface of the asset management strategy that's plugged into the reserves
|
|
6
|
+
* @dev The asset manager is a contract that's plugged and called with `delegatecall` (operates in the context of the
|
|
7
|
+
* reserve - see {Reserve}). The asset manager contract applies a strategy to invest the reserve funds and
|
|
8
|
+
* get additional yields.
|
|
9
|
+
* @author Ensuro
|
|
10
|
+
*/
|
|
11
|
+
interface IAssetManager {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Event emitted when funds are removed from Reserve liquidity and invested in the investment strategy,
|
|
14
|
+
* @param amount The amount invested
|
|
15
|
+
*/
|
|
16
|
+
event MoneyInvested(uint256 amount);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @dev Event emitted when funds are deinvested from the investment strategy and returned to the reserve as liquid
|
|
20
|
+
* funds.
|
|
21
|
+
*
|
|
22
|
+
* @param amount The amount de-invested
|
|
23
|
+
*/
|
|
24
|
+
event MoneyDeinvested(uint256 amount);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @dev Event emitted when investment yields are accounted in the reserve
|
|
28
|
+
*
|
|
29
|
+
* @param earnings The amount of earnings generated since last record. It's positive in the case of earnings or
|
|
30
|
+
* negative when there are losses.
|
|
31
|
+
*/
|
|
32
|
+
event EarningsRecorded(int256 earnings);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @dev Function called when an asset manager is plugged into a reserve. Useful for initialization tasks
|
|
36
|
+
*/
|
|
37
|
+
function connect() external;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @dev Gives the opportunity to the asset manager to rebalance the funds between those that are kept liquid in the
|
|
41
|
+
* reserve balance and those that are invested. Called with delegatecall by the reserve from the external function
|
|
42
|
+
* rebalance (see {Reserve-rebalance}).
|
|
43
|
+
*
|
|
44
|
+
* Events:
|
|
45
|
+
* - Emits {MoneyInvested} or {MoneyDeinvested}
|
|
46
|
+
*/
|
|
47
|
+
function rebalance() external;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @dev Gives the opportunity to the asset manager to rebalance the funds between those that are kept liquid in the
|
|
51
|
+
* reserve balance and those that are invested. Called with delegatecall by the reserve from the external function
|
|
52
|
+
* rebalance (see {Reserve-rebalance}).
|
|
53
|
+
*
|
|
54
|
+
* Events:
|
|
55
|
+
* - Emits {MoneyInvested} or {MoneyDeinvested}
|
|
56
|
+
*/
|
|
57
|
+
function recordEarnings() external returns (int256);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @dev Refills the reserve balance with enought money to do a payment. Called from the reserve when a payment needs
|
|
61
|
+
* to be made and there's no enought liquid balance (`currency().balanceOf(reserve) < paymentAmount`)
|
|
62
|
+
*
|
|
63
|
+
* Events:
|
|
64
|
+
* - Emits {MoneyDeinvested} with the amount transferred to the liquid balance.
|
|
65
|
+
*
|
|
66
|
+
* @param paymentAmount The total amount of the payment that needs to be made. If this function is called, it's
|
|
67
|
+
* because paymentAmount > balanceOf(reserve). The minimum amount that needs to be transferred to the reserve is
|
|
68
|
+
* `paymentAmount - balanceOf(reserve)`, but it can transfer more.
|
|
69
|
+
* @return Returns the actual amount transferred
|
|
70
|
+
*/
|
|
71
|
+
function refillWallet(uint256 paymentAmount) external returns (uint256);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @dev Deinvests all the funds transfer all the assets to the liquid balance. Called from the reserve when the asset
|
|
75
|
+
* manager is unplugged.
|
|
76
|
+
*
|
|
77
|
+
* Events:
|
|
78
|
+
* - Emits {MoneyDeinvested} with the amount transferred to the liquid balance.
|
|
79
|
+
* - Emits {EarningsRecorded} with the amount of earnings since earnings were recorded last time.
|
|
80
|
+
*
|
|
81
|
+
* @return Returns the earnings or losses (negative) since last time earnings were recorded.
|
|
82
|
+
*/
|
|
83
|
+
function deinvestAll() external returns (int256);
|
|
84
|
+
}
|
|
@@ -9,6 +9,16 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
9
9
|
* @author Ensuro
|
|
10
10
|
*/
|
|
11
11
|
interface IEToken is IERC20 {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Enum of the different parameters that are configurable in an EToken.
|
|
14
|
+
*/
|
|
15
|
+
enum Parameter {
|
|
16
|
+
liquidityRequirement,
|
|
17
|
+
minUtilizationRate,
|
|
18
|
+
maxUtilizationRate,
|
|
19
|
+
internalLoanInterestRate
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
/**
|
|
13
23
|
* @dev Event emitted when part of the funds of the eToken are locked as solvency capital.
|
|
14
24
|
* @param interestRate The annualized interestRate paid for the capital (wad)
|
|
@@ -77,7 +87,7 @@ interface IEToken is IERC20 {
|
|
|
77
87
|
*
|
|
78
88
|
* @param provider The address of the liquidity provider
|
|
79
89
|
* @param amount The amount deposited.
|
|
80
|
-
* @return The actual balance of the provider
|
|
90
|
+
* @return The actual balance of the provider
|
|
81
91
|
*/
|
|
82
92
|
function deposit(address provider, uint256 amount) external returns (uint256);
|
|
83
93
|
|
|
@@ -110,12 +120,25 @@ interface IEToken is IERC20 {
|
|
|
110
120
|
* - Must be called by `policyPool()`
|
|
111
121
|
*
|
|
112
122
|
* Events:
|
|
113
|
-
* - Emits {
|
|
123
|
+
* - Emits {InternalBorrowerAdded}
|
|
114
124
|
*
|
|
115
125
|
* @param borrower The address of the _borrower_, a PremiumsAccount that has this eToken as senior or junior eToken.
|
|
116
126
|
*/
|
|
117
127
|
function addBorrower(address borrower) external;
|
|
118
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @dev Removes an authorized _borrower_ to the eToken. The _borrower_ can't no longer lock funds or take loans.
|
|
131
|
+
*
|
|
132
|
+
* Requirements:
|
|
133
|
+
* - Must be called by `policyPool()`
|
|
134
|
+
*
|
|
135
|
+
* Events:
|
|
136
|
+
* - Emits {InternalBorrowerRemoved} with the defaulted debt
|
|
137
|
+
*
|
|
138
|
+
* @param borrower The address of the _borrower_, a PremiumsAccount that has this eToken as senior or junior eToken.
|
|
139
|
+
*/
|
|
140
|
+
function removeBorrower(address borrower) external;
|
|
141
|
+
|
|
119
142
|
/**
|
|
120
143
|
* @dev Lends `amount` to the borrower (msg.sender), transferring the money to `receiver`. This reduces the
|
|
121
144
|
* `totalSupply()` of the eToken, and stores a debt that will be repaid (hopefully) with `repayLoan`.
|
|
@@ -8,12 +8,29 @@ import {IEToken} from "./IEToken.sol";
|
|
|
8
8
|
* @author Ensuro
|
|
9
9
|
*/
|
|
10
10
|
interface ILPWhitelist {
|
|
11
|
+
/**
|
|
12
|
+
* @dev Indicates whether or not a liquidity provider can do a deposit in an eToken.
|
|
13
|
+
*
|
|
14
|
+
* @param etoken The eToken (see {EToken}) where the provider wants to deposit money.
|
|
15
|
+
* @param provider The address of the liquidity provider (user) that wants to deposit
|
|
16
|
+
* @param amount The amount of the deposit
|
|
17
|
+
* @return true if `provider` deposit is accepted, false if not
|
|
18
|
+
*/
|
|
11
19
|
function acceptsDeposit(
|
|
12
20
|
IEToken etoken,
|
|
13
21
|
address provider,
|
|
14
22
|
uint256 amount
|
|
15
23
|
) external view returns (bool);
|
|
16
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @dev Indicates whether or not the eTokens can be transferred from `providerFrom` to `providerTo`
|
|
27
|
+
*
|
|
28
|
+
* @param etoken The eToken (see {EToken}) that the LPs have the intention to transfer.
|
|
29
|
+
* @param providerFrom The current owner of the tokens
|
|
30
|
+
* @param providerTo The destination of the tokens if the transfer is accepted
|
|
31
|
+
* @param amount The amount of tokens to be transferred
|
|
32
|
+
* @return true if the transfer operation is accepted, false if not.
|
|
33
|
+
*/
|
|
17
34
|
function acceptsTransfer(
|
|
18
35
|
IEToken etoken,
|
|
19
36
|
address providerFrom,
|
|
@@ -4,7 +4,7 @@ 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 {
|
|
7
|
+
import {IAccessManager} from "./IAccessManager.sol";
|
|
8
8
|
|
|
9
9
|
interface IPolicyPool {
|
|
10
10
|
/**
|
|
@@ -14,40 +14,40 @@ interface IPolicyPool {
|
|
|
14
14
|
function currency() external view returns (IERC20Metadata);
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* @dev Reference to the {
|
|
18
|
-
*
|
|
19
|
-
* @return The address of the PolicyPoolConfig contract
|
|
17
|
+
* @dev Reference to the {AccessManager} contract, this contract manages the access controls.
|
|
18
|
+
* @return The address of the AccessManager contract
|
|
20
19
|
*/
|
|
21
|
-
function
|
|
20
|
+
function access() external view returns (IAccessManager);
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
|
-
* @dev
|
|
25
|
-
*
|
|
26
|
-
* @return The address of the PolicyNFT contract
|
|
23
|
+
* @dev Address of the treasury, that receives protocol fees.
|
|
24
|
+
* @return The address of the treasury
|
|
27
25
|
*/
|
|
28
|
-
function
|
|
26
|
+
function treasury() external view returns (address);
|
|
29
27
|
|
|
30
28
|
/**
|
|
31
29
|
* @dev Creates a new Policy. Must be called from an active RiskModule
|
|
32
30
|
*
|
|
33
31
|
* Requirements:
|
|
34
32
|
* - `msg.sender` must be an active RiskModule
|
|
35
|
-
* - `
|
|
33
|
+
* - `caller` approved the spending of `currency()` for at least `policy.premium`
|
|
36
34
|
* - `internalId` must be unique within `policy.riskModule` and not used before
|
|
37
35
|
*
|
|
38
36
|
* Events:
|
|
39
37
|
* - {PolicyPool-NewPolicy}: with all the details about the policy
|
|
40
|
-
* - {ERC20-Transfer}: does several transfers from
|
|
38
|
+
* - {ERC20-Transfer}: does several transfers from caller address to the different receivers of the premium
|
|
41
39
|
* (see Premium Split in the docs)
|
|
42
40
|
*
|
|
43
41
|
* @param policy A policy created with {Policy-initialize}
|
|
44
|
-
* @param
|
|
42
|
+
* @param caller The pricer that's creating the policy and will pay for the premium
|
|
43
|
+
* @param policyHolder The address of the policy holder and the payer of the premiums
|
|
45
44
|
* @param internalId A unique id within the RiskModule, that will be used to compute the policy id
|
|
46
45
|
* @return The policy id, identifying the NFT and the policy
|
|
47
46
|
*/
|
|
48
47
|
function newPolicy(
|
|
49
48
|
Policy.PolicyData memory policy,
|
|
50
|
-
address
|
|
49
|
+
address caller,
|
|
50
|
+
address policyHolder,
|
|
51
51
|
uint96 internalId
|
|
52
52
|
) external returns (uint256);
|
|
53
53
|
|
|
@@ -100,6 +100,13 @@ interface IPolicyPool {
|
|
|
100
100
|
*/
|
|
101
101
|
function expirePolicy(Policy.PolicyData calldata policy) external;
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* @dev Returns whether or not a policy is active
|
|
105
|
+
* @param policyId The id of the policy we are querying
|
|
106
|
+
* @return Returns true if a policy with that id was created and wasn't yet resolved or expired, or false otherwise.
|
|
107
|
+
*/
|
|
108
|
+
function isActive(uint256 policyId) external view returns (bool);
|
|
109
|
+
|
|
103
110
|
/**
|
|
104
111
|
* @dev Deposits liquidity into an eToken. Forwards the call to {EToken-deposit}, after transferring the funds.
|
|
105
112
|
* The user will receive etokens for the same amount deposited.
|
|
@@ -9,5 +9,8 @@ import {IPolicyPool} from "./IPolicyPool.sol";
|
|
|
9
9
|
* @author Ensuro
|
|
10
10
|
*/
|
|
11
11
|
interface IPolicyPoolComponent {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Returns the address of the PolicyPool (see {PolicyPool}) where this component belongs.
|
|
14
|
+
*/
|
|
12
15
|
function policyPool() external view returns (IPolicyPool);
|
|
13
16
|
}
|
|
@@ -68,4 +68,9 @@ interface IPremiumsAccount {
|
|
|
68
68
|
* @dev The junior eToken, the primary source of solvency, used if the premiums account is exhausted.
|
|
69
69
|
*/
|
|
70
70
|
function juniorEtk() external view returns (IEToken);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @dev The total amount of premiums hold by this PremiumsAccount
|
|
74
|
+
*/
|
|
75
|
+
function purePremiums() external view returns (uint256);
|
|
71
76
|
}
|