@paraswap/dex-lib 2.33.0 → 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
@@ -72,6 +72,7 @@ import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
72
72
  import { TraderJoeV21 } from './trader-joe-v2.1';
73
73
  import { PancakeswapV3 } from './pancakeswap-v3/pancakeswap-v3';
74
74
  import { Algebra } from './algebra/algebra';
75
+ import { NomiswapV2 } from './uniswap-v2/nomiswap-v2';
75
76
 
76
77
  const LegacyDexes = [
77
78
  CurveV2,
@@ -141,6 +142,7 @@ const Dexes = [
141
142
  MaverickV1,
142
143
  Camelot,
143
144
  SwaapV2,
145
+ NomiswapV2,
144
146
  ];
145
147
 
146
148
  export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
@@ -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', () => {