Merge pull request #3960 from XRPLF/wiki-migration-lp-token-calculation

Add LP tokens calculation formula from wiki page
This commit is contained in:
rachelflynn
2026-09-23 16:41:12 -04:00
committed by GitHub
2 changed files with 20 additions and 9 deletions

View File

@@ -94,7 +94,7 @@ Whoever creates the AMM becomes the first liquidity provider, and receives LP to
For example, if you created an AMM with 5 ETH and 5 USD, and then someone exchanged 1.26 USD for 1 ETH, the pool now has 4 ETH and 6.26 USD in it. You can spend half your LP tokens to withdraw 2 ETH and 3.13 USD.
Anyone can deposit assets to an existing AMM. When they do, they receive new LP tokens based on how much they deposited. The amount that a liquidity provider can withdraw from an AMM is based on the proportion of the AMM's LP tokens they hold compared to the total number of LP tokens outstanding.
Anyone can deposit assets to an existing AMM. When they do, they receive new LP tokens based on how much they deposited. The amount that a liquidity provider can withdraw from an AMM is based on the proportion of the AMM's LP tokens they hold compared to the total number of LP tokens outstanding. For more information about calculating your share, see [Calculate the Value of Your LP Tokens](/docs/references/http-websocket-apis/public-api-methods/path-and-order-book-methods/amm_info.md#calculate-the-value-of-your-lp-tokens).
LP tokens are a specific type of [trust line token](../fungible-tokens/trust-line-tokens.md) and share most of the properties of other trust line tokens. You can use them in many types of payment, or trade them in the decentralized exchange. To receive LP tokens as payment from other holders, you must set up a [trust line](../fungible-tokens/index.md) with a non-zero limit with the AMM Account as the issuer. However, you cannot send and receive LP tokens directly to and from the AMM through regular payments types. Instead, LP tokens are automatically issued when you do an [AMMDeposit transaction][], and you redeem them using an [AMMWithdraw transaction][].

View File

@@ -13,8 +13,7 @@ The {% code-page-name /%} method gets information about an [Automated Market Mak
{% amendment-disclaimer name="AMM" /%}
### Request Format
## Request Format
An example of the request format:
@@ -73,7 +72,7 @@ The request includes the following parameters:
You must specify _either_ `amm_account` or both `asset` and `asset2`.
### Response Format
## Response Format
An example of a successful response:
@@ -202,7 +201,6 @@ The response follows the [standard format][], with a successful result containin
| `ledger_index` | [Ledger Index][] | _(Omitted if `ledger_current_index` is provided instead)_ The [ledger index][] of the ledger version used when retrieving this information. |
| `validated` | Boolean | If `true`, the ledger used for this request is validated and these results are final; if omitted or set to `false`, the data is pending and may change. |
### AMM Description Object
The `amm` field is an object describing the current status of an Automated Market Maker (AMM) in the ledger, and contains the following fields:
@@ -219,7 +217,6 @@ The `amm` field is an object describing the current status of an Automated Marke
| `trading_fee` | Number | The AMM's current trading fee, in units of 1/100,000; a value of 1 is equivalent to a 0.001% fee. |
| `vote_slots` | Array | _(May be omitted)_ The current votes for the AMM's trading fee, as [Vote Slot Objects](#vote-slot-objects). |
### Auction Slot Object
The `auction_slot` field of the `amm` object describes the current auction slot holder of the AMM, and contains the following fields:
@@ -233,7 +230,6 @@ The `auction_slot` field of the `amm` object describes the current auction slot
| `price` | [Currency Amount][] | The amount, in LP Tokens, that the auction slot holder paid to win the auction slot. This affects the price to outbid the current slot holder. |
| `time_interval` | Number | The current 72-minute time interval this auction slot is in, from 0 to 19. The auction slot expires after 24 hours (20 intervals of 72 minutes) and affects the cost to outbid the current holder and how much the current holder is refunded if someone outbids them. |
### Vote Slot Objects
Each entry in the `vote_slots` array represents one liquidity provider's vote to set the trading fee, and contains the following fields:
@@ -244,14 +240,29 @@ Each entry in the `vote_slots` array represents one liquidity provider's vote to
| `trading_fee` | Number | The trading fee this liquidity provider voted for, in units of 1/100,000. |
| `vote_weight` | Number | How much this liquidity provider's vote counts towards the final trading fee. This is proportional to how much of the AMM's LP Tokens this liquidity provider holds. The value is equal to 100,000 times the number of this LP Tokens this liquidity provider holds, divided by the total number of LP Tokens outstanding. For example, a value of 1000 means that the liquidity provider holds 1% of this AMM's LP Tokens. |
## Calculate the Value of Your LP Tokens
### Possible Errors
To calculate the worth of a given amount of LP Tokens, call `amm_info` for the asset pair, then:
1. **Get your fractional share of the pool:** Divide your LP Token amount by the `value` field of `lp_token`, the pool's total outstanding LP Tokens.
2. **Get your share of each asset:** Multiply that fraction by the `value` fields of `amount` and `amount2`.
For example, if you hold `N` LP Tokens:
```text
my_share = N / lp_token.value
my_asset1 = amount.value * my_share
my_asset2 = amount2.value * my_share
```
Redeeming your LP Tokens via [AMMWithdraw](/docs/references/protocol/transactions/types/ammwithdraw) entitles you to withdraw approximately this share of each asset.
## Possible Errors
- Any of the [universal error types][].
- `actNotFound` - The AMM for this asset pair does not exist, or an account specified in the request does not exist.
- `invalidParams` - One or more fields are specified incorrectly, or one or more required fields are missing.
## See Also
- [AMM object](../../../protocol/ledger-data/ledger-entry-types/amm.md) - The canonical storage format of the AMM object