/** * 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'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const SWEEP_EXPIRED_LOYALTY_ATLAS_BANK_DISCRIMINATOR = new Uint8Array([ 166, 255, 19, 94, 50, 36, 180, 31, ]); export function getSweepExpiredLoyaltyAtlasBankDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SWEEP_EXPIRED_LOYALTY_ATLAS_BANK_DISCRIMINATOR, ); } export type SweepExpiredLoyaltyAtlasBankInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountBank extends string | AccountMeta = string, TAccountTreasury extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountProfile extends string ? ReadonlyAccount : TAccountProfile, TAccountBank extends string ? WritableAccount : TAccountBank, TAccountTreasury extends string ? WritableAccount : TAccountTreasury, ...TRemainingAccounts, ] >; export type SweepExpiredLoyaltyAtlasBankInstructionData = { discriminator: ReadonlyUint8Array; factionId: MinorFactionId; }; export type SweepExpiredLoyaltyAtlasBankInstructionDataArgs = { factionId: MinorFactionIdArgs; }; export function getSweepExpiredLoyaltyAtlasBankInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['factionId', getMinorFactionIdEncoder()], ]), (value) => ({ ...value, discriminator: SWEEP_EXPIRED_LOYALTY_ATLAS_BANK_DISCRIMINATOR, }), ); } export function getSweepExpiredLoyaltyAtlasBankInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['factionId', getMinorFactionIdDecoder()], ]); } export function getSweepExpiredLoyaltyAtlasBankInstructionDataCodec(): FixedSizeCodec< SweepExpiredLoyaltyAtlasBankInstructionDataArgs, SweepExpiredLoyaltyAtlasBankInstructionData > { return combineCodec( getSweepExpiredLoyaltyAtlasBankInstructionDataEncoder(), getSweepExpiredLoyaltyAtlasBankInstructionDataDecoder(), ); } export type SweepExpiredLoyaltyAtlasBankInput< TAccountGame extends string = string, TAccountProfile extends string = string, TAccountBank extends string = string, TAccountTreasury extends string = string, > = { game: Address; profile: Address; bank: Address; treasury: Address; factionId: SweepExpiredLoyaltyAtlasBankInstructionDataArgs['factionId']; }; export function getSweepExpiredLoyaltyAtlasBankInstruction< TAccountGame extends string, TAccountProfile extends string, TAccountBank extends string, TAccountTreasury extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SweepExpiredLoyaltyAtlasBankInput< TAccountGame, TAccountProfile, TAccountBank, TAccountTreasury >, config?: { programAddress?: TProgramAddress }, ): SweepExpiredLoyaltyAtlasBankInstruction< TProgramAddress, TAccountGame, TAccountProfile, TAccountBank, TAccountTreasury > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, profile: { value: input.profile ?? null, isWritable: false }, bank: { value: input.bank ?? 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('profile', accounts.profile), getAccountMeta('bank', accounts.bank), getAccountMeta('treasury', accounts.treasury), ], data: getSweepExpiredLoyaltyAtlasBankInstructionDataEncoder().encode( args as SweepExpiredLoyaltyAtlasBankInstructionDataArgs, ), programAddress, } as SweepExpiredLoyaltyAtlasBankInstruction< TProgramAddress, TAccountGame, TAccountProfile, TAccountBank, TAccountTreasury >); } export type ParsedSweepExpiredLoyaltyAtlasBankInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; profile: TAccountMetas[1]; bank: TAccountMetas[2]; treasury: TAccountMetas[3]; }; data: SweepExpiredLoyaltyAtlasBankInstructionData; }; export function parseSweepExpiredLoyaltyAtlasBankInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSweepExpiredLoyaltyAtlasBankInstruction { if (instruction.accounts.length < 4) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 4, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), profile: getNextAccount(), bank: getNextAccount(), treasury: getNextAccount(), }, data: getSweepExpiredLoyaltyAtlasBankInstructionDataDecoder().decode( instruction.data, ), }; }