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

Add AMMClawback Transaction (XLS-0073d) #5142

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

yinyiqian1
Copy link
Collaborator

@yinyiqian1 yinyiqian1 commented Sep 19, 2024

High Level Overview of Change

Context of Change

Spec link: XRPLF/XRPL-Standards#212

This PR includes:

  1. Allow AMMCreate for clawback-enabled tokens
    changes are in AMMCreate and AMM_test
  2. AMMDeposit prohibits depositing if either of the paired tokens is frozen
    changes are in AMMDeposit and AMM_test
  3. Added AMMClawback transaction.
    mainly in AMMClawback and AMMClawback_test

Some refactor happens because I want to call some functions from AMMWithdraw.
1. Refactor of withdraw:

  • Added static withdraw function to return the amountWithdrawActual and amount2WithdrawActual as well.
  • private overload withdraw.
  • Previously in withdraw function, it checks if (!(ctx_.tx[sfFlags] & (tfWithdrawAll | tfOneAssetWithdrawAll))) to decide if it needs to call adjustAmountsByLPTokens. Because these flags only belong to AMMWithdraw, to make this function also work for AMMClawback, I changed it by passing enum WithdrawAll.

2. Refactor of equalWithdrawTokens:
Because I want to call this function in AMMClawback, I make a public static equalWithdrawTokens function. And also private overload equalWithdrawTokens

3. Added deleteAMMAccountIfEmpty
Since I need to reuse the logic in AMMWithdraw that when all the tokens are withdrawn, the amm account is deleted, so I added function deleteAMMAccountIfEmpty.


Reason of adding flag tfClawTwoAssets:
If the issuer issues both assets A and B in the amm pool, when clawing back A, tfClawTwoAssets is used to decide if the paired token B to be clawed back as well or goes back to the holder. If tfClawTwoAssets` is set true, the paired token will be clawed back as well. Otherwise, the paired token goes back to the holder.

Reason of adding both asset and amount in the AMMClawback request:
amount is used to decide if the issuer wants to clawback all the tokens or not. (if amount is not provided, then clawback all) Imagine if an issuer issues both asset A and B in the amm pool, and the issuer wants to clawback all A and give back all the corresponding B to the holder. Then the issuer just needs to specify A in asset field and leave out amount field.

Reasons for setting tfee as 0:
Because we are doing a two-asset withdrawal. tfee is not used.

Reasons for using asset1 and asset2 to navigate amm
To keep the same with other amm transactions and make it simple.
So we require providing asset1 and asset2 in the AMMClawback request.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.2%. Comparing base (bf4a7b6) to head (d3d7292).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5142     +/-   ##
=========================================
+ Coverage     76.2%   76.2%   +0.1%     
=========================================
  Files          760     762      +2     
  Lines        61568   61697    +129     
  Branches      8126    8110     -16     
=========================================
+ Hits         46898   47043    +145     
+ Misses       14670   14654     -16     
Files with missing lines Coverage Δ
include/xrpl/protocol/Feature.h 100.0% <ø> (ø)
include/xrpl/protocol/SField.h 100.0% <ø> (ø)
src/libxrpl/protocol/Feature.cpp 94.6% <ø> (ø)
src/libxrpl/protocol/SField.cpp 77.5% <ø> (ø)
src/libxrpl/protocol/TER.cpp 100.0% <ø> (ø)
src/libxrpl/protocol/TxFormats.cpp 100.0% <100.0%> (ø)
src/xrpld/app/tx/detail/AMMClawback.cpp 100.0% <100.0%> (ø)
src/xrpld/app/tx/detail/AMMClawback.h 100.0% <100.0%> (ø)
src/xrpld/app/tx/detail/AMMCreate.cpp 90.3% <100.0%> (+0.1%) ⬆️
src/xrpld/app/tx/detail/AMMDeposit.cpp 95.0% <100.0%> (-0.1%) ⬇️
... and 4 more

... and 4 files with indirect coverage changes

Impacted file tree graph

@mvadari
Copy link
Collaborator

mvadari commented Sep 19, 2024

Note: The PR title is wrong, it should be XLS-73d

@yinyiqian1 yinyiqian1 changed the title Add AMMClawback Transaction (XLS-0074d) Add AMMClawback Transaction (XLS-0073d) Sep 19, 2024
@yinyiqian1
Copy link
Collaborator Author

Note: The PR title is wrong, it should be XLS-73d
Just corrected it. Thank you.

@yinyiqian1 yinyiqian1 changed the title Add AMMClawback Transaction (XLS-0073d) [Do not review] Add AMMClawback Transaction (XLS-0073d) Sep 19, 2024
@yinyiqian1 yinyiqian1 force-pushed the amm-clawback branch 2 times, most recently from ad78c7c to a8f9c1b Compare September 19, 2024 17:28
@yinyiqian1 yinyiqian1 changed the title [Do not review] Add AMMClawback Transaction (XLS-0073d) Add AMMClawback Transaction (XLS-0073d) Sep 19, 2024
@yinyiqian1 yinyiqian1 marked this pull request as ready for review September 23, 2024 16:36
include/xrpl/protocol/jss.h Outdated Show resolved Hide resolved
include/xrpl/protocol/SField.h Outdated Show resolved Hide resolved
@@ -139,6 +139,8 @@ enum TEMcodes : TERUnderlyingType {

temARRAY_EMPTY,
temARRAY_TOO_LARGE,
temBAD_ASSET_AMOUNT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use temBAD_AMOUN and temBAD_ISSUER instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a temBAD_AMOUNT already defined for non-positive amount errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I mean, don't need to define new ones.

Copy link
Collaborator Author

@yinyiqian1 yinyiqian1 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the request's error message for this one will be inaccurate: Can only send positive amounts.
But I intended to return error message as Malformed: Amount does not match Asset.
temBAD_AMOUNT is only for positive amount check.
I think defining this new error will benefit if in the future, we need to check if asset matches with amount again.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just use temMALFORMED then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also thrown in the escrow code if the asset isn't XRP.

Copy link
Collaborator Author

@yinyiqian1 yinyiqian1 Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in escrow code, if it's using temBAD_AMOUNT, the error message will be "Can only send positive amounts.". It does not match with that the asset isn't XRP. I think in escrow, it should just use temMalformed or define more accurate error type. Maybe we should enrich our error code to return more accurate error messages. Because these errors can be used in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just change the error message, so that it makes sense both in Escrow and here, instead of needing a new error code? I believe changing the error message isn't considered a breaking change/needing an amendment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the message for temBAD_AMOUNT to "bad amount provided". What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Malformed: Bad amount. would keep it in line with the others.

src/libxrpl/protocol/TER.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMDeposit.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMWithdraw.h Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMWithdraw.cpp Show resolved Hide resolved
src/test/jtx/impl/AMM.cpp Show resolved Hide resolved
@kennyzlei kennyzlei requested review from dangell7 and removed request for shawnxie999 September 26, 2024 17:41
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMMClawback_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMMClawback_test.cpp Outdated Show resolved Hide resolved
@yinyiqian1 yinyiqian1 force-pushed the amm-clawback branch 3 times, most recently from 5381c04 to 51df02e Compare September 27, 2024 14:57
src/test/app/AMMClawback_test.cpp Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
src/xrpld/app/misc/detail/AMMUtils.cpp Outdated Show resolved Hide resolved
src/xrpld/app/misc/detail/AMMUtils.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMWithdraw.h Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMWithdraw.h Show resolved Hide resolved
@yinyiqian1 yinyiqian1 force-pushed the amm-clawback branch 2 times, most recently from 99c0d02 to 908318b Compare October 1, 2024 01:36
Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
src/test/jtx/impl/AMM.cpp Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

4 participants