Expand description
Batch (255): several token instructions in one CPI.
The p-token build of SPL Token accepts one instruction whose data is
[255] followed by, per inner instruction, a two-byte header
([account count][data length]) and that instruction’s data; the
accounts of every inner instruction follow each other in the account
list. One CPI then pays one invocation overhead instead of one per
instruction.
TokenBatch is a TokenSink: builders in crate::token or
crate::token_2022_ix are appended with TokenBatch::push through
the same emit that its invoke() uses, so the batched bytes and the
single-CPI bytes are identical by construction. The buffers are const
generic and live on the stack; nothing is allocated.
Each inner instruction must fit the wire format’s 255-byte data and
255-account limits as well as the batch’s capacities. A larger payload
must be sent separately.
One account may appear in several inner instructions (a transfer there
and back); the batch is sent through
crate::cpi::invoke_signed_batch_with_bounds, which keeps every
per-meta check of the default tier and only waives the refusal of one
account behind two writable metas, since for a batch that repeat is the
contract rather than the footgun.
Within an inner instruction, repeated writable accounts are still
refused with AccountBorrowFailed (including self-transfers).
Both programs accepted a batch of two TransferCheckeds on devnet on
2026-09-28 (SPL Token at 2,472 CU for the whole instruction, Token-2022
at 5,575); the Token-2022 build bundled with Mollusk 0.15 refuses
discriminator 255 with InvalidInstruction, so a local test cannot
stand in for the cluster on that point.
Structs§
- Token
Batch - A stack-resident batch of token instructions.
Constants§
- BATCH_
DISCRIMINATOR - The
Batchdiscriminator. - BATCH_
INSTRUCTION_ HEADER_ LEN - Bytes of header in front of each inner instruction: its account count and its data length, one byte each.