/** * 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 { AccountRole, combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, getU8Decoder, getU8Encoder, 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 SKIP_EMPTY_RENT_SOURCES_DISCRIMINATOR = new Uint8Array([ 138, 2, 241, 48, 125, 71, 25, 109, ]); export function getSkipEmptyRentSourcesDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SKIP_EMPTY_RENT_SOURCES_DISCRIMINATOR, ); } export type SkipEmptyRentSourcesInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountCatalog extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountCatalog extends string ? WritableAccount : TAccountCatalog, ...TRemainingAccounts, ] >; export type SkipEmptyRentSourcesInstructionData = { discriminator: ReadonlyUint8Array; kind: number; expectedCursor: number; count: number; }; export type SkipEmptyRentSourcesInstructionDataArgs = { kind: number; expectedCursor: number; count: number; }; export function getSkipEmptyRentSourcesInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['kind', getU8Encoder()], ['expectedCursor', getU32Encoder()], ['count', getU16Encoder()], ]), (value) => ({ ...value, discriminator: SKIP_EMPTY_RENT_SOURCES_DISCRIMINATOR, }), ); } export function getSkipEmptyRentSourcesInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['kind', getU8Decoder()], ['expectedCursor', getU32Decoder()], ['count', getU16Decoder()], ]); } export function getSkipEmptyRentSourcesInstructionDataCodec(): FixedSizeCodec< SkipEmptyRentSourcesInstructionDataArgs, SkipEmptyRentSourcesInstructionData > { return combineCodec( getSkipEmptyRentSourcesInstructionDataEncoder(), getSkipEmptyRentSourcesInstructionDataDecoder(), ); } export type SkipEmptyRentSourcesInput< TAccountGame extends string = string, TAccountCatalog extends string = string, > = { game: Address; catalog: Address; kind: SkipEmptyRentSourcesInstructionDataArgs['kind']; expectedCursor: SkipEmptyRentSourcesInstructionDataArgs['expectedCursor']; count: SkipEmptyRentSourcesInstructionDataArgs['count']; sources: Array
; }; export function getSkipEmptyRentSourcesInstruction< TAccountGame extends string, TAccountCatalog extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SkipEmptyRentSourcesInput, config?: { programAddress?: TProgramAddress }, ): SkipEmptyRentSourcesInstruction< TProgramAddress, TAccountGame, TAccountCatalog > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, catalog: { value: input.catalog ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Remaining accounts. const remainingAccounts: AccountMeta[] = args.sources.map((address) => ({ address, role: AccountRole.READONLY, })); const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('catalog', accounts.catalog), ...remainingAccounts, ], data: getSkipEmptyRentSourcesInstructionDataEncoder().encode( args as SkipEmptyRentSourcesInstructionDataArgs, ), programAddress, } as SkipEmptyRentSourcesInstruction< TProgramAddress, TAccountGame, TAccountCatalog >); } export type ParsedSkipEmptyRentSourcesInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; catalog: TAccountMetas[1]; }; data: SkipEmptyRentSourcesInstructionData; }; export function parseSkipEmptyRentSourcesInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSkipEmptyRentSourcesInstruction { 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(), catalog: getNextAccount() }, data: getSkipEmptyRentSourcesInstructionDataDecoder().decode( instruction.data, ), }; }