Skip to main content

dlp_api/
error.rs

1use num_enum::{IntoPrimitive, TryFromPrimitive};
2use solana_program::program_error::ProgramError;
3use strum::IntoStaticStr;
4use thiserror::Error;
5
6pub const INVALID_ESCROW_PDA: &str = "invalid escrow pda in CallHandler";
7pub const INVALID_ESCROW_OWNER: &str =
8    "escrow can not be delegated in CallHandler";
9
10#[derive(
11    Debug,
12    Error,
13    Clone,
14    Copy,
15    PartialEq,
16    Eq,
17    IntoPrimitive,
18    TryFromPrimitive,
19    IntoStaticStr,
20)]
21#[repr(u32)]
22pub enum DlpError {
23    #[error("Invalid Authority")]
24    InvalidAuthority = 0,
25
26    #[error("Account cannot be undelegated, is_undelegatable is false")]
27    NotUndelegatable = 1,
28
29    #[error("Unauthorized Operation")]
30    Unauthorized = 2,
31
32    #[error("Invalid Authority for the current target program")]
33    InvalidAuthorityForProgram = 3,
34
35    #[error("Delegated account does not match the expected account")]
36    InvalidDelegatedAccount = 4,
37
38    #[error("Delegated account is not in a valid state")]
39    InvalidDelegatedState = 5,
40
41    #[error("Reimbursement account does not match the expected account")]
42    InvalidReimbursementAccount = 6,
43
44    #[error("Invalid account data after CPI")]
45    InvalidAccountDataAfterCPI = 7,
46
47    #[error("Invalid validator balance after CPI")]
48    InvalidValidatorBalanceAfterCPI = 8,
49
50    #[error("Invalid reimbursement address for delegation rent")]
51    InvalidReimbursementAddressForDelegationRent = 9,
52
53    #[error("Authority is invalid for the delegated account program owner")]
54    InvalidWhitelistProgramConfig = 10,
55
56    #[error("Account already undelegated")]
57    AlreadyUndelegated = 11,
58
59    #[error("Commit is out of order")]
60    NonceOutOfOrder = 12,
61
62    #[error("Computation overflow detected")]
63    Overflow = 13,
64
65    #[error("Too many seeds")]
66    TooManySeeds = 14,
67
68    #[error("Invalid length of diff passed to DiffSet::try_new")]
69    InvalidDiff = 15,
70
71    #[error("Diff is not properly aligned")]
72    InvalidDiffAlignment = 16,
73
74    #[error("MergeDiff precondition did not meet")]
75    MergeDiffError = 17,
76
77    #[error("Commit state PDA invalid seeds")]
78    CommitStateInvalidSeeds = 18,
79
80    #[error("Commit state PDA invalid account owner")]
81    CommitStateInvalidAccountOwner = 19,
82
83    #[error("Commit state PDA is already initialized")]
84    CommitStateAlreadyInitialized = 20,
85
86    #[error("Commit state PDA immutable")]
87    CommitStateImmutable = 21,
88
89    #[error("Commit record PDA invalid seeds")]
90    CommitRecordInvalidSeeds = 22,
91
92    #[error("Commit record PDA invalid account owner")]
93    CommitRecordInvalidAccountOwner = 23,
94
95    #[error("Commit record PDA is already initialized")]
96    CommitRecordAlreadyInitialized = 24,
97
98    #[error("Commit record PDA immutable")]
99    CommitRecordImmutable = 25,
100
101    #[error("Delegation record PDA invalid seeds")]
102    DelegationRecordInvalidSeeds = 26,
103
104    #[error("Delegation record PDA invalid account owner")]
105    DelegationRecordInvalidAccountOwner = 27,
106
107    #[error("Delegation record PDA is already initialized")]
108    DelegationRecordAlreadyInitialized = 28,
109
110    #[error("Delegation record PDA immutable")]
111    DelegationRecordImmutable = 29,
112
113    #[error("Delegation metadata PDA invalid seeds")]
114    DelegationMetadataInvalidSeeds = 30,
115
116    #[error("Delegation metadata PDA invalid account owner")]
117    DelegationMetadataInvalidAccountOwner = 31,
118
119    #[error("Delegation metadata PDA is already initialized")]
120    DelegationMetadataAlreadyInitialized = 32,
121
122    #[error("Delegation metadata PDA immutable")]
123    DelegationMetadataImmutable = 33,
124
125    #[error("Undelegate buffer PDA invalid seeds")]
126    UndelegateBufferInvalidSeeds = 34,
127
128    #[error("Undelegate buffer PDA invalid account owner")]
129    UndelegateBufferInvalidAccountOwner = 35,
130
131    #[error("Undelegate buffer PDA is already initialized")]
132    UndelegateBufferAlreadyInitialized = 36,
133
134    #[error("Undelegate buffer PDA immutable")]
135    UndelegateBufferImmutable = 37,
136
137    #[error("Invalid data length for deserialization")]
138    InvalidDataLength = 38,
139
140    #[error("Invalid discriminator for delegation record")]
141    InvalidDiscriminator = 39,
142
143    #[error("Invalid delegation record deserialization")]
144    InvalidDelegationRecordData = 40,
145
146    #[error("Too many account keys passed to the instruction")]
147    TooManyAccountKeys = 41,
148
149    #[error("Account cannot be delegated to the system program")]
150    DelegationToSystemProgramNotAllowed = 42,
151
152    #[error(
153        "The account lamports is too small to make the account rent-exempt"
154    )]
155    InsufficientRent = 43,
156
157    #[error("An infallible error is encountered possibly due to logic error")]
158    InfallibleError = 100,
159}
160
161impl From<DlpError> for ProgramError {
162    fn from(e: DlpError) -> Self {
163        ProgramError::Custom(e as u32)
164    }
165}
166
167impl From<DlpError> for pinocchio::error::ProgramError {
168    fn from(e: DlpError) -> Self {
169        pinocchio::error::ProgramError::Custom(e as u32)
170    }
171}
172
173impl pinocchio::error::ToStr for DlpError {
174    fn to_str(&self) -> &'static str {
175        self.into()
176    }
177}