solana_token_toolkit/error.rs
1//! Error types returned by the `solana-token-toolkit` public API.
2
3use solana_pubkey::Pubkey;
4
5/// All errors returned by `solana-token-toolkit` public API.
6#[derive(thiserror::Error, Debug)]
7#[non_exhaustive]
8pub enum TokenError {
9 /// An RPC call failed.
10 #[cfg(feature = "rpc")]
11 #[error("RPC call failed: {0}")]
12 Rpc(#[from] solana_client::client_error::ClientError),
13
14 /// A requested mint account does not exist on chain.
15 #[error("mint account not found: {0}")]
16 MintNotFound(Pubkey),
17
18 /// Failed to decode a mint account.
19 #[error("mint account decode failed: {mint}: {reason}")]
20 MintDecodeFailed {
21 /// The mint pubkey whose account data could not be decoded.
22 mint: Pubkey,
23 /// Underlying decode error message.
24 reason: String,
25 },
26
27 /// Failed to decode a token account (e.g. while reading wSOL balance).
28 #[error("token account decode failed: {token_account}: {reason}")]
29 TokenAccountDecodeFailed {
30 /// The token account pubkey whose data could not be decoded.
31 token_account: Pubkey,
32 /// Underlying decode error message.
33 reason: String,
34 },
35
36 /// `assemble_token_account_state` was called with mismatched slice lengths.
37 #[error("mints/mint_accounts length mismatch: {mints} vs {mint_accounts}")]
38 LengthMismatch {
39 /// Length of the `mints` slice.
40 mints: usize,
41 /// Length of the `mint_accounts` slice.
42 mint_accounts: usize,
43 },
44
45 /// `reject_transfer_hook_mints` found a hook on a mint.
46 #[error("transfer hook detected on mint {mint} (program: {program})")]
47 TransferHookDetected {
48 /// The mint that has the transfer hook.
49 mint: Pubkey,
50 /// The hook program ID configured on the mint.
51 program: Pubkey,
52 },
53
54 /// `MintIntent::WithBalance` was used with a non-SOL mint.
55 #[error("WithBalance intent on non-SOL mint {0} is not supported")]
56 WithBalanceNotSupported(Pubkey),
57
58 /// `MintIntent::WithBalance` for native SOL was paired with
59 /// `WrapSolStrategy::None`.
60 #[error(
61 "WithBalance intent for native SOL requires WrapSolStrategy::Ata or Keypair, not None"
62 )]
63 IncoherentWrapStrategy,
64
65 /// An `spl-token-*` instruction builder returned an error.
66 #[error("instruction build failed: {0}")]
67 InstructionBuild(String),
68
69 /// `MintIntent::RequireTokenBalance` failed because actual balance is
70 /// below required. `actual` is `0` when the ATA does not exist on chain.
71 #[error("token balance insufficient on mint {mint}: required {required}, actual {actual}")]
72 InsufficientBalance {
73 /// The mint whose balance check failed.
74 mint: Pubkey,
75 /// The amount the caller required.
76 required: u64,
77 /// The actual balance found in `state.mints[mint].ata_account` (or 0 if missing).
78 actual: u64,
79 },
80
81 /// `MintIntent::RequireTokenBalance` was used with `native_mint::ID`
82 /// (SOL/wSOL). For SOL balance preparation, use `MintIntent::WithBalance`
83 /// (which transfers SOL into wSOL).
84 #[error("RequireTokenBalance intent on SOL/wSOL mint {0} is not supported (use WithBalance)")]
85 RequireBalanceForSolNotSupported(Pubkey),
86}