Skip to main content

Module token

Module token 

Source
Expand description

Hopper-native SPL Token CPI builders.

The API is Hopper-owned (builder pattern over AccountView / Signer). A builder’s CPI checks that no account in the instruction is borrowed and that no account fills two writable roles, and leaves signer and writable privileges to the runtime; a multisig authority’s signers take the fully checked bounded path.

Provides checked-by-default TransferChecked, MintToChecked, BurnChecked, ApproveChecked, CloseAccount, Revoke, SetAuthority, FreezeAccount, ThawAccount, SyncNative, and InitializeAccount builders, plus the administrative set (InitializeMint, InitializeMultisig, InitializeMultisig2, InitializeImmutableOwner, GetAccountDataSize, WithdrawExcessLamports, AmountToUiAmount, UiAmountToAmount, UnwrapLamports) and the p-token Batch instruction through TokenBatch. Multisig owner flows are first-class via bounded signer-account slices. Deprecated plain Transfer/MintTo/Burn/Approve builders are compiled only when legacy-token-instructions is explicitly enabled.

§One encoding, two programs, two sinks

Every builder encodes its instruction bytes and account metas exactly once, in its TokenInstruction::emit impl. invoke() and the invoke_signed / invoke_multisig family send that encoding to SPL Token; invoke_on sends it to an explicit TokenProgram, and invoke_for_owner to whichever of the two programs owns the builder’s first account (one 32-byte compare, and a refusal for any other owner). The same emit can also append the instruction to a TokenBatch, which sends several token instructions in one CPI.

Re-exports§

pub use crate::token_admin::return_data_string;
pub use crate::token_admin::return_data_u64;
pub use crate::token_admin::AmountToUiAmount;
pub use crate::token_admin::GetAccountDataSize;
pub use crate::token_admin::InitializeImmutableOwner;
pub use crate::token_admin::InitializeMint;
pub use crate::token_admin::InitializeMultisig;
pub use crate::token_admin::InitializeMultisig2;
pub use crate::token_admin::UiAmountToAmount;
pub use crate::token_admin::UnwrapLamports;
pub use crate::token_admin::WithdrawExcessLamports;
pub use crate::token_admin::MAX_UI_AMOUNT_LEN;
pub use crate::token_batch::TokenBatch;
pub use crate::token_mint::InitializeMint2;
pub use crate::token_mint::MintConfig;
pub use crate::token_mint::MintPlan;
pub use crate::token_mint::MintProgram;

Modules§

instructions
Legacy module-path re-exports.

Structs§

ApproveChecked
Builder for SPL Token ApproveChecked (instruction index 13).
BurnChecked
Builder for SPL Token BurnChecked (instruction index 15).
CheckedMintDecimals
Proof token that an SPL Mint matched expected decimals.
CheckedTokenAuthority
Proof token that an SPL TokenAccount matched an expected token authority.
CheckedTokenMint
Proof token that an SPL TokenAccount matched an expected mint.
CloseAccount
Builder for SPL Token CloseAccount (instruction index 9).
FreezeAccount
Builder for SPL Token FreezeAccount (instruction index 10).
InitializeAccount
Builder for SPL Token InitializeAccount (instruction index 1).
InitializeAccount2
Builder for SPL Token InitializeAccount2 (instruction index 16).
InitializeAccount3
Builder for SPL Token InitializeAccount3 (instruction index 18).
MintToChecked
Builder for SPL Token MintToChecked (instruction index 14).
Revoke
Builder for SPL Token Revoke (instruction index 5).
SetAuthority
Builder for SPL Token SetAuthority (instruction index 6).
SplMint
Known external SPL Mint adapter.
SplMintView
Guard-owned zero-copy SPL Mint view.
SplTokenAccount
Known external SPL TokenAccount adapter.
SplTokenAccountView
Guard-owned zero-copy SPL TokenAccount view.
SyncNative
Builder for SPL Token SyncNative (instruction index 17).
ThawAccount
Builder for SPL Token ThawAccount (instruction index 11).
TokenAmountSnapshot
Snapshot of a token account amount before CPI.
Trailing
A run of accounts appended after a builder’s fixed accounts, all with the same privileges: the multisig signers of an authority, the member list of a new multisig, or the source accounts of a withheld-fee sweep.
TransferChecked
Builder for classic SPL Token TransferChecked (instruction index 12).

Enums§

TokenAuthorityType
Authority classes accepted by SPL Token’s SetAuthority instruction.
TokenProgram
The two token programs every builder in this module can target.

Constants§

MAX_TOKEN_MULTISIG_SIGNERS
SPL Token multisig accounts support at most 11 signer accounts.
SPL_MINT_LEN
SPL_TOKEN_ACCOUNT_LEN
TOKEN_2022_PROGRAM_ID
Token-2022 program address.
TOKEN_PROGRAM_ID
SPL Token program address.

Traits§

TokenInstruction
An SPL Token / Token-2022 instruction builder: something that can encode itself into a TokenSink.
TokenSink
Where a builder’s encoded instruction goes.

Functions§

require_mint_authority
Verify an SPL Mint account’s mint_authority COption field matches expected_authority.
require_mint_decimals
Verify an SPL Mint account’s decimals byte matches expected.
require_mint_freeze_authority
Verify an SPL Mint account’s freeze_authority COption field matches expected_freeze.
require_token_authority
Verify an SPL Token account’s owner field matches authority.key().
require_token_mint
Verify an SPL Token account’s mint field matches expected_mint.
require_token_owner_eq
Verify an SPL Token account’s owner field matches a pubkey supplied directly (i.e. not wrapped in an AccountView).