-
Notifications
You must be signed in to change notification settings - Fork 9
/
EthXHandler.sol
79 lines (72 loc) · 3.18 KB
/
EthXHandler.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.21;
import { IonPool } from "../../IonPool.sol";
import { GemJoin } from "../../join/GemJoin.sol";
import { Whitelist } from "../../Whitelist.sol";
import { StaderLibrary } from "../../libraries/StaderLibrary.sol";
import { IStaderStakePoolsManager } from "../../interfaces/ProviderInterfaces.sol";
import { IonHandlerBase } from "./base/IonHandlerBase.sol";
import { UniswapFlashloanBalancerSwapHandler } from "./base/UniswapFlashloanBalancerSwapHandler.sol";
import { BalancerFlashloanDirectMintHandler } from "./base/BalancerFlashloanDirectMintHandler.sol";
import { UniswapFlashswapHandler } from "./base/UniswapFlashswapHandler.sol";
import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
/**
* @notice Handler for the ETHx collateral.
*
* @custom:security-contact security@molecularlabs.io
*/
contract EthXHandler is
UniswapFlashloanBalancerSwapHandler,
UniswapFlashswapHandler,
BalancerFlashloanDirectMintHandler
{
using StaderLibrary for IStaderStakePoolsManager;
// Stader deposit contract is separate from the ETHx lst contract
IStaderStakePoolsManager public immutable STADER_DEPOSIT;
/**
* @notice Creates a new `EthXHandler` instance.
* @param _ilkIndex of ETHx.
* @param _ionPool `IonPool` contract address.
* @param _gemJoin `GemJoin` contract address associated with ETHx.
* @param _staderDeposit Address for the Stader deposit contract.
* @param _whitelist Address of the `Whitelist` contract.
* @param _wstEthUniswapPool Address of the WSTETH/ETH Uniswap V3 pool.
* @param _ethXUniswapPool Address of the ETHx/ETH Uniswap V3 pool.
* @param _balancerPoolId Balancer pool ID for the ETHx/ETH pool.
*/
constructor(
uint8 _ilkIndex,
IonPool _ionPool,
GemJoin _gemJoin,
IStaderStakePoolsManager _staderDeposit,
Whitelist _whitelist,
IUniswapV3Pool _wstEthUniswapPool,
IUniswapV3Pool _ethXUniswapPool,
bytes32 _balancerPoolId
)
UniswapFlashloanBalancerSwapHandler(_wstEthUniswapPool, _balancerPoolId)
IonHandlerBase(_ilkIndex, _ionPool, _gemJoin, _whitelist)
UniswapFlashswapHandler(_ethXUniswapPool, false)
{
STADER_DEPOSIT = _staderDeposit;
}
/**
* @notice Unwraps weth into eth and deposits into lst contract.
* @dev Unwraps weth into eth and deposits into lst contract.
* @param amountWeth The WETH amount to deposit. [WAD]
* @return Amount of lst received. [WAD]
*/
function _depositWethForLst(uint256 amountWeth) internal override returns (uint256) {
WETH.withdraw(amountWeth);
return STADER_DEPOSIT.depositForLst(amountWeth);
}
/**
* @notice Calculates the amount of eth required to receive `amountLst`.
* @dev Calculates the amount of eth required to receive `amountLst`.
* @param amountLst Desired output amount. [WAD]
* @return Eth required for desired lst output. [WAD]
*/
function _getEthAmountInForLstAmountOut(uint256 amountLst) internal view override returns (uint256) {
return STADER_DEPOSIT.getEthAmountInForLstAmountOut(amountLst);
}
}