@paraswap/dex-lib 2.37.2-current-fee-ramses-v2.4 → 2.37.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 (254) hide show
  1. package/build/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  2. package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
  3. package/build/dex/algebra/algebra-factory.d.ts +25 -0
  4. package/build/dex/algebra/algebra-factory.js +43 -0
  5. package/build/dex/algebra/algebra-factory.js.map +1 -0
  6. package/build/dex/algebra/algebra.d.ts +3 -0
  7. package/build/dex/algebra/algebra.js +27 -5
  8. package/build/dex/algebra/algebra.js.map +1 -1
  9. package/build/dex/algebra/config.js +0 -1
  10. package/build/dex/algebra/config.js.map +1 -1
  11. package/build/dex/algebra/types.d.ts +1 -1
  12. package/build/dex/{woo-fi → hello}/config.d.ts +1 -1
  13. package/build/dex/hello/config.js +15 -0
  14. package/build/dex/hello/config.js.map +1 -0
  15. package/build/dex/hello/hello-pool.d.ts +39 -0
  16. package/build/dex/hello/hello-pool.js +64 -0
  17. package/build/dex/hello/hello-pool.js.map +1 -0
  18. package/build/dex/hello/hello.d.ts +37 -0
  19. package/build/dex/hello/hello.js +126 -0
  20. package/build/dex/hello/hello.js.map +1 -0
  21. package/build/dex/hello/types.d.ts +6 -0
  22. package/build/dex/{woo-fi → hello}/types.js.map +1 -1
  23. package/build/dex/index.js +7 -2
  24. package/build/dex/index.js.map +1 -1
  25. package/build/dex/{dexalot → my-test-dex}/config.d.ts +1 -1
  26. package/build/dex/my-test-dex/config.js +15 -0
  27. package/build/dex/my-test-dex/config.js.map +1 -0
  28. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
  29. package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
  30. package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
  31. package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
  32. package/build/dex/my-test-dex/my-test-dex.js +126 -0
  33. package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
  34. package/build/dex/my-test-dex/types.d.ts +6 -0
  35. package/build/dex/{pancakeswap-v3 → my-test-dex}/types.js.map +1 -1
  36. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
  37. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
  38. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
  39. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
  40. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
  41. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  42. package/build/dex/uniswap-v3/config.js +0 -2
  43. package/build/dex/uniswap-v3/config.js.map +1 -1
  44. package/build/dex/uniswap-v3/types.d.ts +1 -2
  45. package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
  46. package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
  47. package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
  48. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +5 -7
  49. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  50. package/build/dex/uniswap-v3/uniswap-v3.d.ts +3 -0
  51. package/build/dex/uniswap-v3/uniswap-v3.js +29 -9
  52. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  53. package/build/dex-helper/dummy-dex-helper.js +3 -0
  54. package/build/dex-helper/dummy-dex-helper.js.map +1 -1
  55. package/build/dex-helper/icache.d.ts +1 -0
  56. package/package.json +1 -1
  57. package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  58. package/src/dex/algebra/algebra-factory.ts +70 -0
  59. package/src/dex/algebra/algebra.ts +47 -6
  60. package/src/dex/algebra/config.ts +0 -1
  61. package/src/dex/algebra/types.ts +2 -1
  62. package/src/dex/index.ts +6 -3
  63. package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
  64. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
  65. package/src/dex/uniswap-v3/config.ts +0 -2
  66. package/src/dex/uniswap-v3/types.ts +2 -2
  67. package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
  68. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +4 -6
  69. package/src/dex/uniswap-v3/uniswap-v3.ts +67 -27
  70. package/src/dex-helper/dummy-dex-helper.ts +4 -0
  71. package/src/dex-helper/icache.ts +2 -0
  72. package/.idea/aws.xml +0 -17
  73. package/.idea/codeStyles/Project.xml +0 -19
  74. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  75. package/.idea/misc.xml +0 -6
  76. package/.idea/modules.xml +0 -8
  77. package/.idea/paraswap-dex-lib.iml +0 -9
  78. package/.idea/vcs.xml +0 -6
  79. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  80. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  81. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  82. package/build/abi/dexalot/DexalotMainnetRFQ.json +0 -887
  83. package/build/abi/ramses-v2/RamsesV2Pool.abi.json +0 -1580
  84. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  85. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  86. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  87. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  88. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  89. package/build/abi/wBETH.json +0 -1527
  90. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  91. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  92. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  93. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  94. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  95. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  96. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  97. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  98. package/build/dex/algebra/algebra-pool.d.ts +0 -46
  99. package/build/dex/algebra/algebra-pool.js +0 -336
  100. package/build/dex/algebra/algebra-pool.js.map +0 -1
  101. package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
  102. package/build/dex/balancer-v2/LinearMath.js +0 -179
  103. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  104. package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
  105. package/build/dex/balancer-v2/LinearPool.js +0 -324
  106. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  107. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
  108. package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
  109. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  110. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  111. package/build/dex/balancer-v2/StableMath.js +0 -272
  112. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  113. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
  114. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
  115. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  116. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  117. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  118. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  119. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  120. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  121. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  122. package/build/dex/dexalot/config.js +0 -18
  123. package/build/dex/dexalot/config.js.map +0 -1
  124. package/build/dex/dexalot/constants.d.ts +0 -15
  125. package/build/dex/dexalot/constants.js +0 -22
  126. package/build/dex/dexalot/constants.js.map +0 -1
  127. package/build/dex/dexalot/dexalot.d.ts +0 -69
  128. package/build/dex/dexalot/dexalot.js +0 -646
  129. package/build/dex/dexalot/dexalot.js.map +0 -1
  130. package/build/dex/dexalot/rate-fetcher.d.ts +0 -28
  131. package/build/dex/dexalot/rate-fetcher.js +0 -100
  132. package/build/dex/dexalot/rate-fetcher.js.map +0 -1
  133. package/build/dex/dexalot/types.d.ts +0 -114
  134. package/build/dex/dexalot/types.js +0 -12
  135. package/build/dex/dexalot/types.js.map +0 -1
  136. package/build/dex/dexalot/validators.d.ts +0 -5
  137. package/build/dex/dexalot/validators.js +0 -45
  138. package/build/dex/dexalot/validators.js.map +0 -1
  139. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  140. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  141. package/build/dex/quickswap/camelot-v3.js +0 -19
  142. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  143. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  144. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  145. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  146. package/build/dex/quickswap-v3.d.ts +0 -21
  147. package/build/dex/quickswap-v3.js +0 -40
  148. package/build/dex/quickswap-v3.js.map +0 -1
  149. package/build/dex/ramses-v2/config.d.ts +0 -4
  150. package/build/dex/ramses-v2/config.js +0 -28
  151. package/build/dex/ramses-v2/config.js.map +0 -1
  152. package/build/dex/ramses-v2/constants.d.ts +0 -28
  153. package/build/dex/ramses-v2/constants.js +0 -35
  154. package/build/dex/ramses-v2/constants.js.map +0 -1
  155. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  156. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  157. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  158. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  159. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  160. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  161. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  162. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  163. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  164. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  165. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  166. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  167. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  168. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  169. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  170. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  171. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  172. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  173. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  174. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  175. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  176. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  177. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  178. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  179. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  180. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  181. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  182. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  183. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  184. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  185. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  186. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  187. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  188. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  189. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  190. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  191. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  192. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  193. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  194. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  195. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  196. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  197. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  198. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  199. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  200. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  201. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  202. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  203. package/build/dex/ramses-v2/types.d.ts +0 -154
  204. package/build/dex/ramses-v2/types.js +0 -9
  205. package/build/dex/ramses-v2/types.js.map +0 -1
  206. package/build/dex/ramses-v2/utils.d.ts +0 -6
  207. package/build/dex/ramses-v2/utils.js +0 -71
  208. package/build/dex/ramses-v2/utils.js.map +0 -1
  209. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  210. package/build/dex/sushiswap-v3/config.js +0 -132
  211. package/build/dex/sushiswap-v3/config.js.map +0 -1
  212. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  213. package/build/dex/sushiswap-v3/constants.js +0 -32
  214. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  215. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  216. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  217. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  218. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  219. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  220. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  221. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  222. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  223. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  224. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  225. package/build/dex/sushiswap-v3/token.js +0 -23
  226. package/build/dex/sushiswap-v3/token.js.map +0 -1
  227. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  228. package/build/dex/sushiswap-v3/types.js +0 -18
  229. package/build/dex/sushiswap-v3/types.js.map +0 -1
  230. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  231. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  232. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  233. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.d.ts +0 -7
  234. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +0 -87
  235. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +0 -1
  236. package/build/dex/woo-fi/config.js +0 -141
  237. package/build/dex/woo-fi/config.js.map +0 -1
  238. package/build/dex/woo-fi/constants.d.ts +0 -5
  239. package/build/dex/woo-fi/constants.js +0 -20
  240. package/build/dex/woo-fi/constants.js.map +0 -1
  241. package/build/dex/woo-fi/types.d.ts +0 -48
  242. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  243. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  244. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  245. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  246. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  247. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  248. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  249. package/build/dex/woo-fi/woo-fi.js +0 -480
  250. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  251. package/src/abi/ramses-v2/RamsesV2Pool.abi.json +0 -1580
  252. package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +0 -104
  253. /package/build/dex/{pancakeswap-v3 → hello}/types.js +0 -0
  254. /package/build/dex/{woo-fi → my-test-dex}/types.js +0 -0
@@ -1,646 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Dexalot = void 0;
30
- const constants_1 = require("../../constants");
31
- const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
32
- const utils_1 = require("../../utils");
33
- const types_1 = require("./types");
34
- const types_2 = require("../generic-rfq/types");
35
- const simple_exchange_1 = require("../simple-exchange");
36
- const config_1 = require("./config");
37
- const rate_fetcher_1 = require("./rate-fetcher");
38
- const DexalotMainnetRFQ_json_1 = __importDefault(require("../../abi/dexalot/DexalotMainnetRFQ.json"));
39
- const utils_2 = require("ethers/lib/utils");
40
- const ts_essentials_1 = require("ts-essentials");
41
- const constants_2 = require("./constants");
42
- const bigint_constants_1 = require("../../bigint-constants");
43
- const ethers_1 = require("ethers");
44
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
45
- class Dexalot extends simple_exchange_1.SimpleExchange {
46
- constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}, mainnetRFQAddress = config_1.DexalotConfig['Dexalot'][network]
47
- .mainnetRFQAddress, rfqInterface = new utils_2.Interface(DexalotMainnetRFQ_json_1.default)) {
48
- super(dexHelper, dexKey);
49
- this.network = network;
50
- this.dexKey = dexKey;
51
- this.dexHelper = dexHelper;
52
- this.adapters = adapters;
53
- this.mainnetRFQAddress = mainnetRFQAddress;
54
- this.rfqInterface = rfqInterface;
55
- this.isStatePollingDex = true;
56
- this.hasConstantPriceLargeAmounts = false;
57
- this.needWrapNative = false;
58
- this.isFeeOnTransferSupported = false;
59
- this.tokensMap = {};
60
- this.logger = dexHelper.getLogger(dexKey);
61
- const authToken = dexHelper.config.data.dexalotAuthToken;
62
- (0, ts_essentials_1.assert)(authToken !== undefined, 'Dexalot auth token is not specified with env variable');
63
- this.dexalotAuthToken = authToken;
64
- this.pricesCacheKey = 'prices';
65
- this.pairsCacheKey = 'pairs';
66
- this.tokensAddrCacheKey = 'tokens_addr';
67
- this.tokensCacheKey = 'tokens';
68
- this.blacklistCacheKey = 'blacklist';
69
- this.rateFetcher = new rate_fetcher_1.RateFetcher(this.dexHelper, this.dexKey, this.network, this.logger, {
70
- rateConfig: {
71
- pairsIntervalMs: constants_2.DEXALOT_API_PAIRS_POLLING_INTERVAL_MS,
72
- pricesIntervalMs: constants_2.DEXALOT_API_PRICES_POLLING_INTERVAL_MS,
73
- blacklistIntervalMs: constants_2.DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS,
74
- pairsReqParams: this.getAPIReqParams('api/rfq/pairs', 'GET'),
75
- pricesReqParams: this.getAPIReqParams('api/rfq/prices', 'GET'),
76
- blacklistReqParams: this.getAPIReqParams('api/rfq/blacklist', 'GET'),
77
- pairsCacheKey: this.pairsCacheKey,
78
- pairsCacheTTLSecs: constants_2.DEXALOT_PAIRS_CACHES_TTL_S,
79
- pricesCacheKey: this.pricesCacheKey,
80
- pricesCacheTTLSecs: constants_2.DEXALOT_PRICES_CACHES_TTL_S,
81
- tokensAddrCacheKey: this.tokensAddrCacheKey,
82
- tokensCacheKey: this.tokensCacheKey,
83
- tokensCacheTTLSecs: constants_2.DEXALOT_TOKENS_CACHES_TTL_S,
84
- blacklistCacheKey: this.blacklistCacheKey,
85
- blacklistCacheTTLSecs: constants_2.DEXALOT_BLACKLIST_CACHES_TTL_S,
86
- },
87
- });
88
- }
89
- async initializePricing(blockNumber) {
90
- if (!this.dexHelper.config.isSlave) {
91
- this.rateFetcher.start();
92
- }
93
- return;
94
- }
95
- getAdapters(side) {
96
- return this.adapters[side] ? this.adapters[side] : null;
97
- }
98
- getPairString(baseToken, quoteToken) {
99
- return `${baseToken.symbol}/${quoteToken.symbol}`.toLowerCase();
100
- }
101
- async getPairData(srcToken, destToken) {
102
- const normalizedSrcToken = this.normalizeToken(srcToken);
103
- const normalizedDestToken = this.normalizeToken(destToken);
104
- if (normalizedSrcToken.address === normalizedDestToken.address) {
105
- return null;
106
- }
107
- const cachedTokens = (await this.getCachedTokens()) || {};
108
- if (!(normalizedSrcToken.address in cachedTokens) ||
109
- !(normalizedDestToken.address in cachedTokens)) {
110
- return null;
111
- }
112
- normalizedSrcToken.symbol = cachedTokens[normalizedSrcToken.address].symbol;
113
- normalizedDestToken.symbol =
114
- cachedTokens[normalizedDestToken.address].symbol;
115
- const cachedPairs = (await this.getCachedPairs()) || {};
116
- const potentialPairs = [
117
- {
118
- identifier: this.getPairString(normalizedSrcToken, normalizedDestToken),
119
- isSrcBase: true,
120
- },
121
- {
122
- identifier: this.getPairString(normalizedDestToken, normalizedSrcToken),
123
- isSrcBase: false,
124
- },
125
- ];
126
- for (const pair of potentialPairs) {
127
- if (pair.identifier in cachedPairs) {
128
- const pairData = cachedPairs[pair.identifier];
129
- pairData.isSrcBase = pair.isSrcBase;
130
- return pairData;
131
- }
132
- }
133
- return null;
134
- }
135
- getIdentifier(srcAddress, destAddress) {
136
- const sortedAddresses = srcAddress < destAddress
137
- ? [srcAddress, destAddress]
138
- : [destAddress, srcAddress];
139
- return `${this.dexKey}_${sortedAddresses[0].toLowerCase()}_${sortedAddresses[1].toLowerCase()}`;
140
- }
141
- async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
142
- if (!srcToken || !destToken) {
143
- return [];
144
- }
145
- const pairData = await this.getPairData(srcToken, destToken);
146
- if (!pairData) {
147
- return [];
148
- }
149
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
150
- return [this.getIdentifier(tokensAddr[pairData.base.toLowerCase()], tokensAddr[pairData.quote.toLowerCase()])];
151
- }
152
- async getCachedPairs() {
153
- const cachedPairs = await this.dexHelper.cache.get(this.dexKey, this.network, this.pairsCacheKey);
154
- if (cachedPairs) {
155
- return JSON.parse(cachedPairs);
156
- }
157
- return null;
158
- }
159
- async getCachedPrices() {
160
- const cachedPrices = await this.dexHelper.cache.get(this.dexKey, this.network, this.pricesCacheKey);
161
- if (cachedPrices) {
162
- return JSON.parse(cachedPrices);
163
- }
164
- return null;
165
- }
166
- async getCachedTokensAddr() {
167
- const cachedTokensAddr = await this.dexHelper.cache.get(this.dexKey, this.network, this.tokensAddrCacheKey);
168
- if (cachedTokensAddr) {
169
- return JSON.parse(cachedTokensAddr);
170
- }
171
- return null;
172
- }
173
- async getCachedTokens() {
174
- const cachedTokens = await this.dexHelper.cache.get(this.dexKey, this.network, this.tokensCacheKey);
175
- if (cachedTokens) {
176
- return JSON.parse(cachedTokens);
177
- }
178
- return null;
179
- }
180
- normalizeAddress(address) {
181
- return address.toLowerCase() === constants_1.ETHER_ADDRESS
182
- ? constants_1.NULL_ADDRESS
183
- : address.toLowerCase();
184
- }
185
- denormalizeAddress(address) {
186
- return address.toLowerCase() === constants_1.NULL_ADDRESS
187
- ? constants_1.ETHER_ADDRESS
188
- : address.toLowerCase();
189
- }
190
- // Dexalot protocol for native token expects 0x00000... instead of 0xeeeee...
191
- normalizeToken(token) {
192
- return {
193
- address: this.normalizeAddress(token.address),
194
- decimals: token.decimals,
195
- };
196
- }
197
- denormalizeToken(token) {
198
- return {
199
- address: this.denormalizeAddress(token.address),
200
- decimals: token.decimals,
201
- };
202
- }
203
- calculateOrderPrice(amounts, orderbook, baseToken, quoteToken, side) {
204
- let result = [];
205
- for (let i = 0; i < amounts.length; i++) {
206
- let amt = amounts[i];
207
- if (amt === 0n) {
208
- result.push(amt);
209
- continue;
210
- }
211
- let left = 0, right = orderbook.length;
212
- let qty = BigInt(0);
213
- while (left < right) {
214
- let mid = Math.floor((left + right) / 2);
215
- qty = BigInt(ethers_1.ethers.utils
216
- .parseUnits(orderbook[mid][1], quoteToken.decimals)
217
- .toString());
218
- if (side === types_1.ClobSide.ASK) {
219
- const price = BigInt(ethers_1.ethers.utils
220
- .parseUnits(orderbook[mid][0], baseToken.decimals)
221
- .toString());
222
- qty =
223
- (qty * BigInt(10 ** (baseToken.decimals * 2))) /
224
- (price * BigInt(10 ** quoteToken.decimals));
225
- }
226
- if (qty <= amt) {
227
- left = mid + 1;
228
- }
229
- else {
230
- right = mid;
231
- }
232
- }
233
- let price, amount = BigInt(0);
234
- if (left === orderbook.length) {
235
- price = BigInt(ethers_1.ethers.utils
236
- .parseUnits(orderbook[left - 1][0], baseToken.decimals)
237
- .toString());
238
- amount = qty;
239
- }
240
- else if (amounts[i] === qty) {
241
- price = BigInt(ethers_1.ethers.utils
242
- .parseUnits(orderbook[left][0], baseToken.decimals)
243
- .toString());
244
- amount = amounts[i];
245
- }
246
- else {
247
- const lPrice = BigInt(ethers_1.ethers.utils
248
- .parseUnits(orderbook[left][0], baseToken.decimals)
249
- .toString());
250
- const rPrice = BigInt(ethers_1.ethers.utils
251
- .parseUnits(orderbook[left + 1][0], baseToken.decimals)
252
- .toString());
253
- const lQty = qty;
254
- let rQty = BigInt(ethers_1.ethers.utils
255
- .parseUnits(orderbook[left + 1][1], quoteToken.decimals)
256
- .toString());
257
- if (side === types_1.ClobSide.ASK) {
258
- rQty = (rQty * rPrice) / BigInt(10 ** quoteToken.decimals);
259
- }
260
- price = lPrice + ((rPrice - lPrice) * (amt - lQty)) / (rQty - lQty);
261
- amount = amounts[i];
262
- }
263
- if (side === types_1.ClobSide.BID) {
264
- result.push((amount * BigInt(10 ** (baseToken.decimals * 2))) /
265
- (price * BigInt(10 ** quoteToken.decimals)));
266
- }
267
- else {
268
- result.push((price * amount * BigInt(10 ** quoteToken.decimals)) /
269
- BigInt(10 ** (baseToken.decimals * 2)));
270
- }
271
- }
272
- return result;
273
- }
274
- async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools, transferFees, isFirstSwap) {
275
- try {
276
- // Disable multi/mega routes
277
- if (!isFirstSwap) {
278
- return null;
279
- }
280
- if (await this.isRestricted()) {
281
- return null;
282
- }
283
- const normalizedSrcToken = this.normalizeToken(srcToken);
284
- const normalizedDestToken = this.normalizeToken(destToken);
285
- this.tokensMap = (await this.getCachedTokens()) || {};
286
- if (normalizedSrcToken.address === normalizedDestToken.address) {
287
- return null;
288
- }
289
- const pools = limitPools
290
- ? limitPools.filter(p => p ===
291
- this.getIdentifier(normalizedSrcToken.address, normalizedDestToken.address))
292
- : await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);
293
- if (pools.length === 0) {
294
- return null;
295
- }
296
- const pairData = await this.getPairData(normalizedSrcToken, normalizedDestToken);
297
- if (!pairData) {
298
- return null;
299
- }
300
- const priceMap = await this.getCachedPrices();
301
- if (!priceMap) {
302
- return null;
303
- }
304
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
305
- const pairKey = `${pairData.base}/${pairData.quote}`.toLowerCase();
306
- if (!(pairKey in priceMap)
307
- || !pools.includes(this.getIdentifier(tokensAddr[pairData.base.toLowerCase()], tokensAddr[pairData.quote.toLowerCase()]))) {
308
- return null;
309
- }
310
- const priceData = priceMap[pairKey];
311
- const baseToken = pairData.isSrcBase
312
- ? normalizedSrcToken
313
- : normalizedDestToken;
314
- const quoteToken = pairData.isSrcBase
315
- ? normalizedDestToken
316
- : normalizedSrcToken;
317
- // convert from swap to clob side
318
- let orderbook = priceData.asks;
319
- let clobSide = types_1.ClobSide.BID;
320
- if ((side === constants_1.SwapSide.SELL && pairData.isSrcBase) ||
321
- (side === constants_1.SwapSide.BUY && !pairData.isSrcBase)) {
322
- orderbook = priceData.bids;
323
- clobSide = types_1.ClobSide.ASK;
324
- }
325
- if (orderbook.length === 0) {
326
- throw new Error(`Empty orderbook for ${pairKey}`);
327
- }
328
- const prices = this.calculateOrderPrice(amounts, orderbook, baseToken, quoteToken, clobSide);
329
- const outDecimals = clobSide === types_1.ClobSide.BID ? baseToken.decimals : quoteToken.decimals;
330
- const poolIdentifier = this.getIdentifier(pairData.base, pairData.quote);
331
- return [
332
- {
333
- prices,
334
- unit: BigInt(outDecimals),
335
- data: {},
336
- poolIdentifier: poolIdentifier,
337
- exchange: this.dexKey,
338
- gasCost: constants_2.DEXALOT_GAS_COST,
339
- poolAddresses: [this.mainnetRFQAddress],
340
- },
341
- ];
342
- }
343
- catch (e) {
344
- this.logger.error(`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${destToken.address || destToken.symbol}, ${side}:`, e);
345
- return null;
346
- }
347
- }
348
- generateRFQError(errorStr, swapIdentifier) {
349
- const message = `${this.dexKey}-${this.network}: Failed to fetch RFQ for ${swapIdentifier}. ${errorStr}`;
350
- this.logger.warn(message);
351
- throw new types_1.DexalotRfqError(message);
352
- }
353
- async preProcessTransaction(optimalSwapExchange, srcToken, destToken, side, options) {
354
- if (await this.isBlacklisted(options.txOrigin)) {
355
- this.logger.warn(`${this.dexKey}-${this.network}: blacklisted TX Origin address '${options.txOrigin}' trying to build a transaction. Bailing...`);
356
- throw new Error(`${this.dexKey}-${this.network}: user=${options.txOrigin.toLowerCase()} is blacklisted`);
357
- }
358
- if (BigInt(optimalSwapExchange.srcAmount) === 0n) {
359
- throw new Error('getFirmRate failed with srcAmount === 0');
360
- }
361
- const normalizedSrcToken = this.normalizeToken(srcToken);
362
- const normalizedDestToken = this.normalizeToken(destToken);
363
- const swapIdentifier = `${this.getIdentifier(normalizedSrcToken.address, normalizedDestToken.address)}_${side}`;
364
- try {
365
- const makerToken = normalizedDestToken;
366
- const takerToken = normalizedSrcToken;
367
- const rfqParams = {
368
- makerAsset: ethers_1.ethers.utils.getAddress(makerToken.address),
369
- takerAsset: ethers_1.ethers.utils.getAddress(takerToken.address),
370
- makerAmount: side === constants_1.SwapSide.BUY ? optimalSwapExchange.destAmount : undefined,
371
- takerAmount: side === constants_1.SwapSide.SELL ? optimalSwapExchange.srcAmount : undefined,
372
- userAddress: options.txOrigin,
373
- chainid: this.network,
374
- };
375
- const rfq = await this.dexHelper.httpRequest.post(`${constants_2.DEXALOT_API_URL}/api/rfq/firm`, rfqParams, undefined, { 'x-apikey': this.dexalotAuthToken });
376
- if (!rfq) {
377
- this.generateRFQError('Missing quote data', `RFQ ${swapIdentifier} ${JSON.stringify(rfq)}`);
378
- }
379
- else if (!rfq.signature) {
380
- this.generateRFQError('Missing signature', swapIdentifier);
381
- }
382
- rfq.order.signature = rfq.signature;
383
- const { order } = rfq;
384
- (0, ts_essentials_1.assert)(order.makerAsset.toLowerCase() === makerToken.address, `QuoteData makerAsset=${order.makerAsset} is different from Paraswap makerAsset=${makerToken.address}`);
385
- (0, ts_essentials_1.assert)(order.takerAsset.toLowerCase() === takerToken.address, `QuoteData takerAsset=${order.takerAsset} is different from Paraswap takerAsset=${takerToken.address}`);
386
- if (side === constants_1.SwapSide.SELL) {
387
- (0, ts_essentials_1.assert)(order.takerAmount === optimalSwapExchange.srcAmount, `QuoteData takerAmount=${order.takerAmount} is different from Paraswap srcAmount=${optimalSwapExchange.srcAmount}`);
388
- }
389
- else {
390
- (0, ts_essentials_1.assert)(order.makerAmount === optimalSwapExchange.destAmount, `QuoteData makerAmount=${order.makerAmount} is different from Paraswap destAmount=${optimalSwapExchange.destAmount}`);
391
- }
392
- const expiryAsBigInt = BigInt(order.expiry);
393
- const minDeadline = expiryAsBigInt > 0 ? expiryAsBigInt : bigint_constants_1.BI_MAX_UINT256;
394
- const slippageFactor = options.slippageFactor;
395
- let isFailOnSlippage = false;
396
- let slippageErrorMessage = '';
397
- if (side === constants_1.SwapSide.SELL) {
398
- if (BigInt(order.makerAmount) <
399
- BigInt(new bignumber_js_1.default(optimalSwapExchange.destAmount.toString())
400
- .times(slippageFactor)
401
- .toFixed(0))) {
402
- isFailOnSlippage = true;
403
- const message = `${this.dexKey}-${this.network}: too much slippage on quote ${side} quoteTokenAmount ${order.makerAmount} / destAmount ${optimalSwapExchange.destAmount} < ${slippageFactor}`;
404
- slippageErrorMessage = message;
405
- this.logger.warn(message);
406
- }
407
- }
408
- else {
409
- if (BigInt(order.takerAmount) >
410
- BigInt(slippageFactor.times(optimalSwapExchange.srcAmount.toString()).toFixed(0))) {
411
- isFailOnSlippage = true;
412
- const message = `${this.dexKey}-${this.network}: too much slippage on quote ${side} baseTokenAmount ${order.takerAmount} / srcAmount ${optimalSwapExchange.srcAmount} > ${slippageFactor.toFixed()}`;
413
- slippageErrorMessage = message;
414
- this.logger.warn(message);
415
- }
416
- }
417
- let isTooStrictSlippage = false;
418
- if (isFailOnSlippage &&
419
- side === constants_1.SwapSide.SELL &&
420
- new bignumber_js_1.default(1)
421
- .minus(slippageFactor)
422
- .lt(constants_2.DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)) {
423
- isTooStrictSlippage = true;
424
- }
425
- else if (isFailOnSlippage &&
426
- side === constants_1.SwapSide.BUY &&
427
- slippageFactor
428
- .minus(1)
429
- .lt(constants_2.DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)) {
430
- isTooStrictSlippage = true;
431
- }
432
- if (isFailOnSlippage && isTooStrictSlippage) {
433
- throw new types_2.TooStrictSlippageCheckError(slippageErrorMessage);
434
- }
435
- else if (isFailOnSlippage && !isTooStrictSlippage) {
436
- throw new types_2.SlippageCheckError(slippageErrorMessage);
437
- }
438
- return [
439
- {
440
- ...optimalSwapExchange,
441
- data: {
442
- quoteData: order,
443
- },
444
- },
445
- { deadline: minDeadline },
446
- ];
447
- }
448
- catch (e) {
449
- if ((0, utils_1.isAxiosError)(e) && e.response && e.response.data) {
450
- const errorData = e.response.data;
451
- if (errorData.ReasonCode === 'FQ-009') {
452
- this.logger.warn(`${this.dexKey}-${this.network}: Encountered rate limited user=${options.txOrigin}. Adding to local rate limit cache`);
453
- await this.setRateLimited(options.txOrigin, errorData.RetryAfter);
454
- }
455
- else {
456
- await this.setBlacklist(options.txOrigin);
457
- this.logger.error(`${this.dexKey}-${this.network}: Failed to fetch RFQ for ${swapIdentifier}: ${errorData.Reason}`);
458
- }
459
- }
460
- else {
461
- if (e instanceof types_2.TooStrictSlippageCheckError) {
462
- this.logger.warn(`${this.dexKey}-${this.network}: failed to build transaction on side ${side} with too strict slippage. Skipping restriction`);
463
- }
464
- else {
465
- this.logger.warn(`${this.dexKey}-${this.network}: protocol is restricted`);
466
- await this.restrict();
467
- }
468
- }
469
- throw e;
470
- }
471
- }
472
- getCalldataGasCost(poolPrices) {
473
- return (CALLDATA_GAS_COST.DEX_OVERHEAD +
474
- // addresses: makerAsset, takerAsset, maker, taker
475
- CALLDATA_GAS_COST.ADDRESS * 4 +
476
- // uint256: expiry
477
- CALLDATA_GAS_COST.wordNonZeroBytes(16) +
478
- // uint256: nonceAndMeta, makerAmount, takerAmount
479
- CALLDATA_GAS_COST.AMOUNT * 3 +
480
- // bytes: _signature (65 bytes)
481
- CALLDATA_GAS_COST.FULL_WORD * 2 +
482
- CALLDATA_GAS_COST.OFFSET_SMALL);
483
- }
484
- getTokenFromAddress(address) {
485
- return this.tokensMap[this.normalizeAddress(address)];
486
- }
487
- getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
488
- const { quoteData } = data;
489
- (0, ts_essentials_1.assert)(quoteData !== undefined, `${this.dexKey}-${this.network}: quoteData undefined`);
490
- const params = [
491
- {
492
- nonceAndMeta: quoteData.nonceAndMeta,
493
- expiry: quoteData.expiry,
494
- makerAsset: quoteData.makerAsset,
495
- takerAsset: quoteData.takerAsset,
496
- maker: quoteData.maker,
497
- taker: quoteData.taker,
498
- makerAmount: quoteData.makerAmount,
499
- takerAmount: quoteData.takerAmount,
500
- },
501
- quoteData.signature,
502
- ];
503
- const payload = this.abiCoder.encodeParameter({
504
- ParentStruct: {
505
- order: {
506
- nonceAndMeta: 'uint256',
507
- expiry: 'uint128',
508
- makerAsset: 'address',
509
- takerAsset: 'address',
510
- maker: 'address',
511
- taker: 'address',
512
- makerAmount: 'uint256',
513
- takerAmount: 'uint256',
514
- },
515
- signature: 'bytes',
516
- },
517
- }, {
518
- order: params[0],
519
- signature: params[1],
520
- });
521
- return {
522
- targetExchange: this.mainnetRFQAddress,
523
- payload,
524
- networkFee: '0',
525
- };
526
- }
527
- async restrict(ttl = constants_2.DEXALOT_RESTRICT_TTL_S) {
528
- await this.dexHelper.cache.setex(this.dexKey, this.network, constants_2.DEXALOT_RESTRICTED_CACHE_KEY, ttl, 'true');
529
- return true;
530
- }
531
- async isRestricted() {
532
- const result = await this.dexHelper.cache.get(this.dexKey, this.network, constants_2.DEXALOT_RESTRICTED_CACHE_KEY);
533
- return result === 'true';
534
- }
535
- async setBlacklist(txOrigin, ttl = constants_2.DEXALOT_BLACKLIST_CACHES_TTL_S) {
536
- const cachedBlacklist = await this.dexHelper.cache.get(this.dexKey, this.network, this.blacklistCacheKey);
537
- let blacklist = [];
538
- if (cachedBlacklist) {
539
- blacklist = JSON.parse(cachedBlacklist);
540
- }
541
- blacklist.push(txOrigin.toLowerCase());
542
- this.dexHelper.cache.setex(this.dexKey, this.network, this.blacklistCacheKey, ttl, JSON.stringify(blacklist));
543
- return true;
544
- }
545
- async isBlacklisted(txOrigin) {
546
- const cachedBlacklist = await this.dexHelper.cache.get(this.dexKey, this.network, this.blacklistCacheKey);
547
- if (cachedBlacklist) {
548
- const blacklist = JSON.parse(cachedBlacklist);
549
- return blacklist.includes(txOrigin.toLowerCase());
550
- }
551
- // To not show pricing for rate limited users
552
- if (await this.isRateLimited(txOrigin)) {
553
- return true;
554
- }
555
- return false;
556
- }
557
- getRateLimitedKey(address) {
558
- return `rate_limited_${address}`.toLowerCase();
559
- }
560
- async isRateLimited(txOrigin) {
561
- const result = await this.dexHelper.cache.get(this.dexKey, this.network, this.getRateLimitedKey(txOrigin));
562
- return result === constants_2.DEXALOT_RATELIMIT_CACHE_VALUE;
563
- }
564
- async setRateLimited(txOrigin, ttl = constants_2.DEXALOT_RATE_LIMITED_TTL_S) {
565
- await this.dexHelper.cache.setex(this.dexKey, this.network, this.getRateLimitedKey(txOrigin), ttl, constants_2.DEXALOT_RATELIMIT_CACHE_VALUE);
566
- return true;
567
- }
568
- async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
569
- const { quoteData } = data;
570
- (0, ts_essentials_1.assert)(quoteData !== undefined, `${this.dexKey}-${this.network}: quoteData undefined`);
571
- const swapFunction = 'simpleSwap';
572
- const swapFunctionParams = [
573
- [
574
- quoteData.nonceAndMeta,
575
- quoteData.expiry,
576
- quoteData.makerAsset,
577
- quoteData.takerAsset,
578
- quoteData.maker,
579
- quoteData.taker,
580
- quoteData.makerAmount,
581
- quoteData.takerAmount,
582
- ],
583
- quoteData.signature,
584
- ];
585
- const swapData = this.rfqInterface.encodeFunctionData(swapFunction, swapFunctionParams);
586
- return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, this.mainnetRFQAddress);
587
- }
588
- async getTopPoolsForToken(tokenAddress, limit) {
589
- const normalizedTokenAddress = this.normalizeAddress(tokenAddress);
590
- const pairs = (await this.getCachedPairs()) || {};
591
- this.tokensMap = (await this.getCachedTokens()) || {};
592
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
593
- const token = this.getTokenFromAddress(normalizedTokenAddress);
594
- if (!token) {
595
- return [];
596
- }
597
- const tokenSymbol = token.symbol?.toLowerCase() || '';
598
- let pairsByLiquidity = [];
599
- for (const pairName of Object.keys(pairs)) {
600
- if (!pairName.includes(tokenSymbol)) {
601
- continue;
602
- }
603
- const tokensInPair = pairName.split('/');
604
- if (tokensInPair.length !== 2) {
605
- continue;
606
- }
607
- const [baseToken, quoteToken] = tokensInPair;
608
- const addr = tokensAddr[baseToken.toLowerCase()];
609
- let outputToken = this.getTokenFromAddress(addr);
610
- if (baseToken === tokenSymbol) {
611
- const addr = tokensAddr[quoteToken.toLowerCase()];
612
- outputToken = this.getTokenFromAddress(addr);
613
- }
614
- const denormalizedToken = this.denormalizeToken(outputToken);
615
- pairsByLiquidity.push({
616
- exchange: this.dexKey,
617
- address: this.mainnetRFQAddress,
618
- connectorTokens: [{
619
- address: denormalizedToken.address,
620
- decimals: denormalizedToken.decimals,
621
- }],
622
- liquidityUSD: pairs[pairName].liquidityUSD,
623
- });
624
- }
625
- pairsByLiquidity.sort((a, b) => b.liquidityUSD - a.liquidityUSD);
626
- return pairsByLiquidity.slice(0, limit);
627
- }
628
- getAPIReqParams(endpoint, method) {
629
- return {
630
- url: `${constants_2.DEXALOT_API_URL}/${endpoint}`,
631
- headers: { 'x-apikey': this.dexalotAuthToken },
632
- params: {
633
- chainid: this.network,
634
- },
635
- method: method,
636
- };
637
- }
638
- releaseResources() {
639
- if (this.rateFetcher) {
640
- this.rateFetcher.stop();
641
- }
642
- }
643
- }
644
- exports.Dexalot = Dexalot;
645
- Dexalot.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.DexalotConfig);
646
- //# sourceMappingURL=dexalot.js.map