@paraswap/dex-lib 3.11.7-cables.0 → 3.11.7

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.
@@ -1,207 +0,0 @@
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
- });
@@ -1,319 +0,0 @@
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('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
- it('getTopPoolsForToken', async function () {
298
- // We have to check without calling initializePricing, because
299
- // pool-tracker is not calling that function
300
- const cables = new Cables(network, dexKey, dexHelper);
301
- const poolLiquidity = await cables.getTopPoolsForToken(
302
- tokens[tokenASymbol].address,
303
- 10,
304
- );
305
- console.log(
306
- `${tokenASymbol} Top Pools:`,
307
- JSON.stringify(poolLiquidity, null, 2),
308
- );
309
-
310
- if (!cables.hasConstantPriceLargeAmounts) {
311
- checkPoolsLiquidity(
312
- poolLiquidity,
313
- Tokens[network][tokenASymbol].address,
314
- dexKey,
315
- );
316
- }
317
- });
318
- });
319
- });