/** * 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, getU16Decoder, getU16Encoder, 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 CLOSE_LOCAL_MARKET_DISCRIMINATOR = new Uint8Array([ 116, 128, 134, 146, 205, 92, 4, 202, ]); export function getCloseLocalMarketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CLOSE_LOCAL_MARKET_DISCRIMINATOR, ); } export type CloseLocalMarketInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMarketInitializer extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountLocalMarket extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountMarketInitializer extends string ? WritableAccount : TAccountMarketInitializer, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountLocalMarket extends string ? WritableAccount : TAccountLocalMarket, ...TRemainingAccounts, ] >; export type CloseLocalMarketInstructionData = { discriminator: ReadonlyUint8Array; keyIndex: number; }; export type CloseLocalMarketInstructionDataArgs = { keyIndex: number }; export function getCloseLocalMarketInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ]), (value) => ({ ...value, discriminator: CLOSE_LOCAL_MARKET_DISCRIMINATOR }), ); } export function getCloseLocalMarketInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ]); } export function getCloseLocalMarketInstructionDataCodec(): FixedSizeCodec< CloseLocalMarketInstructionDataArgs, CloseLocalMarketInstructionData > { return combineCodec( getCloseLocalMarketInstructionDataEncoder(), getCloseLocalMarketInstructionDataDecoder(), ); } export type CloseLocalMarketInput< TAccountMarketInitializer extends string = string, TAccountGame extends string = string, TAccountSystem extends string = string, TAccountLocalMarket extends string = string, > = { /** The profile that initialized the local market and will receive the rent */ marketInitializer: Address; /** The game account */ game: Address; /** The starbase account */ system: Address; /** The local market to clean up */ localMarket: Address; keyIndex: CloseLocalMarketInstructionDataArgs['keyIndex']; }; export function getCloseLocalMarketInstruction< TAccountMarketInitializer extends string, TAccountGame extends string, TAccountSystem extends string, TAccountLocalMarket extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CloseLocalMarketInput< TAccountMarketInitializer, TAccountGame, TAccountSystem, TAccountLocalMarket >, config?: { programAddress?: TProgramAddress }, ): CloseLocalMarketInstruction< TProgramAddress, TAccountMarketInitializer, TAccountGame, TAccountSystem, TAccountLocalMarket > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { marketInitializer: { value: input.marketInitializer ?? null, isWritable: true, }, game: { value: input.game ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, localMarket: { value: input.localMarket ?? 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('marketInitializer', accounts.marketInitializer), getAccountMeta('game', accounts.game), getAccountMeta('system', accounts.system), getAccountMeta('localMarket', accounts.localMarket), ], data: getCloseLocalMarketInstructionDataEncoder().encode( args as CloseLocalMarketInstructionDataArgs, ), programAddress, } as CloseLocalMarketInstruction< TProgramAddress, TAccountMarketInitializer, TAccountGame, TAccountSystem, TAccountLocalMarket >); } export type ParsedCloseLocalMarketInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The profile that initialized the local market and will receive the rent */ marketInitializer: TAccountMetas[0]; /** The game account */ game: TAccountMetas[1]; /** The starbase account */ system: TAccountMetas[2]; /** The local market to clean up */ localMarket: TAccountMetas[3]; }; data: CloseLocalMarketInstructionData; }; export function parseCloseLocalMarketInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCloseLocalMarketInstruction { 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: { marketInitializer: getNextAccount(), game: getNextAccount(), system: getNextAccount(), localMarket: getNextAccount(), }, data: getCloseLocalMarketInstructionDataDecoder().decode(instruction.data), }; }