@paraswap/dex-lib 4.2.3-1 → 4.2.3-2

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 (323) hide show
  1. package/package.json +1 -1
  2. package/build/abi/AaveV1_lending_pool.json +0 -27
  3. package/build/abi/BProtocol.json +0 -1155
  4. package/build/abi/Jarvis.json +0 -1172
  5. package/build/abi/MStableAsset.json +0 -1545
  6. package/build/abi/OneInchLp.json +0 -1304
  7. package/build/abi/Onebit.json +0 -736
  8. package/build/abi/Shell.json +0 -1294
  9. package/build/abi/TraderJoeV2Router.json +0 -50
  10. package/build/abi/inception/inception-ineth-pool.json +0 -1062
  11. package/build/abi/inception/inception-ratio-feed.json +0 -329
  12. package/build/abi/inception/inception-vault.json +0 -991
  13. package/build/abi/platypus/asset.json +0 -490
  14. package/build/abi/platypus/avax-pool.json +0 -820
  15. package/build/abi/platypus/oracle.json +0 -119
  16. package/build/abi/platypus/pool.json +0 -677
  17. package/build/abi/smardex/all/smardex-router.json +0 -648
  18. package/build/abi/smardex/layer-1/smardex-factory.json +0 -242
  19. package/build/abi/smardex/layer-1/smardex-pool.json +0 -506
  20. package/build/abi/smardex/layer-2/smardex-factory.json +0 -185
  21. package/build/abi/smardex/layer-2/smardex-pool.json +0 -578
  22. package/build/abi/swaap-v1/pool.json +0 -1346
  23. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  24. package/build/abi/usual-m-smart-m/usualM.abi.json +0 -483
  25. package/build/abi/wUSDM.json +0 -757
  26. package/build/abi/wombat/pool.json +0 -1289
  27. package/build/abi/zrx.v2.json +0 -1967
  28. package/build/abi/zrx.v3.json +0 -3454
  29. package/build/abi/zrx.v4.json +0 -2193
  30. package/build/dex/OneInchLp.d.ts +0 -24
  31. package/build/dex/OneInchLp.js +0 -43
  32. package/build/dex/OneInchLp.js.map +0 -1
  33. package/build/dex/aave-v1/aave-v1.d.ts +0 -34
  34. package/build/dex/aave-v1/aave-v1.js +0 -181
  35. package/build/dex/aave-v1/aave-v1.js.map +0 -1
  36. package/build/dex/aave-v1/config.d.ts +0 -11
  37. package/build/dex/aave-v1/config.js +0 -20
  38. package/build/dex/aave-v1/config.js.map +0 -1
  39. package/build/dex/aave-v1/tokens-mainnet.json +0 -134
  40. package/build/dex/aave-v1/tokens.d.ts +0 -3
  41. package/build/dex/aave-v1/tokens.js +0 -50
  42. package/build/dex/aave-v1/tokens.js.map +0 -1
  43. package/build/dex/aave-v1/types.d.ts +0 -12
  44. package/build/dex/aave-v1/types.js +0 -3
  45. package/build/dex/aave-v1/types.js.map +0 -1
  46. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  47. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  48. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  49. package/build/dex/bProtocol/bProtocol.d.ts +0 -15
  50. package/build/dex/bProtocol/bProtocol.js +0 -56
  51. package/build/dex/bProtocol/bProtocol.js.map +0 -1
  52. package/build/dex/bProtocol/types.d.ts +0 -11
  53. package/build/dex/bProtocol/types.js +0 -8
  54. package/build/dex/bProtocol/types.js.map +0 -1
  55. package/build/dex/bProtocol.d.ts +0 -18
  56. package/build/dex/bProtocol.js +0 -39
  57. package/build/dex/bProtocol.js.map +0 -1
  58. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +0 -729
  59. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +0 -732
  60. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +0 -1
  61. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +0 -1406
  62. package/build/dex/balancer-v3/abi/balancerRouter.js +0 -1175
  63. package/build/dex/balancer-v3/abi/balancerRouter.js.map +0 -1
  64. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +0 -2081
  65. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +0 -1851
  66. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +0 -1
  67. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +0 -34
  68. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +0 -406
  69. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +0 -1
  70. package/build/dex/bancor.d.ts +0 -26
  71. package/build/dex/bancor.js +0 -58
  72. package/build/dex/bancor.js.map +0 -1
  73. package/build/dex/compound.d.ts +0 -18
  74. package/build/dex/compound.js +0 -46
  75. package/build/dex/compound.js.map +0 -1
  76. package/build/dex/curve-v2.d.ts +0 -58
  77. package/build/dex/curve-v2.js +0 -180
  78. package/build/dex/curve-v2.js.map +0 -1
  79. package/build/dex/dodo-v1.d.ts +0 -33
  80. package/build/dex/dodo-v1.js +0 -63
  81. package/build/dex/dodo-v1.js.map +0 -1
  82. package/build/dex/erc4626/scripts/validate-state.d.ts +0 -0
  83. package/build/dex/erc4626/scripts/validate-state.js +0 -146
  84. package/build/dex/erc4626/scripts/validate-state.js.map +0 -1
  85. package/build/dex/inception/config.d.ts +0 -4
  86. package/build/dex/inception/config.js +0 -109
  87. package/build/dex/inception/config.js.map +0 -1
  88. package/build/dex/inception/inception-event-pool.d.ts +0 -16
  89. package/build/dex/inception/inception-event-pool.js +0 -49
  90. package/build/dex/inception/inception-event-pool.js.map +0 -1
  91. package/build/dex/inception/inception.d.ts +0 -43
  92. package/build/dex/inception/inception.js +0 -180
  93. package/build/dex/inception/inception.js.map +0 -1
  94. package/build/dex/inception/tokens.d.ts +0 -9
  95. package/build/dex/inception/tokens.js +0 -28
  96. package/build/dex/inception/tokens.js.map +0 -1
  97. package/build/dex/inception/types.d.ts +0 -22
  98. package/build/dex/inception/types.js +0 -3
  99. package/build/dex/inception/types.js.map +0 -1
  100. package/build/dex/inception/utils.d.ts +0 -7
  101. package/build/dex/inception/utils.js +0 -58
  102. package/build/dex/inception/utils.js.map +0 -1
  103. package/build/dex/jarvis.d.ts +0 -56
  104. package/build/dex/jarvis.js +0 -163
  105. package/build/dex/jarvis.js.map +0 -1
  106. package/build/dex/lido.d.ts +0 -19
  107. package/build/dex/lido.js +0 -42
  108. package/build/dex/lido.js.map +0 -1
  109. package/build/dex/mStable.d.ts +0 -44
  110. package/build/dex/mStable.js +0 -75
  111. package/build/dex/mStable.js.map +0 -1
  112. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  113. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  114. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  115. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  116. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  117. package/build/dex/onebit/onebit.d.ts +0 -16
  118. package/build/dex/onebit/onebit.js +0 -61
  119. package/build/dex/onebit/onebit.js.map +0 -1
  120. package/build/dex/onebit/types.d.ts +0 -14
  121. package/build/dex/onebit/types.js +0 -8
  122. package/build/dex/onebit/types.js.map +0 -1
  123. package/build/dex/onebit.d.ts +0 -25
  124. package/build/dex/onebit.js +0 -42
  125. package/build/dex/onebit.js.map +0 -1
  126. package/build/dex/platypus/asset.d.ts +0 -14
  127. package/build/dex/platypus/asset.js +0 -97
  128. package/build/dex/platypus/asset.js.map +0 -1
  129. package/build/dex/platypus/config.d.ts +0 -11
  130. package/build/dex/platypus/config.js +0 -69
  131. package/build/dex/platypus/config.js.map +0 -1
  132. package/build/dex/platypus/platypus.d.ts +0 -63
  133. package/build/dex/platypus/platypus.js +0 -487
  134. package/build/dex/platypus/platypus.js.map +0 -1
  135. package/build/dex/platypus/pool-avax.d.ts +0 -8
  136. package/build/dex/platypus/pool-avax.js +0 -54
  137. package/build/dex/platypus/pool-avax.js.map +0 -1
  138. package/build/dex/platypus/pool-base.d.ts +0 -19
  139. package/build/dex/platypus/pool-base.js +0 -86
  140. package/build/dex/platypus/pool-base.js.map +0 -1
  141. package/build/dex/platypus/pool-pure.d.ts +0 -8
  142. package/build/dex/platypus/pool-pure.js +0 -37
  143. package/build/dex/platypus/pool-pure.js.map +0 -1
  144. package/build/dex/platypus/pool-subscriber.d.ts +0 -14
  145. package/build/dex/platypus/pool-subscriber.js +0 -167
  146. package/build/dex/platypus/pool-subscriber.js.map +0 -1
  147. package/build/dex/platypus/pool.d.ts +0 -8
  148. package/build/dex/platypus/pool.js +0 -58
  149. package/build/dex/platypus/pool.js.map +0 -1
  150. package/build/dex/platypus/types.d.ts +0 -92
  151. package/build/dex/platypus/types.js +0 -10
  152. package/build/dex/platypus/types.js.map +0 -1
  153. package/build/dex/quickswap/spiritswap-v3.d.ts +0 -6
  154. package/build/dex/quickswap/spiritswap-v3.js +0 -19
  155. package/build/dex/quickswap/spiritswap-v3.js.map +0 -1
  156. package/build/dex/shell.d.ts +0 -25
  157. package/build/dex/shell.js +0 -41
  158. package/build/dex/shell.js.map +0 -1
  159. package/build/dex/smardex/config.d.ts +0 -4
  160. package/build/dex/smardex/config.js +0 -64
  161. package/build/dex/smardex/config.js.map +0 -1
  162. package/build/dex/smardex/constants.d.ts +0 -18
  163. package/build/dex/smardex/constants.js +0 -33
  164. package/build/dex/smardex/constants.js.map +0 -1
  165. package/build/dex/smardex/sdk/constants.d.ts +0 -6
  166. package/build/dex/smardex/sdk/constants.js +0 -13
  167. package/build/dex/smardex/sdk/constants.js.map +0 -1
  168. package/build/dex/smardex/sdk/core.d.ts +0 -113
  169. package/build/dex/smardex/sdk/core.js +0 -499
  170. package/build/dex/smardex/sdk/core.js.map +0 -1
  171. package/build/dex/smardex/sdk/errors.d.ts +0 -15
  172. package/build/dex/smardex/sdk/errors.js +0 -22
  173. package/build/dex/smardex/sdk/errors.js.map +0 -1
  174. package/build/dex/smardex/sdk/types.d.ts +0 -62
  175. package/build/dex/smardex/sdk/types.js +0 -3
  176. package/build/dex/smardex/sdk/types.js.map +0 -1
  177. package/build/dex/smardex/sdk/utils.d.ts +0 -44
  178. package/build/dex/smardex/sdk/utils.js +0 -133
  179. package/build/dex/smardex/sdk/utils.js.map +0 -1
  180. package/build/dex/smardex/smardex-event-pool.d.ts +0 -28
  181. package/build/dex/smardex/smardex-event-pool.js +0 -119
  182. package/build/dex/smardex/smardex-event-pool.js.map +0 -1
  183. package/build/dex/smardex/smardex.d.ts +0 -65
  184. package/build/dex/smardex/smardex.js +0 -519
  185. package/build/dex/smardex/smardex.js.map +0 -1
  186. package/build/dex/smardex/types.d.ts +0 -55
  187. package/build/dex/smardex/types.js +0 -3
  188. package/build/dex/smardex/types.js.map +0 -1
  189. package/build/dex/smoothy.d.ts +0 -26
  190. package/build/dex/smoothy.js +0 -48
  191. package/build/dex/smoothy.js.map +0 -1
  192. package/build/dex/solidly/forks-override/cone.d.ts +0 -22
  193. package/build/dex/solidly/forks-override/cone.js +0 -53
  194. package/build/dex/solidly/forks-override/cone.js.map +0 -1
  195. package/build/dex/solidly/forks-override/solisnek.d.ts +0 -8
  196. package/build/dex/solidly/forks-override/solisnek.js +0 -15
  197. package/build/dex/solidly/forks-override/solisnek.js.map +0 -1
  198. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  199. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  200. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  201. package/build/dex/stable-pool.d.ts +0 -28
  202. package/build/dex/stable-pool.js +0 -55
  203. package/build/dex/stable-pool.js.map +0 -1
  204. package/build/dex/swaap-v1/config.d.ts +0 -17
  205. package/build/dex/swaap-v1/config.js +0 -56
  206. package/build/dex/swaap-v1/config.js.map +0 -1
  207. package/build/dex/swaap-v1/constants.d.ts +0 -6
  208. package/build/dex/swaap-v1/constants.js +0 -17
  209. package/build/dex/swaap-v1/constants.js.map +0 -1
  210. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +0 -25
  211. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +0 -62
  212. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +0 -1
  213. package/build/dex/swaap-v1/libraries/Const.d.ts +0 -18
  214. package/build/dex/swaap-v1/libraries/Const.js +0 -26
  215. package/build/dex/swaap-v1/libraries/Const.js.map +0 -1
  216. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +0 -77
  217. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +0 -316
  218. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +0 -1
  219. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +0 -75
  220. package/build/dex/swaap-v1/libraries/LogExpMath.js +0 -418
  221. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +0 -1
  222. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +0 -185
  223. package/build/dex/swaap-v1/libraries/MathMMM.js +0 -453
  224. package/build/dex/swaap-v1/libraries/MathMMM.js.map +0 -1
  225. package/build/dex/swaap-v1/libraries/Num.d.ts +0 -31
  226. package/build/dex/swaap-v1/libraries/Num.js +0 -167
  227. package/build/dex/swaap-v1/libraries/Num.js.map +0 -1
  228. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +0 -23
  229. package/build/dex/swaap-v1/libraries/PoolQuotations.js +0 -131
  230. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +0 -1
  231. package/build/dex/swaap-v1/libraries/Struct.d.ts +0 -56
  232. package/build/dex/swaap-v1/libraries/Struct.js +0 -3
  233. package/build/dex/swaap-v1/libraries/Struct.js.map +0 -1
  234. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +0 -45
  235. package/build/dex/swaap-v1/swaap-v1-pool.js +0 -656
  236. package/build/dex/swaap-v1/swaap-v1-pool.js.map +0 -1
  237. package/build/dex/swaap-v1/swaap-v1.d.ts +0 -62
  238. package/build/dex/swaap-v1/swaap-v1.js +0 -383
  239. package/build/dex/swaap-v1/swaap-v1.js.map +0 -1
  240. package/build/dex/swaap-v1/types.d.ts +0 -106
  241. package/build/dex/swaap-v1/types.js +0 -9
  242. package/build/dex/swaap-v1/types.js.map +0 -1
  243. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
  244. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
  245. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
  246. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  247. package/build/dex/trader-joe-v2.1.js +0 -79
  248. package/build/dex/trader-joe-v2.1.js.map +0 -1
  249. package/build/dex/trader-joe-v2.d.ts +0 -40
  250. package/build/dex/trader-joe-v2.js +0 -74
  251. package/build/dex/trader-joe-v2.js.map +0 -1
  252. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  253. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  254. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  255. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  256. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  257. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  258. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +0 -4
  259. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +0 -43
  260. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +0 -1
  261. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +0 -1
  262. package/build/dex/uniswap-v3/uniswap-v3-worker.js +0 -10
  263. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +0 -1
  264. package/build/dex/usual/usual-m-smart-m.d.ts +0 -17
  265. package/build/dex/usual/usual-m-smart-m.js +0 -50
  266. package/build/dex/usual/usual-m-smart-m.js.map +0 -1
  267. package/build/dex/usual-bond/config.d.ts +0 -3
  268. package/build/dex/usual-bond/config.js +0 -13
  269. package/build/dex/usual-bond/config.js.map +0 -1
  270. package/build/dex/usual-bond/types.d.ts +0 -7
  271. package/build/dex/usual-bond/types.js +0 -3
  272. package/build/dex/usual-bond/types.js.map +0 -1
  273. package/build/dex/usual-bond/usual-bond.d.ts +0 -35
  274. package/build/dex/usual-bond/usual-bond.js +0 -176
  275. package/build/dex/usual-bond/usual-bond.js.map +0 -1
  276. package/build/dex/usual-m-smart-m/config.d.ts +0 -3
  277. package/build/dex/usual-m-smart-m/config.js +0 -13
  278. package/build/dex/usual-m-smart-m/config.js.map +0 -1
  279. package/build/dex/usual-m-smart-m/types.d.ts +0 -7
  280. package/build/dex/usual-m-smart-m/types.js +0 -3
  281. package/build/dex/usual-m-smart-m/types.js.map +0 -1
  282. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +0 -35
  283. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +0 -161
  284. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +0 -1
  285. package/build/dex/usual-m-usd0/config.d.ts +0 -3
  286. package/build/dex/usual-m-usd0/config.js +0 -14
  287. package/build/dex/usual-m-usd0/config.js.map +0 -1
  288. package/build/dex/usual-m-usd0/types.d.ts +0 -8
  289. package/build/dex/usual-m-usd0/types.js +0 -3
  290. package/build/dex/usual-m-usd0/types.js.map +0 -1
  291. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +0 -35
  292. package/build/dex/usual-m-usd0/usual-m-usd0.js +0 -159
  293. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +0 -1
  294. package/build/dex/wusdm/config.d.ts +0 -3
  295. package/build/dex/wusdm/config.js +0 -43
  296. package/build/dex/wusdm/config.js.map +0 -1
  297. package/build/dex/wusdm/constants.d.ts +0 -2
  298. package/build/dex/wusdm/constants.js +0 -6
  299. package/build/dex/wusdm/constants.js.map +0 -1
  300. package/build/dex/wusdm/types.d.ts +0 -18
  301. package/build/dex/wusdm/types.js +0 -11
  302. package/build/dex/wusdm/types.js.map +0 -1
  303. package/build/dex/wusdm/wusdm-pool.d.ts +0 -21
  304. package/build/dex/wusdm/wusdm-pool.js +0 -74
  305. package/build/dex/wusdm/wusdm-pool.js.map +0 -1
  306. package/build/dex/wusdm/wusdm.d.ts +0 -46
  307. package/build/dex/wusdm/wusdm.js +0 -243
  308. package/build/dex/wusdm/wusdm.js.map +0 -1
  309. package/build/dex/zerox/config.d.ts +0 -2
  310. package/build/dex/zerox/config.js +0 -33
  311. package/build/dex/zerox/config.js.map +0 -1
  312. package/build/dex/zerox/index.d.ts +0 -22
  313. package/build/dex/zerox/index.js +0 -225
  314. package/build/dex/zerox/index.js.map +0 -1
  315. package/build/dex/zerox/order.d.ts +0 -88
  316. package/build/dex/zerox/order.js +0 -53
  317. package/build/dex/zerox/order.js.map +0 -1
  318. package/build/dex/zerox/types.d.ts +0 -73
  319. package/build/dex/zerox/types.js +0 -21
  320. package/build/dex/zerox/types.js.map +0 -1
  321. /package/build/dex/uniswap-v4/contract-math/{TickBitmap.d.ts → TickBitMap.d.ts} +0 -0
  322. /package/build/dex/uniswap-v4/contract-math/{TickBitmap.js → TickBitMap.js} +0 -0
  323. /package/build/dex/uniswap-v4/contract-math/{TickBitmap.js.map → TickBitMap.js.map} +0 -0
@@ -1,499 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../src/dex/smardex/sdk/core.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAgE;AAChE,mCAA8C;AAC9C,sDAAoC;AAGpC,uDAAuD;AACvD,SAAS,sBAAsB,CAC7B,QAAgB,EAChB,YAAoB,EACpB,aAAqB,EACrB,cAAsB,EACtB,eAAuB,EACvB,MAAc,EACd,QAAgB;IAEhB,gBAAgB;IAChB,IAAI,aAAa,GAAG,QAAQ,CAAC;IAE7B,oCAAoC;IACpC,IAAI,aAAa,GAAG,cAAc,GAAG,YAAY,GAAG,eAAe,EAAE;QACnE,2BAA2B;QAC3B,MAAM,iBAAiB,GAAG,qBAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;QACxD,MAAM,KAAK,GAAG,YAAY,GAAG,CAAC,qBAAS,GAAG,iBAAiB,GAAG,QAAQ,CAAC,CAAC;QACxE,MAAM,KAAK,GAAG,CAAC,iBAAiB,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QAChD,MAAM,MAAM,GACV,CAAC,CAAC,YAAY,GAAG,aAAa,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC;YACrD,cAAc;YACd,iBAAiB;YACjB,CAAC,qBAAS,GAAG,QAAQ,CAAC;YACxB,YAAY,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;QAEhD,2DAA2D;QAC3D,IAAI,MAAM,GAAG,CAAC,QAAQ,GAAG,KAAK,GAAG,KAAK,CA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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
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * SmardexError class
5
- *
6
- * @class SmardexError extends Error
7
- */
8
- class SmardexError extends Error {
9
- /**
10
- * Create SmardexError object
11
- *
12
- * @param {string} message - error message
13
- * @param {string} [errorName=SmarDexSDK] - identifier for the error
14
- * @returns {SmardexError} SmarDex Error object
15
- */
16
- constructor(message, errorName = 'SmarDexSDK') {
17
- super(message);
18
- this.name = errorName;
19
- }
20
- }
21
- exports.default = SmardexError;
22
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/dex/smardex/sdk/errors.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,MAAqB,YAAa,SAAQ,KAAK;IAC7C;;;;;;OAMG;IACH,YAAY,OAAe,EAAE,SAAS,GAAG,YAAY;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF;AAZD,+BAYC"}
@@ -1,62 +0,0 @@
1
- import { TradeType } from './constants';
2
- export interface Pair {
3
- address?: string;
4
- token0: string;
5
- token1: string;
6
- reserve0: bigint;
7
- reserve1: bigint;
8
- reserve0LastFictive: bigint;
9
- reserve1LastFictive: bigint;
10
- priceAverageLastTimestamp: number;
11
- priceAverage0: bigint;
12
- priceAverage1: bigint;
13
- forcedPriceAverageTimestamp?: number;
14
- prevReserveFic0?: bigint;
15
- prevReserveFic1?: bigint;
16
- feesLP: bigint;
17
- feesPool: bigint;
18
- }
19
- export interface CurrencyAmount {
20
- currency: string;
21
- amount: bigint;
22
- amountMax?: bigint;
23
- newRes0?: bigint;
24
- newRes1?: bigint;
25
- newRes0Fic?: bigint;
26
- newRes1Fic?: bigint;
27
- newPriceAverage0?: bigint;
28
- newPriceAverage1?: bigint;
29
- forcedPriceAverageTimestamp?: number;
30
- }
31
- export interface BestTradeOptions {
32
- maxNumResults?: number;
33
- maxHops?: number;
34
- arbitrage?: boolean;
35
- }
36
- export interface Route {
37
- pairs: Pair[];
38
- path: string[];
39
- input: string;
40
- output: string;
41
- }
42
- export interface Trade {
43
- route: Route;
44
- amountIn: CurrencyAmount;
45
- amountOut: CurrencyAmount;
46
- tradeType: TradeType;
47
- priceImpact?: bigint;
48
- gasFeesUSD?: bigint;
49
- amountInUSD?: bigint;
50
- amountOutUSD?: bigint;
51
- }
52
- export interface GasEstimateData {
53
- gasPrice: bigint;
54
- gasQuantitiesFirstHop: number;
55
- gasQuantitiesAdditionalHop: number;
56
- nativeTokenPrice: bigint;
57
- nativeTokenDecimals: number;
58
- inputTokenPrice: bigint;
59
- inputTokenDecimals: number;
60
- outputTokenPrice: bigint;
61
- outputTokenDecimals: number;
62
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/dex/smardex/sdk/types.ts"],"names":[],"mappings":""}