Skip to content

fix: mark ledger object fields that rippled omits at 0 as optional - #3534

Open
kuan121 wants to merge 1 commit into
mainfrom
fix/dge-8229-default-ledger-fields-optional
Open

kuan121 wants to merge 1 commit into
mainfrom
fix/dge-8229-default-ledger-fields-optional

Conversation

@kuan121

@kuan121 kuan121 commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

Marks the 10 ledger object fields that rippled omits when their value is 0 as optional.

Jira: DGE-8229
Fixes #3154

Context of Change

rippled declares these fields SoeDefault in ledger_entries.macro and InnerObjectFormats.cpp. When the value is 0, the field is absent from the object's JSON. xrpl.js typed them as always present, so code like loan.PaymentRemaining === 0 type-checked but was never true on a repaid loan, because the field isn't there.

Object Fields
MPToken MPTAmount
LoanBroker DebtMaximum
AMM TradingFee, VoteSlots[].VoteEntry.TradingFee, AuctionSlot.DiscountedFee
Loan PaymentRemaining, PrincipalOutstanding, TotalValueOutstanding, NextPaymentDueDate, GracePeriod

That is every SoeDefault field that xrpl.js still typed as required. The others are already optional, as #3153 did for Vault. No RPC response model needs the same change: amm_info always writes trading_fee and discounted_fee, as 0 when the ledger field is absent (AMMInfo.cpp:201-228).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

This changes types only; runtime behaviour is the same. TypeScript code that reads these fields with strictNullChecks must now handle undefined, as six lines in lendingProtocol.test.ts had to. That matches what rippled returns, and it is the same kind of change as #3153.

Did you update HISTORY.md?

  • Yes

Test Plan

Integration tests now check, against a real node, that each field is absent once its value is 0. The checks use existing flows where they reach that state:

  • lendingProtocol.test.ts:
    • A fully repaid loan has no TotalValueOutstanding or NextPaymentDueDate. It already asserted the same for PrincipalOutstanding and PaymentRemaining.
    • A broker updated to DebtMaximum: '0' has no DebtMaximum.
  • mptokenAuthorize.test.ts: a newly authorized MPToken with a zero balance has no MPTAmount.
  • ammVote.test.ts: once every LP votes 0, the AMM has no TradingFee, and its auction slot and vote entries have no fee fields.

Loan.GracePeriod gets no integration check, because LoanSet requires at least 60, so a real loan never stores 0.

All pass against rippleci/xrpld:develop --standalone (xrpld 3.4.0-rc1). The xrpl unit suite (134 suites, 1343 tests) and lint pass, and tsc over src and test reports no new errors.

🤖 Generated with Claude Code

rippled declares these fields soeDEFAULT, so it leaves them out of the
JSON when their value is 0, but xrpl.js typed them as always present:
MPToken.MPTAmount, LoanBroker.DebtMaximum, AMM.TradingFee and the
TradingFee / DiscountedFee of its vote and auction slots, and Loan's
PaymentRemaining, PrincipalOutstanding, TotalValueOutstanding,
NextPaymentDueDate and GracePeriod. Code such as
`loan.PaymentRemaining === 0` type-checked but was never true.

Integration tests now assert each field is absent once it is 0, where
the existing flows can reach that state.

DGE-8229, #3154

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: XRPLF/xrpl.js/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6dd84faf-8a0e-4e75-8ff7-30761acdfbc5
📥 Commits

Reviewing files that changed from the base of the PR and between cfd0fb4 and 2829a0b.

📒 Files selected for processing (8)
  • packages/xrpl/HISTORY.md
  • packages/xrpl/src/models/ledger/AMM.ts
  • packages/xrpl/src/models/ledger/Loan.ts
  • packages/xrpl/src/models/ledger/LoanBroker.ts
  • packages/xrpl/src/models/ledger/MPToken.ts
  • packages/xrpl/test/integration/transactions/ammVote.test.ts
  • packages/xrpl/test/integration/transactions/lendingProtocol.test.ts
  • packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.


Walkthrough

Several ledger model fields are now optional because rippled can omit them when their value is zero. Integration tests check selected omissions for AMM, Loan, LoanBroker, and MPToken ledger entries.

Changes

Ledger field optionality

Layer / File(s) Summary
Optional ledger field contracts
packages/xrpl/src/models/ledger/AMM.ts, packages/xrpl/src/models/ledger/Loan.ts, packages/xrpl/src/models/ledger/LoanBroker.ts, packages/xrpl/src/models/ledger/MPToken.ts, packages/xrpl/HISTORY.md
The ledger models mark the affected zero-valued fields as optional. The changelog lists these fields and states that omitted values are treated as 0.
Integration checks for omitted fields
packages/xrpl/test/integration/transactions/ammVote.test.ts, packages/xrpl/test/integration/transactions/lendingProtocol.test.ts, packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts
The tests check that selected zero-value AMM, Loan, LoanBroker, and MPToken fields are omitted. Lending test casts account for the optional fields.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: mvadari

Merge Risk: ⚪ Minimal · up to 2829a

This change marks ledger fields that rippled omits when their value is 0 as optional in the type definitions. Runtime behavior does not change. Code that reads these fields as always present may need to handle undefined, and the changelog documents this. Merge risk is minimal.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: marking ledger fields omitted by rippled at zero as optional.
Description check ✅ Passed The description includes the required overview, context, change type, HISTORY.md confirmation, and test plan. It explains the affected fields, rationale, compatibility impact, and validation results.
Linked Issues check ✅ Passed Issue #3154 requires rippled DEFAULT ledger fields to be optional and requires supporting tests and correct RPC models. The PR marks the ten reported fields optional, including AMM fields in AMM.ts …
Out of Scope Changes check ✅ Passed The changes stay within issue #3154. The declaration changes model omitted ledger fields, and the integration changes verify the omission behavior. The HISTORY.md entry documents the same fix. No unre…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 7…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a clean, well-scoped type-correctness fix: ten ledger-object fields that rippled genuinely omits when their value is 0 are marked optional in the TypeScript models (AMM, Loan, LoanBroker, MPToken), matching rippled's actual JSON output. The accompanying integration-test updates correctly add assertions that these fields are undefined once the ledger reaches a zero-value state, and existing reads of the now-optional fields are updated with narrowing casts in places where the test context guarantees the value is still non-zero. I didn't find any lines in the diff that misuse the new optionality, introduce incorrect assertions, or regress runtime behavior — the change is type-only as described, and the test plan corroborates it against a live node. No correctness, security, or consistency issues worth flagging in the changed lines.

This branch has not been deployed

No deployments
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.

DEFAULT Serialized fields are not marked Optional in ledger model

1 participant