System XLS: AMM Pool Discovery #565
JibreelMuhammad
started this conversation in
XLS Proposals
Replies: 1 comment
-
Wouldn't this RPC basically be doing the same thing under the hood, thereby still being "expensive and impractical" (perhaps moreso since that effort would now be hidden within rippled)? |
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.
-
Canonical draft (kept current): https://github.com/JibreelMuhammad/xls-drafts/blob/main/XLS-AMM-Pool-Discovery.md
Posting at the Proposal stage per XLS-1; no XLS number is requested yet (an Editor assigns it at PR time). Feedback welcome before I open a PR.
System XLS: AMM Pool Discovery
1. Abstract
This standard adds a read-only public API method,
amm_pools, that enumerates Automated Market Maker (AMM) pools and supports filtering and pagination. It introduces no new ledger entries, no new fields on existing entries, and no new transactions, and therefore requires no amendment — it is a core server (rippled/Clio) feature over state that already exists.Today,
amm_inforeturns details for a pool whose asset pair the caller already knows. There is no protocol-level way to answer the inverse question — "what pools exist?" — without scanning the entire ledger or relying on third-party indexers.amm_poolscloses that gap.2. Motivation
The AMM (XLS-30), and the proposed AMM Swappable Curves work (which adds multiple pools per pair keyed by curve type), both assume the caller can already locate a pool. Discovery is a blind spot:
amm_inforequires the answer in advance: it takesasset+asset2(oramm_account) and returns one known pool. It cannot list pools, filter by a single asset, or find recently created pools.ledger_datascan filtered by entry typeamm— expensive and impractical for most clients, and it returns raw entries rather than a queryable, filterable list.Concrete needs this blocks: routing/best-execution across multiple curve pools for a pair; treasury and custody enumeration; market-oversight (detecting thin pools, comparing spreads); and the basic wallet/frontend primitive "show me all pools for asset X."
3. Specification
3.1. Method:
amm_poolsA new read-only public API method (WebSocket and JSON-RPC) that enumerates AMM pools, optionally filtered, with cursor-based pagination.
3.1.1. Request Fields
asset{ currency, issuer? }; XRP omitsissuer.asset2asset, matches the exact pair.curve_typewith_liquiditytrue, return only pools withLPTokenBalance > 0. Defaultfalse.limit50, maximum200.markerledger_index/ledger_hashvalidated.Filtering semantics: no
asset/asset2enumerates all pools;assetonly returns all pools containing that asset;asset+asset2returns all pools for that exact pair (one per curve type). Asset ordering is normalized server-side, so callers need not order the pair.3.1.2. Response Fields
poolsmarkerledger_indexvalidatedEach element of
pools:amm_accountpool_idassetasset2curve_typetrading_feelp_token{ currency, issuer, value };valueis total supply.amountasset.amount2asset2.amm_poolsreturns summary/identity data for discovery and routing. For full per-pool detail (vote slots, auction slot, etc.), callers follow up withamm_infousing the returnedamm_account.3.1.3. Failure Conditions
invalidParamscurve_typeis out of range.actNotFoundasset/asset2does not exist.lgrNotFoundAn empty
poolsarray (not an error) is returned when the filters match no pools.3.1.4. Example Request
{ "command": "amm_pools", "asset": { "currency": "USD", "issuer": "rISSUER..." }, "with_liquidity": true, "limit": 100, "ledger_index": "validated" }3.1.5. Example Response
{ "result": { "pools": [ { "amm_account": "rAMM1...", "pool_id": "9F3C...", "asset": { "currency": "XRP" }, "asset2": { "currency": "USD", "issuer": "rISSUER..." }, "curve_type": 0, "trading_fee": 500, "lp_token": { "currency": "03A...", "issuer": "rAMM1...", "value": "1000000" }, "amount": "5000000000", "amount2": { "currency": "USD", "issuer": "rISSUER...", "value": "5000" } } ], "marker": "A1B2...", "ledger_index": 12345, "validated": true } }4. Rationale
Why an API method rather than new ledger state. All data needed for discovery already lives in
ltAMMentries; the missing piece is retrieval, not storage. Keeping this off-ledger means zero state growth, no migration, and no amendment vote — the lowest-risk path to the capability.Why mirror existing methods. The request/response shape,
limit/markerpagination, andledger_indexselector followaccount_objectsandbook_offers, so the method is familiar to implementers and clients.Why summary fields only. Returning identity + reserves + fee keeps each page light and lets
amm_pools(discovery) compose cleanly withamm_info(detail) instead of duplicating it.Alternate designs considered. (1) Adding discovery metadata fields (name, tags, status) to
ltAMM: rejected here because it bloats every pool and is a separable concern — it belongs in its own proposal. (2) A newPermissionedDomain-style registry ledger object listing pools: rejected as redundant, since the pools already exist as ledger entries and only need to be queryable. (3) Relying on third-party indexers (status quo): rejected because it fragments a capability the ledger can serve consistently and verifiably.5. Test Plan
markerround-trips.assetonly; verify every returned pool contains that asset and none are omitted.asset+asset2; verify exactly the pools for that pair (one per curve type when Swappable Curves is enabled).with_liquidity: trueexcludes zero-reserve pools;false/absent includes them.limitboundary tests (1, default, max 200, >200 clamped);markercontinuation produces no duplicates or gaps.asset, nonexistent issuer (actNotFound), unavailable ledger (lgrNotFound), out-of-rangecurve_type(invalidParams).rippled/Clio.6. Security Considerations
Denial-of-service / cost. Enumeration is the main abuse surface. Mitigations: a hard
limitcap (200), mandatory cursor pagination, and read-only/idempotent execution. Servers should treatamm_poolslike other large read methods (ledger_data,account_objects) for rate-limiting, and may restrict unfiltered full enumeration to admin connections.No new write surface. The method cannot modify state; it adds no transaction and no authorization path.
Index/consensus consistency. Any server-side AMM index is a derived cache of validated ledger state; results MUST reflect the requested validated ledger and never report pools absent from it.
Privacy. Pools are already public ledger state; serving them via a query reveals nothing a full ledger scan would not.
7. Appendix
7.1. FAQ
Should the response include TVL or 24h volume? TVL is derivable from reserves at query time; rolling volume is not stored on-ledger and would require server-side aggregation. Recommendation: keep volume out of this method (define it where aggregation already happens, e.g. Clio analytics); treat TVL as optional/derived.
Public or admin-only enumeration? Unfiltered enumeration is the heaviest call. Servers may serve it publicly with strict paging and rate limits, or restrict the no-filter case to admin connections by policy.
Sort order. Keyspace order is cheapest and pagination-stable. A
sortoption (e.g. by reserves) can be added later without breaking changes.Beta Was this translation helpful? Give feedback.
All reactions