/** * 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, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, Instruction, InstructionWithAccounts, InstructionWithData, ReadonlyAccount, ReadonlySignerAccount, ReadonlyUint8Array, TransactionSigner, WritableAccount, } from "@solana/kit"; import type { ResolvedInstructionAccount } from "@solana/program-client-core"; import { combineCodec, fixDecoderSize, fixEncoderSize, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, 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"; export const TWO_HOP_SWAP_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 195, 96, 237, 108, 68, 162, 219, 230, ]); export function getTwoHopSwapDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( TWO_HOP_SWAP_DISCRIMINATOR, ); } export type TwoHopSwapInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountTokenProgram extends | string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountTokenAuthority extends string | AccountMeta = string, TAccountWhirlpoolOne extends string | AccountMeta = string, TAccountWhirlpoolTwo extends string | AccountMeta = string, TAccountTokenOwnerAccountOneA extends string | AccountMeta = string, TAccountTokenVaultOneA extends string | AccountMeta = string, TAccountTokenOwnerAccountOneB extends string | AccountMeta = string, TAccountTokenVaultOneB extends string | AccountMeta = string, TAccountTokenOwnerAccountTwoA extends string | AccountMeta = string, TAccountTokenVaultTwoA extends string | AccountMeta = string, TAccountTokenOwnerAccountTwoB extends string | AccountMeta = string, TAccountTokenVaultTwoB 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, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, TAccountTokenAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountTokenAuthority, TAccountWhirlpoolOne extends string ? WritableAccount : TAccountWhirlpoolOne, TAccountWhirlpoolTwo extends string ? WritableAccount : TAccountWhirlpoolTwo, TAccountTokenOwnerAccountOneA extends string ? WritableAccount : TAccountTokenOwnerAccountOneA, TAccountTokenVaultOneA extends string ? WritableAccount : TAccountTokenVaultOneA, TAccountTokenOwnerAccountOneB extends string ? WritableAccount : TAccountTokenOwnerAccountOneB, TAccountTokenVaultOneB extends string ? WritableAccount : TAccountTokenVaultOneB, TAccountTokenOwnerAccountTwoA extends string ? WritableAccount : TAccountTokenOwnerAccountTwoA, TAccountTokenVaultTwoA extends string ? WritableAccount : TAccountTokenVaultTwoA, TAccountTokenOwnerAccountTwoB extends string ? WritableAccount : TAccountTokenOwnerAccountTwoB, TAccountTokenVaultTwoB extends string ? WritableAccount : TAccountTokenVaultTwoB, 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 ? ReadonlyAccount : TAccountOracleOne, TAccountOracleTwo extends string ? ReadonlyAccount : TAccountOracleTwo, ...TRemainingAccounts, ] >; export interface TwoHopSwapInstructionData { discriminator: ReadonlyUint8Array; amount: bigint; otherAmountThreshold: bigint; amountSpecifiedIsInput: boolean; aToBOne: boolean; aToBTwo: boolean; sqrtPriceLimitOne: bigint; sqrtPriceLimitTwo: bigint; } export interface TwoHopSwapInstructionDataArgs { amount: number | bigint; otherAmountThreshold: number | bigint; amountSpecifiedIsInput: boolean; aToBOne: boolean; aToBTwo: boolean; sqrtPriceLimitOne: number | bigint; sqrtPriceLimitTwo: number | bigint; } export function getTwoHopSwapInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["amount", getU64Encoder()], ["otherAmountThreshold", getU64Encoder()], ["amountSpecifiedIsInput", getBooleanEncoder()], ["aToBOne", getBooleanEncoder()], ["aToBTwo", getBooleanEncoder()], ["sqrtPriceLimitOne", getU128Encoder()], ["sqrtPriceLimitTwo", getU128Encoder()], ]), (value) => ({ ...value, discriminator: TWO_HOP_SWAP_DISCRIMINATOR }), ); } export function getTwoHopSwapInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["amount", getU64Decoder()], ["otherAmountThreshold", getU64Decoder()], ["amountSpecifiedIsInput", getBooleanDecoder()], ["aToBOne", getBooleanDecoder()], ["aToBTwo", getBooleanDecoder()], ["sqrtPriceLimitOne", getU128Decoder()], ["sqrtPriceLimitTwo", getU128Decoder()], ]); } export function getTwoHopSwapInstructionDataCodec(): FixedSizeCodec< TwoHopSwapInstructionDataArgs, TwoHopSwapInstructionData > { return combineCodec( getTwoHopSwapInstructionDataEncoder(), getTwoHopSwapInstructionDataDecoder(), ); } export interface TwoHopSwapInput< TAccountTokenProgram extends string = string, TAccountTokenAuthority extends string = string, TAccountWhirlpoolOne extends string = string, TAccountWhirlpoolTwo extends string = string, TAccountTokenOwnerAccountOneA extends string = string, TAccountTokenVaultOneA extends string = string, TAccountTokenOwnerAccountOneB extends string = string, TAccountTokenVaultOneB extends string = string, TAccountTokenOwnerAccountTwoA extends string = string, TAccountTokenVaultTwoA extends string = string, TAccountTokenOwnerAccountTwoB extends string = string, TAccountTokenVaultTwoB 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, > { tokenProgram?: Address; tokenAuthority: TransactionSigner; whirlpoolOne: Address; whirlpoolTwo: Address; tokenOwnerAccountOneA: Address; tokenVaultOneA: Address; tokenOwnerAccountOneB: Address; tokenVaultOneB: Address; tokenOwnerAccountTwoA: Address; tokenVaultTwoA: Address; tokenOwnerAccountTwoB: Address; tokenVaultTwoB: Address; tickArrayOne0: Address; tickArrayOne1: Address; tickArrayOne2: Address; tickArrayTwo0: Address; tickArrayTwo1: Address; tickArrayTwo2: Address; oracleOne: Address; oracleTwo: Address; amount: TwoHopSwapInstructionDataArgs["amount"]; otherAmountThreshold: TwoHopSwapInstructionDataArgs["otherAmountThreshold"]; amountSpecifiedIsInput: TwoHopSwapInstructionDataArgs["amountSpecifiedIsInput"]; aToBOne: TwoHopSwapInstructionDataArgs["aToBOne"]; aToBTwo: TwoHopSwapInstructionDataArgs["aToBTwo"]; sqrtPriceLimitOne: TwoHopSwapInstructionDataArgs["sqrtPriceLimitOne"]; sqrtPriceLimitTwo: TwoHopSwapInstructionDataArgs["sqrtPriceLimitTwo"]; } export function getTwoHopSwapInstruction< TAccountTokenProgram extends string, TAccountTokenAuthority extends string, TAccountWhirlpoolOne extends string, TAccountWhirlpoolTwo extends string, TAccountTokenOwnerAccountOneA extends string, TAccountTokenVaultOneA extends string, TAccountTokenOwnerAccountOneB extends string, TAccountTokenVaultOneB extends string, TAccountTokenOwnerAccountTwoA extends string, TAccountTokenVaultTwoA extends string, TAccountTokenOwnerAccountTwoB extends string, TAccountTokenVaultTwoB 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, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: TwoHopSwapInput< TAccountTokenProgram, TAccountTokenAuthority, TAccountWhirlpoolOne, TAccountWhirlpoolTwo, TAccountTokenOwnerAccountOneA, TAccountTokenVaultOneA, TAccountTokenOwnerAccountOneB, TAccountTokenVaultOneB, TAccountTokenOwnerAccountTwoA, TAccountTokenVaultTwoA, TAccountTokenOwnerAccountTwoB, TAccountTokenVaultTwoB, TAccountTickArrayOne0, TAccountTickArrayOne1, TAccountTickArrayOne2, TAccountTickArrayTwo0, TAccountTickArrayTwo1, TAccountTickArrayTwo2, TAccountOracleOne, TAccountOracleTwo >, config?: { programAddress?: TProgramAddress }, ): TwoHopSwapInstruction< TProgramAddress, TAccountTokenProgram, TAccountTokenAuthority, TAccountWhirlpoolOne, TAccountWhirlpoolTwo, TAccountTokenOwnerAccountOneA, TAccountTokenVaultOneA, TAccountTokenOwnerAccountOneB, TAccountTokenVaultOneB, TAccountTokenOwnerAccountTwoA, TAccountTokenVaultTwoA, TAccountTokenOwnerAccountTwoB, TAccountTokenVaultTwoB, TAccountTickArrayOne0, TAccountTickArrayOne1, TAccountTickArrayOne2, TAccountTickArrayTwo0, TAccountTickArrayTwo1, TAccountTickArrayTwo2, TAccountOracleOne, TAccountOracleTwo > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, whirlpoolOne: { value: input.whirlpoolOne ?? null, isWritable: true }, whirlpoolTwo: { value: input.whirlpoolTwo ?? null, isWritable: true }, tokenOwnerAccountOneA: { value: input.tokenOwnerAccountOneA ?? null, isWritable: true, }, tokenVaultOneA: { value: input.tokenVaultOneA ?? null, isWritable: true }, tokenOwnerAccountOneB: { value: input.tokenOwnerAccountOneB ?? null, isWritable: true, }, tokenVaultOneB: { value: input.tokenVaultOneB ?? null, isWritable: true }, tokenOwnerAccountTwoA: { value: input.tokenOwnerAccountTwoA ?? null, isWritable: true, }, tokenVaultTwoA: { value: input.tokenVaultTwoA ?? null, isWritable: true }, tokenOwnerAccountTwoB: { value: input.tokenOwnerAccountTwoB ?? null, isWritable: true, }, tokenVaultTwoB: { value: input.tokenVaultTwoB ?? null, isWritable: true }, 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: false }, oracleTwo: { value: input.oracleTwo ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("tokenAuthority", accounts.tokenAuthority), getAccountMeta("whirlpoolOne", accounts.whirlpoolOne), getAccountMeta("whirlpoolTwo", accounts.whirlpoolTwo), getAccountMeta("tokenOwnerAccountOneA", accounts.tokenOwnerAccountOneA), getAccountMeta("tokenVaultOneA", accounts.tokenVaultOneA), getAccountMeta("tokenOwnerAccountOneB", accounts.tokenOwnerAccountOneB), getAccountMeta("tokenVaultOneB", accounts.tokenVaultOneB), getAccountMeta("tokenOwnerAccountTwoA", accounts.tokenOwnerAccountTwoA), getAccountMeta("tokenVaultTwoA", accounts.tokenVaultTwoA), getAccountMeta("tokenOwnerAccountTwoB", accounts.tokenOwnerAccountTwoB), getAccountMeta("tokenVaultTwoB", accounts.tokenVaultTwoB), 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), ], data: getTwoHopSwapInstructionDataEncoder().encode( args as TwoHopSwapInstructionDataArgs, ), programAddress, } as TwoHopSwapInstruction< TProgramAddress, TAccountTokenProgram, TAccountTokenAuthority, TAccountWhirlpoolOne, TAccountWhirlpoolTwo, TAccountTokenOwnerAccountOneA, TAccountTokenVaultOneA, TAccountTokenOwnerAccountOneB, TAccountTokenVaultOneB, TAccountTokenOwnerAccountTwoA, TAccountTokenVaultTwoA, TAccountTokenOwnerAccountTwoB, TAccountTokenVaultTwoB, TAccountTickArrayOne0, TAccountTickArrayOne1, TAccountTickArrayOne2, TAccountTickArrayTwo0, TAccountTickArrayTwo1, TAccountTickArrayTwo2, TAccountOracleOne, TAccountOracleTwo >); } export interface ParsedTwoHopSwapInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { tokenProgram: TAccountMetas[0]; tokenAuthority: TAccountMetas[1]; whirlpoolOne: TAccountMetas[2]; whirlpoolTwo: TAccountMetas[3]; tokenOwnerAccountOneA: TAccountMetas[4]; tokenVaultOneA: TAccountMetas[5]; tokenOwnerAccountOneB: TAccountMetas[6]; tokenVaultOneB: TAccountMetas[7]; tokenOwnerAccountTwoA: TAccountMetas[8]; tokenVaultTwoA: TAccountMetas[9]; tokenOwnerAccountTwoB: TAccountMetas[10]; tokenVaultTwoB: TAccountMetas[11]; tickArrayOne0: TAccountMetas[12]; tickArrayOne1: TAccountMetas[13]; tickArrayOne2: TAccountMetas[14]; tickArrayTwo0: TAccountMetas[15]; tickArrayTwo1: TAccountMetas[16]; tickArrayTwo2: TAccountMetas[17]; oracleOne: TAccountMetas[18]; oracleTwo: TAccountMetas[19]; }; data: TwoHopSwapInstructionData; } export function parseTwoHopSwapInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedTwoHopSwapInstruction { if (instruction.accounts.length < 20) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 20, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { tokenProgram: getNextAccount(), tokenAuthority: getNextAccount(), whirlpoolOne: getNextAccount(), whirlpoolTwo: getNextAccount(), tokenOwnerAccountOneA: getNextAccount(), tokenVaultOneA: getNextAccount(), tokenOwnerAccountOneB: getNextAccount(), tokenVaultOneB: getNextAccount(), tokenOwnerAccountTwoA: getNextAccount(), tokenVaultTwoA: getNextAccount(), tokenOwnerAccountTwoB: getNextAccount(), tokenVaultTwoB: getNextAccount(), tickArrayOne0: getNextAccount(), tickArrayOne1: getNextAccount(), tickArrayOne2: getNextAccount(), tickArrayTwo0: getNextAccount(), tickArrayTwo1: getNextAccount(), tickArrayTwo2: getNextAccount(), oracleOne: getNextAccount(), oracleTwo: getNextAccount(), }, data: getTwoHopSwapInstructionDataDecoder().decode(instruction.data), }; }