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

#576: Add support for AMMClawback #601

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

agutierrez0
Copy link
Contributor

@agutierrez0 agutierrez0 commented Feb 19, 2025

closes #576

  • add AmmClawback to SignatureUtils, Transaction.java, TransactionType.java, and TransactionTypeTests.java
    • add test in SignatureUtils for the new AmmClawback class
  • create AmmClawbackFlags with only tfCalwTwoAssets flag or unset flags
  • create AmmClawback under transactions
  • generate new definitions.json
  • create new AmmClawbackTest transaction test
  • updated rippled container version to 2.3.0 from 2.2.0-rc3
  • enable new AMMClawback amendment in rippled.cfg
  • added integration tests under AmmIt
    • one test where we clawback with amount
    • one test where we clawback two assets using tfClawbackTwoAssets
    • one test where we clawback without amount and only clawback one asset

Comment on lines +48 to +50
public boolean tfClawTwoAssets() {
return this.isSet(CLAW_TWO_ASSETS);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unused, i added it to follow the practice I saw with other TransactionFlag classes I saw (e.g. AmmWithdrawFlags). Let me know if I should remove.

@@ -84,7 +82,7 @@ public class RippledContainer {
* No-args constructor.
*/
public RippledContainer() {
try (GenericContainer<?> container = new GenericContainer<>("rippleci/rippled:2.2.0")) {
try (GenericContainer<?> container = new GenericContainer<>("rippleci/rippled:2.3.0")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if there is another version I could use here instead of 2.3.0

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think version 2.3.1 is the most recent version, so we should use that

Comment on lines 69 to 73
@JsonProperty("Flags")
@Value.Default
default AmmClawbackFlags flags() {
return AmmClawbackFlags.UNSET;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed there was only one flag AMMClawback can be set to, this tfClawTwoAssets so I set the default to be UNSET, but if I should instead just make this an Optional<> field, let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To align with other Transaction sub-types, this should default to AmmClawbackFlags.empty()

Copy link
Contributor Author

@agutierrez0 agutierrez0 Feb 19, 2025

Choose a reason for hiding this comment

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

For the three integration tests that I wrote, i would say around 90% of the code is the exact same:

  1. create trust lines
  2. send payments
  3. create amm
  4. deposit in amm
  5. clawback assets in AMM

the only difference really is in the flags and/or the inclusion of amount in the final AMMClawback tx.

should I break down that that 90% into something more reusable?

e.g.

  • create the following functions:
    • createTrustline
    • createPayment
    • depositToAmm
    • etc..
  • adjust the createAmm function so that it can be reused

i had started going down this path (like what I did when changing enableRippling to enableFlag), but wanted to get an opinion first.

import org.xrpl.xrpl4j.model.flags.AmmClawbackFlags;
import org.xrpl.xrpl4j.model.flags.TransactionFlags;
import org.xrpl.xrpl4j.model.ledger.Issue;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import org.xrpl.xrpl4j.model.transactions.Address;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have added this extra import, but on my IDE it shows as unused.

when i define the type for holder, i do see the Address references this path, but doesn't add the import. is there any reason why this happens?

SubmitResult<TrustSet> trustlineSubmitResult2 = xrplClient.submit(signedTrustline2);
assertThat(trustlineSubmitResult2.engineResult()).isEqualTo(TransactionResultCodes.TES_SUCCESS);

// send payment of ZFT to trader wallet from issuer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using real currency names, especially ones that are a familiar, like usd and xrp. It will be one less thing for developers to have keep track of while they seek to understand these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have replaced TST with USD and replaced ZFT with the existing token xrpl4j

and not sure why, i was able to build before committing... but after committing this last change, now my build constantly fails 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

upd: build no longer failing

"nth": 258,
"isVLEncoded": false,
"isSerialized": false,
"isSigningField": false,
"type": "Amount"
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What version of rippled did you generate this definitions.json from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i initially generated the definitions.json using this branch on the xrpl.js library. i compared it to the definitions.json that was commited to that repo after adding support for AMMClawback, and noticed mine was different so i used the same one the xrpl.js library used.

should i instead commit the file i get by running the script again on the latest in rippled's develop branch?

/**
* {@link TransactionFlags} for {@link AmmClawback} transactions.
*/
public class AmmClawbackFlags extends TransactionFlags {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at other TransactionFlags implementations, we always have a static empty() method which calls a private no-arg constructor. Check out OfferCreateFlags for reference

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this class needs a test. Check out OfferCreateFlagsTests as an example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have added this static empty() method and also added AmmClawbackFlagTest. thanks for the references 👍🏽 let me know what you think

Comment on lines 69 to 73
@JsonProperty("Flags")
@Value.Default
default AmmClawbackFlags flags() {
return AmmClawbackFlags.UNSET;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

To align with other Transaction sub-types, this should default to AmmClawbackFlags.empty()

@@ -60,10 +65,11 @@ public class AmmIT extends AbstractIT {

static boolean shouldNotRun() {
return System.getProperty("useTestnet") != null ||
System.getProperty("useClioTestnet") != null;
System.getProperty("useClioTestnet") != null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think your formatting settings are off, I'll send you the intellij formatting template

@@ -84,7 +82,7 @@ public class RippledContainer {
* No-args constructor.
*/
public RippledContainer() {
try (GenericContainer<?> container = new GenericContainer<>("rippleci/rippled:2.2.0")) {
try (GenericContainer<?> container = new GenericContainer<>("rippleci/rippled:2.3.0")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think version 2.3.1 is the most recent version, so we should use that

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.

Add support for AMM Clawback (XLS-74d)
3 participants