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
//! Program-side errors surfaced by the settlement program.
/// Program-side errors surfaced by the settlement program.
/// The discriminant value is the on-chain `ProgramError::Custom` code.
#[derive(Clone, Copy, Debug, Eq, PartialEq, num_enum::TryFromPrimitive)]
#[repr(u32)]
pub enum SettlementError {
/// The `FinalizeSettle` included as input to `BeginSettle` isn't before
/// the actual `BeginSettle` index.
FinalizeBeforeInitialize = 0,
/// Another `BeginSettle`/`FinalizeSettle` of this program appears strictly
/// between this pair's bounds, nesting or overlapping two settlements.
BeginFinalizePairOverlap = 1,
/// The counterpart index points past the end of the transaction's
/// instruction list, so no instruction sits there.
MissingCounterpartInstruction = 2,
/// The instruction at the counterpart index belongs to a different program.
CounterpartIsExternal = 3,
/// The counterpart instruction's discriminator byte couldn't be recovered
/// from its data.
InvalidCounterpartDiscriminator = 4,
/// The counterpart instruction's own counterpart index couldn't be
/// recovered from its data.
InvalidCounterpartCounterpart = 5,
/// The counterpart's discriminator isn't the expected
/// `BeginSettle`/`FinalizeSettle` kind, or its counterpart index doesn't
/// point back at this instruction.
MismatchedCounterpartDiscriminator = 6,
/// An order-creation instruction's intent owner isn't the owner it must
/// have: the signer for `CreateOrder`, the settlement state PDA for
/// `CreateSettlementOwnedOrder`.
OwnerMismatch = 7,
/// An account was provided that cannot be derived from the seeds recognized by the program
AccountNotDerivable = 8,
/// `BeginSettle`'s order accounts aren't passed strictly increasing by
/// address.
OrdersNotStrictlyIncreasing = 9,
/// A `BeginSettle` sell token account doesn't match the
/// `sell_token_account` recorded in the order's intent.
SellTokenAccountMismatch = 10,
/// A `BeginSettle` sell token account isn't a valid SPL token account
/// (wrong data length or not owned by the token program).
SellTokenAccountInvalid = 11,
/// A `BeginSettle` sell token account's SPL owner isn't the order's intent
/// owner.
SellTokenOwnerMismatch = 12,
/// `BeginSettle`'s order-account count doesn't match the structure its
/// instruction data expects: `n` orders each contribute an order PDA, a
/// sell token account, a sell mint, plus one destination account per
/// transfer.
AccountCountNotMatchingOrderCount = 13,
/// `BeginSettle` or `FinalizeSettle` was invoked via CPI rather than as a
/// top-level transaction instruction.
CalledViaCpi = 14,
/// A `BeginSettle` order has been cancelled by its owner and can no longer
/// be settled.
OrderCancelled = 15,
/// A `BeginSettle` order's `valid_to` lies in the past: the order has
/// expired and can no longer be settled.
OrderExpired = 16,
/// The transfer counts in `BeginSettle` don't sum to the number of transfer
/// amounts, so destinations and amounts can't be paired up exactly.
TransferCountMismatch = 17,
/// `BeginSettle`'s state account isn't the canonical settlement state PDA,
/// which must sign the pulls as the user's token delegate.
StateAccountMismatch = 18,
/// `FinalizeSettle`'s push-account count doesn't match its instruction
/// data: each push contributes a source buffer, a destination, and a mint,
/// so the count must be three times the number of push amounts.
AccountCountNotMatchingPushCount = 19,
/// `BeginSettle`: the number of pushes carried by the paired `FinalizeSettle`
/// doesn't equal the number of settled orders. Each order must be paid by
/// exactly one push.
SettledOrderPushCountMismatch = 20,
/// `BeginSettle`: a paired `FinalizeSettle` push doesn't send its proceeds
/// to the order's buy token account; its destination differs from the
/// `buy_token_account` in the order's intent.
PushDestinationMismatch = 21,
/// `BeginSettle`: a paired `FinalizeSettle` push doesn't draw funds from the
/// canonical buffer for the order's `buy_mint`.
PushSourceNotBuffer = 22,
/// `BeginSettle`: the OrderIntent `sell_token_account` holds a different
/// mint than the declared `sell_mint`.
SellMintMismatch = 23,
/// `BeginSettle`: a settled order's executed price (`amount_out/amount_in`)
/// is worse than the order's limit price (`buy_amount/sell_amount`).
LimitPriceViolated = 24,
/// `BeginSettle`: an order's pull amounts sum to more than `u64::MAX`.
PullAmountOverflow = 25,
/// `BeginSettle`: filling this order would consume more tokens than the
/// maximum the user is willing to trade on this intent.
/// Sell: `amount_in > sell_amount`; buy: `amount_out > buy_amount`.
FillExceedsOrderAmount = 26,
/// `BeginSettle`: a non-`partially_fillable` order isn't filled exactly to
/// its amount (either under- or over-filled).
/// Sell: `amount_in != sell_amount`; buy: total `amount_out != buy_amount`.
OrderNotExactlyFilled = 27,
/// `BeginSettle`: the order's cumulative `amount_withdrawn` would exceed
/// `u64::MAX` once this settlement's pulls are added.
AmountWithdrawnOverflow = 28,
/// `BeginSettle`: the order's cumulative `amount_received` would exceed
/// `u64::MAX` once this settlement's push is added.
AmountReceivedOverflow = 29,
/// `ReclaimOrder` was called on an order that has not yet become eligible
/// for reclaim.
OrderNotReclaimable = 30,
/// `ReclaimOrder`'s `reclaim_recipient` account doesn't match the
/// `created_by` address recorded in the order.
ReclaimRecipientMismatch = 31,
/// `ReclaimBuffer`'s `reclaim_authority` account isn't a signer, or doesn't
/// match the `reclaim_authority` address recorded in the settlement state
/// PDA.
ReclaimAuthorityMismatch = 32,
/// A `ReclaimBuffer` `buffer_pda` doesn't sit at the canonical buffer PDA
/// derived from its paired `mint`.
ReclaimBufferNotCanonical = 33,
/// `TransferAuthority`'s signer is neither the manager nor the current
/// holder of the role being transferred, so it may not transfer it.
UnauthorizedAuthorityTransfer = 34,
/// `AddSolver`/`RemoveSolver`'s solver-authority account isn't a signer, or
/// doesn't match the `solver_authority` recorded in the settlement state
/// PDA, so it may not change the solver list.
UnauthorizedSolverManagement = 35,
/// `AddSolver`'s solver is already in the state PDA's solver list.
SolverAlreadyExists = 36,
/// `BeginSettle`'s solver account isn't a signer or isn't in the state PDA's
/// solver list, so it may not settle.
UnauthorizedSolver = 37,
/// `RemoveSolver`'s solver isn't in the state PDA's solver list.
SolverNotFound = 38,
/// `CreateBuffer` asked the token program how long a token account for a
/// mint has to be and couldn't read the answer, so it can't size the
/// buffer.
BufferSizeUnavailable = 39,
/// The token program for a given token or mint is not supported.
InvalidTokenProgram = 40,
/// `CreateSettlementOwnedOrder`'s settlement-owned-order-authority account
/// isn't a signer, or doesn't match the `settlement_owned_order_authority`
/// recorded in the settlement state PDA.
UnauthorizedSettlementOwnedOrder = 41,
/// An intent has a zero sell or buy amount, which is not supported.
ZeroOrderAmount = 42,
/// A mint account supplied to `BeginSettle` or `FinalizeSettle`
/// was not able to be parsed as such.
InvalidMint = 43,
}
impl From<SettlementError> for u32 {
fn from(e: SettlementError) -> Self {
e as u32
}
}
impl From<SettlementError> for solana_program_error::ProgramError {
fn from(e: SettlementError) -> Self {
Self::Custom(e.into())
}
}
impl From<SettlementError> for solana_instruction_error::InstructionError {
fn from(e: SettlementError) -> Self {
Self::Custom(e.into())
}
}