-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathOneStepLeverageStETH.sol
57 lines (51 loc) · 1.94 KB
/
OneStepLeverageStETH.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
import { IERC3156FlashBorrower } from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol";
import { IWstETH } from "./Dependencies/IWstETH.sol";
import { IPositionManager } from "./Interfaces/IPositionManager.sol";
import { IOneStepLeverageStETH } from "./Interfaces/IOneStepLeverageStETH.sol";
import { OneStepLeverage } from "./OneStepLeverage.sol";
import { WstETHWrapper } from "./WstETHWrapper.sol";
import { IAMM } from "./Interfaces/IAMM.sol";
contract OneStepLeverageStETH is IERC3156FlashBorrower, IOneStepLeverageStETH, WstETHWrapper, OneStepLeverage {
constructor(
IPositionManager positionManager_,
IAMM amm_,
IWstETH wstETH_
)
OneStepLeverage(positionManager_, amm_, wstETH_, false)
WstETHWrapper(wstETH_)
{ }
function manageLeveragedPositionStETH(
uint256 debtChange,
bool isDebtIncrease,
uint256 stETHCollateralChange,
bool stETHCollateralIncrease,
bytes calldata ammData,
uint256 minReturnOrAmountToSell,
uint256 maxFeePercentage
)
external
override
{
uint256 wstETHCollateralChange = (stETHCollateralIncrease && stETHCollateralChange > 0)
? wrapStETH(stETHCollateralChange)
: wstETH.getWstETHByStETH(stETHCollateralChange);
wstETHCollateralChange = _manageLeveragedPosition(
debtChange,
isDebtIncrease,
wstETHCollateralChange,
stETHCollateralIncrease,
ammData,
minReturnOrAmountToSell,
maxFeePercentage,
false
);
if (!stETHCollateralIncrease && wstETHCollateralChange > 0) {
unwrapStETH(wstETH.balanceOf(address(this)));
}
emit StETHLeveragedPositionChange(
msg.sender, stETHCollateralChange, stETHCollateralIncrease, debtChange, isDebtIncrease
);
}
}