🤖 Build a GalaSwap Arbitrage Bot — Starter Brief
Best way to build this: use the GalaChain Builder omni-tool in Claude (the agent wired to the 247-tool GalaChain MCP server) — it teaches and scaffolds GalaChain apps for you. Paste this brief into it and say "help me build this step by step."
You're building an arbitrage bot that trades on GalaSwap (the concentrated-liquidity DEX on GalaChain, Uniswap-v3 style) and captures price gaps CEX↔DEX and DEX↔DEX. Teach me and build with me across these areas:
0. Tooling — start here
- Drive the build with the GalaChain Builder omni-tool / MCP server (247 tools): it exposes the chain's contract + gateway surface directly, so you skip the endpoint guesswork and get correct request shapes, signing, and pool reads out of the box.
1. Market structure
- GalaSwap pools are v3-style: tick-based, concentrated liquidity, multiple fee tiers (0.05% / 0.30% / 1%). Price = 1.0001^tick; pools expose sqrtPrice, tick, liquidity.
- On-chain assets are bridged wrappers (GWBTC, GWETH, GUSDC, GALA…). The wrapper price can dislocate from the CEX spot of the underlying — that gap is the edge.
2. Data ingest (real-time)
- CEX side: subscribe to WebSocket order-book + trade streams (don't poll REST for prices — you'll be late and rate-limited). Maintain a local L2 book; compute net bid/ask after taker fees.
- DEX side: read pool state via the MCP tools / GalaChain gateway — GetCompositePool (sqrtPrice/tick/liquidity), GetUserPositions, FetchBalances. Pull TVL/volume from the explore-pools backend. Gotcha: tick can come back null — derive it: tick = round(2·ln(sqrtPrice)/ln(1.0001)).
- Timestamp and health-check every feed; never trade on stale data.
3. Pricing the trade correctly
- DEX effective price must include slippage for your size (walk the liquidity, not just spot) + the pool fee tier + protocol take.
- CEX side nets taker fees + withdrawal cost.
- Edge = CEX_net − DEX_effective (or DEX↔DEX) after all costs. If it's not clearly positive past costs, it's not a trade.
4. Bridging (the part that kills naive bots)
- Moving assets on/off GalaChain via the bridge has latency and fees — you can't bridge per-trade and stay profitable.
- Pre-position inventory on BOTH venues and rebalance in batches. Treat the bridge as a slow settlement layer, not part of the hot path.
5. Execution best practices
- WebSockets > polling everywhere it's offered.
- Hard slippage limits and a fair-value guard (never sell an asset below its true CEX value — discipline beats greed).
- Idempotent order handling, partial-fill logic, on-chain nonce/bundle management, retries with backoff.
- Latency budget end-to-end; a stale quote is a loss.
- Inventory + risk caps, a kill switch, and per-trade loss limits.
- Secure keys (never in code/logs), sign server-side, rate-limit aware.
6. Validate before going live
- Backtest on real measured data only (record live feeds; no synthetic guesses).
- Paper-trade the full loop, then go live tiny, scale on proven PnL.
Start by asking the GalaChain Builder to map the gateway/MCP endpoints and stand up the two data feeds (CEX WebSocket + DEX pool poller), then layer pricing → edge detection → execution → risk.
#GalaChain #GalaSwap #DeFi #algotrading #arbitrage