/** * 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_RENT_SETTLEMENT_DISCRIMINATOR = new Uint8Array([ 9, 68, 127, 65, 202, 58, 172, 212, ]); export function getCommitRentSettlementDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( COMMIT_RENT_SETTLEMENT_DISCRIMINATOR, ); } export type CommitRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountClaimStakeInstance extends string | AccountMeta = string, TAccountCelestialBody extends string | AccountMeta = string, TAccountSystemAndStarbasePlayerSystem extends string | AccountMeta = string, TAccountSystemAndStarbasePlayerStarbasePlayer extends | string | AccountMeta = string, TAccountCurrencyCache extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountCatalog extends string | AccountMeta = string, TAccountAuthority extends string | AccountMeta = string, TAccountEval extends string | AccountMeta = string, TAccountRefund extends string | AccountMeta = string, TAccountXpAccrual extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountProfile extends string ? ReadonlyAccount : TAccountProfile, TAccountClaimStakeInstance extends string ? WritableAccount : TAccountClaimStakeInstance, TAccountCelestialBody extends string ? WritableAccount : TAccountCelestialBody, TAccountSystemAndStarbasePlayerSystem extends string ? ReadonlyAccount : TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer extends string ? ReadonlyAccount : TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache extends string ? WritableAccount : TAccountCurrencyCache, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountCatalog extends string ? ReadonlyAccount : TAccountCatalog, TAccountAuthority extends string ? WritableAccount : TAccountAuthority, TAccountEval extends string ? WritableAccount : TAccountEval, TAccountRefund extends string ? WritableAccount : TAccountRefund, TAccountXpAccrual extends string ? WritableAccount : TAccountXpAccrual, ...TRemainingAccounts, ] >; export type CommitRentSettlementInstructionData = { discriminator: ReadonlyUint8Array; nonce: bigint; }; export type CommitRentSettlementInstructionDataArgs = { nonce: number | bigint; }; export function getCommitRentSettlementInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['nonce', getU64Encoder()], ]), (value) => ({ ...value, discriminator: COMMIT_RENT_SETTLEMENT_DISCRIMINATOR, }), ); } export function getCommitRentSettlementInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['nonce', getU64Decoder()], ]); } export function getCommitRentSettlementInstructionDataCodec(): FixedSizeCodec< CommitRentSettlementInstructionDataArgs, CommitRentSettlementInstructionData > { return combineCodec( getCommitRentSettlementInstructionDataEncoder(), getCommitRentSettlementInstructionDataDecoder(), ); } export type CommitRentSettlementAsyncInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountClaimStakeInstance extends string = string, TAccountCelestialBody extends string = string, TAccountSystemAndStarbasePlayerSystem extends string = string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string = string, TAccountCurrencyCache extends string = string, TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountAuthority extends string = string, TAccountEval extends string = string, TAccountRefund extends string = string, TAccountXpAccrual extends string = string, > = { /** The funder for any Solana rent payments (the body sync may resize it). */ funder: TransactionSigner; /** The stake owner's profile (read-only; binds the starbase player). */ profile: Address; claimStakeInstance: Address; celestialBody: Address; /** The [`StarSystem`] account */ systemAndStarbasePlayerSystem: Address; /** The [`StarbasePlayer`] Account */ systemAndStarbasePlayerStarbasePlayer: Address; currencyCache?: Address; game: Address; catalog: 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; /** Building XP ledger — exactly as `PayClaimStakesRent`: required on v1 games, rejected on legacy ones. */ xpAccrual?: Address; nonce: CommitRentSettlementInstructionDataArgs['nonce']; }; export async function getCommitRentSettlementInstructionAsync< TAccountFunder extends string, TAccountProfile extends string, TAccountClaimStakeInstance extends string, TAccountCelestialBody extends string, TAccountSystemAndStarbasePlayerSystem extends string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string, TAccountCurrencyCache extends string, TAccountGame extends string, TAccountCatalog extends string, TAccountAuthority extends string, TAccountEval extends string, TAccountRefund extends string, TAccountXpAccrual extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CommitRentSettlementAsyncInput< TAccountFunder, TAccountProfile, TAccountClaimStakeInstance, TAccountCelestialBody, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountCatalog, TAccountAuthority, TAccountEval, TAccountRefund, TAccountXpAccrual >, config?: { programAddress?: TProgramAddress }, ): Promise< CommitRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountClaimStakeInstance, TAccountCelestialBody, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountCatalog, TAccountAuthority, TAccountEval, TAccountRefund, TAccountXpAccrual > > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, profile: { value: input.profile ?? null, isWritable: false }, claimStakeInstance: { value: input.claimStakeInstance ?? null, isWritable: true, }, celestialBody: { value: input.celestialBody ?? null, isWritable: true }, systemAndStarbasePlayerSystem: { value: input.systemAndStarbasePlayerSystem ?? null, isWritable: false, }, systemAndStarbasePlayerStarbasePlayer: { value: input.systemAndStarbasePlayerStarbasePlayer ?? null, isWritable: false, }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, catalog: { value: input.catalog ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: true }, eval: { value: input.eval ?? null, isWritable: true }, refund: { value: input.refund ?? null, isWritable: true }, xpAccrual: { value: input.xpAccrual ?? 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('profile', accounts.profile), getAccountMeta('claimStakeInstance', accounts.claimStakeInstance), getAccountMeta('celestialBody', accounts.celestialBody), getAccountMeta( 'systemAndStarbasePlayerSystem', accounts.systemAndStarbasePlayerSystem, ), getAccountMeta( 'systemAndStarbasePlayerStarbasePlayer', accounts.systemAndStarbasePlayerStarbasePlayer, ), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('game', accounts.game), getAccountMeta('catalog', accounts.catalog), getAccountMeta('authority', accounts.authority), getAccountMeta('eval', accounts.eval), getAccountMeta('refund', accounts.refund), getAccountMeta('xpAccrual', accounts.xpAccrual), ], data: getCommitRentSettlementInstructionDataEncoder().encode( args as CommitRentSettlementInstructionDataArgs, ), programAddress, } as CommitRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountClaimStakeInstance, TAccountCelestialBody, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountCatalog, TAccountAuthority, TAccountEval, TAccountRefund, TAccountXpAccrual >); } export type CommitRentSettlementInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountClaimStakeInstance extends string = string, TAccountCelestialBody extends string = string, TAccountSystemAndStarbasePlayerSystem extends string = string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string = string, TAccountCurrencyCache extends string = string, TAccountGame extends string = string, TAccountCatalog extends string = string, TAccountAuthority extends string = string, TAccountEval extends string = string, TAccountRefund extends string = string, TAccountXpAccrual extends string = string, > = { /** The funder for any Solana rent payments (the body sync may resize it). */ funder: TransactionSigner; /** The stake owner's profile (read-only; binds the starbase player). */ profile: Address; claimStakeInstance: Address; celestialBody: Address; /** The [`StarSystem`] account */ systemAndStarbasePlayerSystem: Address; /** The [`StarbasePlayer`] Account */ systemAndStarbasePlayerStarbasePlayer: Address; currencyCache: Address; game: Address; catalog: 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; /** Building XP ledger — exactly as `PayClaimStakesRent`: required on v1 games, rejected on legacy ones. */ xpAccrual?: Address; nonce: CommitRentSettlementInstructionDataArgs['nonce']; }; export function getCommitRentSettlementInstruction< TAccountFunder extends string, TAccountProfile extends string, TAccountClaimStakeInstance extends string, TAccountCelestialBody extends string, TAccountSystemAndStarbasePlayerSystem extends string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string, TAccountCurrencyCache extends string, TAccountGame extends string, TAccountCatalog extends string, TAccountAuthority extends string, TAccountEval extends string, TAccountRefund extends string, TAccountXpAccrual extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CommitRentSettlementInput< TAccountFunder, TAccountProfile, TAccountClaimStakeInstance, TAccountCelestialBody, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountCatalog, TAccountAuthority, TAccountEval, TAccountRefund, TAccountXpAccrual >, config?: { programAddress?: TProgramAddress }, ): CommitRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountClaimStakeInstance, TAccountCelestialBody, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountCatalog, TAccountAuthority, TAccountEval, TAccountRefund, TAccountXpAccrual > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, profile: { value: input.profile ?? null, isWritable: false }, claimStakeInstance: { value: input.claimStakeInstance ?? null, isWritable: true, }, celestialBody: { value: input.celestialBody ?? null, isWritable: true }, systemAndStarbasePlayerSystem: { value: input.systemAndStarbasePlayerSystem ?? null, isWritable: false, }, systemAndStarbasePlayerStarbasePlayer: { value: input.systemAndStarbasePlayerStarbasePlayer ?? null, isWritable: false, }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, catalog: { value: input.catalog ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: true }, eval: { value: input.eval ?? null, isWritable: true }, refund: { value: input.refund ?? null, isWritable: true }, xpAccrual: { value: input.xpAccrual ?? 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('profile', accounts.profile), getAccountMeta('claimStakeInstance', accounts.claimStakeInstance), getAccountMeta('celestialBody', accounts.celestialBody), getAccountMeta( 'systemAndStarbasePlayerSystem', accounts.systemAndStarbasePlayerSystem, ), getAccountMeta( 'systemAndStarbasePlayerStarbasePlayer', accounts.systemAndStarbasePlayerStarbasePlayer, ), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('game', accounts.game), getAccountMeta('catalog', accounts.catalog), getAccountMeta('authority', accounts.authority), getAccountMeta('eval', accounts.eval), getAccountMeta('refund', accounts.refund), getAccountMeta('xpAccrual', accounts.xpAccrual), ], data: getCommitRentSettlementInstructionDataEncoder().encode( args as CommitRentSettlementInstructionDataArgs, ), programAddress, } as CommitRentSettlementInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountClaimStakeInstance, TAccountCelestialBody, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountCatalog, TAccountAuthority, TAccountEval, TAccountRefund, TAccountXpAccrual >); } export type ParsedCommitRentSettlementInstruction< 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]; /** The stake owner's profile (read-only; binds the starbase player). */ profile: TAccountMetas[1]; claimStakeInstance: TAccountMetas[2]; celestialBody: TAccountMetas[3]; /** The [`StarSystem`] account */ systemAndStarbasePlayerSystem: TAccountMetas[4]; /** The [`StarbasePlayer`] Account */ systemAndStarbasePlayerStarbasePlayer: TAccountMetas[5]; currencyCache: TAccountMetas[6]; game: TAccountMetas[7]; catalog: TAccountMetas[8]; authority: TAccountMetas[9]; /** The evaluation being committed. Omitted only for a receipt replay (it was closed by the commit). */ eval?: TAccountMetas[10] | undefined; /** The Eval's funder (receives its rent when the Eval closes). */ refund: TAccountMetas[11]; /** Building XP ledger — exactly as `PayClaimStakesRent`: required on v1 games, rejected on legacy ones. */ xpAccrual?: TAccountMetas[12] | undefined; }; data: CommitRentSettlementInstructionData; }; export function parseCommitRentSettlementInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCommitRentSettlementInstruction { if (instruction.accounts.length < 13) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 13, }, ); } 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(), profile: getNextAccount(), claimStakeInstance: getNextAccount(), celestialBody: getNextAccount(), systemAndStarbasePlayerSystem: getNextAccount(), systemAndStarbasePlayerStarbasePlayer: getNextAccount(), currencyCache: getNextAccount(), game: getNextAccount(), catalog: getNextAccount(), authority: getNextAccount(), eval: getNextOptionalAccount(), refund: getNextAccount(), xpAccrual: getNextOptionalAccount(), }, data: getCommitRentSettlementInstructionDataDecoder().decode( instruction.data, ), }; }