UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

704 lines (701 loc) 21.7 kB
import { PublicKey, Transaction, Signer, Keypair, EpochInfo } from '@solana/web3.js'; import BN__default from 'bn.js'; import Decimal from 'decimal.js'; import { d as ApiClmmConfigInfo, j as ApiV3Token, bZ as GetTransferAmountFee, bY as TransferAmountFee, ck as Price, cj as Percent, cf as TokenAmount, bV as ComputeBudgetConfig, bW as TxTipConfig, ch as Fraction, bL as TokenInfo, q as ApiV3PoolInfoConcentratedItem, G as ClmmKeys } from '../../api-23ae421b.js'; export { d as ApiClmmConfigInfo } from '../../api-23ae421b.js'; import { TxVersion } from '../../common/txTool/txType.js'; import { RewardInfoLayout, TickArrayBitmapExtensionLayout, PoolInfoLayout, TickArrayLayout, PersonalPositionLayout, LockClPositionLayoutV2, LimitOrderLayout } from './layout.js'; import { CollectFeeOn } from './libraries/constants.js'; import 'axios'; import '../../solana/type.js'; import '@solana/spl-token'; import '../../api/url.js'; import '../../common/owner.js'; import '../../common/txTool/lookupTable.js'; import '../../module/token.js'; import '../../common/pubKey.js'; import '../../common/logger.js'; import '../../module/currency.js'; import '../../marshmallow/index.js'; import '../../marshmallow/buffer-layout.js'; interface ApiClmmPoint { price: string; liquidity: string; } interface ApiClmmConfigInfos { [configId: string]: ApiClmmConfigInfo; } interface ClmmConfigInfo { id: PublicKey; index: number; protocolFeeRate: number; tradeFeeRate: number; tickSpacing: number; fundFeeRate: number; fundOwner: string; description: string; } declare type ClmmPoolRewardInfo = ReturnType<typeof RewardInfoLayout.decode> & { perSecond: Decimal; remainingRewards: undefined | BN__default; tokenProgramId: PublicKey; }; interface ClmmPoolInfo { id: PublicKey; mintA: { programId: PublicKey; mint: PublicKey; vault: PublicKey; decimals: number; }; mintB: { programId: PublicKey; mint: PublicKey; vault: PublicKey; decimals: number; }; ammConfig: ClmmConfigInfo; observationId: PublicKey; creator: PublicKey; programId: PublicKey; version: 6; tickSpacing: number; liquidity: BN__default; sqrtPriceX64: BN__default; currentPrice: Decimal; tickCurrent: number; feeGrowthGlobalX64A: BN__default; feeGrowthGlobalX64B: BN__default; protocolFeesTokenA: BN__default; protocolFeesTokenB: BN__default; swapInAmountTokenA: BN__default; swapOutAmountTokenB: BN__default; swapInAmountTokenB: BN__default; swapOutAmountTokenA: BN__default; tickArrayBitmap: BN__default[]; rewardInfos: ClmmPoolRewardInfo[]; day: { volume: number; volumeFee: number; feeA: number; feeB: number; feeApr: number; rewardApr: { A: number; B: number; C: number; }; apr: number; priceMin: number; priceMax: number; }; week: { volume: number; volumeFee: number; feeA: number; feeB: number; feeApr: number; rewardApr: { A: number; B: number; C: number; }; apr: number; priceMin: number; priceMax: number; }; month: { volume: number; volumeFee: number; feeA: number; feeB: number; feeApr: number; rewardApr: { A: number; B: number; C: number; }; apr: number; priceMin: number; priceMax: number; }; tvl: number; lookupTableAccount: PublicKey; startTime: number; exBitmapInfo: ReturnType<typeof TickArrayBitmapExtensionLayout.decode>; } interface ComputeClmmPoolInfo { accInfo: ReturnType<typeof PoolInfoLayout.decode>; id: PublicKey; version: 6; mintA: ApiV3Token; mintB: ApiV3Token; vaultA: PublicKey; vaultB: PublicKey; ammConfig: ClmmConfigInfo; observationId: PublicKey; exBitmapAccount: PublicKey; creator: PublicKey; programId: PublicKey; tickSpacing: number; liquidity: BN__default; sqrtPriceX64: BN__default; currentPrice: Decimal; tickCurrent: number; feeGrowthGlobalX64A: BN__default; feeGrowthGlobalX64B: BN__default; protocolFeesTokenA: BN__default; protocolFeesTokenB: BN__default; tickArrayBitmap: Buffer; startTime: number; exBitmapInfo: ReturnType<typeof TickArrayBitmapExtensionLayout.decode>; rewardInfos: ReturnType<typeof PoolInfoLayout.decode>["rewardInfos"]; } interface ReturnTypeMakeHarvestTransaction { transactions: { transaction: Transaction; signer: Signer[]; }[]; address: { [key: string]: PublicKey; }; } interface ClmmPoolPersonalPosition { poolId: PublicKey; nftMint: PublicKey; priceLower: Decimal; priceUpper: Decimal; amountA: BN__default; amountB: BN__default; tickLower: number; tickUpper: number; liquidity: BN__default; feeGrowthInsideLastX64A: BN__default; feeGrowthInsideLastX64B: BN__default; tokenFeesOwedA: BN__default; tokenFeesOwedB: BN__default; rewardInfos: { growthInsideLastX64: BN__default; rewardAmountOwed: BN__default; pendingReward: BN__default; }[]; leverage: number; tokenFeeAmountA: BN__default; tokenFeeAmountB: BN__default; } declare type SDKParsedConcentratedInfo = { state: ClmmPoolInfo; positionAccount?: ClmmPoolPersonalPosition[]; }; interface ReturnTypeMakeCreatePoolTransaction { signers: (Signer | Keypair)[]; transaction: Transaction; mockPoolInfo: ClmmPoolInfo; } declare type ManipulateLiquidityExtInfo = { address: { tickArrayLower: PublicKey; tickArrayUpper: PublicKey; positionNftAccount: PublicKey; personalPosition: PublicKey; protocolPosition: PublicKey; }; }; interface ReturnTypeGetLiquidityAmountOut { liquidity: BN__default; amountSlippageA: GetTransferAmountFee; amountSlippageB: GetTransferAmountFee; amountA: GetTransferAmountFee; amountB: GetTransferAmountFee; expirationTime: number | undefined; } interface ReturnTypeGetAmountsFromLiquidity { amountSlippageA: BN__default; amountSlippageB: BN__default; } interface ReturnTypeComputeAmountOutFormat { allTrade: boolean; realAmountIn: TransferAmountFee; amountOut: TransferAmountFee; minAmountOut: TransferAmountFee; expirationTime: number | undefined; currentPrice: Price; executionPrice: Price; priceImpact: Percent; fee: TokenAmount; remainingAccounts: PublicKey[]; executionPriceX64: BN__default; } interface ReturnTypeComputeAmountOut { allTrade: boolean; realAmountIn: GetTransferAmountFee; amountOut: GetTransferAmountFee; minAmountOut: GetTransferAmountFee; expirationTime: number | undefined; currentPrice: Decimal; executionPrice: Decimal; priceImpact: Percent; fee: BN__default; remainingAccounts: PublicKey[]; executionPriceX64: BN__default; } interface ReturnTypeComputeAmountOutBaseOut { allTrade: boolean; amountIn: GetTransferAmountFee; maxAmountIn: GetTransferAmountFee; realAmountOut: GetTransferAmountFee; expirationTime: number | undefined; currentPrice: Decimal; executionPrice: Decimal; priceImpact: Percent; fee: BN__default; remainingAccounts: PublicKey[]; } interface ReturnTypeFetchMultiplePoolTickArrays { [poolId: string]: { [key: string]: ReturnType<typeof TickArrayLayout.decode> & { address: PublicKey; }; }; } interface CreateConcentratedPool<T = TxVersion.LEGACY> { programId: PublicKey; owner?: PublicKey; mint1: ApiV3Token; mint2: ApiV3Token; ammConfig: ClmmConfigInfo; initialPrice: Decimal; computeBudgetConfig?: ComputeBudgetConfig; txTipConfig?: TxTipConfig; forerunCreate?: boolean; getObserveState?: boolean; txVersion?: T; feePayer?: PublicKey; } interface CreateCustomizablePool<T = TxVersion.LEGACY> extends Omit<CreateConcentratedPool<T>, "getObserveState"> { collectFeeOn?: CollectFeeOn; dynamicFeeConfig?: PublicKey; } interface UserPositionAccount { /** transform to SDK function, should not used directlly in UI */ sdkParsed: ClmmPoolPersonalPosition; rewardInfos: { pendingReward: TokenAmount | undefined; apr24h: Percent; apr7d: Percent; apr30d: Percent; }[]; inRange: boolean; poolId: PublicKey; nftMint: PublicKey; priceLower: Fraction; priceUpper: Fraction; amountA?: TokenAmount; amountB?: TokenAmount; tokenA?: TokenInfo; tokenB?: TokenInfo; leverage: number; tickLower: number; tickUpper: number; positionPercentA: Percent; positionPercentB: Percent; tokenFeeAmountA?: TokenAmount; tokenFeeAmountB?: TokenAmount; getLiquidityVolume: (tokenPrices: Record<string, Price>) => { wholeLiquidity: Fraction | undefined; baseLiquidity: Fraction | undefined; quoteLiquidity: Fraction | undefined; }; } interface IncreasePositionFromLiquidity<T = TxVersion.LEGACY> { poolInfo: ApiV3PoolInfoConcentratedItem; poolKeys?: ClmmKeys; ownerPosition: ReturnType<typeof PersonalPositionLayout.decode>; ownerInfo: { useSOLBalance?: boolean; }; amountMaxA: BN__default; amountMaxB: BN__default; liquidity: BN__default; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface IncreasePositionFromBase<T = TxVersion.LEGACY> { poolInfo: ApiV3PoolInfoConcentratedItem; ownerPosition: ClmmPoolPersonalPosition; ownerInfo: { useSOLBalance?: boolean; }; base: "MintA" | "MintB"; baseAmount: BN__default; otherAmountMax: BN__default; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface DecreaseLiquidity<T = TxVersion.LEGACY> { poolInfo: ApiV3PoolInfoConcentratedItem; poolKeys?: ClmmKeys; ownerPosition: ReturnType<typeof PersonalPositionLayout.decode>; ownerInfo: { useSOLBalance?: boolean; closePosition?: boolean; }; liquidity: BN__default; amountMinA: BN__default; amountMinB: BN__default; nftAccount?: PublicKey; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface LockPosition<T = TxVersion.LEGACY> { programId?: PublicKey; authProgramId?: PublicKey; poolProgramId?: PublicKey; ownerPosition: ReturnType<typeof PersonalPositionLayout.decode>; payer?: PublicKey; computeBudgetConfig?: ComputeBudgetConfig; txTipConfig?: TxTipConfig; txVersion?: T; getEphemeralSigners?: (k: number) => any; feePayer?: PublicKey; } interface HarvestLockPosition<T = TxVersion.LEGACY> { programId?: PublicKey; authProgramId?: PublicKey; clmmProgram?: PublicKey; poolKeys?: ClmmKeys; lockData: ReturnType<typeof LockClPositionLayoutV2.decode>; ownerInfo?: { useSOLBalance?: boolean; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface OpenPositionFromBase<T = TxVersion.LEGACY> { poolInfo: SimpleClmmPoolInfo; poolKeys?: { vault: { A: string | PublicKey; B: string | PublicKey; }; lookupTableAccount?: string; }; ownerInfo: { useSOLBalance?: boolean; }; tickLower: number; tickUpper: number; base?: "MintA" | "MintB" | null; baseAmount: BN__default; otherAmountMax: BN__default; /** if not pass liquidity or pass BN 0, contract will auto calculate lp by mint amount base */ liquidity?: BN__default; nft2022?: boolean; associatedOnly?: boolean; checkCreateATAOwner?: boolean; withMetadata?: "create" | "no-create"; getEphemeralSigners?: (k: number) => any; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface OpenPositionFromBaseExtInfo { nftMint: PublicKey; tickArrayLower: PublicKey; tickArrayUpper: PublicKey; positionNftAccount: PublicKey; metadataAccount: PublicKey; personalPosition: PublicKey; protocolPosition: PublicKey; } interface OpenPositionFromLiquidity<T = TxVersion.LEGACY> { poolInfo: SimpleClmmPoolInfo; poolKeys?: ClmmKeys; ownerInfo: { useSOLBalance?: boolean; }; amountMaxA: BN__default; amountMaxB: BN__default; base?: "MintA" | "MintB" | null; tickLower: number; tickUpper: number; liquidity: BN__default; associatedOnly?: boolean; checkCreateATAOwner?: boolean; withMetadata?: "create" | "no-create"; getEphemeralSigners?: (k: number) => any; txVersion?: T; computeBudgetConfig: any; nft2022?: boolean; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface OpenPositionFromLiquidityExtInfo { address: { nftMint: PublicKey; tickArrayLower: PublicKey; tickArrayUpper: PublicKey; positionNftAccount: PublicKey; metadataAccount: PublicKey; personalPosition: PublicKey; protocolPosition: PublicKey; }; } interface GetAmountParams { poolInfo: ApiV3PoolInfoConcentratedItem; ownerPosition: ReturnType<typeof PersonalPositionLayout.decode>; liquidity: BN__default; slippage: number; add: boolean; epochInfo: EpochInfo; } interface InitRewardParams<T = TxVersion.LEGACY> { poolInfo: ApiV3PoolInfoConcentratedItem; poolKeys?: ClmmKeys; ownerInfo: { feePayer?: PublicKey; useSOLBalance?: boolean; }; rewardInfo: { mint: ApiV3Token; openTime: number; endTime: number; perSecond: Decimal; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface InitRewardsParams<T = TxVersion.LEGACY> extends Omit<InitRewardParams<T>, "rewardInfo"> { rewardInfos: { mint: ApiV3Token; openTime: number; endTime: number; perSecond: Decimal; }[]; } interface SetRewardParams<T = TxVersion.LEGACY> { poolInfo: ApiV3PoolInfoConcentratedItem; poolKeys?: ClmmKeys; ownerInfo: { feePayer?: PublicKey; useSOLBalance?: boolean; }; rewardInfo: { programId: PublicKey; mint: PublicKey; openTime: number; endTime: number; perSecond: Decimal; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface SetRewardsParams<T = TxVersion.LEGACY> extends Omit<SetRewardParams<T>, "rewardInfo"> { rewardInfos: { mint: ApiV3Token; openTime: number; endTime: number; perSecond: Decimal; }[]; } interface CollectRewardParams<T = TxVersion.LEGACY> { poolInfo: ApiV3PoolInfoConcentratedItem; ownerInfo: { feePayer?: PublicKey; useSOLBalance?: boolean; }; rewardMint: PublicKey; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface CollectRewardsParams<T = TxVersion.LEGACY> extends Omit<CollectRewardParams, "rewardMint"> { rewardMints: PublicKey[]; } interface HarvestAllRewardsParams<T = TxVersion.LEGACY> { allPoolInfo: Record<string, ApiV3PoolInfoConcentratedItem>; allPositions: Record<string, ReturnType<typeof PersonalPositionLayout.decode>[]>; ownerInfo: { feePayer?: PublicKey; useSOLBalance?: boolean; }; lockInfo?: { [poolId: string]: { [positionNft: string]: ReturnType<typeof LockClPositionLayoutV2.decode>; }; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; programId?: PublicKey; txVersion?: T; computeBudgetConfig?: ComputeBudgetConfig; txTipConfig?: TxTipConfig; feePayer?: PublicKey; lockProgram?: PublicKey; lockAuth?: PublicKey; clmmProgram?: PublicKey; } interface ReturnTypeFetchExBitmaps { [exBitmapId: string]: ReturnType<typeof TickArrayBitmapExtensionLayout.decode>; } interface ClosePositionExtInfo { address: { positionNftAccount: PublicKey; personalPosition: PublicKey; }; } interface InitRewardExtInfo { address: { poolRewardVault: PublicKey; operationId: PublicKey; }; } declare type ClmmParsedRpcData = ReturnType<typeof PoolInfoLayout.decode> & { currentPrice: number; programId: PublicKey; }; interface SimpleClmmPoolInfo { id: string; programId: string; mintA: { address: string; programId: string; decimals: number; }; mintB: { address: string; programId: string; decimals: number; }; config: { id: string; tickSpacing: number; }; } interface ClmmLockAddress { positionId: PublicKey; lockPositionId: PublicKey; lockNftAccount: PublicKey; lockNftMint: PublicKey; positionNftAccount: PublicKey; metadataAccount: PublicKey; } interface OpenLimitOrder<T = TxVersion.LEGACY> { poolInfo: SimpleClmmPoolInfo; baseIn?: boolean; orderTick: number; amount: BN__default; noneIndex?: number; ownerInfo?: { feePayer?: PublicKey; useSOLBalance?: boolean; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; tickArrayBitmap?: PublicKey; } interface IncreaseLimitOrder<T = TxVersion.LEGACY> { poolInfo: SimpleClmmPoolInfo; limitOrder: PublicKey; limitOrderInfo?: ReturnType<typeof LimitOrderLayout.decode>; tickArrayBitmap?: PublicKey; amount: BN__default; ownerInfo?: { feePayer?: PublicKey; useSOLBalance?: boolean; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; forerunCreate?: boolean; } interface DecreaseLimitOrder<T = TxVersion.LEGACY> extends IncreaseLimitOrder<T> { /** 0~1000 means 0.01% ~ 100% */ slippage?: number; } interface CloseLimitOrder<T = TxVersion.LEGACY> { programId?: PublicKey; limitOrder: PublicKey; autoWithdraw?: boolean; /** 0~1000 means 0.01% ~ 100% */ slippage?: number; tickArrayBitmap?: PublicKey; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; } interface CloseAllLimitOrder<T = TxVersion.LEGACY> { programId?: PublicKey; limitOrders: PublicKey[]; autoWithdraw?: boolean; /** 0~10000 means 0.01% ~ 100% */ slippage?: number; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; feePayer?: PublicKey; } interface SettleLimitOrder<T = TxVersion.LEGACY> { limitOrder: PublicKey; ownerInfo?: { feePayer?: PublicKey; useSOLBalance?: boolean; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; txTipConfig?: TxTipConfig; feePayer?: PublicKey; forerunCreate?: boolean; } interface SettleAllLimitOrders<T = TxVersion.LEGACY> { limitOrders: PublicKey[]; ownerInfo?: { feePayer?: PublicKey; useSOLBalance?: boolean; }; associatedOnly?: boolean; checkCreateATAOwner?: boolean; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; feePayer?: PublicKey; } export { ApiClmmConfigInfos, ApiClmmPoint, ClmmConfigInfo, ClmmLockAddress, ClmmParsedRpcData, ClmmPoolInfo, ClmmPoolPersonalPosition, ClmmPoolRewardInfo, CloseAllLimitOrder, CloseLimitOrder, ClosePositionExtInfo, CollectRewardParams, CollectRewardsParams, ComputeClmmPoolInfo, CreateConcentratedPool, CreateCustomizablePool, DecreaseLimitOrder, DecreaseLiquidity, GetAmountParams, HarvestAllRewardsParams, HarvestLockPosition, IncreaseLimitOrder, IncreasePositionFromBase, IncreasePositionFromLiquidity, InitRewardExtInfo, InitRewardParams, InitRewardsParams, LockPosition, ManipulateLiquidityExtInfo, OpenLimitOrder, OpenPositionFromBase, OpenPositionFromBaseExtInfo, OpenPositionFromLiquidity, OpenPositionFromLiquidityExtInfo, ReturnTypeComputeAmountOut, ReturnTypeComputeAmountOutBaseOut, ReturnTypeComputeAmountOutFormat, ReturnTypeFetchExBitmaps, ReturnTypeFetchMultiplePoolTickArrays, ReturnTypeGetAmountsFromLiquidity, ReturnTypeGetLiquidityAmountOut, ReturnTypeMakeCreatePoolTransaction, ReturnTypeMakeHarvestTransaction, SDKParsedConcentratedInfo, SetRewardParams, SetRewardsParams, SettleAllLimitOrders, SettleLimitOrder, SimpleClmmPoolInfo, UserPositionAccount };