Skip to main content
In this guide you add USDT and tBOT to the BDEX V2 WBOT/USDT pool on testnet, check what your LP tokens are worth, and remove the liquidity again.
Everything on this page uses testnet (chain 968). Get free test tokens from the faucet.

How V2 liquidity works

A V2 pool holds two tokens. When you add liquidity, you deposit both at the pool’s current ratio and receive LP tokens. The pair contract is itself the LP token. Your LP balance divided by the total supply is your share of the reserves. Every swap pays 0.30% into the reserves, so your share grows with trading volume. The price can move while you’re in the pool. When it does, you get back a different mix of the two tokens than you put in, which can be worth less than simply holding them. This is called impermanent loss.

What you’ll build

A viem script that reads the pool’s reserves, adds 0.02 USDT plus the matching amount of tBOT, prints the value of your LP tokens, then removes all of it.

Prerequisites

  • The bot-defi project and .env file from Wrap BOT.
  • At least 0.02 testnet USDT. Swap tBOT for it with Swap on BDEX V2.
  • Enough tBOT for the matching amount plus gas for four transactions. On 2026-10-01 the tBOT side was about 0.0012.

Steps

1

Write the script

liquidity-v2.ts
2

Understand each part

  • getPair returns the pair address. Pairs store their tokens sorted by address, so read token0 to know which reserve is which.
  • quote(amountA, reserveA, reserveB) returns the matching amount of the other token at the current ratio, with no fee. Use it for liquidity, never for swap quotes.
  • addLiquidityETH takes the token side as an argument and the tBOT side as value. The two minimums protect you if the ratio moves before your transaction lands. The router refunds any tBOT it doesn’t use.
  • Your share is lpBalance / totalSupply of each reserve.
  • removeLiquidityETH burns your LP tokens and sends both tokens back, unwrapping WBOT to tBOT. Approve the pair first, because the router moves your LP tokens.
3

Run it

Verify it worked

Output
You get back slightly less than you put in, because the pool’s math rounds down. The LP amount looks tiny because the pool pairs a 6-decimal token with an 18-decimal one. What it’s worth is what matters.

Troubleshooting

The pool ratio moved between your reserve read and your transaction, so one side fell below its minimum. Read the reserves again and retry.
The router couldn’t pull your tokens. Check the approval for the right token: USDT when adding, the pair address when removing.
The deadline passed. The script builds a fresh deadline for each call, so this only happens if a transaction waits more than 20 minutes.

Next steps

Provide V3 liquidity

Concentrate liquidity in a price range.

BDEX API

List pools and their reserves.
Last modified on October 2, 2026