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

feat: add AMMClawback support #2893

Merged
merged 21 commits into from
Feb 12, 2025
Merged

feat: add AMMClawback support #2893

merged 21 commits into from
Feb 12, 2025

Conversation

khancode
Copy link
Collaborator

@khancode khancode commented Feb 5, 2025

High Level Overview of Change

Adds AMMClawback transaction.

Resources:

Fixes #2850

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)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update HISTORY.md?

  • Yes
  • No, this change does not impact library users

Test Plan

Adds unit and integ tests for AMMClawback transaction.

Copy link

coderabbitai bot commented Feb 5, 2025

Warning

Rate limit exceeded

@khancode has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between eb1185b and 98ef3cb.

📒 Files selected for processing (4)
  • .ci-config/rippled.cfg (1 hunks)
  • packages/xrpl/HISTORY.md (1 hunks)
  • packages/xrpl/src/models/transactions/AMMClawback.ts (1 hunks)
  • packages/xrpl/test/models/AMMClawback.test.ts (1 hunks)

Walkthrough

This pull request introduces comprehensive support for the AMMClawback amendment across several components. The changes update the server configuration, release history, and transaction type definitions, add new TypeScript models and validation logic for AMMClawback transactions, and adjust existing XRPL exports and utility mappings. Additionally, new integration and unit tests have been added to validate the AMMClawback functionality, and a function signature is updated to enable conditional clawback in pool creation.

Changes

File(s) Change Summary
.ci-config/rippled.cfg Added new amendment AMMClawback under [features] and removed obsolete commented configurations.
packages/ripple-binary-codec/HISTORY.md
packages/ripple-binary-codec/src/enums/definitions.json
Updated release notes to include AMMClawback (XLS-73) and added a new transaction type "AMMClawback": 31.
packages/xrpl/HISTORY.md
packages/xrpl/src/models/transactions/AMMClawback.ts
packages/xrpl/src/models/transactions/index.ts
packages/xrpl/src/models/transactions/transaction.ts
packages/xrpl/src/models/utils/flags.ts
Integrated AMMClawback transaction support: added models, validation logic, exports, and flag mapping; deprecated setTransactionFlagsToNumber in favor of convertTxFlagsToNumber.
packages/xrpl/test/integration/transactions/ammClawback.test.ts
packages/xrpl/test/models/AMMClawback.test.ts
Introduced new integration and unit tests to validate the AMMClawback transaction’s structure and behavior.
packages/xrpl/test/integration/utils.ts Updated the createAMMPool function to include an optional enableAMMClawback parameter.

Suggested reviewers

  • mvadari
  • achowdhry-ripple
  • shawnxie999
  • ckeshava

Poem

I'm a hoppy rabbit with a joyful song,
AMMClawback's here, steady and strong.
Codes and tests dance in a playful beat,
Fixing transactions, neat and complete.
With a twitch of my nose, I cheer in delight 🐇✨.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@khancode khancode marked this pull request as ready for review February 6, 2025 16:11
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
packages/xrpl/src/models/transactions/AMMClawback.ts (1)

42-42: Typo in documentation comment: Missing "be" in "it cannot be reverted."

In the documentation comment for the AMMClawback interface, there's a grammatical error in the sentence "After you enable clawback, it cannot reverted." The word "be" is missing.

Apply this diff to correct the typo:

- * After you enable clawback, it cannot reverted: the account permanently gains the ability to claw back
+ * After you enable clawback, it cannot be reverted: the account permanently gains the ability to claw back
packages/xrpl/test/models/AMMClawback.test.ts (3)

145-155: Fix incorrect test title.

The test title suggests checking Account/Asset.issuer match, but the test actually verifies currency match between Amount and Asset.

Apply this diff to fix the test title:

-  it(`throws w/ Account must be the same as Asset.issuer`, function () {
+  it(`throws w/ currency must be the same for Amount and Asset`, function () {

41-41: Optimize performance by avoiding the delete operator.

The delete operator can impact performance. Consider using undefined assignments instead.

Apply this diff to optimize the code:

-    delete ammClawback.Amount
+    ammClawback.Amount = undefined

-    delete ammClawback.Holder
+    ammClawback.Holder = undefined

-    delete ammClawback.Asset
+    ammClawback.Asset = undefined

-    delete ammClawback.Asset2
+    ammClawback.Asset2 = undefined

Also applies to: 47-47, 80-80, 113-113

🧰 Tools
🪛 Biome (1.9.4)

[error] 41-41: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


32-32: Improve type safety by using a more specific type assertion.

The as any type assertion is too broad and bypasses type checking. Consider using a more specific type that matches the expected structure.

Apply this diff to improve type safety:

-    } as any
+    } as Partial<AMMClawback>
packages/xrpl/HISTORY.md (1)

11-12: Deprecation Notice and New Utility Function Update
The section clearly notes the deprecation of setTransactionFlagsToNumber and recommends using convertTxFlagsToNumber instead. Ensure that all internal documentation, API references, and migration guides are updated accordingly to avoid any confusion among users.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 991a1d2 and e9dbc6e.

⛔ Files ignored due to path filters (2)
  • packages/ripple-binary-codec/package-lock.json is excluded by !**/package-lock.json
  • packages/xrpl/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (11)
  • .ci-config/rippled.cfg (1 hunks)
  • packages/ripple-binary-codec/HISTORY.md (1 hunks)
  • packages/ripple-binary-codec/src/enums/definitions.json (1 hunks)
  • packages/xrpl/HISTORY.md (1 hunks)
  • packages/xrpl/src/models/transactions/AMMClawback.ts (1 hunks)
  • packages/xrpl/src/models/transactions/index.ts (1 hunks)
  • packages/xrpl/src/models/transactions/transaction.ts (3 hunks)
  • packages/xrpl/src/models/utils/flags.ts (2 hunks)
  • packages/xrpl/test/integration/transactions/ammClawback.test.ts (1 hunks)
  • packages/xrpl/test/integration/utils.ts (2 hunks)
  • packages/xrpl/test/models/AMMClawback.test.ts (1 hunks)
🧰 Additional context used
📓 Learnings (2)
packages/xrpl/test/models/AMMClawback.test.ts (1)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
packages/xrpl/test/integration/transactions/ammClawback.test.ts (1)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
🪛 Biome (1.9.4)
packages/xrpl/test/models/AMMClawback.test.ts

[error] 41-41: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 47-47: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 80-80: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 113-113: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🪛 GitHub Actions: Node.js CI
packages/xrpl/test/integration/transactions/ammClawback.test.ts

[error] 206-206: ValidationError: AccountSet: invalid SetFlag.

🔇 Additional comments (10)
packages/xrpl/test/integration/transactions/ammClawback.test.ts (1)

20-21: ⚠️ Potential issue

Investigate potential invalid SetFlag in createAMMPool causing pipeline failure

The pipeline failure indicates a ValidationError: AccountSet: invalid SetFlag, which may originate from the createAMMPool function when enabling clawback. Since you're passing true to createAMMPool to enable clawback, ensure that the AccountSet transaction within this function uses the correct SetFlag value.

Run the following script to verify the SetFlag used in the AccountSet transaction:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Search for AccountSet transactions and display their SetFlag values.

# Find all AccountSet transactions in the test directory
rg -A 5 "TransactionType:\s*'AccountSet'" packages/xrpl/test/integration/ -t yaml

# Alternatively, look specifically in the utils file if that's where `createAMMPool` is defined
rg -A 5 "TransactionType:\s*'AccountSet'" packages/xrpl/test/integration/utils.ts

# Review the SetFlag values to ensure they are correct for enabling clawback

Length of output: 351


I'll run a script to search for the definition of the accountSetFlags variable so we can verify whether it holds the correct flag value when clawback is enabled.


🏁 Script executed:

#!/bin/bash
# Search for the definition and usage of `accountSetFlags` in the repository
rg -n "const\s\+accountSetFlags" .

Length of output: 36


I'll run another script to search for the definition of createAMMPool in the repository (specifically in the utils.ts file) so we can inspect how the SetFlag is assigned and whether it uses the correct value for enabling clawback.


🏁 Script executed:

#!/bin/bash
# Search for the definition of createAMMPool in the utils file and display surrounding lines for context.
rg -A 15 "function createAMMPool" packages/xrpl/test/integration/utils.ts

Length of output: 534


I'll run a script to extract more lines from the createAMMPool function to see how accountSetFlags is modified in the clawback branch.


🏁 Script executed:

#!/bin/bash
# Get more context from the createAMMPool function implementation
rg -A 50 "export async function createAMMPool" packages/xrpl/test/integration/utils.ts

Length of output: 1422


Clawback flag usage appears correct in createAMMPool

The inspected code shows that when enableClawback is true, the function sets

accountSetFlags = AccountSetAsfFlags.asfDefaultRipple | AccountSetAsfFlags.asfAllowTrustLineClawback

This indicates that the correct flag (as defined by AccountSetAsfFlags) is ORed in when clawback is enabled.

Given that our search for the flag definition didn’t yield any conflicting value and the AccountSet transaction is constructed using these values, the evidence suggests that the SetFlag value within createAMMPool is implemented as expected.

Actionable Item:
• Verify locally or in staging that the underlying AccountSetAsfFlags constants hold the proper values per XRPL protocol specifications.

packages/xrpl/src/models/transactions/index.ts (1)

17-24: LGTM!

The exports for AMMClawback and related flags are correctly added, enhancing the transaction model's capabilities. No issues found.

.ci-config/rippled.cfg (1)

183-183: LGTM!

The AMMClawback amendment is correctly added to the [features] section with other amendments from version 2.3.0.

packages/xrpl/src/models/utils/flags.ts (1)

8-8: LGTM!

The AMMClawback flags are correctly integrated into the flags handling system, following the established pattern for other transaction types.

Also applies to: 51-51

packages/xrpl/src/models/transactions/transaction.ts (1)

12-12: LGTM!

The AMMClawback transaction type is correctly integrated into the transaction system, following the established pattern for other transaction types:

  1. Import of the transaction type and its validation function
  2. Addition to the SubmittableTransaction type
  3. Addition of the validation case in the switch statement

Also applies to: 119-119, 268-270

packages/xrpl/test/integration/utils.ts (2)

376-393: LGTM! Clean implementation of clawback flag support.

The addition of the enableClawback parameter with a default value of false is a clean way to maintain backward compatibility while adding new functionality. The bitwise operation to combine flags is implemented correctly.


395-399: LGTM! Proper flag setting in AccountSet transaction.

The accountSetFlags is correctly assigned to the SetFlag field in the AccountSet transaction.

packages/ripple-binary-codec/HISTORY.md (1)

5-6: LGTM! Clear and well-formatted changelog entry.

The changelog entry follows the established format and properly references the XLS-73 specification.

packages/ripple-binary-codec/src/enums/definitions.json (1)

3056-3056: LGTM! Proper addition of AMMClawback transaction type.

The new transaction type is correctly defined with a unique code and follows the established format.

packages/xrpl/HISTORY.md (1)

7-10: AMMClawback Amendment Entry – Verify Specification Number
The release notes now include a new entry:
  * Support for the AMMClawback amendment (XLS-73)
Please confirm that the amendment number is correct. The PR objectives mention XLS-74, so this discrepancy should be resolved to ensure consistency across documentation and the implementation.

Copy link
Collaborator

@achowdhry-ripple achowdhry-ripple left a comment

Choose a reason for hiding this comment

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

First pass looks solid, just requesting some typing cleanups and minor changes

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/xrpl/src/models/transactions/AMMClawback.ts (3)

35-71: Consider enhancing documentation with examples.

The interface is well-defined with clear documentation. Consider adding code examples to demonstrate valid transaction structures, especially for the optional Amount field.

Example addition to the documentation:

/**
 * Example:
 * {
 *   TransactionType: 'AMMClawback',
 *   Account: 'rIssuerAccount...',
 *   Holder: 'rHolderAccount...',
 *   Asset: {
 *     currency: 'USD',
 *     issuer: 'rIssuerAccount...'
 *   },
 *   Asset2: {
 *     currency: 'XRP'
 *   },
 *   Amount: {
 *     currency: 'USD',
 *     issuer: 'rIssuerAccount...',
 *     value: '100'
 *   }
 * }
 */

82-83: Consider using type guard for safer type casting.

While the current type casting is better than using @ts-expect-error, consider implementing a type guard function for more robust type safety.

function isAMMClawback(tx: Record<string, unknown>): tx is AMMClawback {
  return (
    tx.TransactionType === 'AMMClawback' &&
    typeof tx.Holder === 'string' &&
    typeof tx.Asset === 'object'
  )
}

// Then use it like:
if (!isAMMClawback(tx)) {
  throw new ValidationError('Invalid AMMClawback transaction')
}
const txAMMClawback = tx // TypeScript now knows this is AMMClawback

87-102: Consider validating Asset2 before Asset issuer checks.

The current validation order might lead to runtime errors if Asset is invalid but we try to access its issuer. Consider validating Asset2 right after Asset to ensure both currency objects are valid before performing issuer comparisons.

  validateRequiredField(tx, 'Asset', isCurrency)
+ validateRequiredField(tx, 'Asset2', isCurrency)

  if (txAMMClawback.Holder === txAMMClawback.Asset.issuer) {
    throw new ValidationError(
      'AMMClawback: Holder and Asset.issuer must be distinct',
    )
  }

  if (txAMMClawback.Account !== txAMMClawback.Asset.issuer) {
    throw new ValidationError(
      'AMMClawback: Account must be the same as Asset.issuer',
    )
  }

- validateRequiredField(tx, 'Asset2', isCurrency)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9dbc6e and b4df9b8.

📒 Files selected for processing (1)
  • packages/xrpl/src/models/transactions/AMMClawback.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: snippets (22.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: integration (18.x)
  • GitHub Check: browser (18.x)
🔇 Additional comments (1)
packages/xrpl/src/models/transactions/AMMClawback.ts (1)

1-34: LGTM! Well-structured imports and flag definitions.

The imports are properly organized, and the flag definitions follow best practices with clear documentation.

@tequdev tequdev mentioned this pull request Feb 7, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/xrpl/test/integration/utils.ts (1)

397-405: Add documentation for the clawback functionality.

While the implementation is correct, please add JSDoc comments explaining:

  • The purpose of the enableAMMClawback parameter
  • The impact of enabling clawback on the AMM pool
  • Any security considerations when using clawback

Add this documentation above the function:

+/**
+ * Creates an AMM pool for testing purposes.
+ *
+ * @param client - The XRPL client
+ * @param enableAMMClawback - When true, enables trustline clawback for the issuer wallet.
+ *                           This allows the issuer to reclaim issued tokens through AMMClawback transactions.
+ *                           Use with caution as it grants significant control to the issuer.
+ * @returns An object containing the issuer wallet, LP wallet, and asset information
+ */
 export async function createAMMPool(
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbb5e07 and 824150c.

📒 Files selected for processing (2)
  • packages/xrpl/test/integration/transactions/ammClawback.test.ts (1 hunks)
  • packages/xrpl/test/integration/utils.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/xrpl/test/integration/transactions/ammClawback.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: snippets (22.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: unit (18.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: integration (18.x)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: browser (18.x)
🔇 Additional comments (2)
packages/xrpl/test/integration/utils.ts (2)

376-379: LGTM! Clear and backward-compatible signature change.

The optional parameter enableAMMClawback with a default value of false is well-named and maintains backward compatibility.


376-459: LGTM! Well-structured implementation with correct ordering of operations.

The function maintains a clear sequence of operations and properly integrates the new clawback functionality without disrupting the existing flow.

@khancode khancode requested a review from ckeshava February 11, 2025 01:27
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/xrpl/test/models/AMMClawback.test.ts (2)

18-36: Consider using proper typing for the test object.

Instead of using as any, consider properly typing the test object using the AMMClawback interface to catch type-related issues early.

-    ammClawback = {
+    ammClawback: AMMClawback = {
       TransactionType: 'AMMClawback',
       Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
       Holder: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9',
       Asset: {
         currency: 'USD',
         issuer: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
       },
       Asset2: {
         currency: 'XRP',
       },
       Amount: {
         currency: 'USD',
         issuer: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
         value: '1000',
       },
       Sequence: 1337,
-    } as any
+    }

44-44: Consider using undefined assignment instead of delete operator.

Using the delete operator can impact performance. Consider using undefined assignment instead.

-    delete ammClawback.Amount
+    ammClawback.Amount = undefined

-    delete ammClawback.Holder
+    ammClawback.Holder = undefined

-    delete ammClawback.Asset
+    ammClawback.Asset = undefined

-    delete ammClawback.Asset2
+    ammClawback.Asset2 = undefined

Also applies to: 56-56, 89-89, 122-122

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6273fa and a960912.

📒 Files selected for processing (2)
  • packages/xrpl/test/integration/transactions/ammClawback.test.ts (1 hunks)
  • packages/xrpl/test/models/AMMClawback.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/xrpl/test/integration/transactions/ammClawback.test.ts
🧰 Additional context used
🧠 Learnings (1)
packages/xrpl/test/models/AMMClawback.test.ts (1)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
🪛 Biome (1.9.4)
packages/xrpl/test/models/AMMClawback.test.ts

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 56-56: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 89-89: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 122-122: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: snippets (22.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: unit (22.x)
  • GitHub Check: integration (18.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: unit (18.x)
  • GitHub Check: browser (18.x)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/xrpl/test/models/AMMClawback.test.ts (1)

38-53: LGTM! Comprehensive positive test cases.

The test cases effectively validate:

  • Basic AMMClawback transaction
  • Optional Amount field
  • tfClawTwoAssets flag
🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

Copy link
Collaborator

@achowdhry-ripple achowdhry-ripple left a comment

Choose a reason for hiding this comment

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

minor fix

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/xrpl/src/models/transactions/AMMClawback.ts (1)

79-90: 🛠️ Refactor suggestion

Move type assertions after all validations.

The type assertions are performed before all validations are complete, which could lead to runtime errors if the fields don't exist or are of the wrong type.

 export function validateAMMClawback(tx: Record<string, unknown>): void {
   validateBaseTransaction(tx)
 
   validateRequiredField(tx, 'Holder', isAccount)
   validateRequiredField(tx, 'Asset', isCurrency)
+  validateRequiredField(tx, 'Asset2', isCurrency)
+  validateOptionalField(tx, 'Amount', isAmount)
 
   // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- required
   const asset = tx.Asset as IssuedCurrency
   // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- required
   const amount = tx.Amount as IssuedCurrencyAmount
🧹 Nitpick comments (4)
packages/xrpl/src/models/transactions/AMMClawback.ts (2)

35-71: Consider enhancing the JSDoc comment.

The main JSDoc comment could be improved by adding @remarks tag to separate the implementation details from the main description, and by adding @throws tag to document potential validation errors.

 /**
  * Claw back tokens from a holder that has deposited your issued tokens into an AMM pool.
  *
+ * @remarks
  * Clawback is disabled by default. To use clawback, you must send an AccountSet transaction to enable the
  * Allow Trust Line Clawback setting. An issuer with any existing tokens cannot enable clawback. You can
  * only enable Allow Trust Line Clawback if you have a completely empty owner directory, meaning you must
  * do so before you set up any trust lines, offers, escrows, payment channels, checks, or signer lists.
  * After you enable clawback, it cannot reverted: the account permanently gains the ability to claw back
  * issued assets on trust lines.
+ *
+ * @throws {ValidationError} When the transaction is malformed.
  */

107-119: Make error messages consistent.

The error messages for Amount validation use slightly different wording than other messages.

     if (amount.currency !== asset.currency) {
       throw new ValidationError(
-        'AMMClawback: currency must be identical for Amount and Asset',
+        'AMMClawback: Amount.currency must match Asset.currency',
       )
     }
 
     if (amount.issuer !== asset.issuer) {
       throw new ValidationError(
-        'AMMClawback: issuer must be identical for Amount and Asset',
+        'AMMClawback: Amount.issuer must match Asset.issuer',
       )
     }
packages/xrpl/test/models/AMMClawback.test.ts (2)

18-36: Improve type safety in test setup.

The test setup uses as any type assertion, which bypasses type checking. Consider using proper types.

-    ammClawback = {
+    ammClawback: AMMClawback = {
       TransactionType: 'AMMClawback',
       Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
       Holder: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9',
       Asset: {
         currency: 'USD',
         issuer: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
       },
       Asset2: {
         currency: 'XRP',
       },
       Amount: {
         currency: 'USD',
         issuer: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
         value: '1000',
       },
       Sequence: 1337,
-    } as any
+    }

44-44: Improve performance by avoiding delete operator.

Static analysis suggests avoiding the delete operator for better performance.

-    delete ammClawback.Amount
+    ammClawback.Amount = undefined

-    delete ammClawback.Holder
+    ammClawback.Holder = undefined

-    delete ammClawback.Asset
+    ammClawback.Asset = undefined

-    delete ammClawback.Asset2
+    ammClawback.Asset2 = undefined

Also applies to: 56-56, 89-89, 122-122

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c64f72e and eb1185b.

📒 Files selected for processing (2)
  • packages/xrpl/src/models/transactions/AMMClawback.ts (1 hunks)
  • packages/xrpl/test/models/AMMClawback.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/xrpl/test/models/AMMClawback.test.ts (1)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
🪛 Biome (1.9.4)
packages/xrpl/test/models/AMMClawback.test.ts

[error] 44-44: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 56-56: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 89-89: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 122-122: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: unit (22.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: snippets (22.x)
  • GitHub Check: unit (18.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: build-and-lint (18.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: integration (18.x)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: browser (18.x)
🔇 Additional comments (2)
packages/xrpl/src/models/transactions/AMMClawback.ts (2)

1-33: LGTM!

The imports are well-organized, and the flag definition follows best practices.


91-101: LGTM!

The validation checks for distinct Holder and matching Account are correct and well-implemented.

@khancode khancode merged commit 35e40d9 into main Feb 12, 2025
16 checks passed
@khancode khancode deleted the amm-clawback branch February 12, 2025 00:00
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.

Support AMMClawback
3 participants