@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,301 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.0;
|
|
3
|
-
|
|
4
|
-
import {WadRayMath} from "./WadRayMath.sol";
|
|
5
|
-
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
6
|
-
import {IPolicyPool} from "../interfaces/IPolicyPool.sol";
|
|
7
|
-
import {PolicyPoolComponent} from "./PolicyPoolComponent.sol";
|
|
8
|
-
import {IAssetManager} from "../interfaces/IAssetManager.sol";
|
|
9
|
-
import {IEToken} from "../interfaces/IEToken.sol";
|
|
10
|
-
import {IPolicyPoolConfig} from "../interfaces/IPolicyPoolConfig.sol";
|
|
11
|
-
import {Policy} from "./Policy.sol";
|
|
12
|
-
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @title Ensuro Asset Manager base contract
|
|
16
|
-
* @dev Base class for asset managers that reinvest the assets of the protocol to get additional returns.
|
|
17
|
-
* The specific asset management strategy needs to be implemented by child contracts.
|
|
18
|
-
* Settings liquidityMin, liquidityMiddle, liquidityMax are the thresholds used to define how much liquidity
|
|
19
|
-
* to keep in the PolicyPool and when to invest/deinvest. Every invest/deinvest operation tries to leave the
|
|
20
|
-
* PolicyPool at liquidityMiddle.
|
|
21
|
-
* @custom:security-contact security@ensuro.co
|
|
22
|
-
* @author Ensuro
|
|
23
|
-
*/
|
|
24
|
-
abstract contract BaseAssetManager is IAssetManager, PolicyPoolComponent {
|
|
25
|
-
using WadRayMath for uint256;
|
|
26
|
-
|
|
27
|
-
uint256 internal _liquidityMin;
|
|
28
|
-
uint256 internal _liquidityMiddle;
|
|
29
|
-
uint256 internal _liquidityMax;
|
|
30
|
-
|
|
31
|
-
uint256 internal _lastInvestmentValue;
|
|
32
|
-
|
|
33
|
-
event MoneyInvested(uint256 amount);
|
|
34
|
-
event MoneyDeinvested(uint256 amount);
|
|
35
|
-
event EarningsDistributed(bool positive, uint256 amount);
|
|
36
|
-
|
|
37
|
-
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
38
|
-
// solhint-disable-next-line no-empty-blocks
|
|
39
|
-
constructor(IPolicyPool policyPool_) PolicyPoolComponent(policyPool_) {}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @dev Initializes the asset manager
|
|
43
|
-
* @param liquidityMin_ Minimal liquidity to keep in pool's wallet
|
|
44
|
-
* @param liquidityMiddle_ Target liquidity when doing rebalance
|
|
45
|
-
* @param liquidityMax_ Maximum liquidity to keep in pool's wallet
|
|
46
|
-
*/
|
|
47
|
-
// solhint-disable-next-line func-name-mixedcase
|
|
48
|
-
function __BaseAssetManager_init(
|
|
49
|
-
uint256 liquidityMin_,
|
|
50
|
-
uint256 liquidityMiddle_,
|
|
51
|
-
uint256 liquidityMax_
|
|
52
|
-
) internal initializer {
|
|
53
|
-
__PolicyPoolComponent_init();
|
|
54
|
-
__BaseAssetManager_init_unchained(liquidityMin_, liquidityMiddle_, liquidityMax_);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// solhint-disable-next-line func-name-mixedcase
|
|
58
|
-
function __BaseAssetManager_init_unchained(
|
|
59
|
-
uint256 liquidityMin_,
|
|
60
|
-
uint256 liquidityMiddle_,
|
|
61
|
-
uint256 liquidityMax_
|
|
62
|
-
) internal initializer {
|
|
63
|
-
/*
|
|
64
|
-
_lastInvestmentValue = 0;
|
|
65
|
-
*/
|
|
66
|
-
_liquidityMin = liquidityMin_;
|
|
67
|
-
_liquidityMiddle = liquidityMiddle_;
|
|
68
|
-
_liquidityMax = liquidityMax_;
|
|
69
|
-
_validateParameters();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function _validateParameters() internal view override {
|
|
73
|
-
require(
|
|
74
|
-
_liquidityMin <= _liquidityMiddle && _liquidityMiddle <= _liquidityMax,
|
|
75
|
-
"Validation: Liquidity limits are invalid"
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @dev Returns the total amount that is available to invest by the asset manager
|
|
81
|
-
*/
|
|
82
|
-
function totalInvestable() public view returns (uint256) {
|
|
83
|
-
uint256 poolInvestable = _policyPool.getInvestable();
|
|
84
|
-
uint256 etksInvestable = 0;
|
|
85
|
-
for (uint256 i = 0; i < _policyPool.getETokenCount(); i++) {
|
|
86
|
-
IEToken etk = _policyPool.getETokenAt(i);
|
|
87
|
-
etksInvestable += etk.getInvestable();
|
|
88
|
-
}
|
|
89
|
-
return poolInvestable + etksInvestable;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @dev Calculates asset earnings and distributes them updating accounting in PolicyPool and eTokens
|
|
94
|
-
*/
|
|
95
|
-
function distributeEarnings() public virtual whenNotPaused {
|
|
96
|
-
// TODO Check: Anyone can call this funcion. This could be a potencial surface of flash loan attack?
|
|
97
|
-
_distributeEarnings(getInvestmentValue());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function _distributeEarnings(uint256 investmentValue) internal virtual whenNotPaused {
|
|
101
|
-
bool positive;
|
|
102
|
-
uint256 earnings;
|
|
103
|
-
if (investmentValue > _lastInvestmentValue) {
|
|
104
|
-
earnings = investmentValue - _lastInvestmentValue;
|
|
105
|
-
positive = true;
|
|
106
|
-
} else if (investmentValue < _lastInvestmentValue) {
|
|
107
|
-
earnings = _lastInvestmentValue - investmentValue;
|
|
108
|
-
positive = false;
|
|
109
|
-
} else {
|
|
110
|
-
return; // No earnings
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
uint256 totalInv = totalInvestable();
|
|
114
|
-
|
|
115
|
-
uint256 remaining = earnings;
|
|
116
|
-
for (uint256 i = 0; i < _policyPool.getETokenCount(); i++) {
|
|
117
|
-
IEToken etk = _policyPool.getETokenAt(i);
|
|
118
|
-
uint256 aux = earnings.wadMul(etk.getInvestable().wadDiv(totalInv));
|
|
119
|
-
if (aux > 0) {
|
|
120
|
-
etk.assetEarnings(aux, positive);
|
|
121
|
-
remaining -= aux;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (remaining > 0) _policyPool.assetEarnings(remaining, positive);
|
|
126
|
-
|
|
127
|
-
_lastInvestmentValue = investmentValue;
|
|
128
|
-
emit EarningsDistributed(positive, earnings);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @dev Returns the current value of the investment portfolio
|
|
133
|
-
*/
|
|
134
|
-
function getInvestmentValue() public view virtual returns (uint256);
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @dev Rebalances cash between PolicyPool wallet and
|
|
138
|
-
*/
|
|
139
|
-
function rebalance() public virtual whenNotPaused {
|
|
140
|
-
// TODO Check: Anyone can call this funcion. This could be a potencial surface of flash loan attack?
|
|
141
|
-
uint256 poolCash = currency().balanceOf(address(_policyPool));
|
|
142
|
-
if (poolCash > _liquidityMax) {
|
|
143
|
-
_invest(poolCash - _liquidityMiddle);
|
|
144
|
-
} else if (poolCash < _liquidityMin) {
|
|
145
|
-
uint256 deinvestAmount = Math.min(getInvestmentValue(), _liquidityMiddle - poolCash);
|
|
146
|
-
if (deinvestAmount > 0) {
|
|
147
|
-
_deinvest(deinvestAmount);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @dev Function to be called automatically by a crontask - Distributes and rebalances
|
|
154
|
-
*/
|
|
155
|
-
function checkpoint() external {
|
|
156
|
-
distributeEarnings();
|
|
157
|
-
rebalance();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @dev This is called from PolicyPool when doesn't have enought money for payment.
|
|
162
|
-
* After the call, there should be enought money in PolicyPool.currency().balanceOf(this) to
|
|
163
|
-
* do the payment
|
|
164
|
-
* @param paymentAmount The amount of the payment
|
|
165
|
-
*/
|
|
166
|
-
function refillWallet(uint256 paymentAmount) external override onlyPolicyPool {
|
|
167
|
-
uint256 poolCash = currency().balanceOf(address(_policyPool));
|
|
168
|
-
require(poolCash < paymentAmount, "No need to refill the wallet for this payment");
|
|
169
|
-
uint256 investmentValue = getInvestmentValue();
|
|
170
|
-
// try to leave the pool balance at liquidity_middle after the payment
|
|
171
|
-
uint256 deinvest = paymentAmount + _liquidityMiddle - poolCash;
|
|
172
|
-
if (deinvest > investmentValue) deinvest = investmentValue;
|
|
173
|
-
_deinvest(deinvest);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function _invest(uint256 amount) internal virtual {
|
|
177
|
-
_lastInvestmentValue += amount;
|
|
178
|
-
emit MoneyInvested(amount);
|
|
179
|
-
// must be reimplemented do the actual cash movement
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function _deinvest(uint256 amount) internal virtual {
|
|
183
|
-
_lastInvestmentValue -= Math.min(_lastInvestmentValue, amount);
|
|
184
|
-
emit MoneyDeinvested(amount);
|
|
185
|
-
// must be reimplemented do the actual cash movement
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @dev Deinvest all the assets and return the cash back to the PolicyPool.
|
|
190
|
-
* Called from PolicyPool when new asset manager is assigned
|
|
191
|
-
*/
|
|
192
|
-
function deinvestAll() external virtual override onlyPolicyPool {
|
|
193
|
-
uint256 poolBalanceBefore = currency().balanceOf(address(_policyPool));
|
|
194
|
-
_liquidateAll();
|
|
195
|
-
uint256 poolBalanceAfter = currency().balanceOf(address(_policyPool));
|
|
196
|
-
_distributeEarnings(poolBalanceAfter - poolBalanceBefore);
|
|
197
|
-
_lastInvestmentValue = 0;
|
|
198
|
-
emit MoneyDeinvested(poolBalanceAfter - poolBalanceBefore);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function _liquidateAll() internal virtual;
|
|
202
|
-
|
|
203
|
-
function liquidityMin() external view returns (uint256) {
|
|
204
|
-
return _liquidityMin;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function liquidityMiddle() external view returns (uint256) {
|
|
208
|
-
return _liquidityMiddle;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function liquidityMax() external view returns (uint256) {
|
|
212
|
-
return _liquidityMax;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function setLiquidityMin(uint256 newValue) external onlyPoolRole2(LEVEL2_ROLE, LEVEL3_ROLE) {
|
|
216
|
-
bool tweak = !hasPoolRole(LEVEL2_ROLE);
|
|
217
|
-
require(
|
|
218
|
-
!tweak || _isTweakRay(_liquidityMin, newValue, 3e26),
|
|
219
|
-
"Tweak exceeded: liquidityMin tweaks only up to 30%"
|
|
220
|
-
);
|
|
221
|
-
_liquidityMin = newValue;
|
|
222
|
-
_parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMin, newValue, tweak);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function setLiquidityMiddle(uint256 newValue) external onlyPoolRole2(LEVEL2_ROLE, LEVEL3_ROLE) {
|
|
226
|
-
bool tweak = !hasPoolRole(LEVEL2_ROLE);
|
|
227
|
-
require(
|
|
228
|
-
!tweak || _isTweakRay(_liquidityMiddle, newValue, 3e26),
|
|
229
|
-
"Tweak exceeded: liquidityMiddle tweaks only up to 30%"
|
|
230
|
-
);
|
|
231
|
-
_liquidityMiddle = newValue;
|
|
232
|
-
_parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMiddle, newValue, tweak);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function setLiquidityMax(uint256 newValue) external onlyPoolRole2(LEVEL2_ROLE, LEVEL3_ROLE) {
|
|
236
|
-
bool tweak = !hasPoolRole(LEVEL2_ROLE);
|
|
237
|
-
require(
|
|
238
|
-
!tweak || _isTweakRay(_liquidityMax, newValue, 3e26),
|
|
239
|
-
"Tweak exceeded: liquidityMax tweaks only up to 30%"
|
|
240
|
-
);
|
|
241
|
-
_liquidityMax = newValue;
|
|
242
|
-
_parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMax, newValue, tweak);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function setLiquidityMultiple(
|
|
246
|
-
uint256 min,
|
|
247
|
-
uint256 middle,
|
|
248
|
-
uint256 max
|
|
249
|
-
) external onlyPoolRole2(LEVEL2_ROLE, LEVEL3_ROLE) {
|
|
250
|
-
bool setMin = min != type(uint256).max;
|
|
251
|
-
bool setMiddle = middle != type(uint256).max;
|
|
252
|
-
bool setMax = max != type(uint256).max;
|
|
253
|
-
bool tweak = !hasPoolRole(LEVEL2_ROLE);
|
|
254
|
-
// First set all - Then call _parameterChanged
|
|
255
|
-
if (setMin) {
|
|
256
|
-
require(
|
|
257
|
-
!tweak || _isTweakRay(_liquidityMin, min, 3e26),
|
|
258
|
-
"Tweak exceeded: liquidityMin tweaks only up to 30%"
|
|
259
|
-
);
|
|
260
|
-
_liquidityMin = min;
|
|
261
|
-
}
|
|
262
|
-
if (setMiddle) {
|
|
263
|
-
require(
|
|
264
|
-
!tweak || _isTweakRay(_liquidityMiddle, middle, 3e26),
|
|
265
|
-
"Tweak exceeded: liquidityMiddle tweaks only up to 30%"
|
|
266
|
-
);
|
|
267
|
-
_liquidityMiddle = middle;
|
|
268
|
-
}
|
|
269
|
-
if (setMax) {
|
|
270
|
-
require(
|
|
271
|
-
!tweak || _isTweakRay(_liquidityMax, max, 3e26),
|
|
272
|
-
"Tweak exceeded: liquidityMax tweaks only up to 30%"
|
|
273
|
-
);
|
|
274
|
-
_liquidityMax = max;
|
|
275
|
-
}
|
|
276
|
-
if (setMin) _parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMin, min, tweak);
|
|
277
|
-
if (setMiddle)
|
|
278
|
-
_parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMiddle, middle, tweak);
|
|
279
|
-
if (setMax) _parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMax, max, tweak);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function _setLiquidityMiddle(uint256 newValue) internal {
|
|
283
|
-
bool tweak = !hasPoolRole(LEVEL2_ROLE);
|
|
284
|
-
require(
|
|
285
|
-
!tweak || _isTweakRay(_liquidityMiddle, newValue, 3e26),
|
|
286
|
-
"Tweak exceeded: liquidityMiddle tweaks only up to 30%"
|
|
287
|
-
);
|
|
288
|
-
_liquidityMiddle = newValue;
|
|
289
|
-
_parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMiddle, newValue, tweak);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function _setLiquidityMax(uint256 newValue) internal {
|
|
293
|
-
bool tweak = !hasPoolRole(LEVEL2_ROLE);
|
|
294
|
-
require(
|
|
295
|
-
!tweak || _isTweakRay(_liquidityMax, newValue, 3e26),
|
|
296
|
-
"Tweak exceeded: liquidityMax tweaks only up to 30%"
|
|
297
|
-
);
|
|
298
|
-
_liquidityMax = newValue;
|
|
299
|
-
_parameterChanged(IPolicyPoolConfig.GovernanceActions.setLiquidityMax, newValue, tweak);
|
|
300
|
-
}
|
|
301
|
-
}
|
package/contracts/DataTypes.sol
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
|
|
3
|
-
pragma solidity ^0.8.0;
|
|
4
|
-
|
|
5
|
-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
6
|
-
import {IEToken} from "../interfaces/IEToken.sol";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @title DataTypes library
|
|
10
|
-
* @dev Library with two EnumerableSet:
|
|
11
|
-
* - ETokenToWadMap: enumerable mapping(EToken ==> amount)
|
|
12
|
-
* - ETokenStatusMap: enumerable mapping(EToken ==> ETokenStatus)
|
|
13
|
-
* @custom:security-contact security@ensuro.co
|
|
14
|
-
* @author Ensuro
|
|
15
|
-
*/
|
|
16
|
-
library DataTypes {
|
|
17
|
-
using EnumerableSet for EnumerableSet.AddressSet;
|
|
18
|
-
|
|
19
|
-
enum ETokenStatus {
|
|
20
|
-
inactive, // doesn't exists - All operations rejected
|
|
21
|
-
active, // deposit / withdraw / lockScr / unlockScr OK
|
|
22
|
-
deprecated, // withdraw OK, unlockScr OK, deposit rejected, no new policies
|
|
23
|
-
suspended // all operations temporarily rejected
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Copied from OpenZeppelin's EnumerableMap but with address as keys
|
|
27
|
-
// and reimplemented with interfaces as keys
|
|
28
|
-
// To implement this library for multiple types with as little code
|
|
29
|
-
// repetition as possible, we write it in terms of a generic Map type with
|
|
30
|
-
// address keys and uint256 values.
|
|
31
|
-
// The Map implementation uses private functions, and user-facing
|
|
32
|
-
// implementations (such as Uint256ToAddressMap) are just wrappers around
|
|
33
|
-
// the underlying Map.
|
|
34
|
-
|
|
35
|
-
struct Map {
|
|
36
|
-
// Storage of keys
|
|
37
|
-
EnumerableSet.AddressSet _keys;
|
|
38
|
-
mapping(address => uint256) _values;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @dev Adds a key-value pair to a map, or updates the value for an existing
|
|
43
|
-
* key. O(1).
|
|
44
|
-
*
|
|
45
|
-
* Returns true if the key was added to the map, that is if it was not
|
|
46
|
-
* already present.
|
|
47
|
-
*/
|
|
48
|
-
function _set(
|
|
49
|
-
Map storage map,
|
|
50
|
-
address key,
|
|
51
|
-
uint256 value
|
|
52
|
-
) private returns (bool) {
|
|
53
|
-
map._values[key] = value;
|
|
54
|
-
return map._keys.add(key);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @dev Removes a key-value pair from a map. O(1).
|
|
59
|
-
*
|
|
60
|
-
* Returns true if the key was removed from the map, that is if it was present.
|
|
61
|
-
*/
|
|
62
|
-
function _remove(Map storage map, address key) private returns (bool) {
|
|
63
|
-
delete map._values[key];
|
|
64
|
-
return map._keys.remove(key);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @dev Returns true if the key is in the map. O(1).
|
|
69
|
-
*/
|
|
70
|
-
function _contains(Map storage map, address key) private view returns (bool) {
|
|
71
|
-
return map._keys.contains(key);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @dev Returns the number of key-value pairs in the map. O(1).
|
|
76
|
-
*/
|
|
77
|
-
function _length(Map storage map) private view returns (uint256) {
|
|
78
|
-
return map._keys.length();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
|
|
83
|
-
*
|
|
84
|
-
* Note that there are no guarantees on the ordering of entries inside the
|
|
85
|
-
* array, and it may change when more entries are added or removed.
|
|
86
|
-
*
|
|
87
|
-
* Requirements:
|
|
88
|
-
*
|
|
89
|
-
* - `index` must be strictly less than {length}.
|
|
90
|
-
*/
|
|
91
|
-
function _at(Map storage map, uint256 index) private view returns (address, uint256) {
|
|
92
|
-
address key = map._keys.at(index);
|
|
93
|
-
return (key, map._values[key]);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @dev Tries to returns the value associated with `key`. O(1).
|
|
98
|
-
* Does not revert if `key` is not in the map.
|
|
99
|
-
*/
|
|
100
|
-
function _tryGet(Map storage map, address key) private view returns (bool, uint256) {
|
|
101
|
-
uint256 value = map._values[key];
|
|
102
|
-
if (value == 0) {
|
|
103
|
-
return (_contains(map, key), 0);
|
|
104
|
-
} else {
|
|
105
|
-
return (true, value);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @dev Returns the value associated with `key`. O(1).
|
|
111
|
-
*
|
|
112
|
-
* Requirements:
|
|
113
|
-
*
|
|
114
|
-
* - `key` must be in the map.
|
|
115
|
-
*/
|
|
116
|
-
function _get(Map storage map, address key) private view returns (uint256) {
|
|
117
|
-
uint256 value = map._values[key];
|
|
118
|
-
require(value != 0 || _contains(map, key), "EnumerableMap: nonexistent key");
|
|
119
|
-
return value;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// ETokenToWadMap
|
|
123
|
-
struct ETokenToWadMap {
|
|
124
|
-
Map _inner;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @dev Adds a key-value pair to a map, or updates the value for an existing
|
|
129
|
-
* key. O(1).
|
|
130
|
-
*
|
|
131
|
-
* Returns true if the key was added to the map, that is if it was not
|
|
132
|
-
* already present.
|
|
133
|
-
*/
|
|
134
|
-
function set(
|
|
135
|
-
ETokenToWadMap storage map,
|
|
136
|
-
IEToken key,
|
|
137
|
-
uint256 value
|
|
138
|
-
) internal returns (bool) {
|
|
139
|
-
return _set(map._inner, address(key), value);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @dev Removes a value from a set. O(1).
|
|
144
|
-
*
|
|
145
|
-
* Returns true if the key was removed from the map, that is if it was present.
|
|
146
|
-
*/
|
|
147
|
-
function remove(ETokenToWadMap storage map, IEToken key) internal returns (bool) {
|
|
148
|
-
return _remove(map._inner, address(key));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @dev Returns true if the key is in the map. O(1).
|
|
153
|
-
*/
|
|
154
|
-
function contains(ETokenToWadMap storage map, IEToken key) internal view returns (bool) {
|
|
155
|
-
return _contains(map._inner, address(key));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @dev Returns the number of elements in the map. O(1).
|
|
160
|
-
*/
|
|
161
|
-
function length(ETokenToWadMap storage map) internal view returns (uint256) {
|
|
162
|
-
return _length(map._inner);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @dev Returns the element stored at position `index` in the set. O(1).
|
|
167
|
-
* Note that there are no guarantees on the ordering of values inside the
|
|
168
|
-
* array, and it may change when more values are added or removed.
|
|
169
|
-
*
|
|
170
|
-
* Requirements:
|
|
171
|
-
*
|
|
172
|
-
* - `index` must be strictly less than {length}.
|
|
173
|
-
*/
|
|
174
|
-
function at(ETokenToWadMap storage map, uint256 index) internal view returns (IEToken, uint256) {
|
|
175
|
-
(address key, uint256 value) = _at(map._inner, index);
|
|
176
|
-
return (IEToken(key), value);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* @dev Tries to returns the value associated with `key`. O(1).
|
|
181
|
-
* Does not revert if `key` is not in the map.
|
|
182
|
-
*
|
|
183
|
-
* _Available since v3.4._
|
|
184
|
-
*/
|
|
185
|
-
function tryGet(ETokenToWadMap storage map, IEToken key) internal view returns (bool, uint256) {
|
|
186
|
-
(bool success, uint256 value) = _tryGet(map._inner, address(key));
|
|
187
|
-
return (success, value);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @dev Returns the value associated with `key`. O(1).
|
|
192
|
-
*
|
|
193
|
-
* Requirements:
|
|
194
|
-
*
|
|
195
|
-
* - `key` must be in the map.
|
|
196
|
-
*/
|
|
197
|
-
function get(ETokenToWadMap storage map, IEToken key) internal view returns (uint256) {
|
|
198
|
-
return uint256(_get(map._inner, address(key)));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// ETokenStatusMap
|
|
202
|
-
struct ETokenStatusMap {
|
|
203
|
-
Map _inner;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @dev Adds a key-value pair to a map, or updates the value for an existing
|
|
208
|
-
* key. O(1).
|
|
209
|
-
*
|
|
210
|
-
* Returns true if the key was added to the map, that is if it was not
|
|
211
|
-
* already present.
|
|
212
|
-
*/
|
|
213
|
-
function set(
|
|
214
|
-
ETokenStatusMap storage map,
|
|
215
|
-
IEToken key,
|
|
216
|
-
ETokenStatus value
|
|
217
|
-
) internal returns (bool) {
|
|
218
|
-
return _set(map._inner, address(key), uint256(value));
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @dev Removes a value from a set. O(1).
|
|
223
|
-
*
|
|
224
|
-
* Returns true if the key was removed from the map, that is if it was present.
|
|
225
|
-
*/
|
|
226
|
-
function remove(ETokenStatusMap storage map, IEToken key) internal returns (bool) {
|
|
227
|
-
return _remove(map._inner, address(key));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* @dev Returns true if the key is in the map. O(1).
|
|
232
|
-
*/
|
|
233
|
-
function contains(ETokenStatusMap storage map, IEToken key) internal view returns (bool) {
|
|
234
|
-
return _contains(map._inner, address(key));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @dev Returns the number of elements in the map. O(1).
|
|
239
|
-
*/
|
|
240
|
-
function length(ETokenStatusMap storage map) internal view returns (uint256) {
|
|
241
|
-
return _length(map._inner);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @dev Returns the element stored at position `index` in the set. O(1).
|
|
246
|
-
* Note that there are no guarantees on the ordering of values inside the
|
|
247
|
-
* array, and it may change when more values are added or removed.
|
|
248
|
-
*
|
|
249
|
-
* Requirements:
|
|
250
|
-
*
|
|
251
|
-
* - `index` must be strictly less than {length}.
|
|
252
|
-
*/
|
|
253
|
-
function at(ETokenStatusMap storage map, uint256 index)
|
|
254
|
-
internal
|
|
255
|
-
view
|
|
256
|
-
returns (IEToken, ETokenStatus)
|
|
257
|
-
{
|
|
258
|
-
(address key, uint256 value) = _at(map._inner, index);
|
|
259
|
-
return (IEToken(key), ETokenStatus(value));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* @dev Tries to returns the value associated with `key`. O(1).
|
|
264
|
-
* Does not revert if `key` is not in the map.
|
|
265
|
-
*
|
|
266
|
-
* _Available since v3.4._
|
|
267
|
-
*/
|
|
268
|
-
function tryGet(ETokenStatusMap storage map, IEToken key)
|
|
269
|
-
internal
|
|
270
|
-
view
|
|
271
|
-
returns (bool, ETokenStatus)
|
|
272
|
-
{
|
|
273
|
-
(bool success, uint256 value) = _tryGet(map._inner, address(key));
|
|
274
|
-
return (success, ETokenStatus(value));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* @dev Returns the value associated with `key`. O(1).
|
|
279
|
-
*
|
|
280
|
-
* Requirements:
|
|
281
|
-
*
|
|
282
|
-
* - `key` must be in the map.
|
|
283
|
-
*/
|
|
284
|
-
function get(ETokenStatusMap storage map, IEToken key) internal view returns (ETokenStatus) {
|
|
285
|
-
return ETokenStatus(_get(map._inner, address(key)));
|
|
286
|
-
}
|
|
287
|
-
}
|