lightcone 0.7.1

Rust SDK for the Lightcone Protocol — unified native + WASM client
Documentation
//! Error types for the Lightcone on-chain program module.

use thiserror::Error;

#[cfg(feature = "native")]
use solana_client::client_error::ClientError;

/// SDK-specific errors
#[derive(Debug, Error)]
pub enum SdkError {
    /// RPC client error
    #[cfg(feature = "native")]
    #[error("RPC error: {0}")]
    Rpc(#[from] ClientError),

    /// Invalid account discriminator
    #[error("Invalid account discriminator: expected {expected}, got {actual}")]
    InvalidDiscriminator { expected: String, actual: String },

    /// Account not found
    #[error("Account not found: {0}")]
    AccountNotFound(String),

    /// Invalid data length
    #[error("Invalid data length: expected {expected}, got {actual}")]
    InvalidDataLength { expected: usize, actual: usize },

    /// Invalid outcome count
    #[error("Invalid outcome count: {count} (must be {min}-{max})", min = crate::program::constants::MIN_OUTCOMES, max = crate::program::constants::MAX_OUTCOMES)]
    InvalidOutcomeCount { count: u8 },

    /// Invalid outcome index
    #[error("Invalid outcome index: {index} (max {max})")]
    InvalidOutcomeIndex { index: u8, max: u8 },

    /// Invalid payout numerators
    #[error("Invalid payout numerators")]
    InvalidPayoutNumerators,

    /// Payout vector exceeds the on-chain u32 representation
    #[error("Payout vector exceeds u32 bounds")]
    PayoutVectorExceedsU32,

    /// Invalid scalar range
    #[error("Invalid scalar range")]
    InvalidScalarRange,

    /// Scalar outcomes must be distinct
    #[error("Scalar outcome indexes must be distinct")]
    DuplicateScalarOutcomes,

    /// Too many makers
    #[error("Too many makers: {count} (max {max})", max = crate::program::constants::MAX_MAKERS)]
    TooManyMakers { count: usize },

    #[error("Signature verification failed")]
    SignatureVerificationFailed,

    #[error("Invalid signature")]
    InvalidSignature,

    /// Serialization error
    #[error("Serialization error: {0}")]
    Serialization(String),

    /// Invalid side value
    #[error("Invalid side value: {0} (must be 0 or 1)")]
    InvalidSide(u8),

    /// Invalid market status
    #[error("Invalid market status: {0}")]
    InvalidMarketStatus(u8),

    /// Missing required field
    #[error("Missing required field: {0}")]
    MissingField(String),

    /// Arithmetic overflow
    #[error("Arithmetic overflow")]
    Overflow,

    /// Invalid mint order
    #[error("Invalid mint order")]
    InvalidMintOrder,

    /// Orderbook already exists
    #[error("Orderbook already exists")]
    OrderbookExists,

    /// Invalid market
    #[error("Invalid market")]
    InvalidMarket,

    /// Market already settled
    #[error("Market already settled")]
    MarketSettled,

    /// Invalid program ID
    #[error("Invalid program ID")]
    InvalidProgramId,

    /// Invalid orderbook
    #[error("Invalid orderbook")]
    InvalidOrderbook,

    /// Full fill required
    #[error("Full fill required")]
    FullFillRequired,

    /// Division by zero
    #[error("Division by zero")]
    DivisionByZero,

    /// Deposit token not active
    #[error("Deposit token not active")]
    DepositTokenNotActive,

    /// User's global deposit balance is insufficient
    #[error("Insufficient global deposit balance")]
    InsufficientGlobalDeposit,

    /// Deposit mints must be ordered by ascending GlobalDepositToken index
    #[error("Invalid deposit mint order")]
    InvalidDepositMintOrder,

    /// Amount must be greater than zero
    #[error("Amount must be greater than zero")]
    ZeroAmount,

    /// Invalid associated token account
    #[error("Invalid associated token account")]
    InvalidAta,

    /// Order status is not fully filled
    #[error("Order status is not fully filled")]
    OrderNotFullyFilled,

    /// Redeem amount is too small to produce a payout
    #[error("Payout too small")]
    PayoutTooSmall,

    /// Token account is not empty
    #[error("Token account is not empty")]
    TokenAccountNotEmpty,

    /// Lookup table must be closed first
    #[error("Lookup table is not closed")]
    LookupTableNotClosed,

    /// Invalid manager
    #[error("Invalid manager")]
    InvalidManager,

    /// Fee bps outside the protocol range.
    #[error("Invalid fee range: maker and taker bps must each be between -500 and 500")]
    InvalidFeeRange,

    /// Fee pair would make protocol fees negative.
    #[error("Invalid fee sum: maker + taker bps must be non-negative")]
    InvalidFeeSum,

    /// Invalid fee receiver.
    #[error("Invalid fee receiver")]
    InvalidFeeReceiver,

    /// Invalid pubkey
    #[error("Invalid pubkey: {0}")]
    InvalidPubkey(String),

    /// Scaling error (price/size conversion)
    #[error("Scaling error: {0}")]
    Scaling(#[from] crate::shared::scaling::ScalingError),

    /// Order has not been signed
    #[error("Order must be signed before converting to submit request")]
    UnsignedOrder,
}

/// Result type alias for SDK operations
pub type SdkResult<T> = Result<T, SdkError>;