/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const EXPIRE_SIGNAL_DISCRIMINATOR = new Uint8Array([ 14, 229, 95, 115, 71, 40, 175, 76, ]); export function getExpireSignalDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( EXPIRE_SIGNAL_DISCRIMINATOR, ); } export type ExpireSignalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountScanSignal extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountScanSignal extends string ? WritableAccount : TAccountScanSignal, ...TRemainingAccounts, ] >; export type ExpireSignalInstructionData = { discriminator: ReadonlyUint8Array; expectedSequence: bigint; }; export type ExpireSignalInstructionDataArgs = { expectedSequence: number | bigint; }; export function getExpireSignalInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['expectedSequence', getU64Encoder()], ]), (value) => ({ ...value, discriminator: EXPIRE_SIGNAL_DISCRIMINATOR }), ); } export function getExpireSignalInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['expectedSequence', getU64Decoder()], ]); } export function getExpireSignalInstructionDataCodec(): FixedSizeCodec< ExpireSignalInstructionDataArgs, ExpireSignalInstructionData > { return combineCodec( getExpireSignalInstructionDataEncoder(), getExpireSignalInstructionDataDecoder(), ); } export type ExpireSignalInput< TAccountGame extends string = string, TAccountScanSignal extends string = string, > = { game: Address; scanSignal: Address; expectedSequence: ExpireSignalInstructionDataArgs['expectedSequence']; }; export function getExpireSignalInstruction< TAccountGame extends string, TAccountScanSignal extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ExpireSignalInput, config?: { programAddress?: TProgramAddress }, ): ExpireSignalInstruction { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, scanSignal: { value: input.scanSignal ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('scanSignal', accounts.scanSignal), ], data: getExpireSignalInstructionDataEncoder().encode( args as ExpireSignalInstructionDataArgs, ), programAddress, } as ExpireSignalInstruction< TProgramAddress, TAccountGame, TAccountScanSignal >); } export type ParsedExpireSignalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; scanSignal: TAccountMetas[1]; }; data: ExpireSignalInstructionData; }; export function parseExpireSignalInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedExpireSignalInstruction { if (instruction.accounts.length < 2) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), scanSignal: getNextAccount() }, data: getExpireSignalInstructionDataDecoder().decode(instruction.data), }; }