Docs · Guides
Provide liquidity
Deposit into a spot market's liquidity vault or the perps vault for sealed shares, see what they earn, and withdraw, in the app or from code.
Mesa's vaults are the liquidity behind its markets. You deposit, hold sealed shares, and earn what the vault earns. This guide covers the two trading vaults. Lending pools are vaults too, and Supply and redeem covers them.
| Vault | You deposit | It earns |
|---|---|---|
| A spot market's liquidity vault | Both assets of the pair | The market's fee on every fill |
| The perps vault | The collateral asset | Perp open and close fees, net funding, and traders' losses, less their gains |
Earn lists every vault with its rate, its total and what it earns from. GET /v1/vaults returns the same, with each vault's composition and share price.
Before you deposit
You need a Mesa balance of what the vault takes: both assets for a spot vault, the collateral asset for the perps vault. See Deposit and withdraw.
Deposit into a spot liquidity vault
1. Open Earn and choose the market's vault.
2. Enter the base amount. The quote amount beside it follows at the vault's current ratio.
3. Press "Review deposit". Check both amounts, the share price and the rate.
4. Press "Deposit".const { share } = await mesa.vaultDeposit({
vaultId: 'vault-lp-sol-usdc',
amountBase: 10_000_000_000n, // 10 SOL
amountQuote: 1_850_000_000n, // 1,850 USDC
amount: 1_850_000_000n, // the quote leg again
})The deposit goes through a batch as one action that locks both amounts. It settles after the market has cleared in that batch, at the ratio the reserves have then:
- shares are minted for the smaller of your two legs at that ratio, and the matching amount of the other leg is taken;
- what is left of the larger leg returns to your balance.
Because the ratio can move with the batch's trade, lock a little more quote than the current ratio needs. The surplus comes back.
Deposit into the perps vault
1. Open Earn and choose the perps vault.
2. Enter the amount.
3. Press "Review deposit", then "Deposit".const vaults = await mesa.mesa.client.vaults()
const perps = vaults.items.find((v) => v.kind === 'perps_vault')!
const { share } = await mesa.vaultDeposit({ vaultId: perps.id, amount: 2_000_000_000n })Shares are minted at the vault's share price of the batch: quote_reserve / total_shares.
Your shares
Shares appear under Your shares on the vault's page and under Shares on Portfolio, with their value at the current share price. While a deposit or withdrawal is still in its batch, the entry says so.
The vault's page charts its Share price, Rate and Total over time. On the batch record, the vault's total changes by your deposit, with no name on it.
What a spot vault's shares earn
The vault trades once per batch: the net of what the batch's orders did not match among themselves, at the batch's clearing price. Each fill pays the market's fee from its output, and the fee stays in the vault's reserves, less the protocol share. The share price is the reserves over the shares, so it rises with every batch that trades.
The vault holds both assets on a constant-product curve, so its mix shifts toward the asset the market has been selling. Your shares are a claim on that mix.
What the perps vault's shares earn
The vault takes the other side of every perp. It receives the open and close fees less the protocol share, the net of funding, and what traders lose, and it pays what they gain.
Withdraw
1. Open Earn and choose the vault.
2. Select "Withdraw" and enter the shares to withdraw.
3. Press "Review withdraw", then "Withdraw".const held = mesa.snapshot().shares.find((s) => s.vaultId === 'vault-lp-sol-usdc')
if (held) await mesa.vaultWithdraw({ vaultId: held.vaultId, shares: held.shares })A withdrawal goes through a batch. From a spot vault it pays both assets, pro rata to the reserves. From the perps vault it pays the collateral asset at the share price of the batch.
Reclaim a refused withdrawal
A withdrawal the vault could not pay is refused once its batch clears: nothing is paid, and the shares are still yours. Take them back with a reclaim.
On the vault's page, the line under "Your shares" reads "withdrawal refused in batch N". Press "Reclaim shares".const held = mesa.snapshot().shares.find((s) => s.vaultId === 'vault-lp-sol-usdc')
if (held?.pending?.state === 'refused') {
await mesa.mesa.run({ kind: 'reclaim', orderId: held.pending.actionId }, console.log)
}What can stop a deposit or withdrawal
| You see | Cause | Do |
|---|---|---|
| "Deposit into Mesa first" | No free balance of what the vault takes | Deposit, then try again |
| "More than is available." | More than your balance or more shares than you hold | Enter less |
| A refused withdrawal | The shares named are too few to pay out in both assets, or the vault cannot pay in that batch | Reclaim the shares, then withdraw them together with the rest of your holding |
MarketNotCleared | Settling was attempted before the vault's market cleared | Nothing. The keeper clears the market first and settles after. |
BATCH_CLOSED, STALE_BATCH | The batch closed while the action was being proved | Send it again |