RebalanceEngine
TheRebalanceEngine is a stateless contract that calculates and executes the trades needed to rebalance a vault’s portfolio.
How It Works
When a vault triggers rebalancing:- Calculate: The engine compares current token weights against target weights
- Plan: It generates a set of
TradeOrderstructs — sells for over-weight tokens, buys for under-weight tokens - Execute: Trades are executed through the
TokenRouterwith slippage protection
Trade Execution
tokenIn/tokenOut: the swap pairamountIn: exact amount to sellminAmountOut: slippage protection (minimum acceptable output)
- Sell: overWeight token → tiltUSDC
- Buy: tiltUSDC → underWeight token
Authorization
Only registered vaults can callexecuteRebalance(). The factory automatically authorizes new vaults on the engine during deployment.
The vault owner or RebalanceEngine can also set authorized callers for triggering rebalances externally (e.g., Chainlink Keepers).
Slippage Protection
Every trade includes aminAmountOut parameter calculated from the oracle price minus the configured slippage tolerance. If the execution price is worse than this minimum, the trade reverts.