@paraswap/dex-lib 3.7.9-dex-deprecation.0 → 3.8.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.
Files changed (54) hide show
  1. package/build/abi/curve-v1-factory/CurveV1Router.abi.json +331 -0
  2. package/build/config.js +1 -1
  3. package/build/dex/curve-v1-factory/config.js +47 -10
  4. package/build/dex/curve-v1-factory/config.js.map +1 -1
  5. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -2
  6. package/build/dex/curve-v1-factory/curve-v1-factory.js +96 -36
  7. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  8. package/build/dex/curve-v1-factory/optimizer.d.ts +2 -0
  9. package/build/dex/curve-v1-factory/optimizer.js +54 -0
  10. package/build/dex/curve-v1-factory/optimizer.js.map +1 -0
  11. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  12. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js +13 -1
  13. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js.map +1 -1
  14. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +2 -2
  15. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +1 -1
  16. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
  17. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +1 -1
  18. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  19. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +4 -3
  20. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +24 -9
  21. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
  22. package/build/dex/curve-v1-factory/types.d.ts +20 -4
  23. package/build/dex/curve-v1-factory/types.js +11 -3
  24. package/build/dex/curve-v1-factory/types.js.map +1 -1
  25. package/build/dex/curve-v1-stable-ng/config.js +18 -0
  26. package/build/dex/curve-v1-stable-ng/config.js.map +1 -1
  27. package/build/dex/index.js +3 -3
  28. package/build/dex/index.js.map +1 -1
  29. package/build/generic-swap-transaction-builder.js +1 -3
  30. package/build/generic-swap-transaction-builder.js.map +1 -1
  31. package/build/router/simpleswap.js +1 -3
  32. package/build/router/simpleswap.js.map +1 -1
  33. package/build/utils.d.ts +1 -1
  34. package/package.json +2 -2
  35. package/src/abi/curve-v1-factory/CurveV1Router.abi.json +331 -0
  36. package/src/config.ts +1 -1
  37. package/src/dex/curve-v1-factory/config.ts +47 -10
  38. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +92 -16
  39. package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +125 -5
  40. package/src/dex/curve-v1-factory/curve-v1-factory.ts +137 -45
  41. package/src/dex/curve-v1-factory/optimizer.ts +61 -0
  42. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +0 -2
  43. package/src/dex/curve-v1-factory/price-handlers/functions/get_dx.ts +24 -1
  44. package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +3 -2
  45. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +1 -0
  46. package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +31 -10
  47. package/src/dex/curve-v1-factory/types.ts +22 -6
  48. package/src/dex/curve-v1-stable-ng/config.ts +18 -0
  49. package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-e2e.test.ts +17 -0
  50. package/src/dex/index.ts +3 -2
  51. package/src/generic-swap-transaction-builder.ts +1 -3
  52. package/src/router/simpleswap.ts +1 -3
  53. package/tests/constants-e2e.ts +1 -1
  54. package/tests/utils-e2e.ts +2 -0
@@ -5,7 +5,13 @@ import {
5
5
  MAX_ALLOWED_STATE_DELAY_FACTOR,
6
6
  MIN_LIQUIDITY_IN_USD,
7
7
  } from '../constants';
8
- import { CurveV1FactoryData, PoolConstants, PoolState } from '../types';
8
+ import {
9
+ CurveV1FactoryData,
10
+ ImplementationNames,
11
+ PoolConstants,
12
+ PoolContextConstants,
13
+ PoolState,
14
+ } from '../types';
9
15
  import { Address } from '@paraswap/core';
10
16
 
11
17
  export type MulticallReturnedTypes = bigint | bigint[];
@@ -38,11 +44,12 @@ export abstract class PoolPollingBase {
38
44
  readonly dexKey: string,
39
45
  readonly network: number,
40
46
  readonly cacheStateKey: string,
41
- readonly implementationName: string,
47
+ readonly implementationName: ImplementationNames,
42
48
  readonly implementationAddress: Address,
43
49
  readonly stateUpdatePeriodMs: number,
44
50
  readonly poolIdentifier: string,
45
51
  readonly poolConstants: PoolConstants,
52
+ readonly poolContextConstants: PoolContextConstants,
46
53
  readonly address: Address,
47
54
  readonly curveLiquidityApiSlug: string,
48
55
  readonly isLendingPool: boolean,
@@ -120,10 +127,17 @@ export abstract class PoolPollingBase {
120
127
 
121
128
  if (iC !== undefined && jC !== undefined) {
122
129
  return {
123
- exchange: this.address,
124
- i: iC,
125
- j: jC,
126
- underlyingSwap: false,
130
+ path: [
131
+ {
132
+ tokenIn: srcAddress,
133
+ tokenOut: destAddress,
134
+ exchange: this.address,
135
+ i: iC,
136
+ j: jC,
137
+ underlyingSwap: false,
138
+ n_coins: this.poolConstants.COINS.length,
139
+ },
140
+ ],
127
141
  };
128
142
  }
129
143
 
@@ -140,10 +154,17 @@ export abstract class PoolPollingBase {
140
154
  // I expect them to be included in old CurveV1 implementation
141
155
  if (iU !== undefined && jU !== undefined && !(iU > 0 && jU > 0)) {
142
156
  return {
143
- exchange: this.address,
144
- i: iU,
145
- j: jU,
146
- underlyingSwap: true,
157
+ path: [
158
+ {
159
+ tokenIn: srcAddress,
160
+ tokenOut: destAddress,
161
+ exchange: this.address,
162
+ i: iU,
163
+ j: jU,
164
+ underlyingSwap: true,
165
+ n_coins: this.poolConstants.COINS.length,
166
+ },
167
+ ],
147
168
  };
148
169
  }
149
170
  }
@@ -15,6 +15,7 @@ export type PoolContextConstants = {
15
15
  // for all pools
16
16
  isWrapNative: boolean;
17
17
  isLending: boolean;
18
+ isStable?: boolean;
18
19
 
19
20
  // Starting from this point, constants are context relevant for pricing
20
21
 
@@ -68,10 +69,15 @@ export type PoolStateWithUpdateInfo<T> = {
68
69
  };
69
70
 
70
71
  export type CurveV1FactoryData = {
71
- exchange: Address;
72
- i: number;
73
- j: number;
74
- underlyingSwap: boolean;
72
+ path: {
73
+ tokenIn: Address;
74
+ tokenOut: Address;
75
+ exchange: Address;
76
+ i: number;
77
+ j: number;
78
+ underlyingSwap: boolean;
79
+ n_coins: number;
80
+ }[];
75
81
  isApproved?: boolean;
76
82
  };
77
83
 
@@ -118,8 +124,6 @@ export enum FactoryImplementationNames {
118
124
  FACTORY_PLAIN_4_OPTIMIZED = 'factory_plain_4_optimized',
119
125
 
120
126
  FACTORY_STABLE_NG = 'factory_stable_ng',
121
- // FACTORY_STABLE_6_NG = 'factory_stable_6_ng',
122
- // FACTORY_STABLE_8_NG = 'factory_stable_8_ng',
123
127
  }
124
128
 
125
129
  export enum CustomImplementationNames {
@@ -188,6 +192,7 @@ type DexParamFactory = {
188
192
 
189
193
  export type DexParams = {
190
194
  factories: DexParamFactory[] | null;
195
+ router: Address;
191
196
  stateUpdatePeriodMs: number;
192
197
  factoryPoolImplementations: Record<Address, FactoryPoolImplementations>;
193
198
  customPools: Record<string, CustomPoolConfig>;
@@ -202,8 +207,19 @@ export enum CurveSwapFunctions {
202
207
  exchange_underlying = 'exchange_underlying',
203
208
  }
204
209
 
210
+ export enum CurveRouterSwapType {
211
+ exchange = 1,
212
+ exchange_underlying = 2,
213
+ }
214
+
215
+ export enum CurveRouterPoolType {
216
+ non_stable = 0,
217
+ stable = 10,
218
+ }
219
+
205
220
  export type CurveV1FactoryIfaces = {
206
221
  exchangeRouter: Interface;
222
+ curveV1Router: Interface;
207
223
  factory: Interface;
208
224
  erc20: Interface;
209
225
  threePool: Interface;
@@ -13,6 +13,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
13
13
  isStableNg: true,
14
14
  },
15
15
  ],
16
+ router: '0x16C6521Dff6baB339122a0FE25a9116693265353', // https://github.com/curvefi/curve-router-ng
16
17
  stateUpdatePeriodMs: 5 * 1000,
17
18
  disabledPools: new Set([]),
18
19
  disabledImplementations: new Set([]),
@@ -59,6 +60,18 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
59
60
  liquidityApiSlug: '/factory-stable-ng',
60
61
  isStoreRateSupported: true,
61
62
  },
63
+ '0xc65cb3156225380beda366610bab18d5835a1647': {
64
+ name: ImplementationNames.FACTORY_STABLE_NG,
65
+ address: '0xc65cb3156225380beda366610bab18d5835a1647',
66
+ liquidityApiSlug: '/factory-stable-ng',
67
+ isStoreRateSupported: true,
68
+ },
69
+ '0xa0ec67a3c483674f77915893346a8ca3abe2b785': {
70
+ name: ImplementationNames.FACTORY_STABLE_NG,
71
+ address: '0xa0ec67a3c483674f77915893346a8ca3abe2b785',
72
+ liquidityApiSlug: '/factory-stable-ng',
73
+ isStoreRateSupported: true,
74
+ },
62
75
  },
63
76
  customPools: {},
64
77
  },
@@ -69,6 +82,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
69
82
  isStableNg: true,
70
83
  },
71
84
  ],
85
+ router: '0x0DCDED3545D565bA3B19E683431381007245d983', // https://github.com/curvefi/curve-router-ng
72
86
  stateUpdatePeriodMs: 2 * 1000,
73
87
  disabledPools: new Set([]),
74
88
  disabledImplementations: new Set([]),
@@ -95,6 +109,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
95
109
  isStableNg: true,
96
110
  },
97
111
  ],
112
+ router: '0x0DCDED3545D565bA3B19E683431381007245d983', // https://github.com/curvefi/curve-router-ng
98
113
  stateUpdatePeriodMs: 2 * 1000,
99
114
  disabledPools: new Set([]),
100
115
  disabledImplementations: new Set([]),
@@ -115,6 +130,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
115
130
  isStableNg: true,
116
131
  },
117
132
  ],
133
+ router: '0x2191718CD32d02B8E60BAdFFeA33E4B5DD9A0A0D', // https://github.com/curvefi/curve-router-ng
118
134
  stateUpdatePeriodMs: 2 * 1000,
119
135
  disabledPools: new Set([]),
120
136
  disabledImplementations: new Set([]),
@@ -141,6 +157,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
141
157
  isStableNg: true,
142
158
  },
143
159
  ],
160
+ router: '0x0DCDED3545D565bA3B19E683431381007245d983', // https://github.com/curvefi/curve-router-ng
144
161
  stateUpdatePeriodMs: 2 * 1000,
145
162
  disabledPools: new Set([]),
146
163
  disabledImplementations: new Set([]),
@@ -161,6 +178,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
161
178
  isStableNg: true,
162
179
  },
163
180
  ],
181
+ router: '0x4f37A9d177470499A2dD084621020b023fcffc1F', // https://github.com/curvefi/curve-router-ng
164
182
  stateUpdatePeriodMs: 2 * 1000,
165
183
  disabledPools: new Set([]),
166
184
  disabledImplementations: new Set([]),
@@ -63,6 +63,23 @@ describe('CurveV1StableNG E2E', () => {
63
63
  sidesToContractMethods,
64
64
  );
65
65
  });
66
+
67
+ describe('GHO -> crvUSD', () => {
68
+ const tokenASymbol: string = 'GHO';
69
+ const tokenBSymbol: string = 'crvUSD';
70
+
71
+ const tokenAAmount: string = '1000000000000000000';
72
+ const tokenBAmount: string = '1000000000000000000';
73
+
74
+ testForNetwork(
75
+ network,
76
+ dexKey,
77
+ tokenASymbol,
78
+ tokenBSymbol,
79
+ tokenAAmount,
80
+ tokenBAmount,
81
+ );
82
+ });
66
83
  });
67
84
 
68
85
  describe('Polygon', () => {
package/src/dex/index.ts CHANGED
@@ -55,6 +55,7 @@ import { CurveFork } from './curve-v1/forks/curve-forks/curve-forks';
55
55
  import { Swerve } from './curve-v1/forks/swerve/swerve';
56
56
  import { CurveV1Factory } from './curve-v1-factory/curve-v1-factory';
57
57
  import { CurveV1StableNg } from './curve-v1-stable-ng/curve-v1-stable-ng';
58
+ import { curveV1Merge } from './curve-v1-factory/optimizer';
58
59
  import { GenericRFQ } from './generic-rfq/generic-rfq';
59
60
  import { WstETH } from './wsteth/wsteth';
60
61
  import { Camelot } from './camelot/camelot';
@@ -187,6 +188,7 @@ export class DexAdapterService {
187
188
  balancerV1Merge,
188
189
  balancerV2Merge,
189
190
  uniswapMerge,
191
+ curveV1Merge,
190
192
  ];
191
193
 
192
194
  constructor(
@@ -322,8 +324,7 @@ export class DexAdapterService {
322
324
  if (this.genericRFQDexKeys.has(dexKey)) {
323
325
  return dexKey;
324
326
  }
325
- if (!isAdapters && /^paraswappool(.*)/i.test(dexKey)) return 'zerox';
326
- else if ('uniswapforkoptimized' === dexKey) {
327
+ if ('uniswapforkoptimized' === dexKey) {
327
328
  if (!this.uniswapV2Alias)
328
329
  throw new Error(
329
330
  `${dexKey} dex is not supported for network(${this.network})!`,
@@ -623,9 +623,7 @@ export class GenericSwapTransactionBuilder {
623
623
  // This assumes that the sum of all swaps srcAmount would sum to priceRoute.srcAmount
624
624
  // Also that it is a direct swap.
625
625
  const _srcAmount =
626
- swapIndex > 0 ||
627
- side === SwapSide.SELL ||
628
- this.dexAdapterService.getDexKeySpecial(se.exchange) === 'zerox'
626
+ swapIndex > 0 || side === SwapSide.SELL
629
627
  ? se.srcAmount
630
628
  : (
631
629
  (BigInt(se.srcAmount) * BigInt(minMaxAmount)) /
@@ -103,9 +103,7 @@ export abstract class SimpleRouterBase<RouterParam>
103
103
  // This assumes that the sum of all swaps srcAmount would sum to priceRoute.srcAmount
104
104
  // Also that it is a direct swap.
105
105
  const _srcAmount =
106
- swapIndex > 0 ||
107
- this.side === SwapSide.SELL ||
108
- this.dexAdapterService.getDexKeySpecial(se.exchange) === 'zerox'
106
+ swapIndex > 0 || this.side === SwapSide.SELL
109
107
  ? se.srcAmount
110
108
  : (
111
109
  (BigInt(se.srcAmount) * BigInt(minMaxAmount)) /
@@ -1556,7 +1556,7 @@ export const Holders: {
1556
1556
  USDA: '0x2686bC6A56D205010637CE1DF124b20Cb19E4054',
1557
1557
  stUSD: '0x4e83c0a323b68E3Bc7CC8a4E35326Fd0544A291E',
1558
1558
  crvUSD: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1559
- GHO: '0x844Dc85EdD8492A56228D293cfEbb823EF3E10EC',
1559
+ GHO: '0x0F11640BF66e2D9352d9c41434A5C6E597c5e4c8',
1560
1560
  wibBTC: '0xFbdCA68601f835b27790D98bbb8eC7f05FDEaA9B',
1561
1561
  MATIC: '0x7073783eee7e9b3e6e4ddac4d7f49dc46044dd9a',
1562
1562
  POL: '0x05A47D9f589a001C15E38D068dCc5DaE6D96a2eb',
@@ -43,6 +43,7 @@ import {
43
43
  constructSimpleSDK,
44
44
  SimpleFetchSDK,
45
45
  } from '@paraswap/sdk';
46
+ import { ParaSwapVersion } from '@paraswap/core';
46
47
  import axios from 'axios';
47
48
  import { SmartToken, StateOverrides } from './smart-tokens';
48
49
  import {
@@ -127,6 +128,7 @@ class APIParaswapSDK implements IParaSwapSDK {
127
128
  ) {
128
129
  this.dexKeys = Array.isArray(dexKeys) ? dexKeys : [dexKeys];
129
130
  this.paraSwap = constructSimpleSDK({
131
+ version: ParaSwapVersion.V6,
130
132
  chainId: network,
131
133
  axios,
132
134
  apiURL: testingEndpoint,