/** * 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, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, 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, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const COMMIT_INVALIDATED_RENT_SETTLEMENT_DISCRIMINATOR = new Uint8Array([ 174, 32, 119, 228, 182, 106, 181, 83, ]); export function getCommitInvalidatedRentSettlementDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( COMMIT_INVALIDATED_RENT_SETTLEMENT_DISCRIMINATOR, ); } export type CommitInvalidatedRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountCatalog extends string | AccountMeta = string, TAccountStake extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountCelestialBody extends string | AccountMeta = string, TAccountCurrencyCache 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< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountCatalog extends string ? ReadonlyAccount : TAccountCatalog, TAccountStake extends string ? WritableAccount : TAccountStake, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountCelestialBody extends string ? WritableAccount : TAccountCelestialBody, TAccountCurrencyCache extends string ? WritableAccount : TAccountCurrencyCache, TAccountAuthority extends string ? WritableAccount : TAccountAuthority, TAccountEval extends string ? WritableAccount : TAccountEval, TAccountRefund extends string ? WritableAccount : TAccountRefund, ...TRemainingAccounts, ] >; export type CommitInvalidatedRentSettlementInstructionData = { discriminator: ReadonlyUint8Array; nonce: bigint; }; export type CommitInvalidatedRentSettlementInstructionDataArgs = { nonce: number | bigint; }; export function getCommitInvalidatedRentSettlementInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['nonce', getU64Encoder()], ]), (value) => ({ ...value, discriminator: COMMIT_INVALIDATED_RENT_SETTLEMENT_DISCRIMINATOR, }), ); } export function getCommitInvalidatedRentSettlementInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['nonce', getU64Decoder()], ]); } export function getCommitInvalidatedRentSettlementInstructionDataCodec(): FixedSizeCodec< CommitInvalidatedRentSettlementInstructionDataArgs, CommitInvalidatedRentSettlementInstructionData > { return combineCodec( getCommitInvalidatedRentSettlementInstructionDataEncoder(), getCommitInvalidatedRentSettlementInstructionDataDecoder(), ); } export type CommitInvalidatedRentSettlementAsyncInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountStake extends string = string, TAccountSystem extends string = string, TAccountCelestialBody extends string = string, TAccountCurrencyCache extends string = string, TAccountAuthority extends string = string, TAccountEval extends string = string, TAccountRefund extends string = string, > = { /** The funder for any Solana rent payments (the body sync may resize it). */ funder: TransactionSigner; game: Address; catalog: Address; /** * The evicted stake — bound to the game and the body below, with NO starbase-sequence validation (its * system's sequence may have moved on), exactly as Begin binds it. */ stake: Address; system: Address; /** Writable: its validation runs the pinned planet sync (which records the eviction). */ celestialBody: Address; currencyCache?: Address; authority: Address; /** The evaluation being committed. Omitted only for a receipt replay (it was closed by the commit). */ eval?: Address; /** The Eval's funder (receives its rent when the Eval closes). */ refund: Address; nonce: CommitInvalidatedRentSettlementInstructionDataArgs['nonce']; }; export async function getCommitInvalidatedRentSettlementInstructionAsync< TAccountFunder extends string, TAccountGame extends string, TAccountCatalog extends string, TAccountStake extends string, TAccountSystem extends string, TAccountCelestialBody extends string, TAccountCurrencyCache extends string, TAccountAuthority extends string, TAccountEval extends string, TAccountRefund extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CommitInvalidatedRentSettlementAsyncInput< TAccountFunder, TAccountGame, TAccountCatalog, TAccountStake, TAccountSystem, TAccountCelestialBody, TAccountCurrencyCache, TAccountAuthority, TAccountEval, TAccountRefund >, config?: { programAddress?: TProgramAddress }, ): Promise< CommitInvalidatedRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountStake, TAccountSystem, TAccountCelestialBody, TAccountCurrencyCache, TAccountAuthority, TAccountEval, TAccountRefund > > { // 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 }, catalog: { value: input.catalog ?? null, isWritable: false }, stake: { value: input.stake ?? null, isWritable: true }, system: { value: input.system ?? null, isWritable: false }, celestialBody: { value: input.celestialBody ?? null, isWritable: true }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, 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 }; // Resolve default values. if (!accounts.currencyCache.value) { accounts.currencyCache.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([ 67, 117, 114, 114, 101, 110, 99, 121, 67, 111, 110, 102, 105, 103, ]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount('game', accounts.game.value), ), ], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('game', accounts.game), getAccountMeta('catalog', accounts.catalog), getAccountMeta('stake', accounts.stake), getAccountMeta('system', accounts.system), getAccountMeta('celestialBody', accounts.celestialBody), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('authority', accounts.authority), getAccountMeta('eval', accounts.eval), getAccountMeta('refund', accounts.refund), ], data: getCommitInvalidatedRentSettlementInstructionDataEncoder().encode( args as CommitInvalidatedRentSettlementInstructionDataArgs, ), programAddress, } as CommitInvalidatedRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountStake, TAccountSystem, TAccountCelestialBody, TAccountCurrencyCache, TAccountAuthority, TAccountEval, TAccountRefund >); } export type CommitInvalidatedRentSettlementInput< TAccountFunder extends string = string, TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountStake extends string = string, TAccountSystem extends string = string, TAccountCelestialBody extends string = string, TAccountCurrencyCache extends string = string, TAccountAuthority extends string = string, TAccountEval extends string = string, TAccountRefund extends string = string, > = { /** The funder for any Solana rent payments (the body sync may resize it). */ funder: TransactionSigner; game: Address; catalog: Address; /** * The evicted stake — bound to the game and the body below, with NO starbase-sequence validation (its * system's sequence may have moved on), exactly as Begin binds it. */ stake: Address; system: Address; /** Writable: its validation runs the pinned planet sync (which records the eviction). */ celestialBody: Address; currencyCache: Address; authority: Address; /** The evaluation being committed. Omitted only for a receipt replay (it was closed by the commit). */ eval?: Address; /** The Eval's funder (receives its rent when the Eval closes). */ refund: Address; nonce: CommitInvalidatedRentSettlementInstructionDataArgs['nonce']; }; export function getCommitInvalidatedRentSettlementInstruction< TAccountFunder extends string, TAccountGame extends string, TAccountCatalog extends string, TAccountStake extends string, TAccountSystem extends string, TAccountCelestialBody extends string, TAccountCurrencyCache extends string, TAccountAuthority extends string, TAccountEval extends string, TAccountRefund extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CommitInvalidatedRentSettlementInput< TAccountFunder, TAccountGame, TAccountCatalog, TAccountStake, TAccountSystem, TAccountCelestialBody, TAccountCurrencyCache, TAccountAuthority, TAccountEval, TAccountRefund >, config?: { programAddress?: TProgramAddress }, ): CommitInvalidatedRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountStake, TAccountSystem, TAccountCelestialBody, TAccountCurrencyCache, TAccountAuthority, TAccountEval, TAccountRefund > { // 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 }, catalog: { value: input.catalog ?? null, isWritable: false }, stake: { value: input.stake ?? null, isWritable: true }, system: { value: input.system ?? null, isWritable: false }, celestialBody: { value: input.celestialBody ?? null, isWritable: true }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, 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('funder', accounts.funder), getAccountMeta('game', accounts.game), getAccountMeta('catalog', accounts.catalog), getAccountMeta('stake', accounts.stake), getAccountMeta('system', accounts.system), getAccountMeta('celestialBody', accounts.celestialBody), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('authority', accounts.authority), getAccountMeta('eval', accounts.eval), getAccountMeta('refund', accounts.refund), ], data: getCommitInvalidatedRentSettlementInstructionDataEncoder().encode( args as CommitInvalidatedRentSettlementInstructionDataArgs, ), programAddress, } as CommitInvalidatedRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountGame, TAccountCatalog, TAccountStake, TAccountSystem, TAccountCelestialBody, TAccountCurrencyCache, TAccountAuthority, TAccountEval, TAccountRefund >); } export type ParsedCommitInvalidatedRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The funder for any Solana rent payments (the body sync may resize it). */ funder: TAccountMetas[0]; game: TAccountMetas[1]; catalog: TAccountMetas[2]; /** * The evicted stake — bound to the game and the body below, with NO starbase-sequence validation (its * system's sequence may have moved on), exactly as Begin binds it. */ stake: TAccountMetas[3]; system: TAccountMetas[4]; /** Writable: its validation runs the pinned planet sync (which records the eviction). */ celestialBody: TAccountMetas[5]; currencyCache: TAccountMetas[6]; authority: TAccountMetas[7]; /** The evaluation being committed. Omitted only for a receipt replay (it was closed by the commit). */ eval?: TAccountMetas[8] | undefined; /** The Eval's funder (receives its rent when the Eval closes). */ refund: TAccountMetas[9]; }; data: CommitInvalidatedRentSettlementInstructionData; }; export function parseCommitInvalidatedRentSettlementInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCommitInvalidatedRentSettlementInstruction { if (instruction.accounts.length < 10) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 10, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SAGE_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), game: getNextAccount(), catalog: getNextAccount(), stake: getNextAccount(), system: getNextAccount(), celestialBody: getNextAccount(), currencyCache: getNextAccount(), authority: getNextAccount(), eval: getNextOptionalAccount(), refund: getNextAccount(), }, data: getCommitInvalidatedRentSettlementInstructionDataDecoder().decode( instruction.data, ), }; }