Class AmmLiquidity
AMM deposits and withdrawals computed exactly, the way rippled's AMMDeposit and
AMMWithdraw compute them under fixAMMv1_3: the LP tokens a deposit issues, the
assets a withdrawal pays, and the refusals the amounts lead to.
Inheritance
Namespace: Xrpl.Sugar
Assembly: Xrpl.dll
Syntax
public static class AmmLiquidity
Remarks
Where AmmMath gives a close decimal estimate, this follows the
node's Number and STAmount arithmetic step by step, rounding included, so a
quote is what the node moves. Read the pool with amm_info immediately before quoting.
Covered are every deposit mode - tfLPToken, tfTwoAsset, tfSingleAsset,
tfOneAssetLPToken, tfLimitLPToken and tfTwoAssetIfEmpty - and every
withdrawal mode - tfLPToken, tfWithdrawAll, tfTwoAsset,
tfSingleAsset, tfOneAssetLPToken, tfOneAssetWithdrawAll and
tfLimitLPToken. Not covered: the transaction's own validation (such as an amount above
the pool's balance, tecAMM_BALANCE in preclaim), and the checks on the account
itself - its funds, reserve, authorization and freezes - which
PreviewAMMDeposit(IXrplClient, AMMDeposit, CancellationToken) and PreviewAMMWithdraw(IXrplClient, AMMWithdraw, CancellationToken) cover.
Methods
| Edit this page View SourceDepositBoth(AmmPool, XrplNumber, XrplNumber, XrplNumber?, LedgerRules)
A proportional deposit of at most amount and amount2
(tfTwoAsset): one of them is deposited in full and the other in proportion.
Declaration
public static AmmQuote DepositBoth(AmmPool pool, XrplNumber amount, XrplNumber amount2, XrplNumber? minLpTokens = null, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| XrplNumber | amount | The most of the pool's first asset to deposit. |
| XrplNumber | amount2 | The most of the pool's second asset to deposit. |
| Nullable | minLpTokens | The transaction's |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
DepositForTokens(AmmPool, XrplNumber, XrplNumber?, XrplNumber?, LedgerRules)
A proportional deposit for lpTokens LP tokens (tfLPToken).
Declaration
public static AmmQuote DepositForTokens(AmmPool pool, XrplNumber lpTokens, XrplNumber? amount = null, XrplNumber? amount2 = null, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| XrplNumber | lpTokens | The LP tokens to receive. |
| Nullable | amount | The transaction's |
| Nullable | amount2 | The transaction's |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
DepositIntoEmptyPool(AmmPool, XrplNumber, XrplNumber, LedgerRules)
Deposits both assets into a pool with no LP tokens outstanding (tfTwoAssetIfEmpty):
the LP tokens are sqrt(amount * amount2) rounded down, as AMMCreate issues them.
Declaration
public static AmmQuote DepositIntoEmptyPool(AmmPool pool, XrplNumber amount, XrplNumber amount2, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The empty pool. |
| XrplNumber | amount | The pool's first asset to deposit. |
| XrplNumber | amount2 | The pool's second asset to deposit. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
DepositSingle(AmmPool, IssuedCurrency, XrplNumber, XrplNumber?, LedgerRules)
A single-asset deposit of amount (tfSingleAsset).
Declaration
public static AmmQuote DepositSingle(AmmPool pool, Common.IssuedCurrency asset, XrplNumber amount, XrplNumber? minLpTokens = null, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| Common.IssuedCurrency | asset | Which of the pool's assets to deposit. |
| XrplNumber | amount | The amount to deposit. |
| Nullable | minLpTokens | The transaction's |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
DepositSingleForTokens(AmmPool, IssuedCurrency, XrplNumber, XrplNumber, LedgerRules)
A single-asset deposit for lpTokens LP tokens, taking at most
maxAmount (tfOneAssetLPToken).
Declaration
public static AmmQuote DepositSingleForTokens(AmmPool pool, Common.IssuedCurrency asset, XrplNumber maxAmount, XrplNumber lpTokens, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| Common.IssuedCurrency | asset | Which of the pool's assets to deposit. |
| XrplNumber | maxAmount | The most of the asset to deposit. |
| XrplNumber | lpTokens | The LP tokens to receive. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
DepositWithEffectivePrice(AmmPool, IssuedCurrency, XrplNumber, XrplNumber, LedgerRules)
A single-asset deposit limited by an effective price (tfLimitLPToken): the
deposit is at most amount - all of it when its price per LP token
stays within effectivePrice - and otherwise the amount at which the
price per LP token reaches the limit.
Declaration
public static AmmQuote DepositWithEffectivePrice(AmmPool pool, Common.IssuedCurrency asset, XrplNumber amount, XrplNumber effectivePrice, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| Common.IssuedCurrency | asset | Which of the pool's assets to deposit. |
| XrplNumber | amount | The transaction's |
| XrplNumber | effectivePrice | The transaction's |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
InitialLpTokens(XrplNumber, XrplNumber, LedgerRules)
The LP tokens AMMCreate issues for a new pool of amount and
amount2: sqrt(amount * amount2), rounded down.
Declaration
public static decimal InitialLpTokens(XrplNumber amount, XrplNumber amount2, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| XrplNumber | amount | The first asset, in its own unit (drops for XRP). |
| XrplNumber | amount2 | The second asset, in its own unit (drops for XRP). |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| decimal |
WithdrawAll(AmmPool, XrplNumber, bool, LedgerRules)
A proportional withdrawal of every LP token the account holds (tfWithdrawAll).
Declaration
public static AmmQuote WithdrawAll(AmmPool pool, XrplNumber holderLpTokens, bool isOnlyLiquidityProvider = false, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| XrplNumber | holderLpTokens | The LP tokens the account holds. |
| bool | isOnlyLiquidityProvider | Whether the account is the pool's only liquidity provider. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
WithdrawAllOfAsset(AmmPool, IssuedCurrency, XrplNumber, XrplNumber, bool, LedgerRules)
A single-asset withdrawal of every LP token the account holds (tfOneAssetWithdrawAll).
Declaration
public static AmmQuote WithdrawAllOfAsset(AmmPool pool, Common.IssuedCurrency asset, XrplNumber minAmount, XrplNumber holderLpTokens, bool isOnlyLiquidityProvider = false, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| Common.IssuedCurrency | asset | Which of the pool's assets to withdraw. |
| XrplNumber | minAmount | The least of the asset to accept; zero accepts any amount. |
| XrplNumber | holderLpTokens | The LP tokens the account holds. |
| bool | isOnlyLiquidityProvider | Whether the account is the pool's only liquidity provider. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
WithdrawBoth(AmmPool, XrplNumber, XrplNumber, XrplNumber, bool, LedgerRules)
A proportional withdrawal of at most amount and
amount2 (tfTwoAsset).
Declaration
public static AmmQuote WithdrawBoth(AmmPool pool, XrplNumber amount, XrplNumber amount2, XrplNumber holderLpTokens, bool isOnlyLiquidityProvider = false, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| XrplNumber | amount | The most of the pool's first asset to withdraw. |
| XrplNumber | amount2 | The most of the pool's second asset to withdraw. |
| XrplNumber | holderLpTokens | The LP tokens the account holds. |
| bool | isOnlyLiquidityProvider | Whether the account is the pool's only liquidity provider. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
WithdrawForTokens(AmmPool, XrplNumber, XrplNumber, bool, LedgerRules)
A proportional withdrawal for lpTokens LP tokens (tfLPToken).
Declaration
public static AmmQuote WithdrawForTokens(AmmPool pool, XrplNumber lpTokens, XrplNumber holderLpTokens, bool isOnlyLiquidityProvider = false, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| XrplNumber | lpTokens | The LP tokens to redeem. |
| XrplNumber | holderLpTokens | The LP tokens the account holds. |
| bool | isOnlyLiquidityProvider | Whether the account is the pool's only liquidity provider. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
WithdrawSingle(AmmPool, IssuedCurrency, XrplNumber, XrplNumber, bool, LedgerRules)
A single-asset withdrawal of amount (tfSingleAsset).
Declaration
public static AmmQuote WithdrawSingle(AmmPool pool, Common.IssuedCurrency asset, XrplNumber amount, XrplNumber holderLpTokens, bool isOnlyLiquidityProvider = false, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| Common.IssuedCurrency | asset | Which of the pool's assets to withdraw. |
| XrplNumber | amount | The amount to withdraw. |
| XrplNumber | holderLpTokens | The LP tokens the account holds. |
| bool | isOnlyLiquidityProvider | Whether the account is the pool's only liquidity provider. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
WithdrawSingleForTokens(AmmPool, IssuedCurrency, XrplNumber, XrplNumber, XrplNumber, bool, LedgerRules)
A single-asset withdrawal for lpTokens LP tokens, paying at least
minAmount (tfOneAssetLPToken).
Declaration
public static AmmQuote WithdrawSingleForTokens(AmmPool pool, Common.IssuedCurrency asset, XrplNumber lpTokens, XrplNumber minAmount, XrplNumber holderLpTokens, bool isOnlyLiquidityProvider = false, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| Common.IssuedCurrency | asset | Which of the pool's assets to withdraw. |
| XrplNumber | lpTokens | The LP tokens to redeem. |
| XrplNumber | minAmount | The least of the asset to accept; zero accepts any amount. |
| XrplNumber | holderLpTokens | The LP tokens the account holds. |
| bool | isOnlyLiquidityProvider | Whether the account is the pool's only liquidity provider. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |
WithdrawWithEffectivePrice(AmmPool, IssuedCurrency, XrplNumber, XrplNumber, XrplNumber, bool, LedgerRules)
A single-asset withdrawal limited by an effective price (tfLimitLPToken): the LP
tokens whose redemption pays the asset at exactly effectivePrice LP
tokens per unit, as long as that pays at least amount.
Declaration
public static AmmQuote WithdrawWithEffectivePrice(AmmPool pool, Common.IssuedCurrency asset, XrplNumber amount, XrplNumber effectivePrice, XrplNumber holderLpTokens, bool isOnlyLiquidityProvider = false, LedgerRules rules = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AmmPool | pool | The pool. |
| Common.IssuedCurrency | asset | Which of the pool's assets to withdraw. |
| XrplNumber | amount | The transaction's |
| XrplNumber | effectivePrice | The transaction's |
| XrplNumber | holderLpTokens | The LP tokens the account holds. |
| bool | isOnlyLiquidityProvider | Whether the account is the pool's only liquidity provider. |
| LedgerRules | rules | The amendments in force; the current rules when null. |
Returns
| Type | Description |
|---|---|
| AmmQuote |