/** * 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, getOptionDecoder, getOptionEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU64Decoder, getU64Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type Option, type OptionOrNullable, type ReadonlyAccount, type ReadonlySignerAccount, 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 ADD_SHIP_ESCROW_DISCRIMINATOR = new Uint8Array([ 186, 19, 218, 150, 167, 181, 212, 89, ]); export function getAddShipEscrowDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ADD_SHIP_ESCROW_DISCRIMINATOR, ); } export type AddShipEscrowInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountProfileSignerSigner extends string | AccountMeta = string, TAccountProfileSignerProfile extends string | AccountMeta = string, TAccountProfileSignerCertificate extends string | AccountMeta = string, TAccountProfileSignerProgram extends string | AccountMeta = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u', TAccountCharacter extends string | AccountMeta = string, TAccountOriginTokenAccount extends string | AccountMeta = string, TAccountShipEscrowTokenAccount extends string | AccountMeta = string, TAccountStarSystem extends string | AccountMeta = string, TAccountStarbasePlayer extends string | AccountMeta = string, TAccountKey extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountTokenProgram extends string | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountProfileSignerSigner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountProfileSignerSigner, TAccountProfileSignerProfile extends string ? WritableAccount : TAccountProfileSignerProfile, TAccountProfileSignerCertificate extends string ? ReadonlyAccount : TAccountProfileSignerCertificate, TAccountProfileSignerProgram extends string ? ReadonlyAccount : TAccountProfileSignerProgram, TAccountCharacter extends string ? ReadonlyAccount : TAccountCharacter, TAccountOriginTokenAccount extends string ? WritableAccount : TAccountOriginTokenAccount, TAccountShipEscrowTokenAccount extends string ? WritableAccount : TAccountShipEscrowTokenAccount, TAccountStarSystem extends string ? ReadonlyAccount : TAccountStarSystem, TAccountStarbasePlayer extends string ? WritableAccount : TAccountStarbasePlayer, TAccountKey extends string ? WritableSignerAccount & AccountSignerMeta : TAccountKey, TAccountProfile extends string ? ReadonlyAccount : TAccountProfile, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type AddShipEscrowInstructionData = { discriminator: ReadonlyUint8Array; keyIndex: number; /** Amount of `Ship` tokens to transfer to escrow */ shipAmount: bigint; /** Unique identifier for the ship; if not provided the a ship id will be auto-selected */ id: Option; }; export type AddShipEscrowInstructionDataArgs = { keyIndex: number; /** Amount of `Ship` tokens to transfer to escrow */ shipAmount: number | bigint; /** Unique identifier for the ship; if not provided the a ship id will be auto-selected */ id: OptionOrNullable; }; export function getAddShipEscrowInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ['shipAmount', getU64Encoder()], ['id', getOptionEncoder(getU16Encoder())], ]), (value) => ({ ...value, discriminator: ADD_SHIP_ESCROW_DISCRIMINATOR }), ); } export function getAddShipEscrowInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ['shipAmount', getU64Decoder()], ['id', getOptionDecoder(getU16Decoder())], ]); } export function getAddShipEscrowInstructionDataCodec(): Codec< AddShipEscrowInstructionDataArgs, AddShipEscrowInstructionData > { return combineCodec( getAddShipEscrowInstructionDataEncoder(), getAddShipEscrowInstructionDataDecoder(), ); } export type AddShipEscrowAsyncInput< TAccountProfileSignerSigner extends string = string, TAccountProfileSignerProfile extends string = string, TAccountProfileSignerCertificate extends string = string, TAccountProfileSignerProgram extends string = string, TAccountCharacter extends string = string, TAccountOriginTokenAccount extends string = string, TAccountShipEscrowTokenAccount extends string = string, TAccountStarSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountKey extends string = string, TAccountProfile extends string = string, TAccountGame extends string = string, TAccountTokenProgram extends string = string, TAccountSystemProgram extends string = string, > = { profileSignerSigner: TransactionSigner; profileSignerProfile: Address; profileSignerCertificate?: Address; profileSignerProgram?: Address; /** The [`Character`] account */ character: Address; /** The Origin Token Account */ originTokenAccount: Address; /** The Escrow Token Account */ shipEscrowTokenAccount: Address; starSystem: Address; starbasePlayer?: Address; key: TransactionSigner; profile: Address; game: Address; /** The Token Program */ tokenProgram?: Address; /** The Solana System program */ systemProgram?: Address; keyIndex: AddShipEscrowInstructionDataArgs['keyIndex']; shipAmount: AddShipEscrowInstructionDataArgs['shipAmount']; id: AddShipEscrowInstructionDataArgs['id']; }; export async function getAddShipEscrowInstructionAsync< TAccountProfileSignerSigner extends string, TAccountProfileSignerProfile extends string, TAccountProfileSignerCertificate extends string, TAccountProfileSignerProgram extends string, TAccountCharacter extends string, TAccountOriginTokenAccount extends string, TAccountShipEscrowTokenAccount extends string, TAccountStarSystem extends string, TAccountStarbasePlayer extends string, TAccountKey extends string, TAccountProfile extends string, TAccountGame extends string, TAccountTokenProgram extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: AddShipEscrowAsyncInput< TAccountProfileSignerSigner, TAccountProfileSignerProfile, TAccountProfileSignerCertificate, TAccountProfileSignerProgram, TAccountCharacter, TAccountOriginTokenAccount, TAccountShipEscrowTokenAccount, TAccountStarSystem, TAccountStarbasePlayer, TAccountKey, TAccountProfile, TAccountGame, TAccountTokenProgram, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< AddShipEscrowInstruction< TProgramAddress, TAccountProfileSignerSigner, TAccountProfileSignerProfile, TAccountProfileSignerCertificate, TAccountProfileSignerProgram, TAccountCharacter, TAccountOriginTokenAccount, TAccountShipEscrowTokenAccount, TAccountStarSystem, TAccountStarbasePlayer, TAccountKey, TAccountProfile, TAccountGame, TAccountTokenProgram, TAccountSystemProgram > > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { profileSignerSigner: { value: input.profileSignerSigner ?? null, isWritable: false, }, profileSignerProfile: { value: input.profileSignerProfile ?? null, isWritable: true, }, profileSignerCertificate: { value: input.profileSignerCertificate ?? null, isWritable: false, }, profileSignerProgram: { value: input.profileSignerProgram ?? null, isWritable: false, }, character: { value: input.character ?? null, isWritable: false }, originTokenAccount: { value: input.originTokenAccount ?? null, isWritable: true, }, shipEscrowTokenAccount: { value: input.shipEscrowTokenAccount ?? null, isWritable: true, }, starSystem: { value: input.starSystem ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, key: { value: input.key ?? null, isWritable: true }, profile: { value: input.profile ?? null, isWritable: false }, game: { value: input.game ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.profileSignerProgram.value) { accounts.profileSignerProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } if (!accounts.starbasePlayer.value) { accounts.starbasePlayer.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([ 83, 116, 97, 114, 98, 97, 115, 101, 80, 108, 97, 121, 101, 114, ]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'starSystem', accounts.starSystem.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'character', accounts.character.value, ), ), ], }); } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('profileSignerSigner', accounts.profileSignerSigner), getAccountMeta('profileSignerProfile', accounts.profileSignerProfile), getAccountMeta( 'profileSignerCertificate', accounts.profileSignerCertificate, ), getAccountMeta('profileSignerProgram', accounts.profileSignerProgram), getAccountMeta('character', accounts.character), getAccountMeta('originTokenAccount', accounts.originTokenAccount), getAccountMeta('shipEscrowTokenAccount', accounts.shipEscrowTokenAccount), getAccountMeta('starSystem', accounts.starSystem), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('key', accounts.key), getAccountMeta('profile', accounts.profile), getAccountMeta('game', accounts.game), getAccountMeta('tokenProgram', accounts.tokenProgram), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getAddShipEscrowInstructionDataEncoder().encode( args as AddShipEscrowInstructionDataArgs, ), programAddress, } as AddShipEscrowInstruction< TProgramAddress, TAccountProfileSignerSigner, TAccountProfileSignerProfile, TAccountProfileSignerCertificate, TAccountProfileSignerProgram, TAccountCharacter, TAccountOriginTokenAccount, TAccountShipEscrowTokenAccount, TAccountStarSystem, TAccountStarbasePlayer, TAccountKey, TAccountProfile, TAccountGame, TAccountTokenProgram, TAccountSystemProgram >); } export type AddShipEscrowInput< TAccountProfileSignerSigner extends string = string, TAccountProfileSignerProfile extends string = string, TAccountProfileSignerCertificate extends string = string, TAccountProfileSignerProgram extends string = string, TAccountCharacter extends string = string, TAccountOriginTokenAccount extends string = string, TAccountShipEscrowTokenAccount extends string = string, TAccountStarSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountKey extends string = string, TAccountProfile extends string = string, TAccountGame extends string = string, TAccountTokenProgram extends string = string, TAccountSystemProgram extends string = string, > = { profileSignerSigner: TransactionSigner; profileSignerProfile: Address; profileSignerCertificate?: Address; profileSignerProgram?: Address; /** The [`Character`] account */ character: Address; /** The Origin Token Account */ originTokenAccount: Address; /** The Escrow Token Account */ shipEscrowTokenAccount: Address; starSystem: Address; starbasePlayer: Address; key: TransactionSigner; profile: Address; game: Address; /** The Token Program */ tokenProgram?: Address; /** The Solana System program */ systemProgram?: Address; keyIndex: AddShipEscrowInstructionDataArgs['keyIndex']; shipAmount: AddShipEscrowInstructionDataArgs['shipAmount']; id: AddShipEscrowInstructionDataArgs['id']; }; export function getAddShipEscrowInstruction< TAccountProfileSignerSigner extends string, TAccountProfileSignerProfile extends string, TAccountProfileSignerCertificate extends string, TAccountProfileSignerProgram extends string, TAccountCharacter extends string, TAccountOriginTokenAccount extends string, TAccountShipEscrowTokenAccount extends string, TAccountStarSystem extends string, TAccountStarbasePlayer extends string, TAccountKey extends string, TAccountProfile extends string, TAccountGame extends string, TAccountTokenProgram extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: AddShipEscrowInput< TAccountProfileSignerSigner, TAccountProfileSignerProfile, TAccountProfileSignerCertificate, TAccountProfileSignerProgram, TAccountCharacter, TAccountOriginTokenAccount, TAccountShipEscrowTokenAccount, TAccountStarSystem, TAccountStarbasePlayer, TAccountKey, TAccountProfile, TAccountGame, TAccountTokenProgram, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): AddShipEscrowInstruction< TProgramAddress, TAccountProfileSignerSigner, TAccountProfileSignerProfile, TAccountProfileSignerCertificate, TAccountProfileSignerProgram, TAccountCharacter, TAccountOriginTokenAccount, TAccountShipEscrowTokenAccount, TAccountStarSystem, TAccountStarbasePlayer, TAccountKey, TAccountProfile, TAccountGame, TAccountTokenProgram, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { profileSignerSigner: { value: input.profileSignerSigner ?? null, isWritable: false, }, profileSignerProfile: { value: input.profileSignerProfile ?? null, isWritable: true, }, profileSignerCertificate: { value: input.profileSignerCertificate ?? null, isWritable: false, }, profileSignerProgram: { value: input.profileSignerProgram ?? null, isWritable: false, }, character: { value: input.character ?? null, isWritable: false }, originTokenAccount: { value: input.originTokenAccount ?? null, isWritable: true, }, shipEscrowTokenAccount: { value: input.shipEscrowTokenAccount ?? null, isWritable: true, }, starSystem: { value: input.starSystem ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, key: { value: input.key ?? null, isWritable: true }, profile: { value: input.profile ?? null, isWritable: false }, game: { value: input.game ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.profileSignerProgram.value) { accounts.profileSignerProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('profileSignerSigner', accounts.profileSignerSigner), getAccountMeta('profileSignerProfile', accounts.profileSignerProfile), getAccountMeta( 'profileSignerCertificate', accounts.profileSignerCertificate, ), getAccountMeta('profileSignerProgram', accounts.profileSignerProgram), getAccountMeta('character', accounts.character), getAccountMeta('originTokenAccount', accounts.originTokenAccount), getAccountMeta('shipEscrowTokenAccount', accounts.shipEscrowTokenAccount), getAccountMeta('starSystem', accounts.starSystem), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('key', accounts.key), getAccountMeta('profile', accounts.profile), getAccountMeta('game', accounts.game), getAccountMeta('tokenProgram', accounts.tokenProgram), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getAddShipEscrowInstructionDataEncoder().encode( args as AddShipEscrowInstructionDataArgs, ), programAddress, } as AddShipEscrowInstruction< TProgramAddress, TAccountProfileSignerSigner, TAccountProfileSignerProfile, TAccountProfileSignerCertificate, TAccountProfileSignerProgram, TAccountCharacter, TAccountOriginTokenAccount, TAccountShipEscrowTokenAccount, TAccountStarSystem, TAccountStarbasePlayer, TAccountKey, TAccountProfile, TAccountGame, TAccountTokenProgram, TAccountSystemProgram >); } export type ParsedAddShipEscrowInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { profileSignerSigner: TAccountMetas[0]; profileSignerProfile: TAccountMetas[1]; profileSignerCertificate?: TAccountMetas[2] | undefined; profileSignerProgram: TAccountMetas[3]; /** The [`Character`] account */ character: TAccountMetas[4]; /** The Origin Token Account */ originTokenAccount: TAccountMetas[5]; /** The Escrow Token Account */ shipEscrowTokenAccount: TAccountMetas[6]; starSystem: TAccountMetas[7]; starbasePlayer: TAccountMetas[8]; key: TAccountMetas[9]; profile: TAccountMetas[10]; game: TAccountMetas[11]; /** The Token Program */ tokenProgram: TAccountMetas[12]; /** The Solana System program */ systemProgram: TAccountMetas[13]; }; data: AddShipEscrowInstructionData; }; export function parseAddShipEscrowInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedAddShipEscrowInstruction { if (instruction.accounts.length < 14) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 14, }, ); } 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: { profileSignerSigner: getNextAccount(), profileSignerProfile: getNextAccount(), profileSignerCertificate: getNextOptionalAccount(), profileSignerProgram: getNextAccount(), character: getNextAccount(), originTokenAccount: getNextAccount(), shipEscrowTokenAccount: getNextAccount(), starSystem: getNextAccount(), starbasePlayer: getNextAccount(), key: getNextAccount(), profile: getNextAccount(), game: getNextAccount(), tokenProgram: getNextAccount(), systemProgram: getNextAccount(), }, data: getAddShipEscrowInstructionDataDecoder().decode(instruction.data), }; }