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