@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
102 lines (99 loc) • 3.77 kB
TypeScript
import BN__default from 'bn.js';
import { PoolInfoLayout, DynamicFeeInfoLayout } from '../layout.js';
import '../../../marshmallow/index.js';
import '@solana/web3.js';
import '../../../marshmallow/buffer-layout.js';
interface SwapStepResult {
sqrtPriceNextX64: BN__default;
amountIn: BN__default;
amountOut: BN__default;
feeAmount: BN__default;
}
interface SwapStateInterface {
amountSpecifiedRemaining: BN__default;
amountCalculated: BN__default;
sqrtPriceX64: BN__default;
tick: number;
feeGrowthGlobalX64: BN__default;
lpFee: BN__default;
protocolFee: BN__default;
fundFee: BN__default;
liquidity: BN__default;
sqrtPriceNextX64: BN__default;
tickNext: number;
baseFeeRate: number;
tickSpacing: number;
tickSpacingIndex: number;
dynamicFeeInfo: ReturnType<typeof DynamicFeeInfoLayout.decode> | undefined;
}
declare class SwapState {
static newValue({ poolInfo, amountSpecified, zeroForOne, feeRate, blockTimestamp }: {
poolInfo: ReturnType<typeof PoolInfoLayout.decode>;
amountSpecified: BN__default;
zeroForOne: boolean;
feeRate: number;
blockTimestamp: number;
}): SwapStateInterface;
static getTargetPriceBasedOnNextTick({ data, tickNext, zeroForOne, sqrtPriceLimitX64 }: {
data: SwapStateInterface;
tickNext: number;
zeroForOne: boolean;
sqrtPriceLimitX64: BN__default;
}): BN__default;
static updateVolatilityAccumulator({ state }: {
state: SwapStateInterface;
}): void;
static computeDynamicFeeRate({ data, tickSpacing }: {
data: ReturnType<typeof DynamicFeeInfoLayout.decode>;
tickSpacing: number;
}): number;
static getTotalFeeRate({ data }: {
data: SwapStateInterface;
}): number;
static getSpacingBoundedPrice({ data, targetPrice, zeroForOne }: {
data: SwapStateInterface;
targetPrice: BN__default;
zeroForOne: boolean;
}): {
isSkipped: boolean;
boundedPrice: BN__default;
};
static applySwapAmounts({ state, amountIn, amountOut, feeAmount, isBaseInput, isFeeOnInput, protocolFeeRate, fundFeeRate, }: {
state: SwapStateInterface;
amountIn: BN__default;
amountOut: BN__default;
feeAmount: BN__default;
isBaseInput: boolean;
isFeeOnInput: boolean;
protocolFeeRate: BN__default;
fundFeeRate: BN__default;
}): void;
static updateDynamicFeeIndex({ state, zeroForOne, isSkippedTickSpacing }: {
state: SwapStateInterface;
zeroForOne: boolean;
isSkippedTickSpacing: boolean;
}): void;
static splitFee({ state, feeAmount, protocolFeeRate, fundFeeRate }: {
state: SwapStateInterface;
feeAmount: BN__default;
protocolFeeRate: BN__default;
fundFeeRate: BN__default;
}): void;
static updateVolatilityAccumulatorOnPrice({ state }: {
state: SwapStateInterface;
}): void;
}
declare class SwapMathUtil {
static newSwapComputationResult({ sqrtPriceNextX64 }: {
sqrtPriceNextX64?: BN__default;
}): SwapStepResult;
static calculateAmountInRange({ sqrtPriceCurrentX64, sqrtPriceTargetX64, liquidity, zeroForOne, isBaseInput }: {
sqrtPriceCurrentX64: BN__default;
sqrtPriceTargetX64: BN__default;
liquidity: BN__default;
zeroForOne: boolean;
isBaseInput: boolean;
}): BN__default | null;
static computeSwap(sqrtPriceCurrentX64: BN__default, sqrtPriceTargetX64: BN__default, liquidity: BN__default, amountRemaining: BN__default, feeRate: number, isBaseInput: boolean, zeroForOne: boolean, isFeeOnInput: boolean): SwapStepResult;
}
export { SwapMathUtil, SwapState, SwapStepResult };