UniswapFlashswapDirectMintHandlerWithDust
Inherits: IonHandlerBase, IUniswapV3SwapCallback
This contract is forked off of the UniswapFlashswapDirectMintHandler, with one distinction that it handles potential dust collateral amounts that can accrue when the contract ends up minting more collateral than originally intended. This situation can occur when the user has a desired leverage amount and thus an exact resulting collateral amount, but due to rounding errors in the minting contract, the handler is forced to mint a dust amount more than the desired collateral amount. In this contract, the dust is added to the total final deposit amount and ends up in the user's vault as additional collateral. The key difference between this contract and UniswapFlashswapDirectMintHandler
is a relaxed bound in comparing the sum of initial user deposit and additionally minted collateral to the caller's requested resulting additional collateral amount. This contract allows for easy creation of leverage positions through a Uniswap flashswap and direct mint of the collateral from the provider. This will be used when the collateral cannot be minted directly with the base asset but can be directly minted by a token that the base asset has a UniswapV3 pool with. This contract is to be used when there exists a UniswapV3 pool between the base asset and the mint asset.
State Variables
MIN_SQRT_RATIO
The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
MAX_SQRT_RATIO
The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
UNISWAP_POOL
MINT_ASSET
MINT_IS_TOKEN0
Functions
constructor
Creates a new UniswapFlashswapDirectMintHandler
instance.
Parameters
Name | Type | Description |
---|---|---|
|
| Pool to perform the flashswap on. |
|
| The asset used to mint the collateral. |
flashswapAndMint
Transfer collateral from user -> Initiate flashswap between from base asset to mint asset -> Use the mint asset to mint the collateral -> Deposit all collateral into IonPool
-> Borrow the base asset -> Close the flashswap by sending the base asset to the Uniswap pool.
Parameters
Name | Type | Description |
---|---|---|
|
| in collateral terms. [WAD] |
|
| in collateral terms. [WAD] |
|
| in base asset terms. [WAD] |
|
| The unix timestamp after which the uniswap transaction reverts. |
|
| used to validate the user is whitelisted. |
_flashswapAndMint
_initiateFlashSwap
Handles swap initiation logic. This function can only initiate exact output swaps.
Parameters
Name | Type | Description |
---|---|---|
|
| Direction of the swap. |
|
| Desired amount of output. |
|
| of output tokens. |
|
| Arbitrary data to be passed through swap callback. |
uniswapV3SwapCallback
From the perspective of the pool i.e. Negative amount means pool is sending. This function is intended to never be called directly. It should only be called by the Uniswap pool during a swap initiated by this contract.
One thing to note from a security perspective is that the pool only calls the callback on msg.sender
. So a theoretical attacker cannot call this function by directing where to call the callback.
Parameters
Name | Type | Description |
---|---|---|
|
| change in token0 |
|
| change in token1 |
|
| arbitrary data |
_mintCollateralAsset
Deposits the mint asset into the provider's collateral-asset deposit contract.
Parameters
Name | Type | Description |
---|---|---|
|
| amount of "mint asset" to deposit. [WAD] |
Returns
Name | Type | Description |
---|---|---|
|
| Amount of collateral asset received. [WAD] |
_getAmountInForCollateralAmountOut
Calculates the amount of mint asset required to receive amountLrt
.
Calculates the amount of mint asset required to receive amountLrt
.
Parameters
Name | Type | Description |
---|---|---|
|
| Desired output amount. [WAD] |
Returns
Name | Type | Description |
---|---|---|
|
| Amount mint asset required for desired output. [WAD] |