@thru/programs
@thru/programs contains program-specific bindings for built-in Thru programs. It is published as one package with subpath exports for each program surface.
Install
Section titled “Install”npm install @thru/programs @thru/sdkEntry Points
Section titled “Entry Points”| Import | What it provides |
|---|---|
@thru/programs/token | Token program instruction builders, account parsers, address derivation, ABI builders, and formatting helpers. |
@thru/programs/passkey-manager | Passkey-manager instruction encoders, challenge helpers, account-context builders, derivation helpers, account parsers, and P-256/WebAuthn encoding utilities. |
@thru/programs/multicall | Multicall instruction encoding for batching calls to multiple programs in one instruction payload. |
@thru/programs/amm | AMM pool derivation, instruction builders, pool metadata parsing, swap quoting, constants, and generated ABI views. |
There is no root runtime import. Import from the program subpath you need.
Token Program
Section titled “Token Program”Use @thru/programs/token when you are creating token mints, creating token accounts, transferring or minting tokens, parsing token account state, or formatting raw token amounts.
import { createTransferInstruction, deriveTokenAccountAddress, formatRawAmount, parseTokenAccountData,} from "@thru/programs/token";
const destination = deriveTokenAccountAddress( ownerAddress, mintAddress, tokenProgramAddress);
const instructionData = createTransferInstruction({ sourceAccountBytes, destinationAccountBytes: destination.bytes, amount: 1_000_000n,});
const parsed = parseTokenAccountData(account);const displayAmount = formatRawAmount(parsed.amount, 6);Important token exports include:
createInitializeMintInstructioncreateInitializeAccountInstructioncreateMintToInstructioncreateTransferInstructionderiveMintAddressderiveTokenAccountAddressderiveWalletSeedparseMintAccountDataparseTokenAccountDataformatRawAmount
Passkey Manager Program
Section titled “Passkey Manager Program”Use @thru/programs/passkey-manager when you need to build passkey-managed wallet instructions, create validate challenges, derive wallet or credential lookup addresses, parse wallet state, or compose passkey-manager instruction bytes.
import { buildAccountContext, concatenateInstructions, createValidateChallenge, encodeTransferInstruction, encodeValidateInstruction,} from "@thru/programs/passkey-manager";
const accountContext = buildAccountContext({ feePayerAddress, walletAddress, readWriteAccounts: [destinationAddress],});
const transfer = encodeTransferInstruction({ accountContext, toAddress: destinationAddress, amount: 1_000_000n,});
const challenge = createValidateChallenge({ nonce, accountAddresses: accountContext.accountAddresses, instructionData: transfer,});
const validate = encodeValidateInstruction({ accountContext, authorityIndex, challenge, signature, authenticatorData, clientDataJSON,});
const instructionData = concatenateInstructions(validate, transfer);Important passkey-manager exports include:
encodeCreateInstructionencodeValidateInstructionencodeTransferInstructionencodeInvokeInstructionencodeAddAuthorityInstructionencodeRemoveAuthorityInstructionencodeRegisterCredentialInstructioncreateValidateChallengederiveWalletAddressderiveCredentialLookupAddressbuildAccountContextparseWalletNoncefetchWalletNonceparseWalletAuthorities- P-256 and byte/base64 helpers used by WebAuthn flows
Multicall Program
Section titled “Multicall Program”Use @thru/programs/multicall when you need to encode a single multicall payload that dispatches multiple inner program instructions.
import { MULTICALL_PROGRAM_ADDRESS, buildMulticallInstruction,} from "@thru/programs/multicall";
const instructionData = buildMulticallInstruction([ { programIdx: 2, instructionData: tokenTransferInstruction, }, { programIdx: 5, instructionData: anotherInstruction, },]);Each call uses the target program’s account index in the transaction account context plus the already-encoded instruction bytes for that program.
Important multicall exports include:
MULTICALL_PROGRAM_ADDRESSMULTICALL_PROGRAM_PUBKEYbuildMulticallInstructionMulticallCall- Generated
InstructionData,InstructionDataBuilder,MulticallArgs,MulticallArgsBuilder, andMulticallErrorABI types
AMM Program
Section titled “AMM Program”Use @thru/programs/amm when you need to derive AMM pool addresses, create pool/liquidity/swap instructions, parse AMM pool metadata, or quote exact-input swaps.
import { AMM_PROGRAM_ADDRESS, createSwapInstruction, deriveAmmPoolAddresses, parseAmmPoolMetadata, quoteAmmSwapExactIn,} from "@thru/programs/amm";
const pool = deriveAmmPoolAddresses(thru, { ammProgramAddress: AMM_PROGRAM_ADDRESS, mintAAddress, mintBAddress,});
const quote = quoteAmmSwapExactIn({ amountIn: 1_000_000n, reserveIn, reserveOut, swapFeeBps: pool.swapFeeBps,});
const swapInstruction = createSwapInstruction({ poolAccountBytes: pool.poolBytes, userTransferAuthorityBytes, userInputAccountBytes, userOutputAccountBytes, vaultInputAccountBytes, vaultOutputAccountBytes, lpMintAccountBytes, tokenProgramAccountBytes, amountIn: quote.amountIn,});
const metadata = parseAmmPoolMetadata(poolAccount);The AMM instruction builders return an async InstructionData function. Pass swapInstruction the same account lookup context used to build the transaction so account indexes are resolved against the final account list.
Important AMM exports include:
AMM_PROGRAM_ADDRESSAMM_DEFAULT_SWAP_FEE_BPSAMM_MAX_SWAP_FEE_BPSAMM_MINIMUM_LIQUIDITYAMM_POOL_METADATA_SIZEsortAmmMintsderiveAmmPoolAddressesderiveAmmLpMintSeedcreateInitPoolInstructioncreateAddLiquidityInstructioncreateWithdrawLiquidityInstructioncreateSwapInstructionparseAmmPoolMetadataquoteAmmSwapExactIn- Generated AMM instruction, event, metadata, and error ABI types