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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
use num_derive::FromPrimitive;
use solana_program::{
decode_error::DecodeError,
msg,
program_error::{PrintProgramError, ProgramError},
};
use thiserror::Error;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Error, FromPrimitive)]
pub enum SwapError {
#[error("Swap account already in use")]
AlreadyInUse,
#[error("Address of the admin fee account is incorrect")]
InvalidAdmin,
#[error("Input account owner is not the program address")]
InvalidOwner,
#[error("Output pool account owner cannot be the program address")]
InvalidOutputOwner,
#[error("Invalid program address generated from nonce and key")]
InvalidProgramAddress,
#[error("Deserialized account is not an SPL Token mint")]
ExpectedMint,
#[error("Deserialized account is not an SPL Token account")]
ExpectedAccount,
#[error("Pool token supply is 0")]
EmptyPool,
#[error("Input token account empty")]
EmptySupply,
#[error("Pool token mint has a non-zero supply")]
InvalidSupply,
#[error("Token account has a delegate")]
InvalidDelegate,
#[error("InvalidInput")]
InvalidInput,
#[error("Address of the provided swap token account is incorrect")]
IncorrectSwapAccount,
#[error("Address of the provided token mint is incorrect")]
IncorrectMint,
#[error("CalculationFailure")]
CalculationFailure,
#[error("Invalid instruction")]
InvalidInstruction,
#[error("Swap input token accounts have the same mint")]
RepeatedMint,
#[error("Swap instruction exceeds desired slippage limit")]
ExceededSlippage,
#[error("Token account has a close authority")]
InvalidCloseAuthority,
#[error("Pool token mint has a freeze authority")]
InvalidFreezeAuthority,
#[error("Conversion to u64 failed with an overflow or underflow")]
ConversionFailure,
#[error("Account is not authorized to execute this instruction")]
Unauthorized,
#[error("Swap pool is paused")]
IsPaused,
#[error("Ramp is locked in this time period")]
RampLocked,
#[error("Insufficient ramp time")]
InsufficientRampTime,
#[error("Active admin transfer in progress")]
ActiveTransfer,
#[error("No active admin transfer in progress")]
NoActiveTransfer,
#[error("Admin transfer deadline exceeded")]
AdminDeadlineExceeded,
#[error("Token mints must have same decimals")]
MismatchedDecimals,
}
impl From<SwapError> for ProgramError {
fn from(e: SwapError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for SwapError {
fn type_of() -> &'static str {
"Swap Error"
}
}
impl PrintProgramError for SwapError {
fn print<E>(&self)
where
E: 'static
+ std::error::Error
+ DecodeError<E>
+ PrintProgramError
+ num_traits::FromPrimitive,
{
match self {
SwapError::AlreadyInUse => msg!("Error: Swap account already in use"),
SwapError::InvalidAdmin => {
msg!("Error: Address of the admin fee account is incorrect")
}
SwapError::InvalidOwner => {
msg!("Error: The input account owner is not the program address")
}
SwapError::InvalidOutputOwner => {
msg!("Error: Output pool account owner cannot be the program address")
}
SwapError::InvalidProgramAddress => {
msg!("Error: Invalid program address generated from nonce and key")
}
SwapError::ExpectedMint => {
msg!("Error: Deserialized account is not an SPL Token mint")
}
SwapError::ExpectedAccount => {
msg!("Error: Deserialized account is not an SPL Token account")
}
SwapError::EmptySupply => msg!("Error: Input token account empty"),
SwapError::EmptyPool => msg!("Error: Pool token supply is 0"),
SwapError::InvalidSupply => msg!("Error: Pool token mint has a non-zero supply"),
SwapError::RepeatedMint => msg!("Error: Swap input token accounts have the same mint"),
SwapError::InvalidDelegate => msg!("Error: Token account has a delegate"),
SwapError::InvalidInput => msg!("Error: InvalidInput"),
SwapError::IncorrectSwapAccount => {
msg!("Error: Address of the provided swap token account is incorrect")
}
SwapError::IncorrectMint => {
msg!("Error: Address of the provided token mint is incorrect")
}
SwapError::CalculationFailure => msg!("Error: CalculationFailure"),
SwapError::InvalidInstruction => msg!("Error: InvalidInstruction"),
SwapError::ExceededSlippage => {
msg!("Error: Swap instruction exceeds desired slippage limit")
}
SwapError::InvalidCloseAuthority => msg!("Error: Token account has a close authority"),
SwapError::InvalidFreezeAuthority => {
msg!("Error: Pool token mint has a freeze authority")
}
SwapError::ConversionFailure => msg!("Error: Conversion to or from u64 failed"),
SwapError::Unauthorized => {
msg!("Error: Account is not authorized to execute this instruction")
}
SwapError::IsPaused => msg!("Error: Swap pool is paused"),
SwapError::RampLocked => msg!("Error: Ramp is locked in this time period"),
SwapError::InsufficientRampTime => msg!("Error: Insufficient ramp time"),
SwapError::ActiveTransfer => msg!("Error: Active admin transfer in progress"),
SwapError::NoActiveTransfer => msg!("Error: No active admin transfer in progress"),
SwapError::AdminDeadlineExceeded => msg!("Error: Admin transfer deadline exceeded"),
SwapError::MismatchedDecimals => msg!("Error: Token mints must have same decimals"),
}
}
}