@pancakeswap/v3-sdk 3.8.7 → 3.8.9
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/functions/getCurrencyPrice.d.ts +11 -0
- package/dist/functions/getCurrencyPrice.d.ts.map +1 -0
- package/dist/functions/getPool.d.ts +23 -0
- package/dist/functions/getPool.d.ts.map +1 -0
- package/dist/functions/getPriceOfCurrency.d.ts +6 -0
- package/dist/functions/getPriceOfCurrency.d.ts.map +1 -0
- package/dist/functions/hasInvolvedCurrency.d.ts +4 -0
- package/dist/functions/hasInvolvedCurrency.d.ts.map +1 -0
- package/dist/functions/index.d.ts +6 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/swap.d.ts +31 -0
- package/dist/functions/swap.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +195 -4
- package/dist/index.mjs +187 -6
- package/dist/utils/sqrtPriceMath.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BigintIsh, Price } from '@pancakeswap/sdk';
|
|
2
|
+
import { Currency } from '@pancakeswap/swap-sdk-core';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current price of the given tokens
|
|
5
|
+
*/
|
|
6
|
+
export declare const getCurrency0Price: ([currency0, currency1]: [Currency, Currency], currentSqrtRatioX96: BigintIsh) => Price<Currency, Currency>;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the current price of the given tokens
|
|
9
|
+
*/
|
|
10
|
+
export declare const getCurrency1Price: ([currency0, currency1]: [Currency, Currency], currentSqrtRatioX96: BigintIsh) => Price<Currency, Currency>;
|
|
11
|
+
//# sourceMappingURL=getCurrencyPrice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCurrencyPrice.d.ts","sourceRoot":"","sources":["../../src/functions/getCurrencyPrice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAGrD;;GAEG;AACH,eAAO,MAAM,iBAAiB,2BACJ,CAAC,QAAQ,EAAE,QAAQ,CAAC,uBACvB,SAAS,KAC7B,MAAM,QAAQ,EAAE,QAAQ,CAI1B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,2BACJ,CAAC,QAAQ,EAAE,QAAQ,CAAC,uBACvB,SAAS,KAC7B,MAAM,QAAQ,EAAE,QAAQ,CAI1B,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BigintIsh, Currency } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { Tick, TickConstructorArgs, TickDataProvider } from '../entities';
|
|
3
|
+
export type PoolState = {
|
|
4
|
+
currency0: Currency;
|
|
5
|
+
currency1: Currency;
|
|
6
|
+
fee: number;
|
|
7
|
+
tickCurrent: number;
|
|
8
|
+
tickSpacing: number;
|
|
9
|
+
sqrtRatioX96: bigint;
|
|
10
|
+
liquidity: bigint;
|
|
11
|
+
tickDataProvider: TickDataProvider;
|
|
12
|
+
};
|
|
13
|
+
export declare const getPool: ({ currencyA, currencyB, fee, sqrtRatioX96, liquidity, tickCurrent, tickSpacing, ticks, }: {
|
|
14
|
+
currencyA: Currency;
|
|
15
|
+
currencyB: Currency;
|
|
16
|
+
fee: number;
|
|
17
|
+
sqrtRatioX96: BigintIsh;
|
|
18
|
+
liquidity: BigintIsh;
|
|
19
|
+
tickCurrent: number;
|
|
20
|
+
tickSpacing: number;
|
|
21
|
+
ticks?: TickDataProvider | (TickConstructorArgs | Tick)[] | undefined;
|
|
22
|
+
}) => PoolState;
|
|
23
|
+
//# sourceMappingURL=getPool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPool.d.ts","sourceRoot":"","sources":["../../src/functions/getPool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,4BAA4B,CAAA;AAEhF,OAAO,EAAsB,IAAI,EAAE,mBAAmB,EAAE,gBAAgB,EAAwB,MAAM,aAAa,CAAA;AAEnH,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,QAAQ,CAAA;IACnB,SAAS,EAAE,QAAQ,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,gBAAgB,CAAA;CACnC,CAAA;AAQD,eAAO,MAAM,OAAO;eAUP,QAAQ;eACR,QAAQ;SACd,MAAM;kBACG,SAAS;eACZ,SAAS;iBACP,MAAM;iBACN,MAAM;;MAEjB,SAeH,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Currency } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { PoolState } from './getPool';
|
|
3
|
+
export declare const getPriceOfCurrency: (pool: Pick<PoolState, 'currency0' | 'currency1' | 'sqrtRatioX96'>, currency: Currency) => import("@pancakeswap/swap-sdk-core").Price<Currency, Currency>;
|
|
4
|
+
export declare const getPriceOfCurrency0: (pool: Pick<PoolState, 'currency0' | 'currency1' | 'sqrtRatioX96'>) => import("@pancakeswap/swap-sdk-core").Price<Currency, Currency>;
|
|
5
|
+
export declare const getPriceOfCurrency1: (pool: Pick<PoolState, 'currency0' | 'currency1' | 'sqrtRatioX96'>) => import("@pancakeswap/swap-sdk-core").Price<Currency, Currency>;
|
|
6
|
+
//# sourceMappingURL=getPriceOfCurrency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPriceOfCurrency.d.ts","sourceRoot":"","sources":["../../src/functions/getPriceOfCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAGrD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,eAAO,MAAM,kBAAkB,SACvB,KAAK,SAAS,EAAE,WAAW,GAAG,WAAW,GAAG,cAAc,CAAC,YACvD,QAAQ,mEAWnB,CAAA;AAED,eAAO,MAAM,mBAAmB,SAAU,KAAK,SAAS,EAAE,WAAW,GAAG,WAAW,GAAG,cAAc,CAAC,mEAC7B,CAAA;AAExE,eAAO,MAAM,mBAAmB,SAAU,KAAK,SAAS,EAAE,WAAW,GAAG,WAAW,GAAG,cAAc,CAAC,mEAC7B,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Currency } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { PoolState } from './getPool';
|
|
3
|
+
export declare const hasInvolvedCurrency: (pool: Pick<PoolState, 'currency0' | 'currency1'>, currency: Currency) => boolean;
|
|
4
|
+
//# sourceMappingURL=hasInvolvedCurrency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasInvolvedCurrency.d.ts","sourceRoot":"","sources":["../../src/functions/hasInvolvedCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,eAAO,MAAM,mBAAmB,SAAU,KAAK,SAAS,EAAE,WAAW,GAAG,WAAW,CAAC,YAAY,QAAQ,YAGvG,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Currency, CurrencyAmount } from '@pancakeswap/sdk';
|
|
2
|
+
import { PoolState } from './getPool';
|
|
3
|
+
export declare const swap: ({ pool, zeroForOne, amountSpecified, sqrtPriceLimitX96, }: {
|
|
4
|
+
pool: PoolState;
|
|
5
|
+
zeroForOne: boolean;
|
|
6
|
+
amountSpecified: bigint;
|
|
7
|
+
sqrtPriceLimitX96?: bigint | undefined;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
amountCalculated: bigint;
|
|
10
|
+
sqrtRatioX96: bigint;
|
|
11
|
+
liquidity: bigint;
|
|
12
|
+
tickCurrent: number;
|
|
13
|
+
amountSpecifiedRemaining: bigint;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Given a desired input amount of a token, return the computed output
|
|
17
|
+
* amount and a pool with state updated after the trade
|
|
18
|
+
*/
|
|
19
|
+
export declare const getOutputAmount: <TCurrencyOut extends Currency = Currency, TCurrencyIn extends Currency = Currency>(pool: PoolState, inputAmount: CurrencyAmount<TCurrencyIn>, options?: {
|
|
20
|
+
sqrtPriceLimitX96?: bigint;
|
|
21
|
+
exact?: boolean;
|
|
22
|
+
}) => Promise<[CurrencyAmount<TCurrencyOut>, PoolState]>;
|
|
23
|
+
/**
|
|
24
|
+
* Given a desired output amount of a token, return the computed input
|
|
25
|
+
* amount and a pool with state updated after the trade
|
|
26
|
+
*/
|
|
27
|
+
export declare const getInputAmount: <TCurrencyIn extends Currency = Currency, TCurrencyOut extends Currency = Currency>(pool: PoolState, outputAmount: CurrencyAmount<TCurrencyOut>, options?: {
|
|
28
|
+
sqrtPriceLimitX96?: bigint;
|
|
29
|
+
exact?: boolean;
|
|
30
|
+
}) => Promise<[CurrencyAmount<TCurrencyIn>, PoolState]>;
|
|
31
|
+
//# sourceMappingURL=swap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../src/functions/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAI3D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAarC,eAAO,MAAM,IAAI;UAMT,SAAS;gBACH,OAAO;qBACF,MAAM;;MAErB,QAAQ;IACV,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,wBAAwB,EAAE,MAAM,CAAA;CACjC,CA0FA,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,4FAIpB,SAAS,sDAEL;IACR,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,uDAkCF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,4FACnB,SAAS,wDAEL;IACR,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,sDAmCF,CAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AAEvB,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAG5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kCAAkC,CAAA;AAChD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AAEvB,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAG5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kCAAkC,CAAA;AAChD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -212,8 +212,7 @@ var SqrtPriceMath = class {
|
|
|
212
212
|
}
|
|
213
213
|
static getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
|
|
214
214
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
215
|
-
sqrtRatioAX96 = sqrtRatioBX96;
|
|
216
|
-
sqrtRatioBX96 = sqrtRatioAX96;
|
|
215
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
217
216
|
}
|
|
218
217
|
const numerator1 = liquidity << 96n;
|
|
219
218
|
const numerator2 = sqrtRatioBX96 - sqrtRatioAX96;
|
|
@@ -221,8 +220,7 @@ var SqrtPriceMath = class {
|
|
|
221
220
|
}
|
|
222
221
|
static getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
|
|
223
222
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
224
|
-
sqrtRatioAX96 = sqrtRatioBX96;
|
|
225
|
-
sqrtRatioBX96 = sqrtRatioAX96;
|
|
223
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
226
224
|
}
|
|
227
225
|
return roundUp ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, Q96) : liquidity * (sqrtRatioBX96 - sqrtRatioAX96) / Q96;
|
|
228
226
|
}
|
|
@@ -1693,6 +1691,56 @@ var Trade = class {
|
|
|
1693
1691
|
return bestTrades;
|
|
1694
1692
|
}
|
|
1695
1693
|
};
|
|
1694
|
+
var getCurrency0Price = ([currency0, currency1], currentSqrtRatioX96) => {
|
|
1695
|
+
const ratio192 = BigInt(currentSqrtRatioX96) * BigInt(currentSqrtRatioX96);
|
|
1696
|
+
return new sdk.Price(currency0, currency1, Q192, ratio192);
|
|
1697
|
+
};
|
|
1698
|
+
var getCurrency1Price = ([currency0, currency1], currentSqrtRatioX96) => {
|
|
1699
|
+
const ratio192 = BigInt(currentSqrtRatioX96) * BigInt(currentSqrtRatioX96);
|
|
1700
|
+
return new sdk.Price(currency1, currency0, Q192, ratio192);
|
|
1701
|
+
};
|
|
1702
|
+
var NO_TICK_DATA_PROVIDER_DEFAULT2 = new NoTickDataProvider();
|
|
1703
|
+
var MAX_FEE_AMOUNT = 1000000n;
|
|
1704
|
+
var getPool = ({
|
|
1705
|
+
currencyA,
|
|
1706
|
+
currencyB,
|
|
1707
|
+
fee,
|
|
1708
|
+
sqrtRatioX96,
|
|
1709
|
+
liquidity,
|
|
1710
|
+
tickCurrent,
|
|
1711
|
+
tickSpacing,
|
|
1712
|
+
ticks = NO_TICK_DATA_PROVIDER_DEFAULT2
|
|
1713
|
+
}) => {
|
|
1714
|
+
invariant9__default.default(Number.isInteger(fee) && BigInt(fee) < MAX_FEE_AMOUNT, "FEE");
|
|
1715
|
+
const [currency0, currency1] = swapSdkCore.sortCurrencies([currencyA, currencyB]);
|
|
1716
|
+
return {
|
|
1717
|
+
currency0,
|
|
1718
|
+
currency1,
|
|
1719
|
+
fee,
|
|
1720
|
+
tickCurrent,
|
|
1721
|
+
tickSpacing,
|
|
1722
|
+
sqrtRatioX96: BigInt(sqrtRatioX96),
|
|
1723
|
+
liquidity: BigInt(liquidity),
|
|
1724
|
+
tickDataProvider: Array.isArray(ticks) ? new TickListDataProvider(ticks) : ticks
|
|
1725
|
+
};
|
|
1726
|
+
};
|
|
1727
|
+
var getPriceOfCurrency = (pool, currency) => {
|
|
1728
|
+
if (currency.isNative) {
|
|
1729
|
+
invariant9__default.default(pool.currency0.isNative, "CURRENCY");
|
|
1730
|
+
return getCurrency0Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1731
|
+
}
|
|
1732
|
+
invariant9__default.default(pool.currency0.equals(currency) || pool.currency1.equals(currency), "CURRENCY");
|
|
1733
|
+
return pool.currency0.equals(currency) ? getCurrency0Price([pool.currency0, pool.currency1], pool.sqrtRatioX96) : getCurrency1Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1734
|
+
};
|
|
1735
|
+
var getPriceOfCurrency0 = (pool) => getCurrency0Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1736
|
+
var getPriceOfCurrency1 = (pool) => getCurrency1Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1737
|
+
|
|
1738
|
+
// src/functions/hasInvolvedCurrency.ts
|
|
1739
|
+
var hasInvolvedCurrency = (pool, currency) => {
|
|
1740
|
+
if (currency.isNative)
|
|
1741
|
+
return pool.currency0.isNative && pool.currency1.chainId === currency.chainId;
|
|
1742
|
+
return pool.currency0.equals(currency) || pool.currency1.equals(currency);
|
|
1743
|
+
};
|
|
1696
1744
|
|
|
1697
1745
|
// src/utils/calldata.ts
|
|
1698
1746
|
function toHex(bigintIsh) {
|
|
@@ -2006,6 +2054,139 @@ var isPoolTickInRange = (pool, tickLower, tickUpper) => {
|
|
|
2006
2054
|
const above = typeof tickUpper === "number" ? pool.tickCurrent >= tickUpper : void 0;
|
|
2007
2055
|
return typeof below === "boolean" && typeof above === "boolean" ? !below && !above : false;
|
|
2008
2056
|
};
|
|
2057
|
+
|
|
2058
|
+
// src/functions/swap.ts
|
|
2059
|
+
var swap = async ({
|
|
2060
|
+
pool,
|
|
2061
|
+
zeroForOne,
|
|
2062
|
+
amountSpecified,
|
|
2063
|
+
sqrtPriceLimitX96
|
|
2064
|
+
}) => {
|
|
2065
|
+
if (!sqrtPriceLimitX96)
|
|
2066
|
+
sqrtPriceLimitX96 = zeroForOne ? TickMath.MIN_SQRT_RATIO + ONE : TickMath.MAX_SQRT_RATIO - ONE;
|
|
2067
|
+
if (zeroForOne) {
|
|
2068
|
+
invariant9__default.default(sqrtPriceLimitX96 > TickMath.MIN_SQRT_RATIO, "RATIO_MIN");
|
|
2069
|
+
invariant9__default.default(sqrtPriceLimitX96 < pool.sqrtRatioX96, "RATIO_CURRENT");
|
|
2070
|
+
} else {
|
|
2071
|
+
invariant9__default.default(sqrtPriceLimitX96 < TickMath.MAX_SQRT_RATIO, "RATIO_MAX");
|
|
2072
|
+
invariant9__default.default(sqrtPriceLimitX96 > pool.sqrtRatioX96, "RATIO_CURRENT");
|
|
2073
|
+
}
|
|
2074
|
+
const exactInput = amountSpecified >= ZERO;
|
|
2075
|
+
const state = {
|
|
2076
|
+
amountSpecifiedRemaining: amountSpecified,
|
|
2077
|
+
amountCalculated: ZERO,
|
|
2078
|
+
sqrtPriceX96: pool.sqrtRatioX96,
|
|
2079
|
+
tick: pool.tickCurrent,
|
|
2080
|
+
liquidity: pool.liquidity
|
|
2081
|
+
};
|
|
2082
|
+
while (state.amountSpecifiedRemaining !== ZERO && state.sqrtPriceX96 != sqrtPriceLimitX96) {
|
|
2083
|
+
const step = {};
|
|
2084
|
+
step.sqrtPriceStartX96 = state.sqrtPriceX96;
|
|
2085
|
+
[step.tickNext, step.initialized] = await pool.tickDataProvider.nextInitializedTickWithinOneWord(
|
|
2086
|
+
state.tick,
|
|
2087
|
+
zeroForOne,
|
|
2088
|
+
pool.tickSpacing
|
|
2089
|
+
);
|
|
2090
|
+
if (step.tickNext < TickMath.MIN_TICK) {
|
|
2091
|
+
step.tickNext = TickMath.MIN_TICK;
|
|
2092
|
+
} else if (step.tickNext > TickMath.MAX_TICK) {
|
|
2093
|
+
step.tickNext = TickMath.MAX_TICK;
|
|
2094
|
+
}
|
|
2095
|
+
step.sqrtPriceNextX96 = TickMath.getSqrtRatioAtTick(step.tickNext);
|
|
2096
|
+
[state.sqrtPriceX96, step.amountIn, step.amountOut, step.feeAmount] = SwapMath.computeSwapStep(
|
|
2097
|
+
state.sqrtPriceX96,
|
|
2098
|
+
(zeroForOne ? step.sqrtPriceNextX96 < sqrtPriceLimitX96 : step.sqrtPriceNextX96 > sqrtPriceLimitX96) ? sqrtPriceLimitX96 : step.sqrtPriceNextX96,
|
|
2099
|
+
state.liquidity,
|
|
2100
|
+
state.amountSpecifiedRemaining,
|
|
2101
|
+
pool.fee
|
|
2102
|
+
);
|
|
2103
|
+
if (exactInput) {
|
|
2104
|
+
state.amountSpecifiedRemaining -= step.amountIn + step.feeAmount;
|
|
2105
|
+
state.amountCalculated = state.amountCalculated - step.amountOut;
|
|
2106
|
+
} else {
|
|
2107
|
+
state.amountSpecifiedRemaining = state.amountSpecifiedRemaining + step.amountOut;
|
|
2108
|
+
state.amountCalculated = state.amountCalculated + (step.amountIn + step.feeAmount);
|
|
2109
|
+
}
|
|
2110
|
+
if (state.sqrtPriceX96 === step.sqrtPriceNextX96) {
|
|
2111
|
+
if (step.initialized) {
|
|
2112
|
+
let liquidityNet = BigInt((await pool.tickDataProvider.getTick(step.tickNext)).liquidityNet);
|
|
2113
|
+
if (zeroForOne)
|
|
2114
|
+
liquidityNet *= NEGATIVE_ONE;
|
|
2115
|
+
state.liquidity = LiquidityMath.addDelta(state.liquidity, liquidityNet);
|
|
2116
|
+
}
|
|
2117
|
+
state.tick = zeroForOne ? step.tickNext - 1 : step.tickNext;
|
|
2118
|
+
} else if (state.sqrtPriceX96 !== step.sqrtPriceStartX96) {
|
|
2119
|
+
state.tick = TickMath.getTickAtSqrtRatio(state.sqrtPriceX96);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
return {
|
|
2123
|
+
amountSpecifiedRemaining: state.amountSpecifiedRemaining,
|
|
2124
|
+
amountCalculated: state.amountCalculated,
|
|
2125
|
+
sqrtRatioX96: state.sqrtPriceX96,
|
|
2126
|
+
liquidity: state.liquidity,
|
|
2127
|
+
tickCurrent: state.tick
|
|
2128
|
+
};
|
|
2129
|
+
};
|
|
2130
|
+
var getOutputAmount = async (pool, inputAmount, options) => {
|
|
2131
|
+
invariant9__default.default(hasInvolvedCurrency(pool, inputAmount.currency), "CURRENCY");
|
|
2132
|
+
const zeroForOne = inputAmount.currency.equals(pool.currency0);
|
|
2133
|
+
const { sqrtPriceLimitX96, exact } = options || {};
|
|
2134
|
+
const {
|
|
2135
|
+
amountCalculated: outputAmount,
|
|
2136
|
+
sqrtRatioX96,
|
|
2137
|
+
liquidity,
|
|
2138
|
+
tickCurrent,
|
|
2139
|
+
amountSpecifiedRemaining
|
|
2140
|
+
} = await swap({
|
|
2141
|
+
pool,
|
|
2142
|
+
zeroForOne,
|
|
2143
|
+
amountSpecified: inputAmount.quotient,
|
|
2144
|
+
sqrtPriceLimitX96
|
|
2145
|
+
});
|
|
2146
|
+
const outputToken = zeroForOne ? pool.currency1 : pool.currency0;
|
|
2147
|
+
if (exact) {
|
|
2148
|
+
invariant9__default.default(amountSpecifiedRemaining === ZERO, "INSUFFICIENT_LIQUIDITY");
|
|
2149
|
+
}
|
|
2150
|
+
return [
|
|
2151
|
+
sdk.CurrencyAmount.fromRawAmount(outputToken, outputAmount * NEGATIVE_ONE),
|
|
2152
|
+
{
|
|
2153
|
+
...pool,
|
|
2154
|
+
sqrtRatioX96,
|
|
2155
|
+
liquidity,
|
|
2156
|
+
tickCurrent
|
|
2157
|
+
}
|
|
2158
|
+
];
|
|
2159
|
+
};
|
|
2160
|
+
var getInputAmount = async (pool, outputAmount, options) => {
|
|
2161
|
+
invariant9__default.default(hasInvolvedCurrency(pool, outputAmount.currency), "CURRENCY");
|
|
2162
|
+
const zeroForOne = outputAmount.currency.equals(pool.currency1);
|
|
2163
|
+
const { sqrtPriceLimitX96, exact } = options || {};
|
|
2164
|
+
const {
|
|
2165
|
+
amountCalculated: inputAmount,
|
|
2166
|
+
sqrtRatioX96,
|
|
2167
|
+
liquidity,
|
|
2168
|
+
tickCurrent,
|
|
2169
|
+
amountSpecifiedRemaining
|
|
2170
|
+
} = await swap({
|
|
2171
|
+
pool,
|
|
2172
|
+
zeroForOne,
|
|
2173
|
+
amountSpecified: outputAmount.quotient * NEGATIVE_ONE,
|
|
2174
|
+
sqrtPriceLimitX96
|
|
2175
|
+
});
|
|
2176
|
+
if (exact) {
|
|
2177
|
+
invariant9__default.default(amountSpecifiedRemaining === ZERO, "INSUFFICIENT_LIQUIDITY");
|
|
2178
|
+
}
|
|
2179
|
+
const inputCurrency = zeroForOne ? pool.currency0 : pool.currency1;
|
|
2180
|
+
return [
|
|
2181
|
+
sdk.CurrencyAmount.fromRawAmount(inputCurrency, inputAmount),
|
|
2182
|
+
{
|
|
2183
|
+
...pool,
|
|
2184
|
+
sqrtRatioX96,
|
|
2185
|
+
liquidity,
|
|
2186
|
+
tickCurrent
|
|
2187
|
+
}
|
|
2188
|
+
];
|
|
2189
|
+
};
|
|
2009
2190
|
var IMulticall = [
|
|
2010
2191
|
{
|
|
2011
2192
|
inputs: [
|
|
@@ -6651,15 +6832,24 @@ exports.encodeSqrtRatioX96 = encodeSqrtRatioX96;
|
|
|
6651
6832
|
exports.getAmountsAtNewPrice = getAmountsAtNewPrice;
|
|
6652
6833
|
exports.getAmountsByLiquidityAndPrice = getAmountsByLiquidityAndPrice;
|
|
6653
6834
|
exports.getAverageLiquidity = getAverageLiquidity;
|
|
6835
|
+
exports.getCurrency0Price = getCurrency0Price;
|
|
6836
|
+
exports.getCurrency1Price = getCurrency1Price;
|
|
6654
6837
|
exports.getDependentAmount = getDependentAmount;
|
|
6655
6838
|
exports.getEstimatedLPFee = getEstimatedLPFee;
|
|
6656
6839
|
exports.getEstimatedLPFeeByAmounts = getEstimatedLPFeeByAmounts;
|
|
6657
6840
|
exports.getEstimatedLPFeeByAmountsWithProtocolFee = getEstimatedLPFeeByAmountsWithProtocolFee;
|
|
6658
6841
|
exports.getEstimatedLPFeeWithProtocolFee = getEstimatedLPFeeWithProtocolFee;
|
|
6842
|
+
exports.getInputAmount = getInputAmount;
|
|
6659
6843
|
exports.getLiquidityByAmountsAndPrice = getLiquidityByAmountsAndPrice;
|
|
6660
6844
|
exports.getLiquidityBySingleAmount = getLiquidityBySingleAmount;
|
|
6661
6845
|
exports.getLiquidityFromSqrtRatioX96 = getLiquidityFromSqrtRatioX96;
|
|
6662
6846
|
exports.getLiquidityFromTick = getLiquidityFromTick;
|
|
6847
|
+
exports.getOutputAmount = getOutputAmount;
|
|
6848
|
+
exports.getPool = getPool;
|
|
6849
|
+
exports.getPriceOfCurrency = getPriceOfCurrency;
|
|
6850
|
+
exports.getPriceOfCurrency0 = getPriceOfCurrency0;
|
|
6851
|
+
exports.getPriceOfCurrency1 = getPriceOfCurrency1;
|
|
6852
|
+
exports.hasInvolvedCurrency = hasInvolvedCurrency;
|
|
6663
6853
|
exports.isMint = isMint;
|
|
6664
6854
|
exports.isPoolTickInRange = isPoolTickInRange;
|
|
6665
6855
|
exports.isSorted = isSorted;
|
|
@@ -6677,6 +6867,7 @@ exports.quoterV2ABI = quoterV2ABI;
|
|
|
6677
6867
|
exports.selfPermitABI = selfPermitABI;
|
|
6678
6868
|
exports.sqrtRatioX96ToPrice = sqrtRatioX96ToPrice;
|
|
6679
6869
|
exports.subIn256 = subIn256;
|
|
6870
|
+
exports.swap = swap;
|
|
6680
6871
|
exports.swapRouterABI = swapRouterABI;
|
|
6681
6872
|
exports.tickToPrice = tickToPrice;
|
|
6682
6873
|
exports.toHex = toHex;
|
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, 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, 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
|
|
@@ -206,8 +206,7 @@ var SqrtPriceMath = class {
|
|
|
206
206
|
}
|
|
207
207
|
static getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
|
|
208
208
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
209
|
-
sqrtRatioAX96 = sqrtRatioBX96;
|
|
210
|
-
sqrtRatioBX96 = sqrtRatioAX96;
|
|
209
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
211
210
|
}
|
|
212
211
|
const numerator1 = liquidity << 96n;
|
|
213
212
|
const numerator2 = sqrtRatioBX96 - sqrtRatioAX96;
|
|
@@ -215,8 +214,7 @@ var SqrtPriceMath = class {
|
|
|
215
214
|
}
|
|
216
215
|
static getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
|
|
217
216
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
218
|
-
sqrtRatioAX96 = sqrtRatioBX96;
|
|
219
|
-
sqrtRatioBX96 = sqrtRatioAX96;
|
|
217
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
220
218
|
}
|
|
221
219
|
return roundUp ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, Q96) : liquidity * (sqrtRatioBX96 - sqrtRatioAX96) / Q96;
|
|
222
220
|
}
|
|
@@ -1687,6 +1685,56 @@ var Trade = class {
|
|
|
1687
1685
|
return bestTrades;
|
|
1688
1686
|
}
|
|
1689
1687
|
};
|
|
1688
|
+
var getCurrency0Price = ([currency0, currency1], currentSqrtRatioX96) => {
|
|
1689
|
+
const ratio192 = BigInt(currentSqrtRatioX96) * BigInt(currentSqrtRatioX96);
|
|
1690
|
+
return new Price(currency0, currency1, Q192, ratio192);
|
|
1691
|
+
};
|
|
1692
|
+
var getCurrency1Price = ([currency0, currency1], currentSqrtRatioX96) => {
|
|
1693
|
+
const ratio192 = BigInt(currentSqrtRatioX96) * BigInt(currentSqrtRatioX96);
|
|
1694
|
+
return new Price(currency1, currency0, Q192, ratio192);
|
|
1695
|
+
};
|
|
1696
|
+
var NO_TICK_DATA_PROVIDER_DEFAULT2 = new NoTickDataProvider();
|
|
1697
|
+
var MAX_FEE_AMOUNT = 1000000n;
|
|
1698
|
+
var getPool = ({
|
|
1699
|
+
currencyA,
|
|
1700
|
+
currencyB,
|
|
1701
|
+
fee,
|
|
1702
|
+
sqrtRatioX96,
|
|
1703
|
+
liquidity,
|
|
1704
|
+
tickCurrent,
|
|
1705
|
+
tickSpacing,
|
|
1706
|
+
ticks = NO_TICK_DATA_PROVIDER_DEFAULT2
|
|
1707
|
+
}) => {
|
|
1708
|
+
invariant9(Number.isInteger(fee) && BigInt(fee) < MAX_FEE_AMOUNT, "FEE");
|
|
1709
|
+
const [currency0, currency1] = sortCurrencies([currencyA, currencyB]);
|
|
1710
|
+
return {
|
|
1711
|
+
currency0,
|
|
1712
|
+
currency1,
|
|
1713
|
+
fee,
|
|
1714
|
+
tickCurrent,
|
|
1715
|
+
tickSpacing,
|
|
1716
|
+
sqrtRatioX96: BigInt(sqrtRatioX96),
|
|
1717
|
+
liquidity: BigInt(liquidity),
|
|
1718
|
+
tickDataProvider: Array.isArray(ticks) ? new TickListDataProvider(ticks) : ticks
|
|
1719
|
+
};
|
|
1720
|
+
};
|
|
1721
|
+
var getPriceOfCurrency = (pool, currency) => {
|
|
1722
|
+
if (currency.isNative) {
|
|
1723
|
+
invariant9(pool.currency0.isNative, "CURRENCY");
|
|
1724
|
+
return getCurrency0Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1725
|
+
}
|
|
1726
|
+
invariant9(pool.currency0.equals(currency) || pool.currency1.equals(currency), "CURRENCY");
|
|
1727
|
+
return pool.currency0.equals(currency) ? getCurrency0Price([pool.currency0, pool.currency1], pool.sqrtRatioX96) : getCurrency1Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1728
|
+
};
|
|
1729
|
+
var getPriceOfCurrency0 = (pool) => getCurrency0Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1730
|
+
var getPriceOfCurrency1 = (pool) => getCurrency1Price([pool.currency0, pool.currency1], pool.sqrtRatioX96);
|
|
1731
|
+
|
|
1732
|
+
// src/functions/hasInvolvedCurrency.ts
|
|
1733
|
+
var hasInvolvedCurrency = (pool, currency) => {
|
|
1734
|
+
if (currency.isNative)
|
|
1735
|
+
return pool.currency0.isNative && pool.currency1.chainId === currency.chainId;
|
|
1736
|
+
return pool.currency0.equals(currency) || pool.currency1.equals(currency);
|
|
1737
|
+
};
|
|
1690
1738
|
|
|
1691
1739
|
// src/utils/calldata.ts
|
|
1692
1740
|
function toHex(bigintIsh) {
|
|
@@ -2000,6 +2048,139 @@ var isPoolTickInRange = (pool, tickLower, tickUpper) => {
|
|
|
2000
2048
|
const above = typeof tickUpper === "number" ? pool.tickCurrent >= tickUpper : void 0;
|
|
2001
2049
|
return typeof below === "boolean" && typeof above === "boolean" ? !below && !above : false;
|
|
2002
2050
|
};
|
|
2051
|
+
|
|
2052
|
+
// src/functions/swap.ts
|
|
2053
|
+
var swap = async ({
|
|
2054
|
+
pool,
|
|
2055
|
+
zeroForOne,
|
|
2056
|
+
amountSpecified,
|
|
2057
|
+
sqrtPriceLimitX96
|
|
2058
|
+
}) => {
|
|
2059
|
+
if (!sqrtPriceLimitX96)
|
|
2060
|
+
sqrtPriceLimitX96 = zeroForOne ? TickMath.MIN_SQRT_RATIO + ONE : TickMath.MAX_SQRT_RATIO - ONE;
|
|
2061
|
+
if (zeroForOne) {
|
|
2062
|
+
invariant9(sqrtPriceLimitX96 > TickMath.MIN_SQRT_RATIO, "RATIO_MIN");
|
|
2063
|
+
invariant9(sqrtPriceLimitX96 < pool.sqrtRatioX96, "RATIO_CURRENT");
|
|
2064
|
+
} else {
|
|
2065
|
+
invariant9(sqrtPriceLimitX96 < TickMath.MAX_SQRT_RATIO, "RATIO_MAX");
|
|
2066
|
+
invariant9(sqrtPriceLimitX96 > pool.sqrtRatioX96, "RATIO_CURRENT");
|
|
2067
|
+
}
|
|
2068
|
+
const exactInput = amountSpecified >= ZERO;
|
|
2069
|
+
const state = {
|
|
2070
|
+
amountSpecifiedRemaining: amountSpecified,
|
|
2071
|
+
amountCalculated: ZERO,
|
|
2072
|
+
sqrtPriceX96: pool.sqrtRatioX96,
|
|
2073
|
+
tick: pool.tickCurrent,
|
|
2074
|
+
liquidity: pool.liquidity
|
|
2075
|
+
};
|
|
2076
|
+
while (state.amountSpecifiedRemaining !== ZERO && state.sqrtPriceX96 != sqrtPriceLimitX96) {
|
|
2077
|
+
const step = {};
|
|
2078
|
+
step.sqrtPriceStartX96 = state.sqrtPriceX96;
|
|
2079
|
+
[step.tickNext, step.initialized] = await pool.tickDataProvider.nextInitializedTickWithinOneWord(
|
|
2080
|
+
state.tick,
|
|
2081
|
+
zeroForOne,
|
|
2082
|
+
pool.tickSpacing
|
|
2083
|
+
);
|
|
2084
|
+
if (step.tickNext < TickMath.MIN_TICK) {
|
|
2085
|
+
step.tickNext = TickMath.MIN_TICK;
|
|
2086
|
+
} else if (step.tickNext > TickMath.MAX_TICK) {
|
|
2087
|
+
step.tickNext = TickMath.MAX_TICK;
|
|
2088
|
+
}
|
|
2089
|
+
step.sqrtPriceNextX96 = TickMath.getSqrtRatioAtTick(step.tickNext);
|
|
2090
|
+
[state.sqrtPriceX96, step.amountIn, step.amountOut, step.feeAmount] = SwapMath.computeSwapStep(
|
|
2091
|
+
state.sqrtPriceX96,
|
|
2092
|
+
(zeroForOne ? step.sqrtPriceNextX96 < sqrtPriceLimitX96 : step.sqrtPriceNextX96 > sqrtPriceLimitX96) ? sqrtPriceLimitX96 : step.sqrtPriceNextX96,
|
|
2093
|
+
state.liquidity,
|
|
2094
|
+
state.amountSpecifiedRemaining,
|
|
2095
|
+
pool.fee
|
|
2096
|
+
);
|
|
2097
|
+
if (exactInput) {
|
|
2098
|
+
state.amountSpecifiedRemaining -= step.amountIn + step.feeAmount;
|
|
2099
|
+
state.amountCalculated = state.amountCalculated - step.amountOut;
|
|
2100
|
+
} else {
|
|
2101
|
+
state.amountSpecifiedRemaining = state.amountSpecifiedRemaining + step.amountOut;
|
|
2102
|
+
state.amountCalculated = state.amountCalculated + (step.amountIn + step.feeAmount);
|
|
2103
|
+
}
|
|
2104
|
+
if (state.sqrtPriceX96 === step.sqrtPriceNextX96) {
|
|
2105
|
+
if (step.initialized) {
|
|
2106
|
+
let liquidityNet = BigInt((await pool.tickDataProvider.getTick(step.tickNext)).liquidityNet);
|
|
2107
|
+
if (zeroForOne)
|
|
2108
|
+
liquidityNet *= NEGATIVE_ONE;
|
|
2109
|
+
state.liquidity = LiquidityMath.addDelta(state.liquidity, liquidityNet);
|
|
2110
|
+
}
|
|
2111
|
+
state.tick = zeroForOne ? step.tickNext - 1 : step.tickNext;
|
|
2112
|
+
} else if (state.sqrtPriceX96 !== step.sqrtPriceStartX96) {
|
|
2113
|
+
state.tick = TickMath.getTickAtSqrtRatio(state.sqrtPriceX96);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
return {
|
|
2117
|
+
amountSpecifiedRemaining: state.amountSpecifiedRemaining,
|
|
2118
|
+
amountCalculated: state.amountCalculated,
|
|
2119
|
+
sqrtRatioX96: state.sqrtPriceX96,
|
|
2120
|
+
liquidity: state.liquidity,
|
|
2121
|
+
tickCurrent: state.tick
|
|
2122
|
+
};
|
|
2123
|
+
};
|
|
2124
|
+
var getOutputAmount = async (pool, inputAmount, options) => {
|
|
2125
|
+
invariant9(hasInvolvedCurrency(pool, inputAmount.currency), "CURRENCY");
|
|
2126
|
+
const zeroForOne = inputAmount.currency.equals(pool.currency0);
|
|
2127
|
+
const { sqrtPriceLimitX96, exact } = options || {};
|
|
2128
|
+
const {
|
|
2129
|
+
amountCalculated: outputAmount,
|
|
2130
|
+
sqrtRatioX96,
|
|
2131
|
+
liquidity,
|
|
2132
|
+
tickCurrent,
|
|
2133
|
+
amountSpecifiedRemaining
|
|
2134
|
+
} = await swap({
|
|
2135
|
+
pool,
|
|
2136
|
+
zeroForOne,
|
|
2137
|
+
amountSpecified: inputAmount.quotient,
|
|
2138
|
+
sqrtPriceLimitX96
|
|
2139
|
+
});
|
|
2140
|
+
const outputToken = zeroForOne ? pool.currency1 : pool.currency0;
|
|
2141
|
+
if (exact) {
|
|
2142
|
+
invariant9(amountSpecifiedRemaining === ZERO, "INSUFFICIENT_LIQUIDITY");
|
|
2143
|
+
}
|
|
2144
|
+
return [
|
|
2145
|
+
CurrencyAmount.fromRawAmount(outputToken, outputAmount * NEGATIVE_ONE),
|
|
2146
|
+
{
|
|
2147
|
+
...pool,
|
|
2148
|
+
sqrtRatioX96,
|
|
2149
|
+
liquidity,
|
|
2150
|
+
tickCurrent
|
|
2151
|
+
}
|
|
2152
|
+
];
|
|
2153
|
+
};
|
|
2154
|
+
var getInputAmount = async (pool, outputAmount, options) => {
|
|
2155
|
+
invariant9(hasInvolvedCurrency(pool, outputAmount.currency), "CURRENCY");
|
|
2156
|
+
const zeroForOne = outputAmount.currency.equals(pool.currency1);
|
|
2157
|
+
const { sqrtPriceLimitX96, exact } = options || {};
|
|
2158
|
+
const {
|
|
2159
|
+
amountCalculated: inputAmount,
|
|
2160
|
+
sqrtRatioX96,
|
|
2161
|
+
liquidity,
|
|
2162
|
+
tickCurrent,
|
|
2163
|
+
amountSpecifiedRemaining
|
|
2164
|
+
} = await swap({
|
|
2165
|
+
pool,
|
|
2166
|
+
zeroForOne,
|
|
2167
|
+
amountSpecified: outputAmount.quotient * NEGATIVE_ONE,
|
|
2168
|
+
sqrtPriceLimitX96
|
|
2169
|
+
});
|
|
2170
|
+
if (exact) {
|
|
2171
|
+
invariant9(amountSpecifiedRemaining === ZERO, "INSUFFICIENT_LIQUIDITY");
|
|
2172
|
+
}
|
|
2173
|
+
const inputCurrency = zeroForOne ? pool.currency0 : pool.currency1;
|
|
2174
|
+
return [
|
|
2175
|
+
CurrencyAmount.fromRawAmount(inputCurrency, inputAmount),
|
|
2176
|
+
{
|
|
2177
|
+
...pool,
|
|
2178
|
+
sqrtRatioX96,
|
|
2179
|
+
liquidity,
|
|
2180
|
+
tickCurrent
|
|
2181
|
+
}
|
|
2182
|
+
];
|
|
2183
|
+
};
|
|
2003
2184
|
var IMulticall = [
|
|
2004
2185
|
{
|
|
2005
2186
|
inputs: [
|
|
@@ -6606,4 +6787,4 @@ var v3PoolAbi = [
|
|
|
6606
6787
|
}
|
|
6607
6788
|
];
|
|
6608
6789
|
|
|
6609
|
-
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, getDependentAmount, getEstimatedLPFee, getEstimatedLPFeeByAmounts, getEstimatedLPFeeByAmountsWithProtocolFee, getEstimatedLPFeeWithProtocolFee, getLiquidityByAmountsAndPrice, getLiquidityBySingleAmount, getLiquidityFromSqrtRatioX96, getLiquidityFromTick, isMint, isPoolTickInRange, isSorted, masterChefV3ABI, maxLiquidityForAmounts, mostSignificantBit, nearestUsableTick, nonfungiblePositionManagerABI, pancakeV3PoolABI, parseProtocolFees, peripheryPaymentsWithFeeABI, priceToClosestTick, quoterABI, quoterV2ABI, selfPermitABI, sqrtRatioX96ToPrice, subIn256, swapRouterABI, tickToPrice, toHex, tradeComparator, v3PoolAbi, v3StakerABI };
|
|
6790
|
+
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 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqrtPriceMath.d.ts","sourceRoot":"","sources":["../../src/utils/sqrtPriceMath.ts"],"names":[],"mappings":"AAiBA,8BAAsB,aAAa;IACjC;;OAEG;IACH,OAAO;WAEO,eAAe,CAC3B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACf,MAAM;
|
|
1
|
+
{"version":3,"file":"sqrtPriceMath.d.ts","sourceRoot":"","sources":["../../src/utils/sqrtPriceMath.ts"],"names":[],"mappings":"AAiBA,8BAAsB,aAAa;IACjC;;OAEG;IACH,OAAO;WAEO,eAAe,CAC3B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACf,MAAM;WAaK,eAAe,CAC3B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACf,MAAM;WAUK,yBAAyB,CACrC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,OAAO,GAClB,MAAM;WASK,0BAA0B,CACtC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,OAAO,GAClB,MAAM;IAST,OAAO,CAAC,MAAM,CAAC,qCAAqC;IA4BpD,OAAO,CAAC,MAAM,CAAC,uCAAuC;CAgBvD"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "3.8.
|
|
7
|
+
"version": "3.8.9",
|
|
8
8
|
"description": "⚒️ An SDK for building applications on top of Pancakeswap V3",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"tiny-invariant": "^1.3.0",
|
|
24
24
|
"tiny-warning": "^1.0.3",
|
|
25
25
|
"toformat": "^2.0.0",
|
|
26
|
-
"viem": "2.
|
|
27
|
-
"@pancakeswap/chains": "0.4.
|
|
28
|
-
"@pancakeswap/sdk": "5.8.
|
|
26
|
+
"viem": "^2.17.3",
|
|
27
|
+
"@pancakeswap/chains": "0.4.6",
|
|
28
|
+
"@pancakeswap/sdk": "5.8.7",
|
|
29
29
|
"@pancakeswap/swap-sdk-core": "1.1.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"tsup": "^6.7.0",
|
|
33
|
-
"@pancakeswap/utils": "6.0.
|
|
33
|
+
"@pancakeswap/utils": "6.0.9"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=10"
|