Providing Liquidity

Adding Liquidity

To safely add liquidity to a pool, we recommend using the router. Adding liquidity function requires commitment to a belief about the current price, which is encoded in the amount*Desired parameters. While it is fairly safe to assume that the current fair market price is around what the current reserve ratio is for a pair due to arbitrage, it is dangerous to obtain this ratio within the same transaction as it can be easily manipulated.

In addition, the amount*Min and vReserveRatioBounds parameters should be utilized as a sanity buffer as the market price may shift drastically before the transaction is confirmed.

// Note: assume that usdc and usdt token approvals have been given to router
// and that transferFrom has been called to transfer tokens to contract from user

// the vReserveRatioBounds below is set to the absolute minimum and maximum values as an example
// it is recommended to read the virtual reserve ratio and set the appropriate values from that 
vReserveRatioBounds = new uint256[2];
(vReserveRatioBounds[0], vReserveRatioBounds[1]) = (0, -1);
    usdc-usdt-pool, // usdc-usdt pool address
    1000 * 1e18, // 1000 usdc
    1000 * 1e18, // 1000 usdt
    999 * 1e18, // 0.1% slippage tolerance (999 usdc / 1000 usdt)
    999 * 1e18, // 0.13% slippage tolerance (1000 usdc / 999 usdt)

Removing Liquidity

As is the case with Uniswap LP tokens, Bunicorn Stable LP tokens implement meta-approvals to vastly help improve UX and save on gas costs. Hence, we recommend the usage of the removeLiquidity*withPermit* functions.

    usdc-usdt-pool, // usdc-usdt pool address
    100 * 1e18, // 100 usdc-usdt LP tokens
    100 * 1e18, // Min receivable of 100 usdc
    100 * 1e18, // Min receivable of 100 usdt
    msg.sender, // send assets to msg.sender
    block.timestamp, // deadline
    approveMax, // boolean flag if max token allowance approval
    v, // approve permit signature field
    r, // approve permit signature field
    s // approve permit signature field

Last updated