/** * 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, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, 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 INDEX_DEMOCRACY_PTR_REGISTRY_DISCRIMINATOR = new Uint8Array([ 46, 58, 56, 32, 190, 100, 244, 158, ]); export function getIndexDemocracyPtrRegistryDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INDEX_DEMOCRACY_PTR_REGISTRY_DISCRIMINATOR, ); } export type IndexDemocracyPtrRegistryInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountCatalog extends string | AccountMeta = string, TAccountRegistry extends string | AccountMeta = string, TAccountEntry extends string | AccountMeta = string, TAccountMember 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, TAccountRegistry extends string ? ReadonlyAccount : TAccountRegistry, TAccountEntry extends string ? WritableAccount : TAccountEntry, TAccountMember extends string ? WritableAccount : TAccountMember, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type IndexDemocracyPtrRegistryInstructionData = { discriminator: ReadonlyUint8Array; systemId: number; expectedRegistryCount: number; }; export type IndexDemocracyPtrRegistryInstructionDataArgs = { systemId: number; expectedRegistryCount: number; }; export function getIndexDemocracyPtrRegistryInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['systemId', getU16Encoder()], ['expectedRegistryCount', getU32Encoder()], ]), (value) => ({ ...value, discriminator: INDEX_DEMOCRACY_PTR_REGISTRY_DISCRIMINATOR, }), ); } export function getIndexDemocracyPtrRegistryInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['systemId', getU16Decoder()], ['expectedRegistryCount', getU32Decoder()], ]); } export function getIndexDemocracyPtrRegistryInstructionDataCodec(): FixedSizeCodec< IndexDemocracyPtrRegistryInstructionDataArgs, IndexDemocracyPtrRegistryInstructionData > { return combineCodec( getIndexDemocracyPtrRegistryInstructionDataEncoder(), getIndexDemocracyPtrRegistryInstructionDataDecoder(), ); } export type IndexDemocracyPtrRegistryInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountRegistry extends string = string, TAccountEntry extends string = string, TAccountMember extends string = string, TAccountSystemProgram extends string = string, > = { funder: TransactionSigner; game: Address; catalog: Address; registry: Address; entry: Address; member: Address; systemProgram?: Address; systemId: IndexDemocracyPtrRegistryInstructionDataArgs['systemId']; expectedRegistryCount: IndexDemocracyPtrRegistryInstructionDataArgs['expectedRegistryCount']; }; export function getIndexDemocracyPtrRegistryInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountCatalog extends string, TAccountRegistry extends string, TAccountEntry extends string, TAccountMember extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: IndexDemocracyPtrRegistryInput< TAccountFunder, TAccountGame, TAccountCatalog, TAccountRegistry, TAccountEntry, TAccountMember, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): IndexDemocracyPtrRegistryInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountRegistry, TAccountEntry, TAccountMember, 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 }, registry: { value: input.registry ?? null, isWritable: false }, entry: { value: input.entry ?? null, isWritable: true }, member: { value: input.member ?? 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('registry', accounts.registry), getAccountMeta('entry', accounts.entry), getAccountMeta('member', accounts.member), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getIndexDemocracyPtrRegistryInstructionDataEncoder().encode( args as IndexDemocracyPtrRegistryInstructionDataArgs, ), programAddress, } as IndexDemocracyPtrRegistryInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountRegistry, TAccountEntry, TAccountMember, TAccountSystemProgram >); } export type ParsedIndexDemocracyPtrRegistryInstruction< 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]; registry: TAccountMetas[3]; entry: TAccountMetas[4]; member: TAccountMetas[5]; systemProgram: TAccountMetas[6]; }; data: IndexDemocracyPtrRegistryInstructionData; }; export function parseIndexDemocracyPtrRegistryInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedIndexDemocracyPtrRegistryInstruction { if (instruction.accounts.length < 7) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 7, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), game: getNextAccount(), catalog: getNextAccount(), registry: getNextAccount(), entry: getNextAccount(), member: getNextAccount(), systemProgram: getNextAccount(), }, data: getIndexDemocracyPtrRegistryInstructionDataDecoder().decode( instruction.data, ), }; }