Skip to content

feat: VRC-20 AMM / liquidity pool backend#1

Draft
HuciferX wants to merge 2 commits into
masterfrom
feat/vrc20-amm-backend
Draft

feat: VRC-20 AMM / liquidity pool backend#1
HuciferX wants to merge 2 commits into
masterfrom
feat/vrc20-amm-backend

Conversation

@HuciferX

@HuciferX HuciferX commented Jun 8, 2026

Copy link
Copy Markdown
Owner

VRC-20 AMM / Liquidity Pool Backend

Implements the complete AMM backend for VRC-20/VTC and Rune/VTC trading pairs, following the virtual reserve model from docs/VRC20_AMM_SPEC.md.

New files (src/amm/)

pool.ts — Core constant product AMM (x × y = k)

  • createPool(), getQuote(), getQuoteReverse() with fee deduction and price impact
  • addLiquidity() / removeLiquidity() with proportional LP token minting/burning
  • Queue impact pricing: adjusts effective reserves based on seller queue depth
  • Fee distribution: 80% to LPs, 20% to protocol treasury

queue.ts — Seller queue management (FIFO matching)

  • joinQueue() / leaveQueue() with escalating slashing (50% → 70% → 90% within 100 blocks)
  • processSwap() — matches buyer with queue sellers, VTC flows directly to sellers
  • Rate limiting: max 24 swaps per block per pool

reservation.ts — Two-phase commit system

  • Phase 1: createReservation() locks price for 5 blocks (~12.5 min)
  • Phase 2: executeReservation() completes swap at locked price (prevents front-running)
  • Automatic expiration and cleanup

router.ts — Multi-hop routing

  • findBestRoute() supports VTC↔Token and Token↔VTC↔Token paths
  • Combined price impact calculation across hops

index.ts — Express REST API router with all endpoints

  • Pool CRUD, quotes, two-phase swaps, liquidity operations, queue management
  • Mount with: app.use("/api", ammRouter)

Storage

In-memory Map for all state — designed to be swapped to MongoDB later.

Validation

  • TypeScript compiles cleanly (tsc --noEmit)
  • End-to-end test: pool creation → quoting → liquidity → queue → reservation → multi-hop routing all pass

Conversation: https://app.warp.dev/conversation/3030e9ea-3e61-4f38-adb6-2811eed8fe03
Run: https://oz.warp.dev/runs/019ea499-40fb-75fc-bdc8-e86fadac2273
This PR was generated with Oz.

oz-agent added 2 commits June 7, 2026 20:24
- bondingCurve.ts: Exponential bonding curve with buy/sell/graduate mechanics
- feeDistributor.ts: Fee split 40/40/20 (creator/treasury/buyback)
- tokenCreator.ts: VRC-20 deploy + vtc-launch inscription generators
- index.ts: REST API endpoints for create, trade, price, graduate

Co-Authored-By: Oz <oz-agent@warp.dev>
Implements the complete AMM backend with:

- pool.ts: Constant product AMM (x*y=k), LP tokens, price impact,
  fee distribution (80% LP / 20% treasury), queue impact pricing
- queue.ts: Seller queue (FIFO matching), escalating slashing penalties
  (50/70/90%), rate limiting (24 swaps/block/pool)
- reservation.ts: Two-phase commit swap system with 5-block TTL,
  price locking to prevent front-running
- router.ts: Multi-hop routing (Token→VTC→Token) with combined
  price impact calculation
- index.ts: Express REST API router with all endpoints for pools,
  swaps, liquidity, queues, and reservations

All modules use in-memory Map storage (swappable to MongoDB).
Follows the VRC20_AMM_SPEC.md virtual reserve model.

Co-Authored-By: Oz <oz-agent@warp.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants