AMM Transactions
Back to AMM: Automated Market Maker
Introduction
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
AMMCreate
35 (ttAMM_CREATE)
Create new AMM pool
AMMDeposit
36 (ttAMM_DEPOSIT)
Add liquidity to pool
AMMWithdraw
37 (ttAMM_WITHDRAW)
Remove liquidity from pool
AMMVote
38 (ttAMM_VOTE)
Vote on trading fee
AMMBid
39 (ttAMM_BID)
Bid for auction slot
AMMDelete
40 (ttAMM_DELETE)
Delete empty pool
AMMClawback
31 (ttAMM_CLAWBACK)
Issuer clawback from pool
Location: include/xrpl/protocol/detail/transactions.macro
AMMCreate
Creates a new AMM pool for a pair of assets.
Location: src/xrpld/app/tx/detail/AMMCreate.cpp
Transaction Fields
Amount
Yes
First asset to deposit
Amount2
Yes
Second asset to deposit
TradingFee
Yes
Initial trading fee (0-1000 basis points)
preflight()
Static validation before ledger access:
preclaim()
Validation with ledger read access:
doApply()
Execution with ledger modifications:
Reserve Requirements
Creating an AMM requires reserve for:
1 AMM pseudo-account
2-3 trustlines (Asset1, Asset2, and potentially LP token)
1 ltAMM ledger entry
AMMDeposit
Adds liquidity to an existing AMM pool in exchange for LP tokens.
Location: src/xrpld/app/tx/detail/AMMDeposit.cpp
Deposit Modes
AMMDeposit supports multiple modes controlled by flags:
tfLPToken
LPTokenOut
Deposit proportional amounts for exact LP tokens
tfSingleAsset
Amount
Deposit single asset (trading fee charged)
tfTwoAsset
Amount, Amount2
Deposit both with maximum constraints
tfOneAssetLPToken
Amount, LPTokenOut
Single asset for exact LP tokens
tfLimitLPToken
Amount, EPrice
Single asset with price limit
tfTwoAssetIfEmpty
Amount, Amount2
Initialize empty pool (special case)
Transaction Fields
Asset
Yes
First asset issue (identifies pool)
Asset2
Yes
Second asset issue (identifies pool)
Amount
Conditional
Asset amount to deposit
Amount2
Conditional
Second asset amount to deposit
LPTokenOut
Conditional
Minimum LP tokens to receive
EPrice
Conditional
Effective price limit
preflight()
doApply() - Proportional Deposit
doApply() - Single Asset Deposit
AMMWithdraw
Removes liquidity from an AMM pool by burning LP tokens.
Location: src/xrpld/app/tx/detail/AMMWithdraw.cpp
Withdrawal Modes
tfLPToken
LPTokenIn
Burn LP tokens for proportional assets
tfSingleAsset
Amount
Withdraw single asset (trading fee charged)
tfTwoAsset
Amount, Amount2
Withdraw specific amounts of both
tfOneAssetLPToken
Amount, LPTokenIn
Withdraw single asset for exact LP tokens
tfOneAssetWithdrawAll
Amount
Withdraw all LP as single asset
tfWithdrawAll
(none)
Withdraw all LP tokens proportionally
Key Validation
doApply() - Proportional Withdrawal
AMMVote
Allows LP token holders to vote on the trading fee.
Location: src/xrpld/app/tx/detail/AMMVote.cpp
Transaction Fields
Asset
Yes
First asset issue (identifies pool)
Asset2
Yes
Second asset issue (identifies pool)
TradingFee
Yes
Proposed fee (0-1000 basis points)
Voting Mechanics
Constants
AMMBid
Bid for the auction slot to receive discounted trading fees.
Location: src/xrpld/app/tx/detail/AMMBid.cpp
Transaction Fields
Asset
Yes
First asset issue (identifies pool)
Asset2
Yes
Second asset issue (identifies pool)
BidMin
No
Minimum bid amount (LP tokens)
BidMax
No
Maximum bid amount (LP tokens)
AuthAccounts
No
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)
Bidding Logic
Slot Constants
AMMDelete
Deletes an empty AMM pool (LP token balance = 0).
Location: src/xrpld/app/tx/detail/AMMDelete.cpp
Transaction Fields
Asset
Yes
First asset issue (identifies pool)
Asset2
Yes
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
tecINCOMPLETEif more remainSubmitter must retry until fully deleted
AMMClawback
Allows asset issuers to clawback their tokens from AMM pools.
Location: src/xrpld/app/tx/detail/AMMClawback.cpp
Prerequisites
featureAMMClawbackamendment must be enabledCaller must be the issuer of the asset being clawed back
Issuer must have
lsfAllowClawbackflag set
Transaction Fields
Holder
Yes
LP account to clawback from
Asset
Yes
Asset to clawback
Asset2
Yes
Other asset in pool
Amount
No
Specific amount (or all if omitted)
Clawback Process
Error Codes
AMM transactions can return specific error codes:
tecAMM_BALANCE
Insufficient pool balance
tecAMM_FAILED
General AMM operation failure
tecAMM_FAILED_BID
Bid too low
tecAMM_FAILED_DEPOSIT
Deposit constraints not met
tecAMM_FAILED_VOTE
Vote failed (weight too low)
tecAMM_FAILED_WITHDRAW
Withdrawal constraints not met
tecAMM_INVALID_TOKENS
Invalid LP token operation
tecAMM_NOT_EMPTY
Cannot delete non-empty pool
tecINCOMPLETE
Deletion in progress
Summary
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.cppsrc/xrpld/app/tx/detail/AMMDeposit.cppsrc/xrpld/app/tx/detail/AMMWithdraw.cppsrc/xrpld/app/tx/detail/AMMVote.cppsrc/xrpld/app/tx/detail/AMMBid.cppsrc/xrpld/app/tx/detail/AMMDelete.cppsrc/xrpld/app/tx/detail/AMMClawback.cppinclude/xrpl/protocol/detail/transactions.macro
Cross-References
Module 02: Transactors - Transaction processing phases
AMM Architecture - Data structures and pool design
AMM Logic - Formulas used in deposit/withdraw
Last updated

