Module @orca-so/whirlpools-core

Orca Whirlpools Core SDK (WebAssembly)

This package provides developers with advanced functionalities for interacting with the Whirlpool Program on Solana. Originally written in Rust, it has been compiled to WebAssembly (Wasm). This compilation makes the SDK accessible in JavaScript/TypeScript environments, offering developers the same core features and calculations for their Typescript projects. The SDK exposes convenient methods for math calculations, quotes, and other utilities, enabling seamless integration within web-based projects.

  • Math Library: Contains a variety of functions for math operations related to bundles, positions, prices, ticks, and tokens, including calculations such as determining position status or price conversions.
  • Quote Library: Provides utility functions for generating quotes, such as increasing liquidity, collecting fees or rewards, and swapping, to help developers make informed decisions regarding liquidity management.

You can install the package via npm:

npm install @orca-so/whirlpools-core

Here are some basic examples of how to use the package:

The following example demonstrates how to use the isPositionInRange function to determine whether a position is currently in range.

import { isPositionInRange } from "@orca-so/whirlpools-core";

const currentSqrtPrice = 7448043534253661173n;
const tickIndex1 = -18304;
const tickIndex2 = -17956;

const inRange = isPositionInRange(currentSqrtPrice, tickIndex1, tickIndex2);
console.log("Position in range:", inRange);

Expected output:

Position in range? true

The following example demonstrates how to use the increaseLiquidityQuoteA function to calculate a quote for increasing liquidity given a token A amount.

import { increaseLiquidityQuoteA } from "@orca-so/whirlpools-core";

const tokenAmountA = 1000000000n;
const slippageToleranceBps = 100;
const currentSqrtPrice = 7437568627975669726n;
const tickIndex1 = -18568;
const tickIndex2 = -17668;
const transferFeeA = { feeBps: 200, maxFee: 1000000000n };

const quote = increaseLiquidityQuoteA(
tokenAmountA,
slippageToleranceBps,
currentSqrtPrice,
tickIndex1,
tickIndex2,
transferFeeA,
);

console.log(quote);

Expected output:

{
liquidityDelta: 16011047470n,
tokenEstA: 1000000000n,
tokenEstB: 127889169n,
tokenMaxA: 1010000000n,
tokenMaxB: 129168061n
}

Interfaces

CollectFeesQuote
CollectRewardQuote
CollectRewardsQuote
DecreaseLiquidityQuote
ExactInSwapQuote
ExactOutSwapQuote
IncreaseLiquidityQuote
PositionFacade
PositionRatio
PositionRewardInfoFacade
TickArrayFacade
TickFacade
TickRange
TransferFee
WhirlpoolFacade
WhirlpoolRewardInfoFacade

Type Aliases

PositionStatus

Functions

_AMOUNT_EXCEEDS_MAX_U64
_ARITHMETIC_OVERFLOW
_FEE_RATE_DENOMINATOR
_FULL_RANGE_ONLY_TICK_SPACING_THRESHOLD
_INVALID_SLIPPAGE_TOLERANCE
_INVALID_SQRT_PRICE_LIMIT_DIRECTION
_INVALID_TICK_INDEX
_INVALID_TIMESTAMP
_INVALID_TRANSFER_FEE
_MAX_TICK_INDEX
_MIN_TICK_INDEX
_NUM_REWARDS
_POSITION_BUNDLE_SIZE
_SQRT_PRICE_LIMIT_OUT_OF_BOUNDS
_SQRT_PRICE_OUT_OF_BOUNDS
_TICK_ARRAY_NOT_EVENLY_SPACED
_TICK_ARRAY_SIZE
_TICK_INDEX_NOT_IN_ARRAY
_TICK_INDEX_OUT_OF_BOUNDS
_TICK_SEQUENCE_EMPTY
_ZERO_TRADABLE_AMOUNT
collectFeesQuote
collectRewardsQuote
decreaseLiquidityQuote
decreaseLiquidityQuoteA
decreaseLiquidityQuoteB
firstUnoccupiedPositionInBundle
getFullRangeTickIndexes
getInitializableTickIndex
getNextInitializableTickIndex
getPrevInitializableTickIndex
getTickArrayStartTickIndex
getTickIndexInArray
increaseLiquidityQuote
increaseLiquidityQuoteA
increaseLiquidityQuoteB
invertPrice
invertSqrtPrice
invertTickIndex
isFullRangeOnly
isPositionBundleEmpty
isPositionBundleFull
isPositionInRange
isTickIndexInBounds
isTickInitializable
orderTickIndexes
positionRatio
positionStatus
priceToSqrtPrice
priceToTickIndex
sqrtPriceToPrice
sqrtPriceToTickIndex
swapQuoteByInputToken
swapQuoteByOutputToken
tickIndexToPrice
tickIndexToSqrtPrice
tryApplySwapFee
tryApplyTransferFee
tryGetAmountDeltaA
tryGetAmountDeltaB
tryGetMaxAmountWithSlippageTolerance
tryGetMinAmountWithSlippageTolerance
tryGetNextSqrtPriceFromA
tryGetNextSqrtPriceFromB
tryReverseApplySwapFee
tryReverseApplyTransferFee