Skip to main content

Crate hopper_token

Crate hopper_token 

Source
Expand description

Hopper-owned SPL Token builder surface.

Thin first-class Hopper wrappers over the canonical runtime builders. This crate gives Hopper a native token CPI surface instead of forcing authored programs to depend on external helper crates.

Modules§

instructions
SPL Token instruction builders exported by Hopper.
layout
Kani proofs and golden-vector tests for the shipped SPL Token and System-program CPI instruction-data encoders.

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.
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).
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.
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).
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.
InitializeMint2
Low-level InitializeMint2 CPI builder for either token program.
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.
MintConfig
Base mint configuration. Initializing a mint does not mint any supply.
MintPlan
Validated, allocation-free mint creation plan.
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.
TokenBatch
A stack-resident batch of token instructions.
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).
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.

Enums§

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

Constants§

BATCH_DISCRIMINATOR
The Batch discriminator.
BATCH_INSTRUCTION_HEADER_LEN
Bytes of header in front of each inner instruction: its account count and its data length, one byte each.
MAX_TOKEN_MULTISIG_SIGNERS
SPL Token multisig accounts support at most 11 signer accounts.
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.
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§

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.

Type Aliases§

MintProgram
The token program a mint is created on: the same selector every token builder takes, under the name mint creation has always used.