@ensuro/core 2.0.0-beta8 → 2.0.0
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 +31 -14
- package/build/contracts/AccessManager.sol/AccessManager.json +7 -2
- package/build/contracts/ERC4626AssetManager.sol/ERC4626AssetManager.json +28 -3
- package/build/contracts/EToken.sol/EToken.json +21 -15
- package/build/contracts/LPManualWhitelist.sol/LPManualWhitelist.json +21 -2
- package/build/contracts/LiquidityThresholdAssetManager.sol/LiquidityThresholdAssetManager.json +26 -1
- package/build/contracts/Policy.sol/Policy.json +2 -2
- package/build/contracts/PolicyPool.sol/PolicyPool.json +40 -2
- package/build/contracts/PolicyPoolComponent.sol/PolicyPoolComponent.json +19 -0
- package/build/contracts/PremiumsAccount.sol/PremiumsAccount.json +21 -15
- package/build/contracts/Reserve.sol/Reserve.json +19 -13
- package/build/contracts/RiskModule.sol/RiskModule.json +19 -0
- package/build/contracts/SignedQuoteRiskModule.sol/SignedQuoteRiskModule.json +1110 -0
- package/build/contracts/TimeScaled.sol/TimeScaled.json +3 -17
- package/build/contracts/TrustfulRiskModule.sol/TrustfulRiskModule.json +137 -2
- package/build/contracts/{WadRayMath.sol → dependencies/WadRayMath.sol}/WadRayMath.json +3 -3
- package/build/contracts/interfaces/IAssetManager.sol/IAssetManager.json +26 -1
- package/build/contracts/interfaces/IPolicyPool.sol/IPolicyPool.json +38 -0
- package/build/contracts/interfaces/IPolicyPoolComponent.sol/IPolicyPoolComponent.json +19 -0
- package/build/contracts/mocks/FixedRateVault.sol/FixedRateVault.json +2 -2
- 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 +115 -2
- package/build/contracts/mocks/PolicyPoolMock.sol/PolicyPoolMockForward.json +2 -2
- package/build/contracts/mocks/RiskModuleMock.sol/RiskModuleMock.json +111 -2
- package/build/contracts/mocks/TestCurrency.sol/TestCurrency.json +2 -2
- package/build/contracts/mocks/TestNFT.sol/TestNFT.json +2 -2
- package/contracts/AccessManager.sol +31 -2
- package/contracts/ERC4626AssetManager.sol +8 -2
- package/contracts/EToken.sol +129 -60
- package/contracts/LPManualWhitelist.sol +18 -2
- package/contracts/LiquidityThresholdAssetManager.sol +28 -12
- package/contracts/Policy.sol +5 -3
- package/contracts/PolicyPool.sol +221 -29
- package/contracts/PolicyPoolComponent.sol +36 -25
- package/contracts/PremiumsAccount.sol +220 -32
- package/contracts/Reserve.sol +130 -19
- package/contracts/RiskModule.sol +53 -20
- package/contracts/SignedQuoteRiskModule.sol +310 -0
- package/contracts/TimeScaled.sol +19 -15
- package/contracts/TrustfulRiskModule.sol +107 -6
- package/contracts/dependencies/WadRayMath.sol +126 -0
- package/contracts/interfaces/IAccessManager.sol +68 -13
- package/contracts/interfaces/IAssetManager.sol +69 -2
- package/contracts/interfaces/IEToken.sol +4 -1
- package/contracts/interfaces/ILPWhitelist.sol +17 -0
- package/contracts/interfaces/IPolicyPool.sol +19 -1
- package/contracts/interfaces/IPolicyPoolComponent.sol +5 -1
- package/contracts/interfaces/IRiskModule.sol +67 -4
- 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 +31 -0
- package/contracts/mocks/RiskModuleMock.sol +7 -1
- package/js/deploy.js +734 -0
- package/js/test-utils.js +184 -69
- package/package.json +4 -2
- package/scripts/change-pragma.sh +19 -0
- package/scripts/deploySmokeTest-fork.sh +53 -0
- package/scripts/deploySmokeTest.sh +51 -0
- package/scripts/storageLayout.js +33 -0
- package/scripts/utils.sh +65 -0
- package/contracts/WadRayMath.sol +0 -135
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
import {IPolicyPool} from "./IPolicyPool.sol";
|
|
5
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title IPolicyPoolComponent interface
|
|
8
9
|
* @dev Interface for Contracts linked (owned) by a PolicyPool. Useful to avoid cyclic dependencies
|
|
9
10
|
* @author Ensuro
|
|
10
11
|
*/
|
|
11
|
-
interface IPolicyPoolComponent {
|
|
12
|
+
interface IPolicyPoolComponent is IERC165 {
|
|
13
|
+
/**
|
|
14
|
+
* @dev Returns the address of the PolicyPool (see {PolicyPool}) where this component belongs.
|
|
15
|
+
*/
|
|
12
16
|
function policyPool() external view returns (IPolicyPool);
|
|
13
17
|
}
|
|
@@ -9,6 +9,9 @@ import {IPremiumsAccount} from "./IPremiumsAccount.sol";
|
|
|
9
9
|
* @author Ensuro
|
|
10
10
|
*/
|
|
11
11
|
interface IRiskModule {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Enum with the different parameters of the risk module, used in {RiskModule-setParam}.
|
|
14
|
+
*/
|
|
12
15
|
enum Parameter {
|
|
13
16
|
moc,
|
|
14
17
|
jrCollRatio,
|
|
@@ -22,28 +25,85 @@ interface IRiskModule {
|
|
|
22
25
|
maxDuration
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Struct of the parameters of the risk module that are used to calculate the different Policy fields (see
|
|
30
|
+
* {Policy-PolicyData}.
|
|
31
|
+
*/
|
|
25
32
|
struct Params {
|
|
33
|
+
/**
|
|
34
|
+
* @dev MoC (Margin of Conservativism) is a factor that multiplies the lossProb to increase or decrease the pure
|
|
35
|
+
* premium.
|
|
36
|
+
*/
|
|
26
37
|
uint256 moc;
|
|
38
|
+
/**
|
|
39
|
+
* @dev Junior Collateralization Ratio is the percentage of policy exposure (payout) that will be covered with the
|
|
40
|
+
* purePremium and the Junior EToken
|
|
41
|
+
*/
|
|
27
42
|
uint256 jrCollRatio;
|
|
43
|
+
/**
|
|
44
|
+
* @dev Collateralization Ratio is the percentage of policy exposure (payout) that will be covered by the
|
|
45
|
+
* purePremium and the Junior and Senior EToken. Usually is calculated as the relation between VAR99.5% and VAR100
|
|
46
|
+
* (full collateralization).
|
|
47
|
+
*/
|
|
28
48
|
uint256 collRatio;
|
|
49
|
+
/**
|
|
50
|
+
* @dev Ensuro PurePremium Fee is the percentage that will be multiplied by the pure premium to obtain the part of
|
|
51
|
+
* the Ensuro Fee that's proportional to the pure premium.
|
|
52
|
+
*/
|
|
29
53
|
uint256 ensuroPpFee;
|
|
54
|
+
/**
|
|
55
|
+
* @dev Ensuro Cost of Capital Fee is the percentage that will be multiplied by the cost of capital (CoC) to
|
|
56
|
+
* obtain the part of the Ensuro Fee that's proportional to the CoC.
|
|
57
|
+
*/
|
|
30
58
|
uint256 ensuroCocFee;
|
|
59
|
+
/**
|
|
60
|
+
* @dev Junior Return on Capital is the annualized interest rate that's charged for the capital locked in the Junior
|
|
61
|
+
* EToken.
|
|
62
|
+
*/
|
|
31
63
|
uint256 jrRoc;
|
|
64
|
+
/**
|
|
65
|
+
* @dev Senior Return on Capital is the annualized interest rate that's charged for the capital locked in the Senior
|
|
66
|
+
* EToken.
|
|
67
|
+
*/
|
|
32
68
|
uint256 srRoc;
|
|
33
69
|
}
|
|
34
70
|
|
|
71
|
+
/**
|
|
72
|
+
* @dev A readable name of this risk module. Never changes.
|
|
73
|
+
*/
|
|
35
74
|
function name() external view returns (string memory);
|
|
36
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @dev Returns different parameters of the risk module (see {Params})
|
|
78
|
+
*/
|
|
37
79
|
function params() external view returns (Params memory);
|
|
38
80
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
81
|
+
/**
|
|
82
|
+
* @dev Returns the maximum duration (in hours) of the policies of this risk module.
|
|
83
|
+
* The `expiration` of the policies has to be `<= (block.timestamp + 3600 * maxDuration())`
|
|
84
|
+
*/
|
|
43
85
|
function maxDuration() external view returns (uint256);
|
|
44
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @dev Returns the maximum payout accepted for new policies.
|
|
89
|
+
*/
|
|
90
|
+
function maxPayoutPerPolicy() external view returns (uint256);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @dev Returns sum of the (maximum) payout of the active policies of this risk module, i.e. the maximum possible
|
|
94
|
+
* amount of money that's exposed for this risk module.
|
|
95
|
+
*/
|
|
45
96
|
function activeExposure() external view returns (uint256);
|
|
46
97
|
|
|
98
|
+
/**
|
|
99
|
+
* @dev Returns maximum exposure (sum of the (maximum) payout of the active policies) of this risk module.
|
|
100
|
+
* `activeExposure() <= exposureLimit()` always
|
|
101
|
+
*/
|
|
102
|
+
function exposureLimit() external view returns (uint256);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @dev Returns the address of the partner that receives the partnerCommission
|
|
106
|
+
*/
|
|
47
107
|
function wallet() external view returns (address);
|
|
48
108
|
|
|
49
109
|
/**
|
|
@@ -56,5 +116,8 @@ interface IRiskModule {
|
|
|
56
116
|
*/
|
|
57
117
|
function releaseExposure(uint256 payout) external;
|
|
58
118
|
|
|
119
|
+
/**
|
|
120
|
+
* @dev Returns the {PremiumsAccount} where the premiums of this risk module are collected. Never changes.
|
|
121
|
+
*/
|
|
59
122
|
function premiumsAccount() external view returns (IPremiumsAccount);
|
|
60
123
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
6
|
+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
7
|
+
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
8
|
+
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
9
|
+
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
10
|
+
import {IPolicyPoolComponent} from "../interfaces/IPolicyPoolComponent.sol";
|
|
11
|
+
import {IEToken} from "../interfaces/IEToken.sol";
|
|
12
|
+
import {IRiskModule} from "../interfaces/IRiskModule.sol";
|
|
13
|
+
import {IPremiumsAccount} from "../interfaces/IPremiumsAccount.sol";
|
|
14
|
+
import {ILPWhitelist} from "../interfaces/ILPWhitelist.sol";
|
|
15
|
+
import {IAccessManager} from "../interfaces/IAccessManager.sol";
|
|
16
|
+
import {IAssetManager} from "../interfaces/IAssetManager.sol";
|
|
17
|
+
|
|
18
|
+
contract InterfaceIdCalculator {
|
|
19
|
+
bytes4 public constant IERC165_INTERFACEID = type(IERC165).interfaceId;
|
|
20
|
+
bytes4 public constant IERC20_INTERFACEID = type(IERC20).interfaceId;
|
|
21
|
+
bytes4 public constant IERC20METADATA_INTERFACEID = type(IERC20Metadata).interfaceId;
|
|
22
|
+
bytes4 public constant IERC721_INTERFACEID = type(IERC721).interfaceId;
|
|
23
|
+
bytes4 public constant IACCESSCONTROL_INTERFACEID = type(IAccessControl).interfaceId;
|
|
24
|
+
bytes4 public constant IPOLICYPOOL_INTERFACEID = type(IPolicyPool).interfaceId;
|
|
25
|
+
bytes4 public constant IPOLICYPOOLCOMPONENT_INTERFACEID = type(IPolicyPoolComponent).interfaceId;
|
|
26
|
+
bytes4 public constant IETOKEN_INTERFACEID = type(IEToken).interfaceId;
|
|
27
|
+
bytes4 public constant IRISKMODULE_INTERFACEID = type(IRiskModule).interfaceId;
|
|
28
|
+
bytes4 public constant IPREMIUMSACCOUNT_INTERFACEID = type(IPremiumsAccount).interfaceId;
|
|
29
|
+
bytes4 public constant ILPWHITELIST_INTERFACEID = type(ILPWhitelist).interfaceId;
|
|
30
|
+
bytes4 public constant IACCESSMANAGER_INTERFACEID = type(IAccessManager).interfaceId;
|
|
31
|
+
bytes4 public constant IASSETMANAGER_INTERFACEID = type(IAssetManager).interfaceId;
|
|
32
|
+
}
|
|
@@ -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
|
}
|
|
@@ -81,6 +81,14 @@ 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
|
+
|
|
88
|
+
function getPolicyHash(uint256 policyId) external view override returns (bytes32) {
|
|
89
|
+
return policyHashes[policyId];
|
|
90
|
+
}
|
|
91
|
+
|
|
84
92
|
function deposit(IEToken, uint256) external pure override {
|
|
85
93
|
revert("Not Implemented deposit");
|
|
86
94
|
}
|
|
@@ -88,6 +96,29 @@ contract PolicyPoolMock is IPolicyPool {
|
|
|
88
96
|
function withdraw(IEToken, uint256) external pure override returns (uint256) {
|
|
89
97
|
revert("Not Implemented withdraw");
|
|
90
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @dev Simple passthrough method for testing Policy.initialize
|
|
102
|
+
*/
|
|
103
|
+
function initializeAndEmitPolicy(
|
|
104
|
+
IRiskModule riskModule,
|
|
105
|
+
IRiskModule.Params memory rmParams,
|
|
106
|
+
uint256 premium,
|
|
107
|
+
uint256 payout,
|
|
108
|
+
uint256 lossProb,
|
|
109
|
+
uint40 expiration
|
|
110
|
+
) external {
|
|
111
|
+
Policy.PolicyData memory policy = Policy.initialize(
|
|
112
|
+
riskModule,
|
|
113
|
+
rmParams,
|
|
114
|
+
premium,
|
|
115
|
+
payout,
|
|
116
|
+
lossProb,
|
|
117
|
+
expiration
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
emit NewPolicy(riskModule, policy);
|
|
121
|
+
}
|
|
91
122
|
}
|
|
92
123
|
|
|
93
124
|
/**
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
pragma solidity ^0.8.0;
|
|
4
3
|
|
|
5
4
|
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
@@ -66,4 +65,11 @@ contract RiskModuleMock is RiskModule {
|
|
|
66
65
|
) external onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
67
66
|
return _newPolicy(payout, premium, lossProb, expiration, payer, onBehalfOf, internalId).id;
|
|
68
67
|
}
|
|
68
|
+
|
|
69
|
+
function resolvePolicy(Policy.PolicyData calldata policy, uint256 payout)
|
|
70
|
+
external
|
|
71
|
+
onlyComponentRole(RESOLVER_ROLE)
|
|
72
|
+
{
|
|
73
|
+
_policyPool.resolvePolicy(policy, payout);
|
|
74
|
+
}
|
|
69
75
|
}
|