FCT_Lib_UniswapV2

FCT_Lib_UniswapV2 adds the ability to do a swaps and add liquidity when not all params are known in advance. It also supports simulating swaps without doing any change on the blockchain.

It is needed because swap and add liquidity needs inputs that are dependent on dynamic data.

The ability to simulate actions like swaps extends the capabilities and possible uses cases for FCTs.

It is not safe to use the "*X*_no*Y*Protection" named functions without adding a validator the checks return values or better to have a validator/s at the end of the FCT that ensures the desired outcome

Main Functions

addLiquidity_noMinProtection

function addLiquidity_noMinProtection(
        bytes32 method,
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity)

Adds liquidity directly from the FCT_Runner without any min amount protection, meaning that the actual amounts that will be used are not assured.

Method

The method field indicates what type of assets to use.

Method can be used as string or as bytes32 in the EIP712 FCT message. When string is used the FCT engine can be informed to hash the value before calling this function.

addLiquidityTo_noMinProtection

function addLiquidityTo_noMinProtection(
        bytes32 method,
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        address to
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity)

The same as addLiquidity_noMinProtection except that the "to" address gets the liquidity token instead and the FCT_Runner

swap_noSlippageProtection

function swap_noSlippageProtection(
        uint256 amount,
        bytes32 method,
        address[] calldata path
    )
        external
        returns (
            uint256 amountIn,
            uint256 amountOut,
            address tokenIn,
            address tokenOut,
            bytes32 pathHash
        )

Swaps tokens or eth directly from the FCT_Runner without any slippage protection, meaning that the actual amounts that will be used are not assured (except the amount that was defined as "exact" according to the chosen method)

Method

The method field indicates what type of assets to use and whether the input or output amount will be assured (exact value)

Method can be used as string or as bytes32 in the EIP712 FCT message. When string is used the FCT engine can be informed to hash the value before calling this function.

swapTo_noSlippageProtection

function swapTo_noSlippageProtection(
        uint256 amount,
        bytes32 method,
        address recipient,
        address[] calldata pathIn
    )
        public
        returns (
            uint256 amountIn,
            uint256 amountOut,
            address tokenIn,
            address tokenOut,
            bytes32 pathHash
        )

The same as swap_noSlippageProtection except that the "to" address gets the liquidity token instead and the FCT_Runner

simulateSwap

function simulateSwap(
        uint256 amount,
        bytes32 method,
        address[] calldata pathIn
    )
        external
        view
        returns (
            uint256 amountIn,
            uint256 amountOut,
            address tokenIn,
            address tokenOut,
            bytes32 pathHash
        )

The same as swap_noSlippageProtection except that the actual swap is not executed.

It is safe to run swap_noSliipageProtection directly after simulateSwap (on the same FCT), using the same inputs, the values will be the same.

Last updated