Docs · Reference

Program: errors

Every error the mesa program returns, with its code, its message, the instructions that raise it and under what condition, what the caller does about it, and how the code reaches an API client.

The mesa program defines 33 errors, numbered 9000 to 9032. This page lists each with the conditions that raise it, read from the program, and what a caller does next. The instructions are in Program: instructions.

How an error reaches the caller

A MesaError leaves the program as Solana's Custom program error carrying the code as a u32. A failed transaction or simulation reports it as the instruction's index and the number:

text
InstructionError(2, Custom(9011))

and the program's log shows the same number in hex, custom program error: 0x2333 for 9011.

When the transaction went through Mesa's API, the failure comes back in the API's error envelope with the code CHAIN_REFUSED or SIMULATION_FAILED, both with HTTP status 422, and a programError object naming the program that refused:

ts
type ApiErrorBody = {
  error: {
    code: string          // 'CHAIN_REFUSED' or 'SIMULATION_FAILED' for a program error
    message: string
    retryable: boolean
    stage: string
    programError?: { programId: string; name: string; number?: number }
  }
}

programError.name is the error's name as listed here and number its code. programId tells whose error it is, because another program in the same transaction can use the same number for something else. The rest of the envelope is in the HTTP API reference.

The errors

CodeHexNameMessage
90000x2328ProofVerificationFailedproof verification failed
90010x2329InvalidInstructionDatainstruction data is invalid
90020x232aInvalidShieldedPoolProgramshielded-pool program account is invalid
90030x232bMissingMesaAuthoritymesa authority account is missing from transact accounts
90040x232cHashingFailedposeidon hashing failed
90050x232dUnauthorizedsigner is not authorized
90060x232eProtocolPausedprotocol is paused
90070x232fMarketPausedmarket is paused
90080x2330InvalidConfigconfiguration parameter is invalid
90090x2331InvalidAccountaccount address, owner or discriminator is invalid
90100x2332AlreadyInitializedaccount is already initialized
90110x2333InvalidBatchTimeclock is before genesis or batch is past place margin
90120x2334BatchNotClosedbatch has not closed yet
90130x2335OpenWindowClosedopen window has closed
90140x2336OpenWindowStillActiveopen window is still active
90150x2337CommitmentMismatchopened action fields do not match stored commitment
90160x2338InvalidActionStateaction is not in the required state
90170x2339ActionLimitExceededbatch target exceeded max_actions_per_market
90180x233aBatchTargetsFullbatch exceeded maximum distinct targets
90190x233bTargetAlreadyClearedtarget has already been cleared in this batch
90200x233cTargetNotClearedtarget has not been cleared in this batch
90210x233dInvalidActionAccountsremaining action accounts do not match opened count or strict index order
90220x233eInsufficientVaultLiquidityvault lacks reserves for the batch trade
90230x233fMathOverflowarithmetic overflow
90240x2340InvalidRentPayerrent payer account does not match action rent payer
90250x2341InvalidMarketMintmarket mints must be distinct and non-zero
90260x2342InvalidSeedReservesinitial vault reserves must be non-zero
90270x2343InvalidOracleoracle account is invalid, unverified or mismatched
90280x2344StaleOracleoracle price is stale
90290x2345UnsupportedCollateralcollateral mint is not accepted by this pool
90300x2346PositionNotLapsedposition has not lapsed past its deadline yet
90310x2347MarketNotClearedmarket must clear before its spot liquidity vault in the same batch
90320x2348NothingToSweepnothing to sweep

ProofVerificationFailed

Code 9000. Raised by every instruction that verifies a proof: deposit, withdraw, consolidate, place, settle, reclaim, renew, repay, close_position and liquidate. The Groth16 check failed against the public inputs the program computed from its own accounts and the clock, or against the private_tx_hash and the public transfers of the transaction.

The usual cause is a value that changed between proving and execution:

  • place: the batch number. A proof made for batch n does not verify once the clock is in batch n + 1.
  • place of a borrow or perp open, renew, repay, liquidate: the oracle price, the pool's borrow index or the perp market's funding index, and the deadline, which moves at each heartbeat epoch.
  • close_position: the pool's borrow index.
  • settle: amounts that differ from the ones the program computes from the batch record.
  • deposit: a proof made for a wallet other than the signer.

Read the accounts again, build the inputs from what they hold now, prove again and send.

InvalidInstructionData

Code 9001. The data after the tag byte could not be used.

  • Any instruction with arguments: they do not decode, the SPP transact data does not parse, or the timelock length prefix runs past the end of the data.
  • place: kind is not one of 1 to 8 or 0x87.
  • open: the data is not exactly 173 bytes.
  • settle: a perp open sent with data, or any other kind sent without a proof and transact.
  • renew: kind is neither 4 nor 5.
  • repay: mode is neither 0 nor 1. In mode 0, kind is not 4 or repaid is zero. In mode 1, kind is neither 4 nor 5.
  • close_position: mode is neither 0 nor 1, or mode 0 with repaid of zero.
  • liquidate: kind is neither 4 nor 5, amount is zero, or a perp's side is neither 0 nor 1.
  • withdraw_seed_shares: shares is zero.

Compare the bytes with the instruction's field table. Empty data and an unknown tag fail earlier, with Solana's own InvalidInstructionData, which is not this code.

InvalidShieldedPoolProgram

Code 9002. Raised by every note-moving instruction when the SPP accounts appended to it do not hold the Solana Privacy Program where the CPI expects it. Build the trailing accounts with the Privacy Rings client's transact CPI builder, as The SPP accounts describes.

MissingMesaAuthority

Code 9003. Raised by every note-moving instruction when the Mesa authority is not among the SPP accounts, and by settle when it is not among the trailing accounts the event is emitted with. A proofless settle of a perp open still needs the authority as its last account. Add the authority, read-only and not as a signer.

HashingFailed

Code 9004. A Poseidon hash failed: of the Mesa authority's identity, of a mint, of the public inputs of a proof, or in open, of the posted fields. A 32-byte value that has to be a field element and is not below the field's modulus causes it. In open, check recipient_owner_hash and recipient_auth.

Unauthorized

Code 9005. Raised by set_config, create_market, create_pool, create_perp_market and withdraw_seed_shares when the admin signer is not Config.admin, and by emit_event when its signer is not the Mesa authority. These instructions are not for users to call. emit_event can be called only by the program itself.

ProtocolPaused

Code 9006. Raised while Config.paused is set by deposit, and by place of an order, a supply, a borrow, a perp open or a vault deposit. Everything that keeps a position sealed or takes funds out runs while paused: withdraw, consolidate, renew, repay, close_position, liquidate, reclaim, and place of a redeem, a perp close or a vault withdrawal. open, clear, settle and sweep_fees run too, so a batch already placed completes. Read Config.paused and send again once it is clear.

MarketPaused

Code 9007. Raised by place of a perp open while the perp market's paused flag is set. A spot order opened against a paused market is recorded as Invalid by open and is reclaimed. Closing a perp, renewing it and clearing either kind of market run while paused.

InvalidConfig

Code 9008. A parameter is out of range.

  • init_config, set_config: protocol_share_bps above 10,000, a zero max_actions_per_market, batch_len, open_window or drand_period, or place_margin not below batch_len. set_config also refuses paused above 1.
  • create_market: fee_bps of 10,000 or more.
  • create_pool: a collateral_count of zero or above 4, a kink_bps of zero or of 10,000 or more, reserve_factor_bps above 10,000, a zero collateral_factor_bps, liq_threshold_bps below collateral_factor_bps or above 10,000, or liq_bonus_bps of 10,000 or more.
  • create_perp_market: a zero max_leverage, maint_margin_bps or max_oi, or maint_margin_bps, liq_bonus_bps, open_fee_bps or close_fee_bps of 10,000 or more.

InvalidAccount

Code 9009. An account is not the one the instruction requires. Every instruction can raise it.

  • config is not the PDA ["config"], is not owned by the program, or does not hold a Config.
  • A batch, action, market, vault, pool or perp market account is not owned by the program, does not start with its account type's discriminator, or does not sit at the PDA of the number or id stored in it.
  • place: batch or action is not the PDA of the current batch and the batch's current action_count.
  • open, settle, reclaim, close_position: the action belongs to another batch than the one passed.
  • open: target is not the PDA of the target id in the posted code.
  • clear: fewer than three accounts, or a third account that is not a market, pool, perp market or vault.
  • clear, liquidate: vault is not the vault the market or perp market names.
  • settle: the market, pool, perp market or vault is not the one the action names, or mesa_program is not the program.
  • sweep_fees, withdraw_seed_shares, the create instructions: authority is not the Mesa authority, a token account is not the associated token account expected, or a program account is not the System, SPL Token or Associated Token Account program.

Derive every PDA from the seeds in Program: accounts and pass the accounts in the order of the instruction's table. For place, read the Batch account again: another action landing first raises action_count, and the action PDA moves with it. The proof does not depend on the index and is kept.

AlreadyInitialized

Code 9010. Raised by init_config when Config exists, by create_market, create_pool and create_perp_market when the new account already holds lamports, and by place when the action account at the batch's next index already exists.

InvalidBatchTime

Code 9011. The clock does not allow the instruction.

  • place: now is before genesis_ts, or later than the batch's close_ts − place_margin. Build the action for the next batch, prove it again and send it once that batch has started.
  • renew: the deadline the program computes, the end of the next heartbeat epoch, is not later than old_deadline. The position already carries that deadline. Renew again in the next epoch.
  • place of a borrow or perp open, renew, repay: the clock is before genesis_ts, or Config.heartbeat is zero.

BatchNotClosed

Code 9012. Raised by open and clear when now is before the batch's close_ts. Wait for the close. GET /v1/clock returns it.

OpenWindowClosed

Code 9013. Raised by open when now is at or past close_ts + open_window. The action stays Sealed, and its owner takes the funds back with reclaim.

OpenWindowStillActive

Code 9014. Raised by clear when some action of the batch is still Sealed and now is before close_ts + open_window, and by reclaim at any time before close_ts + open_window. For clear, open the remaining actions or wait for the window to end. For reclaim, wait for the window to end.

CommitmentMismatch

Code 9015. Raised by open when the posted fields do not hash to the commitment stored at place. Post the fields exactly as the timelock ciphertext holds them, in the layout of the open field table.

InvalidActionState

Code 9016. The action is not in the state the instruction needs.

InstructionNeedsTypical cause
openSealedThe action was already opened
settleOpened, or Refused for the no-opThe action is still Sealed, or was opened as Invalid
reclaimSealed or Invalid, or Refused for a redeem, vault withdraw or perp closeThe action was opened as valid, and is settled through settle
close_position, mode 1Refused, or Sealed or Invalid after the open windowThe borrow or perp open was accepted

Read the Action account's state and send the instruction that matches it. An Action account that no longer exists was settled, reclaimed or closed, and fails with InvalidAccount.

ActionLimitExceeded

Code 9017. Raised by open when the action's target already has Config.max_actions_per_market opened actions in this batch. The action stays Sealed, and its owner takes the funds back with reclaim after the open window.

BatchTargetsFull

Code 9018. Raised by open and clear when the instruction would add a ninth target record to a batch. A Batch account holds records for 8 targets, counted across markets, pools, perp markets and vaults. An action it stops at open stays Sealed and is reclaimed after the open window.

TargetAlreadyCleared

Code 9019. Raised by clear when the target is already cleared in this batch, and by open for an action whose target was cleared before the action was opened. A second clear needs nothing more: move on to settle. An action that open refuses for this reason stays Sealed and is reclaimed after the open window.

TargetNotCleared

Code 9020. Raised by settle when the batch has no cleared record for the action's target. Send clear for the target first. Both can go in one transaction, clear before settle.

InvalidActionAccounts

Code 9021. Raised by clear when the action accounts after the fixed accounts are not exactly the target's opened actions: their number differs from the opened count in the batch's record, one is not an action PDA of this batch in state Opened for this target and of a kind the target takes, or their index values are not strictly increasing. List the batch's Action accounts, keep the Opened ones whose code names the target, sort them by index, and pass all of them.

InsufficientVaultLiquidity

Code 9022. A vault or pool cannot cover what the instruction would take from it.

  • clear of a spot market: a reserve is zero, or the batch's fills and protocol fees would take a whole reserve.
  • clear of a vault: a deposit into a spot vault with an empty reserve or no shares. A withdrawal naming more shares than the vault has in total. A withdrawal the vault's reserves cannot pay is marked Refused and raises nothing.
  • settle of a vault deposit or withdrawal: the same arithmetic on the recorded reserves fails.
  • sweep_fees of a pool: cash is below reserves. Send it again when cash has returned to the pool.
  • withdraw_seed_shares: shares exceeds the admin's seed shares or the total, or a pool's cash cannot pay the amount.

MathOverflow

Code 9023. A checked calculation left its type's range, divided by zero, or produced an index above u64::MAX. Any instruction that computes amounts, prices, shares, interest or funding can raise it. Check the amounts and prices in the action or arguments against the reserves and decimals of the target.

InvalidRentPayer

Code 9024. Raised by settle, reclaim and close_position in mode 1 when the rent_payer account is not the address stored in the Action account. Read rent_payer from the Action account and pass that address, writable.

InvalidMarketMint

Code 9025. Raised by create_market when the base and quote mints are the same account or either is the all-zero address.

InvalidSeedReserves

Code 9026. Raised by create_market when initial_base or initial_quote is zero, or when the starting price or the starting share count they give is zero. Raised by create_pool when initial_cash is zero and by create_perp_market when initial_quote is zero.

InvalidOracle

Code 9027. Raised by place of a borrow or perp open, clear of a perp market, renew, repay, liquidate and create_perp_market when the oracle account is not usable:

  • it is not owned by the program in Config.pyth_receiver;
  • it is shorter than a PriceUpdateV2 account or does not start with that type's discriminator;
  • its verification level is not full;
  • its feed id is not the one the pool lists for the chosen collateral, or the perp market's base_oracle;
  • its price is zero or negative, or scales to zero.

Pass the Pyth price update account of the feed the target names. For a borrow, the feed is collateral_oracles[collateral_index] of the pool.

StaleOracle

Code 9028. Raised by the same instructions as InvalidOracle when the price's publish_time is more than Config.max_oracle_age seconds before the clock, or more than that ahead of it. Post a fresh price update for the feed in the same transaction, ahead of the Mesa instruction, and prove against that price.

UnsupportedCollateral

Code 9029. Raised by place of a borrow, renew, repay and liquidate when collateral_index is not below the pool's collateral_count. Read the pool's collateral_mints and send the index of the position's collateral mint in that list.

PositionNotLapsed

Code 9030. Raised by liquidate when now is at or before old_deadline. A position can be liquidated only after its deadline. Send again once the clock is past it.

MarketNotCleared

Code 9031. Raised by clear of a vault when the vault's market, or perp market for a perps vault, has a record in this batch that is not cleared yet. Clear the market first, then the vault. Both can go in one transaction in that order.

NothingToSweep

Code 9032. Raised by sweep_fees when the pool's reserves is zero, or the vault's protocol fees are zero in every asset it holds. Nothing is owed yet.

Errors from other programs

An instruction can also fail outside this list.

Solana's built-in errors. The program returns IncorrectProgramId when it is invoked under another program id, and InvalidInstructionData for empty data or an unknown tag. A missing account, a missing signature or an account that is not writable where the instruction's table says it must be fails the account checks with one of Solana's built-in errors, and too few SPP accounts fails with NotEnoughAccountKeys. None of these is a Custom code.

The Solana Privacy Program. Every note-moving instruction ends in a CPI to SPP transact, which verifies its own proof and applies the notes. A failure there, such as a note that was already spent or a tree root the proof no longer matches, is returned as SPP's own error and fails the whole transaction, so nothing the mesa program wrote before the CPI stays. It carries SPP's program id in programError.programId, and its number is read against SPP's error list.

The token and system programs. The transfers in sweep_fees, withdraw_seed_shares and the create instructions, and the account creation in place, are CPIs to the SPL Token, Associated Token Account and System programs. A missing token account, a short balance or a payer without enough lamports is returned as that program's error.