@paraswap/dex-lib 3.8.2 → 3.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/.vscode/launch.json +13 -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/integral/factory.json +333 -0
  6. package/build/abi/integral/oracle.json +501 -0
  7. package/build/abi/integral/pool.json +1041 -0
  8. package/build/abi/integral/relayer.json +1536 -0
  9. package/build/abi/oswap/oswap.abi.json +452 -0
  10. package/build/abi/platypus/asset.json +490 -0
  11. package/build/abi/platypus/avax-pool.json +820 -0
  12. package/build/abi/platypus/oracle.json +119 -0
  13. package/build/abi/platypus/pool.json +677 -0
  14. package/build/abi/smardex/all/smardex-router.json +648 -0
  15. package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
  16. package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
  17. package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
  18. package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
  19. package/build/abi/swaap-v1/pool.json +1346 -0
  20. package/build/dex/aave-v1/aave-v1.d.ts +33 -0
  21. package/build/dex/aave-v1/aave-v1.js +158 -0
  22. package/build/dex/aave-v1/aave-v1.js.map +1 -0
  23. package/build/dex/aave-v1/config.d.ts +11 -0
  24. package/build/dex/aave-v1/config.js +20 -0
  25. package/build/dex/aave-v1/config.js.map +1 -0
  26. package/build/dex/aave-v1/tokens-mainnet.json +134 -0
  27. package/build/dex/aave-v1/tokens.d.ts +3 -0
  28. package/build/dex/aave-v1/tokens.js +50 -0
  29. package/build/dex/aave-v1/tokens.js.map +1 -0
  30. package/build/dex/aave-v1/types.d.ts +12 -0
  31. package/build/dex/aave-v1/types.js +3 -0
  32. package/build/dex/aave-v1/types.js.map +1 -0
  33. package/build/dex/aave-v3/aave-v3.js +2 -1
  34. package/build/dex/aave-v3/aave-v3.js.map +1 -1
  35. package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
  36. package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
  37. package/build/dex/angle-staked-stable/angle-staked-stable.js +4 -1
  38. package/build/dex/angle-staked-stable/angle-staked-stable.js.map +1 -1
  39. package/build/dex/bProtocol.d.ts +18 -0
  40. package/build/dex/bProtocol.js +39 -0
  41. package/build/dex/bProtocol.js.map +1 -0
  42. package/build/dex/bancor.d.ts +26 -0
  43. package/build/dex/bancor.js +58 -0
  44. package/build/dex/bancor.js.map +1 -0
  45. package/build/dex/compound/compound.js +2 -1
  46. package/build/dex/compound/compound.js.map +1 -1
  47. package/build/dex/compound.d.ts +18 -0
  48. package/build/dex/compound.js +46 -0
  49. package/build/dex/compound.js.map +1 -0
  50. package/build/dex/curve-v2.d.ts +58 -0
  51. package/build/dex/curve-v2.js +180 -0
  52. package/build/dex/curve-v2.js.map +1 -0
  53. package/build/dex/dodo-v1.d.ts +33 -0
  54. package/build/dex/dodo-v1.js +63 -0
  55. package/build/dex/dodo-v1.js.map +1 -0
  56. package/build/dex/etherfi/etherfi.d.ts +26 -0
  57. package/build/dex/etherfi/etherfi.js +96 -0
  58. package/build/dex/etherfi/etherfi.js.map +1 -0
  59. package/build/dex/etherfi.js +4 -1
  60. package/build/dex/etherfi.js.map +1 -1
  61. package/build/dex/idle-dao/idle-dao.js +1 -0
  62. package/build/dex/idle-dao/idle-dao.js.map +1 -1
  63. package/build/dex/integral/config.d.ts +4 -0
  64. package/build/dex/integral/config.js +20 -0
  65. package/build/dex/integral/config.js.map +1 -0
  66. package/build/dex/integral/context.d.ts +33 -0
  67. package/build/dex/integral/context.js +98 -0
  68. package/build/dex/integral/context.js.map +1 -0
  69. package/build/dex/integral/helpers.d.ts +17 -0
  70. package/build/dex/integral/helpers.js +157 -0
  71. package/build/dex/integral/helpers.js.map +1 -0
  72. package/build/dex/integral/integral-factory.d.ts +21 -0
  73. package/build/dex/integral/integral-factory.js +92 -0
  74. package/build/dex/integral/integral-factory.js.map +1 -0
  75. package/build/dex/integral/integral-pool.d.ts +46 -0
  76. package/build/dex/integral/integral-pool.js +143 -0
  77. package/build/dex/integral/integral-pool.js.map +1 -0
  78. package/build/dex/integral/integral-pricing.d.ts +18 -0
  79. package/build/dex/integral/integral-pricing.js +114 -0
  80. package/build/dex/integral/integral-pricing.js.map +1 -0
  81. package/build/dex/integral/integral-relayer.d.ts +39 -0
  82. package/build/dex/integral/integral-relayer.js +189 -0
  83. package/build/dex/integral/integral-relayer.js.map +1 -0
  84. package/build/dex/integral/integral-token.d.ts +22 -0
  85. package/build/dex/integral/integral-token.js +55 -0
  86. package/build/dex/integral/integral-token.js.map +1 -0
  87. package/build/dex/integral/integral.d.ts +41 -0
  88. package/build/dex/integral/integral.js +382 -0
  89. package/build/dex/integral/integral.js.map +1 -0
  90. package/build/dex/integral/types.d.ts +84 -0
  91. package/build/dex/integral/types.js +9 -0
  92. package/build/dex/integral/types.js.map +1 -0
  93. package/build/dex/integral/utils.d.ts +6 -0
  94. package/build/dex/integral/utils.js +23 -0
  95. package/build/dex/integral/utils.js.map +1 -0
  96. package/build/dex/lido.d.ts +19 -0
  97. package/build/dex/lido.js +42 -0
  98. package/build/dex/lido.js.map +1 -0
  99. package/build/dex/mStable.js +1 -1
  100. package/build/dex/mStable.js.map +1 -1
  101. package/build/dex/onebit.d.ts +25 -0
  102. package/build/dex/onebit.js +42 -0
  103. package/build/dex/onebit.js.map +1 -0
  104. package/build/dex/oswap/config.d.ts +5 -0
  105. package/build/dex/oswap/config.js +31 -0
  106. package/build/dex/oswap/config.js.map +1 -0
  107. package/build/dex/oswap/oswap-pool.d.ts +51 -0
  108. package/build/dex/oswap/oswap-pool.js +150 -0
  109. package/build/dex/oswap/oswap-pool.js.map +1 -0
  110. package/build/dex/oswap/oswap.d.ts +46 -0
  111. package/build/dex/oswap/oswap.js +266 -0
  112. package/build/dex/oswap/oswap.js.map +1 -0
  113. package/build/dex/oswap/types.d.ts +20 -0
  114. package/build/dex/oswap/types.js +3 -0
  115. package/build/dex/oswap/types.js.map +1 -0
  116. package/build/dex/platypus/asset.d.ts +14 -0
  117. package/build/dex/platypus/asset.js +97 -0
  118. package/build/dex/platypus/asset.js.map +1 -0
  119. package/build/dex/platypus/config.d.ts +11 -0
  120. package/build/dex/platypus/config.js +69 -0
  121. package/build/dex/platypus/config.js.map +1 -0
  122. package/build/dex/platypus/platypus.d.ts +62 -0
  123. package/build/dex/platypus/platypus.js +442 -0
  124. package/build/dex/platypus/platypus.js.map +1 -0
  125. package/build/dex/platypus/pool-avax.d.ts +8 -0
  126. package/build/dex/platypus/pool-avax.js +54 -0
  127. package/build/dex/platypus/pool-avax.js.map +1 -0
  128. package/build/dex/platypus/pool-base.d.ts +19 -0
  129. package/build/dex/platypus/pool-base.js +86 -0
  130. package/build/dex/platypus/pool-base.js.map +1 -0
  131. package/build/dex/platypus/pool-pure.d.ts +8 -0
  132. package/build/dex/platypus/pool-pure.js +37 -0
  133. package/build/dex/platypus/pool-pure.js.map +1 -0
  134. package/build/dex/platypus/pool-subscriber.d.ts +14 -0
  135. package/build/dex/platypus/pool-subscriber.js +167 -0
  136. package/build/dex/platypus/pool-subscriber.js.map +1 -0
  137. package/build/dex/platypus/pool.d.ts +8 -0
  138. package/build/dex/platypus/pool.js +58 -0
  139. package/build/dex/platypus/pool.js.map +1 -0
  140. package/build/dex/platypus/types.d.ts +92 -0
  141. package/build/dex/platypus/types.js +10 -0
  142. package/build/dex/platypus/types.js.map +1 -0
  143. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  144. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  145. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  146. package/build/dex/sdai/config.d.ts +11 -0
  147. package/build/dex/sdai/config.js +21 -0
  148. package/build/dex/sdai/config.js.map +1 -0
  149. package/build/dex/sdai/constants.d.ts +2 -0
  150. package/build/dex/sdai/constants.js +6 -0
  151. package/build/dex/sdai/constants.js.map +1 -0
  152. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  153. package/build/dex/sdai/scripts/validate-state.js +102 -0
  154. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  155. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  156. package/build/dex/sdai/sdai-pool.js +85 -0
  157. package/build/dex/sdai/sdai-pool.js.map +1 -0
  158. package/build/dex/sdai/sdai.d.ts +51 -0
  159. package/build/dex/sdai/sdai.js +172 -0
  160. package/build/dex/sdai/sdai.js.map +1 -0
  161. package/build/dex/sdai/types.d.ts +21 -0
  162. package/build/dex/sdai/types.js +11 -0
  163. package/build/dex/sdai/types.js.map +1 -0
  164. package/build/dex/sdai/utils.d.ts +4 -0
  165. package/build/dex/sdai/utils.js +39 -0
  166. package/build/dex/sdai/utils.js.map +1 -0
  167. package/build/dex/simple-exchange.d.ts +1 -1
  168. package/build/dex/simple-exchange.js +4 -2
  169. package/build/dex/simple-exchange.js.map +1 -1
  170. package/build/dex/smardex/config.d.ts +4 -0
  171. package/build/dex/smardex/config.js +64 -0
  172. package/build/dex/smardex/config.js.map +1 -0
  173. package/build/dex/smardex/constants.d.ts +18 -0
  174. package/build/dex/smardex/constants.js +33 -0
  175. package/build/dex/smardex/constants.js.map +1 -0
  176. package/build/dex/smardex/sdk/constants.d.ts +6 -0
  177. package/build/dex/smardex/sdk/constants.js +13 -0
  178. package/build/dex/smardex/sdk/constants.js.map +1 -0
  179. package/build/dex/smardex/sdk/core.d.ts +113 -0
  180. package/build/dex/smardex/sdk/core.js +499 -0
  181. package/build/dex/smardex/sdk/core.js.map +1 -0
  182. package/build/dex/smardex/sdk/errors.d.ts +15 -0
  183. package/build/dex/smardex/sdk/errors.js +22 -0
  184. package/build/dex/smardex/sdk/errors.js.map +1 -0
  185. package/build/dex/smardex/sdk/types.d.ts +62 -0
  186. package/build/dex/smardex/sdk/types.js +3 -0
  187. package/build/dex/smardex/sdk/types.js.map +1 -0
  188. package/build/dex/smardex/sdk/utils.d.ts +44 -0
  189. package/build/dex/smardex/sdk/utils.js +133 -0
  190. package/build/dex/smardex/sdk/utils.js.map +1 -0
  191. package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
  192. package/build/dex/smardex/smardex-event-pool.js +119 -0
  193. package/build/dex/smardex/smardex-event-pool.js.map +1 -0
  194. package/build/dex/smardex/smardex.d.ts +65 -0
  195. package/build/dex/smardex/smardex.js +519 -0
  196. package/build/dex/smardex/smardex.js.map +1 -0
  197. package/build/dex/smardex/types.d.ts +55 -0
  198. package/build/dex/smardex/types.js +3 -0
  199. package/build/dex/smardex/types.js.map +1 -0
  200. package/build/dex/smoothy.d.ts +26 -0
  201. package/build/dex/smoothy.js +48 -0
  202. package/build/dex/smoothy.js.map +1 -0
  203. package/build/dex/solidly/forks-override/cone.d.ts +22 -0
  204. package/build/dex/solidly/forks-override/cone.js +53 -0
  205. package/build/dex/solidly/forks-override/cone.js.map +1 -0
  206. package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
  207. package/build/dex/solidly/forks-override/solisnek.js +15 -0
  208. package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
  209. package/build/dex/spark/spark.js +2 -1
  210. package/build/dex/spark/spark.js.map +1 -1
  211. package/build/dex/stable-pool.d.ts +28 -0
  212. package/build/dex/stable-pool.js +62 -0
  213. package/build/dex/stable-pool.js.map +1 -0
  214. package/build/dex/swaap-v1/config.d.ts +17 -0
  215. package/build/dex/swaap-v1/config.js +56 -0
  216. package/build/dex/swaap-v1/config.js.map +1 -0
  217. package/build/dex/swaap-v1/constants.d.ts +6 -0
  218. package/build/dex/swaap-v1/constants.js +17 -0
  219. package/build/dex/swaap-v1/constants.js.map +1 -0
  220. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
  221. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
  222. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
  223. package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
  224. package/build/dex/swaap-v1/libraries/Const.js +26 -0
  225. package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
  226. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
  227. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
  228. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
  229. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
  230. package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
  231. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
  232. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
  233. package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
  234. package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
  235. package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
  236. package/build/dex/swaap-v1/libraries/Num.js +167 -0
  237. package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
  238. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
  239. package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
  240. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
  241. package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
  242. package/build/dex/swaap-v1/libraries/Struct.js +3 -0
  243. package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
  244. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
  245. package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
  246. package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
  247. package/build/dex/swaap-v1/swaap-v1.d.ts +61 -0
  248. package/build/dex/swaap-v1/swaap-v1.js +369 -0
  249. package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
  250. package/build/dex/swaap-v1/types.d.ts +106 -0
  251. package/build/dex/swaap-v1/types.js +9 -0
  252. package/build/dex/swaap-v1/types.js.map +1 -0
  253. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  254. package/build/dex/trader-joe-v2.1.js +79 -0
  255. package/build/dex/trader-joe-v2.1.js.map +1 -0
  256. package/build/executor/Executor01BytecodeBuilder.js +3 -1
  257. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  258. package/build/executor/Executor02BytecodeBuilder.js +3 -1
  259. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  260. package/build/executor/Executor03BytecodeBuilder.js +2 -0
  261. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  262. package/build/executor/ExecutorBytecodeBuilder.js +2 -0
  263. package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
  264. package/build/executor/compressor/Compressor.d.ts +23 -0
  265. package/build/executor/compressor/Compressor.js +144 -0
  266. package/build/executor/compressor/Compressor.js.map +1 -0
  267. package/build/executor/compressor/compress.d.ts +17 -0
  268. package/build/executor/compressor/compress.js +187 -0
  269. package/build/executor/compressor/compress.js.map +1 -0
  270. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
  271. package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
  272. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
  273. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
  274. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
  275. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
  276. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
  277. package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
  278. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
  279. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
  280. package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
  281. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
  282. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
  283. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
  284. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
  285. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
  286. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
  287. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
  288. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
  289. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
  290. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
  291. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
  292. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
  293. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
  294. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  295. package/build/executor/compressor/fetchSaved.js +17 -0
  296. package/build/executor/compressor/fetchSaved.js.map +1 -0
  297. package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
  298. package/build/executor/compressor/utils/computeCostL2.js +14 -0
  299. package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
  300. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
  301. package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
  302. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
  303. package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
  304. package/build/executor/compressor/utils/getAllIndexes.js +12 -0
  305. package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
  306. package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
  307. package/build/executor/compressor/utils/getByteForAddress.js +14 -0
  308. package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
  309. package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
  310. package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
  311. package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
  312. package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
  313. package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
  314. package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
  315. package/build/executor/compressor/utils/intToByte.d.ts +2 -0
  316. package/build/executor/compressor/utils/intToByte.js +10 -0
  317. package/build/executor/compressor/utils/intToByte.js.map +1 -0
  318. package/build/types.d.ts +1 -0
  319. package/package.json +1 -1
  320. package/src/dex/aave-v3/aave-v3-e2e.test.ts +4 -9
  321. package/src/dex/aave-v3/aave-v3.ts +5 -0
  322. package/src/dex/aave-v3-stata/aave-v3-stata.ts +1 -0
  323. package/src/dex/angle-staked-stable/angle-staked-stable.ts +8 -0
  324. package/src/dex/compound/compound.ts +5 -0
  325. package/src/dex/etherfi.ts +5 -0
  326. package/src/dex/idle-dao/idle-dao.ts +1 -0
  327. package/src/dex/simple-exchange.ts +5 -5
  328. package/src/dex/spark/spark-e2e.test.ts +9 -1
  329. package/src/dex/spark/spark.ts +5 -0
  330. package/src/executor/Executor01BytecodeBuilder.ts +3 -1
  331. package/src/executor/Executor02BytecodeBuilder.ts +3 -1
  332. package/src/executor/Executor03BytecodeBuilder.ts +2 -0
  333. package/src/executor/ExecutorBytecodeBuilder.ts +2 -0
  334. package/src/executor/executor01-bytecode-builder-e2e.test.ts +25 -0
  335. package/src/executor/executor02-bytecode-builder-e2e.test.ts +29 -0
  336. package/src/types.ts +1 -0
  337. package/tests/constants-e2e.ts +13 -13
  338. package/tests/utils-e2e.ts +1 -1
  339. package/.idea/aws.xml +0 -17
  340. package/.idea/codeStyles/Project.xml +0 -19
  341. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  342. package/.idea/misc.xml +0 -6
  343. package/.idea/modules.xml +0 -8
  344. package/.idea/paraswap-dex-lib.iml +0 -9
  345. package/.idea/prettier.xml +0 -7
  346. package/.idea/vcs.xml +0 -6
@@ -0,0 +1,113 @@
1
+ import type { CurrencyAmount, Pair } from './types';
2
+ /**
3
+ * Compute fictive reserves based on current reserves state
4
+ *
5
+ * @param {bigint} reserveIn the reserves of input token.
6
+ * @param {bigint} reserveOut the reserves of output token.
7
+ * @param {bigint} reserveInFic the fictive reserves of input token.
8
+ * @param {bigint} reserveOutFic the fictive reserves of output token.
9
+ * @returns {Array} [ficIn, ficOut]
10
+ */
11
+ export declare function computeReserveFic(reserveIn: bigint, reserveOut: bigint, reserveInFic: bigint, reserveOutFic: bigint): [bigint, bigint];
12
+ /**
13
+ * Simulate a full trasaction, if you know the "in" token quantity, provide you the "out" and all reserves change
14
+ * Use case: you want to receive exactly amountOut and want to know the exact amountIn to send.
15
+ * @param {bigint} amountIn the desired input amount of the trade.
16
+ * @param {bigint} reserveIn the reserves of input token.
17
+ * @param {bigint} reserveOut the reserves of output token.
18
+ * @param {bigint} reserveInFic the fictive reserves of input token.
19
+ * @param {bigint} reserveOutFic the fictive reserves of output token.
20
+ * @param {bigint} priceAverageIn the price average of input token.
21
+ * @param {bigint} priceAverageOut the price average of output token.
22
+ * @param {bigint} feesLP LP fees
23
+ * @param {bigint} feesPool Pool fees
24
+ * @returns {Array} [amountOut, newResIn, newResOut, newResInFic, newResOutFic]
25
+ */
26
+ export declare function getAmountOut(amountIn: bigint, reserveIn: bigint, reserveOut: bigint, reserveInFic: bigint, reserveOutFic: bigint, priceAverageIn: bigint, priceAverageOut: bigint, feesLP: bigint, feesPool: bigint): [bigint, bigint, bigint, bigint, bigint];
27
+ /**
28
+ * Simulate a full transaction, if you know the "out" token quantity, provide you the "in" and all reserves change
29
+ * Use case: you want to receive exactly amountOut and want to know the exact amountIn to send.
30
+ * @param {bigint} amountOut the desired output amount of the trade.
31
+ * @param {bigint} reserveIn the reserves of input token.
32
+ * @param {bigint} reserveOut the reserves of output token.
33
+ * @param {bigint} reserveInFic the fictive reserves of input token.
34
+ * @param {bigint} reserveOutFic the fictive reserves of output token.
35
+ * @param {bigint} priceAverageIn the price average of input token.
36
+ * @param {bigint} priceAverageOut the price average of output token.
37
+ * @param {bigint} feesLP LP fees
38
+ * @param {bigint} feesPool Pool fees
39
+ * @returns {Array} [amountIn, newResIn, newResOut, newResInFic, newResOutFic]
40
+ */
41
+ export declare function getAmountIn(amountOut: bigint, reserveIn: bigint, reserveOut: bigint, reserveInFic: bigint, reserveOutFic: bigint, priceAverageIn: bigint, priceAverageOut: bigint, feesLP: bigint, feesPool: bigint): [bigint, bigint, bigint, bigint, bigint];
42
+ /**
43
+ * Computes the priceAverageIn and priceAverageOut.
44
+ * Use case: you want to send an exact amount of tokenIn and know exactly how much you it will give you of tokenOut.
45
+ * Price averages are modified only if current timestamp does not match last timestamp
46
+ * @param {bigint} reserveFicIn the fictuve reserves of input token.
47
+ * @param {bigint} reserveFicOut the fictuve reserves of output token.
48
+ * @param {number} priceAverageLastTimestamp last timestamp in seconds of price average values.
49
+ * @param {bigint} priceAverageIn the latest price average of input token.
50
+ * @param {bigint} priceAverageOut the latest price average of output token.
51
+ * @param {number} currentTimestampInSecond current timestamp in seconds.
52
+ * @param {number} maxBlockDiffSeconds: Max block difference in seconds
53
+ * @returns {Array} [priceAverageIn, priceAverageOut]
54
+ */
55
+ export declare function getUpdatedPriceAverage(reserveFicIn: bigint, reserveFicOut: bigint, priceAverageLastTimestamp: number, priceAverageIn: bigint, priceAverageOut: bigint, currentTimestampInSecond: number, maxBlockDiffSeconds: number): [bigint, bigint];
56
+ /**
57
+ * Computes the amount of tokenOut, at the precision of 1 wei.
58
+ * Use case: you want to send an exact amount of tokenIn and know exactly how much you it will give you of tokenOut.
59
+ * WARNING: token0 and token1 are pair tokens which addresses hexadecimal's values are sorted as token0 < token1.
60
+ * @param {string} token0 the currency address of token0.
61
+ * @param {string} token1 the currency address of token1.
62
+ * @param {bigint} reserve0 the reserves of token0.
63
+ * @param {bigint} reserve1 the reserves of token1.
64
+ * @param {bigint} reserve0Fic the fictionnal reserves of token0.
65
+ * @param {bigint} reserve1Fic the fictionnal reserves of token1.
66
+ * @param {bigint} tokenAmountIn the input amount of the trade.
67
+ * @param {bigint} tokenAddressIn address of the input token.
68
+ * @param {number} priceAverageLastTimestamp: timestamp in seconds of the latest price average.
69
+ * @param {bigint} priceAverage0 latest price average of token0.
70
+ * @param {bigint} priceAverage1 latest price average of token1.
71
+ * @param {bigint} feesLP LP fees
72
+ * @param {bigint} feesPool Pool fees
73
+ * @param {number} forcedPriceAverageTimestamp: current timestamp or timestamp of the trade in seconds.
74
+ * @param {number} maxBlockDiffSeconds: Max block difference in seconds
75
+ * @returns {Object} { currency, amount, amountMax, newResIn, newResOut, newResInFic, newResOutFic }
76
+ */
77
+ export declare function computeAmountOut(token0: string, token1: string, reserve0: bigint, reserve1: bigint, reserve0Fic: bigint, reserve1Fic: bigint, tokenAmountIn: bigint, tokenAddressIn: string, priceAverageLastTimestamp: number, priceAverage0: bigint, priceAverage1: bigint, feesLP: bigint, feesPool: bigint, forcedPriceAverageTimestamp?: number, maxBlockDiffSeconds?: number): CurrencyAmount;
78
+ /**
79
+ * Computes the amount of tokenIn, at the precision of 1 wei.
80
+ * Use case: you want to receive exactly tokenOut amount and want to know the exact tokenIn amount to send.
81
+ * WARNING: token0 and token1 are pair tokens which addresses hexadecimal's values are sorted as token0 < token1.
82
+ * @param {string} token0 the currency address of token0.
83
+ * @param {string} token1 the currency address of token1.
84
+ * @param {bigint} reserve0 the reserves of token0.
85
+ * @param {bigint} reserve1 the reserves of token1.
86
+ * @param {bigint} reserve0Fic the fictionnal reserves of token0.
87
+ * @param {bigint} reserve1Fic the fictionnal reserves of token1.
88
+ * @param {bigint} tokenAmountOut the output amount of the trade.
89
+ * @param {bigint} tokenAddressOut address of the output token.
90
+ * @param {number} priceAverageLastTimestamp timestamp in seconds of the latest price average.
91
+ * @param {bigint} priceAverage0 latest price average of token0.
92
+ * @param {bigint} priceAverage1 latest price average of token1.
93
+ * @param {bigint} feesLP LP fees
94
+ * @param {bigint} feesPool Pool fees
95
+ * @param {number} forcedPriceAverageTimestamp current timestamp or timestamp of the trade in seconds.
96
+ * @param {number} maxBlockDiffSeconds: Max block difference in seconds
97
+ * @returns {Object} { currency, amount, amountMax, newResIn, newResOut, newResInFic, newResOutFic }
98
+ */
99
+ export declare function computeAmountIn(token0: string, token1: string, reserve0: bigint, reserve1: bigint, reserve0Fic: bigint, reserve1Fic: bigint, tokenAmountOut: bigint, tokenAddressOut: string, priceAverageLastTimestamp: number, priceAverage0: bigint, priceAverage1: bigint, feesLP: bigint, feesPool: bigint, forcedPriceAverageTimestamp?: number, maxBlockDiffSeconds?: number): CurrencyAmount;
100
+ /**
101
+ * Extracts the token addresses composing the route ordered in the route's direction starting with inputCurrency.
102
+ * @param {Pair[]} pairs array of pairs composing the trade.
103
+ * @param {string} inputCurrency the currency from which the route starts.
104
+ * @return {string[]} Array of token addresses composing the route ordered in the route's direction starting with inputCurrency.
105
+ */
106
+ export declare function getPathFromInput(pairs: Pair[], inputCurrency: string): string[];
107
+ /**
108
+ * Extracts the token addresses composing the route ordered in the route's direction ending with outputCurrency.
109
+ * @param {Pair[]} pairs array of pairs composing the trade.
110
+ * @param {string} outputCurrency the currency for which the route finishes.
111
+ * @return {string[]} Array of token addresses composing the route ordered in the route's direction ending with outputCurrency.
112
+ */
113
+ export declare function getPathFromOutput(pairs: Pair[], outputCurrency: string): string[];
@@ -0,0 +1,499 @@
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.getPathFromOutput = exports.getPathFromInput = exports.computeAmountIn = exports.computeAmountOut = exports.getUpdatedPriceAverage = exports.getAmountIn = exports.getAmountOut = exports.computeReserveFic = void 0;
7
+ const constants_1 = require("./constants");
8
+ const utils_1 = require("./utils");
9
+ const errors_1 = __importDefault(require("./errors"));
10
+ // compute first trade amountIn using arbitrage feature
11
+ function computeFirstTradeQtyIn(amountIn, reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut, feesLP, feesPool) {
12
+ // default value
13
+ let firstAmountIn = amountIn;
14
+ // if trade is in the good direction
15
+ if (reserveOutFic * priceAverageIn > reserveInFic * priceAverageOut) {
16
+ // pre-compute all operands
17
+ const feesTotalReversed = constants_1.FEES_BASE - feesLP - feesPool;
18
+ const toSub = reserveInFic * (constants_1.FEES_BASE + feesTotalReversed - feesPool);
19
+ const toDiv = (feesTotalReversed + feesLP) * 2n;
20
+ const inSqrt = ((reserveInFic * reserveOutFic * 4n) / priceAverageOut) *
21
+ priceAverageIn *
22
+ feesTotalReversed *
23
+ (constants_1.FEES_BASE - feesPool) +
24
+ reserveInFic * reserveInFic * feesLP * feesLP;
25
+ // reverse sqrt check to only compute sqrt if really needed
26
+ if (inSqrt < (amountIn * toDiv + toSub) ** 2n) {
27
+ firstAmountIn = ((0, utils_1.sqrt)(inSqrt) - toSub) / toDiv;
28
+ }
29
+ }
30
+ return firstAmountIn;
31
+ }
32
+ // compute first trade amountOut using arbitrage feature
33
+ function computeFirstTradeQtyOut(amountOut, reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut, feesLP, feesPool) {
34
+ // default value
35
+ let firstAmountOut = amountOut;
36
+ // if trade is in the good direction
37
+ if (reserveOutFic * priceAverageIn > reserveInFic * priceAverageOut) {
38
+ // pre-compute all operands
39
+ const feesTotalReversed = constants_1.FEES_BASE - feesLP - feesPool;
40
+ const reserveOutFicPredictedFees = (reserveInFic * feesLP * priceAverageOut) / priceAverageIn;
41
+ const toAdd = reserveOutFic * feesTotalReversed * 2n + reserveOutFicPredictedFees;
42
+ const toDiv = feesTotalReversed * 2n;
43
+ const inSqrt = (reserveOutFic *
44
+ reserveOutFicPredictedFees *
45
+ 4n *
46
+ feesTotalReversed *
47
+ (constants_1.FEES_BASE - feesPool)) /
48
+ feesLP +
49
+ reserveOutFicPredictedFees ** 2n;
50
+ // reverse sqrt check to only compute sqrt if really needed
51
+ if (inSqrt > (toAdd - amountOut * toDiv) ** 2n) {
52
+ firstAmountOut = (toAdd - (0, utils_1.sqrt)(inSqrt)) / toDiv;
53
+ }
54
+ }
55
+ return firstAmountOut;
56
+ }
57
+ // apply uniswap k const rule. amountIn -> amountOut
58
+ // return [amountOut, newResIn, newResOut, newResInFic, newResOutFic]
59
+ function applyKConstRuleOut(amountIn, reserveIn, reserveOut, reserveInFic, reserveOutFic, feesLP, feesPool) {
60
+ // k const rule
61
+ const feesTotalReversed = constants_1.FEES_BASE - feesLP - feesPool;
62
+ const amountInWithFee = amountIn * feesTotalReversed;
63
+ const numerator = amountInWithFee * reserveOutFic;
64
+ const denominator = reserveInFic * constants_1.FEES_BASE + amountInWithFee;
65
+ if (denominator === 0n) {
66
+ throw new errors_1.default('SMARDEX_K_ERROR');
67
+ }
68
+ const amountOut = numerator / denominator;
69
+ // update new reserves and add lp-fees to pools
70
+ const amountInWithFeeLp = (amountIn * feesLP + amountInWithFee) / constants_1.FEES_BASE;
71
+ const newResIn = reserveIn + amountInWithFeeLp;
72
+ const newResInFic = reserveInFic + amountInWithFeeLp;
73
+ const newResOut = reserveOut - amountOut;
74
+ const newResOutFic = reserveOutFic - amountOut;
75
+ return [amountOut, newResIn, newResOut, newResInFic, newResOutFic];
76
+ }
77
+ // apply uniswap k const rule. amountOut -> amountIn
78
+ // returns [amountIn, newResIn, newResOut, newResInFic, newResOutFic]
79
+ function applyKConstRuleIn(amountOut, reserveIn, reserveOut, reserveInFic, reserveOutFic, feesLP, feesPool) {
80
+ // k const rule
81
+ const feesTotalReversed = constants_1.FEES_BASE - feesLP - feesPool;
82
+ const numerator = reserveInFic * amountOut * constants_1.FEES_BASE;
83
+ const denominator = (reserveOutFic - amountOut) * feesTotalReversed;
84
+ if (denominator === 0n) {
85
+ throw new errors_1.default('SMARDEX_K_ERROR');
86
+ }
87
+ const amountIn = numerator / denominator + 1n;
88
+ // update new reserves
89
+ const amountInWithFeeLp = ((feesTotalReversed + feesLP) * amountIn) / constants_1.FEES_BASE;
90
+ const newResIn = reserveIn + amountInWithFeeLp;
91
+ const newResInFic = reserveInFic + amountInWithFeeLp;
92
+ const newResOut = reserveOut - amountOut;
93
+ const newResOutFic = reserveOutFic - amountOut;
94
+ return [amountIn, newResIn, newResOut, newResInFic, newResOutFic];
95
+ }
96
+ /**
97
+ * Compute fictive reserves based on current reserves state
98
+ *
99
+ * @param {bigint} reserveIn the reserves of input token.
100
+ * @param {bigint} reserveOut the reserves of output token.
101
+ * @param {bigint} reserveInFic the fictive reserves of input token.
102
+ * @param {bigint} reserveOutFic the fictive reserves of output token.
103
+ * @returns {Array} [ficIn, ficOut]
104
+ */
105
+ function computeReserveFic(reserveIn, reserveOut, reserveInFic, reserveOutFic) {
106
+ if (reserveOut * reserveInFic < reserveIn * reserveOutFic) {
107
+ const temp = (((reserveOut * reserveOut) / reserveOutFic) * reserveInFic) / reserveIn;
108
+ const newResFicIn = (temp * reserveInFic) / reserveOutFic +
109
+ (reserveOut * reserveInFic) / reserveOutFic;
110
+ const newResFicOut = reserveOut + temp;
111
+ return [newResFicIn / 4n, newResFicOut / 4n];
112
+ }
113
+ const newResFicIn = (reserveInFic * reserveOut) / reserveOutFic + reserveIn;
114
+ const newResFicOut = (reserveIn * reserveOutFic) / reserveInFic + reserveOut;
115
+ return [newResFicIn / 4n, newResFicOut / 4n];
116
+ }
117
+ exports.computeReserveFic = computeReserveFic;
118
+ /**
119
+ * Simulate a full trasaction, if you know the "in" token quantity, provide you the "out" and all reserves change
120
+ * Use case: you want to receive exactly amountOut and want to know the exact amountIn to send.
121
+ * @param {bigint} amountIn the desired input amount of the trade.
122
+ * @param {bigint} reserveIn the reserves of input token.
123
+ * @param {bigint} reserveOut the reserves of output token.
124
+ * @param {bigint} reserveInFic the fictive reserves of input token.
125
+ * @param {bigint} reserveOutFic the fictive reserves of output token.
126
+ * @param {bigint} priceAverageIn the price average of input token.
127
+ * @param {bigint} priceAverageOut the price average of output token.
128
+ * @param {bigint} feesLP LP fees
129
+ * @param {bigint} feesPool Pool fees
130
+ * @returns {Array} [amountOut, newResIn, newResOut, newResInFic, newResOutFic]
131
+ */
132
+ function getAmountOut(amountIn, reserveIn, reserveOut, reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut, feesLP, feesPool) {
133
+ // if (amountIn <= 0n) {
134
+ // throw new SmardexError('INSUFFICIENT_INPUT_AMOUNT');
135
+ // }
136
+ if (reserveIn <= 0n || reserveOut <= 0n) {
137
+ throw new errors_1.default('INSUFFICIENT_LIQUIDITY');
138
+ }
139
+ if (reserveInFic <= 0n || reserveOutFic <= 0n) {
140
+ throw new errors_1.default('INSUFFICIENT_LIQUIDITY');
141
+ }
142
+ if (priceAverageIn <= 0n || priceAverageOut <= 0n) {
143
+ throw new errors_1.default('INSUFFICIENT_PRICE_AVERAGE');
144
+ }
145
+ let reserveInFicUpdated = reserveInFic;
146
+ let reserveOutFicUpdated = reserveOutFic;
147
+ const feesTotalReversed = constants_1.FEES_BASE - feesLP - feesPool;
148
+ const amountWithFees = (amountIn * feesTotalReversed) / constants_1.FEES_BASE;
149
+ const firstAmount = computeFirstTradeQtyIn(amountWithFees, reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut, feesLP, feesPool);
150
+ // if there are 2 trades: 1st trade mustn't re-compute ReserveFic, 2nd should
151
+ if (firstAmount === amountWithFees &&
152
+ (0, utils_1.ratioApproxEq)(reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut)) {
153
+ [reserveInFicUpdated, reserveOutFicUpdated] = computeReserveFic(reserveIn, reserveOut, reserveInFic, reserveOutFic);
154
+ }
155
+ // avoid K constant division by 0
156
+ if (reserveInFicUpdated <= 0n) {
157
+ return [
158
+ 0n,
159
+ reserveIn,
160
+ reserveOut,
161
+ reserveInFicUpdated,
162
+ reserveOutFicUpdated,
163
+ ];
164
+ }
165
+ const firstAmountNoFees = (firstAmount * constants_1.FEES_BASE) / feesTotalReversed;
166
+ let [amountOut, newResIn, newResOut, newResInFic, newResOutFic] = applyKConstRuleOut(firstAmountNoFees, reserveIn, reserveOut, reserveInFicUpdated, reserveOutFicUpdated, feesLP, feesPool);
167
+ // if we need a second trade
168
+ if (firstAmount < amountWithFees && firstAmountNoFees < amountIn) {
169
+ [newResInFic, newResOutFic] = computeReserveFic(newResIn, newResOut, newResInFic, newResOutFic);
170
+ // Avoid K constant division by 0
171
+ if (newResInFic <= 0n) {
172
+ return [
173
+ 0n,
174
+ reserveIn,
175
+ reserveOut,
176
+ reserveInFicUpdated,
177
+ reserveOutFicUpdated,
178
+ ];
179
+ }
180
+ let secondAmountOutNoFees;
181
+ [secondAmountOutNoFees, newResIn, newResOut, newResInFic, newResOutFic] =
182
+ applyKConstRuleOut(amountIn - firstAmountNoFees, newResIn, newResOut, newResInFic, newResOutFic, feesLP, feesPool);
183
+ amountOut += secondAmountOutNoFees;
184
+ }
185
+ if (newResIn <= 0n ||
186
+ newResOut <= 0n ||
187
+ newResInFic <= 0n ||
188
+ newResOutFic <= 0n) {
189
+ throw new errors_1.default('INSUFFICIENT_LIQUIDITY');
190
+ }
191
+ return [amountOut, newResIn, newResOut, newResInFic, newResOutFic];
192
+ }
193
+ exports.getAmountOut = getAmountOut;
194
+ /**
195
+ * Simulate a full transaction, if you know the "out" token quantity, provide you the "in" and all reserves change
196
+ * Use case: you want to receive exactly amountOut and want to know the exact amountIn to send.
197
+ * @param {bigint} amountOut the desired output amount of the trade.
198
+ * @param {bigint} reserveIn the reserves of input token.
199
+ * @param {bigint} reserveOut the reserves of output token.
200
+ * @param {bigint} reserveInFic the fictive reserves of input token.
201
+ * @param {bigint} reserveOutFic the fictive reserves of output token.
202
+ * @param {bigint} priceAverageIn the price average of input token.
203
+ * @param {bigint} priceAverageOut the price average of output token.
204
+ * @param {bigint} feesLP LP fees
205
+ * @param {bigint} feesPool Pool fees
206
+ * @returns {Array} [amountIn, newResIn, newResOut, newResInFic, newResOutFic]
207
+ */
208
+ function getAmountIn(amountOut, reserveIn, reserveOut, reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut, feesLP, feesPool) {
209
+ // if (amountOut <= 0n) {
210
+ // throw new SmardexError('INSUFFICIENT_OUTPUT_AMOUNT');
211
+ // }
212
+ if (reserveIn <= 0n || reserveOut <= 0n) {
213
+ throw new errors_1.default('INSUFFICIENT_LIQUIDITY');
214
+ }
215
+ if (reserveInFic <= 0n || reserveOutFic <= 0n) {
216
+ throw new errors_1.default('INSUFFICIENT_LIQUIDITY');
217
+ }
218
+ if (priceAverageIn <= 0n || priceAverageOut <= 0n) {
219
+ throw new errors_1.default('INSUFFICIENT_PRICE_AVERAGE');
220
+ }
221
+ let reserveInFicUpdated = reserveInFic;
222
+ let reserveOutFicUpdated = reserveOutFic;
223
+ const firstAmount = computeFirstTradeQtyOut(amountOut, reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut, feesLP, feesPool);
224
+ // if there are 2 trades: 1st trade mustn't re-compute ReserveFic, 2nd should
225
+ if (firstAmount === amountOut &&
226
+ (0, utils_1.ratioApproxEq)(reserveInFic, reserveOutFic, priceAverageIn, priceAverageOut)) {
227
+ [reserveInFicUpdated, reserveOutFicUpdated] = computeReserveFic(reserveIn, reserveOut, reserveInFic, reserveOutFic);
228
+ }
229
+ if (
230
+ // Avoid K constant division by 0
231
+ reserveInFic <= 0n ||
232
+ // Avoid finding an amountIn for an exact amountOut that is equal to 0
233
+ amountOut <= 0n) {
234
+ return [
235
+ BigInt('0'),
236
+ reserveIn,
237
+ reserveOut,
238
+ reserveInFicUpdated,
239
+ reserveOutFicUpdated,
240
+ ];
241
+ }
242
+ let [amountIn, newResIn, newResOut, newResInFic, newResOutFic] = applyKConstRuleIn(firstAmount, reserveIn, reserveOut, reserveInFicUpdated, reserveOutFicUpdated, feesLP, feesPool);
243
+ // if we need a second trade
244
+ if (firstAmount < amountOut) {
245
+ // in the second trade ALWAYS recompute fictive reserves
246
+ [newResInFic, newResOutFic] = computeReserveFic(newResIn, newResOut, newResInFic, newResOutFic);
247
+ // Avoid K constant division by 0
248
+ if (newResInFic <= 0n) {
249
+ return [
250
+ BigInt('0'),
251
+ reserveIn,
252
+ reserveOut,
253
+ reserveInFicUpdated,
254
+ reserveOutFicUpdated,
255
+ ];
256
+ }
257
+ let secondAmountIn;
258
+ [secondAmountIn, newResIn, newResOut, newResInFic, newResOutFic] =
259
+ applyKConstRuleIn(amountOut - firstAmount, newResIn, newResOut, newResInFic, newResOutFic, feesLP, feesPool);
260
+ amountIn += secondAmountIn;
261
+ }
262
+ if (newResIn <= 0n ||
263
+ newResOut <= 0n ||
264
+ newResInFic <= 0n ||
265
+ newResOutFic <= 0n) {
266
+ throw new errors_1.default('INSUFFICIENT_LIQUIDITY');
267
+ }
268
+ return [amountIn, newResIn, newResOut, newResInFic, newResOutFic];
269
+ }
270
+ exports.getAmountIn = getAmountIn;
271
+ /**
272
+ * Computes the priceAverageIn and priceAverageOut.
273
+ * Use case: you want to send an exact amount of tokenIn and know exactly how much you it will give you of tokenOut.
274
+ * Price averages are modified only if current timestamp does not match last timestamp
275
+ * @param {bigint} reserveFicIn the fictuve reserves of input token.
276
+ * @param {bigint} reserveFicOut the fictuve reserves of output token.
277
+ * @param {number} priceAverageLastTimestamp last timestamp in seconds of price average values.
278
+ * @param {bigint} priceAverageIn the latest price average of input token.
279
+ * @param {bigint} priceAverageOut the latest price average of output token.
280
+ * @param {number} currentTimestampInSecond current timestamp in seconds.
281
+ * @param {number} maxBlockDiffSeconds: Max block difference in seconds
282
+ * @returns {Array} [priceAverageIn, priceAverageOut]
283
+ */
284
+ function getUpdatedPriceAverage(reserveFicIn, reserveFicOut, priceAverageLastTimestamp, priceAverageIn, priceAverageOut, currentTimestampInSecond, maxBlockDiffSeconds) {
285
+ if (currentTimestampInSecond < priceAverageLastTimestamp) {
286
+ throw new errors_1.default('INVALID_TIMESTAMP', 'SmarDexError');
287
+ }
288
+ // very first time
289
+ if (priceAverageLastTimestamp === 0 ||
290
+ priceAverageIn === 0n ||
291
+ priceAverageOut === 0n) {
292
+ return [reserveFicIn, reserveFicOut];
293
+ }
294
+ // another tx has been done in the same block
295
+ if (priceAverageLastTimestamp === currentTimestampInSecond) {
296
+ return [priceAverageIn, priceAverageOut];
297
+ }
298
+ // need to compute new linear-average price
299
+ // compute new price:
300
+ const timeDiff = Math.min(currentTimestampInSecond - priceAverageLastTimestamp, maxBlockDiffSeconds);
301
+ const priceAverageInRet = reserveFicIn;
302
+ const priceAverageOutRet = ((priceAverageOut *
303
+ priceAverageInRet *
304
+ BigInt(maxBlockDiffSeconds - timeDiff)) /
305
+ priceAverageIn +
306
+ reserveFicOut * BigInt(timeDiff)) /
307
+ BigInt(maxBlockDiffSeconds);
308
+ return [priceAverageInRet, priceAverageOutRet];
309
+ }
310
+ exports.getUpdatedPriceAverage = getUpdatedPriceAverage;
311
+ /**
312
+ * Computes the amount of tokenOut, at the precision of 1 wei.
313
+ * Use case: you want to send an exact amount of tokenIn and know exactly how much you it will give you of tokenOut.
314
+ * WARNING: token0 and token1 are pair tokens which addresses hexadecimal's values are sorted as token0 < token1.
315
+ * @param {string} token0 the currency address of token0.
316
+ * @param {string} token1 the currency address of token1.
317
+ * @param {bigint} reserve0 the reserves of token0.
318
+ * @param {bigint} reserve1 the reserves of token1.
319
+ * @param {bigint} reserve0Fic the fictionnal reserves of token0.
320
+ * @param {bigint} reserve1Fic the fictionnal reserves of token1.
321
+ * @param {bigint} tokenAmountIn the input amount of the trade.
322
+ * @param {bigint} tokenAddressIn address of the input token.
323
+ * @param {number} priceAverageLastTimestamp: timestamp in seconds of the latest price average.
324
+ * @param {bigint} priceAverage0 latest price average of token0.
325
+ * @param {bigint} priceAverage1 latest price average of token1.
326
+ * @param {bigint} feesLP LP fees
327
+ * @param {bigint} feesPool Pool fees
328
+ * @param {number} forcedPriceAverageTimestamp: current timestamp or timestamp of the trade in seconds.
329
+ * @param {number} maxBlockDiffSeconds: Max block difference in seconds
330
+ * @returns {Object} { currency, amount, amountMax, newResIn, newResOut, newResInFic, newResOutFic }
331
+ */
332
+ function computeAmountOut(token0, token1, reserve0, reserve1, reserve0Fic, reserve1Fic, tokenAmountIn, tokenAddressIn, priceAverageLastTimestamp, priceAverage0, priceAverage1, feesLP, feesPool, forcedPriceAverageTimestamp = Math.ceil(Date.now() / 1000) +
333
+ constants_1.LATENCY_OFFSET_SECONDS, maxBlockDiffSeconds = 300) {
334
+ if (tokenAddressIn === token0) {
335
+ const [newPriceAverage0, newPriceAverage1] = getUpdatedPriceAverage(reserve0Fic, reserve1Fic, priceAverageLastTimestamp, priceAverage0, priceAverage1, forcedPriceAverageTimestamp, maxBlockDiffSeconds);
336
+ const [amountOut, newRes0, newRes1, newRes0Fic, newRes1Fic] = getAmountOut(tokenAmountIn, reserve0, reserve1, reserve0Fic, reserve1Fic, newPriceAverage0, newPriceAverage1, feesLP, feesPool);
337
+ // const [amountMax] = getAmountOut(
338
+ // tokenAmountIn,
339
+ // reserve0,
340
+ // reserve1,
341
+ // reserve0Fic.sub(1).lt(0) ? reserve0Fic : reserve0Fic.sub(1),
342
+ // reserve1Fic,
343
+ // newPriceAverage0,
344
+ // newPriceAverage1,
345
+ // );
346
+ return {
347
+ currency: token1,
348
+ amount: amountOut,
349
+ amountMax: amountOut,
350
+ newRes0,
351
+ newRes1,
352
+ newRes0Fic,
353
+ newRes1Fic,
354
+ newPriceAverage0,
355
+ newPriceAverage1,
356
+ };
357
+ }
358
+ // token1 is tokenIn
359
+ const [newPriceAverage1, newPriceAverage0] = getUpdatedPriceAverage(reserve1Fic, reserve0Fic, priceAverageLastTimestamp, priceAverage1, priceAverage0, forcedPriceAverageTimestamp, maxBlockDiffSeconds);
360
+ const [amountOut, newRes1, newRes0, newRes1Fic, newRes0Fic] = getAmountOut(tokenAmountIn, reserve1, reserve0, reserve1Fic, reserve0Fic, newPriceAverage1, newPriceAverage0, feesLP, feesPool);
361
+ // const [amountMax] = getAmountOut(
362
+ // tokenAmountIn,
363
+ // reserve1,
364
+ // reserve0,
365
+ // reserve1Fic.sub(1).lt(0) ? reserve1Fic : reserve1Fic.sub(1),
366
+ // reserve0Fic,
367
+ // newPriceAverage1,
368
+ // newPriceAverage0,
369
+ // );
370
+ return {
371
+ currency: token0,
372
+ amount: amountOut,
373
+ amountMax: amountOut,
374
+ newRes0,
375
+ newRes1,
376
+ newRes0Fic,
377
+ newRes1Fic,
378
+ newPriceAverage0,
379
+ newPriceAverage1,
380
+ forcedPriceAverageTimestamp,
381
+ };
382
+ }
383
+ exports.computeAmountOut = computeAmountOut;
384
+ /**
385
+ * Computes the amount of tokenIn, at the precision of 1 wei.
386
+ * Use case: you want to receive exactly tokenOut amount and want to know the exact tokenIn amount to send.
387
+ * WARNING: token0 and token1 are pair tokens which addresses hexadecimal's values are sorted as token0 < token1.
388
+ * @param {string} token0 the currency address of token0.
389
+ * @param {string} token1 the currency address of token1.
390
+ * @param {bigint} reserve0 the reserves of token0.
391
+ * @param {bigint} reserve1 the reserves of token1.
392
+ * @param {bigint} reserve0Fic the fictionnal reserves of token0.
393
+ * @param {bigint} reserve1Fic the fictionnal reserves of token1.
394
+ * @param {bigint} tokenAmountOut the output amount of the trade.
395
+ * @param {bigint} tokenAddressOut address of the output token.
396
+ * @param {number} priceAverageLastTimestamp timestamp in seconds of the latest price average.
397
+ * @param {bigint} priceAverage0 latest price average of token0.
398
+ * @param {bigint} priceAverage1 latest price average of token1.
399
+ * @param {bigint} feesLP LP fees
400
+ * @param {bigint} feesPool Pool fees
401
+ * @param {number} forcedPriceAverageTimestamp current timestamp or timestamp of the trade in seconds.
402
+ * @param {number} maxBlockDiffSeconds: Max block difference in seconds
403
+ * @returns {Object} { currency, amount, amountMax, newResIn, newResOut, newResInFic, newResOutFic }
404
+ */
405
+ function computeAmountIn(token0, token1, reserve0, reserve1, reserve0Fic, reserve1Fic, tokenAmountOut, tokenAddressOut, priceAverageLastTimestamp, priceAverage0, priceAverage1, feesLP, feesPool, forcedPriceAverageTimestamp = Math.ceil(Date.now() / 1000) +
406
+ constants_1.LATENCY_OFFSET_SECONDS, maxBlockDiffSeconds = 300) {
407
+ if (tokenAddressOut === token0) {
408
+ const [newPriceAverage1, newPriceAverage0] = getUpdatedPriceAverage(reserve1Fic, reserve0Fic, priceAverageLastTimestamp, priceAverage1, priceAverage0, forcedPriceAverageTimestamp, maxBlockDiffSeconds);
409
+ const [amountIn, newRes1, newRes0, newRes1Fic, newRes0Fic] = getAmountIn(tokenAmountOut, reserve1, reserve0, reserve1Fic, reserve0Fic, newPriceAverage1, newPriceAverage0, feesLP, feesPool);
410
+ // const [amountMax] = getAmountIn(
411
+ // tokenAmountOut,
412
+ // reserve1,
413
+ // reserve0,
414
+ // reserve1Fic,
415
+ // reserve0Fic.sub(1).lt(0) ? reserve0Fic : reserve0Fic.sub(1),
416
+ // newPriceAverage1,
417
+ // newPriceAverage0,
418
+ // );
419
+ return {
420
+ currency: token1,
421
+ amount: amountIn,
422
+ amountMax: amountIn,
423
+ newRes0,
424
+ newRes1,
425
+ newRes0Fic,
426
+ newRes1Fic,
427
+ newPriceAverage0,
428
+ newPriceAverage1,
429
+ };
430
+ }
431
+ // token1 is tokenOut
432
+ const [newPriceAverage0, newPriceAverage1] = getUpdatedPriceAverage(reserve0Fic, reserve1Fic, priceAverageLastTimestamp, priceAverage0, priceAverage1, forcedPriceAverageTimestamp, maxBlockDiffSeconds);
433
+ const [amountIn, newRes0, newRes1, newRes0Fic, newRes1Fic] = getAmountIn(tokenAmountOut, reserve0, reserve1, reserve0Fic, reserve1Fic, newPriceAverage0, newPriceAverage1, feesLP, feesPool);
434
+ // const [amountMax] = getAmountIn(
435
+ // tokenAmountOut,
436
+ // reserve0,
437
+ // reserve1,
438
+ // reserve0Fic,
439
+ // reserve1Fic.sub(1).lt(0) ? reserve1Fic : reserve1Fic.sub(1),
440
+ // newPriceAverage0,
441
+ // newPriceAverage1,
442
+ // );
443
+ return {
444
+ currency: token0,
445
+ amount: amountIn,
446
+ amountMax: amountIn,
447
+ newRes0,
448
+ newRes1,
449
+ newRes0Fic,
450
+ newRes1Fic,
451
+ newPriceAverage0,
452
+ newPriceAverage1,
453
+ forcedPriceAverageTimestamp,
454
+ };
455
+ }
456
+ exports.computeAmountIn = computeAmountIn;
457
+ /**
458
+ * Extracts the token addresses composing the route ordered in the route's direction starting with inputCurrency.
459
+ * @param {Pair[]} pairs array of pairs composing the trade.
460
+ * @param {string} inputCurrency the currency from which the route starts.
461
+ * @return {string[]} Array of token addresses composing the route ordered in the route's direction starting with inputCurrency.
462
+ */
463
+ function getPathFromInput(pairs, inputCurrency) {
464
+ const path = [];
465
+ for (let i = 0; i < pairs.length; i += 1) {
466
+ const pairCurrencyIn = path.length === 0 ? inputCurrency : path[path.length - 1];
467
+ const [tokenIn, tokenOut] = pairCurrencyIn === pairs[i].token0
468
+ ? [pairs[i].token0, pairs[i].token1]
469
+ : [pairs[i].token1, pairs[i].token0];
470
+ if (path.length === 0) {
471
+ path.push(tokenIn);
472
+ }
473
+ path.push(tokenOut);
474
+ }
475
+ return path;
476
+ }
477
+ exports.getPathFromInput = getPathFromInput;
478
+ /**
479
+ * Extracts the token addresses composing the route ordered in the route's direction ending with outputCurrency.
480
+ * @param {Pair[]} pairs array of pairs composing the trade.
481
+ * @param {string} outputCurrency the currency for which the route finishes.
482
+ * @return {string[]} Array of token addresses composing the route ordered in the route's direction ending with outputCurrency.
483
+ */
484
+ function getPathFromOutput(pairs, outputCurrency) {
485
+ const path = [];
486
+ for (let i = pairs.length - 1; i >= 0; i -= 1) {
487
+ const pairCurrencyOut = path.length === 0 ? outputCurrency : path[path.length - 1];
488
+ const [tokenOut, tokenIn] = pairCurrencyOut === pairs[i].token0
489
+ ? [pairs[i].token0, pairs[i].token1]
490
+ : [pairs[i].token1, pairs[i].token0];
491
+ if (path.length === 0) {
492
+ path.push(tokenOut);
493
+ }
494
+ path.push(tokenIn);
495
+ }
496
+ return path.reverse();
497
+ }
498
+ exports.getPathFromOutput = getPathFromOutput;
499
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../src/dex/smardex/sdk/core.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAgE;AAChE,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CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QAC7C,MAAM,eAAe,GACnB,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC7D,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GACvB,eAAe,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;YACjC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACpC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACrB;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KACpB;IACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC;AAlBD,8CAkBC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * SmardexError class
3
+ *
4
+ * @class SmardexError extends Error
5
+ */
6
+ export default class SmardexError extends Error {
7
+ /**
8
+ * Create SmardexError object
9
+ *
10
+ * @param {string} message - error message
11
+ * @param {string} [errorName=SmarDexSDK] - identifier for the error
12
+ * @returns {SmardexError} SmarDex Error object
13
+ */
14
+ constructor(message: string, errorName?: string);
15
+ }