@paraswap/dex-lib 2.42.23 → 2.42.24-smardex

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 (65) hide show
  1. package/build/abi/smardex/all/smardex-router.json +479 -0
  2. package/build/abi/smardex/layer-1/smardex-factory.json +176 -0
  3. package/build/abi/smardex/layer-1/smardex-pool.json +768 -0
  4. package/build/abi/smardex/layer-2/smardex-factory.json +265 -0
  5. package/build/abi/smardex/layer-2/smardex-pool.json +898 -0
  6. package/build/config.js +20 -10
  7. package/build/config.js.map +1 -1
  8. package/build/dex/dexalot/constants.js +1 -1
  9. package/build/dex/index.js +2 -0
  10. package/build/dex/index.js.map +1 -1
  11. package/build/dex/smardex/config.d.ts +4 -0
  12. package/build/dex/smardex/config.js +64 -0
  13. package/build/dex/smardex/config.js.map +1 -0
  14. package/build/dex/smardex/constants.d.ts +18 -0
  15. package/build/dex/smardex/constants.js +34 -0
  16. package/build/dex/smardex/constants.js.map +1 -0
  17. package/build/dex/smardex/sdk/constants.d.ts +6 -0
  18. package/build/dex/smardex/sdk/constants.js +13 -0
  19. package/build/dex/smardex/sdk/constants.js.map +1 -0
  20. package/build/dex/smardex/sdk/core.d.ts +113 -0
  21. package/build/dex/smardex/sdk/core.js +499 -0
  22. package/build/dex/smardex/sdk/core.js.map +1 -0
  23. package/build/dex/smardex/sdk/errors.d.ts +15 -0
  24. package/build/dex/smardex/sdk/errors.js +22 -0
  25. package/build/dex/smardex/sdk/errors.js.map +1 -0
  26. package/build/dex/smardex/sdk/types.d.ts +62 -0
  27. package/build/dex/smardex/sdk/types.js +3 -0
  28. package/build/dex/smardex/sdk/types.js.map +1 -0
  29. package/build/dex/smardex/sdk/utils.d.ts +44 -0
  30. package/build/dex/smardex/sdk/utils.js +133 -0
  31. package/build/dex/smardex/sdk/utils.js.map +1 -0
  32. package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
  33. package/build/dex/smardex/smardex-event-pool.js +135 -0
  34. package/build/dex/smardex/smardex-event-pool.js.map +1 -0
  35. package/build/dex/smardex/smardex.d.ts +66 -0
  36. package/build/dex/smardex/smardex.js +567 -0
  37. package/build/dex/smardex/smardex.js.map +1 -0
  38. package/build/dex/smardex/types.d.ts +55 -0
  39. package/build/dex/smardex/types.js +3 -0
  40. package/build/dex/smardex/types.js.map +1 -0
  41. package/build/types.d.ts +1 -0
  42. package/package.json +1 -1
  43. package/src/abi/smardex/all/smardex-router.json +479 -0
  44. package/src/abi/smardex/layer-1/smardex-factory.json +176 -0
  45. package/src/abi/smardex/layer-1/smardex-pool.json +768 -0
  46. package/src/abi/smardex/layer-2/smardex-factory.json +265 -0
  47. package/src/abi/smardex/layer-2/smardex-pool.json +898 -0
  48. package/src/config.ts +21 -10
  49. package/src/dex/dexalot/constants.ts +1 -1
  50. package/src/dex/index.ts +2 -0
  51. package/src/dex/smardex/config.ts +67 -0
  52. package/src/dex/smardex/constants.ts +36 -0
  53. package/src/dex/smardex/sdk/constants.ts +10 -0
  54. package/src/dex/smardex/sdk/core.ts +832 -0
  55. package/src/dex/smardex/sdk/errors.ts +18 -0
  56. package/src/dex/smardex/sdk/types.ts +68 -0
  57. package/src/dex/smardex/sdk/utils.ts +156 -0
  58. package/src/dex/smardex/smardex-e2e.test.ts +275 -0
  59. package/src/dex/smardex/smardex-event-pool.ts +185 -0
  60. package/src/dex/smardex/smardex-events.test.ts +296 -0
  61. package/src/dex/smardex/smardex-integration.test.ts +258 -0
  62. package/src/dex/smardex/smardex.ts +842 -0
  63. package/src/dex/smardex/types.ts +69 -0
  64. package/src/types.ts +1 -0
  65. package/tests/constants-e2e.ts +25 -0
@@ -0,0 +1,296 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ import { Interface } from '@ethersproject/abi';
4
+ import { Tokens } from '../../../tests/constants-e2e';
5
+ dotenv.config();
6
+
7
+ import SmardexPoolLayerOneABI from '../../abi/smardex/layer-1/smardex-pool.json';
8
+ import SmardexPoolLayerTwoABI from '../../abi/smardex/layer-2/smardex-pool.json';
9
+ import { Smardex, SmardexEventPool } from './smardex';
10
+ import { Network } from '../../constants';
11
+ import { DummyDexHelper } from '../../dex-helper/index';
12
+ import { testEventSubscriber } from '../../../tests/utils-events';
13
+ import { SmardexPoolState } from './types';
14
+
15
+ jest.setTimeout(120 * 1000);
16
+ const dexKey = 'Smardex';
17
+
18
+ type NetworkConfig = {
19
+ name: 'ethereum' | 'polygon' | 'bsc' | 'arbitrum' | 'base';
20
+ network: Network;
21
+ tokens: typeof Tokens[Network];
22
+ pools: Array<{
23
+ address: string;
24
+ symbol0: string;
25
+ symbol1: string;
26
+ events: {
27
+ [event: string]: number[];
28
+ };
29
+ }>;
30
+ };
31
+
32
+ const NETWORK_CONFIGS: NetworkConfig[] = [
33
+ {
34
+ name: 'ethereum',
35
+ network: Network.MAINNET,
36
+ tokens: Tokens[Network.MAINNET],
37
+ pools: [
38
+ {
39
+ address: '0xd2bf378cea07fe117ffdfd3f5b7e53c2b0b78c05',
40
+ symbol0: 'SDEX',
41
+ symbol1: 'USDT',
42
+ events: {
43
+ ['Swap']: [
44
+ 18064045,
45
+ 18064060,
46
+ 18064194,
47
+ 18065266,
48
+ 18066464, // the last one contains multiple Swap events
49
+ ],
50
+ ['Burn']: [17231921, 17762042, 17762668],
51
+ ['Mint']: [17739609, 17973926, 18062443],
52
+ // ['FeesChanged']: [], // none on L1
53
+ ['Sync']: [
54
+ 18064045,
55
+ 18064060,
56
+ 18064194,
57
+ 18065266,
58
+ 18066464, // the last one contains multiple Sync events
59
+ ],
60
+ ['Transfer']: [18064025, 18064045, 18065266],
61
+ },
62
+ },
63
+
64
+ {
65
+ address: '0xf3a4B8eFe3e3049F6BC71B47ccB7Ce6665420179',
66
+ symbol0: 'SDEX',
67
+ symbol1: 'ETH',
68
+ events: {
69
+ ['Swap']: [
70
+ 18120396,
71
+ 18120367, // multiple Swap events
72
+ 18119305,
73
+ 18118991,
74
+ 18120209,
75
+ ],
76
+ ['Burn']: [18114357, 18089610, 18026115],
77
+ ['Mint']: [18115825, 18109975, 18093408],
78
+ // ['FeesChanged']: [], // none on L1
79
+ ['Sync']: [
80
+ 18120396,
81
+ 18120367, // multiple Sync events
82
+ 18119305,
83
+ 18118991,
84
+ 18120209,
85
+ ],
86
+ ['Transfer']: [18108643, 18105778, 18105793],
87
+ },
88
+ },
89
+ ],
90
+ },
91
+ {
92
+ name: 'polygon',
93
+ network: Network.POLYGON,
94
+ tokens: Tokens[Network.POLYGON],
95
+ pools: [
96
+ {
97
+ address: '0x77476148B72ECB4E9f6A3cDDC5dd437Df1F003F3',
98
+ symbol0: 'USDC',
99
+ symbol1: 'SDEX',
100
+ events: {
101
+ ['Swap']: [47436997, 47437089, 47437096, 47445056, 47445066],
102
+ ['Burn']: [47423778, 47334674, 46807911],
103
+ ['Mint']: [47417315, 47414686, 47288517],
104
+ ['FeesChanged']: [45861051],
105
+ ['Sync']: [47436997, 47437089, 47437096, 47445056, 47445066],
106
+ ['Transfer']: [47423778, 47403369, 47343062],
107
+ },
108
+ },
109
+ {
110
+ address: '0x7130d1Ab6d9C657240331A4DE3e88b5497Be9cEB',
111
+ symbol0: 'WMATIC',
112
+ symbol1: 'USDC',
113
+ events: {
114
+ ['Swap']: [47448993, 47449888, 47449861, 47448993, 47449214],
115
+ ['Burn']: [47434291, 47433030, 47426957],
116
+ ['Mint']: [47354112, 47268128, 47252146],
117
+ ['FeesChanged']: [], // Fees didn't change on this pool
118
+ ['Sync']: [47448993, 47449888, 47449861, 47448993, 47449214],
119
+ ['Transfer']: [47338250, 47338178, 47333469],
120
+ },
121
+ },
122
+ ],
123
+ },
124
+ {
125
+ name: 'arbitrum',
126
+ network: Network.ARBITRUM,
127
+ tokens: Tokens[Network.ARBITRUM],
128
+ pools: [
129
+ {
130
+ address: '0xacCDd9EE1DCd393E346e5d6350230439b4DA09ab',
131
+ symbol0: 'SDEX',
132
+ symbol1: 'USDC',
133
+ events: {
134
+ ['Swap']: [130424308, 130422563, 130418994, 130415253, 130382808],
135
+ ['Burn']: [129969327, 129138853, 126200497],
136
+ ['Mint']: [130028302, 129940404, 129728771],
137
+ ['FeesChanged']: [], // Fees didn't change on this pool
138
+ ['Sync']: [130424308, 130422563, 130418994, 130415253, 130382808],
139
+ ['Transfer']: [130028373, 129918802, 129668897],
140
+ },
141
+ },
142
+ {
143
+ address: '0xD87899d10Eaa10F3adE05038A38251F758E5C0eb',
144
+ symbol0: 'ARB',
145
+ symbol1: 'USDC',
146
+ events: {
147
+ ['Swap']: [130429535, 130419879, 130417306, 130414469, 130416990],
148
+ ['Burn']: [130200966, 127933595, 125698828],
149
+ ['Mint']: [130263032, 130331095, 128594710],
150
+ ['FeesChanged']: [], // Fees didn't change on this pool
151
+ ['Sync']: [130429535, 130419879, 130417306, 130414469, 130416990],
152
+ ['Transfer']: [130423567, 130423514, 130331095],
153
+ },
154
+ },
155
+ ],
156
+ },
157
+ {
158
+ name: 'bsc',
159
+ network: Network.BSC,
160
+ tokens: Tokens[Network.BSC],
161
+ pools: [
162
+ {
163
+ address: '0xe7b89CbD4E833510F393CCfbE7D433EDbb137aB2',
164
+ symbol0: 'USDT',
165
+ symbol1: 'SDEX',
166
+ events: {
167
+ ['Swap']: [31678152, 31678000, 31674992, 31670581, 31675013],
168
+ ['Burn']: [31660547, 31655719, 31539131],
169
+ ['Mint']: [31652485, 31595468, 31571640],
170
+ ['FeesChanged']: [30531399],
171
+ ['Sync']: [31678152, 31678000, 31674992, 31670581, 31675013],
172
+ ['Transfer']: [31660547, 31655777, 31655736],
173
+ },
174
+ },
175
+ {
176
+ address: '0xf315833053a1187fd5e9813E38BD59937492857a',
177
+ symbol0: 'USDT',
178
+ symbol1: 'BNB',
179
+ events: {
180
+ ['Swap']: [31678534, 31675409, 31678534, 31675014, 31674391],
181
+ ['Burn']: [31666734, 31586726, 31462652],
182
+ ['Mint']: [31662048, 31554796, 31524123],
183
+ ['FeesChanged']: [], // Fees didn't change on this pool
184
+ ['Sync']: [31678534, 31675409, 31678534, 31675014, 31674391],
185
+ ['Transfer']: [31666734, 31632200, 31586970],
186
+ },
187
+ },
188
+ ],
189
+ },
190
+ {
191
+ name: 'base',
192
+ network: Network.BASE,
193
+ tokens: Tokens[Network.BASE],
194
+ pools: [
195
+ {
196
+ address: '0xd70e1bab713d84c3a110ded11e41714542e604ba',
197
+ symbol0: 'WETH',
198
+ symbol1: 'SDEX',
199
+ events: {
200
+ ['Swap']: [4761865, 4757945, 4757945, 4757897],
201
+ ['Burn']: [4692541],
202
+ ['Mint']: [4757945, 4737306, 4701199],
203
+ ['FeesChanged']: [], // Fees didn't change on this pool
204
+ ['Sync']: [4761865, 4757945, 4757945, 4757897],
205
+ ['Transfer']: [4757966, 4737315, 4736210],
206
+ },
207
+ },
208
+ {
209
+ address: '0x5a60c797993ee91f012260d995e1e6c6ce3dda6d',
210
+ symbol0: 'WETH',
211
+ symbol1: 'USDbC',
212
+ events: {
213
+ ['Swap']: [4763447, 4762313, 4762290],
214
+ ['Burn']: [4716925, 4338322, 4282294],
215
+ ['Mint']: [4758649, 4649129, 4645429],
216
+ ['FeesChanged']: [], // Fees didn't change on this pool
217
+ ['Sync']: [4763447, 4762313, 4762290],
218
+ ['Transfer']: [4758649, 4716850, 4645429],
219
+ },
220
+ },
221
+ ],
222
+ },
223
+ ];
224
+
225
+ async function fetchPoolStateFromContractAtBlock(
226
+ smardexEventPool: SmardexEventPool,
227
+ blockNumber: number,
228
+ poolAddress: string,
229
+ logger: any,
230
+ ): Promise<SmardexPoolState | undefined> {
231
+ const message = `Smardex: ${poolAddress} blockNumber ${blockNumber}`;
232
+ console.log(`Fetching state ${message}`);
233
+
234
+ const state = await smardexEventPool.generateState(blockNumber);
235
+ console.log(`Done ${message}`);
236
+
237
+ return state;
238
+ }
239
+
240
+ NETWORK_CONFIGS.forEach(({ name, network, pools, tokens }) => {
241
+ describe(`Events Tests on ${name}`, function () {
242
+ pools.forEach(({ address, events, symbol0, symbol1 }) => {
243
+ describe(`${symbol0} <> ${symbol1}`, function () {
244
+ const poolAddress = address;
245
+ const token0 = tokens[symbol0];
246
+ const token1 = tokens[symbol1];
247
+ // events in the same block must update the same element
248
+ Object.keys(events).forEach((event: string) => {
249
+ events[event].forEach((blockNumber: number) => {
250
+ it(`${event}:${blockNumber} - should return correct state`, async function () {
251
+ const dexHelper = new DummyDexHelper(network);
252
+
253
+ const logger = dexHelper.getLogger(dexKey);
254
+ const smardex = new Smardex(network, dexKey, dexHelper);
255
+ const multicall = smardex.getFeesMultiCallData(poolAddress);
256
+ const SmardexPool = new SmardexEventPool(
257
+ new Interface(
258
+ smardex.isLayer1()
259
+ ? SmardexPoolLayerOneABI
260
+ : SmardexPoolLayerTwoABI,
261
+ ),
262
+ dexHelper,
263
+ poolAddress,
264
+ token0,
265
+ token1,
266
+ logger,
267
+ multicall?.callEntry,
268
+ multicall?.callDecoder,
269
+ smardex.isLayer1(),
270
+ );
271
+
272
+ // It is done in generateState. But here have to make it manually
273
+ SmardexPool.poolAddress = poolAddress.toLowerCase();
274
+ SmardexPool.addressesSubscribed[0] = poolAddress.toLowerCase();
275
+
276
+ await testEventSubscriber(
277
+ SmardexPool,
278
+ SmardexPool.addressesSubscribed,
279
+ (_blockNumber: number) =>
280
+ fetchPoolStateFromContractAtBlock(
281
+ SmardexPool,
282
+ _blockNumber,
283
+ poolAddress,
284
+ logger,
285
+ ),
286
+ blockNumber,
287
+ `${dexKey}_${poolAddress}`,
288
+ dexHelper.provider,
289
+ );
290
+ });
291
+ });
292
+ });
293
+ });
294
+ });
295
+ });
296
+ });
@@ -0,0 +1,258 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { DummyDexHelper } from '../../dex-helper/index';
6
+ import { ETHER_ADDRESS, Network, SwapSide } from '../../constants';
7
+ import { BI_POWS } from '../../bigint-constants';
8
+ import { Smardex } from './smardex';
9
+ import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
10
+ import { Tokens } from '../../../tests/constants-e2e';
11
+
12
+ interface NetworkConfig {
13
+ name: 'ethereum' | 'bsc' | 'polygon' | 'arbitrum' | 'base';
14
+ network: Network;
15
+ tokens: typeof Tokens[Network];
16
+ tokenPairs: { src: string; dest: string; sell: number[]; buy: number[] }[];
17
+ }
18
+
19
+ const networkConfigs: Array<NetworkConfig> = [
20
+ {
21
+ name: 'ethereum',
22
+ network: Network.MAINNET,
23
+ tokens: Tokens[Network.MAINNET],
24
+ tokenPairs: [
25
+ {
26
+ src: 'SDEX',
27
+ dest: 'USDT',
28
+ sell: [0, 10_000, 20_000, 30_000],
29
+ buy: [0, 1_000, 2_000],
30
+ },
31
+ {
32
+ src: 'SDEX',
33
+ dest: 'WETH',
34
+ sell: [0, 100_000, 200_000, 300_000],
35
+ buy: [0, 1, 2, 3],
36
+ },
37
+ {
38
+ src: 'SDEX',
39
+ dest: 'ETH',
40
+ sell: [0, 100_000, 200_000, 300_000],
41
+ buy: [0, 1, 2, 3],
42
+ },
43
+ { src: 'WETH', dest: 'WBTC', sell: [0, 2, 4, 6], buy: [0, 1, 2, 3] },
44
+ ],
45
+ },
46
+ {
47
+ name: 'arbitrum',
48
+ network: Network.ARBITRUM,
49
+ tokens: Tokens[Network.ARBITRUM],
50
+ tokenPairs: [
51
+ {
52
+ src: 'SDEX',
53
+ dest: 'USDC',
54
+ sell: [0, 10_000, 20_000, 30_000],
55
+ buy: [0, 1_000, 2_000],
56
+ },
57
+ {
58
+ src: 'SDEX',
59
+ dest: 'WETH',
60
+ sell: [0, 100_000, 200_000, 300_000],
61
+ buy: [0, 1, 2, 3],
62
+ },
63
+ {
64
+ src: 'SDEX',
65
+ dest: 'ETH',
66
+ sell: [0, 100_000, 200_000, 300_000],
67
+ buy: [0, 1, 2, 3],
68
+ },
69
+ {
70
+ src: 'SDEX',
71
+ dest: 'WBTC',
72
+ sell: [0, 100_000, 200_000, 300_000],
73
+ buy: [0, 1, 2, 3],
74
+ },
75
+ {
76
+ src: 'ARB',
77
+ dest: 'USDC',
78
+ sell: [0, 2_000, 4_000, 6_000],
79
+ buy: [0, 1_000, 2_000],
80
+ },
81
+ ],
82
+ },
83
+ {
84
+ name: 'bsc',
85
+ network: Network.BSC,
86
+ tokens: Tokens[Network.BSC],
87
+ tokenPairs: [
88
+ {
89
+ src: 'SDEX',
90
+ dest: 'USDT',
91
+ sell: [0, 10_000, 20_000, 30_000],
92
+ buy: [0, 1_000, 2_000],
93
+ },
94
+ {
95
+ src: 'bBTC',
96
+ dest: 'SDEX',
97
+ sell: [0, 100_000, 200_000, 300_000],
98
+ buy: [0, 1, 2, 3],
99
+ },
100
+ {
101
+ src: 'USDT',
102
+ dest: 'WBNB',
103
+ sell: [0, 100_000, 200_000, 300_000],
104
+ buy: [0, 10, 20, 30],
105
+ },
106
+ { src: 'ETH', dest: 'SDEX', sell: [0, 2, 4, 6], buy: [0, 1, 2, 3] },
107
+ {
108
+ src: 'USDT',
109
+ dest: 'BNB',
110
+ sell: [0, 2_000, 4_000, 6_000],
111
+ buy: [0, 10, 20, 30],
112
+ },
113
+ ],
114
+ },
115
+ {
116
+ name: 'polygon',
117
+ network: Network.POLYGON,
118
+ tokens: Tokens[Network.POLYGON],
119
+ tokenPairs: [
120
+ {
121
+ src: 'USDC',
122
+ dest: 'SDEX',
123
+ sell: [0, 10_000, 20_000, 30_000],
124
+ buy: [0, 100_000, 200_000],
125
+ },
126
+ {
127
+ src: 'SDEX',
128
+ dest: 'WETH',
129
+ sell: [0, 100_000, 200_000, 300_000],
130
+ buy: [0, 2, 4, 6, 8, 10],
131
+ },
132
+ {
133
+ src: 'USDC',
134
+ dest: 'WMATIC',
135
+ sell: [0, 100_000, 200_000, 300_000],
136
+ buy: [0, 20_000, 40_000, 60_000],
137
+ },
138
+ {
139
+ src: 'USDC',
140
+ dest: 'MATIC',
141
+ sell: [0, 100_000, 200_000, 300_000],
142
+ buy: [0, 20_000, 40_000, 60_000],
143
+ },
144
+ {
145
+ src: 'WBTC',
146
+ dest: 'SDEX',
147
+ sell: [0, 1, 2, 3],
148
+ buy: [0, 500_000, 1_000_000, 1_500_000],
149
+ },
150
+ ],
151
+ },
152
+ {
153
+ name: 'base',
154
+ network: Network.BASE,
155
+ tokens: Tokens[Network.BASE],
156
+ tokenPairs: [
157
+ {
158
+ src: 'WETH',
159
+ dest: 'SDEX',
160
+ sell: [0, 2, 4, 6, 8, 10],
161
+ buy: [0, 100_000, 200_000, 300_000],
162
+ },
163
+ {
164
+ src: 'WETH',
165
+ dest: 'USDbC',
166
+ sell: [0, 2, 4, 6, 8, 10],
167
+ buy: [0, 10_000, 20_000, 30_000],
168
+ },
169
+ ],
170
+ },
171
+ ];
172
+
173
+ networkConfigs.forEach(({ name, network, tokens, tokenPairs }) => {
174
+ describe(`Smardex Integration Tests on ${name}`, () => {
175
+ const dexKey = 'Smardex';
176
+
177
+ let dexHelper: DummyDexHelper;
178
+ let blocknumber: number;
179
+
180
+ beforeEach(async () => {
181
+ dexHelper = new DummyDexHelper(network);
182
+ blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
183
+ });
184
+
185
+ // Help us to test the pool prices and volume for a given amount of tokens to swap
186
+ const testPoolPricesVolume = async (swapSide: SwapSide, pair: any) => {
187
+ const smardex = new Smardex(network, dexKey, dexHelper);
188
+ const currentAmounts =
189
+ swapSide === SwapSide.SELL
190
+ ? pair.sell.map(
191
+ (amount: number) =>
192
+ BigInt(amount) * BI_POWS[tokens[pair.src].decimals],
193
+ )
194
+ : pair.buy.map(
195
+ (amount: number) =>
196
+ BigInt(amount) * BI_POWS[tokens[pair.dest].decimals],
197
+ );
198
+
199
+ const pools = await smardex.getPoolIdentifiers(
200
+ tokens[pair.src],
201
+ tokens[pair.dest],
202
+ swapSide,
203
+ blocknumber,
204
+ );
205
+ console.log(`${pair.src} <> ${pair.dest} Pool Identifiers: `, pools);
206
+ expect(pools.length).toBeGreaterThan(0);
207
+
208
+ const poolPrices = await smardex.getPricesVolume(
209
+ tokens[pair.src],
210
+ tokens[pair.dest],
211
+ currentAmounts,
212
+ swapSide,
213
+ blocknumber,
214
+ pools,
215
+ );
216
+ console.log(`${pair.src} <> ${pair.dest} Pool Prices: `, poolPrices);
217
+ expect(poolPrices).not.toBeNull();
218
+ checkPoolPrices(poolPrices!, currentAmounts, swapSide, dexKey);
219
+ };
220
+
221
+ /**
222
+ * For each token pair, test:
223
+ * - Compute pool identifiers and prices for a given amount of tokens to swap (SELL and BUY)
224
+ * - Get top pools for a token
225
+ */
226
+ tokenPairs.forEach(pair => {
227
+ describe(`${pair.src} <> ${pair.dest}`, () => {
228
+ it('SELL: Compute pool identiers and prices', async () => {
229
+ await testPoolPricesVolume(SwapSide.SELL, pair);
230
+ });
231
+
232
+ it('BUY: Compute pool identiers and prices', async () => {
233
+ await testPoolPricesVolume(SwapSide.BUY, pair);
234
+ });
235
+ });
236
+ });
237
+
238
+ it('getTopPoolsForToken', async () => {
239
+ const smardex = new Smardex(network, dexKey, dexHelper);
240
+ // Get all distinct tokens of the pairs
241
+ const distinctTokens = tokenPairs
242
+ .reduce((acc, pair) => [...acc, pair.src, pair.dest], [] as string[])
243
+ .filter((value, index, self) => self.indexOf(value) === index)
244
+ // Native token doesn't have a pool, avoid it
245
+ .filter(token => tokens[token].address !== ETHER_ADDRESS);
246
+ // Get top pools for each token and check liquidity
247
+ await Promise.all(
248
+ distinctTokens.map(async token =>
249
+ checkPoolsLiquidity(
250
+ await smardex.getTopPoolsForToken(tokens[token].address, 10),
251
+ tokens[token].address,
252
+ dexKey,
253
+ ),
254
+ ),
255
+ );
256
+ });
257
+ });
258
+ });