stable_swap_client/
error.rs1use num_derive::FromPrimitive;
4use solana_program::{
5 decode_error::DecodeError,
6 msg,
7 program_error::{PrintProgramError, ProgramError},
8};
9use thiserror::Error;
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Error, FromPrimitive)]
13pub enum SwapError {
14 #[error("Swap account already in use")]
16 AlreadyInUse,
17 #[error("Address of the admin fee account is incorrect")]
19 InvalidAdmin,
20 #[error("Input account owner is not the program address")]
22 InvalidOwner,
23 #[error("Output pool account owner cannot be the program address")]
25 InvalidOutputOwner,
26 #[error("Invalid program address generated from nonce and key")]
28 InvalidProgramAddress,
29 #[error("Deserialized account is not an SPL Token mint")]
31 ExpectedMint,
32 #[error("Deserialized account is not an SPL Token account")]
34 ExpectedAccount,
35 #[error("Pool token supply is 0")]
37 EmptyPool,
38 #[error("Input token account empty")]
40 EmptySupply,
41 #[error("Pool token mint has a non-zero supply")]
43 InvalidSupply,
44 #[error("Token account has a delegate")]
46 InvalidDelegate,
47 #[error("InvalidInput")]
49 InvalidInput,
50 #[error("Address of the provided swap token account is incorrect")]
52 IncorrectSwapAccount,
53 #[error("Address of the provided token mint is incorrect")]
55 IncorrectMint,
56 #[error("CalculationFailure")]
58 CalculationFailure,
59 #[error("Invalid instruction")]
61 InvalidInstruction,
62 #[error("Swap input token accounts have the same mint")]
64 RepeatedMint,
65 #[error("Swap instruction exceeds desired slippage limit")]
67 ExceededSlippage,
68 #[error("Token account has a close authority")]
70 InvalidCloseAuthority,
71 #[error("Pool token mint has a freeze authority")]
73 InvalidFreezeAuthority,
74 #[error("Conversion to u64 failed with an overflow or underflow")]
76 ConversionFailure,
77 #[error("Account is not authorized to execute this instruction")]
79 Unauthorized,
80 #[error("Swap pool is paused")]
82 IsPaused,
83 #[error("Ramp is locked in this time period")]
85 RampLocked,
86 #[error("Insufficient ramp time")]
88 InsufficientRampTime,
89 #[error("Active admin transfer in progress")]
91 ActiveTransfer,
92 #[error("No active admin transfer in progress")]
94 NoActiveTransfer,
95 #[error("Admin transfer deadline exceeded")]
97 AdminDeadlineExceeded,
98 #[error("Token mints must have same decimals")]
100 MismatchedDecimals,
101}
102
103impl From<SwapError> for ProgramError {
104 fn from(e: SwapError) -> Self {
105 ProgramError::Custom(e as u32)
106 }
107}
108
109impl<T> DecodeError<T> for SwapError {
110 fn type_of() -> &'static str {
111 "Swap Error"
112 }
113}
114
115impl PrintProgramError for SwapError {
116 fn print<E>(&self)
117 where
118 E: 'static
119 + std::error::Error
120 + DecodeError<E>
121 + PrintProgramError
122 + num_traits::FromPrimitive,
123 {
124 match self {
125 SwapError::AlreadyInUse => msg!("Error: Swap account already in use"),
126 SwapError::InvalidAdmin => {
127 msg!("Error: Address of the admin fee account is incorrect")
128 }
129 SwapError::InvalidOwner => {
130 msg!("Error: The input account owner is not the program address")
131 }
132 SwapError::InvalidOutputOwner => {
133 msg!("Error: Output pool account owner cannot be the program address")
134 }
135 SwapError::InvalidProgramAddress => {
136 msg!("Error: Invalid program address generated from nonce and key")
137 }
138 SwapError::ExpectedMint => {
139 msg!("Error: Deserialized account is not an SPL Token mint")
140 }
141 SwapError::ExpectedAccount => {
142 msg!("Error: Deserialized account is not an SPL Token account")
143 }
144 SwapError::EmptySupply => msg!("Error: Input token account empty"),
145 SwapError::EmptyPool => msg!("Error: Pool token supply is 0"),
146 SwapError::InvalidSupply => msg!("Error: Pool token mint has a non-zero supply"),
147 SwapError::RepeatedMint => msg!("Error: Swap input token accounts have the same mint"),
148 SwapError::InvalidDelegate => msg!("Error: Token account has a delegate"),
149 SwapError::InvalidInput => msg!("Error: InvalidInput"),
150 SwapError::IncorrectSwapAccount => {
151 msg!("Error: Address of the provided swap token account is incorrect")
152 }
153 SwapError::IncorrectMint => {
154 msg!("Error: Address of the provided token mint is incorrect")
155 }
156 SwapError::CalculationFailure => msg!("Error: CalculationFailure"),
157 SwapError::InvalidInstruction => msg!("Error: InvalidInstruction"),
158 SwapError::ExceededSlippage => {
159 msg!("Error: Swap instruction exceeds desired slippage limit")
160 }
161 SwapError::InvalidCloseAuthority => msg!("Error: Token account has a close authority"),
162 SwapError::InvalidFreezeAuthority => {
163 msg!("Error: Pool token mint has a freeze authority")
164 }
165 SwapError::ConversionFailure => msg!("Error: Conversion to or from u64 failed"),
166 SwapError::Unauthorized => {
167 msg!("Error: Account is not authorized to execute this instruction")
168 }
169 SwapError::IsPaused => msg!("Error: Swap pool is paused"),
170 SwapError::RampLocked => msg!("Error: Ramp is locked in this time period"),
171 SwapError::InsufficientRampTime => msg!("Error: Insufficient ramp time"),
172 SwapError::ActiveTransfer => msg!("Error: Active admin transfer in progress"),
173 SwapError::NoActiveTransfer => msg!("Error: No active admin transfer in progress"),
174 SwapError::AdminDeadlineExceeded => msg!("Error: Admin transfer deadline exceeded"),
175 SwapError::MismatchedDecimals => msg!("Error: Token mints must have same decimals"),
176 }
177 }
178}