Providing Liquidity To Classic Pools
Add/Remove Liquidity From Classic Pools
Pool creation
In some cases, your contract may be instantiating a new pool for a token pair. This can be done by calling the router's createPool function.
Example
Create a new DAI-USDC pool with amplification factor of 50. Refer to this section to understand more about the amplification factor.
Kindly note the following:
The token addresses are interchangeable, ie.
dmm.createPool(usdc, dai, 50000)
yields the same result.There can be at most 1 unamplified pool for a token pair, ie. only 1 pool can exist with
ampBps = BPS (10000)
. Should there already be an existing unamplified pool, attempts to create another one will fail.
Adding liquidity
To safely add liquidity to a pool, we recommend using the router. There are different functions for adding liquidity to existing pools or creating a new pool, and if the token pair is ERC20-ERC20, or ETH-ERC20.
These methods both require committment 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 utilised as a sanity buffer as the market price may shift drastically before the transaction is confirmed.
Determining the appropriate pool
See this section on pool selection.
Examples
Create a new ERC20-ERC20 pool with amplification factor 100
Add liquidity to an existing ERC20-ERC20 with FoT pool
Creation and liquidity provision to ERC20-ETH pools are similar, with the only difference being the functions to be called.
New ERC20-ERC20 pool via addLiquidityNewPool
For new ERC20-ETH pool creations, the equivalent function is addLiquidityNewPoolETH.
Example: Create a new pool with 100 USDC and 100 USDT
Add to existing ERC20-ERC20 (FoT) pool via addLiquidity
Although CORE is a Fee-on-Transfer (FoT) token, it utilises the same function as adding liquidity to an existing ERC20-ERC20 pool. However, it is likely that the slippage tolerance will have to be adjusted to account for the token fee.
For adding liquidity to existing ERC20-ETH pools, the the equivalent function is addLiquidityETH.
Example: Add 1 CORE and 1000 USDT
Removing liquidity
As is the case with Uniswap LP tokens, DMM-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.
Removing LP tokens from ERC20-ERC20 pool
Removing 100 wbtc-usdt LP tokens via removeLiquidityWithPermit
Note: For FoT tokens like CORE, the same function can be used, but the minimum receivable of core tokens should be adjusted.
Removing LP tokens from ERC20-ETH pool
Removing 100 core-eth LP tokens via removeLiquidityETHWithPermitSupportingFeeOnTransferTokens
Last updated