A rebalance crank is a strategy transaction submitted by the vault admin or operator. The vault program exposes two normal rebalance actions:
deposit_strategy(amount)
withdraw_strategy(amount)
Both actions use the same accounting wrapper after the strategy handler runs.
Required Constraints
Before a rebalance can complete:
- the vault must be a rebalance vault
- the signer must be the vault admin or operator
- the strategy must already be listed on the vault
- the token vault, LP mint, and fee vault must match the vault
- the reserve and collateral vault must match the strategy
- the strategy handler must support the strategy type
In the current source, the implemented external lending handler is JupLend.
Accounting Flow
Record before state
The program records token vault liquidity, strategy current liquidity, vault total amount, unlocked amount, and LP supply.
Run strategy action
For deposits, tokens move from the token vault into the strategy. For withdrawals, strategy collateral is converted back into underlying tokens.
Convert collateral to liquidity
The strategy handler calculates current underlying liquidity from the strategy’s collateral amount and exchange rate.
Update total amount
The program updates total_amount from before and after token-vault and strategy-liquidity values.
Apply gain or loss
Gain is added to locked profit. Loss is reported and reduces locked profit first.
Mint performance-fee LP tokens
If gain is positive, the program calculates the 5% performance fee and mints LP tokens to the configured fee vault when the result is nonzero.
Total Amount Update
newTotalAmount=oldTotalAmount+tokenVaultAfter+strategyLiquidityAfter−tokenVaultBefore−strategyLiquidityBefore
Gain or loss is then measured from oldTotalAmount and newTotalAmount.
Why Locked Profit Changes During Rebalance
Strategy actions are when the vault observes updated strategy value. If a strategy action increases total vault value, that gain is not made fully withdrawable immediately. It is added to locked profit and unlocks over time.
If the strategy action reports a loss, that loss reduces remaining locked profit before affecting future unlocked value.
Fee Behavior
The program charges a 5% performance fee only on positive gain. The fee is represented by newly minted vault LP tokens sent to the configured fee vault. Underlying tokens remain inside the vault system.
See Dynamic Vault Formulas for the exact fee minting formula.
Rebalance transactions are not free-form transfers. They are constrained strategy actions. However, connected strategy behavior, available liquidity, exchange-rate conversions, and operator timing still affect the realized result.