@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,196 +0,0 @@
1
- import { isTradingEnabled, } from '../../core/types';
2
- import { TradingLimitsService } from './TradingLimitsService';
3
- import { BREAKERBOX_ABI, FPMM_ABI } from '../../core/abis';
4
- import { getContractAddress } from '../../core/constants';
5
- import { multicall } from '../../utils/multicall';
6
- /**
7
- * Service for checking trading status and circuit breaker state in the Mento protocol.
8
- * Provides methods to query whether trading is enabled for specific rate feeds,
9
- * token pairs, or routes. Also integrates trading limit checks.
10
- */
11
- export class TradingService {
12
- constructor(publicClient, chainId, routeService) {
13
- this.publicClient = publicClient;
14
- this.chainId = chainId;
15
- this.routeService = routeService;
16
- this.tradingLimitsService = new TradingLimitsService(publicClient, chainId);
17
- }
18
- /**
19
- * Returns the current trading mode for a given rate feed.
20
- *
21
- * The BreakerBox uses a bitmask approach where 0 means bidirectional trading
22
- * is enabled, and any non-zero value means trading is suspended.
23
- *
24
- * @param rateFeedId - The address of the rate feed
25
- * @returns The raw trading mode value from BreakerBox (0 = enabled, non-zero = suspended)
26
- *
27
- * @example
28
- * ```typescript
29
- * const mode = await tradingService.getRateFeedTradingMode(rateFeedId)
30
- * if (mode === TradingMode.BIDIRECTIONAL) {
31
- * console.log('Trading is enabled')
32
- * }
33
- * ```
34
- */
35
- async getRateFeedTradingMode(rateFeedId) {
36
- const breakerBoxAddr = getContractAddress(this.chainId, 'BreakerBox');
37
- const mode = await this.publicClient.readContract({
38
- address: breakerBoxAddr,
39
- abi: BREAKERBOX_ABI,
40
- functionName: 'getRateFeedTradingMode',
41
- args: [rateFeedId],
42
- });
43
- return Number(mode);
44
- }
45
- /**
46
- * Checks if a trading pair is currently tradable.
47
- * For multi-hop routes (e.g., CELO → USDm → USDT), checks that ALL
48
- * intermediate rate feeds are in BIDIRECTIONAL mode.
49
- *
50
- * @param tokenIn - Input token address
51
- * @param tokenOut - Output token address
52
- * @returns true if the pair is tradable (all rate feeds BIDIRECTIONAL), false otherwise
53
- * @throws {RouteNotFoundError} If no route exists between the token pair
54
- *
55
- * @example
56
- * ```typescript
57
- * const isTradable = await tradingService.isPairTradable(USDm, CELO)
58
- * if (!isTradable) {
59
- * console.log('Trading is currently suspended for this pair')
60
- * }
61
- * ```
62
- */
63
- async isPairTradable(tokenIn, tokenOut) {
64
- const route = await this.routeService.findRoute(tokenIn, tokenOut);
65
- return this.isRouteTradable(route);
66
- }
67
- /**
68
- * Checks if a route is currently tradable.
69
- * Verifies that all pools in the route's path have their rate feeds
70
- * in BIDIRECTIONAL mode.
71
- *
72
- * @param route - The route to check
73
- * @returns true if all pools in the route are tradable, false otherwise
74
- *
75
- * @example
76
- * ```typescript
77
- * const route = await routeService.findRoute(tokenIn, tokenOut)
78
- * const isRouteTradable = await tradingService.isRouteTradable(route)
79
- * ```
80
- */
81
- async isRouteTradable(route) {
82
- const tradingModes = await this.getTradingModesForPools(route.path);
83
- // All rate feeds must have trading enabled for the route to be tradable
84
- return tradingModes.every((tradingMode) => isTradingEnabled(tradingMode));
85
- }
86
- /**
87
- * Get trading limits for a pool.
88
- *
89
- * @param pool - The pool to get trading limits for
90
- * @returns Array of TradingLimit objects with maxIn/maxOut/until
91
- *
92
- * @example
93
- * ```typescript
94
- * const limits = await tradingService.getPoolTradingLimits(pool)
95
- * limits.forEach(limit => {
96
- * console.log(`${limit.asset}: maxIn=${limit.maxIn}, maxOut=${limit.maxOut}`)
97
- * })
98
- * ```
99
- */
100
- async getPoolTradingLimits(pool) {
101
- return this.tradingLimitsService.getPoolTradingLimits(pool);
102
- }
103
- /**
104
- * Get complete tradability status for a pool.
105
- * Returns separate flags for circuit breaker and trading limits,
106
- * allowing frontends to show different messages for each condition.
107
- *
108
- * @param pool - The pool to check
109
- * @returns PoolTradabilityStatus with tradable, circuitBreakerOk, limitsOk, and limits
110
- *
111
- * @example
112
- * ```typescript
113
- * const status = await tradingService.getPoolTradabilityStatus(pool)
114
- * if (!status.circuitBreakerOk) {
115
- * showModal("Trading temporarily suspended (circuit breaker)")
116
- * } else if (!status.limitsOk) {
117
- * showModal("Trading limit reached", status.limits)
118
- * }
119
- * ```
120
- */
121
- async getPoolTradabilityStatus(pool) {
122
- const [[tradingMode], limits] = await Promise.all([
123
- this.getTradingModesForPools([pool]),
124
- this.tradingLimitsService.getPoolTradingLimits(pool),
125
- ]);
126
- const circuitBreakerOk = isTradingEnabled(tradingMode);
127
- // Limits are OK if no limits configured OR all limits have capacity
128
- const limitsOk = limits.length === 0 || limits.every((l) => l.maxIn > 0n && l.maxOut > 0n);
129
- return {
130
- tradable: circuitBreakerOk && limitsOk,
131
- circuitBreakerOk,
132
- tradingMode,
133
- limitsOk,
134
- limits,
135
- };
136
- }
137
- /**
138
- * Get the reference rate feed ID for a pool.
139
- * Both FPMM and Virtual pools expose this via the referenceRateFeedID() view function.
140
- *
141
- * @param pool - The pool to get rate feed ID for
142
- * @returns The rate feed ID address
143
- */
144
- async getPoolRateFeedId(pool) {
145
- const [rateFeedId] = await this.getPoolRateFeedIds([pool]);
146
- return rateFeedId;
147
- }
148
- async getTradingModesForPools(pools) {
149
- const rateFeedIds = await this.getPoolRateFeedIds(pools);
150
- return this.getTradingModesForRateFeeds(rateFeedIds);
151
- }
152
- async getPoolRateFeedIds(pools) {
153
- if (pools.length === 0) {
154
- return [];
155
- }
156
- const results = await multicall(this.publicClient, pools.map((pool) => ({
157
- address: pool.poolAddr,
158
- abi: FPMM_ABI,
159
- functionName: 'referenceRateFeedID',
160
- args: [],
161
- })), { allowFailure: false });
162
- return results.map((result) => {
163
- if (result.status === 'failure') {
164
- throw result.error;
165
- }
166
- return result.result;
167
- });
168
- }
169
- async getTradingModesForRateFeeds(rateFeedIds) {
170
- if (rateFeedIds.length === 0) {
171
- return [];
172
- }
173
- const breakerBoxAddr = getContractAddress(this.chainId, 'BreakerBox');
174
- const uniqueRateFeeds = Array.from(new Map(rateFeedIds.map((rateFeedId) => [rateFeedId.toLowerCase(), rateFeedId])).values());
175
- const results = await multicall(this.publicClient, uniqueRateFeeds.map((rateFeedId) => ({
176
- address: breakerBoxAddr,
177
- abi: BREAKERBOX_ABI,
178
- functionName: 'getRateFeedTradingMode',
179
- args: [rateFeedId],
180
- })), { allowFailure: false });
181
- const tradingModes = new Map();
182
- for (const [index, result] of results.entries()) {
183
- if (result.status === 'failure') {
184
- throw result.error;
185
- }
186
- tradingModes.set(uniqueRateFeeds[index].toLowerCase(), Number(result.result));
187
- }
188
- return rateFeedIds.map((rateFeedId) => {
189
- const tradingMode = tradingModes.get(rateFeedId.toLowerCase());
190
- if (tradingMode === undefined) {
191
- throw new Error(`Trading mode not found for rate feed ${rateFeedId}`);
192
- }
193
- return tradingMode;
194
- });
195
- }
196
- }
@@ -1,2 +0,0 @@
1
- export * from './TradingService';
2
- export * from './TradingLimitsService';
@@ -1,118 +0,0 @@
1
- import { celo } from 'viem/chains';
2
- import { defineChain } from 'viem';
3
- import { ChainId } from '../core/constants/chainId';
4
- // Celo Sepolia chain definition (not available in viem/chains yet)
5
- const celoSepolia = defineChain({
6
- id: 11142220,
7
- name: 'Celo Sepolia',
8
- nativeCurrency: {
9
- decimals: 18,
10
- name: 'CELO',
11
- symbol: 'CELO',
12
- },
13
- rpcUrls: {
14
- default: {
15
- http: ['https://forno.celo-sepolia.celo-testnet.org'],
16
- },
17
- },
18
- blockExplorers: {
19
- default: {
20
- name: 'Celo Explorer',
21
- url: 'https://sepolia.celoscan.io',
22
- },
23
- },
24
- testnet: true,
25
- });
26
- const monadTestnet = defineChain({
27
- id: 10143,
28
- name: 'Monad Testnet',
29
- nativeCurrency: {
30
- decimals: 18,
31
- name: 'MON',
32
- symbol: 'MON',
33
- },
34
- rpcUrls: {
35
- default: {
36
- http: ['https://testnet-rpc.monad.xyz'],
37
- },
38
- },
39
- blockExplorers: {
40
- default: {
41
- name: 'Monad Testnet Explorer',
42
- url: 'https://testnet.monadexplorer.com',
43
- },
44
- },
45
- contracts: {
46
- multicall3: {
47
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
48
- blockCreated: 251449,
49
- },
50
- },
51
- testnet: true,
52
- });
53
- const monad = defineChain({
54
- id: 143,
55
- name: 'Monad',
56
- nativeCurrency: {
57
- decimals: 18,
58
- name: 'MON',
59
- symbol: 'MON',
60
- },
61
- rpcUrls: {
62
- default: {
63
- http: ['https://rpc.monad.xyz'],
64
- },
65
- },
66
- blockExplorers: {
67
- default: {
68
- name: 'Monad Explorer',
69
- url: 'https://monadvision.com',
70
- },
71
- },
72
- contracts: {
73
- multicall3: {
74
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
75
- blockCreated: 9248132,
76
- },
77
- },
78
- });
79
- /**
80
- * Get the default RPC URL for a given chain ID
81
- * @param chainId - The chain ID
82
- * @returns The default RPC URL for the chain
83
- * @throws Error if chain ID is not supported
84
- */
85
- export function getDefaultRpcUrl(chainId) {
86
- switch (chainId) {
87
- case ChainId.CELO:
88
- return 'https://forno.celo.org';
89
- case ChainId.CELO_SEPOLIA:
90
- return 'https://forno.celo-sepolia.celo-testnet.org';
91
- case ChainId.MONAD_TESTNET:
92
- return 'https://testnet-rpc.monad.xyz';
93
- case ChainId.MONAD:
94
- return 'https://rpc.monad.xyz';
95
- default:
96
- throw new Error(`Unsupported chain ID: ${chainId}`);
97
- }
98
- }
99
- /**
100
- * Get the viem chain configuration for a given chain ID
101
- * @param chainId - The chain ID
102
- * @returns The viem chain configuration
103
- * @throws Error if chain ID is not supported
104
- */
105
- export function getChainConfig(chainId) {
106
- switch (chainId) {
107
- case ChainId.CELO:
108
- return celo;
109
- case ChainId.CELO_SEPOLIA:
110
- return celoSepolia;
111
- case ChainId.MONAD_TESTNET:
112
- return monadTestnet;
113
- case ChainId.MONAD:
114
- return monad;
115
- default:
116
- throw new Error(`Unsupported chain ID: ${chainId}`);
117
- }
118
- }
@@ -1,56 +0,0 @@
1
- import { PoolType } from '../core/types';
2
- import { FPMM_ABI } from '../core/abis';
3
- import { VIRTUAL_POOL_ABI } from '../core/abis/virtualPool';
4
- import { multicall } from './multicall';
5
- /**
6
- * Calculate cost percentage for a pool based on its type
7
- * Returns cost as a percentage (e.g., 0.5 = 0.5%)
8
- *
9
- * @param pool - The pool to calculate cost for
10
- * @param publicClient - Viem public client for RPC calls
11
- * @returns Cost percentage for the pool
12
- */
13
- export async function getPoolCostPercent(pool, publicClient) {
14
- if (pool.poolType === PoolType.FPMM) {
15
- return getFPMMCostPercent(pool.poolAddr, publicClient);
16
- }
17
- else if (pool.poolType === PoolType.Virtual) {
18
- return getVirtualPoolCostPercent(pool.poolAddr, publicClient);
19
- }
20
- else {
21
- throw new Error('Invalid pool type');
22
- }
23
- }
24
- /**
25
- * Calculate cost for FPMM pools
26
- * FPMM pools use lpFee + protocolFee in basis points (10000 = 100%)
27
- */
28
- async function getFPMMCostPercent(poolAddress, publicClient) {
29
- const results = await multicall(publicClient, [
30
- { address: poolAddress, abi: FPMM_ABI, functionName: 'lpFee' },
31
- { address: poolAddress, abi: FPMM_ABI, functionName: 'protocolFee' },
32
- ]);
33
- if (results[0].status === 'failure' || results[1].status === 'failure') {
34
- throw new Error(`Failed to read fees for pool ${poolAddress}`);
35
- }
36
- const lpFee = results[0].result;
37
- const protocolFee = results[1].result;
38
- // Convert from basis points to percentage using BigInt arithmetic to avoid precision loss
39
- const totalBasisPoints = lpFee + protocolFee;
40
- const scaled = totalBasisPoints * 1000000n;
41
- return Number(scaled / 100n) / 1e6;
42
- }
43
- /**
44
- * Calculate cost for Virtual pools
45
- */
46
- async function getVirtualPoolCostPercent(poolAddress, publicClient) {
47
- const results = await multicall(publicClient, [
48
- { address: poolAddress, abi: VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
49
- ]);
50
- if (results[0].status === 'failure') {
51
- throw new Error(`Failed to read protocolFee for pool ${poolAddress}`);
52
- }
53
- // Convert from basis points to percentage using BigInt arithmetic to avoid precision loss
54
- const scaled = results[0].result * 1000000n;
55
- return Number(scaled / 100n) / 1e6;
56
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Creates a deadline timestamp from a duration in minutes.
3
- *
4
- * @param minutes - Number of minutes from now
5
- * @returns Unix timestamp as bigint suitable for router contract deadline parameter
6
- *
7
- * @example
8
- * ```typescript
9
- * import { deadlineFromMinutes } from '@mento-protocol/mento-sdk'
10
- *
11
- * // 5 minute deadline
12
- * const deadline = deadlineFromMinutes(5)
13
- *
14
- * const swap = await mento.swap.buildSwapParams(
15
- * tokenIn, tokenOut, amountIn, recipient,
16
- * { slippageTolerance: 0.5, deadline }
17
- * )
18
- * ```
19
- */
20
- export function deadlineFromMinutes(minutes) {
21
- return BigInt(Date.now()) / 1000n + BigInt(minutes * 60);
22
- }
@@ -1,9 +0,0 @@
1
- export * from './retry';
2
- export * from './chainConfig';
3
- export * from './routes';
4
- export * from './sortUtils';
5
- export * from './pathEncoder';
6
- export * from './tokens';
7
- export * from './rateFeed';
8
- export * from './tradingLimits';
9
- export * from './deadline';
@@ -1,47 +0,0 @@
1
- /**
2
- * Standard Multicall3 contract address, deployed at the same address on all EVM chains.
3
- * https://www.multicall3.com/
4
- */
5
- export const MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
6
- /**
7
- * Wrapper around viem's multicall that explicitly provides the Multicall3 address.
8
- * This ensures multicall works even when the PublicClient was created without a `chain` config.
9
- */
10
- export async function multicall(publicClient, contracts, options = {}) {
11
- const { allowFailure = true, batchSize } = options;
12
- const client = publicClient;
13
- if (typeof client.multicall !== 'function') {
14
- if (typeof client.readContract !== 'function') {
15
- throw new Error('Public client does not support multicall or readContract');
16
- }
17
- return Promise.all(contracts.map(async (contract) => {
18
- try {
19
- const result = await client.readContract({
20
- ...contract,
21
- args: contract.args ?? [],
22
- });
23
- return { status: 'success', result };
24
- }
25
- catch (error) {
26
- if (!allowFailure) {
27
- throw error;
28
- }
29
- return {
30
- status: 'failure',
31
- error: error instanceof Error ? error : new Error(String(error)),
32
- };
33
- }
34
- }));
35
- }
36
- const raw = await client.multicall({
37
- allowFailure,
38
- batchSize,
39
- contracts: contracts,
40
- multicallAddress: MULTICALL3_ADDRESS,
41
- });
42
- const results = raw;
43
- if (!allowFailure) {
44
- return results.map((result) => ({ status: 'success', result }));
45
- }
46
- return results;
47
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * Converts a route path to the format expected by the Router contract.
3
- * Used by both QuoteService (getAmountsOut) and SwapService (swapTokensForTokens).
4
- *
5
- * @param path - The route path (array of pools)
6
- * @param tokenIn - The input token address (determines swap direction)
7
- * @param _tokenOut - The output token address (unused but kept for API clarity)
8
- * @returns Array of RouterRoute objects for the contract call
9
- * @throws {Error} If path is empty, too long, or contains invalid pools
10
- *
11
- * @example
12
- * ```typescript
13
- * const route = await routeService.findRoute(USDm, CELO)
14
- * const routerRoutes = encodeRoutePath(route.path, USDm, CELO)
15
- * // routerRoutes can now be passed to Router.getAmountsOut or Router.swapTokensForTokens
16
- * ```
17
- */
18
- export function encodeRoutePath(path, tokenIn, _tokenOut) {
19
- // Validate path is not empty
20
- if (!path || path.length === 0) {
21
- throw new Error('Internal error: Route path is empty. This should not happen - routes are validated before encoding.');
22
- }
23
- // Validate all pools have required structure
24
- for (let i = 0; i < path.length; i++) {
25
- const pool = path[i];
26
- if (!pool.token0 || !pool.token1 || !pool.factoryAddr) {
27
- throw new Error(`Invalid pool structure at index ${i}: missing required fields. ` +
28
- `Pool must have token0, token1, and factoryAddr. ` +
29
- `Got: ${JSON.stringify(pool)}`);
30
- }
31
- }
32
- const routes = [];
33
- const tokenInLower = tokenIn.toLowerCase();
34
- // Check if we need to reverse the path
35
- // The path is stored in canonical order, but we may need to traverse it backwards
36
- const firstPool = path[0];
37
- const startsWithTokenIn = firstPool.token0.toLowerCase() === tokenInLower || firstPool.token1.toLowerCase() === tokenInLower;
38
- // If tokenIn isn't in the first pool, reverse the path
39
- const orderedPath = startsWithTokenIn ? path : [...path].reverse();
40
- let currentTokenIn = tokenInLower;
41
- for (const pool of orderedPath) {
42
- const token0 = pool.token0.toLowerCase();
43
- const token1 = pool.token1.toLowerCase();
44
- // Determine direction: which token is the input for this hop?
45
- let from;
46
- let to;
47
- if (currentTokenIn === token0) {
48
- from = pool.token0;
49
- to = pool.token1;
50
- }
51
- else if (currentTokenIn === token1) {
52
- from = pool.token1;
53
- to = pool.token0;
54
- }
55
- else {
56
- throw new Error(`Route encoding error: Token ${currentTokenIn} not found in pool ${pool.poolAddr}. ` +
57
- `Pool contains tokens: ${token0}, ${token1}. ` +
58
- `This indicates the route path is invalid or tokens don't form a connected path.`);
59
- }
60
- routes.push({
61
- from,
62
- to,
63
- factory: pool.factoryAddr,
64
- });
65
- // The output of this hop becomes the input of the next hop
66
- currentTokenIn = to.toLowerCase();
67
- }
68
- return routes;
69
- }
@@ -1,23 +0,0 @@
1
- import { keccak256, toBytes } from 'viem';
2
- /**
3
- * Computes the rate feed ID from a rate feed identifier string.
4
- * Follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
5
- *
6
- * @param rateFeed - The rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
7
- * @returns The computed rate feed address as a hex string
8
- *
9
- * @example
10
- * ```typescript
11
- * const rateFeedId = toRateFeedId('EURUSD')
12
- * // Returns the computed address for the EURUSD rate feed
13
- *
14
- * const relayedRateFeedId = toRateFeedId('relayed:COPUSD')
15
- * // Returns the computed address for the relayed COPUSD rate feed
16
- * ```
17
- */
18
- export function toRateFeedId(rateFeed) {
19
- const hashedBytes = keccak256(toBytes(rateFeed));
20
- const hashAsBigInt = BigInt(hashedBytes);
21
- const maskedToUint160 = hashAsBigInt & ((1n << 160n) - 1n);
22
- return `0x${maskedToUint160.toString(16).padStart(40, '0')}`;
23
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Retry an operation a number of times with exponential backoff.
3
- * @param operation - The operation to retry
4
- * @param options - The retry options
5
- * @returns The result of the operation
6
- */
7
- export async function retryOperation(operation, options = {}) {
8
- const maxAttempts = options.maxAttempts ?? 3;
9
- const delayMs = options.initialDelayMs ?? 1000;
10
- let lastError;
11
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
12
- try {
13
- return await operation();
14
- }
15
- catch (error) {
16
- lastError = error;
17
- if (attempt === maxAttempts)
18
- break;
19
- // Exponential backoff
20
- await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
21
- }
22
- }
23
- throw new Error(`Operation failed after ${maxAttempts} attempts: ${lastError?.message}`);
24
- }
@@ -1,2 +0,0 @@
1
- // Re-export from consolidated cache
2
- export { getCachedRoutes, cachedRoutes } from '../cache/routes';
@@ -1,33 +0,0 @@
1
- /**
2
- * Sorts two token addresses to match the smart contract's _sortTokens behavior.
3
- * Compares addresses as numeric values (BigInt), matching Solidity's address comparison.
4
- *
5
- * Solidity reference:
6
- * ```solidity
7
- * function _sortTokens(address a, address b) private pure returns (address, address) {
8
- * return (a < b) ? (a, b) : (b, a);
9
- * }
10
- * ```
11
- */
12
- export function sortTokenAddresses(tokenA, tokenB) {
13
- return BigInt(tokenA) < BigInt(tokenB)
14
- ? [tokenA, tokenB]
15
- : [tokenB, tokenA];
16
- }
17
- /**
18
- * Creates a canonical route ID from two addresses.
19
- * Uses numeric address comparison to match contract behavior.
20
- */
21
- export function canonicalAddressKey(addressA, addressB, separator = '-') {
22
- const [first, second] = sortTokenAddresses(addressA, addressB);
23
- return `${first}${separator}${second}`;
24
- }
25
- /**
26
- * Creates a canonical pair key from two symbols.
27
- * Uses standard string comparison for human-readable IDs.
28
- */
29
- export function canonicalSymbolKey(symbolA, symbolB, separator = '-') {
30
- return symbolA < symbolB
31
- ? `${symbolA}${separator}${symbolB}`
32
- : `${symbolB}${separator}${symbolA}`;
33
- }
@@ -1,2 +0,0 @@
1
- // Re-export from consolidated cache
2
- export { TokenSymbol, cachedTokens, getCachedTokens, getCachedTokensSync, getTokenAddress, findTokenBySymbol, TOKEN_ADDRESSES_BY_CHAIN, } from '../cache/tokens';