Developer notes for DIDLab Swap

Use these addresses and snippets to script swaps, monitor liquidity, or build dashboards on blockchain.didlab.org. All contracts run on chain ID 252501 with TRUST gas.

Swap snippet (ethers v6)

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://eth.didlab.org");
const router = new ethers.Contract(
  process.env.ROUTER!,
  ["function swapExactTokensForTokens(uint256,uint256,address[],address,uint256) returns (uint256[])"],
  new ethers.Wallet(process.env.PRIVATE_KEY!, provider)
);

async function swapLabToTt(amountLab) {
  const deadline = Math.floor(Date.now() / 1000) + 600;
  const path = [process.env.LABUSDT!, process.env.TT!];
  const amountIn = ethers.parseUnits(amountLab, 6); // LabUSDT decimals
  const minOut = (amountIn * 99n) / 100n; // 1% slippage buffer
  return router.swapExactTokensForTokens(amountIn, minOut, path, process.env.WALLET!, deadline);
}

Replace environment variables with the addresses above. Always approve the router for TT or LabUSDT before invoking the swap.

Add liquidity snippet

const router = new ethers.Contract(
  process.env.ROUTER!,
  ["function addLiquidity(address,address,uint256,uint256,uint256,uint256,address,uint256) returns (uint256,uint256,uint256)"],
  signer
);

const ttAmount = ethers.parseUnits("1000", 18);
const labAmount = ethers.parseUnits("1000", 6);
const deadline = Math.floor(Date.now() / 1000) + 600;

await router.addLiquidity(
  process.env.TT!,
  process.env.LABUSDT!,
  ttAmount,
  labAmount,
  ttAmount * 99n / 100n,
  labAmount * 99n / 100n,
  signer.address,
  deadline
);

Mint equal-value deposits. To remove liquidity, call removeLiquidity with your LP tokens and slippage-protected minimums.

Monitoring checklist

  • Poll getReserves() on the pair contract to watch price changes.
  • Track LP total supply to measure inflows/outflows of classroom liquidity.
  • Log swap events for dashboards via the factory’s PairCreated and pair’s Swap events.
  • Run node ops/check-services.mjs before class to confirm RPC, explorer, faucet, and portal health.

Keep faucet balances topped up and document any redeployments so config.addresses.json stays canonical.