/** * 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, getU64Decoder, getU64Encoder, 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'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const INIT_LOYALTY_EPOCH_DISCRIMINATOR = new Uint8Array([ 119, 252, 142, 88, 23, 159, 229, 35, ]); export function getInitLoyaltyEpochDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INIT_LOYALTY_EPOCH_DISCRIMINATOR, ); } export type InitLoyaltyEpochInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountRegistry extends string | AccountMeta = string, TAccountActiveConfig extends string | AccountMeta = string, TAccountLoyaltyEpoch 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, TAccountRegistry extends string ? ReadonlyAccount : TAccountRegistry, TAccountActiveConfig extends string ? ReadonlyAccount : TAccountActiveConfig, TAccountLoyaltyEpoch extends string ? WritableAccount : TAccountLoyaltyEpoch, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type InitLoyaltyEpochInstructionData = { discriminator: ReadonlyUint8Array; factionId: MinorFactionId; epochIndex: bigint; }; export type InitLoyaltyEpochInstructionDataArgs = { factionId: MinorFactionIdArgs; epochIndex: number | bigint; }; export function getInitLoyaltyEpochInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['factionId', getMinorFactionIdEncoder()], ['epochIndex', getU64Encoder()], ]), (value) => ({ ...value, discriminator: INIT_LOYALTY_EPOCH_DISCRIMINATOR }), ); } export function getInitLoyaltyEpochInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['factionId', getMinorFactionIdDecoder()], ['epochIndex', getU64Decoder()], ]); } export function getInitLoyaltyEpochInstructionDataCodec(): FixedSizeCodec< InitLoyaltyEpochInstructionDataArgs, InitLoyaltyEpochInstructionData > { return combineCodec( getInitLoyaltyEpochInstructionDataEncoder(), getInitLoyaltyEpochInstructionDataDecoder(), ); } export type InitLoyaltyEpochInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountRegistry extends string = string, TAccountActiveConfig extends string = string, TAccountLoyaltyEpoch extends string = string, TAccountSystemProgram extends string = string, > = { funder: TransactionSigner; game: Address; registry: Address; /** PDA-checked against the registry's active version in `process`. */ activeConfig: Address; loyaltyEpoch: Address; systemProgram?: Address; factionId: InitLoyaltyEpochInstructionDataArgs['factionId']; epochIndex: InitLoyaltyEpochInstructionDataArgs['epochIndex']; }; export function getInitLoyaltyEpochInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountRegistry extends string, TAccountActiveConfig extends string, TAccountLoyaltyEpoch extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: InitLoyaltyEpochInput< TAccountFunder, TAccountGame, TAccountRegistry, TAccountActiveConfig, TAccountLoyaltyEpoch, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): InitLoyaltyEpochInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountRegistry, TAccountActiveConfig, TAccountLoyaltyEpoch, 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 }, registry: { value: input.registry ?? null, isWritable: false }, activeConfig: { value: input.activeConfig ?? null, isWritable: false }, loyaltyEpoch: { value: input.loyaltyEpoch ?? 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('registry', accounts.registry), getAccountMeta('activeConfig', accounts.activeConfig), getAccountMeta('loyaltyEpoch', accounts.loyaltyEpoch), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getInitLoyaltyEpochInstructionDataEncoder().encode( args as InitLoyaltyEpochInstructionDataArgs, ), programAddress, } as InitLoyaltyEpochInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountRegistry, TAccountActiveConfig, TAccountLoyaltyEpoch, TAccountSystemProgram >); } export type ParsedInitLoyaltyEpochInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { funder: TAccountMetas[0]; game: TAccountMetas[1]; registry: TAccountMetas[2]; /** PDA-checked against the registry's active version in `process`. */ activeConfig: TAccountMetas[3]; loyaltyEpoch: TAccountMetas[4]; systemProgram: TAccountMetas[5]; }; data: InitLoyaltyEpochInstructionData; }; export function parseInitLoyaltyEpochInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitLoyaltyEpochInstruction { 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; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), game: getNextAccount(), registry: getNextAccount(), activeConfig: getNextAccount(), loyaltyEpoch: getNextAccount(), systemProgram: getNextAccount(), }, data: getInitLoyaltyEpochInstructionDataDecoder().decode(instruction.data), }; }