Skip to content

@thru/programs

View as Markdown

@thru/programs contains program-specific bindings for built-in Thru programs. It is published as one package with subpath exports for each program surface.

Terminal window
npm install @thru/programs @thru/sdk
ImportWhat it provides
@thru/programs/tokenToken program instruction builders, account parsers, address derivation, ABI builders, and formatting helpers.
@thru/programs/passkey-managerPasskey-manager instruction encoders, challenge helpers, account-context builders, derivation helpers, account parsers, and P-256/WebAuthn encoding utilities.
@thru/programs/multicallMulticall instruction encoding for batching calls to multiple programs in one instruction payload.
@thru/programs/ammAMM 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.

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:

  • createInitializeMintInstruction
  • createInitializeAccountInstruction
  • createMintToInstruction
  • createTransferInstruction
  • deriveMintAddress
  • deriveTokenAccountAddress
  • deriveWalletSeed
  • parseMintAccountData
  • parseTokenAccountData
  • formatRawAmount

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:

  • encodeCreateInstruction
  • encodeValidateInstruction
  • encodeTransferInstruction
  • encodeInvokeInstruction
  • encodeAddAuthorityInstruction
  • encodeRemoveAuthorityInstruction
  • encodeRegisterCredentialInstruction
  • createValidateChallenge
  • deriveWalletAddress
  • deriveCredentialLookupAddress
  • buildAccountContext
  • parseWalletNonce
  • fetchWalletNonce
  • parseWalletAuthorities
  • P-256 and byte/base64 helpers used by WebAuthn flows

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_ADDRESS
  • MULTICALL_PROGRAM_PUBKEY
  • buildMulticallInstruction
  • MulticallCall
  • Generated InstructionData, InstructionDataBuilder, MulticallArgs, MulticallArgsBuilder, and MulticallError ABI types

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_ADDRESS
  • AMM_DEFAULT_SWAP_FEE_BPS
  • AMM_MAX_SWAP_FEE_BPS
  • AMM_MINIMUM_LIQUIDITY
  • AMM_POOL_METADATA_SIZE
  • sortAmmMints
  • deriveAmmPoolAddresses
  • deriveAmmLpMintSeed
  • createInitPoolInstruction
  • createAddLiquidityInstruction
  • createWithdrawLiquidityInstruction
  • createSwapInstruction
  • parseAmmPoolMetadata
  • quoteAmmSwapExactIn
  • Generated AMM instruction, event, metadata, and error ABI types