/** * 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 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_ATLAS_BANK_DISCRIMINATOR = new Uint8Array([ 112, 99, 251, 142, 134, 48, 222, 183, ]); export function getInitLoyaltyAtlasBankDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INIT_LOYALTY_ATLAS_BANK_DISCRIMINATOR, ); } export type InitLoyaltyAtlasBankInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountBank 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, TAccountProfile extends string ? ReadonlyAccount : TAccountProfile, TAccountBank extends string ? WritableAccount : TAccountBank, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type InitLoyaltyAtlasBankInstructionData = { discriminator: ReadonlyUint8Array; factionId: MinorFactionId; }; export type InitLoyaltyAtlasBankInstructionDataArgs = { factionId: MinorFactionIdArgs; }; export function getInitLoyaltyAtlasBankInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['factionId', getMinorFactionIdEncoder()], ]), (value) => ({ ...value, discriminator: INIT_LOYALTY_ATLAS_BANK_DISCRIMINATOR, }), ); } export function getInitLoyaltyAtlasBankInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['factionId', getMinorFactionIdDecoder()], ]); } export function getInitLoyaltyAtlasBankInstructionDataCodec(): FixedSizeCodec< InitLoyaltyAtlasBankInstructionDataArgs, InitLoyaltyAtlasBankInstructionData > { return combineCodec( getInitLoyaltyAtlasBankInstructionDataEncoder(), getInitLoyaltyAtlasBankInstructionDataDecoder(), ); } export type InitLoyaltyAtlasBankInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountProfile extends string = string, TAccountBank extends string = string, TAccountSystemProgram extends string = string, > = { funder: TransactionSigner; game: Address; profile: Address; bank: Address; systemProgram?: Address; factionId: InitLoyaltyAtlasBankInstructionDataArgs['factionId']; }; export function getInitLoyaltyAtlasBankInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountProfile extends string, TAccountBank extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: InitLoyaltyAtlasBankInput< TAccountFunder, TAccountGame, TAccountProfile, TAccountBank, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): InitLoyaltyAtlasBankInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountProfile, TAccountBank, 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 }, profile: { value: input.profile ?? null, isWritable: false }, bank: { value: input.bank ?? 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('profile', accounts.profile), getAccountMeta('bank', accounts.bank), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getInitLoyaltyAtlasBankInstructionDataEncoder().encode( args as InitLoyaltyAtlasBankInstructionDataArgs, ), programAddress, } as InitLoyaltyAtlasBankInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountProfile, TAccountBank, TAccountSystemProgram >); } export type ParsedInitLoyaltyAtlasBankInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { funder: TAccountMetas[0]; game: TAccountMetas[1]; profile: TAccountMetas[2]; bank: TAccountMetas[3]; systemProgram: TAccountMetas[4]; }; data: InitLoyaltyAtlasBankInstructionData; }; export function parseInitLoyaltyAtlasBankInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitLoyaltyAtlasBankInstruction { 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: { funder: getNextAccount(), game: getNextAccount(), profile: getNextAccount(), bank: getNextAccount(), systemProgram: getNextAccount(), }, data: getInitLoyaltyAtlasBankInstructionDataDecoder().decode( instruction.data, ), }; }