how leverage works
PerpLand's leverage doesn't use an external lender. There's no Aave, no Morpho, no off-protocol pool of capital. The leverage comes from the protocol's own bands: ETH that's already accumulated in already-traversed bands is single-sided-removed and added to the user's collateral for the buy.
step by step
1. user calls openLong{value: C}(leverage L) 2. hook computes: borrow = C × (L − 1) borrowFee = borrow × 1% // → stakers effectiveCol = C − borrowFee 3. hook walks bands 0..299 farthest-first - skip if band.tickLower ≤ currentTick // not passed yet - skip if band.borrowedETH ≥ 40% × band capacity - else: modifyLiquidity(-L), take(ETH, hook, freed) - accumulate freed ETH until borrow is satisfied 4. hook swaps (effectiveCol + borrow) ETH → PERP via the pool 5. position recorded: collateral, debt, holding, openFundingIndex, openedAtBlockper-band cap
Each band can have at most 40% × TICK_WIDTH_ETH = 2 ETH of outstanding borrow. This keeps any single band's LP from being fully drained — even if all positions abandon, half the pool's depth in that band stays in place.
borrow walk caps
The per-open borrow walk has two limits:
- MAX_BORROW_BANDS = 5 — a single open touches at most 5 bands. Caps gas + caps the maximum borrow per open to ~10 ETH.
- MAX_CURVE_ADVANCE_PER_BLOCK = 5 ETH — global per- block budget shared across direct buys + all opens. Closes the multi-block sustained-pump attack.
what the user gets
After an open, the user has:
- A
positionIdmapped to a position struct: owner, collateral, debt, holding token amount, open price, open block, open funding index. - A liquidation price at
Pliq = Pentry × 1.05 × (L − 1)/L. - The right to close at any time after
CLOSE_COOLDOWN_BLOCKS.
what the user does NOT get
- PERP tokens directly. The hook holds them as position collateral. Users only get ETH back, via close or liquidation surplus.
- The ability to transfer the position. v0.1 positions are non-transferable. A future version could wrap as ERC-721.