FluidVaultLiquidationResolver
Resolver contract that helps in finding available token swaps through Fluid Vault liquidations.
FluidVaultLiquidationsResolver__AddressZero
error FluidVaultLiquidationsResolver__AddressZero()
thrown if an input param address is zero
FluidVaultLiquidationsResolver__InvalidParams
error FluidVaultLiquidationsResolver__InvalidParams()
thrown if an invalid param is given to a method
constructor
constructor(contract IFluidVaultResolver vaultResolver_) public
constructor sets the immutable vault resolver address
getAllSwapPairs
function getAllSwapPairs() public view returns (struct Structs.VaultData[] vaultDatas_)
returns all token swap pairs available through Fluid Vault Liquidations
getVaultForSwap
function getVaultForSwap(address tokenIn_, address tokenOut_) public view returns (address vault_)
returns the vault address for a certain tokenIn_
swapped to a tokenOut_
.
returns zero address if no vault is available for a given pair.
for native token, send 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.
getVaultsForSwap
function getVaultsForSwap(address[] tokensIn_, address[] tokensOut_) public view returns (struct Structs.VaultData[] vaultDatas_)
returns all available token pair swaps for any tokensIn_
to any tokensOut_
with the vault address.
for native token, send 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.
getSwapAvailable
function getSwapAvailable(address tokenIn_, address tokenOut_) public returns (struct Structs.SwapData swapData_)
finds the total available swappable amount for a tokenIn_
to tokenOut_
swap, considering both a swap
that uses liquidation with absorb and without absorb. Sometimes with absorb can provide better swaps,
sometimes without absorb can provide better swaps. But available liquidity for "withAbsorb" amounts will
always be >= normal amounts.
returned data can be fed into getSwapCalldata
to prepare the tx that executes the swap.
expected to be called with callStatic, although this method does not do any actual state changes anyway.
for native token, send 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.
getSwapsAvailable
function getSwapsAvailable(address[] tokensIn_, address[] tokensOut_) public returns (struct Structs.SwapData[] swapDatas_)
finds the total available swappable amount for any tokensIn_
to any tokesnOut_
swap, considering both
a swap that uses liquidation with absorb and without absorb. Sometimes with absorb can provide better swaps,
sometimes without absorb can provide better swaps. But available liquidity for "withAbsorb" amounts will
always be >= normal amounts. Token pairs that are not available will not be listed in returned SwapData array.
e.g. for tokensIn*: USDC & USDT and tokensOut*: ETH & wstETH, this would return any available token pair incl.
the available swappable amounts, so for USDC -> ETH, USDC -> wstETH, USDT -> ETH, USDT -> wstETH.
returned data can be fed into getSwapCalldata
to prepare the tx that executes the swap.
expected to be called with callStatic, although this method does not do any actual state changes anyway.
for native token, send 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.
getSwapCalldata
function getSwapCalldata(address vault_, address receiver_, uint256 tokenInAmt_, uint256 tokenOutAmt_, uint256 slippage_, bool withAbsorb_) public pure returns (bytes calldata_)
returns the calldata to execute a swap as found through this contract by triggering a vault liquidation.
tokenInAmt_
must come from msg.sender, tokenOutAmt_
goes to receiver_
. If the input token is the
native token, msg.value must be sent along when triggering the actual call with the returned calldata.
Parameters
Name | Type | Description |
---|---|---|
vault_ | address | vault address at which the liquidation is executed |
receiver_ | address | receiver address that the output token is sent to |
tokenInAmt_ | uint256 | input token amount (debt token at vault) |
tokenOutAmt_ | uint256 | expected output token amount (collateral token at vault) |
slippage_ | uint256 | maximum allowed slippage for the expected output token amount. Reverts iIf received token out amount is lower than this. in 1e4 percentage, e.g. 1% = 10000, 0.3% = 3000, 0.01% = 100, 0.0001% = 1. |
withAbsorb_ | bool | set to true to trigger liquidation with executing absorb() first. Liquidity is >= when this is set to true. Rate can be better with or without, check before via other methods. |
Return Values
Name | Type | Description |
---|---|---|
calldata_ | bytes | the calldata that can be used to trigger the liquidation call, resulting in the desired swap. |
getSwapDataForVault
function getSwapDataForVault(address vault_) public returns (struct Structs.SwapData swapData_)
returns the available swap (liquidation) amounts at a certain vault_
, considering both
a swap that uses liquidation with absorb and without absorb. Sometimes with absorb can provide better swaps,
sometimes without absorb can provide better swaps. But available liquidity for "withAbsorb" amounts will
always be >= normal amounts.
returned data can be fed into getSwapCalldata
to prepare the tx that executes the swap.
expected to be called with callStatic, although this method does not do any actual state changes anyway.
exactInput
function exactInput(address tokenIn_, address tokenOut_, uint256 inAmt_) public returns (address vault_, uint256 actualInAmt_, uint256 outAmt_, bool withAbsorb_)
finds a swap from tokenIn_
to tokenOut_
for an exact input amount inAmt_
. If available amount is
less then the desired input amount, it returns the available amount. Considers the best rate available
for mode with absorb and mode without absorb.
returned data can be fed into getSwapCalldata
to prepare the tx that executes the swap.
Parameters
Name | Type | Description |
---|---|---|
tokenIn_ | address | input token (debt token at vault) |
tokenOut_ | address | output token (collateral token at vault) |
inAmt_ | uint256 | exact input token amount that should be swapped to output token |
Return Values
Name | Type | Description |
---|---|---|
vault_ | address | vault address at which the swap is available. |
actualInAmt_ | uint256 | actual input token amount. Equals inAmt_ , but if less then the desired swap amount is available, then the available amount is returned instead. |
outAmt_ | uint256 | received output token amount for actualInAmt_ of input token |
withAbsorb_ | bool | flag for using mode "withAbsorb". Is set to true if a) liquidity without absorb would not cover the desired inAmt_ or if b) the rate of with absorb is better than without absorb. |
exactOutput
function exactOutput(address tokenIn_, address tokenOut_, uint256 outAmt_) public returns (address vault_, uint256 inAmt_, uint256 actualOutAmt_, bool withAbsorb_)
finds a swap from tokenIn_
to tokenOut_
for an exact output amount outAmt_
. If available amount is
less then the desired output amount, it returns the available amount. Considers the best rate available
for mode with absorb and mode without absorb.
returned data can be fed into getSwapCalldata
to prepare the tx that executes the swap.
Parameters
Name | Type | Description |
---|---|---|
tokenIn_ | address | input token (debt token at vault) |
tokenOut_ | address | output token (collateral token at vault) |
outAmt_ | uint256 | exact output token amount that should be received as a result of the swap |
Return Values
Name | Type | Description |
---|---|---|
vault_ | address | vault address at which the swap is available. |
inAmt_ | uint256 | required input token amount to receive actualOutAmt_ of output token |
actualOutAmt_ | uint256 | actual output token amount. Equals outAmt_ , but if less then the desired swap amount is available, then the available amount is returned instead |
withAbsorb_ | bool | flag for using mode "withAbsorb". Is set to true if a) liquidity without absorb would not cover the desired outAmt_ or if b) the rate of with absorb is better than without absorb. |