@paraswap/dex-lib 2.42.26 → 2.42.27

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