Docs · Concepts
Liquidity vaults
The vaults behind Mesa's markets, how each one trades, what its shares earn, and how deposits and withdrawals pass through a batch.
A vault is the liquidity behind a market. Mesa has three kinds: one liquidity vault per spot market, one lending pool per asset, and the perps vault. Each is a public account with public reserves and totals, and the claims on it are sealed share notes.
The three kinds
| Vault | Trades with | Earns from |
|---|---|---|
| Spot liquidity vault | Each batch's net imbalance in its market, at the clearing price | The market's fee on every fill |
| Lending pool | Borrowers of its asset | Interest |
| Perps vault | Every perp position, at the oracle price | Open and close fees, funding, and traders' losses |
The app lists all of them at /earn, and GET /v1/vaults returns them with their composition, share price and history.
Spot liquidity vaults
A spot vault holds a market's base and quote assets on a constant-product curve, x · y = k. It gives a market depth from its first batch: a batch with one order still clears, against the vault.
The vault trades once per batch. After the batch opens, the program finds the price at which the orders' net demand equals what the curve sells, and the vault trades exactly that net amount at that price. Orders that match each other never touch it. The rule and an example are in Clearing at one price.
No order sees the vault's price before the batch closes, and the whole batch trades at the price the batch itself sets, so no arbitrage trades against the vault between batches.
The market's fee_bps is taken from each fill's output. The vault keeps it in its reserves, less the protocol share, so the value of a share rises with every batch that trades.
Deposit and withdraw
A deposit brings both assets. It is placed into a batch as two locked amounts under one action, and settles after the market has cleared in that batch:
- shares are minted at the ratio of the reserves as the clear left them;
- whichever leg exceeds that ratio is refunded to your balance.
A withdrawal places shares into a batch and settles into both assets, pro rata to the reserves.
Lending pools
A pool holds one asset. Suppliers hold shares; borrowers pay interest at a rate set by the pool's utilization along a curve with a kink: base at zero utilization, rising by slope1 up to the kink, and by slope2 beyond it.
Interest accrues each time the pool clears. A share of it, the pool's reserve_factor_bps, goes to the pool's reserves, and the rest raises the share price:
share price = (cash + borrows − reserves) / supply_sharesA supply mints shares at the share price of the batch it settles in, and a redeem burns them at that batch's price. A redeem is paid from the pool's cash, which is what has not been lent out.
The perps vault
The perps vault is the counterparty to every perp position. A position opens and closes at the oracle price, so there is no order book. A trader's loss is paid into the vault when the position closes or is liquidated, and a gain is paid out of it. The vault also receives each market's open and close fees. It stands on the other side of any imbalance between longs and shorts, so the net of funding lands in it.
Shares are minted and redeemed at quote_reserve / total_shares, through a batch like every other deposit.
Shares are sealed
A share note records which pool or vault it claims and how many shares. Only its owner can read it. The vault's total shares and reserves are public, so anyone can compute the share price, and nobody can see how the shares are divided.
Parameters
Each vault's and pool's parameters are fields of its public account: a market's fee_bps; a pool's rate curve, collateral_factor_bps, liq_threshold_bps, liq_bonus_bps and reserve_factor_bps; a perp market's fees, max_leverage, maint_margin_bps and max_oi. Markets, pools and their parameters lists them with their current values.
To provide liquidity, follow Provide liquidity or Supply and redeem.