@mento-protocol/mento-sdk 3.2.2 → 3.2.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 (397) hide show
  1. package/dist/cjs/ChainClient.d.ts +9 -0
  2. package/dist/cjs/ChainClient.js +58 -0
  3. package/dist/cjs/TestChainClient.d.ts +7 -0
  4. package/dist/cjs/TestChainClient.js +41 -0
  5. package/dist/cjs/constants/addresses.d.ts +4 -0
  6. package/dist/cjs/constants/addresses.js +59 -0
  7. package/dist/cjs/constants/currencies.d.ts +5 -0
  8. package/dist/cjs/constants/currencies.js +29 -0
  9. package/dist/cjs/constants/index.d.ts +4 -0
  10. package/dist/{services/borrow → cjs/constants}/index.js +4 -4
  11. package/dist/cjs/constants/tokens.11142220.d.ts +2 -0
  12. package/dist/cjs/constants/tokens.11142220.js +128 -0
  13. package/dist/cjs/constants/tokens.42220.d.ts +2 -0
  14. package/dist/cjs/constants/tokens.42220.js +128 -0
  15. package/dist/cjs/constants/tokens.d.ts +65 -0
  16. package/dist/cjs/constants/tokens.js +170 -0
  17. package/dist/cjs/constants/tradablePairs.11142220.d.ts +2 -0
  18. package/dist/cjs/constants/tradablePairs.11142220.js +7391 -0
  19. package/dist/cjs/constants/tradablePairs.42220.d.ts +2 -0
  20. package/dist/cjs/constants/tradablePairs.42220.js +7391 -0
  21. package/dist/cjs/constants/tradablePairs.d.ts +16 -0
  22. package/dist/cjs/constants/tradablePairs.js +53 -0
  23. package/dist/cjs/enums/chainId.d.ts +4 -0
  24. package/dist/{core/constants → cjs/enums}/chainId.js +1 -4
  25. package/dist/cjs/enums/index.d.ts +3 -0
  26. package/dist/{services/liquidity → cjs/enums}/index.js +3 -2
  27. package/dist/cjs/enums/proposalState.d.ts +10 -0
  28. package/dist/cjs/enums/proposalState.js +14 -0
  29. package/dist/cjs/enums/tradingMode.d.ts +17 -0
  30. package/dist/cjs/enums/tradingMode.js +21 -0
  31. package/dist/cjs/governance.d.ts +62 -0
  32. package/dist/cjs/governance.js +151 -0
  33. package/dist/cjs/index.d.ts +7 -0
  34. package/dist/{core/constants → cjs}/index.js +7 -6
  35. package/dist/cjs/interfaces/IChainClient.d.ts +6 -0
  36. package/dist/{core/types/route.js → cjs/interfaces/IChainClient.js} +0 -1
  37. package/dist/cjs/interfaces/index.d.ts +4 -0
  38. package/dist/{core/errors → cjs/interfaces}/index.js +4 -4
  39. package/dist/cjs/interfaces/tradingLimit.d.ts +7 -0
  40. package/dist/{core/types/token.js → cjs/interfaces/tradingLimit.js} +0 -1
  41. package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +10 -0
  42. package/dist/{core/types/borrow.js → cjs/interfaces/tradingLimitsConfig.js} +0 -1
  43. package/dist/cjs/interfaces/tradingLimitsState.d.ts +9 -0
  44. package/dist/{core/types/provider.js → cjs/interfaces/tradingLimitsState.js} +0 -1
  45. package/dist/cjs/limits.d.ts +33 -0
  46. package/dist/cjs/limits.js +130 -0
  47. package/dist/cjs/mento.d.ts +287 -0
  48. package/dist/cjs/mento.js +699 -0
  49. package/dist/{utils → cjs}/routeUtils.d.ts +93 -84
  50. package/dist/{utils → cjs}/routeUtils.js +124 -123
  51. package/dist/cjs/types/contractAddressMap.d.ts +4 -0
  52. package/dist/cjs/types/contractAddressMap.js +2 -0
  53. package/dist/cjs/types/contractAddresses.d.ts +23 -0
  54. package/dist/cjs/types/contractAddresses.js +2 -0
  55. package/dist/cjs/types/index.d.ts +2 -0
  56. package/dist/{services/pools → cjs/types}/index.js +2 -2
  57. package/dist/cjs/utils.d.ts +80 -0
  58. package/dist/cjs/utils.js +177 -0
  59. package/dist/esm/ChainClient.d.ts +9 -0
  60. package/dist/esm/ChainClient.js +54 -0
  61. package/dist/esm/TestChainClient.d.ts +7 -0
  62. package/dist/esm/TestChainClient.js +37 -0
  63. package/dist/esm/constants/addresses.d.ts +4 -0
  64. package/dist/esm/constants/addresses.js +55 -0
  65. package/dist/esm/constants/currencies.d.ts +5 -0
  66. package/dist/esm/constants/currencies.js +26 -0
  67. package/dist/esm/constants/index.d.ts +4 -0
  68. package/dist/esm/constants/index.js +4 -0
  69. package/dist/esm/constants/tokens.11142220.d.ts +2 -0
  70. package/dist/esm/constants/tokens.11142220.js +125 -0
  71. package/dist/esm/constants/tokens.42220.d.ts +2 -0
  72. package/dist/esm/constants/tokens.42220.js +125 -0
  73. package/dist/esm/constants/tokens.d.ts +65 -0
  74. package/dist/esm/constants/tokens.js +142 -0
  75. package/dist/esm/constants/tradablePairs.11142220.d.ts +2 -0
  76. package/dist/esm/constants/tradablePairs.11142220.js +7388 -0
  77. package/dist/esm/constants/tradablePairs.42220.d.ts +2 -0
  78. package/dist/esm/constants/tradablePairs.42220.js +7388 -0
  79. package/dist/esm/constants/tradablePairs.d.ts +16 -0
  80. package/dist/esm/constants/tradablePairs.js +26 -0
  81. package/dist/esm/enums/chainId.d.ts +4 -0
  82. package/dist/esm/{core/constants → enums}/chainId.js +0 -2
  83. package/dist/esm/enums/index.d.ts +3 -0
  84. package/dist/esm/enums/index.js +3 -0
  85. package/dist/esm/enums/proposalState.d.ts +10 -0
  86. package/dist/esm/enums/proposalState.js +11 -0
  87. package/dist/esm/enums/tradingMode.d.ts +17 -0
  88. package/dist/esm/enums/tradingMode.js +18 -0
  89. package/dist/esm/governance.d.ts +62 -0
  90. package/dist/esm/governance.js +147 -0
  91. package/dist/esm/index.d.ts +7 -0
  92. package/dist/esm/index.js +6 -138
  93. package/dist/esm/interfaces/IChainClient.d.ts +6 -0
  94. package/dist/esm/interfaces/index.d.ts +4 -0
  95. package/dist/esm/interfaces/index.js +4 -0
  96. package/dist/esm/interfaces/tradingLimit.d.ts +7 -0
  97. package/dist/esm/interfaces/tradingLimitsConfig.d.ts +10 -0
  98. package/dist/esm/interfaces/tradingLimitsState.d.ts +9 -0
  99. package/dist/esm/limits.d.ts +33 -0
  100. package/dist/esm/limits.js +123 -0
  101. package/dist/esm/mento.d.ts +287 -0
  102. package/dist/esm/mento.js +671 -0
  103. package/dist/esm/routeUtils.d.ts +304 -0
  104. package/dist/esm/{utils/routeUtils.js → routeUtils.js} +116 -115
  105. package/dist/esm/types/contractAddressMap.d.ts +4 -0
  106. package/dist/esm/types/contractAddresses.d.ts +23 -0
  107. package/dist/esm/types/index.d.ts +2 -0
  108. package/dist/esm/types/index.js +2 -0
  109. package/dist/esm/utils.d.ts +80 -0
  110. package/dist/esm/utils.js +162 -0
  111. package/package.json +1 -1
  112. package/dist/cache/routes.d.ts +0 -13
  113. package/dist/cache/routes.js +0 -13733
  114. package/dist/cache/tokens.d.ts +0 -68
  115. package/dist/cache/tokens.js +0 -446
  116. package/dist/core/abis/activePool.d.ts +0 -2
  117. package/dist/core/abis/activePool.js +0 -14
  118. package/dist/core/abis/addressesRegistry.d.ts +0 -2
  119. package/dist/core/abis/addressesRegistry.js +0 -26
  120. package/dist/core/abis/bipoolmanager.d.ts +0 -34
  121. package/dist/core/abis/bipoolmanager.js +0 -72
  122. package/dist/core/abis/borrowerOperations.d.ts +0 -9
  123. package/dist/core/abis/borrowerOperations.js +0 -89
  124. package/dist/core/abis/breakerbox.d.ts +0 -13
  125. package/dist/core/abis/breakerbox.js +0 -8
  126. package/dist/core/abis/broker.d.ts +0 -2
  127. package/dist/core/abis/broker.js +0 -9
  128. package/dist/core/abis/erc20.d.ts +0 -9
  129. package/dist/core/abis/erc20.js +0 -21
  130. package/dist/core/abis/fpmm.d.ts +0 -270
  131. package/dist/core/abis/fpmm.js +0 -49
  132. package/dist/core/abis/fpmmFactory.d.ts +0 -85
  133. package/dist/core/abis/fpmmFactory.js +0 -26
  134. package/dist/core/abis/hintHelpers.d.ts +0 -2
  135. package/dist/core/abis/hintHelpers.js +0 -14
  136. package/dist/core/abis/index.d.ts +0 -22
  137. package/dist/core/abis/index.js +0 -38
  138. package/dist/core/abis/liquidityStrategy.d.ts +0 -132
  139. package/dist/core/abis/liquidityStrategy.js +0 -10
  140. package/dist/core/abis/multiTroveGetter.d.ts +0 -8
  141. package/dist/core/abis/multiTroveGetter.js +0 -15
  142. package/dist/core/abis/priceFeed.d.ts +0 -7
  143. package/dist/core/abis/priceFeed.js +0 -16
  144. package/dist/core/abis/pricingmodule.d.ts +0 -2
  145. package/dist/core/abis/pricingmodule.js +0 -6
  146. package/dist/core/abis/reserve.d.ts +0 -3
  147. package/dist/core/abis/reserve.js +0 -18
  148. package/dist/core/abis/router.d.ts +0 -521
  149. package/dist/core/abis/router.js +0 -45
  150. package/dist/core/abis/sortedTroves.d.ts +0 -2
  151. package/dist/core/abis/sortedTroves.js +0 -15
  152. package/dist/core/abis/systemParams.d.ts +0 -2
  153. package/dist/core/abis/systemParams.js +0 -14
  154. package/dist/core/abis/troveManager.d.ts +0 -2
  155. package/dist/core/abis/troveManager.js +0 -27
  156. package/dist/core/abis/troveNFT.d.ts +0 -2
  157. package/dist/core/abis/troveNFT.js +0 -9
  158. package/dist/core/abis/virtualPool.d.ts +0 -50
  159. package/dist/core/abis/virtualPool.js +0 -11
  160. package/dist/core/abis/virtualPoolFactory.d.ts +0 -59
  161. package/dist/core/abis/virtualPoolFactory.js +0 -17
  162. package/dist/core/constants/addresses.d.ts +0 -18
  163. package/dist/core/constants/addresses.js +0 -113
  164. package/dist/core/constants/borrowConstants.d.ts +0 -10
  165. package/dist/core/constants/borrowConstants.js +0 -16
  166. package/dist/core/constants/borrowRegistries.d.ts +0 -7
  167. package/dist/core/constants/borrowRegistries.js +0 -30
  168. package/dist/core/constants/chainId.d.ts +0 -7
  169. package/dist/core/constants/contractNames.d.ts +0 -21
  170. package/dist/core/constants/contractNames.js +0 -24
  171. package/dist/core/constants/index.d.ts +0 -6
  172. package/dist/core/errors/base.d.ts +0 -8
  173. package/dist/core/errors/base.js +0 -17
  174. package/dist/core/errors/index.d.ts +0 -4
  175. package/dist/core/errors/oracle.d.ts +0 -9
  176. package/dist/core/errors/oracle.js +0 -15
  177. package/dist/core/errors/router.d.ts +0 -14
  178. package/dist/core/errors/router.js +0 -24
  179. package/dist/core/types/borrow.d.ts +0 -87
  180. package/dist/core/types/contractAddresses.d.ts +0 -42
  181. package/dist/core/types/contractAddresses.js +0 -3
  182. package/dist/core/types/index.d.ts +0 -10
  183. package/dist/core/types/index.js +0 -26
  184. package/dist/core/types/liquidity.d.ts +0 -194
  185. package/dist/core/types/liquidity.js +0 -3
  186. package/dist/core/types/pool.d.ts +0 -208
  187. package/dist/core/types/pool.js +0 -14
  188. package/dist/core/types/provider.d.ts +0 -45
  189. package/dist/core/types/route.d.ts +0 -62
  190. package/dist/core/types/token.d.ts +0 -21
  191. package/dist/core/types/tradingLimits.d.ts +0 -91
  192. package/dist/core/types/tradingLimits.js +0 -3
  193. package/dist/core/types/tradingMode.d.ts +0 -24
  194. package/dist/core/types/tradingMode.js +0 -31
  195. package/dist/core/types/transaction.d.ts +0 -45
  196. package/dist/core/types/transaction.js +0 -3
  197. package/dist/esm/cache/routes.js +0 -13728
  198. package/dist/esm/cache/tokens.js +0 -438
  199. package/dist/esm/core/abis/activePool.js +0 -10
  200. package/dist/esm/core/abis/addressesRegistry.js +0 -22
  201. package/dist/esm/core/abis/bipoolmanager.js +0 -68
  202. package/dist/esm/core/abis/borrowerOperations.js +0 -85
  203. package/dist/esm/core/abis/breakerbox.js +0 -4
  204. package/dist/esm/core/abis/broker.js +0 -5
  205. package/dist/esm/core/abis/erc20.js +0 -17
  206. package/dist/esm/core/abis/fpmm.js +0 -45
  207. package/dist/esm/core/abis/fpmmFactory.js +0 -22
  208. package/dist/esm/core/abis/hintHelpers.js +0 -10
  209. package/dist/esm/core/abis/index.js +0 -21
  210. package/dist/esm/core/abis/liquidityStrategy.js +0 -6
  211. package/dist/esm/core/abis/multiTroveGetter.js +0 -11
  212. package/dist/esm/core/abis/priceFeed.js +0 -12
  213. package/dist/esm/core/abis/pricingmodule.js +0 -2
  214. package/dist/esm/core/abis/reserve.js +0 -14
  215. package/dist/esm/core/abis/router.js +0 -41
  216. package/dist/esm/core/abis/sortedTroves.js +0 -11
  217. package/dist/esm/core/abis/systemParams.js +0 -10
  218. package/dist/esm/core/abis/troveManager.js +0 -23
  219. package/dist/esm/core/abis/troveNFT.js +0 -5
  220. package/dist/esm/core/abis/virtualPool.js +0 -7
  221. package/dist/esm/core/abis/virtualPoolFactory.js +0 -13
  222. package/dist/esm/core/constants/addresses.js +0 -107
  223. package/dist/esm/core/constants/borrowConstants.js +0 -12
  224. package/dist/esm/core/constants/borrowRegistries.js +0 -25
  225. package/dist/esm/core/constants/contractNames.js +0 -20
  226. package/dist/esm/core/constants/index.js +0 -5
  227. package/dist/esm/core/errors/base.js +0 -12
  228. package/dist/esm/core/errors/index.js +0 -3
  229. package/dist/esm/core/errors/oracle.js +0 -10
  230. package/dist/esm/core/errors/router.js +0 -18
  231. package/dist/esm/core/types/index.js +0 -9
  232. package/dist/esm/core/types/pool.js +0 -10
  233. package/dist/esm/core/types/tradingLimits.js +0 -1
  234. package/dist/esm/core/types/tradingMode.js +0 -26
  235. package/dist/esm/core/types/transaction.js +0 -1
  236. package/dist/esm/package.json +0 -1
  237. package/dist/esm/services/borrow/BorrowService.js +0 -455
  238. package/dist/esm/services/borrow/borrowHelpers.js +0 -3
  239. package/dist/esm/services/borrow/borrowMath.js +0 -127
  240. package/dist/esm/services/borrow/index.js +0 -3
  241. package/dist/esm/services/borrow/internal/borrowApprovalService.js +0 -48
  242. package/dist/esm/services/borrow/internal/borrowContextStore.js +0 -35
  243. package/dist/esm/services/borrow/internal/borrowErc20.js +0 -38
  244. package/dist/esm/services/borrow/internal/borrowHints.js +0 -27
  245. package/dist/esm/services/borrow/internal/borrowPositionParser.js +0 -82
  246. package/dist/esm/services/borrow/internal/borrowReadService.js +0 -271
  247. package/dist/esm/services/borrow/internal/borrowRegistryReader.js +0 -108
  248. package/dist/esm/services/borrow/internal/borrowTransactionService.js +0 -271
  249. package/dist/esm/services/borrow/internal/borrowTypes.js +0 -1
  250. package/dist/esm/services/borrow/internal/borrowValidation.js +0 -89
  251. package/dist/esm/services/index.js +0 -8
  252. package/dist/esm/services/liquidity/LiquidityService.js +0 -163
  253. package/dist/esm/services/liquidity/basicLiquidity.js +0 -162
  254. package/dist/esm/services/liquidity/index.js +0 -1
  255. package/dist/esm/services/liquidity/liquidityHelpers.js +0 -95
  256. package/dist/esm/services/liquidity/rebalance.js +0 -59
  257. package/dist/esm/services/liquidity/zapHelpers.js +0 -120
  258. package/dist/esm/services/liquidity/zapIn.js +0 -112
  259. package/dist/esm/services/liquidity/zapOut.js +0 -248
  260. package/dist/esm/services/pools/PoolService.js +0 -204
  261. package/dist/esm/services/pools/index.js +0 -1
  262. package/dist/esm/services/pools/poolDetails.js +0 -209
  263. package/dist/esm/services/pools/poolDiscovery.js +0 -112
  264. package/dist/esm/services/pools/rebalancePreview.js +0 -181
  265. package/dist/esm/services/quotes/QuoteService.js +0 -85
  266. package/dist/esm/services/quotes/index.js +0 -1
  267. package/dist/esm/services/routes/RouteService.js +0 -268
  268. package/dist/esm/services/routes/index.js +0 -1
  269. package/dist/esm/services/swap/SwapService.js +0 -247
  270. package/dist/esm/services/swap/index.js +0 -1
  271. package/dist/esm/services/tokens/index.js +0 -1
  272. package/dist/esm/services/tokens/tokenService.js +0 -285
  273. package/dist/esm/services/trading/TradingLimitsService.js +0 -154
  274. package/dist/esm/services/trading/TradingService.js +0 -196
  275. package/dist/esm/services/trading/index.js +0 -2
  276. package/dist/esm/utils/chainConfig.js +0 -118
  277. package/dist/esm/utils/costUtils.js +0 -56
  278. package/dist/esm/utils/deadline.js +0 -22
  279. package/dist/esm/utils/index.js +0 -9
  280. package/dist/esm/utils/multicall.js +0 -47
  281. package/dist/esm/utils/pathEncoder.js +0 -69
  282. package/dist/esm/utils/rateFeed.js +0 -23
  283. package/dist/esm/utils/retry.js +0 -24
  284. package/dist/esm/utils/routes.js +0 -2
  285. package/dist/esm/utils/sortUtils.js +0 -33
  286. package/dist/esm/utils/tokens.js +0 -2
  287. package/dist/esm/utils/tradingLimits.js +0 -163
  288. package/dist/esm/utils/validation.js +0 -30
  289. package/dist/index.d.ts +0 -101
  290. package/dist/index.js +0 -158
  291. package/dist/services/borrow/BorrowService.d.ts +0 -381
  292. package/dist/services/borrow/BorrowService.js +0 -460
  293. package/dist/services/borrow/borrowHelpers.d.ts +0 -4
  294. package/dist/services/borrow/borrowHelpers.js +0 -13
  295. package/dist/services/borrow/borrowMath.d.ts +0 -21
  296. package/dist/services/borrow/borrowMath.js +0 -137
  297. package/dist/services/borrow/index.d.ts +0 -4
  298. package/dist/services/borrow/internal/borrowApprovalService.d.ts +0 -14
  299. package/dist/services/borrow/internal/borrowApprovalService.js +0 -53
  300. package/dist/services/borrow/internal/borrowContextStore.d.ts +0 -11
  301. package/dist/services/borrow/internal/borrowContextStore.js +0 -40
  302. package/dist/services/borrow/internal/borrowErc20.d.ts +0 -5
  303. package/dist/services/borrow/internal/borrowErc20.js +0 -43
  304. package/dist/services/borrow/internal/borrowHints.d.ts +0 -7
  305. package/dist/services/borrow/internal/borrowHints.js +0 -31
  306. package/dist/services/borrow/internal/borrowPositionParser.d.ts +0 -4
  307. package/dist/services/borrow/internal/borrowPositionParser.js +0 -87
  308. package/dist/services/borrow/internal/borrowReadService.d.ts +0 -31
  309. package/dist/services/borrow/internal/borrowReadService.js +0 -276
  310. package/dist/services/borrow/internal/borrowRegistryReader.d.ts +0 -5
  311. package/dist/services/borrow/internal/borrowRegistryReader.js +0 -113
  312. package/dist/services/borrow/internal/borrowTransactionService.d.ts +0 -23
  313. package/dist/services/borrow/internal/borrowTransactionService.js +0 -276
  314. package/dist/services/borrow/internal/borrowTypes.d.ts +0 -15
  315. package/dist/services/borrow/internal/borrowTypes.js +0 -3
  316. package/dist/services/borrow/internal/borrowValidation.d.ts +0 -14
  317. package/dist/services/borrow/internal/borrowValidation.js +0 -104
  318. package/dist/services/index.d.ts +0 -9
  319. package/dist/services/index.js +0 -25
  320. package/dist/services/liquidity/LiquidityService.d.ts +0 -139
  321. package/dist/services/liquidity/LiquidityService.js +0 -168
  322. package/dist/services/liquidity/basicLiquidity.d.ts +0 -11
  323. package/dist/services/liquidity/basicLiquidity.js +0 -172
  324. package/dist/services/liquidity/index.d.ts +0 -2
  325. package/dist/services/liquidity/liquidityHelpers.d.ts +0 -19
  326. package/dist/services/liquidity/liquidityHelpers.js +0 -104
  327. package/dist/services/liquidity/rebalance.d.ts +0 -6
  328. package/dist/services/liquidity/rebalance.js +0 -64
  329. package/dist/services/liquidity/zapHelpers.d.ts +0 -66
  330. package/dist/services/liquidity/zapHelpers.js +0 -129
  331. package/dist/services/liquidity/zapIn.d.ts +0 -18
  332. package/dist/services/liquidity/zapIn.js +0 -119
  333. package/dist/services/liquidity/zapOut.d.ts +0 -9
  334. package/dist/services/liquidity/zapOut.js +0 -255
  335. package/dist/services/pools/PoolService.d.ts +0 -69
  336. package/dist/services/pools/PoolService.js +0 -209
  337. package/dist/services/pools/index.d.ts +0 -2
  338. package/dist/services/pools/poolDetails.d.ts +0 -13
  339. package/dist/services/pools/poolDetails.js +0 -216
  340. package/dist/services/pools/poolDiscovery.d.ts +0 -12
  341. package/dist/services/pools/poolDiscovery.js +0 -117
  342. package/dist/services/pools/rebalancePreview.d.ts +0 -5
  343. package/dist/services/pools/rebalancePreview.js +0 -186
  344. package/dist/services/quotes/QuoteService.d.ts +0 -51
  345. package/dist/services/quotes/QuoteService.js +0 -91
  346. package/dist/services/quotes/index.d.ts +0 -2
  347. package/dist/services/quotes/index.js +0 -18
  348. package/dist/services/routes/RouteService.d.ts +0 -117
  349. package/dist/services/routes/RouteService.js +0 -306
  350. package/dist/services/routes/index.d.ts +0 -2
  351. package/dist/services/routes/index.js +0 -18
  352. package/dist/services/swap/SwapService.d.ts +0 -198
  353. package/dist/services/swap/SwapService.js +0 -252
  354. package/dist/services/swap/index.d.ts +0 -2
  355. package/dist/services/swap/index.js +0 -18
  356. package/dist/services/tokens/index.d.ts +0 -2
  357. package/dist/services/tokens/index.js +0 -18
  358. package/dist/services/tokens/tokenService.d.ts +0 -55
  359. package/dist/services/tokens/tokenService.js +0 -290
  360. package/dist/services/trading/TradingLimitsService.d.ts +0 -38
  361. package/dist/services/trading/TradingLimitsService.js +0 -159
  362. package/dist/services/trading/TradingService.d.ts +0 -113
  363. package/dist/services/trading/TradingService.js +0 -201
  364. package/dist/services/trading/index.d.ts +0 -3
  365. package/dist/services/trading/index.js +0 -19
  366. package/dist/utils/chainConfig.d.ts +0 -16
  367. package/dist/utils/chainConfig.js +0 -123
  368. package/dist/utils/costUtils.d.ts +0 -12
  369. package/dist/utils/costUtils.js +0 -60
  370. package/dist/utils/deadline.d.ts +0 -21
  371. package/dist/utils/deadline.js +0 -26
  372. package/dist/utils/index.d.ts +0 -10
  373. package/dist/utils/index.js +0 -26
  374. package/dist/utils/multicall.d.ts +0 -30
  375. package/dist/utils/multicall.js +0 -52
  376. package/dist/utils/pathEncoder.d.ts +0 -34
  377. package/dist/utils/pathEncoder.js +0 -73
  378. package/dist/utils/rateFeed.d.ts +0 -18
  379. package/dist/utils/rateFeed.js +0 -27
  380. package/dist/utils/retry.d.ts +0 -12
  381. package/dist/utils/retry.js +0 -28
  382. package/dist/utils/routes.d.ts +0 -3
  383. package/dist/utils/routes.js +0 -8
  384. package/dist/utils/sortUtils.d.ts +0 -24
  385. package/dist/utils/sortUtils.js +0 -39
  386. package/dist/utils/tokens.d.ts +0 -2
  387. package/dist/utils/tokens.js +0 -13
  388. package/dist/utils/tradingLimits.d.ts +0 -41
  389. package/dist/utils/tradingLimits.js +0 -171
  390. package/dist/utils/validation.d.ts +0 -19
  391. package/dist/utils/validation.js +0 -34
  392. /package/dist/esm/{core/types/borrow.js → interfaces/IChainClient.js} +0 -0
  393. /package/dist/esm/{core/types/contractAddresses.js → interfaces/tradingLimit.js} +0 -0
  394. /package/dist/esm/{core/types/liquidity.js → interfaces/tradingLimitsConfig.js} +0 -0
  395. /package/dist/esm/{core/types/provider.js → interfaces/tradingLimitsState.js} +0 -0
  396. /package/dist/esm/{core/types/route.js → types/contractAddressMap.js} +0 -0
  397. /package/dist/esm/{core/types/token.js → types/contractAddresses.js} +0 -0
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildRebalanceParamsInternal = buildRebalanceParamsInternal;
4
- exports.buildRebalanceTransactionInternal = buildRebalanceTransactionInternal;
5
- const viem_1 = require("viem");
6
- const abis_1 = require("../../core/abis");
7
- const validation_1 = require("../../utils/validation");
8
- const liquidityHelpers_1 = require("./liquidityHelpers");
9
- function getRebalanceUnavailableError(poolAddress) {
10
- return new Error(`Pool ${poolAddress} is not currently rebalanceable or does not have a supported liquidity strategy.`);
11
- }
12
- function assertRebalanceActionAmounts(poolAddress, amountRequired, amountTransferred) {
13
- if (amountRequired <= 0n || amountTransferred <= 0n) {
14
- throw new Error(`Rebalance action for pool ${poolAddress} has zero amounts and cannot be executed.`);
15
- }
16
- }
17
- async function buildRebalanceParamsInternal(publicClient, chainId, poolService, poolAddress) {
18
- (0, validation_1.validateAddress)(poolAddress, 'poolAddress');
19
- const preview = await poolService.getPoolRebalancePreview(poolAddress);
20
- if (!preview) {
21
- throw getRebalanceUnavailableError(poolAddress);
22
- }
23
- assertRebalanceActionAmounts(poolAddress, preview.amountRequired.amount, preview.amountTransferred.amount);
24
- const data = (0, viem_1.encodeFunctionData)({
25
- abi: abis_1.LIQUIDITY_STRATEGY_ABI,
26
- functionName: 'rebalance',
27
- args: [poolAddress],
28
- });
29
- return {
30
- params: {
31
- to: preview.strategyAddress,
32
- data,
33
- value: '0',
34
- },
35
- poolAddress,
36
- strategyAddress: preview.strategyAddress,
37
- inputToken: preview.inputToken,
38
- outputToken: preview.outputToken,
39
- amountRequired: preview.amountRequired.amount,
40
- expectedAmountTransferred: preview.amountTransferred.amount,
41
- expectedProtocolIncentive: preview.protocolIncentive.amount,
42
- expectedLiquiditySourceIncentive: preview.liquiditySourceIncentive.amount,
43
- approvalToken: preview.approvalToken,
44
- approvalSpender: preview.approvalSpender,
45
- approvalAmount: preview.approvalAmount,
46
- direction: preview.direction,
47
- };
48
- }
49
- async function buildRebalanceTransactionInternal(publicClient, chainId, poolService, poolAddress, owner) {
50
- (0, validation_1.validateAddress)(owner, 'owner');
51
- const rebalance = await buildRebalanceParamsInternal(publicClient, chainId, poolService, poolAddress);
52
- const approvalToken = rebalance.approvalToken;
53
- const approvalSpender = rebalance.approvalSpender;
54
- const currentAllowance = await (0, liquidityHelpers_1.getAllowance)(publicClient, approvalToken, owner, chainId, approvalSpender);
55
- const approval = currentAllowance < rebalance.approvalAmount
56
- ? {
57
- token: rebalance.approvalToken,
58
- amount: rebalance.approvalAmount,
59
- params: (0, liquidityHelpers_1.buildApprovalParams)(chainId, approvalToken, rebalance.approvalAmount, approvalSpender),
60
- }
61
- : null;
62
- return { approval, rebalance };
63
- }
64
- //# sourceMappingURL=rebalance.js.map
@@ -1,66 +0,0 @@
1
- import { Address } from 'viem';
2
- import { RouteService } from '../routes';
3
- import { ZapParams } from '../../core/types';
4
- import { RouterRoute } from '../../utils/pathEncoder';
5
- /**
6
- * Encodes the zapIn function call for the Router contract
7
- */
8
- export declare function encodeZapInCall(tokenIn: Address, amountInA: bigint, amountInB: bigint, zapParams: ZapParams, routesA: RouterRoute[], routesB: RouterRoute[], recipient: Address): string;
9
- /**
10
- * Encodes the zapOut function call for the Router contract
11
- */
12
- export declare function encodeZapOutCall(tokenOut: Address, liquidity: bigint, zapParams: ZapParams, routesA: RouterRoute[], routesB: RouterRoute[]): string;
13
- /**
14
- * Finds routes for zap in operations (from tokenIn to both pool tokens)
15
- *
16
- * @param routeService - Route service for finding swap paths
17
- * @param tokenIn - Input token address
18
- * @param token0 - Pool's token0 address
19
- * @param token1 - Pool's token1 address
20
- * @returns Routes from tokenIn to token0 and token1
21
- */
22
- export declare function findZapInRoutes(routeService: RouteService, tokenIn: string, token0: string, token1: string): Promise<{
23
- routesA: RouterRoute[];
24
- routesB: RouterRoute[];
25
- }>;
26
- /**
27
- * Finds routes for zap out operations (from both pool tokens to tokenOut)
28
- *
29
- * @param routeService - Route service for finding swap paths
30
- * @param token0 - Pool's token0 address
31
- * @param token1 - Pool's token1 address
32
- * @param tokenOut - Output token address
33
- * @returns Routes from token0 and token1 to tokenOut
34
- */
35
- export declare function findZapOutRoutes(routeService: RouteService, token0: string, token1: string, tokenOut: string): Promise<{
36
- routesA: RouterRoute[];
37
- routesB: RouterRoute[];
38
- }>;
39
- /**
40
- * Splits an amount into two parts based on a ratio
41
- *
42
- * @param amountIn - Total input amount
43
- * @param splitRatio - Ratio for splitting (0-1, e.g., 0.5 for 50/50)
44
- * @returns Split amounts for each part
45
- */
46
- export declare function splitAmount(amountIn: bigint, splitRatio: number): {
47
- amountA: bigint;
48
- amountB: bigint;
49
- };
50
- /**
51
- * Estimates minimum LP tokens from zap in amounts.
52
- *
53
- * This is a conservative lower-bound estimate. The inputs are slippage-adjusted
54
- * minimums, not expected amounts. Actual LP tokens minted on-chain may be higher
55
- * because the router uses balanceOf(address(this)) after swaps, which can exceed
56
- * the pre-calculated minimums.
57
- *
58
- * @param amountOutA - Minimum amount of token0 after swap (slippage-adjusted)
59
- * @param amountOutB - Minimum amount of token1 after swap (slippage-adjusted)
60
- * @param reserve0 - Current reserve of token0 in pool
61
- * @param reserve1 - Current reserve of token1 in pool
62
- * @param totalSupply - Total LP token supply
63
- * @returns Conservative estimate of minimum LP tokens to be minted
64
- */
65
- export declare function estimateLiquidityFromZapIn(amountOutA: bigint, amountOutB: bigint, reserve0: bigint, reserve1: bigint, totalSupply: bigint): bigint;
66
- //# sourceMappingURL=zapHelpers.d.ts.map
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeZapInCall = encodeZapInCall;
4
- exports.encodeZapOutCall = encodeZapOutCall;
5
- exports.findZapInRoutes = findZapInRoutes;
6
- exports.findZapOutRoutes = findZapOutRoutes;
7
- exports.splitAmount = splitAmount;
8
- exports.estimateLiquidityFromZapIn = estimateLiquidityFromZapIn;
9
- const viem_1 = require("viem");
10
- const abis_1 = require("../../core/abis");
11
- const pathEncoder_1 = require("../../utils/pathEncoder");
12
- // ========== ENCODING FUNCTIONS ==========
13
- /**
14
- * Encodes the zapIn function call for the Router contract
15
- */
16
- function encodeZapInCall(tokenIn, amountInA, amountInB, zapParams, routesA, routesB, recipient) {
17
- return (0, viem_1.encodeFunctionData)({
18
- abi: abis_1.ROUTER_ABI,
19
- functionName: 'zapIn',
20
- args: [tokenIn, amountInA, amountInB, zapParams, routesA, routesB, recipient],
21
- });
22
- }
23
- /**
24
- * Encodes the zapOut function call for the Router contract
25
- */
26
- function encodeZapOutCall(tokenOut, liquidity, zapParams, routesA, routesB) {
27
- return (0, viem_1.encodeFunctionData)({
28
- abi: abis_1.ROUTER_ABI,
29
- functionName: 'zapOut',
30
- args: [tokenOut, liquidity, zapParams, routesA, routesB],
31
- });
32
- }
33
- // ========== ROUTING FUNCTIONS ==========
34
- /**
35
- * Finds routes for zap in operations (from tokenIn to both pool tokens)
36
- *
37
- * @param routeService - Route service for finding swap paths
38
- * @param tokenIn - Input token address
39
- * @param token0 - Pool's token0 address
40
- * @param token1 - Pool's token1 address
41
- * @returns Routes from tokenIn to token0 and token1
42
- */
43
- async function findZapInRoutes(routeService, tokenIn, token0, token1) {
44
- const [routeA, routeB] = await Promise.all([
45
- tokenIn.toLowerCase() !== token0.toLowerCase()
46
- ? routeService.findRoute(tokenIn, token0)
47
- : Promise.resolve(null),
48
- tokenIn.toLowerCase() !== token1.toLowerCase()
49
- ? routeService.findRoute(tokenIn, token1)
50
- : Promise.resolve(null),
51
- ]);
52
- const routesA = routeA ? (0, pathEncoder_1.encodeRoutePath)(routeA.path, tokenIn, token0) : [];
53
- const routesB = routeB ? (0, pathEncoder_1.encodeRoutePath)(routeB.path, tokenIn, token1) : [];
54
- return { routesA, routesB };
55
- }
56
- /**
57
- * Finds routes for zap out operations (from both pool tokens to tokenOut)
58
- *
59
- * @param routeService - Route service for finding swap paths
60
- * @param token0 - Pool's token0 address
61
- * @param token1 - Pool's token1 address
62
- * @param tokenOut - Output token address
63
- * @returns Routes from token0 and token1 to tokenOut
64
- */
65
- async function findZapOutRoutes(routeService, token0, token1, tokenOut) {
66
- const [routeA, routeB] = await Promise.all([
67
- token0.toLowerCase() !== tokenOut.toLowerCase()
68
- ? routeService.findRoute(token0, tokenOut)
69
- : Promise.resolve(null),
70
- token1.toLowerCase() !== tokenOut.toLowerCase()
71
- ? routeService.findRoute(token1, tokenOut)
72
- : Promise.resolve(null),
73
- ]);
74
- const routesA = routeA ? (0, pathEncoder_1.encodeRoutePath)(routeA.path, token0, tokenOut) : [];
75
- const routesB = routeB ? (0, pathEncoder_1.encodeRoutePath)(routeB.path, token1, tokenOut) : [];
76
- return { routesA, routesB };
77
- }
78
- // ========== CALCULATION FUNCTIONS ==========
79
- /**
80
- * Splits an amount into two parts based on a ratio
81
- *
82
- * @param amountIn - Total input amount
83
- * @param splitRatio - Ratio for splitting (0-1, e.g., 0.5 for 50/50)
84
- * @returns Split amounts for each part
85
- */
86
- function splitAmount(amountIn, splitRatio) {
87
- if (splitRatio < 0 || splitRatio > 1) {
88
- throw new Error('Split ratio must be between 0 and 1');
89
- }
90
- const amountA = (amountIn * BigInt(Math.floor(splitRatio * 10000))) / 10000n;
91
- const amountB = amountIn - amountA;
92
- return { amountA, amountB };
93
- }
94
- /**
95
- * Estimates minimum LP tokens from zap in amounts.
96
- *
97
- * This is a conservative lower-bound estimate. The inputs are slippage-adjusted
98
- * minimums, not expected amounts. Actual LP tokens minted on-chain may be higher
99
- * because the router uses balanceOf(address(this)) after swaps, which can exceed
100
- * the pre-calculated minimums.
101
- *
102
- * @param amountOutA - Minimum amount of token0 after swap (slippage-adjusted)
103
- * @param amountOutB - Minimum amount of token1 after swap (slippage-adjusted)
104
- * @param reserve0 - Current reserve of token0 in pool
105
- * @param reserve1 - Current reserve of token1 in pool
106
- * @param totalSupply - Total LP token supply
107
- * @returns Conservative estimate of minimum LP tokens to be minted
108
- */
109
- function estimateLiquidityFromZapIn(amountOutA, amountOutB, reserve0, reserve1, totalSupply) {
110
- if (totalSupply === 0n) {
111
- // First liquidity provision - use geometric mean with BigInt sqrt
112
- // to avoid precision loss from Number() conversion on 18-decimal values
113
- const product = amountOutA * amountOutB;
114
- if (product === 0n)
115
- return 0n;
116
- let x = product;
117
- let y = (x + 1n) / 2n;
118
- while (y < x) {
119
- x = y;
120
- y = (x + product / x) / 2n;
121
- }
122
- return x;
123
- }
124
- // Existing pool - calculate based on smaller ratio
125
- const liquidityA = (amountOutA * totalSupply) / reserve0;
126
- const liquidityB = (amountOutB * totalSupply) / reserve1;
127
- return liquidityA < liquidityB ? liquidityA : liquidityB;
128
- }
129
- //# sourceMappingURL=zapHelpers.js.map
@@ -1,18 +0,0 @@
1
- import { PublicClient } from 'viem';
2
- import { PoolService } from '../pools';
3
- import { RouteService } from '../routes';
4
- import { LiquidityOptions, PreparedZapIn, ZapInQuote, ZapInDetails, ZapInTransaction } from '../../core/types';
5
- /**
6
- * Builds a complete zap in transaction including approval if needed
7
- */
8
- export declare function buildZapInTransactionInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, recipient: string, owner: string, options: LiquidityOptions): Promise<ZapInTransaction>;
9
- /**
10
- * Builds zap in transaction parameters without checking approval
11
- */
12
- export declare function buildZapInParamsInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, recipient: string, options: LiquidityOptions): Promise<ZapInDetails>;
13
- /**
14
- * Quotes a zap in operation (read-only)
15
- */
16
- export declare function quoteZapInInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, options: LiquidityOptions): Promise<ZapInQuote>;
17
- export declare function prepareZapInInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, recipient: string, owner: string | undefined, options: LiquidityOptions): Promise<PreparedZapIn>;
18
- //# sourceMappingURL=zapIn.d.ts.map
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildZapInTransactionInternal = buildZapInTransactionInternal;
4
- exports.buildZapInParamsInternal = buildZapInParamsInternal;
5
- exports.quoteZapInInternal = quoteZapInInternal;
6
- exports.prepareZapInInternal = prepareZapInInternal;
7
- const abis_1 = require("../../core/abis");
8
- const constants_1 = require("../../core/constants");
9
- const validation_1 = require("../../utils/validation");
10
- const liquidityHelpers_1 = require("./liquidityHelpers");
11
- const zapHelpers_1 = require("./zapHelpers");
12
- // ========== ZAP IN OPERATIONS ==========
13
- /**
14
- * Builds a complete zap in transaction including approval if needed
15
- */
16
- async function buildZapInTransactionInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, owner, options) {
17
- const prepared = await prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, owner, options);
18
- return {
19
- approval: prepared.approval ?? null,
20
- zapIn: prepared.details,
21
- };
22
- }
23
- /**
24
- * Builds zap in transaction parameters without checking approval
25
- */
26
- async function buildZapInParamsInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, options) {
27
- const prepared = await prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, undefined, options);
28
- return prepared.details;
29
- }
30
- /**
31
- * Quotes a zap in operation (read-only)
32
- */
33
- async function quoteZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, options) {
34
- const prepared = await prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, tokenIn, undefined, options);
35
- return prepared.quote;
36
- }
37
- async function prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, owner, options) {
38
- if (owner) {
39
- (0, validation_1.validateAddress)(owner, 'owner');
40
- }
41
- const [context, currentAllowance] = await Promise.all([
42
- prepareZapInContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, options),
43
- owner ? (0, liquidityHelpers_1.getAllowance)(publicClient, tokenIn, owner, chainId) : Promise.resolve(null),
44
- ]);
45
- const approval = owner && currentAllowance !== null && currentAllowance < amountIn
46
- ? { token: tokenIn, amount: amountIn, params: (0, liquidityHelpers_1.buildApprovalParams)(chainId, tokenIn, amountIn) }
47
- : owner
48
- ? null
49
- : undefined;
50
- return {
51
- routesA: context.routesA,
52
- routesB: context.routesB,
53
- quote: context.quote,
54
- approval,
55
- details: context.details,
56
- };
57
- }
58
- async function prepareZapInContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, options) {
59
- (0, validation_1.validateAddress)(poolAddress, 'poolAddress');
60
- (0, validation_1.validateAddress)(tokenIn, 'tokenIn');
61
- (0, validation_1.validateAddress)(recipient, 'recipient');
62
- const { token0, token1, factoryAddr } = await (0, liquidityHelpers_1.getPoolInfo)(poolService, poolAddress);
63
- const { amountA: amountInA, amountB: amountInB } = (0, zapHelpers_1.splitAmount)(amountIn, amountInSplit);
64
- const [{ routesA, routesB }, poolSnapshot] = await Promise.all([
65
- (0, zapHelpers_1.findZapInRoutes)(routeService, tokenIn, token0, token1),
66
- (0, liquidityHelpers_1.getPoolSnapshot)(publicClient, poolAddress),
67
- ]);
68
- const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
69
- const [amountOutMinA, amountOutMinB, amountAMin, amountBMin] = (await publicClient.readContract({
70
- address: routerAddress,
71
- abi: abis_1.ROUTER_ABI,
72
- functionName: 'generateZapInParams',
73
- args: [token0, token1, factoryAddr, amountInA, amountInB, routesA, routesB],
74
- }));
75
- const finalAmountAMin = (0, liquidityHelpers_1.calculateMinAmount)(amountAMin, options.slippageTolerance);
76
- const finalAmountBMin = (0, liquidityHelpers_1.calculateMinAmount)(amountBMin, options.slippageTolerance);
77
- const finalAmountOutMinA = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinA, options.slippageTolerance);
78
- const finalAmountOutMinB = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinB, options.slippageTolerance);
79
- const expectedLiquidity = (0, zapHelpers_1.estimateLiquidityFromZapIn)(finalAmountOutMinA, finalAmountOutMinB, poolSnapshot.reserve0, poolSnapshot.reserve1, poolSnapshot.totalSupply);
80
- const quote = {
81
- amountOutFromA: finalAmountOutMinA,
82
- amountOutFromB: finalAmountOutMinB,
83
- amountAMin: finalAmountAMin,
84
- amountBMin: finalAmountBMin,
85
- estimatedMinLiquidity: expectedLiquidity,
86
- };
87
- const zapParams = {
88
- tokenA: token0,
89
- tokenB: token1,
90
- factory: factoryAddr,
91
- amountAMin: finalAmountAMin,
92
- amountBMin: finalAmountBMin,
93
- amountOutMinA: finalAmountOutMinA,
94
- amountOutMinB: finalAmountOutMinB,
95
- };
96
- const data = (0, zapHelpers_1.encodeZapInCall)(tokenIn, amountInA, amountInB, zapParams, routesA, routesB, recipient);
97
- return {
98
- routesA,
99
- routesB,
100
- quote,
101
- details: {
102
- params: {
103
- to: routerAddress,
104
- data,
105
- value: '0',
106
- },
107
- poolAddress,
108
- tokenIn,
109
- amountIn,
110
- amountInA,
111
- amountInB,
112
- routesA,
113
- routesB,
114
- zapParams,
115
- estimatedMinLiquidity: expectedLiquidity,
116
- },
117
- };
118
- }
119
- //# sourceMappingURL=zapIn.js.map
@@ -1,9 +0,0 @@
1
- import { PublicClient } from 'viem';
2
- import { PoolService } from '../pools';
3
- import { RouteService } from '../routes';
4
- import { LiquidityOptions, PreparedZapOut, ZapOutQuote, ZapOutDetails, ZapOutTransaction } from '../../core/types';
5
- export declare function buildZapOutTransactionInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, recipient: string, owner: string, options: LiquidityOptions): Promise<ZapOutTransaction>;
6
- export declare function buildZapOutParamsInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, recipient: string, options: LiquidityOptions): Promise<ZapOutDetails>;
7
- export declare function quoteZapOutInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, options: LiquidityOptions): Promise<ZapOutQuote>;
8
- export declare function prepareZapOutInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, recipient: string, owner: string | undefined, options: LiquidityOptions): Promise<PreparedZapOut>;
9
- //# sourceMappingURL=zapOut.d.ts.map
@@ -1,255 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildZapOutTransactionInternal = buildZapOutTransactionInternal;
4
- exports.buildZapOutParamsInternal = buildZapOutParamsInternal;
5
- exports.quoteZapOutInternal = quoteZapOutInternal;
6
- exports.prepareZapOutInternal = prepareZapOutInternal;
7
- const abis_1 = require("../../core/abis");
8
- const constants_1 = require("../../core/constants");
9
- const errors_1 = require("../../core/errors");
10
- const validation_1 = require("../../utils/validation");
11
- const pathEncoder_1 = require("../../utils/pathEncoder");
12
- const liquidityHelpers_1 = require("./liquidityHelpers");
13
- const zapHelpers_1 = require("./zapHelpers");
14
- const INSUFFICIENT_LIQUIDITY_SELECTOR = '0xbb55fd27';
15
- const MAX_ROUTE_CANDIDATES_PER_LEG = 8;
16
- const MAX_ROUTE_COMBINATIONS = 48;
17
- const ROUTE_SIMULATION_BATCH_SIZE = 6;
18
- async function buildZapOutTransactionInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options) {
19
- const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options);
20
- return {
21
- approval: prepared.approval ?? null,
22
- zapOut: prepared.details,
23
- };
24
- }
25
- async function buildZapOutParamsInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options) {
26
- const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, undefined, options);
27
- return prepared.details;
28
- }
29
- async function quoteZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, options) {
30
- const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, tokenOut, undefined, options);
31
- return prepared.quote;
32
- }
33
- async function prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options) {
34
- if (owner) {
35
- (0, validation_1.validateAddress)(owner, 'owner');
36
- }
37
- const [context, currentAllowance] = await Promise.all([
38
- prepareZapOutContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options),
39
- owner ? (0, liquidityHelpers_1.getAllowance)(publicClient, poolAddress, owner, chainId) : Promise.resolve(null),
40
- ]);
41
- let details = context.details;
42
- const approval = owner && currentAllowance !== null && currentAllowance < liquidity
43
- ? { token: poolAddress, amount: liquidity, params: (0, liquidityHelpers_1.buildApprovalParams)(chainId, poolAddress, liquidity) }
44
- : owner
45
- ? null
46
- : undefined;
47
- if (owner && currentAllowance !== null && currentAllowance >= liquidity) {
48
- const ownerAddr = owner;
49
- const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
50
- try {
51
- await simulateZapOut(publicClient, ownerAddr, routerAddress, details.params.data);
52
- }
53
- catch (error) {
54
- if (!isInsufficientLiquidityError(error)) {
55
- throw error;
56
- }
57
- details = await findViableZapOutDetails(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, ownerAddr, options);
58
- }
59
- }
60
- return {
61
- routesA: details.routesA,
62
- routesB: details.routesB,
63
- quote: {
64
- amountOutFromA: details.zapParams.amountOutMinA,
65
- amountOutFromB: details.zapParams.amountOutMinB,
66
- amountAMin: details.zapParams.amountAMin,
67
- amountBMin: details.zapParams.amountBMin,
68
- estimatedMinTokenOut: details.estimatedMinTokenOut,
69
- },
70
- approval,
71
- details,
72
- };
73
- }
74
- async function prepareZapOutContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options) {
75
- (0, validation_1.validateAddress)(poolAddress, 'poolAddress');
76
- (0, validation_1.validateAddress)(tokenOut, 'tokenOut');
77
- (0, validation_1.validateAddress)(recipient, 'recipient');
78
- const { token0, token1, factoryAddr } = await (0, liquidityHelpers_1.getPoolInfo)(poolService, poolAddress);
79
- const { routesA, routesB } = await (0, zapHelpers_1.findZapOutRoutes)(routeService, token0, token1, tokenOut);
80
- const details = await buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options);
81
- return {
82
- routesA,
83
- routesB,
84
- quote: {
85
- amountOutFromA: details.zapParams.amountOutMinA,
86
- amountOutFromB: details.zapParams.amountOutMinB,
87
- amountAMin: details.zapParams.amountAMin,
88
- amountBMin: details.zapParams.amountBMin,
89
- estimatedMinTokenOut: details.estimatedMinTokenOut,
90
- },
91
- details,
92
- };
93
- }
94
- async function buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options) {
95
- const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
96
- const [amountOutMinA, amountOutMinB, amountAMin, amountBMin] = (await publicClient.readContract({
97
- address: routerAddress,
98
- abi: abis_1.ROUTER_ABI,
99
- functionName: 'generateZapOutParams',
100
- args: [token0, token1, factoryAddr, liquidity, routesA, routesB],
101
- }));
102
- const finalAmountAMin = (0, liquidityHelpers_1.calculateMinAmount)(amountAMin, options.slippageTolerance);
103
- const finalAmountBMin = (0, liquidityHelpers_1.calculateMinAmount)(amountBMin, options.slippageTolerance);
104
- const finalAmountOutMinA = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinA, options.slippageTolerance);
105
- const finalAmountOutMinB = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinB, options.slippageTolerance);
106
- const zapParams = {
107
- tokenA: token0,
108
- tokenB: token1,
109
- factory: factoryAddr,
110
- amountAMin: finalAmountAMin,
111
- amountBMin: finalAmountBMin,
112
- amountOutMinA: finalAmountOutMinA,
113
- amountOutMinB: finalAmountOutMinB,
114
- };
115
- const data = (0, zapHelpers_1.encodeZapOutCall)(tokenOut, liquidity, zapParams, routesA, routesB);
116
- return {
117
- params: {
118
- to: routerAddress,
119
- data,
120
- value: '0',
121
- },
122
- poolAddress,
123
- tokenOut,
124
- liquidity,
125
- routesA,
126
- routesB,
127
- zapParams,
128
- estimatedMinTokenOut: finalAmountOutMinA + finalAmountOutMinB,
129
- };
130
- }
131
- async function findViableZapOutDetails(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, owner, options) {
132
- const { token0, token1, factoryAddr } = await (0, liquidityHelpers_1.getPoolInfo)(poolService, poolAddress);
133
- const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
134
- const allRoutes = await routeService.getRoutes({ cached: false, returnAllRoutes: true });
135
- const [routesAOptions, routesBOptions] = await Promise.all([
136
- getEncodedRouteCandidates(routeService, token0, tokenOut, poolAddress, allRoutes),
137
- getEncodedRouteCandidates(routeService, token1, tokenOut, poolAddress, allRoutes),
138
- ]);
139
- const routeCombinations = [];
140
- outer: for (const routesA of routesAOptions) {
141
- for (const routesB of routesBOptions) {
142
- routeCombinations.push({ routesA, routesB });
143
- if (routeCombinations.length >= MAX_ROUTE_COMBINATIONS) {
144
- break outer;
145
- }
146
- }
147
- }
148
- let best = null;
149
- for (let index = 0; index < routeCombinations.length; index += ROUTE_SIMULATION_BATCH_SIZE) {
150
- const batch = routeCombinations.slice(index, index + ROUTE_SIMULATION_BATCH_SIZE);
151
- const candidates = await Promise.all(batch.map(async ({ routesA, routesB }) => {
152
- try {
153
- const candidate = await buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options);
154
- await simulateZapOut(publicClient, owner, routerAddress, candidate.params.data);
155
- return candidate;
156
- }
157
- catch {
158
- return null;
159
- }
160
- }));
161
- for (const candidate of candidates) {
162
- if (candidate && (!best || candidate.estimatedMinTokenOut > best.estimatedMinTokenOut)) {
163
- best = candidate;
164
- }
165
- }
166
- }
167
- if (!best) {
168
- throw new errors_1.ZapOutRouteNotViableError(poolAddress, tokenOut);
169
- }
170
- return best;
171
- }
172
- async function getEncodedRouteCandidates(routeService, tokenIn, tokenOut, sourcePoolAddress, allRoutes) {
173
- if (tokenIn.toLowerCase() === tokenOut.toLowerCase()) {
174
- return [[]];
175
- }
176
- const rawCandidates = [];
177
- try {
178
- rawCandidates.push(await routeService.findRoute(tokenIn, tokenOut));
179
- }
180
- catch {
181
- // Continue; we'll try the broader route set next.
182
- }
183
- const pairCandidates = (allRoutes ?? await routeService.getRoutes({ cached: false, returnAllRoutes: true })).filter((route) => {
184
- const a0 = route.tokens[0].address.toLowerCase();
185
- const a1 = route.tokens[1].address.toLowerCase();
186
- const t0 = tokenIn.toLowerCase();
187
- const t1 = tokenOut.toLowerCase();
188
- return (a0 === t0 && a1 === t1) || (a0 === t1 && a1 === t0);
189
- });
190
- rawCandidates.push(...pairCandidates);
191
- if (rawCandidates.length === 0) {
192
- throw new errors_1.RouteNotFoundError(tokenIn, tokenOut);
193
- }
194
- rawCandidates.sort((routeA, routeB) => {
195
- const routeAUsesSourcePool = routeUsesPool(routeA, sourcePoolAddress) ? 1 : 0;
196
- const routeBUsesSourcePool = routeUsesPool(routeB, sourcePoolAddress) ? 1 : 0;
197
- if (routeAUsesSourcePool !== routeBUsesSourcePool)
198
- return routeAUsesSourcePool - routeBUsesSourcePool;
199
- if (routeA.path.length !== routeB.path.length)
200
- return routeA.path.length - routeB.path.length;
201
- return 0;
202
- });
203
- const encodedRoutes = [];
204
- const seen = new Set();
205
- for (const route of rawCandidates) {
206
- try {
207
- const encoded = (0, pathEncoder_1.encodeRoutePath)(route.path, tokenIn, tokenOut);
208
- const key = JSON.stringify(encoded);
209
- if (seen.has(key))
210
- continue;
211
- seen.add(key);
212
- encodedRoutes.push(encoded);
213
- if (encodedRoutes.length >= MAX_ROUTE_CANDIDATES_PER_LEG) {
214
- break;
215
- }
216
- }
217
- catch {
218
- // Invalid path encoding for this direction; skip.
219
- }
220
- }
221
- if (encodedRoutes.length === 0) {
222
- throw new errors_1.RouteNotFoundError(tokenIn, tokenOut);
223
- }
224
- return encodedRoutes;
225
- }
226
- function routeUsesPool(route, poolAddress) {
227
- const normalizedPool = poolAddress.toLowerCase();
228
- return route.path.some((hop) => hop.poolAddr.toLowerCase() === normalizedPool);
229
- }
230
- async function simulateZapOut(publicClient, owner, routerAddress, data) {
231
- await publicClient.call({
232
- account: owner,
233
- to: routerAddress,
234
- data,
235
- });
236
- }
237
- function isInsufficientLiquidityError(error) {
238
- const message = extractErrorMessage(error).toLowerCase();
239
- return (message.includes(INSUFFICIENT_LIQUIDITY_SELECTOR) ||
240
- message.includes('insufficientliquidity'));
241
- }
242
- function extractErrorMessage(error) {
243
- if (!(error instanceof Error)) {
244
- return String(error);
245
- }
246
- const typed = error;
247
- const parts = [
248
- typed.message,
249
- typed.shortMessage,
250
- typed.details,
251
- typed.cause instanceof Error ? typed.cause.message : undefined,
252
- ].filter((part) => Boolean(part));
253
- return parts.join(' | ');
254
- }
255
- //# sourceMappingURL=zapOut.js.map