/** * 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, 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, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const CHANGE_RENTAL_DISCRIMINATOR = new Uint8Array([ 107, 122, 221, 24, 12, 249, 70, 193, ]); export function getChangeRentalDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CHANGE_RENTAL_DISCRIMINATOR, ); } export type ChangeRentalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountSubProfileInvalidator extends string | AccountMeta = string, TAccountNewSubProfile extends string | AccountMeta = string, TAccountFleet extends string | AccountMeta = string, TAccountGameId extends string | AccountMeta = string, TAccountSubProfileFaction extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountSubProfileInvalidator extends string ? WritableSignerAccount & AccountSignerMeta : TAccountSubProfileInvalidator, TAccountNewSubProfile extends string ? ReadonlyAccount : TAccountNewSubProfile, TAccountFleet extends string ? WritableAccount : TAccountFleet, TAccountGameId extends string ? ReadonlyAccount : TAccountGameId, TAccountSubProfileFaction extends string ? ReadonlyAccount : TAccountSubProfileFaction, ...TRemainingAccounts, ] >; export type ChangeRentalInstructionData = { discriminator: ReadonlyUint8Array }; export type ChangeRentalInstructionDataArgs = {}; export function getChangeRentalInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CHANGE_RENTAL_DISCRIMINATOR }), ); } export function getChangeRentalInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getChangeRentalInstructionDataCodec(): FixedSizeCodec< ChangeRentalInstructionDataArgs, ChangeRentalInstructionData > { return combineCodec( getChangeRentalInstructionDataEncoder(), getChangeRentalInstructionDataDecoder(), ); } export type ChangeRentalInput< TAccountSubProfileInvalidator extends string = string, TAccountNewSubProfile extends string = string, TAccountFleet extends string = string, TAccountGameId extends string = string, TAccountSubProfileFaction extends string = string, > = { /** The fleet rental invalidator */ subProfileInvalidator: TransactionSigner; /** The new sub profile */ newSubProfile: Address; /** The fleet */ fleet: Address; /** The [`Game`] account */ gameId: Address; /** The faction that the sub_profile belongs to. */ subProfileFaction: Address; }; export function getChangeRentalInstruction< TAccountSubProfileInvalidator extends string, TAccountNewSubProfile extends string, TAccountFleet extends string, TAccountGameId extends string, TAccountSubProfileFaction extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ChangeRentalInput< TAccountSubProfileInvalidator, TAccountNewSubProfile, TAccountFleet, TAccountGameId, TAccountSubProfileFaction >, config?: { programAddress?: TProgramAddress }, ): ChangeRentalInstruction< TProgramAddress, TAccountSubProfileInvalidator, TAccountNewSubProfile, TAccountFleet, TAccountGameId, TAccountSubProfileFaction > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { subProfileInvalidator: { value: input.subProfileInvalidator ?? null, isWritable: true, }, newSubProfile: { value: input.newSubProfile ?? null, isWritable: false }, fleet: { value: input.fleet ?? null, isWritable: true }, gameId: { value: input.gameId ?? null, isWritable: false }, subProfileFaction: { value: input.subProfileFaction ?? null, isWritable: false, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('subProfileInvalidator', accounts.subProfileInvalidator), getAccountMeta('newSubProfile', accounts.newSubProfile), getAccountMeta('fleet', accounts.fleet), getAccountMeta('gameId', accounts.gameId), getAccountMeta('subProfileFaction', accounts.subProfileFaction), ], data: getChangeRentalInstructionDataEncoder().encode({}), programAddress, } as ChangeRentalInstruction< TProgramAddress, TAccountSubProfileInvalidator, TAccountNewSubProfile, TAccountFleet, TAccountGameId, TAccountSubProfileFaction >); } export type ParsedChangeRentalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The fleet rental invalidator */ subProfileInvalidator: TAccountMetas[0]; /** The new sub profile */ newSubProfile: TAccountMetas[1]; /** The fleet */ fleet: TAccountMetas[2]; /** The [`Game`] account */ gameId: TAccountMetas[3]; /** The faction that the sub_profile belongs to. */ subProfileFaction: TAccountMetas[4]; }; data: ChangeRentalInstructionData; }; export function parseChangeRentalInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedChangeRentalInstruction { if (instruction.accounts.length < 5) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { subProfileInvalidator: getNextAccount(), newSubProfile: getNextAccount(), fleet: getNextAccount(), gameId: getNextAccount(), subProfileFaction: getNextAccount(), }, data: getChangeRentalInstructionDataDecoder().decode(instruction.data), }; }