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 mm in the debt asset and a multiplier L\mathcal L. Idealised, it borrows m(L−1)m(\mathcal L - 1) of the same asset from the market and swaps mLm\mathcal L 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 mm to be the amount the margin transfer credited after any transfer fee, and reads the multiplier in basis points:

b=⌊m Lbps10,000⌋−m,n=m+bb = \left\lfloor \frac{m\,\mathcal L_{\text{bps}}}{10{,}000} \right\rfloor - m, \qquad n = m + b

The borrow bb 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:

  1. 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.
  2. Quote the swap of nn 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 optional limit_price_nad, a quote-per-base limit rounded against the trader (SlippageExceeded). While either side's LP capital is wiped out, the quote fails with InsufficientLiquidity.
  3. Move the output into the leverage collateral vault.
  4. Record the side's crowding potential, then apply the swap and the borrow. Reserve cash must cover bb (InsufficientBorrowHeadroom).
  5. Measure the reference depth after the trade, store the margin terms and run the admission tests below (LeverageInitialMarginTooLow).
  6. 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 LL, band edges at 5% and 15% of LL, marginal maintenance rates, an entry buffer and an admission charge AA. Price, LP activity and other traders' positions never rebase them.

ConstantValueMeaning
Maximum multiplier20×Ceiling on the requested multiplier, checked by open_leverage and by entry orders; the initial margin binds first
Maintenance tiers7%, 12%, 17% bandsRates on the parts of a position below 5%, between 5% and 15%, and above 15% of LL
Entry buffer3 percentage pointsAdded to maintenance for the initial margin, before the crowding charge

Reference depth

LL starts from the collateral side's reserve cash CC. It shrinks when the debt side's cash dd is worth less than CC at the symmetric average, and when the curve's current depth ℓ\ell is above its pessimistic depth ℓ^\hat\ell, the lower of observed depth and its average:

L=⌊⌊C⋅min⁡(d, v)v⌋⋅min⁡(ℓ^, ℓ)ℓ⌋L = \left\lfloor \left\lfloor C\cdot\frac{\min(d,\ v)}{v} \right\rfloor \cdot \frac{\min(\hat\ell,\ \ell)}{\ell} \right\rfloor

Here vv is CC valued at the symmetric average in debt units. A zero result fails with InsufficientLiquidity.

Maintenance and initial margin

For a position holding cc collateral atoms, each slice of cc is weighted by its band's rate:

W(c)=7%⋅min⁡(c, 0.05L)+12%⋅min⁡((c−0.05L)+, 0.1L)+17%⋅(c−0.15L)+\begin{aligned} W(c) ={}& 7\%\cdot\min(c,\ 0.05L) \\ &+ 12\%\cdot\min\big((c - 0.05L)^+,\ 0.1L\big) \\ &+ 17\%\cdot(c - 0.15L)^+ \end{aligned} MM(c)=⌈W(c)c⌉IM(c)=max⁡ ⁣(MM(c)+3%, ⌈Ac⌉)\begin{aligned} \text{MM}(c) &= \left\lceil \frac{W(c)}{c} \right\rceil \\ \text{IM}(c) &= \max\!\Big(\text{MM}(c) + 3\%,\ \left\lceil \frac{A}{c} \right\rceil\Big) \end{aligned}

Both round up to whole basis points. A charge AA as large as the whole collateral fails with LeverageInitialMarginTooLow.

Crowding

The charge AA comes from the side's leverage book EE, the gross collateral of every position on that side that owes debt. The program prices the book with a potential FF, the larger of two terms: the same bands plus the 3-point buffer applied to all of EE, and a crowding term whose rate starts rising once EE passes 20% of LL and which overtakes the bands when EE is about 1.11 times LL:

S(E)=W(E)+3%⋅EF(E)=max⁡(S(E), E⋅r(E))r(E)=10%+110 (E/L−20%)+\begin{aligned} S(E) &= W(E) + 3\%\cdot E \\ F(E) &= \max\big(S(E),\ E\cdot r(E)\big) \\ r(E) &= 10\% + \tfrac{1}{10}\,(E/L - 20\%)^+ \end{aligned}

An open charges the rise in FF it causes, and never less than the position's own size-based equity:

A=max⁡(Fafter−Fbefore, S(c))A = \max\big(F_{\text{after}} - F_{\text{before}},\ S(c)\big)

FbeforeF_{\text{before}} uses the book and depth before the trade; FafterF_{\text{after}} adds cc 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: LL rounds down, and SS, FF, MM and IM round up.

Worked example

Take LL = 10,000 SOL, unchanged by the trade. The program's integer formulas give:

Position ccBook EE beforeMMIMHighest multiple
300 SOLnone7.00%10.00%10×
1,000 SOLnone9.50%12.50%8×
3,000 SOLnone13.67%16.67%5.99×
1,000 SOL2,000 SOL9.50%20.00%5×
1,000 SOL12,000 SOL9.50%33.00%3.03×

The last column is 10,000/IMbps10{,}000/\text{IM}_{\text{bps}}, the multiple at which entry equity 1/L1/\mathcal L 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:

  1. Selling all of it on the curve now returns QQ debt atoms, with Q>DQ > D and (Q−D)/Q≥IM(Q - D)/Q \ge \text{IM}, rounded down to whole basis points.
  2. At the lower of the directional and symmetric averages its collateral is worth VV, with V>DV > D and V−D≥⌈IM⋅V⌉V - D \ge \lceil \text{IM}\cdot V \rceil.
  3. At the symmetric average alone, its equity in basis points is at least IM.

When terms change

  • open_leverage stores fresh terms at the post-trade depth.
  • increase_leverage keeps the rates and buffer, lowers the stored LL 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 AA by the share of collateral left, rounded up. LL stays, so MM falls as the position shrinks.
  • Repaying all the debt takes the position out of EE and sets AA 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 VV debt atoms. It compares that with the indexed debt DD and MM at the current collateral. A position can be liquidated once

D>0  andD≥V  or  V−D≤MM⋅V\begin{aligned} &D > 0\ \text{ and} \\ &D \ge V\ \text{ or }\ V - D \le \text{MM}\cdot V \end{aligned}

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

InstructionEffectChecks
increase_leverageBorrows more, adds margin, or both, and swaps the sum into collateralOwner only; market live and not reduce-only; the whole position passes the admission tests again; no multiplier ceiling
decrease_leverageSells part of the collateral to repay debt and pays any surplus to the ownerMust leave collateral behind (InsufficientAmount); min_repay_out and max_surplus_out (SlippageExceeded)
close_leverageSells close_bps of the position, from 1 to 10,000The 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_leverageRepay debt from outside; collateral is unchangedAny payer; no health check; repay_leverage works when a guided market's oracle cannot be read
withdraw_repaid_leverageReturns all the collateral once the debt is zero and closes the accountOwner only; debt must be zero (InsufficientDebt)

A partial close sells ⌊c⋅bps/10,000⌋\lfloor c\cdot\text{bps}/10{,}000 \rfloor of the collateral and burns ⌈shares⋅slice/c⌉\lceil \text{shares}\cdot\text{slice}/c \rceil 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:

  1. 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.
  2. Calls the order's before hook, before_take_profit or before_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).
  3. 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.
  4. 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.

OrderKindTriggerNotes
Take-profit1Symmetric average price at or above the levelclose_bps from 1 to 10,000; no expiry
Stop-loss2Symmetric average price at or below the levelThe 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
EntryOwn accountThe opening's all-in price meets the stored limit when a keeper executes, at or before expiryMargin and executor bounty escrowed; multiplier above 1× and at most 20×; any future Unix expiry; refunds only through the owner's cancel
hLP stop-loss1Principal NAV per hLP token at or below the levelhLP escrowed; yield recipient set to the owner
hLP stop-rate2Funding APR average at or above the levelSame escrow

The hLP stop-loss reads ⌊109 Qw/h⌋\lfloor 10^9\,Q_w/h \rfloor, where QwQ_w is what withdrawing the escrowed hh 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

rˉ′=α rˉ+(1−α) r,α=2−Δt/12 h\bar r' = \alpha\,\bar r + (1 - \alpha)\,r, \qquad \alpha = 2^{-\Delta t / 12\,\text{h}}

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

h=⌊V (10,000−MM−1)D⌋h = \left\lfloor \frac{V\,(10{,}000 - \text{MM} - 1)}{D} \right\rfloor

in basis points, with VV 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:

  1. Check that the order is active and unexpired, and that the LP and payment fit the per-execution and remaining limits.
  2. Refresh health, which must be at or below the trigger (TriggerNotMet).
  3. The keeper pays the debt, through repay_leverage for a leverage position, and the payment must be worth at least the order's minimum per unit of LP.
  4. The reward is the payment times the keeper fee, rounded down.
  5. Redeem the LP through remove_liquidity or withdraw_single_sided, with a minimum that covers the payment, the reward and a 10 bps protocol fee.
  6. Reimburse the keeper, take the fee and return the rest to the sponsor.
  7. 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.