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 28 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

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need an import here because AmmClawback and Address are in the same package. We can remove this

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 removed the extra import 👍🏽

// create Trustline from issuer to trader for currency TST and define two currencies
String testCurrency = "TST";
TrustSet trustSet = TrustSet.builder()
.account(traderKeyPair.publicKey().deriveAddress())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to fix formatting - use 2 spaces (no tabs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after finally being able to build, i have been able to address all of the checkstyle errors

assertThat(trustlineSubmitResult2.engineResult()).isEqualTo(TransactionResultCodes.TES_SUCCESS);

// send payment of ZFT to trader wallet from issuer
Payment paymentZFT = Payment.builder()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This naming convention breaks our Checkstyle plugin. Need to replace all instances of ...ZFT with Zft. For example:

Suggested change
Payment paymentZFT = Payment.builder()
Payment paymentZft = Payment.builder()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

assertThat(paymentZFTSubmitResult.engineResult()).isEqualTo(TransactionResultCodes.TES_SUCCESS);

// send payment of TST to trader wallet from issuer
Payment paymentTST = Payment.builder()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This naming convention breaks our Checkstyle plugin. Need to replace all instances of ...TFT with Tft. For example:

Suggested change
Payment paymentTST = Payment.builder()
Payment paymentTft = Payment.builder()

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've updated this along with all the other checkstyle issues

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

" \"Fee\" : \"10\",\n" +
" \"Sequence\" : 6,\n" +
" \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" +
" \"TransactionType\" : \"AMMClawback\"\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test currently fails. Need to add this:

Suggested change
" \"TransactionType\" : \"AMMClawback\"\n" +
" \"TransactionType\" : \"AMMClawback\",\n" +
" \"Flags\" : 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.

thanks for raising the issues in this unit test file, added the extra field to the json and switched to USD from TST

.value("25")
.build()
)
.holder(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is failing -- This transaction won't build without specifying asset1 and asset2.

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 addressed all of the failing tests in this unit test file

.value("25")
.build()
)
.holder(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is failing -- This transaction won't build without specifying asset1 and asset2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed all the tests in this unit test file, all 3 passing now

.signingPublicKey(
PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC")
)
.flags((AmmClawbackFlags) 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.

Suggested change
.flags((AmmClawbackFlags) AmmClawbackFlags.UNSET)
.flags(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 have removed this unnecessary casting, my IDE was also showing i didnt need this

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

public class AmmClawbackTest extends AbstractJsonTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use this as a standard Javadoc for unit tests:

Suggested change
public class AmmClawbackTest extends AbstractJsonTest {
/**
* Unit tests for {@link AmmClawback}.
**/
public class AmmClawbackTest extends AbstractJsonTest {

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, thanks for mentioning i didn't know these were called a "Javadoc"

"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?

@nkramer44 nkramer44 self-assigned this Mar 10, 2025
@agutierrez0
Copy link
Contributor Author

@nkramer44 / @sappenin - was looking to wrap up this work, could you PTAL? saw comment on this thread, not sure if we want to wait till that's merged?

@sappenin
Copy link
Collaborator

@nkramer44 / @sappenin - was looking to wrap up this work, could you PTAL? saw comment on this thread, not sure if we want to wait till that's merged?

@agutierrez0 Please see my code review comments. If they've been addressed, please add a response to let me know to go check. Once addressed, I'll resolve the comments.

@Test
void testJson() throws JSONException, JsonProcessingException {
AmmClawback ammClawback = AmmClawback.builder()
.account(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please set your tabs to use spaces and set all indent levels to 2.

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 just applied this formatting to all of the files I have changed, these are my IntelliJ settings:

image

let me know if i should change any of these settings and re apply again

@agutierrez0
Copy link
Contributor Author

@sappenin i have addressed your requested changes (format change requested today + changes requested on Feb 25th), could you please take a look?

@agutierrez0 agutierrez0 requested a review from sappenin March 25, 2025 18:58
@nkramer44 nkramer44 assigned nkramer44 and unassigned nkramer44 Mar 27, 2025
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