/** * 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, 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 ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const CANCEL_RENT_SETTLEMENT_DISCRIMINATOR = new Uint8Array([ 9, 186, 34, 209, 211, 4, 162, 50, ]); export function getCancelRentSettlementDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CANCEL_RENT_SETTLEMENT_DISCRIMINATOR, ); } export type CancelRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountOwnerSigner extends string | AccountMeta = string, TAccountOwnerProfile extends string | AccountMeta = string, TAccountOwnerCertificate extends string | AccountMeta = string, TAccountOwnerProgram extends string | AccountMeta = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u', 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< [ TAccountOwnerSigner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountOwnerSigner, TAccountOwnerProfile extends string ? WritableAccount : TAccountOwnerProfile, TAccountOwnerCertificate extends string ? ReadonlyAccount : TAccountOwnerCertificate, TAccountOwnerProgram extends string ? ReadonlyAccount : TAccountOwnerProgram, 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 CancelRentSettlementInstructionData = { discriminator: ReadonlyUint8Array; keyIndex: number; nonce: bigint; }; export type CancelRentSettlementInstructionDataArgs = { keyIndex: number; nonce: number | bigint; }; export function getCancelRentSettlementInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ['nonce', getU64Encoder()], ]), (value) => ({ ...value, discriminator: CANCEL_RENT_SETTLEMENT_DISCRIMINATOR, }), ); } export function getCancelRentSettlementInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ['nonce', getU64Decoder()], ]); } export function getCancelRentSettlementInstructionDataCodec(): FixedSizeCodec< CancelRentSettlementInstructionDataArgs, CancelRentSettlementInstructionData > { return combineCodec( getCancelRentSettlementInstructionDataEncoder(), getCancelRentSettlementInstructionDataDecoder(), ); } export type CancelRentSettlementInput< TAccountOwnerSigner extends string = string, TAccountOwnerProfile extends string = string, TAccountOwnerCertificate extends string = string, TAccountOwnerProgram extends string = string, TAccountGame extends string = string, TAccountStake extends string = string, TAccountAuthority extends string = string, TAccountEval extends string = string, TAccountRefund extends string = string, > = { ownerSigner: TransactionSigner; ownerProfile: Address; ownerCertificate?: Address; ownerProgram?: Address; game: Address; stake: Address; authority: Address; eval: Address; /** The Eval's funder (receives its rent). */ refund: Address; keyIndex: CancelRentSettlementInstructionDataArgs['keyIndex']; nonce: CancelRentSettlementInstructionDataArgs['nonce']; }; export function getCancelRentSettlementInstruction< TAccountOwnerSigner extends string, TAccountOwnerProfile extends string, TAccountOwnerCertificate extends string, TAccountOwnerProgram extends string, TAccountGame extends string, TAccountStake extends string, TAccountAuthority extends string, TAccountEval extends string, TAccountRefund extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CancelRentSettlementInput< TAccountOwnerSigner, TAccountOwnerProfile, TAccountOwnerCertificate, TAccountOwnerProgram, TAccountGame, TAccountStake, TAccountAuthority, TAccountEval, TAccountRefund >, config?: { programAddress?: TProgramAddress }, ): CancelRentSettlementInstruction< TProgramAddress, TAccountOwnerSigner, TAccountOwnerProfile, TAccountOwnerCertificate, TAccountOwnerProgram, TAccountGame, TAccountStake, TAccountAuthority, TAccountEval, TAccountRefund > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { ownerSigner: { value: input.ownerSigner ?? null, isWritable: false }, ownerProfile: { value: input.ownerProfile ?? null, isWritable: true }, ownerCertificate: { value: input.ownerCertificate ?? null, isWritable: false, }, ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }, 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 }; // Resolve default values. if (!accounts.ownerProgram.value) { accounts.ownerProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('ownerSigner', accounts.ownerSigner), getAccountMeta('ownerProfile', accounts.ownerProfile), getAccountMeta('ownerCertificate', accounts.ownerCertificate), getAccountMeta('ownerProgram', accounts.ownerProgram), getAccountMeta('game', accounts.game), getAccountMeta('stake', accounts.stake), getAccountMeta('authority', accounts.authority), getAccountMeta('eval', accounts.eval), getAccountMeta('refund', accounts.refund), ], data: getCancelRentSettlementInstructionDataEncoder().encode( args as CancelRentSettlementInstructionDataArgs, ), programAddress, } as CancelRentSettlementInstruction< TProgramAddress, TAccountOwnerSigner, TAccountOwnerProfile, TAccountOwnerCertificate, TAccountOwnerProgram, TAccountGame, TAccountStake, TAccountAuthority, TAccountEval, TAccountRefund >); } export type ParsedCancelRentSettlementInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { ownerSigner: TAccountMetas[0]; ownerProfile: TAccountMetas[1]; ownerCertificate?: TAccountMetas[2] | undefined; ownerProgram: TAccountMetas[3]; game: TAccountMetas[4]; stake: TAccountMetas[5]; authority: TAccountMetas[6]; eval: TAccountMetas[7]; /** The Eval's funder (receives its rent). */ refund: TAccountMetas[8]; }; data: CancelRentSettlementInstructionData; }; export function parseCancelRentSettlementInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCancelRentSettlementInstruction { if (instruction.accounts.length < 9) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 9, }, ); } 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: { ownerSigner: getNextAccount(), ownerProfile: getNextAccount(), ownerCertificate: getNextOptionalAccount(), ownerProgram: getNextAccount(), game: getNextAccount(), stake: getNextAccount(), authority: getNextAccount(), eval: getNextAccount(), refund: getNextAccount(), }, data: getCancelRentSettlementInstructionDataDecoder().decode( instruction.data, ), }; }