Skip to content
34 changes: 24 additions & 10 deletions contracts/ERROR_CODES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@

This document lists all error codes thrown by the AirFlex Escrow and Marketplace Soroban contracts.

Discriminants are the values of the `ContractError` enum in
`contracts/escrow/src/lib.rs` and `contracts/marketplace/src/lib.rs`. Codes `1`–`14`
are shared by both contracts; escrow appends `15`–`16`. The server-side mirror in
`server/src/services/contractErrors.ts` maps every code back to a typed error.

**Never renumber an existing variant** — new variants are always appended with the
next integer, because deployed callers decode by discriminant.

## Error Codes Reference

| Error Code | Error Name | Description | Contract |
|---|---|---|---|
| `1` / `101` | `Unauthorized` | Caller is not authorized to perform this operation (e.g. missing signature or wrong role). | Escrow & Marketplace |
| `2` / `102` | `AlreadyInitialized` | The contract has already been initialized with an admin and parameters. | Escrow & Marketplace |
| `3` / `103` | `ContractPaused` | Operations are currently paused by the administrator emergency pause. | Escrow & Marketplace |
| `4` / `104` | `InvalidStatus` | The requested state transition is invalid for the current `TradeStatus` or `ListingStatus`. | Escrow & Marketplace |
| `5` / `105` | `TradeNotFound` / `ListingNotFound` | The specified trade ID or listing ID does not exist in persistent storage. | Escrow & Marketplace |
| `6` / `106` | `TokenNotAllowed` | The requested token address is not in the contract's allowed tokens whitelist. | Escrow |
| `7` / `107` | `InsufficientAmount` / `InvalidAmount` | The specified amount is zero, negative, or exceeds available fill balance. | Escrow & Marketplace |
| `8` / `108` | `ExpiryNotReached` | Attempted to trigger auto-cancellation or refund before the expiry timestamp. | Escrow & Marketplace |
| `9` / `109` | `AlreadyExpired` | Attempted to deposit or accept a listing after its expiry timestamp. | Escrow & Marketplace |
| `10` / `110` | `DisputeAlreadyFlagged` | A dispute has already been raised for this trade/listing. | Escrow & Marketplace |
| `1` | `AlreadyInitialized` | `initialize` was called on a contract that already has an admin. | Escrow & Marketplace |
| `2` | `Unauthorized` | The caller is not permitted to perform this action (missing signature, seller acting as buyer, admin acting as buyer, or a caller who is not a party to the trade). | Escrow & Marketplace |
| `3` | `TradeNotFound` | No trade/listing with the given ID exists in storage. | Escrow & Marketplace |
| `4` | `WrongStatus` | The action is invalid for the trade's current status. | Escrow & Marketplace |
| `5` | `TradeExpired` | The trade has passed its expiry timestamp (also returned when a listing has *not* yet expired). | Escrow & Marketplace |
| `6` | `InsufficientFunds` | The requested amount exceeds the trade's remaining capacity or the contract's balance. | Escrow & Marketplace |
| `7` | `InvalidExpiry` | The supplied expiry is not in the future. | Escrow & Marketplace |
| `8` | `AlreadyDisputed` | A dispute is already open on this trade. | Escrow & Marketplace |
| `9` | `ContractPaused` | The contract is paused by the admin circuit breaker. | Escrow & Marketplace |
| `10` | `TimelockNotExpired` | A timelocked action was attempted too early (buyer refund before expiry, or the 72-hour emergency-withdrawal timelock). | Escrow & Marketplace |
| `11` | `UnsupportedToken` | The token is not on the contract's allow-list. | Escrow & Marketplace |
| `12` | `InvalidAmount` | The amount is zero, negative, or not a whole number of stroops. | Escrow & Marketplace |
| `13` | `FillAlreadyProcessed` | The sub-escrow fill has already been released or refunded. | Escrow & Marketplace |
| `14` | `NotAParty` | The caller is neither the seller nor a buyer of the trade. | Escrow & Marketplace |
| `15` | `PauseCooldownNotExpired` | `unpause` was called before the 5-minute pause cooldown elapsed. | Escrow |
| `16` | `DuplicateFill` | The buyer already holds an active (unreleased, unrefunded) sub-escrow on this trade — one active fill per buyer per trade (issue #294). | Escrow |

## Escrow Contract — Canonical Error Code Table

Expand Down
Loading
Loading