Skip to content

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

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

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

Conversation

@RomThpt

@RomThpt RomThpt commented Mar 20, 2026

Copy link
Copy Markdown

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.

@godexsoft

Copy link
Copy Markdown
Contributor

We recently merged a refactor to develop that enables clang-tidy's readability-identifier-naming. Your branch now has heavy conflicts that are largely mechanical. Below is a workflow that aligns your branch's naming with develop before merging, which should minimize the merge conflicts.

One-time setup

If you don't already have clang-tidy working in your env, on macOS:

brew install llvm@21
# Follow brew's hint to put $(brew --prefix llvm@21)/bin on PATH so run-clang-tidy is found.

Workflow on your branch (before merging develop)

1. Grab the new .clang-tidy from develop without pulling anything else. Sync your fork on GitHub first, then:

git remote -v   # should show 'upstream' among others; if not:
# git remote set-url upstream git@github.com:XRPLF/rippled.git
git fetch upstream
git checkout upstream/develop -- .clang-tidy

2. Reconfigure conan/cmake so compile_commands.json is fresh.

3. Apply renames for the files modified in your PR:

git diff --name-only $(git merge-base HEAD upstream/develop) HEAD \
  | grep -E '\.(cpp|h|hpp|ipp)$' \
  | xargs run-clang-tidy -p build -fix -allow-no-checks
# or -p .build, or whatever your build dir is called

4. Build + test, then commit as a single dedicated commit:

cmake --build build -j8
git commit -am "refactor: Align identifier naming with develop"

5. Now merge develop:

git merge upstream/develop

Extra

Run clang-tidy once more after the merge to catch any stragglers introduced from develop's side:

run-clang-tidy -p build -fix -allow-no-checks src tests
# or -p .build, or whatever your build dir is called

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.

2 participants