BR Academy
0%
The XRP Ledger Ecosystem·Lesson 22 of 35·8 min

Decentralized Exchange and Automated Market Maker

The concept

The XRP Ledger has had a trading venue built directly into its protocol since launch — no separate smart contract, no third-party platform required. This lesson covers both of its native trading mechanisms: the original order-book DEX, and the Automated Market Maker (AMM) feature added later via a protocol amendment (the amendment process itself is covered in Lesson 6.1).

The order-book DEX lets any account place buy or sell offers for any pair of currencies the ledger supports — XRP against an issued currency, or one issued currency against another. These offers sit in an order book, and the ledger automatically matches compatible buy and sell offers, the same conceptual model as a traditional exchange's order book, except that it's enforced directly by the protocol rather than operated by a company. This is the mechanism behind the auto-bridging feature you saw in Lesson 3.3.

The AMM feature, added via amendment, works differently: instead of individual buy/sell offers, users can deposit a pair of assets into a shared liquidity pool, and trades execute against that pool's pricing curve rather than against a matched counter-offer. Liquidity providers who deposit into a pool earn a share of the trading fees generated by swaps against it — a model conceptually similar to AMMs you may have encountered on other blockchains, but implemented here as a native ledger feature rather than a third-party smart contract deployed on top of a general-purpose platform.

The key point to take away: both mechanisms coexist on the same ledger, and they aren't in competition for a single trade — the ledger's routing logic can execute a given trade against whichever offers the better price, whether that's a matching order-book offer or an AMM pool, or even splitting a single trade across both.

It's worth being specific about what a liquidity provider actually takes on when depositing into an AMM pool, since "earning trading fees" is only half the picture. Pool composition shifts with every trade executed against it, which means a liquidity provider's share of the pool can end up worth a different mix of the two assets than what they originally deposited — a dynamic commonly called impermanent loss in AMM designs generally. This is a structural property of pooled-liquidity mechanisms, not unique to the XRP Ledger's implementation, and it's the reason AMM liquidity provision is a meaningfully different risk profile from simply placing a resting order-book offer, even though both ultimately serve the same function of providing tradable liquidity to the ledger.

Worked example

Picture two trades happening on the same currency pair, side by side:

Order-book trade: A seller places an offer to sell 1,000 units of an issued currency for XRP at a specific exchange rate. A buyer's matching buy offer, at a compatible rate, is already resting in the order book. The ledger matches them directly — the trade executes at the rate both parties specified, with no pool or curve involved.

AMM trade: A different trader wants to swap the same currency pair but there's no matching order-book offer at a favorable rate. Instead, their trade executes against an AMM liquidity pool for that pair — the pool's pricing curve determines the exchange rate based on the pool's current balance of each asset, and the trade shifts that balance slightly, moving the pool's price for the next trade.

Both trades settle on the same ledger, in the same few-second ledger close cycle, using the same underlying consensus process from Module 2 — they're just two different liquidity sources for the same kind of swap.

Now extend the example to the liquidity-provider side: suppose a liquidity provider deposits an equal value of XRP and an issued currency into that same AMM pool. As subsequent trades move through the pool, its balance of the two assets shifts away from the original 50/50 split — the pool now holds relatively more of whichever asset was being sold into it and relatively less of whichever was being bought out. If the provider withdraws their share at this point, they receive a mix of the two assets reflecting the pool's current composition, not necessarily the exact amounts they originally deposited — plus their accumulated share of trading fees earned along the way. Whether the fees earned offset any difference in asset mix depends on trading volume and price movement over the period the liquidity was deposited, which is precisely the impermanent-loss trade-off described above.

Exercise

Name one similarity and one difference between the XRPL's order-book DEX and its AMM feature.

Model answer:

  • Similarity: Both are native protocol features enforced directly by the ledger itself, not smart contracts deployed on top of a separate platform — and both can be used to execute a currency swap on the same ledger, within the same settlement model covered in Module 2.
  • Difference: The order-book DEX matches individual buy and sell offers directly against each other at the rates each party specified, while the AMM executes trades against a shared liquidity pool's pricing curve, with liquidity providers earning a share of trading fees rather than placing individual offers.

Check your answer against this: if you named "speed" or "fees" as the key difference, reconsider — both mechanisms settle within the same ledger-close cycle and fee structure (Lesson 4.3); the structural difference is in how a trade's counterparty-side liquidity is sourced (a matched offer vs. a shared pool).

Second question: why does an AMM liquidity provider take on a risk that a resting order-book offer placer does not? Answer: Because an AMM pool's asset composition shifts continuously with every trade executed against it, meaning a liquidity provider's withdrawn share can be worth a different mix of assets than originally deposited (impermanent loss) — whereas a resting order-book offer either executes at the exact rate specified or simply remains unfilled and unchanged, with no equivalent exposure to a shifting pool composition.

Recap

  • The XRP Ledger's order-book DEX has existed since launch, letting any account place buy/sell offers for any currency pair directly on the protocol.
  • The AMM feature, added via amendment, lets users pool liquidity for a pair and earn trading fees, with trades executing against the pool's pricing curve instead of a matched offer — and carries a structurally different risk (impermanent loss) for liquidity providers than placing a resting offer does.
  • Both mechanisms coexist on the same ledger, and a trade can route through whichever offers the better price — they are complementary liquidity sources, not competing platforms.

Resources

  • Decentralized Exchange overview, XRPL.org — https://xrpl.org/docs/concepts/tokens/decentralized-exchange
  • Automated Market Maker (AMM) reference, XRPL.org — https://xrpl.org/docs/concepts/tokens/decentralized-exchange/automated-market-makers
  • OfferCreate transaction reference — https://xrpl.org/docs/references/protocol/transactions/types/offercreate