V2 Router
The V2 Router provides helper functions for adding and removing liquidity from V2 pools. It handles token sorting, pair creation (if needed), and optimal deposit calculations.For swaps, use the Universal Router instead. The V2 Router is primarily used for liquidity operations.
Key Functions
addLiquidity
Adds liquidity to an ERC-20 / ERC-20 pair. Creates the pair if it doesn’t exist.| Parameter | Description |
|---|---|
tokenA, tokenB | Token addresses |
amountADesired, amountBDesired | Ideal amounts to deposit |
amountAMin, amountBMin | Minimum accepted (slippage protection) |
to | Recipient of LP tokens |
deadline | Transaction deadline (Unix timestamp) |
addLiquidityETH
Adds liquidity to a KAS / ERC-20 pair. Send native KAS asmsg.value.
removeLiquidity
Burns LP tokens and returns both underlying tokens.removeLiquidityETH
Burns LP tokens from a KAS pair and returns native KAS + ERC-20 token.ABI
Token Approval
Before callingaddLiquidity, approve both tokens to the V2 Router:
removeLiquidity, approve the LP token to the V2 Router: