XRPL-Labs/Xaman-App

[Feature] AMM amendment: impact notes

Opened this issue · 0 comments

The AMM amendment hit devnet;
https://opensource.ripple.com/docs/xls-30d-amm/automated-market-makers/

Time to implement in Xumm. This issue contains an incomplete list of things to take into account when implementing in Xumm

TLDR:

  • Couple of new tx types
  • Alternative TL type on home screen for LP tokens (regular TrustLines with some visual display differences)
  • Filter in asset list in Send flow
  • AMM Specific fields to show in event list & tx details (2 assets per tx)
  • Different actions for AMM TLs: Deposit/Withdraw from AMM, instead of Send & Exchange

0. The AMM behaves on the XRPL as if it's an account.

1. New TX types

AMMBid
AMMCreate
AMMDelete
AMMDeposit
AMMVote
AMMWithdraw

2. New type of TrustLines

A Trust Line from the LP (user, liquidity provider) to the AMM contains the LP Tokens (liquidity pool tokens).

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.

Home screen TLs

We should render Home Screen TLs with an AMM badge, and display both assets. The both make up the specific AMM, and there can only be one AMM per pair.

3. !!! These TrustLines have a non standard currency code (HEX). This means that in the Asset list, we should detect that these assets are AMMs and render them accordingly, instead of a regular Trust Line.

LP Tokens use a special type of currency code in the 160-bit hexadecimal "non-standard" format. These codes have the first 8 bits 0x03. The remainder of the code is a SHA-512 hash, truncated to the first 152 bits, of the two assets' currency codes and their issuers. (The assets are placed in a "canonical order" with the numerically lower currency+issuer pair first.) As a result, the LP Tokens for a given asset pair's AMM have a predictable, consistent currency code.

This means that in the Send flow, these assets are not to be selected. When the TL is tapped, we shouldn't render Send/Exchange, but AMM specific features. I propose:

AMMDeposit
AMMWithdraw

Both the simplest implementation, where just a given amount of LP tokens can be withdrawn or a fixed amount of the AMM assets.

Both should be treated as "Double asset deposits/withdrawals":

"in which you provide both assets in the AMM's pool, proportional to the balance of the assets already there. These deposits are not subject to a fee."

If users want more complex AMM transactions, they should use an xApp.

Event list & Events

We should display both assets affected for the AMM in the event list, so users can see both assets affected (e.g. 1 USD & 2 XRP deposited). Same on the Event details page.