@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
|
@@ -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);
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
|
|
5
|
+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
6
|
+
import {IPolicyPoolComponent} from "./interfaces/IPolicyPoolComponent.sol";
|
|
7
|
+
import {IAssetManager} from "./interfaces/IAssetManager.sol";
|
|
8
|
+
import {IAccessManager} from "./interfaces/IAccessManager.sol";
|
|
9
|
+
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @title Base class for asset management strategies that use thresholds for cash and investment balance
|
|
13
|
+
* @dev Base class for asset management strategies that use thresholds for cash and investment balance.
|
|
14
|
+
* The specific asset management strategy needs to be implemented by child contracts.
|
|
15
|
+
* Settings liquidityMin, liquidityMiddle, liquidityMax are the thresholds used to define how much liquidity
|
|
16
|
+
* to keep in the PolicyPool and when to invest/deinvest. Every invest/deinvest operation tries to leave the
|
|
17
|
+
* cash at liquidityMiddle.
|
|
18
|
+
* @custom:security-contact security@ensuro.co
|
|
19
|
+
* @author Ensuro
|
|
20
|
+
*/
|
|
21
|
+
abstract contract LiquidityThresholdAssetManager is IAssetManager {
|
|
22
|
+
using SafeCast for uint256;
|
|
23
|
+
|
|
24
|
+
IERC20Metadata internal immutable _asset;
|
|
25
|
+
event GovernanceAction(IAccessManager.GovernanceActions indexed action, uint256 value);
|
|
26
|
+
|
|
27
|
+
struct DiamondStorage {
|
|
28
|
+
uint32 liquidityMin; // stored with 0 decimals
|
|
29
|
+
uint32 liquidityMiddle; // stored with 0 decimals
|
|
30
|
+
uint32 liquidityMax; // stored with 0 decimals
|
|
31
|
+
uint128 lastInvestmentValue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
modifier validateParamsAfterChange() {
|
|
35
|
+
_;
|
|
36
|
+
_validateParameters();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
constructor(IERC20Metadata asset_) {
|
|
40
|
+
_asset = asset_;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
|
|
44
|
+
// Inspired from https://eips.ethereum.org/EIPS/eip-2535#facets-state-variables-and-diamond-storage
|
|
45
|
+
// Set the position of our struct in contract storage
|
|
46
|
+
bytes32 storagePosition = keccak256("co.ensuro.LiquidityThresholdAssetManager");
|
|
47
|
+
// solhint-disable-next-line no-inline-assembly
|
|
48
|
+
assembly {
|
|
49
|
+
ds.slot := storagePosition
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function _validateParameters() internal view {
|
|
54
|
+
DiamondStorage storage ds = diamondStorage();
|
|
55
|
+
|
|
56
|
+
require(
|
|
57
|
+
ds.liquidityMin <= ds.liquidityMiddle && ds.liquidityMiddle <= ds.liquidityMax,
|
|
58
|
+
"Validation: Liquidity limits are invalid"
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function connect() public virtual override {
|
|
63
|
+
require(
|
|
64
|
+
IPolicyPoolComponent(address(this)).policyPool().currency() == _asset,
|
|
65
|
+
"Asset mismatch"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function recordEarnings() external virtual override returns (int256) {
|
|
70
|
+
uint256 investmentValue = getInvestmentValue();
|
|
71
|
+
DiamondStorage storage ds = diamondStorage();
|
|
72
|
+
int256 earnings = int256(investmentValue) - int256(uint256(ds.lastInvestmentValue));
|
|
73
|
+
ds.lastInvestmentValue = investmentValue.toUint128();
|
|
74
|
+
emit EarningsRecorded(earnings);
|
|
75
|
+
return earnings;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @dev Returns the current value of the investment portfolio
|
|
80
|
+
*/
|
|
81
|
+
function getInvestmentValue() public view virtual returns (uint256);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @dev Rebalances cash between PolicyPool wallet and
|
|
85
|
+
*/
|
|
86
|
+
function rebalance() external virtual override {
|
|
87
|
+
uint256 cash = _asset.balanceOf(address(this));
|
|
88
|
+
if (cash > liquidityMax()) {
|
|
89
|
+
_invest(cash - liquidityMiddle());
|
|
90
|
+
} else if (cash < liquidityMin()) {
|
|
91
|
+
uint256 deinvestAmount = Math.min(getInvestmentValue(), liquidityMiddle() - cash);
|
|
92
|
+
if (deinvestAmount > 0) {
|
|
93
|
+
_deinvest(deinvestAmount);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @dev This is called from PolicyPool when doesn't have enought money for payment.
|
|
100
|
+
* After the call, there should be enought money in PolicyPool.currency().balanceOf(this) to
|
|
101
|
+
* do the payment
|
|
102
|
+
* @param paymentAmount The amount of the payment
|
|
103
|
+
*/
|
|
104
|
+
function refillWallet(uint256 paymentAmount) external override returns (uint256 deinvest) {
|
|
105
|
+
uint256 cash = _asset.balanceOf(address(this));
|
|
106
|
+
require(cash < paymentAmount, "No need to refill the wallet for this payment");
|
|
107
|
+
uint256 investmentValue = getInvestmentValue();
|
|
108
|
+
// try to leave the pool balance at liquidity_middle after the payment
|
|
109
|
+
deinvest = paymentAmount + liquidityMiddle() - cash;
|
|
110
|
+
if (deinvest > investmentValue) deinvest = investmentValue;
|
|
111
|
+
_deinvest(deinvest);
|
|
112
|
+
return deinvest;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function _invest(uint256 amount) internal virtual {
|
|
116
|
+
DiamondStorage storage ds = diamondStorage();
|
|
117
|
+
ds.lastInvestmentValue += amount.toUint128();
|
|
118
|
+
emit MoneyInvested(amount);
|
|
119
|
+
// must be reimplemented do the actual cash movement
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function _deinvest(uint256 amount) internal virtual {
|
|
123
|
+
DiamondStorage storage ds = diamondStorage();
|
|
124
|
+
ds.lastInvestmentValue -= Math.min(uint256(ds.lastInvestmentValue), amount).toUint128();
|
|
125
|
+
emit MoneyDeinvested(amount);
|
|
126
|
+
// must be reimplemented do the actual cash movement
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function liquidityMin() public view returns (uint256) {
|
|
130
|
+
return diamondStorage().liquidityMin * 10**_asset.decimals();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function liquidityMiddle() public view returns (uint256) {
|
|
134
|
+
return diamondStorage().liquidityMiddle * 10**_asset.decimals();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function liquidityMax() public view returns (uint256) {
|
|
138
|
+
return diamondStorage().liquidityMax * 10**_asset.decimals();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function setLiquidityThresholds(
|
|
142
|
+
uint256 min,
|
|
143
|
+
uint256 middle,
|
|
144
|
+
uint256 max
|
|
145
|
+
) external validateParamsAfterChange {
|
|
146
|
+
DiamondStorage storage ds = diamondStorage();
|
|
147
|
+
if (min != type(uint256).max) {
|
|
148
|
+
ds.liquidityMin = (min / 10**_asset.decimals()).toUint32();
|
|
149
|
+
emit GovernanceAction(IAccessManager.GovernanceActions.setLiquidityMin, min);
|
|
150
|
+
}
|
|
151
|
+
if (middle != type(uint256).max) {
|
|
152
|
+
ds.liquidityMiddle = (middle / 10**_asset.decimals()).toUint32();
|
|
153
|
+
emit GovernanceAction(IAccessManager.GovernanceActions.setLiquidityMiddle, middle);
|
|
154
|
+
}
|
|
155
|
+
if (max != type(uint256).max) {
|
|
156
|
+
ds.liquidityMax = (max / 10**_asset.decimals()).toUint32();
|
|
157
|
+
emit GovernanceAction(IAccessManager.GovernanceActions.setLiquidityMax, max);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
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
|
-
import {WadRayMath} from "./WadRayMath.sol";
|
|
4
|
-
import {IRiskModule} from "
|
|
3
|
+
import {WadRayMath} from "./dependencies/WadRayMath.sol";
|
|
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) {
|