Ready. This template is published in uzolabs/templates and has been deployed and verified on testnet. It’s a learning template and hasn’t been audited. Use test funds only.
Project layout
Project layout
frontend/src/dex/, so a quote in the terminal and a quote in the browser come from the same code. There are no contracts.
Finding pools
Terminal
Output
getPair on the V2 factory and getPool on the V3 factory once per fee tier. Not every tier has a pool, and some hold very little.
Quotes
Terminal
Output
- V2 quotes come from Router02’s
getAmountsOut. - V3 quotes come from QuoterV2’s
quoteExactInputSingle. It isn’t a view function: it runs the swap and reverts with the result. The template calls it with viem’ssimulateContract, which useseth_call, so nothing is sent.
BOT and WBOT
Pools hold ERC-20 tokens. BOT isn’t one, so pools trade WBOT, which is always worth exactly 1 BOT.
“ETH” in the router function names means the chain’s native coin, which is BOT here.
Slippage, deadline and approvals
- Slippage. The minimum you accept is the quote minus your slippage, 0.5% by default and at most 5%. If the pool would give less, the swap reverts and you only lose gas.
- Deadline. Each swap carries a deadline 20 minutes ahead, so a transaction stuck in the mempool can’t fill hours later.
- Approvals. Before swapping a token, the script approves the router for exactly the trade amount. Router02 and SwapRouter each need their own approval. If enough is already approved, the script skips that step.
- Decimals. USDT has 6 decimals and BOT and WBOT have 18. Every amount goes through
parseUnits(amount, token.decimals). See USDT and decimals.
A swap from the terminal
Terminal
Output
The widget
“What you got” is your balance after the block minus your balance before it. If a transaction reverted on chain, the widget replays it on the block before to get the router’s reason. It never reads event logs, because BOT Chain’s public RPCs don’t serve
eth_getLogs.
Next steps
Customize
Change slippage, add tokens and routes.
Slippage and deadlines
How the minimum and deadline protect a swap.