@paraswap/dex-lib 4.1.3-wusdl.0 → 4.1.3

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 (39) hide show
  1. package/build/dex/aave-v3-stata-v2/config.js +13 -0
  2. package/build/dex/aave-v3-stata-v2/config.js.map +1 -1
  3. package/build/dex/algebra/config.js +1 -1
  4. package/build/dex/algebra/config.js.map +1 -1
  5. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -1
  6. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +2 -0
  7. package/build/dex/balancer-v3/balancer-v3-pool.js +14 -4
  8. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -1
  9. package/build/dex/balancer-v3/balancer-v3.js +1 -1
  10. package/build/dex/balancer-v3/balancer-v3.js.map +1 -1
  11. package/build/dex/balancer-v3/config.js +12 -0
  12. package/build/dex/balancer-v3/config.js.map +1 -1
  13. package/build/dex/cables/cables.d.ts +1 -1
  14. package/build/dex/cables/cables.js +26 -7
  15. package/build/dex/cables/cables.js.map +1 -1
  16. package/build/generic-swap-transaction-builder.d.ts +1 -1
  17. package/build/generic-swap-transaction-builder.js +6 -1
  18. package/build/generic-swap-transaction-builder.js.map +1 -1
  19. package/build/implementations/local-paraswap-sdk.js +1 -1
  20. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  21. package/package.json +3 -3
  22. package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +11 -32
  23. package/src/dex/aave-v3-stata-v2/config.ts +16 -0
  24. package/src/dex/algebra/config.ts +1 -1
  25. package/src/dex/balancer-v2/balancer-v2-integration.test.ts +11 -12
  26. package/src/dex/balancer-v2/pools/gyro/GyroEPool.ts +0 -1
  27. package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +110 -0
  28. package/src/dex/balancer-v3/balancer-v3-events.test.ts +157 -84
  29. package/src/dex/balancer-v3/balancer-v3-integration.test.ts +101 -5
  30. package/src/dex/balancer-v3/balancer-v3-pool.ts +33 -13
  31. package/src/dex/balancer-v3/balancer-v3.ts +1 -1
  32. package/src/dex/balancer-v3/config.ts +12 -0
  33. package/src/dex/cables/cables-e2e.test.ts +40 -40
  34. package/src/dex/cables/cables.ts +37 -10
  35. package/src/generic-swap-transaction-builder.ts +10 -2
  36. package/src/implementations/local-paraswap-sdk.ts +1 -1
  37. package/tests/constants-e2e.ts +46 -1
  38. package/tests/tenderly-simulation.ts +2 -0
  39. package/tests/utils-e2e.ts +4 -7
@@ -399,11 +399,15 @@ export class Cables extends SimpleExchange implements IDex<any> {
399
399
  let decimals = baseToken.decimals;
400
400
  let out_decimals = quoteToken.decimals;
401
401
 
402
- let price = this.calculatePriceSwap(
403
- orderbook,
404
- Number(amt) / 10 ** decimals,
405
- isInputQuote,
406
- );
402
+ let price = 0;
403
+
404
+ try {
405
+ price = this.calculatePriceSwap(
406
+ orderbook,
407
+ Number(amt) / 10 ** decimals,
408
+ isInputQuote,
409
+ );
410
+ } catch {}
407
411
  result.push(BigInt(Math.round(price * 10 ** out_decimals)));
408
412
  }
409
413
  return result;
@@ -416,11 +420,17 @@ export class Cables extends SimpleExchange implements IDex<any> {
416
420
  ) {
417
421
  let sumBaseQty = 0;
418
422
  let sumQuoteQty = 0;
423
+
419
424
  const selectedRows: string[][] = [];
420
425
 
421
426
  const isBase = qtyMode;
422
427
  const isQuote = !qtyMode;
423
428
 
429
+ const totalVolume: number = prices.reduce(
430
+ (sum, [, volume]) => sum + Number(volume),
431
+ 0,
432
+ );
433
+
424
434
  for (const [price, volume] of prices) {
425
435
  if (isBase) {
426
436
  if (sumBaseQty >= requiredQty) {
@@ -460,6 +470,10 @@ export class Cables extends SimpleExchange implements IDex<any> {
460
470
  selectedRows.push([price, currentBaseQty.toString()]);
461
471
  }
462
472
 
473
+ if (sumBaseQty == 0) {
474
+ return 0;
475
+ }
476
+
463
477
  const vSumBase = selectedRows.reduce((sum: number, [price, volume]) => {
464
478
  return sum + Number(price) * Number(volume);
465
479
  }, 0);
@@ -468,11 +482,24 @@ export class Cables extends SimpleExchange implements IDex<any> {
468
482
  .dividedBy(new BigNumber(sumBaseQty))
469
483
  .toNumber();
470
484
 
485
+ let result: any;
471
486
  if (isBase) {
472
- return requiredQty / price;
487
+ result = requiredQty / price;
473
488
  } else {
474
- return requiredQty * price;
489
+ result = requiredQty * price;
475
490
  }
491
+
492
+ if (isQuote) {
493
+ if (requiredQty > totalVolume) {
494
+ result = 0;
495
+ }
496
+ } else {
497
+ if (result > totalVolume) {
498
+ result = 0;
499
+ }
500
+ }
501
+
502
+ return result;
476
503
  }
477
504
 
478
505
  async getPricesVolume(
@@ -538,10 +565,10 @@ export class Cables extends SimpleExchange implements IDex<any> {
538
565
  const priceData = priceMap[pairKey];
539
566
 
540
567
  let orderbook: any[] = [];
541
- if (side === SwapSide.BUY) {
568
+ orderbook = priceData.bids;
569
+ // reverse orderbook if isInputQuote
570
+ if (isInputQuote) {
542
571
  orderbook = priceData.asks;
543
- } else {
544
- orderbook = priceData.bids;
545
572
  }
546
573
  if (orderbook?.length === 0) {
547
574
  throw new Error(`Empty orderbook for ${pairKey}`);
@@ -447,7 +447,7 @@ export class GenericSwapTransactionBuilder {
447
447
  uuid: string;
448
448
  beneficiary?: Address;
449
449
  onlyParams?: boolean;
450
- }): Promise<TxObject> {
450
+ }): Promise<TxObject | (string | string[])[]> {
451
451
  // if beneficiary is not defined, then in smart contract it will be replaced to msg.sender
452
452
  const _beneficiary =
453
453
  beneficiary !== NULL_ADDRESS &&
@@ -494,6 +494,8 @@ export class GenericSwapTransactionBuilder {
494
494
  ));
495
495
  }
496
496
 
497
+ if (onlyParams) return params;
498
+
497
499
  const value = (
498
500
  priceRoute.srcToken.toLowerCase() === ETHER_ADDRESS.toLowerCase()
499
501
  ? BigInt(
@@ -525,8 +527,14 @@ export class GenericSwapTransactionBuilder {
525
527
  isReferral,
526
528
  isSkipBlacklist,
527
529
  }: FeeParams): string {
530
+ const partnerAddress =
531
+ feePercent === '0' && !isTakeSurplus && !isReferral
532
+ ? NULL_ADDRESS
533
+ : partner;
534
+
528
535
  // Partner address shifted left to make room for flags and fee percent
529
- const partialFeeCodeWithPartnerAddress = BigNumber.from(partner).shl(96);
536
+ const partialFeeCodeWithPartnerAddress =
537
+ BigNumber.from(partnerAddress).shl(96);
530
538
  let partialFeeCodeWithBitFlags = BigNumber.from(0); // default 0 is safe if none the conditions pass
531
539
 
532
540
  const isFixedFees = !BigNumber.from(feePercent).isZero();
@@ -117,7 +117,7 @@ export class LocalParaswapSDK implements IParaSwapSDK {
117
117
  transferFees?: TransferFeeParams,
118
118
  forceRoute?: AddressOrSymbol[],
119
119
  ): Promise<OptimalRate> {
120
- const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
120
+ const blockNumber = await this.dexHelper.provider.getBlockNumber();
121
121
  const poolIdentifiers =
122
122
  _poolIdentifiers ||
123
123
  (await this.pricingHelper.getPoolIdentifiers(
@@ -1209,6 +1209,10 @@ export const Tokens: {
1209
1209
  addBalance: _balancesFn,
1210
1210
  addAllowance: _allowancesFn,
1211
1211
  },
1212
+ waArbWETH: {
1213
+ address: '0x4ce13a79f45c1be00bdabd38b764ac28c082704e',
1214
+ decimals: 18,
1215
+ },
1212
1216
  ETH: { address: ETHER_ADDRESS, decimals: 18 },
1213
1217
  USDCe: {
1214
1218
  address: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8',
@@ -1243,6 +1247,10 @@ export const Tokens: {
1243
1247
  addBalance: _balancesFn,
1244
1248
  addAllowance: _allowancesFn,
1245
1249
  },
1250
+ waArbUSDT: {
1251
+ address: '0xa6D12574eFB239FC1D2099732bd8b5dC6306897F',
1252
+ decimals: 6,
1253
+ },
1246
1254
  FRAX: {
1247
1255
  address: '0x17FC002b466eEc40DaE837Fc4bE5c67993ddBd6F',
1248
1256
  decimals: 18,
@@ -1361,6 +1369,10 @@ export const Tokens: {
1361
1369
  address: '0x7dff72693f6a4149b17e7c6314655f6a9f7c8b33',
1362
1370
  decimals: 18,
1363
1371
  },
1372
+ waArbwstETH: {
1373
+ address: '0xe98fc055c99decd8da0c111b090885d5d15c774e',
1374
+ decimals: 18,
1375
+ },
1364
1376
  },
1365
1377
  [Network.OPTIMISM]: {
1366
1378
  DAI: {
@@ -1678,10 +1690,34 @@ export const Tokens: {
1678
1690
  address: '0x4ea71a20e655794051d1ee8b6e4a3269b13ccacc',
1679
1691
  decimals: 6,
1680
1692
  },
1693
+ waBasUSDC: {
1694
+ address: '0xC768c589647798a6EE01A91FdE98EF2ed046DBD6',
1695
+ decimals: 6,
1696
+ },
1681
1697
  aaveUSDC: {
1682
1698
  address: '0x4e65fe4dba92790696d040ac24aa414708f5c0ab',
1683
1699
  decimals: 6,
1684
1700
  },
1701
+ aBasUSDC: {
1702
+ address: '0x4e65fe4dba92790696d040ac24aa414708f5c0ab',
1703
+ decimals: 6,
1704
+ },
1705
+ waBasWETH: {
1706
+ address: '0xe298b938631f750dd409fb18227c4a23dcdaab9b',
1707
+ decimals: 18,
1708
+ },
1709
+ waBaswstETH: {
1710
+ address: '0x0830820d1a9aa1554364752d6d8f55c836871b74',
1711
+ decimals: 18,
1712
+ },
1713
+ sUSDS: {
1714
+ address: '0x5875eee11cf8398102fdad704c9e96607675467a',
1715
+ decimals: 18,
1716
+ },
1717
+ smUSDC: {
1718
+ address: '0x616a4e1db48e22028f6bbf20444cd3b8e3273738',
1719
+ decimals: 18,
1720
+ },
1685
1721
  },
1686
1722
  [Network.SEPOLIA]: {
1687
1723
  ETH: { address: ETHER_ADDRESS, decimals: 18 },
@@ -2007,6 +2043,7 @@ export const Holders: {
2007
2043
  MIM: '0xf46bb6dda9709c49efb918201d97f6474eac5aea',
2008
2044
  VST: '0x59bf0545fca0e5ad48e13da269facd2e8c886ba4',
2009
2045
  aArbUSDC: '0x048BF2F5908e95976CeAD0E47D805b3803E286e2',
2046
+ waArbUSDT: '0xa6D12574eFB239FC1D2099732bd8b5dC6306897F',
2010
2047
  ZYB: '0x3ec0eddcd1e25025077327886a78133589082fb2',
2011
2048
  WBTC: '0xd9d611c6943585bc0e18e51034af8fa28778f7da',
2012
2049
  RDNT: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6',
@@ -2025,6 +2062,7 @@ export const Holders: {
2025
2062
  GHO: '0xda39E48523770197EF3CbB70C1bf1cCCF9B4b1E7',
2026
2063
  USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812',
2027
2064
  wUSDM: '0x12c9cE6b155c8aaC74004732A621B64bC669bb79',
2065
+ waArbWETH: '0x854B004700885A61107B458f11eCC169A019b764',
2028
2066
  },
2029
2067
  [Network.OPTIMISM]: {
2030
2068
  ETH: '0xF6D4E5a7c5215F91f59a95065190CCa24bf64554',
@@ -2087,7 +2125,7 @@ export const Holders: {
2087
2125
  waGnoGNO: '0x9Ec6472Fc33D9a5D17613484aDF0295A001fDF32',
2088
2126
  },
2089
2127
  [Network.BASE]: {
2090
- WETH: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28',
2128
+ WETH: '0x24D61e5411C143135068557AfD06546d81A751b8',
2091
2129
  PRIME: '0xe3879b7359695f802d6FD56Bb76fD82C362Dafd6',
2092
2130
  ETH: '0xd34ea7278e6bd48defe656bbe263aef11101469c',
2093
2131
  MAV: '0xf977814e90da44bfa03b6295a0616a897441acec',
@@ -2107,10 +2145,17 @@ export const Holders: {
2107
2145
  DOG: '0xbe3ab8a87730684ef1e476064c2e43c3e982f8e8',
2108
2146
  stataUSDC: '0x88Cac91ADDE2208039A227B373C2A692C0700547',
2109
2147
  aaveUSDC: '0x5DE3c5BE52D7aDbdC3aEFe2eA061A2ECE0C7d766',
2148
+ waBasUSDC: '0xC768c589647798a6EE01A91FdE98EF2ed046DBD6',
2110
2149
  USDM: '0x426c4966fC76Bf782A663203c023578B744e4C5E',
2111
2150
  crvUSD: '0xBbAbDB1385deA5285113581A7024d6DC04131101',
2112
2151
  cbETH: '0x50e011dD1e2b4906F1534623cD134B30422bb11E',
2113
2152
  wUSDM: '0xe30965Acd0Ee1CE2e0Cd0AcBFB3596bD6fC78A51',
2153
+ aBasUSDC: '0xC006544B93e86E8999623C1D12d2E352c61C8123',
2154
+ waBasWETH: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
2155
+ wstETH: '0x96892b8FBd24e0aC40BD98A304095a6c485A6A68',
2156
+ waBaswstETH: '0x854B004700885A61107B458f11eCC169A019b764',
2157
+ sUSDS: '0xC9716E991396AA933Fa7A481003a5953bcBabC17',
2158
+ smUSDC: '0x88457F47c9BEC8379eB90d8dC3592F79084e555d',
2114
2159
  },
2115
2160
  [Network.SEPOLIA]: {
2116
2161
  bal: '0xDb4ff41B4C1222c2b1869A67Be115070688989a2',
@@ -21,6 +21,7 @@ export type SimulationResult = {
21
21
 
22
22
  export interface TransactionSimulator {
23
23
  vnetId: string;
24
+ rpcURL: string;
24
25
  setup(): Promise<void>;
25
26
 
26
27
  getChainNameByChainId(network: number): string;
@@ -33,6 +34,7 @@ export interface TransactionSimulator {
33
34
 
34
35
  export class EstimateGasSimulation implements TransactionSimulator {
35
36
  vnetId: string = '0';
37
+ rpcURL: string = '';
36
38
 
37
39
  constructor(private provider: Provider) {}
38
40
 
@@ -214,7 +214,7 @@ class APIParaswapSDK implements IParaSwapSDK {
214
214
  const minMaxAmount = _minMaxAmount.toString();
215
215
  let deadline = Number((Math.floor(Date.now() / 1000) + 10 * 60).toFixed());
216
216
 
217
- return await this.transactionBuilder.build({
217
+ return (await this.transactionBuilder.build({
218
218
  priceRoute,
219
219
  minMaxAmount: minMaxAmount.toString(),
220
220
  userAddress,
@@ -222,7 +222,7 @@ class APIParaswapSDK implements IParaSwapSDK {
222
222
  partnerFeePercent: '0',
223
223
  deadline: deadline.toString(),
224
224
  uuid: uuid(),
225
- });
225
+ })) as TxObject;
226
226
  }
227
227
  }
228
228
 
@@ -485,11 +485,8 @@ export async function testE2E(
485
485
  }
486
486
 
487
487
  if (paraswap.dexHelper?.replaceProviderWithRPC) {
488
- paraswap.dexHelper?.replaceProviderWithRPC(
489
- `https://virtual.${ts.getChainNameByChainId(network)}.rpc.tenderly.co/${
490
- ts.vnetId
491
- }`,
492
- );
488
+ console.log('ts.rpcURL: ', ts.rpcURL);
489
+ paraswap.dexHelper?.replaceProviderWithRPC(ts.rpcURL);
493
490
  }
494
491
 
495
492
  try {