@paraswap/dex-lib 2.42.4-baseswap → 2.42.4

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 (216) hide show
  1. package/.vscode/launch.json +16 -0
  2. package/build/dex/index.js +0 -2
  3. package/build/dex/index.js.map +1 -1
  4. package/build/test.js +26 -0
  5. package/package.json +1 -1
  6. package/src/dex/index.ts +0 -2
  7. package/build/abi/kyberswap-elastic/IAntiSnipAttackPositionManager.json +0 -1276
  8. package/build/abi/kyberswap-elastic/IFactory.json +0 -550
  9. package/build/abi/kyberswap-elastic/IPool.json +0 -1042
  10. package/build/abi/kyberswap-elastic/IQuoterV2.json +0 -226
  11. package/build/abi/kyberswap-elastic/IRouter.json +0 -239
  12. package/build/abi/kyberswap-elastic/TicksFeesReader.json +0 -142
  13. package/build/abi/wombat/asset.json +0 -769
  14. package/build/abi/wombat/bmw.json +0 -1247
  15. package/build/abi/wombat/pool.json +0 -1364
  16. package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +0 -26
  17. package/build/dex/baseswap-v3/baseswap-v3-factory.js +0 -44
  18. package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +0 -1
  19. package/build/dex/baseswap-v3/baseswap-v3-pool.d.ts +0 -46
  20. package/build/dex/baseswap-v3/baseswap-v3-pool.js +0 -312
  21. package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +0 -1
  22. package/build/dex/baseswap-v3/baseswap-v3.d.ts +0 -71
  23. package/build/dex/baseswap-v3/baseswap-v3.js +0 -752
  24. package/build/dex/baseswap-v3/baseswap-v3.js.map +0 -1
  25. package/build/dex/baseswap-v3/config.d.ts +0 -9
  26. package/build/dex/baseswap-v3/config.js +0 -48
  27. package/build/dex/baseswap-v3/config.js.map +0 -1
  28. package/build/dex/baseswap-v3/constants.d.ts +0 -28
  29. package/build/dex/baseswap-v3/constants.js +0 -35
  30. package/build/dex/baseswap-v3/constants.js.map +0 -1
  31. package/build/dex/baseswap-v3/contract-math/BitMath.d.ts +0 -4
  32. package/build/dex/baseswap-v3/contract-math/BitMath.js +0 -93
  33. package/build/dex/baseswap-v3/contract-math/BitMath.js.map +0 -1
  34. package/build/dex/baseswap-v3/contract-math/FixedPoint128.d.ts +0 -3
  35. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js +0 -8
  36. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +0 -1
  37. package/build/dex/baseswap-v3/contract-math/FixedPoint96.d.ts +0 -4
  38. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js +0 -9
  39. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +0 -1
  40. package/build/dex/baseswap-v3/contract-math/FullMath.d.ts +0 -4
  41. package/build/dex/baseswap-v3/contract-math/FullMath.js +0 -19
  42. package/build/dex/baseswap-v3/contract-math/FullMath.js.map +0 -1
  43. package/build/dex/baseswap-v3/contract-math/LiquidityMath.d.ts +0 -3
  44. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js +0 -22
  45. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +0 -1
  46. package/build/dex/baseswap-v3/contract-math/Oracle.d.ts +0 -10
  47. package/build/dex/baseswap-v3/contract-math/Oracle.js +0 -133
  48. package/build/dex/baseswap-v3/contract-math/Oracle.js.map +0 -1
  49. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.d.ts +0 -10
  50. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js +0 -91
  51. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +0 -1
  52. package/build/dex/baseswap-v3/contract-math/SwapMath.d.ts +0 -8
  53. package/build/dex/baseswap-v3/contract-math/SwapMath.js +0 -70
  54. package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +0 -1
  55. package/build/dex/baseswap-v3/contract-math/Tick.d.ts +0 -7
  56. package/build/dex/baseswap-v3/contract-math/Tick.js +0 -45
  57. package/build/dex/baseswap-v3/contract-math/Tick.js.map +0 -1
  58. package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +0 -7
  59. package/build/dex/baseswap-v3/contract-math/TickBitMap.js +0 -84
  60. package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +0 -1
  61. package/build/dex/baseswap-v3/contract-math/TickMath.d.ts +0 -8
  62. package/build/dex/baseswap-v3/contract-math/TickMath.js +0 -162
  63. package/build/dex/baseswap-v3/contract-math/TickMath.js.map +0 -1
  64. package/build/dex/baseswap-v3/contract-math/UnsafeMath.d.ts +0 -3
  65. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js +0 -10
  66. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +0 -1
  67. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.d.ts +0 -37
  68. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js +0 -393
  69. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +0 -1
  70. package/build/dex/baseswap-v3/contract-math/utils.d.ts +0 -7
  71. package/build/dex/baseswap-v3/contract-math/utils.js +0 -42
  72. package/build/dex/baseswap-v3/contract-math/utils.js.map +0 -1
  73. package/build/dex/baseswap-v3/types.d.ts +0 -164
  74. package/build/dex/baseswap-v3/types.js +0 -9
  75. package/build/dex/baseswap-v3/types.js.map +0 -1
  76. package/build/dex/baseswap-v3/utils.d.ts +0 -6
  77. package/build/dex/baseswap-v3/utils.js +0 -65
  78. package/build/dex/baseswap-v3/utils.js.map +0 -1
  79. package/build/dex/hello/config.d.ts +0 -4
  80. package/build/dex/hello/config.js +0 -15
  81. package/build/dex/hello/config.js.map +0 -1
  82. package/build/dex/hello/hello-pool.d.ts +0 -39
  83. package/build/dex/hello/hello-pool.js +0 -64
  84. package/build/dex/hello/hello-pool.js.map +0 -1
  85. package/build/dex/hello/hello.d.ts +0 -37
  86. package/build/dex/hello/hello.js +0 -126
  87. package/build/dex/hello/hello.js.map +0 -1
  88. package/build/dex/hello/types.d.ts +0 -6
  89. package/build/dex/hello/types.js +0 -3
  90. package/build/dex/hello/types.js.map +0 -1
  91. package/build/dex/kyberswap-elastic/config.d.ts +0 -4
  92. package/build/dex/kyberswap-elastic/config.js +0 -80
  93. package/build/dex/kyberswap-elastic/config.js.map +0 -1
  94. package/build/dex/kyberswap-elastic/constants.d.ts +0 -17
  95. package/build/dex/kyberswap-elastic/constants.js +0 -42
  96. package/build/dex/kyberswap-elastic/constants.js.map +0 -1
  97. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.d.ts +0 -4
  98. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js +0 -9
  99. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js.map +0 -1
  100. package/build/dex/kyberswap-elastic/contract-math/FullMath.d.ts +0 -5
  101. package/build/dex/kyberswap-elastic/contract-math/FullMath.js +0 -22
  102. package/build/dex/kyberswap-elastic/contract-math/FullMath.js.map +0 -1
  103. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.d.ts +0 -3
  104. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js +0 -12
  105. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js.map +0 -1
  106. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.d.ts +0 -3
  107. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js +0 -22
  108. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js.map +0 -1
  109. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.d.ts +0 -5
  110. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js +0 -25
  111. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js.map +0 -1
  112. package/build/dex/kyberswap-elastic/contract-math/QuadMath.d.ts +0 -4
  113. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js +0 -27
  114. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js.map +0 -1
  115. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.d.ts +0 -3
  116. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js +0 -14
  117. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js.map +0 -1
  118. package/build/dex/kyberswap-elastic/contract-math/SafeCast.d.ts +0 -8
  119. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js +0 -30
  120. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js.map +0 -1
  121. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.d.ts +0 -10
  122. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js +0 -91
  123. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js.map +0 -1
  124. package/build/dex/kyberswap-elastic/contract-math/SwapMath.d.ts +0 -13
  125. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js +0 -188
  126. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js.map +0 -1
  127. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.d.ts +0 -6
  128. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js +0 -41
  129. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js.map +0 -1
  130. package/build/dex/kyberswap-elastic/contract-math/TickMath.d.ts +0 -9
  131. package/build/dex/kyberswap-elastic/contract-math/TickMath.js +0 -165
  132. package/build/dex/kyberswap-elastic/contract-math/TickMath.js.map +0 -1
  133. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.d.ts +0 -3
  134. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js +0 -10
  135. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js.map +0 -1
  136. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.d.ts +0 -28
  137. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js +0 -502
  138. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js.map +0 -1
  139. package/build/dex/kyberswap-elastic/contract-math/utils.d.ts +0 -3
  140. package/build/dex/kyberswap-elastic/contract-math/utils.js +0 -16
  141. package/build/dex/kyberswap-elastic/contract-math/utils.js.map +0 -1
  142. package/build/dex/kyberswap-elastic/errors.d.ts +0 -2
  143. package/build/dex/kyberswap-elastic/errors.js +0 -6
  144. package/build/dex/kyberswap-elastic/errors.js.map +0 -1
  145. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.d.ts +0 -80
  146. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js +0 -458
  147. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js.map +0 -1
  148. package/build/dex/kyberswap-elastic/kyberswap-elastic.d.ts +0 -53
  149. package/build/dex/kyberswap-elastic/kyberswap-elastic.js +0 -610
  150. package/build/dex/kyberswap-elastic/kyberswap-elastic.js.map +0 -1
  151. package/build/dex/kyberswap-elastic/types.d.ts +0 -134
  152. package/build/dex/kyberswap-elastic/types.js +0 -9
  153. package/build/dex/kyberswap-elastic/types.js.map +0 -1
  154. package/build/dex/kyberswap-elastic/utils/decoders.d.ts +0 -9
  155. package/build/dex/kyberswap-elastic/utils/decoders.js +0 -78
  156. package/build/dex/kyberswap-elastic/utils/decoders.js.map +0 -1
  157. package/build/dex/my-test-dex/config.d.ts +0 -4
  158. package/build/dex/my-test-dex/config.js +0 -15
  159. package/build/dex/my-test-dex/config.js.map +0 -1
  160. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +0 -39
  161. package/build/dex/my-test-dex/my-test-dex-pool.js +0 -64
  162. package/build/dex/my-test-dex/my-test-dex-pool.js.map +0 -1
  163. package/build/dex/my-test-dex/my-test-dex.d.ts +0 -37
  164. package/build/dex/my-test-dex/my-test-dex.js +0 -126
  165. package/build/dex/my-test-dex/my-test-dex.js.map +0 -1
  166. package/build/dex/my-test-dex/types.d.ts +0 -6
  167. package/build/dex/my-test-dex/types.js +0 -3
  168. package/build/dex/my-test-dex/types.js.map +0 -1
  169. package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
  170. package/build/dex/solidly/forks-override/fvm.js +0 -42
  171. package/build/dex/solidly/forks-override/fvm.js.map +0 -1
  172. package/build/dex/wombat/config.d.ts +0 -5
  173. package/build/dex/wombat/config.js +0 -36
  174. package/build/dex/wombat/config.js.map +0 -1
  175. package/build/dex/wombat/types.d.ts +0 -33
  176. package/build/dex/wombat/types.js +0 -3
  177. package/build/dex/wombat/types.js.map +0 -1
  178. package/build/dex/wombat/utils.d.ts +0 -9
  179. package/build/dex/wombat/utils.js +0 -66
  180. package/build/dex/wombat/utils.js.map +0 -1
  181. package/build/dex/wombat/wombat-bmw.d.ts +0 -40
  182. package/build/dex/wombat/wombat-bmw.js +0 -145
  183. package/build/dex/wombat/wombat-bmw.js.map +0 -1
  184. package/build/dex/wombat/wombat-pool.d.ts +0 -22
  185. package/build/dex/wombat/wombat-pool.js +0 -161
  186. package/build/dex/wombat/wombat-pool.js.map +0 -1
  187. package/build/dex/wombat/wombat-quoter.d.ts +0 -16
  188. package/build/dex/wombat/wombat-quoter.js +0 -176
  189. package/build/dex/wombat/wombat-quoter.js.map +0 -1
  190. package/build/dex/wombat/wombat.d.ts +0 -55
  191. package/build/dex/wombat/wombat.js +0 -292
  192. package/build/dex/wombat/wombat.js.map +0 -1
  193. package/src/dex/baseswap-v3/baseswap-v3-e2e.test.ts +0 -129
  194. package/src/dex/baseswap-v3/baseswap-v3-events.test.ts +0 -141
  195. package/src/dex/baseswap-v3/baseswap-v3-factory.ts +0 -73
  196. package/src/dex/baseswap-v3/baseswap-v3-integration.test.ts +0 -472
  197. package/src/dex/baseswap-v3/baseswap-v3-pool.ts +0 -519
  198. package/src/dex/baseswap-v3/baseswap-v3.ts +0 -1243
  199. package/src/dex/baseswap-v3/config.ts +0 -53
  200. package/src/dex/baseswap-v3/constants.ts +0 -41
  201. package/src/dex/baseswap-v3/contract-math/BitMath.ts +0 -90
  202. package/src/dex/baseswap-v3/contract-math/FixedPoint128.ts +0 -3
  203. package/src/dex/baseswap-v3/contract-math/FixedPoint96.ts +0 -4
  204. package/src/dex/baseswap-v3/contract-math/FullMath.ts +0 -30
  205. package/src/dex/baseswap-v3/contract-math/LiquidityMath.ts +0 -17
  206. package/src/dex/baseswap-v3/contract-math/Oracle.ts +0 -226
  207. package/src/dex/baseswap-v3/contract-math/SqrtPriceMath.ts +0 -226
  208. package/src/dex/baseswap-v3/contract-math/SwapMath.ts +0 -139
  209. package/src/dex/baseswap-v3/contract-math/Tick.ts +0 -82
  210. package/src/dex/baseswap-v3/contract-math/TickBitMap.ts +0 -123
  211. package/src/dex/baseswap-v3/contract-math/TickMath.ts +0 -211
  212. package/src/dex/baseswap-v3/contract-math/UnsafeMath.ts +0 -5
  213. package/src/dex/baseswap-v3/contract-math/uniswap-v3-math.ts +0 -666
  214. package/src/dex/baseswap-v3/contract-math/utils.ts +0 -55
  215. package/src/dex/baseswap-v3/types.ts +0 -191
  216. package/src/dex/baseswap-v3/utils.ts +0 -83
@@ -1,191 +0,0 @@
1
- import { BigNumber, BytesLike } from 'ethers';
2
- import { NumberAsString } from '../../types';
3
- import { Address } from '../../types';
4
- import { AbiItem } from 'web3-utils';
5
- import { MultiResult } from '../../lib/multi-wrapper';
6
- import { BaseswapV3EventPool } from './baseswap-v3-pool';
7
-
8
- export type OracleObservation = {
9
- blockTimestamp: bigint;
10
- tickCumulative: bigint;
11
- secondsPerLiquidityCumulativeX128: bigint;
12
- initialized: boolean;
13
- };
14
-
15
- export type OracleObservationCandidates = {
16
- beforeOrAt: OracleObservation;
17
- atOrAfter: OracleObservation;
18
- };
19
-
20
- export type TickInfo = {
21
- liquidityGross: bigint;
22
- liquidityNet: bigint;
23
- tickCumulativeOutside: bigint;
24
- secondsPerLiquidityOutsideX128: bigint;
25
- secondsOutside: bigint;
26
- initialized: boolean;
27
- };
28
-
29
- export type Slot0 = {
30
- sqrtPriceX96: bigint;
31
- tick: bigint;
32
- observationIndex: number;
33
- observationCardinality: number;
34
- observationCardinalityNext: number;
35
- feeProtocol: bigint;
36
- };
37
-
38
- export type PoolState = {
39
- pool: string;
40
- blockTimestamp: bigint;
41
- tickSpacing: bigint;
42
- fee: bigint;
43
- slot0: Slot0;
44
- liquidity: bigint;
45
- maxLiquidityPerTick: bigint;
46
- tickBitmap: Record<NumberAsString, bigint>;
47
- ticks: Record<NumberAsString, TickInfo>;
48
- observations: Record<number, OracleObservation>;
49
- isValid: boolean;
50
- startTickBitmap: bigint;
51
- lowestKnownTick: bigint;
52
- highestKnownTick: bigint;
53
- balance0: bigint;
54
- balance1: bigint;
55
- };
56
-
57
- export type FactoryState = Record<string, never>;
58
-
59
- export type UniswapV3Data = {
60
- path: {
61
- tokenIn: Address;
62
- tokenOut: Address;
63
- fee: NumberAsString;
64
- currentFee?: NumberAsString;
65
- }[];
66
- isApproved?: boolean;
67
- };
68
-
69
- export type DecodeStateMultiCallFunc = (
70
- result: MultiResult<BytesLike> | BytesLike,
71
- ) => DecodedStateMultiCallResultWithRelativeBitmaps;
72
-
73
- export type DexParams = {
74
- router: Address;
75
- quoter: Address;
76
- factory: Address;
77
- stateMulticall: Address;
78
- uniswapMulticall: Address;
79
- supportedFees: bigint[];
80
- chunksCount: number;
81
- initRetryFrequency: number;
82
- deployer?: Address;
83
- subgraphURL: string;
84
- initHash: string;
85
- stateMultiCallAbi?: AbiItem[];
86
- eventPoolImplementation?: typeof BaseswapV3EventPool;
87
- decodeStateMultiCallResultWithRelativeBitmaps?: DecodeStateMultiCallFunc;
88
- };
89
-
90
- export type UniswapV3SimpleSwapSellParam = {
91
- path: string;
92
- recipient: Address;
93
- deadline: string;
94
- amountIn: NumberAsString;
95
- amountOutMinimum: NumberAsString;
96
- };
97
-
98
- export type UniswapV3SimpleSwapBuyParam = {
99
- path: string;
100
- recipient: Address;
101
- deadline: string;
102
- amountOut: NumberAsString;
103
- amountInMaximum: NumberAsString;
104
- };
105
-
106
- export type UniswapV3SimpleSwapParams =
107
- | UniswapV3SimpleSwapSellParam
108
- | UniswapV3SimpleSwapBuyParam;
109
-
110
- export type UniswapV3Param = [
111
- fromToken: Address,
112
- toToken: Address,
113
- exchange: Address,
114
- fromAmount: NumberAsString,
115
- toAmount: NumberAsString,
116
- expectedAmount: NumberAsString,
117
- feePercent: NumberAsString,
118
- deadline: NumberAsString,
119
- partner: Address,
120
- isApproved: boolean,
121
- beneficiary: Address,
122
- path: string,
123
- permit: string,
124
- uuid: string,
125
- ];
126
-
127
- export enum UniswapV3Functions {
128
- exactInput = 'exactInput',
129
- exactOutput = 'exactOutput',
130
- }
131
-
132
- export type TickInfoMappings = {
133
- index: number;
134
- value: TickInfo;
135
- };
136
-
137
- export type TickBitMapMappings = {
138
- index: number;
139
- value: bigint;
140
- };
141
-
142
- export type OutputResult = {
143
- outputs: bigint[];
144
- tickCounts: number[];
145
- };
146
-
147
- // Just rewrote every type with BigNumber basically
148
-
149
- export type TickBitMapMappingsWithBigNumber = {
150
- index: number;
151
- value: BigNumber;
152
- };
153
-
154
- export type TickInfoWithBigNumber = {
155
- initialized: boolean;
156
- liquidityGross: BigNumber;
157
- liquidityNet: BigNumber;
158
- secondsOutside: number;
159
- secondsPerLiquidityOutsideX128: BigNumber;
160
- tickCumulativeOutside: BigNumber;
161
- };
162
-
163
- export type TickInfoMappingsWithBigNumber = {
164
- index: number;
165
- value: TickInfoWithBigNumber;
166
- };
167
-
168
- export type DecodedStateMultiCallResultWithRelativeBitmaps = {
169
- pool: Address;
170
- blockTimestamp: BigNumber;
171
- slot0: {
172
- feeProtocol: number;
173
- observationCardinality: number;
174
- observationCardinalityNext: number;
175
- observationIndex: number;
176
- sqrtPriceX96: BigNumber;
177
- tick: number;
178
- unlocked: boolean;
179
- };
180
- liquidity: BigNumber;
181
- tickSpacing: number;
182
- maxLiquidityPerTick: BigNumber;
183
- observation: {
184
- blockTimestamp: number;
185
- initialized: boolean;
186
- secondsPerLiquidityCumulativeX128: BigNumber;
187
- tickCumulative: BigNumber;
188
- };
189
- tickBitmap: TickBitMapMappingsWithBigNumber[];
190
- ticks: TickInfoMappingsWithBigNumber[];
191
- };
@@ -1,83 +0,0 @@
1
- import { BytesLike, ethers } from 'ethers';
2
- import { assert } from 'ts-essentials';
3
- import { extractSuccessAndValue } from '../../lib/decoders';
4
- import { MultiResult } from '../../lib/multi-wrapper';
5
- import { DexConfigMap } from '../../types';
6
- import {
7
- DexParams,
8
- DecodedStateMultiCallResultWithRelativeBitmaps,
9
- } from './types';
10
-
11
- export function getUniswapV3DexKey(UniswapV3Config: DexConfigMap<DexParams>) {
12
- const UniswapV3Keys = Object.keys(UniswapV3Config);
13
- if (UniswapV3Keys.length !== 1) {
14
- throw new Error(
15
- `UniswapV3 key in UniswapV3Config is not unique. Update relevant places (optimizer) or fix config issue. Received: ${JSON.stringify(
16
- UniswapV3Config,
17
- (_0, value) => (typeof value === 'bigint' ? value.toString() : value),
18
- )}`,
19
- );
20
- }
21
-
22
- return UniswapV3Keys[0].toLowerCase();
23
- }
24
-
25
- export function decodeStateMultiCallResultWithRelativeBitmaps(
26
- result: MultiResult<BytesLike> | BytesLike,
27
- ): DecodedStateMultiCallResultWithRelativeBitmaps {
28
- const [isSuccess, toDecode] = extractSuccessAndValue(result);
29
-
30
- assert(
31
- isSuccess && toDecode !== '0x',
32
- `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`,
33
- );
34
-
35
- const decoded = ethers.utils.defaultAbiCoder.decode(
36
- [
37
- // I don't want to pass here any interface, so I just use it in ethers format
38
- `
39
- tuple(
40
- address pool,
41
- uint256 blockTimestamp,
42
- tuple(
43
- uint160 sqrtPriceX96,
44
- int24 tick,
45
- uint16 observationIndex,
46
- uint16 observationCardinality,
47
- uint16 observationCardinalityNext,
48
- uint8 feeProtocol,
49
- bool unlocked,
50
- ) slot0,
51
- uint128 liquidity,
52
- int24 tickSpacing,
53
- uint128 maxLiquidityPerTick,
54
- tuple(
55
- uint32 blockTimestamp,
56
- int56 tickCumulative,
57
- uint160 secondsPerLiquidityCumulativeX128,
58
- bool initialized,
59
- ) observation,
60
- tuple(
61
- int16 index,
62
- uint256 value,
63
- )[] tickBitmap,
64
- tuple(
65
- int24 index,
66
- tuple(
67
- uint128 liquidityGross,
68
- int128 liquidityNet,
69
- int56 tickCumulativeOutside,
70
- uint160 secondsPerLiquidityOutsideX128,
71
- uint32 secondsOutside,
72
- bool initialized,
73
- ) value,
74
- )[] ticks
75
- )
76
- `,
77
- ],
78
- toDecode,
79
- )[0];
80
- // This conversion is not precise, because when we decode, we have more values
81
- // But I typed only the ones that are used later
82
- return decoded as DecodedStateMultiCallResultWithRelativeBitmaps;
83
- }