@paraswap/dex-lib 4.0.3 → 4.0.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 (214) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/integral/factory.json +333 -0
  10. package/build/abi/integral/oracle.json +501 -0
  11. package/build/abi/{inception/inception-ineth-pool.json → integral/pool.json} +522 -543
  12. package/build/abi/{wombat/pool.json → integral/relayer.json} +720 -473
  13. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  14. package/build/dex/aave-v1/aave-v1.js +0 -23
  15. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  16. package/build/dex/bebop/bebop.js +1 -1
  17. package/build/dex/bebop/bebop.js.map +1 -1
  18. package/build/dex/cables/cables.d.ts +4 -2
  19. package/build/dex/cables/cables.js +90 -155
  20. package/build/dex/cables/cables.js.map +1 -1
  21. package/build/dex/cables/constants.d.ts +0 -1
  22. package/build/dex/cables/constants.js +2 -3
  23. package/build/dex/cables/constants.js.map +1 -1
  24. package/build/dex/cables/rate-fetcher.js +26 -10
  25. package/build/dex/cables/rate-fetcher.js.map +1 -1
  26. package/build/dex/cables/types.d.ts +15 -28
  27. package/build/dex/cables/types.js +2 -13
  28. package/build/dex/cables/types.js.map +1 -1
  29. package/build/dex/dexalot/dexalot.js.map +1 -1
  30. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +49 -0
  31. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
  32. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
  33. package/build/dex/index.js +2 -0
  34. package/build/dex/index.js.map +1 -1
  35. package/build/dex/integral/config.d.ts +4 -0
  36. package/build/dex/integral/config.js +20 -0
  37. package/build/dex/integral/config.js.map +1 -0
  38. package/build/dex/integral/context.d.ts +40 -0
  39. package/build/dex/integral/context.js +158 -0
  40. package/build/dex/integral/context.js.map +1 -0
  41. package/build/dex/integral/integral-factory.d.ts +24 -0
  42. package/build/dex/integral/integral-factory.js +95 -0
  43. package/build/dex/integral/integral-factory.js.map +1 -0
  44. package/build/dex/integral/integral-pool.d.ts +50 -0
  45. package/build/dex/integral/integral-pool.js +149 -0
  46. package/build/dex/integral/integral-pool.js.map +1 -0
  47. package/build/dex/integral/integral-pricing.d.ts +18 -0
  48. package/build/dex/integral/integral-pricing.js +114 -0
  49. package/build/dex/integral/integral-pricing.js.map +1 -0
  50. package/build/dex/integral/integral-relayer.d.ts +42 -0
  51. package/build/dex/integral/integral-relayer.js +192 -0
  52. package/build/dex/integral/integral-relayer.js.map +1 -0
  53. package/build/dex/integral/integral-token.d.ts +27 -0
  54. package/build/dex/integral/integral-token.js +59 -0
  55. package/build/dex/integral/integral-token.js.map +1 -0
  56. package/build/dex/integral/integral.d.ts +41 -0
  57. package/build/dex/integral/integral.js +376 -0
  58. package/build/dex/integral/integral.js.map +1 -0
  59. package/build/dex/integral/types.d.ts +85 -0
  60. package/build/dex/integral/types.js +9 -0
  61. package/build/dex/integral/types.js.map +1 -0
  62. package/build/dex/integral/utils-e2e.d.ts +9 -0
  63. package/build/dex/integral/utils-e2e.js +131 -0
  64. package/build/dex/integral/utils-e2e.js.map +1 -0
  65. package/build/dex/integral/utils.d.ts +17 -0
  66. package/build/dex/integral/utils.js +94 -0
  67. package/build/dex/integral/utils.js.map +1 -0
  68. package/build/dex/jarvis.d.ts +1 -2
  69. package/build/dex/jarvis.js +0 -58
  70. package/build/dex/jarvis.js.map +1 -1
  71. package/build/dex/platypus/platypus.d.ts +1 -2
  72. package/build/dex/platypus/platypus.js +0 -45
  73. package/build/dex/platypus/platypus.js.map +1 -1
  74. package/build/dex/stable-pool.js +8 -1
  75. package/build/dex/stable-pool.js.map +1 -1
  76. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  77. package/build/dex/swaap-v1/swaap-v1.js +0 -14
  78. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  79. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  80. package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
  81. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  82. package/build/dex/zerox/index.d.ts +26 -4
  83. package/build/dex/zerox/index.js +42 -50
  84. package/build/dex/zerox/index.js.map +1 -1
  85. package/build/dex/zerox/types.d.ts +0 -29
  86. package/build/dex/zerox/types.js +1 -8
  87. package/build/dex/zerox/types.js.map +1 -1
  88. package/build/executor/Executor01BytecodeBuilder.js +11 -6
  89. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  90. package/build/executor/Executor02BytecodeBuilder.js +11 -6
  91. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  92. package/build/executor/Executor03BytecodeBuilder.js +11 -6
  93. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  94. package/build/types.d.ts +1 -0
  95. package/package.json +1 -1
  96. package/src/abi/cables/CablesMainnetRFQ.json +1083 -0
  97. package/src/dex/bebop/bebop.ts +1 -1
  98. package/src/dex/cables/cables-e2e.test.ts +207 -0
  99. package/src/dex/cables/cables-integration.test.ts +391 -0
  100. package/src/dex/cables/cables.ts +823 -0
  101. package/src/dex/cables/config.ts +13 -0
  102. package/src/dex/cables/constants.ts +33 -0
  103. package/src/dex/cables/rate-fetcher.ts +212 -0
  104. package/src/dex/cables/types.ts +113 -0
  105. package/src/dex/cables/validators.test.ts +151 -0
  106. package/src/dex/cables/validators.ts +61 -0
  107. package/src/dex/dexalot/dexalot.ts +1 -0
  108. package/src/dex/index.ts +2 -0
  109. package/src/executor/Executor01BytecodeBuilder.ts +15 -11
  110. package/src/executor/Executor02BytecodeBuilder.ts +13 -9
  111. package/src/executor/Executor03BytecodeBuilder.ts +16 -9
  112. package/src/types.ts +1 -0
  113. package/tests/constants-e2e.ts +2 -2
  114. package/.vscode/launch.json +0 -53
  115. package/.vscode/settings.json +0 -2
  116. package/.vscode/tasks.json +0 -15
  117. package/build/abi/inception/inception-ratio-feed.json +0 -329
  118. package/build/abi/inception/inception-vault.json +0 -991
  119. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  120. package/build/abi/usual-m-smart-m/usualM.abi.json +0 -483
  121. package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +0 -681
  122. package/build/abi/usual-m-wrapped-m/usualM.abi.json +0 -509
  123. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  124. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  125. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  126. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +0 -729
  127. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +0 -732
  128. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +0 -1
  129. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +0 -1406
  130. package/build/dex/balancer-v3/abi/balancerRouter.js +0 -1175
  131. package/build/dex/balancer-v3/abi/balancerRouter.js.map +0 -1
  132. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +0 -2081
  133. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +0 -1851
  134. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +0 -1
  135. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +0 -34
  136. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +0 -406
  137. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +0 -1
  138. package/build/dex/inception/config.d.ts +0 -4
  139. package/build/dex/inception/config.js +0 -109
  140. package/build/dex/inception/config.js.map +0 -1
  141. package/build/dex/inception/inception-event-pool.d.ts +0 -16
  142. package/build/dex/inception/inception-event-pool.js +0 -49
  143. package/build/dex/inception/inception-event-pool.js.map +0 -1
  144. package/build/dex/inception/inception.d.ts +0 -43
  145. package/build/dex/inception/inception.js +0 -180
  146. package/build/dex/inception/inception.js.map +0 -1
  147. package/build/dex/inception/tokens.d.ts +0 -9
  148. package/build/dex/inception/tokens.js +0 -28
  149. package/build/dex/inception/tokens.js.map +0 -1
  150. package/build/dex/inception/types.d.ts +0 -22
  151. package/build/dex/inception/types.js +0 -3
  152. package/build/dex/inception/types.js.map +0 -1
  153. package/build/dex/inception/utils.d.ts +0 -7
  154. package/build/dex/inception/utils.js +0 -58
  155. package/build/dex/inception/utils.js.map +0 -1
  156. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  157. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  158. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  159. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  160. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  161. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  162. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  163. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  164. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  165. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  166. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  167. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  168. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  169. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  170. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +0 -4
  171. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +0 -43
  172. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +0 -1
  173. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +0 -1
  174. package/build/dex/uniswap-v3/uniswap-v3-worker.js +0 -10
  175. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +0 -1
  176. package/build/dex/usual/types.d.ts +0 -13
  177. package/build/dex/usual/types.js +0 -3
  178. package/build/dex/usual/types.js.map +0 -1
  179. package/build/dex/usual/usual-bond.d.ts +0 -18
  180. package/build/dex/usual/usual-bond.js +0 -52
  181. package/build/dex/usual/usual-bond.js.map +0 -1
  182. package/build/dex/usual/usual-m-smart-m.d.ts +0 -17
  183. package/build/dex/usual/usual-m-smart-m.js +0 -50
  184. package/build/dex/usual/usual-m-smart-m.js.map +0 -1
  185. package/build/dex/usual/usual-m-usd0.d.ts +0 -17
  186. package/build/dex/usual/usual-m-usd0.js +0 -51
  187. package/build/dex/usual/usual-m-usd0.js.map +0 -1
  188. package/build/dex/usual/usual-m-wrapped-m.d.ts +0 -17
  189. package/build/dex/usual/usual-m-wrapped-m.js +0 -50
  190. package/build/dex/usual/usual-m-wrapped-m.js.map +0 -1
  191. package/build/dex/usual/usual.d.ts +0 -27
  192. package/build/dex/usual/usual.js +0 -125
  193. package/build/dex/usual/usual.js.map +0 -1
  194. package/build/dex/usual-m-smart-m/config.d.ts +0 -3
  195. package/build/dex/usual-m-smart-m/config.js +0 -13
  196. package/build/dex/usual-m-smart-m/config.js.map +0 -1
  197. package/build/dex/usual-m-smart-m/types.d.ts +0 -7
  198. package/build/dex/usual-m-smart-m/types.js +0 -3
  199. package/build/dex/usual-m-smart-m/types.js.map +0 -1
  200. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +0 -35
  201. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +0 -161
  202. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +0 -1
  203. package/build/dex/usual-m-usd0/config.d.ts +0 -3
  204. package/build/dex/usual-m-usd0/config.js +0 -14
  205. package/build/dex/usual-m-usd0/config.js.map +0 -1
  206. package/build/dex/usual-m-usd0/types.d.ts +0 -8
  207. package/build/dex/usual-m-usd0/types.js +0 -3
  208. package/build/dex/usual-m-usd0/types.js.map +0 -1
  209. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +0 -35
  210. package/build/dex/usual-m-usd0/usual-m-usd0.js +0 -159
  211. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +0 -1
  212. package/build/lib/pub-sub.d.ts +0 -35
  213. package/build/lib/pub-sub.js +0 -106
  214. package/build/lib/pub-sub.js.map +0 -1
@@ -723,7 +723,7 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
723
723
  }
724
724
  }
725
725
 
726
- if (side == SwapSide.SELL) {
726
+ if (side === SwapSide.SELL) {
727
727
  const requiredAmount = BigInt(optimalSwapExchange.destAmount);
728
728
  const quoteAmount = BigInt(
729
729
  response.buyTokens[utils.getAddress(destToken.address)].amount,
@@ -0,0 +1,207 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+ import { testE2E } from '../../../tests/utils-e2e';
4
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
5
+ import { Network, ContractMethod, SwapSide } from '../../constants';
6
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
7
+ import { generateConfig } from '../../config';
8
+
9
+ const sleepMs: number = 10000;
10
+ const slippage: number = 100;
11
+
12
+ describe('Cables E2E', () => {
13
+ const dexKey = 'Cables';
14
+
15
+ const sideToContractMethods = new Map([
16
+ [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
17
+ [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
18
+ ]);
19
+
20
+ describe('Arbitrum', () => {
21
+ const network = Network.ARBITRUM;
22
+ const provider = new StaticJsonRpcProvider(
23
+ generateConfig(network).privateHttpProvider,
24
+ network,
25
+ );
26
+ const tokens = Tokens[network];
27
+ const holders = Holders[network];
28
+
29
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
30
+ [
31
+ {
32
+ name: 'USDC',
33
+ sellAmount: '500000',
34
+ buyAmount: '700000',
35
+ },
36
+ {
37
+ name: 'USDT',
38
+ sellAmount: '600000',
39
+ buyAmount: '850000',
40
+ },
41
+ ],
42
+ [
43
+ {
44
+ name: 'WETH',
45
+ sellAmount: '100000000000000000',
46
+ buyAmount: '200000000000000000',
47
+ },
48
+ {
49
+ name: 'USDT',
50
+ sellAmount: '6000000',
51
+ buyAmount: '8000000',
52
+ },
53
+ ],
54
+ ];
55
+
56
+ sideToContractMethods.forEach((contractMethods, side) =>
57
+ describe(`${side}`, () => {
58
+ contractMethods.forEach((contractMethod: ContractMethod) => {
59
+ pairs.forEach(pair => {
60
+ describe(`${contractMethod}`, () => {
61
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
62
+ await testE2E(
63
+ side === SwapSide.SELL
64
+ ? tokens[pair[0].name]
65
+ : tokens[pair[1].name],
66
+ side === SwapSide.SELL
67
+ ? tokens[pair[1].name]
68
+ : tokens[pair[0].name],
69
+ side === SwapSide.SELL
70
+ ? holders[pair[0].name]
71
+ : holders[pair[1].name],
72
+ side === SwapSide.SELL
73
+ ? pair[0].sellAmount
74
+ : pair[0].buyAmount,
75
+ side,
76
+ dexKey,
77
+ contractMethod,
78
+ network,
79
+ provider,
80
+ undefined,
81
+ undefined,
82
+ undefined,
83
+ slippage,
84
+ sleepMs,
85
+ );
86
+ });
87
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
88
+ await testE2E(
89
+ side === SwapSide.SELL
90
+ ? tokens[pair[1].name]
91
+ : tokens[pair[0].name],
92
+ side === SwapSide.SELL
93
+ ? tokens[pair[0].name]
94
+ : tokens[pair[1].name],
95
+ side === SwapSide.SELL
96
+ ? holders[pair[1].name]
97
+ : holders[pair[0].name],
98
+ side === SwapSide.SELL
99
+ ? pair[1].sellAmount
100
+ : pair[1].buyAmount,
101
+ side,
102
+ dexKey,
103
+ contractMethod,
104
+ network,
105
+ provider,
106
+ undefined,
107
+ undefined,
108
+ undefined,
109
+ slippage,
110
+ sleepMs,
111
+ );
112
+ });
113
+ });
114
+ });
115
+ });
116
+ }),
117
+ );
118
+ });
119
+
120
+ describe('Avalanche', () => {
121
+ const network = Network.AVALANCHE;
122
+ const provider = new StaticJsonRpcProvider(
123
+ generateConfig(network).privateHttpProvider,
124
+ network,
125
+ );
126
+ const tokens = Tokens[network];
127
+ const holders = Holders[network];
128
+
129
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
130
+ [
131
+ {
132
+ name: 'USDC',
133
+ sellAmount: '1000000',
134
+ buyAmount: '700000',
135
+ },
136
+ {
137
+ name: 'USDT',
138
+ sellAmount: '1000000',
139
+ buyAmount: '850000',
140
+ },
141
+ ],
142
+ ];
143
+
144
+ sideToContractMethods.forEach((contractMethods, side) =>
145
+ describe(`${side}`, () => {
146
+ contractMethods.forEach((contractMethod: ContractMethod) => {
147
+ pairs.forEach(pair => {
148
+ describe(`${contractMethod}`, () => {
149
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
150
+ await testE2E(
151
+ side === SwapSide.SELL
152
+ ? tokens[pair[0].name]
153
+ : tokens[pair[1].name],
154
+ side === SwapSide.SELL
155
+ ? tokens[pair[1].name]
156
+ : tokens[pair[0].name],
157
+ side === SwapSide.SELL
158
+ ? holders[pair[0].name]
159
+ : holders[pair[1].name],
160
+ side === SwapSide.SELL
161
+ ? pair[0].sellAmount
162
+ : pair[0].buyAmount,
163
+ side,
164
+ dexKey,
165
+ contractMethod,
166
+ network,
167
+ provider,
168
+ undefined,
169
+ undefined,
170
+ undefined,
171
+ slippage,
172
+ sleepMs,
173
+ );
174
+ });
175
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
176
+ await testE2E(
177
+ side === SwapSide.SELL
178
+ ? tokens[pair[1].name]
179
+ : tokens[pair[0].name],
180
+ side === SwapSide.SELL
181
+ ? tokens[pair[0].name]
182
+ : tokens[pair[1].name],
183
+ side === SwapSide.SELL
184
+ ? holders[pair[1].name]
185
+ : holders[pair[0].name],
186
+ side === SwapSide.SELL
187
+ ? pair[1].sellAmount
188
+ : pair[1].buyAmount,
189
+ side,
190
+ dexKey,
191
+ contractMethod,
192
+ network,
193
+ provider,
194
+ undefined,
195
+ undefined,
196
+ undefined,
197
+ slippage,
198
+ sleepMs,
199
+ );
200
+ });
201
+ });
202
+ });
203
+ });
204
+ }),
205
+ );
206
+ });
207
+ });
@@ -0,0 +1,391 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { DummyDexHelper } from '../../dex-helper/index';
6
+ import { Network, SwapSide } from '../../constants';
7
+ import { BI_POWS } from '../../bigint-constants';
8
+ import { Cables } from './cables';
9
+ import {
10
+ checkPoolPrices,
11
+ checkPoolsLiquidity,
12
+ checkConstantPoolPrices,
13
+ sleep,
14
+ } from '../../../tests/utils';
15
+ import { Tokens } from '../../../tests/constants-e2e';
16
+
17
+ async function testPricingOnNetwork(
18
+ cables: Cables,
19
+ network: Network,
20
+ dexKey: string,
21
+ blockNumber: number,
22
+ srcTokenSymbol: string,
23
+ destTokenSymbol: string,
24
+ side: SwapSide,
25
+ amounts: bigint[],
26
+ ) {
27
+ const networkTokens = Tokens[network];
28
+
29
+ const pools = await cables.getPoolIdentifiers(
30
+ networkTokens[srcTokenSymbol],
31
+ networkTokens[destTokenSymbol],
32
+ side,
33
+ blockNumber,
34
+ );
35
+ console.log(
36
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
37
+ pools,
38
+ );
39
+
40
+ expect(pools.length).toBeGreaterThan(0);
41
+
42
+ const poolPrices = await cables.getPricesVolume(
43
+ networkTokens[srcTokenSymbol],
44
+ networkTokens[destTokenSymbol],
45
+ amounts,
46
+ side,
47
+ blockNumber,
48
+ pools,
49
+ );
50
+ console.log(
51
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
52
+ poolPrices,
53
+ );
54
+
55
+ expect(poolPrices).not.toBeNull();
56
+ if (cables.hasConstantPriceLargeAmounts) {
57
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
58
+ } else {
59
+ checkPoolPrices(poolPrices!, amounts, side, dexKey);
60
+ }
61
+ }
62
+
63
+ describe('Cables', function () {
64
+ const dexKey = 'Cables';
65
+ let blockNumber: number;
66
+ let cables: Cables;
67
+
68
+ describe('Avalanche', () => {
69
+ const network = Network.AVALANCHE;
70
+ const dexHelper = new DummyDexHelper(network);
71
+
72
+ const tokens = Tokens[network];
73
+
74
+ const tokenASymbol = 'USDC';
75
+ const tokenBSymbol = 'USDT';
76
+
77
+ const amountsForTokenA = [
78
+ 0n,
79
+ 1n * BI_POWS[tokens[tokenASymbol].decimals],
80
+ 2n * BI_POWS[tokens[tokenASymbol].decimals],
81
+ 3n * BI_POWS[tokens[tokenASymbol].decimals],
82
+ 4n * BI_POWS[tokens[tokenASymbol].decimals],
83
+ 5n * BI_POWS[tokens[tokenASymbol].decimals],
84
+ 6n * BI_POWS[tokens[tokenASymbol].decimals],
85
+ 7n * BI_POWS[tokens[tokenASymbol].decimals],
86
+ 8n * BI_POWS[tokens[tokenASymbol].decimals],
87
+ 9n * BI_POWS[tokens[tokenASymbol].decimals],
88
+ 10n * BI_POWS[tokens[tokenASymbol].decimals],
89
+ ];
90
+
91
+ const amountsForTokenB = [
92
+ 0n,
93
+ 1n * BI_POWS[tokens[tokenBSymbol].decimals],
94
+ 2n * BI_POWS[tokens[tokenBSymbol].decimals],
95
+ 3n * BI_POWS[tokens[tokenBSymbol].decimals],
96
+ 4n * BI_POWS[tokens[tokenBSymbol].decimals],
97
+ 5n * BI_POWS[tokens[tokenBSymbol].decimals],
98
+ 6n * BI_POWS[tokens[tokenBSymbol].decimals],
99
+ 7n * BI_POWS[tokens[tokenBSymbol].decimals],
100
+ 8n * BI_POWS[tokens[tokenBSymbol].decimals],
101
+ 9n * BI_POWS[tokens[tokenBSymbol].decimals],
102
+ 10n * BI_POWS[tokens[tokenBSymbol].decimals],
103
+ ];
104
+
105
+ beforeEach(async () => {
106
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
107
+ cables = new Cables(network, dexKey, dexHelper);
108
+ await cables.initializePricing(blockNumber);
109
+ await sleep(5000);
110
+ });
111
+
112
+ afterEach(async () => {
113
+ if (cables.releaseResources) cables.releaseResources();
114
+ await sleep(5000);
115
+ });
116
+
117
+ it(`getPoolIdentifiers and getPricesVolume SELL ${tokenASymbol} ${tokenBSymbol}`, async function () {
118
+ await testPricingOnNetwork(
119
+ cables,
120
+ network,
121
+ dexKey,
122
+ blockNumber,
123
+ tokenASymbol,
124
+ tokenBSymbol,
125
+ SwapSide.SELL,
126
+ amountsForTokenA,
127
+ );
128
+ });
129
+
130
+ it(`getPoolIdentifiers and getPricesVolume BUY ${tokenASymbol} ${tokenBSymbol}`, async function () {
131
+ await testPricingOnNetwork(
132
+ cables,
133
+ network,
134
+ dexKey,
135
+ blockNumber,
136
+ tokenASymbol,
137
+ tokenBSymbol,
138
+ SwapSide.BUY,
139
+ amountsForTokenB,
140
+ );
141
+ });
142
+
143
+ it(`getPoolIdentifiers and getPricesVolume SELL ${tokenBSymbol} ${tokenASymbol}`, async function () {
144
+ await testPricingOnNetwork(
145
+ cables,
146
+ network,
147
+ dexKey,
148
+ blockNumber,
149
+ tokenBSymbol,
150
+ tokenASymbol,
151
+ SwapSide.SELL,
152
+ amountsForTokenB,
153
+ );
154
+ });
155
+
156
+ it(`getPoolIdentifiers and getPricesVolume BUY ${tokenBSymbol} ${tokenASymbol}`, async function () {
157
+ await testPricingOnNetwork(
158
+ cables,
159
+ network,
160
+ dexKey,
161
+ blockNumber,
162
+ tokenBSymbol,
163
+ tokenASymbol,
164
+ SwapSide.BUY,
165
+ amountsForTokenA,
166
+ );
167
+ });
168
+
169
+ it.skip('getTopPoolsForToken', async function () {
170
+ // We have to check without calling initializePricing, because
171
+ // pool-tracker is not calling that function
172
+ const cables = new Cables(network, dexKey, dexHelper);
173
+ const poolLiquidity = await cables.getTopPoolsForToken(
174
+ tokens[tokenASymbol].address,
175
+ 10,
176
+ );
177
+ console.log(
178
+ `${tokenASymbol} Top Pools:`,
179
+ JSON.stringify(poolLiquidity, null, 2),
180
+ );
181
+ console.log(
182
+ `${tokenASymbol} Top Pools:`,
183
+ JSON.stringify(poolLiquidity, null, 2),
184
+ );
185
+
186
+ if (!cables.hasConstantPriceLargeAmounts) {
187
+ checkPoolsLiquidity(
188
+ poolLiquidity,
189
+ Tokens[network][tokenASymbol].address,
190
+ dexKey,
191
+ );
192
+ }
193
+ });
194
+ });
195
+
196
+ describe('Arbitrum', () => {
197
+ const network = Network.ARBITRUM;
198
+ const dexHelper = new DummyDexHelper(network);
199
+
200
+ const tokens = Tokens[network];
201
+
202
+ const tokenASymbol = 'USDC';
203
+ const tokenBSymbol = 'USDT';
204
+
205
+ const amountsForTokenA = [
206
+ 0n,
207
+ 1n * BI_POWS[tokens[tokenASymbol].decimals],
208
+ 2n * BI_POWS[tokens[tokenASymbol].decimals],
209
+ 3n * BI_POWS[tokens[tokenASymbol].decimals],
210
+ 4n * BI_POWS[tokens[tokenASymbol].decimals],
211
+ 5n * BI_POWS[tokens[tokenASymbol].decimals],
212
+ 6n * BI_POWS[tokens[tokenASymbol].decimals],
213
+ 7n * BI_POWS[tokens[tokenASymbol].decimals],
214
+ 8n * BI_POWS[tokens[tokenASymbol].decimals],
215
+ 9n * BI_POWS[tokens[tokenASymbol].decimals],
216
+ 10n * BI_POWS[tokens[tokenASymbol].decimals],
217
+ ];
218
+
219
+ const amountsForTokenB = [
220
+ 0n,
221
+ 1n * BI_POWS[tokens[tokenBSymbol].decimals],
222
+ 2n * BI_POWS[tokens[tokenBSymbol].decimals],
223
+ 3n * BI_POWS[tokens[tokenBSymbol].decimals],
224
+ 4n * BI_POWS[tokens[tokenBSymbol].decimals],
225
+ 5n * BI_POWS[tokens[tokenBSymbol].decimals],
226
+ 6n * BI_POWS[tokens[tokenBSymbol].decimals],
227
+ 7n * BI_POWS[tokens[tokenBSymbol].decimals],
228
+ 8n * BI_POWS[tokens[tokenBSymbol].decimals],
229
+ 9n * BI_POWS[tokens[tokenBSymbol].decimals],
230
+ 10n * BI_POWS[tokens[tokenBSymbol].decimals],
231
+ ];
232
+
233
+ beforeEach(async () => {
234
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
235
+ cables = new Cables(network, dexKey, dexHelper);
236
+ await cables.initializePricing(blockNumber);
237
+ await sleep(5000);
238
+ });
239
+
240
+ afterEach(async () => {
241
+ if (cables.releaseResources) cables.releaseResources();
242
+ await sleep(5000);
243
+ });
244
+
245
+ it(`getPoolIdentifiers and getPricesVolume SELL ${tokenASymbol} ${tokenBSymbol}`, async function () {
246
+ await testPricingOnNetwork(
247
+ cables,
248
+ network,
249
+ dexKey,
250
+ blockNumber,
251
+ tokenASymbol,
252
+ tokenBSymbol,
253
+ SwapSide.SELL,
254
+ amountsForTokenA,
255
+ );
256
+ });
257
+
258
+ it(`getPoolIdentifiers and getPricesVolume BUY ${tokenASymbol} ${tokenBSymbol}`, async function () {
259
+ await testPricingOnNetwork(
260
+ cables,
261
+ network,
262
+ dexKey,
263
+ blockNumber,
264
+ tokenASymbol,
265
+ tokenBSymbol,
266
+ SwapSide.BUY,
267
+ amountsForTokenB,
268
+ );
269
+ });
270
+
271
+ it(`getPoolIdentifiers and getPricesVolume SELL ${tokenBSymbol} ${tokenASymbol}`, async function () {
272
+ await testPricingOnNetwork(
273
+ cables,
274
+ network,
275
+ dexKey,
276
+ blockNumber,
277
+ tokenBSymbol,
278
+ tokenASymbol,
279
+ SwapSide.SELL,
280
+ amountsForTokenB,
281
+ );
282
+ });
283
+
284
+ it(`getPoolIdentifiers and getPricesVolume BUY ${tokenBSymbol} ${tokenASymbol}`, async function () {
285
+ await testPricingOnNetwork(
286
+ cables,
287
+ network,
288
+ dexKey,
289
+ blockNumber,
290
+ tokenBSymbol,
291
+ tokenASymbol,
292
+ SwapSide.BUY,
293
+ amountsForTokenA,
294
+ );
295
+ });
296
+
297
+ describe.skip('getTopPoolsForToken', () => {
298
+ it('USDC getTopPoolsForToken', async function () {
299
+ // We have to check without calling initializePricing, because
300
+ // pool-tracker is not calling that function
301
+ const tokenSymbol = 'USDC';
302
+ const cables = new Cables(network, dexKey, dexHelper);
303
+ const poolLiquidity = await cables.getTopPoolsForToken(
304
+ tokens[tokenSymbol].address,
305
+ 10,
306
+ );
307
+ console.log(
308
+ `${tokenASymbol} Top Pools:`,
309
+ JSON.stringify(poolLiquidity, null, 2),
310
+ );
311
+
312
+ if (!cables.hasConstantPriceLargeAmounts) {
313
+ checkPoolsLiquidity(
314
+ poolLiquidity,
315
+ Tokens[network][tokenASymbol].address,
316
+ dexKey,
317
+ );
318
+ }
319
+ });
320
+
321
+ it('WETH getTopPoolsForToken', async function () {
322
+ // We have to check without calling initializePricing, because
323
+ // pool-tracker is not calling that function
324
+ const tokenSymbol = 'WETH';
325
+ const cables = new Cables(network, dexKey, dexHelper);
326
+ const poolLiquidity = await cables.getTopPoolsForToken(
327
+ tokens[tokenSymbol].address,
328
+ 10,
329
+ );
330
+ console.log(
331
+ `${tokenASymbol} Top Pools:`,
332
+ JSON.stringify(poolLiquidity, null, 2),
333
+ );
334
+
335
+ if (!cables.hasConstantPriceLargeAmounts) {
336
+ checkPoolsLiquidity(
337
+ poolLiquidity,
338
+ Tokens[network][tokenASymbol].address,
339
+ dexKey,
340
+ );
341
+ }
342
+ });
343
+
344
+ it('ETH getTopPoolsForToken', async function () {
345
+ // We have to check without calling initializePricing, because
346
+ // pool-tracker is not calling that function
347
+ const tokenSymbol = 'ETH';
348
+ const cables = new Cables(network, dexKey, dexHelper);
349
+ const poolLiquidity = await cables.getTopPoolsForToken(
350
+ tokens[tokenSymbol].address,
351
+ 10,
352
+ );
353
+ console.log(
354
+ `${tokenASymbol} Top Pools:`,
355
+ JSON.stringify(poolLiquidity, null, 2),
356
+ );
357
+
358
+ if (!cables.hasConstantPriceLargeAmounts) {
359
+ checkPoolsLiquidity(
360
+ poolLiquidity,
361
+ Tokens[network][tokenASymbol].address,
362
+ dexKey,
363
+ );
364
+ }
365
+ });
366
+
367
+ it('ARB getTopPoolsForToken', async function () {
368
+ // We have to check without calling initializePricing, because
369
+ // pool-tracker is not calling that function
370
+ const tokenSymbol = 'ARB';
371
+ const cables = new Cables(network, dexKey, dexHelper);
372
+ const poolLiquidity = await cables.getTopPoolsForToken(
373
+ tokens[tokenSymbol].address,
374
+ 10,
375
+ );
376
+ console.log(
377
+ `${tokenASymbol} Top Pools:`,
378
+ JSON.stringify(poolLiquidity, null, 2),
379
+ );
380
+
381
+ if (!cables.hasConstantPriceLargeAmounts) {
382
+ checkPoolsLiquidity(
383
+ poolLiquidity,
384
+ Tokens[network][tokenASymbol].address,
385
+ dexKey,
386
+ );
387
+ }
388
+ });
389
+ });
390
+ });
391
+ });