feat: VRC-20 AMM / liquidity pool backend#1
Draft
HuciferX wants to merge 2 commits into
Draft
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 impactaddLiquidity()/removeLiquidity()with proportional LP token minting/burningqueue.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 sellersreservation.ts — Two-phase commit system
createReservation()locks price for 5 blocks (~12.5 min)executeReservation()completes swap at locked price (prevents front-running)router.ts — Multi-hop routing
findBestRoute()supports VTC↔Token and Token↔VTC↔Token pathsindex.ts — Express REST API router with all endpoints
app.use("/api", ammRouter)Storage
In-memory
Mapfor all state — designed to be swapped to MongoDB later.Validation
tsc --noEmit)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.