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

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/.idea/codeStyles/codeStyleConfig.xml +5 -0
  2. package/.idea/misc.xml +6 -0
  3. package/.idea/modules.xml +8 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/.vscode/launch.json +21 -0
  6. package/build/abi/AugustusRFQRouter.abi.json +1248 -0
  7. package/build/abi/woo-fi/WooFeeManager.abi.json +318 -0
  8. package/build/abi/woo-fi/WooPP.abi.json +548 -0
  9. package/build/abi/woo-fi/Wooracle.abi.json +260 -0
  10. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  11. package/build/dex/aave-v3/tokens/avalanche.json +50 -0
  12. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  13. package/build/dex/aave-v3/tokens/mainnet.json +44 -0
  14. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  15. package/build/dex/aave-v3/tokens/polygon.json +98 -0
  16. package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +79 -0
  17. package/build/dex/balancer-v2/VirtualBoostedPool.js +382 -0
  18. package/build/dex/balancer-v2/VirtualBoostedPool.js.map +1 -0
  19. package/build/dex/generic-rfq/generic-rfq.d.ts +8 -4
  20. package/build/dex/generic-rfq/generic-rfq.js +39 -0
  21. package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
  22. package/build/dex/generic-rfq/types.d.ts +17 -1
  23. package/build/dex/generic-rfq/types.js +6 -1
  24. package/build/dex/generic-rfq/types.js.map +1 -1
  25. package/build/dex/index.js +1 -1
  26. package/build/dex/index.js.map +1 -1
  27. package/build/dex/paraswap-limit-orders/types.d.ts +7 -6
  28. package/build/dex/quickswap-v3.d.ts +21 -0
  29. package/build/dex/quickswap-v3.js +40 -0
  30. package/build/dex/quickswap-v3.js.map +1 -0
  31. package/build/dex/test-aave-v3/config.d.ts +4 -0
  32. package/build/dex/test-aave-v3/config.js +15 -0
  33. package/build/dex/test-aave-v3/config.js.map +1 -0
  34. package/build/dex/test-aave-v3/test-aave-v3-pool.d.ts +39 -0
  35. package/build/dex/test-aave-v3/test-aave-v3-pool.js +63 -0
  36. package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +1 -0
  37. package/build/dex/test-aave-v3/test-aave-v3.d.ts +37 -0
  38. package/build/dex/test-aave-v3/test-aave-v3.js +126 -0
  39. package/build/dex/test-aave-v3/test-aave-v3.js.map +1 -0
  40. package/build/dex/test-aave-v3/types.d.ts +6 -0
  41. package/build/dex/test-aave-v3/types.js +3 -0
  42. package/build/dex/test-aave-v3/types.js.map +1 -0
  43. package/build/dex/woo-fi/config.d.ts +4 -0
  44. package/build/dex/woo-fi/config.js +141 -0
  45. package/build/dex/woo-fi/config.js.map +1 -0
  46. package/build/dex/woo-fi/constants.d.ts +5 -0
  47. package/build/dex/woo-fi/constants.js +20 -0
  48. package/build/dex/woo-fi/constants.js.map +1 -0
  49. package/build/dex/woo-fi/types.d.ts +48 -0
  50. package/build/dex/woo-fi/types.js +3 -0
  51. package/build/dex/woo-fi/types.js.map +1 -0
  52. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +14 -0
  53. package/build/dex/woo-fi/woo-fi-decimal-math.js +42 -0
  54. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +1 -0
  55. package/build/dex/woo-fi/woo-fi-math.d.ts +31 -0
  56. package/build/dex/woo-fi/woo-fi-math.js +300 -0
  57. package/build/dex/woo-fi/woo-fi-math.js.map +1 -0
  58. package/build/dex/woo-fi/woo-fi.d.ts +65 -0
  59. package/build/dex/woo-fi/woo-fi.js +480 -0
  60. package/build/dex/woo-fi/woo-fi.js.map +1 -0
  61. package/compare-quotes.ts +12 -0
  62. package/fetch-rfq-quotes.ts +148 -0
  63. package/package.json +3 -3
  64. package/src/abi/AugustusRFQRouter.abi.json +1248 -0
  65. package/src/dex/generic-rfq/generic-rfq.ts +70 -2
  66. package/src/dex/generic-rfq/types.ts +26 -1
  67. package/src/dex/index.ts +1 -1
  68. package/src/dex/paraswap-limit-orders/types.ts +11 -9
  69. package/tests/utils-e2e.ts +2 -2
@@ -6,6 +6,7 @@ import {
6
6
  PreprocessTransactionOptions,
7
7
  Config,
8
8
  PoolLiquidity,
9
+ TxInfo,
9
10
  } from '../../types';
10
11
  import { Network, SwapSide } from '../../constants';
11
12
  import { IDexHelper } from '../../dex-helper';
@@ -15,12 +16,19 @@ import { ParaSwapLimitOrdersData } from '../paraswap-limit-orders/types';
15
16
  import { ONE_ORDER_GASCOST } from '../paraswap-limit-orders/constant';
16
17
  import { RateFetcher } from './rate-fetcher';
17
18
  import {
19
+ AugustusRFQRouterFunctions,
20
+ GenericRFQParam,
18
21
  PriceAndAmountBigNumber,
19
22
  RFQConfig,
20
23
  SlippageCheckError,
21
24
  } from './types';
22
- import { OptimalSwapExchange } from '@paraswap/core';
25
+ import { Address, NumberAsString, OptimalSwapExchange } from '@paraswap/core';
23
26
  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';
24
32
 
25
33
  export const OVERORDER_BPS = 100;
26
34
  export const BPS_MAX_VALUE = 10000n;
@@ -28,10 +36,15 @@ export const BPS_MAX_VALUE = 10000n;
28
36
  export const overOrder = (amount: string, bps: number) =>
29
37
  ((BigInt(amount) * (BPS_MAX_VALUE + BigInt(bps))) / BPS_MAX_VALUE).toString();
30
38
 
31
- export class GenericRFQ extends ParaSwapLimitOrders {
39
+ export class GenericRFQ
40
+ extends ParaSwapLimitOrders
41
+ implements IDexTxBuilder<ParaSwapLimitOrdersData, GenericRFQParam>
42
+ {
32
43
  readonly isStatePollingDex = true;
33
44
  private rateFetcher: RateFetcher;
34
45
 
46
+ private routerInterface: Interface;
47
+
35
48
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] = [];
36
49
 
37
50
  static builderDexKeysWithNetwork(config: Config): void {
@@ -51,6 +64,7 @@ export class GenericRFQ extends ParaSwapLimitOrders {
51
64
  ) {
52
65
  super(network, dexKey, dexHelper);
53
66
  this.rateFetcher = new RateFetcher(dexHelper, config, dexKey, this.logger);
67
+ this.routerInterface = new Interface(AugustusRFQRouterABI);
54
68
  }
55
69
 
56
70
  async initializePricing(blockNumber: number): Promise<void> {
@@ -297,4 +311,58 @@ export class GenericRFQ extends ParaSwapLimitOrders {
297
311
  this.rateFetcher.stop();
298
312
  }
299
313
  }
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
+ }
300
368
  }
@@ -1,7 +1,10 @@
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 { AugustusOrderWithString } from '../paraswap-limit-orders/types';
4
+ import {
5
+ AugustusOrderWithString,
6
+ OrderInfoType,
7
+ } from '../paraswap-limit-orders/types';
5
8
 
6
9
  export type Pair = {
7
10
  base: string;
@@ -96,3 +99,25 @@ export type RFQFirmRateResponse = {
96
99
  };
97
100
 
98
101
  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
@@ -215,7 +215,7 @@ export class DexAdapterService {
215
215
  this.genericRFQDexKeys.add(rfqName.toLowerCase());
216
216
  });
217
217
 
218
- this.directFunctionsNames = [...LegacyDexes, ...Dexes]
218
+ this.directFunctionsNames = [...LegacyDexes, ...Dexes, GenericRFQ]
219
219
  .flatMap(dexAdapter => {
220
220
  const _dexAdapter = dexAdapter as IGetDirectFunctionName;
221
221
  return _dexAdapter.getDirectFunctionName
@@ -58,16 +58,18 @@ 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
+
61
71
  export type OrderInfo = {
62
- order: Omit<
63
- AugustusOrder,
64
- 'nonceAndMeta' | 'makerAmount' | 'takerAmount' | 'expiry'
65
- > & {
66
- expiry: string;
67
- nonceAndMeta: BigIntAsString;
68
- makerAmount: BigIntAsString;
69
- takerAmount: BigIntAsString;
70
- };
72
+ order: OrderInfoType;
71
73
  signature: string;
72
74
  takerTokenFillAmount: BigIntAsString;
73
75
  permitTakerAsset: string;
@@ -468,7 +468,7 @@ export async function newTestE2E({
468
468
  .addAllowance(
469
469
  senderAddress,
470
470
  config.tokenTransferProxyAddress,
471
- amount.toString(),
471
+ MAX_UINT,
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
- (BigInt(MAX_UINT) / 8n).toString(),
479
+ MAX_UINT,
480
480
  );
481
481
  }
482
482