Skip to content

feat(clamm): implement XLS-99 Concentrated Liquidity AMM#6605

Open
RomThpt wants to merge 1 commit intoXRPLF:developfrom
RomThpt:feature/clamm-xls99-squashed
Open

feat(clamm): implement XLS-99 Concentrated Liquidity AMM#6605
RomThpt wants to merge 1 commit intoXRPLF:developfrom
RomThpt:feature/clamm-xls99-squashed

Conversation

@RomThpt
Copy link
Copy Markdown

@RomThpt RomThpt commented Mar 20, 2026

Summary

Implement a Concentrated Liquidity Automated Market Maker (CLAMM) for the XRP Ledger, as specified in XLS-99. Unlike XLS-30 which distributes liquidity uniformly, CLAMM allows LPs to concentrate capital within specific price ranges for up to 4000x capital efficiency improvement.

Ledger Entries (4 new)

  • CLAMM (0x008A): Pool state -- current tick, sqrt price, active liquidity, fee tier, auction slot
  • CLAMMTick (0x008B): Per-tick liquidity boundaries and fee growth tracking (sparse storage)
  • CLAMMPosition (0x008C): LP position linked to NFToken (XLS-20) -- tick range, liquidity, uncollected fees
  • CLAMMTickBitmap (0x008D): Compressed 256-bit bitmap for efficient initialized tick lookup

Transactions (9 new)

Type ID Description
CLAMMCreate 85 Create pool with asset pair, fee tier, initial price
CLAMMDeposit 86 Add liquidity within a price range, mint position NFToken
CLAMMWithdraw 87 Remove liquidity, burn NFToken on full withdrawal
CLAMMSwap 88 Direct swap through a pool
CLAMMCollectFees 89 Collect accumulated fees without removing liquidity
CLAMMVote 90 Vote on trading fee parameters (liquidity-weighted)
CLAMMBid 91 Bid for auction slot (discounted fees, MEV protection)
CLAMMDelete 92 Remove empty pools from ledger (multi-call for large pools)
CLAMMClawback 93 Issuer clawback of tokens from holder CLAMM positions

RPCs (4 new)

  • clamm_info: Pool information (by pool_id or asset/asset2/fee_tier)
  • clamm_positions: Query positions by account or nftoken_id
  • clamm_ticks: Query tick data within a range
  • clamm_quote: Swap quote simulation

Key Design Decisions

  • Fee tiers: 4 predefined tiers (0.01%, 0.05%, 0.30%, 1.00%) linked to tick spacing, preventing scam pools
  • NFToken positions: Reuses XLS-20 infrastructure for unique, tradeable LP positions
  • Payment engine integration: CLAMMLiquidity/CLAMMOffer enable automatic routing through CLAMM pools alongside DEX and XLS-30 AMM
  • Continuous auction: Adapted from XLS-30 for MEV protection
  • Math precision: Q64.96 fixed-point with boost::multiprecision (uint128/uint256/uint512)

Amendment

Feature flag: featureCLAMM

Test Plan

  • Unit tests: pool lifecycle, deposits, withdrawals, swaps, fees, voting, bidding (CLAMM_test.cpp -- 4881 lines)
  • Payment routing tests (CLAMMPayment_test.cpp)
  • Tick bitmap navigation tests (CLAMMBitmap_test.cpp)
  • Fuzz tests: random deposit/withdraw/swap sequences (CLAMMFuzz_test.cpp)
  • Invariant tests (ValidCLAMM)
  • Cross-feature tests (NFToken transfer, freeze, clawback)

Related

Implement a Concentrated Liquidity Automated Market Maker for the XRP
Ledger, enabling LPs to concentrate capital within specific price ranges
for up to 4000x capital efficiency improvement over XLS-30.

Ledger entries:
- CLAMM (0x008A): pool state with current tick, sqrt price, liquidity
- CLAMMTick (0x008B): per-tick liquidity and fee growth data
- CLAMMPosition (0x008C): LP position linked to NFToken (XLS-20)
- CLAMMTickBitmap (0x008D): compressed bitmap for tick lookup

Transactions:
- CLAMMCreate (85): create pool with asset pair, fee tier, initial price
- CLAMMDeposit (86): add liquidity within a price range, mint NFToken
- CLAMMWithdraw (87): remove liquidity, burn NFToken on full withdrawal
- CLAMMSwap (88): direct swap through a pool
- CLAMMCollectFees (89): collect accumulated fees without removing liquidity
- CLAMMVote (90): vote on trading fee parameters
- CLAMMBid (91): bid for auction slot (discounted fees, MEV protection)
- CLAMMDelete (92): remove empty pools from ledger
- CLAMMClawback (93): issuer clawback of tokens from CLAMM positions

RPCs: clamm_info, clamm_positions, clamm_ticks, clamm_quote

Integration:
- Payment engine routing through CLAMM pools (CLAMMLiquidity/CLAMMOffer)
- NFToken position transfer with fee settlement
- NFTokenBurn blocked for CLAMM positions
- ValidCLAMM invariant checker

Tests: unit tests, payment routing, tick bitmap, fuzz testing

Spec: XRPLF/XRPL-Standards#498
@github-actions
Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant