Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper handling of OfferCreate type of transactions #4

Open
b0tm1nd opened this issue Jul 12, 2023 · 3 comments
Open

Improper handling of OfferCreate type of transactions #4

b0tm1nd opened this issue Jul 12, 2023 · 3 comments

Comments

@b0tm1nd
Copy link

b0tm1nd commented Jul 12, 2023

A transaction of this kind when doing a token-token exchange will return 2 separate transactions with parseExchanges() with absolutely wrong exchange rates.
From what I have discovered, there is only documentation for a transaction metadata at https://xrpl.org/transaction-metadata.html
but nothing really about what is inside of PreviousFields and FinalFields.
That's why I'm wondering where the logic from parseExchanges() comes from?
Thanks

PS. I have found an abandoned project at https://www.npmjs.com/package/ripple-lib-transactionparser and also ripple-lib which are closed in flavor of the official https://github.com/XRPLF/xrpl.js
But can't really find how can you parse a transaction with it.

@Mwni
Copy link
Owner

Mwni commented Jul 12, 2023

This is because the exchange in question consumed 2 offers. You can pass extractExchanges(tx, { collapse: true }) to have the expected output, but note that you will lose information about the individual offers, such as maker, hash and sequence.

PS. I respect your courage to use this library in alpha without any documentation whatsoever 😄

@b0tm1nd
Copy link
Author

b0tm1nd commented Jul 12, 2023

PS. I respect your courage to use this library in alpha without any documentation whatsoever smile

Do you mean like using your library? I've started working on a ready made project and there happened an issue with improper calculation of exchange rates for OfferCreate type of transactions.
So I've started digging the code and documentation.. For some reason could not find any documentation for PreviousFields and FinalFields, TakerPays, TakerGets..
Then searched gitHub for those keywords and found that it's actually using some files and functions from your lib.

Wondering how have you figured out to calculate a transaction balance by subtracting (previousTakerPays.value - finalTakerPays.value) as this is not in documentation?
I've seen similar libs use (FinalFields.Balance - PreviousFields.Balance) for the goal.

@Mwni
Copy link
Owner

Mwni commented Jul 12, 2023

previousTakerPays.value - finalTakerPays.value represents the change in the offer size, thus allows for derivation of the amount consumed by the taker, and by extension, in aggregate, the actual exchange rate of the trade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants