Amendment XLS: AMM Invalid State Recovery and Settlement #556
shortthefomo
started this conversation in
XLS Proposals
Replies: 1 comment
-
|
I'm supportive of the idea of cleaning up ledger corruption, but I have some concerns with this fix as described:
|
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
Abstract
This proposal extends the existing LedgerStateFix transaction to handle Automated Market Makers (AMMs) on the XRP Ledger that enter an invalid state. When triggered on a qualifying AMM, the pool is closed and any remaining locked tokens are proportionally returned to liquidity providers (LP token holders).
Motivation
The current AMM implementation (XLS-30) lacks a built-in recovery path for inconsistent or broken states caused by bugs, extreme edge cases, or future protocol changes. This can lead to permanent liquidity lockup. Leveraging the existing
LedgerStateFixframework provides a recovery mechanism without introducing a new transaction type.With further optionality to AMM on the horizon there should at least be a way to clean these up.
Real-World Examples of Invalid AMM States
Pathfinding operations for example for ever trip over this invariant pools when looking for routes. Even though the path find operations complete because they are sandboxed the logs are littered for example.
Example 1: Drained Pool + Invariant Violation (March 2024 Bug)
One of the earliest AMM pools (USD.rvYA / USD.rhub) was impacted by a multi-path payment bug.
Example 2: Fully Drained One-Sided Pool (EUR.rhub / SeagullCash.rNHe)
Another pool hit by the same bug:
OfferCreatetransaction (using auto-bridging) completely drained one side of the pool.These pools still exist today and cause these errors/warnings depending how you classify that in the logs today.
Specification
1. Invalid State Definition
An AMM is considered to be in an invalid state if any of the following conditions are met:
2. LedgerStateFix Extension
TransactionType:
LedgerStateFix(existing)New LedgerFixType
Add a new
LedgerFixTypevalue for AMM recovery:3(assuming values 1 and 2 are already allocated to prior fixes)Additional Fields (when
LedgerFixType= 3):AssetAsset2Behavior (
LedgerFixType= 3)Asset+Asset2pair.tecAMM_NOT_INVALID.AMMledger object, associatedAccountRoot, and related trust lines (processed in batches if necessary).If trust line cleanup exceeds transaction limits, return
tecINCOMPLETE(similar toAMMDelete).3. Error Codes
tecAMM_NOT_INVALID— The specified AMM is not in an invalid state.tecAMM_INVALID_STATE— Returned by all standard AMM transactions when the pool is invalid. Users should useLedgerStateFixinstead.tecINSUFFICIENT_BALANCE— Defensive error during distribution.4. Changes to Existing Components
AMMDeposit,AMMWithdraw,AMMBid,AMMDelete, etc. must returntecAMM_INVALID_STATEif the pool is invalid.amm_infoshould return two new fields:InvalidState(boolean)InvalidStateReason(optional string)5. Proportional Distribution
For each LP holder with LP balance
L_iand total LP supplyL:(L_i / L) × Balance_A(L_i / L) × Balance_BDistributions are performed using standard payment primitives. Any dust amounts below the minimum transfer threshold may be burned or sent to the account that triggered the settlement.
Implementation Considerations
LedgerFixTypeupon detection of invalid state.Rationale
LedgerStateFixlogic.LedgerStateFixfor exceptional state corrections.Beta Was this translation helpful? Give feedback.
All reactions