feat: add per-call max_fee_bps slippage protection to deduct - #519
Merged
greatest0fallt1me merged 1 commit intoJun 27, 2026
Merged
Conversation
|
@Okorie2000-code Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Merged via direct push to main (admin) |
4 tasks
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
Implements issue #498. Adds a
max_fee_bps: u16parameter todeductthat reverts with the new typedVaultError::Slippage(code 35) when the deducted amount expressed in basis points of the current balance exceeds the caller's limit.Pass
u16::MAX(65535) to disable the guard — backward-compatible default for all existing integrations.Security rationale
The slippage guard is a pre-mutation check. It fires after input validation and idempotency checks but strictly before any state write or external token transfer. A failed check leaves the vault in exactly the state it was before the call — no partial effects, no balance change. This protects callers against race conditions or unexpected balance drift that could cause a single call to drain a disproportionately large fraction of the vault.
Changes
lib.rs—Slippage = 35added toVaultError;max_fee_bps: u16added todeduct; slippage check inserted before state mutation.test.rs— 8 new targeted tests (below/equal/above limit,u16::MAX, boundary 0 and 1 bps, pre-mutation assertion, regression).deduct/try_deductcall sites updated to pass&u16::MAX.docs/interfaces/vault.json—max_fee_bpsparam andSlippage (35)error documented.Closes
Closes #498