/** * 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 { AccountRole, combineCodec, fixDecoderSize, fixEncoderSize, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, 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 STEP_RENT_SETTLEMENT_DISCRIMINATOR = new Uint8Array([ 78, 174, 172, 127, 216, 49, 14, 158, ]); export function getStepRentSettlementDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( STEP_RENT_SETTLEMENT_DISCRIMINATOR, ); } export type StepRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountCatalog extends string | AccountMeta = string, TAccountStake extends string | AccountMeta = string, TAccountAuthority extends string | AccountMeta = string, TAccountEval extends string | AccountMeta = string, TAccountGridHead extends string | AccountMeta = string, TAccountLevelHead extends string | AccountMeta = string, TAccountDefHead extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountCatalog extends string ? ReadonlyAccount : TAccountCatalog, TAccountStake extends string ? ReadonlyAccount : TAccountStake, TAccountAuthority extends string ? ReadonlyAccount : TAccountAuthority, TAccountEval extends string ? WritableAccount : TAccountEval, TAccountGridHead extends string ? ReadonlyAccount : TAccountGridHead, TAccountLevelHead extends string ? ReadonlyAccount : TAccountLevelHead, TAccountDefHead extends string ? ReadonlyAccount : TAccountDefHead, ...TRemainingAccounts, ] >; export type StepRentSettlementInstructionData = { discriminator: ReadonlyUint8Array; nonce: bigint; budget: number; hints: Array; }; export type StepRentSettlementInstructionDataArgs = { nonce: number | bigint; budget: number; hints: Array; }; export function getStepRentSettlementInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['nonce', getU64Encoder()], ['budget', getU16Encoder()], ['hints', getArrayEncoder(getU32Encoder(), { size: 3 })], ]), (value) => ({ ...value, discriminator: STEP_RENT_SETTLEMENT_DISCRIMINATOR, }), ); } export function getStepRentSettlementInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['nonce', getU64Decoder()], ['budget', getU16Decoder()], ['hints', getArrayDecoder(getU32Decoder(), { size: 3 })], ]); } export function getStepRentSettlementInstructionDataCodec(): FixedSizeCodec< StepRentSettlementInstructionDataArgs, StepRentSettlementInstructionData > { return combineCodec( getStepRentSettlementInstructionDataEncoder(), getStepRentSettlementInstructionDataDecoder(), ); } export type StepRentSettlementInput< TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountStake extends string = string, TAccountAuthority extends string = string, TAccountEval extends string = string, TAccountGridHead extends string = string, TAccountLevelHead extends string = string, TAccountDefHead extends string = string, > = { game: Address; catalog: Address; stake: Address; authority: Address; eval: Address; gridHead: Address; levelHead: Address; defHead: Address; nonce: StepRentSettlementInstructionDataArgs['nonce']; budget: StepRentSettlementInstructionDataArgs['budget']; hints: StepRentSettlementInstructionDataArgs['hints']; pages: Array
; }; export function getStepRentSettlementInstruction< TAccountGame extends string, TAccountCatalog extends string, TAccountStake extends string, TAccountAuthority extends string, TAccountEval extends string, TAccountGridHead extends string, TAccountLevelHead extends string, TAccountDefHead extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: StepRentSettlementInput< TAccountGame, TAccountCatalog, TAccountStake, TAccountAuthority, TAccountEval, TAccountGridHead, TAccountLevelHead, TAccountDefHead >, config?: { programAddress?: TProgramAddress }, ): StepRentSettlementInstruction< TProgramAddress, TAccountGame, TAccountCatalog, TAccountStake, TAccountAuthority, TAccountEval, TAccountGridHead, TAccountLevelHead, TAccountDefHead > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, catalog: { value: input.catalog ?? null, isWritable: false }, stake: { value: input.stake ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: false }, eval: { value: input.eval ?? null, isWritable: true }, gridHead: { value: input.gridHead ?? null, isWritable: false }, levelHead: { value: input.levelHead ?? null, isWritable: false }, defHead: { value: input.defHead ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Remaining accounts. const remainingAccounts: AccountMeta[] = args.pages.map((address) => ({ address, role: AccountRole.READONLY, })); const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('catalog', accounts.catalog), getAccountMeta('stake', accounts.stake), getAccountMeta('authority', accounts.authority), getAccountMeta('eval', accounts.eval), getAccountMeta('gridHead', accounts.gridHead), getAccountMeta('levelHead', accounts.levelHead), getAccountMeta('defHead', accounts.defHead), ...remainingAccounts, ], data: getStepRentSettlementInstructionDataEncoder().encode( args as StepRentSettlementInstructionDataArgs, ), programAddress, } as StepRentSettlementInstruction< TProgramAddress, TAccountGame, TAccountCatalog, TAccountStake, TAccountAuthority, TAccountEval, TAccountGridHead, TAccountLevelHead, TAccountDefHead >); } export type ParsedStepRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { game: TAccountMetas[0]; catalog: TAccountMetas[1]; stake: TAccountMetas[2]; authority: TAccountMetas[3]; eval: TAccountMetas[4]; gridHead: TAccountMetas[5]; levelHead: TAccountMetas[6]; defHead: TAccountMetas[7]; }; data: StepRentSettlementInstructionData; }; export function parseStepRentSettlementInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedStepRentSettlementInstruction { if (instruction.accounts.length < 8) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), catalog: getNextAccount(), stake: getNextAccount(), authority: getNextAccount(), eval: getNextAccount(), gridHead: getNextAccount(), levelHead: getNextAccount(), defHead: getNextAccount(), }, data: getStepRentSettlementInstructionDataDecoder().decode( instruction.data, ), }; }