Skip to main content

percli_program/
error.rs

1use anchor_lang::prelude::*;
2
3#[error_code]
4pub enum PercolatorError {
5    #[msg("Insufficient balance for this operation")]
6    InsufficientBalance,
7    #[msg("Account is undercollateralized")]
8    Undercollateralized,
9    #[msg("Unauthorized signer")]
10    Unauthorized,
11    #[msg("Invalid matching engine")]
12    InvalidMatchingEngine,
13    #[msg("PnL not yet warmed up")]
14    PnlNotWarmedUp,
15    #[msg("Arithmetic overflow")]
16    Overflow,
17    #[msg("Account not found in engine")]
18    AccountNotFound,
19    #[msg("Account is not an LP account")]
20    NotAnLPAccount,
21    #[msg("Position size mismatch")]
22    PositionSizeMismatch,
23    #[msg("Account kind mismatch")]
24    AccountKindMismatch,
25    #[msg("Side is blocked (drain-only or reset pending)")]
26    SideBlocked,
27    #[msg("Engine state is corrupt")]
28    CorruptState,
29    #[msg("Invalid oracle price")]
30    InvalidOraclePrice,
31    #[msg("Account index out of range")]
32    AccountIndexOutOfRange,
33    #[msg("Oracle price is stale")]
34    StaleOracle,
35    #[msg("Oracle price is negative or zero")]
36    InvalidOraclePriceValue,
37    #[msg("Deposit amount exceeds u64 token limit")]
38    AmountOverflow,
39    #[msg("Market header is already at the v1 layout")]
40    AlreadyMigrated,
41    #[msg("Market header is not a legacy v0 layout")]
42    NotLegacyLayout,
43    #[msg("No authority transfer is pending")]
44    NoPendingAuthority,
45}
46
47pub fn from_risk_error(e: percli_core::RiskError) -> Error {
48    match e {
49        percli_core::RiskError::InsufficientBalance => {
50            error!(PercolatorError::InsufficientBalance)
51        }
52        percli_core::RiskError::Undercollateralized => {
53            error!(PercolatorError::Undercollateralized)
54        }
55        percli_core::RiskError::Unauthorized => error!(PercolatorError::Unauthorized),
56        percli_core::RiskError::InvalidMatchingEngine => {
57            error!(PercolatorError::InvalidMatchingEngine)
58        }
59        percli_core::RiskError::PnlNotWarmedUp => error!(PercolatorError::PnlNotWarmedUp),
60        percli_core::RiskError::Overflow => error!(PercolatorError::Overflow),
61        percli_core::RiskError::AccountNotFound => error!(PercolatorError::AccountNotFound),
62        percli_core::RiskError::NotAnLPAccount => error!(PercolatorError::NotAnLPAccount),
63        percli_core::RiskError::PositionSizeMismatch => {
64            error!(PercolatorError::PositionSizeMismatch)
65        }
66        percli_core::RiskError::AccountKindMismatch => {
67            error!(PercolatorError::AccountKindMismatch)
68        }
69        percli_core::RiskError::SideBlocked => error!(PercolatorError::SideBlocked),
70        percli_core::RiskError::CorruptState => error!(PercolatorError::CorruptState),
71    }
72}