Uncategorized XRPL

The XRPL Payments Engine

The XRPL is home to the first decentralized exchange (DEX), which began before the term “DeFi” even existed. It has an orderbook design and allows any type of blockchain-based asset (cryptocurrencies, fiat currencies, tokenized assets, and more) to be traded permissionlessly.  

The DEX is powered by a collection of backend rippled functions that together form the Payments Engine, which will also integrate with the XRPL AMM if approved. The Payments Engine supports a number of on-chain features and functions, including complex algorithms that facilitate efficient trades between any pair of assets, such as finding the best pricing between the DEX and AMM.

This article will provide an overview of:

  • What is a DEX, and how do they vary?
  • The XRPL DEX
  • The Payments Engine

What is a DEX?

Centralized exchanges (CEXs) such as Binance or Coinbase operate off-chain, take custody of one’s funds, and are centralized in nature. While they may provide a seamless user experience and have deep liquidity, they’re not true blockchain and there’s always some degree of potential risk, as evidenced with FTX. In contrast, decentralized exchanges (DEXs) operate fully on-chain, do not custody funds, and are fully driven by code.

There are two primary DEX architectures:

  1. Central Limit Order Book (CLOBs): similar to the traditional stock exchange, where users place buy orders and sell orders. When they match, a trade executes.
  2. Algorithmic Market Makers (AMMs): token holders provide their tokens as liquidity to facilitate trades for others, receiving a share of trading fees in return. An AMM algorithmically prices assets on the DEX to facilitate trades.

CLOBs benefit from being more intuitive for users, as they are similar to TradFi exchanges. Their pricing works well in highly liquid markets due to deep supply and demand, as well as small spreads. AMMs are better for illiquid markets because orders are filled quickly. They’re also more scalable on-chain because CLOB transaction costs can quickly add up and a given network may have a limited storage capacity.

The XRPL DEX

The XRPL’s DEX is CLOB-based and was the first DEX in existence. The DEX is a fully functioning on-chain order book that was built into the network itself with consistently low transaction costs. Being embedded directly into the protocol allows developers to interface seamlessly with its infrastructure, eliminating the need for smart contracts that typically fragment liquidity and heighten the risk of smart contract breaches.

That being said, the XRPL is also introducing an AMM which, if approved, would be the first hybrid AMM/CLOB DEX of its kind! The AMM is also built directly into the network and has some unique features that I covered in a separate thread.

Given that the XRPL is built for nearly any type of asset, it’s reasonable to assume that not all assets will have adequate liquidity between them. For this reason, a matching engine was created which finds the best possible path between two assets! For example, I might wish to purchase something in tokenized gold while the seller wants to be paid in Japanese Yen. 

The matching engine can facilitate this in two ways:

  1. Pathfinding: this refers to finding a payment path between the buyer and seller. This might mean converting the gold directly to Yen, or there might be slight price discrepancies that make another path cheaper.
  2. Autobridging: using XRP tokens as an intermediary currency to connect the tokens.

Imagine that $100 of gold could be directly traded for $99.7 of Japanese Yen. This is a slight discrepancy, but it quickly adds up for big trades. It might be possible that trading gold for USD, and then USD for Yen, in fact provides a more efficient trading path, and the trader might receive $99.8 worth of Yen. This would be pathfinding, whereas if the intermediary currency were XRP, it would be autobridging.

This matching engine forms part of the Payments Engine (PE) which I’ll cover next. The PE powers the XRPL on the backend, finding the best prices possible.

Payments Engine

As mentioned, the Payments Engine is integrated with the current DEX, and will also integrate with the AMM if it is approved.

The Payments Engine (PE) is responsible for:

  • Executing payments: transferring value between accounts.
  • Offer crossings: matching buying and selling orders on the DEX.
  • Cash cheques: similar to paper checks in TradFi but all on the XRPL.

Given that many consumers, institutions, and even countries will be using the XRPL, there’s a need for the PE to be as efficient as possible.

How does it always find the best path possible?

It uses features such as pathfinding and autobridging that facilitate how it chooses the best path. Depending on this, different applicable paths can be taken to get between the assets in question.

In the context of pathfinding, it would calculate the aggregate price for various trading routes and select the best. 

Conclusion

The above provided an overview of the XRPL’s DEX and Payments Engine, covering how they work in tandem to provide the best price possible for users.

This is a necessary precursor to more assets on the XRPL and widespread adoption that will add significant complications to the network. Fortunately, having a powerful PE means payments, transactions, and cash checks can all be efficiently executed.

The CLOB DEX also complements the AMM, and both have inherent tradeoffs. 

In the meantime – looking to get involved with the XRPL? Many large institutions and firms are beginning to build and it’s a great opportunity for those with developer experience.

If you are interested in learning more about building on the XRPL, feel free to book a call with me and we can discuss the process.

Leave a Reply

Your email address will not be published. Required fields are marked *