/** * 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, getU64Decoder, getU64Encoder, 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 RETIRE_STALE_RENT_SETTLEMENT_DISCRIMINATOR = new Uint8Array([ 76, 150, 185, 138, 22, 135, 252, 35, ]); export function getRetireStaleRentSettlementDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( RETIRE_STALE_RENT_SETTLEMENT_DISCRIMINATOR, ); } export type RetireStaleRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountStake extends string | AccountMeta = string, TAccountAuthority extends string | AccountMeta = string, TAccountEval extends string | AccountMeta = string, TAccountRefund extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountStake extends string ? ReadonlyAccount : TAccountStake, TAccountAuthority extends string ? WritableAccount : TAccountAuthority, TAccountEval extends string ? WritableAccount : TAccountEval, TAccountRefund extends string ? WritableAccount : TAccountRefund, ...TRemainingAccounts, ] >; export type RetireStaleRentSettlementInstructionData = { discriminator: ReadonlyUint8Array; nonce: bigint; }; export type RetireStaleRentSettlementInstructionDataArgs = { nonce: number | bigint; }; export function getRetireStaleRentSettlementInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['nonce', getU64Encoder()], ]), (value) => ({ ...value, discriminator: RETIRE_STALE_RENT_SETTLEMENT_DISCRIMINATOR, }), ); } export function getRetireStaleRentSettlementInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['nonce', getU64Decoder()], ]); } export function getRetireStaleRentSettlementInstructionDataCodec(): FixedSizeCodec< RetireStaleRentSettlementInstructionDataArgs, RetireStaleRentSettlementInstructionData > { return combineCodec( getRetireStaleRentSettlementInstructionDataEncoder(), getRetireStaleRentSettlementInstructionDataDecoder(), ); } export type RetireStaleRentSettlementInput< TAccountGame extends string = string, TAccountStake extends string = string, TAccountAuthority extends string = string, TAccountEval extends string = string, TAccountRefund extends string = string, > = { game: Address; /** The stake ADDRESS the authority belongs to — it may have been closed (or closed and re-created). */ stake: Address; authority: Address; eval: Address; /** The Eval's original funder. */ refund: Address; nonce: RetireStaleRentSettlementInstructionDataArgs['nonce']; }; export function getRetireStaleRentSettlementInstruction< TAccountGame extends string, TAccountStake extends string, TAccountAuthority extends string, TAccountEval extends string, TAccountRefund extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: RetireStaleRentSettlementInput< TAccountGame, TAccountStake, TAccountAuthority, TAccountEval, TAccountRefund >, config?: { programAddress?: TProgramAddress }, ): RetireStaleRentSettlementInstruction< TProgramAddress, TAccountGame, TAccountStake, TAccountAuthority, TAccountEval, TAccountRefund > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, stake: { value: input.stake ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: true }, eval: { value: input.eval ?? null, isWritable: true }, refund: { value: input.refund ?? 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('stake', accounts.stake), getAccountMeta('authority', accounts.authority), getAccountMeta('eval', accounts.eval), getAccountMeta('refund', accounts.refund), ], data: getRetireStaleRentSettlementInstructionDataEncoder().encode( args as RetireStaleRentSettlementInstructionDataArgs, ), programAddress, } as RetireStaleRentSettlementInstruction< TProgramAddress, TAccountGame, TAccountStake, TAccountAuthority, TAccountEval, TAccountRefund >); } export type ParsedRetireStaleRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; /** The stake ADDRESS the authority belongs to — it may have been closed (or closed and re-created). */ stake: TAccountMetas[1]; authority: TAccountMetas[2]; eval: TAccountMetas[3]; /** The Eval's original funder. */ refund: TAccountMetas[4]; }; data: RetireStaleRentSettlementInstructionData; }; export function parseRetireStaleRentSettlementInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRetireStaleRentSettlementInstruction { 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(), stake: getNextAccount(), authority: getNextAccount(), eval: getNextAccount(), refund: getNextAccount(), }, data: getRetireStaleRentSettlementInstructionDataDecoder().decode( instruction.data, ), }; }