/** * 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, 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 ADMIT_RENT_SOURCE_DISCRIMINATOR = new Uint8Array([ 86, 172, 211, 156, 20, 178, 59, 178, ]); export function getAdmitRentSourceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ADMIT_RENT_SOURCE_DISCRIMINATOR, ); } export type AdmitRentSourceInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountCatalog extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountBody extends string | AccountMeta = string, TAccountHead extends string | AccountMeta = string, TAccountCurrentPage extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountCatalog extends string ? WritableAccount : TAccountCatalog, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountBody extends string ? ReadonlyAccount : TAccountBody, TAccountHead extends string ? WritableAccount : TAccountHead, TAccountCurrentPage extends string ? ReadonlyAccount : TAccountCurrentPage, ...TRemainingAccounts, ] >; export type AdmitRentSourceInstructionData = { discriminator: ReadonlyUint8Array; kind: number; expectedCursor: number; }; export type AdmitRentSourceInstructionDataArgs = { kind: number; expectedCursor: number; }; export function getAdmitRentSourceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['kind', getU8Encoder()], ['expectedCursor', getU32Encoder()], ]), (value) => ({ ...value, discriminator: ADMIT_RENT_SOURCE_DISCRIMINATOR }), ); } export function getAdmitRentSourceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['kind', getU8Decoder()], ['expectedCursor', getU32Decoder()], ]); } export function getAdmitRentSourceInstructionDataCodec(): FixedSizeCodec< AdmitRentSourceInstructionDataArgs, AdmitRentSourceInstructionData > { return combineCodec( getAdmitRentSourceInstructionDataEncoder(), getAdmitRentSourceInstructionDataDecoder(), ); } export type AdmitRentSourceInput< TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountSystem extends string = string, TAccountBody extends string = string, TAccountHead extends string = string, TAccountCurrentPage extends string = string, > = { game: Address; catalog: Address; /** LEVEL only. */ system?: Address; /** GRID only. */ body?: Address; /** The source's existing head. */ head: Address; /** The page holding the head's latest record. */ currentPage: Address; kind: AdmitRentSourceInstructionDataArgs['kind']; expectedCursor: AdmitRentSourceInstructionDataArgs['expectedCursor']; }; export function getAdmitRentSourceInstruction< TAccountGame extends string, TAccountCatalog extends string, TAccountSystem extends string, TAccountBody extends string, TAccountHead extends string, TAccountCurrentPage extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: AdmitRentSourceInput< TAccountGame, TAccountCatalog, TAccountSystem, TAccountBody, TAccountHead, TAccountCurrentPage >, config?: { programAddress?: TProgramAddress }, ): AdmitRentSourceInstruction< TProgramAddress, TAccountGame, TAccountCatalog, TAccountSystem, TAccountBody, TAccountHead, TAccountCurrentPage > { // 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 }, system: { value: input.system ?? null, isWritable: false }, body: { value: input.body ?? null, isWritable: false }, head: { value: input.head ?? null, isWritable: true }, currentPage: { value: input.currentPage ?? null, isWritable: false }, }; 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('catalog', accounts.catalog), getAccountMeta('system', accounts.system), getAccountMeta('body', accounts.body), getAccountMeta('head', accounts.head), getAccountMeta('currentPage', accounts.currentPage), ], data: getAdmitRentSourceInstructionDataEncoder().encode( args as AdmitRentSourceInstructionDataArgs, ), programAddress, } as AdmitRentSourceInstruction< TProgramAddress, TAccountGame, TAccountCatalog, TAccountSystem, TAccountBody, TAccountHead, TAccountCurrentPage >); } export type ParsedAdmitRentSourceInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; catalog: TAccountMetas[1]; /** LEVEL only. */ system?: TAccountMetas[2] | undefined; /** GRID only. */ body?: TAccountMetas[3] | undefined; /** The source's existing head. */ head: TAccountMetas[4]; /** The page holding the head's latest record. */ currentPage: TAccountMetas[5]; }; data: AdmitRentSourceInstructionData; }; export function parseAdmitRentSourceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedAdmitRentSourceInstruction { if (instruction.accounts.length < 6) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 6, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SAGE_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), catalog: getNextAccount(), system: getNextOptionalAccount(), body: getNextOptionalAccount(), head: getNextAccount(), currentPage: getNextAccount(), }, data: getAdmitRentSourceInstructionDataDecoder().decode(instruction.data), }; }