Skip to content

Commit

Permalink
Fix AMM asset restrictions (no LP tokens)
Browse files Browse the repository at this point in the history
  • Loading branch information
mDuo13 committed Oct 31, 2023
1 parent b488ecb commit b37bccd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions content/@i18n/ja/concepts/tokens/automated-market-makers.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ AMMは、プール内の資産残高に基づき取引レートを設定しま

XRP Ledgerの実装は、重みパラメータを0.5とした _幾何平均_ AMMですので、_定積_ マーケットメーカーのように機能します。 _定積_ AMMの公式や一般的なAMMの経済学についての詳しい説明は、[Kris Machowski's Introduction to Automated Market Makers](https://www.machow.ski/posts/an_introduction_to_automated_market_makers/)をご覧ください。

### 資産の制限 <a id="restrictions-on-assets"></a>
<!-- TODO: translate this section -->

To prevent misuse, some restrictions apply to the assets used in an AMM. If you try to create an AMM with an asset that does not meet these restrictions, the transaction fails. The rules are as follows:

- The asset must not be an LP Token from another AMM.
- If the asset is a token whose issuer uses [Authorized Trust Lines](authorized-trust-lines.html), the creator of the AMM must be authorized to hold those tokens. Only users whose trust lines are authorized can deposit that token into the AMM or withdraw it; however, users can still deposit or withdraw the other asset.
- If the [Clawback amendment][] :not_enabled: is enabled, the issuer of the token must not have enabled the ability to claw back their tokens.

## LPトークン
<!-- TODO: add diagrams showcasing flow of funds -->
Expand Down
10 changes: 9 additions & 1 deletion content/concepts/tokens/automated-market-makers.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ The AMM also charges a percentage trading fee on top of the exchange rate.

The XRP Ledger's implements a _geometric mean_ AMM with a weight parameter of 0.5, so it functions like a _constant product_ market maker. For a detailed explanation of the _constant product_ AMM formula and the economics of AMMs in general, see [Kris Machowski's Introduction to Automated Market Makers](https://www.machow.ski/posts/an_introduction_to_automated_market_makers/).

### Restrictions on Assets

To prevent misuse, some restrictions apply to the assets used in an AMM. If you try to create an AMM with an asset that does not meet these restrictions, the transaction fails. The rules are as follows:

- The asset must not be an LP Token from another AMM.
- If the asset is a token whose issuer uses [Authorized Trust Lines](authorized-trust-lines.html), the creator of the AMM must be authorized to hold those tokens. Only users whose trust lines are authorized can deposit that token into the AMM or withdraw it; however, users can still deposit or withdraw the other asset.
- If the [Clawback amendment][] :not_enabled: is enabled, the issuer of the token must not have enabled the ability to claw back their tokens.


## LP Tokens
<!-- TODO: add diagrams showcasing flow of funds -->
Expand All @@ -43,7 +51,7 @@ For example, if you created an AMM with 5 ETH and 5 USD, and then someone exchan

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.

LP Tokens are like other tokens in the XRP Ledger, so you can use them in many [types of payments](payment-types.html), trade them in the decentralized exchange, or even deposit them as assets for new AMMs. (To receive LP Tokens as payment, you must set up a [trust line](trust-lines-and-issuing.html) with a nonzero limit with the AMM Account as the issuer.) However, you can _only_ send LP Tokens directly to the AMM (redeeming them) using the [AMMWithdraw][] transaction type, not through other types of payments. Similarly, you can only send assets to the AMM's pool through the [AMMDeposit][] transaction type.
LP Tokens are like other tokens in the XRP Ledger, so you can use them in many [types of payments](payment-types.html) or trade them in the decentralized exchange. (To receive LP Tokens as payment, you must set up a [trust line](trust-lines-and-issuing.html) with a nonzero limit with the AMM Account as the issuer.) However, you can _only_ send LP Tokens directly to the AMM (redeeming them) using the [AMMWithdraw][] transaction type, not through other types of payments. Similarly, you can only send assets to the AMM's pool through the [AMMDeposit][] transaction type.

The AMM is designed so that an AMM's asset pool is empty if and only if the AMM has no outstanding LP Tokens. This situation can only occur as the result of an [AMMWithdraw][] transaction; when it does, the AMM is automatically deleted.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Creates both an [AMM entry][] and a [special AccountRoot entry](accountroot.html
| `Amount2` | [Currency Amount][] | Amount | Yes | The second of the two assets to fund this AMM with. This must be a positive amount. |
| `TradingFee` | Number | UInt16 | Yes | The fee to charge for trades against this AMM instance, in units of 1/100,000; a value of 1 is equivalent to 0.001%. The maximum value is `1000`, indicating a 1% fee. The minimum value is `0`. |

One or both of `Amount` and `Amount2` can be [tokens](tokens.html); at most one of them can be [XRP](xrp.html). They cannot both have the same currency code and issuer. The tokens' issuers must have [Default Ripple](rippling.html#the-default-ripple-flag) enabled. If the [Clawback amendment][] :not_enabled: is enabled, those issuers must not have enabled the Allow Clawback flag. An AMM's LP tokens _can_ be used as one of the assets for another AMM.
One or both of `Amount` and `Amount2` can be [tokens](tokens.html); at most one of them can be [XRP](xrp.html). They cannot both have the same currency code and issuer. The tokens' issuers must have [Default Ripple](rippling.html#the-default-ripple-flag) enabled. If the [Clawback amendment][] :not_enabled: is enabled, those issuers must not have enabled the Allow Clawback flag. The assets _cannot_ be LP tokens for another AMM.

## Special Transaction Cost

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ _JavaScript_

As the creator of an AMM, you are also the first liquidity provider and you have to supply it with a starting pool of assets. Other users of the XRP Ledger can also become liquidity providers by supplying assets after the AMM exists. It's crucial to choose assets carefully because, as a liquidity provider for an AMM, you are supplying some amounts of both for users to swap between. If one of the AMM's assets becomes worthless, other users can use the AMM to trade for the other asset, leaving the AMM (and thus, its liquidity providers including you) holding only the worthless one. Technically, the AMM always holds some positive amount of both assets, but the amounts can be very small.

You can choose any pair of fungible assets in the XRP Ledger, including XRP or tokens, including LP Tokens from another AMM. If you use a token, you must hold some amount of that token. (If a token's issuer uses, [authorized trust lines](authorized-trust-lines.html), that means you have to be authorized first.)
You can choose any pair of fungible assets in the XRP Ledger, including XRP or tokens, as long as they meet the [restrictions on AMM assets](automated-market-makers.html#restrictions-on-assets).

For each of the two assets, you need to know its currency code and issuer; as an exception, XRP has no issuer. For each of the assets, you must hold a balance of the asset (or _be_ the issuer). The following sample code acquires two assets, "TST" (which it buys using XRP) and "FOO" (which it receives from the issuer).

Expand Down
4 changes: 3 additions & 1 deletion dactyl-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ pages:
- en

- md: "@i18n/ja/concepts/tokens/automated-market-makers.md"
outdated_translation: true
targets:
- ja

Expand Down Expand Up @@ -2501,6 +2502,7 @@ pages:
- en

- md: "@i18n/ja/references/protocol-reference/transactions/transaction-types/ammcreate.md"
outdated_translation: true
targets:
- ja

Expand Down Expand Up @@ -3003,7 +3005,7 @@ pages:
- md: "@i18n/ja/references/http-websocket-apis/api-conventions/rippled-server-states.md"
targets:
- ja

# TODO: translate
- md: references/http-websocket-apis/api-conventions/ctid.md
targets:
Expand Down

0 comments on commit b37bccd

Please sign in to comment.