@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
@@ -29,37 +29,12 @@ import { constructSimpleSDK, SimpleFetchSDK } from '@paraswap/sdk';
29
29
  import axios from 'axios';
30
30
  import { SmartToken, StateOverrides } from './smart-tokens';
31
31
  import { GIFTER_ADDRESS } from './constants-e2e';
32
- import { generateDeployBytecode, sleep } from './utils';
32
+ import { sleep } from './utils';
33
33
  import { assert } from 'ts-essentials';
34
34
 
35
35
  export const testingEndpoint = process.env.E2E_TEST_ENDPOINT;
36
36
 
37
- const testContractProjectRootPath = process.env.TEST_CONTRACT_PROJECT_ROOT_PATH;
38
- const testContractName = process.env.TEST_CONTRACT_NAME;
39
- const testContractConfigFileName = process.env.TEST_CONTRACT_CONFIG_FILE_NAME;
40
- const testContractRelativePath = process.env.TEST_CONTRACT_RELATIVE_PATH;
41
- // Comma separated fields from config or actual values
42
- const testContractDeployArgs = process.env.TEST_CONTRACT_DEPLOY_ARGS;
43
-
44
- // If you want to test against deployed and verified contract
45
- const deployedTestContractAddress = process.env.DEPLOYED_TEST_CONTRACT_ADDRESS;
46
- const testContractType = process.env.TEST_CONTRACT_TYPE;
47
-
48
- // Only for router tests
49
- const testDirectRouterAbiPath = process.env.TEST_DIRECT_ROUTER_ABI_PATH;
50
-
51
- const directRouterIface = new Interface(
52
- testDirectRouterAbiPath ? require(testDirectRouterAbiPath) : '[]',
53
- );
54
-
55
- const testContractBytecode = generateDeployBytecode(
56
- testContractProjectRootPath,
57
- testContractName,
58
- testContractConfigFileName,
59
- testContractRelativePath,
60
- testContractDeployArgs,
61
- testContractType,
62
- );
37
+ const adapterBytecode = '';
63
38
 
64
39
  const erc20Interface = new Interface(Erc20ABI);
65
40
  const augustusInterface = new Interface(AugustusABI);
@@ -171,7 +146,7 @@ function allowTokenTransferProxyParams(
171
146
  };
172
147
  }
173
148
 
174
- function deployContractParams(bytecode: string, network = Network.MAINNET) {
149
+ function deployAdapterParams(bytecode: string, network = Network.MAINNET) {
175
150
  const ownerAddress = DEPLOYER_ADDRESS[network];
176
151
  if (!ownerAddress) throw new Error('No deployer address set for network');
177
152
  return {
@@ -181,51 +156,13 @@ function deployContractParams(bytecode: string, network = Network.MAINNET) {
181
156
  };
182
157
  }
183
158
 
184
- function augustusSetImplementationParams(
185
- contractAddress: Address,
186
- network: Network,
187
- functionName: string,
188
- ) {
159
+ function whiteListAdapterParams(contractAddress: Address, network: Network) {
189
160
  const augustusAddress = generateConfig(network).augustusAddress;
190
161
  if (!augustusAddress) throw new Error('No whitelist address set for network');
191
162
  const ownerAddress = MULTISIG[network];
192
163
  if (!ownerAddress) throw new Error('No whitelist owner set for network');
193
-
194
- return {
195
- from: ownerAddress,
196
- to: augustusAddress,
197
- data: augustusInterface.encodeFunctionData('setImplementation', [
198
- directRouterIface.getSighash(functionName),
199
- contractAddress,
200
- ]),
201
- value: '0',
202
- };
203
- }
204
-
205
- function augustusGrantRoleParams(
206
- contractAddress: Address,
207
- network: Network,
208
- type: string = 'adapter',
209
- ) {
210
- const augustusAddress = generateConfig(network).augustusAddress;
211
- if (!augustusAddress) throw new Error('No whitelist address set for network');
212
- const ownerAddress = MULTISIG[network];
213
- if (!ownerAddress) throw new Error('No whitelist owner set for network');
214
-
215
- let role: string;
216
- switch (type) {
217
- case 'adapter':
218
- role =
219
- '0x8429d542926e6695b59ac6fbdcd9b37e8b1aeb757afab06ab60b1bb5878c3b49';
220
- break;
221
- case 'router':
222
- role =
223
- '0x7a05a596cb0ce7fdea8a1e1ec73be300bdb35097c944ce1897202f7a13122eb2';
224
- break;
225
- default:
226
- throw new Error(`Unrecognized type ${type}`);
227
- }
228
-
164
+ const role =
165
+ '0x8429d542926e6695b59ac6fbdcd9b37e8b1aeb757afab06ab60b1bb5878c3b49';
229
166
  return {
230
167
  from: ownerAddress,
231
168
  to: augustusAddress,
@@ -237,21 +174,6 @@ function augustusGrantRoleParams(
237
174
  };
238
175
  }
239
176
 
240
- export function formatDeployMessage(
241
- type: 'router' | 'adapter',
242
- address: Address,
243
- forkId: string,
244
- contractName: string,
245
- contractPath: string,
246
- ) {
247
- // This formatting is useful for verification on Tenderly
248
- return `Deployed ${type} contract with env params:
249
- TENDERLY_FORK_ID=${forkId}
250
- TENDERLY_VERIFY_CONTRACT_ADDRESS=${address}
251
- TENDERLY_VERIFY_CONTRACT_NAME=${contractName}
252
- TENDERLY_VERIFY_CONTRACT_PATH=${contractPath}`;
253
- }
254
-
255
177
  export async function testE2E(
256
178
  srcToken: Token,
257
179
  destToken: Token,
@@ -261,13 +183,12 @@ export async function testE2E(
261
183
  dexKey: string,
262
184
  contractMethod: ContractMethod,
263
185
  network: Network = Network.MAINNET,
264
- _0: Provider,
186
+ provider: Provider,
265
187
  poolIdentifiers?: string[],
266
188
  limitOrderProvider?: DummyLimitOrderProvider,
267
189
  transferFees?: TransferFeeParams,
268
190
  // Specified in BPS: part of 10000
269
191
  slippage?: number,
270
- sleepMs?: number,
271
192
  ) {
272
193
  const amount = BigInt(_amount);
273
194
  const ts = new TenderlySimulation(network);
@@ -281,63 +202,26 @@ export async function testE2E(
281
202
  expect(allowanceTx!.success).toEqual(true);
282
203
  }
283
204
 
284
- if (deployedTestContractAddress) {
285
- const whitelistTx = await ts.simulate(
286
- augustusGrantRoleParams(
287
- deployedTestContractAddress,
288
- network,
289
- testContractType || 'adapter',
290
- ),
291
- );
292
- expect(whitelistTx.success).toEqual(true);
293
-
294
- if (testContractType === 'router') {
295
- const setImplementationTx = await ts.simulate(
296
- augustusSetImplementationParams(
297
- deployedTestContractAddress,
298
- network,
299
- contractMethod,
300
- ),
301
- );
302
- expect(setImplementationTx.success).toEqual(true);
303
- }
304
- } else if (testContractBytecode) {
205
+ if (adapterBytecode) {
305
206
  const deployTx = await ts.simulate(
306
- deployContractParams(testContractBytecode, network),
207
+ deployAdapterParams(adapterBytecode, network),
307
208
  );
308
209
 
309
210
  expect(deployTx.success).toEqual(true);
310
-
311
- const contractAddress =
211
+ const adapterAddress =
312
212
  deployTx.transaction.transaction_info.contract_address;
313
213
  console.log(
314
- formatDeployMessage(
315
- 'adapter',
316
- contractAddress,
317
- ts.forkId,
318
- testContractName || '',
319
- testContractRelativePath || '',
320
- ),
214
+ 'Deployed adapter to address',
215
+ adapterAddress,
216
+ 'used',
217
+ deployTx.gasUsed,
218
+ 'gas',
321
219
  );
220
+
322
221
  const whitelistTx = await ts.simulate(
323
- augustusGrantRoleParams(
324
- contractAddress,
325
- network,
326
- testContractType || 'adapter',
327
- ),
222
+ whiteListAdapterParams(adapterAddress, network),
328
223
  );
329
224
  expect(whitelistTx.success).toEqual(true);
330
-
331
- if (testContractType === 'router') {
332
- const setImplementationTx = await ts.simulate(
333
- augustusSetImplementationParams(
334
- contractAddress,
335
- network,
336
- contractMethod,
337
- ),
338
- );
339
- expect(setImplementationTx.success).toEqual(true);
340
- }
341
225
  }
342
226
 
343
227
  const useAPI = testingEndpoint && !poolIdentifiers;
@@ -348,10 +232,6 @@ export async function testE2E(
348
232
 
349
233
  if (paraswap.initializePricing) await paraswap.initializePricing();
350
234
 
351
- if (sleepMs) {
352
- await sleep(sleepMs);
353
- }
354
-
355
235
  if (paraswap.dexHelper?.replaceProviderWithRPC) {
356
236
  paraswap.dexHelper?.replaceProviderWithRPC(
357
237
  `https://rpc.tenderly.co/fork/${ts.forkId}`,
@@ -465,13 +345,13 @@ export async function newTestE2E({
465
345
  await ts.setup();
466
346
  }
467
347
 
468
- if (useTenderly && testContractBytecode) {
348
+ if (useTenderly && adapterBytecode) {
469
349
  assert(
470
350
  ts instanceof TenderlySimulation,
471
351
  '`ts` is not an instance of TenderlySimulation',
472
352
  );
473
353
  const deployTx = await ts.simulate(
474
- deployContractParams(testContractBytecode, network),
354
+ deployAdapterParams(adapterBytecode, network),
475
355
  );
476
356
 
477
357
  expect(deployTx.success).toEqual(true);
@@ -486,7 +366,7 @@ export async function newTestE2E({
486
366
  );
487
367
 
488
368
  const whitelistTx = await ts.simulate(
489
- augustusGrantRoleParams(adapterAddress, network),
369
+ whiteListAdapterParams(adapterAddress, network),
490
370
  );
491
371
  expect(whitelistTx.success).toEqual(true);
492
372
  }
package/tests/utils.ts CHANGED
@@ -1,8 +1,5 @@
1
- /* eslint-disable no-console */
2
- import { ethers } from 'ethers';
3
1
  import { PoolPrices, PoolLiquidity, Address } from '../src/types';
4
2
  import { SwapSide } from '../src/constants';
5
- import { assert } from 'ts-essentials';
6
3
 
7
4
  // Assuming that the amounts are increasing at same interval, and start with 0
8
5
  export function checkPoolPrices(
@@ -76,52 +73,3 @@ export const sleep = (time: number) =>
76
73
  new Promise(resolve => {
77
74
  setTimeout(resolve, time);
78
75
  });
79
-
80
- export const generateDeployBytecode = (
81
- testContractProjectRootPath: string | undefined,
82
- testContractName: string | undefined,
83
- testContractConfigFileName: string | undefined,
84
- testContractRelativePath: string | undefined,
85
- testContractDeployArgs: string | undefined,
86
- testContractType: string | undefined,
87
- ): string => {
88
- if (
89
- !testContractProjectRootPath ||
90
- !testContractName ||
91
- !testContractConfigFileName ||
92
- !testContractRelativePath ||
93
- !testContractDeployArgs ||
94
- !testContractType
95
- ) {
96
- return '';
97
- }
98
-
99
- const artifactJsonPath = `${testContractProjectRootPath}/artifacts/${testContractName}.json`;
100
- const configJsonPath = `${testContractProjectRootPath}/config/${testContractConfigFileName}.json`;
101
- const fieldsToPickFromConfig = testContractDeployArgs.split(',');
102
-
103
- const artifact = require(artifactJsonPath) as {
104
- abi: ethers.ContractInterface;
105
- bytecode: string;
106
- };
107
- // I don't want to type this testing thing. If something is wrong, I will just throw
108
- const config = require(configJsonPath) as any;
109
- const factory = new ethers.ContractFactory(artifact.abi, artifact.bytecode);
110
-
111
- const args = fieldsToPickFromConfig.map(f => {
112
- const value = config[f];
113
- if (value === undefined) {
114
- console.log(
115
- `Field ${f} is not defined in configJsonPath=${configJsonPath}. Using value as it is`,
116
- );
117
- return f;
118
- }
119
- return value;
120
- });
121
-
122
- const deployedBytecode = factory.getDeployTransaction(...args).data;
123
-
124
- assert(deployedBytecode !== undefined, 'deployedBytecode is undefined');
125
-
126
- return deployedBytecode.toString();
127
- };