@paraswap/dex-lib 2.20.3 → 2.21.1-chronos

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 (144) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/build/config.js +2 -4
  9. package/build/config.js.map +1 -1
  10. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  11. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  12. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  13. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  14. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  15. package/build/dex/balancer-v2/balancer-v2.d.ts +3 -9
  16. package/build/dex/balancer-v2/balancer-v2.js +0 -83
  17. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  18. package/build/dex/balancer-v2/constants.d.ts +0 -4
  19. package/build/dex/balancer-v2/constants.js +1 -6
  20. package/build/dex/balancer-v2/constants.js.map +1 -1
  21. package/build/dex/balancer-v2/types.d.ts +1 -20
  22. package/build/dex/balancer-v2/types.js.map +1 -1
  23. package/build/dex/curve-v1/constants.d.ts +0 -1
  24. package/build/dex/curve-v1/constants.js +1 -2
  25. package/build/dex/curve-v1/constants.js.map +1 -1
  26. package/build/dex/curve-v1/curve-v1.d.ts +3 -9
  27. package/build/dex/curve-v1/curve-v1.js +4 -92
  28. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  29. package/build/dex/curve-v1/types.d.ts +0 -24
  30. package/build/dex/curve-v1/types.js +1 -6
  31. package/build/dex/curve-v1/types.js.map +1 -1
  32. package/build/dex/curve-v1-factory/constants.d.ts +0 -1
  33. package/build/dex/curve-v1-factory/constants.js +1 -2
  34. package/build/dex/curve-v1-factory/constants.js.map +1 -1
  35. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +4 -11
  36. package/build/dex/curve-v1-factory/curve-v1-factory.js +0 -87
  37. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  38. package/build/dex/curve-v1-factory/types.d.ts +0 -24
  39. package/build/dex/curve-v1-factory/types.js +1 -6
  40. package/build/dex/curve-v1-factory/types.js.map +1 -1
  41. package/build/dex/curve-v2.d.ts +7 -29
  42. package/build/dex/curve-v2.js +1 -91
  43. package/build/dex/curve-v2.js.map +1 -1
  44. package/build/dex/idex.d.ts +1 -1
  45. package/build/dex/index.js +2 -2
  46. package/build/dex/index.js.map +1 -1
  47. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
  48. package/build/dex/pancakeswap-v3/types.d.ts +14 -0
  49. package/build/dex/pancakeswap-v3/types.js +3 -0
  50. package/build/dex/pancakeswap-v3/types.js.map +1 -0
  51. package/build/dex/pancakeswap-v3/utils.js.map +1 -1
  52. package/build/dex/quickswap/camelot-v3.d.ts +6 -0
  53. package/build/dex/quickswap/camelot-v3.js +19 -0
  54. package/build/dex/quickswap/camelot-v3.js.map +1 -0
  55. package/build/dex/simple-exchange.d.ts +0 -2
  56. package/build/dex/simple-exchange.js +0 -1
  57. package/build/dex/simple-exchange.js.map +1 -1
  58. package/build/dex/solidly/config.js +13 -0
  59. package/build/dex/solidly/config.js.map +1 -1
  60. package/build/dex/solidly/forks-override/chronos.d.ts +23 -0
  61. package/build/dex/solidly/forks-override/chronos.js +132 -0
  62. package/build/dex/solidly/forks-override/chronos.js.map +1 -0
  63. package/build/dex/solidly/solidly.js +1 -0
  64. package/build/dex/solidly/solidly.js.map +1 -1
  65. package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
  66. package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
  67. package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
  68. package/build/dex/uniswap-v3/constants.d.ts +0 -4
  69. package/build/dex/uniswap-v3/constants.js +1 -6
  70. package/build/dex/uniswap-v3/constants.js.map +1 -1
  71. package/build/dex/uniswap-v3/types.d.ts +3 -20
  72. package/build/dex/uniswap-v3/types.js.map +1 -1
  73. package/build/dex/uniswap-v3/uniswap-v3.d.ts +1 -7
  74. package/build/dex/uniswap-v3/uniswap-v3.js +1 -85
  75. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  76. package/build/dex/woo-fi-v2/config.js +6 -6
  77. package/build/dex/zerox/index.d.ts +1 -1
  78. package/build/dex/zerox/index.js +1 -1
  79. package/build/dex/zerox/index.js.map +1 -1
  80. package/build/implementations/local-paraswap-sdk.js +1 -5
  81. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  82. package/build/router/directswap.js +1 -7
  83. package/build/router/directswap.js.map +1 -1
  84. package/build/router/index.js.map +1 -1
  85. package/build/router/payload-encoder.js +6 -16
  86. package/build/router/payload-encoder.js.map +1 -1
  87. package/build/types.d.ts +0 -2
  88. package/build/utils.d.ts +0 -2
  89. package/build/utils.js +1 -5
  90. package/build/utils.js.map +1 -1
  91. package/package.json +4 -6
  92. package/src/config.ts +2 -5
  93. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -79
  94. package/src/dex/balancer-v2/balancer-v2.ts +4 -153
  95. package/src/dex/balancer-v2/constants.ts +0 -5
  96. package/src/dex/balancer-v2/types.ts +1 -21
  97. package/src/dex/curve-v1/constants.ts +0 -2
  98. package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -57
  99. package/src/dex/curve-v1/curve-v1.ts +5 -144
  100. package/src/dex/curve-v1/types.ts +0 -26
  101. package/src/dex/curve-v1-factory/constants.ts +0 -2
  102. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -1
  103. package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -140
  104. package/src/dex/curve-v1-factory/types.ts +0 -26
  105. package/src/dex/curve-v2.ts +8 -169
  106. package/src/dex/idex.ts +0 -6
  107. package/src/dex/index.ts +2 -2
  108. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +6 -3
  109. package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +14 -3
  110. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
  111. package/src/dex/pancakeswap-v3/utils.ts +4 -1
  112. package/src/dex/simple-exchange.ts +0 -6
  113. package/src/dex/solidly/config.ts +14 -0
  114. package/src/dex/solidly/forks-override/chronos.ts +206 -0
  115. package/src/dex/solidly/solidly-e2e.test.ts +205 -31
  116. package/src/dex/solidly/solidly-integration.test.ts +141 -0
  117. package/src/dex/solidly/solidly.ts +1 -0
  118. package/src/dex/uniswap-v2/uniswap-v2.ts +0 -6
  119. package/src/dex/uniswap-v3/constants.ts +0 -5
  120. package/src/dex/uniswap-v3/types.ts +3 -23
  121. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +2 -100
  122. package/src/dex/uniswap-v3/uniswap-v3.ts +3 -138
  123. package/src/dex/woo-fi-v2/config.ts +6 -6
  124. package/src/dex/zerox/index.ts +0 -7
  125. package/src/implementations/local-paraswap-sdk.ts +1 -8
  126. package/src/router/directswap.ts +0 -23
  127. package/src/router/index.ts +2 -0
  128. package/src/router/payload-encoder.ts +5 -22
  129. package/src/types.ts +0 -2
  130. package/src/utils.ts +0 -5
  131. package/tests/constants-e2e.ts +9 -4
  132. package/tests/utils-e2e.ts +20 -140
  133. package/tests/utils.ts +0 -52
  134. package/src/abi/DirectSwap.json +0 -1018
  135. package/src/abi/swaap-v2/vault.json +0 -918
  136. package/src/dex/swaap-v2/config.ts +0 -19
  137. package/src/dex/swaap-v2/constants.ts +0 -37
  138. package/src/dex/swaap-v2/rate-fetcher.ts +0 -214
  139. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -172
  140. package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -142
  141. package/src/dex/swaap-v2/swaap-v2.ts +0 -901
  142. package/src/dex/swaap-v2/types.ts +0 -95
  143. package/src/dex/swaap-v2/utils.ts +0 -36
  144. package/src/dex/swaap-v2/validators.ts +0 -128
@@ -1,24 +1,17 @@
1
1
  import { Interface, AbiCoder, JsonFragment } from '@ethersproject/abi';
2
- import _ from 'lodash';
3
- import { NumberAsString, OptimalSwapExchange } from '@paraswap/core';
4
- import { assert } from 'ts-essentials';
5
2
  import BigNumber from 'bignumber.js';
6
3
  import CurveABI from '../../abi/Curve.json';
7
- import DirectSwapABI from '../../abi/DirectSwap.json';
8
4
  import { Adapters, CurveV1Config } from './config';
9
5
 
10
6
  import {
11
7
  AdapterExchangeParam,
12
8
  Address,
13
9
  ExchangePrices,
14
- ExchangeTxInfo,
15
10
  PoolLiquidity,
16
11
  PoolPrices,
17
- PreprocessTransactionOptions,
18
12
  SimpleExchangeParam,
19
13
  Token,
20
14
  TransferFeeParams,
21
- TxInfo,
22
15
  } from '../../types';
23
16
  import {
24
17
  Network,
@@ -55,6 +48,8 @@ import { TBTCPool, address as TBTCPoolAddress } from './pools/tBTCpool';
55
48
  import { USDKPool, address as USDKPoolAddress } from './pools/usdkpool';
56
49
  import { USTPool, address as USTPoolAddress } from './pools/ustpool';
57
50
  import { SLINKPool, address as SLINKPoolAddress } from './pools/sLinkpool';
51
+
52
+ import * as _ from 'lodash';
58
53
  import {
59
54
  getBigIntPow,
60
55
  getDexKeysWithNetwork,
@@ -62,13 +57,9 @@ import {
62
57
  isDestTokenTransferFeeToBeExchanged,
63
58
  isSrcTokenTransferFeeToBeExchanged,
64
59
  Utils,
65
- uuidToBytes16,
66
60
  } from '../../utils';
67
61
  import { BN_0 } from '../../bignumber-constants';
68
- import {
69
- getLocalDeadlineAsFriendlyPlaceholder,
70
- SimpleExchange,
71
- } from '../simple-exchange';
62
+ import { SimpleExchange } from '../simple-exchange';
72
63
  import { IDex } from '../idex';
73
64
  import { IDexHelper } from '../../dex-helper';
74
65
  import { Logger } from 'log4js';
@@ -80,12 +71,9 @@ import {
80
71
  CurveV1Data,
81
72
  TokenWithReasonableVolume,
82
73
  CurveSwapFunctions,
83
- CurveV1SwapType,
84
- DirectCurveV1Param,
85
74
  } from './types';
86
75
  import { erc20Iface } from '../../lib/utils-interfaces';
87
76
  import { applyTransferFee } from '../../lib/token-transfer-fee';
88
- import { DIRECT_METHOD_NAME } from './constants';
89
77
 
90
78
  const CURVE_DEFAULT_CHUNKS = 10;
91
79
 
@@ -94,10 +82,7 @@ const CURVE_POOL_GAS = 200 * 1000;
94
82
 
95
83
  const coder = new AbiCoder();
96
84
 
97
- export class CurveV1
98
- extends SimpleExchange
99
- implements IDex<CurveV1Data, DirectCurveV1Param>
100
- {
85
+ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
101
86
  exchangeRouterInterface: Interface;
102
87
  minConversionRate = '1';
103
88
 
@@ -117,8 +102,6 @@ export class CurveV1
117
102
 
118
103
  protected disableFeeOnTransferTokenAddresses: Set<string>;
119
104
 
120
- readonly directSwapIface = new Interface(DirectSwapABI);
121
-
122
105
  readonly SRC_TOKEN_DEX_TRANSFERS = 1;
123
106
  readonly DEST_TOKEN_DEX_TRANSFERS = 1;
124
107
 
@@ -857,128 +840,6 @@ export class CurveV1
857
840
  return this.adapters[side];
858
841
  }
859
842
 
860
- static getDirectFunctionName(): string[] {
861
- return [DIRECT_METHOD_NAME];
862
- }
863
-
864
- getTokenFromAddress(address: Address): Token {
865
- // In this Dex decimals are not used
866
- return { address, decimals: 0 };
867
- }
868
-
869
- async preProcessTransaction(
870
- optimalSwapExchange: OptimalSwapExchange<CurveV1Data>,
871
- srcToken: Token,
872
- _0: Token,
873
- _1: SwapSide,
874
- options: PreprocessTransactionOptions,
875
- ): Promise<[OptimalSwapExchange<CurveV1Data>, ExchangeTxInfo]> {
876
- if (!options.isDirectMethod) {
877
- return [
878
- optimalSwapExchange,
879
- {
880
- deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
881
- },
882
- ];
883
- }
884
-
885
- assert(
886
- optimalSwapExchange.data !== undefined,
887
- `preProcessTransaction: data field is missing`,
888
- );
889
-
890
- let isApproved: boolean | undefined;
891
-
892
- try {
893
- this.erc20Contract.options.address =
894
- this.dexHelper.config.wrapETH(srcToken).address;
895
- const allowance = await this.erc20Contract.methods
896
- .allowance(this.augustusAddress, optimalSwapExchange.data.exchange)
897
- .call(undefined, 'latest');
898
- isApproved =
899
- BigInt(allowance.toString()) >= BigInt(optimalSwapExchange.srcAmount);
900
- } catch (e) {
901
- this.logger.error(
902
- `preProcessTransaction failed to retrieve allowance info: `,
903
- e,
904
- );
905
- }
906
-
907
- return [
908
- {
909
- ...optimalSwapExchange,
910
- data: {
911
- ...optimalSwapExchange.data,
912
- isApproved,
913
- },
914
- },
915
- {
916
- deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
917
- },
918
- ];
919
- }
920
-
921
- getDirectParam(
922
- srcToken: Address,
923
- destToken: Address,
924
- srcAmount: NumberAsString,
925
- destAmount: NumberAsString,
926
- expectedAmount: NumberAsString,
927
- data: CurveV1Data,
928
- side: SwapSide,
929
- permit: string,
930
- uuid: string,
931
- feePercent: NumberAsString,
932
- deadline: NumberAsString,
933
- partner: string,
934
- beneficiary: string,
935
- contractMethod?: string,
936
- ): TxInfo<DirectCurveV1Param> {
937
- if (contractMethod !== DIRECT_METHOD_NAME) {
938
- throw new Error(`Invalid contract method ${contractMethod}`);
939
- }
940
- assert(side === SwapSide.SELL, 'Buy not supported');
941
-
942
- let isApproved: boolean = !!data.isApproved;
943
- if (data.isApproved === undefined) {
944
- this.logger.warn(`isApproved is undefined, defaulting to false`);
945
- }
946
-
947
- const swapParams: DirectCurveV1Param = [
948
- srcToken,
949
- destToken,
950
- data.exchange,
951
- srcAmount,
952
- destAmount,
953
- expectedAmount,
954
- feePercent,
955
- data.i.toString(),
956
- data.j.toString(),
957
- partner,
958
- isApproved,
959
- data.underlyingSwap
960
- ? CurveV1SwapType.EXCHANGE_UNDERLYING
961
- : CurveV1SwapType.EXCHANGE,
962
- beneficiary,
963
- // For CurveV1 we work as it is, without wrapping and unwrapping
964
- false,
965
- permit,
966
- uuidToBytes16(uuid),
967
- ];
968
-
969
- const encoder = (...params: DirectCurveV1Param) => {
970
- return this.directSwapIface.encodeFunctionData(DIRECT_METHOD_NAME, [
971
- params,
972
- ]);
973
- };
974
-
975
- return {
976
- params: swapParams,
977
- encoder,
978
- networkFee: '0',
979
- };
980
- }
981
-
982
843
  async getSimpleParam(
983
844
  srcToken: string,
984
845
  destToken: string,
@@ -1082,7 +943,7 @@ export class CurveV1
1082
943
  // the balances array in the pool as it was a mess to have each curve abi
1083
944
  // Some have balances[uint128] some have balances[uint256]
1084
945
  // One of the consequence for such a hack is below for ETH Pools
1085
- // TODO: below can be highly optimized
946
+ // TODO: below can be highly optimised
1086
947
  // * we don't need to query token decimals every iteration
1087
948
  // * we can use the decimals from the tokens list using the api
1088
949
 
@@ -1,4 +1,3 @@
1
- import { NumberAsString } from '@paraswap/core';
2
1
  import { Address, Token } from '../../types';
3
2
 
4
3
  export type CurveV1Data = {
@@ -7,7 +6,6 @@ export type CurveV1Data = {
7
6
  j: number;
8
7
  underlyingSwap: boolean;
9
8
  deadline: number;
10
- isApproved?: boolean;
11
9
  };
12
10
 
13
11
  export type PoolConfig = {
@@ -44,27 +42,3 @@ export enum CurveSwapFunctions {
44
42
  exchange = 'exchange',
45
43
  exchange_underlying = 'exchange_underlying',
46
44
  }
47
-
48
- export enum CurveV1SwapType {
49
- EXCHANGE,
50
- EXCHANGE_UNDERLYING,
51
- }
52
-
53
- export type DirectCurveV1Param = [
54
- fromToken: Address,
55
- toToken: Address,
56
- exchange: Address,
57
- fromAmount: NumberAsString,
58
- toAmount: NumberAsString,
59
- expectedAmount: NumberAsString,
60
- feePercent: NumberAsString,
61
- i: NumberAsString,
62
- j: NumberAsString,
63
- partner: Address,
64
- isApproved: boolean,
65
- swapType: CurveV1SwapType,
66
- beneficiary: Address,
67
- needWrapNative: boolean,
68
- permit: string,
69
- uuid: string,
70
- ];
@@ -34,5 +34,3 @@ export const NETWORK_ID_TO_NAME: Record<number, string> = {
34
34
  // revisited
35
35
  export const FACTORY_MAX_PLAIN_COINS = 4;
36
36
  export const FACTORY_MAX_PLAIN_IMPLEMENTATIONS_FOR_COIN = 10;
37
-
38
- export const DIRECT_METHOD_NAME = 'directCurveV1Swap';
@@ -29,7 +29,6 @@ function testForNetwork(
29
29
  ContractMethod.simpleSwap,
30
30
  ContractMethod.multiSwap,
31
31
  ContractMethod.megaSwap,
32
- ContractMethod.directCurveV1Swap,
33
32
  ],
34
33
  ],
35
34
  ]);
@@ -1,7 +1,5 @@
1
1
  import _ from 'lodash';
2
- import { AbiItem } from 'web3-utils';
3
- import { NumberAsString, OptimalSwapExchange } from '@paraswap/core';
4
- import { assert, AsyncOrSync } from 'ts-essentials';
2
+ import { AsyncOrSync } from 'ts-essentials';
5
3
  import { Interface, JsonFragment } from '@ethersproject/abi';
6
4
  import {
7
5
  Token,
@@ -13,9 +11,6 @@ import {
13
11
  PoolLiquidity,
14
12
  Logger,
15
13
  TransferFeeParams,
16
- TxInfo,
17
- PreprocessTransactionOptions,
18
- ExchangeTxInfo,
19
14
  } from '../../types';
20
15
  import {
21
16
  SwapSide,
@@ -28,7 +23,6 @@ import {
28
23
  getBigIntPow,
29
24
  getDexKeysWithNetwork,
30
25
  isSrcTokenTransferFeeToBeExchanged,
31
- uuidToBytes16,
32
26
  } from '../../utils';
33
27
  import { IDex } from '../idex';
34
28
  import { IDexHelper } from '../../dex-helper/idex-helper';
@@ -36,19 +30,13 @@ import {
36
30
  CurveSwapFunctions,
37
31
  CurveV1FactoryData,
38
32
  CurveV1FactoryIfaces,
39
- CurveV1SwapType,
40
33
  CustomImplementationNames,
41
34
  ImplementationNames,
42
35
  PoolConstants,
43
- DirectCurveV1Param,
44
36
  } from './types';
45
- import {
46
- getLocalDeadlineAsFriendlyPlaceholder,
47
- SimpleExchange,
48
- } from '../simple-exchange';
37
+ import { SimpleExchange } from '../simple-exchange';
49
38
  import { CurveV1FactoryConfig, Adapters } from './config';
50
39
  import {
51
- DIRECT_METHOD_NAME,
52
40
  FACTORY_MAX_PLAIN_COINS,
53
41
  FACTORY_MAX_PLAIN_IMPLEMENTATIONS_FOR_COIN,
54
42
  MIN_AMOUNT_TO_RECEIVE,
@@ -56,7 +44,6 @@ import {
56
44
  } from './constants';
57
45
  import { CurveV1FactoryPoolManager } from './curve-v1-pool-manager';
58
46
  import CurveABI from '../../abi/Curve.json';
59
- import DirectSwapABI from '../../abi/DirectSwap.json';
60
47
  import FactoryCurveV1ABI from '../../abi/curve-v1-factory/FactoryCurveV1.json';
61
48
  import ThreePoolABI from '../../abi/curve-v1-factory/ThreePool.json';
62
49
  import ERC20ABI from '../../abi/erc20.json';
@@ -74,6 +61,7 @@ import { CustomBasePoolForFactory } from './state-polling-pools/custom-pool-poll
74
61
  import ImplementationConstants from './price-handlers/functions/constants';
75
62
  import { applyTransferFee } from '../../lib/token-transfer-fee';
76
63
  import { PriceHandler } from './price-handlers/price-handler';
64
+ import { AbiItem } from 'web3-utils';
77
65
 
78
66
  const DefaultCoinsABI: AbiItem = {
79
67
  type: 'function',
@@ -94,7 +82,7 @@ const DefaultCoinsABI: AbiItem = {
94
82
 
95
83
  export class CurveV1Factory
96
84
  extends SimpleExchange
97
- implements IDex<CurveV1FactoryData, DirectCurveV1Param>
85
+ implements IDex<CurveV1FactoryData>
98
86
  {
99
87
  readonly hasConstantPriceLargeAmounts = false;
100
88
  readonly needWrapNative = false;
@@ -110,8 +98,6 @@ export class CurveV1Factory
110
98
  readonly SRC_TOKEN_DEX_TRANSFERS = 1;
111
99
  readonly DEST_TOKEN_DEX_TRANSFERS = 1;
112
100
 
113
- readonly directSwapIface = new Interface(DirectSwapABI);
114
-
115
101
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
116
102
  getDexKeysWithNetwork(CurveV1FactoryConfig);
117
103
 
@@ -828,128 +814,6 @@ export class CurveV1Factory
828
814
  };
829
815
  }
830
816
 
831
- getTokenFromAddress(address: Address): Token {
832
- // In this Dex decimals are not used
833
- return { address, decimals: 0 };
834
- }
835
-
836
- async preProcessTransaction(
837
- optimalSwapExchange: OptimalSwapExchange<CurveV1FactoryData>,
838
- srcToken: Token,
839
- _0: Token,
840
- _1: SwapSide,
841
- options: PreprocessTransactionOptions,
842
- ): Promise<[OptimalSwapExchange<CurveV1FactoryData>, ExchangeTxInfo]> {
843
- if (!options.isDirectMethod) {
844
- return [
845
- optimalSwapExchange,
846
- {
847
- deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
848
- },
849
- ];
850
- }
851
-
852
- assert(
853
- optimalSwapExchange.data !== undefined,
854
- `preProcessTransaction: data field is missing`,
855
- );
856
-
857
- let isApproved: boolean | undefined;
858
-
859
- try {
860
- this.erc20Contract.options.address =
861
- this.dexHelper.config.wrapETH(srcToken).address;
862
- const allowance = await this.erc20Contract.methods
863
- .allowance(this.augustusAddress, optimalSwapExchange.data.exchange)
864
- .call(undefined, 'latest');
865
- isApproved =
866
- BigInt(allowance.toString()) >= BigInt(optimalSwapExchange.srcAmount);
867
- } catch (e) {
868
- this.logger.error(
869
- `preProcessTransaction failed to retrieve allowance info: `,
870
- e,
871
- );
872
- }
873
-
874
- return [
875
- {
876
- ...optimalSwapExchange,
877
- data: {
878
- ...optimalSwapExchange.data,
879
- isApproved,
880
- },
881
- },
882
- {
883
- deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
884
- },
885
- ];
886
- }
887
-
888
- getDirectParam(
889
- srcToken: Address,
890
- destToken: Address,
891
- srcAmount: NumberAsString,
892
- destAmount: NumberAsString,
893
- expectedAmount: NumberAsString,
894
- data: CurveV1FactoryData,
895
- side: SwapSide,
896
- permit: string,
897
- uuid: string,
898
- feePercent: NumberAsString,
899
- deadline: NumberAsString,
900
- partner: string,
901
- beneficiary: string,
902
- contractMethod?: string,
903
- ): TxInfo<DirectCurveV1Param> {
904
- if (contractMethod !== DIRECT_METHOD_NAME) {
905
- throw new Error(`Invalid contract method ${contractMethod}`);
906
- }
907
- assert(side === SwapSide.SELL, 'Buy not supported');
908
-
909
- let isApproved: boolean = !!data.isApproved;
910
- if (data.isApproved === undefined) {
911
- this.logger.warn(`isApproved is undefined, defaulting to false`);
912
- }
913
-
914
- const swapParams: DirectCurveV1Param = [
915
- srcToken,
916
- destToken,
917
- data.exchange,
918
- srcAmount,
919
- destAmount,
920
- expectedAmount,
921
- feePercent,
922
- data.i.toString(),
923
- data.j.toString(),
924
- partner,
925
- isApproved,
926
- data.underlyingSwap
927
- ? CurveV1SwapType.EXCHANGE_UNDERLYING
928
- : CurveV1SwapType.EXCHANGE,
929
- beneficiary,
930
- // For CurveV1 we work as it is, without wrapping and unwrapping
931
- false,
932
- permit,
933
- uuidToBytes16(uuid),
934
- ];
935
-
936
- const encoder = (...params: DirectCurveV1Param) => {
937
- return this.directSwapIface.encodeFunctionData(DIRECT_METHOD_NAME, [
938
- params,
939
- ]);
940
- };
941
-
942
- return {
943
- params: swapParams,
944
- encoder,
945
- networkFee: '0',
946
- };
947
- }
948
-
949
- static getDirectFunctionName(): string[] {
950
- return [DIRECT_METHOD_NAME];
951
- }
952
-
953
817
  async getSimpleParam(
954
818
  srcToken: string,
955
819
  destToken: string,
@@ -1,5 +1,4 @@
1
1
  import { Interface } from '@ethersproject/abi';
2
- import { NumberAsString } from '@paraswap/core';
3
2
  import { Address } from '../../types';
4
3
 
5
4
  // The difference between PoolContextConstants and PoolConstants lies in the fact
@@ -70,7 +69,6 @@ export type CurveV1FactoryData = {
70
69
  i: number;
71
70
  j: number;
72
71
  underlyingSwap: boolean;
73
- isApproved?: boolean;
74
72
  };
75
73
 
76
74
  export enum FactoryImplementationNames {
@@ -183,27 +181,3 @@ export type CurveV1FactoryIfaces = {
183
181
  };
184
182
 
185
183
  export type LiquidityInCache = Record<string, number>;
186
-
187
- export enum CurveV1SwapType {
188
- EXCHANGE,
189
- EXCHANGE_UNDERLYING,
190
- }
191
-
192
- export type DirectCurveV1Param = [
193
- fromToken: Address,
194
- toToken: Address,
195
- exchange: Address,
196
- fromAmount: NumberAsString,
197
- toAmount: NumberAsString,
198
- expectedAmount: NumberAsString,
199
- feePercent: NumberAsString,
200
- i: NumberAsString,
201
- j: NumberAsString,
202
- partner: Address,
203
- isApproved: boolean,
204
- swapType: CurveV1SwapType,
205
- beneficiary: Address,
206
- needWrapNative: boolean,
207
- permit: string,
208
- uuid: string,
209
- ];