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.
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.
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
vReserveRatioBounds parameters should be utilised as a sanity buffer as the market price may shift drastically before the transaction is confirmed.
- 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.
For new ERC20-ETH pool creations, the equivalent function is addLiquidityNewPoolETH.
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.
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
Note: For FoT tokens like CORE, the same function can be used, but the minimum receivable of core tokens should be adjusted.