Isolated leverage
A leverage position posts margin, borrows the same asset and swaps the total in one step. Its maintenance margin is stored by size, and keepers run its orders through a delegate program with bounded hooks.
Updated Nov 15, 2026
Opening a position
open_leverage takes margin in the debt asset and a multiplier . Idealised, it borrows of the same asset from the market and swaps through the curve. The output becomes the position's collateral, held in the leverage collateral vault, one token account per market and collateral mint, and the loan is tracked in the market's isolated debt bucket for that asset. Entry pays fees, price impact and any transfer fee, so the collateral is a little less than the notional divided by the entry price.
The program takes to be the amount the margin transfer credited after any transfer fee, and reads the multiplier in basis points:
The borrow rounds down and must be positive (AmountZero). The multiplier must be above 1× (InvalidArgument) and at most 20× (LeverageMultiplierTooHigh). A margin of 1,000 USDC at 50,000 bps borrows 4,000 USDC and swaps 5,000.
The instruction runs in this order:
- Read the oracle feed if the market is oracle-guided, check that the market has started and is not reduce-only, take the margin and accrue interest.
- Quote the swap of on the concentrated curve. The output, net of the collateral mint's transfer fee, must reach
min_collateral_out, and the all-in price must satisfy the optionallimit_price_nad, a quote-per-base limit rounded against the trader (SlippageExceeded). While either side's LP capital is wiped out, the quote fails withInsufficientLiquidity. - Move the output into the leverage collateral vault.
- Record the side's crowding potential, then apply the swap and the borrow. Reserve cash must cover (
InsufficientBorrowHeadroom). - Measure the reference depth after the trade, store the margin terms and run the admission tests below (
LeverageInitialMarginTooLow). - Settle the hedged vaults and check the reserves' custody.
Opens, size changes and closes all trade on the concentrated swap path. Liquidations use the flash and emergency paths in Internal unwind.
Stored margin terms
Each position stores its terms in collateral atoms when it takes on risk: a reference depth , band edges at 5% and 15% of , marginal maintenance rates, an entry buffer and an admission charge . Price, LP activity and other traders' positions never rebase them.
| Constant | Value | Meaning |
|---|---|---|
| Maximum multiplier | 20× | Ceiling on the requested multiplier, checked by open_leverage and by entry orders; the initial margin binds first |
| Maintenance tiers | 7%, 12%, 17% bands | Rates on the parts of a position below 5%, between 5% and 15%, and above 15% of |
| Entry buffer | 3 percentage points | Added to maintenance for the initial margin, before the crowding charge |
Reference depth
starts from the collateral side's reserve cash . It shrinks when the debt side's cash is worth less than at the symmetric average, and when the curve's current depth is above its pessimistic depth , the lower of observed depth and its average:
Here is valued at the symmetric average in debt units. A zero result fails with InsufficientLiquidity.
Maintenance and initial margin
For a position holding collateral atoms, each slice of is weighted by its band's rate:
Both round up to whole basis points. A charge as large as the whole collateral fails with LeverageInitialMarginTooLow.
Crowding
The charge comes from the side's leverage book , the gross collateral of every position on that side that owes debt. The program prices the book with a potential , the larger of two terms: the same bands plus the 3-point buffer applied to all of , and a crowding term whose rate starts rising once passes 20% of and which overtakes the bands when is about 1.11 times :
An open charges the rise in it causes, and never less than the position's own size-based equity:
uses the book and depth before the trade; adds to the book and uses the depth after it. The potential has no cap, so a charge above the whole collateral rejects the position. Rounding works against the trader: rounds down, and , , MM and IM round up.
Worked example
Take = 10,000 SOL, unchanged by the trade. The program's integer formulas give:
| Position | Book before | MM | IM | Highest multiple |
|---|---|---|---|---|
| 300 SOL | none | 7.00% | 10.00% | 10× |
| 1,000 SOL | none | 9.50% | 12.50% | 8× |
| 3,000 SOL | none | 13.67% | 16.67% | 5.99× |
| 1,000 SOL | 2,000 SOL | 9.50% | 20.00% | 5× |
| 1,000 SOL | 12,000 SOL | 9.50% | 33.00% | 3.03× |
The last column is , the multiple at which entry equity just meets IM with no fees or price impact. IM never falls below 10%, so no position opens above 10× whatever its size, and costs lower that ceiling further. The fourth row is the second position opened after 2,000 SOL of other leverage: the book is already past the 15% band, so each new unit is charged 17% plus the buffer.
Admission tests
After an open or an increase, the whole position must pass three tests against IM, each failing with LeverageInitialMarginTooLow:
- Selling all of it on the curve now returns debt atoms, with and , rounded down to whole basis points.
- At the lower of the directional and symmetric averages its collateral is worth , with and .
- At the symmetric average alone, its equity in basis points is at least IM.
When terms change
open_leveragestores fresh terms at the post-trade depth.increase_leveragekeeps the rates and buffer, lowers the stored to the current depth when that is smaller, so it can only tighten, and adds the crowding charge for the new collateral alone. After a full repayment the whole position is admitted again with fresh terms.- A decrease, a partial close or a partial liquidation scales by the share of collateral left, rounded up. stays, so MM falls as the position shrinks.
- Repaying all the debt takes the position out of and sets to zero. A repayment never re-checks IM.
Health and liquidation
Health marks the collateral the vault could deliver, net of the mint's transfer fee, linearly at the symmetric average and rounded down to debt atoms. It compares that with the indexed debt and MM at the current collateral. A position can be liquidated once
so equality counts. Depth and slippage stay out of this test, so a liquidity withdrawal cannot make a healthy position liquidatable. Internal unwind covers the fills, their discounts and the unwind at 70% of maintenance.
Market health, which public borrows, LP withdrawals and hLP deposits must keep above its floor, counts only public debt, so leverage debt never enters it. The debt still counts toward utilization and accrues on the same borrow index as public loans, so it pays the same rate.
A trigger, whether an order's or a liquidation's, only lets a keeper try. The close or fill must still pass its own checks in that slot.
Changing a position
| Instruction | Effect | Checks |
|---|---|---|
increase_leverage | Borrows more, adds margin, or both, and swaps the sum into collateral | Owner only; market live and not reduce-only; the whole position passes the admission tests again; no multiplier ceiling |
decrease_leverage | Sells part of the collateral to repay debt and pays any surplus to the owner | Must leave collateral behind (InsufficientAmount); min_repay_out and max_surplus_out (SlippageExceeded) |
close_leverage | Sells close_bps of the position, from 1 to 10,000 | The sale must cover the slice's debt (InsufficientAmount) and leave the owner min_amount_out; a full close closes the account |
add_leverage_margin, repay_leverage | Repay debt from outside; collateral is unchanged | Any payer; no health check; repay_leverage works when a guided market's oracle cannot be read |
withdraw_repaid_leverage | Returns all the collateral once the debt is zero and closes the account | Owner only; debt must be zero (InsufficientDebt) |
A partial close sells of the collateral and burns of the debt shares, rounded up so the rest cannot come out more leveraged. A decrease or partial close must leave the rest strictly above MM, both on the executable closeout and at the symmetric average, or it fails with LeveragePositionNotLiquidatable. Of these instructions only increase_leverage stops in reduce-only. While a flash liquidation holds the position, every action fails with LiquidationSessionActive.
The leverage-delegate program
Orders live in a second program. A position owner creates a delegation with create_leverage_delegation, naming the delegate program and a bitmask of actions; the Dusk program acts only on the close bit. The delegation is bound to the position's opening, its open_curve_revision, so closing a position and opening another at the same address leaves the old delegation and orders unusable.
A keeper executes an order through delegated_close_leverage, which calls the delegate twice. In order, the Dusk program:
- Accrues interest, cuts the slice and quotes the sale of the slice and of the whole position, then writes those quotes onto the position as a close approval for that slot.
- Calls the order's before hook,
before_take_profitorbefore_stop_loss, with every account read-only and no signer privilege. The hook checks the trigger against the approval and returns a fixed 222-byte approval, which Dusk compares byte for byte (InvalidLeverageDelegation). - Clears the approval, executes the sale it quoted, and pays the protocol fee, the executor and the owner in that order, checking each credit. The owner's share goes to the owner's own token account and must reach
min_amount_out. - Calls the after hook,
after_close_order, which checks the balance changes and closes the order account to its owner, so each order executes once, partial ones included.
The keeper receives its incentive and nothing else from the close. Take-profit and stop-loss orders trigger on the collateral's symmetric average price in debt tokens, refreshed in the same slot, and each order also stores a minimum payout to the owner. A trigger that does not hold fails with TriggerNotMet, and a close that would pay the owner less than the minimum fails with MinimumPayoutNotMet.
| Order | Kind | Trigger | Notes |
|---|---|---|---|
| Take-profit | 1 | Symmetric average price at or above the level | close_bps from 1 to 10,000; no expiry |
| Stop-loss | 2 | Symmetric average price at or below the level | The hooks check no health: a full close needs only the sale to cover the debt, and a partial one must leave the rest above maintenance |
| Entry | Own account | The opening's all-in price meets the stored limit when a keeper executes, at or before expiry | Margin and executor bounty escrowed; multiplier above 1× and at most 20×; any future Unix expiry; refunds only through the owner's cancel |
| hLP stop-loss | 1 | Principal NAV per hLP token at or below the level | hLP escrowed; yield recipient set to the owner |
| hLP stop-rate | 2 | Funding APR average at or above the level | Same escrow |
The hLP stop-loss reads , where is what withdrawing the escrowed hLP would pay in the target token now, principal only; accrued yield stays with the holder. The stop-rate reads an average of the rate the vault pays, the borrow APR plus the protocol's markup. Each interest accrual on a vault with funding debt updates it with weight
and before its first update the order reads the current APR. The twelve-hour half-life is a program constant, so an order's meaning cannot change after the owner signs it.
Every executed order pays a protocol fee of 10 bps, rounded up, to an account the futarchy treasury owns, on top of swap fees and the executor's incentive. The base and the incentive depend on the order:
- Take-profit and stop-loss: the fee is on the sale output, plus any transfer-fee gross-up. The executor then takes 5%, rounded up, of the opening margin on a full close or of the net residual on a partial one. Both are capped by what the residual leaves, and the owner receives the rest.
- Entry: the fee is on the opened notional, margin plus borrowed principal, and comes from a separate fee deposit; the executor receives the bounty the owner set at creation.
- hLP orders: the executor takes 5% of the withdrawal output, rounded up, before the owner's minimum-output check. The fee comes from what is left above the owner's minimum, which the owner must still receive (
InvalidOrder).
Entry and hLP orders pay the fee only as far as their budget allows, so it can be partial or nothing.
Protection orders
A sponsor, who need not own the position, can escrow srLP or hLP in an order through create_protection_order and let any keeper pay down a position when its health falls to a trigger. The order's action is fixed at creation: repay a borrow position, add collateral to a borrow position, or repay a leverage position. A leverage position can only be repaid. hLP qualifies only when its target token is the payment token.
For a leverage position, protection health is
in basis points, with the symmetric-average value used for liquidation. A reading of 10,000 is one basis point of equity above maintenance, and a position with no debt reads the maximum. The trigger must be above 10,000, the target above the trigger, the keeper fee at most 1,000 bps and every per-execution limit positive. The LP sits in the order's own token account, with no delegate or close authority.
execute_protection_order runs in this order:
- Check that the order is active and unexpired, and that the LP and payment fit the per-execution and remaining limits.
- Refresh health, which must be at or below the trigger (
TriggerNotMet). - The keeper pays the debt, through
repay_leveragefor a leverage position, and the payment must be worth at least the order's minimum per unit of LP. - The reward is the payment times the keeper fee, rounded down.
- Redeem the LP through
remove_liquidityorwithdraw_single_sided, with a minimum that covers the payment, the reward and a 10 bps protocol fee. - Reimburse the keeper, take the fee and return the rest to the sponsor.
- Health afterwards must reach the target and exceed where it started (
InvalidOrder).
Everything happens in one instruction and rolls back on any failure. The sponsor alone funds or cancels the order; cancelling returns all the LP.
Anyone may also repay a leverage position directly with repay_leverage, with no order and no reward. donate_collateral accepts borrow positions only.
Parameters
The 20× ceiling, the bands and rates, the buffer, the crowding curve, the 10 bps order fee, the 5% executor incentives and the funding average's half-life are program constants. Nothing in a market's configuration holds them, so neither the creator nor the operator can change them. A protection order's keeper fee and an entry order's bounty are set by whoever creates the order. Market settings that feed into these terms, such as the averages' half-lives and the curve's shape, change only through an operator bundle after the full notice; see Lifecycles.