Documentation
¶
Overview ¶
Package token2022 provides typed instruction builders for the SPL Token-2022 program (TokenzQd...), the extension-capable successor to the classic SPL Token program (Tokenkeg...).
For the core instructions (Transfer, TransferChecked, MintTo, Burn, CloseAccount, InitializeMint2, InitializeAccount3), the wire format is byte-identical to classic SPL Token. This package reuses the builders from programs/token and wraps them to substitute Token-2022's program id.
Extension instructions use a u8 discriminator (not u32). Families with multiple sub-operations use [family_tag u8, sub_tag u8, ...].
Index ¶
- Constants
- Variables
- func NewBurn(account, mint, authority solana.PublicKey, amount uint64) solana.Instruction
- func NewCloseAccount(account, destination, authority solana.PublicKey) solana.Instruction
- func NewDisableCpiGuard(account, owner solana.PublicKey) solana.Instruction
- func NewDisableRequiredMemoTransfers(account, owner solana.PublicKey) solana.Instruction
- func NewEnableCpiGuard(account, owner solana.PublicKey) solana.Instruction
- func NewEnableRequiredMemoTransfers(account, owner solana.PublicKey) solana.Instruction
- func NewHarvestWithheldTokensToMint(mint solana.PublicKey, sources []solana.PublicKey) solana.Instruction
- func NewInitializeAccount3(account, mint, owner solana.PublicKey) solana.Instruction
- func NewInitializeDefaultAccountState(mint solana.PublicKey, state AccountState) solana.Instruction
- func NewInitializeInterestBearingMint(mint solana.PublicKey, rateAuthority *solana.PublicKey, rate int16) solana.Instruction
- func NewInitializeMetadataPointer(mint solana.PublicKey, authority, metadataAddress *solana.PublicKey) solana.Instruction
- func NewInitializeMint2(mint solana.PublicKey, decimals uint8, ...) solana.Instruction
- func NewInitializeMintCloseAuthority(mint solana.PublicKey, closeAuth *solana.PublicKey) solana.Instruction
- func NewInitializeNonTransferableMint(mint solana.PublicKey) solana.Instruction
- func NewInitializePermanentDelegate(mint, delegate solana.PublicKey) solana.Instruction
- func NewInitializeTransferFeeConfig(mint solana.PublicKey, ...) solana.Instruction
- func NewInitializeTransferHook(mint solana.PublicKey, authority, programId *solana.PublicKey) solana.Instruction
- func NewMintTo(mint, destination, authority solana.PublicKey, amount uint64) solana.Instruction
- func NewSetTransferFee(mint, authority solana.PublicKey, feeBasisPoints uint16, maximumFee uint64) solana.Instruction
- func NewTransfer(source, destination, authority solana.PublicKey, amount uint64) solana.Instruction
- func NewTransferChecked(source, mint, destination, authority solana.PublicKey, amount uint64, ...) solana.Instruction
- func NewUpdateDefaultAccountState(mint, freezeAuthority solana.PublicKey, state AccountState) solana.Instruction
- func NewUpdateInterestBearingMintRate(mint, rateAuthority solana.PublicKey, rate int16) solana.Instruction
- func NewUpdateMetadataPointer(mint, authority solana.PublicKey, metadataAddress *solana.PublicKey) solana.Instruction
- func NewUpdateTransferHook(mint, authority solana.PublicKey, programId *solana.PublicKey) solana.Instruction
- func NewWithdrawWithheldTokensFromAccounts(mint, destination, withdrawAuthority solana.PublicKey, ...) solana.Instruction
- func NewWithdrawWithheldTokensFromMint(mint, destination, withdrawAuthority solana.PublicKey) solana.Instruction
- func Wrap(ix solana.Instruction) solana.Instruction
- type Account
- type AccountExtensions
- type AccountState
- type InterestBearingConfig
- type MetadataPointerConfig
- type MintExtensions
- type MintState
- type TransferFee
- type TransferFeeConfig
- type TransferHookConfig
Constants ¶
const ( ExtTransferFeeConfig uint16 = 1 ExtTransferFeeAmount uint16 = 2 ExtMintCloseAuthority uint16 = 3 ExtDefaultAccountState uint16 = 6 ExtImmutableOwner uint16 = 7 ExtMemoTransfer uint16 = 8 ExtNonTransferable uint16 = 9 ExtInterestBearingConfig uint16 = 10 ExtCpiGuard uint16 = 11 ExtPermanentDelegate uint16 = 12 ExtMetadataPointer uint16 = 16 ExtTransferHook uint16 = 18 )
Extension type IDs for Token-2022 (spl-token-2022 ExtensionType enum).
Variables ¶
var ProgramID = solana.MustPublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
ProgramID is the canonical address of the Token-2022 program, verified against the declare_id! call in the spl_token_2022 interface crate at https://github.com/solana-program/token-2022.
Functions ¶
func NewBurn ¶
func NewBurn(account, mint, authority solana.PublicKey, amount uint64) solana.Instruction
NewBurn builds a Token-2022 Burn instruction.
func NewCloseAccount ¶
func NewCloseAccount(account, destination, authority solana.PublicKey) solana.Instruction
NewCloseAccount builds a Token-2022 CloseAccount instruction.
func NewDisableCpiGuard ¶
func NewDisableCpiGuard(account, owner solana.PublicKey) solana.Instruction
NewDisableCpiGuard builds a DisableCpiGuard instruction (tag 34, sub 1). owner must sign.
func NewDisableRequiredMemoTransfers ¶
func NewDisableRequiredMemoTransfers(account, owner solana.PublicKey) solana.Instruction
NewDisableRequiredMemoTransfers builds a DisableRequiredMemoTransfers instruction (tag 30, sub 1). owner must sign.
func NewEnableCpiGuard ¶
func NewEnableCpiGuard(account, owner solana.PublicKey) solana.Instruction
NewEnableCpiGuard builds an EnableCpiGuard instruction (tag 34, sub 0) that prevents instructions from CPI-calling token transfers on behalf of this account. owner must sign.
func NewEnableRequiredMemoTransfers ¶
func NewEnableRequiredMemoTransfers(account, owner solana.PublicKey) solana.Instruction
NewEnableRequiredMemoTransfers builds an EnableRequiredMemoTransfers instruction (tag 30, sub 0). owner must sign.
func NewHarvestWithheldTokensToMint ¶
func NewHarvestWithheldTokensToMint(mint solana.PublicKey, sources []solana.PublicKey) solana.Instruction
NewHarvestWithheldTokensToMint builds a HarvestWithheldTokensToMint instruction (tag 26, sub 4) that moves withheld fees from source token accounts back to the mint account.
func NewInitializeAccount3 ¶
func NewInitializeAccount3(account, mint, owner solana.PublicKey) solana.Instruction
NewInitializeAccount3 builds a Token-2022 InitializeAccount3 instruction.
func NewInitializeDefaultAccountState ¶
func NewInitializeDefaultAccountState(mint solana.PublicKey, state AccountState) solana.Instruction
NewInitializeDefaultAccountState builds an InitializeDefaultAccountState instruction (tag 28, sub 0) that sets the default state for newly created token accounts for this mint.
func NewInitializeInterestBearingMint ¶
func NewInitializeInterestBearingMint(mint solana.PublicKey, rateAuthority *solana.PublicKey, rate int16) solana.Instruction
NewInitializeInterestBearingMint builds an InitializeInterestBearingMint instruction (tag 33, sub 0). rateAuthority may be nil. rate is in basis points per year (signed; negative = deflation).
func NewInitializeMetadataPointer ¶
func NewInitializeMetadataPointer(mint solana.PublicKey, authority, metadataAddress *solana.PublicKey) solana.Instruction
NewInitializeMetadataPointer builds an InitializeMetadataPointer instruction (tag 39, sub 0). Either authority or metadataAddress may be nil.
func NewInitializeMint2 ¶
func NewInitializeMint2(mint solana.PublicKey, decimals uint8, mintAuthority, freezeAuthority solana.PublicKey) solana.Instruction
NewInitializeMint2 builds a Token-2022 InitializeMint2 instruction. For mints that use Token-2022 extensions, additional instructions (typically InitializeXxxExtension) must be sent in the same transaction before the mint is finalised; those are not yet exposed by this package.
func NewInitializeMintCloseAuthority ¶
func NewInitializeMintCloseAuthority(mint solana.PublicKey, closeAuth *solana.PublicKey) solana.Instruction
NewInitializeMintCloseAuthority builds an InitializeMintCloseAuthority instruction (tag 25). Call this before InitializeMint2 to allow the mint to be closed later. closeAuth may be nil to disable close.
func NewInitializeNonTransferableMint ¶
func NewInitializeNonTransferableMint(mint solana.PublicKey) solana.Instruction
NewInitializeNonTransferableMint builds an InitializeNonTransferableMint instruction (tag 32) that makes all tokens minted by this mint soul-bound (non-transferable between accounts).
func NewInitializePermanentDelegate ¶
func NewInitializePermanentDelegate(mint, delegate solana.PublicKey) solana.Instruction
NewInitializePermanentDelegate builds an InitializePermanentDelegate instruction (tag 35) that grants delegate irrevocable authority over all token accounts for this mint.
func NewInitializeTransferFeeConfig ¶
func NewInitializeTransferFeeConfig( mint solana.PublicKey, transferFeeAuthority, withdrawWithheldAuthority *solana.PublicKey, feeBasisPoints uint16, maximumFee uint64, ) solana.Instruction
NewInitializeTransferFeeConfig builds an InitializeTransferFeeConfig instruction (tag 26, sub 0). Call before InitializeMint2. Either authority may be nil to disable that capability.
func NewInitializeTransferHook ¶
func NewInitializeTransferHook(mint solana.PublicKey, authority, programId *solana.PublicKey) solana.Instruction
NewInitializeTransferHook builds an InitializeTransferHook instruction (tag 36, sub 0). Either authority or programId may be nil.
func NewMintTo ¶
func NewMintTo(mint, destination, authority solana.PublicKey, amount uint64) solana.Instruction
NewMintTo builds a Token-2022 MintTo instruction.
func NewSetTransferFee ¶
func NewSetTransferFee(mint, authority solana.PublicKey, feeBasisPoints uint16, maximumFee uint64) solana.Instruction
NewSetTransferFee builds a SetTransferFee instruction (tag 26, sub 5). authority is the transfer fee config authority and must sign.
func NewTransfer ¶
func NewTransfer(source, destination, authority solana.PublicKey, amount uint64) solana.Instruction
NewTransfer builds a Token-2022 Transfer instruction. The wire format matches classic SPL Token exactly; only the dispatched program id differs.
func NewTransferChecked ¶
func NewTransferChecked(source, mint, destination, authority solana.PublicKey, amount uint64, decimals uint8) solana.Instruction
NewTransferChecked builds a Token-2022 TransferChecked instruction.
func NewUpdateDefaultAccountState ¶
func NewUpdateDefaultAccountState(mint, freezeAuthority solana.PublicKey, state AccountState) solana.Instruction
NewUpdateDefaultAccountState builds an UpdateDefaultAccountState instruction (tag 28, sub 1). freezeAuthority must sign.
func NewUpdateInterestBearingMintRate ¶
func NewUpdateInterestBearingMintRate(mint, rateAuthority solana.PublicKey, rate int16) solana.Instruction
NewUpdateInterestBearingMintRate builds an UpdateInterestBearingMintRate instruction (tag 33, sub 1). rateAuthority must sign.
func NewUpdateMetadataPointer ¶
func NewUpdateMetadataPointer(mint, authority solana.PublicKey, metadataAddress *solana.PublicKey) solana.Instruction
NewUpdateMetadataPointer builds an UpdateMetadataPointer instruction (tag 39, sub 1). authority must sign. metadataAddress may be nil to clear.
func NewUpdateTransferHook ¶
func NewUpdateTransferHook(mint, authority solana.PublicKey, programId *solana.PublicKey) solana.Instruction
NewUpdateTransferHook builds an UpdateTransferHook instruction (tag 36, sub 1). authority must sign. programId may be nil to clear.
func NewWithdrawWithheldTokensFromAccounts ¶
func NewWithdrawWithheldTokensFromAccounts(mint, destination, withdrawAuthority solana.PublicKey, sources []solana.PublicKey) solana.Instruction
NewWithdrawWithheldTokensFromAccounts builds a WithdrawWithheldTokensFromAccounts instruction (tag 26, sub 3). withdrawAuthority must sign; sources are the accounts to harvest from.
func NewWithdrawWithheldTokensFromMint ¶
func NewWithdrawWithheldTokensFromMint(mint, destination, withdrawAuthority solana.PublicKey) solana.Instruction
NewWithdrawWithheldTokensFromMint builds a WithdrawWithheldTokensFromMint instruction (tag 26, sub 2). withdrawAuthority must sign.
func Wrap ¶
func Wrap(ix solana.Instruction) solana.Instruction
Wrap wraps an arbitrary solana.Instruction so that its ProgramID resolves to Token-2022's program id. Use this as an escape hatch for instructions that are not yet covered by a typed builder in this package but are byte-identical to their SPL Token counterpart.
Types ¶
type Account ¶
type Account struct {
Mint solana.PublicKey
Owner solana.PublicKey
Amount uint64
Delegate *solana.PublicKey
State uint8
IsNative *uint64
DelegatedAmount uint64
CloseAuthority *solana.PublicKey
Extensions AccountExtensions
}
Account is the decoded state of a Token-2022 token account. Base fields are identical to the classic SPL Token account layout (165 bytes).
Named Account (not AccountState) because the package already exports an AccountState uint8 for the frozen/thawed enum used by the DefaultAccountState extension.
func DecodeAccount ¶
DecodeAccount decodes a raw Token-2022 token account data buffer. The buffer must be at least 165 bytes; extension TLV data is parsed when additional bytes are present.
The first 165 bytes are byte-identical to a classic SPL Token account, so this function delegates to token.DecodeAccountState for that header and only owns the Token-2022-specific TLV section.
type AccountExtensions ¶
type AccountExtensions struct {
WithheldAmount *uint64
MemoTransfer *bool
ImmutableOwner bool
CpiGuard *bool
}
AccountExtensions holds the decoded extension data for a Token-2022 account.
type AccountState ¶
type AccountState uint8
AccountState represents the frozen/thawed state of a token account.
const ( AccountStateUninitialized AccountState = 0 AccountStateInitialized AccountState = 1 AccountStateFrozen AccountState = 2 )
type InterestBearingConfig ¶
type InterestBearingConfig struct {
RateAuthority *solana.PublicKey
InitializationTimestamp int64
PreUpdateAverageRate int16
LastUpdateTimestamp int64
CurrentRate int16
}
InterestBearingConfig holds interest-bearing-mint extension data.
type MetadataPointerConfig ¶
MetadataPointerConfig holds the metadata-pointer extension data.
type MintExtensions ¶
type MintExtensions struct {
CloseAuthority *solana.PublicKey
DefaultState *uint8
NonTransferable bool
PermanentDelegate *solana.PublicKey
TransferFeeConfig *TransferFeeConfig
InterestBearing *InterestBearingConfig
MetadataPointer *MetadataPointerConfig
TransferHook *TransferHookConfig
}
MintExtensions holds the decoded extension data for a Token-2022 mint. Fields are nil when the extension is absent.
type MintState ¶
type MintState struct {
MintAuthority *solana.PublicKey
Supply uint64
Decimals uint8
IsInitialized bool
FreezeAuthority *solana.PublicKey
Extensions MintExtensions
}
MintState is the decoded state of a Token-2022 mint account. The base fields are identical to the classic SPL Token mint layout (82 bytes); extensions are parsed from the TLV region that follows.
func DecodeMintState ¶
DecodeMintState decodes a raw Token-2022 mint account data buffer. The buffer must be at least 82 bytes; extension TLV data is parsed when additional bytes are present.
The first 82 bytes are byte-identical to a classic SPL Token mint, so this function delegates to token.DecodeMintState for that header and only owns the Token-2022-specific TLV section.
type TransferFee ¶
TransferFee holds per-epoch fee parameters.
type TransferFeeConfig ¶
type TransferFeeConfig struct {
TransferFeeConfigAuthority *solana.PublicKey
WithdrawWithheldAuthority *solana.PublicKey
WithheldAmount uint64
OlderTransferFee TransferFee
NewerTransferFee TransferFee
}
TransferFeeConfig holds the transfer-fee extension data for a mint.