Managing leverage
TL;DR
To leverage up: mint the CDP stablecoin, swap half of the amount into the volatile token (e.g. wBTC) and pair it with the other half into the AMM and add the resulting LP liquidity to the vault’s leveraged position.
To unwind / delever: withdraw LP liquidity, convert the volatile portion back into the CDP stablecoin, and repay debt.
Mechanical and neural-based keepers manage on-chain execution of the low-level ops; lowering debt rebalancing costs, maximising swap fee capture and minimising IL.
Leverage-up flow
Mint stablecoin. Vault mints stablecoin against the deposited collateral.
Swap / pair stablecoin with volatile asset. Swap the freshly minted stablecoin for the volatile token where needed, preparing the right ratio to add to the LP.
Deposit into LP (add liquidity). Add stablecoin + volatile asset into the ALM . Read more here.
Update loop accounting. Increase
commulative_lpandcommulative_debtbookkeeping so the vault’s internal state reflects the new looped exposure. These numbers drive subsequent CR (collateralisation ratio) calculations.
Delever / unwind flow
Withdraw LP liquidity
ALM withdraws the required LP position(s) to free up the volatile token + stablecoin proportion.
Convert volatile portion to stablecoin
Swap the volatile token portion for stablecoin (on the DEX) so that the vault holds stablecoin needed to repay debt. This swap considers slippage & market depth.
Repay stablecoin debt
Repay the stablecoin, which lowers
cumulative_debtdecreasing leverage in turn increasing the vault’s collateral ratio.
Safety & mechanical guardrails
Mechanical keepers are the deterministic layer that executes the flows above when certain hard constraints are met.
Ensure on-chain collateralisation stays within predefined parameters (e.g. 190-220%) by executing increase-leverage and decrease-leverage.
Check gas & slippage budgets.
Neural leveraging agents
Role: the agent proposes timing of rebalances inside the mechanical banding (top/bottom leverage limits). It recommends smaller sub-target rebalances (mid / upper-subtarget / lower-subtarget) rather than jumping straight to extremes.
Not a replacement for keepers: the agent does not open or close leverage loops directly. It issues a decision (do nothing / mid / top-subtarget / bottom-subtarget). Keepers apply the mechanical safety checks and execute the corresponding on-chain flow (leverage up or delever) only if allowed.
Why we use this hybrid: agents can time rebalances to windows of higher fee capture and lower expected slippage (observed in our backtests), while keepers guarantee on-chain safety and consistent execution. Our development and backtests showed the agent can improve outcomes while staying within the same mechanical constraints.
Example action mapping (how an agent’s choice maps to flows)
Action = Do nothing (0) → no change. Keeper continues monitoring.
Action = Rebalance to midpoint (1) → small leverage-up or delever sequence executed: mint/repay only the stablecoins required to hit midpoint target.
Action = Rebalance to upper sub-target (2) → a controlled leverage-up flow (mint stablecoins → deposit into LP) sised to move to the upper sub-target leverage.
Action = Rebalance to lower sub-target (3) → a controlled delever: withdraw LP → swap volatile → repay stablecoin sised to move to the lower sub-target. These actions are intentionally discretised so the vault avoids large single-shot moves and limits slippage.
Last updated
