AMM Architecture
Back to AMM: Automated Market Maker
Introduction
The XRP Ledger's AMM implementation introduces a sophisticated architecture that coexists with the traditional Central Limit Order Book (CLOB). Unlike simple AMM designs, XRPL's implementation includes governance mechanisms (fee voting), auction slots for reduced fees, and deep integration with the pathfinding engine.
This chapter explores the core data structures, the pseudo-account model, LP token design, and how these components interact to provide decentralized liquidity.
Core Concepts
What is an AMM?
An Automated Market Maker is a decentralized exchange mechanism that uses a mathematical formula to price assets. Instead of matching buyers and sellers through an order book, AMMs use liquidity pools where:
Liquidity Providers (LPs) deposit pairs of assets into pools
Traders swap one asset for another against the pool
Prices are determined algorithmically based on pool balances
Fees are distributed to LPs proportionally to their ownership
XRPL AMM vs. Traditional AMMs
Formula
x * y = k
x * y = k (same)
Fee Model
Fixed fee
Governance-voted fee
Fee Discount
None
Auction slot mechanism
Order Book
Separate
Integrated with CLOB
LP Tokens
ERC-20
Native XRPL tokens
Pathfinding
External
Native integration
The ltAMM Ledger Entry
Every AMM pool is represented by an ltAMM ledger entry (type 0x0079). This entry stores the pool configuration, current state, and governance data.
Location: include/xrpl/protocol/detail/ledger_entries.macro
Structure
Field Details
sfAccount - The pseudo-account that holds pool assets. This is a special account created during AMMCreate with no signing keys.
sfTradingFee - Current trading fee in basis points (1/100th of a percent). Range: 0-1000 (0% to 1%). Determined by weighted LP voting.
sfLPTokenBalance - Total LP tokens outstanding. Represents total pool ownership claims.
sfAsset / sfAsset2 - The two assets in the pool. Always ordered: Asset < Asset2 (lexicographic ordering ensures uniqueness).
Keylet Access
Location: include/xrpl/protocol/Keylet.h
Pseudo-Account Architecture
Each AMM pool operates through a pseudo-account - a special XRPL account with unique properties.
Characteristics
No Master Key: The account's master key is disabled (cannot sign transactions)
AMM-Controlled: Only AMM transactors can modify its state
Holds Assets: Contains trustlines for both pool assets and LP tokens
Identified by sfAMMID: AccountRoot contains
sfAMMIDfield linking to ltAMM
Creation Process (in AMMCreate)
Security Model
The pseudo-account design ensures:
No External Control: Without signing keys, no one can directly transact from this account
Protocol-Only Access: Only AMM transactors (AMMDeposit, AMMWithdraw, etc.) can modify balances
Trustline Isolation: Pool assets are isolated in dedicated trustlines
LP Token Design
LP (Liquidity Provider) tokens represent fractional ownership of pool assets. XRPL implements them as native tokens with a special currency code.
Currency Code Structure
Location: src/xrpld/app/misc/AMMUtils.cpp
LP Token Properties
Currency Code
0x03 prefix + 19-byte hash
Issuer
AMM pseudo-account
Precision
16 significant digits
Transferable
Yes (standard trustlines)
Tradeable
Yes (can be traded on DEX)
Initial LP Token Calculation
When a pool is created, the initial LP token balance is:
This geometric mean ensures the initial LP tokens represent equal value from both assets.
Code Reference: src/xrpld/app/misc/AMMHelpers.cpp:5-17
VoteSlots: Fee Governance
LPs can vote on the trading fee through the sfVoteSlots array. This implements decentralized governance for pool parameters.
Purpose and Use Cases
Why Governance-Voted Fees?
Unlike traditional AMMs with fixed fees (e.g., Uniswap's 0.3%), XRPL allows LPs to collectively decide the optimal fee for their pool. This enables:
Market-Driven Optimization: Volatile pairs may need higher fees; stable pairs can have lower fees
Competitive Positioning: LPs can adjust fees to attract more trading volume
Risk Compensation: Higher fees for riskier asset pairs
When to Use AMMVote:
You hold LP tokens and want to influence the pool's trading fee
You believe the current fee is too high (reducing volume) or too low (not compensating risk)
You want to align the pool's economics with market conditions
Structure
Voting Mechanics
Weight Calculation: Vote weight = (LP balance / Total LP tokens) * 100000
Fee Calculation: TradingFee = sum(weight_i * fee_i) / sum(weight_i)
Slot Management: If 8 slots full, new voter must have higher weight than lowest existing voter
Instant Effect: Fee changes immediately when votes are cast or LP balances change
Example Scenario
What happens when Eve (with 2,000 LP tokens) wants to vote?
Eve has more LP than Dave (500), so she can replace Dave's slot
New fee recalculates with Eve's vote instead of Dave's
AuctionSlot: Discounted Trading
The auction slot mechanism allows LPs to bid for reduced trading fees during a 24-hour period.
Purpose and Use Cases
Why Auction Slots?
The auction slot creates a market mechanism where those who benefit most from low fees pay for that privilege. This is particularly valuable for:
Arbitrage Bots: Need low fees to capture small price discrepancies
High-Frequency Traders: Volume traders where fees significantly impact profitability
Market Makers: Entities providing liquidity across multiple venues
When to Use AMMBid:
You plan to execute many trades against this pool in the next 24 hours
The fee savings from 0% trading outweigh the LP token cost
You want to authorize trading bots to use your discounted fee
Economic Design:
The auction creates revenue for LPs (bid payments are partially burned)
Competition for the slot ensures fair market pricing
Time decay prevents slot hoarding at low prices
Structure
Auction Mechanics
Time Division:
24-hour slot divided into 20 intervals (1.2 hours each)
Three states: Empty, Occupied (>=5% remaining), Tailing (<5% remaining)
Bidding Formula:
Refund Mechanism:
Example Scenario
Benefits
Slot Holder: Trades with discounted fee (often 0%)
AuthAccounts: Up to 4 additional accounts can use discounted fee
All LPs: LP tokens paid are partially burned, increasing LP token value
VoteSlots vs AuctionSlot: Key Differences
Purpose
Set trading fee for everyone
Get discounted fee for yourself
Slots
Up to 8
Exactly 1
Cost
Free (just hold LP tokens)
Pay LP tokens to win
Duration
Permanent (until vote changes)
24 hours
Benefit
Influence pool economics
Personal trading advantage
Who benefits
All pool users
Slot holder + 4 authorized
Transaction
AMMVote
AMMBid
Integration with Pathfinding
AMM pools don't just exist in isolation - they're deeply integrated with XRPL's pathfinding engine (covered in detail in AMM Pathfinding).
Key Integration Points
AMMLiquidity: Generates synthetic offers from AMM pools
AMMOffer: Represents an AMM-backed offer in payment paths
Quality Matching: AMM offers compete with CLOB offers on price
Dual Liquidity Model
AMM Amendment
The AMM feature is controlled by the featureAMM amendment.
Location: include/xrpl/protocol/detail/features.macro
Related Amendments
featureAMM
Core AMM functionality
fixUniversalNumber
Required precision improvements
fixAMMv1_1
Rounding bug fixes
fixAMMv1_2
Additional fixes
fixAMMv1_3
Precision loss compensation
fixAMMOverflowOffer
Offer generation overflow fix
featureAMMClawback
Asset issuer clawback support
Checking AMM Availability
Both amendments must be active for AMM functionality to work.
Summary
The XRPL AMM architecture combines:
ltAMM Ledger Entry: Stores pool state, governance, and auction data
Pseudo-Account: Holds pool assets securely without signing keys
LP Tokens: Native tokens representing pool ownership
VoteSlots: Decentralized fee governance by LPs
AuctionSlot: Reduced fee mechanism for active participants
Pathfinding Integration: Seamless liquidity alongside CLOB
This design enables sophisticated DeFi functionality while maintaining XRPL's performance and security characteristics.
References to Source Code
include/xrpl/protocol/detail/ledger_entries.macro- ltAMM definitionsrc/xrpld/app/misc/AMMHelpers.h- LP token calculationssrc/xrpld/app/misc/AMMUtils.cpp- Utility functionssrc/xrpld/app/tx/detail/AMMCreate.cpp- Pool creationinclude/xrpl/protocol/detail/features.macro- AMM amendmentssrc/xrpld/app/misc/AMMCore.h- Constants and core definitions
Cross-References
Module 02: Transactors - Transaction processing phases
Module 03: Ledger Data Structures - Ledger entry types
Module 09: Amendments - Feature activation
Last updated

