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.
1
// Note: assume that usdc and usdt token approvals have been given to router
2
// and that transferFrom has been called to transfer tokens to contract from user
3
4
// the vReserveRatioBounds below is set to the absolute minimum and maximum values as an example
5
// it is recommended to read the virtual reserve ratio and set the appropriate values from that
6
vReserveRatioBounds = new uint256[2];
7
(vReserveRatioBounds[0], vReserveRatioBounds[1]) = (0, -1);
8
buniCornRouter.addLiquidity(
9
usdc,
10
usdt,
11
usdc-usdt-pool, // usdc-usdt pool address
12
1000 * 1e18, // 1000 usdc
13
1000 * 1e18, // 1000 usdt
14
999 * 1e18, // 0.1% slippage tolerance (999 usdc / 1000 usdt)
15
999 * 1e18, // 0.13% slippage tolerance (1000 usdc / 999 usdt)
16
vReserveRatioBounds
17
);
Copied!

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.
1
buniCornRouter.removeLiquidityWithPermit(
2
usdc,
3
usdt,
4
usdc-usdt-pool, // usdc-usdt pool address
5
100 * 1e18, // 100 usdc-usdt LP tokens
6
100 * 1e18, // Min receivable of 100 usdc
7
100 * 1e18, // Min receivable of 100 usdt
8
msg.sender, // send assets to msg.sender
9
block.timestamp, // deadline
10
approveMax, // boolean flag if max token allowance approval
11
v, // approve permit signature field
12
r, // approve permit signature field
13
s // approve permit signature field
14
);
Copied!

Last modified 3mo ago