1use std::fmt;
4
5#[derive(Debug)]
7pub enum StrikeError {
8 Rpc(alloy::transports::TransportError),
10 Contract(String),
12 NonceMismatch { expected: u64, got: u64 },
14 MarketNotActive(u64),
16 InsufficientBalance,
18 Config(String),
20 NoWallet,
22 WebSocket(String),
24 Indexer(String),
26 Other(eyre::Report),
28}
29
30impl fmt::Display for StrikeError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::Rpc(e) => write!(f, "RPC error: {e}"),
34 Self::Contract(reason) => write!(f, "contract reverted: {reason}"),
35 Self::NonceMismatch { expected, got } => {
36 write!(f, "nonce mismatch: expected {expected}, got {got}")
37 }
38 Self::MarketNotActive(id) => write!(f, "market {id} is not active"),
39 Self::InsufficientBalance => write!(f, "insufficient USDT balance"),
40 Self::Config(msg) => write!(f, "config error: {msg}"),
41 Self::NoWallet => write!(f, "no wallet configured — cannot send transactions"),
42 Self::WebSocket(msg) => write!(f, "WebSocket error: {msg}"),
43 Self::Indexer(msg) => write!(f, "indexer error: {msg}"),
44 Self::Other(e) => write!(f, "{e}"),
45 }
46 }
47}
48
49impl std::error::Error for StrikeError {}
50
51impl From<alloy::transports::TransportError> for StrikeError {
52 fn from(e: alloy::transports::TransportError) -> Self {
53 Self::Rpc(e)
54 }
55}
56
57impl From<eyre::Report> for StrikeError {
58 fn from(e: eyre::Report) -> Self {
59 Self::Other(e)
60 }
61}
62
63impl From<reqwest::Error> for StrikeError {
64 fn from(e: reqwest::Error) -> Self {
65 Self::Indexer(e.to_string())
66 }
67}
68
69pub type Result<T> = std::result::Result<T, StrikeError>;