Skip to content

Add missing field types to lending protocol related objects and support Int32 serialized type#3198

Merged
Patel-Raj11 merged 9 commits intomainfrom
lp-updates
Feb 12, 2026
Merged

Add missing field types to lending protocol related objects and support Int32 serialized type#3198
Patel-Raj11 merged 9 commits intomainfrom
lp-updates

Conversation

@Patel-Raj11
Copy link
Collaborator

@Patel-Raj11 Patel-Raj11 commented Feb 9, 2026

High Level Overview of Change

Add newly added fields to lending protocol related ledger objects and transactions:

  1. Add ManagementFeeOutstanding and LoanScale to Loan object.
  2. Add ManagementFeeRate and Data to LoanBroker object.
  3. Add ShareMPTID and Scale to Vault object.
  4. Add AssetsMaximum, Data and Scale to vault_info response.
  5. Add DestinationTag to LoanBrokerCoverWithdraw and VaultWithdraw transactions.
  6. Add LoanPayFlags.
  7. Add Scale to VaultCreate transaction.
  8. Add support for Int32 serialized type in ripple-binary-codec. Needed for LoanScale field of Loan object.

Context of Change

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

Added unit and updated integration tests.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds lending-protocol fields and validations across ledger models and transactions, introduces Vault Scale and DestinationTag handling, registers LoanPay flags with runtime validation, adds Int/Int32 codec types, and expands related unit and integration tests.

Changes

Cohort / File(s) Summary
Ledger object models
packages/xrpl/src/models/ledger/Loan.ts, packages/xrpl/src/models/ledger/LoanBroker.ts, packages/xrpl/src/models/ledger/Vault.ts
Loan: removed TotalValueOutstanding, added LoanScale? and ManagementFeeOutstanding?. LoanBroker: added Data? and ManagementFeeRate?. Vault: renamed MPTokenIssuanceIDShareMPTID and added Scale?.
Transaction models — LoanPay & flags
packages/xrpl/src/models/transactions/loanPay.ts, packages/xrpl/src/models/transactions/index.ts, packages/xrpl/src/models/utils/flags.ts
Introduced exported LoanPayFlags enum and LoanPayFlagsInterface; LoanPay accepts `Flags?: number
Transaction models — VaultCreate / VaultWithdraw / LoanBrokerCoverWithdraw
packages/xrpl/src/models/transactions/vaultCreate.ts, packages/xrpl/src/models/transactions/vaultWithdraw.ts, packages/xrpl/src/models/transactions/loanBrokerCoverWithdraw.ts
VaultCreate: added Scale?: number with asset-type validation (forbidden for XRP/MPT; IOU must be 0–18). VaultWithdraw and LoanBrokerCoverWithdraw: added optional DestinationTag?: number and numeric validation; LoanBrokerCoverWithdraw also accepts Destination.
Method response models
packages/xrpl/src/models/methods/vaultInfo.ts
Added AssetsMaximum?, Data?, and Scale? to VaultInfoResponse.vault.
Codec integer types
packages/ripple-binary-codec/src/types/int.ts, packages/ripple-binary-codec/src/types/int-32.ts, packages/ripple-binary-codec/src/types/index.ts
Added abstract signed Int base class and concrete Int32 signed 32-bit type; registered and exported Int32 in the codec registry.
Tests — integration & unit
packages/xrpl/test/integration/..., packages/xrpl/test/models/..., packages/ripple-binary-codec/test/int.test.ts
Extended integration tests for vaults and lending flows; added unit tests for LoanPay flag validation, VaultCreate Scale validation, and Int32 behavior including encode/decode round-trips.
Exports & changelogs
packages/xrpl/src/models/transactions/index.ts, packages/xrpl/HISTORY.md, packages/ripple-binary-codec/HISTORY.md
Expanded export surface (LoanPay flags/interfaces, Int32); updated HISTORY entries for lending-protocol and Int32 additions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • achowdhry-ripple
  • ckeshava
  • mvadari
  • pdp2121

Poem

🐇 I nibbled schema leaves and stitched a Scale so neat,
Flags hop in single-file, one at a time to meet,
Tags guide where coins tumble, metadata tucked tight,
Int32 counts every hop, signed and snug at night,
Tests thump like little feet—ledger gardens bright.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately and specifically describes the two main changes: adding missing field types to lending protocol objects and adding Int32 serialized type support.
Description check ✅ Passed The PR description comprehensively covers the changes with a detailed list of modifications, includes required template sections (High Level Overview, Type of Change, HISTORY.md update), and provides sufficient context about the lending protocol updates.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lp-updates

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Patel-Raj11 Patel-Raj11 requested a review from ckeshava February 9, 2026 21:29
@Patel-Raj11 Patel-Raj11 requested a review from kuan121 February 10, 2026 00:49
Copy link
Contributor

@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

🤖 Fix all issues with AI agents
In `@packages/xrpl/src/models/transactions/vaultCreate.ts`:
- Around line 167-187: The Scale validation must enforce integer values for IOU
assets: in the VaultCreate validation block (referencing tx.Scale, isIOU, isXRP,
isMPT, MAX_SCALE, and ValidationError) remove the redundant typeof check and add
an integer check (e.g., Number.isInteger(tx.Scale)) when isIOU is true, keeping
the existing 0..MAX_SCALE bounds; ensure the thrown ValidationError message
reflects the integer requirement (e.g., "Scale must be an integer between 0 and
MAX_SCALE inclusive for IOU assets").
🧹 Nitpick comments (2)
packages/xrpl/src/models/transactions/vaultCreate.ts (1)

161-165: Asset type detection looks correct but is narrowly scoped.

The asset type detection (XRP / MPT / IOU) at lines 161–165 is only used inside the if (tx.Scale !== undefined) block. If future validation rules also need asset-type awareness, consider hoisting this detection above the Scale block. Not blocking for now since it only serves the Scale check.

packages/xrpl/test/integration/transactions/lendingProtocol.test.ts (1)

217-222: Consider using BigInt instead of parseInt for comparing ledger amounts.

parseInt would silently truncate values in scientific notation (e.g., "5e6"5). While current values are plain integer strings, using BigInt(paidLoan.PrincipalOutstanding) would be more robust and consistent with BigInt usage elsewhere in this file (e.g., lines 529–531).

Proposed fix
      assert.isTrue(
-       parseInt(paidLoan.PrincipalOutstanding, 10) <
-         parseInt(loanObject.PrincipalOutstanding, 10),
+       BigInt(paidLoan.PrincipalOutstanding) <
+         BigInt(loanObject.PrincipalOutstanding),
        'Principal should decrease after payment',
      )

And similarly at line 232:

      assert.isTrue(
-       parseInt(paidLoan.PrincipalOutstanding, 10) > 0,
+       BigInt(paidLoan.PrincipalOutstanding) > BigInt(0),
        'Principal should not be zero',
      )

kuan121
kuan121 previously approved these changes Feb 10, 2026
Copy link
Collaborator

@ckeshava ckeshava left a comment

Choose a reason for hiding this comment

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

Where can I find the binary codec for the Int32 type? There is a new field titled LoanScale introduced in the Lending Protocol.

@Patel-Raj11 Patel-Raj11 changed the title Add missing field types to lending protocol related objects Add missing field types to lending protocol related objects and support Int32 serialized type Feb 12, 2026
Copy link
Contributor

@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: 4

🤖 Fix all issues with AI agents
In `@packages/ripple-binary-codec/HISTORY.md`:
- Around line 5-6: The changelog entry "* Add `Int32` serialized type." is
incorrectly placed under the "### Fixed" section; move that bullet to the "###
Added" section (or create an "Added" heading if missing) so the new Int32
serialized type is recorded as a feature addition rather than a fix, keeping the
exact bullet text and formatting intact.

In `@packages/ripple-binary-codec/src/types/int-32.ts`:
- Around line 43-51: The string branch in Int32.from uses Number.parseInt which
truncates decimals (e.g., "1.5" -> 1); update the logic in the block handling
typeof val === 'string' to parse via Number(val) (or parseFloat) and then
validate with Number.isFinite(num) and Number.isInteger(num) before calling
Int32.checkIntRange and writeInt32BE; ensure you throw the same Error message
for non-numeric or non-integer strings and return new Int32(buf) on success
(references: Int32, Int32.checkIntRange, writeInt32BE).

In `@packages/ripple-binary-codec/src/types/int.ts`:
- Around line 59-69: The static method checkIntRange uses this.constructor.name
which resolves to "Function"; update the error message to use the class
constructor's name via this.name instead. Locate the static method checkIntRange
and change the error construction so it references this.name (e.g., `Invalid
${this.name}: ...`) so the thrown Error reports the correct class name like
Int32.

In `@packages/ripple-binary-codec/test/int.test.ts`:
- Around line 176-181: Remove the debug console.log call in the test "can encode
and decode Loan with negative LoanScale": delete the line console.log(decoded)
from the it block that encodes with encode(...) and decodes with decode(...),
leaving only the expect(decoded).toEqual(loanWithScale) assertion so the test no
longer emits noisy output; reference symbols: encode, decode, loanWithScale, and
the it block name.

@Patel-Raj11
Copy link
Collaborator Author

Where can I find the binary codec for the Int32 type? There is a new field titled LoanScale introduced in the Lending Protocol.

I completely missed this, thanks for highlighting. Added Int32 serialization here dd53824

@Patel-Raj11 Patel-Raj11 merged commit b1e139a into main Feb 12, 2026
12 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.

3 participants