@ensuro/core 1.2.6 → 2.0.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 +49 -17
- package/build/contracts/EToken.sol/EToken.json +163 -173
- package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +112 -315
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +34 -2
- package/build/contracts/Policy.sol/Policy.json +2 -2
- package/build/contracts/PolicyNFT.sol/PolicyNFT.json +16 -3
- package/build/contracts/PolicyPool.sol/PolicyPool.json +105 -351
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +32 -0
- package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +77 -98
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +761 -0
- package/build/contracts/{BaseAssetManager.sol/BaseAssetManager.json → Reserve.sol/Reserve.json} +23 -191
- package/build/contracts/RiskModule.sol/RiskModule.json +94 -302
- package/build/contracts/TimeScaled.sol/TimeScaled.json +24 -0
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +142 -325
- package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +15 -2
- 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/{interfaces → contracts/interfaces}/IEToken.sol/IEToken.json +32 -97
- 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}/IPolicyNFT.sol/IPolicyNFT.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyPool.sol/IPolicyPool.json +121 -108
- package/build/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +1 -1
- package/build/{interfaces → contracts/interfaces}/IPolicyPoolConfig.sol/IPolicyPoolConfig.json +20 -49
- package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +302 -0
- package/build/{interfaces → contracts/interfaces}/IRiskModule.sol/IRiskModule.json +58 -34
- 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/LinkTokenMock.sol/LinkTokenMock.json +370 -0
- package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +202 -0
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +35 -0
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +603 -0
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +92 -0
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +343 -0
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +388 -0
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +16 -3
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +16 -3
- package/contracts/EToken.sol +210 -267
- package/contracts/FlightDelayRiskModule.sol +30 -21
- package/contracts/LPManualWhitelist.sol +4 -4
- package/contracts/Policy.sol +48 -44
- package/contracts/PolicyNFT.sol +2 -2
- package/contracts/PolicyPool.sol +114 -467
- package/contracts/PolicyPoolComponent.sol +14 -3
- package/contracts/PolicyPoolConfig.sol +29 -91
- package/contracts/PremiumsAccount.sol +274 -0
- package/contracts/Reserve.sol +34 -0
- package/contracts/RiskModule.sol +216 -164
- package/contracts/TimeScaled.sol +134 -0
- package/contracts/TrustfulRiskModule.sol +23 -21
- package/contracts/dependencies/ERC1967Proxy.sol +19 -0
- package/contracts/dependencies/IERC20Metadata.sol +19 -0
- package/contracts/interfaces/IEToken.sol +172 -0
- package/{interfaces → contracts/interfaces}/ILPWhitelist.sol +0 -0
- package/{interfaces → contracts/interfaces}/IPolicyHolder.sol +0 -0
- package/{interfaces → contracts/interfaces}/IPolicyNFT.sol +0 -0
- package/contracts/interfaces/IPolicyPool.sol +138 -0
- package/{interfaces → contracts/interfaces}/IPolicyPoolComponent.sol +0 -0
- package/{interfaces → contracts/interfaces}/IPolicyPoolConfig.sol +31 -22
- package/contracts/interfaces/IPremiumsAccount.sol +71 -0
- package/contracts/interfaces/IRiskModule.sol +60 -0
- package/contracts/mocks/ForwardProxy.sol +66 -0
- package/contracts/mocks/IMintableERC20.sol +13 -0
- package/contracts/mocks/LinkTokenMock.sol +30 -0
- package/contracts/mocks/PolicyHolderMock.sol +68 -0
- package/contracts/mocks/PolicyPoolComponentMock.sol +17 -0
- package/contracts/mocks/PolicyPoolMock.sol +122 -0
- package/contracts/mocks/TestCurrency.sol +35 -0
- package/contracts/mocks/TestNFT.sol +23 -0
- package/contracts/upgraded/PolicyNFTv1.sol +1 -1
- package/js/test-utils.js +278 -0
- package/package.json +2 -2
- package/build/contracts/AaveAssetManager.sol/AaveAssetManager.json +0 -723
- package/build/contracts/DataTypes.sol/DataTypes.json +0 -10
- package/build/contracts/Exchange.sol/Exchange.json +0 -546
- package/build/contracts/extras/IPriceRiskModule.sol/IPriceRiskModule.json +0 -253
- package/build/contracts/extras/PriceRiskModule.sol/PriceRiskModule.json +0 -1036
- package/build/interfaces/IAssetManager.sol/IAssetManager.json +0 -31
- package/build/interfaces/IExchange.sol/IPriceOracle.json +0 -30
- package/contracts/AaveAssetManager.sol +0 -298
- package/contracts/BaseAssetManager.sol +0 -301
- package/contracts/DataTypes.sol +0 -287
- package/contracts/Exchange.sol +0 -173
- package/contracts/extras/IPriceRiskModule.sol +0 -41
- package/contracts/extras/PriceRiskModule.sol +0 -243
- 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/IPolicyPool.sol +0 -44
- package/interfaces/IRiskModule.sol +0 -29
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
import {IPolicyPool} from "
|
|
4
|
+
import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
5
|
+
import {IPremiumsAccount} from "./interfaces/IPremiumsAccount.sol";
|
|
5
6
|
import {RiskModule} from "./RiskModule.sol";
|
|
6
7
|
import {Policy} from "./Policy.sol";
|
|
7
8
|
|
|
@@ -19,35 +20,36 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
19
20
|
|
|
20
21
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
21
22
|
// solhint-disable-next-line no-empty-blocks
|
|
22
|
-
constructor(IPolicyPool policyPool_
|
|
23
|
+
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
|
|
24
|
+
RiskModule(policyPool_, premiumsAccount_)
|
|
25
|
+
{} // solhint-disable-line no-empty-blocks
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* @dev Initializes the RiskModule
|
|
26
29
|
* @param name_ Name of the Risk Module
|
|
27
|
-
* @param
|
|
28
|
-
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param scrLimit_ Max SCR to be allocated to this module (in wad)
|
|
30
|
+
* @param collRatio_ Collateralization ratio to compute solvency requirement as % of payout (in ray)
|
|
31
|
+
* @param ensuroPpFee_ % of pure premium that will go for Ensuro treasury (in ray)
|
|
32
|
+
* @param srRoc_ return on capital paid to Senior LPs (annualized percentage - in ray)
|
|
33
|
+
* @param maxPayoutPerPolicy_ Maximum payout per policy (in wad)
|
|
34
|
+
* @param exposureLimit_ Max exposure (sum of payouts) to be allocated to this module (in wad)
|
|
33
35
|
* @param wallet_ Address of the RiskModule provider
|
|
34
36
|
*/
|
|
35
37
|
function initialize(
|
|
36
38
|
string memory name_,
|
|
37
|
-
uint256
|
|
38
|
-
uint256
|
|
39
|
-
uint256
|
|
40
|
-
uint256
|
|
41
|
-
uint256
|
|
39
|
+
uint256 collRatio_,
|
|
40
|
+
uint256 ensuroPpFee_,
|
|
41
|
+
uint256 srRoc_,
|
|
42
|
+
uint256 maxPayoutPerPolicy_,
|
|
43
|
+
uint256 exposureLimit_,
|
|
42
44
|
address wallet_
|
|
43
45
|
) public initializer {
|
|
44
46
|
__RiskModule_init(
|
|
45
47
|
name_,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
collRatio_,
|
|
49
|
+
ensuroPpFee_,
|
|
50
|
+
srRoc_,
|
|
51
|
+
maxPayoutPerPolicy_,
|
|
52
|
+
exposureLimit_,
|
|
51
53
|
wallet_
|
|
52
54
|
);
|
|
53
55
|
}
|
|
@@ -59,13 +61,13 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
59
61
|
uint40 expiration,
|
|
60
62
|
address customer,
|
|
61
63
|
uint96 internalId
|
|
62
|
-
) external
|
|
64
|
+
) external onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
63
65
|
return _newPolicy(payout, premium, lossProb, expiration, customer, internalId).id;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
|
|
67
69
|
external
|
|
68
|
-
|
|
70
|
+
onlyComponentRole(RESOLVER_ROLE)
|
|
69
71
|
whenNotPaused
|
|
70
72
|
{
|
|
71
73
|
_policyPool.resolvePolicy(policy, payout);
|
|
@@ -73,7 +75,7 @@ contract TrustfulRiskModule is RiskModule {
|
|
|
73
75
|
|
|
74
76
|
function resolvePolicyFullPayout(Policy.PolicyData calldata policy, bool customerWon)
|
|
75
77
|
external
|
|
76
|
-
|
|
78
|
+
onlyComponentRole(RESOLVER_ROLE)
|
|
77
79
|
whenNotPaused
|
|
78
80
|
{
|
|
79
81
|
_policyPool.resolvePolicyFullPayout(policy, customerWon);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
This is a workaround for:
|
|
6
|
+
|
|
7
|
+
https://github.com/eth-brownie/brownie/issues/1581
|
|
8
|
+
|
|
9
|
+
Which affects ethproto. The contract is just here for ethproto's
|
|
10
|
+
sake and is not actually used by any contract.
|
|
11
|
+
|
|
12
|
+
Once that bug is fixed (either in brownie or in ethproto) this
|
|
13
|
+
file can be safely removed.
|
|
14
|
+
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {ERC1967Proxy as ERC1967ProxyOriginal} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
18
|
+
|
|
19
|
+
abstract contract ERC1967Proxy is ERC1967ProxyOriginal {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
This is a workaround for:
|
|
6
|
+
|
|
7
|
+
https://github.com/eth-brownie/brownie/issues/1581
|
|
8
|
+
|
|
9
|
+
Which affects ethproto. The contract is just here for ethproto's
|
|
10
|
+
sake and is not actually used by any contract.
|
|
11
|
+
|
|
12
|
+
Once that bug is fixed (either in brownie or in ethproto) this
|
|
13
|
+
file can be safely removed.
|
|
14
|
+
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {IERC20Metadata as IERC20MetadataOriginal} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
18
|
+
|
|
19
|
+
interface IERC20Metadata is IERC20MetadataOriginal {}
|
|
@@ -0,0 +1,172 @@
|
|
|
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 Event emitted when part of the funds of the eToken are locked as solvency capital.
|
|
14
|
+
* @param interestRate The annualized interestRate paid for the capital (wad)
|
|
15
|
+
* @param value The amount locked
|
|
16
|
+
*/
|
|
17
|
+
event SCRLocked(uint256 interestRate, uint256 value);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @dev Event emitted when the locked funds are unlocked and no longer used as solvency capital.
|
|
21
|
+
* @param interestRate The annualized interestRate that was paid for the capital (wad)
|
|
22
|
+
* @param value The amount unlocked
|
|
23
|
+
*/
|
|
24
|
+
event SCRUnlocked(uint256 interestRate, uint256 value);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @dev Returns the amount of capital that's locked as solvency capital for active policies.
|
|
28
|
+
*/
|
|
29
|
+
function scr() external view returns (uint256);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @dev Locks part of the liquidity of the EToken as solvency capital.
|
|
33
|
+
*
|
|
34
|
+
* Requirements:
|
|
35
|
+
* - Must be called by a _borrower_ previously added with `addBorrower`.
|
|
36
|
+
* - `scrAmount` <= `fundsAvailableToLock()`
|
|
37
|
+
*
|
|
38
|
+
* Events:
|
|
39
|
+
* - Emits {SCRLocked}
|
|
40
|
+
*
|
|
41
|
+
* @param scrAmount The amount to lock
|
|
42
|
+
* @param policyInterestRate The annualized interest rate (wad) to be paid for the `scrAmount`
|
|
43
|
+
*/
|
|
44
|
+
function lockScr(uint256 scrAmount, uint256 policyInterestRate) external;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @dev Unlocks solvency capital previously locked with `lockScr`. The capital no longer needed as solvency.
|
|
48
|
+
*
|
|
49
|
+
* Requirements:
|
|
50
|
+
* - Must be called by a _borrower_ previously added with `addBorrower`.
|
|
51
|
+
* - `scrAmount` <= `scr()`
|
|
52
|
+
*
|
|
53
|
+
* Events:
|
|
54
|
+
* - Emits {SCRUnlocked}
|
|
55
|
+
*
|
|
56
|
+
* @param scrAmount The amount to unlock
|
|
57
|
+
* @param policyInterestRate The annualized interest rate that was paid for the `scrAmount`, must be the same that was
|
|
58
|
+
* sent in `lockScr` call.
|
|
59
|
+
*/
|
|
60
|
+
function unlockScr(
|
|
61
|
+
uint256 scrAmount,
|
|
62
|
+
uint256 policyInterestRate,
|
|
63
|
+
int256 adjustment
|
|
64
|
+
) external;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @dev Registers a deposit of liquidity in the pool. Called from the PolicyPool, assumes the amount has already been
|
|
68
|
+
* transferred. `amount` of eToken are minted and given to the provider in exchange of the liquidity provided.
|
|
69
|
+
*
|
|
70
|
+
* Requirements:
|
|
71
|
+
* - Must be called by `policyPool()`
|
|
72
|
+
* - The amount was transferred
|
|
73
|
+
* - `utilizationRate()` after the deposit is >= `minUtilizationRate()`
|
|
74
|
+
*
|
|
75
|
+
* Events:
|
|
76
|
+
* - Emits {Transfer} with `from` = 0x0 and to = `provider`
|
|
77
|
+
*
|
|
78
|
+
* @param provider The address of the liquidity provider
|
|
79
|
+
* @param amount The amount deposited.
|
|
80
|
+
* @return The actual balance of the provider (TODO)
|
|
81
|
+
*/
|
|
82
|
+
function deposit(address provider, uint256 amount) external returns (uint256);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @dev Withdraws an amount from an eToken. `withdrawn` eTokens are be burned and the user receives the same amount
|
|
86
|
+
* in `currency()`. If the asked `amount` can't be withdrawn, it withdraws as much as possible
|
|
87
|
+
*
|
|
88
|
+
* Requirements:
|
|
89
|
+
* - Must be called by `policyPool()`
|
|
90
|
+
*
|
|
91
|
+
* Events:
|
|
92
|
+
* - Emits {Transfer} with `from` = `provider` and to = `0x0`
|
|
93
|
+
*
|
|
94
|
+
* @param provider The address of the liquidity provider
|
|
95
|
+
* @param amount The amount to withdraw. If `amount` == `type(uint256).max`, then tries to withdraw all the balance.
|
|
96
|
+
* @return withdrawn The actual amount that withdrawn. `withdrawn <= amount && withdrawn <= balanceOf(provider)`
|
|
97
|
+
*/
|
|
98
|
+
function withdraw(address provider, uint256 amount) external returns (uint256 withdrawn);
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @dev Returns the total amount that can be withdrawn
|
|
102
|
+
*/
|
|
103
|
+
function totalWithdrawable() external view returns (uint256);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @dev Adds an authorized _borrower_ to the eToken. This _borrower_ will be allowed to lock/unlock funds and to take
|
|
107
|
+
* loans.
|
|
108
|
+
*
|
|
109
|
+
* Requirements:
|
|
110
|
+
* - Must be called by `policyPool()`
|
|
111
|
+
*
|
|
112
|
+
* Events:
|
|
113
|
+
* - Emits {PoolBorrowerAdded}
|
|
114
|
+
*
|
|
115
|
+
* @param borrower The address of the _borrower_, a PremiumsAccount that has this eToken as senior or junior eToken.
|
|
116
|
+
*/
|
|
117
|
+
function addBorrower(address borrower) external;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @dev Lends `amount` to the borrower (msg.sender), transferring the money to `receiver`. This reduces the
|
|
121
|
+
* `totalSupply()` of the eToken, and stores a debt that will be repaid (hopefully) with `repayLoan`.
|
|
122
|
+
*
|
|
123
|
+
* Requirements:
|
|
124
|
+
* - Must be called by a _borrower_ previously added with `addBorrower`.
|
|
125
|
+
*
|
|
126
|
+
* Events:
|
|
127
|
+
* - Emits {InternalLoan}
|
|
128
|
+
* - Emits {ERC20-Transfer} transferring `lent` to `receiver`
|
|
129
|
+
*
|
|
130
|
+
* @param amount The amount required
|
|
131
|
+
* @param receiver The received of the funds lent. This is usually the policyholder if the loan is used for a payout.
|
|
132
|
+
* @param fromAvailable If `true`, the funds that can be lent are only the available ones, i.e., excluding the funds
|
|
133
|
+
* locked as `scr()`. If `false`, all the `totalSupply()` is available to be lent.
|
|
134
|
+
* @return Returns the amount that wasn't able to fulfil. `amount - lent`
|
|
135
|
+
*/
|
|
136
|
+
function internalLoan(
|
|
137
|
+
uint256 amount,
|
|
138
|
+
address receiver,
|
|
139
|
+
bool fromAvailable
|
|
140
|
+
) external returns (uint256);
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @dev Repays a loan taken with `internalLoan`.
|
|
144
|
+
*
|
|
145
|
+
* Requirements:
|
|
146
|
+
* - `msg.sender` approved the spending of `currency()` for at least `amount`
|
|
147
|
+
|
|
148
|
+
* Events:
|
|
149
|
+
* - Emits {InternalLoanRepaid}
|
|
150
|
+
* - Emits {ERC20-Transfer} transferring `amount` from `msg.sender` to `this`
|
|
151
|
+
*
|
|
152
|
+
* @param amount The amount to repaid, that will be transferred from `msg.sender` balance.
|
|
153
|
+
* @param onBehalfOf The address of the borrower that took the loan. Usually `onBehalfOf == msg.sender` but we keep it
|
|
154
|
+
* open because in some cases with might need someone else pays the debt.
|
|
155
|
+
*/
|
|
156
|
+
function repayLoan(uint256 amount, address onBehalfOf) external;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @dev Returns the updated debt (principal + interest) of the `borrower`.
|
|
160
|
+
*/
|
|
161
|
+
function getLoan(address borrower) external view returns (uint256);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @dev The annualized interest rate at which the `totalSupply()` grows
|
|
165
|
+
*/
|
|
166
|
+
function tokenInterestRate() external view returns (uint256);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @dev The weighted average annualized interest rate paid by the currently locked `scr()`.
|
|
170
|
+
*/
|
|
171
|
+
function scrInterestRate() external view returns (uint256);
|
|
172
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,138 @@
|
|
|
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 {IPolicyPoolConfig} from "./IPolicyPoolConfig.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 {PolicyPoolConfig} contract, this contract manages the access controls and installed risk
|
|
18
|
+
* modules.
|
|
19
|
+
* @return The address of the PolicyPoolConfig contract
|
|
20
|
+
*/
|
|
21
|
+
function config() external view returns (IPolicyPoolConfig);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @dev Reference to the {PolicyNFT} contract. This contract it's an ERC721 Token that handles the ownership of the
|
|
25
|
+
* policies.
|
|
26
|
+
* @return The address of the PolicyNFT contract
|
|
27
|
+
*/
|
|
28
|
+
function policyNFT() external view returns (address);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @dev Creates a new Policy. Must be called from an active RiskModule
|
|
32
|
+
*
|
|
33
|
+
* Requirements:
|
|
34
|
+
* - `msg.sender` must be an active RiskModule
|
|
35
|
+
* - `customer` approved the spending of `currency()` for at least `policy.premium`
|
|
36
|
+
* - `internalId` must be unique within `policy.riskModule` and not used before
|
|
37
|
+
*
|
|
38
|
+
* Events:
|
|
39
|
+
* - {PolicyPool-NewPolicy}: with all the details about the policy
|
|
40
|
+
* - {ERC20-Transfer}: does several transfers from customer address to the different receivers of the premium
|
|
41
|
+
* (see Premium Split in the docs)
|
|
42
|
+
*
|
|
43
|
+
* @param policy A policy created with {Policy-initialize}
|
|
44
|
+
* @param customer The address of the policy holder and the payer of the premiums
|
|
45
|
+
* @param internalId A unique id within the RiskModule, that will be used to compute the policy id
|
|
46
|
+
* @return The policy id, identifying the NFT and the policy
|
|
47
|
+
*/
|
|
48
|
+
function newPolicy(
|
|
49
|
+
Policy.PolicyData memory policy,
|
|
50
|
+
address customer,
|
|
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 Deposits liquidity into an eToken. Forwards the call to {EToken-deposit}, after transferring the funds.
|
|
105
|
+
* The user will receive etokens for the same amount deposited.
|
|
106
|
+
*
|
|
107
|
+
* Requirements:
|
|
108
|
+
* - `msg.sender` approved the spending of `currency()` for at least `amount`
|
|
109
|
+
* - `eToken` is an active eToken installed in the pool.
|
|
110
|
+
*
|
|
111
|
+
* Events:
|
|
112
|
+
* - {EToken-Transfer}: from 0x0 to `msg.sender`, reflects the eTokens minted.
|
|
113
|
+
* - {ERC20-Transfer}: from `msg.sender` to address(eToken)
|
|
114
|
+
*
|
|
115
|
+
* @param eToken The address of the eToken to which the user wants to provide liquidity
|
|
116
|
+
* @param amount The amount to deposit
|
|
117
|
+
*/
|
|
118
|
+
function deposit(IEToken eToken, uint256 amount) external;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @dev Withdraws an amount from an eToken. Forwards the call to {EToken-withdraw}.
|
|
122
|
+
* `amount` of eTokens will be burned and the user will receive the same amount in `currency()`.
|
|
123
|
+
*
|
|
124
|
+
* Requirements:
|
|
125
|
+
* - `eToken` is an active (or deprecated) eToken installed in the pool.
|
|
126
|
+
*
|
|
127
|
+
* Events:
|
|
128
|
+
* - {EToken-Transfer}: from `msg.sender` to `0x0`, reflects the eTokens burned.
|
|
129
|
+
* - {ERC20-Transfer}: from address(eToken) to `msg.sender`
|
|
130
|
+
*
|
|
131
|
+
* @param eToken The address of the eToken from where the user wants to withdraw liquidity
|
|
132
|
+
* @param amount The amount to withdraw. If equal to type(uint256).max, means full withdrawal.
|
|
133
|
+
* If the balance is not enought or can't be withdrawn (locked as SCR), it withdraws
|
|
134
|
+
* as much as it can, but doesn't fails.
|
|
135
|
+
* @return Returns the actual amount withdrawn.
|
|
136
|
+
*/
|
|
137
|
+
function withdraw(IEToken eToken, uint256 amount) external returns (uint256);
|
|
138
|
+
}
|
|
File without changes
|
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
import {IAccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
|
|
5
|
-
import {IAssetManager} from "./IAssetManager.sol";
|
|
6
|
-
import {IInsolvencyHook} from "./IInsolvencyHook.sol";
|
|
7
5
|
import {ILPWhitelist} from "./ILPWhitelist.sol";
|
|
8
6
|
import {IRiskModule} from "./IRiskModule.sol";
|
|
9
|
-
import {IExchange} from "./IExchange.sol";
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* @title IPolicyPoolAccess - Interface for the contract that handles roles for the PolicyPool and components
|
|
@@ -22,20 +19,35 @@ interface IPolicyPoolConfig is IAccessControlUpgradeable {
|
|
|
22
19
|
setLPWhitelist, // Changes PolicyPool Liquidity Providers Whitelist
|
|
23
20
|
addRiskModule,
|
|
24
21
|
removeRiskModule,
|
|
22
|
+
cfgFiller1, // Reserve space for future PolicyPoolConfig actions
|
|
23
|
+
cfgFiller2, // Reserve space for future PolicyPoolConfig actions
|
|
24
|
+
cfgFiller3, // Reserve space for future PolicyPoolConfig actions
|
|
25
|
+
cfgFiller4, // Reserve space for future PolicyPoolConfig actions
|
|
25
26
|
// RiskModule Governance Actions
|
|
26
|
-
setScrPercentage,
|
|
27
27
|
setMoc,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
setJrCollRatio,
|
|
29
|
+
setCollRatio,
|
|
30
|
+
setEnsuroPpFee,
|
|
31
|
+
setEnsuroCocFee,
|
|
32
|
+
setJrRoc,
|
|
33
|
+
setSrRoc,
|
|
34
|
+
setMaxPayoutPerPolicy,
|
|
35
|
+
setExposureLimit,
|
|
36
|
+
setMaxDuration,
|
|
34
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
|
|
35
42
|
// EToken Governance Actions
|
|
36
43
|
setLiquidityRequirement,
|
|
44
|
+
setMinUtilizationRate,
|
|
37
45
|
setMaxUtilizationRate,
|
|
38
|
-
|
|
46
|
+
setInternalLoanInterestRate,
|
|
47
|
+
etkFiller1, // Reserve space for future EToken actions
|
|
48
|
+
etkFiller2, // Reserve space for future EToken actions
|
|
49
|
+
etkFiller3, // Reserve space for future EToken actions
|
|
50
|
+
etkFiller4, // Reserve space for future EToken actions
|
|
39
51
|
// AssetManager Governance Actions
|
|
40
52
|
setLiquidityMin,
|
|
41
53
|
setLiquidityMiddle,
|
|
@@ -44,9 +56,8 @@ interface IPolicyPoolConfig is IAccessControlUpgradeable {
|
|
|
44
56
|
setClaimRewardsMin,
|
|
45
57
|
setReinvestRewardsMin,
|
|
46
58
|
setMaxSlippage,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
setExchange, // Changes exchange helper contract
|
|
59
|
+
setPriceOracle, // Changes exchange's PriceOracle
|
|
60
|
+
setSwapRouter, // Changes exchange's SwapRouter
|
|
50
61
|
last
|
|
51
62
|
}
|
|
52
63
|
|
|
@@ -61,6 +72,12 @@ interface IPolicyPoolConfig is IAccessControlUpgradeable {
|
|
|
61
72
|
|
|
62
73
|
function checkRole(bytes32 role, address account) external view;
|
|
63
74
|
|
|
75
|
+
function checkComponentRole(
|
|
76
|
+
address component,
|
|
77
|
+
bytes32 role,
|
|
78
|
+
address account
|
|
79
|
+
) external view;
|
|
80
|
+
|
|
64
81
|
function checkRole2(
|
|
65
82
|
bytes32 role1,
|
|
66
83
|
bytes32 role2,
|
|
@@ -69,14 +86,6 @@ interface IPolicyPoolConfig is IAccessControlUpgradeable {
|
|
|
69
86
|
|
|
70
87
|
function connect() external;
|
|
71
88
|
|
|
72
|
-
function assetManager() external view returns (IAssetManager);
|
|
73
|
-
|
|
74
|
-
function insolvencyHook() external view returns (IInsolvencyHook);
|
|
75
|
-
|
|
76
|
-
function lpWhitelist() external view returns (ILPWhitelist);
|
|
77
|
-
|
|
78
|
-
function exchange() external view returns (IExchange);
|
|
79
|
-
|
|
80
89
|
function treasury() external view returns (address);
|
|
81
90
|
|
|
82
91
|
function checkAcceptsNewPolicy(IRiskModule riskModule) external view;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IEToken} from "./IEToken.sol";
|
|
5
|
+
import {Policy} from "../Policy.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title IPremiumsAccount interface
|
|
9
|
+
* @dev Interface for Premiums Account contracts.
|
|
10
|
+
* @author Ensuro
|
|
11
|
+
*/
|
|
12
|
+
interface IPremiumsAccount {
|
|
13
|
+
/**
|
|
14
|
+
* @dev Adds a policy to the PremiumsAccount. Stores the pure premiums and locks the aditional funds from junior and
|
|
15
|
+
* senior eTokens.
|
|
16
|
+
*
|
|
17
|
+
* Requirements:
|
|
18
|
+
* - Must be called by `policyPool()`
|
|
19
|
+
*
|
|
20
|
+
* Events:
|
|
21
|
+
* - {EToken-SCRLocked}
|
|
22
|
+
*
|
|
23
|
+
* @param policy The policy to add (created in this transaction)
|
|
24
|
+
*/
|
|
25
|
+
function policyCreated(Policy.PolicyData memory policy) external;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @dev The PremiumsAccount is notified that the policy was resolved and issues the payout to the policyHolder.
|
|
29
|
+
*
|
|
30
|
+
* Requirements:
|
|
31
|
+
* - Must be called by `policyPool()`
|
|
32
|
+
*
|
|
33
|
+
* Events:
|
|
34
|
+
* - {ERC20-Transfer}: `to == policyHolder`, `amount == payout`
|
|
35
|
+
* - {EToken-InternalLoan}: optional, if a loan needs to be taken
|
|
36
|
+
* - {EToken-SCRUnlocked}
|
|
37
|
+
*
|
|
38
|
+
* @param policyHolder The one that will receive the payout
|
|
39
|
+
* @param policy The policy that was resolved
|
|
40
|
+
* @param payout The amount that has to be transferred to `policyHolder`
|
|
41
|
+
*/
|
|
42
|
+
function policyResolvedWithPayout(
|
|
43
|
+
address policyHolder,
|
|
44
|
+
Policy.PolicyData memory policy,
|
|
45
|
+
uint256 payout
|
|
46
|
+
) external;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @dev The PremiumsAccount is notified that the policy has expired, unlocks the SCR and earns the pure premium.
|
|
50
|
+
*
|
|
51
|
+
* Requirements:
|
|
52
|
+
* - Must be called by `policyPool()`
|
|
53
|
+
*
|
|
54
|
+
* Events:
|
|
55
|
+
* - {ERC20-Transfer}: `to == policyHolder`, `amount == payout`
|
|
56
|
+
* - {EToken-InternalLoanRepaid}: optional, if a loan was taken before
|
|
57
|
+
*
|
|
58
|
+
* @param policy The policy that has expired
|
|
59
|
+
*/
|
|
60
|
+
function policyExpired(Policy.PolicyData memory policy) external;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @dev The senior eToken, the secondary source of solvency, used if the premiums account is exhausted and junior too
|
|
64
|
+
*/
|
|
65
|
+
function seniorEtk() external view returns (IEToken);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @dev The junior eToken, the primary source of solvency, used if the premiums account is exhausted.
|
|
69
|
+
*/
|
|
70
|
+
function juniorEtk() external view returns (IEToken);
|
|
71
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IPremiumsAccount} from "./IPremiumsAccount.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title IRiskModule interface
|
|
8
|
+
* @dev Interface for RiskModule smart contracts. Gives access to RiskModule configuration parameters
|
|
9
|
+
* @author Ensuro
|
|
10
|
+
*/
|
|
11
|
+
interface IRiskModule {
|
|
12
|
+
enum Parameter {
|
|
13
|
+
moc,
|
|
14
|
+
jrCollRatio,
|
|
15
|
+
collRatio,
|
|
16
|
+
ensuroPpFee,
|
|
17
|
+
ensuroCocFee,
|
|
18
|
+
jrRoc,
|
|
19
|
+
srRoc,
|
|
20
|
+
maxPayoutPerPolicy,
|
|
21
|
+
exposureLimit,
|
|
22
|
+
maxDuration
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
struct Params {
|
|
26
|
+
uint256 moc;
|
|
27
|
+
uint256 jrCollRatio;
|
|
28
|
+
uint256 collRatio;
|
|
29
|
+
uint256 ensuroPpFee;
|
|
30
|
+
uint256 ensuroCocFee;
|
|
31
|
+
uint256 jrRoc;
|
|
32
|
+
uint256 srRoc;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function name() external view returns (string memory);
|
|
36
|
+
|
|
37
|
+
function params() external view returns (Params memory);
|
|
38
|
+
|
|
39
|
+
function maxPayoutPerPolicy() external view returns (uint256);
|
|
40
|
+
|
|
41
|
+
function exposureLimit() external view returns (uint256);
|
|
42
|
+
|
|
43
|
+
function maxDuration() external view returns (uint256);
|
|
44
|
+
|
|
45
|
+
function activeExposure() external view returns (uint256);
|
|
46
|
+
|
|
47
|
+
function wallet() external view returns (address);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @dev Called when a policy expires or is resolved to update the exposure.
|
|
51
|
+
*
|
|
52
|
+
* Requirements:
|
|
53
|
+
* - Must be called by `policyPool()`
|
|
54
|
+
*
|
|
55
|
+
* @param payout The exposure (maximum payout) of the policy
|
|
56
|
+
*/
|
|
57
|
+
function releaseExposure(uint256 payout) external;
|
|
58
|
+
|
|
59
|
+
function premiumsAccount() external view returns (IPremiumsAccount);
|
|
60
|
+
}
|