Skip to content

Commit 715d561

Browse files
Merge PR #1052: docs: markets error catalog (admin; conflicts auto-resolved -X theirs)
2 parents 6fdf0aa + 4523e88 commit 715d561

7 files changed

Lines changed: 81 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ members = [
55
"contracts/predictify-hybrid/fuzz",
66
"contracts/disputes/fuzz",
77
]
8-
exclude = [
9-
"contracts/markets",
10-
]
8+
exclude = []
119

1210
[workspace.dependencies]
1311
soroban-sdk = "25.0.0"

commit.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
git add .
3+
git commit -m "docs: markets error catalog"
4+
git push -u origin task/markets-errcat

commit_out.txt

Whitespace-only changes.

contracts/markets/src/errors.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#![no_std]
2+
use soroban_sdk::contracterror;
3+
4+
/// A stable catalog of errors for the markets smart contract.
5+
#[contracterror]
6+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
7+
#[repr(u32)]
8+
pub enum ContractError {
9+
/// Action is unauthorized; typically thrown when an admin action is invoked by a non-admin.
10+
Unauthorized = 1,
11+
/// Market not found; thrown when querying or interacting with a non-existent market.
12+
MarketNotFound = 2,
13+
/// Market is closed; thrown when trying to interact with a market that has already ended.
14+
MarketClosed = 3,
15+
/// Market already resolved; thrown when attempting to resolve a market more than once.
16+
MarketAlreadyResolved = 4,
17+
/// Market not resolved; thrown when attempting to claim winnings before resolution.
18+
MarketNotResolved = 5,
19+
/// Invalid outcome; thrown when the provided outcome is not supported by the market.
20+
InvalidOutcome = 6,
21+
/// Invalid configuration; thrown when market setup parameters are out of bounds.
22+
InvalidConfig = 7,
23+
/// Overflow; thrown when math operations overflow, preventing unsafe state changes.
24+
Overflow = 8,
25+
/// Stake too small; thrown when a deposit or bet is below the minimum threshold.
26+
StakeTooSmall = 9,
27+
/// Invalid State; thrown when a generic state transition fails.
28+
InvalidState = 10,
29+
}
30+
31+
#[cfg(test)]
32+
mod tests {
33+
use super::*;
34+
35+
#[test]
36+
fn test_error_variants() {
37+
assert_eq!(ContractError::Unauthorized as u32, 1);
38+
assert_eq!(ContractError::MarketNotFound as u32, 2);
39+
assert_eq!(ContractError::MarketClosed as u32, 3);
40+
assert_eq!(ContractError::MarketAlreadyResolved as u32, 4);
41+
assert_eq!(ContractError::MarketNotResolved as u32, 5);
42+
assert_eq!(ContractError::InvalidOutcome as u32, 6);
43+
assert_eq!(ContractError::InvalidConfig as u32, 7);
44+
assert_eq!(ContractError::Overflow as u32, 8);
45+
assert_eq!(ContractError::StakeTooSmall as u32, 9);
46+
assert_eq!(ContractError::InvalidState as u32, 10);
47+
}
48+
}

contracts/markets/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#![no_std]
22
// Markets test utility package placeholder
3+
pub mod errors;
4+

docs/errors/markets.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Markets Error Catalog
2+
3+
This document describes the `ContractError` variants for the markets smart contract.
4+
5+
## Error Codes
6+
7+
| Code | Name | Description |
8+
| ---- | ---- | ----------- |
9+
| `1` | `Unauthorized` | Action is unauthorized; typically thrown when an admin action is invoked by a non-admin. |
10+
| `2` | `MarketNotFound` | Market not found; thrown when querying or interacting with a non-existent market. |
11+
| `3` | `MarketClosed` | Market is closed; thrown when trying to interact with a market that has already ended. |
12+
| `4` | `MarketAlreadyResolved` | Market already resolved; thrown when attempting to resolve a market more than once. |
13+
| `5` | `MarketNotResolved` | Market not resolved; thrown when attempting to claim winnings before resolution. |
14+
| `6` | `InvalidOutcome` | Invalid outcome; thrown when the provided outcome is not supported by the market. |
15+
| `7` | `InvalidConfig` | Invalid configuration; thrown when market setup parameters are out of bounds. |
16+
| `8` | `Overflow` | Overflow; thrown when math operations overflow, preventing unsafe state changes. |
17+
| `9` | `StakeTooSmall` | Stake too small; thrown when a deposit or bet is below the minimum threshold. |
18+
| `10` | `InvalidState` | Invalid State; thrown when a generic state transition fails. |

0 commit comments

Comments
 (0)