refactor: reuse fee helper when hydrating pending swaps#348
Open
victortran0904 wants to merge 1 commit into
Open
refactor: reuse fee helper when hydrating pending swaps#348victortran0904 wants to merge 1 commit into
victortran0904 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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_swapto computeuser_receivesviaapply_fee_deduction(state.to_amount, FEE_DIVISOR)instead of inlining the calculation. - Add a regression test covering fee deduction when
to_amountis 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.
0f8f695 to
e068c1d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apply_fee_deduction(..., FEE_DIVISOR)when hydratinguser_receivesfrom an on-chain reservationFixes #334
Tests
uv run pytest tests/test_probe_pending_reservation.py -quv run pytest tests/test_rate.py -quv run ruff check allways/cli/swap_commands/helpers.py tests/test_probe_pending_reservation.pygit diff --check