@paraswap/dex-lib 2.42.22 → 2.42.23
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/build/abi/hashflow/HashflowRouter.abi.json +816 -246
- package/build/abi/kyberswap-elastic/IAntiSnipAttackPositionManager.json +1276 -0
- package/build/abi/kyberswap-elastic/IFactory.json +550 -0
- package/build/abi/kyberswap-elastic/IPool.json +1042 -0
- package/build/abi/kyberswap-elastic/IQuoterV2.json +226 -0
- package/build/abi/kyberswap-elastic/IRouter.json +239 -0
- package/build/abi/kyberswap-elastic/TicksFeesReader.json +142 -0
- package/build/abi/wombat/asset.json +769 -0
- package/build/abi/wombat/bmw.json +1247 -0
- package/build/abi/wombat/pool.json +1364 -0
- package/build/config.js +14 -14
- package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +26 -0
- package/build/dex/baseswap-v3/baseswap-v3-factory.js +44 -0
- package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +1 -0
- package/build/dex/baseswap-v3/baseswap-v3-pool.d.ts +46 -0
- package/build/dex/baseswap-v3/baseswap-v3-pool.js +312 -0
- package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +1 -0
- package/build/dex/baseswap-v3/baseswap-v3.d.ts +71 -0
- package/build/dex/baseswap-v3/baseswap-v3.js +752 -0
- package/build/dex/baseswap-v3/baseswap-v3.js.map +1 -0
- package/build/dex/baseswap-v3/config.d.ts +9 -0
- package/build/dex/baseswap-v3/config.js +48 -0
- package/build/dex/baseswap-v3/config.js.map +1 -0
- package/build/dex/baseswap-v3/constants.d.ts +28 -0
- package/build/dex/baseswap-v3/constants.js +35 -0
- package/build/dex/baseswap-v3/constants.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.js +93 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.js +8 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.js +9 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.js +19 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.js +22 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.d.ts +10 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.js +133 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.js +70 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/Tick.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/Tick.js +45 -0
- package/build/dex/baseswap-v3/contract-math/Tick.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.js +84 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.d.ts +8 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.js +162 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.js +10 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.d.ts +37 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js +393 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/utils.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/utils.js +42 -0
- package/build/dex/baseswap-v3/contract-math/utils.js.map +1 -0
- package/build/dex/baseswap-v3/types.d.ts +164 -0
- package/build/dex/baseswap-v3/types.js +9 -0
- package/build/dex/baseswap-v3/types.js.map +1 -0
- package/build/dex/baseswap-v3/utils.d.ts +6 -0
- package/build/dex/baseswap-v3/utils.js +65 -0
- package/build/dex/baseswap-v3/utils.js.map +1 -0
- package/build/dex/hashflow/config.d.ts +1 -1
- package/build/dex/hashflow/config.js +6 -6
- package/build/dex/hashflow/config.js.map +1 -1
- package/build/dex/hashflow/hashflow.d.ts +7 -7
- package/build/dex/hashflow/hashflow.js +47 -54
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/hashflow/rate-fetcher.d.ts +1 -1
- package/build/dex/hashflow/rate-fetcher.js +2 -4
- package/build/dex/hashflow/rate-fetcher.js.map +1 -1
- package/build/dex/hashflow/types.d.ts +5 -6
- package/build/dex/hashflow/types.js.map +1 -1
- package/build/dex/hashflow/validators.js +11 -4
- package/build/dex/hashflow/validators.js.map +1 -1
- package/build/dex/hello/config.d.ts +4 -0
- package/build/dex/hello/config.js +15 -0
- package/build/dex/hello/config.js.map +1 -0
- package/build/dex/hello/hello-pool.d.ts +39 -0
- package/build/dex/hello/hello-pool.js +64 -0
- package/build/dex/hello/hello-pool.js.map +1 -0
- package/build/dex/hello/hello.d.ts +37 -0
- package/build/dex/hello/hello.js +126 -0
- package/build/dex/hello/hello.js.map +1 -0
- package/build/dex/hello/types.d.ts +6 -0
- package/build/dex/hello/types.js +3 -0
- package/build/dex/hello/types.js.map +1 -0
- package/build/dex/kyberswap-elastic/config.d.ts +4 -0
- package/build/dex/kyberswap-elastic/config.js +80 -0
- package/build/dex/kyberswap-elastic/config.js.map +1 -0
- package/build/dex/kyberswap-elastic/constants.d.ts +17 -0
- package/build/dex/kyberswap-elastic/constants.js +42 -0
- package/build/dex/kyberswap-elastic/constants.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js +9 -0
- package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/FullMath.d.ts +5 -0
- package/build/dex/kyberswap-elastic/contract-math/FullMath.js +22 -0
- package/build/dex/kyberswap-elastic/contract-math/FullMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js +12 -0
- package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js +22 -0
- package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.d.ts +5 -0
- package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js +25 -0
- package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/QuadMath.d.ts +4 -0
- package/build/dex/kyberswap-elastic/contract-math/QuadMath.js +27 -0
- package/build/dex/kyberswap-elastic/contract-math/QuadMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js +14 -0
- package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/SafeCast.d.ts +8 -0
- package/build/dex/kyberswap-elastic/contract-math/SafeCast.js +30 -0
- package/build/dex/kyberswap-elastic/contract-math/SafeCast.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/SwapMath.d.ts +13 -0
- package/build/dex/kyberswap-elastic/contract-math/SwapMath.js +188 -0
- package/build/dex/kyberswap-elastic/contract-math/SwapMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.d.ts +6 -0
- package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js +41 -0
- package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/TickMath.d.ts +9 -0
- package/build/dex/kyberswap-elastic/contract-math/TickMath.js +165 -0
- package/build/dex/kyberswap-elastic/contract-math/TickMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js +10 -0
- package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.d.ts +28 -0
- package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js +502 -0
- package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js.map +1 -0
- package/build/dex/kyberswap-elastic/contract-math/utils.d.ts +3 -0
- package/build/dex/kyberswap-elastic/contract-math/utils.js +16 -0
- package/build/dex/kyberswap-elastic/contract-math/utils.js.map +1 -0
- package/build/dex/kyberswap-elastic/errors.d.ts +2 -0
- package/build/dex/kyberswap-elastic/errors.js +6 -0
- package/build/dex/kyberswap-elastic/errors.js.map +1 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.d.ts +80 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js +458 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js.map +1 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic.d.ts +53 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic.js +610 -0
- package/build/dex/kyberswap-elastic/kyberswap-elastic.js.map +1 -0
- package/build/dex/kyberswap-elastic/types.d.ts +134 -0
- package/build/dex/kyberswap-elastic/types.js +9 -0
- package/build/dex/kyberswap-elastic/types.js.map +1 -0
- package/build/dex/kyberswap-elastic/utils/decoders.d.ts +9 -0
- package/build/dex/kyberswap-elastic/utils/decoders.js +78 -0
- package/build/dex/kyberswap-elastic/utils/decoders.js.map +1 -0
- package/build/dex/morphex/config.d.ts +11 -0
- package/build/dex/morphex/config.js +43 -0
- package/build/dex/morphex/config.js.map +1 -0
- package/build/dex/morphex/morphex.d.ts +25 -0
- package/build/dex/morphex/morphex.js +19 -0
- package/build/dex/morphex/morphex.js.map +1 -0
- package/build/dex/my-test-dex/config.d.ts +4 -0
- package/build/dex/my-test-dex/config.js +15 -0
- package/build/dex/my-test-dex/config.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
- package/build/dex/my-test-dex/my-test-dex.js +126 -0
- package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
- package/build/dex/my-test-dex/types.d.ts +6 -0
- package/build/dex/my-test-dex/types.js +3 -0
- package/build/dex/my-test-dex/types.js.map +1 -0
- package/build/dex/solidly/forks-override/fvm.d.ts +20 -0
- package/build/dex/solidly/forks-override/fvm.js +42 -0
- package/build/dex/solidly/forks-override/fvm.js.map +1 -0
- package/build/dex/wombat/config.d.ts +4 -0
- package/build/dex/wombat/config.js +99 -0
- package/build/dex/wombat/config.js.map +1 -0
- package/build/dex/wombat/types.d.ts +33 -0
- package/build/dex/wombat/types.js +3 -0
- package/build/dex/wombat/types.js.map +1 -0
- package/build/dex/wombat/utils.d.ts +9 -0
- package/build/dex/wombat/utils.js +66 -0
- package/build/dex/wombat/utils.js.map +1 -0
- package/build/dex/wombat/wombat-bmw.d.ts +40 -0
- package/build/dex/wombat/wombat-bmw.js +147 -0
- package/build/dex/wombat/wombat-bmw.js.map +1 -0
- package/build/dex/wombat/wombat-pool.d.ts +22 -0
- package/build/dex/wombat/wombat-pool.js +161 -0
- package/build/dex/wombat/wombat-pool.js.map +1 -0
- package/build/dex/wombat/wombat-quoter.d.ts +16 -0
- package/build/dex/wombat/wombat-quoter.js +176 -0
- package/build/dex/wombat/wombat-quoter.js.map +1 -0
- package/build/dex/wombat/wombat.d.ts +55 -0
- package/build/dex/wombat/wombat.js +290 -0
- package/build/dex/wombat/wombat.js.map +1 -0
- package/build/lib/fetcher/fetcher.d.ts +1 -1
- package/build/lib/fetcher/fetcher.js.map +1 -1
- package/package.json +2 -2
- package/src/abi/hashflow/HashflowRouter.abi.json +816 -246
- package/src/config.ts +14 -14
- package/src/dex/hashflow/config.ts +8 -8
- package/src/dex/hashflow/hashflow-e2e.test.ts +4 -4
- package/src/dex/hashflow/hashflow-integration.test.ts +9 -6
- package/src/dex/hashflow/hashflow.ts +70 -87
- package/src/dex/hashflow/rate-fetcher.ts +6 -8
- package/src/dex/hashflow/types.ts +5 -6
- package/src/dex/hashflow/validators.ts +11 -4
- package/src/lib/fetcher/fetcher.ts +2 -2
- package/tests/constants-e2e.ts +1 -1
- package/tests/tenderly-simulation.ts +5 -2
- package/.vscode/launch.json +0 -39
- package/.vscode/settings.json +0 -2
- package/.vscode/tasks.json +0 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuadMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/QuadMath.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAQ;IACnB,MAAM,CAAC,uBAAuB,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;QAC5D,IAAI,WAAW,GAAW,EAAE,CAAC;QAE7B,WAAW,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,CAAS;QACnB,IAAI,CAAC,GAAG,EAAE,CAAC;QAEX,IAAI,CAAC,GAAG,CAAC,EAAE;YACT,CAAC,GAAG,CAAC,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,EAAE;gBACZ,CAAC,GAAG,CAAC,CAAC;gBACN,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;aACtB;SACF;aAAM,IAAI,CAAC,IAAI,EAAE,EAAE;YAClB,CAAC,GAAG,EAAE,CAAC;SACR;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAxBD,4BAwBC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReinvestmentMath = void 0;
|
|
4
|
+
const FullMath_1 = require("./FullMath");
|
|
5
|
+
class ReinvestmentMath {
|
|
6
|
+
static calcrMintQty(reinvestL, reinvestLLast, baseL, rTokenSupply) {
|
|
7
|
+
let rMintQty = 0n;
|
|
8
|
+
let lpContribution = FullMath_1.FullMath.mulDivFloor(baseL, reinvestL - reinvestLLast, baseL + reinvestL);
|
|
9
|
+
rMintQty = FullMath_1.FullMath.mulDivFloor(rTokenSupply, lpContribution, reinvestLLast);
|
|
10
|
+
return rMintQty;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ReinvestmentMath = ReinvestmentMath;
|
|
14
|
+
//# sourceMappingURL=ReinvestmentMath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReinvestmentMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/ReinvestmentMath.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,MAAa,gBAAgB;IAC3B,MAAM,CAAC,YAAY,CACjB,SAAiB,EACjB,aAAqB,EACrB,KAAa,EACb,YAAoB;QAEpB,IAAI,QAAQ,GAAW,EAAE,CAAC;QAE1B,IAAI,cAAc,GAAG,mBAAQ,CAAC,WAAW,CACvC,KAAK,EACL,SAAS,GAAG,aAAa,EACzB,KAAK,GAAG,SAAS,CAClB,CAAC;QACF,QAAQ,GAAG,mBAAQ,CAAC,WAAW,CAC7B,YAAY,EACZ,cAAc,EACd,aAAa,CACd,CAAC;QACF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AArBD,4CAqBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class SafeCast {
|
|
2
|
+
static toInt256(a: bigint): bigint;
|
|
3
|
+
static revToInt256(a: bigint): bigint;
|
|
4
|
+
static revToInt128(a: bigint): bigint;
|
|
5
|
+
static revToUint256(a: bigint): bigint;
|
|
6
|
+
static revToUint128(a: bigint): bigint;
|
|
7
|
+
static toUint160(y: bigint): bigint;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SafeCast = void 0;
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
|
+
class SafeCast {
|
|
6
|
+
static toInt256(a) {
|
|
7
|
+
(0, utils_1._require)(a < 2n ** 255n, 'toInt256: a < 2n ** 255n');
|
|
8
|
+
return BigInt.asIntN(256, a);
|
|
9
|
+
}
|
|
10
|
+
static revToInt256(a) {
|
|
11
|
+
(0, utils_1._require)(a < 2n ** 255n, 'toInt256: a < 2n ** 255n');
|
|
12
|
+
return BigInt.asIntN(256, -a);
|
|
13
|
+
}
|
|
14
|
+
static revToInt128(a) {
|
|
15
|
+
(0, utils_1._require)(a < 2n ** 127n, 'toInt256: a < 2n ** 255n');
|
|
16
|
+
return BigInt.asIntN(128, -a);
|
|
17
|
+
}
|
|
18
|
+
static revToUint256(a) {
|
|
19
|
+
return BigInt.asUintN(256, -a);
|
|
20
|
+
}
|
|
21
|
+
static revToUint128(a) {
|
|
22
|
+
return BigInt.asUintN(128, -a);
|
|
23
|
+
}
|
|
24
|
+
static toUint160(y) {
|
|
25
|
+
(0, utils_1._require)(BigInt.asUintN(160, y) == y, 'toUint160 overflow');
|
|
26
|
+
return BigInt.asUintN(160, y);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SafeCast = SafeCast;
|
|
30
|
+
//# sourceMappingURL=SafeCast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SafeCast.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/SafeCast.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAE1C,MAAa,QAAQ;IACnB,MAAM,CAAC,QAAQ,CAAC,CAAS;QACvB,IAAA,gBAAQ,EAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,CAAS;QAC1B,IAAA,gBAAQ,EAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,CAAS;QAC1B,IAAA,gBAAQ,EAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,CAAS;QAC3B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,CAAS;QAC3B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,CAAS;QACxB,IAAA,gBAAQ,EAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;CACF;AA5BD,4BA4BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SqrtPriceMath {
|
|
2
|
+
static getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96: bigint, liquidity: bigint, amount: bigint, add: boolean): bigint;
|
|
3
|
+
static getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96: bigint, liquidity: bigint, amount: bigint, add: boolean): bigint;
|
|
4
|
+
static getNextSqrtPriceFromInput(sqrtPX96: bigint, liquidity: bigint, amountIn: bigint, zeroForOne: boolean): bigint;
|
|
5
|
+
static getNextSqrtPriceFromOutput(sqrtPX96: bigint, liquidity: bigint, amountOut: bigint, zeroForOne: boolean): bigint;
|
|
6
|
+
static getAmount0Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
|
|
7
|
+
static getAmount1Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
|
|
8
|
+
static _getAmount0DeltaO(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint): bigint;
|
|
9
|
+
static _getAmount1DeltaO(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint): bigint;
|
|
10
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqrtPriceMath = void 0;
|
|
4
|
+
const bigint_constants_1 = require("../../../bigint-constants");
|
|
5
|
+
const FixedPoint96_1 = require("./FixedPoint96");
|
|
6
|
+
const FullMath_1 = require("./FullMath");
|
|
7
|
+
const UnsafeMath_1 = require("./UnsafeMath");
|
|
8
|
+
const utils_1 = require("../../../utils");
|
|
9
|
+
class SqrtPriceMath {
|
|
10
|
+
static getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amount, add) {
|
|
11
|
+
if (amount === 0n)
|
|
12
|
+
return sqrtPX96;
|
|
13
|
+
const numerator1 = BigInt.asUintN(256, liquidity) << FixedPoint96_1.FixedPoint96.RESOLUTION;
|
|
14
|
+
const product = amount * sqrtPX96;
|
|
15
|
+
if (add) {
|
|
16
|
+
if (product / amount === sqrtPX96) {
|
|
17
|
+
const denominator = numerator1 + product;
|
|
18
|
+
if (denominator >= numerator1) {
|
|
19
|
+
return BigInt.asUintN(160, FullMath_1.FullMath.mulDivCeil(numerator1, sqrtPX96, denominator));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return BigInt.asUintN(160, UnsafeMath_1.UnsafeMath.divRoundingUp(numerator1, numerator1 / sqrtPX96 + amount));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
(0, utils_1._require)(product / amount === sqrtPX96 && numerator1 > product, '', { product, amount, sqrtPX96, numerator1 }, 'product / amount === sqrtPX96 && numerator1 > product');
|
|
26
|
+
const denominator = numerator1 - product;
|
|
27
|
+
return BigInt.asUintN(160, FullMath_1.FullMath.mulDivCeil(numerator1, sqrtPX96, denominator));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amount, add) {
|
|
31
|
+
if (add) {
|
|
32
|
+
const quotient = amount <= bigint_constants_1.BI_MAX_UINT160
|
|
33
|
+
? (amount << FixedPoint96_1.FixedPoint96.RESOLUTION) / liquidity
|
|
34
|
+
: FullMath_1.FullMath.mulDiv(amount, FixedPoint96_1.FixedPoint96.Q96, liquidity);
|
|
35
|
+
return BigInt.asUintN(160, BigInt.asUintN(256, sqrtPX96) + quotient);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const quotient = amount <= bigint_constants_1.BI_MAX_UINT160
|
|
39
|
+
? UnsafeMath_1.UnsafeMath.divRoundingUp(amount << FixedPoint96_1.FixedPoint96.RESOLUTION, liquidity)
|
|
40
|
+
: FullMath_1.FullMath.mulDivCeil(amount, FixedPoint96_1.FixedPoint96.Q96, liquidity);
|
|
41
|
+
(0, utils_1._require)(sqrtPX96 > quotient, '', { sqrtPX96, quotient }, 'sqrtPX96 > quotient');
|
|
42
|
+
return BigInt.asUintN(160, sqrtPX96 - quotient);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
static getNextSqrtPriceFromInput(sqrtPX96, liquidity, amountIn, zeroForOne) {
|
|
46
|
+
(0, utils_1._require)(sqrtPX96 > 0n, '', { sqrtPX96 }, 'sqrtPX96 > 0n');
|
|
47
|
+
(0, utils_1._require)(liquidity > 0n, '', { liquidity }, 'liquidity > 0n');
|
|
48
|
+
return zeroForOne
|
|
49
|
+
? SqrtPriceMath.getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true)
|
|
50
|
+
: SqrtPriceMath.getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true);
|
|
51
|
+
}
|
|
52
|
+
static getNextSqrtPriceFromOutput(sqrtPX96, liquidity, amountOut, zeroForOne) {
|
|
53
|
+
(0, utils_1._require)(sqrtPX96 > 0n, '', { sqrtPX96 }, 'sqrtPX96 > 0n');
|
|
54
|
+
(0, utils_1._require)(liquidity > 0n, '', { liquidity }, 'liquidity > 0n');
|
|
55
|
+
return zeroForOne
|
|
56
|
+
? SqrtPriceMath.getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false)
|
|
57
|
+
: SqrtPriceMath.getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false);
|
|
58
|
+
}
|
|
59
|
+
static getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
|
|
60
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
61
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
62
|
+
}
|
|
63
|
+
const numerator1 = BigInt.asUintN(256, liquidity) << FixedPoint96_1.FixedPoint96.RESOLUTION;
|
|
64
|
+
const numerator2 = sqrtRatioBX96 - sqrtRatioAX96;
|
|
65
|
+
(0, utils_1._require)(sqrtRatioAX96 > 0, '', { sqrtRatioAX96 }, 'sqrtRatioAX96 > 0');
|
|
66
|
+
return roundUp
|
|
67
|
+
? UnsafeMath_1.UnsafeMath.divRoundingUp(FullMath_1.FullMath.mulDivCeil(numerator1, numerator2, sqrtRatioBX96), sqrtRatioAX96)
|
|
68
|
+
: FullMath_1.FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96;
|
|
69
|
+
}
|
|
70
|
+
static getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
|
|
71
|
+
if (sqrtRatioAX96 > sqrtRatioBX96)
|
|
72
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
73
|
+
return roundUp
|
|
74
|
+
? FullMath_1.FullMath.mulDivCeil(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96_1.FixedPoint96.Q96)
|
|
75
|
+
: FullMath_1.FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96_1.FixedPoint96.Q96);
|
|
76
|
+
}
|
|
77
|
+
// Overloaded with different argument numbers
|
|
78
|
+
static _getAmount0DeltaO(sqrtRatioAX96, sqrtRatioBX96, liquidity) {
|
|
79
|
+
return liquidity < 0
|
|
80
|
+
? -BigInt.asIntN(256, SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, -liquidity), false))
|
|
81
|
+
: BigInt.asIntN(256, SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, liquidity), true));
|
|
82
|
+
}
|
|
83
|
+
// Overloaded with different argument numbers
|
|
84
|
+
static _getAmount1DeltaO(sqrtRatioAX96, sqrtRatioBX96, liquidity) {
|
|
85
|
+
return liquidity < 0
|
|
86
|
+
? -BigInt.asIntN(256, SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, -liquidity), false))
|
|
87
|
+
: BigInt.asIntN(256, SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, liquidity), true));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.SqrtPriceMath = SqrtPriceMath;
|
|
91
|
+
//# sourceMappingURL=SqrtPriceMath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqrtPriceMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/SqrtPriceMath.ts"],"names":[],"mappings":";;;AAAA,gEAA2D;AAC3D,iDAA8C;AAC9C,yCAAsC;AACtC,6CAA0C;AAC1C,0CAA0C;AAE1C,MAAa,aAAa;IACxB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H,CAAC,CAAC,MAAM,CAAC,MAAM,CACX,GAAG,EACH,aAAa,CAAC,eAAe,CAC3B,aAAa,EACb,aAAa,EACb,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,EAC9B,IAAI,CACL,CACF,CAAC;IACR,CAAC;CACF;AA3ND,sCA2NC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class SwapMath {
|
|
2
|
+
static computeSwapStep(liquidity: bigint, currentSqrtP: bigint, targetSqrtP: bigint, feeInFeeUnits: bigint, specifiedAmount: bigint, isExactInput: boolean, isToken0: boolean): {
|
|
3
|
+
usedAmount: bigint;
|
|
4
|
+
returnedAmount: bigint;
|
|
5
|
+
deltaL: bigint;
|
|
6
|
+
nextSqrtP: bigint;
|
|
7
|
+
};
|
|
8
|
+
static calcReachAmount(liquidity: bigint, currentSqrtP: bigint, targetSqrtP: bigint, feeInFeeUnits: bigint, isExactInput: boolean, isToken0: boolean): bigint;
|
|
9
|
+
static estimateIncrementalLiquidity(absDelta: bigint, liquidity: bigint, currentSqrtP: bigint, feeInFeeUnits: bigint, isExactInput: boolean, isToken0: boolean): bigint;
|
|
10
|
+
static calcIncrementalLiquidity(absDelta: bigint, liquidity: bigint, currentSqrtP: bigint, nextSqrtP: bigint, isExactInput: boolean, isToken0: boolean): bigint;
|
|
11
|
+
static calcFinalPrice(absDelta: bigint, liquidity: bigint, deltaL: bigint, currentSqrtP: bigint, isExactInput: boolean, isToken0: boolean): bigint;
|
|
12
|
+
static calcReturnedAmount(liquidity: bigint, currentSqrtP: bigint, nextSqrtP: bigint, deltaL: bigint, isExactInput: boolean, isToken0: boolean): bigint;
|
|
13
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapMath = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const FullMath_1 = require("./FullMath");
|
|
6
|
+
const QuadMath_1 = require("./QuadMath");
|
|
7
|
+
const SafeCast_1 = require("./SafeCast");
|
|
8
|
+
class SwapMath {
|
|
9
|
+
static computeSwapStep(liquidity, currentSqrtP, targetSqrtP, feeInFeeUnits, specifiedAmount, isExactInput, isToken0) {
|
|
10
|
+
let nextSqrtP = 0n;
|
|
11
|
+
let deltaL = 0n;
|
|
12
|
+
let returnedAmount = 0n;
|
|
13
|
+
let usedAmount = 0n;
|
|
14
|
+
if (currentSqrtP === targetSqrtP)
|
|
15
|
+
return {
|
|
16
|
+
usedAmount,
|
|
17
|
+
returnedAmount,
|
|
18
|
+
deltaL,
|
|
19
|
+
nextSqrtP: currentSqrtP,
|
|
20
|
+
};
|
|
21
|
+
usedAmount = this.calcReachAmount(liquidity, currentSqrtP, targetSqrtP, feeInFeeUnits, isExactInput, isToken0);
|
|
22
|
+
if ((isExactInput && usedAmount > specifiedAmount) ||
|
|
23
|
+
(!isExactInput && usedAmount <= specifiedAmount)) {
|
|
24
|
+
usedAmount = specifiedAmount;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
nextSqrtP = targetSqrtP;
|
|
28
|
+
}
|
|
29
|
+
let absDelta = usedAmount >= 0 ? usedAmount : SafeCast_1.SafeCast.revToUint256(usedAmount);
|
|
30
|
+
if (nextSqrtP == 0n) {
|
|
31
|
+
deltaL = this.estimateIncrementalLiquidity(absDelta, liquidity, currentSqrtP, feeInFeeUnits, isExactInput, isToken0);
|
|
32
|
+
nextSqrtP = SafeCast_1.SafeCast.toUint160(this.calcFinalPrice(absDelta, liquidity, deltaL, currentSqrtP, isExactInput, isToken0));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
deltaL = this.calcIncrementalLiquidity(absDelta, liquidity, currentSqrtP, nextSqrtP, isExactInput, isToken0);
|
|
36
|
+
}
|
|
37
|
+
returnedAmount = this.calcReturnedAmount(liquidity, currentSqrtP, nextSqrtP, deltaL, isExactInput, isToken0);
|
|
38
|
+
return {
|
|
39
|
+
usedAmount,
|
|
40
|
+
returnedAmount,
|
|
41
|
+
deltaL,
|
|
42
|
+
nextSqrtP: BigInt.asUintN(160, nextSqrtP),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static calcReachAmount(liquidity, currentSqrtP, targetSqrtP, feeInFeeUnits, isExactInput, isToken0) {
|
|
46
|
+
let reachAmount = 0n;
|
|
47
|
+
let absPriceDiff;
|
|
48
|
+
absPriceDiff =
|
|
49
|
+
currentSqrtP >= targetSqrtP
|
|
50
|
+
? currentSqrtP - targetSqrtP
|
|
51
|
+
: targetSqrtP - currentSqrtP;
|
|
52
|
+
if (isExactInput) {
|
|
53
|
+
if (isToken0) {
|
|
54
|
+
let denominator = constants_1.TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP;
|
|
55
|
+
let numerator = FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_FEE_UNITS * absPriceDiff, denominator);
|
|
56
|
+
reachAmount = SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivFloor(numerator, constants_1.TWO_POW_96, currentSqrtP));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
let denominator = constants_1.TWO_FEE_UNITS * currentSqrtP - feeInFeeUnits * targetSqrtP;
|
|
60
|
+
let numerator = FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_FEE_UNITS * absPriceDiff, denominator);
|
|
61
|
+
reachAmount = SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivFloor(numerator, currentSqrtP, constants_1.TWO_POW_96));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (isToken0) {
|
|
66
|
+
// numerator: (liquidity)(absPriceDiff)(2 * currentSqrtP - deltaL * (currentSqrtP + targetSqrtP))
|
|
67
|
+
// denominator: (currentSqrtP * targetSqrtP) * (2 * currentSqrtP - deltaL * targetSqrtP)
|
|
68
|
+
// overflow should not happen because the absPriceDiff is capped to ~5%
|
|
69
|
+
let denominator = constants_1.TWO_FEE_UNITS * currentSqrtP - feeInFeeUnits * targetSqrtP;
|
|
70
|
+
let numerator = denominator - feeInFeeUnits * currentSqrtP;
|
|
71
|
+
numerator = FullMath_1.FullMath.mulDivFloor(liquidity << 96n, numerator, denominator);
|
|
72
|
+
reachAmount = SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(numerator, absPriceDiff, currentSqrtP) /
|
|
73
|
+
targetSqrtP);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// numerator: liquidity * absPriceDiff * (TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * (targetSqrtP + currentSqrtP))
|
|
77
|
+
// denominator: (TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP)
|
|
78
|
+
// overflow should not happen because the absPriceDiff is capped to ~5%
|
|
79
|
+
let denominator = constants_1.TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP;
|
|
80
|
+
let numerator = denominator - feeInFeeUnits * targetSqrtP;
|
|
81
|
+
numerator = FullMath_1.FullMath.mulDivFloor(liquidity, numerator, denominator);
|
|
82
|
+
reachAmount = SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(numerator, absPriceDiff, constants_1.TWO_POW_96));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return reachAmount;
|
|
86
|
+
}
|
|
87
|
+
static estimateIncrementalLiquidity(absDelta, liquidity, currentSqrtP, feeInFeeUnits, isExactInput, isToken0) {
|
|
88
|
+
let deltaL = 0n;
|
|
89
|
+
if (isExactInput) {
|
|
90
|
+
if (isToken0) {
|
|
91
|
+
// deltaL = feeInFeeUnits * absDelta * currentSqrtP / 2
|
|
92
|
+
deltaL = FullMath_1.FullMath.mulDivFloor(currentSqrtP, absDelta * feeInFeeUnits, constants_1.TWO_FEE_UNITS << 96n);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// deltaL = feeInFeeUnits * absDelta * / (currentSqrtP * 2)
|
|
96
|
+
// Because nextSqrtP = (liquidity + absDelta / currentSqrtP) * currentSqrtP / (liquidity + deltaL)
|
|
97
|
+
// so we round up deltaL, to round down nextSqrtP
|
|
98
|
+
deltaL = FullMath_1.FullMath.mulDivFloor(constants_1.TWO_POW_96, absDelta * feeInFeeUnits, constants_1.TWO_FEE_UNITS * currentSqrtP);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// obtain the smaller root of the quadratic equation
|
|
103
|
+
// ax^2 - 2bx + c = 0 such that b > 0, and x denotes deltaL
|
|
104
|
+
let a = feeInFeeUnits;
|
|
105
|
+
let b = (constants_1.FEE_UNITS - feeInFeeUnits) * liquidity;
|
|
106
|
+
let c = feeInFeeUnits * liquidity * absDelta;
|
|
107
|
+
if (isToken0) {
|
|
108
|
+
// a = feeInFeeUnits
|
|
109
|
+
// b = (FEE_UNITS - feeInFeeUnits) * liquidity - FEE_UNITS * absDelta * currentSqrtP
|
|
110
|
+
// c = feeInFeeUnits * liquidity * absDelta * currentSqrtP
|
|
111
|
+
b -= FullMath_1.FullMath.mulDivFloor(constants_1.FEE_UNITS * absDelta, currentSqrtP, constants_1.TWO_POW_96);
|
|
112
|
+
c = FullMath_1.FullMath.mulDivFloor(c, currentSqrtP, constants_1.TWO_POW_96);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// a = feeInFeeUnits
|
|
116
|
+
// b = (FEE_UNITS - feeInFeeUnits) * liquidity - FEE_UNITS * absDelta / currentSqrtP
|
|
117
|
+
// c = liquidity * feeInFeeUnits * absDelta / currentSqrtP
|
|
118
|
+
b -= FullMath_1.FullMath.mulDivFloor(constants_1.FEE_UNITS * absDelta, constants_1.TWO_POW_96, currentSqrtP);
|
|
119
|
+
c = FullMath_1.FullMath.mulDivFloor(c, constants_1.TWO_POW_96, currentSqrtP);
|
|
120
|
+
}
|
|
121
|
+
deltaL = QuadMath_1.QuadMath.getSmallerRootOfQuadEqn(a, b, c);
|
|
122
|
+
}
|
|
123
|
+
return deltaL;
|
|
124
|
+
}
|
|
125
|
+
static calcIncrementalLiquidity(absDelta, liquidity, currentSqrtP, nextSqrtP, isExactInput, isToken0) {
|
|
126
|
+
let deltaL = 0n;
|
|
127
|
+
if (isToken0) {
|
|
128
|
+
let tmp1 = FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_POW_96, currentSqrtP);
|
|
129
|
+
let tmp2 = isExactInput ? tmp1 + absDelta : tmp1 - absDelta;
|
|
130
|
+
let tmp3 = FullMath_1.FullMath.mulDivFloor(nextSqrtP, tmp2, constants_1.TWO_POW_96);
|
|
131
|
+
deltaL = tmp3 > liquidity ? tmp3 - liquidity : 0n;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
let tmp1 = FullMath_1.FullMath.mulDivFloor(liquidity, currentSqrtP, constants_1.TWO_POW_96);
|
|
135
|
+
let tmp2 = isExactInput ? tmp1 + absDelta : tmp1 - absDelta;
|
|
136
|
+
let tmp3 = FullMath_1.FullMath.mulDivFloor(tmp2, constants_1.TWO_POW_96, nextSqrtP);
|
|
137
|
+
deltaL = tmp3 > liquidity ? tmp3 - liquidity : 0n;
|
|
138
|
+
}
|
|
139
|
+
return deltaL;
|
|
140
|
+
}
|
|
141
|
+
static calcFinalPrice(absDelta, liquidity, deltaL, currentSqrtP, isExactInput, isToken0) {
|
|
142
|
+
if (isToken0) {
|
|
143
|
+
let tmp = FullMath_1.FullMath.mulDivFloor(absDelta, currentSqrtP, constants_1.TWO_POW_96);
|
|
144
|
+
if (isExactInput) {
|
|
145
|
+
return FullMath_1.FullMath.mulDivCeil(liquidity + deltaL, currentSqrtP, liquidity + tmp);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return FullMath_1.FullMath.mulDivFloor(liquidity + deltaL, currentSqrtP, liquidity - tmp);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
let tmp = FullMath_1.FullMath.mulDivFloor(absDelta, constants_1.TWO_POW_96, currentSqrtP);
|
|
153
|
+
if (isExactInput) {
|
|
154
|
+
return FullMath_1.FullMath.mulDivFloor(liquidity + tmp, currentSqrtP, liquidity + deltaL);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return FullMath_1.FullMath.mulDivCeil(liquidity - tmp, currentSqrtP, liquidity + deltaL);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
static calcReturnedAmount(liquidity, currentSqrtP, nextSqrtP, deltaL, isExactInput, isToken0) {
|
|
162
|
+
let returnedAmount = 0n;
|
|
163
|
+
if (isToken0) {
|
|
164
|
+
if (isExactInput) {
|
|
165
|
+
returnedAmount =
|
|
166
|
+
SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(deltaL, nextSqrtP, constants_1.TWO_POW_96)) +
|
|
167
|
+
SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(liquidity, currentSqrtP - nextSqrtP, constants_1.TWO_POW_96));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
returnedAmount =
|
|
171
|
+
SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(deltaL, nextSqrtP, constants_1.TWO_POW_96)) +
|
|
172
|
+
SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(liquidity, nextSqrtP - currentSqrtP, constants_1.TWO_POW_96));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
returnedAmount =
|
|
177
|
+
SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(liquidity + deltaL, constants_1.TWO_POW_96, nextSqrtP)) +
|
|
178
|
+
SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_POW_96, currentSqrtP));
|
|
179
|
+
}
|
|
180
|
+
if (isExactInput && returnedAmount == 1n) {
|
|
181
|
+
// rounding make returnedAmount == 1
|
|
182
|
+
returnedAmount = 0n;
|
|
183
|
+
}
|
|
184
|
+
return returnedAmount;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.SwapMath = SwapMath;
|
|
188
|
+
//# sourceMappingURL=SwapMath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwapMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/SwapMath.ts"],"names":[],"mappings":";;;AAAA,4CAAoE;AACpE,yCAAsC;AACtC,yCAAsC;AACtC,yCAAsC;AAEtC,MAAa,QAAQ;IACnB,MAAM,CAAC,eAAe,CACpB,SAAiB,EACjB,YAAoB,EACpB,WAAmB,EACnB,aAAqB,EACrB,eAAuB,EACvB,YAAqB,EACrB,QAAiB;QAOjB,IAAI,SAAS,GAAG,EAAE,CAAC;QACnB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,cAAc,GAAG,EAAE,CAAC;QACxB,IAAI,UAAU,GAAG,EAAE,CAAC;QAEpB,IAAI,YAAY,KAAK,WAAW;YAC9B,OAAO;gBACL,UAAU;gBACV,cAAc;gBACd,MAAM;gBACN,SAAS,EAAE,YAAY;aACxB,CAAC;QAEJ,UAAU,GAAG,IAAI,CAAC,eAAe,CAC/B,SAAS,EACT,YAAY,EACZ,WAAW,EACX,aAAa,EACb,YAAY,EACZ,QAAQ,CACT,CAAC;QAEF,IACE,CAAC,YAAY,IAAI,UAAU,GAAG,eAAe,CAAC;YAC9C,CAAC,CAAC,YAAY,IAAI,UAAU,IAAI,eAAe,CAAC,EAChD;YACA,UAAU,GAAG,eAAe,CAAC;SAC9B;aAAM;YACL,SAAS,GAAG,WAAW,CAAC;SACzB;QAED,IAAI,QAAQ,GACV,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,mBAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QACnE,IAAI,SAAS,IAAI,EAAE,EAAE;Y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ACF,CAAC;aACL;iBAAM;gBACL,cAAc;oBACZ,mBAAQ,CAAC,QAAQ,CACf,mBAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,sBAAU,CAAC,CACnD;wBACD,mBAAQ,CAAC,QAAQ,CACf,mBAAQ,CAAC,UAAU,CACjB,SAAS,EACT,SAAS,GAAG,YAAY,EACxB,sBAAU,CACX,CACF,CAAC;aACL;SACF;aAAM;YACL,cAAc;gBACZ,mBAAQ,CAAC,QAAQ,CACf,mBAAQ,CAAC,UAAU,CAAC,SAAS,GAAG,MAAM,EAAE,sBAAU,EAAE,SAAS,CAAC,CAC/D;oBACD,mBAAQ,CAAC,WAAW,CAClB,mBAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,sBAAU,EAAE,YAAY,CAAC,CAC1D,CAAC;SACL;QAED,IAAI,YAAY,IAAI,cAAc,IAAI,EAAE,EAAE;YACxC,oCAAoC;YACpC,cAAc,GAAG,EAAE,CAAC;SACrB;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AA1VD,4BA0VC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NumberAsString } from '@paraswap/core';
|
|
2
|
+
import { LinkedlistData } from '../types';
|
|
3
|
+
export declare class LinkedList {
|
|
4
|
+
static remove(data: Record<NumberAsString, LinkedlistData>, removedValue: bigint): bigint;
|
|
5
|
+
static insert(data: Record<NumberAsString, LinkedlistData>, newValue: bigint, lowerValue: bigint, nextValue: bigint): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinkedList = void 0;
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
|
+
class LinkedList {
|
|
6
|
+
static remove(data, removedValue) {
|
|
7
|
+
(0, utils_1._require)(Number(removedValue) in data, 'non exist value');
|
|
8
|
+
let node = data[Number(removedValue)];
|
|
9
|
+
if (node.previous == removedValue)
|
|
10
|
+
return removedValue;
|
|
11
|
+
let ret = node.previous;
|
|
12
|
+
if (node.next == removedValue)
|
|
13
|
+
return ret;
|
|
14
|
+
data[Number(node.previous)].next = node.next;
|
|
15
|
+
data[Number(node.next)].previous = node.previous;
|
|
16
|
+
delete data[Number(removedValue)];
|
|
17
|
+
return ret;
|
|
18
|
+
}
|
|
19
|
+
static insert(data, newValue, lowerValue, nextValue) {
|
|
20
|
+
data[Number(newValue)] = {
|
|
21
|
+
previous: lowerValue,
|
|
22
|
+
next: nextValue,
|
|
23
|
+
};
|
|
24
|
+
if (!data[Number(nextValue)]) {
|
|
25
|
+
data[Number(nextValue)] = {
|
|
26
|
+
next: 0n,
|
|
27
|
+
previous: 0n,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (!data[Number(lowerValue)]) {
|
|
31
|
+
data[Number(lowerValue)] = {
|
|
32
|
+
next: 0n,
|
|
33
|
+
previous: 0n,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
data[Number(nextValue)].previous = newValue;
|
|
37
|
+
data[Number(lowerValue)].next = newValue;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.LinkedList = LinkedList;
|
|
41
|
+
//# sourceMappingURL=TickLinkedList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TickLinkedList.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/TickLinkedList.ts"],"names":[],"mappings":";;;AAEA,0CAA0C;AAG1C,MAAa,UAAU;IACrB,MAAM,CAAC,MAAM,CACX,IAA4C,EAC5C,YAAoB;QAEpB,IAAA,gBAAQ,EAAC,MAAM,CAAC,YAAY,CAAC,IAAI,IAAI,EAAE,iBAAiB,CAAC,CAAC;QAC1D,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;QAEtC,IAAI,IAAI,CAAC,QAAQ,IAAI,YAAY;YAAE,OAAO,YA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
export declare class TickMath {
|
|
2
|
+
static readonly MIN_TICK = -887272n;
|
|
3
|
+
static readonly MAX_TICK: bigint;
|
|
4
|
+
static readonly MIN_SQRT_RATIO = 4295128739n;
|
|
5
|
+
static readonly MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342n;
|
|
6
|
+
static getSqrtRatioAtTick(tick: bigint): bigint;
|
|
7
|
+
static getTickAtSqrtRatio(sqrtPriceX96: bigint): bigint;
|
|
8
|
+
static getMaxNumberTicks(_tickDistance: bigint): bigint;
|
|
9
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TickMath = void 0;
|
|
4
|
+
const bigint_constants_1 = require("../../../bigint-constants");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const utils_2 = require("./utils");
|
|
7
|
+
class TickMath {
|
|
8
|
+
static getSqrtRatioAtTick(tick) {
|
|
9
|
+
const absTick = tick < 0n
|
|
10
|
+
? BigInt.asUintN(256, -BigInt.asIntN(256, tick))
|
|
11
|
+
: BigInt.asUintN(256, BigInt.asIntN(256, tick));
|
|
12
|
+
(0, utils_1._require)(absTick <= BigInt.asUintN(256, TickMath.MAX_TICK), 'T', { absTick }, 'absTick <= BigInt.asUintN(256, TickMath.MAX_TICK)');
|
|
13
|
+
let ratio = (absTick & 0x1n) !== 0n
|
|
14
|
+
? 0xfffcb933bd6fad37aa2d162d1a594001n
|
|
15
|
+
: 0x100000000000000000000000000000000n;
|
|
16
|
+
if ((absTick & 0x2n) !== 0n)
|
|
17
|
+
ratio = (ratio * 0xfff97272373d413259a46990580e213an) >> 128n;
|
|
18
|
+
if ((absTick & 0x4n) !== 0n)
|
|
19
|
+
ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdccn) >> 128n;
|
|
20
|
+
if ((absTick & 0x8n) !== 0n)
|
|
21
|
+
ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0n) >> 128n;
|
|
22
|
+
if ((absTick & 0x10n) !== 0n)
|
|
23
|
+
ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644n) >> 128n;
|
|
24
|
+
if ((absTick & 0x20n) !== 0n)
|
|
25
|
+
ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0n) >> 128n;
|
|
26
|
+
if ((absTick & 0x40n) !== 0n)
|
|
27
|
+
ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861n) >> 128n;
|
|
28
|
+
if ((absTick & 0x80n) !== 0n)
|
|
29
|
+
ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053n) >> 128n;
|
|
30
|
+
if ((absTick & 0x100n) !== 0n)
|
|
31
|
+
ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4n) >> 128n;
|
|
32
|
+
if ((absTick & 0x200n) !== 0n)
|
|
33
|
+
ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54n) >> 128n;
|
|
34
|
+
if ((absTick & 0x400n) !== 0n)
|
|
35
|
+
ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3n) >> 128n;
|
|
36
|
+
if ((absTick & 0x800n) !== 0n)
|
|
37
|
+
ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9n) >> 128n;
|
|
38
|
+
if ((absTick & 0x1000n) !== 0n)
|
|
39
|
+
ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825n) >> 128n;
|
|
40
|
+
if ((absTick & 0x2000n) !== 0n)
|
|
41
|
+
ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5n) >> 128n;
|
|
42
|
+
if ((absTick & 0x4000n) !== 0n)
|
|
43
|
+
ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7n) >> 128n;
|
|
44
|
+
if ((absTick & 0x8000n) !== 0n)
|
|
45
|
+
ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6n) >> 128n;
|
|
46
|
+
if ((absTick & 0x10000n) !== 0n)
|
|
47
|
+
ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9n) >> 128n;
|
|
48
|
+
if ((absTick & 0x20000n) !== 0n)
|
|
49
|
+
ratio = (ratio * 0x5d6af8dedb81196699c329225ee604n) >> 128n;
|
|
50
|
+
if ((absTick & 0x40000n) !== 0n)
|
|
51
|
+
ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98n) >> 128n;
|
|
52
|
+
if ((absTick & 0x80000n) !== 0n)
|
|
53
|
+
ratio = (ratio * 0x48a170391f7dc42444e8fa2n) >> 128n;
|
|
54
|
+
if (tick > 0)
|
|
55
|
+
ratio = bigint_constants_1.BI_MAX_UINT256 / ratio;
|
|
56
|
+
return BigInt.asUintN(160, (ratio >> 32n) + (ratio % (1n << 32n) == 0n ? 0n : 1n));
|
|
57
|
+
}
|
|
58
|
+
static getTickAtSqrtRatio(sqrtPriceX96) {
|
|
59
|
+
(0, utils_1._require)(sqrtPriceX96 >= TickMath.MIN_SQRT_RATIO &&
|
|
60
|
+
sqrtPriceX96 < TickMath.MAX_SQRT_RATIO, 'R', { sqrtPriceX96 }, 'sqrtPriceX96 >= TickMath.MIN_SQRT_RATIO && sqrtPriceX96 < TickMath.MAX_SQRT_RATIO');
|
|
61
|
+
let ratio = BigInt.asUintN(256, sqrtPriceX96) << 32n;
|
|
62
|
+
let r = ratio;
|
|
63
|
+
let msb = 0n;
|
|
64
|
+
let f = (0, utils_2._gt)(r, 0xffffffffffffffffffffffffffffffffn) << 7n;
|
|
65
|
+
msb = msb | f;
|
|
66
|
+
r = r >> f;
|
|
67
|
+
f = (0, utils_2._gt)(r, 0xffffffffffffffffn) << 6n;
|
|
68
|
+
msb = msb | f;
|
|
69
|
+
r = r >> f;
|
|
70
|
+
f = (0, utils_2._gt)(r, 0xffffffffn) << 5n;
|
|
71
|
+
msb = msb | f;
|
|
72
|
+
r = r >> f;
|
|
73
|
+
f = (0, utils_2._gt)(r, 0xffffn) << 4n;
|
|
74
|
+
msb = msb | f;
|
|
75
|
+
r = r >> f;
|
|
76
|
+
f = (0, utils_2._gt)(r, 0xffn) << 3n;
|
|
77
|
+
msb = msb | f;
|
|
78
|
+
r = r >> f;
|
|
79
|
+
f = (0, utils_2._gt)(r, 0xfn) << 2n;
|
|
80
|
+
msb = msb | f;
|
|
81
|
+
r = r >> f;
|
|
82
|
+
f = (0, utils_2._gt)(r, 0x3n) << 1n;
|
|
83
|
+
msb = msb | f;
|
|
84
|
+
r = r >> f;
|
|
85
|
+
f = (0, utils_2._gt)(r, 0x1n);
|
|
86
|
+
msb = msb | f;
|
|
87
|
+
if (msb >= 128n)
|
|
88
|
+
r = ratio >> (msb - 127n);
|
|
89
|
+
else
|
|
90
|
+
r = ratio << (127n - msb);
|
|
91
|
+
let log_2 = (BigInt.asIntN(256, msb) - 128n) << 64n;
|
|
92
|
+
r = (r * r) >> 127n;
|
|
93
|
+
f = r >> 128n;
|
|
94
|
+
log_2 = log_2 | (f << 63n);
|
|
95
|
+
r = r >> f;
|
|
96
|
+
r = (r * r) >> 127n;
|
|
97
|
+
f = r >> 128n;
|
|
98
|
+
log_2 = log_2 | (f << 62n);
|
|
99
|
+
r = r >> f;
|
|
100
|
+
r = (r * r) >> 127n;
|
|
101
|
+
f = r >> 128n;
|
|
102
|
+
log_2 = log_2 | (f << 61n);
|
|
103
|
+
r = r >> f;
|
|
104
|
+
r = (r * r) >> 127n;
|
|
105
|
+
f = r >> 128n;
|
|
106
|
+
log_2 = log_2 | (f << 60n);
|
|
107
|
+
r = r >> f;
|
|
108
|
+
r = (r * r) >> 127n;
|
|
109
|
+
f = r >> 128n;
|
|
110
|
+
log_2 = log_2 | (f << 59n);
|
|
111
|
+
r = r >> f;
|
|
112
|
+
r = (r * r) >> 127n;
|
|
113
|
+
f = r >> 128n;
|
|
114
|
+
log_2 = log_2 | (f << 58n);
|
|
115
|
+
r = r >> f;
|
|
116
|
+
r = (r * r) >> 127n;
|
|
117
|
+
f = r >> 128n;
|
|
118
|
+
log_2 = log_2 | (f << 57n);
|
|
119
|
+
r = r >> f;
|
|
120
|
+
r = (r * r) >> 127n;
|
|
121
|
+
f = r >> 128n;
|
|
122
|
+
log_2 = log_2 | (f << 56n);
|
|
123
|
+
r = r >> f;
|
|
124
|
+
r = (r * r) >> 127n;
|
|
125
|
+
f = r >> 128n;
|
|
126
|
+
log_2 = log_2 | (f << 55n);
|
|
127
|
+
r = r >> f;
|
|
128
|
+
r = (r * r) >> 127n;
|
|
129
|
+
f = r >> 128n;
|
|
130
|
+
log_2 = log_2 | (f << 54n);
|
|
131
|
+
r = r >> f;
|
|
132
|
+
r = (r * r) >> 127n;
|
|
133
|
+
f = r >> 128n;
|
|
134
|
+
log_2 = log_2 | (f << 53n);
|
|
135
|
+
r = r >> f;
|
|
136
|
+
r = (r * r) >> 127n;
|
|
137
|
+
f = r >> 128n;
|
|
138
|
+
log_2 = log_2 | (f << 52n);
|
|
139
|
+
r = r >> f;
|
|
140
|
+
r = (r * r) >> 127n;
|
|
141
|
+
f = r >> 128n;
|
|
142
|
+
log_2 = log_2 | (f << 51n);
|
|
143
|
+
r = r >> f;
|
|
144
|
+
r = (r * r) >> 127n;
|
|
145
|
+
f = r >> 128n;
|
|
146
|
+
log_2 = log_2 | (f << 50n);
|
|
147
|
+
const log_sqrt10001 = log_2 * 255738958999603826347141n; // 128.128 number
|
|
148
|
+
const tickLow = BigInt.asIntN(24, (log_sqrt10001 - 3402992956809132418596140100660247210n) >> 128n);
|
|
149
|
+
const tickHi = BigInt.asIntN(24, (log_sqrt10001 + 291339464771989622907027621153398088495n) >> 128n);
|
|
150
|
+
return tickLow === tickHi
|
|
151
|
+
? tickLow
|
|
152
|
+
: TickMath.getSqrtRatioAtTick(tickHi) <= sqrtPriceX96
|
|
153
|
+
? tickHi
|
|
154
|
+
: tickLow;
|
|
155
|
+
}
|
|
156
|
+
static getMaxNumberTicks(_tickDistance) {
|
|
157
|
+
return BigInt.asUintN(24, TickMath.MAX_TICK / _tickDistance) << 1n;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.TickMath = TickMath;
|
|
161
|
+
TickMath.MIN_TICK = -887272n;
|
|
162
|
+
TickMath.MAX_TICK = -TickMath.MIN_TICK;
|
|
163
|
+
TickMath.MIN_SQRT_RATIO = 4295128739n;
|
|
164
|
+
TickMath.MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342n;
|
|
165
|
+
//# sourceMappingURL=TickMath.js.map
|