Back to AMM: Automated Market Maker
The AMM feature introduces seven new transaction types to the XRP Ledger. Each transaction follows the standard transactor pattern (preflight, preclaim, doApply) covered in Module 02.
This chapter details each transaction type, its validation phases, flags, and execution logic.
Transaction Type Overview
Transaction
Type Code
Purpose
Remove liquidity from pool
Issuer clawback from pool
Location: include/xrpl/protocol/detail/transactions.macro
Creates a new AMM pool for a pair of assets.
Location: src/xrpld/app/tx/detail/AMMCreate.cpp
Transaction Fields
Initial trading fee (0-1000 basis points)
Static validation before ledger access:
Validation with ledger read access:
Execution with ledger modifications:
Reserve Requirements
Creating an AMM requires reserve for:
2-3 trustlines (Asset1, Asset2, and potentially LP token)
Adds liquidity to an existing AMM pool in exchange for LP tokens.
Location: src/xrpld/app/tx/detail/AMMDeposit.cpp
AMMDeposit supports multiple modes controlled by flags:
Flag
Required Fields
Description
Deposit proportional amounts for exact LP tokens
Deposit single asset (trading fee charged)
Deposit both with maximum constraints
Single asset for exact LP tokens
Single asset with price limit
Initialize empty pool (special case)
Transaction Fields
First asset issue (identifies pool)
Second asset issue (identifies pool)
Second asset amount to deposit
Minimum LP tokens to receive
doApply() - Proportional Deposit
doApply() - Single Asset Deposit
Removes liquidity from an AMM pool by burning LP tokens.
Location: src/xrpld/app/tx/detail/AMMWithdraw.cpp
Withdrawal Modes
Flag
Required Fields
Description
Burn LP tokens for proportional assets
Withdraw single asset (trading fee charged)
Withdraw specific amounts of both
Withdraw single asset for exact LP tokens
Withdraw all LP as single asset
Withdraw all LP tokens proportionally
doApply() - Proportional Withdrawal
Allows LP token holders to vote on the trading fee.
Location: src/xrpld/app/tx/detail/AMMVote.cpp
Transaction Fields
First asset issue (identifies pool)
Second asset issue (identifies pool)
Proposed fee (0-1000 basis points)
Voting Mechanics
Bid for the auction slot to receive discounted trading fees.
Location: src/xrpld/app/tx/detail/AMMBid.cpp
Transaction Fields
First asset issue (identifies pool)
Second asset issue (identifies pool)
Minimum bid amount (LP tokens)
Maximum bid amount (LP tokens)
Up to 4 accounts to authorize
Auction Slot States
Empty: No current holder, minimum bid applies
Occupied: Holder with >= 5% time remaining
Tailing: Holder with < 5% time remaining (easier to outbid)
Deletes an empty AMM pool (LP token balance = 0).
Location: src/xrpld/app/tx/detail/AMMDelete.cpp
Transaction Fields
First asset issue (identifies pool)
Second asset issue (identifies pool)
Deletion Process
Incremental Deletion
For pools with many trustlines (from LP token holders), deletion happens incrementally:
Each AMMDelete removes a limited number of trustlines
Transaction returns tecINCOMPLETE if more remain
Submitter must retry until fully deleted
Allows asset issuers to clawback their tokens from AMM pools.
Location: src/xrpld/app/tx/detail/AMMClawback.cpp
featureAMMClawback amendment must be enabled
Caller must be the issuer of the asset being clawed back
Issuer must have lsfAllowClawback flag set
Transaction Fields
LP account to clawback from
Specific amount (or all if omitted)
Clawback Process
AMM transactions can return specific error codes:
Insufficient pool balance
General AMM operation failure
Deposit constraints not met
Vote failed (weight too low)
Withdrawal constraints not met
Invalid LP token operation
Cannot delete non-empty pool
The seven AMM transaction types provide complete lifecycle management:
AMMCreate: Initialize pools with two assets
AMMDeposit: Add liquidity (multiple modes)
AMMWithdraw: Remove liquidity (multiple modes)
AMMVote: Govern trading fees
AMMBid: Compete for reduced fees
AMMDelete: Clean up empty pools
AMMClawback: Regulatory compliance for issuers
Each follows the standard transactor pattern (preflight, preclaim, doApply) ensuring consistent validation and execution.
References to Source Code
src/xrpld/app/tx/detail/AMMCreate.cpp
src/xrpld/app/tx/detail/AMMDeposit.cpp
src/xrpld/app/tx/detail/AMMWithdraw.cpp
src/xrpld/app/tx/detail/AMMVote.cpp
src/xrpld/app/tx/detail/AMMBid.cpp
src/xrpld/app/tx/detail/AMMDelete.cpp
src/xrpld/app/tx/detail/AMMClawback.cpp
include/xrpl/protocol/detail/transactions.macro
Cross-References
AMM Logic - Formulas used in deposit/withdraw