Amendment Idea: Concentrated Liquidity AMM #427
RomThpt
started this conversation in
Ideas (pre standard proposal)
Replies: 3 comments 3 replies
-
|
Hi @RomThpt - please review the guidelines for how to create discussions in this repo. There should not be a number assigned (those are now assigned at PR) and there should be a preamble section labeling this as an |
Beta Was this translation helpful? Give feedback.
1 reply
-
Beta Was this translation helpful? Give feedback.
1 reply
-
|
do you have any more proposed specs for "NFToken-based LP positions that are fully tradeable"? Would be curious how you see that working for the XRPL. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Idea: Concentrated Liquidity AMM
Category: Amendment
Status: Idea
This is an early idea for a Concentrated Liquidity Automated Market Maker (CL AMM) for the XRP Ledger. Unlike the existing XLS-30 AMM which distributes liquidity uniformly across all prices, this design would allow liquidity providers to concentrate their capital within specific price ranges, dramatically improving capital efficiency (up to 4000x for stablecoin pairs).
Motivation
The current XRPL AMM (XLS-30) uses a constant product formula where liquidity is distributed uniformly across all prices. This approach is capital inefficient because most liquidity sits idle at price points far from the current market price.
Limitations of XLS-30:
Benefits of Concentrated Liquidity:
Key Design Elements
Fee Tiers and Tick Spacing
This idea proposes linked fee tiers that determine both the trading fee and tick granularity. This approach mirrors Uniswap V3's proven model while adapting to XRPL's architecture.
STABLE(0)LOW(1)MEDIUM(2)HIGH(3)Why link fee and tick spacing?
FeeTier) instead of configuring twoTick Range Coverage:
Potential Ledger Entries
1. CLAMM
Pool state containing current tick, liquidity, and fee growth.
AssetAsset2FeeTierTickSpacingTradingFeeCurrentTickSqrtPriceLiquidityFeeGrowthGlobal0FeeGrowthGlobal1ProtocolFees0ProtocolFees12. CLAMMTick
Per-tick liquidity and fee data. Only ticks with liquidity are stored (sparse).
PoolIDTickIndexLiquidityGrossLiquidityNetFeeGrowthOutside0FeeGrowthOutside13. CLAMMPosition
LP positions linked to NFTokens.
PoolIDNFTokenIDOwnerLowerTickUpperTickLiquidityFeeGrowthInside0LastFeeGrowthInside1LastTokensOwed0TokensOwed1Potential Transactions
1. CLAMMCreate
Create a new concentrated liquidity pool.
{ "TransactionType": "CLAMMCreate", "Account": "rCreator...", "Asset": { "currency": "USD", "issuer": "rIssuer..." }, "Asset2": { "currency": "XRP" }, "FeeTier": 2, "InitialPrice": "1500000000000000000" }AssetAsset2FeeTierInitialPrice2. CLAMMDeposit
Add liquidity within a price range. Mints an NFToken representing the position.
{ "TransactionType": "CLAMMDeposit", "Account": "rLP...", "PoolID": "hash...", "LowerTick": -120, "UpperTick": 180, "Amount": { "currency": "USD", "issuer": "rIssuer...", "value": "1000" }, "Amount2": { "currency": "XRP", "value": "500" }, "MinLiquidity": "100000" }PoolIDLowerTickUpperTickAmountAmount2MinLiquidity3. CLAMMWithdraw
Remove liquidity from a position. Burns the NFToken if fully withdrawn.
{ "TransactionType": "CLAMMWithdraw", "Account": "rLP...", "NFTokenID": "hash...", "LiquidityAmount": "50000", "MinAmount": { "currency": "USD", "issuer": "rIssuer...", "value": "400" }, "MinAmount2": { "currency": "XRP", "value": "200" } }NFTokenIDLiquidityAmountMinAmountMinAmount24. CLAMMSwap
Execute a swap through the pool.
{ "TransactionType": "CLAMMSwap", "Account": "rTrader...", "PoolID": "hash...", "AmountIn": { "currency": "USD", "issuer": "rIssuer...", "value": "100" }, "MinAmountOut": { "currency": "XRP", "value": "45" } }PoolIDAmountInMinAmountOut5. CLAMMCollectFees
Collect accumulated fees without removing liquidity.
{ "TransactionType": "CLAMMCollectFees", "Account": "rLP...", "NFTokenID": "hash..." }NFTokenID6. CLAMMVote
Vote on protocol fee percentage (similar to XLS-30).
{ "TransactionType": "CLAMMVote", "Account": "rLP...", "PoolID": "hash...", "ProtocolFee": 1000 }PoolIDProtocolFeePotential RPCs
clamm_info
Get pool information.
Request:
{ "command": "clamm_info", "pool_id": "hash..." }Response:
{ "pool": { "asset": { "currency": "USD", "issuer": "rIssuer..." }, "asset2": { "currency": "XRP" }, "fee_tier": 2, "current_tick": 50, "sqrt_price": "1050000000000000000", "liquidity": "1000000000", "trading_fee": 3000, "protocol_fee": 0 } }clamm_positions
Query positions for an account.
Request:
{ "command": "clamm_positions", "account": "rLP..." }Math Precision
All implementations would need to use:
Price Calculation:
Where
TICK_BASEdepends on the fee tier:Swap Algorithm
amountRemaining > 0:a. Calculate maximum swap amount at current tick
b. If
amountRemaining <= maxAtTick: swap within tick, donec. Else: consume liquidity at tick, cross to next tick
d. Update
Liquidity += LiquidityNetof new tickCurrentTick,SqrtPrice, fee accumulators)Feedback Requested
Looking forward to community feedback!
References
Beta Was this translation helpful? Give feedback.
All reactions