XRPLF / xrpl-dev-portal

Source code for xrpl.org including developer documentation
https://xrpl.org
Other
533 stars 1.02k forks source link

Convert AMM LP token code to human readable string #2689

Closed binaryechoes closed 3 months ago

binaryechoes commented 3 months ago

Hello,

What is the recommended approach for converting the AMM LP token code to a human readable string (eg. 03930D02208264E2E40EC1B0C09E4DB96EE197B1 -> XRP/USD) using Python?

For example, here's how I convert 5553444300000000000000000000000000000000 to USDC.

>>> token_code = '5553444300000000000000000000000000000000' # usdc
>>> bytes.fromhex(token_code).decode("ascii").replace('\x00', '')
'USDC'

However, this does not work for AMM LP token codes.

Reference: https://xrpl.org/docs/concepts/tokens/decentralized-exchange/automated-market-makers/#lp-token-currency-codes https://xrpl.org/docs/references/protocol/data-types/currency-formats/#currency-codes https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0030-automated-market-maker

Thanks, Justin

mDuo13 commented 3 months ago

There is no way to convert directly from an AMM currency code to something human readable. The AMM currency code needs to represent more data than can fit in one currency code (namely, two currency codes), so it just doesn't have what you need.

If you know the AMM's info, you can replace the currency code with a string that represents "LP Tokens from this AMM" in whatever way makes sense, but the data in the currency code can only serve as a checksum or on that info at best.

binaryechoes commented 3 months ago

Great, thank you for the confirmation/info @mDuo13!