Skip to content

feat(sdk-coin-xrp): add MPT transaction builders#8891

Merged
HimanshuS2212 merged 1 commit into
masterfrom
CGD-1471-mpt-sdk-builders
Jun 1, 2026
Merged

feat(sdk-coin-xrp): add MPT transaction builders#8891
HimanshuS2212 merged 1 commit into
masterfrom
CGD-1471-mpt-sdk-builders

Conversation

@HimanshuS2212
Copy link
Copy Markdown
Contributor

@HimanshuS2212 HimanshuS2212 commented May 29, 2026

TICKET: CGD-1470

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 29, 2026

CGD-1470

@HimanshuS2212 HimanshuS2212 marked this pull request as ready for review May 29, 2026 06:18
@HimanshuS2212 HimanshuS2212 requested review from a team as code owners May 29, 2026 06:18
Comment thread modules/sdk-coin-xrp/src/lib/utils.ts
Comment thread modules/sdk-coin-xrp/src/lib/mpTokenAuthorizeBuilder.ts Outdated
@HimanshuS2212 HimanshuS2212 force-pushed the CGD-1471-mpt-sdk-builders branch 2 times, most recently from 9cd3bf3 to 13e3231 Compare May 29, 2026 10:22
@0xPrabh
Copy link
Copy Markdown
Contributor

0xPrabh commented Jun 1, 2026

@claude

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Claude finished @0xPrabh's task —— View job


Code Review for MPT Transaction Builders

Todo List:

  • Read repository guidelines from CLAUDE.md
  • Examine the changed files to understand MPT implementation
  • Analyze existing review comments and verify issues
  • Check for additional code quality issues
  • Provide comprehensive review feedback

Summary

This PR successfully adds Multi-Purpose Token (MPT) transaction builders for XRP, implementing both MPT authorization and transfer functionality. The implementation follows BitGoJS patterns and includes comprehensive test coverage.

Confirmed Issues from Existing Review

1. Critical: Type predicate issue in isMPTAmount (utils.ts:233-235)

The reviewer is absolutely correct. The current implementation loses type narrowing capability:

// Current - returns boolean instead of type predicate
public isMPTAmount(amount: unknown): boolean {
  return isMPTAmount(amount);
}

// Should be (matching isIssuedCurrencyAmount pattern)
public isMPTAmount(amount: Amount | MPTAmount): amount is MPTAmount {
  return isMPTAmount(amount);
}

Impact: This forces unsafe as MPTAmount casts in transaction.ts at lines 286, 368, 421, and 437, which are type-unsafe and could silently fail if the type guard returns false positives.

2. Minor: Class naming suggestion (mpTokenAuthorizeBuilder.ts:8)

The reviewer suggests either MPTAuthorizeBuilder or MPTTokenAuthorizeBuilder for consistency. Given that MPT stands for "Multi-Purpose Token," MPTAuthorizeBuilder would be more concise and eliminate redundancy.

Additional Code Quality Issues

3. Error handling consistency

  • Both builders use appropriate error messages for validation
  • Hex string validation is correctly implemented with proper regex patterns
  • Good use of BuildTransactionError for domain-specific errors

4. Code organization and patterns

  • ✅ Follows established BitGoJS patterns (extends TransactionBuilder)
  • ✅ Proper use of fluent interface with method chaining
  • ✅ Correct implementation of abstract methods
  • ✅ Good separation of concerns between builders

5. Test coverage

  • ✅ Comprehensive test coverage for both builders
  • ✅ Tests cover both positive and negative cases
  • ✅ Proper validation of transaction structure and content

6. Transaction handling in transaction.ts

The MPT-related changes are well-integrated:

  • ✅ Proper case handling in switch statements
  • ✅ Correct transaction type mapping
  • ✅ Good integration with existing toJson() and loadInputsAndOutputs() methods

7. Interface definitions (iface.ts)

  • ✅ Proper type exports and re-exports
  • ✅ Good integration of MPT types into existing type hierarchy
  • ✅ Clean addition of mptAmount and mptIssuanceId fields to TxData

Recommendations

High Priority

  1. Fix the type predicate in utils.ts - This is a type safety issue that should be addressed
  2. Remove unsafe type casts in transaction.ts - After fixing the type predicate, remove the as MPTAmount casts

Medium Priority

  1. Consider renaming MPTokenAuthorizeBuilder to MPTAuthorizeBuilder for consistency and conciseness

Low Priority

  1. Documentation: Consider adding JSDoc comments to the new builder classes explaining MPT concepts for future maintainers

Architecture Assessment

The implementation correctly follows BitGoJS architectural patterns:

  • ✅ Proper use of builder pattern for transaction construction
  • ✅ Integration with existing factory pattern
  • ✅ Consistent error handling and validation
  • ✅ Good separation between authorization and transfer operations
  • ✅ Proper handling of XRP-specific transaction types

The code is production-ready once the type predicate issue is resolved. The MPT functionality is well-encapsulated and doesn't disrupt existing XRP transaction handling.


Job run: Link to job run

Comment thread modules/sdk-coin-xrp/src/lib/transaction.ts
Comment thread modules/sdk-coin-xrp/src/lib/mpTokenAuthorizeBuilder.ts
Comment thread modules/sdk-coin-xrp/src/lib/mpTokenAuthorizeBuilder.ts
Comment thread modules/sdk-coin-xrp/src/lib/transactionBuilderFactory.ts Outdated
Comment thread modules/sdk-coin-xrp/src/lib/transaction.ts Outdated
@HimanshuS2212 HimanshuS2212 force-pushed the CGD-1471-mpt-sdk-builders branch from 13e3231 to d187eee Compare June 1, 2026 06:51
@HimanshuS2212 HimanshuS2212 force-pushed the CGD-1471-mpt-sdk-builders branch from d187eee to c04303a Compare June 1, 2026 07:25
@HimanshuS2212 HimanshuS2212 merged commit 291a6fb into master Jun 1, 2026
22 checks passed
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