/** * 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 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'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const SWEEP_LOYALTY_EPOCH_DISCRIMINATOR = new Uint8Array([ 33, 58, 217, 102, 243, 231, 183, 126, ]); export function getSweepLoyaltyEpochDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SWEEP_LOYALTY_EPOCH_DISCRIMINATOR, ); } export type SweepLoyaltyEpochInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountEpoch extends string | AccountMeta = string, TAccountTreasury extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountEpoch extends string ? WritableAccount : TAccountEpoch, TAccountTreasury extends string ? WritableAccount : TAccountTreasury, ...TRemainingAccounts, ] >; export type SweepLoyaltyEpochInstructionData = { discriminator: ReadonlyUint8Array; factionId: MinorFactionId; epochIndex: bigint; }; export type SweepLoyaltyEpochInstructionDataArgs = { factionId: MinorFactionIdArgs; epochIndex: number | bigint; }; export function getSweepLoyaltyEpochInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['factionId', getMinorFactionIdEncoder()], ['epochIndex', getU64Encoder()], ]), (value) => ({ ...value, discriminator: SWEEP_LOYALTY_EPOCH_DISCRIMINATOR }), ); } export function getSweepLoyaltyEpochInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['factionId', getMinorFactionIdDecoder()], ['epochIndex', getU64Decoder()], ]); } export function getSweepLoyaltyEpochInstructionDataCodec(): FixedSizeCodec< SweepLoyaltyEpochInstructionDataArgs, SweepLoyaltyEpochInstructionData > { return combineCodec( getSweepLoyaltyEpochInstructionDataEncoder(), getSweepLoyaltyEpochInstructionDataDecoder(), ); } export type SweepLoyaltyEpochInput< TAccountGame extends string = string, TAccountEpoch extends string = string, TAccountTreasury extends string = string, > = { game: Address; epoch: Address; treasury: Address; factionId: SweepLoyaltyEpochInstructionDataArgs['factionId']; epochIndex: SweepLoyaltyEpochInstructionDataArgs['epochIndex']; }; export function getSweepLoyaltyEpochInstruction< TAccountGame extends string, TAccountEpoch extends string, TAccountTreasury extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SweepLoyaltyEpochInput, config?: { programAddress?: TProgramAddress }, ): SweepLoyaltyEpochInstruction< TProgramAddress, TAccountGame, TAccountEpoch, TAccountTreasury > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, epoch: { value: input.epoch ?? null, isWritable: true }, treasury: { value: input.treasury ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('epoch', accounts.epoch), getAccountMeta('treasury', accounts.treasury), ], data: getSweepLoyaltyEpochInstructionDataEncoder().encode( args as SweepLoyaltyEpochInstructionDataArgs, ), programAddress, } as SweepLoyaltyEpochInstruction< TProgramAddress, TAccountGame, TAccountEpoch, TAccountTreasury >); } export type ParsedSweepLoyaltyEpochInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; epoch: TAccountMetas[1]; treasury: TAccountMetas[2]; }; data: SweepLoyaltyEpochInstructionData; }; export function parseSweepLoyaltyEpochInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSweepLoyaltyEpochInstruction { if (instruction.accounts.length < 3) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), epoch: getNextAccount(), treasury: getNextAccount(), }, data: getSweepLoyaltyEpochInstructionDataDecoder().decode(instruction.data), }; }