/** * 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 type { AccountMeta, AccountSignerMeta, Address, Codec, Decoder, Encoder, Instruction, InstructionWithAccounts, InstructionWithData, Option, OptionOrNullable, ReadonlyAccount, ReadonlySignerAccount, ReadonlyUint8Array, TransactionSigner, WritableAccount, } from "@solana/kit"; import type { ResolvedInstructionAccount } from "@solana/program-client-core"; import type { RemainingAccountsInfo, RemainingAccountsInfoArgs, } from "../types/index.js"; import { combineCodec, fixDecoderSize, fixEncoderSize, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU128Decoder, getU128Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, } from "@solana/kit"; import { getAccountMetaFactory } from "@solana/program-client-core"; import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; import { getRemainingAccountsInfoDecoder, getRemainingAccountsInfoEncoder, } from "../types/index.js"; export const TWO_HOP_SWAP_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( [186, 143, 209, 29, 254, 2, 194, 117], ); export function getTwoHopSwapV2DiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( TWO_HOP_SWAP_V2_DISCRIMINATOR, ); } export type TwoHopSwapV2Instruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolOne extends string | AccountMeta = string, TAccountWhirlpoolTwo extends string | AccountMeta = string, TAccountTokenMintInput extends string | AccountMeta = string, TAccountTokenMintIntermediate extends string | AccountMeta = string, TAccountTokenMintOutput extends string | AccountMeta = string, TAccountTokenProgramInput extends string | AccountMeta = string, TAccountTokenProgramIntermediate extends string | AccountMeta = string, TAccountTokenProgramOutput extends string | AccountMeta = string, TAccountTokenOwnerAccountInput extends string | AccountMeta = string, TAccountTokenVaultOneInput extends string | AccountMeta = string, TAccountTokenVaultOneIntermediate extends string | AccountMeta = string, TAccountTokenVaultTwoIntermediate extends string | AccountMeta = string, TAccountTokenVaultTwoOutput extends string | AccountMeta = string, TAccountTokenOwnerAccountOutput extends string | AccountMeta = string, TAccountTokenAuthority extends string | AccountMeta = string, TAccountTickArrayOne0 extends string | AccountMeta = string, TAccountTickArrayOne1 extends string | AccountMeta = string, TAccountTickArrayOne2 extends string | AccountMeta = string, TAccountTickArrayTwo0 extends string | AccountMeta = string, TAccountTickArrayTwo1 extends string | AccountMeta = string, TAccountTickArrayTwo2 extends string | AccountMeta = string, TAccountOracleOne extends string | AccountMeta = string, TAccountOracleTwo extends string | AccountMeta = string, TAccountMemoProgram extends | string | AccountMeta = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpoolOne extends string ? WritableAccount : TAccountWhirlpoolOne, TAccountWhirlpoolTwo extends string ? WritableAccount : TAccountWhirlpoolTwo, TAccountTokenMintInput extends string ? ReadonlyAccount : TAccountTokenMintInput, TAccountTokenMintIntermediate extends string ? ReadonlyAccount : TAccountTokenMintIntermediate, TAccountTokenMintOutput extends string ? ReadonlyAccount : TAccountTokenMintOutput, TAccountTokenProgramInput extends string ? ReadonlyAccount : TAccountTokenProgramInput, TAccountTokenProgramIntermediate extends string ? ReadonlyAccount : TAccountTokenProgramIntermediate, TAccountTokenProgramOutput extends string ? ReadonlyAccount : TAccountTokenProgramOutput, TAccountTokenOwnerAccountInput extends string ? WritableAccount : TAccountTokenOwnerAccountInput, TAccountTokenVaultOneInput extends string ? WritableAccount : TAccountTokenVaultOneInput, TAccountTokenVaultOneIntermediate extends string ? WritableAccount : TAccountTokenVaultOneIntermediate, TAccountTokenVaultTwoIntermediate extends string ? WritableAccount : TAccountTokenVaultTwoIntermediate, TAccountTokenVaultTwoOutput extends string ? WritableAccount : TAccountTokenVaultTwoOutput, TAccountTokenOwnerAccountOutput extends string ? WritableAccount : TAccountTokenOwnerAccountOutput, TAccountTokenAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountTokenAuthority, TAccountTickArrayOne0 extends string ? WritableAccount : TAccountTickArrayOne0, TAccountTickArrayOne1 extends string ? WritableAccount : TAccountTickArrayOne1, TAccountTickArrayOne2 extends string ? WritableAccount : TAccountTickArrayOne2, TAccountTickArrayTwo0 extends string ? WritableAccount : TAccountTickArrayTwo0, TAccountTickArrayTwo1 extends string ? WritableAccount : TAccountTickArrayTwo1, TAccountTickArrayTwo2 extends string ? WritableAccount : TAccountTickArrayTwo2, TAccountOracleOne extends string ? WritableAccount : TAccountOracleOne, TAccountOracleTwo extends string ? WritableAccount : TAccountOracleTwo, TAccountMemoProgram extends string ? ReadonlyAccount : TAccountMemoProgram, ...TRemainingAccounts, ] >; export interface TwoHopSwapV2InstructionData { discriminator: ReadonlyUint8Array; amount: bigint; otherAmountThreshold: bigint; amountSpecifiedIsInput: boolean; aToBOne: boolean; aToBTwo: boolean; sqrtPriceLimitOne: bigint; sqrtPriceLimitTwo: bigint; remainingAccountsInfo: Option; } export interface TwoHopSwapV2InstructionDataArgs { amount: number | bigint; otherAmountThreshold: number | bigint; amountSpecifiedIsInput: boolean; aToBOne: boolean; aToBTwo: boolean; sqrtPriceLimitOne: number | bigint; sqrtPriceLimitTwo: number | bigint; remainingAccountsInfo: OptionOrNullable; } export function getTwoHopSwapV2InstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["amount", getU64Encoder()], ["otherAmountThreshold", getU64Encoder()], ["amountSpecifiedIsInput", getBooleanEncoder()], ["aToBOne", getBooleanEncoder()], ["aToBTwo", getBooleanEncoder()], ["sqrtPriceLimitOne", getU128Encoder()], ["sqrtPriceLimitTwo", getU128Encoder()], [ "remainingAccountsInfo", getOptionEncoder(getRemainingAccountsInfoEncoder()), ], ]), (value) => ({ ...value, discriminator: TWO_HOP_SWAP_V2_DISCRIMINATOR }), ); } export function getTwoHopSwapV2InstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["amount", getU64Decoder()], ["otherAmountThreshold", getU64Decoder()], ["amountSpecifiedIsInput", getBooleanDecoder()], ["aToBOne", getBooleanDecoder()], ["aToBTwo", getBooleanDecoder()], ["sqrtPriceLimitOne", getU128Decoder()], ["sqrtPriceLimitTwo", getU128Decoder()], [ "remainingAccountsInfo", getOptionDecoder(getRemainingAccountsInfoDecoder()), ], ]); } export function getTwoHopSwapV2InstructionDataCodec(): Codec< TwoHopSwapV2InstructionDataArgs, TwoHopSwapV2InstructionData > { return combineCodec( getTwoHopSwapV2InstructionDataEncoder(), getTwoHopSwapV2InstructionDataDecoder(), ); } export interface TwoHopSwapV2Input< TAccountWhirlpoolOne extends string = string, TAccountWhirlpoolTwo extends string = string, TAccountTokenMintInput extends string = string, TAccountTokenMintIntermediate extends string = string, TAccountTokenMintOutput extends string = string, TAccountTokenProgramInput extends string = string, TAccountTokenProgramIntermediate extends string = string, TAccountTokenProgramOutput extends string = string, TAccountTokenOwnerAccountInput extends string = string, TAccountTokenVaultOneInput extends string = string, TAccountTokenVaultOneIntermediate extends string = string, TAccountTokenVaultTwoIntermediate extends string = string, TAccountTokenVaultTwoOutput extends string = string, TAccountTokenOwnerAccountOutput extends string = string, TAccountTokenAuthority extends string = string, TAccountTickArrayOne0 extends string = string, TAccountTickArrayOne1 extends string = string, TAccountTickArrayOne2 extends string = string, TAccountTickArrayTwo0 extends string = string, TAccountTickArrayTwo1 extends string = string, TAccountTickArrayTwo2 extends string = string, TAccountOracleOne extends string = string, TAccountOracleTwo extends string = string, TAccountMemoProgram extends string = string, > { whirlpoolOne: Address; whirlpoolTwo: Address; tokenMintInput: Address; tokenMintIntermediate: Address; tokenMintOutput: Address; tokenProgramInput: Address; tokenProgramIntermediate: Address; tokenProgramOutput: Address; tokenOwnerAccountInput: Address; tokenVaultOneInput: Address; tokenVaultOneIntermediate: Address; tokenVaultTwoIntermediate: Address; tokenVaultTwoOutput: Address; tokenOwnerAccountOutput: Address; tokenAuthority: TransactionSigner; tickArrayOne0: Address; tickArrayOne1: Address; tickArrayOne2: Address; tickArrayTwo0: Address; tickArrayTwo1: Address; tickArrayTwo2: Address; oracleOne: Address; oracleTwo: Address; memoProgram?: Address; amount: TwoHopSwapV2InstructionDataArgs["amount"]; otherAmountThreshold: TwoHopSwapV2InstructionDataArgs["otherAmountThreshold"]; amountSpecifiedIsInput: TwoHopSwapV2InstructionDataArgs["amountSpecifiedIsInput"]; aToBOne: TwoHopSwapV2InstructionDataArgs["aToBOne"]; aToBTwo: TwoHopSwapV2InstructionDataArgs["aToBTwo"]; sqrtPriceLimitOne: TwoHopSwapV2InstructionDataArgs["sqrtPriceLimitOne"]; sqrtPriceLimitTwo: TwoHopSwapV2InstructionDataArgs["sqrtPriceLimitTwo"]; remainingAccountsInfo: TwoHopSwapV2InstructionDataArgs["remainingAccountsInfo"]; } export function getTwoHopSwapV2Instruction< TAccountWhirlpoolOne extends string, TAccountWhirlpoolTwo extends string, TAccountTokenMintInput extends string, TAccountTokenMintIntermediate extends string, TAccountTokenMintOutput extends string, TAccountTokenProgramInput extends string, TAccountTokenProgramIntermediate extends string, TAccountTokenProgramOutput extends string, TAccountTokenOwnerAccountInput extends string, TAccountTokenVaultOneInput extends string, TAccountTokenVaultOneIntermediate extends string, TAccountTokenVaultTwoIntermediate extends string, TAccountTokenVaultTwoOutput extends string, TAccountTokenOwnerAccountOutput extends string, TAccountTokenAuthority extends string, TAccountTickArrayOne0 extends string, TAccountTickArrayOne1 extends string, TAccountTickArrayOne2 extends string, TAccountTickArrayTwo0 extends string, TAccountTickArrayTwo1 extends string, TAccountTickArrayTwo2 extends string, TAccountOracleOne extends string, TAccountOracleTwo extends string, TAccountMemoProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: TwoHopSwapV2Input< TAccountWhirlpoolOne, TAccountWhirlpoolTwo, TAccountTokenMintInput, TAccountTokenMintIntermediate, TAccountTokenMintOutput, TAccountTokenProgramInput, TAccountTokenProgramIntermediate, TAccountTokenProgramOutput, TAccountTokenOwnerAccountInput, TAccountTokenVaultOneInput, TAccountTokenVaultOneIntermediate, TAccountTokenVaultTwoIntermediate, TAccountTokenVaultTwoOutput, TAccountTokenOwnerAccountOutput, TAccountTokenAuthority, TAccountTickArrayOne0, TAccountTickArrayOne1, TAccountTickArrayOne2, TAccountTickArrayTwo0, TAccountTickArrayTwo1, TAccountTickArrayTwo2, TAccountOracleOne, TAccountOracleTwo, TAccountMemoProgram >, config?: { programAddress?: TProgramAddress }, ): TwoHopSwapV2Instruction< TProgramAddress, TAccountWhirlpoolOne, TAccountWhirlpoolTwo, TAccountTokenMintInput, TAccountTokenMintIntermediate, TAccountTokenMintOutput, TAccountTokenProgramInput, TAccountTokenProgramIntermediate, TAccountTokenProgramOutput, TAccountTokenOwnerAccountInput, TAccountTokenVaultOneInput, TAccountTokenVaultOneIntermediate, TAccountTokenVaultTwoIntermediate, TAccountTokenVaultTwoOutput, TAccountTokenOwnerAccountOutput, TAccountTokenAuthority, TAccountTickArrayOne0, TAccountTickArrayOne1, TAccountTickArrayOne2, TAccountTickArrayTwo0, TAccountTickArrayTwo1, TAccountTickArrayTwo2, TAccountOracleOne, TAccountOracleTwo, TAccountMemoProgram > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpoolOne: { value: input.whirlpoolOne ?? null, isWritable: true }, whirlpoolTwo: { value: input.whirlpoolTwo ?? null, isWritable: true }, tokenMintInput: { value: input.tokenMintInput ?? null, isWritable: false }, tokenMintIntermediate: { value: input.tokenMintIntermediate ?? null, isWritable: false, }, tokenMintOutput: { value: input.tokenMintOutput ?? null, isWritable: false, }, tokenProgramInput: { value: input.tokenProgramInput ?? null, isWritable: false, }, tokenProgramIntermediate: { value: input.tokenProgramIntermediate ?? null, isWritable: false, }, tokenProgramOutput: { value: input.tokenProgramOutput ?? null, isWritable: false, }, tokenOwnerAccountInput: { value: input.tokenOwnerAccountInput ?? null, isWritable: true, }, tokenVaultOneInput: { value: input.tokenVaultOneInput ?? null, isWritable: true, }, tokenVaultOneIntermediate: { value: input.tokenVaultOneIntermediate ?? null, isWritable: true, }, tokenVaultTwoIntermediate: { value: input.tokenVaultTwoIntermediate ?? null, isWritable: true, }, tokenVaultTwoOutput: { value: input.tokenVaultTwoOutput ?? null, isWritable: true, }, tokenOwnerAccountOutput: { value: input.tokenOwnerAccountOutput ?? null, isWritable: true, }, tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, tickArrayOne0: { value: input.tickArrayOne0 ?? null, isWritable: true }, tickArrayOne1: { value: input.tickArrayOne1 ?? null, isWritable: true }, tickArrayOne2: { value: input.tickArrayOne2 ?? null, isWritable: true }, tickArrayTwo0: { value: input.tickArrayTwo0 ?? null, isWritable: true }, tickArrayTwo1: { value: input.tickArrayTwo1 ?? null, isWritable: true }, tickArrayTwo2: { value: input.tickArrayTwo2 ?? null, isWritable: true }, oracleOne: { value: input.oracleOne ?? null, isWritable: true }, oracleTwo: { value: input.oracleTwo ?? null, isWritable: true }, memoProgram: { value: input.memoProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.memoProgram.value) { accounts.memoProgram.value = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" as Address<"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("whirlpoolOne", accounts.whirlpoolOne), getAccountMeta("whirlpoolTwo", accounts.whirlpoolTwo), getAccountMeta("tokenMintInput", accounts.tokenMintInput), getAccountMeta("tokenMintIntermediate", accounts.tokenMintIntermediate), getAccountMeta("tokenMintOutput", accounts.tokenMintOutput), getAccountMeta("tokenProgramInput", accounts.tokenProgramInput), getAccountMeta( "tokenProgramIntermediate", accounts.tokenProgramIntermediate, ), getAccountMeta("tokenProgramOutput", accounts.tokenProgramOutput), getAccountMeta("tokenOwnerAccountInput", accounts.tokenOwnerAccountInput), getAccountMeta("tokenVaultOneInput", accounts.tokenVaultOneInput), getAccountMeta( "tokenVaultOneIntermediate", accounts.tokenVaultOneIntermediate, ), getAccountMeta( "tokenVaultTwoIntermediate", accounts.tokenVaultTwoIntermediate, ), getAccountMeta("tokenVaultTwoOutput", accounts.tokenVaultTwoOutput), getAccountMeta( "tokenOwnerAccountOutput", accounts.tokenOwnerAccountOutput, ), getAccountMeta("tokenAuthority", accounts.tokenAuthority), getAccountMeta("tickArrayOne0", accounts.tickArrayOne0), getAccountMeta("tickArrayOne1", accounts.tickArrayOne1), getAccountMeta("tickArrayOne2", accounts.tickArrayOne2), getAccountMeta("tickArrayTwo0", accounts.tickArrayTwo0), getAccountMeta("tickArrayTwo1", accounts.tickArrayTwo1), getAccountMeta("tickArrayTwo2", accounts.tickArrayTwo2), getAccountMeta("oracleOne", accounts.oracleOne), getAccountMeta("oracleTwo", accounts.oracleTwo), getAccountMeta("memoProgram", accounts.memoProgram), ], data: getTwoHopSwapV2InstructionDataEncoder().encode( args as TwoHopSwapV2InstructionDataArgs, ), programAddress, } as TwoHopSwapV2Instruction< TProgramAddress, TAccountWhirlpoolOne, TAccountWhirlpoolTwo, TAccountTokenMintInput, TAccountTokenMintIntermediate, TAccountTokenMintOutput, TAccountTokenProgramInput, TAccountTokenProgramIntermediate, TAccountTokenProgramOutput, TAccountTokenOwnerAccountInput, TAccountTokenVaultOneInput, TAccountTokenVaultOneIntermediate, TAccountTokenVaultTwoIntermediate, TAccountTokenVaultTwoOutput, TAccountTokenOwnerAccountOutput, TAccountTokenAuthority, TAccountTickArrayOne0, TAccountTickArrayOne1, TAccountTickArrayOne2, TAccountTickArrayTwo0, TAccountTickArrayTwo1, TAccountTickArrayTwo2, TAccountOracleOne, TAccountOracleTwo, TAccountMemoProgram >); } export interface ParsedTwoHopSwapV2Instruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpoolOne: TAccountMetas[0]; whirlpoolTwo: TAccountMetas[1]; tokenMintInput: TAccountMetas[2]; tokenMintIntermediate: TAccountMetas[3]; tokenMintOutput: TAccountMetas[4]; tokenProgramInput: TAccountMetas[5]; tokenProgramIntermediate: TAccountMetas[6]; tokenProgramOutput: TAccountMetas[7]; tokenOwnerAccountInput: TAccountMetas[8]; tokenVaultOneInput: TAccountMetas[9]; tokenVaultOneIntermediate: TAccountMetas[10]; tokenVaultTwoIntermediate: TAccountMetas[11]; tokenVaultTwoOutput: TAccountMetas[12]; tokenOwnerAccountOutput: TAccountMetas[13]; tokenAuthority: TAccountMetas[14]; tickArrayOne0: TAccountMetas[15]; tickArrayOne1: TAccountMetas[16]; tickArrayOne2: TAccountMetas[17]; tickArrayTwo0: TAccountMetas[18]; tickArrayTwo1: TAccountMetas[19]; tickArrayTwo2: TAccountMetas[20]; oracleOne: TAccountMetas[21]; oracleTwo: TAccountMetas[22]; memoProgram: TAccountMetas[23]; }; data: TwoHopSwapV2InstructionData; } export function parseTwoHopSwapV2Instruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedTwoHopSwapV2Instruction { if (instruction.accounts.length < 24) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 24, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { whirlpoolOne: getNextAccount(), whirlpoolTwo: getNextAccount(), tokenMintInput: getNextAccount(), tokenMintIntermediate: getNextAccount(), tokenMintOutput: getNextAccount(), tokenProgramInput: getNextAccount(), tokenProgramIntermediate: getNextAccount(), tokenProgramOutput: getNextAccount(), tokenOwnerAccountInput: getNextAccount(), tokenVaultOneInput: getNextAccount(), tokenVaultOneIntermediate: getNextAccount(), tokenVaultTwoIntermediate: getNextAccount(), tokenVaultTwoOutput: getNextAccount(), tokenOwnerAccountOutput: getNextAccount(), tokenAuthority: getNextAccount(), tickArrayOne0: getNextAccount(), tickArrayOne1: getNextAccount(), tickArrayOne2: getNextAccount(), tickArrayTwo0: getNextAccount(), tickArrayTwo1: getNextAccount(), tickArrayTwo2: getNextAccount(), oracleOne: getNextAccount(), oracleTwo: getNextAccount(), memoProgram: getNextAccount(), }, data: getTwoHopSwapV2InstructionDataDecoder().decode(instruction.data), }; }