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§
- Amount
ToUi Amount 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 withreturn_data_string.- GetAccount
Data Size GetAccountDataSize(21): ask the token program how many bytes a token account formintneeds, as au64in the return data. On Token-2022 the mint’s required account extensions are included automatically andextension_typesadds more (for examplecrate::token_2022_ext::EXT_IMMUTABLE_OWNER); SPL Token ignores the list and answers 165.- Initialize
Immutable Owner InitializeImmutableOwner(22): mark a not-yet-initialized token account so that its owner can never be changed. Runs beforeInitializeAccount3. On Token-2022 it needs the 4-byte extension header in the allocation (GetAccountDataSizewith type 7 reports the size); SPL Token accepts it as a no-op on a 165-byte account.- Initialize
Mint InitializeMint(0): the Rent-sysvar form ofInitializeMint2. The mint must already be allocated (82 bytes on SPL Token) and owned by the token program. PreferInitializeMint2in new code; this form exists for callers whose instruction already carries the Rent sysvar.- Initialize
Multisig InitializeMultisig(2): turn a 355-byte, token-program-owned account into anm-of-nmultisig oversigners. The member accounts are listed read-only and do not sign. Requires the Rent sysvar account;InitializeMultisig2does not.- Initialize
Multisig2 InitializeMultisig2(19):InitializeMultisigwithout the Rent sysvar account.- UiAmount
ToAmount UiAmountToAmount(24): parse a decimal string against the mint and return the raw amount as au64in the return data. Read it withreturn_data_u64. Strings longer thanMAX_UI_AMOUNT_LENbytes are refused before the CPI.- Unwrap
Lamports UnwrapLamports(45): move lamports out of a native (wrapped SOL) token account todestinationwithout closing it, the whole balance withamount: Noneor 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 withInvalidInstructionData.- Withdraw
Excess Lamports WithdrawExcessLamports(38): move every lamport above the rent-exempt minimum out of a token account, mint, or multisig intodestination.authorityis 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
GetAccountDataSizeorReallocatecarries. Token-2022 defines 29; the buffer leaves room for growth. - MAX_
UI_ AMOUNT_ LEN - The longest UI-amount string
UiAmountToAmountcarries: 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
u64a token program left in the return data, refusing return data set by any other program or shorter than eight bytes.