SV3 logo

Errors

Decode SV3 custom errors from simulation failures and reverted receipts.

SDK failures are Sv3Error subclasses with a stable code. On-chain reverts are decoded against protocolErrorsAbi. You should not parse provider strings.

parseProtocolError walks nested viem cause / data, so a simulateContract failure still yields SlippageExceeded instead of a hex blob.

Import

import {
  parseProtocolError,
  toProtocolRevertError,
  ProtocolRevertError,
} from "@repo/contract-client";

On a client: sv3.errors.parse and sv3.errors.toError.

Usage

try {
  await sv3.transactions.executePrepared(prepared);
} catch (error) {
  const revert = toProtocolRevertError(error);
  revert.errorName;
  // 'SlippageExceeded' | 'BelowMinimum' | 'ProtocolPaused' | …
  revert.errorArgs;
}

parseProtocolError accepts revert hex, a nested viem error, or any object with data / cause. It classifies:

kindMeaning
protocolNamed custom error from the ABI
empty0x revert data
panicSolidity panic (0x4e487b71…)
unknownAnything else

Empty data and panics are fallbacks, not the UX for ordinary invalid inputs.

Simulation failures are SimulationFailedError with a ProtocolRevertError as cause. Mined reverts are TransactionRevertedError with the same decode after wait.

Common protocol names

BelowMinimum, SlippageExceeded, MaxInputExceeded, ProtocolPaused, MarketPaused, ZeroAmount, BorrowCapacityExceeded, InsufficientFreeCollateral, InsufficientBacking, CanaryCapExceeded, Expired.

Local math throws the same names (BelowMinimum, BorrowCapacityExceeded, …) so a slider failure matches simulate.

Client errors

ErrorWhen
UnsupportedChainErrorchainId not 8453 / 31337
UnsupportedCurveRevisionErrorSnapshot math is not in SUPPORTED_MATH
WalletClientRequiredErrorWrite without a wallet
AccountMismatchErrorPrepared account ≠ wallet
StaleStateErrorMarket nonce moved before send
InvalidDeadlineErrorDeadline config out of range
InvalidAmountErrorSigned or zero inputs in unit math
SimulationFailedErrorSimulate reverted
TransactionRejectedErrorWallet rejected
TransactionRevertedErrorMined revert

Tips

  • Compare errorName, not the message string. Messages are for logs.
  • encodeProtocolError({ errorName, args }) is exported for tests.