@paraswap/dex-lib 2.16.4 → 2.16.5-direct-swaps.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 (131) hide show
  1. package/build/abi/DirectSwap.json +970 -0
  2. package/build/abi/woo-fi/WooFeeManager.abi.json +318 -0
  3. package/build/abi/woo-fi/WooPP.abi.json +548 -0
  4. package/build/abi/woo-fi/Wooracle.abi.json +260 -0
  5. package/build/config.js +6 -6
  6. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  7. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  8. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  9. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  10. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  11. package/build/dex/balancer-v2/balancer-v2.d.ts +9 -3
  12. package/build/dex/balancer-v2/balancer-v2.js +81 -0
  13. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  14. package/build/dex/balancer-v2/constants.d.ts +4 -0
  15. package/build/dex/balancer-v2/constants.js +6 -1
  16. package/build/dex/balancer-v2/constants.js.map +1 -1
  17. package/build/dex/balancer-v2/types.d.ts +18 -1
  18. package/build/dex/balancer-v2/types.js.map +1 -1
  19. package/build/dex/curve-v1/constants.d.ts +1 -0
  20. package/build/dex/curve-v1/constants.js +2 -1
  21. package/build/dex/curve-v1/constants.js.map +1 -1
  22. package/build/dex/curve-v1/curve-v1.d.ts +9 -3
  23. package/build/dex/curve-v1/curve-v1.js +90 -4
  24. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  25. package/build/dex/curve-v1/types.d.ts +23 -0
  26. package/build/dex/curve-v1/types.js +6 -1
  27. package/build/dex/curve-v1/types.js.map +1 -1
  28. package/build/dex/curve-v1-factory/constants.d.ts +1 -0
  29. package/build/dex/curve-v1-factory/constants.js +2 -1
  30. package/build/dex/curve-v1-factory/constants.js.map +1 -1
  31. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +11 -4
  32. package/build/dex/curve-v1-factory/curve-v1-factory.js +85 -0
  33. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  34. package/build/dex/curve-v1-factory/types.d.ts +23 -0
  35. package/build/dex/curve-v1-factory/types.js +6 -1
  36. package/build/dex/curve-v1-factory/types.js.map +1 -1
  37. package/build/dex/curve-v2.d.ts +28 -7
  38. package/build/dex/curve-v2.js +89 -1
  39. package/build/dex/curve-v2.js.map +1 -1
  40. package/build/dex/idex.d.ts +1 -1
  41. package/build/dex/quickswap-v3.d.ts +21 -0
  42. package/build/dex/quickswap-v3.js +40 -0
  43. package/build/dex/quickswap-v3.js.map +1 -0
  44. package/build/dex/simple-exchange.d.ts +2 -0
  45. package/build/dex/simple-exchange.js +1 -0
  46. package/build/dex/simple-exchange.js.map +1 -1
  47. package/build/dex/test-dex/config.d.ts +4 -0
  48. package/build/dex/test-dex/config.js +15 -0
  49. package/build/dex/test-dex/config.js.map +1 -0
  50. package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
  51. package/build/dex/test-dex/test-dex-pool.js +63 -0
  52. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  53. package/build/dex/test-dex/test-dex.d.ts +37 -0
  54. package/build/dex/test-dex/test-dex.js +126 -0
  55. package/build/dex/test-dex/test-dex.js.map +1 -0
  56. package/build/dex/test-dex/types.d.ts +6 -0
  57. package/build/dex/test-dex/types.js +3 -0
  58. package/build/dex/test-dex/types.js.map +1 -0
  59. package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
  60. package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
  61. package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
  62. package/build/dex/uniswap-v3/constants.d.ts +4 -0
  63. package/build/dex/uniswap-v3/constants.js +6 -1
  64. package/build/dex/uniswap-v3/constants.js.map +1 -1
  65. package/build/dex/uniswap-v3/types.d.ts +20 -3
  66. package/build/dex/uniswap-v3/types.js.map +1 -1
  67. package/build/dex/uniswap-v3/uniswap-v3.d.ts +7 -1
  68. package/build/dex/uniswap-v3/uniswap-v3.js +85 -1
  69. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  70. package/build/dex/woo-fi/config.d.ts +4 -0
  71. package/build/dex/woo-fi/config.js +141 -0
  72. package/build/dex/woo-fi/config.js.map +1 -0
  73. package/build/dex/woo-fi/constants.d.ts +5 -0
  74. package/build/dex/woo-fi/constants.js +20 -0
  75. package/build/dex/woo-fi/constants.js.map +1 -0
  76. package/build/dex/woo-fi/types.d.ts +48 -0
  77. package/build/dex/woo-fi/types.js +3 -0
  78. package/build/dex/woo-fi/types.js.map +1 -0
  79. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +14 -0
  80. package/build/dex/woo-fi/woo-fi-decimal-math.js +42 -0
  81. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +1 -0
  82. package/build/dex/woo-fi/woo-fi-math.d.ts +31 -0
  83. package/build/dex/woo-fi/woo-fi-math.js +300 -0
  84. package/build/dex/woo-fi/woo-fi-math.js.map +1 -0
  85. package/build/dex/woo-fi/woo-fi.d.ts +65 -0
  86. package/build/dex/woo-fi/woo-fi.js +480 -0
  87. package/build/dex/woo-fi/woo-fi.js.map +1 -0
  88. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  89. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  90. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  91. package/build/dex/zerox/index.d.ts +1 -1
  92. package/build/dex/zerox/index.js +1 -1
  93. package/build/dex/zerox/index.js.map +1 -1
  94. package/build/implementations/local-paraswap-sdk.js +5 -1
  95. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  96. package/build/router/directswap.js +3 -1
  97. package/build/router/directswap.js.map +1 -1
  98. package/build/router/index.js.map +1 -1
  99. package/build/types.d.ts +1 -0
  100. package/package.json +5 -3
  101. package/src/abi/DirectSwap.json +970 -0
  102. package/src/config.ts +6 -6
  103. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +71 -0
  104. package/src/dex/balancer-v2/balancer-v2.ts +150 -3
  105. package/src/dex/balancer-v2/constants.ts +5 -0
  106. package/src/dex/balancer-v2/types.ts +19 -1
  107. package/src/dex/curve-v1/constants.ts +2 -0
  108. package/src/dex/curve-v1/curve-v1-e2e.test.ts +57 -0
  109. package/src/dex/curve-v1/curve-v1.ts +142 -5
  110. package/src/dex/curve-v1/types.ts +25 -0
  111. package/src/dex/curve-v1-factory/constants.ts +2 -0
  112. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +1 -0
  113. package/src/dex/curve-v1-factory/curve-v1-factory.ts +138 -4
  114. package/src/dex/curve-v1-factory/types.ts +25 -0
  115. package/src/dex/curve-v2.ts +166 -8
  116. package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +2 -2
  117. package/src/dex/idex.ts +6 -0
  118. package/src/dex/simple-exchange.ts +6 -0
  119. package/src/dex/uniswap-v2/uniswap-v2.ts +6 -0
  120. package/src/dex/uniswap-v3/constants.ts +5 -0
  121. package/src/dex/uniswap-v3/types.ts +23 -3
  122. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +100 -2
  123. package/src/dex/uniswap-v3/uniswap-v3.ts +138 -3
  124. package/src/dex/zerox/index.ts +7 -0
  125. package/src/implementations/local-paraswap-sdk.ts +8 -1
  126. package/src/router/directswap.ts +9 -0
  127. package/src/router/index.ts +0 -2
  128. package/src/types.ts +1 -0
  129. package/tests/constants-e2e.ts +3 -3
  130. package/tests/utils-e2e.ts +135 -20
  131. package/tests/utils.ts +52 -0
@@ -29,12 +29,37 @@ 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 { sleep } from './utils';
32
+ import { generateDeployBytecode, 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 adapterBytecode = '';
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
+ );
38
63
 
39
64
  const erc20Interface = new Interface(Erc20ABI);
40
65
  const augustusInterface = new Interface(AugustusABI);
@@ -146,7 +171,7 @@ function allowTokenTransferProxyParams(
146
171
  };
147
172
  }
148
173
 
149
- function deployAdapterParams(bytecode: string, network = Network.MAINNET) {
174
+ function deployContractParams(bytecode: string, network = Network.MAINNET) {
150
175
  const ownerAddress = DEPLOYER_ADDRESS[network];
151
176
  if (!ownerAddress) throw new Error('No deployer address set for network');
152
177
  return {
@@ -156,13 +181,51 @@ function deployAdapterParams(bytecode: string, network = Network.MAINNET) {
156
181
  };
157
182
  }
158
183
 
159
- function whiteListAdapterParams(contractAddress: Address, network: Network) {
184
+ function augustusSetImplementationParams(
185
+ contractAddress: Address,
186
+ network: Network,
187
+ functionName: string,
188
+ ) {
160
189
  const augustusAddress = generateConfig(network).augustusAddress;
161
190
  if (!augustusAddress) throw new Error('No whitelist address set for network');
162
191
  const ownerAddress = MULTISIG[network];
163
192
  if (!ownerAddress) throw new Error('No whitelist owner set for network');
164
- const role =
165
- '0x8429d542926e6695b59ac6fbdcd9b37e8b1aeb757afab06ab60b1bb5878c3b49';
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
+
166
229
  return {
167
230
  from: ownerAddress,
168
231
  to: augustusAddress,
@@ -174,6 +237,21 @@ function whiteListAdapterParams(contractAddress: Address, network: Network) {
174
237
  };
175
238
  }
176
239
 
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
+
177
255
  export async function testE2E(
178
256
  srcToken: Token,
179
257
  destToken: Token,
@@ -183,7 +261,7 @@ export async function testE2E(
183
261
  dexKey: string,
184
262
  contractMethod: ContractMethod,
185
263
  network: Network = Network.MAINNET,
186
- provider: Provider,
264
+ _0: Provider,
187
265
  poolIdentifiers?: string[],
188
266
  limitOrderProvider?: DummyLimitOrderProvider,
189
267
  transferFees?: TransferFeeParams,
@@ -202,26 +280,63 @@ export async function testE2E(
202
280
  expect(allowanceTx!.success).toEqual(true);
203
281
  }
204
282
 
205
- if (adapterBytecode) {
283
+ if (deployedTestContractAddress) {
284
+ const whitelistTx = await ts.simulate(
285
+ augustusGrantRoleParams(
286
+ deployedTestContractAddress,
287
+ network,
288
+ testContractType || 'adapter',
289
+ ),
290
+ );
291
+ expect(whitelistTx.success).toEqual(true);
292
+
293
+ if (testContractType === 'router') {
294
+ const setImplementationTx = await ts.simulate(
295
+ augustusSetImplementationParams(
296
+ deployedTestContractAddress,
297
+ network,
298
+ contractMethod,
299
+ ),
300
+ );
301
+ expect(setImplementationTx.success).toEqual(true);
302
+ }
303
+ } else if (testContractBytecode) {
206
304
  const deployTx = await ts.simulate(
207
- deployAdapterParams(adapterBytecode, network),
305
+ deployContractParams(testContractBytecode, network),
208
306
  );
209
307
 
210
308
  expect(deployTx.success).toEqual(true);
211
- const adapterAddress =
309
+
310
+ const contractAddress =
212
311
  deployTx.transaction.transaction_info.contract_address;
213
312
  console.log(
214
- 'Deployed adapter to address',
215
- adapterAddress,
216
- 'used',
217
- deployTx.gasUsed,
218
- 'gas',
313
+ formatDeployMessage(
314
+ 'adapter',
315
+ contractAddress,
316
+ ts.forkId,
317
+ testContractName || '',
318
+ testContractRelativePath || '',
319
+ ),
219
320
  );
220
-
221
321
  const whitelistTx = await ts.simulate(
222
- whiteListAdapterParams(adapterAddress, network),
322
+ augustusGrantRoleParams(
323
+ contractAddress,
324
+ network,
325
+ testContractType || 'adapter',
326
+ ),
223
327
  );
224
328
  expect(whitelistTx.success).toEqual(true);
329
+
330
+ if (testContractType === 'router') {
331
+ const setImplementationTx = await ts.simulate(
332
+ augustusSetImplementationParams(
333
+ contractAddress,
334
+ network,
335
+ contractMethod,
336
+ ),
337
+ );
338
+ expect(setImplementationTx.success).toEqual(true);
339
+ }
225
340
  }
226
341
 
227
342
  const useAPI = testingEndpoint && !poolIdentifiers;
@@ -345,13 +460,13 @@ export async function newTestE2E({
345
460
  await ts.setup();
346
461
  }
347
462
 
348
- if (useTenderly && adapterBytecode) {
463
+ if (useTenderly && testContractBytecode) {
349
464
  assert(
350
465
  ts instanceof TenderlySimulation,
351
466
  '`ts` is not an instance of TenderlySimulation',
352
467
  );
353
468
  const deployTx = await ts.simulate(
354
- deployAdapterParams(adapterBytecode, network),
469
+ deployContractParams(testContractBytecode, network),
355
470
  );
356
471
 
357
472
  expect(deployTx.success).toEqual(true);
@@ -366,7 +481,7 @@ export async function newTestE2E({
366
481
  );
367
482
 
368
483
  const whitelistTx = await ts.simulate(
369
- whiteListAdapterParams(adapterAddress, network),
484
+ augustusGrantRoleParams(adapterAddress, network),
370
485
  );
371
486
  expect(whitelistTx.success).toEqual(true);
372
487
  }
package/tests/utils.ts CHANGED
@@ -1,5 +1,8 @@
1
+ /* eslint-disable no-console */
2
+ import { ethers } from 'ethers';
1
3
  import { PoolPrices, PoolLiquidity, Address } from '../src/types';
2
4
  import { SwapSide } from '../src/constants';
5
+ import { assert } from 'ts-essentials';
3
6
 
4
7
  // Assuming that the amounts are increasing at same interval, and start with 0
5
8
  export function checkPoolPrices(
@@ -73,3 +76,52 @@ export const sleep = (time: number) =>
73
76
  new Promise(resolve => {
74
77
  setTimeout(resolve, time);
75
78
  });
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
+ };