Show / Hide Table of Contents

Class AmmOfferMath

The arithmetic of an AMM pool's synthetic offer, as rippled's payment engine does it: the swap formulas and the offer a pool puts beside an order book, with rippled's Number rounding.

Inheritance
object
AmmOfferMath
Namespace: Xrpl.Amounts
Assembly: Xrpl.dll
Syntax
public static class AmmOfferMath
Remarks

The amounts are the pool's balances and what moves in or out of it, each in its own asset; the trading fee is in units of 1/100,000 (1000 is 1%). The rules decide the rounding: fixAMMv1_1 for the swaps and the spot-price change, fixAMMv1_2 for the largest offer beside a book, the Number scale for all of them. The results are the ones inside a transaction.

Fields

| Edit this page View Source

MaxTradingFee

The highest trading fee a pool can have, 1% (TRADING_FEE_THRESHOLD).

Declaration
public const ushort MaxTradingFee = 1000
Field Value
Type Description
ushort

Methods

| Edit this page View Source

ChangeSpotPriceQuality(XrplAmount, XrplAmount, XrplQuality, ushort, LedgerRules)

changeSpotPriceQuality: the offer that brings the pool's spot price to quality, or that has that quality itself; null when neither can be generated.

Declaration
public static (XrplAmount In, XrplAmount Out)? ChangeSpotPriceQuality(XrplAmount poolIn, XrplAmount poolOut, XrplQuality quality, ushort tradingFee, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount poolIn

The pool's balance of the asset paid in.

XrplAmount poolOut

The pool's balance of the asset paid out.

XrplQuality quality

The quality to reach, usually the best one of the order book beside the pool.

ushort tradingFee

The pool's trading fee, in units of 1/100,000.

LedgerRules rules

The amendments in force; all of them when null.

Returns
Type Description
(XrplAmount In, XrplAmount Out)?
Exceptions
Type Condition
ArgumentException

tradingFee is above MaxTradingFee.

| Edit this page View Source

PoolOffer(XrplAmount, XrplAmount, ushort, XrplQuality?, LedgerRules)

The offer the pool puts beside an order book whose best quality is bookQuality, on a payment or a crossing along one strand (AMMLiquidity::getOffer): the offer that brings the pool's spot price to the book's quality - or, under fixAMMv1_2, the pool's largest offer when that one is better than the book - and the largest offer, 99% of poolOut, when there is no book.

Declaration
public static AmmPoolOffer? PoolOffer(XrplAmount poolIn, XrplAmount poolOut, ushort tradingFee, XrplQuality? bookQuality, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount poolIn

The pool's balance of the asset paid in.

XrplAmount poolOut

The pool's balance of the asset paid out.

ushort tradingFee

The pool's trading fee, in units of 1/100,000.

XrplQuality? bookQuality

The best quality of the order book beside the pool; null for an empty book.

LedgerRules rules

The amendments in force; all of them when null.

Returns
Type Description
AmmPoolOffer?

The offer, or null when the pool's spot price does not beat the book or no offer can be generated.

Remarks

On several strands the engine sizes the pool's offers differently, in slices of the initial pool; that and its limit of 30 pool offers per transaction depend on the whole flow and are not modelled here.

Exceptions
Type Condition
ArgumentException

tradingFee is above MaxTradingFee, or a balance has no asset.

| Edit this page View Source

SwapIn(XrplAmount, XrplAmount, XrplAmount, ushort, LedgerRules)

swapAssetIn: what the pool pays out for amountIn.

Declaration
public static XrplAmount SwapIn(XrplAmount poolIn, XrplAmount poolOut, XrplAmount amountIn, ushort tradingFee, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount poolIn

The pool's balance of the asset paid in.

XrplAmount poolOut

The pool's balance of the asset paid out.

XrplAmount amountIn

What goes into the pool.

ushort tradingFee

The pool's trading fee, in units of 1/100,000.

LedgerRules rules

The amendments in force; all of them when null.

Returns
Type Description
XrplAmount
Exceptions
Type Condition
ArgumentException

tradingFee is above MaxTradingFee.

| Edit this page View Source

SwapOut(XrplAmount, XrplAmount, XrplAmount, ushort, LedgerRules)

swapAssetOut: what the pool takes in to pay out amountOut.

Declaration
public static XrplAmount SwapOut(XrplAmount poolIn, XrplAmount poolOut, XrplAmount amountOut, ushort tradingFee, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount poolIn

The pool's balance of the asset paid in.

XrplAmount poolOut

The pool's balance of the asset paid out.

XrplAmount amountOut

What comes out of the pool; less than poolOut.

ushort tradingFee

The pool's trading fee, in units of 1/100,000.

LedgerRules rules

The amendments in force; all of them when null.

Returns
Type Description
XrplAmount
Exceptions
Type Condition
ArgumentException

tradingFee is above MaxTradingFee.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX