@paraswap/dex-lib 2.42.11 → 2.42.13

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 (228) hide show
  1. package/build/abi/kyberswap-elastic/IAntiSnipAttackPositionManager.json +1276 -0
  2. package/build/abi/kyberswap-elastic/IFactory.json +550 -0
  3. package/build/abi/kyberswap-elastic/IPool.json +1042 -0
  4. package/build/abi/kyberswap-elastic/IQuoterV2.json +226 -0
  5. package/build/abi/kyberswap-elastic/IRouter.json +239 -0
  6. package/build/abi/kyberswap-elastic/TicksFeesReader.json +142 -0
  7. package/build/abi/wombat/asset.json +769 -0
  8. package/build/abi/wombat/bmw.json +1247 -0
  9. package/build/abi/wombat/pool.json +1364 -0
  10. package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +26 -0
  11. package/build/dex/baseswap-v3/baseswap-v3-factory.js +44 -0
  12. package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +1 -0
  13. package/build/dex/{algebra/algebra-pool.d.ts → baseswap-v3/baseswap-v3-pool.d.ts} +16 -16
  14. package/build/dex/{algebra/algebra-pool.js → baseswap-v3/baseswap-v3-pool.js} +137 -161
  15. package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +1 -0
  16. package/build/dex/baseswap-v3/baseswap-v3.d.ts +71 -0
  17. package/build/dex/baseswap-v3/baseswap-v3.js +752 -0
  18. package/build/dex/baseswap-v3/baseswap-v3.js.map +1 -0
  19. package/build/dex/baseswap-v3/config.d.ts +9 -0
  20. package/build/dex/baseswap-v3/config.js +48 -0
  21. package/build/dex/baseswap-v3/config.js.map +1 -0
  22. package/build/dex/baseswap-v3/constants.d.ts +28 -0
  23. package/build/dex/baseswap-v3/constants.js +35 -0
  24. package/build/dex/baseswap-v3/constants.js.map +1 -0
  25. package/build/dex/baseswap-v3/contract-math/BitMath.d.ts +4 -0
  26. package/build/dex/baseswap-v3/contract-math/BitMath.js +93 -0
  27. package/build/dex/baseswap-v3/contract-math/BitMath.js.map +1 -0
  28. package/build/dex/baseswap-v3/contract-math/FixedPoint128.d.ts +3 -0
  29. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js +8 -0
  30. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +1 -0
  31. package/build/dex/baseswap-v3/contract-math/FixedPoint96.d.ts +4 -0
  32. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js +9 -0
  33. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +1 -0
  34. package/build/dex/baseswap-v3/contract-math/FullMath.d.ts +4 -0
  35. package/build/dex/baseswap-v3/contract-math/FullMath.js +19 -0
  36. package/build/dex/baseswap-v3/contract-math/FullMath.js.map +1 -0
  37. package/build/dex/baseswap-v3/contract-math/LiquidityMath.d.ts +3 -0
  38. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js +22 -0
  39. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +1 -0
  40. package/build/dex/baseswap-v3/contract-math/Oracle.d.ts +10 -0
  41. package/build/dex/baseswap-v3/contract-math/Oracle.js +133 -0
  42. package/build/dex/baseswap-v3/contract-math/Oracle.js.map +1 -0
  43. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.d.ts +10 -0
  44. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js +91 -0
  45. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +1 -0
  46. package/build/dex/baseswap-v3/contract-math/SwapMath.d.ts +8 -0
  47. package/build/dex/baseswap-v3/contract-math/SwapMath.js +70 -0
  48. package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +1 -0
  49. package/build/dex/baseswap-v3/contract-math/Tick.d.ts +7 -0
  50. package/build/dex/baseswap-v3/contract-math/Tick.js +45 -0
  51. package/build/dex/baseswap-v3/contract-math/Tick.js.map +1 -0
  52. package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +7 -0
  53. package/build/dex/baseswap-v3/contract-math/TickBitMap.js +84 -0
  54. package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +1 -0
  55. package/build/dex/baseswap-v3/contract-math/TickMath.d.ts +8 -0
  56. package/build/dex/baseswap-v3/contract-math/TickMath.js +162 -0
  57. package/build/dex/baseswap-v3/contract-math/TickMath.js.map +1 -0
  58. package/build/dex/baseswap-v3/contract-math/UnsafeMath.d.ts +3 -0
  59. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js +10 -0
  60. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +1 -0
  61. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.d.ts +37 -0
  62. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js +393 -0
  63. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +1 -0
  64. package/build/dex/baseswap-v3/contract-math/utils.d.ts +7 -0
  65. package/build/dex/baseswap-v3/contract-math/utils.js +42 -0
  66. package/build/dex/baseswap-v3/contract-math/utils.js.map +1 -0
  67. package/build/dex/baseswap-v3/types.d.ts +164 -0
  68. package/build/dex/baseswap-v3/types.js +9 -0
  69. package/build/dex/baseswap-v3/types.js.map +1 -0
  70. package/build/dex/baseswap-v3/utils.d.ts +6 -0
  71. package/build/dex/baseswap-v3/utils.js +65 -0
  72. package/build/dex/baseswap-v3/utils.js.map +1 -0
  73. package/build/dex/dexalot/dexalot.d.ts +3 -2
  74. package/build/dex/dexalot/dexalot.js +33 -19
  75. package/build/dex/dexalot/dexalot.js.map +1 -1
  76. package/build/dex/hello/config.d.ts +4 -0
  77. package/build/dex/hello/config.js +15 -0
  78. package/build/dex/hello/config.js.map +1 -0
  79. package/build/dex/hello/hello-pool.d.ts +39 -0
  80. package/build/dex/hello/hello-pool.js +64 -0
  81. package/build/dex/hello/hello-pool.js.map +1 -0
  82. package/build/dex/hello/hello.d.ts +37 -0
  83. package/build/dex/hello/hello.js +126 -0
  84. package/build/dex/hello/hello.js.map +1 -0
  85. package/build/dex/hello/types.d.ts +6 -0
  86. package/build/dex/hello/types.js +3 -0
  87. package/build/dex/hello/types.js.map +1 -0
  88. package/build/dex/kyberswap-elastic/config.d.ts +4 -0
  89. package/build/dex/kyberswap-elastic/config.js +80 -0
  90. package/build/dex/kyberswap-elastic/config.js.map +1 -0
  91. package/build/dex/kyberswap-elastic/constants.d.ts +17 -0
  92. package/build/dex/kyberswap-elastic/constants.js +42 -0
  93. package/build/dex/kyberswap-elastic/constants.js.map +1 -0
  94. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.d.ts +4 -0
  95. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js +9 -0
  96. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js.map +1 -0
  97. package/build/dex/kyberswap-elastic/contract-math/FullMath.d.ts +5 -0
  98. package/build/dex/kyberswap-elastic/contract-math/FullMath.js +22 -0
  99. package/build/dex/kyberswap-elastic/contract-math/FullMath.js.map +1 -0
  100. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.d.ts +3 -0
  101. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js +12 -0
  102. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js.map +1 -0
  103. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.d.ts +3 -0
  104. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js +22 -0
  105. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js.map +1 -0
  106. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.d.ts +5 -0
  107. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js +25 -0
  108. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js.map +1 -0
  109. package/build/dex/kyberswap-elastic/contract-math/QuadMath.d.ts +4 -0
  110. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js +27 -0
  111. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js.map +1 -0
  112. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.d.ts +3 -0
  113. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js +14 -0
  114. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js.map +1 -0
  115. package/build/dex/kyberswap-elastic/contract-math/SafeCast.d.ts +8 -0
  116. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js +30 -0
  117. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js.map +1 -0
  118. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.d.ts +10 -0
  119. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js +91 -0
  120. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js.map +1 -0
  121. package/build/dex/kyberswap-elastic/contract-math/SwapMath.d.ts +13 -0
  122. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js +188 -0
  123. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js.map +1 -0
  124. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.d.ts +6 -0
  125. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js +41 -0
  126. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js.map +1 -0
  127. package/build/dex/kyberswap-elastic/contract-math/TickMath.d.ts +9 -0
  128. package/build/dex/kyberswap-elastic/contract-math/TickMath.js +165 -0
  129. package/build/dex/kyberswap-elastic/contract-math/TickMath.js.map +1 -0
  130. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.d.ts +3 -0
  131. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js +10 -0
  132. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js.map +1 -0
  133. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.d.ts +28 -0
  134. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js +502 -0
  135. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js.map +1 -0
  136. package/build/dex/kyberswap-elastic/contract-math/utils.d.ts +3 -0
  137. package/build/dex/kyberswap-elastic/contract-math/utils.js +16 -0
  138. package/build/dex/kyberswap-elastic/contract-math/utils.js.map +1 -0
  139. package/build/dex/kyberswap-elastic/errors.d.ts +2 -0
  140. package/build/dex/kyberswap-elastic/errors.js +6 -0
  141. package/build/dex/kyberswap-elastic/errors.js.map +1 -0
  142. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.d.ts +80 -0
  143. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js +458 -0
  144. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js.map +1 -0
  145. package/build/dex/kyberswap-elastic/kyberswap-elastic.d.ts +53 -0
  146. package/build/dex/kyberswap-elastic/kyberswap-elastic.js +610 -0
  147. package/build/dex/kyberswap-elastic/kyberswap-elastic.js.map +1 -0
  148. package/build/dex/kyberswap-elastic/types.d.ts +134 -0
  149. package/build/dex/kyberswap-elastic/types.js +9 -0
  150. package/build/dex/kyberswap-elastic/types.js.map +1 -0
  151. package/build/dex/kyberswap-elastic/utils/decoders.d.ts +9 -0
  152. package/build/dex/kyberswap-elastic/utils/decoders.js +78 -0
  153. package/build/dex/kyberswap-elastic/utils/decoders.js.map +1 -0
  154. package/build/dex/morphex/config.d.ts +11 -0
  155. package/build/dex/morphex/config.js +43 -0
  156. package/build/dex/morphex/config.js.map +1 -0
  157. package/build/dex/morphex/morphex.d.ts +25 -0
  158. package/build/dex/morphex/morphex.js +19 -0
  159. package/build/dex/morphex/morphex.js.map +1 -0
  160. package/build/dex/my-test-dex/config.d.ts +4 -0
  161. package/build/dex/my-test-dex/config.js +15 -0
  162. package/build/dex/my-test-dex/config.js.map +1 -0
  163. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
  164. package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
  165. package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
  166. package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
  167. package/build/dex/my-test-dex/my-test-dex.js +126 -0
  168. package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
  169. package/build/dex/my-test-dex/types.d.ts +6 -0
  170. package/build/dex/my-test-dex/types.js +3 -0
  171. package/build/dex/my-test-dex/types.js.map +1 -0
  172. package/build/dex/solidly/forks-override/fvm.d.ts +20 -0
  173. package/build/dex/solidly/forks-override/fvm.js +42 -0
  174. package/build/dex/solidly/forks-override/fvm.js.map +1 -0
  175. package/build/dex/swaap-v2/constants.d.ts +7 -3
  176. package/build/dex/swaap-v2/constants.js +8 -4
  177. package/build/dex/swaap-v2/constants.js.map +1 -1
  178. package/build/dex/swaap-v2/rate-fetcher.d.ts +2 -1
  179. package/build/dex/swaap-v2/rate-fetcher.js +25 -0
  180. package/build/dex/swaap-v2/rate-fetcher.js.map +1 -1
  181. package/build/dex/swaap-v2/swaap-v2.d.ts +4 -2
  182. package/build/dex/swaap-v2/swaap-v2.js +57 -20
  183. package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
  184. package/build/dex/swaap-v2/types.d.ts +8 -0
  185. package/build/dex/swaap-v2/utils.d.ts +3 -3
  186. package/build/dex/swaap-v2/utils.js +6 -8
  187. package/build/dex/swaap-v2/utils.js.map +1 -1
  188. package/build/dex/swaap-v2/validators.d.ts +1 -0
  189. package/build/dex/swaap-v2/validators.js +6 -1
  190. package/build/dex/swaap-v2/validators.js.map +1 -1
  191. package/build/dex/wombat/config.d.ts +5 -0
  192. package/build/dex/wombat/config.js +50 -0
  193. package/build/dex/wombat/config.js.map +1 -0
  194. package/build/dex/wombat/types.d.ts +33 -0
  195. package/build/dex/wombat/types.js +3 -0
  196. package/build/dex/wombat/types.js.map +1 -0
  197. package/build/dex/wombat/utils.d.ts +9 -0
  198. package/build/dex/wombat/utils.js +66 -0
  199. package/build/dex/wombat/utils.js.map +1 -0
  200. package/build/dex/wombat/wombat-bmw.d.ts +40 -0
  201. package/build/dex/wombat/wombat-bmw.js +145 -0
  202. package/build/dex/wombat/wombat-bmw.js.map +1 -0
  203. package/build/dex/wombat/wombat-pool.d.ts +22 -0
  204. package/build/dex/wombat/wombat-pool.js +161 -0
  205. package/build/dex/wombat/wombat-pool.js.map +1 -0
  206. package/build/dex/wombat/wombat-quoter.d.ts +16 -0
  207. package/build/dex/wombat/wombat-quoter.js +176 -0
  208. package/build/dex/wombat/wombat-quoter.js.map +1 -0
  209. package/build/dex/wombat/wombat.d.ts +55 -0
  210. package/build/dex/wombat/wombat.js +292 -0
  211. package/build/dex/wombat/wombat.js.map +1 -0
  212. package/package.json +1 -1
  213. package/src/dex/dexalot/dexalot.ts +48 -22
  214. package/src/dex/swaap-v2/constants.ts +11 -3
  215. package/src/dex/swaap-v2/rate-fetcher.ts +51 -1
  216. package/src/dex/swaap-v2/swaap-v2.ts +97 -43
  217. package/src/dex/swaap-v2/types.ts +10 -0
  218. package/src/dex/swaap-v2/utils.ts +9 -16
  219. package/src/dex/swaap-v2/validators.ts +6 -0
  220. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  221. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  222. package/build/dex/algebra/algebra-pool.js.map +0 -1
  223. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  224. package/build/dex/quickswap/camelot-v3.js +0 -19
  225. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  226. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  227. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  228. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
@@ -395,7 +395,8 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
395
395
  .toString(),
396
396
  );
397
397
  if (isInputQuote) {
398
- lQty = (lQty * BigInt(10 ** (baseToken.decimals * 2))) /
398
+ lQty =
399
+ (lQty * BigInt(10 ** (baseToken.decimals * 2))) /
399
400
  (lPrice * BigInt(10 ** quoteToken.decimals));
400
401
  rQty =
401
402
  (rQty * BigInt(10 ** (baseToken.decimals * 2))) /
@@ -432,10 +433,6 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
432
433
  transferFees?: TransferFeeParams,
433
434
  ): Promise<null | ExchangePrices<DexalotData>> {
434
435
  try {
435
- if (await this.isRestricted()) {
436
- return null;
437
- }
438
-
439
436
  const normalizedSrcToken = this.normalizeToken(srcToken);
440
437
  const normalizedDestToken = this.normalizeToken(destToken);
441
438
 
@@ -444,7 +441,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
444
441
  return null;
445
442
  }
446
443
 
447
- const pools = limitPools
444
+ let pools = limitPools
448
445
  ? limitPools.filter(
449
446
  p =>
450
447
  p ===
@@ -455,6 +452,9 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
455
452
  )
456
453
  : await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);
457
454
 
455
+ pools = await Promise.all(
456
+ pools.map(async p => !(await this.isRestrictedPool(p))),
457
+ ).then(res => pools.filter((_v, i) => res[i]));
458
458
  if (pools.length === 0) {
459
459
  return null;
460
460
  }
@@ -505,14 +505,16 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
505
505
  throw new Error(`Empty orderbook for ${pairKey}`);
506
506
  }
507
507
 
508
- const isInputQuote = (clobSide === ClobSide.ASK && side === SwapSide.SELL) || (clobSide === ClobSide.BID && side === SwapSide.BUY);
508
+ const isInputQuote =
509
+ (clobSide === ClobSide.ASK && side === SwapSide.SELL) ||
510
+ (clobSide === ClobSide.BID && side === SwapSide.BUY);
509
511
 
510
512
  const prices = this.calculateOrderPrice(
511
513
  amounts,
512
514
  orderbook,
513
515
  baseToken,
514
516
  quoteToken,
515
- isInputQuote
517
+ isInputQuote,
516
518
  );
517
519
  const outDecimals =
518
520
  clobSide === ClobSide.BID ? baseToken.decimals : quoteToken.decimals;
@@ -579,15 +581,24 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
579
581
  const makerToken = normalizedDestToken;
580
582
  const takerToken = normalizedSrcToken;
581
583
 
584
+ const isSell = side === SwapSide.SELL;
585
+ const isBuy = side === SwapSide.BUY;
586
+
587
+ const slippageBps = isSell
588
+ ? BigNumber(1)
589
+ .minus(options.slippageFactor)
590
+ .multipliedBy(10000)
591
+ .toFixed(0)
592
+ : options.slippageFactor.minus(1).multipliedBy(10000).toFixed(0);
582
593
  const rfqParams = {
583
594
  makerAsset: ethers.utils.getAddress(makerToken.address),
584
595
  takerAsset: ethers.utils.getAddress(takerToken.address),
585
- makerAmount:
586
- side === SwapSide.BUY ? optimalSwapExchange.destAmount : undefined,
587
- takerAmount:
588
- side === SwapSide.SELL ? optimalSwapExchange.srcAmount : undefined,
596
+ makerAmount: isBuy ? optimalSwapExchange.destAmount : undefined,
597
+ takerAmount: isSell ? optimalSwapExchange.srcAmount : undefined,
589
598
  userAddress: options.txOrigin,
590
599
  chainid: this.network,
600
+ partner: options.partner,
601
+ slippage: slippageBps,
591
602
  };
592
603
 
593
604
  const rfq: RFQResponse = await this.dexHelper.httpRequest.post(
@@ -616,7 +627,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
616
627
  order.takerAsset.toLowerCase() === takerToken.address,
617
628
  `QuoteData takerAsset=${order.takerAsset} is different from Paraswap takerAsset=${takerToken.address}`,
618
629
  );
619
- if (side === SwapSide.SELL) {
630
+ if (isSell) {
620
631
  assert(
621
632
  order.takerAmount === optimalSwapExchange.srcAmount,
622
633
  `QuoteData takerAmount=${order.takerAmount} is different from Paraswap srcAmount=${optimalSwapExchange.srcAmount}`,
@@ -635,7 +646,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
635
646
  let isFailOnSlippage = false;
636
647
  let slippageErrorMessage = '';
637
648
 
638
- if (side === SwapSide.SELL) {
649
+ if (isSell) {
639
650
  if (
640
651
  BigInt(order.makerAmount) <
641
652
  BigInt(
@@ -674,7 +685,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
674
685
  let isTooStrictSlippage = false;
675
686
  if (
676
687
  isFailOnSlippage &&
677
- side === SwapSide.SELL &&
688
+ isSell &&
678
689
  new BigNumber(1)
679
690
  .minus(slippageFactor)
680
691
  .lt(DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)
@@ -682,7 +693,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
682
693
  isTooStrictSlippage = true;
683
694
  } else if (
684
695
  isFailOnSlippage &&
685
- side === SwapSide.BUY &&
696
+ isBuy &&
686
697
  slippageFactor
687
698
  .minus(1)
688
699
  .lt(DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)
@@ -725,10 +736,18 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
725
736
  `${this.dexKey}-${this.network}: failed to build transaction on side ${side} with too strict slippage. Skipping restriction`,
726
737
  );
727
738
  } else {
739
+ const poolIdentifiers = await this.getPoolIdentifiers(
740
+ srcToken,
741
+ destToken,
742
+ side,
743
+ 0,
744
+ );
728
745
  this.logger.warn(
729
- `${this.dexKey}-${this.network}: protocol is restricted`,
746
+ `${this.dexKey}-${this.network}: protocol is restricted for pools ${poolIdentifiers} due to swap: ${swapIdentifier}`,
747
+ );
748
+ await Promise.all(
749
+ poolIdentifiers.map(async p => await this.restrictPool(p)),
730
750
  );
731
- await this.restrict();
732
751
  }
733
752
  }
734
753
 
@@ -813,22 +832,29 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
813
832
  };
814
833
  }
815
834
 
816
- async restrict(ttl: number = DEXALOT_RESTRICT_TTL_S): Promise<boolean> {
835
+ getRestrictedPoolKey(poolIdentifier: string): string {
836
+ return `${DEXALOT_RESTRICTED_CACHE_KEY}-${poolIdentifier}`;
837
+ }
838
+
839
+ async restrictPool(
840
+ poolIdentifier: string,
841
+ ttl: number = DEXALOT_RESTRICT_TTL_S,
842
+ ): Promise<boolean> {
817
843
  await this.dexHelper.cache.setex(
818
844
  this.dexKey,
819
845
  this.network,
820
- DEXALOT_RESTRICTED_CACHE_KEY,
846
+ this.getRestrictedPoolKey(poolIdentifier),
821
847
  ttl,
822
848
  'true',
823
849
  );
824
850
  return true;
825
851
  }
826
852
 
827
- async isRestricted(): Promise<boolean> {
853
+ async isRestrictedPool(poolIdentifier: string): Promise<boolean> {
828
854
  const result = await this.dexHelper.cache.get(
829
855
  this.dexKey,
830
856
  this.network,
831
- DEXALOT_RESTRICTED_CACHE_KEY,
857
+ this.getRestrictedPoolKey(poolIdentifier),
832
858
  );
833
859
 
834
860
  return result === 'true';
@@ -20,13 +20,15 @@ export const SWAAP_RFQ_PRICES_ENDPOINT = 'prices';
20
20
 
21
21
  export const SWAAP_RFQ_QUOTE_ENDPOINT = 'quote';
22
22
 
23
+ export const SWAAP_NOTIFY_ENDPOINT = 'notify';
24
+
23
25
  export const SWAAP_RFQ_TOKENS_ENDPOINT = 'tokens';
24
26
 
25
- export const SWAAP_BLACKLIST_TTL_S = 60 * 60 * 24; // 24 hours
27
+ export const SWAAP_403_TTL_S = 60 * 60 * 24; // 24 hours
26
28
 
27
- export const SWAAP_RESTRICT_TTL_S = 60 * 30; // 30 minutes
29
+ export const SWAAP_429_TTL_S = 60 * 60 * 1; // 1 hour
28
30
 
29
- export const SWAAP_RESTRICTED_CACHE_KEY = 'restricted';
31
+ export const SWAAP_POOL_RESTRICT_TTL_S = 60 * 30; // 30 minutes
30
32
 
31
33
  export const GAS_COST_ESTIMATION = 170_000;
32
34
 
@@ -40,3 +42,9 @@ export const SWAAP_ORDER_TYPE_BUY = 2;
40
42
 
41
43
  export const SWAAP_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION =
42
44
  new BigNumber('0.001');
45
+
46
+ export const SWAAP_NOTIFY_TIMEOUT_MS = 2000;
47
+
48
+ export const SWAAP_NOTIFICATION_ORIGIN = 'paraswap';
49
+
50
+ export const SWAAP_BANNED_CODE = 1;
@@ -11,14 +11,21 @@ import {
11
11
  SwaapV2OrderType,
12
12
  SwaapV2TokensResponse,
13
13
  TokensMap,
14
+ SwaapV2NotificationRequest,
15
+ SwaapV2NotificationResponse,
14
16
  } from './types';
15
17
  import {
16
18
  priceLevelsResponseValidator,
17
19
  getQuoteResponseValidator,
18
20
  getTokensResponseValidator,
21
+ notifyResponseValidator,
19
22
  } from './validators';
20
23
  import { normalizeTokenAddress } from './utils';
21
- import { SWAAP_RFQ_QUOTE_TIMEOUT_MS } from './constants';
24
+ import {
25
+ SWAAP_RFQ_QUOTE_TIMEOUT_MS,
26
+ SWAAP_NOTIFY_TIMEOUT_MS,
27
+ SWAAP_NOTIFICATION_ORIGIN,
28
+ } from './constants';
22
29
  import { RequestConfig } from '../../dex-helper/irequest-wrapper';
23
30
 
24
31
  export class RateFetcher {
@@ -211,4 +218,47 @@ export class RateFetcher {
211
218
  throw e;
212
219
  }
213
220
  }
221
+
222
+ async notify(
223
+ code: number,
224
+ message: string,
225
+ requestParameters: RequestConfig,
226
+ ): Promise<SwaapV2NotificationResponse> {
227
+ const _payload: SwaapV2NotificationRequest = {
228
+ origin: SWAAP_NOTIFICATION_ORIGIN,
229
+ code: code,
230
+ message: message,
231
+ };
232
+
233
+ try {
234
+ let payload: RequestConfig = {
235
+ data: _payload,
236
+ ...requestParameters,
237
+ timeout: SWAAP_NOTIFY_TIMEOUT_MS,
238
+ };
239
+
240
+ this.logger.info(
241
+ 'Notify Request:',
242
+ JSON.stringify(payload).replace(/(?:\r\n|\r|\n)/g, ' '),
243
+ );
244
+ const { data } = await this.dexHelper.httpRequest.request<unknown>(
245
+ payload,
246
+ );
247
+ this.logger.info(
248
+ 'Notify Response: ',
249
+ JSON.stringify(data).replace(/(?:\r\n|\r|\n)/g, ' '),
250
+ );
251
+ const notifyResp = validateAndCast<SwaapV2NotificationResponse>(
252
+ data,
253
+ notifyResponseValidator,
254
+ );
255
+
256
+ return {
257
+ success: notifyResp.success,
258
+ };
259
+ } catch (e) {
260
+ this.logger.error(e);
261
+ throw e;
262
+ }
263
+ }
214
264
  }
@@ -11,7 +11,13 @@ import {
11
11
  OptimalSwapExchange,
12
12
  PreprocessTransactionOptions,
13
13
  } from '../../types';
14
- import { SwapSide, Network, MAX_INT, MAX_UINT } from '../../constants';
14
+ import {
15
+ SwapSide,
16
+ Network,
17
+ MAX_INT,
18
+ MAX_UINT,
19
+ CACHE_PREFIX,
20
+ } from '../../constants';
15
21
  import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
16
22
  import { getDexKeysWithNetwork, isAxiosError } from '../../utils';
17
23
  import { IDex } from '../idex';
@@ -23,6 +29,7 @@ import {
23
29
  SwaapV2APIParameters,
24
30
  SwaapV2QuoteError,
25
31
  TokensMap,
32
+ SwaapV2NotificationResponse,
26
33
  } from './types';
27
34
  import { SimpleExchange } from '../simple-exchange';
28
35
  import { Adapters, SwaapV2Config } from './config';
@@ -41,10 +48,10 @@ import {
41
48
  GAS_COST_ESTIMATION,
42
49
  BATCH_SWAP_SELECTOR,
43
50
  CALLER_SLOT,
44
- SWAAP_BLACKLIST_TTL_S,
51
+ SWAAP_403_TTL_S,
52
+ SWAAP_429_TTL_S,
45
53
  SWAAP_RFQ_TOKENS_ENDPOINT,
46
- SWAAP_RESTRICT_TTL_S,
47
- SWAAP_RESTRICTED_CACHE_KEY,
54
+ SWAAP_POOL_RESTRICT_TTL_S,
48
55
  SWAAP_RFQ_API_TOKENS_POLLING_INTERVAL_MS,
49
56
  SWAAP_RFQ_TOKENS_CACHES_TTL_S,
50
57
  SWAAP_PRICES_CACHE_KEY,
@@ -52,6 +59,8 @@ import {
52
59
  SWAAP_ORDER_TYPE_SELL,
53
60
  SWAAP_ORDER_TYPE_BUY,
54
61
  SWAAP_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION,
62
+ SWAAP_BANNED_CODE,
63
+ SWAAP_NOTIFY_ENDPOINT,
55
64
  } from './constants';
56
65
  import { getPoolIdentifier, normalizeTokenAddress, getPairName } from './utils';
57
66
  import { Method } from '../../dex-helper/irequest-wrapper';
@@ -71,6 +80,7 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
71
80
  private rateFetcher: RateFetcher;
72
81
  private swaapV2AuthToken: string;
73
82
  private tokensMap: TokensMap = {};
83
+ private runtimeMMsRestrictHashMapKey: string;
74
84
 
75
85
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
76
86
  getDexKeysWithNetwork(SwaapV2Config);
@@ -113,6 +123,9 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
113
123
  },
114
124
  },
115
125
  );
126
+
127
+ this.runtimeMMsRestrictHashMapKey =
128
+ `${CACHE_PREFIX}_${this.dexKey}_${this.network}_restricted_mms`.toLowerCase();
116
129
  }
117
130
 
118
131
  async initializePricing(blockNumber: number): Promise<void> {
@@ -298,22 +311,22 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
298
311
  blockNumber: number,
299
312
  limitPools?: string[],
300
313
  ): Promise<null | ExchangePrices<SwaapV2Data>> {
314
+ const normalizedSrcToken = this.normalizeToken(srcToken);
315
+ const normalizedDestToken = this.normalizeToken(destToken);
316
+
317
+ const requestedPoolIdentifier: string = getPoolIdentifier(
318
+ this.dexKey,
319
+ normalizedSrcToken.address,
320
+ normalizedDestToken.address,
321
+ );
322
+
301
323
  try {
302
- if (await this.isRestricted()) {
324
+ if (await this.isRestrictedPool(requestedPoolIdentifier)) {
303
325
  return null;
304
326
  }
305
327
 
306
328
  this.tokensMap = (await this.getCachedTokens()) || {};
307
329
 
308
- const normalizedSrcToken = this.normalizeToken(srcToken);
309
- const normalizedDestToken = this.normalizeToken(destToken);
310
-
311
- const requestedPoolIdentifier: string = getPoolIdentifier(
312
- this.dexKey,
313
- normalizedSrcToken.address,
314
- normalizedDestToken.address,
315
- );
316
-
317
330
  if (normalizedSrcToken.address === normalizedDestToken.address) {
318
331
  return null;
319
332
  }
@@ -561,11 +574,13 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
561
574
  { deadline: minDeadline },
562
575
  ];
563
576
  } catch (e) {
564
- if (
565
- isAxiosError(e) &&
566
- (e.response?.status === 403 || e.response?.status === 429)
567
- ) {
568
- await this.setBlacklist(options.txOrigin);
577
+ if (isAxiosError(e) && e.response?.status === 403) {
578
+ await this.setBlacklist(options.txOrigin, SWAAP_403_TTL_S);
579
+ this.logger.warn(
580
+ `${this.dexKey}-${this.network}: Encountered blacklisted user=${options.txOrigin}. Adding to local blacklist cache`,
581
+ );
582
+ } else if (isAxiosError(e) && e.response?.status === 429) {
583
+ await this.setBlacklist(options.txOrigin, SWAAP_429_TTL_S);
569
584
  this.logger.warn(
570
585
  `${this.dexKey}-${this.network}: Encountered restricted user=${options.txOrigin}. Adding to local blacklist cache`,
571
586
  );
@@ -578,7 +593,16 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
578
593
  this.logger.warn(
579
594
  `${this.dexKey}-${this.network}: protocol is restricted`,
580
595
  );
581
- await this.restrict();
596
+ const poolIdentifier = getPoolIdentifier(
597
+ this.dexKey,
598
+ normalizedSrcToken.address,
599
+ normalizedDestToken.address,
600
+ );
601
+ var message = 'Unknown error';
602
+ if (e instanceof Error) {
603
+ message = `${e.name}: ${e.message}`;
604
+ }
605
+ await this.restrictPool(message, poolIdentifier);
582
606
  }
583
607
  }
584
608
 
@@ -586,25 +610,45 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
586
610
  }
587
611
  }
588
612
 
589
- async restrict(ttl: number = SWAAP_RESTRICT_TTL_S): Promise<boolean> {
590
- await this.dexHelper.cache.setex(
591
- this.dexKey,
592
- this.network,
593
- SWAAP_RESTRICTED_CACHE_KEY,
594
- ttl,
595
- 'true',
613
+ async restrictPool(message: string, poolIdentifier: string): Promise<void> {
614
+ this.logger.warn(
615
+ `${this.dexKey}-${this.network}: ${poolIdentifier} was restricted for ${SWAAP_POOL_RESTRICT_TTL_S} sec. due to fails`,
596
616
  );
597
- return true;
598
- }
599
617
 
600
- async isRestricted(): Promise<boolean> {
601
- const result = await this.dexHelper.cache.get(
602
- this.dexKey,
603
- this.network,
604
- SWAAP_RESTRICTED_CACHE_KEY,
618
+ // We use timestamp for creation date to later discern if it already expired or not
619
+ await this.dexHelper.cache.hset(
620
+ this.runtimeMMsRestrictHashMapKey,
621
+ poolIdentifier,
622
+ Date.now().toString(),
605
623
  );
606
624
 
607
- return result === 'true';
625
+ this.rateFetcher
626
+ .notify(SWAAP_BANNED_CODE, message, this.getNotifyReqParams())
627
+ .then((answer: SwaapV2NotificationResponse) => {
628
+ if (answer.success) {
629
+ this.logger.info(`Successfully notified Swaap API`);
630
+ } else {
631
+ this.logger.error(`Swaap API was not successfully notified`);
632
+ }
633
+ })
634
+ .catch(e => {
635
+ // Must never happen
636
+ this.logger.error(`Swaap API notification failed: ${e}`);
637
+ });
638
+ }
639
+
640
+ async isRestrictedPool(poolIdentifier: string): Promise<boolean> {
641
+ const expirationThreshold = Date.now() - SWAAP_POOL_RESTRICT_TTL_S * 1000;
642
+ const createdAt = await this.dexHelper.cache.hget(
643
+ this.runtimeMMsRestrictHashMapKey,
644
+ poolIdentifier,
645
+ );
646
+ const wasNotRestricted = createdAt === null;
647
+ if (wasNotRestricted) {
648
+ return false;
649
+ }
650
+ const restrictionExpired = +createdAt < expirationThreshold;
651
+ return !restrictionExpired;
608
652
  }
609
653
 
610
654
  async isBlacklisted(txOrigin: Address): Promise<boolean> {
@@ -622,7 +666,7 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
622
666
 
623
667
  async setBlacklist(
624
668
  txOrigin: Address,
625
- ttl: number = SWAAP_BLACKLIST_TTL_S,
669
+ ttl: number = SWAAP_403_TTL_S,
626
670
  ): Promise<boolean> {
627
671
  await this.dexHelper.cache.setex(
628
672
  this.dexKey,
@@ -866,10 +910,6 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
866
910
  tokenAddress: Address,
867
911
  limit: number,
868
912
  ): Promise<PoolLiquidity[]> {
869
- if (await this.isRestricted()) {
870
- return [];
871
- }
872
-
873
913
  this.tokensMap = (await this.getCachedTokens()) || {};
874
914
  const normalizedTokenAddress = normalizeTokenAddress(tokenAddress);
875
915
 
@@ -880,12 +920,22 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
880
920
  }
881
921
 
882
922
  return Object.keys(pLevels)
883
- .filter((pair: string) => {
923
+ .filter(async (pair: string) => {
884
924
  const { base, quote } = pLevels[pair];
885
925
 
886
- return (
887
- normalizedTokenAddress === base || normalizedTokenAddress === quote
926
+ const levelDoesNotIncludeToken =
927
+ normalizedTokenAddress !== base && normalizedTokenAddress !== quote;
928
+ if (levelDoesNotIncludeToken) {
929
+ return false;
930
+ }
931
+
932
+ const poolIdentifier: string = getPoolIdentifier(
933
+ this.dexKey,
934
+ base,
935
+ quote,
888
936
  );
937
+ const isRestrictedPool = await this.isRestrictedPool(poolIdentifier);
938
+ return !isRestrictedPool;
889
939
  })
890
940
  .map((pair: string) => {
891
941
  return {
@@ -924,6 +974,10 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
924
974
  return this.getAPIReqParams(SWAAP_RFQ_QUOTE_ENDPOINT, 'POST');
925
975
  }
926
976
 
977
+ getNotifyReqParams(): SwaapV2APIParameters {
978
+ return this.getAPIReqParams(SWAAP_NOTIFY_ENDPOINT, 'POST');
979
+ }
980
+
927
981
  getTokensReqParams(): SwaapV2APIParameters {
928
982
  return this.getAPIReqParams(SWAAP_RFQ_TOKENS_ENDPOINT, 'GET');
929
983
  }
@@ -93,3 +93,13 @@ export type SwaapV2APIParameters = {
93
93
  export type TokensMap = {
94
94
  [address: string]: Token;
95
95
  };
96
+
97
+ export type SwaapV2NotificationRequest = {
98
+ origin: string;
99
+ code: number;
100
+ message: string;
101
+ };
102
+
103
+ export type SwaapV2NotificationResponse = {
104
+ success: boolean;
105
+ };
@@ -1,32 +1,25 @@
1
1
  import { Address } from '../../types';
2
- import { CACHE_PREFIX, ETHER_ADDRESS, NULL_ADDRESS } from '../../constants';
2
+ import { ETHER_ADDRESS, NULL_ADDRESS } from '../../constants';
3
3
 
4
4
  export const getIdentifierPrefix = (
5
5
  dexKey: string,
6
- srcAddress: Address,
7
- destAddress: Address,
6
+ tokenA: Address,
7
+ tokenB: Address,
8
8
  ) => {
9
- return `${dexKey}_${getPairName(srcAddress, destAddress)}`.toLowerCase();
9
+ return `${dexKey}_${getPairName(tokenA, tokenB)}`.toLowerCase();
10
10
  };
11
11
 
12
- export const getPairName = (srcAddress: Address, destAddress: Address) => {
13
- const sortedAddresses =
14
- srcAddress < destAddress
15
- ? [srcAddress, destAddress]
16
- : [destAddress, srcAddress];
12
+ export const getPairName = (tokenA: Address, tokenB: Address) => {
13
+ const sortedAddresses = tokenA < tokenB ? [tokenA, tokenB] : [tokenB, tokenA];
17
14
  return `${sortedAddresses[0]}_${sortedAddresses[1]}`.toLowerCase();
18
15
  };
19
16
 
20
17
  export const getPoolIdentifier = (
21
18
  dexKey: string,
22
- srcAddress: Address,
23
- destAddress: Address,
19
+ tokenA: Address,
20
+ tokenB: Address,
24
21
  ) => {
25
- return `${getIdentifierPrefix(
26
- dexKey,
27
- srcAddress,
28
- destAddress,
29
- )}`.toLowerCase();
22
+ return `${getIdentifierPrefix(dexKey, tokenA, tokenB)}`.toLowerCase();
30
23
  };
31
24
 
32
25
  export const normalizeTokenAddress = (address: string): string => {
@@ -126,3 +126,9 @@ export const getQuoteResponseValidator = joi
126
126
  success: joi.boolean().required(),
127
127
  })
128
128
  .unknown(true);
129
+
130
+ export const notifyResponseValidator = joi
131
+ .object({
132
+ success: joi.boolean().required(),
133
+ })
134
+ .unknown(true);