Skip to content

refactor: reuse fee helper when hydrating pending swaps#348

Open
victortran0904 wants to merge 1 commit into
entrius:testfrom
victortran0904:codex/use-apply-fee-deduction-in-hydrate
Open

refactor: reuse fee helper when hydrating pending swaps#348
victortran0904 wants to merge 1 commit into
entrius:testfrom
victortran0904:codex/use-apply-fee-deduction-in-hydrate

Conversation

@victortran0904
Copy link
Copy Markdown

Summary

  • use apply_fee_deduction(..., FEE_DIVISOR) when hydrating user_receives from an on-chain reservation
  • add regression coverage for a non-divisible destination amount

Fixes #334

Tests

  • uv run pytest tests/test_probe_pending_reservation.py -q
  • uv run pytest tests/test_rate.py -q
  • uv run ruff check allways/cli/swap_commands/helpers.py tests/test_probe_pending_reservation.py
  • git diff --check

Copilot AI review requested due to automatic review settings May 20, 2026 05:58
@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Restructures code without changing behavior label May 20, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes duplicated protocol-fee math in the CLI pending-swap hydration path by reusing the shared apply_fee_deduction helper, and adds a regression test to ensure fee rounding behavior stays correct for non-divisible destination amounts.

Changes:

  • Refactor hydrate_pending_swap to compute user_receives via apply_fee_deduction(state.to_amount, FEE_DIVISOR) instead of inlining the calculation.
  • Add a regression test covering fee deduction when to_amount is not cleanly divisible by the fee divisor (e.g., 101 -> 100).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
allways/cli/swap_commands/helpers.py Replaces inline fee deduction with the shared apply_fee_deduction helper using FEE_DIVISOR.
tests/test_probe_pending_reservation.py Adds regression coverage verifying hydrate_pending_swap sets fee-adjusted user_receives for non-divisible amounts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@victortran0904 victortran0904 force-pushed the codex/use-apply-fee-deduction-in-hydrate branch from 0f8f695 to e068c1d Compare May 20, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Restructures code without changing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: hydrate_pending_swap inlines fee math instead of using apply_fee_deduction

2 participants