Skip to main content

Outcome

A Telegram bot in TypeScript that lets a user /buy <token> or /sell <token>, quotes via Velora mode=ALL, surfaces slippage and price impact, and executes via Delta when available (gasless, MEV-protected). Falls back to Market with a conservative slippage when Delta is unavailable.

Prompt

You are building a Telegram bot in TypeScript using `grammy` or `telegraf`. The bot has access to a user's connected EVM wallet via a custodied key tied to chat id (assume the wallet infra is solved; just call `signMessage` and `signTransaction`).

Implement `/buy <symbol_or_address> <amount_in_usd>` and `/sell <symbol_or_address> <amount_in_usd>`.

Requirements:
- Resolve token addresses against Velora's tokens endpoint (`/tokens/:chainId`).
- Quote with `mode=ALL` at `GET https://api.velora.xyz/v2/quote`. Always set `partner` to the bot's partner identifier (`my-app-name` is only a placeholder). Native ETH placeholder: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`.
- Show the user `destAmount`, `destUSD`, `gasCostUSD`, and `priceImpact` BEFORE asking them to confirm.
- If `response.delta` exists, prefer the Delta path: build → sign EIP-712 → submit → poll. The user pays no gas.
- If only `response.market` exists, fall back to Market with `slippage=100` (1%) and warn the user about MEV exposure on larger trades (size > $5k).
- Include the `priceImpact` warning at >2%.

Reference these docs and follow them exactly:
- https://velora.xyz/docs/overview/why-velora
- https://velora.xyz/docs/api-reference/market/prices
- https://velora.xyz/docs/api-reference/market/quote
- https://velora.xyz/docs/api-reference/delta/orders-build
- https://velora.xyz/docs/api-reference/delta/orders-submit

Do NOT auto-execute trades without explicit user confirmation. Do NOT swallow Delta polling errors silently.

End-state check

  • A /buy flow on a $1k trade routes through Delta and settles gaslessly within the lifecycle window.
  • On a tiny test trade where Delta returns no quote, Market is used with the slippage and MEV warning surfaced.
Last modified on June 14, 2026