fix: apply max_slip_fee cap in buy-side inversion#1413
Open
fix: apply max_slip_fee cap in buy-side inversion#1413
Conversation
|
Crate versions that have not been updated:
Runtime version has not been increased. |
|
Quick benchmark at commit c82845c has been executed successfully. |
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.
Description
Fixes a bug where
max_slip_feecap was not applied during buy-side trade inversion in theOmnipool math, breaking the invariant
delta_hub_reserve_in − total_protocol_fee = D_net.Changes:
calculate_buy_state_changes— afterinvert_buy_side_slip, check if cap fired and overrided_grosswith the capped linear formula; same check afterinvert_sell_side_feesfor thesell-side leg of buy inversion
buy_slip_fee_cap_invariant_holdsandsell_slip_fee_cap_invariant_holdsRelated Issue
#1412
Motivation and Context
The forward path (
calculate_slip_fee_amount) correctly caps the slip fee; the inverse path didnot - so the two paths produced inconsistent results when the slip rate exceeded
max_slip_fee.Sell trades are unaffected (no inversion involved).
How Has This Been Tested?
Two regression tests, one per inversion step, each verified to fail before the fix and pass after.
Checklist: