@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: MIT
|
|
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 {Policy} from "./Policy.sol";
|
|
6
7
|
import {RiskModule} from "./RiskModule.sol";
|
|
7
8
|
import {Chainlink} from "@chainlink/contracts/src/v0.8/Chainlink.sol";
|
|
@@ -44,39 +45,40 @@ contract FlightDelayRiskModule is RiskModule, ChainlinkClientUpgradeable {
|
|
|
44
45
|
|
|
45
46
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
46
47
|
// solhint-disable-next-line no-empty-blocks
|
|
47
|
-
constructor(IPolicyPool policyPool_
|
|
48
|
+
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
|
|
49
|
+
RiskModule(policyPool_, premiumsAccount_)
|
|
50
|
+
{} // solhint-disable-line no-empty-blocks
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
53
|
* @dev Initializes the RiskModule
|
|
51
54
|
* @param name_ Name of the Risk Module
|
|
52
|
-
* @param
|
|
53
|
-
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
57
|
-
* @param scrLimit_ Max SCR to be allocated to this module (in wad)
|
|
55
|
+
* @param collRatio_ Collateralization ratio to compute solvency requirement as % of payout (in ray)
|
|
56
|
+
* @param ensuroPpFee_ % of pure premium that will go for Ensuro treasury (in ray)
|
|
57
|
+
* @param srRoc_ return on capital paid to Senior LPs (annualized percentage - in ray)
|
|
58
|
+
* @param maxPayoutPerPolicy_ Maximum payout per policy (in wad)
|
|
59
|
+
* @param exposureLimit_ Max exposure (sum of payouts) to be allocated to this module (in wad)
|
|
58
60
|
* @param wallet_ Address of the RiskModule provider
|
|
59
61
|
* @param linkToken_ Address of ChainLink LINK token
|
|
60
62
|
* @param oracleParams_ Parameters of the Oracle
|
|
61
63
|
*/
|
|
62
64
|
function initialize(
|
|
63
65
|
string memory name_,
|
|
64
|
-
uint256
|
|
65
|
-
uint256
|
|
66
|
-
uint256
|
|
67
|
-
uint256
|
|
68
|
-
uint256
|
|
66
|
+
uint256 collRatio_,
|
|
67
|
+
uint256 ensuroPpFee_,
|
|
68
|
+
uint256 srRoc_,
|
|
69
|
+
uint256 maxPayoutPerPolicy_,
|
|
70
|
+
uint256 exposureLimit_,
|
|
69
71
|
address wallet_,
|
|
70
72
|
address linkToken_,
|
|
71
73
|
OracleParams memory oracleParams_
|
|
72
74
|
) public initializer {
|
|
73
75
|
__RiskModule_init(
|
|
74
76
|
name_,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
collRatio_,
|
|
78
|
+
ensuroPpFee_,
|
|
79
|
+
srRoc_,
|
|
80
|
+
maxPayoutPerPolicy_,
|
|
81
|
+
exposureLimit_,
|
|
80
82
|
wallet_
|
|
81
83
|
);
|
|
82
84
|
__ChainlinkClient_init();
|
|
@@ -92,7 +94,10 @@ contract FlightDelayRiskModule is RiskModule, ChainlinkClientUpgradeable {
|
|
|
92
94
|
_oracleParams = oracleParams_;
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
function setOracleParams(OracleParams memory newParams)
|
|
97
|
+
function setOracleParams(OracleParams memory newParams)
|
|
98
|
+
external
|
|
99
|
+
onlyComponentRole(ORACLE_ADMIN_ROLE)
|
|
100
|
+
{
|
|
96
101
|
_oracleParams = newParams;
|
|
97
102
|
}
|
|
98
103
|
|
|
@@ -121,7 +126,7 @@ contract FlightDelayRiskModule is RiskModule, ChainlinkClientUpgradeable {
|
|
|
121
126
|
uint256 lossProb,
|
|
122
127
|
address customer,
|
|
123
128
|
uint96 internalId
|
|
124
|
-
) external
|
|
129
|
+
) external onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
125
130
|
require(expectedArrival > block.timestamp, "expectedArrival can't be in the past");
|
|
126
131
|
require(departure != 0 && expectedArrival > departure, "expectedArrival <= departure!");
|
|
127
132
|
uint40 expiration = expectedArrival +
|
|
@@ -176,7 +181,11 @@ contract FlightDelayRiskModule is RiskModule, ChainlinkClientUpgradeable {
|
|
|
176
181
|
* @dev Forces the resolution of the policy (without waiting Chainlink scheduled on creation)
|
|
177
182
|
* @param policyId The id of the policy previously created (in newPolicy)
|
|
178
183
|
*/
|
|
179
|
-
function resolvePolicy(uint256 policyId)
|
|
184
|
+
function resolvePolicy(uint256 policyId)
|
|
185
|
+
external
|
|
186
|
+
onlyComponentRole(PRICER_ROLE)
|
|
187
|
+
returns (uint256)
|
|
188
|
+
{
|
|
180
189
|
PolicyData storage policy = _policies[policyId];
|
|
181
190
|
require(policy.expectedArrival != 0, "Policy not found!");
|
|
182
191
|
_chainlinkRequest(policyId, policy, 0);
|
|
@@ -1,10 +1,10 @@
|
|
|
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
5
|
import {PolicyPoolComponent} from "./PolicyPoolComponent.sol";
|
|
6
|
-
import {ILPWhitelist} from "
|
|
7
|
-
import {IEToken} from "
|
|
6
|
+
import {ILPWhitelist} from "./interfaces/ILPWhitelist.sol";
|
|
7
|
+
import {IEToken} from "./interfaces/IEToken.sol";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @title Manual Whitelisting contract
|
|
@@ -32,7 +32,7 @@ contract LPManualWhitelist is ILPWhitelist, PolicyPoolComponent {
|
|
|
32
32
|
|
|
33
33
|
function whitelistAddress(address provider, bool whitelisted)
|
|
34
34
|
external
|
|
35
|
-
|
|
35
|
+
onlyComponentRole(LP_WHITELIST_ROLE)
|
|
36
36
|
{
|
|
37
37
|
_whitelisted[provider] = whitelisted;
|
|
38
38
|
emit LPWhitelisted(provider, whitelisted);
|
package/contracts/Policy.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
import {WadRayMath} from "./WadRayMath.sol";
|
|
4
|
-
import {IRiskModule} from "
|
|
4
|
+
import {IRiskModule} from "./interfaces/IRiskModule.sol";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @title Policy library
|
|
@@ -13,33 +13,30 @@ import {IRiskModule} from "../interfaces/IRiskModule.sol";
|
|
|
13
13
|
library Policy {
|
|
14
14
|
using WadRayMath for uint256;
|
|
15
15
|
|
|
16
|
-
uint256 internal constant
|
|
17
|
-
uint256 internal constant SECONDS_IN_YEAR_RAY = 31536000e27; /* 365 * 24 * 3600 * 10e27 */
|
|
16
|
+
uint256 internal constant SECONDS_PER_YEAR = 365 days;
|
|
18
17
|
|
|
19
18
|
// Active Policies
|
|
20
19
|
struct PolicyData {
|
|
21
20
|
uint256 id;
|
|
22
21
|
uint256 payout;
|
|
23
22
|
uint256 premium;
|
|
24
|
-
uint256
|
|
25
|
-
uint256
|
|
23
|
+
uint256 jrScr;
|
|
24
|
+
uint256 srScr;
|
|
25
|
+
uint256 lossProb; // original loss probability (in wad)
|
|
26
26
|
uint256 purePremium; // share of the premium that covers expected losses
|
|
27
27
|
// equal to payout * lossProb * riskModule.moc
|
|
28
|
-
uint256
|
|
29
|
-
uint256
|
|
30
|
-
uint256
|
|
28
|
+
uint256 ensuroCommission; // share of the premium that goes for Ensuro
|
|
29
|
+
uint256 partnerCommission; // share of the premium that goes for the RM
|
|
30
|
+
uint256 jrCoc; // share of the premium that goes to junior liquidity providers (won or not)
|
|
31
|
+
uint256 srCoc; // share of the premium that goes to senior liquidity providers (won or not)
|
|
31
32
|
IRiskModule riskModule;
|
|
32
33
|
uint40 start;
|
|
33
34
|
uint40 expiration;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
/// #if_succeeds {:msg "premium preserved"} premium == (newPolicy.premium);
|
|
37
|
-
/// #if_succeeds
|
|
38
|
-
/// {:msg "premium distributed"}
|
|
39
|
-
/// premium == (newPolicy.purePremium + newPolicy.premiumForLps +
|
|
40
|
-
/// newPolicy.premiumForRm + newPolicy.premiumForEnsuro);
|
|
41
37
|
function initialize(
|
|
42
38
|
IRiskModule riskModule,
|
|
39
|
+
IRiskModule.Params memory rmParams,
|
|
43
40
|
uint256 premium,
|
|
44
41
|
uint256 payout,
|
|
45
42
|
uint256 lossProb,
|
|
@@ -47,55 +44,62 @@ library Policy {
|
|
|
47
44
|
) internal view returns (PolicyData memory newPolicy) {
|
|
48
45
|
require(premium <= payout, "Premium cannot be more than payout");
|
|
49
46
|
PolicyData memory policy;
|
|
47
|
+
|
|
50
48
|
policy.riskModule = riskModule;
|
|
51
49
|
policy.premium = premium;
|
|
52
50
|
policy.payout = payout;
|
|
53
51
|
policy.lossProb = lossProb;
|
|
54
|
-
policy.purePremium = payout.wadToRay().rayMul(lossProb.rayMul(riskModule.moc())).rayToWad();
|
|
55
|
-
policy.scr = payout.wadMul(riskModule.scrPercentage().rayToWad()) - policy.purePremium;
|
|
56
|
-
require(policy.scr != 0, "SCR can't be zero");
|
|
57
52
|
policy.start = uint40(block.timestamp);
|
|
58
53
|
policy.expiration = expiration;
|
|
59
|
-
policy.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
policy.purePremium = payout.wadMul(lossProb.wadMul(rmParams.moc));
|
|
55
|
+
// Calculate Junior and Senior SCR
|
|
56
|
+
policy.jrScr = payout.wadMul(rmParams.jrCollRatio);
|
|
57
|
+
if (policy.jrScr > policy.purePremium) {
|
|
58
|
+
policy.jrScr -= policy.purePremium;
|
|
59
|
+
} else {
|
|
60
|
+
policy.jrScr = 0;
|
|
61
|
+
}
|
|
62
|
+
policy.srScr = payout.wadMul(rmParams.collRatio);
|
|
63
|
+
if (policy.srScr > (policy.purePremium + policy.jrScr)) {
|
|
64
|
+
policy.srScr -= policy.purePremium + policy.jrScr;
|
|
65
|
+
} else {
|
|
66
|
+
policy.srScr = 0;
|
|
67
|
+
}
|
|
68
|
+
// Calculate CoCs
|
|
69
|
+
policy.jrCoc = policy.jrScr.wadMul(
|
|
70
|
+
(rmParams.jrRoc * (policy.expiration - policy.start)) / SECONDS_PER_YEAR
|
|
65
71
|
);
|
|
66
|
-
policy.
|
|
67
|
-
|
|
72
|
+
policy.srCoc = policy.srScr.wadMul(
|
|
73
|
+
(rmParams.srRoc * (policy.expiration - policy.start)) / SECONDS_PER_YEAR
|
|
68
74
|
);
|
|
75
|
+
uint256 coc = policy.jrCoc + policy.srCoc;
|
|
76
|
+
policy.ensuroCommission =
|
|
77
|
+
policy.purePremium.wadMul(rmParams.ensuroPpFee) +
|
|
78
|
+
coc.wadMul(rmParams.ensuroCocFee);
|
|
69
79
|
require(
|
|
70
|
-
policy.purePremium + policy.
|
|
80
|
+
(policy.purePremium + policy.ensuroCommission + coc) <= premium,
|
|
71
81
|
"Premium less than minimum"
|
|
72
82
|
);
|
|
73
|
-
policy.
|
|
74
|
-
premium -
|
|
75
|
-
policy.purePremium -
|
|
76
|
-
policy.premiumForLps -
|
|
77
|
-
policy.premiumForEnsuro;
|
|
83
|
+
policy.partnerCommission = premium - policy.purePremium - coc - policy.ensuroCommission;
|
|
78
84
|
return policy;
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
function
|
|
87
|
+
function jrInterestRate(PolicyData memory policy) internal pure returns (uint256) {
|
|
82
88
|
return
|
|
83
|
-
policy
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
((policy.jrCoc * SECONDS_PER_YEAR) / (policy.expiration - policy.start)).wadDiv(policy.jrScr);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function jrAccruedInterest(PolicyData memory policy) internal view returns (uint256) {
|
|
93
|
+
return (policy.jrCoc * (block.timestamp - policy.start)) / (policy.expiration - policy.start);
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
function
|
|
91
|
-
uint256 secs = block.timestamp - policy.start;
|
|
96
|
+
function srInterestRate(PolicyData memory policy) internal pure returns (uint256) {
|
|
92
97
|
return
|
|
93
|
-
policy
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.rayToWad();
|
|
98
|
+
((policy.srCoc * SECONDS_PER_YEAR) / (policy.expiration - policy.start)).wadDiv(policy.srScr);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function srAccruedInterest(PolicyData memory policy) internal view returns (uint256) {
|
|
102
|
+
return (policy.srCoc * (block.timestamp - policy.start)) / (policy.expiration - policy.start);
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
function hash(PolicyData memory policy) internal pure returns (bytes32) {
|
package/contracts/PolicyNFT.sol
CHANGED
|
@@ -4,9 +4,9 @@ pragma solidity ^0.8.2;
|
|
|
4
4
|
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
5
5
|
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
|
|
6
6
|
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
|
|
7
|
-
import {IPolicyPool} from "
|
|
7
|
+
import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
8
8
|
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
9
|
-
import {IPolicyNFT} from "
|
|
9
|
+
import {IPolicyNFT} from "./interfaces/IPolicyNFT.sol";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @title PolicyNFT - NFT that keeps track of issued policies and its owners
|