1use std::fmt::Display;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum PlasmaError {
5 InvariantViolation(u128, u128),
6 MismatchedFees(u128, u128),
7 UninitializedPool,
8 SwapAmountMismatch,
9 Overflow,
10 Underflow,
11 UnexpectedArgument,
12 MissingExpectedArgument,
13 BelowMinimumLpSharesRequired,
14 BelowMinimumWithdrawaRequired {
15 quote_amount_to_withdraw: u64,
16 base_amount_to_withdraw: u64,
17 },
18 VestingPeriodNotOver,
19 IncorrectProtocolFeeRecipient,
20 TooManyShares,
21 SwapExactOutTooLarge,
22 SwapExactInTooLarge,
23 SwapOutputGreaterThanOrEqualToReserves(u128, u128),
24}
25
26impl Display for PlasmaError {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 match self {
29 PlasmaError::InvariantViolation(k_start, k_end) => {
30 write!(
31 f,
32 "InvariantViolation: k_end {} is less than k_start {} ",
33 k_end, k_start
34 )
35 }
36 PlasmaError::MismatchedFees(expected, actual) => {
37 write!(
38 f,
39 "MismatchedFees: Expected {} but got {}",
40 expected, actual
41 )
42 }
43 PlasmaError::UninitializedPool => write!(f, "Pool is uninitialized"),
44 PlasmaError::SwapAmountMismatch => write!(f, "SwapAmountMismatch"),
45 PlasmaError::Overflow => write!(f, "Calculation overflowed"),
46 PlasmaError::Underflow => write!(f, "Difference underflowed"),
47 PlasmaError::UnexpectedArgument => write!(f, "Unexpected argument"),
48 PlasmaError::MissingExpectedArgument => write!(f, "Missing expected argument"),
49 PlasmaError::BelowMinimumLpSharesRequired => {
50 write!(f, "Must mint at least 1 LP share")
51 }
52 PlasmaError::BelowMinimumWithdrawaRequired {
53 quote_amount_to_withdraw,
54 base_amount_to_withdraw,
55 } => write!(
56 f,
57 "Must withdraw at least 1 base token (actual: {} base) and 1 quote token (actual: {} quote)",
58 base_amount_to_withdraw, quote_amount_to_withdraw
59 ),
60 PlasmaError::VestingPeriodNotOver => write!(f, "Previous vesting period not over"),
61 PlasmaError::IncorrectProtocolFeeRecipient => {
62 write!(
63 f,
64 "Given protocol fee recipient is not one of the protocol fee recipients"
65 )
66 }
67 PlasmaError::TooManyShares => write!(f, "Too many shares supplied"),
68 PlasmaError::SwapExactOutTooLarge => write!(f, "SwapExactOut amount too large"),
69 PlasmaError::SwapExactInTooLarge => write!(f, "SwapExactIn amount too large"),
70 PlasmaError::SwapOutputGreaterThanOrEqualToReserves(input, reserves) => {
71 write!(
72 f,
73 "Swap output {} is greater than or equal to reserves {}",
74 input, reserves
75 )
76 }
77 }
78 }
79}