UniswapFlashloanBalancerSwapHandler
Inherits: IUniswapV3FlashCallback, IonHandlerBase
This contract allows for easy creation and closing of leverage positions through Uniswap flashloans and LST swaps on Balancer. In terms of creation, this may be a more desirable path than directly minting from an LST provider since market prices tend to be slightly lower than provider exchange rates. DEXes also provide an avenue for atomic deleveraging since the LST -> ETH exchange can be made. NOTE: Uniswap flashloans do charge a small fee.
Some tokens only have liquidity on Balancer. Due to the reentrancy lock on the Balancer VAULT, utilizing their free flashloan followed by a pool swap is not possible. Instead, we will take a cheap (0.01%) flashloan from the wstETH/ETH uniswap pool and perform the Balancer swap. The rETH/ETH uniswap pool could also be used since it has a 0.01% fee but it does have less liquidity.
State Variables
VAULT
WETH_IS_TOKEN0_ON_UNISWAP
FLASHLOAN_POOL
BALANCER_POOL_ID
Functions
constructor
Creates a new instance of UniswapFlashloanBalancerSwapHandler
Parameters
flashLeverageWethAndSwap
Transfer collateral from user + flashloan WETH from Uniswap -> swap for collateral using WETH on Balancer pool -> deposit all collateral into IonPool
-> borrow WETH from IonPool
-> repay Uniswap flashloan + fee. Uniswap flashloans do incur a fee.
Parameters
flashDeleverageWethAndSwap
Flashloan WETH from Uniswap -> repay debt in IonPool
-> withdraw collateral from IonPool
-> sell collateral for WETH
on Balancer -> repay Uniswap flashloan + fee. Uniswap flashloans do incur a fee.
Parameters
uniswapV3FlashCallback
Called to msg.sender
after transferring to the recipient from IUniswapV3Pool#flash.
In the implementation, you must repay the pool the tokens sent by flash()
plus the computed fee amounts. The caller of this method must be checked to be a UniswapV3Pool. Initiator is guaranteed to be this contract since UniswapV3 pools will only call the callback on msg.sender.
Parameters
_simulateGivenOutBalancerSwap
Simulates a Balancer swap with a desired amount of assetOut
.
Parameters