← Back to learning hubGuide · Automated Market Makers

AMM fundamentals for DIDLab Swap.

DIDLab Swap mirrors Uniswap v2 mechanics. Liquidity providers deposit equal-value amounts of LabUSDT and TrustToken (TT) to mint LP tokens. Traders route through the router contract, paying fees to the pool and adjusting the price along the x·y = k curve.

x·y = k in plain English

The TT/LabUSDT pool keeps the product of reserves constant. When a trader adds LabUSDT, the pool must remove TT to maintain k. The execution price equals the slope of the curve between the start and end points.

Initial: TT = 100,000 · LabUSDT = 100,000 → k = 10,000,000,000
Swap 1,000 LabUSDT in → new LabUSDT = 101,000
Solve for TT: TT = k / LabUSDT ≈ 99,009.9
Trader receives ≈ 990.1 TT minus 0.3% fee to LPs

TrustToken stays 18 decimals, LabUSDT is 6 decimals. The router handles precision so you can focus on the swap logic.

Slippage, approvals, and WTRUST

  • Approvals: Before swapping, approve the router to spend LabUSDT or TT. The UI tracks allowance and prompts once.
  • Slippage: Set a tolerance that matches the classroom activity. The UI shows min received so students avoid surprised fills.
  • WTRUST tooltip: WTRUST = Wrapped TRUST. It appears whenever pools need the native TRUST asset.
  • Impermanent loss: Teach LPs that price divergences between TT and LabUSDT can reduce their LP token value until fees offset it.

Keep faucets topped up so students always have TRUST for gas and TT for trading exercises.

Classroom exercises

  1. Approve LabUSDT, swap into TT, and verify the transaction hash on Blockscout.
  2. Provide equal-value liquidity, capture the LP token mint event, and record pool share.
  3. Trigger a swap that moves the price and calculate slippage manually from reserves.
  4. Remove liquidity and compare net TT/LabUSDT returns versus a hold strategy to demonstrate impermanent loss.

More resources

Document manual checks—faucet drip, pair reserves, Blockscout indexing—before each class.