/** * 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 REAP_EXPIRED_MARKET_DISCRIMINATOR = new Uint8Array([ 186, 120, 54, 25, 147, 107, 80, 86, ]); export function getReapExpiredMarketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( REAP_EXPIRED_MARKET_DISCRIMINATOR, ); } export type ReapExpiredMarketInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountEncounterMarket extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableAccount : TAccountFunder, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountEncounterMarket extends string ? WritableAccount : TAccountEncounterMarket, ...TRemainingAccounts, ] >; export type ReapExpiredMarketInstructionData = { discriminator: ReadonlyUint8Array; /** Unused — present only for interface parity with the other permissionless close instructions. */ keyIndex: number; }; export type ReapExpiredMarketInstructionDataArgs = { /** Unused — present only for interface parity with the other permissionless close instructions. */ keyIndex: number; }; export function getReapExpiredMarketInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ]), (value) => ({ ...value, discriminator: REAP_EXPIRED_MARKET_DISCRIMINATOR }), ); } export function getReapExpiredMarketInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ]); } export function getReapExpiredMarketInstructionDataCodec(): FixedSizeCodec< ReapExpiredMarketInstructionDataArgs, ReapExpiredMarketInstructionData > { return combineCodec( getReapExpiredMarketInstructionDataEncoder(), getReapExpiredMarketInstructionDataDecoder(), ); } export type ReapExpiredMarketInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountEncounterMarket extends string = string, > = { /** The Profile that funded the market at reveal; receives the rent refund (pinned by address). */ funder: Address; /** The game account (scopes the market). */ game: Address; /** The expired market to close; rent flows to `funder`. */ encounterMarket: Address; keyIndex: ReapExpiredMarketInstructionDataArgs['keyIndex']; }; export function getReapExpiredMarketInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountEncounterMarket extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ReapExpiredMarketInput< TAccountFunder, TAccountGame, TAccountEncounterMarket >, config?: { programAddress?: TProgramAddress }, ): ReapExpiredMarketInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountEncounterMarket > { // 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 }, encounterMarket: { value: input.encounterMarket ?? 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('funder', accounts.funder), getAccountMeta('game', accounts.game), getAccountMeta('encounterMarket', accounts.encounterMarket), ], data: getReapExpiredMarketInstructionDataEncoder().encode( args as ReapExpiredMarketInstructionDataArgs, ), programAddress, } as ReapExpiredMarketInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountEncounterMarket >); } export type ParsedReapExpiredMarketInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The Profile that funded the market at reveal; receives the rent refund (pinned by address). */ funder: TAccountMetas[0]; /** The game account (scopes the market). */ game: TAccountMetas[1]; /** The expired market to close; rent flows to `funder`. */ encounterMarket: TAccountMetas[2]; }; data: ReapExpiredMarketInstructionData; }; export function parseReapExpiredMarketInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedReapExpiredMarketInstruction { 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: { funder: getNextAccount(), game: getNextAccount(), encounterMarket: getNextAccount(), }, data: getReapExpiredMarketInstructionDataDecoder().decode(instruction.data), }; }