XRPLF / rippled

Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
https://xrpl.org
ISC License
4.48k stars 1.45k forks source link

Cannot determine which is the AMM Pool on the trustline between the AMM Pool and the token issuer. #4991

Open tequdev opened 2 months ago

tequdev commented 2 months ago

Issue Description

Cannot determine which is the AMM Account on the High or Low account on the trust line between the AMM Pool and the token issuer.

This is due to that lsfAMMNode does not have High ,Low information.

{
  "ModifiedNode": {
    "FinalFields": {
      "Balance": {
        "currency": "5553444300000000000000000000000000000000",
        "issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
        "value": "-224388.3522748358"
      },
      "Flags": 16908288,
      "HighLimit": {
        "currency": "5553444300000000000000000000000000000000",
        "issuer": "rGHt6LT5v9DVaEAmFzj5ciuxuj41ZjLofs",
        "value": "0"
      },
      "HighNode": "0",
      "LowLimit": {
        "currency": "5553444300000000000000000000000000000000",
        "issuer": "rcEGREd8NmkKRE8GE424sksyt1tJVFZwu",
        "value": "0"
      },
      "LowNode": "10a"
    },
    "LedgerEntryType": "RippleState",
    "LedgerIndex": "CDE55A8290DF221A643F51798BE6294A69384066D1ECFB7C2B9BEE2004B38D63",
    "PreviousFields": {
      "Balance": {
        "currency": "5553444300000000000000000000000000000000",
        "issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
        "value": "-224388.1546979297"
      }
    },
    "PreviousTxnID": "FCA38878BFA22CC4941045FB7088755623C6F4B303359371209CACB29A920668",
    "PreviousTxnLgrSeq": 87339469
  }
}
mvadari commented 2 months ago

The code I use to determine which is the issuer:

let limit = obj.LowLimit.value === "0" ? obj.LowLimit : obj.HighLimit;
if (obj.Balance.value !== "0") {
    limit = Number(obj.Balance.value) < 0 ? obj.LowLimit : obj.HighLimit;
}
const issuer = limit.issuer;

The balance of an AMM trustline should never be 0, so it should be easy to figure out that way.

tequdev commented 2 months ago

It seems that most situations can be handled with that script. but isn't Balance to be 0 in a situation where an AMMDelete transaction could happen?

mvadari commented 2 months ago

In that case, both trustlines should be deleted, so only one account should be in both trustlines, right?

ximinez commented 2 months ago

The intention of that flag was only to signal to tooling that an AMM is involved. The expectation was that any tools that care can query the account IDs to determine which is the AMM.

tequdev commented 2 months ago

In that case, both trustlines should be deleted, so only one account should be in both trustlines, right?

Ah yes, in SeagullCash's experience, when tokens are gone from the pool, the Pool-Issuer trustline is deleted, so there cannot be a Pool-Issuer trustline with a Balance of 0.

But if the issuer changes the trustline flag, the trustline may not be removed.

mvadari commented 2 months ago

In that case, both trustlines should be deleted, so only one account should be in both trustlines, right?

Ah yes, in SeagullCash's experience, when tokens are gone from the pool, the Pool-Issuer trustline is deleted, so there cannot be a Pool-Issuer trustline with a Balance of 0.

But if the issuer changes the trustline flag, the trustline may not be removed.

In that case, the AMMDelete would fail anyways I assume.