@paraswap/dex-lib 2.41.4 → 2.42.0-traderjoe-mainnet

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 (30) hide show
  1. package/build/abi/polygon-migration/PolygonMigration.abi.json +364 -0
  2. package/build/config.js +2 -2
  3. package/build/dex/index.js +2 -0
  4. package/build/dex/index.js.map +1 -1
  5. package/build/dex/polygon-migrator/config.d.ts +11 -0
  6. package/build/dex/polygon-migrator/config.js +21 -0
  7. package/build/dex/polygon-migrator/config.js.map +1 -0
  8. package/build/dex/polygon-migrator/constants.d.ts +1 -0
  9. package/build/dex/polygon-migrator/constants.js +5 -0
  10. package/build/dex/polygon-migrator/constants.js.map +1 -0
  11. package/build/dex/polygon-migrator/polygon-migrator.d.ts +48 -0
  12. package/build/dex/polygon-migrator/polygon-migrator.js +114 -0
  13. package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -0
  14. package/build/dex/polygon-migrator/types.d.ts +11 -0
  15. package/build/dex/polygon-migrator/types.js +9 -0
  16. package/build/dex/polygon-migrator/types.js.map +1 -0
  17. package/build/dex/trader-joe-v2.1.js +1 -0
  18. package/build/dex/trader-joe-v2.1.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/abi/polygon-migration/PolygonMigration.abi.json +364 -0
  21. package/src/config.ts +2 -2
  22. package/src/dex/index.ts +2 -0
  23. package/src/dex/polygon-migrator/config.ts +25 -0
  24. package/src/dex/polygon-migrator/constants.ts +1 -0
  25. package/src/dex/polygon-migrator/polygon-migrator-e2e.test.ts +96 -0
  26. package/src/dex/polygon-migrator/polygon-migrator-integration.test.ts +139 -0
  27. package/src/dex/polygon-migrator/polygon-migrator.ts +167 -0
  28. package/src/dex/polygon-migrator/types.ts +14 -0
  29. package/src/dex/trader-joe-v2.1.ts +1 -0
  30. package/tests/constants-e2e.ts +10 -0
@@ -0,0 +1,167 @@
1
+ import { SimpleExchange } from '../simple-exchange';
2
+ import { IDex } from '../idex';
3
+ import {
4
+ DexParams,
5
+ PolygonMigrationData,
6
+ PolygonMigratorFunctions,
7
+ } from './types';
8
+ import { Network, SwapSide } from '../../constants';
9
+ import { getDexKeysWithNetwork } from '../../utils';
10
+ import { Adapters, PolygonMigratorConfig } from './config';
11
+ import {
12
+ AdapterExchangeParam,
13
+ Address,
14
+ ExchangePrices,
15
+ Logger,
16
+ PoolLiquidity,
17
+ PoolPrices,
18
+ SimpleExchangeParam,
19
+ Token,
20
+ } from '../../types';
21
+ import { IDexHelper } from '../../dex-helper';
22
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
23
+ import { BI_POWS } from '../../bigint-constants';
24
+ import { POLYGON_MIGRATION_GAS_COST } from './constants';
25
+ import PolygonMigrationAbi from '../../abi/polygon-migration/PolygonMigration.abi.json';
26
+ import { Interface } from 'ethers/lib/utils';
27
+
28
+ export class PolygonMigrator
29
+ extends SimpleExchange
30
+ implements IDex<PolygonMigrationData, DexParams>
31
+ {
32
+ readonly hasConstantPriceLargeAmounts = true;
33
+ readonly isFeeOnTransferSupported = false;
34
+
35
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
36
+ getDexKeysWithNetwork(PolygonMigratorConfig);
37
+
38
+ logger: Logger;
39
+
40
+ constructor(
41
+ protected network: Network,
42
+ dexKey: string,
43
+ protected dexHelper: IDexHelper,
44
+ readonly migratorAddress: string = PolygonMigratorConfig[dexKey][network]
45
+ .migratorAddress,
46
+ readonly polTokenAddress: string = PolygonMigratorConfig[dexKey][network]
47
+ .polTokenAddress,
48
+ readonly maticTokenAddress: string = PolygonMigratorConfig[dexKey][network]
49
+ .maticTokenAddress,
50
+ protected unitPrice = BI_POWS[18],
51
+ protected adapters = Adapters[network] || {},
52
+ protected migratorInterface = new Interface(PolygonMigrationAbi),
53
+ ) {
54
+ super(dexHelper, dexKey);
55
+ this.logger = dexHelper.getLogger(dexKey);
56
+ }
57
+
58
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
59
+ return this.adapters[side] || null;
60
+ }
61
+
62
+ isMatic(tokenAddress: Address) {
63
+ return this.maticTokenAddress.toLowerCase() === tokenAddress.toLowerCase();
64
+ }
65
+
66
+ isPol(tokenAddress: Address) {
67
+ return this.polTokenAddress.toLowerCase() === tokenAddress.toLowerCase();
68
+ }
69
+
70
+ isAppropriatePair(srcToken: Token, destToken: Token) {
71
+ return (
72
+ (this.isMatic(srcToken.address) && this.isPol(destToken.address)) ||
73
+ (this.isMatic(destToken.address) && this.isPol(srcToken.address))
74
+ );
75
+ }
76
+
77
+ async getPoolIdentifiers(
78
+ srcToken: Token,
79
+ destToken: Token,
80
+ side: SwapSide,
81
+ blockNumber: number,
82
+ ): Promise<string[]> {
83
+ if (this.isAppropriatePair(srcToken, destToken)) {
84
+ return [`${this.dexKey}_${srcToken.address}_${destToken.address}`];
85
+ }
86
+
87
+ return [];
88
+ }
89
+
90
+ async getPricesVolume(
91
+ srcToken: Token,
92
+ destToken: Token,
93
+ amounts: bigint[],
94
+ side: SwapSide,
95
+ blockNumber: number,
96
+ limitPools?: string[],
97
+ ): Promise<null | ExchangePrices<PolygonMigrationData>> {
98
+ if (!this.isAppropriatePair(srcToken, destToken)) {
99
+ return null;
100
+ }
101
+
102
+ return [
103
+ {
104
+ prices: amounts,
105
+ unit: this.unitPrice,
106
+ gasCost: POLYGON_MIGRATION_GAS_COST,
107
+ exchange: this.dexKey,
108
+ poolAddresses: [this.migratorAddress],
109
+ data: null,
110
+ },
111
+ ];
112
+ }
113
+
114
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
115
+ getCalldataGasCost(
116
+ poolPrices: PoolPrices<PolygonMigrationData>,
117
+ ): number | number[] {
118
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
119
+ }
120
+
121
+ getAdapterParam(
122
+ srcToken: string,
123
+ destToken: string,
124
+ srcAmount: string,
125
+ destAmount: string,
126
+ data: PolygonMigrationData,
127
+ side: SwapSide,
128
+ ): AdapterExchangeParam {
129
+ return {
130
+ targetExchange: this.migratorAddress,
131
+ payload: '0x',
132
+ networkFee: '0',
133
+ };
134
+ }
135
+
136
+ async getSimpleParam(
137
+ srcToken: string,
138
+ destToken: string,
139
+ srcAmount: string,
140
+ destAmount: string,
141
+ data: PolygonMigrationData,
142
+ side: SwapSide,
143
+ ): Promise<SimpleExchangeParam> {
144
+ const swapData = this.migratorInterface.encodeFunctionData(
145
+ this.isMatic(srcToken)
146
+ ? PolygonMigratorFunctions.migrate
147
+ : PolygonMigratorFunctions.unmigrate,
148
+ [srcAmount],
149
+ );
150
+
151
+ return this.buildSimpleParamWithoutWETHConversion(
152
+ srcToken,
153
+ srcAmount,
154
+ destToken,
155
+ destAmount,
156
+ swapData,
157
+ this.migratorAddress,
158
+ );
159
+ }
160
+
161
+ async getTopPoolsForToken(
162
+ tokenAddress: Address,
163
+ limit: number,
164
+ ): Promise<PoolLiquidity[]> {
165
+ return [];
166
+ }
167
+ }
@@ -0,0 +1,14 @@
1
+ import { Address } from '../../types';
2
+
3
+ export type PolygonMigrationData = null;
4
+
5
+ export type DexParams = {
6
+ migratorAddress: Address;
7
+ polTokenAddress: Address;
8
+ maticTokenAddress: Address;
9
+ };
10
+
11
+ export enum PolygonMigratorFunctions {
12
+ migrate = 'migrate',
13
+ unmigrate = 'unmigrate',
14
+ }
@@ -15,6 +15,7 @@ const TRADERJOE_V2_1_ROUTER_ADDRESS: { [network: number]: Address } = {
15
15
  [Network.AVALANCHE]: '0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30',
16
16
  [Network.ARBITRUM]: '0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30',
17
17
  [Network.BSC]: '0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30',
18
+ [Network.MAINNET]: '0x9A93a421b74F1c5755b83dD2C211614dC419C44b',
18
19
  };
19
20
 
20
21
  type RouterPath = [
@@ -311,6 +311,14 @@ export const Tokens: {
311
311
  address: '0x8751d4196027d4e6da63716fa7786b5174f04c15',
312
312
  decimals: 18,
313
313
  },
314
+ MATIC: {
315
+ address: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0',
316
+ decimals: 18,
317
+ },
318
+ POL: {
319
+ address: '0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6',
320
+ decimals: 19,
321
+ },
314
322
  },
315
323
  [Network.ROPSTEN]: {
316
324
  DAI: {
@@ -1008,6 +1016,8 @@ export const Holders: {
1008
1016
  crvUSD: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1009
1017
  GHO: '0x844Dc85EdD8492A56228D293cfEbb823EF3E10EC',
1010
1018
  wibBTC: '0xFbdCA68601f835b27790D98bbb8eC7f05FDEaA9B',
1019
+ MATIC: '0x7073783eee7e9b3e6e4ddac4d7f49dc46044dd9a',
1020
+ POL: '0x57B6Ad484ccdd902C4419424bA648ba6Ed45dc68',
1011
1021
  },
1012
1022
  [Network.ROPSTEN]: {
1013
1023
  ETH: '0x43262A12d8610AA70C15DbaeAC321d51613c9071',