feat(clamm): implement XLS-99 Concentrated Liquidity AMM#6605
Conversation
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
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
|
We recently merged a refactor to One-time setupIf 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 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-tidy2. Reconfigure conan/cmake so 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 called4. 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/developExtraRun 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 |
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)
0x008A): Pool state -- current tick, sqrt price, active liquidity, fee tier, auction slot0x008B): Per-tick liquidity boundaries and fee growth tracking (sparse storage)0x008C): LP position linked to NFToken (XLS-20) -- tick range, liquidity, uncollected fees0x008D): Compressed 256-bit bitmap for efficient initialized tick lookupTransactions (9 new)
RPCs (4 new)
clamm_info: Pool information (by pool_id or asset/asset2/fee_tier)clamm_positions: Query positions by account or nftoken_idclamm_ticks: Query tick data within a rangeclamm_quote: Swap quote simulationKey Design Decisions
Amendment
Feature flag:
featureCLAMMTest Plan
CLAMM_test.cpp-- 4881 lines)CLAMMPayment_test.cpp)CLAMMBitmap_test.cpp)CLAMMFuzz_test.cpp)Related