Docs · Concepts

Sealed positions and renewal

What a borrow or perp position is, how it proves it is healthy each heartbeat without showing its contents, who can renew it, and what the owner can change.

A position is a borrow or a perp. Its collateral, liquidation price and owner are sealed. To stay sealed it has to keep proving it is healthy, which is what keeps lenders whole. This page covers the proof and its schedule. Liquidation covers what happens to a position that stops.

What a position holds

A position is one note. The note's own asset and amount are the collateral. Its data holds the rest.

FieldBorrowPerp
Kind, side, targetThe pool borrowed fromLong or short, and the perp market
debtPrincipal at entrySize, in base atoms
entryThe pool's borrow index at entryThe oracle price at entry
fundingUnusedThe market's funding index at entry
deadlineThe time it is renewed toThe same
homeThe account holder a liquidation's remainder returns toThe same

A position is isolated: one collateral asset against one debt, or one perp.

The position note is created when the borrow or perp open is placed, before the batch closes, with a proof that it is healthy at the oracle price at that moment. That price is a perp's entry price, and the pool's borrow index at that moment is a borrow's entry index. When the batch opens, the debt or size becomes public as part of the action's terms. The collateral stays in the sealed note.

Heartbeats

Time is cut into heartbeat epochs of one length, heartbeat, set in Config and returned by GET /v1/config as heartbeatSeconds. Epoch e covers

text
[genesis_ts + e · heartbeat,  genesis_ts + (e + 1) · heartbeat)

A position's deadline is always the end of an epoch. A position opened or renewed during epoch e gets the end of epoch e + 1, so it has at least one full heartbeat ahead of it.

A position that keeps renewing

placedrenewedrenewedrenewedrenewed

Each proof says only that it is healthy at the oracle price. Nobody reads it.

A position that stops

placedrenewedreneweddeadline passed: openhealthy: renewed, sealed againunhealthy: liquidated by anyone

Its collateral, debt or size become readable only after a missed deadline.

A position across heartbeats: renewed, renewed, then left to lapse.

Every position renewed in the same epoch carries the same deadline. A renewal therefore tells the chain that some position renewed, and its deadline does not single it out from the others.

Renewal

renew replaces a position with the same position and a new deadline. Its proof shows, without revealing any field, that the position is healthy at the oracle price and index the program reads at that moment:

text
borrow:  collateral · price · liq_threshold  ≥  debt · index / entry
perp:    collateral + pnl − funding          ≥  size · price · maint_margin

The circuit allows one change, the deadline, and the program checks the new deadline is the one the epoch rule gives. Collateral, debt and owner cannot move in a renewal.

pnl is the position's size times the move in the oracle price since entry, signed by its side. funding is covered below.

Who can renew

Renewal needs the position's keys and no spend secret. Three things can hold them:

  • Your browser, while the app is open.
  • Your own script, running the SDK's renew loop.
  • The watcher, Mesa's service, once you hand it that position's key.

What you hand the watcher is one position's keys and contents. It lets the watcher read and renew that position. It opens nothing else in your account, and a renewal can only produce the same position with a later deadline, so the watcher can move nothing. Keep positions renewed sets up each of the three.

What a renewal shows

The chain shows that a position in some pool or perp market was renewed to an epoch's deadline, and the oracle price the proof used.

Funding

Each time a perp market clears, its funding index moves by the oracle price, the market's funding_rate_bps_per_hour, the time since the last clear, and the imbalance of open interest:

text
price · rate · elapsed · (oi_long − oi_short) / (oi_long + oi_short)

The index moves only at a clear, as a pool's borrow index does.

When longs outweigh shorts the index rises and longs pay. When shorts outweigh longs it falls and shorts pay. A position owes its size times the change in the index since its entry, signed by its side. That amount counts in its health at every renewal and is settled when the position closes or is liquidated. The perps vault stands on the other side of the imbalance, so the net of funding paid and received lands in the vault.

The timelock on a position

Each instruction that creates or renews a position also publishes a ciphertext of the position's contents and keys, encrypted to the drand round at its deadline. While the position keeps renewing, each ciphertext is replaced by the next before its round arrives, and by then the position it describes has already been spent, so it opens nothing current.

If a deadline passes without a renewal, the round is published and the ciphertext can be decrypted by anyone. The position has lapsed: its collateral, debt and entry are readable.

A lapsed position that is unhealthy can be liquidated by anyone.

Changing a position

These need the owner's spend secret.

ActionWhat it doesInstruction
RepayReduces a borrow's debt by an amount paid from your balancerepay
Add collateralMoves balance into the positionrepay, with nothing repaid
Remove collateralMoves collateral back to your balancerepay, with nothing repaid
Close a borrowRepays the whole debt at the current index and returns the collateralclose_position
Close a perpGoes through a batch and settles against the perps vaultplace

Each of them proves the position healthy afterwards and sets a new deadline. A repayment's amount is public, as an amount repaid to a pool.

A borrow or perp open that its batch Refused leaves a position that was never activated. close_position returns its collateral with nothing to repay.

Why a sealed position is safe to lend against

A lender cannot see any single position, and can still rely on all of them: every position that has not lapsed carries a proof of health no older than one heartbeat, checked on chain against the oracle. The heartbeat's length and each market's liquidation threshold are set together, so that a position that was healthy at its last proof is still worth more than its debt when its deadline arrives.