Integration Workflows
Discovering or Creating Pools
Call
factory.getPair(tokenA, tokenB).If it returns
address(0), callfactory.createPair(tokenA, tokenB)(tokens will be sorted).Alternatively, derive the address off-chain via
pair = address(uint(keccak256(abi.encodePacked(hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), INIT_CODE_PAIR_HASH))))and watch forPairCreated.
Adding Liquidity (token-token)
Use
router.getAmountsOutorWarpLibrary.quoteto decideamountAMin/amountBMin.IERC20(tokenA/B).approve(router, amountADesired/amountBDesired).Call
router.addLiquidity(...)and receive LP tokens into.Capture the returned
(amountA, amountB, liquidity)for accounting. For bonding-curve launchpads graduating to Warp,addLiquidityETHis typically the final step that pairs the emitted token with native ETH/WMEGAETH.
Removing Liquidity
Use
removeLiquidityorremoveLiquidityETHto withdraw, optionally signing a permit beforehand so the router can transfer LP tokens without a separate transaction.Integrations that tax transfers must route through the
SupportingFeeOnTransferTokensvariants to avoid shortfalls.
Swapping
Construct a
patharray (up to any length) of token addresses.Determine
amountIn/amountOutvia the helper methods.Approve the router for the first token (unless swapping from native ETH).
Call the appropriate swap function and monitor for
Swapevents emitted by each touched pair.Set
deadlineon every user call to avoid stuck transactions.
Last updated