Asset Management
Recipe - Target Weight Rebalance
A policy to maintain a fixed portfolio allocation.
Recipe: Target Weight Rebalance
This policy allows a manager to rebalance a portfolio to match a target allocation (e.g., 50% WBTC, 50% USDC), but only if the trade reduces the "drift" (deviation from target).
The Strategy
Goal: Maintain 50/50 split.
Constraint: Only allow the rebalance direction chosen by your off-chain logic.
Safety: Prevent "churning" by requiring a minimum drift before rebalancing (calculated off-chain).
Off-chain logic stays bounded
The policy encodes the minimum drift threshold and permitted token pair, preventing discretionary drift trades.
The Policy
import "abis/UniswapRouter.json" as Uniswap;
permission TargetWeightRebalance -> 1.0.0 {
parameters: {
router: address,
tokenIn: address,
tokenOut: address,
minDriftBps: uint256,
driftBps: uint256
}
fn main() -> bool {
if (context.target != parameters.router) {
return false;
}
if (parameters.driftBps < parameters.minDriftBps) {
return false;
}
if (context.selector == Uniswap.exactInputSingle) {
if (Uniswap.exactInputSingle.params.tokenIn != parameters.tokenIn) {
return false;
}
return Uniswap.exactInputSingle.params.tokenOut == parameters.tokenOut;
}
return false;
}
}Integration
This policy turns a dumb wallet into a Smart Index Fund. The manager can execute the rebalance, but they cannot:
- Trade outside the token pair specified in the policy parameters.
- Rebalance unless the drift threshold is met (as calculated off-chain).