@paraswap/dex-lib 5.1.32 → 5.1.33-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/build/abi/BProtocol.json +1155 -0
  2. package/build/abi/Jarvis.json +1172 -0
  3. package/build/abi/MStableAsset.json +1545 -0
  4. package/build/abi/OneInchLp.json +1304 -0
  5. package/build/abi/Onebit.json +736 -0
  6. package/build/abi/Shell.json +1294 -0
  7. package/build/abi/TraderJoeV2Router.json +50 -0
  8. package/build/abi/curve-v1/StableSwapArbitrum2Pool.json +1206 -0
  9. package/build/abi/curve-v1/StableSwapGnosis3Pool.json +868 -0
  10. package/build/abi/curve-v1/StableSwapOptimism3Pool.json +1216 -0
  11. package/build/abi/idle-dao/idle-cdo-factory.json +38 -0
  12. package/build/abi/idle-dao/idle-cdo.json +1245 -0
  13. package/build/abi/infusion/InfusionFactory.json +147 -0
  14. package/build/abi/infusion/InfusionPair.json +658 -0
  15. package/build/abi/infusion/InfusionRouter.json +442 -0
  16. package/build/abi/maker-psm/pot.json +322 -0
  17. package/build/abi/maker-psm/psm.json +243 -0
  18. package/build/abi/maker-psm/vat.json +363 -0
  19. package/build/abi/nomiswap-v2/nomiswap-v2-pool.json +773 -0
  20. package/build/abi/quick-perps/fast-price-events.json +70 -0
  21. package/build/abi/quick-perps/fast-price-feed.json +741 -0
  22. package/build/abi/quick-perps/reader.json +313 -0
  23. package/build/abi/quick-perps/vault-price-feed.json +323 -0
  24. package/build/abi/quick-perps/vault.json +1953 -0
  25. package/build/abi/uniswap-v2/excalibur-pool.json +881 -0
  26. package/build/abi/uniswap-v2/mdex-factory.json +759 -0
  27. package/build/abi/wUSDM.json +757 -0
  28. package/build/abi/zrx.v2.json +1967 -0
  29. package/build/abi/zrx.v3.json +3454 -0
  30. package/build/abi/zrx.v4.json +2193 -0
  31. package/build/dex/OneInchLp.d.ts +24 -0
  32. package/build/dex/OneInchLp.js +43 -0
  33. package/build/dex/OneInchLp.js.map +1 -0
  34. package/build/dex/bProtocol/bProtocol.d.ts +15 -0
  35. package/build/dex/bProtocol/bProtocol.js +56 -0
  36. package/build/dex/bProtocol/bProtocol.js.map +1 -0
  37. package/build/dex/bProtocol/types.d.ts +11 -0
  38. package/build/dex/bProtocol/types.js +8 -0
  39. package/build/dex/bProtocol/types.js.map +1 -0
  40. package/build/dex/curve-v1/config.js +6 -3
  41. package/build/dex/curve-v1/config.js.map +1 -1
  42. package/build/dex/curve-v1/curve-v1.js +24 -1
  43. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  44. package/build/dex/curve-v1/pools/arbitrum-2pool.d.ts +7 -0
  45. package/build/dex/curve-v1/pools/arbitrum-2pool.js +26 -0
  46. package/build/dex/curve-v1/pools/arbitrum-2pool.js.map +1 -0
  47. package/build/dex/curve-v1/pools/gnosis-3pool.d.ts +7 -0
  48. package/build/dex/curve-v1/pools/gnosis-3pool.js +26 -0
  49. package/build/dex/curve-v1/pools/gnosis-3pool.js.map +1 -0
  50. package/build/dex/curve-v1/pools/optimism-3pool.d.ts +7 -0
  51. package/build/dex/curve-v1/pools/optimism-3pool.js +27 -0
  52. package/build/dex/curve-v1/pools/optimism-3pool.js.map +1 -0
  53. package/build/dex/curve-v1/pools/sidechain-pool.d.ts +12 -0
  54. package/build/dex/curve-v1/pools/sidechain-pool.js +61 -0
  55. package/build/dex/curve-v1/pools/sidechain-pool.js.map +1 -0
  56. package/build/dex/ekubo/pools/base-pool.d.ts +47 -0
  57. package/build/dex/ekubo/pools/base-pool.js +184 -0
  58. package/build/dex/ekubo/pools/base-pool.js.map +1 -0
  59. package/build/dex/ekubo/pools/iface.d.ts +46 -0
  60. package/build/dex/ekubo/pools/iface.js +75 -0
  61. package/build/dex/ekubo/pools/iface.js.map +1 -0
  62. package/build/dex/ekubo/pools/math/price.d.ts +7 -0
  63. package/build/dex/ekubo/pools/math/price.js +112 -0
  64. package/build/dex/ekubo/pools/math/price.js.map +1 -0
  65. package/build/dex/ekubo/pools/oracle-pool.d.ts +10 -0
  66. package/build/dex/ekubo/pools/oracle-pool.js +19 -0
  67. package/build/dex/ekubo/pools/oracle-pool.js.map +1 -0
  68. package/build/dex/ekubo/pools/pool-utils.d.ts +44 -0
  69. package/build/dex/ekubo/pools/pool-utils.js +240 -0
  70. package/build/dex/ekubo/pools/pool-utils.js.map +1 -0
  71. package/build/dex/idle-dao/config.d.ts +5 -0
  72. package/build/dex/idle-dao/config.js +24 -0
  73. package/build/dex/idle-dao/config.js.map +1 -0
  74. package/build/dex/idle-dao/idle-dao.d.ts +42 -0
  75. package/build/dex/idle-dao/idle-dao.js +279 -0
  76. package/build/dex/idle-dao/idle-dao.js.map +1 -0
  77. package/build/dex/idle-dao/token_list.d.ts +4 -0
  78. package/build/dex/idle-dao/token_list.js +289 -0
  79. package/build/dex/idle-dao/token_list.js.map +1 -0
  80. package/build/dex/idle-dao/tokens.d.ts +9 -0
  81. package/build/dex/idle-dao/tokens.js +68 -0
  82. package/build/dex/idle-dao/tokens.js.map +1 -0
  83. package/build/dex/idle-dao/types.d.ts +35 -0
  84. package/build/dex/idle-dao/types.js +11 -0
  85. package/build/dex/idle-dao/types.js.map +1 -0
  86. package/build/dex/idle-dao/utils.d.ts +8 -0
  87. package/build/dex/idle-dao/utils.js +149 -0
  88. package/build/dex/idle-dao/utils.js.map +1 -0
  89. package/build/dex/infusion/config.d.ts +3 -0
  90. package/build/dex/infusion/config.js +20 -0
  91. package/build/dex/infusion/config.js.map +1 -0
  92. package/build/dex/infusion/infusion-stable-pool.d.ts +4 -0
  93. package/build/dex/infusion/infusion-stable-pool.js +74 -0
  94. package/build/dex/infusion/infusion-stable-pool.js.map +1 -0
  95. package/build/dex/infusion/infusion.d.ts +51 -0
  96. package/build/dex/infusion/infusion.js +500 -0
  97. package/build/dex/infusion/infusion.js.map +1 -0
  98. package/build/dex/infusion/types.d.ts +45 -0
  99. package/build/dex/infusion/types.js.map +1 -0
  100. package/build/dex/infusion/utils/isStablePair.d.ts +2 -0
  101. package/build/dex/infusion/utils/isStablePair.js +18 -0
  102. package/build/dex/infusion/utils/isStablePair.js.map +1 -0
  103. package/build/dex/jarvis.d.ts +56 -0
  104. package/build/dex/jarvis.js +163 -0
  105. package/build/dex/jarvis.js.map +1 -0
  106. package/build/dex/mStable.d.ts +44 -0
  107. package/build/dex/mStable.js +75 -0
  108. package/build/dex/mStable.js.map +1 -0
  109. package/build/dex/maker-psm/config.d.ts +11 -0
  110. package/build/dex/maker-psm/config.js +53 -0
  111. package/build/dex/maker-psm/config.js.map +1 -0
  112. package/build/dex/maker-psm/maker-psm.d.ts +103 -0
  113. package/build/dex/maker-psm/maker-psm.js +493 -0
  114. package/build/dex/maker-psm/maker-psm.js.map +1 -0
  115. package/build/dex/maker-psm/types.d.ts +39 -0
  116. package/build/{generic-swap-transaction-builder/dex-encoder/ports.js → dex/maker-psm/types.js} +1 -1
  117. package/build/dex/maker-psm/types.js.map +1 -0
  118. package/build/dex/onebit/onebit.d.ts +16 -0
  119. package/build/dex/onebit/onebit.js +61 -0
  120. package/build/dex/onebit/onebit.js.map +1 -0
  121. package/build/dex/onebit/types.d.ts +14 -0
  122. package/build/dex/onebit/types.js +8 -0
  123. package/build/dex/onebit/types.js.map +1 -0
  124. package/build/dex/quick-perps/config.d.ts +11 -0
  125. package/build/dex/quick-perps/config.js +27 -0
  126. package/build/dex/quick-perps/config.js.map +1 -0
  127. package/build/dex/quick-perps/fast-price-feed.d.ts +26 -0
  128. package/build/dex/quick-perps/fast-price-feed.js +184 -0
  129. package/build/dex/quick-perps/fast-price-feed.js.map +1 -0
  130. package/build/dex/quick-perps/pool.d.ts +21 -0
  131. package/build/dex/quick-perps/pool.js +229 -0
  132. package/build/dex/quick-perps/pool.js.map +1 -0
  133. package/build/dex/quick-perps/quick-perps.d.ts +53 -0
  134. package/build/dex/quick-perps/quick-perps.js +247 -0
  135. package/build/dex/quick-perps/quick-perps.js.map +1 -0
  136. package/build/dex/quick-perps/types.d.ts +98 -0
  137. package/build/{executor/encoding-types.js → dex/quick-perps/types.js} +1 -1
  138. package/build/dex/quick-perps/types.js.map +1 -0
  139. package/build/dex/quick-perps/usdq.d.ts +15 -0
  140. package/build/dex/quick-perps/usdq.js +62 -0
  141. package/build/dex/quick-perps/usdq.js.map +1 -0
  142. package/build/dex/quick-perps/vault-price-feed.d.ts +43 -0
  143. package/build/dex/quick-perps/vault-price-feed.js +203 -0
  144. package/build/dex/quick-perps/vault-price-feed.js.map +1 -0
  145. package/build/dex/quick-perps/vault-utils.d.ts +8 -0
  146. package/build/dex/quick-perps/vault-utils.js +42 -0
  147. package/build/dex/quick-perps/vault-utils.js.map +1 -0
  148. package/build/dex/quick-perps/vault.d.ts +46 -0
  149. package/build/dex/quick-perps/vault.js +182 -0
  150. package/build/dex/quick-perps/vault.js.map +1 -0
  151. package/build/dex/se-vlr/config.d.ts +3 -0
  152. package/build/dex/se-vlr/config.js +24 -0
  153. package/build/dex/se-vlr/config.js.map +1 -0
  154. package/build/dex/se-vlr/se-vlr-pool.d.ts +39 -0
  155. package/build/dex/se-vlr/se-vlr-pool.js +70 -0
  156. package/build/dex/se-vlr/se-vlr-pool.js.map +1 -0
  157. package/build/dex/se-vlr/se-vlr.d.ts +35 -0
  158. package/build/dex/se-vlr/se-vlr.js +131 -0
  159. package/build/dex/se-vlr/se-vlr.js.map +1 -0
  160. package/build/dex/se-vlr/types.d.ts +6 -0
  161. package/build/dex/se-vlr/types.js +3 -0
  162. package/build/dex/se-vlr/types.js.map +1 -0
  163. package/build/dex/shell.d.ts +25 -0
  164. package/build/dex/shell.js +41 -0
  165. package/build/dex/shell.js.map +1 -0
  166. package/build/dex/solidly/forks-override/aerodrome.d.ts +14 -0
  167. package/build/dex/solidly/forks-override/aerodrome.js +46 -0
  168. package/build/dex/solidly/forks-override/aerodrome.js.map +1 -0
  169. package/build/dex/solidly/forks-override/chronos.d.ts +23 -0
  170. package/build/dex/solidly/forks-override/chronos.js +141 -0
  171. package/build/dex/solidly/forks-override/chronos.js.map +1 -0
  172. package/build/dex/solidly/forks-override/usdfi.d.ts +8 -0
  173. package/build/dex/solidly/forks-override/usdfi.js +15 -0
  174. package/build/dex/solidly/forks-override/usdfi.js.map +1 -0
  175. package/build/dex/solidly/forks-override/velocimeter.d.ts +23 -0
  176. package/build/dex/solidly/forks-override/velocimeter.js +77 -0
  177. package/build/dex/solidly/forks-override/velocimeter.js.map +1 -0
  178. package/build/dex/tessera/types.d.ts +3 -0
  179. package/build/dex/tessera/types.js +3 -0
  180. package/build/dex/tessera/types.js.map +1 -0
  181. package/build/dex/trader-joe-v2.d.ts +40 -0
  182. package/build/dex/trader-joe-v2.js +74 -0
  183. package/build/dex/trader-joe-v2.js.map +1 -0
  184. package/build/dex/uniswap-v2/dfyn.d.ts +19 -0
  185. package/build/dex/uniswap-v2/dfyn.js +61 -0
  186. package/build/dex/uniswap-v2/dfyn.js.map +1 -0
  187. package/build/dex/uniswap-v2/excalibur.d.ts +24 -0
  188. package/build/dex/uniswap-v2/excalibur.js +47 -0
  189. package/build/dex/uniswap-v2/excalibur.js.map +1 -0
  190. package/build/dex/uniswap-v2/mdex.d.ts +24 -0
  191. package/build/dex/uniswap-v2/mdex.js +50 -0
  192. package/build/dex/uniswap-v2/mdex.js.map +1 -0
  193. package/build/dex/uniswap-v2/nomiswap-v2.d.ts +24 -0
  194. package/build/dex/uniswap-v2/nomiswap-v2.js +57 -0
  195. package/build/dex/uniswap-v2/nomiswap-v2.js.map +1 -0
  196. package/build/dex/uniswap-v3/scripts/bench-all-dexes.js +160 -0
  197. package/build/dex/uniswap-v3/scripts/bench-all-dexes.js.map +1 -0
  198. package/build/dex/uniswap-v3/uniswap-v3-new.d.ts +94 -0
  199. package/build/dex/uniswap-v3/uniswap-v3-new.js +923 -0
  200. package/build/dex/uniswap-v3/uniswap-v3-new.js.map +1 -0
  201. package/build/dex/uniswap-v4/contract-math/Position.d.ts +3 -0
  202. package/build/dex/uniswap-v4/contract-math/Position.js +10 -0
  203. package/build/dex/uniswap-v4/contract-math/Position.js.map +1 -0
  204. package/build/dex/usual-bond/config.d.ts +3 -0
  205. package/build/dex/usual-bond/config.js +13 -0
  206. package/build/dex/usual-bond/config.js.map +1 -0
  207. package/build/dex/usual-bond/types.d.ts +7 -0
  208. package/build/dex/usual-bond/types.js +3 -0
  209. package/build/dex/usual-bond/types.js.map +1 -0
  210. package/build/dex/usual-bond/usual-bond.d.ts +35 -0
  211. package/build/dex/usual-bond/usual-bond.js +176 -0
  212. package/build/dex/usual-bond/usual-bond.js.map +1 -0
  213. package/build/dex/wusdm/config.d.ts +3 -0
  214. package/build/dex/wusdm/config.js +43 -0
  215. package/build/dex/wusdm/config.js.map +1 -0
  216. package/build/dex/wusdm/constants.d.ts +2 -0
  217. package/build/dex/wusdm/constants.js +6 -0
  218. package/build/dex/wusdm/constants.js.map +1 -0
  219. package/build/dex/wusdm/types.d.ts +18 -0
  220. package/build/dex/wusdm/types.js +11 -0
  221. package/build/dex/wusdm/types.js.map +1 -0
  222. package/build/dex/wusdm/wusdm-pool.d.ts +21 -0
  223. package/build/dex/wusdm/wusdm-pool.js +74 -0
  224. package/build/dex/wusdm/wusdm-pool.js.map +1 -0
  225. package/build/dex/wusdm/wusdm.d.ts +46 -0
  226. package/build/dex/wusdm/wusdm.js +243 -0
  227. package/build/dex/wusdm/wusdm.js.map +1 -0
  228. package/build/dex/zerox/config.d.ts +2 -0
  229. package/build/dex/zerox/config.js +33 -0
  230. package/build/dex/zerox/config.js.map +1 -0
  231. package/build/dex/zerox/index.d.ts +22 -0
  232. package/build/dex/zerox/index.js +225 -0
  233. package/build/dex/zerox/index.js.map +1 -0
  234. package/build/dex/zerox/order.d.ts +88 -0
  235. package/build/dex/zerox/order.js +53 -0
  236. package/build/dex/zerox/order.js.map +1 -0
  237. package/build/dex/zerox/types.d.ts +73 -0
  238. package/build/dex/zerox/types.js +21 -0
  239. package/build/dex/zerox/types.js.map +1 -0
  240. package/package.json +1 -1
  241. package/build/abi/pancakeswap-infinity/cl-pool-manager.json +0 -80
  242. package/build/dex/fluid-dex/scripts/measure-calc-time.js +0 -178
  243. package/build/dex/fluid-dex/scripts/measure-calc-time.js.map +0 -1
  244. package/build/dex/uniswap-v4/api-go/compare-pricing.d.ts +0 -1
  245. package/build/dex/uniswap-v4/api-go/compare-pricing.js +0 -187
  246. package/build/dex/uniswap-v4/api-go/compare-pricing.js.map +0 -1
  247. package/build/dex/uniswap-v4/api-go/compare-states.d.ts +0 -1
  248. package/build/dex/uniswap-v4/api-go/compare-states.js +0 -149
  249. package/build/dex/uniswap-v4/api-go/compare-states.js.map +0 -1
  250. package/build/dex/uniswap-v4/api-go/fetch-pool-key.d.ts +0 -0
  251. package/build/dex/uniswap-v4/api-go/fetch-pool-key.js +0 -140
  252. package/build/dex/uniswap-v4/api-go/fetch-pool-key.js.map +0 -1
  253. package/build/executor/__test-utils__/snapshot-test-helpers.d.ts +0 -10
  254. package/build/executor/__test-utils__/snapshot-test-helpers.js +0 -72
  255. package/build/executor/__test-utils__/snapshot-test-helpers.js.map +0 -1
  256. package/build/executor/address-utils.d.ts +0 -2
  257. package/build/executor/address-utils.js +0 -7
  258. package/build/executor/address-utils.js.map +0 -1
  259. package/build/executor/approval.d.ts +0 -9
  260. package/build/executor/approval.js +0 -29
  261. package/build/executor/approval.js.map +0 -1
  262. package/build/executor/encoding-context.d.ts +0 -4
  263. package/build/executor/encoding-context.js +0 -54
  264. package/build/executor/encoding-context.js.map +0 -1
  265. package/build/executor/encoding-types.d.ts +0 -75
  266. package/build/executor/encoding-types.js.map +0 -1
  267. package/build/executor/factory.d.ts +0 -4
  268. package/build/executor/factory.js +0 -23
  269. package/build/executor/factory.js.map +0 -1
  270. package/build/executor/route-plan.d.ts +0 -8
  271. package/build/executor/route-plan.js +0 -109
  272. package/build/executor/route-plan.js.map +0 -1
  273. package/build/generic-swap-transaction-builder/dex-encoder/direct-methods.d.ts +0 -6
  274. package/build/generic-swap-transaction-builder/dex-encoder/direct-methods.js +0 -39
  275. package/build/generic-swap-transaction-builder/dex-encoder/direct-methods.js.map +0 -1
  276. package/build/generic-swap-transaction-builder/dex-encoder/index.d.ts +0 -4
  277. package/build/generic-swap-transaction-builder/dex-encoder/index.js +0 -21
  278. package/build/generic-swap-transaction-builder/dex-encoder/index.js.map +0 -1
  279. package/build/generic-swap-transaction-builder/dex-encoder/ports.d.ts +0 -26
  280. package/build/generic-swap-transaction-builder/dex-encoder/ports.js.map +0 -1
  281. package/build/generic-swap-transaction-builder/dex-encoder/ts-adapter.d.ts +0 -22
  282. package/build/generic-swap-transaction-builder/dex-encoder/ts-adapter.js +0 -299
  283. package/build/generic-swap-transaction-builder/dex-encoder/ts-adapter.js.map +0 -1
  284. package/build/generic-swap-transaction-builder/dex-encoder/types.d.ts +0 -207
  285. package/build/generic-swap-transaction-builder/dex-encoder/types.js +0 -194
  286. package/build/generic-swap-transaction-builder/dex-encoder/types.js.map +0 -1
  287. package/build/generic-swap-transaction-builder/orchestration.d.ts +0 -65
  288. package/build/generic-swap-transaction-builder/orchestration.js +0 -198
  289. package/build/generic-swap-transaction-builder/orchestration.js.map +0 -1
  290. package/build/generic-swap-transaction-builder/resolved/build-transaction.d.ts +0 -13
  291. package/build/generic-swap-transaction-builder/resolved/build-transaction.js +0 -343
  292. package/build/generic-swap-transaction-builder/resolved/build-transaction.js.map +0 -1
  293. package/build/generic-swap-transaction-builder/resolved/index.d.ts +0 -4
  294. package/build/generic-swap-transaction-builder/resolved/index.js +0 -21
  295. package/build/generic-swap-transaction-builder/resolved/index.js.map +0 -1
  296. package/build/generic-swap-transaction-builder/resolved/route-plan.d.ts +0 -2
  297. package/build/generic-swap-transaction-builder/resolved/route-plan.js +0 -11
  298. package/build/generic-swap-transaction-builder/resolved/route-plan.js.map +0 -1
  299. package/build/generic-swap-transaction-builder/resolved/types.d.ts +0 -67
  300. package/build/generic-swap-transaction-builder/resolved/types.js.map +0 -1
  301. package/build/generic-swap-transaction-builder/resolved/validation.d.ts +0 -10
  302. package/build/generic-swap-transaction-builder/resolved/validation.js +0 -69
  303. package/build/generic-swap-transaction-builder/resolved/validation.js.map +0 -1
  304. /package/build/{generic-swap-transaction-builder/resolved → dex/infusion}/types.js +0 -0
  305. /package/build/dex/{fluid-dex/scripts/measure-calc-time.d.ts → uniswap-v3/scripts/bench-all-dexes.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/infusion/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEvC,QAAA,cAAc,GAA4B;IACrD,QAAQ,EAAE;QACR,CAAC,mBAAO,CAAC,IAAI,CAAC,EAAE;YACd,WAAW,EACT,2GAA2G;YAC7G,cAAc,EAAE,4CAA4C;YAC5D,MAAM,EAAE,4CAA4C;YACpD,QAAQ,EACN,oEAAoE;YACtE,8CAA8C;YAC9C,SAAS,EAAE,CAAC;YACZ,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,GAAG,GAAG,IAAI;YACvB,OAAO,EAAE,CAAC;SACX;KACF;CACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { InfusionPoolOrderedParams } from './types';
2
+ export declare class InfusionStablePool {
3
+ static getSellPrice(priceParams: InfusionPoolOrderedParams, srcAmount: bigint, feeFactor: number): bigint;
4
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfusionStablePool = void 0;
4
+ const bigint_constants_1 = require("../../bigint-constants");
5
+ const uniswap_v2_1 = require("../uniswap-v2/uniswap-v2");
6
+ const e18 = bigint_constants_1.BI_POWS[18];
7
+ function _k(x, y, decimals0, decimals1) {
8
+ const _x = (x * e18) / decimals0;
9
+ const _y = (y * e18) / decimals1;
10
+ const _a = (_x * _y) / e18;
11
+ const _b = (_x * _x) / e18 + (_y * _y) / e18;
12
+ // x3y+y3x >= k
13
+ return (_a * _b) / e18;
14
+ }
15
+ function _f(x0, y) {
16
+ return ((x0 * ((((y * y) / e18) * y) / e18)) / e18 +
17
+ (((((x0 * x0) / e18) * x0) / e18) * y) / e18);
18
+ }
19
+ function _d(x0, y) {
20
+ return (3n * x0 * ((y * y) / e18)) / e18 + (((x0 * x0) / e18) * x0) / e18;
21
+ }
22
+ function _getY(x0, xy, y) {
23
+ for (let i = 0; i < 255; i++) {
24
+ const yPrev = y;
25
+ const k = _f(x0, y);
26
+ if (k < xy) {
27
+ const dy = ((xy - k) * e18) / _d(x0, y);
28
+ y = y + dy;
29
+ }
30
+ else {
31
+ const dy = ((k - xy) * e18) / _d(x0, y);
32
+ y = y - dy;
33
+ }
34
+ if (_closeTo(y, yPrev, 1n)) {
35
+ break;
36
+ }
37
+ }
38
+ return y;
39
+ }
40
+ function _closeTo(a, b, target) {
41
+ if (a > b) {
42
+ if (a - b <= target) {
43
+ return true;
44
+ }
45
+ }
46
+ else {
47
+ if (b - a <= target) {
48
+ return true;
49
+ }
50
+ }
51
+ return false;
52
+ }
53
+ class InfusionStablePool {
54
+ static getSellPrice(priceParams, srcAmount, feeFactor) {
55
+ const { reservesIn, reservesOut, decimalsIn, decimalsOut, fee } = priceParams;
56
+ // FIXME: some dexes use uint112 others use uint256
57
+ if (BigInt(reservesIn) + srcAmount > uniswap_v2_1.RESERVE_LIMIT) {
58
+ return 0n;
59
+ }
60
+ const amountIn = srcAmount - (srcAmount * BigInt(fee)) / BigInt(feeFactor);
61
+ const reservesInN = BigInt(reservesIn);
62
+ const reservesOutN = BigInt(reservesOut);
63
+ const decimalsInN = 10n ** BigInt(decimalsIn);
64
+ const decimalsOutN = 10n ** BigInt(decimalsOut);
65
+ const xy = _k(reservesInN, reservesOutN, decimalsInN, decimalsOutN);
66
+ const reserveA = (reservesInN * e18) / decimalsInN;
67
+ const reserveB = (reservesOutN * e18) / decimalsOutN;
68
+ const amountInNorm = (amountIn * e18) / decimalsInN;
69
+ const y = reserveB - _getY(amountInNorm + reserveA, xy, reserveB);
70
+ return (y * decimalsOutN) / e18;
71
+ }
72
+ }
73
+ exports.InfusionStablePool = InfusionStablePool;
74
+ //# sourceMappingURL=infusion-stable-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infusion-stable-pool.js","sourceRoot":"","sources":["../../../src/dex/infusion/infusion-stable-pool.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,51 @@
1
+ import { UniswapV2 } from '../uniswap-v2/uniswap-v2';
2
+ import { Network } from '../../constants';
3
+ import { AdapterExchangeParam, Address, DexExchangeParam, ExchangePrices, PoolLiquidity, Token, TransferFeeParams } from '../../types';
4
+ import { IDexHelper } from '../../dex-helper';
5
+ import { NumberAsString, SwapSide } from '@paraswap/core';
6
+ import { PoolState, InfusionData, InfusionPair, InfusionPoolOrderedParams } from './types';
7
+ export declare enum InfusionRouterFunctions {
8
+ sellExactEth = "swapExactETHForTokens",
9
+ sellExactToken = "swapExactTokensForETH",
10
+ swapExactIn = "swapExactTokensForTokens"
11
+ }
12
+ export declare class Infusion extends UniswapV2 {
13
+ protected network: Network;
14
+ protected dexHelper: IDexHelper;
15
+ pairs: {
16
+ [key: string]: InfusionPair;
17
+ };
18
+ stableFee?: number;
19
+ volatileFee?: number;
20
+ readonly isFeeOnTransferSupported: boolean;
21
+ readonly SRC_TOKEN_DEX_TRANSFERS = 1;
22
+ readonly DEST_TOKEN_DEX_TRANSFERS = 1;
23
+ static dexKeysWithNetwork: {
24
+ key: string;
25
+ networks: Network[];
26
+ }[];
27
+ constructor(network: Network, dexKey: string, dexHelper: IDexHelper, isDynamicFees?: boolean, factoryAddress?: Address, subgraphURL?: string, initCode?: string, feeCode?: number, poolGasCost?: number, routerAddress?: Address);
28
+ findInfusionPairs(from: Token, to: Token): Promise<InfusionPair[]>;
29
+ batchCatchUpPairs(pairs: [Token, Token][], blockNumber: number): Promise<void>;
30
+ getManyPoolReserves(pairs: InfusionPair[], blockNumber: number): Promise<PoolState[]>;
31
+ getSellPrice(priceParams: InfusionPoolOrderedParams, srcAmount: bigint): bigint;
32
+ getPricesVolume(_from: Token, _to: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[], transferFees?: TransferFeeParams): Promise<ExchangePrices<InfusionData> | null>;
33
+ getTopPoolsForToken(tokenAddress: Address, count: number): Promise<PoolLiquidity[]>;
34
+ getInfusionPairOrderedParams(from: Token, to: Token, blockNumber: number, tokenDexTransferFee: number): Promise<Array<InfusionPoolOrderedParams | null>>;
35
+ getPoolIdentifiers(_from: Token, _to: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
36
+ poolPostfix(stable: boolean): "S" | "V";
37
+ getAdapters(side: SwapSide): {
38
+ name: string;
39
+ index: number;
40
+ }[] | null;
41
+ getAdapterParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, toAmount: NumberAsString, // required for buy case
42
+ data: InfusionData, side: SwapSide): AdapterExchangeParam;
43
+ getDexParam(src: Address, dest: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: InfusionData, side: SwapSide): DexExchangeParam;
44
+ protected getFeesMultiCallData(pair: InfusionPair): {
45
+ callEntry: {
46
+ target: string;
47
+ callData: string;
48
+ };
49
+ callDecoder: (values: any[]) => number;
50
+ };
51
+ }
@@ -0,0 +1,500 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Infusion = exports.InfusionRouterFunctions = void 0;
7
+ const uniswap_v2_1 = require("../uniswap-v2/uniswap-v2");
8
+ const constants_1 = require("../../constants");
9
+ const erc20_json_1 = __importDefault(require("../../abi/erc20.json"));
10
+ const utils_1 = require("../../utils");
11
+ const InfusionFactory_json_1 = __importDefault(require("../../abi/infusion/InfusionFactory.json"));
12
+ const InfusionPair_json_1 = __importDefault(require("../../abi/infusion/InfusionPair.json"));
13
+ const InfusionRouter_json_1 = __importDefault(require("../../abi/infusion/InfusionRouter.json"));
14
+ const lodash_1 = __importDefault(require("lodash"));
15
+ const core_1 = require("@paraswap/core");
16
+ const abi_1 = require("@ethersproject/abi");
17
+ const infusion_stable_pool_1 = require("./infusion-stable-pool");
18
+ const uniswap_v2_constant_product_pool_1 = require("../uniswap-v2/uniswap-v2-constant-product-pool");
19
+ const config_1 = require("./config");
20
+ const token_transfer_fee_1 = require("../../lib/token-transfer-fee");
21
+ const isStablePair_1 = require("./utils/isStablePair");
22
+ const decoders_1 = require("../../lib/decoders");
23
+ const INFUSION_RECHECK_PAIR_EXISTENCE_AFTER_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
24
+ var InfusionRouterFunctions;
25
+ (function (InfusionRouterFunctions) {
26
+ InfusionRouterFunctions["sellExactEth"] = "swapExactETHForTokens";
27
+ InfusionRouterFunctions["sellExactToken"] = "swapExactTokensForETH";
28
+ InfusionRouterFunctions["swapExactIn"] = "swapExactTokensForTokens";
29
+ })(InfusionRouterFunctions || (exports.InfusionRouterFunctions = InfusionRouterFunctions = {}));
30
+ const VelodromeFactoryABI = [
31
+ {
32
+ inputs: [{ internalType: 'bool', name: '_stable', type: 'bool' }],
33
+ name: 'getFee',
34
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
35
+ stateMutability: 'view',
36
+ type: 'function',
37
+ },
38
+ ];
39
+ const velodromeFactoryIface = new abi_1.Interface(VelodromeFactoryABI);
40
+ const erc20Iface = new abi_1.Interface(erc20_json_1.default);
41
+ const infusionPairIface = new abi_1.Interface(InfusionPair_json_1.default);
42
+ const defaultAbiCoder = new abi_1.AbiCoder();
43
+ class Infusion extends uniswap_v2_1.UniswapV2 {
44
+ network;
45
+ dexHelper;
46
+ pairs = {};
47
+ stableFee;
48
+ volatileFee;
49
+ isFeeOnTransferSupported = true;
50
+ SRC_TOKEN_DEX_TRANSFERS = 1;
51
+ DEST_TOKEN_DEX_TRANSFERS = 1;
52
+ static dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(lodash_1.default.pick(config_1.InfusionConfig, ['Infusion']));
53
+ constructor(network, dexKey, dexHelper, isDynamicFees = true, factoryAddress, subgraphURL, initCode, feeCode, poolGasCost, routerAddress) {
54
+ super(network, dexKey, dexHelper, isDynamicFees, factoryAddress !== undefined
55
+ ? factoryAddress
56
+ : config_1.InfusionConfig[dexKey][network].factoryAddress, subgraphURL === ''
57
+ ? undefined
58
+ : subgraphURL !== undefined
59
+ ? subgraphURL
60
+ : config_1.InfusionConfig[dexKey][network].subgraphURL, initCode !== undefined
61
+ ? initCode
62
+ : config_1.InfusionConfig[dexKey][network].initCode, feeCode !== undefined ? feeCode : config_1.InfusionConfig[dexKey][network].feeCode, poolGasCost !== undefined
63
+ ? poolGasCost
64
+ : config_1.InfusionConfig[dexKey][network].poolGasCost, infusionPairIface);
65
+ this.network = network;
66
+ this.dexHelper = dexHelper;
67
+ this.stableFee = config_1.InfusionConfig[dexKey][network].stableFee;
68
+ this.volatileFee = config_1.InfusionConfig[dexKey][network].volatileFee;
69
+ this.factory = new dexHelper.web3Provider.eth.Contract(InfusionFactory_json_1.default, factoryAddress !== undefined
70
+ ? factoryAddress
71
+ : config_1.InfusionConfig[dexKey][network].factoryAddress);
72
+ this.router =
73
+ routerAddress !== undefined
74
+ ? routerAddress
75
+ : config_1.InfusionConfig[dexKey][network].router || '';
76
+ this.feeFactor =
77
+ config_1.InfusionConfig[dexKey][network].feeFactor || this.feeFactor;
78
+ }
79
+ async findInfusionPairs(from, to) {
80
+ const [token0, token1] = from.address.toLowerCase() < to.address.toLowerCase()
81
+ ? [from, to]
82
+ : [to, from];
83
+ const pairKeyBase = `${token0.address.toLowerCase()}-${token1.address.toLowerCase()}`;
84
+ const stableValues = [false, true];
85
+ const pairKeys = stableValues.map(stable => `${pairKeyBase}-${this.poolPostfix(stable)}`);
86
+ // get cached pairs
87
+ const pairs = pairKeys.map(key => this.pairs[key]);
88
+ if (pairs.every(Boolean))
89
+ return pairs;
90
+ const cachedPairsRaw = await this.dexHelper.cache.hmget(this.pairsHashCacheKey, pairKeys);
91
+ const cachedPairs = cachedPairsRaw.map(p => p ? JSON.parse(p) : null);
92
+ const shouldFetchFromRpc = cachedPairs.some((cachedPair, i) => {
93
+ if (cachedPair &&
94
+ (cachedPair.exchange ||
95
+ (cachedPair.checkExistenceAfter &&
96
+ cachedPair.checkExistenceAfter > Date.now()))) {
97
+ // prevent wiping initialized pool
98
+ if (!pairs[i]?.pool) {
99
+ pairs[i] = cachedPair;
100
+ this.pairs[pairKeys[i]] = cachedPair;
101
+ }
102
+ return false;
103
+ }
104
+ return true;
105
+ });
106
+ if (!shouldFetchFromRpc)
107
+ return pairs;
108
+ const calldata = stableValues.map(stable => {
109
+ return {
110
+ target: this.factoryAddress,
111
+ callData: this.factory.methods
112
+ .getPair(token0.address, token1.address, stable)
113
+ .encodeABI(),
114
+ };
115
+ });
116
+ const data = await this.dexHelper.multiContract.methods.aggregate(calldata).call({});
117
+ const exchanges = data.returnData.map(decoders_1.addressDecode);
118
+ // cache and return
119
+ stableValues.forEach((stable, i) => {
120
+ // prevent wiping initialized pool
121
+ if (pairs[i]?.pool) {
122
+ return;
123
+ }
124
+ const exchange = exchanges[i];
125
+ if (exchange === constants_1.NULL_ADDRESS) {
126
+ pairs[i] = {
127
+ token0,
128
+ token1,
129
+ stable,
130
+ checkExistenceAfter: Date.now() + INFUSION_RECHECK_PAIR_EXISTENCE_AFTER_MS,
131
+ };
132
+ }
133
+ else {
134
+ pairs[i] = { token0, token1, stable, exchange };
135
+ }
136
+ this.pairs[pairKeys[i]] = pairs[i];
137
+ });
138
+ const pairsToCache = pairKeys
139
+ .map((key, i) => [key, pairs[i]])
140
+ .filter(([_, pair]) => !pair.pool);
141
+ await this.dexHelper.cache.hmset(this.pairsHashCacheKey, Object.fromEntries(pairsToCache.map(([key, pair]) => [key, JSON.stringify(pair)])));
142
+ return pairs;
143
+ }
144
+ async batchCatchUpPairs(pairs, blockNumber) {
145
+ if (!blockNumber)
146
+ return;
147
+ const pairsToFetch = [];
148
+ for (const _pair of pairs) {
149
+ const infusionPairs = await this.findInfusionPairs(_pair[0], _pair[1]);
150
+ for (const pair of infusionPairs) {
151
+ if (!(pair && pair.exchange))
152
+ continue;
153
+ if (!pair.pool) {
154
+ pairsToFetch.push(pair);
155
+ }
156
+ else if (!pair.pool.getState(blockNumber)) {
157
+ pairsToFetch.push(pair);
158
+ }
159
+ }
160
+ }
161
+ if (!pairsToFetch.length)
162
+ return;
163
+ const reserves = await this.getManyPoolReserves(pairsToFetch, blockNumber);
164
+ if (reserves.length !== pairsToFetch.length) {
165
+ this.logger.error(`Error_getManyPoolReserves didn't get any pool reserves`);
166
+ }
167
+ for (let i = 0; i < pairsToFetch.length; i++) {
168
+ const pairState = reserves[i];
169
+ const pair = pairsToFetch[i];
170
+ if (!pair.pool) {
171
+ await this.addPool(pair, pairState.reserves0, pairState.reserves1, pairState.feeCode, blockNumber);
172
+ }
173
+ else
174
+ pair.pool.setState(pairState, blockNumber);
175
+ }
176
+ }
177
+ async getManyPoolReserves(pairs, blockNumber) {
178
+ try {
179
+ const multiCallFeeData = pairs.map(pair => this.getFeesMultiCallData(pair));
180
+ const calldata = pairs
181
+ .map((pair, i) => {
182
+ let calldata = [
183
+ {
184
+ target: pair.token0.address,
185
+ callData: erc20Iface.encodeFunctionData('balanceOf', [
186
+ pair.exchange,
187
+ ]),
188
+ },
189
+ {
190
+ target: pair.token1.address,
191
+ callData: erc20Iface.encodeFunctionData('balanceOf', [
192
+ pair.exchange,
193
+ ]),
194
+ },
195
+ ];
196
+ if (this.isDynamicFees)
197
+ calldata.push(multiCallFeeData[i].callEntry);
198
+ return calldata;
199
+ })
200
+ .flat();
201
+ const data = await this.dexHelper.multiContract.methods
202
+ .aggregate(calldata)
203
+ .call({}, blockNumber);
204
+ const returnData = lodash_1.default.chunk(data.returnData, this.isDynamicFees ? 3 : 2);
205
+ return pairs.map((pair, i) => ({
206
+ reserves0: defaultAbiCoder
207
+ .decode(['uint256'], returnData[i][0])[0]
208
+ .toString(),
209
+ reserves1: defaultAbiCoder
210
+ .decode(['uint256'], returnData[i][1])[0]
211
+ .toString(),
212
+ feeCode: this.isDynamicFees
213
+ ? multiCallFeeData[i].callDecoder(returnData[i][2])
214
+ : (pair.stable ? this.stableFee : this.volatileFee) || this.feeCode,
215
+ }));
216
+ }
217
+ catch (e) {
218
+ this.logger.error(`Error_getManyPoolReserves could not get reserves with error:`, e);
219
+ return [];
220
+ }
221
+ }
222
+ getSellPrice(priceParams, srcAmount) {
223
+ return priceParams.stable
224
+ ? infusion_stable_pool_1.InfusionStablePool.getSellPrice(priceParams, srcAmount, this.feeFactor)
225
+ : uniswap_v2_constant_product_pool_1.Uniswapv2ConstantProductPool.getSellPrice(priceParams, srcAmount, this.feeFactor);
226
+ }
227
+ async getPricesVolume(_from, _to, amounts, side, blockNumber,
228
+ // list of pool identifiers to use for pricing, if undefined use all pools
229
+ limitPools, transferFees = {
230
+ srcFee: 0,
231
+ destFee: 0,
232
+ srcDexFee: 0,
233
+ destDexFee: 0,
234
+ }) {
235
+ try {
236
+ if (side === core_1.SwapSide.BUY)
237
+ return null; // Buy side not implemented yet
238
+ const from = this.dexHelper.config.wrapETH(_from);
239
+ const to = this.dexHelper.config.wrapETH(_to);
240
+ if (from.address.toLowerCase() === to.address.toLowerCase()) {
241
+ return null;
242
+ }
243
+ const tokenAddress = [
244
+ from.address.toLowerCase(),
245
+ to.address.toLowerCase(),
246
+ ]
247
+ .sort((a, b) => (a > b ? 1 : -1))
248
+ .join('_');
249
+ await this.batchCatchUpPairs([[from, to]], blockNumber);
250
+ const pairParams = await this.getInfusionPairOrderedParams(from, to, blockNumber, transferFees.srcDexFee);
251
+ const resultPools = pairParams.map(pairParam => {
252
+ if (!pairParam)
253
+ return null;
254
+ const stable = pairParam.stable;
255
+ // We don't support fee on transfer for stable pools yet
256
+ if (stable &&
257
+ (transferFees.srcFee !== 0 || transferFees.srcDexFee !== 0)) {
258
+ return null;
259
+ }
260
+ const poolIdentifier = `${this.dexKey}_${tokenAddress}` + this.poolPostfix(stable);
261
+ if (limitPools && limitPools.every(p => p !== poolIdentifier))
262
+ return null;
263
+ const isSell = side === core_1.SwapSide.SELL;
264
+ const unitAmount = (0, utils_1.getBigIntPow)(from.decimals);
265
+ const [unitVolumeWithFee, ...amountsWithFee] = (0, token_transfer_fee_1.applyTransferFee)([unitAmount, ...amounts], side, isSell ? transferFees.srcFee : transferFees.destFee, isSell ? constants_1.SRC_TOKEN_PARASWAP_TRANSFERS : constants_1.DEST_TOKEN_PARASWAP_TRANSFERS);
266
+ const unit = this.getSellPricePath(unitVolumeWithFee, [pairParam]);
267
+ const prices = amountsWithFee.map(amount => amount === 0n ? 0n : this.getSellPricePath(amount, [pairParam]));
268
+ const [unitOutWithFee, ...outputsWithFee] = (0, token_transfer_fee_1.applyTransferFee)([unit, ...prices], side,
269
+ // This part is confusing, because we treat differently SELL and BUY fees
270
+ // If Buy, we should apply transfer fee on srcToken on top of dexFee applied earlier
271
+ // But for Sell we should apply only one dexFee
272
+ isSell ? transferFees.destDexFee : transferFees.srcFee, isSell ? this.DEST_TOKEN_DEX_TRANSFERS : constants_1.SRC_TOKEN_PARASWAP_TRANSFERS);
273
+ return {
274
+ prices: outputsWithFee,
275
+ unit: unitOutWithFee,
276
+ data: {
277
+ router: this.router,
278
+ path: [from.address.toLowerCase(), to.address.toLowerCase()],
279
+ factory: this.factoryAddress,
280
+ initCode: this.initCode,
281
+ feeFactor: this.feeFactor,
282
+ isFeeTokenInRoute: Object.values(transferFees).some(f => f !== 0),
283
+ pools: [
284
+ {
285
+ address: pairParam.exchange,
286
+ fee: parseInt(pairParam.fee),
287
+ direction: pairParam.direction,
288
+ },
289
+ ],
290
+ },
291
+ exchange: this.dexKey,
292
+ poolIdentifiers: [poolIdentifier],
293
+ gasCost: this.poolGasCost,
294
+ poolAddresses: [pairParam.exchange],
295
+ };
296
+ });
297
+ const resultPoolsFiltered = resultPools.filter(item => !!item); // filter null elements
298
+ return resultPoolsFiltered.length > 0 ? resultPoolsFiltered : null;
299
+ }
300
+ catch (e) {
301
+ if (blockNumber === 0)
302
+ this.logger.error(`Error_getPricesVolume: Aurelius block manager not yet instantiated`);
303
+ this.logger.error(`Error_getPrices:`, e);
304
+ return null;
305
+ }
306
+ }
307
+ async getTopPoolsForToken(tokenAddress, count) {
308
+ if (!this.subgraphURL)
309
+ return [];
310
+ let stableFieldKey = 'isStable';
311
+ const query = `query ($token: Bytes!, $count: Int) {
312
+ pools0: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token0: $token, reserve0_gt: 1, reserve1_gt: 1}) {
313
+ id
314
+ ${stableFieldKey}
315
+ token0 {
316
+ id
317
+ decimals
318
+ }
319
+ token1 {
320
+ id
321
+ decimals
322
+ }
323
+ reserveUSD
324
+ }
325
+ pools1: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token1: $token, reserve0_gt: 1, reserve1_gt: 1}) {
326
+ id
327
+ ${stableFieldKey}
328
+ token0 {
329
+ id
330
+ decimals
331
+ }
332
+ token1 {
333
+ id
334
+ decimals
335
+ }
336
+ reserveUSD
337
+ }
338
+ }`;
339
+ const { data } = await this.dexHelper.httpRequest.post(this.subgraphURL, {
340
+ query,
341
+ variables: { token: tokenAddress.toLowerCase(), count },
342
+ }, constants_1.SUBGRAPH_TIMEOUT);
343
+ if (!(data && data.pools0 && data.pools1))
344
+ throw new Error("Couldn't fetch the pools from the subgraph");
345
+ const pools0 = lodash_1.default.map(data.pools0, pool => ({
346
+ exchange: this.dexKey,
347
+ stable: pool[stableFieldKey],
348
+ address: pool.id.toLowerCase(),
349
+ connectorTokens: [
350
+ {
351
+ address: pool.token1.id.toLowerCase(),
352
+ decimals: parseInt(pool.token1.decimals),
353
+ },
354
+ ],
355
+ liquidityUSD: parseFloat(pool.reserveUSD),
356
+ }));
357
+ const pools1 = lodash_1.default.map(data.pools1, pool => ({
358
+ exchange: this.dexKey,
359
+ stable: pool[stableFieldKey],
360
+ address: pool.id.toLowerCase(),
361
+ connectorTokens: [
362
+ {
363
+ address: pool.token0.id.toLowerCase(),
364
+ decimals: parseInt(pool.token0.decimals),
365
+ },
366
+ ],
367
+ liquidityUSD: parseFloat(pool.reserveUSD),
368
+ }));
369
+ return lodash_1.default.slice(lodash_1.default.sortBy(lodash_1.default.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]), 0, count);
370
+ }
371
+ // Same as at uniswap-v2-pool.json, but extended with decimals and stable
372
+ async getInfusionPairOrderedParams(from, to, blockNumber, tokenDexTransferFee) {
373
+ const pairs = await this.findInfusionPairs(from, to);
374
+ return pairs.map(pair => {
375
+ if (!(pair && pair.pool && pair.exchange))
376
+ return null;
377
+ const pairState = pair.pool.getState(blockNumber);
378
+ if (!pairState) {
379
+ this.logger.error(`Error_orderPairParams expected reserves, got none (maybe the pool doesn't exist) ${from.symbol || from.address} ${to.symbol || to.address}`);
380
+ return null;
381
+ }
382
+ const fee = (pairState.feeCode + tokenDexTransferFee).toString();
383
+ const pairReversed = pair.token1.address.toLowerCase() === from.address.toLowerCase();
384
+ if (pairReversed) {
385
+ return {
386
+ tokenIn: from.address,
387
+ tokenOut: to.address,
388
+ reservesIn: pairState.reserves1,
389
+ reservesOut: pairState.reserves0,
390
+ fee,
391
+ direction: false,
392
+ exchange: pair.exchange,
393
+ decimalsIn: from.decimals,
394
+ decimalsOut: to.decimals,
395
+ stable: pair.stable,
396
+ };
397
+ }
398
+ return {
399
+ tokenIn: from.address,
400
+ tokenOut: to.address,
401
+ reservesIn: pairState.reserves0,
402
+ reservesOut: pairState.reserves1,
403
+ fee,
404
+ direction: true,
405
+ exchange: pair.exchange,
406
+ decimalsIn: from.decimals,
407
+ decimalsOut: to.decimals,
408
+ stable: pair.stable,
409
+ };
410
+ });
411
+ }
412
+ async getPoolIdentifiers(_from, _to, side, blockNumber) {
413
+ if (side === core_1.SwapSide.BUY)
414
+ return [];
415
+ const from = this.dexHelper.config.wrapETH(_from);
416
+ const to = this.dexHelper.config.wrapETH(_to);
417
+ if (from.address.toLowerCase() === to.address.toLowerCase()) {
418
+ return [];
419
+ }
420
+ const tokenAddress = [from.address.toLowerCase(), to.address.toLowerCase()]
421
+ .sort((a, b) => (a > b ? 1 : -1))
422
+ .join('_');
423
+ const poolIdentifier = `${this.dexKey}_${tokenAddress}`;
424
+ const poolIdentifierUniswap = poolIdentifier + this.poolPostfix(false);
425
+ const poolIdentifierStable = poolIdentifier + this.poolPostfix(true);
426
+ return [poolIdentifierUniswap, poolIdentifierStable];
427
+ }
428
+ poolPostfix(stable) {
429
+ return stable ? 'S' : 'V';
430
+ }
431
+ getAdapters(side) {
432
+ return null;
433
+ }
434
+ getAdapterParam(srcToken, destToken, srcAmount, toAmount, // required for buy case
435
+ data, side) {
436
+ return {
437
+ targetExchange: data.router,
438
+ payload: '',
439
+ networkFee: '0',
440
+ };
441
+ }
442
+ getDexParam(src, dest, srcAmount, destAmount, recipient, data, side) {
443
+ if (side === core_1.SwapSide.BUY)
444
+ throw new Error(`Buy not supported`);
445
+ let routerMethod;
446
+ let routerArgs;
447
+ const stable = (0, isStablePair_1.isStablePair)(this.network, src, dest);
448
+ const from = (0, utils_1.isETHAddress)(src)
449
+ ? this.dexHelper.config.data.wrappedNativeTokenAddress
450
+ : src;
451
+ const to = (0, utils_1.isETHAddress)(dest)
452
+ ? this.dexHelper.config.data.wrappedNativeTokenAddress
453
+ : dest;
454
+ routerMethod = (0, utils_1.isETHAddress)(src)
455
+ ? InfusionRouterFunctions.sellExactEth
456
+ : InfusionRouterFunctions.swapExactIn;
457
+ routerMethod = (0, utils_1.isETHAddress)(dest)
458
+ ? InfusionRouterFunctions.sellExactToken
459
+ : routerMethod;
460
+ routerArgs = (0, utils_1.isETHAddress)(src)
461
+ ? [
462
+ destAmount,
463
+ [{ from, to, stable }],
464
+ recipient,
465
+ Math.floor(new Date().getTime() / 1000) + 120,
466
+ ]
467
+ : [
468
+ srcAmount,
469
+ destAmount,
470
+ [{ from, to, stable }],
471
+ recipient,
472
+ Math.floor(new Date().getTime() / 1000) + 120,
473
+ ];
474
+ const exchangeData = new abi_1.Interface(InfusionRouter_json_1.default).encodeFunctionData(routerMethod, routerArgs);
475
+ return {
476
+ needWrapNative: this.needWrapNative,
477
+ dexFuncHasRecipient: true,
478
+ exchangeData,
479
+ targetExchange: data.router,
480
+ returnAmountPos: undefined,
481
+ };
482
+ }
483
+ getFeesMultiCallData(pair) {
484
+ const callEntry = {
485
+ target: this.factoryAddress,
486
+ callData: velodromeFactoryIface.encodeFunctionData('getFee', [
487
+ pair.stable,
488
+ ]),
489
+ };
490
+ const callDecoder = (values) => parseInt(velodromeFactoryIface
491
+ .decodeFunctionResult('getFee', values)[0]
492
+ .toString());
493
+ return {
494
+ callEntry,
495
+ callDecoder,
496
+ };
497
+ }
498
+ }
499
+ exports.Infusion = Infusion;
500
+ //# sourceMappingURL=infusion.js.map