@paraswap/dex-lib 2.42.4-baseswap → 2.42.4-baseswap.2

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.
Files changed (33) hide show
  1. package/build/dex/index.js +0 -2
  2. package/build/dex/index.js.map +1 -1
  3. package/build/dex/uniswap-v3/config.js +14 -0
  4. package/build/dex/uniswap-v3/config.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/dex/index.ts +0 -2
  7. package/src/dex/uniswap-v3/config.ts +14 -0
  8. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +24 -0
  9. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +375 -0
  10. package/src/dex/baseswap-v3/baseswap-v3-e2e.test.ts +0 -129
  11. package/src/dex/baseswap-v3/baseswap-v3-events.test.ts +0 -141
  12. package/src/dex/baseswap-v3/baseswap-v3-factory.ts +0 -73
  13. package/src/dex/baseswap-v3/baseswap-v3-integration.test.ts +0 -472
  14. package/src/dex/baseswap-v3/baseswap-v3-pool.ts +0 -519
  15. package/src/dex/baseswap-v3/baseswap-v3.ts +0 -1243
  16. package/src/dex/baseswap-v3/config.ts +0 -53
  17. package/src/dex/baseswap-v3/constants.ts +0 -41
  18. package/src/dex/baseswap-v3/contract-math/BitMath.ts +0 -90
  19. package/src/dex/baseswap-v3/contract-math/FixedPoint128.ts +0 -3
  20. package/src/dex/baseswap-v3/contract-math/FixedPoint96.ts +0 -4
  21. package/src/dex/baseswap-v3/contract-math/FullMath.ts +0 -30
  22. package/src/dex/baseswap-v3/contract-math/LiquidityMath.ts +0 -17
  23. package/src/dex/baseswap-v3/contract-math/Oracle.ts +0 -226
  24. package/src/dex/baseswap-v3/contract-math/SqrtPriceMath.ts +0 -226
  25. package/src/dex/baseswap-v3/contract-math/SwapMath.ts +0 -139
  26. package/src/dex/baseswap-v3/contract-math/Tick.ts +0 -82
  27. package/src/dex/baseswap-v3/contract-math/TickBitMap.ts +0 -123
  28. package/src/dex/baseswap-v3/contract-math/TickMath.ts +0 -211
  29. package/src/dex/baseswap-v3/contract-math/UnsafeMath.ts +0 -5
  30. package/src/dex/baseswap-v3/contract-math/uniswap-v3-math.ts +0 -666
  31. package/src/dex/baseswap-v3/contract-math/utils.ts +0 -55
  32. package/src/dex/baseswap-v3/types.ts +0 -191
  33. package/src/dex/baseswap-v3/utils.ts +0 -83
@@ -1,139 +0,0 @@
1
- import { BI_POWS } from '../../../bigint-constants';
2
- import { FullMath } from './FullMath';
3
- import { SqrtPriceMath } from './SqrtPriceMath';
4
-
5
- export class SwapMath {
6
- static computeSwapStep(
7
- sqrtRatioCurrentX96: bigint,
8
- sqrtRatioTargetX96: bigint,
9
- liquidity: bigint,
10
- amountRemaining: bigint,
11
- feePips: bigint,
12
- ): {
13
- sqrtRatioNextX96: bigint;
14
- amountIn: bigint;
15
- amountOut: bigint;
16
- feeAmount: bigint;
17
- } {
18
- const zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96;
19
- const exactIn = amountRemaining >= 0n;
20
-
21
- let sqrtRatioNextX96 = 0n;
22
- let amountIn = 0n;
23
- let amountOut = 0n;
24
- let feeAmount = 0n;
25
-
26
- if (exactIn) {
27
- const amountRemainingLessFee = FullMath.mulDiv(
28
- BigInt.asUintN(256, amountRemaining),
29
- BI_POWS[6] - feePips,
30
- BI_POWS[6],
31
- );
32
- amountIn = zeroForOne
33
- ? SqrtPriceMath.getAmount0Delta(
34
- sqrtRatioTargetX96,
35
- sqrtRatioCurrentX96,
36
- liquidity,
37
- true,
38
- )
39
- : SqrtPriceMath.getAmount1Delta(
40
- sqrtRatioCurrentX96,
41
- sqrtRatioTargetX96,
42
- liquidity,
43
- true,
44
- );
45
- if (amountRemainingLessFee >= amountIn)
46
- sqrtRatioNextX96 = sqrtRatioTargetX96;
47
- else
48
- sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromInput(
49
- sqrtRatioCurrentX96,
50
- liquidity,
51
- amountRemainingLessFee,
52
- zeroForOne,
53
- );
54
- } else {
55
- amountOut = zeroForOne
56
- ? SqrtPriceMath.getAmount1Delta(
57
- sqrtRatioTargetX96,
58
- sqrtRatioCurrentX96,
59
- liquidity,
60
- false,
61
- )
62
- : SqrtPriceMath.getAmount0Delta(
63
- sqrtRatioCurrentX96,
64
- sqrtRatioTargetX96,
65
- liquidity,
66
- false,
67
- );
68
- if (BigInt.asUintN(256, -amountRemaining) >= amountOut)
69
- sqrtRatioNextX96 = sqrtRatioTargetX96;
70
- else
71
- sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromOutput(
72
- sqrtRatioCurrentX96,
73
- liquidity,
74
- BigInt.asUintN(256, -amountRemaining),
75
- zeroForOne,
76
- );
77
- }
78
-
79
- const max = sqrtRatioTargetX96 == sqrtRatioNextX96;
80
-
81
- if (zeroForOne) {
82
- amountIn =
83
- max && exactIn
84
- ? amountIn
85
- : SqrtPriceMath.getAmount0Delta(
86
- sqrtRatioNextX96,
87
- sqrtRatioCurrentX96,
88
- liquidity,
89
- true,
90
- );
91
- amountOut =
92
- max && !exactIn
93
- ? amountOut
94
- : SqrtPriceMath.getAmount1Delta(
95
- sqrtRatioNextX96,
96
- sqrtRatioCurrentX96,
97
- liquidity,
98
- false,
99
- );
100
- } else {
101
- amountIn =
102
- max && exactIn
103
- ? amountIn
104
- : SqrtPriceMath.getAmount1Delta(
105
- sqrtRatioCurrentX96,
106
- sqrtRatioNextX96,
107
- liquidity,
108
- true,
109
- );
110
- amountOut =
111
- max && !exactIn
112
- ? amountOut
113
- : SqrtPriceMath.getAmount0Delta(
114
- sqrtRatioCurrentX96,
115
- sqrtRatioNextX96,
116
- liquidity,
117
- false,
118
- );
119
- }
120
-
121
- // cap the output amount to not exceed the remaining output amount
122
- if (!exactIn && amountOut > BigInt.asUintN(256, -amountRemaining)) {
123
- amountOut = BigInt.asUintN(256, -amountRemaining);
124
- }
125
-
126
- if (exactIn && sqrtRatioNextX96 != sqrtRatioTargetX96) {
127
- // we didn't reach the target, so take the remainder of the maximum input as fee
128
- feeAmount = BigInt.asUintN(256, amountRemaining) - amountIn;
129
- } else {
130
- feeAmount = FullMath.mulDivRoundingUp(
131
- amountIn,
132
- feePips,
133
- BI_POWS[6] - feePips,
134
- );
135
- }
136
-
137
- return { sqrtRatioNextX96, amountIn, amountOut, feeAmount };
138
- }
139
- }
@@ -1,82 +0,0 @@
1
- import { PoolState, TickInfo } from '../types';
2
- import { LiquidityMath } from './LiquidityMath';
3
- import { _require } from '../../../utils';
4
- import { NumberAsString } from '@paraswap/core';
5
- import { ZERO_TICK_INFO } from '../constants';
6
-
7
- export class Tick {
8
- static update(
9
- state: Pick<PoolState, 'ticks'>,
10
- tick: bigint,
11
- tickCurrent: bigint,
12
- liquidityDelta: bigint,
13
- secondsPerLiquidityCumulativeX128: bigint,
14
- tickCumulative: bigint,
15
- time: bigint,
16
- upper: boolean,
17
- maxLiquidity: bigint,
18
- ): boolean {
19
- let info = state.ticks[Number(tick)];
20
-
21
- if (info === undefined) {
22
- info = { ...ZERO_TICK_INFO };
23
- state.ticks[Number(tick)] = info;
24
- }
25
-
26
- const liquidityGrossBefore = info.liquidityGross;
27
- const liquidityGrossAfter = LiquidityMath.addDelta(
28
- liquidityGrossBefore,
29
- liquidityDelta,
30
- );
31
-
32
- _require(
33
- liquidityGrossAfter <= maxLiquidity,
34
- 'LO',
35
- { liquidityGrossAfter, maxLiquidity },
36
- 'liquidityGrossAfter <= maxLiquidity',
37
- );
38
-
39
- const flipped = (liquidityGrossAfter == 0n) != (liquidityGrossBefore == 0n);
40
-
41
- if (liquidityGrossBefore == 0n) {
42
- if (tick <= tickCurrent) {
43
- info.secondsPerLiquidityOutsideX128 = secondsPerLiquidityCumulativeX128;
44
- info.tickCumulativeOutside = tickCumulative;
45
- info.secondsOutside = time;
46
- }
47
- info.initialized = true;
48
- }
49
-
50
- info.liquidityGross = liquidityGrossAfter;
51
-
52
- info.liquidityNet = upper
53
- ? BigInt.asIntN(
54
- 128,
55
- BigInt.asIntN(256, info.liquidityNet) - liquidityDelta,
56
- )
57
- : BigInt.asIntN(
58
- 128,
59
- BigInt.asIntN(256, info.liquidityNet) + liquidityDelta,
60
- );
61
- return flipped;
62
- }
63
-
64
- static clear(state: Pick<PoolState, 'ticks'>, tick: bigint) {
65
- delete state.ticks[Number(tick)];
66
- }
67
-
68
- static cross(
69
- ticks: Record<NumberAsString, TickInfo>,
70
- tick: bigint,
71
- secondsPerLiquidityCumulativeX128: bigint,
72
- tickCumulative: bigint,
73
- time: bigint,
74
- ): bigint {
75
- const info = ticks[Number(tick)];
76
- info.secondsPerLiquidityOutsideX128 =
77
- secondsPerLiquidityCumulativeX128 - info.secondsPerLiquidityOutsideX128;
78
- info.tickCumulativeOutside = tickCumulative - info.tickCumulativeOutside;
79
- info.secondsOutside = time - info.secondsOutside;
80
- return info.liquidityNet;
81
- }
82
- }
@@ -1,123 +0,0 @@
1
- import { BI_MAX_UINT8 } from '../../../bigint-constants';
2
- import { PoolState } from '../types';
3
- import { BitMath } from './BitMath';
4
- import { _require } from '../../../utils';
5
- import { DeepReadonly } from 'ts-essentials';
6
- import {
7
- OUT_OF_RANGE_ERROR_POSTFIX,
8
- TICK_BITMAP_BUFFER,
9
- TICK_BITMAP_TO_USE,
10
- } from '../constants';
11
-
12
- function isWordPosOut(
13
- wordPos: bigint,
14
- startTickBitmap: bigint,
15
- // For pricing we use wider range to check price impact. If function called from event
16
- // it must always be within buffer
17
- isPriceQuery: boolean,
18
- ) {
19
- let lowerTickBitmapLimit;
20
- let upperTickBitmapLimit;
21
-
22
- if (isPriceQuery) {
23
- lowerTickBitmapLimit =
24
- startTickBitmap - (TICK_BITMAP_BUFFER + TICK_BITMAP_TO_USE);
25
- upperTickBitmapLimit =
26
- startTickBitmap + (TICK_BITMAP_BUFFER + TICK_BITMAP_TO_USE);
27
- } else {
28
- lowerTickBitmapLimit = startTickBitmap - TICK_BITMAP_BUFFER;
29
- upperTickBitmapLimit = startTickBitmap + TICK_BITMAP_BUFFER;
30
- }
31
-
32
- _require(
33
- wordPos >= lowerTickBitmapLimit && wordPos <= upperTickBitmapLimit,
34
- `wordPos is out of safe state tickBitmap request range: ${OUT_OF_RANGE_ERROR_POSTFIX}`,
35
- { wordPos },
36
- `wordPos >= LOWER_TICK_REQUEST_LIMIT && wordPos <= UPPER_TICK_REQUEST_LIMIT`,
37
- );
38
- }
39
-
40
- export class TickBitMap {
41
- static position(tick: bigint): [bigint, bigint] {
42
- return [BigInt.asIntN(16, tick >> 8n), BigInt.asUintN(8, tick % 256n)];
43
- }
44
-
45
- static flipTick(
46
- state: Pick<PoolState, 'startTickBitmap' | 'tickBitmap'>,
47
- tick: bigint,
48
- tickSpacing: bigint,
49
- ) {
50
- _require(
51
- tick % tickSpacing === 0n,
52
- '',
53
- { tick, tickSpacing },
54
- 'tick % tickSpacing == 0n,',
55
- );
56
- const [wordPos, bitPos] = TickBitMap.position(tick / tickSpacing);
57
- const mask = 1n << bitPos;
58
-
59
- // flipTick is used only in _updatePosition which is always state changing event
60
- // Therefore it is never used in price query
61
- isWordPosOut(wordPos, state.startTickBitmap, false);
62
-
63
- const stringWordPos = wordPos.toString();
64
- if (state.tickBitmap[stringWordPos] === undefined) {
65
- state.tickBitmap[stringWordPos] = 0n;
66
- }
67
-
68
- state.tickBitmap[stringWordPos] ^= mask;
69
- }
70
-
71
- static nextInitializedTickWithinOneWord(
72
- state: DeepReadonly<Pick<PoolState, 'startTickBitmap' | 'tickBitmap'>>,
73
- tick: bigint,
74
- tickSpacing: bigint,
75
- lte: boolean,
76
- isPriceQuery: boolean,
77
- ): [bigint, boolean] {
78
- let compressed = tick / tickSpacing;
79
- if (tick < 0n && tick % tickSpacing != 0n) compressed--;
80
-
81
- let next = 0n;
82
- let initialized = false;
83
-
84
- if (lte) {
85
- const [wordPos, bitPos] = TickBitMap.position(compressed);
86
- const mask = (1n << bitPos) - 1n + (1n << bitPos);
87
-
88
- isWordPosOut(wordPos, state.startTickBitmap, isPriceQuery);
89
- let tickBitmapValue = state.tickBitmap[wordPos.toString()];
90
- tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
91
-
92
- const masked = tickBitmapValue & mask;
93
-
94
- initialized = masked != 0n;
95
- next = initialized
96
- ? (compressed -
97
- BigInt.asIntN(24, bitPos - BitMath.mostSignificantBit(masked))) *
98
- tickSpacing
99
- : (compressed - BigInt.asIntN(24, bitPos)) * tickSpacing;
100
- } else {
101
- // start from the word of the next tick, since the current tick state doesn't matter
102
- const [wordPos, bitPos] = TickBitMap.position(compressed + 1n);
103
- const mask = ~((1n << bitPos) - 1n);
104
-
105
- isWordPosOut(wordPos, state.startTickBitmap, isPriceQuery);
106
- let tickBitmapValue = state.tickBitmap[wordPos.toString()];
107
- tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
108
-
109
- const masked = tickBitmapValue & mask;
110
-
111
- initialized = masked != 0n;
112
- next = initialized
113
- ? (compressed +
114
- 1n +
115
- BigInt.asIntN(24, BitMath.leastSignificantBit(masked) - bitPos)) *
116
- tickSpacing
117
- : (compressed + 1n + BigInt.asIntN(24, BI_MAX_UINT8 - bitPos)) *
118
- tickSpacing;
119
- }
120
-
121
- return [next, initialized];
122
- }
123
- }
@@ -1,211 +0,0 @@
1
- import { gt } from 'lodash';
2
- import { BI_MAX_UINT256 } from '../../../bigint-constants';
3
- import { _gt } from './utils';
4
- import { _require } from '../../../utils';
5
-
6
- export class TickMath {
7
- static readonly MIN_TICK = -887272n;
8
- static readonly MAX_TICK = -TickMath.MIN_TICK;
9
- static readonly MIN_SQRT_RATIO = 4295128739n;
10
- static readonly MAX_SQRT_RATIO =
11
- 1461446703485210103287273052203988822378723970342n;
12
-
13
- static getSqrtRatioAtTick(tick: bigint): bigint {
14
- const absTick =
15
- tick < 0n
16
- ? BigInt.asUintN(256, -BigInt.asIntN(256, tick))
17
- : BigInt.asUintN(256, BigInt.asIntN(256, tick));
18
- _require(
19
- absTick <= BigInt.asUintN(256, TickMath.MAX_TICK),
20
- 'T',
21
- { absTick },
22
- 'absTick <= BigInt.asUintN(256, TickMath.MAX_TICK)',
23
- );
24
-
25
- let ratio =
26
- (absTick & 0x1n) !== 0n
27
- ? 0xfffcb933bd6fad37aa2d162d1a594001n
28
- : 0x100000000000000000000000000000000n;
29
- if ((absTick & 0x2n) !== 0n)
30
- ratio = (ratio * 0xfff97272373d413259a46990580e213an) >> 128n;
31
- if ((absTick & 0x4n) !== 0n)
32
- ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdccn) >> 128n;
33
- if ((absTick & 0x8n) !== 0n)
34
- ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0n) >> 128n;
35
- if ((absTick & 0x10n) !== 0n)
36
- ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644n) >> 128n;
37
- if ((absTick & 0x20n) !== 0n)
38
- ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0n) >> 128n;
39
- if ((absTick & 0x40n) !== 0n)
40
- ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861n) >> 128n;
41
- if ((absTick & 0x80n) !== 0n)
42
- ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053n) >> 128n;
43
- if ((absTick & 0x100n) !== 0n)
44
- ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4n) >> 128n;
45
- if ((absTick & 0x200n) !== 0n)
46
- ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54n) >> 128n;
47
- if ((absTick & 0x400n) !== 0n)
48
- ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3n) >> 128n;
49
- if ((absTick & 0x800n) !== 0n)
50
- ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9n) >> 128n;
51
- if ((absTick & 0x1000n) !== 0n)
52
- ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825n) >> 128n;
53
- if ((absTick & 0x2000n) !== 0n)
54
- ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5n) >> 128n;
55
- if ((absTick & 0x4000n) !== 0n)
56
- ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7n) >> 128n;
57
- if ((absTick & 0x8000n) !== 0n)
58
- ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6n) >> 128n;
59
- if ((absTick & 0x10000n) !== 0n)
60
- ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9n) >> 128n;
61
- if ((absTick & 0x20000n) !== 0n)
62
- ratio = (ratio * 0x5d6af8dedb81196699c329225ee604n) >> 128n;
63
- if ((absTick & 0x40000n) !== 0n)
64
- ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98n) >> 128n;
65
- if ((absTick & 0x80000n) !== 0n)
66
- ratio = (ratio * 0x48a170391f7dc42444e8fa2n) >> 128n;
67
-
68
- if (tick > 0) ratio = BI_MAX_UINT256 / ratio;
69
- return BigInt.asUintN(
70
- 160,
71
- (ratio >> 32n) + (ratio % (1n << 32n) == 0n ? 0n : 1n),
72
- );
73
- }
74
-
75
- static getTickAtSqrtRatio(sqrtPriceX96: bigint): bigint {
76
- _require(
77
- sqrtPriceX96 >= TickMath.MIN_SQRT_RATIO &&
78
- sqrtPriceX96 < TickMath.MAX_SQRT_RATIO,
79
- 'R',
80
- { sqrtPriceX96 },
81
- 'sqrtPriceX96 >= TickMath.MIN_SQRT_RATIO && sqrtPriceX96 < TickMath.MAX_SQRT_RATIO',
82
- );
83
-
84
- let ratio = BigInt.asUintN(256, sqrtPriceX96) << 32n;
85
-
86
- let r = ratio;
87
- let msb = 0n;
88
-
89
- let f = _gt(r, 0xffffffffffffffffffffffffffffffffn) << 7n;
90
- msb = msb | f;
91
- r = r >> f;
92
-
93
- f = _gt(r, 0xffffffffffffffffn) << 6n;
94
- msb = msb | f;
95
- r = r >> f;
96
-
97
- f = _gt(r, 0xffffffffn) << 5n;
98
- msb = msb | f;
99
- r = r >> f;
100
-
101
- f = _gt(r, 0xffffn) << 4n;
102
- msb = msb | f;
103
- r = r >> f;
104
-
105
- f = _gt(r, 0xffn) << 3n;
106
- msb = msb | f;
107
- r = r >> f;
108
-
109
- f = _gt(r, 0xfn) << 2n;
110
- msb = msb | f;
111
- r = r >> f;
112
-
113
- f = _gt(r, 0x3n) << 1n;
114
- msb = msb | f;
115
- r = r >> f;
116
-
117
- f = _gt(r, 0x1n);
118
- msb = msb | f;
119
-
120
- if (msb >= 128n) r = ratio >> (msb - 127n);
121
- else r = ratio << (127n - msb);
122
-
123
- let log_2 = (BigInt.asIntN(256, msb) - 128n) << 64n;
124
-
125
- r = (r * r) >> 127n;
126
- f = r >> 128n;
127
- log_2 = log_2 | (f << 63n);
128
- r = r >> f;
129
-
130
- r = (r * r) >> 127n;
131
- f = r >> 128n;
132
- log_2 = log_2 | (f << 62n);
133
- r = r >> f;
134
-
135
- r = (r * r) >> 127n;
136
- f = r >> 128n;
137
- log_2 = log_2 | (f << 61n);
138
- r = r >> f;
139
-
140
- r = (r * r) >> 127n;
141
- f = r >> 128n;
142
- log_2 = log_2 | (f << 60n);
143
- r = r >> f;
144
-
145
- r = (r * r) >> 127n;
146
- f = r >> 128n;
147
- log_2 = log_2 | (f << 59n);
148
- r = r >> f;
149
-
150
- r = (r * r) >> 127n;
151
- f = r >> 128n;
152
- log_2 = log_2 | (f << 58n);
153
- r = r >> f;
154
-
155
- r = (r * r) >> 127n;
156
- f = r >> 128n;
157
- log_2 = log_2 | (f << 57n);
158
- r = r >> f;
159
-
160
- r = (r * r) >> 127n;
161
- f = r >> 128n;
162
- log_2 = log_2 | (f << 56n);
163
- r = r >> f;
164
-
165
- r = (r * r) >> 127n;
166
- f = r >> 128n;
167
- log_2 = log_2 | (f << 55n);
168
- r = r >> f;
169
-
170
- r = (r * r) >> 127n;
171
- f = r >> 128n;
172
- log_2 = log_2 | (f << 54n);
173
- r = r >> f;
174
-
175
- r = (r * r) >> 127n;
176
- f = r >> 128n;
177
- log_2 = log_2 | (f << 53n);
178
- r = r >> f;
179
-
180
- r = (r * r) >> 127n;
181
- f = r >> 128n;
182
- log_2 = log_2 | (f << 52n);
183
- r = r >> f;
184
-
185
- r = (r * r) >> 127n;
186
- f = r >> 128n;
187
- log_2 = log_2 | (f << 51n);
188
- r = r >> f;
189
-
190
- r = (r * r) >> 127n;
191
- f = r >> 128n;
192
- log_2 = log_2 | (f << 50n);
193
-
194
- const log_sqrt10001 = log_2 * 255738958999603826347141n; // 128.128 number
195
-
196
- const tickLow = BigInt.asIntN(
197
- 24,
198
- (log_sqrt10001 - 3402992956809132418596140100660247210n) >> 128n,
199
- );
200
- const tickHi = BigInt.asIntN(
201
- 24,
202
- (log_sqrt10001 + 291339464771989622907027621153398088495n) >> 128n,
203
- );
204
-
205
- return tickLow === tickHi
206
- ? tickLow
207
- : TickMath.getSqrtRatioAtTick(tickHi) <= sqrtPriceX96
208
- ? tickHi
209
- : tickLow;
210
- }
211
- }
@@ -1,5 +0,0 @@
1
- export class UnsafeMath {
2
- static divRoundingUp(x: bigint, y: bigint) {
3
- return (x + y - 1n) / y;
4
- }
5
- }