/** * 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 SWEEP_EXPIRED_COMBAT_REWARD_LOOT_DISCRIMINATOR = new Uint8Array([ 128, 207, 120, 6, 21, 111, 42, 161, ]); export function getSweepExpiredCombatRewardLootDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SWEEP_EXPIRED_COMBAT_REWARD_LOOT_DISCRIMINATOR, ); } export type SweepExpiredCombatRewardLootInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountLoot extends string | AccountMeta = string, TAccountTreasury extends string | AccountMeta = string, TAccountLootCreator extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountLoot extends string ? WritableAccount : TAccountLoot, TAccountTreasury extends string ? WritableAccount : TAccountTreasury, TAccountLootCreator extends string ? WritableAccount : TAccountLootCreator, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type SweepExpiredCombatRewardLootInstructionData = { discriminator: ReadonlyUint8Array; }; export type SweepExpiredCombatRewardLootInstructionDataArgs = {}; export function getSweepExpiredCombatRewardLootInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: SWEEP_EXPIRED_COMBAT_REWARD_LOOT_DISCRIMINATOR, }), ); } export function getSweepExpiredCombatRewardLootInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getSweepExpiredCombatRewardLootInstructionDataCodec(): FixedSizeCodec< SweepExpiredCombatRewardLootInstructionDataArgs, SweepExpiredCombatRewardLootInstructionData > { return combineCodec( getSweepExpiredCombatRewardLootInstructionDataEncoder(), getSweepExpiredCombatRewardLootInstructionDataDecoder(), ); } export type SweepExpiredCombatRewardLootInput< TAccountGame extends string = string, TAccountLoot extends string = string, TAccountTreasury extends string = string, TAccountLootCreator extends string = string, TAccountSystemProgram extends string = string, > = { game: Address; loot: Address; treasury: Address; /** Original Loot creator; receives rent if all ordinary/reward items are gone. */ lootCreator: Address; systemProgram?: Address; }; export function getSweepExpiredCombatRewardLootInstruction< TAccountGame extends string, TAccountLoot extends string, TAccountTreasury extends string, TAccountLootCreator extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SweepExpiredCombatRewardLootInput< TAccountGame, TAccountLoot, TAccountTreasury, TAccountLootCreator, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): SweepExpiredCombatRewardLootInstruction< TProgramAddress, TAccountGame, TAccountLoot, TAccountTreasury, TAccountLootCreator, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, loot: { value: input.loot ?? null, isWritable: true }, treasury: { value: input.treasury ?? null, isWritable: true }, lootCreator: { value: input.lootCreator ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('loot', accounts.loot), getAccountMeta('treasury', accounts.treasury), getAccountMeta('lootCreator', accounts.lootCreator), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getSweepExpiredCombatRewardLootInstructionDataEncoder().encode({}), programAddress, } as SweepExpiredCombatRewardLootInstruction< TProgramAddress, TAccountGame, TAccountLoot, TAccountTreasury, TAccountLootCreator, TAccountSystemProgram >); } export type ParsedSweepExpiredCombatRewardLootInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; loot: TAccountMetas[1]; treasury: TAccountMetas[2]; /** Original Loot creator; receives rent if all ordinary/reward items are gone. */ lootCreator: TAccountMetas[3]; systemProgram: TAccountMetas[4]; }; data: SweepExpiredCombatRewardLootInstructionData; }; export function parseSweepExpiredCombatRewardLootInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSweepExpiredCombatRewardLootInstruction { if (instruction.accounts.length < 5) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), loot: getNextAccount(), treasury: getNextAccount(), lootCreator: getNextAccount(), systemProgram: getNextAccount(), }, data: getSweepExpiredCombatRewardLootInstructionDataDecoder().decode( instruction.data, ), }; }