@paraswap/dex-lib 2.16.3-rfq-direct.0 → 2.16.3

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 (69) hide show
  1. package/build/abi/DirectSwap.json +970 -0
  2. package/build/config.js +2 -2
  3. package/build/dex/aave-v3/tokens/arbitrum.json +20 -20
  4. package/build/dex/aave-v3/tokens/avalanche.json +44 -20
  5. package/build/dex/aave-v3/tokens/fantom.json +30 -30
  6. package/build/dex/aave-v3/tokens/optimism.json +18 -18
  7. package/build/dex/aave-v3/tokens/polygon.json +60 -42
  8. package/build/dex/generic-rfq/generic-rfq.d.ts +4 -8
  9. package/build/dex/generic-rfq/generic-rfq.js +0 -39
  10. package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
  11. package/build/dex/generic-rfq/types.d.ts +1 -17
  12. package/build/dex/generic-rfq/types.js +1 -6
  13. package/build/dex/generic-rfq/types.js.map +1 -1
  14. package/build/dex/index.js +3 -1
  15. package/build/dex/index.js.map +1 -1
  16. package/build/dex/maverick-v1/config.js +1 -1
  17. package/build/dex/maverick-v1/config.js.map +1 -1
  18. package/build/dex/paraswap-limit-orders/types.d.ts +6 -7
  19. package/build/dex/quickswap/config.js +8 -0
  20. package/build/dex/quickswap/config.js.map +1 -1
  21. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  22. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  23. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  24. package/build/dex/{test-aave-v3 → test-dex}/config.d.ts +1 -1
  25. package/build/dex/{test-aave-v3 → test-dex}/config.js +3 -3
  26. package/build/dex/test-dex/config.js.map +1 -0
  27. package/build/dex/{test-aave-v3/test-aave-v3-pool.d.ts → test-dex/test-dex-pool.d.ts} +3 -3
  28. package/build/dex/{test-aave-v3/test-aave-v3-pool.js → test-dex/test-dex-pool.js} +7 -7
  29. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  30. package/build/dex/{test-aave-v3/test-aave-v3.d.ts → test-dex/test-dex.d.ts} +8 -8
  31. package/build/dex/{test-aave-v3/test-aave-v3.js → test-dex/test-dex.js} +7 -7
  32. package/build/dex/test-dex/test-dex.js.map +1 -0
  33. package/build/dex/{test-aave-v3 → test-dex}/types.d.ts +1 -1
  34. package/build/dex/{test-aave-v3 → test-dex}/types.js.map +1 -1
  35. package/build/dex/uniswap-v3/config.js +4 -0
  36. package/build/dex/uniswap-v3/config.js.map +1 -1
  37. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  38. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  39. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  40. package/package.json +3 -3
  41. package/src/config.ts +2 -2
  42. package/src/dex/generic-rfq/generic-rfq.ts +2 -70
  43. package/src/dex/generic-rfq/types.ts +1 -26
  44. package/src/dex/index.ts +3 -1
  45. package/src/dex/maverick-v1/config.ts +1 -1
  46. package/src/dex/paraswap-limit-orders/types.ts +9 -11
  47. package/src/dex/quickswap/config.ts +9 -0
  48. package/src/dex/quickswap/quickswap-e2e.test.ts +94 -0
  49. package/src/dex/quickswap/spiritswap-v3.ts +19 -0
  50. package/src/dex/uniswap-v3/config.ts +4 -0
  51. package/tests/constants-e2e.ts +2 -2
  52. package/tests/utils-e2e.ts +2 -2
  53. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  54. package/.idea/misc.xml +0 -6
  55. package/.idea/modules.xml +0 -8
  56. package/.idea/vcs.xml +0 -6
  57. package/.vscode/launch.json +0 -21
  58. package/build/abi/AugustusRFQRouter.abi.json +0 -1248
  59. package/build/dex/aave-v3/tokens/mainnet.json +0 -44
  60. package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +0 -79
  61. package/build/dex/balancer-v2/VirtualBoostedPool.js +0 -382
  62. package/build/dex/balancer-v2/VirtualBoostedPool.js.map +0 -1
  63. package/build/dex/test-aave-v3/config.js.map +0 -1
  64. package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +0 -1
  65. package/build/dex/test-aave-v3/test-aave-v3.js.map +0 -1
  66. package/compare-quotes.ts +0 -12
  67. package/fetch-rfq-quotes.ts +0 -148
  68. package/src/abi/AugustusRFQRouter.abi.json +0 -1248
  69. /package/build/dex/{test-aave-v3 → test-dex}/types.js +0 -0
@@ -6,7 +6,6 @@ import {
6
6
  PreprocessTransactionOptions,
7
7
  Config,
8
8
  PoolLiquidity,
9
- TxInfo,
10
9
  } from '../../types';
11
10
  import { Network, SwapSide } from '../../constants';
12
11
  import { IDexHelper } from '../../dex-helper';
@@ -16,19 +15,12 @@ import { ParaSwapLimitOrdersData } from '../paraswap-limit-orders/types';
16
15
  import { ONE_ORDER_GASCOST } from '../paraswap-limit-orders/constant';
17
16
  import { RateFetcher } from './rate-fetcher';
18
17
  import {
19
- AugustusRFQRouterFunctions,
20
- GenericRFQParam,
21
18
  PriceAndAmountBigNumber,
22
19
  RFQConfig,
23
20
  SlippageCheckError,
24
21
  } from './types';
25
- import { Address, NumberAsString, OptimalSwapExchange } from '@paraswap/core';
22
+ import { OptimalSwapExchange } from '@paraswap/core';
26
23
  import { BI_MAX_UINT256 } from '../../bigint-constants';
27
- import { Interface } from 'ethers/lib/utils';
28
- import AugustusRFQRouterABI from '../../abi/AugustusRFQRouter.abi.json';
29
- import { IDexTxBuilder } from '../idex';
30
- import { isETHAddress } from '../../utils';
31
- import { assert } from 'ts-essentials';
32
24
 
33
25
  export const OVERORDER_BPS = 100;
34
26
  export const BPS_MAX_VALUE = 10000n;
@@ -36,15 +28,10 @@ export const BPS_MAX_VALUE = 10000n;
36
28
  export const overOrder = (amount: string, bps: number) =>
37
29
  ((BigInt(amount) * (BPS_MAX_VALUE + BigInt(bps))) / BPS_MAX_VALUE).toString();
38
30
 
39
- export class GenericRFQ
40
- extends ParaSwapLimitOrders
41
- implements IDexTxBuilder<ParaSwapLimitOrdersData, GenericRFQParam>
42
- {
31
+ export class GenericRFQ extends ParaSwapLimitOrders {
43
32
  readonly isStatePollingDex = true;
44
33
  private rateFetcher: RateFetcher;
45
34
 
46
- private routerInterface: Interface;
47
-
48
35
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] = [];
49
36
 
50
37
  static builderDexKeysWithNetwork(config: Config): void {
@@ -64,7 +51,6 @@ export class GenericRFQ
64
51
  ) {
65
52
  super(network, dexKey, dexHelper);
66
53
  this.rateFetcher = new RateFetcher(dexHelper, config, dexKey, this.logger);
67
- this.routerInterface = new Interface(AugustusRFQRouterABI);
68
54
  }
69
55
 
70
56
  async initializePricing(blockNumber: number): Promise<void> {
@@ -311,58 +297,4 @@ export class GenericRFQ
311
297
  this.rateFetcher.stop();
312
298
  }
313
299
  }
314
-
315
- getDirectParam(
316
- srcToken: Address,
317
- destToken: Address,
318
- srcAmount: NumberAsString,
319
- destAmount: NumberAsString,
320
- data: ParaSwapLimitOrdersData,
321
- side: SwapSide,
322
- permit: string,
323
- contractMethod: string,
324
- ): TxInfo<GenericRFQParam> {
325
- const usePermit = permit !== '0x';
326
-
327
- assert(
328
- contractMethod ===
329
- (usePermit
330
- ? AugustusRFQRouterFunctions.swapOnAugustusRFQWithPermit
331
- : AugustusRFQRouterFunctions.swapOnAugustusRFQ),
332
- );
333
-
334
- if (data.orderInfos === null && data.orderInfos!.length === 1) {
335
- throw new Error('`orderInfos` cannot be empty');
336
- }
337
-
338
- const encoder = (...params: GenericRFQParam) => {
339
- return this.routerInterface.encodeFunctionData(
340
- usePermit
341
- ? AugustusRFQRouterFunctions.swapOnAugustusRFQWithPermit
342
- : AugustusRFQRouterFunctions.swapOnAugustusRFQ,
343
- params,
344
- );
345
- };
346
-
347
- const wrapETH = isETHAddress(srcAmount) ? 1 : 0;
348
- return {
349
- params: usePermit
350
- ? [
351
- data.orderInfos![0].order,
352
- data.orderInfos![0].signature,
353
- wrapETH,
354
- permit,
355
- ]
356
- : [data.orderInfos![0].order, data.orderInfos![0].signature, wrapETH],
357
- encoder,
358
- networkFee: '0',
359
- };
360
- }
361
-
362
- static getDirectFunctionName(): string[] {
363
- return [
364
- AugustusRFQRouterFunctions.swapOnAugustusRFQ,
365
- AugustusRFQRouterFunctions.swapOnAugustusRFQWithPermit,
366
- ];
367
- }
368
300
  }
@@ -1,10 +1,7 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { RequestConfig } from '../../dex-helper/irequest-wrapper';
3
3
  import { Address, Token } from '../../types';
4
- import {
5
- AugustusOrderWithString,
6
- OrderInfoType,
7
- } from '../paraswap-limit-orders/types';
4
+ import { AugustusOrderWithString } from '../paraswap-limit-orders/types';
8
5
 
9
6
  export type Pair = {
10
7
  base: string;
@@ -99,25 +96,3 @@ export type RFQFirmRateResponse = {
99
96
  };
100
97
 
101
98
  export class SlippageCheckError extends Error {}
102
-
103
- export enum AugustusRFQRouterFunctions {
104
- swapOnAugustusRFQ = 'swapOnAugustusRFQ',
105
- swapOnAugustusRFQWithPermit = 'swapOnAugustusRFQWithPermit',
106
- }
107
-
108
- export type SwapOnGenericRFQParam = [
109
- order: OrderInfoType,
110
- signature: string,
111
- wrapETH: number,
112
- ];
113
-
114
- export type SwapOnGenericRFQWithPermitParam = [
115
- order: OrderInfoType,
116
- signature: string,
117
- wrapETH: number,
118
- permit: string,
119
- ];
120
-
121
- export type GenericRFQParam =
122
- | SwapOnGenericRFQParam
123
- | SwapOnGenericRFQWithPermitParam;
package/src/dex/index.ts CHANGED
@@ -63,6 +63,7 @@ import { MaverickV1 } from './maverick-v1/maverick-v1';
63
63
  import { QuickSwapV3 } from './quickswap/quickswap-v3';
64
64
  import { ZyberSwapV3 } from './quickswap/zyberswap-v3';
65
65
  import { TraderJoeV2 } from './trader-joe-v2';
66
+ import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
66
67
  import { PancakeswapV3 } from './uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3';
67
68
 
68
69
  const LegacyDexes = [
@@ -81,6 +82,7 @@ const LegacyDexes = [
81
82
  DodoV2,
82
83
  QuickSwapV3,
83
84
  ZyberSwapV3,
85
+ SpiritSwapV3,
84
86
  TraderJoeV2,
85
87
  Jarvis,
86
88
  Lido,
@@ -215,7 +217,7 @@ export class DexAdapterService {
215
217
  this.genericRFQDexKeys.add(rfqName.toLowerCase());
216
218
  });
217
219
 
218
- this.directFunctionsNames = [...LegacyDexes, ...Dexes, GenericRFQ]
220
+ this.directFunctionsNames = [...LegacyDexes, ...Dexes]
219
221
  .flatMap(dexAdapter => {
220
222
  const _dexAdapter = dexAdapter as IGetDirectFunctionName;
221
223
  return _dexAdapter.getDirectFunctionName
@@ -10,7 +10,7 @@ export const MaverickV1Config: DexConfigMap<DexParams> = {
10
10
  MaverickV1: {
11
11
  [Network.MAINNET]: {
12
12
  subgraphURL:
13
- 'https://gateway.thegraph.com/api/4b42aaaee3e81a3f29390e9df7010cbc/subgraphs/id/9n4uEbt1XV6DnYH7AGHJ84Gh2fpu68iwxwBKnWqVMX9G',
13
+ 'https://api.thegraph.com/subgraphs/name/maverickprotocol/maverick-mainnet',
14
14
  routerAddress: '0x4a585e0f7c18e2c414221d6402652d5e0990e5f8',
15
15
  poolInspectorAddress: '0xaA5BF61a664109e959D69C38734d4EA7dF74e456',
16
16
  },
@@ -58,18 +58,16 @@ export type DexParams = {
58
58
  rfqAddress: string;
59
59
  };
60
60
 
61
- export type OrderInfoType = Omit<
62
- AugustusOrder,
63
- 'nonceAndMeta' | 'makerAmount' | 'takerAmount' | 'expiry'
64
- > & {
65
- expiry: string;
66
- nonceAndMeta: BigIntAsString;
67
- makerAmount: BigIntAsString;
68
- takerAmount: BigIntAsString;
69
- };
70
-
71
61
  export type OrderInfo = {
72
- order: OrderInfoType;
62
+ order: Omit<
63
+ AugustusOrder,
64
+ 'nonceAndMeta' | 'makerAmount' | 'takerAmount' | 'expiry'
65
+ > & {
66
+ expiry: string;
67
+ nonceAndMeta: BigIntAsString;
68
+ makerAmount: BigIntAsString;
69
+ takerAmount: BigIntAsString;
70
+ };
73
71
  signature: string;
74
72
  takerTokenFillAmount: BigIntAsString;
75
73
  permitTakerAsset: string;
@@ -21,4 +21,13 @@ export const QuickSwapConfig: DexConfigMap<DexParams> = {
21
21
  '0xfa2ad44b9e39d38a7d396bb44a41ea957ac7b622c5c6afdc285728c300b3382a',
22
22
  },
23
23
  },
24
+ SpiritSwapV3: {
25
+ [Network.FANTOM]: {
26
+ factoryAddress: '0xC58A98644fCeee73bc2B6d349B3102627e2Ec58e',
27
+ router: '0x03108EDEd4902e89781839c885496c6de9D21956',
28
+ quoteAddress: '0xc4D1310D60A36c7d849A332Be8Dcff29603fe907',
29
+ initCode:
30
+ '0xa360004fb86ddf4cd7fe9aa67d0c6a7f7812d9069142659003dc503e1d7d241f',
31
+ },
32
+ },
24
33
  };
@@ -354,4 +354,98 @@ describe('QuickSwap', () => {
354
354
  });
355
355
  });
356
356
  });
357
+
358
+ describe('Fantom', () => {
359
+ const network = Network.FANTOM;
360
+ const tokens = Tokens[network];
361
+ const holders = Holders[network];
362
+ const provider = new StaticJsonRpcProvider(
363
+ generateConfig(network).privateHttpProvider,
364
+ network,
365
+ );
366
+ describe('SpiritSwapV3', () => {
367
+ const dexKey = 'SpiritSwapV3';
368
+
369
+ const sideToContractMethods = new Map([
370
+ [
371
+ SwapSide.SELL,
372
+ [
373
+ ContractMethod.simpleSwap,
374
+ ContractMethod.multiSwap,
375
+ ContractMethod.megaSwap,
376
+ ],
377
+ ],
378
+ [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
379
+ ]);
380
+
381
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
382
+ [
383
+ [
384
+ {
385
+ name: 'USDC',
386
+ sellAmount: '100',
387
+ buyAmount: '10000000000000000',
388
+ },
389
+ {
390
+ name: 'WFTM',
391
+ sellAmount: '10000000000000000',
392
+ buyAmount: '100',
393
+ },
394
+ ],
395
+ [
396
+ {
397
+ name: 'FTM',
398
+ sellAmount: '1000000000000000',
399
+ buyAmount: '100',
400
+ },
401
+ {
402
+ name: 'USDC',
403
+ sellAmount: '100',
404
+ buyAmount: '10000000000000000',
405
+ },
406
+ ],
407
+ ];
408
+
409
+ sideToContractMethods.forEach((contractMethods, side) =>
410
+ describe(`${side}`, () => {
411
+ contractMethods.forEach((contractMethod: ContractMethod) => {
412
+ pairs.forEach(pair => {
413
+ describe(`${contractMethod}`, () => {
414
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
415
+ await testE2E(
416
+ tokens[pair[0].name],
417
+ tokens[pair[1].name],
418
+ holders[pair[0].name],
419
+ side === SwapSide.SELL
420
+ ? pair[0].sellAmount
421
+ : pair[0].buyAmount,
422
+ side,
423
+ dexKey,
424
+ contractMethod,
425
+ network,
426
+ provider,
427
+ );
428
+ });
429
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
430
+ await testE2E(
431
+ tokens[pair[1].name],
432
+ tokens[pair[0].name],
433
+ holders[pair[1].name],
434
+ side === SwapSide.SELL
435
+ ? pair[1].sellAmount
436
+ : pair[1].buyAmount,
437
+ side,
438
+ dexKey,
439
+ contractMethod,
440
+ network,
441
+ provider,
442
+ );
443
+ });
444
+ });
445
+ });
446
+ });
447
+ }),
448
+ );
449
+ });
450
+ });
357
451
  });
@@ -0,0 +1,19 @@
1
+ import { IDexHelper } from '../../dex-helper';
2
+ import _ from 'lodash';
3
+ import { QuickSwapConfig } from './config';
4
+ import { QuickSwapV3 } from './quickswap-v3';
5
+
6
+ const config = _.pick(QuickSwapConfig, ['SpiritSwapV3']).SpiritSwapV3;
7
+
8
+ export class SpiritSwapV3 extends QuickSwapV3 {
9
+ static dexKeys = ['spiritswapv3'];
10
+
11
+ // public static dexKeysWithNetwork
12
+ constructor(dexHelper: IDexHelper) {
13
+ super(
14
+ dexHelper,
15
+ 'spiritswapv3',
16
+ config[dexHelper.config.data.network].router,
17
+ );
18
+ }
19
+ }
@@ -141,4 +141,8 @@ export const Adapters: Record<number, AdapterMappings> = {
141
141
  [SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 3 }],
142
142
  [SwapSide.BUY]: [{ name: 'OptimismBuyAdapter', index: 2 }],
143
143
  },
144
+ [Network.FANTOM]: {
145
+ [SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 11 }],
146
+ [SwapSide.BUY]: [{ name: 'FantomBuyAdapter', index: 3 }],
147
+ },
144
148
  };
@@ -904,7 +904,7 @@ export const Holders: {
904
904
  [Network.FANTOM]: {
905
905
  DAI: '0x370f4b2dcf75c94d8d4450b493661a9c6170d0b5',
906
906
  FTM: '0x431e81E5dfB5A24541b5Ff8762bDEF3f32F96354',
907
- WFTM: '0x431e81E5dfB5A24541b5Ff8762bDEF3f32F96354',
907
+ WFTM: '0x3e923747ca2675e096d812c3b24846ac39aed645',
908
908
  USDC: '0xe48793b1533b351ae184e1c3119d0955dde7b330',
909
909
  FUSDT: '0x9ade1c17d25246c405604344f89E8F23F8c1c632',
910
910
  POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591',
@@ -913,7 +913,7 @@ export const Holders: {
913
913
  MIM: '0xbcab7d083cf6a01e0dda9ed7f8a02b47d125e682',
914
914
  FRAX: '0x4423ac71f53ca92e2f2be5917a9c2468e7412f4a',
915
915
  nETH: '0x16b658270ac50c0063940ed287c401b3df7ccf70',
916
- WETH: '0x4ad64fd7ca6d6150614179b9bce4094bc18f29cb',
916
+ WETH: '0x7b7b957c284c2c227c980d6e2f804311947b84d0',
917
917
  SPIRIT: '0x0d0707963952f2fba59dd06f2b425ace40b492fe',
918
918
  wBOMB: '0x28aa4f9ffe21365473b64c161b566c3cdead0108',
919
919
  TOR: '0x70de4b5ed310fd93da3c0bae824fb99cb4d44dd8',
@@ -468,7 +468,7 @@ export async function newTestE2E({
468
468
  .addAllowance(
469
469
  senderAddress,
470
470
  config.tokenTransferProxyAddress,
471
- MAX_UINT,
471
+ amount.toString(),
472
472
  );
473
473
  } else {
474
474
  srcToken
@@ -476,7 +476,7 @@ export async function newTestE2E({
476
476
  .addAllowance(
477
477
  senderAddress,
478
478
  config.tokenTransferProxyAddress,
479
- MAX_UINT,
479
+ (BigInt(MAX_UINT) / 8n).toString(),
480
480
  );
481
481
  }
482
482
 
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager">
4
- <output url="file://$PROJECT_DIR$/out" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/paraswap-dex-lib.iml" filepath="$PROJECT_DIR$/paraswap-dex-lib.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>
@@ -1,21 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "node",
9
- "request": "launch",
10
- "name": "Launch Program",
11
- "skipFiles": [
12
- "<node_internals>/**"
13
- ],
14
- "program": "${workspaceFolder}/build/index.js",
15
- "preLaunchTask": "tsc: build - tsconfig.json",
16
- "outFiles": [
17
- "${workspaceFolder}/build/**/*.js"
18
- ]
19
- }
20
- ]
21
- }