/** * 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 AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const CREATE_AND_ADMIT_RENT_SOURCE_DISCRIMINATOR = new Uint8Array([ 188, 83, 195, 162, 64, 77, 238, 177, ]); export function getCreateAndAdmitRentSourceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CREATE_AND_ADMIT_RENT_SOURCE_DISCRIMINATOR, ); } export type CreateAndAdmitRentSourceInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, 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, TAccountPage0 extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, 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, TAccountPage0 extends string ? WritableAccount : TAccountPage0, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type CreateAndAdmitRentSourceInstructionData = { discriminator: ReadonlyUint8Array; kind: number; expectedCursor: number; }; export type CreateAndAdmitRentSourceInstructionDataArgs = { kind: number; expectedCursor: number; }; export function getCreateAndAdmitRentSourceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['kind', getU8Encoder()], ['expectedCursor', getU32Encoder()], ]), (value) => ({ ...value, discriminator: CREATE_AND_ADMIT_RENT_SOURCE_DISCRIMINATOR, }), ); } export function getCreateAndAdmitRentSourceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['kind', getU8Decoder()], ['expectedCursor', getU32Decoder()], ]); } export function getCreateAndAdmitRentSourceInstructionDataCodec(): FixedSizeCodec< CreateAndAdmitRentSourceInstructionDataArgs, CreateAndAdmitRentSourceInstructionData > { return combineCodec( getCreateAndAdmitRentSourceInstructionDataEncoder(), getCreateAndAdmitRentSourceInstructionDataDecoder(), ); } export type CreateAndAdmitRentSourceInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountSystem extends string = string, TAccountBody extends string = string, TAccountHead extends string = string, TAccountPage0 extends string = string, TAccountSystemProgram extends string = string, > = { funder: TransactionSigner; game: Address; catalog: Address; /** LEVEL only. */ system?: Address; /** GRID only. */ body?: Address; /** The new head. */ head: Address; /** Its page 0. */ page0: Address; systemProgram?: Address; kind: CreateAndAdmitRentSourceInstructionDataArgs['kind']; expectedCursor: CreateAndAdmitRentSourceInstructionDataArgs['expectedCursor']; }; export function getCreateAndAdmitRentSourceInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountCatalog extends string, TAccountSystem extends string, TAccountBody extends string, TAccountHead extends string, TAccountPage0 extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CreateAndAdmitRentSourceInput< TAccountFunder, TAccountGame, TAccountCatalog, TAccountSystem, TAccountBody, TAccountHead, TAccountPage0, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): CreateAndAdmitRentSourceInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountSystem, TAccountBody, TAccountHead, TAccountPage0, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, 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 }, page0: { value: input.page0 ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('game', accounts.game), getAccountMeta('catalog', accounts.catalog), getAccountMeta('system', accounts.system), getAccountMeta('body', accounts.body), getAccountMeta('head', accounts.head), getAccountMeta('page0', accounts.page0), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getCreateAndAdmitRentSourceInstructionDataEncoder().encode( args as CreateAndAdmitRentSourceInstructionDataArgs, ), programAddress, } as CreateAndAdmitRentSourceInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountSystem, TAccountBody, TAccountHead, TAccountPage0, TAccountSystemProgram >); } export type ParsedCreateAndAdmitRentSourceInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { funder: TAccountMetas[0]; game: TAccountMetas[1]; catalog: TAccountMetas[2]; /** LEVEL only. */ system?: TAccountMetas[3] | undefined; /** GRID only. */ body?: TAccountMetas[4] | undefined; /** The new head. */ head: TAccountMetas[5]; /** Its page 0. */ page0: TAccountMetas[6]; systemProgram: TAccountMetas[7]; }; data: CreateAndAdmitRentSourceInstructionData; }; export function parseCreateAndAdmitRentSourceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCreateAndAdmitRentSourceInstruction { if (instruction.accounts.length < 8) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8, }, ); } 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: { funder: getNextAccount(), game: getNextAccount(), catalog: getNextAccount(), system: getNextOptionalAccount(), body: getNextOptionalAccount(), head: getNextAccount(), page0: getNextAccount(), systemProgram: getNextAccount(), }, data: getCreateAndAdmitRentSourceInstructionDataDecoder().decode( instruction.data, ), }; }