manifest/program/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use solana_program::program_error::ProgramError;
use thiserror::Error;

#[derive(Debug, Error)]
#[repr(u32)]
pub enum ManifestError {
    #[error("Invalid market parameters error")]
    InvalidMarketParameters = 0,
    #[error("Invalid deposit accounts error")]
    InvalidDepositAccounts = 1,
    #[error("Invalid withdraw accounts error")]
    InvalidWithdrawAccounts = 2,
    #[error("Invalid cancel error")]
    InvalidCancel = 3,
    #[error("Internal free list corruption error")]
    InvalidFreeList = 4,
    #[error("Cannot claim a second seat for the same trader")]
    AlreadyClaimedSeat = 5,
    #[error("Matched on a post only order")]
    PostOnlyCrosses = 6,
    #[error("New order is already expired")]
    AlreadyExpired = 7,
    #[error("Less than minimum out amount")]
    InsufficientOut = 8,
    #[error("Invalid place order from wallet params")]
    InvalidPlaceOrderFromWalletParams = 9,
    #[error("Index hint did not match actual index")]
    WrongIndexHintParams = 10,
    #[error("Price is not positive")]
    PriceNotPositive = 11,
    #[error("Order settlement would overflow")]
    OrderWouldOverflow = 12,
    #[error("Order is too small to settle any value")]
    OrderTooSmall = 13,
    #[error("Overflow in token addition")]
    Overflow = 14,
    #[error("Missing Global account")]
    MissingGlobal = 15,
    #[error("Insufficient funds on global account to rest an order")]
    GlobalInsufficient = 16,
    #[error("Account key did not match expected")]
    IncorrectAccount = 17,
    #[error("Mint not allowed for market")]
    InvalidMint = 18,
    #[error("Cannot claim a new global seat, use evict")]
    TooManyGlobalSeats = 19,
    #[error("Can only evict the lowest depositor")]
    InvalidEvict = 20,
    #[error("Tried to clean order that was not eligible to be cleaned")]
    InvalidClean = 21,
}

impl From<ManifestError> for ProgramError {
    fn from(e: ManifestError) -> Self {
        ProgramError::Custom(e as u32)
    }
}

#[cfg(feature = "certora")]
#[macro_export]
macro_rules! require {
    ($test:expr, $err:expr, $($arg:tt)*) => {{
        ::cvt::cvt_assume!($test);
        Ok::<(), crate::ProgramError>(())
    }};
}

#[cfg(not(feature = "certora"))]
#[macro_export]
macro_rules! require {
  ($test:expr, $err:expr, $($arg:tt)*) => {
    if $test {
        Ok(())
    } else {
        #[cfg(target_os = "solana")]
        solana_program::msg!("[{}:{}] {}", std::file!(), std::line!(), std::format_args!($($arg)*));
        #[cfg(not(target_os = "solana"))]
        std::println!("[{}:{}] {}", std::file!(), std::line!(), std::format_args!($($arg)*));
        Err(($err))
    }
  };
}