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

temREDUNDANT when swapping Gatehub USD with Bistamp USD (Version: 2.1.1) #4994

Closed VLEFF closed 2 days ago

VLEFF commented 2 months ago

Issue Description

When executing a swap transaction between Gatehub USD and Bitstamp USD, a temREDUNDANT error is thrown by the rippled engine.

Same currency with different issuer is the only reason I can see behind this bug, since it only appears for this swap pair.

Steps to Reproduce

{
  "TransactionType":"Payment",
  "Destination":"<my-account>",
  "Account":"<my-account>",
  "Amount":{
      "value":10.8951797815249,
      "currency":"USD",
      "issuer":"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"
   },
   "SendMax":{
      "value":11.0279832334121,
      "currency":"USD",
      "issuer":"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
   },
   "Fee":"10",
   "Sequence":<my-sequence>,
   "Flags":2147614720,
}
tequdev commented 2 months ago

For Swaps with the same currency code, you should specify the Paths field.

https://github.com/XRPLF/rippled/blob/c88166e055e4378f78fb0236e0bf347d6544e517/src/ripple/app/tx/impl/Payment.cpp#L121-L130

VLEFF commented 2 months ago

Why that? Is that a feature or a bug? Since issuers are different, it should be treated as different currencies

tequdev commented 2 months ago

It is a very long-standing process and I don't know about it. It may be a check that is necessary when considering the Rippling.

VLEFF commented 2 months ago

Ok, at least there is a solution! I'm still curious about the exact reason, if someone with this knowledge passes by

VLEFF commented 2 months ago

@tequdev How should the path be built?

I tried many combination with what I found on https://xrpl.org/docs/concepts/tokens/fungible-tokens/paths/ and https://xrpl.org/docs/references/http-websocket-apis/public-api-methods/path-and-order-book-methods/ripple_path_find/

But I always end up with either a temBAD_PATH, temBAD_PATH_LOOP or tecPATH_DRY (trustlines are set, and partial payment flag is on).

I didn't find anything about paths for AMM, maybe it's different?

The only path accepted by rippled engine that threw tecPATH_DRY is this one :

[
    {
        "account": "<my-account>"
    },
    {
        "account": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"
    },
    {
        "currency": "USD",
        "issuer": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"
    },
    {
        "currency": "USD",
        "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
    },
    {
        "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
    },
    {
        "account": "<my-account>"
    }
]

EDIT:

ripple-path-find method don't return any path

{
    "method": "ripple_path_find",
    "params": [
        {
            "destination_account": "<my-account>",
            "source_account": "<my-account>",
            "destination_amount": {
                "currency": "USD",
                "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
                "value": "0.001"
            },
            "source_currencies": [
                {
                    "currency": "USD",
                    "issuer": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"
                }
            ]
        }
    ]
}
{
    "result": {
        "alternatives": [],
        "destination_account": "<my-account>",
        "destination_amount": {
            "currency": "USD",
            "issuer": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",
            "value": "0.001"
        },
        "destination_currencies": [
            "MAG",
            "EUR",
            "ELS",
            "5845504500000000000000000000000000000000",
            "5553444300000000000000000000000000000000",
            "USD",
            "RPR",
            "434F524500000000000000000000000000000000",
            "XLM",
            "XDX",
            "ARK",
            "XRP"
        ],
        "full_reply": true,
        "source_account": "<my-account>",
        "status": "success"
    }
}
tequdev commented 2 months ago

it would work with the following Paths field

"Paths": [
    [
        {
            "currency":"XRP"
        },
        {
            "currency":"USD"
            "issuer":"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        }
    ]
]

When specifying both destination_amount and source_amount in path_find, the amount you want to send should be specified in source_amount, and the value of destination_amount should be "-1". https://github.com/XRPLF/rippled/blob/c88166e055e4378f78fb0236e0bf347d6544e517/src/ripple/app/paths/PathRequest.cpp#L177-L182

Your code is incorrect, so it is not making the expected path_find result.

VLEFF commented 2 months ago

I'll try the path later,

for the path request, I'm not using source_amount, this is not the problem (I'm not getting the amount malformed exception)

VLEFF commented 2 months ago

I just tried your path, and it works!

I was asking myself "why add XRP in the path since XRP is not involved?" But after trying to remove it and only use :

"Paths": [
    [
        {
            "currency":"USD"
            "issuer":"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        }
    ]
]

It works too. As simple as that.

Thx for the help ;)

mvadari commented 2 days ago

Closing this issue as it appears resolved.