A Developer's Guide to Payment Engine System Design
Tags: blockchain, web3, cryptocurrency, xrpl
Published: 2023-06-20 20:32:57

The RippleX engineering team has [published a new whitepaper](https://ripple.com/reports/Payment-Engine-System-Design.pdf) that provides an overview of the Payment Engine (PE) system, including design concepts and examples. The PE system is a subsystem within the rippled software that is responsible for executing payments, offer crossings, and cash checks in the XRPL network, and is also used as part of the XRP Ledger's [path finding algorithm](https://xrpl.org/paths.html). The full whitepaper demonstrates key concepts of the PE system with several examples.

**<span style="text-decoration:underline;">Synopsis (Super Summary)</span>**

The document provides an overview of the design concepts and examples related to the Payment Engine (PE) system, which is a subsystem within the XRPL's rippled software. Here is a summary of the main points covered:

**<span style="text-decoration:underline;">Payment Engine Overview</span>**



* Payment Engine is responsible for executing [payments](https://xrpl.org/payment-types.html), offer crossings, and cash checks in the XRPL network.
* It converts payment paths into a sequence of specific steps and executes them sequentially.
* The steps can involve different types, such as XRPEndpointStep, BookStep, and DirectStep, depending on the nature of the payment.

**<span style="text-decoration:underline;">Design Concepts By Example</span>**



* Several examples are provided to illustrate different design concepts and scenarios.
* Examples include executing steps in reverse and forward directions, re-executing steps based on limitations, consuming offers at the same quality, iterative payment execution, and multi-path payment execution.
* The examples showcase how payments are executed, how offers and liquidity are consumed, and how the system handles various scenarios.

**<span style="text-decoration:underline;">Payments via Automated Market Maker (AMM)</span>**



* The document discusses the integration of [Automated Market Maker (AMM)](https://github.com/XRPLF/XRPL-Standards/discussions/78) functionality into the BookStep process.
* AMM allows tokens to be traded in both directions based on [mathematical formulas](https://opensource.ripple.com/docs/xls-30d-amm/automated-market-makers/).
* AMM offers are handled within BookStep and can be chosen based on spot price quality (SPQ).
* The document explains how AMM offers are generated and resized during payment execution.

**<span style="text-decoration:underline;">Multi-Path Payment Execution</span>**



* The document explores the execution of payments involving multiple paths, where liquidity can be consumed from different sources.
* Paths are sorted based on their quality, and the best quality path is executed first.
* The document introduces a Fibonacci sequence-based approach to generating synthetic AMM offers in multi-path payments.
* The iterative approach is used to execute multi-path payments until the requested output or input amounts are fulfilled.

The document provides conceptual understanding of the Payment Engine subsystem and helps developers delve into the coding implementation details. It demonstrates various payment scenarios, the interaction between different steps, and the considerations involved in executing payments within the XRPL network.

[Read the full whitepaper here](https://ripple.com/reports/Payment-Engine-System-Design.pdf).