@pancakeswap/v3-sdk 3.9.1 → 3.9.3
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/dist/index.js +13 -2
- package/dist/index.mjs +11 -4
- package/dist/utils/maxLiquidityForAmounts.d.ts +29 -0
- package/dist/utils/maxLiquidityForAmounts.d.ts.map +1 -1
- package/dist/utils/nearestUsableTick.d.ts.map +1 -1
- package/dist/utils/priceTickConversions.d.ts +11 -3
- package/dist/utils/priceTickConversions.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -858,10 +858,15 @@ function encodeSqrtRatioX96(amount1, amount0) {
|
|
|
858
858
|
function tickToPrice(baseToken, quoteToken, tick) {
|
|
859
859
|
const sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);
|
|
860
860
|
const ratioX192 = sqrtRatioX96 * sqrtRatioX96;
|
|
861
|
-
return
|
|
861
|
+
return swapSdkCore.isCurrencySorted(baseToken, quoteToken) ? new swapSdkCore.Price(baseToken, quoteToken, Q192, ratioX192) : new swapSdkCore.Price(baseToken, quoteToken, ratioX192, Q192);
|
|
862
|
+
}
|
|
863
|
+
function tickToPriceV2(baseToken, quoteToken, tick) {
|
|
864
|
+
const sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);
|
|
865
|
+
const ratioX192 = sqrtRatioX96 * sqrtRatioX96;
|
|
866
|
+
return swapSdkCore.sortCurrencies([baseToken, quoteToken])[0] === baseToken ? new swapSdkCore.Price(baseToken, quoteToken, Q192, ratioX192) : new swapSdkCore.Price(baseToken, quoteToken, ratioX192, Q192);
|
|
862
867
|
}
|
|
863
868
|
function priceToClosestTick(price) {
|
|
864
|
-
const sorted = price.baseCurrency
|
|
869
|
+
const sorted = swapSdkCore.isCurrencySorted(price.baseCurrency, price.quoteCurrency);
|
|
865
870
|
const sqrtRatioX96 = sorted ? encodeSqrtRatioX96(price.numerator, price.denominator) : encodeSqrtRatioX96(price.denominator, price.numerator);
|
|
866
871
|
let tick = TickMath.getTickAtSqrtRatio(sqrtRatioX96);
|
|
867
872
|
const nextTickPrice = tickToPrice(price.baseCurrency, price.quoteCurrency, tick + 1);
|
|
@@ -1777,6 +1782,8 @@ function nearestUsableTick(tick, tickSpacing) {
|
|
|
1777
1782
|
invariant9__default.default(Number.isInteger(tick) && Number.isInteger(tickSpacing), "INTEGERS");
|
|
1778
1783
|
invariant9__default.default(tickSpacing > 0, "TICK_SPACING");
|
|
1779
1784
|
invariant9__default.default(tick >= TickMath.MIN_TICK && tick <= TickMath.MAX_TICK, "TICK_BOUND");
|
|
1785
|
+
if (tickSpacing === 1)
|
|
1786
|
+
return tick;
|
|
1780
1787
|
const rounded = Math.round(tick / tickSpacing) * tickSpacing;
|
|
1781
1788
|
if (rounded < TickMath.MIN_TICK)
|
|
1782
1789
|
return rounded + tickSpacing;
|
|
@@ -6858,6 +6865,9 @@ exports.isMint = isMint;
|
|
|
6858
6865
|
exports.isPoolTickInRange = isPoolTickInRange;
|
|
6859
6866
|
exports.isSorted = isSorted;
|
|
6860
6867
|
exports.masterChefV3ABI = masterChefV3ABI;
|
|
6868
|
+
exports.maxLiquidityForAmount0Imprecise = maxLiquidityForAmount0Imprecise;
|
|
6869
|
+
exports.maxLiquidityForAmount0Precise = maxLiquidityForAmount0Precise;
|
|
6870
|
+
exports.maxLiquidityForAmount1 = maxLiquidityForAmount1;
|
|
6861
6871
|
exports.maxLiquidityForAmounts = maxLiquidityForAmounts;
|
|
6862
6872
|
exports.mostSignificantBit = mostSignificantBit;
|
|
6863
6873
|
exports.nearestUsableTick = nearestUsableTick;
|
|
@@ -6874,6 +6884,7 @@ exports.subIn256 = subIn256;
|
|
|
6874
6884
|
exports.swap = swap;
|
|
6875
6885
|
exports.swapRouterABI = swapRouterABI;
|
|
6876
6886
|
exports.tickToPrice = tickToPrice;
|
|
6887
|
+
exports.tickToPriceV2 = tickToPriceV2;
|
|
6877
6888
|
exports.toHex = toHex;
|
|
6878
6889
|
exports.tradeComparator = tradeComparator;
|
|
6879
6890
|
exports.v3PoolAbi = v3PoolAbi;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Price, CurrencyAmount, Percent as Percent$1, MaxUint256 as MaxUint256$1, TradeType, Fraction, sortedInsert, validateAndParseAddress, ZERO as ZERO$2, ONE as ONE$1 } from '@pancakeswap/sdk';
|
|
2
2
|
import invariant9 from 'tiny-invariant';
|
|
3
3
|
import { ChainId } from '@pancakeswap/chains';
|
|
4
|
-
import { Percent, MaxUint256, sqrt, Price as Price$1, sortCurrencies, CurrencyAmount as CurrencyAmount$1, Fraction as Fraction$1, ZERO as ZERO$1, TradeType as TradeType$1 } from '@pancakeswap/swap-sdk-core';
|
|
4
|
+
import { Percent, MaxUint256, sqrt, isCurrencySorted, Price as Price$1, sortCurrencies, CurrencyAmount as CurrencyAmount$1, Fraction as Fraction$1, ZERO as ZERO$1, TradeType as TradeType$1 } from '@pancakeswap/swap-sdk-core';
|
|
5
5
|
import { keccak256, encodeAbiParameters, parseAbiParameters, encodePacked, encodeFunctionData, toBytes, getAddress, pad, isBytes, slice, concat } from 'viem';
|
|
6
6
|
|
|
7
7
|
// src/entities/pool.ts
|
|
@@ -852,10 +852,15 @@ function encodeSqrtRatioX96(amount1, amount0) {
|
|
|
852
852
|
function tickToPrice(baseToken, quoteToken, tick) {
|
|
853
853
|
const sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);
|
|
854
854
|
const ratioX192 = sqrtRatioX96 * sqrtRatioX96;
|
|
855
|
-
return baseToken
|
|
855
|
+
return isCurrencySorted(baseToken, quoteToken) ? new Price$1(baseToken, quoteToken, Q192, ratioX192) : new Price$1(baseToken, quoteToken, ratioX192, Q192);
|
|
856
|
+
}
|
|
857
|
+
function tickToPriceV2(baseToken, quoteToken, tick) {
|
|
858
|
+
const sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);
|
|
859
|
+
const ratioX192 = sqrtRatioX96 * sqrtRatioX96;
|
|
860
|
+
return sortCurrencies([baseToken, quoteToken])[0] === baseToken ? new Price$1(baseToken, quoteToken, Q192, ratioX192) : new Price$1(baseToken, quoteToken, ratioX192, Q192);
|
|
856
861
|
}
|
|
857
862
|
function priceToClosestTick(price) {
|
|
858
|
-
const sorted = price.baseCurrency
|
|
863
|
+
const sorted = isCurrencySorted(price.baseCurrency, price.quoteCurrency);
|
|
859
864
|
const sqrtRatioX96 = sorted ? encodeSqrtRatioX96(price.numerator, price.denominator) : encodeSqrtRatioX96(price.denominator, price.numerator);
|
|
860
865
|
let tick = TickMath.getTickAtSqrtRatio(sqrtRatioX96);
|
|
861
866
|
const nextTickPrice = tickToPrice(price.baseCurrency, price.quoteCurrency, tick + 1);
|
|
@@ -1771,6 +1776,8 @@ function nearestUsableTick(tick, tickSpacing) {
|
|
|
1771
1776
|
invariant9(Number.isInteger(tick) && Number.isInteger(tickSpacing), "INTEGERS");
|
|
1772
1777
|
invariant9(tickSpacing > 0, "TICK_SPACING");
|
|
1773
1778
|
invariant9(tick >= TickMath.MIN_TICK && tick <= TickMath.MAX_TICK, "TICK_BOUND");
|
|
1779
|
+
if (tickSpacing === 1)
|
|
1780
|
+
return tick;
|
|
1774
1781
|
const rounded = Math.round(tick / tickSpacing) * tickSpacing;
|
|
1775
1782
|
if (rounded < TickMath.MIN_TICK)
|
|
1776
1783
|
return rounded + tickSpacing;
|
|
@@ -6791,4 +6798,4 @@ var v3PoolAbi = [
|
|
|
6791
6798
|
}
|
|
6792
6799
|
];
|
|
6793
6800
|
|
|
6794
|
-
export { ADDRESS_ZERO, DEPLOYER_ADDRESSES, FACTORY_ADDRESSES, FeeAmount, FeeCalculator, FullMath, LiquidityMath, MasterChefV3, MaxUint128, Multicall, NFT_POSITION_MANAGER_ADDRESSES, NoTickDataProvider, NonfungiblePositionManager, POOL_INIT_CODE_HASHES, Payments, Pool, Position, PositionLibrary, PositionMath, Route, SelfPermit, SqrtPriceMath, Staker, SwapMath, SwapQuoter, SwapRouter, TICK_SPACINGS, Tick, TickLibrary, TickList, TickListDataProvider, TickMath, Trade, computePoolAddress, encodeRouteToPath, encodeSqrtRatioX96, getAmountsAtNewPrice, getAmountsByLiquidityAndPrice, getAverageLiquidity, getCurrency0Price, getCurrency1Price, getDependentAmount, getEstimatedLPFee, getEstimatedLPFeeByAmounts, getEstimatedLPFeeByAmountsWithProtocolFee, getEstimatedLPFeeWithProtocolFee, getInputAmount, getLiquidityByAmountsAndPrice, getLiquidityBySingleAmount, getLiquidityFromSqrtRatioX96, getLiquidityFromTick, getOutputAmount, getPool, getPriceOfCurrency, getPriceOfCurrency0, getPriceOfCurrency1, hasInvolvedCurrency, isMint, isPoolTickInRange, isSorted, masterChefV3ABI, maxLiquidityForAmounts, mostSignificantBit, nearestUsableTick, nonfungiblePositionManagerABI, pancakeV3PoolABI, parseProtocolFees, peripheryPaymentsWithFeeABI, priceToClosestTick, quoterABI, quoterV2ABI, selfPermitABI, sqrtRatioX96ToPrice, subIn256, swap, swapRouterABI, tickToPrice, toHex, tradeComparator, v3PoolAbi, v3StakerABI };
|
|
6801
|
+
export { ADDRESS_ZERO, DEPLOYER_ADDRESSES, FACTORY_ADDRESSES, FeeAmount, FeeCalculator, FullMath, LiquidityMath, MasterChefV3, MaxUint128, Multicall, NFT_POSITION_MANAGER_ADDRESSES, NoTickDataProvider, NonfungiblePositionManager, POOL_INIT_CODE_HASHES, Payments, Pool, Position, PositionLibrary, PositionMath, Route, SelfPermit, SqrtPriceMath, Staker, SwapMath, SwapQuoter, SwapRouter, TICK_SPACINGS, Tick, TickLibrary, TickList, TickListDataProvider, TickMath, Trade, computePoolAddress, encodeRouteToPath, encodeSqrtRatioX96, getAmountsAtNewPrice, getAmountsByLiquidityAndPrice, getAverageLiquidity, getCurrency0Price, getCurrency1Price, getDependentAmount, getEstimatedLPFee, getEstimatedLPFeeByAmounts, getEstimatedLPFeeByAmountsWithProtocolFee, getEstimatedLPFeeWithProtocolFee, getInputAmount, getLiquidityByAmountsAndPrice, getLiquidityBySingleAmount, getLiquidityFromSqrtRatioX96, getLiquidityFromTick, getOutputAmount, getPool, getPriceOfCurrency, getPriceOfCurrency0, getPriceOfCurrency1, hasInvolvedCurrency, isMint, isPoolTickInRange, isSorted, masterChefV3ABI, maxLiquidityForAmount0Imprecise, maxLiquidityForAmount0Precise, maxLiquidityForAmount1, maxLiquidityForAmounts, mostSignificantBit, nearestUsableTick, nonfungiblePositionManagerABI, pancakeV3PoolABI, parseProtocolFees, peripheryPaymentsWithFeeABI, priceToClosestTick, quoterABI, quoterV2ABI, selfPermitABI, sqrtRatioX96ToPrice, subIn256, swap, swapRouterABI, tickToPrice, tickToPriceV2, toHex, tradeComparator, v3PoolAbi, v3StakerABI };
|
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
import { BigintIsh } from '@pancakeswap/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an imprecise maximum amount of liquidity received for a given amount of token 0.
|
|
4
|
+
* This function is available to accommodate LiquidityAmounts#getLiquidityForAmount0 in the v3 periphery,
|
|
5
|
+
* which could be more precise by at least 32 bits by dividing by Q64 instead of Q96 in the intermediate step,
|
|
6
|
+
* and shifting the subtracted ratio left by 32 bits. This imprecise calculation will likely be replaced in a future
|
|
7
|
+
* v3 router contract.
|
|
8
|
+
* @param sqrtRatioAX96 The price at the lower boundary
|
|
9
|
+
* @param sqrtRatioBX96 The price at the upper boundary
|
|
10
|
+
* @param amount0 The token0 amount
|
|
11
|
+
* @returns liquidity for amount0, imprecise
|
|
12
|
+
*/
|
|
13
|
+
export declare function maxLiquidityForAmount0Imprecise(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount0: BigintIsh): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a precise maximum amount of liquidity received for a given amount of token 0 by dividing by Q64 instead of Q96 in the intermediate step,
|
|
16
|
+
* and shifting the subtracted ratio left by 32 bits.
|
|
17
|
+
* @param sqrtRatioAX96 The price at the lower boundary
|
|
18
|
+
* @param sqrtRatioBX96 The price at the upper boundary
|
|
19
|
+
* @param amount0 The token0 amount
|
|
20
|
+
* @returns liquidity for amount0, precise
|
|
21
|
+
*/
|
|
22
|
+
export declare function maxLiquidityForAmount0Precise(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount0: BigintIsh): bigint;
|
|
23
|
+
/**
|
|
24
|
+
* Computes the maximum amount of liquidity received for a given amount of token1
|
|
25
|
+
* @param sqrtRatioAX96 The price at the lower tick boundary
|
|
26
|
+
* @param sqrtRatioBX96 The price at the upper tick boundary
|
|
27
|
+
* @param amount1 The token1 amount
|
|
28
|
+
* @returns liquidity for amount1
|
|
29
|
+
*/
|
|
30
|
+
export declare function maxLiquidityForAmount1(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount1: BigintIsh): bigint;
|
|
2
31
|
/**
|
|
3
32
|
* Computes the maximum amount of liquidity received for a given amount of token0, token1,
|
|
4
33
|
* and the prices at the tick boundaries.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maxLiquidityForAmounts.d.ts","sourceRoot":"","sources":["../../src/utils/maxLiquidityForAmounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"maxLiquidityForAmounts.d.ts","sourceRoot":"","sources":["../../src/utils/maxLiquidityForAmounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAG5C;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,SAAS,GACjB,MAAM,CAMR;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,SAAS,GACjB,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,MAAM,CAK/G;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,mBAAmB,EAAE,MAAM,EAC3B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,SAAS,EAClB,gBAAgB,EAAE,OAAO,GACxB,MAAM,CAgBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nearestUsableTick.d.ts","sourceRoot":"","sources":["../../src/utils/nearestUsableTick.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"nearestUsableTick.d.ts","sourceRoot":"","sources":["../../src/utils/nearestUsableTick.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UASlE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Price, Token } from '@pancakeswap/swap-sdk-core';
|
|
1
|
+
import { Currency, Price, Token } from '@pancakeswap/swap-sdk-core';
|
|
2
2
|
/**
|
|
3
3
|
* Returns a price object corresponding to the input tick and the base/quote token
|
|
4
4
|
* Inputs must be tokens because the address order is used to interpret the price represented by the tick
|
|
@@ -6,11 +6,19 @@ import { Price, Token } from '@pancakeswap/swap-sdk-core';
|
|
|
6
6
|
* @param quoteToken the quote token of the price
|
|
7
7
|
* @param tick the tick for which to return the price
|
|
8
8
|
*/
|
|
9
|
-
export declare function tickToPrice(baseToken:
|
|
9
|
+
export declare function tickToPrice<TBase extends Currency | Token, TQuote extends Currency | Token>(baseToken: TBase, quoteToken: TQuote, tick: number): Price<TBase, TQuote>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a price object corresponding to the input tick and the base/quote token
|
|
12
|
+
* Inputs must be tokens because the address order is used to interpret the price represented by the tick
|
|
13
|
+
* @param baseToken the base token of the price
|
|
14
|
+
* @param quoteToken the quote token of the price
|
|
15
|
+
* @param tick the tick for which to return the price
|
|
16
|
+
*/
|
|
17
|
+
export declare function tickToPriceV2(baseToken: Currency, quoteToken: Currency, tick: number): Price<Currency, Currency>;
|
|
10
18
|
/**
|
|
11
19
|
* Returns the first tick for which the given price is greater than or equal to the tick price
|
|
12
20
|
* @param price for which to return the closest tick that represents a price less than or equal to the input price,
|
|
13
21
|
* i.e. the price of the returned tick is less than or equal to the input price
|
|
14
22
|
*/
|
|
15
|
-
export declare function priceToClosestTick(price: Price<
|
|
23
|
+
export declare function priceToClosestTick(price: Price<Currency, Currency>): number;
|
|
16
24
|
//# sourceMappingURL=priceTickConversions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"priceTickConversions.d.ts","sourceRoot":"","sources":["../../src/utils/priceTickConversions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"priceTickConversions.d.ts","sourceRoot":"","sources":["../../src/utils/priceTickConversions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,KAAK,EAAkB,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAIrG;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,SAAS,QAAQ,GAAG,KAAK,EAAE,MAAM,SAAS,QAAQ,GAAG,KAAK,EACzF,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACX,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAQtB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAQhH;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,MAAM,CAiB3E"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "3.9.
|
|
7
|
+
"version": "3.9.3",
|
|
8
8
|
"description": "⚒️ An SDK for building applications on top of Pancakeswap V3",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"tiny-warning": "^1.0.3",
|
|
25
25
|
"toformat": "^2.0.0",
|
|
26
26
|
"viem": "^2.22.23",
|
|
27
|
-
"@pancakeswap/chains": "0.5.
|
|
28
|
-
"@pancakeswap/sdk": "5.8.
|
|
29
|
-
"@pancakeswap/swap-sdk-core": "1.
|
|
27
|
+
"@pancakeswap/chains": "0.5.2",
|
|
28
|
+
"@pancakeswap/sdk": "5.8.14",
|
|
29
|
+
"@pancakeswap/swap-sdk-core": "1.4.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"tsup": "^6.7.0",
|
|
33
|
-
"@pancakeswap/utils": "6.
|
|
33
|
+
"@pancakeswap/utils": "6.1.1"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=10"
|