/** * 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, 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 RECONCILE_KING_SYSTEM_DISCRIMINATOR = new Uint8Array([ 146, 232, 95, 197, 82, 227, 228, 135, ]); export function getReconcileKingSystemDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( RECONCILE_KING_SYSTEM_DISCRIMINATOR, ); } export type ReconcileKingSystemInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountRewardRegistry extends string | AccountMeta = string, TAccountRewardConfig extends string | AccountMeta = string, TAccountStarSystem extends string | AccountMeta = string, TAccountOwnership extends string | AccountMeta = string, TAccountTracker extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountRewardRegistry extends string ? ReadonlyAccount : TAccountRewardRegistry, TAccountRewardConfig extends string ? ReadonlyAccount : TAccountRewardConfig, TAccountStarSystem extends string ? ReadonlyAccount : TAccountStarSystem, TAccountOwnership extends string ? ReadonlyAccount : TAccountOwnership, TAccountTracker extends string ? WritableAccount : TAccountTracker, ...TRemainingAccounts, ] >; export type ReconcileKingSystemInstructionData = { discriminator: ReadonlyUint8Array; }; export type ReconcileKingSystemInstructionDataArgs = {}; export function getReconcileKingSystemInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: RECONCILE_KING_SYSTEM_DISCRIMINATOR, }), ); } export function getReconcileKingSystemInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getReconcileKingSystemInstructionDataCodec(): FixedSizeCodec< ReconcileKingSystemInstructionDataArgs, ReconcileKingSystemInstructionData > { return combineCodec( getReconcileKingSystemInstructionDataEncoder(), getReconcileKingSystemInstructionDataDecoder(), ); } export type ReconcileKingSystemInput< TAccountGame extends string = string, TAccountRewardRegistry extends string = string, TAccountRewardConfig extends string = string, TAccountStarSystem extends string = string, TAccountOwnership extends string = string, TAccountTracker extends string = string, > = { game: Address; rewardRegistry: Address; rewardConfig: Address; starSystem: Address; ownership?: Address; tracker: Address; }; export function getReconcileKingSystemInstruction< TAccountGame extends string, TAccountRewardRegistry extends string, TAccountRewardConfig extends string, TAccountStarSystem extends string, TAccountOwnership extends string, TAccountTracker extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ReconcileKingSystemInput< TAccountGame, TAccountRewardRegistry, TAccountRewardConfig, TAccountStarSystem, TAccountOwnership, TAccountTracker >, config?: { programAddress?: TProgramAddress }, ): ReconcileKingSystemInstruction< TProgramAddress, TAccountGame, TAccountRewardRegistry, TAccountRewardConfig, TAccountStarSystem, TAccountOwnership, TAccountTracker > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, rewardRegistry: { value: input.rewardRegistry ?? null, isWritable: false }, rewardConfig: { value: input.rewardConfig ?? null, isWritable: false }, starSystem: { value: input.starSystem ?? null, isWritable: false }, ownership: { value: input.ownership ?? null, isWritable: false }, tracker: { value: input.tracker ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('rewardRegistry', accounts.rewardRegistry), getAccountMeta('rewardConfig', accounts.rewardConfig), getAccountMeta('starSystem', accounts.starSystem), getAccountMeta('ownership', accounts.ownership), getAccountMeta('tracker', accounts.tracker), ], data: getReconcileKingSystemInstructionDataEncoder().encode({}), programAddress, } as ReconcileKingSystemInstruction< TProgramAddress, TAccountGame, TAccountRewardRegistry, TAccountRewardConfig, TAccountStarSystem, TAccountOwnership, TAccountTracker >); } export type ParsedReconcileKingSystemInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; rewardRegistry: TAccountMetas[1]; rewardConfig: TAccountMetas[2]; starSystem: TAccountMetas[3]; ownership?: TAccountMetas[4] | undefined; tracker: TAccountMetas[5]; }; data: ReconcileKingSystemInstructionData; }; export function parseReconcileKingSystemInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedReconcileKingSystemInstruction { 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(), rewardRegistry: getNextAccount(), rewardConfig: getNextAccount(), starSystem: getNextAccount(), ownership: getNextOptionalAccount(), tracker: getNextAccount(), }, data: getReconcileKingSystemInstructionDataDecoder().decode( instruction.data, ), }; }