@paraswap/dex-lib 2.21.0 → 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 (131) hide show
  1. package/build/config.js +2 -4
  2. package/build/config.js.map +1 -1
  3. package/build/dex/balancer-v2/balancer-v2.d.ts +3 -9
  4. package/build/dex/balancer-v2/balancer-v2.js +0 -83
  5. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  6. package/build/dex/balancer-v2/constants.d.ts +0 -4
  7. package/build/dex/balancer-v2/constants.js +1 -6
  8. package/build/dex/balancer-v2/constants.js.map +1 -1
  9. package/build/dex/balancer-v2/types.d.ts +1 -20
  10. package/build/dex/balancer-v2/types.js.map +1 -1
  11. package/build/dex/curve-v1/constants.d.ts +0 -1
  12. package/build/dex/curve-v1/constants.js +1 -2
  13. package/build/dex/curve-v1/constants.js.map +1 -1
  14. package/build/dex/curve-v1/curve-v1.d.ts +3 -9
  15. package/build/dex/curve-v1/curve-v1.js +4 -92
  16. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  17. package/build/dex/curve-v1/types.d.ts +0 -24
  18. package/build/dex/curve-v1/types.js +1 -6
  19. package/build/dex/curve-v1/types.js.map +1 -1
  20. package/build/dex/curve-v1-factory/constants.d.ts +0 -1
  21. package/build/dex/curve-v1-factory/constants.js +1 -2
  22. package/build/dex/curve-v1-factory/constants.js.map +1 -1
  23. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +4 -11
  24. package/build/dex/curve-v1-factory/curve-v1-factory.js +0 -87
  25. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  26. package/build/dex/curve-v1-factory/types.d.ts +0 -24
  27. package/build/dex/curve-v1-factory/types.js +1 -6
  28. package/build/dex/curve-v1-factory/types.js.map +1 -1
  29. package/build/dex/curve-v2.d.ts +7 -29
  30. package/build/dex/curve-v2.js +1 -91
  31. package/build/dex/curve-v2.js.map +1 -1
  32. package/build/dex/idex.d.ts +1 -1
  33. package/build/dex/index.js +2 -4
  34. package/build/dex/index.js.map +1 -1
  35. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
  36. package/build/dex/pancakeswap-v3/utils.js.map +1 -1
  37. package/build/dex/quickswap/config.js +0 -8
  38. package/build/dex/quickswap/config.js.map +1 -1
  39. package/build/dex/simple-exchange.d.ts +0 -2
  40. package/build/dex/simple-exchange.js +0 -1
  41. package/build/dex/simple-exchange.js.map +1 -1
  42. package/build/dex/solidly/config.js +13 -0
  43. package/build/dex/solidly/config.js.map +1 -1
  44. package/build/dex/solidly/forks-override/chronos.d.ts +3 -0
  45. package/build/dex/solidly/forks-override/chronos.js +88 -0
  46. package/build/dex/solidly/forks-override/chronos.js.map +1 -1
  47. package/build/dex/solidly/solidly.js +1 -0
  48. package/build/dex/solidly/solidly.js.map +1 -1
  49. package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
  50. package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
  51. package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
  52. package/build/dex/uniswap-v3/constants.d.ts +0 -4
  53. package/build/dex/uniswap-v3/constants.js +1 -6
  54. package/build/dex/uniswap-v3/constants.js.map +1 -1
  55. package/build/dex/uniswap-v3/types.d.ts +3 -20
  56. package/build/dex/uniswap-v3/types.js.map +1 -1
  57. package/build/dex/uniswap-v3/uniswap-v3.d.ts +1 -7
  58. package/build/dex/uniswap-v3/uniswap-v3.js +1 -85
  59. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  60. package/build/dex/woo-fi-v2/config.js +6 -6
  61. package/build/dex/zerox/index.d.ts +1 -1
  62. package/build/dex/zerox/index.js +1 -1
  63. package/build/dex/zerox/index.js.map +1 -1
  64. package/build/implementations/local-paraswap-sdk.js +1 -5
  65. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  66. package/build/router/directswap.js +1 -7
  67. package/build/router/directswap.js.map +1 -1
  68. package/build/router/index.js.map +1 -1
  69. package/build/router/payload-encoder.js +6 -16
  70. package/build/router/payload-encoder.js.map +1 -1
  71. package/build/types.d.ts +0 -2
  72. package/build/utils.d.ts +0 -2
  73. package/build/utils.js +1 -5
  74. package/build/utils.js.map +1 -1
  75. package/package.json +4 -6
  76. package/src/config.ts +2 -5
  77. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -79
  78. package/src/dex/balancer-v2/balancer-v2.ts +4 -153
  79. package/src/dex/balancer-v2/constants.ts +0 -5
  80. package/src/dex/balancer-v2/types.ts +1 -21
  81. package/src/dex/curve-v1/constants.ts +0 -2
  82. package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -57
  83. package/src/dex/curve-v1/curve-v1.ts +5 -144
  84. package/src/dex/curve-v1/types.ts +0 -26
  85. package/src/dex/curve-v1-factory/constants.ts +0 -2
  86. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -1
  87. package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -140
  88. package/src/dex/curve-v1-factory/types.ts +0 -26
  89. package/src/dex/curve-v2.ts +8 -169
  90. package/src/dex/idex.ts +0 -6
  91. package/src/dex/index.ts +2 -4
  92. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +6 -3
  93. package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +14 -3
  94. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
  95. package/src/dex/pancakeswap-v3/utils.ts +4 -1
  96. package/src/dex/quickswap/config.ts +0 -9
  97. package/src/dex/quickswap/quickswap-e2e.test.ts +0 -109
  98. package/src/dex/simple-exchange.ts +0 -6
  99. package/src/dex/solidly/config.ts +14 -0
  100. package/src/dex/solidly/forks-override/chronos.ts +206 -0
  101. package/src/dex/solidly/solidly-e2e.test.ts +205 -31
  102. package/src/dex/solidly/solidly-integration.test.ts +141 -0
  103. package/src/dex/solidly/solidly.ts +1 -0
  104. package/src/dex/uniswap-v2/uniswap-v2.ts +0 -6
  105. package/src/dex/uniswap-v3/constants.ts +0 -5
  106. package/src/dex/uniswap-v3/types.ts +3 -23
  107. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +2 -100
  108. package/src/dex/uniswap-v3/uniswap-v3.ts +3 -138
  109. package/src/dex/woo-fi-v2/config.ts +6 -6
  110. package/src/dex/zerox/index.ts +0 -7
  111. package/src/implementations/local-paraswap-sdk.ts +1 -8
  112. package/src/router/directswap.ts +0 -23
  113. package/src/router/index.ts +2 -0
  114. package/src/router/payload-encoder.ts +5 -22
  115. package/src/types.ts +0 -2
  116. package/src/utils.ts +0 -5
  117. package/tests/constants-e2e.ts +9 -4
  118. package/tests/utils-e2e.ts +20 -140
  119. package/tests/utils.ts +0 -52
  120. package/src/abi/DirectSwap.json +0 -1018
  121. package/src/abi/swaap-v2/vault.json +0 -918
  122. package/src/dex/quickswap/camelot-v3.ts +0 -15
  123. package/src/dex/swaap-v2/config.ts +0 -19
  124. package/src/dex/swaap-v2/constants.ts +0 -37
  125. package/src/dex/swaap-v2/rate-fetcher.ts +0 -214
  126. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -172
  127. package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -142
  128. package/src/dex/swaap-v2/swaap-v2.ts +0 -901
  129. package/src/dex/swaap-v2/types.ts +0 -95
  130. package/src/dex/swaap-v2/utils.ts +0 -36
  131. package/src/dex/swaap-v2/validators.ts +0 -128
@@ -7,9 +7,6 @@ import {
7
7
  ExchangePrices,
8
8
  Log,
9
9
  Logger,
10
- TxInfo,
11
- PreprocessTransactionOptions,
12
- ExchangeTxInfo,
13
10
  PoolLiquidity,
14
11
  PoolPrices,
15
12
  SimpleExchangeParam,
@@ -30,13 +27,8 @@ import { WeightedPool } from './pools/weighted/WeightedPool';
30
27
  import { PhantomStablePool } from './pools/phantom-stable/PhantomStablePool';
31
28
  import { LinearPool } from './pools/linear/LinearPool';
32
29
  import VaultABI from '../../abi/balancer-v2/vault.json';
33
- import DirectSwapABI from '../../abi/DirectSwap.json';
34
30
  import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
35
- import {
36
- getDexKeysWithNetwork,
37
- getBigIntPow,
38
- uuidToBytes16,
39
- } from '../../utils';
31
+ import { getBigIntPow, getDexKeysWithNetwork } from '../../utils';
40
32
  import { IDex } from '../../dex/idex';
41
33
  import { IDexHelper } from '../../dex-helper';
42
34
  import {
@@ -49,15 +41,11 @@ import {
49
41
  PoolStateCache,
50
42
  PoolStateMap,
51
43
  SubgraphPoolAddressDictionary,
52
- BalancerV2DirectParam,
53
44
  SubgraphPoolBase,
54
45
  SwapTypes,
55
46
  } from './types';
56
- import {
57
- getLocalDeadlineAsFriendlyPlaceholder,
58
- SimpleExchange,
59
- } from '../simple-exchange';
60
- import { BalancerConfig, Adapters } from './config';
47
+ import { SimpleExchange } from '../simple-exchange';
48
+ import { Adapters, BalancerConfig } from './config';
61
49
  import {
62
50
  getAllPoolsUsedInPaths,
63
51
  isSameAddress,
@@ -65,12 +53,10 @@ import {
65
53
  poolGetPathForTokenInOut,
66
54
  } from './utils';
67
55
  import {
68
- DirectMethods,
69
56
  MIN_USD_LIQUIDITY_TO_FETCH,
70
57
  STABLE_GAS_COST,
71
58
  VARIABLE_GAS_COST_PER_CYCLE,
72
59
  } from './constants';
73
- import { NumberAsString, OptimalSwapExchange } from '@paraswap/core';
74
60
 
75
61
  const fetchAllPools = `query ($count: Int) {
76
62
  pools: pools(
@@ -507,16 +493,13 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
507
493
 
508
494
  export class BalancerV2
509
495
  extends SimpleExchange
510
- implements
511
- IDex<BalancerV2Data, BalancerV2DirectParam, OptimizedBalancerV2Data>
496
+ implements IDex<BalancerV2Data, BalancerParam, OptimizedBalancerV2Data>
512
497
  {
513
498
  public eventPools: BalancerV2EventPool;
514
499
 
515
500
  readonly hasConstantPriceLargeAmounts = false;
516
501
  readonly isFeeOnTransferSupported = false;
517
502
 
518
- readonly directSwapIface = new Interface(DirectSwapABI);
519
-
520
503
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
521
504
  getDexKeysWithNetwork(BalancerConfig);
522
505
 
@@ -1036,138 +1019,6 @@ export class BalancerV2
1036
1019
  return params;
1037
1020
  }
1038
1021
 
1039
- static getDirectFunctionName(): string[] {
1040
- return [DirectMethods.directSell, DirectMethods.directBuy];
1041
- }
1042
-
1043
- getTokenFromAddress(address: Address): Token {
1044
- // In this Dex decimals are not used
1045
- return { address, decimals: 0 };
1046
- }
1047
-
1048
- async preProcessTransaction(
1049
- optimalSwapExchange: OptimalSwapExchange<OptimizedBalancerV2Data>,
1050
- srcToken: Token,
1051
- _0: Token,
1052
- _1: SwapSide,
1053
- options: PreprocessTransactionOptions,
1054
- ): Promise<[OptimalSwapExchange<OptimizedBalancerV2Data>, ExchangeTxInfo]> {
1055
- if (!options.isDirectMethod) {
1056
- return [
1057
- optimalSwapExchange,
1058
- {
1059
- deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
1060
- },
1061
- ];
1062
- }
1063
-
1064
- assert(
1065
- optimalSwapExchange.data !== undefined,
1066
- `preProcessTransaction: data field is missing`,
1067
- );
1068
-
1069
- let isApproved: boolean | undefined;
1070
-
1071
- try {
1072
- this.erc20Contract.options.address =
1073
- this.dexHelper.config.wrapETH(srcToken).address;
1074
- const allowance = await this.erc20Contract.methods
1075
- .allowance(this.augustusAddress, this.vaultAddress)
1076
- .call(undefined, 'latest');
1077
- isApproved =
1078
- BigInt(allowance.toString()) >= BigInt(optimalSwapExchange.srcAmount);
1079
- } catch (e) {
1080
- this.logger.error(
1081
- `preProcessTransaction failed to retrieve allowance info: `,
1082
- e,
1083
- );
1084
- }
1085
-
1086
- return [
1087
- {
1088
- ...optimalSwapExchange,
1089
- data: {
1090
- ...optimalSwapExchange.data,
1091
- isApproved,
1092
- },
1093
- },
1094
- {
1095
- deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
1096
- },
1097
- ];
1098
- }
1099
-
1100
- getDirectParam(
1101
- srcToken: Address,
1102
- destToken: Address,
1103
- srcAmount: NumberAsString,
1104
- destAmount: NumberAsString,
1105
- expectedAmount: NumberAsString,
1106
- data: OptimizedBalancerV2Data,
1107
- side: SwapSide,
1108
- permit: string,
1109
- uuid: string,
1110
- feePercent: NumberAsString,
1111
- deadline: NumberAsString,
1112
- partner: string,
1113
- beneficiary: string,
1114
- contractMethod?: string,
1115
- ): TxInfo<BalancerV2DirectParam> {
1116
- if (
1117
- contractMethod !== DirectMethods.directSell &&
1118
- contractMethod !== DirectMethods.directBuy
1119
- ) {
1120
- throw new Error(`Invalid contract method ${contractMethod}`);
1121
- }
1122
-
1123
- let isApproved: boolean = !!data.isApproved;
1124
- if (data.isApproved === undefined) {
1125
- this.logger.warn(`isApproved is undefined, defaulting to false`);
1126
- }
1127
-
1128
- const [, swaps, assets, funds, limits, _deadline] = this.getBalancerParam(
1129
- srcToken,
1130
- destToken,
1131
- srcAmount,
1132
- destAmount,
1133
- data,
1134
- side,
1135
- );
1136
-
1137
- const swapParams: BalancerV2DirectParam = [
1138
- swaps,
1139
- assets,
1140
- funds,
1141
- limits,
1142
- srcAmount,
1143
- destAmount,
1144
- expectedAmount,
1145
- _deadline,
1146
- feePercent,
1147
- this.vaultAddress,
1148
- partner,
1149
- isApproved,
1150
- beneficiary,
1151
- permit,
1152
- uuidToBytes16(uuid),
1153
- ];
1154
-
1155
- const encoder = (...params: BalancerV2DirectParam) => {
1156
- return this.directSwapIface.encodeFunctionData(
1157
- side === SwapSide.SELL
1158
- ? DirectMethods.directSell
1159
- : DirectMethods.directBuy,
1160
- [params],
1161
- );
1162
- };
1163
-
1164
- return {
1165
- params: swapParams,
1166
- encoder,
1167
- networkFee: '0',
1168
- };
1169
- }
1170
-
1171
1022
  async getSimpleParam(
1172
1023
  srcToken: string,
1173
1024
  destToken: string,
@@ -8,8 +8,3 @@ export const STABLE_GAS_COST = 84_000;
8
8
 
9
9
  // I see three pools used in trade: (57856 + 79098 + 51041) / 3 = 62665 ~ 63k
10
10
  export const VARIABLE_GAS_COST_PER_CYCLE = 63_000;
11
-
12
- export enum DirectMethods {
13
- directSell = 'directBalancerV2GivenInSwap',
14
- directBuy = 'directBalancerV2GivenOutSwap',
15
- }
@@ -1,4 +1,3 @@
1
- import { NumberAsString } from '@paraswap/core';
2
1
  import { Address } from '../../types';
3
2
 
4
3
  // These should match the Balancer Pool types available on Subgraph
@@ -86,13 +85,12 @@ export type BalancerSwapV2 = {
86
85
 
87
86
  export type OptimizedBalancerV2Data = {
88
87
  swaps: BalancerSwapV2[];
89
- isApproved?: boolean;
90
88
  };
91
89
 
92
90
  export type BalancerFunds = {
93
91
  sender: string;
94
- fromInternalBalance: boolean;
95
92
  recipient: string;
93
+ fromInternalBalance: boolean;
96
94
  toInternalBalance: boolean;
97
95
  };
98
96
 
@@ -119,24 +117,6 @@ export type BalancerParam = [
119
117
  deadline: string,
120
118
  ];
121
119
 
122
- export type BalancerV2DirectParam = [
123
- swaps: BalancerSwap[],
124
- assets: Address[],
125
- funds: BalancerFunds,
126
- limits: NumberAsString[],
127
- fromAmount: NumberAsString,
128
- toAmount: NumberAsString,
129
- expectedAmount: NumberAsString,
130
- deadline: NumberAsString,
131
- feePercent: NumberAsString,
132
- vault: Address,
133
- partner: Address,
134
- isApproved: boolean,
135
- beneficiary: Address,
136
- permit: string,
137
- uuid: string,
138
- ];
139
-
140
120
  export type BalancerV2Data = {
141
121
  poolId: string;
142
122
  };
@@ -2,8 +2,6 @@ import { CurveV1Config } from './config';
2
2
  import { SwerveConfig } from './forks/swerve/config';
3
3
  import { CurveForksConfig } from './forks/curve-forks/config';
4
4
 
5
- export const DIRECT_METHOD_NAME = 'directCurveV1Swap';
6
-
7
5
  export const AllCurveForks = [
8
6
  ...Object.keys(CurveV1Config),
9
7
  ...Object.keys(CurveForksConfig),
@@ -133,63 +133,6 @@ describe('CurveV1 E2E', () => {
133
133
  });
134
134
  });
135
135
 
136
- describe('CurveV1 POLYGON', () => {
137
- const network = Network.POLYGON;
138
- const tokens = Tokens[network];
139
- const holders = Holders[network];
140
- const provider = new StaticJsonRpcProvider(
141
- generateConfig(network).privateHttpProvider,
142
- network,
143
- );
144
-
145
- const tokensToTest = [
146
- [
147
- {
148
- symbol: 'USDT',
149
- amount: (10 ** 8).toString(),
150
- },
151
- {
152
- symbol: 'DAI',
153
- amount: (10 ** 8).toString(),
154
- },
155
- ],
156
- ];
157
-
158
- const sideToContractMethods = new Map([
159
- [
160
- SwapSide.SELL,
161
- [
162
- ContractMethod.simpleSwap,
163
- ContractMethod.multiSwap,
164
- ContractMethod.megaSwap,
165
- ContractMethod.directCurveV1Swap,
166
- ],
167
- ],
168
- ]);
169
-
170
- sideToContractMethods.forEach((contractMethods, side) =>
171
- contractMethods.forEach((contractMethod: ContractMethod) => {
172
- tokensToTest.forEach(pair => {
173
- describe(`${contractMethod}`, () => {
174
- it(`${pair[0].symbol} -> ${pair[1].symbol}`, async () => {
175
- await testE2E(
176
- tokens[pair[0].symbol],
177
- tokens[pair[1].symbol],
178
- holders[pair[0].symbol],
179
- side === SwapSide.SELL ? pair[0].amount : pair[1].amount,
180
- side,
181
- dexKey,
182
- contractMethod,
183
- network,
184
- provider,
185
- );
186
- });
187
- });
188
- });
189
- }),
190
- );
191
- });
192
-
193
136
  describe('FANTOM', () => {
194
137
  const network = Network.FANTOM;
195
138
  const tokens = Tokens[network];
@@ -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
  ]);