@paraswap/dex-lib 2.33.1-equalizer → 2.33.1-nomiswap-v2

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.
package/src/dex/index.ts CHANGED
@@ -51,7 +51,6 @@ import { SpiritSwapV2 } from './solidly/forks-override/spiritSwapV2';
51
51
  import { Synthetix } from './synthetix/synthetix';
52
52
  import { Cone } from './solidly/forks-override/cone';
53
53
  import { SoliSnek } from './solidly/forks-override/solisnek';
54
- import { Equalizer } from './solidly/forks-override/equalizer';
55
54
  import { BalancerV1 } from './balancer-v1/balancer-v1';
56
55
  import { balancerV1Merge } from './balancer-v1/optimizer';
57
56
  import { CurveV1 } from './curve-v1/curve-v1';
@@ -73,6 +72,7 @@ import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
73
72
  import { TraderJoeV21 } from './trader-joe-v2.1';
74
73
  import { PancakeswapV3 } from './pancakeswap-v3/pancakeswap-v3';
75
74
  import { Algebra } from './algebra/algebra';
75
+ import { NomiswapV2 } from './uniswap-v2/nomiswap-v2';
76
76
 
77
77
  const LegacyDexes = [
78
78
  CurveV2,
@@ -134,7 +134,6 @@ const Dexes = [
134
134
  VelodromeV2,
135
135
  Cone,
136
136
  SoliSnek,
137
- Equalizer,
138
137
  Synthetix,
139
138
  CurveV1Factory,
140
139
  SwaapV1,
@@ -143,6 +142,7 @@ const Dexes = [
143
142
  MaverickV1,
144
143
  Camelot,
145
144
  SwaapV2,
145
+ NomiswapV2,
146
146
  ];
147
147
 
148
148
  export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
@@ -148,16 +148,6 @@ export const SolidlyConfig: DexConfigMap<DexParams> = {
148
148
  feeCode: 0,
149
149
  },
150
150
  },
151
- Equalizer: {
152
- [Network.FANTOM]: {
153
- factoryAddress: '0xc6366EFD0AF1d09171fe0EBF32c7943BB310832a',
154
- router: '0x93d2611EB8b85bE4FDEa9D94Ce9913D90072eC0f',
155
- initCode:
156
- '0x02ada2a0163cd4f7e0f0c9805f5230716a95b174140e4c84c14883de216cc6a3',
157
- feeCode: 0,
158
- poolGasCost: 180 * 1000,
159
- },
160
- },
161
151
  };
162
152
 
163
153
  export const Adapters: Record<number, AdapterMappings> = {
@@ -165,7 +155,7 @@ export const Adapters: Record<number, AdapterMappings> = {
165
155
  [SwapSide.SELL]: [{ name: 'PolygonAdapter02', index: 3 }], // dystopia
166
156
  },
167
157
  [Network.FANTOM]: {
168
- [SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 10 }], // solidly + spiritSwapV2 + Equalizer
158
+ [SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 10 }], // solidly + spiritSwapV2
169
159
  },
170
160
  [Network.OPTIMISM]: {
171
161
  [SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 8 }], // velodrome
@@ -389,29 +389,6 @@ describe('Solidly E2E', () => {
389
389
  });
390
390
  });
391
391
  });
392
-
393
- describe('Equalizer', () => {
394
- const dexKey = 'Equalizer';
395
- const network = Network.FANTOM;
396
-
397
- const tokenASymbol: string = 'FUSDT';
398
- const tokenBSymbol: string = 'USDC';
399
-
400
- const tokenAAmount: string = '111110';
401
- const tokenBAmount: string = '100000';
402
- const nativeTokenAmount = '11000000000000000';
403
-
404
- testForNetwork(
405
- network,
406
- dexKey,
407
- tokenASymbol,
408
- tokenBSymbol,
409
- tokenAAmount,
410
- tokenBAmount,
411
- nativeTokenAmount,
412
- );
413
-
414
- });
415
392
  });
416
393
 
417
394
  describe('Mainnet', () => {
@@ -15,7 +15,6 @@ import { Chronos } from './forks-override/chronos';
15
15
  import { Ramses } from './forks-override/ramses';
16
16
  import * as util from 'util';
17
17
  import { VelodromeV2 } from './forks-override/velodromeV2';
18
- import { Equalizer } from './forks-override/equalizer';
19
18
 
20
19
  const amounts18 = [0n, BI_POWS[18], 2000000000000000000n];
21
20
  const amounts6 = [0n, BI_POWS[6], 2000000n];
@@ -354,120 +353,6 @@ describe('Solidly integration tests', () => {
354
353
  });
355
354
  });
356
355
  });
357
-
358
- describe('Equalizer', () => {
359
- const dexKey = 'Equalizer';
360
- const equalizer = new Equalizer(network, dexKey, dexHelper);
361
-
362
- describe('UniswapV2 like pool', function () {
363
- const TokenASymbol = 'WFTM';
364
- const tokenA = Tokens[network][TokenASymbol];
365
- const TokenBSymbol = 'FUSDT';
366
- const tokenB = Tokens[network][TokenBSymbol];
367
-
368
- const amounts = amounts18;
369
-
370
- it('getPoolIdentifiers and getPricesVolume', async function () {
371
- const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
372
- const pools = await equalizer.getPoolIdentifiers(
373
- tokenA,
374
- tokenB,
375
- SwapSide.SELL,
376
- blocknumber,
377
- );
378
- console.log(
379
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
380
- pools,
381
- );
382
-
383
- expect(pools.length).toBeGreaterThan(0);
384
-
385
- const poolPrices = await equalizer.getPricesVolume(
386
- tokenA,
387
- tokenB,
388
- amounts,
389
- SwapSide.SELL,
390
- blocknumber,
391
- pools,
392
- );
393
- console.log(
394
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
395
- poolPrices,
396
- );
397
-
398
- expect(poolPrices).not.toBeNull();
399
- checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
400
-
401
- // Check if onchain pricing equals to calculated ones
402
-
403
- for (const i in poolPrices || []) {
404
- await checkOnChainPricing(
405
- equalizer,
406
- 'getAmountOut',
407
- blocknumber,
408
- poolPrices![i].prices,
409
- poolPrices![i].poolAddresses![0],
410
- tokenA.address,
411
- amounts,
412
- );
413
- }
414
- });
415
- });
416
-
417
- describe('Curve like stable pool', function () {
418
- const TokenASymbol = 'FUSDT';
419
- const tokenA = Tokens[network][TokenASymbol];
420
- const TokenBSymbol = 'USDC';
421
- const tokenB = Tokens[network][TokenBSymbol];
422
-
423
- const amounts = amounts6; // amounts6;
424
-
425
- it('getPoolIdentifiers and getPricesVolume', async function () {
426
- const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
427
- const pools = await equalizer.getPoolIdentifiers(
428
- tokenA,
429
- tokenB,
430
- SwapSide.SELL,
431
- blocknumber,
432
- );
433
- console.log(
434
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
435
- pools,
436
- );
437
-
438
- expect(pools.length).toBeGreaterThan(0);
439
-
440
- const poolPrices = await equalizer.getPricesVolume(
441
- tokenA,
442
- tokenB,
443
- amounts,
444
- SwapSide.SELL,
445
- blocknumber,
446
- pools,
447
- );
448
- console.log(
449
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
450
- poolPrices,
451
- );
452
-
453
- expect(poolPrices).not.toBeNull();
454
- checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
455
-
456
- // Check if onchain pricing equals to calculated ones
457
- for (const i in poolPrices || []) {
458
- await checkOnChainPricing(
459
- equalizer,
460
- 'getAmountOut',
461
- blocknumber,
462
- poolPrices![i].prices,
463
- poolPrices![i].poolAddresses![0],
464
- tokenA.address,
465
- amounts,
466
- );
467
- }
468
- });
469
- });
470
- });
471
356
  });
472
357
 
473
358
  describe('Polygon', () => {
@@ -74,7 +74,6 @@ export class Solidly extends UniswapV2 {
74
74
  'SoliSnek',
75
75
  'Chronos',
76
76
  'Ramses',
77
- 'Equalizer',
78
77
  ]),
79
78
  );
80
79
 
@@ -0,0 +1,62 @@
1
+ import { Network } from '../../constants';
2
+ import { getDexKeysWithNetwork } from '../../utils';
3
+ import { IDexHelper } from '../../dex-helper/idex-helper';
4
+ import { UniswapV2, UniswapV2Pair } from '../uniswap-v2/uniswap-v2';
5
+ import { Interface } from '@ethersproject/abi';
6
+ import NomiswapPoolABI from '../../abi/nomiswap-v2/nomiswap-v2-pool.json';
7
+ import { DexParams } from './types';
8
+ import { DexConfigMap } from '../../types';
9
+
10
+ export const NomiswapV2Config: DexConfigMap<DexParams> = {
11
+ NomiswapV2: {
12
+ [Network.BSC]: {
13
+ factoryAddress: '0xd6715A8be3944ec72738F0BFDC739d48C3c29349',
14
+ initCode:
15
+ '0x83eb759f5ea0525124f03d4ac741bb4af0bb1c703d5f694bd42a8bd72e495a01',
16
+ poolGasCost: 120 * 1000,
17
+ feeCode: 0, // this is ignored as Nomiswap uses dynamic fees,
18
+ subgraphURL: 'https://api.thegraph.com/subgraphs/name/nominex/nomiswap-exchange-subgraph',
19
+ },
20
+ },
21
+ };
22
+
23
+ export class NomiswapV2 extends UniswapV2 {
24
+ nomiswapPool: Interface;
25
+
26
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
27
+ getDexKeysWithNetwork(NomiswapV2Config);
28
+
29
+ constructor(
30
+ protected network: Network,
31
+ dexKey: string,
32
+ protected dexHelper: IDexHelper,
33
+ ) {
34
+ super(
35
+ network,
36
+ dexKey,
37
+ dexHelper,
38
+ true,
39
+ NomiswapV2Config[dexKey][network].factoryAddress,
40
+ NomiswapV2Config[dexKey][network].subgraphURL,
41
+ NomiswapV2Config[dexKey][network].initCode,
42
+ NomiswapV2Config[dexKey][network].feeCode,
43
+ NomiswapV2Config[dexKey][network].poolGasCost,
44
+ );
45
+ this.nomiswapPool = new Interface(NomiswapPoolABI);
46
+ }
47
+
48
+ protected getFeesMultiCallData(pair: UniswapV2Pair) {
49
+ const callEntry = {
50
+ target: pair.exchange!,
51
+ callData: this.nomiswapPool.encodeFunctionData('swapFee', []),
52
+ };
53
+ const callDecoder = (values: any[]) =>
54
+ parseInt(
55
+ this.nomiswapPool.decodeFunctionResult('swapFee', values)[0].toString(),
56
+ ) * 10;
57
+ return {
58
+ callEntry,
59
+ callDecoder,
60
+ };
61
+ }
62
+ }
@@ -2,11 +2,110 @@ import dotenv from 'dotenv';
2
2
  dotenv.config();
3
3
 
4
4
  import { testE2E } from '../../../tests/utils-e2e';
5
- import { Tokens, Holders } from '../../../tests/constants-e2e';
5
+ import { Tokens, Holders, NativeTokenSymbols } from '../../../tests/constants-e2e';
6
6
  import { Network, ContractMethod, SwapSide } from '../../constants';
7
7
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
8
8
  import { generateConfig } from '../../config';
9
9
 
10
+ function testForNetwork(
11
+ network: Network,
12
+ dexKey: string,
13
+ tokenASymbol: string,
14
+ tokenBSymbol: string,
15
+ tokenAAmount: string,
16
+ tokenBAmount: string,
17
+ nativeTokenAmount: string,
18
+ slippage?: number | undefined,
19
+ ) {
20
+ const provider = new StaticJsonRpcProvider(
21
+ generateConfig(network).privateHttpProvider,
22
+ network,
23
+ );
24
+ const tokens = Tokens[network];
25
+ const holders = Holders[network];
26
+ const nativeTokenSymbol = NativeTokenSymbols[network];
27
+
28
+ const sideToContractMethods = new Map([
29
+ [
30
+ SwapSide.SELL,
31
+ [
32
+ ContractMethod.simpleSwap,
33
+ ContractMethod.multiSwap,
34
+ ContractMethod.megaSwap,
35
+ ],
36
+ ],
37
+ [
38
+ SwapSide.BUY,
39
+ [
40
+ ContractMethod.simpleBuy,
41
+ ContractMethod.buy,
42
+ ],
43
+ ],
44
+ ]);
45
+
46
+ describe(`${network}`, () => {
47
+ sideToContractMethods.forEach((contractMethods, side) =>
48
+ describe(`${side}`, () => {
49
+ contractMethods.forEach((contractMethod: ContractMethod) => {
50
+ describe(`${contractMethod}`, () => {
51
+ it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
52
+ await testE2E(
53
+ tokens[nativeTokenSymbol],
54
+ tokens[tokenASymbol],
55
+ holders[nativeTokenSymbol],
56
+ side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
57
+ side,
58
+ dexKey,
59
+ contractMethod,
60
+ network,
61
+ provider,
62
+ undefined,
63
+ undefined,
64
+ undefined,
65
+ slippage,
66
+ );
67
+ });
68
+ it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
69
+ await testE2E(
70
+ tokens[tokenASymbol],
71
+ tokens[nativeTokenSymbol],
72
+ holders[tokenASymbol],
73
+ side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
74
+ side,
75
+ dexKey,
76
+ contractMethod,
77
+ network,
78
+ provider,
79
+ undefined,
80
+ undefined,
81
+ undefined,
82
+ slippage,
83
+ );
84
+ });
85
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
86
+ await testE2E(
87
+ tokens[tokenASymbol],
88
+ tokens[tokenBSymbol],
89
+ holders[tokenASymbol],
90
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
91
+ side,
92
+ dexKey,
93
+ contractMethod,
94
+ network,
95
+ provider,
96
+ undefined,
97
+ undefined,
98
+ undefined,
99
+ slippage,
100
+ );
101
+ });
102
+ });
103
+ });
104
+ }),
105
+ );
106
+ });
107
+ }
108
+
10
109
  describe('UniswapV2 E2E BSC', () => {
11
110
  const network = Network.BSC;
12
111
  const tokens = Tokens[network];
@@ -1407,6 +1506,28 @@ describe('UniswapV2 E2E BSC', () => {
1407
1506
  });
1408
1507
  });
1409
1508
 
1509
+ describe('NomiswapV2', () => {
1510
+ const dexKey = 'NomiswapV2';
1511
+ const network = Network.BSC;
1512
+
1513
+ const tokenASymbol: string = 'USDC';
1514
+ const tokenBSymbol: string = 'USDT';
1515
+
1516
+ const tokenAAmount: string = '1111100000';
1517
+ const tokenBAmount: string = '1000000000';
1518
+ const nativeTokenAmount = '11000000000000';
1519
+
1520
+ testForNetwork(
1521
+ network,
1522
+ dexKey,
1523
+ tokenASymbol,
1524
+ tokenBSymbol,
1525
+ tokenAAmount,
1526
+ tokenBAmount,
1527
+ nativeTokenAmount,
1528
+ );
1529
+ });
1530
+
1410
1531
  describe(`Swapsicle`, () => {
1411
1532
  const dexKey = 'Swapsicle';
1412
1533
 
@@ -112,7 +112,6 @@ function testForNetwork(
112
112
  });
113
113
  }
114
114
 
115
-
116
115
  describe('UniswapV3 E2E', () => {
117
116
 
118
117
  describe('UniswapV3', () => {
@@ -1,58 +0,0 @@
1
- import { Solidly } from '../solidly';
2
- import { SolidlyPair } from '../types';
3
- import { Network } from '../../../constants';
4
- import { IDexHelper } from '../../../dex-helper';
5
- import { Interface } from '@ethersproject/abi';
6
- import { getDexKeysWithNetwork } from '../../../utils';
7
- import { SolidlyConfig } from '../config';
8
- import _ from 'lodash';
9
-
10
- const EqualizerFactoryABI = [
11
- {
12
- inputs: [{ internalType: 'bool', name: '_stable', type: 'bool' }],
13
- name: 'getFee',
14
- outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
15
- stateMutability: 'view',
16
- type: 'function',
17
- },
18
- ];
19
-
20
- const equalizerFactoryIface = new Interface(EqualizerFactoryABI);
21
-
22
- export class Equalizer extends Solidly {
23
- public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
24
- getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Equalizer']));
25
-
26
- constructor(
27
- protected network: Network,
28
- dexKey: string,
29
- protected dexHelper: IDexHelper,
30
- ) {
31
- super(
32
- network,
33
- dexKey,
34
- dexHelper,
35
- true, // dynamic fees
36
- );
37
- }
38
-
39
- protected getFeesMultiCallData(pair: SolidlyPair) {
40
- const callEntry = {
41
- target: this.factoryAddress,
42
- callData: equalizerFactoryIface.encodeFunctionData('getFee', [
43
- pair.stable,
44
- ]),
45
- };
46
- const callDecoder = (values: any[]) =>
47
- parseInt(
48
- equalizerFactoryIface
49
- .decodeFunctionResult('getFee', values)[0]
50
- .toString(),
51
- );
52
-
53
- return {
54
- callEntry,
55
- callDecoder,
56
- };
57
- }
58
- }