Skip to content

fix: issue #39#42

Merged
ch4r10t33r merged 1 commit into
masterfrom
issue-39
May 12, 2026
Merged

fix: issue #39#42
ch4r10t33r merged 1 commit into
masterfrom
issue-39

Conversation

@nikhilkumar1612
Copy link
Copy Markdown
Member

Summary

Closes #39.

This PR fixes precision drift in relayer_getFeeData.rate without changing the API shape. The rate field remains a numeric value in the response, but RelayX now computes it using exact scaled integer math and rounds it deterministically to 6 decimal places before serialization.

Problem

relayer_getFeeData was deriving rate from Chainlink-style oracle values using f64 arithmetic. That can introduce binary floating-point precision and rounding inconsistencies, especially when clients use the returned rate for fee calculations.

What Changed

  • Replaced the direct f64-based rate calculation in src/methods/fee_data.rs with scaled U256 integer math.
  • Added a deterministic half-up rounding rule to 6 decimal places for relayer_getFeeData.rate.
  • Kept the response contract unchanged:
    • rate is still returned as a JSON number
    • FeeDataResponse.rate remains f64
  • Added unit tests covering:
    • half-up rounding at 6 decimals
    • recurring-decimal behavior
    • invalid/non-positive oracle answers
  • Updated docs to document the 6-decimal rounding rule.

Why This Approach

The issue is not that rate is a number on the wire. The issue is that the number was previously derived using floating-point math.

This change preserves backward compatibility for clients while making the returned value deterministic and easier to reason about.

Testing

  • cargo test --lib

Notes

  • Native token responses are unchanged and still return rate: 1.0.
  • Stub mode behavior is unchanged.
  • relayer_getQuote is intentionally not changed in this PR; this fix is scoped to relayer_getFeeData / relayer_getExchangeRate.

Copy link
Copy Markdown
Member

@ch4r10t33r ch4r10t33r left a comment

Choose a reason for hiding this comment

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

LGTM

@ch4r10t33r ch4r10t33r merged commit 625c0b3 into master May 12, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Correctness: f64 used for relayer_getFeeData rate (precision and rounding)

2 participants