@paraswap/dex-lib 3.8.22 → 3.8.23-remove-logs-oswap

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 (375) hide show
  1. package/.vscode/launch.json +16 -0
  2. package/.vscode/settings.json +3 -0
  3. package/build/abi/AaveV1_lending_pool.json +27 -0
  4. package/build/abi/Uncompressor.json +250 -0
  5. package/build/abi/infusion/InfusionFactory.json +147 -0
  6. package/build/abi/infusion/InfusionPair.json +658 -0
  7. package/build/abi/infusion/InfusionRouter.json +442 -0
  8. package/build/abi/integral/factory.json +333 -0
  9. package/build/abi/integral/oracle.json +501 -0
  10. package/build/abi/integral/pool.json +1041 -0
  11. package/build/abi/integral/relayer.json +1536 -0
  12. package/build/abi/oswap/oswap.abi.json +452 -0
  13. package/build/abi/platypus/asset.json +490 -0
  14. package/build/abi/platypus/avax-pool.json +820 -0
  15. package/build/abi/platypus/oracle.json +119 -0
  16. package/build/abi/platypus/pool.json +677 -0
  17. package/build/abi/smardex/all/smardex-router.json +648 -0
  18. package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
  19. package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
  20. package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
  21. package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
  22. package/build/abi/swaap-v1/pool.json +1346 -0
  23. package/build/dex/aave-v1/aave-v1.d.ts +33 -0
  24. package/build/dex/aave-v1/aave-v1.js +158 -0
  25. package/build/dex/aave-v1/aave-v1.js.map +1 -0
  26. package/build/dex/aave-v1/config.d.ts +11 -0
  27. package/build/dex/aave-v1/config.js +20 -0
  28. package/build/dex/aave-v1/config.js.map +1 -0
  29. package/build/dex/aave-v1/tokens-mainnet.json +134 -0
  30. package/build/dex/aave-v1/tokens.d.ts +3 -0
  31. package/build/dex/aave-v1/tokens.js +50 -0
  32. package/build/dex/aave-v1/tokens.js.map +1 -0
  33. package/build/dex/aave-v1/types.d.ts +12 -0
  34. package/build/dex/aave-v1/types.js +3 -0
  35. package/build/dex/aave-v1/types.js.map +1 -0
  36. package/build/dex/bProtocol.d.ts +18 -0
  37. package/build/dex/bProtocol.js +39 -0
  38. package/build/dex/bProtocol.js.map +1 -0
  39. package/build/dex/bancor.d.ts +26 -0
  40. package/build/dex/bancor.js +58 -0
  41. package/build/dex/bancor.js.map +1 -0
  42. package/build/dex/compound.d.ts +18 -0
  43. package/build/dex/compound.js +46 -0
  44. package/build/dex/compound.js.map +1 -0
  45. package/build/dex/curve-v2.d.ts +58 -0
  46. package/build/dex/curve-v2.js +180 -0
  47. package/build/dex/curve-v2.js.map +1 -0
  48. package/build/dex/dodo-v1.d.ts +33 -0
  49. package/build/dex/dodo-v1.js +63 -0
  50. package/build/dex/dodo-v1.js.map +1 -0
  51. package/build/dex/etherfi/etherfi.d.ts +26 -0
  52. package/build/dex/etherfi/etherfi.js +96 -0
  53. package/build/dex/etherfi/etherfi.js.map +1 -0
  54. package/build/dex/generic-rfq/rate-fetcher.js +1 -1
  55. package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
  56. package/build/dex/index.js +4 -0
  57. package/build/dex/index.js.map +1 -1
  58. package/build/dex/infusion/config.d.ts +3 -0
  59. package/build/dex/infusion/config.js +20 -0
  60. package/build/dex/infusion/config.js.map +1 -0
  61. package/build/dex/infusion/infusion-stable-pool.d.ts +4 -0
  62. package/build/dex/infusion/infusion-stable-pool.js +74 -0
  63. package/build/dex/infusion/infusion-stable-pool.js.map +1 -0
  64. package/build/dex/infusion/infusion.d.ts +51 -0
  65. package/build/dex/infusion/infusion.js +457 -0
  66. package/build/dex/infusion/infusion.js.map +1 -0
  67. package/build/dex/infusion/types.d.ts +45 -0
  68. package/build/dex/infusion/types.js +3 -0
  69. package/build/dex/infusion/types.js.map +1 -0
  70. package/build/dex/infusion/utils/isStablePair.d.ts +2 -0
  71. package/build/dex/infusion/utils/isStablePair.js +18 -0
  72. package/build/dex/infusion/utils/isStablePair.js.map +1 -0
  73. package/build/dex/integral/config.d.ts +4 -0
  74. package/build/dex/integral/config.js +20 -0
  75. package/build/dex/integral/config.js.map +1 -0
  76. package/build/dex/integral/context.d.ts +40 -0
  77. package/build/dex/integral/context.js +158 -0
  78. package/build/dex/integral/context.js.map +1 -0
  79. package/build/dex/integral/helpers.d.ts +17 -0
  80. package/build/dex/integral/helpers.js +157 -0
  81. package/build/dex/integral/helpers.js.map +1 -0
  82. package/build/dex/integral/integral-factory.d.ts +24 -0
  83. package/build/dex/integral/integral-factory.js +95 -0
  84. package/build/dex/integral/integral-factory.js.map +1 -0
  85. package/build/dex/integral/integral-pool.d.ts +50 -0
  86. package/build/dex/integral/integral-pool.js +149 -0
  87. package/build/dex/integral/integral-pool.js.map +1 -0
  88. package/build/dex/integral/integral-pricing.d.ts +18 -0
  89. package/build/dex/integral/integral-pricing.js +114 -0
  90. package/build/dex/integral/integral-pricing.js.map +1 -0
  91. package/build/dex/integral/integral-relayer.d.ts +42 -0
  92. package/build/dex/integral/integral-relayer.js +192 -0
  93. package/build/dex/integral/integral-relayer.js.map +1 -0
  94. package/build/dex/integral/integral-token.d.ts +27 -0
  95. package/build/dex/integral/integral-token.js +59 -0
  96. package/build/dex/integral/integral-token.js.map +1 -0
  97. package/build/dex/integral/integral.d.ts +41 -0
  98. package/build/dex/integral/integral.js +376 -0
  99. package/build/dex/integral/integral.js.map +1 -0
  100. package/build/dex/integral/types.d.ts +85 -0
  101. package/build/dex/integral/types.js +9 -0
  102. package/build/dex/integral/types.js.map +1 -0
  103. package/build/dex/integral/utils-e2e.d.ts +9 -0
  104. package/build/dex/integral/utils-e2e.js +131 -0
  105. package/build/dex/integral/utils-e2e.js.map +1 -0
  106. package/build/dex/integral/utils.d.ts +17 -0
  107. package/build/dex/integral/utils.js +94 -0
  108. package/build/dex/integral/utils.js.map +1 -0
  109. package/build/dex/lido.d.ts +19 -0
  110. package/build/dex/lido.js +42 -0
  111. package/build/dex/lido.js.map +1 -0
  112. package/build/dex/lite-psm/lite-psm.js +2 -5
  113. package/build/dex/lite-psm/lite-psm.js.map +1 -1
  114. package/build/dex/maker-psm/maker-psm.js +2 -6
  115. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  116. package/build/dex/maverick-v2/config.js +4 -0
  117. package/build/dex/maverick-v2/config.js.map +1 -1
  118. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js +4 -0
  119. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js.map +1 -1
  120. package/build/dex/maverick-v2/maverick-v2-pool.d.ts +1 -1
  121. package/build/dex/maverick-v2/maverick-v2-pool.js +8 -8
  122. package/build/dex/maverick-v2/maverick-v2-pool.js.map +1 -1
  123. package/build/dex/maverick-v2/maverick-v2.d.ts +5 -4
  124. package/build/dex/maverick-v2/maverick-v2.js +73 -63
  125. package/build/dex/maverick-v2/maverick-v2.js.map +1 -1
  126. package/build/dex/maverick-v2/types.d.ts +4 -0
  127. package/build/dex/onebit.d.ts +25 -0
  128. package/build/dex/onebit.js +42 -0
  129. package/build/dex/onebit.js.map +1 -0
  130. package/build/dex/oswap/config.d.ts +5 -0
  131. package/build/dex/oswap/config.js +31 -0
  132. package/build/dex/oswap/config.js.map +1 -0
  133. package/build/dex/oswap/oswap-pool.d.ts +51 -0
  134. package/build/dex/oswap/oswap-pool.js +150 -0
  135. package/build/dex/oswap/oswap-pool.js.map +1 -0
  136. package/build/dex/oswap/oswap.d.ts +46 -0
  137. package/build/dex/oswap/oswap.js +273 -0
  138. package/build/dex/oswap/oswap.js.map +1 -0
  139. package/build/dex/oswap/types.d.ts +20 -0
  140. package/build/dex/oswap/types.js +3 -0
  141. package/build/dex/oswap/types.js.map +1 -0
  142. package/build/dex/platypus/asset.d.ts +14 -0
  143. package/build/dex/platypus/asset.js +97 -0
  144. package/build/dex/platypus/asset.js.map +1 -0
  145. package/build/dex/platypus/config.d.ts +11 -0
  146. package/build/dex/platypus/config.js +69 -0
  147. package/build/dex/platypus/config.js.map +1 -0
  148. package/build/dex/platypus/platypus.d.ts +62 -0
  149. package/build/dex/platypus/platypus.js +442 -0
  150. package/build/dex/platypus/platypus.js.map +1 -0
  151. package/build/dex/platypus/pool-avax.d.ts +8 -0
  152. package/build/dex/platypus/pool-avax.js +54 -0
  153. package/build/dex/platypus/pool-avax.js.map +1 -0
  154. package/build/dex/platypus/pool-base.d.ts +19 -0
  155. package/build/dex/platypus/pool-base.js +86 -0
  156. package/build/dex/platypus/pool-base.js.map +1 -0
  157. package/build/dex/platypus/pool-pure.d.ts +8 -0
  158. package/build/dex/platypus/pool-pure.js +37 -0
  159. package/build/dex/platypus/pool-pure.js.map +1 -0
  160. package/build/dex/platypus/pool-subscriber.d.ts +14 -0
  161. package/build/dex/platypus/pool-subscriber.js +167 -0
  162. package/build/dex/platypus/pool-subscriber.js.map +1 -0
  163. package/build/dex/platypus/pool.d.ts +8 -0
  164. package/build/dex/platypus/pool.js +58 -0
  165. package/build/dex/platypus/pool.js.map +1 -0
  166. package/build/dex/platypus/types.d.ts +92 -0
  167. package/build/dex/platypus/types.js +10 -0
  168. package/build/dex/platypus/types.js.map +1 -0
  169. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  170. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  171. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  172. package/build/dex/sdai/config.d.ts +11 -0
  173. package/build/dex/sdai/config.js +21 -0
  174. package/build/dex/sdai/config.js.map +1 -0
  175. package/build/dex/sdai/constants.d.ts +2 -0
  176. package/build/dex/sdai/constants.js +6 -0
  177. package/build/dex/sdai/constants.js.map +1 -0
  178. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  179. package/build/dex/sdai/scripts/validate-state.js +102 -0
  180. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  181. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  182. package/build/dex/sdai/sdai-pool.js +85 -0
  183. package/build/dex/sdai/sdai-pool.js.map +1 -0
  184. package/build/dex/sdai/sdai.d.ts +51 -0
  185. package/build/dex/sdai/sdai.js +172 -0
  186. package/build/dex/sdai/sdai.js.map +1 -0
  187. package/build/dex/sdai/types.d.ts +21 -0
  188. package/build/dex/sdai/types.js +11 -0
  189. package/build/dex/sdai/types.js.map +1 -0
  190. package/build/dex/sdai/utils.d.ts +4 -0
  191. package/build/dex/sdai/utils.js +39 -0
  192. package/build/dex/sdai/utils.js.map +1 -0
  193. package/build/dex/smardex/config.d.ts +4 -0
  194. package/build/dex/smardex/config.js +64 -0
  195. package/build/dex/smardex/config.js.map +1 -0
  196. package/build/dex/smardex/constants.d.ts +18 -0
  197. package/build/dex/smardex/constants.js +33 -0
  198. package/build/dex/smardex/constants.js.map +1 -0
  199. package/build/dex/smardex/sdk/constants.d.ts +6 -0
  200. package/build/dex/smardex/sdk/constants.js +13 -0
  201. package/build/dex/smardex/sdk/constants.js.map +1 -0
  202. package/build/dex/smardex/sdk/core.d.ts +113 -0
  203. package/build/dex/smardex/sdk/core.js +499 -0
  204. package/build/dex/smardex/sdk/core.js.map +1 -0
  205. package/build/dex/smardex/sdk/errors.d.ts +15 -0
  206. package/build/dex/smardex/sdk/errors.js +22 -0
  207. package/build/dex/smardex/sdk/errors.js.map +1 -0
  208. package/build/dex/smardex/sdk/types.d.ts +62 -0
  209. package/build/dex/smardex/sdk/types.js +3 -0
  210. package/build/dex/smardex/sdk/types.js.map +1 -0
  211. package/build/dex/smardex/sdk/utils.d.ts +44 -0
  212. package/build/dex/smardex/sdk/utils.js +133 -0
  213. package/build/dex/smardex/sdk/utils.js.map +1 -0
  214. package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
  215. package/build/dex/smardex/smardex-event-pool.js +119 -0
  216. package/build/dex/smardex/smardex-event-pool.js.map +1 -0
  217. package/build/dex/smardex/smardex.d.ts +65 -0
  218. package/build/dex/smardex/smardex.js +519 -0
  219. package/build/dex/smardex/smardex.js.map +1 -0
  220. package/build/dex/smardex/types.d.ts +55 -0
  221. package/build/dex/smardex/types.js +3 -0
  222. package/build/dex/smardex/types.js.map +1 -0
  223. package/build/dex/smoothy.d.ts +26 -0
  224. package/build/dex/smoothy.js +48 -0
  225. package/build/dex/smoothy.js.map +1 -0
  226. package/build/dex/solidly/forks-override/cone.d.ts +22 -0
  227. package/build/dex/solidly/forks-override/cone.js +53 -0
  228. package/build/dex/solidly/forks-override/cone.js.map +1 -0
  229. package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
  230. package/build/dex/solidly/forks-override/solisnek.js +15 -0
  231. package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
  232. package/build/dex/stable-pool.d.ts +28 -0
  233. package/build/dex/stable-pool.js +62 -0
  234. package/build/dex/stable-pool.js.map +1 -0
  235. package/build/dex/swaap-v1/config.d.ts +17 -0
  236. package/build/dex/swaap-v1/config.js +56 -0
  237. package/build/dex/swaap-v1/config.js.map +1 -0
  238. package/build/dex/swaap-v1/constants.d.ts +6 -0
  239. package/build/dex/swaap-v1/constants.js +17 -0
  240. package/build/dex/swaap-v1/constants.js.map +1 -0
  241. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
  242. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
  243. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
  244. package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
  245. package/build/dex/swaap-v1/libraries/Const.js +26 -0
  246. package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
  247. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
  248. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
  249. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
  250. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
  251. package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
  252. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
  253. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
  254. package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
  255. package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
  256. package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
  257. package/build/dex/swaap-v1/libraries/Num.js +167 -0
  258. package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
  259. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
  260. package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
  261. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
  262. package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
  263. package/build/dex/swaap-v1/libraries/Struct.js +3 -0
  264. package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
  265. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
  266. package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
  267. package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
  268. package/build/dex/swaap-v1/swaap-v1.d.ts +61 -0
  269. package/build/dex/swaap-v1/swaap-v1.js +369 -0
  270. package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
  271. package/build/dex/swaap-v1/types.d.ts +106 -0
  272. package/build/dex/swaap-v1/types.js +9 -0
  273. package/build/dex/swaap-v1/types.js.map +1 -0
  274. package/build/dex/trader-joe-v2.1/optimizer.js +1 -4
  275. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -1
  276. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  277. package/build/dex/trader-joe-v2.1.js +79 -0
  278. package/build/dex/trader-joe-v2.1.js.map +1 -0
  279. package/build/executor/compressor/Compressor.d.ts +23 -0
  280. package/build/executor/compressor/Compressor.js +144 -0
  281. package/build/executor/compressor/Compressor.js.map +1 -0
  282. package/build/executor/compressor/compress.d.ts +17 -0
  283. package/build/executor/compressor/compress.js +187 -0
  284. package/build/executor/compressor/compress.js.map +1 -0
  285. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
  286. package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
  287. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
  288. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
  289. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
  290. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
  291. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
  292. package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
  293. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
  294. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
  295. package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
  296. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
  297. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
  298. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
  299. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
  300. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
  301. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
  302. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
  303. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
  304. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
  305. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
  306. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
  307. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
  308. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
  309. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  310. package/build/executor/compressor/fetchSaved.js +17 -0
  311. package/build/executor/compressor/fetchSaved.js.map +1 -0
  312. package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
  313. package/build/executor/compressor/utils/computeCostL2.js +14 -0
  314. package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
  315. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
  316. package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
  317. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
  318. package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
  319. package/build/executor/compressor/utils/getAllIndexes.js +12 -0
  320. package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
  321. package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
  322. package/build/executor/compressor/utils/getByteForAddress.js +14 -0
  323. package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
  324. package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
  325. package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
  326. package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
  327. package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
  328. package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
  329. package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
  330. package/build/executor/compressor/utils/intToByte.d.ts +2 -0
  331. package/build/executor/compressor/utils/intToByte.js +10 -0
  332. package/build/executor/compressor/utils/intToByte.js.map +1 -0
  333. package/package.json +1 -1
  334. package/src/abi/infusion/InfusionFactory.json +147 -0
  335. package/src/abi/infusion/InfusionPair.json +658 -0
  336. package/src/abi/infusion/InfusionRouter.json +442 -0
  337. package/src/abi/maverick-v2/MaverickV2Router.json +778 -0
  338. package/src/abi/oswap/oswap.abi.json +452 -0
  339. package/src/dex/generic-rfq/rate-fetcher.ts +6 -5
  340. package/src/dex/index.ts +4 -0
  341. package/src/dex/infusion/config.ts +21 -0
  342. package/src/dex/infusion/infusion-e2e.test.ts +110 -0
  343. package/src/dex/infusion/infusion-integration.test.ts +232 -0
  344. package/src/dex/infusion/infusion-stable-pool.ts +91 -0
  345. package/src/dex/infusion/infusion.ts +652 -0
  346. package/src/dex/infusion/types.ts +60 -0
  347. package/src/dex/infusion/utils/isStablePair.ts +18 -0
  348. package/src/dex/lite-psm/lite-psm.ts +2 -5
  349. package/src/dex/maker-psm/maker-psm.ts +2 -6
  350. package/src/dex/maverick-v2/config.ts +4 -0
  351. package/src/dex/maverick-v2/maverick-math/maverick-pool-math.ts +5 -0
  352. package/src/dex/maverick-v2/maverick-v2-e2e.test.ts +21 -43
  353. package/src/dex/maverick-v2/maverick-v2-integration.test.ts +100 -96
  354. package/src/dex/maverick-v2/maverick-v2-pool.ts +8 -8
  355. package/src/dex/maverick-v2/maverick-v2.ts +111 -81
  356. package/src/dex/maverick-v2/types.ts +4 -0
  357. package/src/dex/oswap/config.ts +32 -0
  358. package/src/dex/oswap/oswap-e2e.test.ts +91 -0
  359. package/src/dex/oswap/oswap-events.test.ts +88 -0
  360. package/src/dex/oswap/oswap-integration.test.ts +291 -0
  361. package/src/dex/oswap/oswap-pool.ts +190 -0
  362. package/src/dex/oswap/oswap.ts +392 -0
  363. package/src/dex/oswap/types.ts +29 -0
  364. package/tests/constants-e2e.ts +10 -1
  365. package/.idea/aws.xml +0 -17
  366. package/.idea/codeStyles/Project.xml +0 -19
  367. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  368. package/.idea/misc.xml +0 -6
  369. package/.idea/modules.xml +0 -8
  370. package/.idea/paraswap-dex-lib.iml +0 -9
  371. package/.idea/prettier.xml +0 -7
  372. package/.idea/vcs.xml +0 -6
  373. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
  374. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
  375. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
@@ -0,0 +1,150 @@
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.OSwapEventPool = void 0;
7
+ const abi_1 = require("@ethersproject/abi");
8
+ const utils_1 = require("../../utils");
9
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
+ const decoders_1 = require("../../lib/decoders");
11
+ const oswap_abi_json_1 = __importDefault(require("../../abi/oswap/oswap.abi.json"));
12
+ const ERC20_abi_json_1 = __importDefault(require("../../abi/ERC20.abi.json"));
13
+ class OSwapEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
14
+ constructor(parentName, pool, network, dexHelper, logger, iOSwap = new abi_1.Interface(oswap_abi_json_1.default), iERC20 = new abi_1.Interface(ERC20_abi_json_1.default)) {
15
+ super(parentName, pool.id, dexHelper, logger);
16
+ this.parentName = parentName;
17
+ this.pool = pool;
18
+ this.network = network;
19
+ this.dexHelper = dexHelper;
20
+ this.iOSwap = iOSwap;
21
+ this.iERC20 = iERC20;
22
+ this.handlers = {};
23
+ this.logDecoder = (log) => this.parseLog(log);
24
+ this.addressesSubscribed = [pool.address, pool.token0, pool.token1];
25
+ this.handlers['TraderateChanged'] = this.handleTraderateChanged.bind(this);
26
+ this.handlers['Transfer'] = this.handleTransfer.bind(this);
27
+ }
28
+ parseLog(log) {
29
+ if (log.address.toLowerCase() === this.pool.address) {
30
+ return this.iOSwap.parseLog(log);
31
+ }
32
+ return this.iERC20.parseLog(log);
33
+ }
34
+ /**
35
+ * The function is called every time any of the subscribed
36
+ * addresses release log. The function accepts the current
37
+ * state, updates the state according to the log, and returns
38
+ * the updated state.
39
+ * @param state - Current state of event subscriber
40
+ * @param log - Log released by one of the subscribed addresses
41
+ * @returns Updates state of the event subscriber after the log
42
+ */
43
+ processLog(state, log) {
44
+ try {
45
+ const event = this.logDecoder(log);
46
+ if (event.name in this.handlers) {
47
+ return this.handlers[event.name](event, state, log);
48
+ }
49
+ }
50
+ catch (e) {
51
+ (0, utils_1.catchParseLogError)(e, this.logger);
52
+ }
53
+ return null;
54
+ }
55
+ /**
56
+ * The function generates state using on-chain calls. This
57
+ * function is called to regenerate state if the event based
58
+ * system fails to fetch events and the local state is no
59
+ * more correct.
60
+ * @param blockNumber - Blocknumber for which the state should
61
+ * should be generated
62
+ * @returns state of the event subscriber at blocknumber
63
+ */
64
+ async generateState(blockNumber) {
65
+ const iERC20 = new abi_1.Interface(ERC20_abi_json_1.default);
66
+ const callData = [
67
+ {
68
+ target: this.pool.token0,
69
+ callData: iERC20.encodeFunctionData('balanceOf', [this.pool.address]),
70
+ decodeFunction: decoders_1.uint256ToBigInt,
71
+ },
72
+ {
73
+ target: this.pool.token1,
74
+ callData: iERC20.encodeFunctionData('balanceOf', [this.pool.address]),
75
+ decodeFunction: decoders_1.uint256ToBigInt,
76
+ },
77
+ {
78
+ target: this.pool.address,
79
+ callData: this.iOSwap.encodeFunctionData('traderate0', []),
80
+ decodeFunction: decoders_1.uint256ToBigInt,
81
+ },
82
+ {
83
+ target: this.pool.address,
84
+ callData: this.iOSwap.encodeFunctionData('traderate1', []),
85
+ decodeFunction: decoders_1.uint256ToBigInt,
86
+ },
87
+ ];
88
+ const results = await this.dexHelper.multiWrapper.aggregate(callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize);
89
+ return {
90
+ balance0: results[0].toString(),
91
+ balance1: results[1].toString(),
92
+ traderate0: results[2].toString(),
93
+ traderate1: results[3].toString(),
94
+ };
95
+ }
96
+ async getStateOrGenerate(blockNumber, readonly = true) {
97
+ let state = this.getState(blockNumber);
98
+ if (!state) {
99
+ state = await this.generateState(blockNumber);
100
+ if (!readonly)
101
+ this.setState(state, blockNumber);
102
+ }
103
+ return state;
104
+ }
105
+ /**
106
+ * Handle a trade rate change on the pool.
107
+ */
108
+ handleTraderateChanged(event, state, log) {
109
+ return {
110
+ ...state,
111
+ traderate0: event.args.traderate0.toBigInt(),
112
+ traderate1: event.args.traderate1.toBigInt(),
113
+ };
114
+ }
115
+ /**
116
+ * Process the transfer events for tokens in/out of the pool
117
+ * to keep the state's token balances up to date.
118
+ */
119
+ handleTransfer(event, state, log) {
120
+ let balance0 = BigInt(state.balance0);
121
+ let balance1 = BigInt(state.balance1);
122
+ const tokenAddress = log.address.toLowerCase();
123
+ const fromAddress = event.args.from.toLowerCase();
124
+ const toAddress = event.args.to.toLowerCase();
125
+ const amount = event.args.value.toBigInt();
126
+ if (fromAddress == this.pool.address) {
127
+ if (tokenAddress === this.pool.token0) {
128
+ balance0 -= amount;
129
+ }
130
+ else if (tokenAddress === this.pool.token1) {
131
+ balance1 -= amount;
132
+ }
133
+ }
134
+ else if (toAddress == this.pool.address) {
135
+ if (tokenAddress === this.pool.token0) {
136
+ balance0 += amount;
137
+ }
138
+ else if (tokenAddress === this.pool.token1) {
139
+ balance1 += amount;
140
+ }
141
+ }
142
+ return {
143
+ ...state,
144
+ balance0: balance0.toString(),
145
+ balance1: balance1.toString(),
146
+ };
147
+ }
148
+ }
149
+ exports.OSwapEventPool = OSwapEventPool;
150
+ //# sourceMappingURL=oswap-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oswap-pool.js","sourceRoot":"","sources":["../../../src/dex/oswap/oswap-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAG/C,uCAAiD;AACjD,+EAA0E;AAG1E,iDAAqD;AAErD,oFAAsD;AACtD,8EAAgD;AAEhD,MAAa,cAAe,SAAQ,mDAAuC;IAazE,YACW,UAAkB,EAClB,IAAe,EACd,OAAe,EACf,SAAqB,EAC/B,MAAc,EACJ,SAAS,IAAI,eAAS,CAAC,wBAAQ,CAAC,EAChC,SAAS,IAAI,eAAS,CAAC,wBAAQ,CAAC;QAE1C,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QARrC,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAW;QACd,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAY;QAErB,WAAM,GAAN,MAAM,CAA0B;QAChC,WAAM,GAAN,MAAM,CAA0B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YACpC,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACrC,QAAQ,IAAI,MAAM,CAAC;aACpB;iBAAM,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC5C,QAAQ,IAAI,MAAM,CAAC;aACpB;SACF;aAAM,IAAI,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACzC,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACrC,QAAQ,IAAI,MAAM,CAAC;aACpB;iBAAM,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC5C,QAAQ,IAAI,MAAM,CAAC;aACpB;SACF;QAED,OAAO;YACL,GAAG,KAAK;YACR,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;YAC7B,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;SAC9B,CAAC;IACJ,CAAC;CACF;AAjLD,wCAiLC"}
@@ -0,0 +1,46 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { AsyncOrSync } from 'ts-essentials';
3
+ import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, PoolLiquidity, Logger, NumberAsString, DexExchangeParam } from '../../types';
4
+ import { SwapSide, Network } from '../../constants';
5
+ import { Context, IDex } from '../../dex/idex';
6
+ import { IDexHelper } from '../../dex-helper/idex-helper';
7
+ import { OSwapData, OSwapPool, OSwapPoolState } from './types';
8
+ import { SimpleExchange } from '../simple-exchange';
9
+ import { OSwapEventPool } from './oswap-pool';
10
+ export declare class OSwap extends SimpleExchange implements IDex<OSwapData> {
11
+ readonly network: Network;
12
+ readonly dexKey: string;
13
+ readonly dexHelper: IDexHelper;
14
+ protected adapters: import("../../types").AdapterMappings;
15
+ readonly eventPools: {
16
+ [id: string]: OSwapEventPool;
17
+ };
18
+ readonly hasConstantPriceLargeAmounts = false;
19
+ readonly needWrapNative = true;
20
+ readonly isFeeOnTransferSupported = false;
21
+ static dexKeysWithNetwork: {
22
+ key: string;
23
+ networks: Network[];
24
+ }[];
25
+ logger: Logger;
26
+ readonly iOSwap: Interface;
27
+ readonly pools: [OSwapPool];
28
+ constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: import("../../types").AdapterMappings);
29
+ getAdapters(side: SwapSide): {
30
+ name: string;
31
+ index: number;
32
+ }[] | null;
33
+ getPoolByTokenPair(srcToken: Token, destToken: Token): OSwapPool | null;
34
+ getPoolById(id: string): OSwapPool | null;
35
+ getPoolsByTokenAddress(tokenAddress: Address): OSwapPool[];
36
+ getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
37
+ calcPrice(pool: OSwapPool, state: OSwapPoolState, from: Token, amount: bigint, side: SwapSide, checkLiquidity?: boolean): bigint;
38
+ hasEnoughLiquidity(pool: OSwapPool, state: OSwapPoolState, from: Token, amount: bigint, needed: bigint, side: SwapSide): boolean;
39
+ getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<OSwapData>>;
40
+ getCalldataGasCost(poolPrices: PoolPrices<OSwapData>): number | number[];
41
+ getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: OSwapData, side: SwapSide): AdapterExchangeParam;
42
+ getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: OSwapData, side: SwapSide, _: Context, executorAddress: Address): DexExchangeParam;
43
+ updatePoolState(): Promise<void>;
44
+ getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
45
+ releaseResources(): AsyncOrSync<void>;
46
+ }
@@ -0,0 +1,273 @@
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.OSwap = void 0;
30
+ const abi_1 = require("@ethersproject/abi");
31
+ const constants_1 = require("../../constants");
32
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
33
+ const utils_1 = require("../../utils");
34
+ const simple_exchange_1 = require("../simple-exchange");
35
+ const config_1 = require("./config");
36
+ const oswap_pool_1 = require("./oswap-pool");
37
+ const oswap_abi_json_1 = __importDefault(require("../../abi/oswap/oswap.abi.json"));
38
+ const utils_2 = require("../../executor/utils");
39
+ class OSwap extends simple_exchange_1.SimpleExchange {
40
+ constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
41
+ super(dexHelper, dexKey);
42
+ this.network = network;
43
+ this.dexKey = dexKey;
44
+ this.dexHelper = dexHelper;
45
+ this.adapters = adapters;
46
+ this.eventPools = {};
47
+ this.hasConstantPriceLargeAmounts = false;
48
+ // This may change in the future, but currently OSwap does not support native ETH.
49
+ this.needWrapNative = true;
50
+ this.isFeeOnTransferSupported = false;
51
+ this.logger = dexHelper.getLogger(dexKey);
52
+ this.iOSwap = new abi_1.Interface(oswap_abi_json_1.default);
53
+ this.pools = config_1.OSwapConfig[dexKey][network].pools;
54
+ // Create an OSwapEventPool per pool, to track each pool's state by subscribing to on-chain events.
55
+ for (const pool of this.pools) {
56
+ this.eventPools[pool.id] = new oswap_pool_1.OSwapEventPool(dexKey, pool, network, dexHelper, this.logger);
57
+ }
58
+ }
59
+ // Returns the list of contract adapters (name and index)
60
+ // for a buy/sell. Return null if there are no adapters.
61
+ getAdapters(side) {
62
+ return null;
63
+ }
64
+ // Returns the pool matching the specified token pair or null if none found.
65
+ // Note: OSwap V1 does not support more than 1 pool per pair.
66
+ getPoolByTokenPair(srcToken, destToken) {
67
+ const srcAddress = srcToken.address.toLowerCase();
68
+ const destAddress = destToken.address.toLowerCase();
69
+ // A pair must have 2 different tokens.
70
+ if (srcAddress === destAddress)
71
+ return null;
72
+ for (const pool of this.pools) {
73
+ if ((srcAddress === pool.token0 && destAddress === pool.token1) ||
74
+ (srcAddress === pool.token1 && destAddress === pool.token0)) {
75
+ return pool;
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+ getPoolById(id) {
81
+ for (const pool of this.pools) {
82
+ if (pool.id === id)
83
+ return pool;
84
+ }
85
+ return null;
86
+ }
87
+ // Returns a list of pool using the token.
88
+ getPoolsByTokenAddress(tokenAddress) {
89
+ const address = tokenAddress.toLowerCase();
90
+ let pools = [];
91
+ for (const pool of this.pools) {
92
+ if (address === pool.token0 || address === pool.token1) {
93
+ pools.push(pool);
94
+ }
95
+ }
96
+ return pools;
97
+ }
98
+ // Returns the list of pool identifiers that can be used
99
+ // for a given swap. poolIdentifiers must be unique
100
+ // across DEXes. It is recommended to use
101
+ // ${dexKey}_${poolAddress} as a poolIdentifier
102
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
103
+ const pool = this.getPoolByTokenPair(srcToken, destToken);
104
+ return pool ? [pool.id] : [];
105
+ }
106
+ // Sell: Given "amount" of "from" token, how much of "to" token will be received by the trader.
107
+ // Buy: Given "amount" of "dest" token, how much of "to" token is required from the trader.
108
+ // Note: OSwap traderate is at precision 36.
109
+ calcPrice(pool, state, from, amount, side, checkLiquidity = true) {
110
+ const rate = from.address.toLowerCase() === pool.token0
111
+ ? BigInt(state.traderate0)
112
+ : BigInt(state.traderate1);
113
+ const price = side === constants_1.SwapSide.SELL
114
+ ? (amount * rate) / (0, utils_1.getBigIntPow)(36)
115
+ : (amount * (0, utils_1.getBigIntPow)(36)) / rate;
116
+ if (checkLiquidity &&
117
+ !this.hasEnoughLiquidity(pool, state, from, amount, price, side)) {
118
+ throw new Error('Not enough liquidity');
119
+ }
120
+ return price;
121
+ }
122
+ // Returns true if the pool has enough liquidity for the swap. False otherwise.
123
+ hasEnoughLiquidity(pool, state, from, amount, needed, side) {
124
+ if (side === constants_1.SwapSide.SELL) {
125
+ return from.address.toLowerCase() === pool.token0
126
+ ? needed <= BigInt(state.balance1)
127
+ : needed <= BigInt(state.balance0);
128
+ }
129
+ // SwapSide.BUY
130
+ return from.address.toLowerCase() === pool.token0
131
+ ? amount <= BigInt(state.balance1)
132
+ : amount <= BigInt(state.balance0);
133
+ }
134
+ // Returns pool prices for amounts.
135
+ // If limitPools is defined only pools in limitPools
136
+ // should be used. If limitPools is undefined then
137
+ // any pool can be used.
138
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
139
+ try {
140
+ // Get the pool to use.
141
+ const pool = this.getPoolByTokenPair(srcToken, destToken);
142
+ if (!pool)
143
+ return null;
144
+ // Make sure the pool meets the optional limitPools filter.
145
+ if (limitPools && !limitPools.includes(pool.id))
146
+ return null;
147
+ const eventPool = this.eventPools[pool.id];
148
+ if (!eventPool) {
149
+ this.logger.error(`OSwap pool ${pool.id}: No EventPool found.`);
150
+ return null;
151
+ }
152
+ const state = await eventPool.getStateOrGenerate(blockNumber);
153
+ // Calculate the prices
154
+ const unitAmount = (0, utils_1.getBigIntPow)(18);
155
+ const unitPrice = this.calcPrice(pool, state, srcToken, unitAmount, side, false);
156
+ const prices = amounts.map(amount => this.calcPrice(pool, state, srcToken, amount, side));
157
+ return [
158
+ {
159
+ prices,
160
+ unit: unitPrice,
161
+ data: {
162
+ pool: pool.address,
163
+ path: [srcToken.address, destToken.address],
164
+ },
165
+ exchange: this.dexKey,
166
+ poolIdentifier: pool.id,
167
+ gasCost: config_1.OSWAP_GAS_COST,
168
+ poolAddresses: [pool.address],
169
+ },
170
+ ];
171
+ }
172
+ catch (e) {
173
+ this.logger.error(`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${destToken.address || destToken.symbol}, ${side}:`, e);
174
+ return null;
175
+ }
176
+ }
177
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
178
+ getCalldataGasCost(poolPrices) {
179
+ return (CALLDATA_GAS_COST.DEX_OVERHEAD +
180
+ // ParentStruct header
181
+ CALLDATA_GAS_COST.OFFSET_SMALL +
182
+ // ParentStruct -> path[] header
183
+ CALLDATA_GAS_COST.OFFSET_SMALL +
184
+ // ParentStruct -> path length
185
+ CALLDATA_GAS_COST.LENGTH_SMALL +
186
+ // ParentStruct -> path[0]
187
+ CALLDATA_GAS_COST.ADDRESS +
188
+ // ParentStruct -> path[1]
189
+ CALLDATA_GAS_COST.ADDRESS +
190
+ // ParentStruct -> receiver header
191
+ CALLDATA_GAS_COST.OFFSET_SMALL +
192
+ // ParentStruct -> receiver
193
+ CALLDATA_GAS_COST.ADDRESS);
194
+ }
195
+ // Encode params required by the exchange adapter
196
+ // Used for multiSwap, buy & megaSwap
197
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
198
+ return {
199
+ targetExchange: data.pool,
200
+ payload: '',
201
+ networkFee: '0',
202
+ };
203
+ }
204
+ // Encode call data used by simpleSwap like routers
205
+ // Used for simpleSwap & simpleBuy
206
+ getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, _, executorAddress) {
207
+ let method;
208
+ let args;
209
+ let returnAmountPos = undefined;
210
+ const deadline = (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)();
211
+ if (side === constants_1.SwapSide.SELL) {
212
+ method = 'swapExactTokensForTokens';
213
+ returnAmountPos = (0, utils_2.extractReturnAmountPosition)(this.iOSwap, method, 'amounts', 1);
214
+ args = [srcAmount, destAmount, data.path, recipient, deadline];
215
+ }
216
+ else {
217
+ method = 'swapTokensForExactTokens';
218
+ args = [destAmount, srcAmount, data.path, recipient, deadline];
219
+ }
220
+ const swapData = this.iOSwap.encodeFunctionData(method, args);
221
+ return {
222
+ needWrapNative: this.needWrapNative,
223
+ dexFuncHasRecipient: true,
224
+ exchangeData: swapData,
225
+ targetExchange: data.pool,
226
+ returnAmountPos,
227
+ };
228
+ }
229
+ // This is called once before getTopPoolsForToken is
230
+ // called for multiple tokens. This can be helpful to
231
+ // update common state required for calculating
232
+ // getTopPoolsForToken. It is optional for a DEX
233
+ // to implement this
234
+ async updatePoolState() {
235
+ return Promise.resolve();
236
+ }
237
+ // Returns a list of top pools based on liquidity. Max
238
+ // limit number pools should be returned.
239
+ async getTopPoolsForToken(tokenAddress, limit) {
240
+ // Get the list of pools using the token.
241
+ const pools = this.getPoolsByTokenAddress(tokenAddress);
242
+ if (!pools.length)
243
+ return [];
244
+ const results = await Promise.all(pools.map(async (pool) => {
245
+ // Get the pool's balance and its USD value.
246
+ const eventPool = this.eventPools[pool.id];
247
+ const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
248
+ const state = await eventPool.getStateOrGenerate(blockNumber);
249
+ const usd0 = await this.dexHelper.getTokenUSDPrice({ address: pool.token0, decimals: 18 }, BigInt(state.balance0));
250
+ const usd1 = await this.dexHelper.getTokenUSDPrice({ address: pool.token1, decimals: 18 }, BigInt(state.balance1));
251
+ // Get the other token in the pair.
252
+ const pairedToken = pool.token0 === tokenAddress.toLowerCase()
253
+ ? { address: pool.token1, decimals: 18 }
254
+ : { address: pool.token0, decimals: 18 };
255
+ return {
256
+ exchange: this.dexKey,
257
+ address: pool.address,
258
+ connectorTokens: [pairedToken],
259
+ liquidityUSD: usd0 + usd1,
260
+ };
261
+ }));
262
+ return results
263
+ .filter(r => r)
264
+ .sort((a, b) => a.liquidityUSD - b.liquidityUSD)
265
+ .slice(0, limit);
266
+ }
267
+ // This is optional function in case if your implementation has acquired any resources
268
+ // you need to release for graceful shutdown. For example, it may be any interval timer
269
+ releaseResources() { }
270
+ }
271
+ exports.OSwap = OSwap;
272
+ OSwap.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.OSwapConfig);
273
+ //# sourceMappingURL=oswap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oswap.js","sourceRoot":"","sources":["../../../src/dex/oswap/oswap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+C;AAa/C,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAkE;AAIlE,wDAG4B;AAC5B,qCAAiE;AACjE,6CAA8C;AAC9C,oFAAsD;AACtD,gDAAmE;AAEnE,MAAa,KAAM,SAAQ,gCAAc;IAmBvC,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,iBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QAE5C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QALhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAA0B;QAtBrC,eAAU,GAAqC,EAAE,CAAC;QAElD,iCAA4B,GAAG,KAAK,CAAC;QAE9C,kFAAkF;QACzE,mBAAc,GAAG,IAAI,CAAC;QAEtB,6BAAwB,GAAG,KAAK,CAAC;QAkBxC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,IAAI,eAAS,CAAC,wBAAQ,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0,0 +1,20 @@
1
+ import { Address } from '../../types';
2
+ export declare type OSwapPoolState = {
3
+ traderate0: string;
4
+ traderate1: string;
5
+ balance0: string;
6
+ balance1: string;
7
+ };
8
+ export declare type OSwapData = {
9
+ pool: Address;
10
+ path: Address[];
11
+ };
12
+ export declare type OSwapPool = {
13
+ id: string;
14
+ address: Address;
15
+ token0: Address;
16
+ token1: Address;
17
+ };
18
+ export declare type DexParams = {
19
+ pools: [OSwapPool];
20
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/oswap/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { DeepReadonly } from 'ts-essentials';
2
+ import { PartialEventSubscriber } from '../../composed-event-subscriber';
3
+ import { Address, BlockHeader, Log, Logger, MultiCallInput, MultiCallOutput } from '../../types';
4
+ import { Lens } from '../../lens';
5
+ import { Interface } from '@ethersproject/abi';
6
+ import { PlatypusAssetState } from './types';
7
+ export declare class PlatypusAssetSubscriber<State> extends PartialEventSubscriber<State, PlatypusAssetState> {
8
+ private asset;
9
+ static readonly assetInterface: Interface;
10
+ constructor(asset: Address, lens: Lens<DeepReadonly<State>, DeepReadonly<PlatypusAssetState>>, logger: Logger);
11
+ processLog(state: DeepReadonly<PlatypusAssetState>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): DeepReadonly<PlatypusAssetState> | null;
12
+ getGenerateStateMultiCallInputs(): MultiCallInput[];
13
+ generateState(multicallOutputs: MultiCallOutput[], blockNumber?: number | 'latest'): DeepReadonly<PlatypusAssetState>;
14
+ }
@@ -0,0 +1,97 @@
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.PlatypusAssetSubscriber = void 0;
7
+ const composed_event_subscriber_1 = require("../../composed-event-subscriber");
8
+ const abi_1 = require("@ethersproject/abi");
9
+ const asset_json_1 = __importDefault(require("../../abi/platypus/asset.json"));
10
+ class PlatypusAssetSubscriber extends composed_event_subscriber_1.PartialEventSubscriber {
11
+ constructor(asset, lens, logger) {
12
+ super([asset], lens, logger);
13
+ this.asset = asset;
14
+ }
15
+ processLog(state, log, blockHeader) {
16
+ try {
17
+ const parsed = PlatypusAssetSubscriber.assetInterface.parseLog(log);
18
+ switch (parsed.name) {
19
+ case 'CashAdded': {
20
+ const previousCashPosition = BigInt(parsed.args.previousCashPosition.toString());
21
+ const cashBeingAdded = BigInt(parsed.args.cashBeingAdded.toString());
22
+ if (state.cash !== previousCashPosition) {
23
+ this.logger.error('state.cash !== previousCashPosition');
24
+ }
25
+ return {
26
+ cash: previousCashPosition + cashBeingAdded,
27
+ liability: state.liability,
28
+ };
29
+ }
30
+ case 'CashRemoved': {
31
+ const previousCashPosition = BigInt(parsed.args.previousCashPosition.toString());
32
+ const cashBeingRemoved = BigInt(parsed.args.cashBeingRemoved.toString());
33
+ if (state.cash !== previousCashPosition) {
34
+ this.logger.error('state.cash !== previousCashPosition');
35
+ }
36
+ return {
37
+ cash: previousCashPosition - cashBeingRemoved,
38
+ liability: state.liability,
39
+ };
40
+ }
41
+ case 'LiabilityAdded': {
42
+ const previousLiabilityPosition = BigInt(parsed.args.previousLiabilityPosition.toString());
43
+ const liabilityBeingAdded = BigInt(parsed.args.liabilityBeingAdded.toString());
44
+ if (state.liability !== previousLiabilityPosition) {
45
+ this.logger.error('state.liability !== previousLiabilityPosition');
46
+ }
47
+ return {
48
+ cash: state.cash,
49
+ liability: previousLiabilityPosition + liabilityBeingAdded,
50
+ };
51
+ }
52
+ case 'LiabilityRemoved': {
53
+ const previousLiabilityPosition = BigInt(parsed.args.previousLiabilityPosition.toString());
54
+ const liabilityBeingRemoved = BigInt(parsed.args.liabilityBeingRemoved.toString());
55
+ if (state.liability !== previousLiabilityPosition) {
56
+ this.logger.error('state.liability !== previousLiabilityPosition');
57
+ }
58
+ return {
59
+ cash: state.cash,
60
+ liability: previousLiabilityPosition - liabilityBeingRemoved,
61
+ };
62
+ }
63
+ default:
64
+ return null;
65
+ }
66
+ }
67
+ catch (e) {
68
+ this.logger.error('Failed to parse log', e);
69
+ return null;
70
+ }
71
+ }
72
+ getGenerateStateMultiCallInputs() {
73
+ return [
74
+ {
75
+ target: this.asset,
76
+ callData: PlatypusAssetSubscriber.assetInterface.encodeFunctionData('cash'),
77
+ },
78
+ {
79
+ target: this.asset,
80
+ callData: PlatypusAssetSubscriber.assetInterface.encodeFunctionData('liability'),
81
+ },
82
+ ];
83
+ }
84
+ generateState(multicallOutputs, blockNumber) {
85
+ return {
86
+ cash: BigInt(PlatypusAssetSubscriber.assetInterface
87
+ .decodeFunctionResult('cash', multicallOutputs[0])[0]
88
+ .toString()),
89
+ liability: BigInt(PlatypusAssetSubscriber.assetInterface
90
+ .decodeFunctionResult('liability', multicallOutputs[1])[0]
91
+ .toString()),
92
+ };
93
+ }
94
+ }
95
+ exports.PlatypusAssetSubscriber = PlatypusAssetSubscriber;
96
+ PlatypusAssetSubscriber.assetInterface = new abi_1.Interface(asset_json_1.default);
97
+ //# sourceMappingURL=asset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset.js","sourceRoot":"","sources":["../../../src/dex/platypus/asset.ts"],"names":[],"mappings":";;;;;;AACA,+EAAyE;AAUzE,4CAA+C;AAC/C,+EAAqD;AAGrD,MAAa,uBAA+B,SAAQ,kDAGnD;IAGC,YACU,KAAc,EACtB,IAAiE,EACjE,MAAc;QAEd,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAJrB,UAAK,GAAL,KAAK,CAAS;IAKxB,CAAC;IAEM,UAAU,CACf,KAAuC,EACvC,GAAkB,EAClB,WAAkC;QAElC,IAAI;YACF,MAAM,MAAM,GAAG,u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AmC,EACnC,WAA+B;QAE/B,OAAO;YACL,IAAI,EAAE,MAAM,CACV,uBAAuB,CAAC,cAAc;iBACnC,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;iBACpD,QAAQ,EAAE,CACd;YACD,SAAS,EAAE,MAAM,CACf,uBAAuB,CAAC,cAAc;iBACnC,oBAAoB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;iBACzD,QAAQ,EAAE,CACd;SACF,CAAC;IACJ,CAAC;;AA1HH,0DA2HC;AAvHiB,sCAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ export declare const PlatypusConfig: DexConfigMap<DexParams>;
4
+ export declare const Adapters: {
5
+ [chainId: number]: {
6
+ [side: string]: {
7
+ name: string;
8
+ index: number;
9
+ }[] | null;
10
+ };
11
+ };