@ensuro/core 2.0.0-beta1 → 2.0.0-beta11
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 +36 -14
- package/build/contracts/AccessManager.sol/AccessManager.json +564 -0
- package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +238 -0
- package/build/contracts/EToken.sol/EToken.json +147 -46
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +23 -4
- package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +222 -0
- package/build/contracts/Policy.sol/Policy.json +2 -2
- package/build/contracts/PolicyPool.sol/PolicyPool.json +437 -61
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +21 -2
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +142 -16
- package/build/contracts/Reserve.sol/Reserve.json +85 -8
- package/build/contracts/RiskModule.sol/RiskModule.json +21 -2
- package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +979 -0
- package/build/contracts/TimeScaled.sol/TimeScaled.json +3 -17
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +24 -5
- package/build/contracts/{WadRayMath.sol → dependencies/WadRayMath.sol}/WadRayMath.json +3 -3
- package/build/contracts/interfaces/{IPolicyPoolConfig.sol/IPolicyPoolConfig.json → IAccessManager.sol/IAccessManager.json} +77 -59
- package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +128 -0
- package/build/contracts/interfaces/IEToken.sol/IEToken.json +13 -0
- package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +40 -16
- package/build/contracts/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +19 -0
- package/build/contracts/interfaces/IPremiumsAccount.sol/IPremiumsAccount.json +13 -0
- package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +736 -0
- package/build/contracts/mocks/ForwardProxy.sol/ForwardProxy.json +2 -2
- package/build/contracts/mocks/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +180 -0
- package/build/contracts/mocks/PolicyHolderMock.sol/PolicyHolderMock.json +28 -2
- package/build/contracts/mocks/PolicyPoolComponentMock.sol/PolicyPoolComponentMock.json +21 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMock.json +118 -19
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +6 -6
- package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +783 -0
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +2 -2
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +2 -2
- package/contracts/AccessManager.sol +132 -0
- package/contracts/ERC4626AssetManager.sol +55 -0
- package/contracts/EToken.sol +208 -102
- package/contracts/LPManualWhitelist.sol +19 -3
- package/contracts/LiquidityThresholdAssetManager.sol +175 -0
- package/contracts/Policy.sol +5 -3
- package/contracts/PolicyPool.sol +381 -116
- package/contracts/PolicyPoolComponent.sol +61 -44
- package/contracts/PremiumsAccount.sol +324 -86
- package/contracts/Reserve.sol +199 -4
- package/contracts/RiskModule.sol +62 -31
- package/contracts/SignedQuoteRiskModule.sol +248 -0
- package/contracts/TimeScaled.sol +19 -15
- package/contracts/TrustfulRiskModule.sol +69 -2
- package/contracts/dependencies/WadRayMath.sol +126 -0
- package/contracts/interfaces/IAccessManager.sol +148 -0
- package/contracts/interfaces/IAssetManager.sol +89 -0
- package/contracts/interfaces/IEToken.sol +25 -2
- package/contracts/interfaces/ILPWhitelist.sol +17 -0
- package/contracts/interfaces/IPolicyPool.sol +21 -14
- package/contracts/interfaces/IPolicyPoolComponent.sol +5 -1
- package/contracts/interfaces/IPremiumsAccount.sol +5 -0
- package/contracts/interfaces/IRiskModule.sol +67 -4
- package/contracts/mocks/FixedRateVault.sol +85 -0
- package/contracts/mocks/InterfaceIdCalculator.sol +32 -0
- package/contracts/mocks/PolicyHolderMock.sol +21 -0
- package/contracts/mocks/PolicyPoolComponentMock.sol +10 -0
- package/contracts/mocks/PolicyPoolMock.sol +41 -15
- package/contracts/mocks/RiskModuleMock.sol +75 -0
- package/js/deploy.js +704 -0
- package/js/test-utils.js +339 -159
- package/package.json +1 -1
- package/build/contracts/FlightDelayRiskModule.sol/FlightDelayRiskModule.json +0 -890
- package/build/contracts/PolicyNFT.sol/PolicyNFT.json +0 -583
- package/build/contracts/PolicyPoolConfig.sol/PolicyPoolConfig.json +0 -691
- package/build/contracts/dependencies/ChainlinkClientUpgradeable.sol/ChainlinkClientUpgradeable.json +0 -63
- package/build/contracts/interfaces/IPolicyNFT.sol/IPolicyNFT.json +0 -321
- package/build/contracts/mocks/LinkTokenMock.sol/LinkTokenMock.json +0 -370
- package/build/contracts/mocks/TestCurrencyUUPS.sol/TestCurrencyUUPS.json +0 -353
- package/build/contracts/upgraded/IPolicyNFTv1.sol/IPolicyNFTv1.json +0 -322
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1.json +0 -584
- package/build/contracts/upgraded/PolicyNFTv1.sol/PolicyNFTv1_Upgrade.json +0 -615
- package/contracts/FlightDelayRiskModule.sol +0 -217
- package/contracts/PolicyNFT.sol +0 -96
- package/contracts/PolicyPoolConfig.sol +0 -204
- package/contracts/WadRayMath.sol +0 -135
- package/contracts/dependencies/ChainlinkClientUpgradeable.sol +0 -371
- package/contracts/interfaces/IPolicyNFT.sol +0 -15
- package/contracts/interfaces/IPolicyPoolConfig.sol +0 -96
- package/contracts/mocks/LinkTokenMock.sol +0 -30
- package/contracts/upgraded/IPolicyNFTv1.sol +0 -15
- package/contracts/upgraded/PolicyNFTv1.sol +0 -126
|
@@ -8,11 +8,13 @@ contract PolicyHolderMock is IPolicyHolder {
|
|
|
8
8
|
uint256 public policyId;
|
|
9
9
|
uint256 public payout;
|
|
10
10
|
bool public fail;
|
|
11
|
+
bool public notImplemented;
|
|
11
12
|
|
|
12
13
|
event NotificationReceived(uint256 kind, uint256 policyId, address operator, address from);
|
|
13
14
|
|
|
14
15
|
constructor(bool fail_) {
|
|
15
16
|
fail = fail_;
|
|
17
|
+
notImplemented = false;
|
|
16
18
|
payout = type(uint256).max;
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -20,12 +22,21 @@ contract PolicyHolderMock is IPolicyHolder {
|
|
|
20
22
|
fail = fail_;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
function setNotImplemented(bool notImplemented_) external {
|
|
26
|
+
notImplemented = notImplemented_;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
function onERC721Received(
|
|
24
30
|
address operator,
|
|
25
31
|
address from,
|
|
26
32
|
uint256 policyId_,
|
|
27
33
|
bytes calldata
|
|
28
34
|
) external override returns (bytes4) {
|
|
35
|
+
if (notImplemented)
|
|
36
|
+
// solhint-disable-next-line no-inline-assembly
|
|
37
|
+
assembly {
|
|
38
|
+
revert(0, 0)
|
|
39
|
+
}
|
|
29
40
|
if (fail) revert("onERC721Received: They told me I have to fail");
|
|
30
41
|
policyId = policyId_;
|
|
31
42
|
emit NotificationReceived(0, policyId_, operator, from);
|
|
@@ -37,6 +48,11 @@ contract PolicyHolderMock is IPolicyHolder {
|
|
|
37
48
|
address from,
|
|
38
49
|
uint256 policyId_
|
|
39
50
|
) external override returns (bytes4) {
|
|
51
|
+
if (notImplemented)
|
|
52
|
+
// solhint-disable-next-line no-inline-assembly
|
|
53
|
+
assembly {
|
|
54
|
+
revert(0, 0)
|
|
55
|
+
}
|
|
40
56
|
if (fail) revert("onPolicyExpired: They told me I have to fail");
|
|
41
57
|
policyId = policyId_;
|
|
42
58
|
payout = 0;
|
|
@@ -59,6 +75,11 @@ contract PolicyHolderMock is IPolicyHolder {
|
|
|
59
75
|
uint256 policyId_,
|
|
60
76
|
uint256 amount
|
|
61
77
|
) external override returns (bytes4) {
|
|
78
|
+
if (notImplemented)
|
|
79
|
+
// solhint-disable-next-line no-inline-assembly
|
|
80
|
+
assembly {
|
|
81
|
+
revert(0, 0)
|
|
82
|
+
}
|
|
62
83
|
if (fail) revert("onPayoutReceived: They told me I have to fail");
|
|
63
84
|
policyId = policyId_;
|
|
64
85
|
payout = amount;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
4
5
|
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
5
6
|
import {IPolicyPoolComponent} from "../interfaces/IPolicyPoolComponent.sol";
|
|
6
7
|
|
|
@@ -14,4 +15,13 @@ contract PolicyPoolComponentMock is IPolicyPoolComponent {
|
|
|
14
15
|
function policyPool() external view override returns (IPolicyPool) {
|
|
15
16
|
return _policyPool;
|
|
16
17
|
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @dev See {IERC165-supportsInterface}.
|
|
21
|
+
*/
|
|
22
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
23
|
+
return
|
|
24
|
+
interfaceId == type(IERC165).interfaceId ||
|
|
25
|
+
interfaceId == type(IPolicyPoolComponent).interfaceId;
|
|
26
|
+
}
|
|
17
27
|
}
|
|
@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
5
5
|
import {IRiskModule} from "../interfaces/IRiskModule.sol";
|
|
6
6
|
import {IEToken} from "../interfaces/IEToken.sol";
|
|
7
|
-
import {
|
|
7
|
+
import {IAccessManager} from "../interfaces/IAccessManager.sol";
|
|
8
8
|
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
|
|
9
9
|
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
10
10
|
import {Policy} from "../Policy.sol";
|
|
@@ -17,7 +17,7 @@ contract PolicyPoolMock is IPolicyPool {
|
|
|
17
17
|
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
|
|
18
18
|
|
|
19
19
|
IERC20Metadata internal _currency;
|
|
20
|
-
|
|
20
|
+
IAccessManager internal _access;
|
|
21
21
|
|
|
22
22
|
mapping(uint256 => Policy.PolicyData) internal policies;
|
|
23
23
|
mapping(uint256 => bytes32) internal policyHashes;
|
|
@@ -25,27 +25,27 @@ contract PolicyPoolMock is IPolicyPool {
|
|
|
25
25
|
event NewPolicy(IRiskModule indexed riskModule, Policy.PolicyData policy);
|
|
26
26
|
event PolicyResolved(IRiskModule indexed riskModule, uint256 indexed policyId, uint256 payout);
|
|
27
27
|
|
|
28
|
-
constructor(IERC20Metadata currency_,
|
|
28
|
+
constructor(IERC20Metadata currency_, IAccessManager access_) {
|
|
29
29
|
_currency = currency_;
|
|
30
|
-
|
|
31
|
-
_config.connect();
|
|
30
|
+
_access = access_;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
function currency() external view override returns (IERC20Metadata) {
|
|
35
34
|
return _currency;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
function
|
|
39
|
-
return
|
|
37
|
+
function access() external view override returns (IAccessManager) {
|
|
38
|
+
return _access;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
function
|
|
41
|
+
function treasury() external pure override returns (address) {
|
|
43
42
|
return address(0);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
function newPolicy(
|
|
47
46
|
Policy.PolicyData memory policy,
|
|
48
|
-
address, /*
|
|
47
|
+
address, /* caller */
|
|
48
|
+
address, /* policyHolder */
|
|
49
49
|
uint96 internalId
|
|
50
50
|
) external override returns (uint256) {
|
|
51
51
|
policy.id = (uint256(uint160(address(policy.riskModule))) << 96) + internalId;
|
|
@@ -81,6 +81,10 @@ contract PolicyPoolMock is IPolicyPool {
|
|
|
81
81
|
return _resolvePolicy(policy, customerWon ? policy.payout : 0);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
function isActive(uint256 policyId) external view override returns (bool) {
|
|
85
|
+
return policyHashes[policyId] != bytes32(0);
|
|
86
|
+
}
|
|
87
|
+
|
|
84
88
|
function deposit(IEToken, uint256) external pure override {
|
|
85
89
|
revert("Not Implemented deposit");
|
|
86
90
|
}
|
|
@@ -88,6 +92,29 @@ contract PolicyPoolMock is IPolicyPool {
|
|
|
88
92
|
function withdraw(IEToken, uint256) external pure override returns (uint256) {
|
|
89
93
|
revert("Not Implemented withdraw");
|
|
90
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @dev Simple passthrough method for testing Policy.initialize
|
|
98
|
+
*/
|
|
99
|
+
function initializeAndEmitPolicy(
|
|
100
|
+
IRiskModule riskModule,
|
|
101
|
+
IRiskModule.Params memory rmParams,
|
|
102
|
+
uint256 premium,
|
|
103
|
+
uint256 payout,
|
|
104
|
+
uint256 lossProb,
|
|
105
|
+
uint40 expiration
|
|
106
|
+
) external {
|
|
107
|
+
Policy.PolicyData memory policy = Policy.initialize(
|
|
108
|
+
riskModule,
|
|
109
|
+
rmParams,
|
|
110
|
+
premium,
|
|
111
|
+
payout,
|
|
112
|
+
lossProb,
|
|
113
|
+
expiration
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
emit NewPolicy(riskModule, policy);
|
|
117
|
+
}
|
|
91
118
|
}
|
|
92
119
|
|
|
93
120
|
/**
|
|
@@ -100,23 +127,22 @@ contract PolicyPoolMockForward is ForwardProxy {
|
|
|
100
127
|
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
|
|
101
128
|
|
|
102
129
|
IERC20Metadata internal _currency;
|
|
103
|
-
|
|
130
|
+
IAccessManager internal _access;
|
|
104
131
|
|
|
105
132
|
constructor(
|
|
106
133
|
address forwardTo,
|
|
107
134
|
IERC20Metadata currency_,
|
|
108
|
-
|
|
135
|
+
IAccessManager access_
|
|
109
136
|
) ForwardProxy(forwardTo) {
|
|
110
137
|
_currency = currency_;
|
|
111
|
-
|
|
112
|
-
_config.connect();
|
|
138
|
+
_access = access_;
|
|
113
139
|
}
|
|
114
140
|
|
|
115
141
|
function currency() external view returns (IERC20Metadata) {
|
|
116
142
|
return _currency;
|
|
117
143
|
}
|
|
118
144
|
|
|
119
|
-
function
|
|
120
|
-
return
|
|
145
|
+
function access() external view returns (IAccessManager) {
|
|
146
|
+
return _access;
|
|
121
147
|
}
|
|
122
148
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
5
|
+
import {IPremiumsAccount} from "../interfaces/IPremiumsAccount.sol";
|
|
6
|
+
import {RiskModule} from "../RiskModule.sol";
|
|
7
|
+
import {Policy} from "../Policy.sol";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title Trustful Risk Module
|
|
11
|
+
* @dev Risk Module without any validation, just the newPolicy and resolvePolicy need to be called by
|
|
12
|
+
authorized users
|
|
13
|
+
* @custom:security-contact security@ensuro.co
|
|
14
|
+
* @author Ensuro
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
contract RiskModuleMock is RiskModule {
|
|
18
|
+
bytes32 public constant PRICER_ROLE = keccak256("PRICER_ROLE");
|
|
19
|
+
bytes32 public constant RESOLVER_ROLE = keccak256("RESOLVER_ROLE");
|
|
20
|
+
|
|
21
|
+
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
22
|
+
// solhint-disable-next-line no-empty-blocks
|
|
23
|
+
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
|
|
24
|
+
RiskModule(policyPool_, premiumsAccount_)
|
|
25
|
+
{} // solhint-disable-line no-empty-blocks
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @dev Initializes the RiskModule
|
|
29
|
+
* @param name_ Name of the Risk Module
|
|
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)
|
|
35
|
+
* @param wallet_ Address of the RiskModule provider
|
|
36
|
+
*/
|
|
37
|
+
function initialize(
|
|
38
|
+
string memory name_,
|
|
39
|
+
uint256 collRatio_,
|
|
40
|
+
uint256 ensuroPpFee_,
|
|
41
|
+
uint256 srRoc_,
|
|
42
|
+
uint256 maxPayoutPerPolicy_,
|
|
43
|
+
uint256 exposureLimit_,
|
|
44
|
+
address wallet_
|
|
45
|
+
) public initializer {
|
|
46
|
+
__RiskModule_init(
|
|
47
|
+
name_,
|
|
48
|
+
collRatio_,
|
|
49
|
+
ensuroPpFee_,
|
|
50
|
+
srRoc_,
|
|
51
|
+
maxPayoutPerPolicy_,
|
|
52
|
+
exposureLimit_,
|
|
53
|
+
wallet_
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function newPolicy(
|
|
58
|
+
uint256 payout,
|
|
59
|
+
uint256 premium,
|
|
60
|
+
uint256 lossProb,
|
|
61
|
+
uint40 expiration,
|
|
62
|
+
address payer,
|
|
63
|
+
address onBehalfOf,
|
|
64
|
+
uint96 internalId
|
|
65
|
+
) external onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
66
|
+
return _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId).id;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
|
|
70
|
+
external
|
|
71
|
+
onlyComponentRole(RESOLVER_ROLE)
|
|
72
|
+
{
|
|
73
|
+
_policyPool.resolvePolicy(policy, payout);
|
|
74
|
+
}
|
|
75
|
+
}
|