@paraswap/dex-lib 2.42.30-smardex → 2.42.31

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 (55) hide show
  1. package/build/dex/index.js +2 -2
  2. package/build/dex/index.js.map +1 -1
  3. package/build/dex/smardex/config.js +0 -7
  4. package/build/dex/smardex/config.js.map +1 -1
  5. package/build/dex/smardex/constants.d.ts +1 -1
  6. package/build/dex/smardex/constants.js +2 -2
  7. package/build/dex/smardex/constants.js.map +1 -1
  8. package/build/dex/smardex/sdk/utils.js.map +1 -1
  9. package/build/dex/smardex/smardex-event-pool.d.ts +2 -2
  10. package/build/dex/smardex/smardex-event-pool.js +9 -11
  11. package/build/dex/smardex/smardex-event-pool.js.map +1 -1
  12. package/build/dex/smardex/smardex.d.ts +1 -6
  13. package/build/dex/smardex/smardex.js +95 -52
  14. package/build/dex/smardex/smardex.js.map +1 -1
  15. package/build/dex/smardex/types.d.ts +1 -12
  16. package/build/dex/wombat/utils.d.ts +1 -0
  17. package/build/dex/wombat/utils.js +14 -1
  18. package/build/dex/wombat/utils.js.map +1 -1
  19. package/build/dex/wombat/wombat-bmw.d.ts +2 -2
  20. package/build/dex/wombat/wombat-bmw.js +8 -25
  21. package/build/dex/wombat/wombat-bmw.js.map +1 -1
  22. package/build/dex/wombat/wombat-pool.d.ts +51 -17
  23. package/build/dex/wombat/wombat-pool.js +398 -112
  24. package/build/dex/wombat/wombat-pool.js.map +1 -1
  25. package/build/dex/wombat/wombat.d.ts +1 -1
  26. package/build/dex/wombat/wombat.js +12 -18
  27. package/build/dex/wombat/wombat.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/abi/smardex/layer-1/smardex-factory.json +242 -0
  30. package/src/abi/smardex/layer-1/smardex-pool.json +506 -0
  31. package/src/abi/wombat/pool-v3.json +2013 -0
  32. package/src/dex/index.ts +2 -2
  33. package/src/dex/smardex/config.ts +0 -8
  34. package/src/dex/smardex/constants.ts +1 -1
  35. package/src/dex/smardex/sdk/utils.ts +2 -0
  36. package/src/dex/smardex/smardex-e2e.test.ts +21 -22
  37. package/src/dex/smardex/smardex-event-pool.ts +9 -11
  38. package/src/dex/smardex/smardex-events.test.ts +15 -27
  39. package/src/dex/smardex/smardex-integration.test.ts +1 -7
  40. package/src/dex/smardex/smardex.ts +118 -70
  41. package/src/dex/smardex/types.ts +1 -11
  42. package/src/dex/wombat/utils.ts +20 -0
  43. package/src/dex/wombat/wombat-bmw.ts +8 -31
  44. package/src/dex/wombat/wombat-e2e.test.ts +13 -1
  45. package/src/dex/wombat/wombat-events.test.ts +147 -0
  46. package/src/dex/wombat/wombat-integration.test.ts +70 -111
  47. package/src/dex/wombat/wombat-pool.ts +623 -171
  48. package/src/dex/wombat/wombat.ts +13 -23
  49. package/tests/constants-e2e.ts +11 -7
  50. package/src/dex/smardex/subgraph-queries.ts +0 -16
  51. package/src/dex/smardex/usd-reserves.ts +0 -137
  52. /package/src/abi/smardex/{smardex-router.json → all/smardex-router.json} +0 -0
  53. /package/src/abi/smardex/{smardex-factory.json → layer-2/smardex-factory.json} +0 -0
  54. /package/src/abi/smardex/{smardex-pool.json → layer-2/smardex-pool.json} +0 -0
  55. /package/src/abi/wombat/{pool.json → pool-v2.json} +0 -0
@@ -14,7 +14,7 @@ import {
14
14
  } from '../../types';
15
15
  import { Network } from '../../constants';
16
16
  import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
17
- import { getBigIntPow, getDexKeysWithNetwork, isETHAddress } from '../../utils';
17
+ import { getBigIntPow, getDexKeysWithNetwork } from '../../utils';
18
18
  import { IDex } from '../idex';
19
19
  import { IDexHelper } from '../../dex-helper';
20
20
  import { DexParams, PoolState, WombatData } from './types';
@@ -23,7 +23,7 @@ import {
23
23
  SimpleExchange,
24
24
  } from '../simple-exchange';
25
25
  import { Adapters, WombatConfig } from './config';
26
- import PoolABI from '../../abi/wombat/pool.json';
26
+ import PoolABI from '../../abi/wombat/pool-v2.json';
27
27
  import AssetABI from '../../abi/wombat/asset.json';
28
28
  import ERC20ABI from '../../abi/erc20.json';
29
29
  import { WombatQuoter } from './wombat-quoter';
@@ -98,23 +98,17 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
98
98
  }
99
99
  }
100
100
 
101
- onAssetAdded = async (
102
- pool: Address,
103
- asset2TokenMap: Map<Address, Address>,
104
- blockNumber: number,
105
- ): Promise<void> => {
101
+ onAssetAdded = async (pool: Address, blockNumber: number): Promise<void> => {
106
102
  if (!this.pools[pool]) {
107
103
  this.pools[pool] = new WombatPool(
108
104
  this.dexKey,
109
105
  this.getPoolIdentifier(pool),
106
+ this.network,
110
107
  this.dexHelper,
108
+ this.logger,
111
109
  pool,
112
- asset2TokenMap,
113
110
  );
114
- await this.pools[pool].getState('latest', true);
115
- this.pollingManager.initializeAllPendingPools();
116
- } else {
117
- this.pools[pool].addAssets(asset2TokenMap);
111
+ await this.pools[pool].initialize(blockNumber);
118
112
  }
119
113
  };
120
114
 
@@ -135,7 +129,6 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
135
129
  blockNumber: number,
136
130
  ): Promise<string[]> {
137
131
  if (side === SwapSide.BUY) return [];
138
- await this.updatePoolState();
139
132
  return (
140
133
  await this.findPools(
141
134
  this.dexHelper.config.wrapETH(srcToken).address.toLowerCase(),
@@ -195,7 +188,7 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
195
188
  destTokenAddress,
196
189
  [getBigIntPow(srcToken.decimals), ...amounts],
197
190
  side,
198
- state.value,
191
+ state,
199
192
  );
200
193
  promises.push({
201
194
  prices,
@@ -240,15 +233,14 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
240
233
  ): Promise<Address[]> {
241
234
  const pools: Address[] = [];
242
235
  for (const [poolAddress, pool] of Object.entries(this.pools)) {
243
- let stateOj = await pool.getState(blockNumber);
244
- if (!stateOj) {
236
+ const state = await pool.getState(blockNumber);
237
+ if (!state) {
245
238
  this.logger.warn(
246
239
  `State of pool ${poolAddress} is null in findPools, skipping...`,
247
240
  );
248
241
  continue;
249
242
  }
250
243
 
251
- const state = stateOj.value;
252
244
  if (
253
245
  state &&
254
246
  !state.params.paused &&
@@ -340,10 +332,10 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
340
332
  const usdPromises = [];
341
333
  const poolStates: { [poolAddress: string]: DeepReadonly<PoolState> } = {};
342
334
  const poolStateObjs = await Promise.all(
343
- Object.values(this.pools).map(pool => pool.getState()),
335
+ Object.values(this.pools).map(pool => pool.getState(blockNumber)),
344
336
  );
345
337
 
346
- for (const [poolAddress, pool] of Object.entries(this.pools)) {
338
+ for (const [poolAddress, _] of Object.entries(this.pools)) {
347
339
  const index = Object.keys(this.pools).indexOf(poolAddress);
348
340
  let state = poolStateObjs[index];
349
341
  if (!state) {
@@ -352,10 +344,8 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
352
344
  );
353
345
  continue;
354
346
  }
355
- poolStates[poolAddress] = state.value;
356
- for (const [tokenAddress, assetState] of Object.entries(
357
- state.value.asset,
358
- )) {
347
+ poolStates[poolAddress] = state;
348
+ for (const [tokenAddress, assetState] of Object.entries(state.asset)) {
359
349
  usdPromises.push(
360
350
  this.dexHelper.getTokenUSDPrice(
361
351
  {
@@ -73,6 +73,10 @@ export const Tokens: {
73
73
  address: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
74
74
  decimals: 18,
75
75
  },
76
+ frxETH: {
77
+ address: '0x5E8422345238F34275888049021821E8E08CAa1f',
78
+ decimals: 18,
79
+ },
76
80
  WETH: {
77
81
  address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
78
82
  decimals: 18,
@@ -327,10 +331,6 @@ export const Tokens: {
327
331
  address: '0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6',
328
332
  decimals: 19,
329
333
  },
330
- WASSIE: {
331
- address: '0x2c95D751DA37A5C1d9c5a7Fd465c1d50F3d96160',
332
- decimals: 18,
333
- },
334
334
  },
335
335
  [Network.ROPSTEN]: {
336
336
  DAI: {
@@ -940,6 +940,10 @@ export const Tokens: {
940
940
  address: '0x68f180fcCe6836688e9084f035309E29Bf0A2095',
941
941
  decimals: 8,
942
942
  },
943
+ frxETH: {
944
+ address: '0x6806411765Af15Bddd26f8f544A34cC40cb9838B',
945
+ decimals: 18,
946
+ },
943
947
  },
944
948
  [Network.ZKEVM]: {
945
949
  ETH: {
@@ -1072,8 +1076,7 @@ export const Holders: {
1072
1076
  MATIC: '0x7073783eee7e9b3e6e4ddac4d7f49dc46044dd9a',
1073
1077
  POL: '0x57B6Ad484ccdd902C4419424bA648ba6Ed45dc68',
1074
1078
  SDEX: '0xB0470cF15B22a6A32c49a7C20E3821B944A76058',
1075
- ALPH: '0xA344855388C9f2760e998eb2207B58de6E7d0360',
1076
- WASSIE: '0x9Faf7Ad8711f6B87CFcF39c235b0A03eF4bDD7C2',
1079
+ frxETH: '0x9df2322bdAEC46627100C999E6dDdD27837fec6e',
1077
1080
  },
1078
1081
  [Network.ROPSTEN]: {
1079
1082
  ETH: '0x43262A12d8610AA70C15DbaeAC321d51613c9071',
@@ -1234,6 +1237,7 @@ export const Holders: {
1234
1237
  wstETH: '0xf7626459234e9249808a06aa08dc6b67c8e0a2fc',
1235
1238
  rETH: '0x4c2e69e58b14de9afedfb94319519ce34e087283',
1236
1239
  WBTC: '0xb9c8f0d3254007ee4b98970b94544e473cd610ec',
1240
+ frxETH: '0x4d4edf8291d169f975b99914b6ab3326abb45938',
1237
1241
  },
1238
1242
  [Network.ZKEVM]: {
1239
1243
  ETH: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9',
@@ -1248,7 +1252,7 @@ export const Holders: {
1248
1252
  ETH: '0xdd9176ea3e7559d6b68b537ef555d3e89403f742',
1249
1253
  MAV: '0x7499785aa5d1bdf0a0ac862c1ef3698d3cba6568',
1250
1254
  USDC: '0xaac391f166f33cdaefaa4afa6616a3bea66b694d',
1251
- USDbC: '0x13a13869b814be8f13b86e9875ab51bda882e391', //'0xc68a33de9ceac7bdaed242ae1dc40d673ed4f643', -> this holder does not have balance anymore...
1255
+ USDbC: '0xcc46564eb2063b60cd457da49d09dca9544dfeae',
1252
1256
  DAI: '0x20f03e26968b179025f65c1f4afadfd3959c8d03',
1253
1257
  BAL: '0x854b004700885a61107b458f11ecc169a019b764',
1254
1258
  GOLD: '0x1374c25b3710758c326ee0c70ec48b595d5ccf8c',
@@ -1,16 +0,0 @@
1
- export const fetchPaginatedPairUSDReservesQuery = (
2
- first: number,
3
- skip: number,
4
- ) =>
5
- `query {
6
- pairs(
7
- orderBy: reserveUSD
8
- orderDirection: desc
9
- where: {reserve0_gt: 1, reserve1_gt: 1}
10
- first: ${first}
11
- skip: ${skip}
12
- ) {
13
- id
14
- reserveUSD
15
- }
16
- }`;
@@ -1,137 +0,0 @@
1
- import { Network, SUBGRAPH_TIMEOUT } from '../../constants';
2
- import { IDexHelper } from '../../dex-helper';
3
- import { Address, Logger } from '../../types';
4
- import { fetchPaginatedPairUSDReservesQuery } from './subgraph-queries';
5
- import { SubgraphPairReserve, USDReserve } from './types';
6
-
7
- // Service for managing USD reserves for Smardex
8
- export class USDReservesService {
9
- private static readonly CACHE_KEY_LOCK = 'cached-reserves-usd';
10
- private static readonly CACHE_TTL_LOCK = 120; // 2 minutes
11
- private static readonly CACHE_TTL_RESERVES = 60 * 60; // 1 hour
12
- private static readonly CACHE_RESERVE_KEY_SUFFIX = '-usd-reserve';
13
- private readonly subgraphURL: string;
14
- private readonly dexHelper: IDexHelper;
15
- private readonly dexKey: string;
16
- private readonly network: Network;
17
- private readonly logger: Logger;
18
-
19
- constructor(
20
- dexKey: string,
21
- network: Network,
22
- dexHelper: IDexHelper,
23
- subgraphURL: string,
24
- ) {
25
- this.dexKey = dexKey;
26
- this.subgraphURL = subgraphURL;
27
- this.network = network;
28
- this.dexHelper = dexHelper;
29
- this.logger = dexHelper.getLogger();
30
- }
31
-
32
- // Retrieves USD reserve for a specific pair from the cache
33
- async getUSDReserveForPair(pairAddress: Address): Promise<number> {
34
- const suffix = USDReservesService.CACHE_RESERVE_KEY_SUFFIX;
35
- await this.refreshUSDReservesIfNeeded();
36
- const cachedReserve = await this.dexHelper.cache.get(
37
- this.dexKey,
38
- this.network,
39
- `${pairAddress.toLowerCase()}${suffix}`,
40
- );
41
- return cachedReserve ? Number(cachedReserve) : 0;
42
- }
43
-
44
- // Updates USD reserves if they are outdated
45
- private async refreshUSDReservesIfNeeded(): Promise<void> {
46
- if (!this.subgraphURL || !(await this.areUSDReservesOutdated())) {
47
- return;
48
- }
49
- await this.lockUSDReservesCache();
50
- const pairs = await this.fetchSubgraphReserves();
51
- await this.cacheUSDReserves(pairs);
52
- }
53
-
54
- // Acquires a lock on the USD reserves cache
55
- private async lockUSDReservesCache(): Promise<void> {
56
- await this.dexHelper.cache.setex(
57
- this.dexKey,
58
- this.network,
59
- USDReservesService.CACHE_KEY_LOCK,
60
- USDReservesService.CACHE_TTL_LOCK,
61
- Date.now().toString(),
62
- );
63
- }
64
-
65
- // Checks if the USD reserves are outdated
66
- private async areUSDReservesOutdated(): Promise<boolean> {
67
- const lastUpdate = await this.dexHelper.cache.get(
68
- this.dexKey,
69
- this.network,
70
- USDReservesService.CACHE_KEY_LOCK,
71
- );
72
- return !lastUpdate;
73
- }
74
-
75
- // Caches USD reserves for all pairs
76
- private async cacheUSDReserves(reserves: USDReserve[]): Promise<void> {
77
- const suffix = USDReservesService.CACHE_RESERVE_KEY_SUFFIX;
78
- for (const reserve of reserves) {
79
- await this.dexHelper.cache.setex(
80
- this.dexKey,
81
- this.network,
82
- `${reserve.pairAddress}${suffix}`,
83
- USDReservesService.CACHE_TTL_RESERVES,
84
- reserve.reserveUSD.toString(),
85
- );
86
- }
87
- }
88
-
89
- async fetchSubgraphReserves(): Promise<USDReserve[]> {
90
- const pageSize = 100;
91
- let page = 1;
92
- let pairs: USDReserve[] = [];
93
- let paginatedPairs = await this.fetchPaginatedReserves(page, pageSize);
94
- while (paginatedPairs.length > 0) {
95
- pairs = [...pairs, ...paginatedPairs];
96
- page++;
97
- paginatedPairs = await this.fetchPaginatedReserves(page, pageSize);
98
- }
99
- return pairs;
100
- }
101
-
102
- // Fetches pair data from the subgraph
103
- async fetchPaginatedReserves(
104
- page: number,
105
- pageSize: number,
106
- ): Promise<USDReserve[]> {
107
- const skip = Math.max(0, page - 1) * pageSize;
108
- const limit = pageSize;
109
- const paginatedQuery: string = fetchPaginatedPairUSDReservesQuery(
110
- limit,
111
- skip,
112
- );
113
-
114
- try {
115
- const apiToken = this.dexHelper.config.data.smardexSubgraphAuthToken!;
116
- const response = await this.dexHelper.httpRequest.post(
117
- this.subgraphURL,
118
- { query: paginatedQuery },
119
- SUBGRAPH_TIMEOUT,
120
- { 'x-api-key': apiToken },
121
- );
122
- if (!response.data || !response.data.pairs) {
123
- return [];
124
- }
125
- return response.data.pairs.map((pair: SubgraphPairReserve) => ({
126
- pairAddress: pair.id,
127
- reserveUSD: pair.reserveUSD,
128
- }));
129
- } catch (error) {
130
- this.logger.error(
131
- 'Error fetching paginated reserves from subgraph',
132
- error,
133
- );
134
- return [];
135
- }
136
- }
137
- }
File without changes