rust: Renamed → to make clear it returns the fee in the token's raw… - #170
Merged
Conversation
rust: Align remaining Result<_, String> APIs to PoolError
rust: No panic when current time < last for quant and reclamm
Fix `stable_math::compute_invariant` panics on a zero balance
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.
4.
compute_and_charge_aggregate_swap_feesreturns raw units but reads as scaled-18Impact: the crate is internally safe, but the API shape misleads consumers. It cost us a real
bug that a wei-exact
amountOutparity suite could not catch.The helper mirrors the Vault and returns the fee in the token's raw units:
vault::swap::swapbinds it to a scaled-18 name and subtracts it from scaled-18 balances:Inside the crate this is harmless —
updated_balancesonly feedsAfterSwapParams, andswap()returns
Result<U256, _>, so for hookless pools the value is computed and discarded.It is a trap for anyone reproducing that balance update, which a quoter must do to report post-swap
state for multi-hop routing. We copied the pattern and under-deducted the protocol fee by the
token's scaling factor —
1e12for USDC, and exactly zero for 18-decimal tokens at a rate of one,which is why it survived our parity suite for so long. Measured with a 6-decimal input token, 1%
swap fee, 25% aggregate share:
Suggested fix: rename the function to
..._raw, or return a newtype carrying the unit. Renamingthe local in
vault::swap::swapalone would remove most of the hazard.