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
use solana_program::program_error::ProgramError;
use thiserror::Error;

#[derive(Error, Debug)]
#[repr(u32)]
pub enum Error {
    #[error("overflow occured")]
    Overflow,
    #[error("drop price can't be zero")]
    DropPriceZero,
    #[error("drop start and end dates overlap")]
    DropInvalidDate,
    #[error("drop already in progress")]
    DropAlreadyExists,
    #[error("no drop in progress")]
    NoDrop,
    #[error("drop timeframe has expired")]
    DropTimeframeExpired,
    #[error("actual price is greater than expected")]
    ExpectedPriceMismatch,
    #[error("post repost window expired")]
    RepostWindowExpired,
    #[error("can't redeem yet")]
    CantRedeemNow,
}

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

impl<T> From<Error> for Result<T, ProgramError> {
    fn from(e: Error) -> Self {
        Err(ProgramError::Custom(e as u32))
    }
}