Skip to content

fix: apply max_slip_fee cap in buy-side inversion#1413

Open
F3Joule wants to merge 11 commits intomasterfrom
f3/fix-slip-fee-cap
Open

fix: apply max_slip_fee cap in buy-side inversion#1413
F3Joule wants to merge 11 commits intomasterfrom
f3/fix-slip-fee-cap

Conversation

@F3Joule
Copy link
Copy Markdown
Contributor

@F3Joule F3Joule commented Apr 7, 2026

Description

Fixes a bug where max_slip_fee cap was not applied during buy-side trade inversion in the
Omnipool math, breaking the invariant delta_hub_reserve_in − total_protocol_fee = D_net.

Changes:

  • calculate_buy_state_changes — after invert_buy_side_slip, check if cap fired and override
    d_gross with the capped linear formula; same check after invert_sell_side_fees for the
    sell-side leg of buy inversion
  • Add regression tests buy_slip_fee_cap_invariant_holds and sell_slip_fee_cap_invariant_holds

Related Issue

#1412

Motivation and Context

The forward path (calculate_slip_fee_amount) correctly caps the slip fee; the inverse path did
not - 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:

  • I have updated the documentation if necessary.
  • I have added tests to cover my changes, regression test if fixing an issue.
  • This is a breaking change.

@F3Joule F3Joule self-assigned this Apr 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Crate versions that have not been updated:

  • hydra-dx-math: v13.2.1

Runtime version has not been increased.

@F3Joule F3Joule marked this pull request as ready for review April 8, 2026 12:09
@F3Joule F3Joule requested a review from enthusiastmartin April 8, 2026 12:12
@github-actions
Copy link
Copy Markdown

Quick benchmark at commit c82845c has been executed successfully.
View results

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.

1 participant