@paraswap/dex-lib 3.11.4 → 3.11.5-cables.1

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.
@@ -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,183 @@
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: '1000000000000000000',
46
+ buyAmount: '1000000000000000000',
47
+ },
48
+ {
49
+ name: 'USDT',
50
+ sellAmount: '6000000',
51
+ buyAmount: '6000000',
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
+ tokens[pair[0].name],
64
+ tokens[pair[1].name],
65
+ holders[pair[0].name],
66
+ side === SwapSide.SELL
67
+ ? pair[0].sellAmount
68
+ : pair[0].buyAmount,
69
+ side,
70
+ dexKey,
71
+ contractMethod,
72
+ network,
73
+ provider,
74
+ undefined,
75
+ undefined,
76
+ undefined,
77
+ slippage,
78
+ sleepMs,
79
+ );
80
+ });
81
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
82
+ await testE2E(
83
+ tokens[pair[1].name],
84
+ tokens[pair[0].name],
85
+ holders[pair[1].name],
86
+ side === SwapSide.SELL
87
+ ? pair[1].sellAmount
88
+ : pair[1].buyAmount,
89
+ side,
90
+ dexKey,
91
+ contractMethod,
92
+ network,
93
+ provider,
94
+ undefined,
95
+ undefined,
96
+ undefined,
97
+ slippage,
98
+ sleepMs,
99
+ );
100
+ });
101
+ });
102
+ });
103
+ });
104
+ }),
105
+ );
106
+ });
107
+
108
+ describe('Avalanche', () => {
109
+ const network = Network.AVALANCHE;
110
+ const provider = new StaticJsonRpcProvider(
111
+ generateConfig(network).privateHttpProvider,
112
+ network,
113
+ );
114
+ const tokens = Tokens[network];
115
+ const holders = Holders[network];
116
+
117
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
118
+ [
119
+ {
120
+ name: 'USDC',
121
+ sellAmount: '1000000',
122
+ buyAmount: '700000',
123
+ },
124
+ {
125
+ name: 'USDT',
126
+ sellAmount: '1000000',
127
+ buyAmount: '850000',
128
+ },
129
+ ],
130
+ ];
131
+
132
+ sideToContractMethods.forEach((contractMethods, side) =>
133
+ describe(`${side}`, () => {
134
+ contractMethods.forEach((contractMethod: ContractMethod) => {
135
+ pairs.forEach(pair => {
136
+ describe(`${contractMethod}`, () => {
137
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
138
+ await testE2E(
139
+ tokens[pair[0].name],
140
+ tokens[pair[1].name],
141
+ holders[pair[0].name],
142
+ side === SwapSide.SELL
143
+ ? pair[0].sellAmount
144
+ : pair[0].buyAmount,
145
+ side,
146
+ dexKey,
147
+ contractMethod,
148
+ network,
149
+ provider,
150
+ undefined,
151
+ undefined,
152
+ undefined,
153
+ slippage,
154
+ sleepMs,
155
+ );
156
+ });
157
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
158
+ await testE2E(
159
+ tokens[pair[1].name],
160
+ tokens[pair[0].name],
161
+ holders[pair[1].name],
162
+ side === SwapSide.SELL
163
+ ? pair[1].sellAmount
164
+ : pair[1].buyAmount,
165
+ side,
166
+ dexKey,
167
+ contractMethod,
168
+ network,
169
+ provider,
170
+ undefined,
171
+ undefined,
172
+ undefined,
173
+ slippage,
174
+ sleepMs,
175
+ );
176
+ });
177
+ });
178
+ });
179
+ });
180
+ }),
181
+ );
182
+ });
183
+ });
@@ -0,0 +1,319 @@
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
+ });