@stabbleorg/mclmm-sdk 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/config.d.ts +25 -0
- package/lib/api/config.d.ts.map +1 -0
- package/lib/api/index.d.ts +15 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/pools.d.ts +39 -0
- package/lib/api/pools.d.ts.map +1 -0
- package/lib/client.d.ts +43 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/clmm.d.ts +91 -0
- package/lib/clmm.d.ts.map +1 -0
- package/lib/constants.d.ts +62 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/generated/accounts/ammConfig.d.ts +58 -0
- package/lib/generated/accounts/ammConfig.d.ts.map +1 -0
- package/lib/generated/accounts/index.d.ts +17 -0
- package/lib/generated/accounts/index.d.ts.map +1 -0
- package/lib/generated/accounts/observationState.d.ts +51 -0
- package/lib/generated/accounts/observationState.d.ts.map +1 -0
- package/lib/generated/accounts/operationState.d.ts +38 -0
- package/lib/generated/accounts/operationState.d.ts.map +1 -0
- package/lib/generated/accounts/personalPositionState.d.ts +73 -0
- package/lib/generated/accounts/personalPositionState.d.ts.map +1 -0
- package/lib/generated/accounts/poolState.d.ts +157 -0
- package/lib/generated/accounts/poolState.d.ts.map +1 -0
- package/lib/generated/accounts/protocolPositionState.d.ts +70 -0
- package/lib/generated/accounts/protocolPositionState.d.ts.map +1 -0
- package/lib/generated/accounts/supportMintAssociated.d.ts +36 -0
- package/lib/generated/accounts/supportMintAssociated.d.ts.map +1 -0
- package/lib/generated/accounts/tickArrayBitmapExtension.d.ts +36 -0
- package/lib/generated/accounts/tickArrayBitmapExtension.d.ts.map +1 -0
- package/lib/generated/accounts/tickArrayState.d.ts +39 -0
- package/lib/generated/accounts/tickArrayState.d.ts.map +1 -0
- package/lib/generated/errors/ammV3.d.ts +110 -0
- package/lib/generated/errors/ammV3.d.ts.map +1 -0
- package/lib/generated/errors/index.d.ts +9 -0
- package/lib/generated/errors/index.d.ts.map +1 -0
- package/lib/generated/index.d.ts +13 -0
- package/lib/generated/index.d.ts.map +1 -0
- package/lib/generated/instructions/closePosition.d.ts +78 -0
- package/lib/generated/instructions/closePosition.d.ts.map +1 -0
- package/lib/generated/instructions/closeProtocolPosition.d.ts +40 -0
- package/lib/generated/instructions/closeProtocolPosition.d.ts.map +1 -0
- package/lib/generated/instructions/collectFundFee.d.ts +96 -0
- package/lib/generated/instructions/collectFundFee.d.ts.map +1 -0
- package/lib/generated/instructions/collectProtocolFee.d.ts +96 -0
- package/lib/generated/instructions/collectProtocolFee.d.ts.map +1 -0
- package/lib/generated/instructions/collectRemainingRewards.d.ts +76 -0
- package/lib/generated/instructions/collectRemainingRewards.d.ts.map +1 -0
- package/lib/generated/instructions/createAmmConfig.d.ts +78 -0
- package/lib/generated/instructions/createAmmConfig.d.ts.map +1 -0
- package/lib/generated/instructions/createOperationAccount.d.ts +57 -0
- package/lib/generated/instructions/createOperationAccount.d.ts.map +1 -0
- package/lib/generated/instructions/createPool.d.ts +133 -0
- package/lib/generated/instructions/createPool.d.ts.map +1 -0
- package/lib/generated/instructions/createSupportMintAssociated.d.ts +64 -0
- package/lib/generated/instructions/createSupportMintAssociated.d.ts.map +1 -0
- package/lib/generated/instructions/decreaseLiquidity.d.ts +100 -0
- package/lib/generated/instructions/decreaseLiquidity.d.ts.map +1 -0
- package/lib/generated/instructions/decreaseLiquidityV2.d.ts +120 -0
- package/lib/generated/instructions/decreaseLiquidityV2.d.ts.map +1 -0
- package/lib/generated/instructions/increaseLiquidity.d.ts +100 -0
- package/lib/generated/instructions/increaseLiquidity.d.ts.map +1 -0
- package/lib/generated/instructions/increaseLiquidityV2.d.ts +118 -0
- package/lib/generated/instructions/increaseLiquidityV2.d.ts.map +1 -0
- package/lib/generated/instructions/index.d.ts +34 -0
- package/lib/generated/instructions/index.d.ts.map +1 -0
- package/lib/generated/instructions/initializeReward.d.ts +113 -0
- package/lib/generated/instructions/initializeReward.d.ts.map +1 -0
- package/lib/generated/instructions/openPosition.d.ts +198 -0
- package/lib/generated/instructions/openPosition.d.ts.map +1 -0
- package/lib/generated/instructions/openPositionV2.d.ts +218 -0
- package/lib/generated/instructions/openPositionV2.d.ts.map +1 -0
- package/lib/generated/instructions/openPositionWithToken22Nft.d.ts +201 -0
- package/lib/generated/instructions/openPositionWithToken22Nft.d.ts.map +1 -0
- package/lib/generated/instructions/setRewardParams.d.ts +92 -0
- package/lib/generated/instructions/setRewardParams.d.ts.map +1 -0
- package/lib/generated/instructions/swap.d.ts +95 -0
- package/lib/generated/instructions/swap.d.ts.map +1 -0
- package/lib/generated/instructions/swapRouterBaseIn.d.ts +71 -0
- package/lib/generated/instructions/swapRouterBaseIn.d.ts.map +1 -0
- package/lib/generated/instructions/swapV2.d.ts +112 -0
- package/lib/generated/instructions/swapV2.d.ts.map +1 -0
- package/lib/generated/instructions/transferRewardOwner.d.ts +46 -0
- package/lib/generated/instructions/transferRewardOwner.d.ts.map +1 -0
- package/lib/generated/instructions/updateAmmConfig.d.ts +51 -0
- package/lib/generated/instructions/updateAmmConfig.d.ts.map +1 -0
- package/lib/generated/instructions/updateOperationAccount.d.ts +66 -0
- package/lib/generated/instructions/updateOperationAccount.d.ts.map +1 -0
- package/lib/generated/instructions/updatePoolStatus.d.ts +44 -0
- package/lib/generated/instructions/updatePoolStatus.d.ts.map +1 -0
- package/lib/generated/instructions/updateRewardInfos.d.ts +39 -0
- package/lib/generated/instructions/updateRewardInfos.d.ts.map +1 -0
- package/lib/generated/programs/ammV3.d.ts +109 -0
- package/lib/generated/programs/ammV3.d.ts.map +1 -0
- package/lib/generated/programs/index.d.ts +9 -0
- package/lib/generated/programs/index.d.ts.map +1 -0
- package/lib/generated/shared/index.d.ts +50 -0
- package/lib/generated/shared/index.d.ts.map +1 -0
- package/lib/generated/types/collectPersonalFeeEvent.d.ts +37 -0
- package/lib/generated/types/collectPersonalFeeEvent.d.ts.map +1 -0
- package/lib/generated/types/collectProtocolFeeEvent.d.ts +37 -0
- package/lib/generated/types/collectProtocolFeeEvent.d.ts.map +1 -0
- package/lib/generated/types/configChangeEvent.d.ts +23 -0
- package/lib/generated/types/configChangeEvent.d.ts.map +1 -0
- package/lib/generated/types/createPersonalPositionEvent.d.ts +57 -0
- package/lib/generated/types/createPersonalPositionEvent.d.ts.map +1 -0
- package/lib/generated/types/decreaseLiquidityEvent.d.ts +51 -0
- package/lib/generated/types/decreaseLiquidityEvent.d.ts.map +1 -0
- package/lib/generated/types/increaseLiquidityEvent.d.ts +41 -0
- package/lib/generated/types/increaseLiquidityEvent.d.ts.map +1 -0
- package/lib/generated/types/index.d.ts +23 -0
- package/lib/generated/types/index.d.ts.map +1 -0
- package/lib/generated/types/liquidityCalculateEvent.d.ts +51 -0
- package/lib/generated/types/liquidityCalculateEvent.d.ts.map +1 -0
- package/lib/generated/types/liquidityChangeEvent.d.ts +41 -0
- package/lib/generated/types/liquidityChangeEvent.d.ts.map +1 -0
- package/lib/generated/types/observation.d.ts +29 -0
- package/lib/generated/types/observation.d.ts.map +1 -0
- package/lib/generated/types/poolCreatedEvent.d.ts +52 -0
- package/lib/generated/types/poolCreatedEvent.d.ts.map +1 -0
- package/lib/generated/types/positionRewardInfo.d.ts +20 -0
- package/lib/generated/types/positionRewardInfo.d.ts.map +1 -0
- package/lib/generated/types/rewardInfo.d.ts +66 -0
- package/lib/generated/types/rewardInfo.d.ts.map +1 -0
- package/lib/generated/types/swapEvent.d.ts +77 -0
- package/lib/generated/types/swapEvent.d.ts.map +1 -0
- package/lib/generated/types/tickState.d.ts +42 -0
- package/lib/generated/types/tickState.d.ts.map +1 -0
- package/lib/generated/types/updateRewardInfosEvent.d.ts +21 -0
- package/lib/generated/types/updateRewardInfosEvent.d.ts.map +1 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +9385 -0
- package/lib/index.mjs +10022 -0
- package/lib/pool-manager.d.ts +84 -0
- package/lib/pool-manager.d.ts.map +1 -0
- package/lib/position-manager.d.ts +127 -0
- package/lib/position-manager.d.ts.map +1 -0
- package/lib/rewards.d.ts +7 -0
- package/lib/rewards.d.ts.map +1 -0
- package/lib/swap.d.ts +6 -0
- package/lib/swap.d.ts.map +1 -0
- package/lib/types.d.ts +307 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/utils/index.d.ts +83 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/math.d.ts +51 -0
- package/lib/utils/math.d.ts.map +1 -0
- package/lib/utils/pda.d.ts +80 -0
- package/lib/utils/pda.d.ts.map +1 -0
- package/lib/utils/pool.d.ts +180 -0
- package/lib/utils/pool.d.ts.map +1 -0
- package/lib/utils/tick.d.ts +172 -0
- package/lib/utils/tick.d.ts.map +1 -0
- package/lib/utils/tickQuery.d.ts +13 -0
- package/lib/utils/tickQuery.d.ts.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
export declare class MathUtils {
|
|
4
|
+
static mulDivRoundingUp(a: BN, b: BN, denominator: BN): BN;
|
|
5
|
+
static mulDivFloor(a: BN, b: BN, denominator: BN): BN;
|
|
6
|
+
static mulDivCeil(a: BN, b: BN, denominator: BN): BN;
|
|
7
|
+
static x64ToDecimal(num: BN, decimalPlaces?: number): Decimal;
|
|
8
|
+
static decimalToX64(num: Decimal): BN;
|
|
9
|
+
static wrappingSubU128(n0: BN, n1: BN): BN;
|
|
10
|
+
}
|
|
11
|
+
export declare class SqrtPriceMath {
|
|
12
|
+
static sqrtPriceX64ToPrice(sqrtPriceX64: BN, decimalsA: number, decimalsB: number): Decimal;
|
|
13
|
+
static priceToSqrtPriceX64(price: Decimal, decimalsA: number, decimalsB: number): BN;
|
|
14
|
+
static getNextSqrtPriceX64FromInput(sqrtPriceX64: BN, liquidity: BN, amountIn: BN, zeroForOne: boolean): BN;
|
|
15
|
+
static getNextSqrtPriceX64FromOutput(sqrtPriceX64: BN, liquidity: BN, amountOut: BN, zeroForOne: boolean): BN;
|
|
16
|
+
private static getNextSqrtPriceFromTokenAmountARoundingUp;
|
|
17
|
+
private static getNextSqrtPriceFromTokenAmountBRoundingDown;
|
|
18
|
+
static getSqrtPriceX64FromTick(tick: number): BN;
|
|
19
|
+
static getTickFromPrice(price: Decimal, decimalsA: number, decimalsB: number): number;
|
|
20
|
+
static getTickFromSqrtPriceX64(sqrtPriceX64: BN): number;
|
|
21
|
+
}
|
|
22
|
+
export declare class TickMath {
|
|
23
|
+
static getTickWithPriceAndTickspacing(price: Decimal, tickSpacing: number, mintDecimalsA: number, mintDecimalsB: number): number;
|
|
24
|
+
static roundPriceWithTickspacing(price: Decimal, tickSpacing: number, mintDecimalsA: number, mintDecimalsB: number): Decimal;
|
|
25
|
+
}
|
|
26
|
+
export declare class LiquidityMath {
|
|
27
|
+
static addDelta(x: BN, y: BN): BN;
|
|
28
|
+
static getTokenAmountAFromLiquidity(sqrtPriceX64A: BN, sqrtPriceX64B: BN, liquidity: BN, roundUp: boolean): BN;
|
|
29
|
+
static getTokenAmountBFromLiquidity(sqrtPriceX64A: BN, sqrtPriceX64B: BN, liquidity: BN, roundUp: boolean): BN;
|
|
30
|
+
static getLiquidityFromTokenAmountA(sqrtPriceX64A: BN, sqrtPriceX64B: BN, amountA: BN, roundUp: boolean): BN;
|
|
31
|
+
static getLiquidityFromTokenAmountB(sqrtPriceX64A: BN, sqrtPriceX64B: BN, amountB: BN): BN;
|
|
32
|
+
static getLiquidityFromTokenAmounts(sqrtPriceCurrentX64: BN, sqrtPriceX64A: BN, sqrtPriceX64B: BN, amountA: BN, amountB: BN): BN;
|
|
33
|
+
static getAmountsFromLiquidity(sqrtPriceCurrentX64: BN, sqrtPriceX64A: BN, sqrtPriceX64B: BN, liquidity: BN, roundUp: boolean): {
|
|
34
|
+
amountA: BN;
|
|
35
|
+
amountB: BN;
|
|
36
|
+
};
|
|
37
|
+
static getAmountsFromLiquidityWithSlippage(sqrtPriceCurrentX64: BN, sqrtPriceX64A: BN, sqrtPriceX64B: BN, liquidity: BN, amountMax: boolean, roundUp: boolean, amountSlippage: number): {
|
|
38
|
+
amountSlippageA: BN;
|
|
39
|
+
amountSlippageB: BN;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface StepComputations {
|
|
43
|
+
sqrtPriceStartX64: BN;
|
|
44
|
+
tickNext: number;
|
|
45
|
+
initialized: boolean;
|
|
46
|
+
sqrtPriceNextX64: BN;
|
|
47
|
+
amountIn: BN;
|
|
48
|
+
amountOut: BN;
|
|
49
|
+
feeAmount: BN;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/utils/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,OAAO,MAAM,YAAY,CAAC;AAoBjC,qBAAa,SAAS;WACN,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;WASnD,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;WAO9C,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;WAQ7C,YAAY,CAAC,GAAG,EAAE,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO;WAMtD,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,EAAE;WAI9B,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE;CAGlD;AAmBD,qBAAa,aAAa;WACV,mBAAmB,CAC/B,YAAY,EAAE,EAAE,EAChB,SAAS,EAAE,MAAM,EACjB,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M account types
|
|
4
|
+
*/
|
|
5
|
+
import { type Address, type ProgramDerivedAddress } from "@solana/kit";
|
|
6
|
+
export declare class PdaUtils {
|
|
7
|
+
/**
|
|
8
|
+
* Derive pool state PDA
|
|
9
|
+
* @param ammConfig - AMM config address
|
|
10
|
+
* @param tokenMintA - Token A mint address
|
|
11
|
+
* @param tokenMintB - Token B mint address
|
|
12
|
+
* @returns Pool state PDA
|
|
13
|
+
*/
|
|
14
|
+
static getPoolStatePda(ammConfig: Address, tokenMintA: Address, tokenMintB: Address): Promise<ProgramDerivedAddress>;
|
|
15
|
+
/**
|
|
16
|
+
* Derive AMM config PDA
|
|
17
|
+
* @param index - Config index
|
|
18
|
+
* @returns AMM config PDA
|
|
19
|
+
*/
|
|
20
|
+
static getAmmConfigPda(index: number): Promise<ProgramDerivedAddress>;
|
|
21
|
+
/**
|
|
22
|
+
* Derive position state PDA
|
|
23
|
+
* @param nftMint - Position NFT mint address
|
|
24
|
+
* @returns Position state PDA
|
|
25
|
+
*/
|
|
26
|
+
static getPositionStatePda(nftMint: Address): Promise<ProgramDerivedAddress>;
|
|
27
|
+
/**
|
|
28
|
+
* Derive tick array state PDA
|
|
29
|
+
* @param poolState - Pool state address
|
|
30
|
+
* @param startTickIndex - Starting tick index of the array
|
|
31
|
+
* @returns Tick array state PDA
|
|
32
|
+
*/
|
|
33
|
+
static getTickArrayStatePda(poolState: Address, startTickIndex: number): Promise<ProgramDerivedAddress>;
|
|
34
|
+
/**
|
|
35
|
+
* Derive observation state PDA
|
|
36
|
+
* @param poolState - Pool state address
|
|
37
|
+
* @returns Observation state PDA
|
|
38
|
+
*/
|
|
39
|
+
static getObservationStatePda(poolState: Address): Promise<ProgramDerivedAddress>;
|
|
40
|
+
static getPoolVaultIdPda(poolAddress: Address, vaultAddress: Address): Promise<ProgramDerivedAddress>;
|
|
41
|
+
/**
|
|
42
|
+
* Derive tick array bitmap extension PDA
|
|
43
|
+
* @param poolState - Pool state address
|
|
44
|
+
* @returns Tick array bitmap extension PDA
|
|
45
|
+
*/
|
|
46
|
+
static getTickArrayBitmapExtensionPda(poolState: Address): Promise<ProgramDerivedAddress>;
|
|
47
|
+
/**
|
|
48
|
+
* Calculate start tick index for tick array containing a specific tick
|
|
49
|
+
* @param tick - Target tick
|
|
50
|
+
* @param tickSpacing - Tick spacing of the pool
|
|
51
|
+
* @returns Start tick index for the tick array
|
|
52
|
+
*/
|
|
53
|
+
static getTickArrayStartIndex(tick: number, tickSpacing: number): number;
|
|
54
|
+
/**
|
|
55
|
+
* Get all tick array PDAs needed for a price range
|
|
56
|
+
* @param poolState - Pool state address
|
|
57
|
+
* @param tickLower - Lower tick of range
|
|
58
|
+
* @param tickUpper - Upper tick of range
|
|
59
|
+
* @param tickSpacing - Tick spacing of the pool
|
|
60
|
+
* @param tickCurrent - Current pool tick
|
|
61
|
+
* @returns Array of tick array PDAs
|
|
62
|
+
*/
|
|
63
|
+
static getTickArrayPdasForRange(poolState: Address, tickLower: number, tickUpper: number, tickSpacing: number, tickCurrent: number): Promise<ProgramDerivedAddress[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Derive protocol position state PDA
|
|
66
|
+
* @param poolState - Pool state address
|
|
67
|
+
* @param tickLowerIndex - Lower tick index
|
|
68
|
+
* @param tickUpperIndex - Upper tick index
|
|
69
|
+
* @returns Protocol position state PDA
|
|
70
|
+
*/
|
|
71
|
+
static getProtocolPositionStatePda(poolState: Address, tickLowerIndex: number, tickUpperIndex: number): Promise<ProgramDerivedAddress>;
|
|
72
|
+
/**
|
|
73
|
+
* Derive operation state PDA
|
|
74
|
+
* @param poolState - Pool state address
|
|
75
|
+
* @returns Operation state PDA
|
|
76
|
+
*/
|
|
77
|
+
static getOperationStatePda(poolState: Address): Promise<ProgramDerivedAddress>;
|
|
78
|
+
}
|
|
79
|
+
export declare function getMetadataPda(mint: Address): Promise<ProgramDerivedAddress>;
|
|
80
|
+
//# sourceMappingURL=pda.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,qBAAqB,CAAC;IAYjC;;;;OAIG;WACU,oBAAoB,CAC/B,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,qBAAqB,CAAC;CAMlC;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,qBAAqB,CAAC,CAShC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
import type { PoolState, AmmConfig } from "../generated";
|
|
3
|
+
import { type TickArray } from "./tick";
|
|
4
|
+
import BN from "bn.js";
|
|
5
|
+
/**
|
|
6
|
+
* Pool information with computed values
|
|
7
|
+
*/
|
|
8
|
+
export interface ComputedPoolInfo {
|
|
9
|
+
/** Pool state */
|
|
10
|
+
poolState: PoolState;
|
|
11
|
+
/** Current price in human readable format */
|
|
12
|
+
currentPrice: number;
|
|
13
|
+
/** Current sqrt price X64 */
|
|
14
|
+
sqrtPriceX64: BN;
|
|
15
|
+
/** Current tick */
|
|
16
|
+
tickCurrent: number;
|
|
17
|
+
/** Current liquidity */
|
|
18
|
+
liquidity: BN;
|
|
19
|
+
/** Token A vault balance */
|
|
20
|
+
vaultABalance: BN;
|
|
21
|
+
/** Token B vault balance */
|
|
22
|
+
vaultBBalance: BN;
|
|
23
|
+
/** Fee growth global for token A */
|
|
24
|
+
feeGrowthGlobalA: BN;
|
|
25
|
+
/** Fee growth global for token B */
|
|
26
|
+
feeGrowthGlobalB: BN;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Swap computation result
|
|
30
|
+
*/
|
|
31
|
+
export interface SwapResult {
|
|
32
|
+
/** Whether entire input was consumed */
|
|
33
|
+
allTrade: boolean;
|
|
34
|
+
/** Amount calculated (output for exact input, input for exact output) */
|
|
35
|
+
amountCalculated: BN;
|
|
36
|
+
/** Final sqrt price after swap */
|
|
37
|
+
sqrtPriceX64: BN;
|
|
38
|
+
/** Liquidity after swap */
|
|
39
|
+
liquidity: BN;
|
|
40
|
+
/** Fee amount charged */
|
|
41
|
+
feeAmount: BN;
|
|
42
|
+
/** Required tick arrays */
|
|
43
|
+
tickArrays: Address[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Liquidity calculation result
|
|
47
|
+
*/
|
|
48
|
+
export interface LiquidityResult {
|
|
49
|
+
/** Liquidity amount */
|
|
50
|
+
liquidity: BN;
|
|
51
|
+
/** Token A amount */
|
|
52
|
+
amount0: BN;
|
|
53
|
+
/** Token B amount */
|
|
54
|
+
amount1: BN;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Pool utility functions
|
|
58
|
+
*/
|
|
59
|
+
export declare class PoolUtils {
|
|
60
|
+
/**
|
|
61
|
+
* Calculate pool state from raw pool data
|
|
62
|
+
* @param poolState - Raw pool state
|
|
63
|
+
* @param ammConfig - AMM configuration
|
|
64
|
+
* @returns Computed pool information
|
|
65
|
+
*/
|
|
66
|
+
static computePoolInfo(poolState: PoolState, _ammConfig: AmmConfig): ComputedPoolInfo;
|
|
67
|
+
/**
|
|
68
|
+
* Calculate swap output for exact input
|
|
69
|
+
* @param poolInfo - Pool information
|
|
70
|
+
* @param inputMint - Input token mint
|
|
71
|
+
* @param amountIn - Input amount
|
|
72
|
+
* @param slippageTolerance - Slippage tolerance (0-1)
|
|
73
|
+
* @param tickArrays - Available tick arrays
|
|
74
|
+
* @returns Swap computation result
|
|
75
|
+
*/
|
|
76
|
+
static computeSwapExactInput(poolInfo: ComputedPoolInfo, inputMint: Address, amountIn: BN, _slippageTolerance?: number, tickArrays?: TickArray[]): SwapResult;
|
|
77
|
+
/**
|
|
78
|
+
* Calculate swap input for exact output
|
|
79
|
+
* @param poolInfo - Pool information
|
|
80
|
+
* @param outputMint - Output token mint
|
|
81
|
+
* @param amountOut - Desired output amount
|
|
82
|
+
* @param slippageTolerance - Slippage tolerance (0-1)
|
|
83
|
+
* @param tickArrays - Available tick arrays
|
|
84
|
+
* @returns Swap computation result
|
|
85
|
+
*/
|
|
86
|
+
static computeSwapExactOutput(poolInfo: ComputedPoolInfo, outputMint: Address, amountOut: BN, _slippageTolerance?: number, tickArrays?: TickArray[]): SwapResult;
|
|
87
|
+
/**
|
|
88
|
+
* Core swap computation
|
|
89
|
+
* @param poolInfo - Pool information
|
|
90
|
+
* @param amount - Swap amount
|
|
91
|
+
* @param sqrtPriceLimitX64 - Price limit
|
|
92
|
+
* @param zeroForOne - Swap direction
|
|
93
|
+
* @param exactInput - Whether exact input or output
|
|
94
|
+
* @param tickArrays - Available tick arrays
|
|
95
|
+
* @returns Swap result
|
|
96
|
+
*/
|
|
97
|
+
private static computeSwap;
|
|
98
|
+
/**
|
|
99
|
+
* Compute a single swap step
|
|
100
|
+
* @param sqrtPriceCurrentX64 - Current sqrt price
|
|
101
|
+
* @param sqrtPriceTargetX64 - Target sqrt price
|
|
102
|
+
* @param liquidity - Current liquidity
|
|
103
|
+
* @param amountRemaining - Remaining amount to swap
|
|
104
|
+
* @param feeBps - Fee in basis points
|
|
105
|
+
* @param exactInput - Whether exact input
|
|
106
|
+
* @param zeroForOne - Swap direction
|
|
107
|
+
* @returns Step result
|
|
108
|
+
*/
|
|
109
|
+
private static computeSwapStep;
|
|
110
|
+
/**
|
|
111
|
+
* Calculate amount0 delta between two sqrt prices
|
|
112
|
+
* @param sqrtRatioAX64 - First sqrt ratio
|
|
113
|
+
* @param sqrtRatioBX64 - Second sqrt ratio
|
|
114
|
+
* @param liquidity - Liquidity amount
|
|
115
|
+
* @param roundUp - Whether to round up
|
|
116
|
+
* @returns Amount0 delta
|
|
117
|
+
*/
|
|
118
|
+
private static getAmount0Delta;
|
|
119
|
+
/**
|
|
120
|
+
* Calculate amount1 delta between two sqrt prices
|
|
121
|
+
* @param sqrtRatioAX64 - First sqrt ratio
|
|
122
|
+
* @param sqrtRatioBX64 - Second sqrt ratio
|
|
123
|
+
* @param liquidity - Liquidity amount
|
|
124
|
+
* @param roundUp - Whether to round up
|
|
125
|
+
* @returns Amount1 delta
|
|
126
|
+
*/
|
|
127
|
+
private static getAmount1Delta;
|
|
128
|
+
/**
|
|
129
|
+
* Calculate optimal liquidity amounts for a position
|
|
130
|
+
* @param poolInfo - Pool information
|
|
131
|
+
* @param tickLower - Lower tick
|
|
132
|
+
* @param tickUpper - Upper tick
|
|
133
|
+
* @param amount0Desired - Desired amount of token 0
|
|
134
|
+
* @param amount1Desired - Desired amount of token 1
|
|
135
|
+
* @returns Liquidity calculation result
|
|
136
|
+
*/
|
|
137
|
+
static calculateLiquidity(poolInfo: ComputedPoolInfo, tickLower: number, tickUpper: number, amount0Desired: BN, amount1Desired: BN): LiquidityResult;
|
|
138
|
+
/**
|
|
139
|
+
* Calculate liquidity from token0 amount
|
|
140
|
+
* @param sqrtRatioAX64 - Lower sqrt ratio
|
|
141
|
+
* @param sqrtRatioBX64 - Upper sqrt ratio
|
|
142
|
+
* @param amount0 - Token0 amount
|
|
143
|
+
* @returns Liquidity
|
|
144
|
+
*/
|
|
145
|
+
private static getLiquidityFromAmount0;
|
|
146
|
+
/**
|
|
147
|
+
* Calculate liquidity from token1 amount
|
|
148
|
+
* @param sqrtRatioAX64 - Lower sqrt ratio
|
|
149
|
+
* @param sqrtRatioBX64 - Upper sqrt ratio
|
|
150
|
+
* @param amount1 - Token1 amount
|
|
151
|
+
* @returns Liquidity
|
|
152
|
+
*/
|
|
153
|
+
private static getLiquidityFromAmount1;
|
|
154
|
+
/**
|
|
155
|
+
* Calculate token0 amount from liquidity
|
|
156
|
+
* @param sqrtRatioAX64 - Lower sqrt ratio
|
|
157
|
+
* @param sqrtRatioBX64 - Upper sqrt ratio
|
|
158
|
+
* @param liquidity - Liquidity amount
|
|
159
|
+
* @returns Token0 amount
|
|
160
|
+
*/
|
|
161
|
+
static getAmount0FromLiquidity(sqrtRatioAX64: BN, sqrtRatioBX64: BN, liquidity: BN): BN;
|
|
162
|
+
/**
|
|
163
|
+
* Calculate token1 amount from liquidity
|
|
164
|
+
* @param sqrtRatioAX64 - Lower sqrt ratio
|
|
165
|
+
* @param sqrtRatioBX64 - Upper sqrt ratio
|
|
166
|
+
* @param liquidity - Liquidity amount
|
|
167
|
+
* @returns Token1 amount
|
|
168
|
+
*/
|
|
169
|
+
static getAmount1FromLiquidity(sqrtRatioAX64: BN, sqrtRatioBX64: BN, liquidity: BN): BN;
|
|
170
|
+
private static maxTickInTickArrayBitmap;
|
|
171
|
+
private static tickRange;
|
|
172
|
+
/**
|
|
173
|
+
* Calculate if tick indexes overflow default tick array bitmap.
|
|
174
|
+
* @param tickSpacing - tick spacing
|
|
175
|
+
* @param tickIndexs - upper and lower bound start tick indexes
|
|
176
|
+
* @returns true if it overflows, false otherwise
|
|
177
|
+
*/
|
|
178
|
+
static isOverflowDefaultTickArrayBitmap(tickSpacing: number, tickIndexs: Array<number>): boolean;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/utils/pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,QAAQ,CAAC;AAUhB,OAAO,EAAW,MAAM,OAAO,CAAC;AAGhC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,YAAY,EAAE,EAAE,CAAC;IACjB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,SAAS,EAAE,EAAE,CAAC;IACd,4BAA4B;IAC5B,aAAa,EAAE,EAAE,CAAC;IAClB,4BAA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ACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAmH9B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IA4B9B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAyB9B;;;;;;;;OAQG;IACH,MAAM,CAAC,kBAAkB,CACvB,QAAQ,EAAE,gBAAgB,EAC1B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,EAAE,EAClB,cAAc,EAAE,EAAE,GACjB,eAAe;IA6DlB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAoBtC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAetC;;;;;;OAMG;WACW,uBAAuB,CACnC,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,EAAE,EACjB,SAAS,EAAE,EAAE,GACZ,EAAE;IAWL;;;;;;OAMG;WACW,uBAAuB,CACnC,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,EAAE,EACjB,SAAS,EAAE,EAAE,GACZ,EAAE;IAWL,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAIvC,OAAO,CAAC,MAAM,CAAC,SAAS;IAyBxB;;;;;OAKG;WACW,gCAAgC,CAC5C,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,GACxB,OAAO;CAkBX"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ClusterUrl, type Address } from "@solana/kit";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
import { TickArrayBitmapExtension } from "../generated";
|
|
5
|
+
export declare const TICK_ARRAY_SIZE = 60;
|
|
6
|
+
export declare const TICK_ARRAY_BITMAP_SIZE = 512;
|
|
7
|
+
/**
|
|
8
|
+
* Individual tick state
|
|
9
|
+
*/
|
|
10
|
+
export interface Tick {
|
|
11
|
+
/** The tick index */
|
|
12
|
+
tick: number;
|
|
13
|
+
/** Amount of net liquidity added or removed when crossing this tick */
|
|
14
|
+
liquidityNet: bigint;
|
|
15
|
+
/** Total liquidity referencing this tick */
|
|
16
|
+
liquidityGross: bigint;
|
|
17
|
+
/** Fee growth on the other side of this tick from the current tick */
|
|
18
|
+
feeGrowthOutside0X64: bigint;
|
|
19
|
+
feeGrowthOutside1X64: bigint;
|
|
20
|
+
/** Reward growth on the other side of this tick from the current tick */
|
|
21
|
+
rewardGrowthsOutside: [bigint, bigint, bigint];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Tick array containing multiple ticks
|
|
25
|
+
*/
|
|
26
|
+
export interface TickArray {
|
|
27
|
+
/** Pool ID this tick array belongs to */
|
|
28
|
+
poolId: Address;
|
|
29
|
+
/** Starting tick index of this array */
|
|
30
|
+
startTickIndex: number;
|
|
31
|
+
/** Array of tick states */
|
|
32
|
+
ticks: Tick[];
|
|
33
|
+
/** Number of initialized ticks in this array */
|
|
34
|
+
initializedTickCount: number;
|
|
35
|
+
}
|
|
36
|
+
export interface ReturnTypeGetPriceAndTick {
|
|
37
|
+
tick: number;
|
|
38
|
+
price: Decimal;
|
|
39
|
+
}
|
|
40
|
+
export interface ReturnTypeGetTickPrice {
|
|
41
|
+
tick: number;
|
|
42
|
+
price: Decimal;
|
|
43
|
+
tickSqrtPriceX64: BN;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Tick utility functions
|
|
47
|
+
*/
|
|
48
|
+
export declare class TickUtils {
|
|
49
|
+
/**
|
|
50
|
+
* Validate that a tick is within valid range
|
|
51
|
+
* @param tick - Tick to validate
|
|
52
|
+
* @throws ClmmError if tick is out of range
|
|
53
|
+
*/
|
|
54
|
+
static validateTick(tick: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Validate that tick range is valid
|
|
57
|
+
* @param tickLower - Lower tick
|
|
58
|
+
* @param tickUpper - Upper tick
|
|
59
|
+
* @param tickSpacing - Tick spacing for the pool
|
|
60
|
+
* @throws ClmmError if range is invalid
|
|
61
|
+
*/
|
|
62
|
+
static validateTickRange(tickLower: number, tickUpper: number, tickSpacing: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get the start index of the tick array containing a specific tick
|
|
65
|
+
* @param tick - Target tick
|
|
66
|
+
* @param tickSpacing - Tick spacing of the pool
|
|
67
|
+
* @returns Start tick index for the tick array
|
|
68
|
+
*/
|
|
69
|
+
static getTickArrayStartIndex(tick: number, tickSpacing: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* Check if a tick is initialized (has liquidity)
|
|
72
|
+
* @param tick - Tick to check
|
|
73
|
+
* @returns Whether tick is initialized
|
|
74
|
+
*/
|
|
75
|
+
static isTickInitialized(tick: Tick): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Get all tick array start indices needed for a price range
|
|
78
|
+
* @param tickLower - Lower tick of range
|
|
79
|
+
* @param tickUpper - Upper tick of range
|
|
80
|
+
* @param tickSpacing - Tick spacing of the pool
|
|
81
|
+
* @param tickCurrent - Current pool tick
|
|
82
|
+
* @returns Array of start indices
|
|
83
|
+
*/
|
|
84
|
+
static getTickArrayStartIndices(tickLower: number, tickUpper: number, tickSpacing: number, tickCurrent: number): number[];
|
|
85
|
+
/**
|
|
86
|
+
* Find next initialized tick in a direction
|
|
87
|
+
* @param ticks - Array of tick states
|
|
88
|
+
* @param startTick - Starting tick index
|
|
89
|
+
* @param tickSpacing - Tick spacing
|
|
90
|
+
* @param zeroForOne - Direction (true = decreasing ticks)
|
|
91
|
+
* @returns Next initialized tick and whether found
|
|
92
|
+
*/
|
|
93
|
+
static findNextInitializedTick(ticks: Tick[], startTick: number, tickSpacing: number, zeroForOne: boolean): {
|
|
94
|
+
tick: number;
|
|
95
|
+
found: boolean;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Calculate tick index from price
|
|
99
|
+
* @param price - Price (token1/token0)
|
|
100
|
+
* @param decimalsA - Token A decimals
|
|
101
|
+
* @param decimalsB - Token B decimals
|
|
102
|
+
* @returns Tick index
|
|
103
|
+
*/
|
|
104
|
+
static priceToTick(price: number, decimalsA: number, decimalsB: number): number;
|
|
105
|
+
/**
|
|
106
|
+
* Calculate price from tick index
|
|
107
|
+
* @param tick - Tick index
|
|
108
|
+
* @param decimalsA - Token A decimals
|
|
109
|
+
* @param decimalsB - Token B decimals
|
|
110
|
+
* @returns Price (token1/token0)
|
|
111
|
+
*/
|
|
112
|
+
static tickToPrice(tick: number, decimalsA: number, decimalsB: number): number;
|
|
113
|
+
/**
|
|
114
|
+
* Get the tick index at a given price with proper spacing alignment
|
|
115
|
+
* @param price - Target price
|
|
116
|
+
* @param decimalsA - Token A decimals
|
|
117
|
+
* @param decimalsB - Token B decimals
|
|
118
|
+
* @param tickSpacing - Tick spacing
|
|
119
|
+
* @param roundUp - Whether to round up or down
|
|
120
|
+
* @returns Aligned tick index
|
|
121
|
+
*/
|
|
122
|
+
static priceToAlignedTick(price: number, decimalsA: number, decimalsB: number, tickSpacing: number, roundUp?: boolean): number;
|
|
123
|
+
/**
|
|
124
|
+
* Align tick to spacing requirements
|
|
125
|
+
* @param tick - Raw tick
|
|
126
|
+
* @param tickSpacing - Required spacing
|
|
127
|
+
* @param roundUp - Whether to round up or down
|
|
128
|
+
* @returns Aligned tick
|
|
129
|
+
*/
|
|
130
|
+
static alignTickToSpacing(tick: number, tickSpacing: number, roundUp?: boolean): number;
|
|
131
|
+
static checkIsOutOfBoundary(tick: number): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Check if tick array boundary is valid
|
|
134
|
+
* @param startIndex - Start index of tick array
|
|
135
|
+
* @param tickSpacing - Tick spacing
|
|
136
|
+
* @returns Whether boundary is valid
|
|
137
|
+
*/
|
|
138
|
+
static isValidTickArrayBoundary(startIndex: number, tickSpacing: number): boolean;
|
|
139
|
+
static getTickArrayStartIndexByTick(tickIndex: number, tickSpacing: number): number;
|
|
140
|
+
static mergeTickArrayBitmap(bns: BN[]): BN;
|
|
141
|
+
static searchLowBitFromStart(tickArrayBitmap: BN[], exTickArrayBitmap: TickArrayBitmapExtension, currentTickArrayBitStartIndex: number, expectedCount: number, tickSpacing: number): number[];
|
|
142
|
+
static searchHightBitFromStart(tickArrayBitmap: BN[], exTickArrayBitmap: TickArrayBitmapExtension, currentTickArrayBitStartIndex: number, expectedCount: number, tickSpacing: number): number[];
|
|
143
|
+
static getInitializedTickArrayInRange(tickArrayBitmap: BN[], exTickArrayBitmap: TickArrayBitmapExtension, tickSpacing: number, tickArrayStartIndex: number, expectedCount: number): number[];
|
|
144
|
+
static getTickArrayBitIndex(tickIndex: number, tickSpacing: number): number;
|
|
145
|
+
static getTickPrice({ mintADecimals, mintBDecimals, tick, baseIn, }: {
|
|
146
|
+
mintADecimals: number;
|
|
147
|
+
mintBDecimals: number;
|
|
148
|
+
tick: number;
|
|
149
|
+
baseIn: boolean;
|
|
150
|
+
}): ReturnTypeGetTickPrice;
|
|
151
|
+
static getPriceAndTick({ tickSpacing, mintADecimals, mintBDecimals, price, baseIn, }: {
|
|
152
|
+
tickSpacing: number;
|
|
153
|
+
mintADecimals: number;
|
|
154
|
+
mintBDecimals: number;
|
|
155
|
+
price: Decimal;
|
|
156
|
+
baseIn: boolean;
|
|
157
|
+
}): ReturnTypeGetPriceAndTick;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* NOTE: Not Implemented
|
|
161
|
+
*
|
|
162
|
+
* Fetch tick arrays for a pool within a price range
|
|
163
|
+
* @param cluster - RPC cluster | endpoint
|
|
164
|
+
* @param poolAddress - Pool address
|
|
165
|
+
* @param tickLower - Lower tick of range
|
|
166
|
+
* @param tickUpper - Upper tick of range
|
|
167
|
+
* @param tickSpacing - Tick spacing
|
|
168
|
+
* @param tickCurrent - Current tick
|
|
169
|
+
* @returns Promise of tick arrays
|
|
170
|
+
*/
|
|
171
|
+
export declare function fetchTickArraysForRange(cluster: ClusterUrl, poolAddress: Address, tickLower: number, tickUpper: number, tickSpacing: number, tickCurrent: number): Promise<TickArray[]>;
|
|
172
|
+
//# sourceMappingURL=tick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tick.d.ts","sourceRoot":"","sources":["../../src/utils/tick.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAIvD,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,cAAc,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,yEAAyE;IACzE,oBAAoB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,yCAAyC;IACzC,MAAM,EAAE,OAAO,CAAC;IAChB,wCAAwC;IACxC,cAAc,EAAE,MAAM,CAAC;IACvB,2BAA2B;IAC3B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,gDAAgD;IAChD,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,gBAAgB,EAAE,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB;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L,MAAM,GACP,EAAE;QACD,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,KAAK,EAAE,OAAO,CAAC;QACf,MAAM,EAAE,OAAO,CAAC;KACjB,GAAG,yBAAyB;CAoB9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,EAAE,CAAC,CAEtB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import { TickArrayBitmapExtension, TickArrayState } from "../generated";
|
|
3
|
+
import { Account, Address, Rpc, SolanaRpcApiDevnet, SolanaRpcApiMainnet, SolanaRpcApiTestnet } from "@solana/kit";
|
|
4
|
+
export declare const FETCH_TICKARRAY_COUNT = 15;
|
|
5
|
+
export declare class TickQuery {
|
|
6
|
+
static getTickArrays(rpc: Rpc<SolanaRpcApiMainnet | SolanaRpcApiDevnet | SolanaRpcApiTestnet>, poolId: Address, tickCurrent: number, tickSpacing: number, tickArrayBitmapArray: BN[], exTickArrayBitmap: TickArrayBitmapExtension): Promise<{
|
|
7
|
+
[key: string]: Account<TickArrayState>;
|
|
8
|
+
}>;
|
|
9
|
+
static getArrayStartIndex(tickIndex: number, tickSpacing: number): number;
|
|
10
|
+
static checkIsValidStartIndex(tickIndex: number, tickSpacing: number): boolean;
|
|
11
|
+
static tickCount(tickSpacing: number): number;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=tickQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tickQuery.d.ts","sourceRoot":"","sources":["../../src/utils/tickQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,OAAO,CAAC;AAGvB,OAAO,EAEL,wBAAwB,EACxB,cAAc,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,OAAO,EACP,OAAO,EACP,GAAG,EACH,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,qBAAa,SAAS;WACA,aAAa,CAC/B,GAAG,EAAE,GAAG,CAAC,mBAAmB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC,EACxE,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,oBAAoB,EAAE,EAAE,EAAE,EAC1B,iBAAiB,EAAE,wBAAwB,GAC1C,OAAO,CAAC;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;KAAE,CAAC;WAuPxC,kBAAkB,CAC9B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM;WAOK,sBAAsB,CAClC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAClB,OAAO;WAeI,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;CAGrD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stabbleorg/mclmm-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "SDK for Stabble's margin-enabled concentrated liquidity market maker",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"build": "yarn build:js && yarn build:types",
|
|
31
31
|
"generate-clients": "ts-node ./scripts/generate-clients.ts",
|
|
32
32
|
"ts": "tsc --noEmit",
|
|
33
|
-
"prepare:canary": "yarn build && npm version --prerelease --preid=canary"
|
|
33
|
+
"prepare:canary": "yarn build && npm version --prerelease --preid=canary",
|
|
34
|
+
"prepublishOnly": "echo \"Building before publish!\" && yarn build"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@codama/nodes-from-anchor": "^1.2.9",
|