Docs menu

Protocol

Orders and pricing

Two-step orders, fill price, PnL, borrow, funding and liquidation, with the formulas the deployed contracts use.

View as Markdown

On this page

An order is a request first and a position second. Every number on this page is enforced by the deployed contracts. Values are the current testnet settings.

Two-step orders

The request records intent and escrows funds. The fill happens in a later transaction, at an oracle price that was published after the request was created. This closes the oracle front-running gap, where a trader who sees the next price before the chain does trades against the old one.

A requester can't cancel a live request, because cancelling would let them wait for the next price and walk away if it moved against them. If no fill arrives within 60 seconds the request expires, and the collateral and execution fee are refunded in full. Closes go through the same path, so an exit is priced fairly too.

Who fills

Any address can execute a pending request and earn its 0.1 USDG execution fee. Lanista runs a keeper, but the engine doesn't depend on it.

Fill price

P_fill = P_oracle × (1 + spread)   when buying
P_fill = P_oracle × (1 − spread)   when selling

The spread is 0.2% on every market. Longs open and shorts close at the higher price.

Profit and loss

PnL = d × S × (P_exit − P_entry) / P_entry

S is position size in USDG and d is +1 for a long, −1 for a short. Profit on a position is capped at 100% of its size, and the pool reserves that amount when the position opens.

Borrow

borrow per hour = r0 × U / U_max

U is the pool's reserved share. r0 is 0.01% an hour and U_max is the 60% utilisation cap, so borrow cost rises as the pool fills.

Funding

funding per hour = k × (OI_long − OI_short) / pool

k is 0.01% an hour. The heavier side pays the lighter side, which pushes open interest back toward balance.

Liquidation

liquidatable when  collateral + PnL − fees < m × S

m is the maintenance margin: 2% for stock markets, 1% for crypto. The liquidator earns 0.5% of the position's collateral.