Skip to content

Commit 4523e88

Browse files
committed
docs: markets error catalog
1 parent 489fb5a commit 4523e88

8 files changed

Lines changed: 149 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 76 additions & 2 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
@@ -4,9 +4,7 @@ members = [
44
"contracts/*",
55
"contracts/predictify-hybrid/fuzz",
66
]
7-
exclude = [
8-
"contracts/markets",
9-
]
7+
exclude = []
108

119
[workspace.dependencies]
1210
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+

contracts/predictify-hybrid/src/disputes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,7 +2904,6 @@ impl DisputeUtils {
29042904
env.storage().persistent().extend_ttl(&key, 535680, 535680);
29052905
Ok(result)
29062906
}
2907-
}
29082907

29092908
/// Persist a [`DisputeVoting`] record under the `dispute_v` + `dispute_id` key.
29102909
pub fn store_dispute_voting(
@@ -3050,7 +3049,6 @@ impl DisputeUtils {
30503049
fees_distributed: false,
30513050
}))
30523051
}
3053-
}
30543052

30553053
/// Persist a [`DisputeEscalation`] under the `dispute_e` + `dispute_id` key.
30563054
pub fn store_dispute_escalation(

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)