cow_settlement_interface/error.rs
1//! Program-side errors surfaced by the settlement program.
2
3/// Program-side errors surfaced by the settlement program.
4/// The discriminant value is the on-chain `ProgramError::Custom` code.
5#[derive(Clone, Copy, Debug, Eq, PartialEq, num_enum::TryFromPrimitive)]
6#[repr(u32)]
7pub enum SettlementError {
8 /// The `FinalizeSettle` included as input to `BeginSettle` isn't before
9 /// the actual `BeginSettle` index.
10 FinalizeBeforeInitialize = 0,
11 /// Another `BeginSettle`/`FinalizeSettle` of this program appears strictly
12 /// between this pair's bounds, nesting or overlapping two settlements.
13 BeginFinalizePairOverlap = 1,
14 /// The counterpart index points past the end of the transaction's
15 /// instruction list, so no instruction sits there.
16 MissingCounterpartInstruction = 2,
17 /// The instruction at the counterpart index belongs to a different program.
18 CounterpartIsExternal = 3,
19 /// The counterpart instruction's discriminator byte couldn't be recovered
20 /// from its data.
21 InvalidCounterpartDiscriminator = 4,
22 /// The counterpart instruction's own counterpart index couldn't be
23 /// recovered from its data.
24 InvalidCounterpartCounterpart = 5,
25 /// The counterpart's discriminator isn't the expected
26 /// `BeginSettle`/`FinalizeSettle` kind, or its counterpart index doesn't
27 /// point back at this instruction.
28 MismatchedCounterpartDiscriminator = 6,
29 /// An order-creation instruction's intent owner isn't the owner it must
30 /// have: the signer for `CreateOrder`, the settlement state PDA for
31 /// `CreateSelfOrder`.
32 OwnerMismatch = 7,
33 /// An account was provided that cannot be derived from the seeds recognized by the program
34 AccountNotDerivable = 8,
35 /// `BeginSettle`'s order accounts aren't passed strictly increasing by
36 /// address.
37 OrdersNotStrictlyIncreasing = 9,
38 /// A `BeginSettle` sell token account doesn't match the
39 /// `sell_token_account` recorded in the order's intent.
40 SellTokenAccountMismatch = 10,
41 /// A `BeginSettle` sell token account isn't a valid SPL token account
42 /// (wrong data length or not owned by the token program).
43 SellTokenAccountInvalid = 11,
44 /// A `BeginSettle` sell token account's SPL owner isn't the order's intent
45 /// owner.
46 SellTokenOwnerMismatch = 12,
47 /// `BeginSettle`'s order-account count doesn't match the structure its
48 /// instruction data expects: `n` orders each contribute an order PDA and a
49 /// sell token account, plus one destination account per transfer.
50 AccountCountNotMatchingOrderCount = 13,
51 /// `BeginSettle` or `FinalizeSettle` was invoked via CPI rather than as a
52 /// top-level transaction instruction.
53 CalledViaCpi = 14,
54 /// A `BeginSettle` order has been cancelled by its owner and can no longer
55 /// be settled.
56 OrderCancelled = 15,
57 /// A `BeginSettle` order's `valid_to` lies in the past: the order has
58 /// expired and can no longer be settled.
59 OrderExpired = 16,
60 /// The transfer counts in `BeginSettle` don't sum to the number of transfer
61 /// amounts, so destinations and amounts can't be paired up exactly.
62 TransferCountMismatch = 17,
63 /// `BeginSettle`'s state account isn't the canonical settlement state PDA,
64 /// which must sign the pulls as the user's token delegate.
65 StateAccountMismatch = 18,
66 /// `FinalizeSettle`'s push-account count doesn't match its instruction
67 /// data: each push contributes a source buffer and a destination account,
68 /// so the count must be twice the number of push amounts.
69 AccountCountNotMatchingPushCount = 19,
70 /// `BeginSettle`: the number of pushes carried by the paired `FinalizeSettle`
71 /// doesn't equal the number of settled orders. Each order must be paid by
72 /// exactly one push.
73 SettledOrderPushCountMismatch = 20,
74 /// `BeginSettle`: a paired `FinalizeSettle` push doesn't send its proceeds
75 /// to the order's buy token account; its destination differs from the
76 /// `buy_token_account` in the order's intent.
77 PushDestinationMismatch = 21,
78 /// `BeginSettle`: a paired `FinalizeSettle` push doesn't draw funds from the
79 /// canonical buffer for the order's `buy_mint`.
80 PushSourceNotBuffer = 22,
81 /// `BeginSettle`: the OrderIntent `sell_token_account` holds a different
82 /// mint than the declared `sell_mint`.
83 SellMintMismatch = 23,
84 /// `BeginSettle`: a settled order's executed price (`amount_out/amount_in`)
85 /// is worse than the order's limit price (`buy_amount/sell_amount`).
86 LimitPriceViolated = 24,
87 /// `BeginSettle`: an order's pull amounts sum to more than `u64::MAX`.
88 PullAmountOverflow = 25,
89 /// `BeginSettle`: filling this order would consume more tokens than the
90 /// maximum the user is willing to trade on this intent.
91 /// Sell: `amount_in > sell_amount`; buy: `amount_out > buy_amount`.
92 FillExceedsOrderAmount = 26,
93 /// `BeginSettle`: a non-`partially_fillable` order isn't filled exactly to
94 /// its amount (either under- or over-filled).
95 /// Sell: `amount_in != sell_amount`; buy: total `amount_out != buy_amount`.
96 OrderNotExactlyFilled = 27,
97 /// `BeginSettle`: the order's cumulative `amount_withdrawn` would exceed
98 /// `u64::MAX` once this settlement's pulls are added.
99 AmountWithdrawnOverflow = 28,
100 /// `BeginSettle`: the order's cumulative `amount_received` would exceed
101 /// `u64::MAX` once this settlement's push is added.
102 AmountReceivedOverflow = 29,
103 /// `ReclaimOrder` was called on an order that has is not yet eligible for reclaim.
104 OrderNotReclaimable = 30,
105 /// `ReclaimOrder`'s `reclaim_recipient` account doesn't match the
106 /// `created_by` address recorded in the order.
107 ReclaimRecipientMismatch = 31,
108 /// `ReclaimBuffer`'s `reclaim_authority` account isn't a signer, or doesn't
109 /// match the `reclaim_authority` address recorded in the settlement state
110 /// PDA.
111 ReclaimAuthorityMismatch = 32,
112 /// A `ReclaimBuffer` `buffer_pda` doesn't sit at the canonical buffer PDA
113 /// derived from its paired `mint`.
114 ReclaimBufferNotCanonical = 33,
115 /// `TransferAuthority`'s signer is neither the manager nor the current
116 /// holder of the role being transferred, so it may not transfer it.
117 UnauthorizedAuthorityTransfer = 34,
118 /// `AddSolver`/`RemoveSolver`'s manager account isn't a signer, or doesn't
119 /// match the `manager` recorded in the settlement state PDA, so it may not
120 /// change the solver list.
121 UnauthorizedSolverManagement = 35,
122 /// `AddSolver`'s solver is already in the state PDA's solver list.
123 SolverAlreadyExists = 36,
124 /// `BeginSettle`'s solver account isn't a signer or isn't in the state PDA's
125 /// solver list, so it may not settle.
126 UnauthorizedSolver = 37,
127 /// `RemoveSolver`'s solver isn't in the state PDA's solver list.
128 SolverNotFound = 38,
129 /// A created order's intent isn't set with the `created_on_chain` flag
130 /// corresponding to the behavior of the invoked order creation instruction.
131 OrderCreatedOnChainMismatch = 39,
132 /// `CreateBuffer` asked the token program how long a token account for a
133 /// mint has to be and couldn't read the answer, so it can't size the
134 /// buffer.
135 BufferSizeUnavailable = 40,
136 /// The token program for a given token or mint is not supported.
137 InvalidTokenProgram = 41,
138 /// `CreateSelfOrder`'s self-order-authority account isn't a signer, or
139 /// doesn't match the `self_order_authority` recorded in the settlement state
140 /// PDA, so it may not create self orders.
141 UnauthorizedSelfOrder = 42,
142 /// `BeginSettle`: a paired `FinalizeSettle` push paying an order that buys
143 /// native SOL doesn't draw from the settlement state PDA.
144 PushSourceNotStatePda = 43,
145}
146
147impl From<SettlementError> for u32 {
148 fn from(e: SettlementError) -> Self {
149 e as u32
150 }
151}
152
153impl From<SettlementError> for solana_program_error::ProgramError {
154 fn from(e: SettlementError) -> Self {
155 Self::Custom(e.into())
156 }
157}
158
159impl From<SettlementError> for solana_instruction_error::InstructionError {
160 fn from(e: SettlementError) -> Self {
161 Self::Custom(e.into())
162 }
163}