/** * 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, getU32Decoder, getU32Encoder, 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_DEMOCRACY_PTR_EMPTY_REGISTRIES_DISCRIMINATOR = new Uint8Array( [215, 171, 15, 195, 34, 152, 237, 225], ); export function getSkipDemocracyPtrEmptyRegistriesDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SKIP_DEMOCRACY_PTR_EMPTY_REGISTRIES_DISCRIMINATOR, ); } export type SkipDemocracyPtrEmptyRegistriesInstruction< 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 SkipDemocracyPtrEmptyRegistriesInstructionData = { discriminator: ReadonlyUint8Array; expectedSystemId: number; }; export type SkipDemocracyPtrEmptyRegistriesInstructionDataArgs = { expectedSystemId: number; }; export function getSkipDemocracyPtrEmptyRegistriesInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['expectedSystemId', getU32Encoder()], ]), (value) => ({ ...value, discriminator: SKIP_DEMOCRACY_PTR_EMPTY_REGISTRIES_DISCRIMINATOR, }), ); } export function getSkipDemocracyPtrEmptyRegistriesInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['expectedSystemId', getU32Decoder()], ]); } export function getSkipDemocracyPtrEmptyRegistriesInstructionDataCodec(): FixedSizeCodec< SkipDemocracyPtrEmptyRegistriesInstructionDataArgs, SkipDemocracyPtrEmptyRegistriesInstructionData > { return combineCodec( getSkipDemocracyPtrEmptyRegistriesInstructionDataEncoder(), getSkipDemocracyPtrEmptyRegistriesInstructionDataDecoder(), ); } export type SkipDemocracyPtrEmptyRegistriesInput< TAccountGame extends string = string, TAccountCatalog extends string = string, > = { game: Address; catalog: Address; expectedSystemId: SkipDemocracyPtrEmptyRegistriesInstructionDataArgs['expectedSystemId']; registries: Array
; }; export function getSkipDemocracyPtrEmptyRegistriesInstruction< TAccountGame extends string, TAccountCatalog extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SkipDemocracyPtrEmptyRegistriesInput, config?: { programAddress?: TProgramAddress }, ): SkipDemocracyPtrEmptyRegistriesInstruction< 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.registries.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: getSkipDemocracyPtrEmptyRegistriesInstructionDataEncoder().encode( args as SkipDemocracyPtrEmptyRegistriesInstructionDataArgs, ), programAddress, } as SkipDemocracyPtrEmptyRegistriesInstruction< TProgramAddress, TAccountGame, TAccountCatalog >); } export type ParsedSkipDemocracyPtrEmptyRegistriesInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; catalog: TAccountMetas[1]; }; data: SkipDemocracyPtrEmptyRegistriesInstructionData; }; export function parseSkipDemocracyPtrEmptyRegistriesInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSkipDemocracyPtrEmptyRegistriesInstruction { 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: getSkipDemocracyPtrEmptyRegistriesInstructionDataDecoder().decode( instruction.data, ), }; }