Skip to main content

lightcone_sdk/program/
error.rs

1//! Error types for the Lightcone on-chain program module.
2
3use thiserror::Error;
4
5/// SDK-specific errors
6#[derive(Debug, Error)]
7pub enum SdkError {
8    /// RPC client error
9    #[error("RPC error: {0}")]
10    Rpc(#[from] solana_client::client_error::ClientError),
11
12    /// Invalid account discriminator
13    #[error("Invalid account discriminator: expected {expected}, got {actual}")]
14    InvalidDiscriminator {
15        expected: String,
16        actual: String,
17    },
18
19    /// Account not found
20    #[error("Account not found: {0}")]
21    AccountNotFound(String),
22
23    /// Invalid data length
24    #[error("Invalid data length: expected {expected}, got {actual}")]
25    InvalidDataLength {
26        expected: usize,
27        actual: usize,
28    },
29
30    /// Invalid order hash
31    #[error("Invalid order hash")]
32    InvalidOrderHash,
33
34    /// Invalid signature
35    #[error("Invalid signature")]
36    InvalidSignature,
37
38    /// Order expired
39    #[error("Order expired")]
40    OrderExpired,
41
42    /// Invalid outcome count
43    #[error("Invalid outcome count: {count} (must be {min}-{max})", min = crate::program::constants::MIN_OUTCOMES, max = crate::program::constants::MAX_OUTCOMES)]
44    InvalidOutcomeCount { count: u8 },
45
46    /// Invalid outcome index
47    #[error("Invalid outcome index: {index} (max {max})")]
48    InvalidOutcomeIndex {
49        index: u8,
50        max: u8,
51    },
52
53    /// Too many makers
54    #[error("Too many makers: {count} (max {max})", max = crate::program::constants::MAX_MAKERS)]
55    TooManyMakers { count: usize },
56
57    /// Serialization error
58    #[error("Serialization error: {0}")]
59    Serialization(String),
60
61    /// Invalid side value
62    #[error("Invalid side value: {0} (must be 0 or 1)")]
63    InvalidSide(u8),
64
65    /// Invalid market status
66    #[error("Invalid market status: {0}")]
67    InvalidMarketStatus(u8),
68
69    /// Signature verification failed
70    #[error("Signature verification failed")]
71    SignatureVerificationFailed,
72
73    /// Missing required field
74    #[error("Missing required field: {0}")]
75    MissingField(String),
76
77    /// Orders do not cross
78    #[error("Orders do not cross (prices incompatible)")]
79    OrdersDoNotCross,
80
81    /// Fill amount exceeds remaining
82    #[error("Fill amount {fill} exceeds remaining {remaining}")]
83    FillAmountExceedsRemaining {
84        fill: u64,
85        remaining: u64,
86    },
87
88    /// Arithmetic overflow
89    #[error("Arithmetic overflow")]
90    Overflow,
91
92    /// Invalid pubkey
93    #[error("Invalid pubkey: {0}")]
94    InvalidPubkey(String),
95}
96
97/// Result type alias for SDK operations
98pub type SdkResult<T> = Result<T, SdkError>;