@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
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.0;
|
|
3
|
-
|
|
4
|
-
import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
5
|
-
import {IPremiumsAccount} from "./interfaces/IPremiumsAccount.sol";
|
|
6
|
-
import {Policy} from "./Policy.sol";
|
|
7
|
-
import {RiskModule} from "./RiskModule.sol";
|
|
8
|
-
import {Chainlink} from "@chainlink/contracts/src/v0.8/Chainlink.sol";
|
|
9
|
-
import {ChainlinkClientUpgradeable} from "./dependencies/ChainlinkClientUpgradeable.sol";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @title Flight Delay Risk Module
|
|
13
|
-
* @dev Risk Module that resolves policy based in actualarrivaldate of flight
|
|
14
|
-
* @custom:security-contact security@ensuro.co
|
|
15
|
-
* @author Ensuro
|
|
16
|
-
*/
|
|
17
|
-
contract FlightDelayRiskModule is RiskModule, ChainlinkClientUpgradeable {
|
|
18
|
-
using Chainlink for Chainlink.Request;
|
|
19
|
-
|
|
20
|
-
bytes32 public constant PRICER_ROLE = keccak256("PRICER_ROLE");
|
|
21
|
-
bytes32 public constant ORACLE_ADMIN_ROLE = keccak256("ORACLE_ADMIN_ROLE");
|
|
22
|
-
// Multiplier to calculate expiration = expectedArrival + tolerance + delayTime * DELAY_EXPIRATION_TIMES
|
|
23
|
-
uint40 public constant DELAY_EXPIRATION_TIMES = 5;
|
|
24
|
-
|
|
25
|
-
struct PolicyData {
|
|
26
|
-
Policy.PolicyData ensuroPolicy;
|
|
27
|
-
string flight;
|
|
28
|
-
uint40 departure;
|
|
29
|
-
uint40 expectedArrival;
|
|
30
|
-
uint40 tolerance;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
struct OracleParams {
|
|
34
|
-
address oracle;
|
|
35
|
-
uint96 delayTime;
|
|
36
|
-
uint256 fee;
|
|
37
|
-
bytes16 dataJobId;
|
|
38
|
-
bytes16 sleepJobId;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
OracleParams internal _oracleParams;
|
|
42
|
-
|
|
43
|
-
mapping(bytes32 => uint256) internal _pendingQueries;
|
|
44
|
-
mapping(uint256 => PolicyData) internal _policies;
|
|
45
|
-
|
|
46
|
-
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
47
|
-
// solhint-disable-next-line no-empty-blocks
|
|
48
|
-
constructor(IPolicyPool policyPool_, IPremiumsAccount premiumsAccount_)
|
|
49
|
-
RiskModule(policyPool_, premiumsAccount_)
|
|
50
|
-
{} // solhint-disable-line no-empty-blocks
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @dev Initializes the RiskModule
|
|
54
|
-
* @param name_ Name of the Risk Module
|
|
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)
|
|
60
|
-
* @param wallet_ Address of the RiskModule provider
|
|
61
|
-
* @param linkToken_ Address of ChainLink LINK token
|
|
62
|
-
* @param oracleParams_ Parameters of the Oracle
|
|
63
|
-
*/
|
|
64
|
-
function initialize(
|
|
65
|
-
string memory name_,
|
|
66
|
-
uint256 collRatio_,
|
|
67
|
-
uint256 ensuroPpFee_,
|
|
68
|
-
uint256 srRoc_,
|
|
69
|
-
uint256 maxPayoutPerPolicy_,
|
|
70
|
-
uint256 exposureLimit_,
|
|
71
|
-
address wallet_,
|
|
72
|
-
address linkToken_,
|
|
73
|
-
OracleParams memory oracleParams_
|
|
74
|
-
) public initializer {
|
|
75
|
-
__RiskModule_init(
|
|
76
|
-
name_,
|
|
77
|
-
collRatio_,
|
|
78
|
-
ensuroPpFee_,
|
|
79
|
-
srRoc_,
|
|
80
|
-
maxPayoutPerPolicy_,
|
|
81
|
-
exposureLimit_,
|
|
82
|
-
wallet_
|
|
83
|
-
);
|
|
84
|
-
__ChainlinkClient_init();
|
|
85
|
-
__FlightDelayRiskModule_init_unchained(linkToken_, oracleParams_);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// solhint-disable-next-line func-name-mixedcase
|
|
89
|
-
function __FlightDelayRiskModule_init_unchained(
|
|
90
|
-
address linkToken_,
|
|
91
|
-
OracleParams memory oracleParams_
|
|
92
|
-
) internal initializer {
|
|
93
|
-
setChainlinkToken(linkToken_);
|
|
94
|
-
_oracleParams = oracleParams_;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function setOracleParams(OracleParams memory newParams)
|
|
98
|
-
external
|
|
99
|
-
onlyComponentRole(ORACLE_ADMIN_ROLE)
|
|
100
|
-
{
|
|
101
|
-
_oracleParams = newParams;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function oracleParams() external view returns (OracleParams memory) {
|
|
105
|
-
return _oracleParams;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @dev Creates a new policy
|
|
110
|
-
* @param flight Flight Number as String (ex: NAX105)
|
|
111
|
-
* @param departure Departure in epoch seconds (ex: 1631817600)
|
|
112
|
-
* @param expectedArrival Expected arrival in epoch seconds (ex: 1631824800)
|
|
113
|
-
* @param tolerance In seconds, the tolerance margin after expectedArrival before trigger the policy
|
|
114
|
-
* @param payout Payout for customer in case policy is triggered
|
|
115
|
-
* @param premium Premium the customer pays
|
|
116
|
-
* @param lossProb Probability of policy being triggered
|
|
117
|
-
* @param customer Customer address (to take premium from and send payout)
|
|
118
|
-
*/
|
|
119
|
-
function newPolicy(
|
|
120
|
-
string memory flight,
|
|
121
|
-
uint40 departure,
|
|
122
|
-
uint40 expectedArrival,
|
|
123
|
-
uint40 tolerance,
|
|
124
|
-
uint256 payout,
|
|
125
|
-
uint256 premium,
|
|
126
|
-
uint256 lossProb,
|
|
127
|
-
address customer,
|
|
128
|
-
uint96 internalId
|
|
129
|
-
) external onlyComponentRole(PRICER_ROLE) returns (uint256) {
|
|
130
|
-
require(expectedArrival > block.timestamp, "expectedArrival can't be in the past");
|
|
131
|
-
require(departure != 0 && expectedArrival > departure, "expectedArrival <= departure!");
|
|
132
|
-
uint40 expiration = expectedArrival +
|
|
133
|
-
tolerance +
|
|
134
|
-
uint40(_oracleParams.delayTime) *
|
|
135
|
-
DELAY_EXPIRATION_TIMES;
|
|
136
|
-
Policy.PolicyData memory ensuroPolicy = _newPolicy(
|
|
137
|
-
payout,
|
|
138
|
-
premium,
|
|
139
|
-
lossProb,
|
|
140
|
-
expiration,
|
|
141
|
-
customer,
|
|
142
|
-
internalId
|
|
143
|
-
);
|
|
144
|
-
PolicyData storage policy = _policies[ensuroPolicy.id];
|
|
145
|
-
policy.ensuroPolicy = ensuroPolicy;
|
|
146
|
-
policy.flight = flight;
|
|
147
|
-
policy.departure = departure;
|
|
148
|
-
policy.expectedArrival = expectedArrival;
|
|
149
|
-
policy.tolerance = tolerance;
|
|
150
|
-
|
|
151
|
-
uint256 until = expectedArrival + tolerance + uint256(_oracleParams.delayTime);
|
|
152
|
-
_chainlinkRequest(ensuroPolicy.id, policy, until);
|
|
153
|
-
return ensuroPolicy.id;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function _chainlinkRequest(
|
|
157
|
-
uint256 policyId,
|
|
158
|
-
PolicyData storage policy,
|
|
159
|
-
uint256 until
|
|
160
|
-
) internal {
|
|
161
|
-
// request takes a JobID, a callback address, and callback function as input
|
|
162
|
-
Chainlink.Request memory req = buildChainlinkRequest(
|
|
163
|
-
until == 0 ? _oracleParams.dataJobId : _oracleParams.sleepJobId,
|
|
164
|
-
address(this),
|
|
165
|
-
this.fulfill.selector
|
|
166
|
-
);
|
|
167
|
-
req.add("flight", policy.flight);
|
|
168
|
-
req.add("endpoint", "actualarrivaldate");
|
|
169
|
-
req.addUint("departure", policy.departure);
|
|
170
|
-
if (until > 0) {
|
|
171
|
-
req.addUint("until", until);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Sends the request with the amount of payment specified to the oracle
|
|
175
|
-
// (results will arrive with the callback = later)
|
|
176
|
-
bytes32 queryId = sendChainlinkRequestTo(_oracleParams.oracle, req, _oracleParams.fee);
|
|
177
|
-
_pendingQueries[queryId] = policyId;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @dev Forces the resolution of the policy (without waiting Chainlink scheduled on creation)
|
|
182
|
-
* @param policyId The id of the policy previously created (in newPolicy)
|
|
183
|
-
*/
|
|
184
|
-
function resolvePolicy(uint256 policyId)
|
|
185
|
-
external
|
|
186
|
-
onlyComponentRole(PRICER_ROLE)
|
|
187
|
-
returns (uint256)
|
|
188
|
-
{
|
|
189
|
-
PolicyData storage policy = _policies[policyId];
|
|
190
|
-
require(policy.expectedArrival != 0, "Policy not found!");
|
|
191
|
-
_chainlinkRequest(policyId, policy, 0);
|
|
192
|
-
return policyId;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function fulfill(bytes32 queryId, int256 actualArrivalDate)
|
|
196
|
-
public
|
|
197
|
-
recordChainlinkFulfillment(queryId)
|
|
198
|
-
{
|
|
199
|
-
uint256 policyId = _pendingQueries[queryId];
|
|
200
|
-
require(policyId != 0, "queryId not found!");
|
|
201
|
-
PolicyData storage policy = _policies[policyId];
|
|
202
|
-
|
|
203
|
-
if (actualArrivalDate == 0) {
|
|
204
|
-
if (block.timestamp > (policy.expectedArrival + policy.tolerance)) {
|
|
205
|
-
// Treat as arrived after tolerance
|
|
206
|
-
actualArrivalDate = int256(uint256((policy.expectedArrival + policy.tolerance) + 1));
|
|
207
|
-
} else {
|
|
208
|
-
// Not arrived yet
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
bool customerWon = (actualArrivalDate <= 0 || // cancelled
|
|
213
|
-
uint256(actualArrivalDate) > uint256(policy.expectedArrival + policy.tolerance)); // arrived after tolerance
|
|
214
|
-
|
|
215
|
-
_policyPool.resolvePolicyFullPayout(policy.ensuroPolicy, customerWon);
|
|
216
|
-
}
|
|
217
|
-
}
|
package/contracts/PolicyNFT.sol
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.2;
|
|
3
|
-
|
|
4
|
-
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
5
|
-
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
|
|
6
|
-
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
|
|
7
|
-
import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
8
|
-
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
9
|
-
import {IPolicyNFT} from "./interfaces/IPolicyNFT.sol";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @title PolicyNFT - NFT that keeps track of issued policies and its owners
|
|
13
|
-
* @dev Every time a new policy is accepted by the PolicyPool, a new NFT is minted generating a new
|
|
14
|
-
* policyId owned by the customer. Only the PolicyPool can mint NFTs.
|
|
15
|
-
* After creation, NFTs can be transferred in the ERC721 standard way and that changes the policy holder.
|
|
16
|
-
* @custom:security-contact security@ensuro.co
|
|
17
|
-
* @author Ensuro
|
|
18
|
-
*/
|
|
19
|
-
contract PolicyNFT is UUPSUpgradeable, ERC721Upgradeable, PausableUpgradeable, IPolicyNFT {
|
|
20
|
-
bytes32 public constant GUARDIAN_ROLE = keccak256("GUARDIAN_ROLE");
|
|
21
|
-
bytes32 public constant LEVEL1_ROLE = keccak256("LEVEL1_ROLE");
|
|
22
|
-
|
|
23
|
-
IPolicyPool internal _policyPool;
|
|
24
|
-
|
|
25
|
-
modifier onlyPolicyPool() {
|
|
26
|
-
require(_msgSender() == address(_policyPool), "The caller must be the PolicyPool");
|
|
27
|
-
_;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
modifier onlyPoolRole2(bytes32 role1, bytes32 role2) {
|
|
31
|
-
_policyPool.config().checkRole2(role1, role2, msg.sender);
|
|
32
|
-
_;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
modifier onlyPoolRole(bytes32 role) {
|
|
36
|
-
_policyPool.config().checkRole(role, msg.sender);
|
|
37
|
-
_;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function initialize(
|
|
41
|
-
string memory name_,
|
|
42
|
-
string memory symbol_,
|
|
43
|
-
IPolicyPool policyPool_
|
|
44
|
-
) public initializer {
|
|
45
|
-
__UUPSUpgradeable_init();
|
|
46
|
-
__Pausable_init();
|
|
47
|
-
__ERC721_init(name_, symbol_);
|
|
48
|
-
__PolicyNFT_init_unchained(policyPool_);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// solhint-disable-next-line func-name-mixedcase
|
|
52
|
-
function __PolicyNFT_init_unchained(IPolicyPool policyPool_) internal initializer {
|
|
53
|
-
_policyPool = policyPool_;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// solhint-disable-next-line no-empty-blocks
|
|
57
|
-
function _authorizeUpgrade(address) internal override onlyPoolRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {}
|
|
58
|
-
|
|
59
|
-
function pause() public onlyPoolRole(GUARDIAN_ROLE) {
|
|
60
|
-
_pause();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function unpause() public onlyPoolRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {
|
|
64
|
-
_unpause();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @dev This function can be called only once in contract's lifetime. It links the NFT with the
|
|
69
|
-
* PolicyPool contract. It's called in PolicyPool initialization.
|
|
70
|
-
*/
|
|
71
|
-
function connect() external override {
|
|
72
|
-
require(
|
|
73
|
-
address(_policyPool) == address(0) || address(_policyPool) == _msgSender(),
|
|
74
|
-
"PolicyPool already connected"
|
|
75
|
-
);
|
|
76
|
-
_policyPool = IPolicyPool(_msgSender());
|
|
77
|
-
// Not possible to do this validation because connect is called in _policyPool initialize :'(
|
|
78
|
-
// require(_policyPool.policyNFT() == address(this), "PolicyPool not connected to this config");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function policyPool() external view returns (IPolicyPool) {
|
|
82
|
-
return _policyPool;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function safeMint(address to, uint256 policyId) external override onlyPolicyPool whenNotPaused {
|
|
86
|
-
_safeMint(to, policyId, "");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function _beforeTokenTransfer(
|
|
90
|
-
address from,
|
|
91
|
-
address to,
|
|
92
|
-
uint256 tokenId
|
|
93
|
-
) internal override whenNotPaused {
|
|
94
|
-
super._beforeTokenTransfer(from, to, tokenId);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.0;
|
|
3
|
-
|
|
4
|
-
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
|
|
5
|
-
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
6
|
-
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
7
|
-
import {IPolicyPoolConfig} from "./interfaces/IPolicyPoolConfig.sol";
|
|
8
|
-
import {IPolicyPool} from "./interfaces/IPolicyPool.sol";
|
|
9
|
-
import {IRiskModule} from "./interfaces/IRiskModule.sol";
|
|
10
|
-
import {ILPWhitelist} from "./interfaces/ILPWhitelist.sol";
|
|
11
|
-
import {IPolicyPoolComponent} from "./interfaces/IPolicyPoolComponent.sol";
|
|
12
|
-
import {WadRayMath} from "./WadRayMath.sol";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @title PolicyPoolConfig - Protocol access roles and other settings/components
|
|
16
|
-
* @dev Contract that holds the access roles for PolicyPool and other components of the protocol.
|
|
17
|
-
* @custom:security-contact security@ensuro.co
|
|
18
|
-
* @author Ensuro
|
|
19
|
-
*/
|
|
20
|
-
contract PolicyPoolConfig is
|
|
21
|
-
Initializable,
|
|
22
|
-
AccessControlUpgradeable,
|
|
23
|
-
UUPSUpgradeable,
|
|
24
|
-
IPolicyPoolConfig
|
|
25
|
-
{
|
|
26
|
-
using WadRayMath for uint256;
|
|
27
|
-
|
|
28
|
-
// Core governance roles
|
|
29
|
-
bytes32 public constant GUARDIAN_ROLE = keccak256("GUARDIAN_ROLE");
|
|
30
|
-
bytes32 public constant LEVEL1_ROLE = keccak256("LEVEL1_ROLE");
|
|
31
|
-
bytes32 public constant LEVEL2_ROLE = keccak256("LEVEL2_ROLE");
|
|
32
|
-
bytes32 public constant LEVEL3_ROLE = keccak256("LEVEL3_ROLE");
|
|
33
|
-
|
|
34
|
-
uint256 public constant L2_RM_LIMIT = 5e16; // 5% in WAD
|
|
35
|
-
|
|
36
|
-
address internal _treasury; // address of Ensuro treasury
|
|
37
|
-
IPolicyPool internal _policyPool;
|
|
38
|
-
ILPWhitelist internal _lpWhitelist; // Contract that handles whitelisting of Liquidity Providers
|
|
39
|
-
|
|
40
|
-
mapping(IRiskModule => RiskModuleStatus) private _riskModules;
|
|
41
|
-
|
|
42
|
-
event ComponentChanged(IPolicyPoolConfig.GovernanceActions indexed action, address value);
|
|
43
|
-
|
|
44
|
-
modifier onlyRole2(bytes32 role1, bytes32 role2) {
|
|
45
|
-
if (!hasRole(role1, _msgSender())) _checkRole(role2, _msgSender());
|
|
46
|
-
_;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
modifier onlyRole3(
|
|
50
|
-
bytes32 role1,
|
|
51
|
-
bytes32 role2,
|
|
52
|
-
bytes32 role3
|
|
53
|
-
) {
|
|
54
|
-
if (!hasRole(role1, _msgSender()) && !hasRole(role2, _msgSender())) {
|
|
55
|
-
_checkRole(role3, _msgSender());
|
|
56
|
-
}
|
|
57
|
-
_;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function initialize(IPolicyPool policyPool_, address treasury_) public initializer {
|
|
61
|
-
__AccessControl_init();
|
|
62
|
-
__UUPSUpgradeable_init();
|
|
63
|
-
__PolicyPoolConfig_init_unchained(policyPool_, treasury_);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// solhint-disable-next-line func-name-mixedcase
|
|
67
|
-
function __PolicyPoolConfig_init_unchained(IPolicyPool policyPool_, address treasury_)
|
|
68
|
-
internal
|
|
69
|
-
initializer
|
|
70
|
-
{
|
|
71
|
-
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
|
72
|
-
_policyPool = policyPool_;
|
|
73
|
-
_treasury = treasury_;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @dev This function can be called only once in contract's lifetime. It links the PolicyPoolConfig with the
|
|
78
|
-
* PolicyPool contract. It's called in PolicyPool initialization.
|
|
79
|
-
*/
|
|
80
|
-
function connect() external override {
|
|
81
|
-
require(
|
|
82
|
-
address(_policyPool) == address(0) || address(_policyPool) == _msgSender(),
|
|
83
|
-
"PolicyPool already connected"
|
|
84
|
-
);
|
|
85
|
-
_policyPool = IPolicyPool(_msgSender());
|
|
86
|
-
// Not possible to do this validation because connect is called in _policyPool initialize :'(
|
|
87
|
-
// require(_policyPool.config() == this, "PolicyPool not connected to this config");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function policyPool() external view returns (IPolicyPool) {
|
|
91
|
-
return _policyPool;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// solhint-disable-next-line no-empty-blocks
|
|
95
|
-
function _authorizeUpgrade(address) internal override onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE) {}
|
|
96
|
-
|
|
97
|
-
function getComponentRole(address component, bytes32 role) public pure returns (bytes32) {
|
|
98
|
-
return bytes32(bytes20(component)) ^ role;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function checkComponentRole(
|
|
102
|
-
address component,
|
|
103
|
-
bytes32 role,
|
|
104
|
-
address account
|
|
105
|
-
) external view override {
|
|
106
|
-
_checkRole(getComponentRole(component, role), account);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function grantComponentRole(
|
|
110
|
-
address component,
|
|
111
|
-
bytes32 role,
|
|
112
|
-
address account
|
|
113
|
-
) external onlyRole(getRoleAdmin(getComponentRole(component, role))) {
|
|
114
|
-
_grantRole(getComponentRole(component, role), account);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function checkRole(bytes32 role, address account) external view override {
|
|
118
|
-
_checkRole(role, account);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function checkRole2(
|
|
122
|
-
bytes32 role1,
|
|
123
|
-
bytes32 role2,
|
|
124
|
-
address account
|
|
125
|
-
) external view override {
|
|
126
|
-
if (!hasRole(role1, account)) _checkRole(role2, account);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function setTreasury(address treasury_) external onlyRole(LEVEL1_ROLE) {
|
|
130
|
-
_treasury = treasury_;
|
|
131
|
-
emit ComponentChanged(GovernanceActions.setTreasury, _treasury);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function treasury() external view override returns (address) {
|
|
135
|
-
return _treasury;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function setLPWhitelist(ILPWhitelist lpWhitelist_)
|
|
139
|
-
external
|
|
140
|
-
onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
|
|
141
|
-
{
|
|
142
|
-
require(
|
|
143
|
-
address(lpWhitelist_) == address(0) ||
|
|
144
|
-
IPolicyPoolComponent(address(lpWhitelist_)).policyPool() == _policyPool,
|
|
145
|
-
"Component not linked to this PolicyPool"
|
|
146
|
-
);
|
|
147
|
-
_lpWhitelist = lpWhitelist_;
|
|
148
|
-
emit ComponentChanged(GovernanceActions.setLPWhitelist, address(_lpWhitelist));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function lpWhitelist() external view override returns (ILPWhitelist) {
|
|
152
|
-
return _lpWhitelist;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function addRiskModule(IRiskModule riskModule) external onlyRole(LEVEL1_ROLE) {
|
|
156
|
-
require(
|
|
157
|
-
_riskModules[riskModule] == RiskModuleStatus.inactive,
|
|
158
|
-
"Risk Module already in the pool"
|
|
159
|
-
);
|
|
160
|
-
require(address(riskModule) != address(0), "riskModule can't be zero");
|
|
161
|
-
require(
|
|
162
|
-
IPolicyPoolComponent(address(riskModule)).policyPool() == _policyPool,
|
|
163
|
-
"RiskModule not linked to this pool"
|
|
164
|
-
);
|
|
165
|
-
_riskModules[riskModule] = RiskModuleStatus.active;
|
|
166
|
-
emit RiskModuleStatusChanged(riskModule, RiskModuleStatus.active);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function removeRiskModule(IRiskModule riskModule) external onlyRole(LEVEL2_ROLE) {
|
|
170
|
-
require(_riskModules[riskModule] != RiskModuleStatus.inactive, "Risk Module not found");
|
|
171
|
-
require(riskModule.activeExposure() == 0, "Can't remove a module with active policies");
|
|
172
|
-
delete _riskModules[riskModule];
|
|
173
|
-
emit RiskModuleStatusChanged(riskModule, RiskModuleStatus.inactive);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function changeRiskModuleStatus(IRiskModule riskModule, RiskModuleStatus newStatus)
|
|
177
|
-
external
|
|
178
|
-
onlyRole2(GUARDIAN_ROLE, LEVEL1_ROLE)
|
|
179
|
-
{
|
|
180
|
-
require(_riskModules[riskModule] != RiskModuleStatus.inactive, "Risk Module not found");
|
|
181
|
-
require(
|
|
182
|
-
newStatus != RiskModuleStatus.suspended || hasRole(GUARDIAN_ROLE, msg.sender),
|
|
183
|
-
"Only GUARDIAN can suspend modules"
|
|
184
|
-
);
|
|
185
|
-
// To activate LEVEL1 required or LEVEL2 if <5% of total liquidity
|
|
186
|
-
require(hasRole(LEVEL1_ROLE, msg.sender), "Only LEVEL1 can activate modules");
|
|
187
|
-
// Anyone (LEVEL1, GUARDIAN) can deprecate
|
|
188
|
-
_riskModules[riskModule] = newStatus;
|
|
189
|
-
emit RiskModuleStatusChanged(riskModule, newStatus);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function checkAcceptsNewPolicy(IRiskModule riskModule) external view override {
|
|
193
|
-
RiskModuleStatus rmStatus = _riskModules[riskModule];
|
|
194
|
-
require(rmStatus == RiskModuleStatus.active, "RM module not found or not active");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function checkAcceptsResolvePolicy(IRiskModule riskModule) external view override {
|
|
198
|
-
RiskModuleStatus rmStatus = _riskModules[riskModule];
|
|
199
|
-
require(
|
|
200
|
-
rmStatus == RiskModuleStatus.active || rmStatus == RiskModuleStatus.deprecated,
|
|
201
|
-
"Module must be active or deprecated to process resolutions"
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
}
|
package/contracts/WadRayMath.sol
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.0;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @title WadRayMath library
|
|
6
|
-
* @author Aave / Ensuro
|
|
7
|
-
* @dev Provides mul and div function for wads (decimal numbers with 18 digits precision) and rays
|
|
8
|
-
* (decimals with 27 digits)
|
|
9
|
-
* @custom:security-contact security@ensuro.co
|
|
10
|
-
**/
|
|
11
|
-
|
|
12
|
-
library WadRayMath {
|
|
13
|
-
uint256 internal constant WAD = 1e18;
|
|
14
|
-
uint256 internal constant HALF_WAD = WAD / 2;
|
|
15
|
-
|
|
16
|
-
uint256 internal constant RAY = 1e27;
|
|
17
|
-
uint256 internal constant HALF_RAY = RAY / 2;
|
|
18
|
-
|
|
19
|
-
uint256 internal constant WAD_RAY_RATIO = 1e9;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @return One ray, 1e27
|
|
23
|
-
**/
|
|
24
|
-
function ray() internal pure returns (uint256) {
|
|
25
|
-
return RAY;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @return One wad, 1e18
|
|
30
|
-
**/
|
|
31
|
-
|
|
32
|
-
function wad() internal pure returns (uint256) {
|
|
33
|
-
return WAD;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @return Half ray, 1e27/2
|
|
38
|
-
**/
|
|
39
|
-
function halfRay() internal pure returns (uint256) {
|
|
40
|
-
return HALF_RAY;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @return Half ray, 1e18/2
|
|
45
|
-
**/
|
|
46
|
-
function halfWad() internal pure returns (uint256) {
|
|
47
|
-
return HALF_WAD;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @dev Multiplies two wad, rounding half up to the nearest wad
|
|
52
|
-
* @param a Wad
|
|
53
|
-
* @param b Wad
|
|
54
|
-
* @return The result of a*b, in wad
|
|
55
|
-
**/
|
|
56
|
-
function wadMul(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
57
|
-
if (a == 0 || b == 0) {
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
require(a <= (type(uint256).max - HALF_WAD) / b, "wadMul: Math Multiplication Overflow");
|
|
62
|
-
|
|
63
|
-
return (a * b + HALF_WAD) / WAD;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @dev Divides two wad, rounding half up to the nearest wad
|
|
68
|
-
* @param a Wad
|
|
69
|
-
* @param b Wad
|
|
70
|
-
* @return The result of a/b, in wad
|
|
71
|
-
**/
|
|
72
|
-
function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
73
|
-
require(b != 0, "wadDiv: Division by zero");
|
|
74
|
-
uint256 halfB = b / 2;
|
|
75
|
-
|
|
76
|
-
require(a <= (type(uint256).max - halfB) / WAD, "wadDiv: Math Multiplication Overflow");
|
|
77
|
-
|
|
78
|
-
return (a * WAD + halfB) / b;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @dev Multiplies two ray, rounding half up to the nearest ray
|
|
83
|
-
* @param a Ray
|
|
84
|
-
* @param b Ray
|
|
85
|
-
* @return The result of a*b, in ray
|
|
86
|
-
**/
|
|
87
|
-
function rayMul(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
88
|
-
if (a == 0 || b == 0) {
|
|
89
|
-
return 0;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
require(a <= (type(uint256).max - HALF_RAY) / b, "rayMul: Math Multiplication Overflow");
|
|
93
|
-
|
|
94
|
-
return (a * b + HALF_RAY) / RAY;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @dev Divides two ray, rounding half up to the nearest ray
|
|
99
|
-
* @param a Ray
|
|
100
|
-
* @param b Ray
|
|
101
|
-
* @return The result of a/b, in ray
|
|
102
|
-
**/
|
|
103
|
-
function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
104
|
-
require(b != 0, "rayDiv: Division by zero");
|
|
105
|
-
uint256 halfB = b / 2;
|
|
106
|
-
|
|
107
|
-
require(a <= (type(uint256).max - halfB) / RAY, "rayDiv: Math Multiplication Overflow");
|
|
108
|
-
|
|
109
|
-
return (a * RAY + halfB) / b;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @dev Casts ray down to wad
|
|
114
|
-
* @param a Ray
|
|
115
|
-
* @return a casted to wad, rounded half up to the nearest wad
|
|
116
|
-
**/
|
|
117
|
-
function rayToWad(uint256 a) internal pure returns (uint256) {
|
|
118
|
-
uint256 halfRatio = WAD_RAY_RATIO / 2;
|
|
119
|
-
uint256 result = halfRatio + a;
|
|
120
|
-
require(result >= halfRatio, "rayToWad: Math Addition Overflow");
|
|
121
|
-
|
|
122
|
-
return result / WAD_RAY_RATIO;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @dev Converts wad up to ray
|
|
127
|
-
* @param a Wad
|
|
128
|
-
* @return a converted in ray
|
|
129
|
-
**/
|
|
130
|
-
function wadToRay(uint256 a) internal pure returns (uint256) {
|
|
131
|
-
uint256 result = a * WAD_RAY_RATIO;
|
|
132
|
-
require(result / WAD_RAY_RATIO == a, "wadToRad: Math Multiplication Overflow");
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
}
|