Skip to content

Reject deposit/withdraw amounts with invalid decimal precision - #506

Merged
ONEONUORA merged 3 commits into
Fracverse:masterfrom
Keengfk:feat/yield-decimal-precision-validation
Jul 28, 2026
Merged

Reject deposit/withdraw amounts with invalid decimal precision#506
ONEONUORA merged 3 commits into
Fracverse:masterfrom
Keengfk:feat/yield-decimal-precision-validation

Conversation

@Keengfk

@Keengfk Keengfk commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Reject deposit/withdrawal amounts with invalid decimal precision

Naira token amounts are stored and processed as integer micro-units — the
smallest indivisible denomination on-chain. Fractional values like 1000.5 are
meaningless at the contract level and were previously either silently truncated
by serde or surfaced as an unhelpful type error.

Changes

  • Added a deserialize_whole_number custom serde deserializer in
    backend/src/api/yield.rs that accepts any JSON number but rejects it with a
    clear domain-specific error if it has a fractional part (checked via
    f64::fract() != 0.0)
  • Applied the deserializer to DepositRequest.amount and WithdrawRequest.amount
    — Axum returns HTTP 422 Unprocessable Entity on failure
  • Added integration tests in backend/tests/yield_api_tests.rs covering:
    • 1000.5, 0.1 → 422 on deposit
    • 500.99, 1.1 → 422 on withdraw
    • 1000.0, 500.0 (whole-number floats) → pass precision check

Testing

Existing yield endpoint tests remain unchanged and continue to cover balance,
history, toggle-auto, deposit, and withdraw flows.

closes #478

- Add deserialize_whole_number helper that rejects fractional micro-unit
  amounts (e.g. 1000.5) with a clear error message
- Apply custom deserializer to DepositRequest.amount and
  WithdrawRequest.amount — Axum returns HTTP 422 on failure
- Add integration tests asserting 422 for fractional inputs and
  non-422 for whole-number inputs on both endpoints

Naira token amounts are integer micro-units; sub-unit fractions are
unrepresentable on-chain and must be rejected at the API boundary.
@drips-wave

drips-wave Bot commented Jul 23, 2026

Copy link
Copy Markdown

@Keengfk Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@ONEONUORA

Copy link
Copy Markdown
Contributor

@Keengfk
Sync with master branch
Update your branch
Work on your issue description
Make sure your implementation passes CI Checks

@ONEONUORA

Copy link
Copy Markdown
Contributor

@Keengfk
PLs update on this

@ONEONUORA

Copy link
Copy Markdown
Contributor

@Keengfk
Update on this PR
You will be unassigned at the end of today

@ONEONUORA ONEONUORA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great job @Keengfk

@ONEONUORA
ONEONUORA merged commit b815f2e into Fracverse:master Jul 28, 2026
11 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.

[BE-060] Yield API: Enforce decimal token precision checks

2 participants