/** * 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, 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 DECREASE_LIQUIDITY_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([58, 127, 188, 62, 79, 82, 196, 96]); export function getDecreaseLiquidityV2DiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( DECREASE_LIQUIDITY_V2_DISCRIMINATOR, ); } export type DecreaseLiquidityV2Instruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpool extends string | AccountMeta = string, TAccountTokenProgramA extends string | AccountMeta = string, TAccountTokenProgramB extends string | AccountMeta = string, TAccountMemoProgram extends | string | AccountMeta = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr", TAccountPositionAuthority extends string | AccountMeta = string, TAccountPosition extends string | AccountMeta = string, TAccountPositionTokenAccount extends string | AccountMeta = string, TAccountTokenMintA extends string | AccountMeta = string, TAccountTokenMintB extends string | AccountMeta = string, TAccountTokenOwnerAccountA extends string | AccountMeta = string, TAccountTokenOwnerAccountB extends string | AccountMeta = string, TAccountTokenVaultA extends string | AccountMeta = string, TAccountTokenVaultB extends string | AccountMeta = string, TAccountTickArrayLower extends string | AccountMeta = string, TAccountTickArrayUpper extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpool extends string ? WritableAccount : TAccountWhirlpool, TAccountTokenProgramA extends string ? ReadonlyAccount : TAccountTokenProgramA, TAccountTokenProgramB extends string ? ReadonlyAccount : TAccountTokenProgramB, TAccountMemoProgram extends string ? ReadonlyAccount : TAccountMemoProgram, TAccountPositionAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountPositionAuthority, TAccountPosition extends string ? WritableAccount : TAccountPosition, TAccountPositionTokenAccount extends string ? ReadonlyAccount : TAccountPositionTokenAccount, TAccountTokenMintA extends string ? ReadonlyAccount : TAccountTokenMintA, TAccountTokenMintB extends string ? ReadonlyAccount : TAccountTokenMintB, TAccountTokenOwnerAccountA extends string ? WritableAccount : TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB extends string ? WritableAccount : TAccountTokenOwnerAccountB, TAccountTokenVaultA extends string ? WritableAccount : TAccountTokenVaultA, TAccountTokenVaultB extends string ? WritableAccount : TAccountTokenVaultB, TAccountTickArrayLower extends string ? WritableAccount : TAccountTickArrayLower, TAccountTickArrayUpper extends string ? WritableAccount : TAccountTickArrayUpper, ...TRemainingAccounts, ] >; export interface DecreaseLiquidityV2InstructionData { discriminator: ReadonlyUint8Array; liquidityAmount: bigint; tokenMinA: bigint; tokenMinB: bigint; remainingAccountsInfo: Option; } export interface DecreaseLiquidityV2InstructionDataArgs { liquidityAmount: number | bigint; tokenMinA: number | bigint; tokenMinB: number | bigint; remainingAccountsInfo: OptionOrNullable; } export function getDecreaseLiquidityV2InstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["liquidityAmount", getU128Encoder()], ["tokenMinA", getU64Encoder()], ["tokenMinB", getU64Encoder()], [ "remainingAccountsInfo", getOptionEncoder(getRemainingAccountsInfoEncoder()), ], ]), (value) => ({ ...value, discriminator: DECREASE_LIQUIDITY_V2_DISCRIMINATOR, }), ); } export function getDecreaseLiquidityV2InstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["liquidityAmount", getU128Decoder()], ["tokenMinA", getU64Decoder()], ["tokenMinB", getU64Decoder()], [ "remainingAccountsInfo", getOptionDecoder(getRemainingAccountsInfoDecoder()), ], ]); } export function getDecreaseLiquidityV2InstructionDataCodec(): Codec< DecreaseLiquidityV2InstructionDataArgs, DecreaseLiquidityV2InstructionData > { return combineCodec( getDecreaseLiquidityV2InstructionDataEncoder(), getDecreaseLiquidityV2InstructionDataDecoder(), ); } export interface DecreaseLiquidityV2Input< TAccountWhirlpool extends string = string, TAccountTokenProgramA extends string = string, TAccountTokenProgramB extends string = string, TAccountMemoProgram extends string = string, TAccountPositionAuthority extends string = string, TAccountPosition extends string = string, TAccountPositionTokenAccount extends string = string, TAccountTokenMintA extends string = string, TAccountTokenMintB extends string = string, TAccountTokenOwnerAccountA extends string = string, TAccountTokenOwnerAccountB extends string = string, TAccountTokenVaultA extends string = string, TAccountTokenVaultB extends string = string, TAccountTickArrayLower extends string = string, TAccountTickArrayUpper extends string = string, > { whirlpool: Address; tokenProgramA: Address; tokenProgramB: Address; memoProgram?: Address; positionAuthority: TransactionSigner; position: Address; positionTokenAccount: Address; tokenMintA: Address; tokenMintB: Address; tokenOwnerAccountA: Address; tokenOwnerAccountB: Address; tokenVaultA: Address; tokenVaultB: Address; tickArrayLower: Address; tickArrayUpper: Address; liquidityAmount: DecreaseLiquidityV2InstructionDataArgs["liquidityAmount"]; tokenMinA: DecreaseLiquidityV2InstructionDataArgs["tokenMinA"]; tokenMinB: DecreaseLiquidityV2InstructionDataArgs["tokenMinB"]; remainingAccountsInfo: DecreaseLiquidityV2InstructionDataArgs["remainingAccountsInfo"]; } export function getDecreaseLiquidityV2Instruction< TAccountWhirlpool extends string, TAccountTokenProgramA extends string, TAccountTokenProgramB extends string, TAccountMemoProgram extends string, TAccountPositionAuthority extends string, TAccountPosition extends string, TAccountPositionTokenAccount extends string, TAccountTokenMintA extends string, TAccountTokenMintB extends string, TAccountTokenOwnerAccountA extends string, TAccountTokenOwnerAccountB extends string, TAccountTokenVaultA extends string, TAccountTokenVaultB extends string, TAccountTickArrayLower extends string, TAccountTickArrayUpper extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, >( input: DecreaseLiquidityV2Input< TAccountWhirlpool, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper >, config?: { programAddress?: TProgramAddress }, ): DecreaseLiquidityV2Instruction< TProgramAddress, TAccountWhirlpool, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper > { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpool: { value: input.whirlpool ?? null, isWritable: true }, tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, memoProgram: { value: input.memoProgram ?? null, isWritable: false }, positionAuthority: { value: input.positionAuthority ?? null, isWritable: false, }, position: { value: input.position ?? null, isWritable: true }, positionTokenAccount: { value: input.positionTokenAccount ?? null, isWritable: false, }, tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, tokenOwnerAccountA: { value: input.tokenOwnerAccountA ?? null, isWritable: true, }, tokenOwnerAccountB: { value: input.tokenOwnerAccountB ?? null, isWritable: true, }, tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: true }, tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: true }, }; 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("whirlpool", accounts.whirlpool), getAccountMeta("tokenProgramA", accounts.tokenProgramA), getAccountMeta("tokenProgramB", accounts.tokenProgramB), getAccountMeta("memoProgram", accounts.memoProgram), getAccountMeta("positionAuthority", accounts.positionAuthority), getAccountMeta("position", accounts.position), getAccountMeta("positionTokenAccount", accounts.positionTokenAccount), getAccountMeta("tokenMintA", accounts.tokenMintA), getAccountMeta("tokenMintB", accounts.tokenMintB), getAccountMeta("tokenOwnerAccountA", accounts.tokenOwnerAccountA), getAccountMeta("tokenOwnerAccountB", accounts.tokenOwnerAccountB), getAccountMeta("tokenVaultA", accounts.tokenVaultA), getAccountMeta("tokenVaultB", accounts.tokenVaultB), getAccountMeta("tickArrayLower", accounts.tickArrayLower), getAccountMeta("tickArrayUpper", accounts.tickArrayUpper), ], data: getDecreaseLiquidityV2InstructionDataEncoder().encode( args as DecreaseLiquidityV2InstructionDataArgs, ), programAddress, } as DecreaseLiquidityV2Instruction< TProgramAddress, TAccountWhirlpool, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper >); } export interface ParsedDecreaseLiquidityV2Instruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpool: TAccountMetas[0]; tokenProgramA: TAccountMetas[1]; tokenProgramB: TAccountMetas[2]; memoProgram: TAccountMetas[3]; positionAuthority: TAccountMetas[4]; position: TAccountMetas[5]; positionTokenAccount: TAccountMetas[6]; tokenMintA: TAccountMetas[7]; tokenMintB: TAccountMetas[8]; tokenOwnerAccountA: TAccountMetas[9]; tokenOwnerAccountB: TAccountMetas[10]; tokenVaultA: TAccountMetas[11]; tokenVaultB: TAccountMetas[12]; tickArrayLower: TAccountMetas[13]; tickArrayUpper: TAccountMetas[14]; }; data: DecreaseLiquidityV2InstructionData; } export function parseDecreaseLiquidityV2Instruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedDecreaseLiquidityV2Instruction { if (instruction.accounts.length < 15) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 15, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { whirlpool: getNextAccount(), tokenProgramA: getNextAccount(), tokenProgramB: getNextAccount(), memoProgram: getNextAccount(), positionAuthority: getNextAccount(), position: getNextAccount(), positionTokenAccount: getNextAccount(), tokenMintA: getNextAccount(), tokenMintB: getNextAccount(), tokenOwnerAccountA: getNextAccount(), tokenOwnerAccountB: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), tickArrayLower: getNextAccount(), tickArrayUpper: getNextAccount(), }, data: getDecreaseLiquidityV2InstructionDataDecoder().decode( instruction.data, ), }; }