/** * This code was AUTOGENERATED using the kinobi library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun kinobi to update it. * * @see https://github.com/kinobi-so/kinobi */ import { AccountRole, combineCodec, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, transformEncoder, type Address, type Codec, type Decoder, type Encoder, type IAccountMeta, type IAccountSignerMeta, type IInstruction, type IInstructionWithAccounts, type IInstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type TransactionSigner, type WritableAccount, } from '@solana/web3.js'; import { TOKEN_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export type FreezeAccountInstruction< TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, TAccountAccount extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< [ TAccountAccount extends string ? WritableAccount : TAccountAccount, TAccountMint extends string ? ReadonlyAccount : TAccountMint, TAccountOwner extends string ? ReadonlyAccount : TAccountOwner, ...TRemainingAccounts, ] >; export type FreezeAccountInstructionData = { discriminator: number }; export type FreezeAccountInstructionDataArgs = {}; export function getFreezeAccountInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([['discriminator', getU8Encoder()]]), (value) => ({ ...value, discriminator: 10 }) ); } export function getFreezeAccountInstructionDataDecoder(): Decoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getFreezeAccountInstructionDataCodec(): Codec< FreezeAccountInstructionDataArgs, FreezeAccountInstructionData > { return combineCodec( getFreezeAccountInstructionDataEncoder(), getFreezeAccountInstructionDataDecoder() ); } export type FreezeAccountInput< TAccountAccount extends string = string, TAccountMint extends string = string, TAccountOwner extends string = string, > = { /** The account to freeze. */ account: Address; /** The token mint. */ mint: Address; /** The mint freeze authority or its multisignature account. */ owner: Address | TransactionSigner; multiSigners?: Array; }; export function getFreezeAccountInstruction< TAccountAccount extends string, TAccountMint extends string, TAccountOwner extends string, >( input: FreezeAccountInput ): FreezeAccountInstruction< typeof TOKEN_PROGRAM_ADDRESS, TAccountAccount, TAccountMint, (typeof input)['owner'] extends TransactionSigner ? ReadonlySignerAccount & IAccountSignerMeta : TAccountOwner > { // Program address. const programAddress = TOKEN_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { account: { value: input.account ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, owner: { value: input.owner ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; // Remaining accounts. const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( (signer) => ({ address: signer.address, role: AccountRole.READONLY_SIGNER, signer, }) ); const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.account), getAccountMeta(accounts.mint), getAccountMeta(accounts.owner), ...remainingAccounts, ], programAddress, data: getFreezeAccountInstructionDataEncoder().encode({}), } as FreezeAccountInstruction< typeof TOKEN_PROGRAM_ADDRESS, TAccountAccount, TAccountMint, (typeof input)['owner'] extends TransactionSigner ? ReadonlySignerAccount & IAccountSignerMeta : TAccountOwner >; return instruction; } export type ParsedFreezeAccountInstruction< TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; accounts: { /** The account to freeze. */ account: TAccountMetas[0]; /** The token mint. */ mint: TAccountMetas[1]; /** The mint freeze authority or its multisignature account. */ owner: TAccountMetas[2]; }; data: FreezeAccountInstructionData; }; export function parseFreezeAccountInstruction< TProgram extends string, TAccountMetas extends readonly IAccountMeta[], >( instruction: IInstruction & IInstructionWithAccounts & IInstructionWithData ): ParsedFreezeAccountInstruction { if (instruction.accounts.length < 3) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts![accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { account: getNextAccount(), mint: getNextAccount(), owner: getNextAccount(), }, data: getFreezeAccountInstructionDataDecoder().decode(instruction.data), }; }