Buying and selling
Wallet executes; API indexes the receipt.
Execute buys and sells on-chain first. Then call POST /buy or POST /sell with the tx hash so the API indexes the trade.
ETH on the curve
tsbuySellEth.ts
import { parseEther, parseAbi } from "viem";
const routerAbi = parseAbi([
"function buy(address curve, uint256 minTokensOut) payable",
"function sell(address curve, uint256 tokenAmount, uint256 minEthOut)",
]);
// Buy with ETH
await walletClient.writeContract({
address: "0xf4070f50Aed754c12d781d21de9986742017A2B8" as `0x${string}`,
abi: routerAbi,
functionName: "buy",
args: [curveAddress, minTokensOut],
value: parseEther("0.1"),
});
// Sell tokens back to the curve (approve Router/curve first if required by your path)
await walletClient.writeContract({
address: "0xf4070f50Aed754c12d781d21de9986742017A2B8" as `0x${string}`,
abi: routerAbi,
functionName: "sell",
args: [curveAddress, tokenAmount, minEthOut],
});USDG on the curve (LaunchZap)
Requires LaunchZap configured (0xbb0AC5E8910e525B84c014973F10f5595076D951 when set). Approve USDG to LaunchZap, then:
tsbuySellUsdg.ts
import { parseAbi } from "viem";
const zapAbi = parseAbi([
"function buyCurveWithUsdg(address curve, uint256 usdgIn, uint256 minWethOut, uint256 minTokensOut, uint24 usdgWethFee) returns (uint256 tokensOut)",
"function sellCurveForUsdg(address curve, uint256 tokenAmount, uint256 minEthOut, uint256 minUsdgOut, uint24 wethUsdgFee) returns (uint256 usdgOut)",
]);
const usdgWethFee = 3000; // Uniswap V3 pool fee tier used by the zap
await walletClient.writeContract({
address: "0xbb0AC5E8910e525B84c014973F10f5595076D951" as `0x${string}`,
abi: zapAbi,
functionName: "buyCurveWithUsdg",
args: [curveAddress, usdgIn, minWethOut, minTokensOut, usdgWethFee],
});Sync the receipt
bashsync-buy.sh
curl -sS -X POST "${API_URL}/buy" \
-H "authorization: Bearer $JWT" \
-H "content-type: application/json" \
-d '{
"token": "0xToken",
"amount": "1000000000000000000",
"txHash": "0x…"
}'After graduation, use Uniswap V4 Universal Router for ETH swaps (USDG tab is disabled for V4 tokens in the Trancepad UI). Local Anvil may use SimpleDEX instead.