/** * 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, 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 ADD_RENTAL_DISCRIMINATOR = new Uint8Array([ 213, 113, 170, 123, 187, 90, 28, 115, ]); export function getAddRentalDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(ADD_RENTAL_DISCRIMINATOR); } export type AddRentalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountOwnerProfile extends string | AccountMeta = string, TAccountOwnerKey extends string | AccountMeta = string, TAccountInvalidator extends string | AccountMeta = string, TAccountGameId extends string | AccountMeta = string, TAccountFleet extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountOwnerProfile extends string ? ReadonlyAccount : TAccountOwnerProfile, TAccountOwnerKey extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountOwnerKey, TAccountInvalidator extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountInvalidator, TAccountGameId extends string ? ReadonlyAccount : TAccountGameId, TAccountFleet extends string ? WritableAccount : TAccountFleet, ...TRemainingAccounts, ] >; export type AddRentalInstructionData = { discriminator: ReadonlyUint8Array; /** the index of the owner key in the player profile */ ownerKeyIndex: number; }; export type AddRentalInstructionDataArgs = { /** the index of the owner key in the player profile */ ownerKeyIndex: number; }; export function getAddRentalInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['ownerKeyIndex', getU16Encoder()], ]), (value) => ({ ...value, discriminator: ADD_RENTAL_DISCRIMINATOR }), ); } export function getAddRentalInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['ownerKeyIndex', getU16Decoder()], ]); } export function getAddRentalInstructionDataCodec(): FixedSizeCodec< AddRentalInstructionDataArgs, AddRentalInstructionData > { return combineCodec( getAddRentalInstructionDataEncoder(), getAddRentalInstructionDataDecoder(), ); } export type AddRentalInput< TAccountOwnerProfile extends string = string, TAccountOwnerKey extends string = string, TAccountInvalidator extends string = string, TAccountGameId extends string = string, TAccountFleet extends string = string, > = { /** The fleet owner's profile. */ ownerProfile: Address; /** The key on the owner profile with renting permissions. */ ownerKey: TransactionSigner; /** The fleet rental invalidator - this is a signer to help make sure the fleet won't be locked. */ invalidator: TransactionSigner; /** The [`Game`] account */ gameId: Address; /** The fleet to rent out. */ fleet: Address; ownerKeyIndex: AddRentalInstructionDataArgs['ownerKeyIndex']; }; export function getAddRentalInstruction< TAccountOwnerProfile extends string, TAccountOwnerKey extends string, TAccountInvalidator extends string, TAccountGameId extends string, TAccountFleet extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: AddRentalInput< TAccountOwnerProfile, TAccountOwnerKey, TAccountInvalidator, TAccountGameId, TAccountFleet >, config?: { programAddress?: TProgramAddress }, ): AddRentalInstruction< TProgramAddress, TAccountOwnerProfile, TAccountOwnerKey, TAccountInvalidator, TAccountGameId, TAccountFleet > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { ownerProfile: { value: input.ownerProfile ?? null, isWritable: false }, ownerKey: { value: input.ownerKey ?? null, isWritable: false }, invalidator: { value: input.invalidator ?? null, isWritable: false }, gameId: { value: input.gameId ?? null, isWritable: false }, fleet: { value: input.fleet ?? 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('ownerProfile', accounts.ownerProfile), getAccountMeta('ownerKey', accounts.ownerKey), getAccountMeta('invalidator', accounts.invalidator), getAccountMeta('gameId', accounts.gameId), getAccountMeta('fleet', accounts.fleet), ], data: getAddRentalInstructionDataEncoder().encode( args as AddRentalInstructionDataArgs, ), programAddress, } as AddRentalInstruction< TProgramAddress, TAccountOwnerProfile, TAccountOwnerKey, TAccountInvalidator, TAccountGameId, TAccountFleet >); } export type ParsedAddRentalInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The fleet owner's profile. */ ownerProfile: TAccountMetas[0]; /** The key on the owner profile with renting permissions. */ ownerKey: TAccountMetas[1]; /** The fleet rental invalidator - this is a signer to help make sure the fleet won't be locked. */ invalidator: TAccountMetas[2]; /** The [`Game`] account */ gameId: TAccountMetas[3]; /** The fleet to rent out. */ fleet: TAccountMetas[4]; }; data: AddRentalInstructionData; }; export function parseAddRentalInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedAddRentalInstruction { 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: { ownerProfile: getNextAccount(), ownerKey: getNextAccount(), invalidator: getNextAccount(), gameId: getNextAccount(), fleet: getNextAccount(), }, data: getAddRentalInstructionDataDecoder().decode(instruction.data), }; }