@shift-defi/strategies 0.1.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 +55 -0
- package/contracts/curve-gauge/CurveGauge.sol +296 -0
- package/contracts/dependencies/aave-v3/DataTypes.sol +333 -0
- package/contracts/dependencies/aave-v3/IAtoken.sol +141 -0
- package/contracts/dependencies/aave-v3/IInitializableAToken.sol +51 -0
- package/contracts/dependencies/aave-v3/IPool.sol +822 -0
- package/contracts/dependencies/aave-v3/IPoolAddressesProvider.sol +223 -0
- package/contracts/dependencies/aave-v3/IScaledBalanceToken.sol +66 -0
- package/contracts/dependencies/angle/IAngleMerkleDistributor.sol +11 -0
- package/contracts/dependencies/compound-v3/ICompoundV3.sol +17 -0
- package/contracts/dependencies/curve/ICurveStableSwapNG.sol +16 -0
- package/contracts/dependencies/curve/ILiquidityGaugeV6.sol +16 -0
- package/contracts/dependencies/fluid/IFluidLendingResolver.sol +6 -0
- package/contracts/dependencies/fluid/IFluidMerkleDistributor.sol +26 -0
- package/contracts/dependencies/fluid/IFluidToken.sol +14 -0
- package/contracts/fluid/FluidSupply.sol +255 -0
- package/contracts/interfaces/ICompoundV3Supply.sol +32 -0
- package/contracts/interfaces/ICurveGauge.sol +35 -0
- package/contracts/interfaces/IFluidSupply.sol +26 -0
- package/contracts/interfaces/IMorphoVault.sol +63 -0
- package/contracts/morpho/MorphoVault.sol +340 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# ShiftDeFi Onchain Template
|
|
2
|
+
|
|
3
|
+
This repository contains basic setup for ShiftDeFi onhcain projects.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Build
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
$ forge build
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Test
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
$ forge test
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Format
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
$ forge fmt
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Gas Snapshots
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
$ forge snapshot
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Anvil
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
$ anvil
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Deploy
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Cast
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
$ cast <subcommand>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Help
|
|
50
|
+
|
|
51
|
+
```shell
|
|
52
|
+
$ forge --help
|
|
53
|
+
$ anvil --help
|
|
54
|
+
$ cast --help
|
|
55
|
+
```
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.28;
|
|
3
|
+
|
|
4
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
|
|
6
|
+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
7
|
+
|
|
8
|
+
import {StrategyTemplate} from "@shift-defi/core/StrategyTemplate.sol";
|
|
9
|
+
import {IStrategyTemplate} from "@shift-defi/core/interfaces/IStrategyTemplate.sol";
|
|
10
|
+
import {Errors} from "@shift-defi/core/libraries/Errors.sol";
|
|
11
|
+
|
|
12
|
+
import {ICurveStableSwapNG} from "contracts/dependencies/curve/ICurveStableSwapNG.sol";
|
|
13
|
+
import {ILiquidityGaugeV6} from "contracts/dependencies/curve/ILiquidityGaugeV6.sol";
|
|
14
|
+
|
|
15
|
+
import {ICurveGauge} from "contracts/interfaces/ICurveGauge.sol";
|
|
16
|
+
|
|
17
|
+
contract CurveGauge is StrategyTemplate, ICurveGauge {
|
|
18
|
+
using SafeERC20 for IERC20;
|
|
19
|
+
using Math for uint256;
|
|
20
|
+
|
|
21
|
+
address public gauge;
|
|
22
|
+
address public lpToken;
|
|
23
|
+
address public underlyingAsset0;
|
|
24
|
+
address public underlyingAsset1;
|
|
25
|
+
|
|
26
|
+
uint256 public lastStoredVirtualPrice;
|
|
27
|
+
uint256 public lastStoredGaugeBalance;
|
|
28
|
+
|
|
29
|
+
bytes32 internal constant UNDERLYING_ASSETS_STATE_ID = keccak256("UNDERLYING_ASSETS_STATE_ID");
|
|
30
|
+
bytes32 internal constant CURVE_LP_STATE_ID = keccak256("CURVE_LP_STATE_ID");
|
|
31
|
+
bytes32 internal constant CURVE_GAUGE_STATE_ID = keccak256("CURVE_GAUGE_STATE_ID");
|
|
32
|
+
|
|
33
|
+
constructor() {
|
|
34
|
+
_disableInitializers();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function initialize(
|
|
38
|
+
address strategyContainer,
|
|
39
|
+
address _gauge,
|
|
40
|
+
uint256 _enterMaxSlippage,
|
|
41
|
+
uint256 _exitMaxSlippage,
|
|
42
|
+
uint256 _emergencyExitMaxSlippage
|
|
43
|
+
) external initializer {
|
|
44
|
+
__StrategyTemplate_init(strategyContainer, _enterMaxSlippage, _exitMaxSlippage, _emergencyExitMaxSlippage);
|
|
45
|
+
|
|
46
|
+
require(_gauge != address(0), Errors.ZeroAddress());
|
|
47
|
+
gauge = _gauge;
|
|
48
|
+
lpToken = ILiquidityGaugeV6(_gauge).lp_token();
|
|
49
|
+
underlyingAsset0 = ICurveStableSwapNG(lpToken).coins(0);
|
|
50
|
+
underlyingAsset1 = ICurveStableSwapNG(lpToken).coins(1);
|
|
51
|
+
|
|
52
|
+
_setState(UNDERLYING_ASSETS_STATE_ID, false, false, true, 1);
|
|
53
|
+
_setState(CURVE_LP_STATE_ID, false, true, false, 2);
|
|
54
|
+
_setState(CURVE_GAUGE_STATE_ID, true, true, false, 3);
|
|
55
|
+
|
|
56
|
+
lastStoredVirtualPrice = ICurveStableSwapNG(lpToken).get_virtual_price();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// @inheritdoc IStrategyTemplate
|
|
60
|
+
function stateNav(bytes32 stateId) public view override returns (uint256) {
|
|
61
|
+
if (stateId == CURVE_GAUGE_STATE_ID) {
|
|
62
|
+
return _curveGaugeNav();
|
|
63
|
+
} else if (stateId == CURVE_LP_STATE_ID) {
|
|
64
|
+
return _curveLpNav();
|
|
65
|
+
} else if (stateId == UNDERLYING_ASSETS_STATE_ID) {
|
|
66
|
+
return _underlyingAssetsNav();
|
|
67
|
+
} else if (stateId == NO_ALLOCATION_STATE_ID) {
|
|
68
|
+
return 0;
|
|
69
|
+
} else {
|
|
70
|
+
revert StateNotFound(stateId);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _underlyingAssetsNav() internal view returns (uint256) {
|
|
75
|
+
address asset0 = underlyingAsset0;
|
|
76
|
+
address asset1 = underlyingAsset1;
|
|
77
|
+
uint256 balance0 = IERC20(asset0).balanceOf(address(this));
|
|
78
|
+
uint256 balance1 = IERC20(asset1).balanceOf(address(this));
|
|
79
|
+
return getTokenAmountInNotion(asset0, balance0) + getTokenAmountInNotion(asset1, balance1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function _curveLpNav() internal view returns (uint256) {
|
|
83
|
+
address lpTokenCached = lpToken;
|
|
84
|
+
uint256 lpBalance = IERC20(lpTokenCached).balanceOf(address(this));
|
|
85
|
+
uint256 totalSupply = IERC20(lpTokenCached).totalSupply();
|
|
86
|
+
|
|
87
|
+
if (totalSupply == 0) {
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
uint256[] memory poolReserves = ICurveStableSwapNG(lpTokenCached).get_balances();
|
|
92
|
+
uint256 totalPoolNav = getTokenAmountInNotion(underlyingAsset0, poolReserves[0]) +
|
|
93
|
+
getTokenAmountInNotion(underlyingAsset1, poolReserves[1]);
|
|
94
|
+
|
|
95
|
+
return totalPoolNav.mulDiv(lpBalance, totalSupply);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function _curveGaugeNav() internal view returns (uint256) {
|
|
99
|
+
address gaugeCached = gauge;
|
|
100
|
+
uint256 stakedLp = ILiquidityGaugeV6(gaugeCached).balanceOf(address(this));
|
|
101
|
+
|
|
102
|
+
address lpTokenCached = lpToken;
|
|
103
|
+
uint256 totalSupply = IERC20(lpTokenCached).totalSupply();
|
|
104
|
+
|
|
105
|
+
if (stakedLp == 0 || totalSupply == 0) {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
uint256[] memory poolReserves = ICurveStableSwapNG(lpTokenCached).get_balances();
|
|
110
|
+
uint256 totalPoolNav = getTokenAmountInNotion(underlyingAsset0, poolReserves[0]) +
|
|
111
|
+
getTokenAmountInNotion(underlyingAsset1, poolReserves[1]);
|
|
112
|
+
|
|
113
|
+
return totalPoolNav.mulDiv(stakedLp, totalSupply);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function _enterCurveLp() internal {
|
|
117
|
+
uint256[] memory amounts = new uint256[](2);
|
|
118
|
+
amounts[0] = IERC20(underlyingAsset0).balanceOf(address(this));
|
|
119
|
+
amounts[1] = IERC20(underlyingAsset1).balanceOf(address(this));
|
|
120
|
+
|
|
121
|
+
if (amounts[0] == 0 && amounts[1] == 0) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (amounts[0] > 0) {
|
|
126
|
+
IERC20(underlyingAsset0).safeIncreaseAllowance(lpToken, amounts[0]);
|
|
127
|
+
}
|
|
128
|
+
if (amounts[1] > 0) {
|
|
129
|
+
IERC20(underlyingAsset1).safeIncreaseAllowance(lpToken, amounts[1]);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
ICurveStableSwapNG(lpToken).add_liquidity(amounts, 0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function _enterCurveGauge() internal {
|
|
136
|
+
address lpTokenCached = lpToken;
|
|
137
|
+
address gaugeCached = gauge;
|
|
138
|
+
|
|
139
|
+
uint256 lpBalance = IERC20(lpTokenCached).balanceOf(address(this));
|
|
140
|
+
|
|
141
|
+
if (lpBalance == 0) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
IERC20(lpTokenCached).safeIncreaseAllowance(gaugeCached, lpBalance);
|
|
146
|
+
ILiquidityGaugeV6(gaugeCached).deposit(lpBalance);
|
|
147
|
+
|
|
148
|
+
lastStoredGaugeBalance = ILiquidityGaugeV6(gaugeCached).balanceOf(address(this));
|
|
149
|
+
lastStoredVirtualPrice = ICurveStableSwapNG(lpTokenCached).get_virtual_price();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function _enterTarget() internal override {
|
|
153
|
+
_enterCurveLp();
|
|
154
|
+
_enterCurveGauge();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function _enterState(bytes32 stateId) internal override {
|
|
158
|
+
if (stateId == CURVE_GAUGE_STATE_ID) {
|
|
159
|
+
_enterCurveLp();
|
|
160
|
+
_enterCurveGauge();
|
|
161
|
+
} else if (stateId == CURVE_LP_STATE_ID) {
|
|
162
|
+
_enterCurveLp();
|
|
163
|
+
} else {
|
|
164
|
+
revert StateNotFound(stateId);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function _exitCurveLp(uint256 share) internal {
|
|
169
|
+
address lpTokenCached = lpToken;
|
|
170
|
+
uint256 lpBalance = IERC20(lpTokenCached).balanceOf(address(this));
|
|
171
|
+
uint256 lpToWithdraw = lpBalance.mulDiv(share, MAX_BPS);
|
|
172
|
+
|
|
173
|
+
if (lpToWithdraw == 0) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
uint256[] memory minAmountsOut = new uint256[](2);
|
|
178
|
+
|
|
179
|
+
ICurveStableSwapNG(lpTokenCached).remove_liquidity(lpToWithdraw, minAmountsOut);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function _exitCurveGauge(uint256 share) internal {
|
|
183
|
+
address gaugeCached = gauge;
|
|
184
|
+
uint256 gaugeBalance = ILiquidityGaugeV6(gaugeCached).balanceOf(address(this));
|
|
185
|
+
uint256 gaugeLpToWithdraw = gaugeBalance.mulDiv(share, MAX_BPS);
|
|
186
|
+
|
|
187
|
+
if (gaugeLpToWithdraw == 0) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
ILiquidityGaugeV6(gaugeCached).withdraw(gaugeLpToWithdraw);
|
|
192
|
+
|
|
193
|
+
lastStoredGaugeBalance = ILiquidityGaugeV6(gaugeCached).balanceOf(address(this));
|
|
194
|
+
lastStoredVirtualPrice = ICurveStableSwapNG(lpToken).get_virtual_price();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function _exitTarget(uint256 share) internal override {
|
|
198
|
+
_exitCurveGauge(share);
|
|
199
|
+
_exitCurveLp(MAX_BPS);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function _exitFromState(bytes32 stateId, uint256 share) internal override {
|
|
203
|
+
if (stateId == CURVE_GAUGE_STATE_ID) {
|
|
204
|
+
_exitCurveGauge(share);
|
|
205
|
+
} else if (stateId == CURVE_LP_STATE_ID) {
|
|
206
|
+
_exitCurveLp(share);
|
|
207
|
+
} else {
|
|
208
|
+
revert StateNotFound(stateId);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function _emergencyExit(bytes32 toStateId, uint256 share) internal override {
|
|
213
|
+
bytes32 currentStateId = currentStateId();
|
|
214
|
+
if (toStateId == CURVE_LP_STATE_ID) {
|
|
215
|
+
_exitCurveGauge(share);
|
|
216
|
+
} else if (toStateId == UNDERLYING_ASSETS_STATE_ID) {
|
|
217
|
+
if (currentStateId == CURVE_GAUGE_STATE_ID) {
|
|
218
|
+
_exitCurveGauge(share);
|
|
219
|
+
_exitCurveLp(MAX_BPS);
|
|
220
|
+
} else {
|
|
221
|
+
_exitCurveLp(share);
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
revert StateNotFound(toStateId);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function _harvest(bytes32 _stateId, address _treasury, uint256 _feePct) internal override {
|
|
229
|
+
AutomaticHarvestLocalVars memory vars;
|
|
230
|
+
vars.gaugeCached = gauge;
|
|
231
|
+
vars.lpTokenCached = lpToken;
|
|
232
|
+
vars.asset0Cached = underlyingAsset0;
|
|
233
|
+
vars.asset1Cached = underlyingAsset1;
|
|
234
|
+
|
|
235
|
+
vars.lastStoredGaugeBalance = lastStoredGaugeBalance;
|
|
236
|
+
vars.lastStoredVirtualPrice = lastStoredVirtualPrice;
|
|
237
|
+
|
|
238
|
+
vars.currentGaugeBalance = ILiquidityGaugeV6(vars.gaugeCached).balanceOf(address(this));
|
|
239
|
+
vars.currentVirtualPrice = ICurveStableSwapNG(vars.lpTokenCached).get_virtual_price();
|
|
240
|
+
|
|
241
|
+
if (vars.lastStoredGaugeBalance == 0) {
|
|
242
|
+
lastStoredGaugeBalance = vars.currentGaugeBalance;
|
|
243
|
+
lastStoredVirtualPrice = vars.currentVirtualPrice;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (_feePct > 0 && vars.currentVirtualPrice > vars.lastStoredVirtualPrice) {
|
|
248
|
+
vars.accruedLpValue =
|
|
249
|
+
(vars.currentGaugeBalance * vars.currentVirtualPrice -
|
|
250
|
+
vars.lastStoredGaugeBalance * vars.lastStoredVirtualPrice) / vars.currentVirtualPrice;
|
|
251
|
+
|
|
252
|
+
vars.gaugeTokensToTreasury = vars.accruedLpValue.mulDiv(_feePct, MAX_BPS);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
vars.asset0BalanceBefore = IERC20(vars.asset0Cached).balanceOf(address(this));
|
|
256
|
+
vars.asset1BalanceBefore = IERC20(vars.asset1Cached).balanceOf(address(this));
|
|
257
|
+
|
|
258
|
+
ILiquidityGaugeV6(vars.gaugeCached).claim_rewards();
|
|
259
|
+
|
|
260
|
+
vars.asset0Rewards = IERC20(vars.asset0Cached).balanceOf(address(this)) - vars.asset0BalanceBefore;
|
|
261
|
+
vars.asset1Rewards = IERC20(vars.asset1Cached).balanceOf(address(this)) - vars.asset1BalanceBefore;
|
|
262
|
+
|
|
263
|
+
if ((vars.asset0Rewards != 0 || vars.asset1Rewards != 0) && _stateId == CURVE_GAUGE_STATE_ID) {
|
|
264
|
+
uint256[] memory amounts = new uint256[](2);
|
|
265
|
+
amounts[0] = vars.asset0Rewards;
|
|
266
|
+
amounts[1] = vars.asset1Rewards;
|
|
267
|
+
|
|
268
|
+
IERC20(vars.asset0Cached).safeIncreaseAllowance(vars.lpTokenCached, amounts[0]);
|
|
269
|
+
IERC20(vars.asset1Cached).safeIncreaseAllowance(vars.lpTokenCached, amounts[1]);
|
|
270
|
+
|
|
271
|
+
ICurveStableSwapNG(vars.lpTokenCached).add_liquidity(amounts, 0);
|
|
272
|
+
|
|
273
|
+
_enterCurveGauge();
|
|
274
|
+
|
|
275
|
+
vars.reinvestGaugeDelta =
|
|
276
|
+
ILiquidityGaugeV6(vars.gaugeCached).balanceOf(address(this)) - vars.currentGaugeBalance;
|
|
277
|
+
|
|
278
|
+
if (vars.reinvestGaugeDelta > 0) {
|
|
279
|
+
vars.feeFromReinvest = vars.reinvestGaugeDelta.mulDiv(_feePct, MAX_BPS);
|
|
280
|
+
if (vars.feeFromReinvest > 0) {
|
|
281
|
+
vars.gaugeTokensToTreasury += vars.feeFromReinvest;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (vars.gaugeTokensToTreasury > 0) {
|
|
287
|
+
IERC20(vars.gaugeCached).safeTransfer(_treasury, vars.gaugeTokensToTreasury);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
lastStoredGaugeBalance = ILiquidityGaugeV6(vars.gaugeCached).balanceOf(address(this));
|
|
291
|
+
lastStoredVirtualPrice = Math.max(
|
|
292
|
+
ICurveStableSwapNG(vars.lpTokenCached).get_virtual_price(),
|
|
293
|
+
vars.lastStoredVirtualPrice
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
library DataTypes {
|
|
5
|
+
/**
|
|
6
|
+
* This exists specifically to maintain the `getReserveData()` interface, since the new, internal
|
|
7
|
+
* `ReserveData` struct includes the reserve's `virtualUnderlyingBalance`.
|
|
8
|
+
*/
|
|
9
|
+
struct ReserveDataLegacy {
|
|
10
|
+
//stores the reserve configuration
|
|
11
|
+
ReserveConfigurationMap configuration;
|
|
12
|
+
//the liquidity index. Expressed in ray
|
|
13
|
+
uint128 liquidityIndex;
|
|
14
|
+
//the current supply rate. Expressed in ray
|
|
15
|
+
uint128 currentLiquidityRate;
|
|
16
|
+
//variable borrow index. Expressed in ray
|
|
17
|
+
uint128 variableBorrowIndex;
|
|
18
|
+
//the current variable borrow rate. Expressed in ray
|
|
19
|
+
uint128 currentVariableBorrowRate;
|
|
20
|
+
// DEPRECATED on v3.2.0
|
|
21
|
+
uint128 currentStableBorrowRate;
|
|
22
|
+
//timestamp of last update
|
|
23
|
+
uint40 lastUpdateTimestamp;
|
|
24
|
+
//the id of the reserve. Represents the position in the list of the active reserves
|
|
25
|
+
uint16 id;
|
|
26
|
+
//aToken address
|
|
27
|
+
address aTokenAddress;
|
|
28
|
+
// DEPRECATED on v3.2.0
|
|
29
|
+
address stableDebtTokenAddress;
|
|
30
|
+
//variableDebtToken address
|
|
31
|
+
address variableDebtTokenAddress;
|
|
32
|
+
// DEPRECATED on v3.4.0, should use the `RESERVE_INTEREST_RATE_STRATEGY` variable from the Pool contract
|
|
33
|
+
address interestRateStrategyAddress;
|
|
34
|
+
//the current treasury balance, scaled
|
|
35
|
+
uint128 accruedToTreasury;
|
|
36
|
+
// DEPRECATED on v3.4.0
|
|
37
|
+
uint128 unbacked;
|
|
38
|
+
//the outstanding debt borrowed against this asset in isolation mode
|
|
39
|
+
uint128 isolationModeTotalDebt;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
struct ReserveData {
|
|
43
|
+
//stores the reserve configuration
|
|
44
|
+
ReserveConfigurationMap configuration;
|
|
45
|
+
//the liquidity index. Expressed in ray
|
|
46
|
+
uint128 liquidityIndex;
|
|
47
|
+
//the current supply rate. Expressed in ray
|
|
48
|
+
uint128 currentLiquidityRate;
|
|
49
|
+
//variable borrow index. Expressed in ray
|
|
50
|
+
uint128 variableBorrowIndex;
|
|
51
|
+
//the current variable borrow rate. Expressed in ray
|
|
52
|
+
uint128 currentVariableBorrowRate;
|
|
53
|
+
/// @notice reused `__deprecatedStableBorrowRate` storage from pre 3.2
|
|
54
|
+
// the current accumulate deficit in underlying tokens
|
|
55
|
+
uint128 deficit;
|
|
56
|
+
//timestamp of last update
|
|
57
|
+
uint40 lastUpdateTimestamp;
|
|
58
|
+
//the id of the reserve. Represents the position in the list of the active reserves
|
|
59
|
+
uint16 id;
|
|
60
|
+
//timestamp until when liquidations are not allowed on the reserve, if set to past liquidations will be allowed
|
|
61
|
+
uint40 liquidationGracePeriodUntil;
|
|
62
|
+
//aToken address
|
|
63
|
+
address aTokenAddress;
|
|
64
|
+
// DEPRECATED on v3.2.0
|
|
65
|
+
address __deprecatedStableDebtTokenAddress;
|
|
66
|
+
//variableDebtToken address
|
|
67
|
+
address variableDebtTokenAddress;
|
|
68
|
+
// DEPRECATED on v3.4.0, should use the `RESERVE_INTEREST_RATE_STRATEGY` variable from the Pool contract
|
|
69
|
+
address __deprecatedInterestRateStrategyAddress;
|
|
70
|
+
//the current treasury balance, scaled
|
|
71
|
+
uint128 accruedToTreasury;
|
|
72
|
+
// In aave 3.3.0 this storage slot contained the `unbacked`
|
|
73
|
+
uint128 virtualUnderlyingBalance;
|
|
74
|
+
//the outstanding debt borrowed against this asset in isolation mode
|
|
75
|
+
uint128 isolationModeTotalDebt;
|
|
76
|
+
//the amount of underlying accounted for by the protocol
|
|
77
|
+
// DEPRECATED on v3.4.0. Moved into the same slot as accruedToTreasury for optimized storage access.
|
|
78
|
+
uint128 __deprecatedVirtualUnderlyingBalance;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
struct ReserveConfigurationMap {
|
|
82
|
+
//bit 0-15: LTV
|
|
83
|
+
//bit 16-31: Liq. threshold
|
|
84
|
+
//bit 32-47: Liq. bonus
|
|
85
|
+
//bit 48-55: Decimals
|
|
86
|
+
//bit 56: reserve is active
|
|
87
|
+
//bit 57: reserve is frozen
|
|
88
|
+
//bit 58: borrowing is enabled
|
|
89
|
+
//bit 59: DEPRECATED: stable rate borrowing enabled
|
|
90
|
+
//bit 60: asset is paused
|
|
91
|
+
//bit 61: borrowing in isolation mode is enabled
|
|
92
|
+
//bit 62: siloed borrowing enabled
|
|
93
|
+
//bit 63: flashloaning enabled
|
|
94
|
+
//bit 64-79: reserve factor
|
|
95
|
+
//bit 80-115: borrow cap in whole tokens, borrowCap == 0 => no cap
|
|
96
|
+
//bit 116-151: supply cap in whole tokens, supplyCap == 0 => no cap
|
|
97
|
+
//bit 152-167: liquidation protocol fee
|
|
98
|
+
//bit 168-175: DEPRECATED: eMode category
|
|
99
|
+
//bit 176-211: DEPRECATED: unbacked mint cap
|
|
100
|
+
//bit 212-251: debt ceiling for isolation mode with (ReserveConfiguration::DEBT_CEILING_DECIMALS) decimals
|
|
101
|
+
//bit 252: DEPRECATED: virtual accounting is enabled for the reserve
|
|
102
|
+
//bit 253-255 unused
|
|
103
|
+
|
|
104
|
+
uint256 data;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
struct UserConfigurationMap {
|
|
108
|
+
/**
|
|
109
|
+
* @dev Bitmap of the users collaterals and borrows. It is divided in pairs of bits, one pair per asset.
|
|
110
|
+
* The first bit indicates if an asset is used as collateral by the user, the second whether an
|
|
111
|
+
* asset is borrowed by the user.
|
|
112
|
+
*/
|
|
113
|
+
uint256 data;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// DEPRECATED: kept for backwards compatibility, might be removed in a future version
|
|
117
|
+
struct EModeCategoryLegacy {
|
|
118
|
+
// each eMode category has a custom ltv and liquidation threshold
|
|
119
|
+
uint16 ltv;
|
|
120
|
+
uint16 liquidationThreshold;
|
|
121
|
+
uint16 liquidationBonus;
|
|
122
|
+
// DEPRECATED
|
|
123
|
+
address priceSource;
|
|
124
|
+
string label;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
struct CollateralConfig {
|
|
128
|
+
uint16 ltv;
|
|
129
|
+
uint16 liquidationThreshold;
|
|
130
|
+
uint16 liquidationBonus;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
struct EModeCategoryBaseConfiguration {
|
|
134
|
+
uint16 ltv;
|
|
135
|
+
uint16 liquidationThreshold;
|
|
136
|
+
uint16 liquidationBonus;
|
|
137
|
+
string label;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
struct EModeCategory {
|
|
141
|
+
// each eMode category has a custom ltv and liquidation threshold
|
|
142
|
+
uint16 ltv;
|
|
143
|
+
uint16 liquidationThreshold;
|
|
144
|
+
uint16 liquidationBonus;
|
|
145
|
+
uint128 collateralBitmap;
|
|
146
|
+
string label;
|
|
147
|
+
uint128 borrowableBitmap;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
enum InterestRateMode {
|
|
151
|
+
NONE,
|
|
152
|
+
__DEPRECATED,
|
|
153
|
+
VARIABLE
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
struct ReserveCache {
|
|
157
|
+
uint256 currScaledVariableDebt;
|
|
158
|
+
uint256 nextScaledVariableDebt;
|
|
159
|
+
uint256 currLiquidityIndex;
|
|
160
|
+
uint256 nextLiquidityIndex;
|
|
161
|
+
uint256 currVariableBorrowIndex;
|
|
162
|
+
uint256 nextVariableBorrowIndex;
|
|
163
|
+
uint256 currLiquidityRate;
|
|
164
|
+
uint256 currVariableBorrowRate;
|
|
165
|
+
uint256 reserveFactor;
|
|
166
|
+
ReserveConfigurationMap reserveConfiguration;
|
|
167
|
+
address aTokenAddress;
|
|
168
|
+
address variableDebtTokenAddress;
|
|
169
|
+
uint40 reserveLastUpdateTimestamp;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
struct ExecuteLiquidationCallParams {
|
|
173
|
+
address liquidator;
|
|
174
|
+
uint256 debtToCover;
|
|
175
|
+
address collateralAsset;
|
|
176
|
+
address debtAsset;
|
|
177
|
+
address borrower;
|
|
178
|
+
bool receiveAToken;
|
|
179
|
+
address priceOracle;
|
|
180
|
+
uint8 borrowerEModeCategory;
|
|
181
|
+
address priceOracleSentinel;
|
|
182
|
+
address interestRateStrategyAddress;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
struct ExecuteSupplyParams {
|
|
186
|
+
address user;
|
|
187
|
+
address asset;
|
|
188
|
+
address interestRateStrategyAddress;
|
|
189
|
+
uint256 amount;
|
|
190
|
+
address onBehalfOf;
|
|
191
|
+
uint16 referralCode;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
struct ExecuteBorrowParams {
|
|
195
|
+
address asset;
|
|
196
|
+
address user;
|
|
197
|
+
address onBehalfOf;
|
|
198
|
+
address interestRateStrategyAddress;
|
|
199
|
+
uint256 amount;
|
|
200
|
+
InterestRateMode interestRateMode;
|
|
201
|
+
uint16 referralCode;
|
|
202
|
+
bool releaseUnderlying;
|
|
203
|
+
address oracle;
|
|
204
|
+
uint8 userEModeCategory;
|
|
205
|
+
address priceOracleSentinel;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
struct ExecuteRepayParams {
|
|
209
|
+
address asset;
|
|
210
|
+
address user;
|
|
211
|
+
address interestRateStrategyAddress;
|
|
212
|
+
uint256 amount;
|
|
213
|
+
InterestRateMode interestRateMode;
|
|
214
|
+
address onBehalfOf;
|
|
215
|
+
bool useATokens;
|
|
216
|
+
address oracle;
|
|
217
|
+
uint8 userEModeCategory;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
struct ExecuteWithdrawParams {
|
|
221
|
+
address user;
|
|
222
|
+
address asset;
|
|
223
|
+
address interestRateStrategyAddress;
|
|
224
|
+
uint256 amount;
|
|
225
|
+
address to;
|
|
226
|
+
address oracle;
|
|
227
|
+
uint8 userEModeCategory;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
struct ExecuteEliminateDeficitParams {
|
|
231
|
+
address user;
|
|
232
|
+
address asset;
|
|
233
|
+
address interestRateStrategyAddress;
|
|
234
|
+
uint256 amount;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
struct FinalizeTransferParams {
|
|
238
|
+
address asset;
|
|
239
|
+
address from;
|
|
240
|
+
address to;
|
|
241
|
+
uint256 scaledAmount;
|
|
242
|
+
uint256 scaledBalanceFromBefore;
|
|
243
|
+
uint256 scaledBalanceToBefore;
|
|
244
|
+
address oracle;
|
|
245
|
+
uint8 fromEModeCategory;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
struct FlashloanParams {
|
|
249
|
+
address user;
|
|
250
|
+
address receiverAddress;
|
|
251
|
+
address[] assets;
|
|
252
|
+
uint256[] amounts;
|
|
253
|
+
uint256[] interestRateModes;
|
|
254
|
+
address interestRateStrategyAddress;
|
|
255
|
+
address onBehalfOf;
|
|
256
|
+
bytes params;
|
|
257
|
+
uint16 referralCode;
|
|
258
|
+
uint256 flashLoanPremium;
|
|
259
|
+
address addressesProvider;
|
|
260
|
+
address pool;
|
|
261
|
+
uint8 userEModeCategory;
|
|
262
|
+
bool isAuthorizedFlashBorrower;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
struct FlashloanSimpleParams {
|
|
266
|
+
address user;
|
|
267
|
+
address receiverAddress;
|
|
268
|
+
address asset;
|
|
269
|
+
address interestRateStrategyAddress;
|
|
270
|
+
uint256 amount;
|
|
271
|
+
bytes params;
|
|
272
|
+
uint16 referralCode;
|
|
273
|
+
uint256 flashLoanPremium;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
struct FlashLoanRepaymentParams {
|
|
277
|
+
address user;
|
|
278
|
+
uint256 amount;
|
|
279
|
+
uint256 totalPremium;
|
|
280
|
+
address asset;
|
|
281
|
+
address interestRateStrategyAddress;
|
|
282
|
+
address receiverAddress;
|
|
283
|
+
uint16 referralCode;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
struct CalculateUserAccountDataParams {
|
|
287
|
+
UserConfigurationMap userConfig;
|
|
288
|
+
address user;
|
|
289
|
+
address oracle;
|
|
290
|
+
uint8 userEModeCategory;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
struct ValidateBorrowParams {
|
|
294
|
+
ReserveCache reserveCache;
|
|
295
|
+
UserConfigurationMap userConfig;
|
|
296
|
+
address asset;
|
|
297
|
+
address userAddress;
|
|
298
|
+
uint256 amountScaled;
|
|
299
|
+
InterestRateMode interestRateMode;
|
|
300
|
+
address oracle;
|
|
301
|
+
uint8 userEModeCategory;
|
|
302
|
+
address priceOracleSentinel;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
struct ValidateLiquidationCallParams {
|
|
306
|
+
ReserveCache debtReserveCache;
|
|
307
|
+
uint256 totalDebt;
|
|
308
|
+
uint256 healthFactor;
|
|
309
|
+
address priceOracleSentinel;
|
|
310
|
+
address borrower;
|
|
311
|
+
address liquidator;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
struct CalculateInterestRatesParams {
|
|
315
|
+
uint256 unbacked;
|
|
316
|
+
uint256 liquidityAdded;
|
|
317
|
+
uint256 liquidityTaken;
|
|
318
|
+
uint256 totalDebt;
|
|
319
|
+
uint256 reserveFactor;
|
|
320
|
+
address reserve;
|
|
321
|
+
// @notice DEPRECATED in 3.4, but kept for backwards compatibility
|
|
322
|
+
bool usingVirtualBalance;
|
|
323
|
+
uint256 virtualUnderlyingBalance;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
struct InitReserveParams {
|
|
327
|
+
address asset;
|
|
328
|
+
address aTokenAddress;
|
|
329
|
+
address variableDebtAddress;
|
|
330
|
+
uint16 reservesCount;
|
|
331
|
+
uint16 maxNumberReserves;
|
|
332
|
+
}
|
|
333
|
+
}
|