Telegram DEX Trading Terminals: STON.fi & DeDust Routing, Limit Orders, and Sniping Bot APIs
Build enterprise-grade decentralized exchange (DEX) trading terminals directly inside Telegram Mini Apps. Learn how to aggregate liquidity across STON.fi and DeDust AMM pools, protect traders against malicious front-running and MEV sandwich attacks, construct raw Bag of Cells (BOC) payloads, and execute sub-second limit order swaps over TON Connect 2.0.
hub Why Embedded Telegram DEXs Outperform Web Terminals
Traditional decentralized exchange interfaces require desktop web browsers, third-party wallet browser extensions, and repetitive approval prompts that cause traders to miss fast-moving price breakouts. By embedding DEX terminals inside Telegram Mini Apps, traders receive real-time price alerts in chat, click an inline link, and execute non-custodial swaps with pre-authorized TON Connect session keys in less than two seconds.
account_tree 1. Telegram DEX Terminal Pipeline
Executing reliable, low-slippage swaps inside Telegram requires coordinating four high-frequency infrastructure layers.
1. Mempool Liquidity Aggregator
Query live pool reserves across STON.fi v2 and DeDust simultaneously. Split large volume trades across multiple liquidity pools to minimize market price impact.
2. Slippage & MEV Guard
Set tight min_ask_amount parameters to ensure that if a sandwich bot attempts to front-run the trade, the contract automatically aborts and returns funds safely.
3. TON Connect 2.0 BOC Signer
Compile the swap message into a binary Bag of Cells (BOC) and dispatch it via TON Connect. The user's mobile wallet signs the transaction with biometrics in one tap.
4. Real-Time Settlement Telemetry
Track block confirmations over TonAPI WebSocket streams, push dynamic PnL updates to the user's chat, and update portfolio balances instantly.
TON DEX Swap Slippage & Routing Simulator
code 2. Constructing the STON.fi Swap Cell in TypeScript
Mini-App trading bots construct binary smart contract swap payloads using @ton/core and pass them directly to the TON Connect provider.
// Construct STON.fi Swap Forward Payload in TypeScript
import { beginCell, toNano, Address } from "@ton/core";
export function buildDexSwapMessage(
jettonToReceive: Address,
minAskAmount: bigint,
recipientAddress: Address
) {
const forwardPayload = beginCell()
.storeUint(0x25938561, 32) // STON.fi swap op code
.storeAddress(jettonToReceive)
.storeCoins(minAskAmount)
.storeAddress(recipientAddress)
.storeUint(0, 1) // has_ref
.endCell();
return {
validUntil: Math.floor(Date.now() / 1000) + 300, // 5 min TTL
messages: [
{
address: "EQB3ncyBUTjZUA5EnFKR5_ioIppmErdr2o79wpNTsvOcVCwU", // Router
amount: toNano("0.3").toString(), // Gas attachment
payload: forwardPayload.toBoc().toString("base64")
}
]
};
}
task_alt 3. Production Trading Bot Checklist
- Short Transaction TTL: Never set transaction validity longer than 3 minutes to avoid stale executions after sharp market reversals.
- Excess Gas Refund: Always specify the user's personal wallet address in the response address field so unspent gas returns automatically.
- Private RPC Endpoints: Route high-speed sniping transactions through private TON Lite-Servers to bypass public node mempool congestion.
- Zero-Spread Split Routing: Automatically partition trades over $1,000 USD across both STON.fi and DeDust to secure optimal blended execution prices.
One-Page Technical Summary Infographic
Click the poster below to inspect the complete 4-tier trading engine: mempool liquidity aggregator, MEV sandwich guard, TON Connect 2.0 batch signer, and real-time on-chain execution telemetry.