FluidVaultLiquidationResolver

Resolver contract that helps in finding available token swaps through Fluid Vault liquidations.

Functions

constructor

constructor sets the immutable vault resolver address

constructor(IFluidVaultResolver vaultResolver_) Variables(vaultResolver_);

getAllSwapPairs

returns all token swap pairs available through Fluid Vault Liquidations

function getAllSwapPairs() public view returns (VaultData[] memory vaultDatas_);

getVaultForSwap

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.

function getVaultForSwap(address tokenIn_, address tokenOut_) public view returns (address vault_);

getVaultsForSwap

returns all available token pair swaps for any tokensIn_ to any tokensOut_ with the vault address.

for native token, send 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.

function getVaultsForSwap(address[] calldata tokensIn_, address[] calldata tokensOut_)
    public
    view
    returns (VaultData[] memory vaultDatas_);

getSwapAvailable

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.

function getSwapAvailable(address tokenIn_, address tokenOut_) public returns (SwapData memory swapData_);

getSwapsAvailable

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.

function getSwapsAvailable(address[] calldata tokensIn_, address[] calldata tokensOut_)
    public
    returns (SwapData[] memory swapDatas_);

getSwapCalldata

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.

function getSwapCalldata(
    address vault_,
    address receiver_,
    uint256 tokenInAmt_,
    uint256 tokenOutAmt_,
    uint256 slippage_,
    bool withAbsorb_
) public pure returns (bytes memory calldata_);

Parameters

NameTypeDescription
vault_addressvault address at which the liquidation is executed
receiver_addressreceiver address that the output token is sent to
tokenInAmt_uint256input token amount (debt token at vault)
tokenOutAmt_uint256expected output token amount (collateral token at vault)
slippage_uint256maximum 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_boolset 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.

Returns

NameTypeDescription
calldata_bytesthe calldata that can be used to trigger the liquidation call, resulting in the desired swap.

getSwapDataForVault

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.

function getSwapDataForVault(address vault_) public returns (SwapData memory swapData_);

exactInput

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.

function exactInput(address tokenIn_, address tokenOut_, uint256 inAmt_)
    public
    returns (address vault_, uint256 actualInAmt_, uint256 outAmt_, bool withAbsorb_);

Parameters

NameTypeDescription
tokenIn_addressinput token (debt token at vault)
tokenOut_addressoutput token (collateral token at vault)
inAmt_uint256exact input token amount that should be swapped to output token

Returns

NameTypeDescription
vault_addressvault address at which the swap is available.
actualInAmt_uint256actual input token amount. Equals inAmt_, but if less then the desired swap amount is available, then the available amount is returned instead.
outAmt_uint256received output token amount for actualInAmt_ of input token
withAbsorb_boolflag 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

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.

function exactOutput(address tokenIn_, address tokenOut_, uint256 outAmt_)
    public
    returns (address vault_, uint256 inAmt_, uint256 actualOutAmt_, bool withAbsorb_);

Parameters

NameTypeDescription
tokenIn_addressinput token (debt token at vault)
tokenOut_addressoutput token (collateral token at vault)
outAmt_uint256exact output token amount that should be received as a result of the swap

Returns

NameTypeDescription
vault_addressvault address at which the swap is available.
inAmt_uint256required input token amount to receive actualOutAmt_ of output token
actualOutAmt_uint256actual output token amount. Equals outAmt_, but if less then the desired swap amount is available, then the available amount is returned instead
withAbsorb_boolflag 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.

Errors

FluidVaultLiquidationsResolver__AddressZero

thrown if an input param address is zero

error FluidVaultLiquidationsResolver__AddressZero();

FluidVaultLiquidationsResolver__InvalidParams

thrown if an invalid param is given to a method

error FluidVaultLiquidationsResolver__InvalidParams();

Structs

VaultData

    struct VaultData{
        ///
        /// @param vault vault address at which the token pair is available
        address vault;
        ///
        /// @param tokenIn input token, borrow token at the vault
        address tokenIn;
        ///
        /// @param tokenOut output token, collateral token at the vault
        address tokenOut;
    }

SwapData

    struct SwapData {
        ///
        /// @param vault vault address at which the token pair is available
        address vault;
        ///
        /// @param inAmt total input token available amount (without absorb)
        uint256 inAmt;
        ///
        /// @param outAmt total output token amount received for `inAmt` (without absorb)
        uint256 outAmt;
        ///
        /// @param inAmtWithAbsorb total input token available amount (with absorb)
        uint256 inAmtWithAbsorb;
        ///
        /// @param outAmtWithAbsorb total output token amount received for `inAmtWithAbsorb` (with absorb)
        uint256 outAmtWithAbsorb;
    }