/** * 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, 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 ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const INVALIDATE_RENTAL_DISCRIMINATOR = new Uint8Array([ 180, 183, 106, 153, 255, 8, 232, 178, ]); export function getInvalidateRentalDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INVALIDATE_RENTAL_DISCRIMINATOR, ); } export type InvalidateRentalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountSubProfileInvalidator extends string | AccountMeta = string, TAccountFleet extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountSubProfileInvalidator extends string ? WritableSignerAccount & AccountSignerMeta : TAccountSubProfileInvalidator, TAccountFleet extends string ? WritableAccount : TAccountFleet, ...TRemainingAccounts, ] >; export type InvalidateRentalInstructionData = { discriminator: ReadonlyUint8Array; /** Whether or not to remove the invalidator */ removeInvalidator: boolean; }; export type InvalidateRentalInstructionDataArgs = { /** Whether or not to remove the invalidator */ removeInvalidator: boolean; }; export function getInvalidateRentalInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['removeInvalidator', getBooleanEncoder()], ]), (value) => ({ ...value, discriminator: INVALIDATE_RENTAL_DISCRIMINATOR }), ); } export function getInvalidateRentalInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['removeInvalidator', getBooleanDecoder()], ]); } export function getInvalidateRentalInstructionDataCodec(): FixedSizeCodec< InvalidateRentalInstructionDataArgs, InvalidateRentalInstructionData > { return combineCodec( getInvalidateRentalInstructionDataEncoder(), getInvalidateRentalInstructionDataDecoder(), ); } export type InvalidateRentalInput< TAccountSubProfileInvalidator extends string = string, TAccountFleet extends string = string, > = { /** The fleet rental invalidator */ subProfileInvalidator: TransactionSigner; /** The fleet */ fleet: Address; removeInvalidator: InvalidateRentalInstructionDataArgs['removeInvalidator']; remainingAccounts: Array
; }; export function getInvalidateRentalInstruction< TAccountSubProfileInvalidator extends string, TAccountFleet extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: InvalidateRentalInput, config?: { programAddress?: TProgramAddress }, ): InvalidateRentalInstruction< TProgramAddress, TAccountSubProfileInvalidator, TAccountFleet > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { subProfileInvalidator: { value: input.subProfileInvalidator ?? null, isWritable: true, }, fleet: { value: input.fleet ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Remaining accounts. const remainingAccounts: AccountMeta[] = args.remainingAccounts.map( (address) => ({ address, role: AccountRole.READONLY }), ); const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('subProfileInvalidator', accounts.subProfileInvalidator), getAccountMeta('fleet', accounts.fleet), ...remainingAccounts, ], data: getInvalidateRentalInstructionDataEncoder().encode( args as InvalidateRentalInstructionDataArgs, ), programAddress, } as InvalidateRentalInstruction< TProgramAddress, TAccountSubProfileInvalidator, TAccountFleet >); } export type ParsedInvalidateRentalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The fleet rental invalidator */ subProfileInvalidator: TAccountMetas[0]; /** The fleet */ fleet: TAccountMetas[1]; }; data: InvalidateRentalInstructionData; }; export function parseInvalidateRentalInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInvalidateRentalInstruction { if (instruction.accounts.length < 2) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { subProfileInvalidator: getNextAccount(), fleet: getNextAccount(), }, data: getInvalidateRentalInstructionDataDecoder().decode(instruction.data), }; }