@ensuro/core 1.2.7 → 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 +63 -27
- 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 +217 -190
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +17 -4
- package/build/contracts/{extras/IPriceRiskModule.sol/IPriceRiskModule.json → LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json} +81 -131
- package/build/contracts/Policy.sol/Policy.json +2 -2
- package/build/contracts/PolicyPool.sol/PolicyPool.json +425 -295
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +15 -2
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +868 -0
- package/build/contracts/{BaseAssetManager.sol/BaseAssetManager.json → Reserve.sol/Reserve.json} +37 -166
- package/build/contracts/RiskModule.sol/RiskModule.json +85 -312
- package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +960 -0
- package/build/contracts/{DataTypes.sol/DataTypes.json → TimeScaled.sol/TimeScaled.json} +4 -4
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +134 -336
- package/build/contracts/dependencies/ERC1967Proxy.sol/ERC1967Proxy.json +64 -0
- package/build/{interfaces/IExchange.sol/IExchange.json → contracts/dependencies/IERC20Metadata.sol/IERC20Metadata.json} +83 -79
- package/build/contracts/{WadRayMath.sol → dependencies/WadRayMath.sol}/WadRayMath.json +3 -3
- package/build/{interfaces/IPolicyPoolConfig.sol/IPolicyPoolConfig.json → contracts/interfaces/IAccessManager.sol/IAccessManager.json} +79 -77
- package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +109 -0
- package/build/{interfaces → contracts/interfaces}/IEToken.sol/IEToken.json +39 -91
- package/build/{interfaces → contracts/interfaces}/ILPWhitelist.sol/ILPWhitelist.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyHolder.sol/IPolicyHolder.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyPool.sol/IPolicyPool.json +137 -100
- package/build/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +1 -1
- package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +315 -0
- package/build/{interfaces → contracts/interfaces}/IRiskModule.sol/IRiskModule.json +58 -34
- package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +736 -0
- package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +43 -0
- package/build/{interfaces/IInsolvencyHook.sol/IInsolvencyHook.json → contracts/mocks/IMintableERC20.sol/IMintableERC20.json} +13 -8
- package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +228 -0
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +35 -0
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +702 -0
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +92 -0
- package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +764 -0
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +343 -0
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +388 -0
- package/contracts/AccessManager.sol +103 -0
- package/contracts/ERC4626AssetManager.sol +52 -0
- package/contracts/EToken.sol +254 -299
- package/contracts/LPManualWhitelist.sol +4 -4
- package/contracts/LiquidityThresholdAssetManager.sol +160 -0
- package/contracts/Policy.sol +49 -45
- package/contracts/PolicyPool.sol +379 -514
- package/contracts/PolicyPoolComponent.sol +41 -41
- package/contracts/PremiumsAccount.sol +480 -0
- package/contracts/Reserve.sol +213 -0
- package/contracts/RiskModule.sol +233 -174
- package/contracts/SignedQuoteRiskModule.sol +241 -0
- package/contracts/TimeScaled.sol +138 -0
- package/contracts/TrustfulRiskModule.sol +85 -23
- package/contracts/dependencies/ERC1967Proxy.sol +19 -0
- package/contracts/dependencies/IERC20Metadata.sol +19 -0
- 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 +195 -0
- package/contracts/interfaces/ILPWhitelist.sol +40 -0
- package/{interfaces → contracts/interfaces}/IPolicyHolder.sol +0 -0
- package/contracts/interfaces/IPolicyPool.sol +145 -0
- package/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol +3 -0
- package/contracts/interfaces/IPremiumsAccount.sol +76 -0
- package/contracts/interfaces/IRiskModule.sol +123 -0
- package/contracts/mocks/FixedRateVault.sol +85 -0
- package/contracts/mocks/ForwardProxy.sol +66 -0
- package/contracts/mocks/IMintableERC20.sol +13 -0
- package/contracts/mocks/PolicyHolderMock.sol +89 -0
- package/contracts/mocks/PolicyPoolComponentMock.sol +17 -0
- package/contracts/mocks/PolicyPoolMock.sol +148 -0
- package/contracts/mocks/RiskModuleMock.sol +75 -0
- package/contracts/mocks/TestCurrency.sol +35 -0
- package/contracts/mocks/TestNFT.sol +23 -0
- package/js/test-utils.js +356 -0
- package/package.json +2 -2
- package/build/contracts/AaveAssetManager.sol/AaveAssetManager.json +0 -742
- package/build/contracts/Exchange.sol/Exchange.json +0 -591
- package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +0 -1112
- package/build/contracts/PolicyNFT.sol/PolicyNFT.json +0 -570
- package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +0 -686
- package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +0 -50
- package/build/contracts/extras/PriceRiskModule.sol/PriceRiskModule.json +0 -1055
- package/build/contracts/upgraded/IPolicyNFTv1.sol/IPolicyNFTv1.json +0 -322
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +0 -571
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +0 -602
- package/build/interfaces/IAssetManager.sol/IAssetManager.json +0 -31
- package/build/interfaces/IExchange.sol/IPriceOracle.json +0 -30
- package/build/interfaces/IPolicyNFT.sol/IPolicyNFT.json +0 -321
- package/contracts/AaveAssetManager.sol +0 -298
- package/contracts/BaseAssetManager.sol +0 -301
- package/contracts/DataTypes.sol +0 -287
- package/contracts/Exchange.sol +0 -189
- package/contracts/FlightDelayRiskModule.sol +0 -208
- package/contracts/PolicyNFT.sol +0 -96
- package/contracts/PolicyPoolConfig.sol +0 -247
- package/contracts/WadRayMath.sol +0 -135
- package/contracts/dependencies/ChainlinkClientUpgradeable.sol +0 -371
- package/contracts/extras/IPriceRiskModule.sol +0 -41
- package/contracts/extras/PriceRiskModule.sol +0 -243
- package/contracts/upgraded/IPolicyNFTv1.sol +0 -15
- package/contracts/upgraded/PolicyNFTv1.sol +0 -126
- package/interfaces/IAssetManager.sol +0 -23
- package/interfaces/IEToken.sol +0 -48
- package/interfaces/IExchange.sol +0 -59
- package/interfaces/IInsolvencyHook.sol +0 -27
- package/interfaces/ILPWhitelist.sol +0 -23
- package/interfaces/IPolicyNFT.sol +0 -15
- package/interfaces/IPolicyPool.sol +0 -44
- package/interfaces/IPolicyPoolConfig.sol +0 -87
- package/interfaces/IRiskModule.sol +0 -29
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title IEToken interface
|
|
8
|
+
* @dev Interface for EToken smart contracts, these are the capital pools.
|
|
9
|
+
* @author Ensuro
|
|
10
|
+
*/
|
|
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
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @dev Event emitted when part of the funds of the eToken are locked as solvency capital.
|
|
24
|
+
* @param interestRate The annualized interestRate paid for the capital (wad)
|
|
25
|
+
* @param value The amount locked
|
|
26
|
+
*/
|
|
27
|
+
event SCRLocked(uint256 interestRate, uint256 value);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @dev Event emitted when the locked funds are unlocked and no longer used as solvency capital.
|
|
31
|
+
* @param interestRate The annualized interestRate that was paid for the capital (wad)
|
|
32
|
+
* @param value The amount unlocked
|
|
33
|
+
*/
|
|
34
|
+
event SCRUnlocked(uint256 interestRate, uint256 value);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @dev Returns the amount of capital that's locked as solvency capital for active policies.
|
|
38
|
+
*/
|
|
39
|
+
function scr() external view returns (uint256);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @dev Locks part of the liquidity of the EToken as solvency capital.
|
|
43
|
+
*
|
|
44
|
+
* Requirements:
|
|
45
|
+
* - Must be called by a _borrower_ previously added with `addBorrower`.
|
|
46
|
+
* - `scrAmount` <= `fundsAvailableToLock()`
|
|
47
|
+
*
|
|
48
|
+
* Events:
|
|
49
|
+
* - Emits {SCRLocked}
|
|
50
|
+
*
|
|
51
|
+
* @param scrAmount The amount to lock
|
|
52
|
+
* @param policyInterestRate The annualized interest rate (wad) to be paid for the `scrAmount`
|
|
53
|
+
*/
|
|
54
|
+
function lockScr(uint256 scrAmount, uint256 policyInterestRate) external;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @dev Unlocks solvency capital previously locked with `lockScr`. The capital no longer needed as solvency.
|
|
58
|
+
*
|
|
59
|
+
* Requirements:
|
|
60
|
+
* - Must be called by a _borrower_ previously added with `addBorrower`.
|
|
61
|
+
* - `scrAmount` <= `scr()`
|
|
62
|
+
*
|
|
63
|
+
* Events:
|
|
64
|
+
* - Emits {SCRUnlocked}
|
|
65
|
+
*
|
|
66
|
+
* @param scrAmount The amount to unlock
|
|
67
|
+
* @param policyInterestRate The annualized interest rate that was paid for the `scrAmount`, must be the same that was
|
|
68
|
+
* sent in `lockScr` call.
|
|
69
|
+
*/
|
|
70
|
+
function unlockScr(
|
|
71
|
+
uint256 scrAmount,
|
|
72
|
+
uint256 policyInterestRate,
|
|
73
|
+
int256 adjustment
|
|
74
|
+
) external;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @dev Registers a deposit of liquidity in the pool. Called from the PolicyPool, assumes the amount has already been
|
|
78
|
+
* transferred. `amount` of eToken are minted and given to the provider in exchange of the liquidity provided.
|
|
79
|
+
*
|
|
80
|
+
* Requirements:
|
|
81
|
+
* - Must be called by `policyPool()`
|
|
82
|
+
* - The amount was transferred
|
|
83
|
+
* - `utilizationRate()` after the deposit is >= `minUtilizationRate()`
|
|
84
|
+
*
|
|
85
|
+
* Events:
|
|
86
|
+
* - Emits {Transfer} with `from` = 0x0 and to = `provider`
|
|
87
|
+
*
|
|
88
|
+
* @param provider The address of the liquidity provider
|
|
89
|
+
* @param amount The amount deposited.
|
|
90
|
+
* @return The actual balance of the provider
|
|
91
|
+
*/
|
|
92
|
+
function deposit(address provider, uint256 amount) external returns (uint256);
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @dev Withdraws an amount from an eToken. `withdrawn` eTokens are be burned and the user receives the same amount
|
|
96
|
+
* in `currency()`. If the asked `amount` can't be withdrawn, it withdraws as much as possible
|
|
97
|
+
*
|
|
98
|
+
* Requirements:
|
|
99
|
+
* - Must be called by `policyPool()`
|
|
100
|
+
*
|
|
101
|
+
* Events:
|
|
102
|
+
* - Emits {Transfer} with `from` = `provider` and to = `0x0`
|
|
103
|
+
*
|
|
104
|
+
* @param provider The address of the liquidity provider
|
|
105
|
+
* @param amount The amount to withdraw. If `amount` == `type(uint256).max`, then tries to withdraw all the balance.
|
|
106
|
+
* @return withdrawn The actual amount that withdrawn. `withdrawn <= amount && withdrawn <= balanceOf(provider)`
|
|
107
|
+
*/
|
|
108
|
+
function withdraw(address provider, uint256 amount) external returns (uint256 withdrawn);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @dev Returns the total amount that can be withdrawn
|
|
112
|
+
*/
|
|
113
|
+
function totalWithdrawable() external view returns (uint256);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @dev Adds an authorized _borrower_ to the eToken. This _borrower_ will be allowed to lock/unlock funds and to take
|
|
117
|
+
* loans.
|
|
118
|
+
*
|
|
119
|
+
* Requirements:
|
|
120
|
+
* - Must be called by `policyPool()`
|
|
121
|
+
*
|
|
122
|
+
* Events:
|
|
123
|
+
* - Emits {InternalBorrowerAdded}
|
|
124
|
+
*
|
|
125
|
+
* @param borrower The address of the _borrower_, a PremiumsAccount that has this eToken as senior or junior eToken.
|
|
126
|
+
*/
|
|
127
|
+
function addBorrower(address borrower) external;
|
|
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
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @dev Lends `amount` to the borrower (msg.sender), transferring the money to `receiver`. This reduces the
|
|
144
|
+
* `totalSupply()` of the eToken, and stores a debt that will be repaid (hopefully) with `repayLoan`.
|
|
145
|
+
*
|
|
146
|
+
* Requirements:
|
|
147
|
+
* - Must be called by a _borrower_ previously added with `addBorrower`.
|
|
148
|
+
*
|
|
149
|
+
* Events:
|
|
150
|
+
* - Emits {InternalLoan}
|
|
151
|
+
* - Emits {ERC20-Transfer} transferring `lent` to `receiver`
|
|
152
|
+
*
|
|
153
|
+
* @param amount The amount required
|
|
154
|
+
* @param receiver The received of the funds lent. This is usually the policyholder if the loan is used for a payout.
|
|
155
|
+
* @param fromAvailable If `true`, the funds that can be lent are only the available ones, i.e., excluding the funds
|
|
156
|
+
* locked as `scr()`. If `false`, all the `totalSupply()` is available to be lent.
|
|
157
|
+
* @return Returns the amount that wasn't able to fulfil. `amount - lent`
|
|
158
|
+
*/
|
|
159
|
+
function internalLoan(
|
|
160
|
+
uint256 amount,
|
|
161
|
+
address receiver,
|
|
162
|
+
bool fromAvailable
|
|
163
|
+
) external returns (uint256);
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @dev Repays a loan taken with `internalLoan`.
|
|
167
|
+
*
|
|
168
|
+
* Requirements:
|
|
169
|
+
* - `msg.sender` approved the spending of `currency()` for at least `amount`
|
|
170
|
+
|
|
171
|
+
* Events:
|
|
172
|
+
* - Emits {InternalLoanRepaid}
|
|
173
|
+
* - Emits {ERC20-Transfer} transferring `amount` from `msg.sender` to `this`
|
|
174
|
+
*
|
|
175
|
+
* @param amount The amount to repaid, that will be transferred from `msg.sender` balance.
|
|
176
|
+
* @param onBehalfOf The address of the borrower that took the loan. Usually `onBehalfOf == msg.sender` but we keep it
|
|
177
|
+
* open because in some cases with might need someone else pays the debt.
|
|
178
|
+
*/
|
|
179
|
+
function repayLoan(uint256 amount, address onBehalfOf) external;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @dev Returns the updated debt (principal + interest) of the `borrower`.
|
|
183
|
+
*/
|
|
184
|
+
function getLoan(address borrower) external view returns (uint256);
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @dev The annualized interest rate at which the `totalSupply()` grows
|
|
188
|
+
*/
|
|
189
|
+
function tokenInterestRate() external view returns (uint256);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @dev The weighted average annualized interest rate paid by the currently locked `scr()`.
|
|
193
|
+
*/
|
|
194
|
+
function scrInterestRate() external view returns (uint256);
|
|
195
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IEToken} from "./IEToken.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title ILPWhitelist - Interface that handles the whitelisting of Liquidity Providers
|
|
8
|
+
* @author Ensuro
|
|
9
|
+
*/
|
|
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
|
+
*/
|
|
19
|
+
function acceptsDeposit(
|
|
20
|
+
IEToken etoken,
|
|
21
|
+
address provider,
|
|
22
|
+
uint256 amount
|
|
23
|
+
) external view returns (bool);
|
|
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
|
+
*/
|
|
34
|
+
function acceptsTransfer(
|
|
35
|
+
IEToken etoken,
|
|
36
|
+
address providerFrom,
|
|
37
|
+
address providerTo,
|
|
38
|
+
uint256 amount
|
|
39
|
+
) external view returns (bool);
|
|
40
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
5
|
+
import {Policy} from "../Policy.sol";
|
|
6
|
+
import {IEToken} from "./IEToken.sol";
|
|
7
|
+
import {IAccessManager} from "./IAccessManager.sol";
|
|
8
|
+
|
|
9
|
+
interface IPolicyPool {
|
|
10
|
+
/**
|
|
11
|
+
* @dev Reference to the main currency (ERC20) used in the protocol
|
|
12
|
+
* @return The address of the currency (e.g. USDC) token used in the protocol
|
|
13
|
+
*/
|
|
14
|
+
function currency() external view returns (IERC20Metadata);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @dev Reference to the {AccessManager} contract, this contract manages the access controls.
|
|
18
|
+
* @return The address of the AccessManager contract
|
|
19
|
+
*/
|
|
20
|
+
function access() external view returns (IAccessManager);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @dev Address of the treasury, that receives protocol fees.
|
|
24
|
+
* @return The address of the treasury
|
|
25
|
+
*/
|
|
26
|
+
function treasury() external view returns (address);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @dev Creates a new Policy. Must be called from an active RiskModule
|
|
30
|
+
*
|
|
31
|
+
* Requirements:
|
|
32
|
+
* - `msg.sender` must be an active RiskModule
|
|
33
|
+
* - `caller` approved the spending of `currency()` for at least `policy.premium`
|
|
34
|
+
* - `internalId` must be unique within `policy.riskModule` and not used before
|
|
35
|
+
*
|
|
36
|
+
* Events:
|
|
37
|
+
* - {PolicyPool-NewPolicy}: with all the details about the policy
|
|
38
|
+
* - {ERC20-Transfer}: does several transfers from caller address to the different receivers of the premium
|
|
39
|
+
* (see Premium Split in the docs)
|
|
40
|
+
*
|
|
41
|
+
* @param policy A policy created with {Policy-initialize}
|
|
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
|
|
44
|
+
* @param internalId A unique id within the RiskModule, that will be used to compute the policy id
|
|
45
|
+
* @return The policy id, identifying the NFT and the policy
|
|
46
|
+
*/
|
|
47
|
+
function newPolicy(
|
|
48
|
+
Policy.PolicyData memory policy,
|
|
49
|
+
address caller,
|
|
50
|
+
address policyHolder,
|
|
51
|
+
uint96 internalId
|
|
52
|
+
) external returns (uint256);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @dev Resolves a policy with a payout. Must be called from an active RiskModule
|
|
56
|
+
*
|
|
57
|
+
* Requirements:
|
|
58
|
+
* - `policy`: must be a Policy previously created with `newPolicy` (checked with `policy.hash()`) and not
|
|
59
|
+
* resolved before and not expired (if payout > 0).
|
|
60
|
+
* - `payout`: must be less than equal to `policy.payout`.
|
|
61
|
+
*
|
|
62
|
+
* Events:
|
|
63
|
+
* - {PolicyPool-PolicyResolved}: with the payout
|
|
64
|
+
* - {ERC20-Transfer}: to the policyholder with the payout
|
|
65
|
+
*
|
|
66
|
+
* @param policy A policy previously created with `newPolicy`
|
|
67
|
+
* @param payout The amount to paid to the policyholder
|
|
68
|
+
*/
|
|
69
|
+
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout) external;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @dev Resolves a policy with a payout that can be either 0 or the maximum payout of the policy
|
|
73
|
+
*
|
|
74
|
+
* Requirements:
|
|
75
|
+
* - `policy`: must be a Policy previously created with `newPolicy` (checked with `policy.hash()`) and not
|
|
76
|
+
* resolved before and not expired (if customerWon).
|
|
77
|
+
*
|
|
78
|
+
* Events:
|
|
79
|
+
* - {PolicyPool-PolicyResolved}: with the payout
|
|
80
|
+
* - {ERC20-Transfer}: to the policyholder with the payout
|
|
81
|
+
*
|
|
82
|
+
* @param policy A policy previously created with `newPolicy`
|
|
83
|
+
* @param customerWon Indicated if the payout is zero or the maximum payout
|
|
84
|
+
*/
|
|
85
|
+
function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon) external;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @dev Resolves a policy with a payout 0, unlocking the solvency. Can be called by anyone, but only after
|
|
89
|
+
* `Policy.expiration`.
|
|
90
|
+
*
|
|
91
|
+
* Requirements:
|
|
92
|
+
* - `policy`: must be a Policy previously created with `newPolicy` (checked with `policy.hash()`) and not resolved
|
|
93
|
+
* before
|
|
94
|
+
* - Policy expired: `Policy.expiration` <= block.timestamp
|
|
95
|
+
*
|
|
96
|
+
* Events:
|
|
97
|
+
* - {PolicyPool-PolicyResolved}: with payout == 0
|
|
98
|
+
*
|
|
99
|
+
* @param policy A policy previously created with `newPolicy`
|
|
100
|
+
*/
|
|
101
|
+
function expirePolicy(Policy.PolicyData calldata policy) external;
|
|
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
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @dev Deposits liquidity into an eToken. Forwards the call to {EToken-deposit}, after transferring the funds.
|
|
112
|
+
* The user will receive etokens for the same amount deposited.
|
|
113
|
+
*
|
|
114
|
+
* Requirements:
|
|
115
|
+
* - `msg.sender` approved the spending of `currency()` for at least `amount`
|
|
116
|
+
* - `eToken` is an active eToken installed in the pool.
|
|
117
|
+
*
|
|
118
|
+
* Events:
|
|
119
|
+
* - {EToken-Transfer}: from 0x0 to `msg.sender`, reflects the eTokens minted.
|
|
120
|
+
* - {ERC20-Transfer}: from `msg.sender` to address(eToken)
|
|
121
|
+
*
|
|
122
|
+
* @param eToken The address of the eToken to which the user wants to provide liquidity
|
|
123
|
+
* @param amount The amount to deposit
|
|
124
|
+
*/
|
|
125
|
+
function deposit(IEToken eToken, uint256 amount) external;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @dev Withdraws an amount from an eToken. Forwards the call to {EToken-withdraw}.
|
|
129
|
+
* `amount` of eTokens will be burned and the user will receive the same amount in `currency()`.
|
|
130
|
+
*
|
|
131
|
+
* Requirements:
|
|
132
|
+
* - `eToken` is an active (or deprecated) eToken installed in the pool.
|
|
133
|
+
*
|
|
134
|
+
* Events:
|
|
135
|
+
* - {EToken-Transfer}: from `msg.sender` to `0x0`, reflects the eTokens burned.
|
|
136
|
+
* - {ERC20-Transfer}: from address(eToken) to `msg.sender`
|
|
137
|
+
*
|
|
138
|
+
* @param eToken The address of the eToken from where the user wants to withdraw liquidity
|
|
139
|
+
* @param amount The amount to withdraw. If equal to type(uint256).max, means full withdrawal.
|
|
140
|
+
* If the balance is not enought or can't be withdrawn (locked as SCR), it withdraws
|
|
141
|
+
* as much as it can, but doesn't fails.
|
|
142
|
+
* @return Returns the actual amount withdrawn.
|
|
143
|
+
*/
|
|
144
|
+
function withdraw(IEToken eToken, uint256 amount) external returns (uint256);
|
|
145
|
+
}
|
|
@@ -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
|
}
|