Fix: Add 5% fee margin buffer for scheduling estimation variance#68
Merged
Fix: Add 5% fee margin buffer for scheduling estimation variance#68
Conversation
Removed the isInternallyManaged check in executeTransaction(). Now ANY execution (internal or external) will trigger scheduleNextRebalance() if the AutoBalancer has a recurring config. This ensures externally-scheduled transactions (e.g., Supervisor recovery) will restart the self-scheduling cycle instead of being fire-once. The scheduleNextRebalance function already handles deduplication by checking for existing scheduled transactions within the interval.
This adds a new optional flag 'restartRecurring' in the data parameter that,
when true, signals the AutoBalancer to resume self-scheduling after execution
even for externally-scheduled transactions.
Use case: Supervisor recovery - when a stuck tide is seeded by the Supervisor,
it should resume its normal self-scheduling cycle rather than being 'fire once'.
Design:
- Default behavior unchanged: external schedules are 'fire once'
- Pass {"restartRecurring": true} to restart the self-scheduling cycle
- Preserves original design from PR #45 while enabling recovery scenarios
See: #45 for original design context
…overy instead Keep only the fee buffer fix (5% margin) in scheduleNextRebalance(). The recovery mechanism now uses Schedule capability to directly call scheduleNextRebalance() rather than passing a flag through executeTransaction().
Merged
6 tasks
46cb774 to
94560b3
Compare
nialexsan
approved these changes
Nov 28, 2025
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
Adds a 5% margin buffer to the fee estimation in
AutoBalancer.scheduleNextRebalance()to handle variance in scheduling cost calculations.Problem
When AutoBalancers self-schedule recurring rebalances, they estimate the required fees via
FlowTransactionScheduler.estimate(). However, the actual fee at scheduling time can sometimes slightly exceed the estimate, causing the scheduling to fail with insufficient fees even when the account has adequate funds.Solution
Add a 5% buffer (
1.05multiplier) when:Changes
DeFiActions.cdc: Added 5% fee margin buffer inscheduleNextRebalance()Testing
Tested in FlowVaults-sc with comprehensive scheduling tests - all 18 tests pass.