Skip to main content

Module token_admin

Module token_admin 

Source
Expand description

Administrative SPL Token / Token-2022 builders: mint and multisig initialization, immutable-owner accounts, the data-size and UI-amount queries, and lamport withdrawal from token accounts.

Every builder here is re-exported from crate::token and follows the same contract as the transfer family: one TokenInstruction::emit encodes the bytes and metas, invoke() sends them to SPL Token, invoke_on to an explicit TokenProgram, invoke_for_owner to the program that owns the first account, and a crate::token::TokenBatch can collect them.

Structs§

AmountToUiAmount
AmountToUiAmount (23): format a raw amount with the mint’s decimals (and, on Token-2022, its interest or scaled-UI configuration) as a UTF-8 string in the return data. Read it with return_data_string.
GetAccountDataSize
GetAccountDataSize (21): ask the token program how many bytes a token account for mint needs, as a u64 in the return data. On Token-2022 the mint’s required account extensions are included automatically and extension_types adds more (for example crate::token_2022_ext::EXT_IMMUTABLE_OWNER); SPL Token ignores the list and answers 165.
InitializeImmutableOwner
InitializeImmutableOwner (22): mark a not-yet-initialized token account so that its owner can never be changed. Runs before InitializeAccount3. On Token-2022 it needs the 4-byte extension header in the allocation (GetAccountDataSize with type 7 reports the size); SPL Token accepts it as a no-op on a 165-byte account.
InitializeMint
InitializeMint (0): the Rent-sysvar form of InitializeMint2. The mint must already be allocated (82 bytes on SPL Token) and owned by the token program. Prefer InitializeMint2 in new code; this form exists for callers whose instruction already carries the Rent sysvar.
InitializeMultisig
InitializeMultisig (2): turn a 355-byte, token-program-owned account into an m-of-n multisig over signers. The member accounts are listed read-only and do not sign. Requires the Rent sysvar account; InitializeMultisig2 does not.
InitializeMultisig2
InitializeMultisig2 (19): InitializeMultisig without the Rent sysvar account.
UiAmountToAmount
UiAmountToAmount (24): parse a decimal string against the mint and return the raw amount as a u64 in the return data. Read it with return_data_u64. Strings longer than MAX_UI_AMOUNT_LEN bytes are refused before the CPI.
UnwrapLamports
UnwrapLamports (45): move lamports out of a native (wrapped SOL) token account to destination without closing it, the whole balance with amount: None or a part of it. The instruction exists in the p-token build of SPL Token; a program that does not know discriminator 45 refuses it with InvalidInstructionData.
WithdrawExcessLamports
WithdrawExcessLamports (38): move every lamport above the rent-exempt minimum out of a token account, mint, or multisig into destination. authority is the account’s owner (or the mint’s close authority, or the multisig itself), directly signed or through multisig signers.

Constants§

MAX_EXTENSION_TYPES
The most extension types one GetAccountDataSize or Reallocate carries. Token-2022 defines 29; the buffer leaves room for growth.
MAX_UI_AMOUNT_LEN
The longest UI-amount string UiAmountToAmount carries: the instruction is one byte of discriminator plus at most 254 bytes of UTF-8.

Functions§

return_data_string
The string a token program left in the return data, copied into out; the result is its length. Refuses return data from any other program and anything longer than the buffer.
return_data_u64
The u64 a token program left in the return data, refusing return data set by any other program or shorter than eight bytes.