@mento-protocol/mento-sdk 3.2.3 → 3.2.5

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 (396) hide show
  1. package/dist/cache/routes.d.ts +13 -0
  2. package/dist/cache/routes.js +14089 -0
  3. package/dist/cache/tokens.d.ts +68 -0
  4. package/dist/cache/tokens.js +460 -0
  5. package/dist/core/abis/activePool.d.ts +2 -0
  6. package/dist/core/abis/activePool.js +14 -0
  7. package/dist/core/abis/addressesRegistry.d.ts +2 -0
  8. package/dist/core/abis/addressesRegistry.js +26 -0
  9. package/dist/core/abis/bipoolmanager.d.ts +34 -0
  10. package/dist/core/abis/bipoolmanager.js +72 -0
  11. package/dist/core/abis/borrowerOperations.d.ts +9 -0
  12. package/dist/core/abis/borrowerOperations.js +89 -0
  13. package/dist/core/abis/breakerbox.d.ts +13 -0
  14. package/dist/core/abis/breakerbox.js +8 -0
  15. package/dist/core/abis/broker.d.ts +2 -0
  16. package/dist/core/abis/broker.js +9 -0
  17. package/dist/core/abis/erc20.d.ts +9 -0
  18. package/dist/core/abis/erc20.js +21 -0
  19. package/dist/core/abis/fpmm.d.ts +270 -0
  20. package/dist/core/abis/fpmm.js +49 -0
  21. package/dist/core/abis/fpmmFactory.d.ts +85 -0
  22. package/dist/core/abis/fpmmFactory.js +26 -0
  23. package/dist/core/abis/hintHelpers.d.ts +2 -0
  24. package/dist/core/abis/hintHelpers.js +14 -0
  25. package/dist/core/abis/index.d.ts +22 -0
  26. package/dist/core/abis/index.js +38 -0
  27. package/dist/core/abis/liquidityStrategy.d.ts +132 -0
  28. package/dist/core/abis/liquidityStrategy.js +10 -0
  29. package/dist/core/abis/multiTroveGetter.d.ts +8 -0
  30. package/dist/core/abis/multiTroveGetter.js +15 -0
  31. package/dist/core/abis/priceFeed.d.ts +7 -0
  32. package/dist/core/abis/priceFeed.js +16 -0
  33. package/dist/core/abis/pricingmodule.d.ts +2 -0
  34. package/dist/core/abis/pricingmodule.js +6 -0
  35. package/dist/core/abis/reserve.d.ts +3 -0
  36. package/dist/core/abis/reserve.js +18 -0
  37. package/dist/core/abis/router.d.ts +521 -0
  38. package/dist/core/abis/router.js +45 -0
  39. package/dist/core/abis/sortedTroves.d.ts +2 -0
  40. package/dist/core/abis/sortedTroves.js +15 -0
  41. package/dist/core/abis/systemParams.d.ts +2 -0
  42. package/dist/core/abis/systemParams.js +14 -0
  43. package/dist/core/abis/troveManager.d.ts +2 -0
  44. package/dist/core/abis/troveManager.js +27 -0
  45. package/dist/core/abis/troveNFT.d.ts +2 -0
  46. package/dist/core/abis/troveNFT.js +9 -0
  47. package/dist/core/abis/virtualPool.d.ts +50 -0
  48. package/dist/core/abis/virtualPool.js +11 -0
  49. package/dist/core/abis/virtualPoolFactory.d.ts +59 -0
  50. package/dist/core/abis/virtualPoolFactory.js +17 -0
  51. package/dist/core/constants/addresses.d.ts +18 -0
  52. package/dist/core/constants/addresses.js +113 -0
  53. package/dist/core/constants/borrowConstants.d.ts +10 -0
  54. package/dist/core/constants/borrowConstants.js +16 -0
  55. package/dist/core/constants/borrowRegistries.d.ts +7 -0
  56. package/dist/core/constants/borrowRegistries.js +30 -0
  57. package/dist/core/constants/chainId.d.ts +7 -0
  58. package/dist/{cjs/enums → core/constants}/chainId.js +4 -1
  59. package/dist/core/constants/contractNames.d.ts +21 -0
  60. package/dist/core/constants/contractNames.js +24 -0
  61. package/dist/core/constants/index.d.ts +6 -0
  62. package/dist/core/constants/index.js +22 -0
  63. package/dist/core/errors/base.d.ts +8 -0
  64. package/dist/core/errors/base.js +17 -0
  65. package/dist/core/errors/index.d.ts +4 -0
  66. package/dist/{cjs/constants → core/errors}/index.js +4 -4
  67. package/dist/core/errors/oracle.d.ts +9 -0
  68. package/dist/core/errors/oracle.js +15 -0
  69. package/dist/core/errors/router.d.ts +14 -0
  70. package/dist/core/errors/router.js +24 -0
  71. package/dist/core/types/borrow.d.ts +87 -0
  72. package/dist/{cjs/interfaces/tradingLimitsConfig.js → core/types/borrow.js} +1 -0
  73. package/dist/core/types/contractAddresses.d.ts +42 -0
  74. package/dist/{cjs → core}/types/contractAddresses.js +1 -0
  75. package/dist/core/types/index.d.ts +10 -0
  76. package/dist/core/types/index.js +26 -0
  77. package/dist/core/types/liquidity.d.ts +194 -0
  78. package/dist/core/types/liquidity.js +3 -0
  79. package/dist/core/types/pool.d.ts +208 -0
  80. package/dist/core/types/pool.js +14 -0
  81. package/dist/core/types/provider.d.ts +45 -0
  82. package/dist/{cjs/interfaces/tradingLimitsState.js → core/types/provider.js} +1 -0
  83. package/dist/core/types/route.d.ts +62 -0
  84. package/dist/{cjs/interfaces/IChainClient.js → core/types/route.js} +1 -0
  85. package/dist/core/types/token.d.ts +21 -0
  86. package/dist/{cjs/interfaces/tradingLimit.js → core/types/token.js} +1 -0
  87. package/dist/core/types/tradingLimits.d.ts +91 -0
  88. package/dist/core/types/tradingLimits.js +3 -0
  89. package/dist/core/types/tradingMode.d.ts +24 -0
  90. package/dist/core/types/tradingMode.js +31 -0
  91. package/dist/core/types/transaction.d.ts +45 -0
  92. package/dist/core/types/transaction.js +3 -0
  93. package/dist/esm/cache/routes.js +14084 -0
  94. package/dist/esm/cache/tokens.js +452 -0
  95. package/dist/esm/core/abis/activePool.js +10 -0
  96. package/dist/esm/core/abis/addressesRegistry.js +22 -0
  97. package/dist/esm/core/abis/bipoolmanager.js +68 -0
  98. package/dist/esm/core/abis/borrowerOperations.js +85 -0
  99. package/dist/esm/core/abis/breakerbox.js +4 -0
  100. package/dist/esm/core/abis/broker.js +5 -0
  101. package/dist/esm/core/abis/erc20.js +17 -0
  102. package/dist/esm/core/abis/fpmm.js +45 -0
  103. package/dist/esm/core/abis/fpmmFactory.js +22 -0
  104. package/dist/esm/core/abis/hintHelpers.js +10 -0
  105. package/dist/esm/core/abis/index.js +21 -0
  106. package/dist/esm/core/abis/liquidityStrategy.js +6 -0
  107. package/dist/esm/core/abis/multiTroveGetter.js +11 -0
  108. package/dist/esm/core/abis/priceFeed.js +12 -0
  109. package/dist/esm/core/abis/pricingmodule.js +2 -0
  110. package/dist/esm/core/abis/reserve.js +14 -0
  111. package/dist/esm/core/abis/router.js +41 -0
  112. package/dist/esm/core/abis/sortedTroves.js +11 -0
  113. package/dist/esm/core/abis/systemParams.js +10 -0
  114. package/dist/esm/core/abis/troveManager.js +23 -0
  115. package/dist/esm/core/abis/troveNFT.js +5 -0
  116. package/dist/esm/core/abis/virtualPool.js +7 -0
  117. package/dist/esm/core/abis/virtualPoolFactory.js +13 -0
  118. package/dist/esm/core/constants/addresses.js +107 -0
  119. package/dist/esm/core/constants/borrowConstants.js +12 -0
  120. package/dist/esm/core/constants/borrowRegistries.js +25 -0
  121. package/dist/esm/{enums → core/constants}/chainId.js +2 -0
  122. package/dist/esm/core/constants/contractNames.js +20 -0
  123. package/dist/esm/core/constants/index.js +5 -0
  124. package/dist/esm/core/errors/base.js +12 -0
  125. package/dist/esm/core/errors/index.js +3 -0
  126. package/dist/esm/core/errors/oracle.js +10 -0
  127. package/dist/esm/core/errors/router.js +18 -0
  128. package/dist/esm/core/types/index.js +9 -0
  129. package/dist/esm/core/types/pool.js +10 -0
  130. package/dist/esm/core/types/tradingLimits.js +1 -0
  131. package/dist/esm/core/types/tradingMode.js +26 -0
  132. package/dist/esm/core/types/transaction.js +1 -0
  133. package/dist/esm/index.js +138 -6
  134. package/dist/esm/package.json +1 -0
  135. package/dist/esm/services/borrow/BorrowService.js +455 -0
  136. package/dist/esm/services/borrow/borrowHelpers.js +3 -0
  137. package/dist/esm/services/borrow/borrowMath.js +127 -0
  138. package/dist/esm/services/borrow/index.js +3 -0
  139. package/dist/esm/services/borrow/internal/borrowApprovalService.js +48 -0
  140. package/dist/esm/services/borrow/internal/borrowContextStore.js +35 -0
  141. package/dist/esm/services/borrow/internal/borrowErc20.js +38 -0
  142. package/dist/esm/services/borrow/internal/borrowHints.js +27 -0
  143. package/dist/esm/services/borrow/internal/borrowPositionParser.js +82 -0
  144. package/dist/esm/services/borrow/internal/borrowReadService.js +271 -0
  145. package/dist/esm/services/borrow/internal/borrowRegistryReader.js +108 -0
  146. package/dist/esm/services/borrow/internal/borrowTransactionService.js +271 -0
  147. package/dist/esm/services/borrow/internal/borrowTypes.js +1 -0
  148. package/dist/esm/services/borrow/internal/borrowValidation.js +89 -0
  149. package/dist/esm/services/index.js +8 -0
  150. package/dist/esm/services/liquidity/LiquidityService.js +163 -0
  151. package/dist/esm/services/liquidity/basicLiquidity.js +162 -0
  152. package/dist/esm/services/liquidity/index.js +1 -0
  153. package/dist/esm/services/liquidity/liquidityHelpers.js +95 -0
  154. package/dist/esm/services/liquidity/rebalance.js +59 -0
  155. package/dist/esm/services/liquidity/zapHelpers.js +120 -0
  156. package/dist/esm/services/liquidity/zapIn.js +112 -0
  157. package/dist/esm/services/liquidity/zapOut.js +248 -0
  158. package/dist/esm/services/pools/PoolService.js +204 -0
  159. package/dist/esm/services/pools/index.js +1 -0
  160. package/dist/esm/services/pools/poolDetails.js +209 -0
  161. package/dist/esm/services/pools/poolDiscovery.js +112 -0
  162. package/dist/esm/services/pools/rebalancePreview.js +181 -0
  163. package/dist/esm/services/quotes/QuoteService.js +85 -0
  164. package/dist/esm/services/quotes/index.js +1 -0
  165. package/dist/esm/services/routes/RouteService.js +268 -0
  166. package/dist/esm/services/routes/index.js +1 -0
  167. package/dist/esm/services/swap/SwapService.js +247 -0
  168. package/dist/esm/services/swap/index.js +1 -0
  169. package/dist/esm/services/tokens/index.js +1 -0
  170. package/dist/esm/services/tokens/tokenService.js +285 -0
  171. package/dist/esm/services/trading/TradingLimitsService.js +154 -0
  172. package/dist/esm/services/trading/TradingService.js +222 -0
  173. package/dist/esm/services/trading/index.js +2 -0
  174. package/dist/esm/utils/chainConfig.js +118 -0
  175. package/dist/esm/utils/costUtils.js +56 -0
  176. package/dist/esm/utils/deadline.js +22 -0
  177. package/dist/esm/utils/index.js +9 -0
  178. package/dist/esm/utils/multicall.js +47 -0
  179. package/dist/esm/utils/pathEncoder.js +69 -0
  180. package/dist/esm/utils/rateFeed.js +23 -0
  181. package/dist/esm/utils/retry.js +24 -0
  182. package/dist/esm/{routeUtils.js → utils/routeUtils.js} +115 -116
  183. package/dist/esm/utils/routes.js +2 -0
  184. package/dist/esm/utils/sortUtils.js +33 -0
  185. package/dist/esm/utils/tokens.js +2 -0
  186. package/dist/esm/utils/tradingLimits.js +163 -0
  187. package/dist/esm/utils/validation.js +30 -0
  188. package/dist/index.d.ts +101 -0
  189. package/dist/index.js +158 -0
  190. package/dist/services/borrow/BorrowService.d.ts +381 -0
  191. package/dist/services/borrow/BorrowService.js +460 -0
  192. package/dist/services/borrow/borrowHelpers.d.ts +4 -0
  193. package/dist/services/borrow/borrowHelpers.js +13 -0
  194. package/dist/services/borrow/borrowMath.d.ts +21 -0
  195. package/dist/services/borrow/borrowMath.js +137 -0
  196. package/dist/services/borrow/index.d.ts +4 -0
  197. package/dist/{cjs/interfaces → services/borrow}/index.js +4 -4
  198. package/dist/services/borrow/internal/borrowApprovalService.d.ts +14 -0
  199. package/dist/services/borrow/internal/borrowApprovalService.js +53 -0
  200. package/dist/services/borrow/internal/borrowContextStore.d.ts +11 -0
  201. package/dist/services/borrow/internal/borrowContextStore.js +40 -0
  202. package/dist/services/borrow/internal/borrowErc20.d.ts +5 -0
  203. package/dist/services/borrow/internal/borrowErc20.js +43 -0
  204. package/dist/services/borrow/internal/borrowHints.d.ts +7 -0
  205. package/dist/services/borrow/internal/borrowHints.js +31 -0
  206. package/dist/services/borrow/internal/borrowPositionParser.d.ts +4 -0
  207. package/dist/services/borrow/internal/borrowPositionParser.js +87 -0
  208. package/dist/services/borrow/internal/borrowReadService.d.ts +31 -0
  209. package/dist/services/borrow/internal/borrowReadService.js +276 -0
  210. package/dist/services/borrow/internal/borrowRegistryReader.d.ts +5 -0
  211. package/dist/services/borrow/internal/borrowRegistryReader.js +113 -0
  212. package/dist/services/borrow/internal/borrowTransactionService.d.ts +23 -0
  213. package/dist/services/borrow/internal/borrowTransactionService.js +276 -0
  214. package/dist/services/borrow/internal/borrowTypes.d.ts +15 -0
  215. package/dist/services/borrow/internal/borrowTypes.js +3 -0
  216. package/dist/services/borrow/internal/borrowValidation.d.ts +14 -0
  217. package/dist/services/borrow/internal/borrowValidation.js +104 -0
  218. package/dist/services/index.d.ts +9 -0
  219. package/dist/{cjs → services}/index.js +9 -7
  220. package/dist/services/liquidity/LiquidityService.d.ts +139 -0
  221. package/dist/services/liquidity/LiquidityService.js +168 -0
  222. package/dist/services/liquidity/basicLiquidity.d.ts +11 -0
  223. package/dist/services/liquidity/basicLiquidity.js +172 -0
  224. package/dist/services/liquidity/index.d.ts +2 -0
  225. package/dist/{cjs/types → services/liquidity}/index.js +2 -2
  226. package/dist/services/liquidity/liquidityHelpers.d.ts +19 -0
  227. package/dist/services/liquidity/liquidityHelpers.js +104 -0
  228. package/dist/services/liquidity/rebalance.d.ts +6 -0
  229. package/dist/services/liquidity/rebalance.js +64 -0
  230. package/dist/services/liquidity/zapHelpers.d.ts +66 -0
  231. package/dist/services/liquidity/zapHelpers.js +129 -0
  232. package/dist/services/liquidity/zapIn.d.ts +18 -0
  233. package/dist/services/liquidity/zapIn.js +119 -0
  234. package/dist/services/liquidity/zapOut.d.ts +9 -0
  235. package/dist/services/liquidity/zapOut.js +255 -0
  236. package/dist/services/pools/PoolService.d.ts +69 -0
  237. package/dist/services/pools/PoolService.js +209 -0
  238. package/dist/services/pools/index.d.ts +2 -0
  239. package/dist/{cjs/enums → services/pools}/index.js +2 -3
  240. package/dist/services/pools/poolDetails.d.ts +13 -0
  241. package/dist/services/pools/poolDetails.js +216 -0
  242. package/dist/services/pools/poolDiscovery.d.ts +12 -0
  243. package/dist/services/pools/poolDiscovery.js +117 -0
  244. package/dist/services/pools/rebalancePreview.d.ts +5 -0
  245. package/dist/services/pools/rebalancePreview.js +186 -0
  246. package/dist/services/quotes/QuoteService.d.ts +51 -0
  247. package/dist/services/quotes/QuoteService.js +91 -0
  248. package/dist/services/quotes/index.d.ts +2 -0
  249. package/dist/services/quotes/index.js +18 -0
  250. package/dist/services/routes/RouteService.d.ts +117 -0
  251. package/dist/services/routes/RouteService.js +306 -0
  252. package/dist/services/routes/index.d.ts +2 -0
  253. package/dist/services/routes/index.js +18 -0
  254. package/dist/services/swap/SwapService.d.ts +198 -0
  255. package/dist/services/swap/SwapService.js +252 -0
  256. package/dist/services/swap/index.d.ts +2 -0
  257. package/dist/services/swap/index.js +18 -0
  258. package/dist/services/tokens/index.d.ts +2 -0
  259. package/dist/services/tokens/index.js +18 -0
  260. package/dist/services/tokens/tokenService.d.ts +55 -0
  261. package/dist/services/tokens/tokenService.js +290 -0
  262. package/dist/services/trading/TradingLimitsService.d.ts +38 -0
  263. package/dist/services/trading/TradingLimitsService.js +159 -0
  264. package/dist/services/trading/TradingService.d.ts +115 -0
  265. package/dist/services/trading/TradingService.js +227 -0
  266. package/dist/services/trading/index.d.ts +3 -0
  267. package/dist/services/trading/index.js +19 -0
  268. package/dist/utils/chainConfig.d.ts +16 -0
  269. package/dist/utils/chainConfig.js +123 -0
  270. package/dist/utils/costUtils.d.ts +12 -0
  271. package/dist/utils/costUtils.js +60 -0
  272. package/dist/utils/deadline.d.ts +21 -0
  273. package/dist/utils/deadline.js +26 -0
  274. package/dist/utils/index.d.ts +10 -0
  275. package/dist/utils/index.js +26 -0
  276. package/dist/utils/multicall.d.ts +30 -0
  277. package/dist/utils/multicall.js +52 -0
  278. package/dist/utils/pathEncoder.d.ts +34 -0
  279. package/dist/utils/pathEncoder.js +73 -0
  280. package/dist/utils/rateFeed.d.ts +18 -0
  281. package/dist/utils/rateFeed.js +27 -0
  282. package/dist/utils/retry.d.ts +12 -0
  283. package/dist/utils/retry.js +28 -0
  284. package/dist/{esm → utils}/routeUtils.d.ts +84 -93
  285. package/dist/{cjs → utils}/routeUtils.js +123 -124
  286. package/dist/utils/routes.d.ts +3 -0
  287. package/dist/utils/routes.js +8 -0
  288. package/dist/utils/sortUtils.d.ts +24 -0
  289. package/dist/utils/sortUtils.js +39 -0
  290. package/dist/utils/tokens.d.ts +2 -0
  291. package/dist/utils/tokens.js +13 -0
  292. package/dist/utils/tradingLimits.d.ts +41 -0
  293. package/dist/utils/tradingLimits.js +171 -0
  294. package/dist/utils/validation.d.ts +19 -0
  295. package/dist/utils/validation.js +34 -0
  296. package/package.json +1 -1
  297. package/dist/cjs/ChainClient.d.ts +0 -9
  298. package/dist/cjs/ChainClient.js +0 -58
  299. package/dist/cjs/TestChainClient.d.ts +0 -7
  300. package/dist/cjs/TestChainClient.js +0 -41
  301. package/dist/cjs/constants/addresses.d.ts +0 -4
  302. package/dist/cjs/constants/addresses.js +0 -59
  303. package/dist/cjs/constants/currencies.d.ts +0 -5
  304. package/dist/cjs/constants/currencies.js +0 -29
  305. package/dist/cjs/constants/index.d.ts +0 -4
  306. package/dist/cjs/constants/tokens.11142220.d.ts +0 -2
  307. package/dist/cjs/constants/tokens.11142220.js +0 -128
  308. package/dist/cjs/constants/tokens.42220.d.ts +0 -2
  309. package/dist/cjs/constants/tokens.42220.js +0 -128
  310. package/dist/cjs/constants/tokens.d.ts +0 -65
  311. package/dist/cjs/constants/tokens.js +0 -170
  312. package/dist/cjs/constants/tradablePairs.11142220.d.ts +0 -2
  313. package/dist/cjs/constants/tradablePairs.11142220.js +0 -7391
  314. package/dist/cjs/constants/tradablePairs.42220.d.ts +0 -2
  315. package/dist/cjs/constants/tradablePairs.42220.js +0 -7391
  316. package/dist/cjs/constants/tradablePairs.d.ts +0 -16
  317. package/dist/cjs/constants/tradablePairs.js +0 -53
  318. package/dist/cjs/enums/chainId.d.ts +0 -4
  319. package/dist/cjs/enums/index.d.ts +0 -3
  320. package/dist/cjs/enums/proposalState.d.ts +0 -10
  321. package/dist/cjs/enums/proposalState.js +0 -14
  322. package/dist/cjs/enums/tradingMode.d.ts +0 -17
  323. package/dist/cjs/enums/tradingMode.js +0 -21
  324. package/dist/cjs/governance.d.ts +0 -62
  325. package/dist/cjs/governance.js +0 -151
  326. package/dist/cjs/index.d.ts +0 -7
  327. package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
  328. package/dist/cjs/interfaces/index.d.ts +0 -4
  329. package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
  330. package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
  331. package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
  332. package/dist/cjs/limits.d.ts +0 -33
  333. package/dist/cjs/limits.js +0 -130
  334. package/dist/cjs/mento.d.ts +0 -287
  335. package/dist/cjs/mento.js +0 -699
  336. package/dist/cjs/routeUtils.d.ts +0 -304
  337. package/dist/cjs/types/contractAddressMap.d.ts +0 -4
  338. package/dist/cjs/types/contractAddressMap.js +0 -2
  339. package/dist/cjs/types/contractAddresses.d.ts +0 -23
  340. package/dist/cjs/types/index.d.ts +0 -2
  341. package/dist/cjs/utils.d.ts +0 -80
  342. package/dist/cjs/utils.js +0 -177
  343. package/dist/esm/ChainClient.d.ts +0 -9
  344. package/dist/esm/ChainClient.js +0 -54
  345. package/dist/esm/TestChainClient.d.ts +0 -7
  346. package/dist/esm/TestChainClient.js +0 -37
  347. package/dist/esm/constants/addresses.d.ts +0 -4
  348. package/dist/esm/constants/addresses.js +0 -55
  349. package/dist/esm/constants/currencies.d.ts +0 -5
  350. package/dist/esm/constants/currencies.js +0 -26
  351. package/dist/esm/constants/index.d.ts +0 -4
  352. package/dist/esm/constants/index.js +0 -4
  353. package/dist/esm/constants/tokens.11142220.d.ts +0 -2
  354. package/dist/esm/constants/tokens.11142220.js +0 -125
  355. package/dist/esm/constants/tokens.42220.d.ts +0 -2
  356. package/dist/esm/constants/tokens.42220.js +0 -125
  357. package/dist/esm/constants/tokens.d.ts +0 -65
  358. package/dist/esm/constants/tokens.js +0 -142
  359. package/dist/esm/constants/tradablePairs.11142220.d.ts +0 -2
  360. package/dist/esm/constants/tradablePairs.11142220.js +0 -7388
  361. package/dist/esm/constants/tradablePairs.42220.d.ts +0 -2
  362. package/dist/esm/constants/tradablePairs.42220.js +0 -7388
  363. package/dist/esm/constants/tradablePairs.d.ts +0 -16
  364. package/dist/esm/constants/tradablePairs.js +0 -26
  365. package/dist/esm/enums/chainId.d.ts +0 -4
  366. package/dist/esm/enums/index.d.ts +0 -3
  367. package/dist/esm/enums/index.js +0 -3
  368. package/dist/esm/enums/proposalState.d.ts +0 -10
  369. package/dist/esm/enums/proposalState.js +0 -11
  370. package/dist/esm/enums/tradingMode.d.ts +0 -17
  371. package/dist/esm/enums/tradingMode.js +0 -18
  372. package/dist/esm/governance.d.ts +0 -62
  373. package/dist/esm/governance.js +0 -147
  374. package/dist/esm/index.d.ts +0 -7
  375. package/dist/esm/interfaces/IChainClient.d.ts +0 -6
  376. package/dist/esm/interfaces/index.d.ts +0 -4
  377. package/dist/esm/interfaces/index.js +0 -4
  378. package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
  379. package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
  380. package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
  381. package/dist/esm/limits.d.ts +0 -33
  382. package/dist/esm/limits.js +0 -123
  383. package/dist/esm/mento.d.ts +0 -287
  384. package/dist/esm/mento.js +0 -671
  385. package/dist/esm/types/contractAddressMap.d.ts +0 -4
  386. package/dist/esm/types/contractAddresses.d.ts +0 -23
  387. package/dist/esm/types/index.d.ts +0 -2
  388. package/dist/esm/types/index.js +0 -2
  389. package/dist/esm/utils.d.ts +0 -80
  390. package/dist/esm/utils.js +0 -162
  391. /package/dist/esm/{interfaces/IChainClient.js → core/types/borrow.js} +0 -0
  392. /package/dist/esm/{types → core/types}/contractAddresses.js +0 -0
  393. /package/dist/esm/{interfaces/tradingLimit.js → core/types/liquidity.js} +0 -0
  394. /package/dist/esm/{interfaces/tradingLimitsConfig.js → core/types/provider.js} +0 -0
  395. /package/dist/esm/{interfaces/tradingLimitsState.js → core/types/route.js} +0 -0
  396. /package/dist/esm/{types/contractAddressMap.js → core/types/token.js} +0 -0
@@ -1,304 +0,0 @@
1
- import { TradablePairWithSpread } from './constants';
2
- import { Address } from './interfaces';
3
- import { TradablePair, TradablePairID } from './mento';
4
- type TokenSymbol = string;
5
- interface ExchangeDetails {
6
- providerAddr: Address;
7
- id: string;
8
- assets: [Address, Address];
9
- }
10
- /**
11
- * =============================================================================
12
- * ROUTE GENERATION UTILITIES
13
- * =============================================================================
14
- *
15
- * Utilities for generating optimal trading routes in the Mento protocol.
16
- *
17
- * The main workflow is:
18
- *
19
- * 1. Build connectivity structures from direct trading pairs
20
- * 2. Generate all possible routes (direct + two-hop)
21
- * 3. Select optimal routes using spread data or heuristics
22
- *
23
- * ALGORITHM OVERVIEW:
24
- * - Creates a graph where tokens are nodes and direct exchanges are edges
25
- * - Uses graph traversal to find two-hop routes through intermediate tokens
26
- * - Optimizes route selection based on spread costs when available
27
- * - Falls back to heuristics (prefer direct routes, major stablecoins)
28
- * =============================================================================
29
- */
30
- /**
31
- * Connectivity data structure that represents the token graph connecting all tokens.
32
- * Helps to efficiently answer: "How can I trade from token A to token B?"
33
- *
34
- * CONCRETE EXAMPLE:
35
- * Given these direct trading pairs:
36
- * - cUSD ↔ CELO (direct exchange exists)
37
- * - CELO ↔ cEUR (direct exchange exists)
38
- * - cUSD ↔ cREAL (direct exchange exists)
39
- *
40
- * How route finding works:
41
- * - Direct route: cUSD → cEUR? Check token graph: cUSD connects to [CELO, cREAL], none is cEUR → No direct route
42
- * - Two-hop route: cUSD → ? → cEUR?
43
- * - cUSD connects to CELO, CELO connects to cEUR → Found route: cUSD → CELO → cEUR
44
- * - cUSD connects to cREAL, cREAL connects to [cUSD] → No route via cREAL
45
- *
46
- * The "connectivity" part means we can quickly traverse the network of
47
- * token connections to find all possible trading paths.
48
- */
49
- export interface ConnectivityData {
50
- /** Maps token address to symbol for efficient lookups
51
- *
52
- * ```
53
- * '0x765D...' → 'cUSD'
54
- * '0x471E...' → 'CELO'
55
- * '0xD876...' → 'cEUR'
56
- * ```
57
- */
58
- addrToSymbol: Map<Address, TokenSymbol>;
59
- /** Adjacency list mapping which tokens connect to which
60
- * Used for finding two-hop routes by traversing token → neighbor → neighbor.
61
- *
62
- * Example for a cUSD => cEUR swap: First we find cUSD → [CELO, cKES, ...]
63
- * Then we find CELO → [cUSD, cEUR, ...] = found route via cUSD → CELO → cEUR
64
- *
65
- * ```
66
- * 'cUSD_addr' → Set(['CELO_addr', 'cKES_addr']) // cUSD connects to CELO and cKES
67
- * 'CELO_addr' → Set(['cUSD_addr', 'cEUR_addr']) // CELO connects to cUSD and cEUR
68
- * 'cEUR_addr' → Set(['CELO_addr']) // cEUR connects to CELO
69
- * 'cKES_addr' → Set(['cUSD_addr']) // cKES connects to cUSD
70
- * ```
71
- */
72
- tokenGraph: Map<Address, Set<Address>>;
73
- /** Maps sorted token address pairs to their direct exchange hop details
74
- * ```
75
- * 'CELO_addr-cEUR_addr' → { exchange details for CELO ↔ cEUR }
76
- * 'CELO_addr-cUSD_addr' → { exchange details for CELO ↔ cUSD }
77
- * 'cUSD_addr-cKES_addr' → { exchange details for cUSD ↔ cKES }
78
- * ```
79
- */
80
- directPathMap: Map<TradablePairID, ExchangeDetails>;
81
- /** Original direct trading pairs from mento.getDirectPairs() for reference */
82
- directPairs: TradablePair[];
83
- }
84
- /**
85
- * Builds the connectivity data structures needed for route generation.
86
- *
87
- * Transforms a list of direct trading pairs into our ConnectivityData
88
- * that allow us to quickly find trading routes.
89
- *
90
- * **Construction Process:**
91
- *
92
- * ```
93
- * Input: TradablePairs = [
94
- * { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1_CELO_cUSD] },
95
- * { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2_CELO_cEUR] }
96
- * ]
97
- *
98
- * Step 1 - Build addrToSymbol map:
99
- * cUSD.address → 'cUSD'
100
- * CELO.address → 'CELO'
101
- * cEUR.address → 'cEUR'
102
- *
103
- * Step 2 - Build directPathMap (sorted alphabetically for consistency):
104
- * 'CELO_addr-cEUR_addr' → exchange2_CELO_cEUR
105
- * 'CELO_addr-cUSD_addr' → exchange1_CELO_cUSD
106
- *
107
- * Step 3 - Build bidirectional tokenGraph:
108
- * cUSD.address → Set([CELO.address])
109
- * CELO.address → Set([cUSD.address, cEUR.address])
110
- * cEUR.address → Set([CELO.address])
111
- * ```
112
- *
113
- * **Result**: We can now efficiently answer:
114
- * - "What's the symbol for address X?" → addrToSymbol.get(addr)
115
- * - "What exchange connects tokens X and Y?" → directPathMap.get(sortedAddressPairKey)
116
- * - "What tokens can I reach from token X?" → tokenGraph.get(X)
117
- *
118
- * @param directPairs - Array of direct trading pairs
119
- * @returns Connectivity data structure for efficient route generation
120
- *
121
- * @example
122
- * ```typescript
123
- * const directPairs = [
124
- * { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1] },
125
- * { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2] }
126
- * ]
127
- *
128
- * const connectivityData = buildConnectivityStructures(directPairs)
129
- *
130
- * // Now we can efficiently find routes:
131
- * // 1. Check if cUSD connects to anything: connectivityData.tokenGraph.get(cUSD.address) → [CELO.address]
132
- * // 2. Check if CELO connects to cEUR: connectivityData.tokenGraph.get(CELO.address) → [cUSD.address, cEUR.address] ✓
133
- * // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-cEUR_addr') → exchange2_CELO_cEUR
134
- * // Result: Found route cUSD → CELO → cEUR with exchange details
135
- * ```
136
- */
137
- export declare function buildConnectivityStructures(directPairs: TradablePair[]): ConnectivityData;
138
- /**
139
- * Generates all possible routes (direct + two-hop) using connectivity data.
140
- *
141
- * This function implements a route discovery algorithm that:
142
- *
143
- * 1. **Adds all direct pairs** (single-hop routes)
144
- * 2. **Discovers two-hop routes** using graph traversal:
145
- * - For each token A, find its neighbors (tokens directly connected)
146
- * - For each neighbor B, find B's neighbors
147
- * - If B connects to token C (C ≠ A), then A->B->C is a valid route
148
- *
149
- * **Route Deduplication**: Multiple routes between the same token pair
150
- * are collected in arrays, allowing the selection algorithm to choose
151
- * the best one based on spread data or heuristics.
152
- *
153
- * **Canonical Pair IDs**: All pairs use alphabetically sorted symbols
154
- * (e.g., 'cEUR-cUSD' not 'cUSD-cEUR') for consistent identification.
155
- *
156
- * @param connectivityData - The connectivity data from buildConnectivityStructures()
157
- * @returns Map of pair ID -> array of possible routes for that pair
158
- *
159
- * @example
160
- * ```typescript
161
- * // Given direct pairs: cUSD-CELO, CELO-cEUR, cUSD-USDC
162
- * const allRoutes = generateAllRoutes(connectivityData)
163
- *
164
- * // Results might include:
165
- * // 'cUSD-CELO' -> [{ path: [cUSD->CELO] }] // direct route
166
- * // 'cEUR-cUSD' -> [
167
- * // { path: [cUSD->USDC, USDC->cEUR] } // two-hop via USDC
168
- * // { path: [cUSD->CELO, CELO->cEUR] } // two-hop via CELO
169
- * // ]
170
- * ```
171
- */
172
- export declare function generateAllRoutes(connectivityData: ConnectivityData): Map<TradablePairID, TradablePair[]>;
173
- /**
174
- * Creates a two-hop tradable pair if valid exchange hops exist.
175
- *
176
- * 1. **Validates tokens exist** in the asset map
177
- * 2. **Finds exchange hops** for both segments of the route
178
- * 3. **Creates canonical pair structure** with sorted symbols
179
- *
180
- * **Route Structure**: The resulting pair represents trading from start->end
181
- * via intermediate token, but the assets are ordered alphabetically by symbol
182
- * for consistency (canonical form).
183
- *
184
- * **Path Representation**: The path array contains the actual exchange hops
185
- * needed to execute the trade, preserving the routing information.
186
- *
187
- * @param startToken - Starting token address
188
- * @param intermediate - Intermediate token address for routing
189
- * @param end - Destination token address
190
- * @param assetMap - Map of token address -> Asset details
191
- * @param directPathMap - Map of token pairs -> exchange hop details
192
- * @returns Route if valid route exists, null otherwise
193
- *
194
- * @example
195
- * ```typescript
196
- * // Create route: cUSD -> CELO -> cEUR
197
- * const pair = createTwoHopPair(
198
- * '0x765D...', // cUSD address
199
- * '0x471E...', // CELO address
200
- * '0xD876...', // cEUR address
201
- * addrToSymbol,
202
- * directPathMap
203
- * )
204
- *
205
- * // Result:
206
- * // {
207
- * // id: 'cEUR-cUSD', // alphabetical order
208
- * // assets: [cEUR, cUSD], // alphabetical order
209
- * // path: [ // actual routing path
210
- * // { cUSD->CELO exchange },
211
- * // { CELO->cEUR exchange }
212
- * // ]
213
- * // }
214
- * ```
215
- */
216
- export declare function createTwoHopPair(startToken: Address, intermediateToken: Address, endToken: Address, addrToSymbol: Map<Address, TokenSymbol>, directPathMap: Map<string, {
217
- providerAddr: Address;
218
- id: string;
219
- assets: [Address, Address];
220
- }>): TradablePair | null;
221
- /**
222
- * Selects optimal routes from all candidates based on spread data or heuristics.
223
- *
224
- * This is the route optimization engine that implements the following logic:
225
- *
226
- * **For Single Route**: Use it directly (no optimization needed)
227
- *
228
- * **For Multiple Routes**:
229
- * - If `returnAllRoutes=true`: Return all routes (used for cache generation)
230
- * - If `returnAllRoutes=false`: Apply optimization to select the best route
231
- *
232
- * **Route Selection Strategy**: Delegates to `selectBestRoute()` which uses
233
- * a multi-tier approach prioritizing cost efficiency and reliability.
234
- *
235
- * @param allRoutes - Map of pair ID -> array of possible routes
236
- * @param returnAllRoutes - Whether to return all routes or optimize selection
237
- * @param assetMap - Asset map for token symbol lookups during optimization
238
- * @returns Array of selected optimal routes
239
- *
240
- * @example
241
- * ```typescript
242
- * // Multiple routes for cUSD-cEUR pair
243
- * const candidates = new Map([
244
- * ['cEUR-cUSD', [
245
- * { path: [cUSD->CELO->cEUR], spreadData: { totalSpreadPercent: 0.5 } },
246
- * { path: [cUSD->cREAL->cEUR], spreadData: { totalSpreadPercent: 0.3 } },
247
- * { path: [cUSD->cEUR] } // direct route, no spread data
248
- * ]]
249
- * ])
250
- *
251
- * const optimal = selectOptimalRoutes(candidates, false, assetMap)
252
- * // Returns the cUSD->cREAL->cEUR route (lowest spread: 0.3%)
253
- * ```
254
- */
255
- export declare function selectOptimalRoutes(allRoutes: Map<TradablePairID, TradablePair[]>, returnAllRoutes: boolean, addrToSymbol: Map<Address, TokenSymbol>): (TradablePair | TradablePairWithSpread)[];
256
- /**
257
- * Selects the best route from candidates using spread data or fallback heuristics.
258
- *
259
- * This function implements a sophisticated route selection algorithm with
260
- * multiple optimization tiers:
261
- *
262
- * **Tier 1 - Spread-Based Optimization** (Preferred):
263
- * - Use routes with spread data (actual cost information)
264
- * - Select route with lowest `totalSpreadPercent`
265
- * - This provides the most cost-efficient trading
266
- *
267
- * **Tier 2 - Direct Route Preference** (Fallback):
268
- * - If no spread data available, prefer direct (single-hop) routes
269
- * - Direct routes have lower execution risk and gas costs
270
- *
271
- * **Tier 3 - Major Stablecoin Preference** (Final Fallback):
272
- * - For two-hop routes, prefer those going through major stablecoins
273
- * - Major FX currencies like cUSD and cEUR typically have better liquidity
274
- *
275
- * **Tier 4 - First Available** (Last Resort):
276
- * - If no other heuristics apply, use the first route found
277
- *
278
- * @param candidates - Array of possible routes for the same token pair
279
- * @param assetMap - Asset map for token symbol lookups
280
- * @returns The optimal route selected using the tier system
281
- *
282
- * @example
283
- * ```typescript
284
- * const candidates = [
285
- * { path: [A->B->C], spreadData: { totalSpreadPercent: 0.8 } },
286
- * { path: [A->D->C], spreadData: { totalSpreadPercent: 0.4 } }, // Winner: lowest spread
287
- * { path: [A->C] }, // direct route, no spread data
288
- * ]
289
- *
290
- * const best = selectBestRoute(candidates, assetMap)
291
- * // Returns the A->D->C route (0.4% spread)
292
- * ```
293
- */
294
- export declare function selectBestRoute(candidates: TradablePair[], addrToSymbol: Map<Address, TokenSymbol>): TradablePair | TradablePairWithSpread;
295
- /**
296
- * Extracts the intermediate token address from a two-hop route.
297
- * In a two-hop route A->B->C, this function finds token B (the intermediate).
298
- */
299
- export declare function getIntermediateToken(route: TradablePair): Address | undefined;
300
- /**
301
- * Type guard to check if a Route has spread data.
302
- */
303
- export declare function hasSpreadData(pair: TradablePair | TradablePairWithSpread): pair is TradablePairWithSpread;
304
- export {};
@@ -1,4 +0,0 @@
1
- import { ContractAddresses } from '.';
2
- export type ContractAddressMap = {
3
- [chainId: number]: Partial<ContractAddresses>;
4
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,23 +0,0 @@
1
- export type ContractAddresses = {
2
- GovernanceFactory: string;
3
- Airgrab: string;
4
- Emission: string;
5
- MentoGovernor: string;
6
- MentoToken: string;
7
- TimelockController: string;
8
- Locking: string;
9
- MentoRouter: string;
10
- Broker: string;
11
- BiPoolManager: string;
12
- BreakerBox: string;
13
- Reserve: string;
14
- ConstantSumPricingModule: string;
15
- ConstantProductPricingModule: string;
16
- MedianDeltaBreaker: string;
17
- ValueDeltaBreaker: string;
18
- StableToken: string;
19
- StableTokenEUR: string;
20
- StableTokenBRL: string;
21
- StableTokenXOF: string;
22
- SortedOracles: string;
23
- };
@@ -1,2 +0,0 @@
1
- export * from './contractAddresses';
2
- export * from './contractAddressMap';
@@ -1,80 +0,0 @@
1
- import { BigNumberish, providers, Signer } from 'ethers';
2
- import { TokenSymbol } from './constants';
3
- import { Address } from './interfaces';
4
- import { Token, TradablePair } from './mento';
5
- /**
6
- * Gets the chain ID from a signer or provider
7
- * @param signerOrProvider an ethers provider or signer
8
- * @returns the chain ID
9
- */
10
- export declare function getChainId(signerOrProvider: Signer | providers.Provider): Promise<number>;
11
- /**
12
- * Ensures that given signer is truly a a connected signer
13
- * @param signer an ethers signer
14
- * @throws if signer is invalid or not connected
15
- */
16
- export declare function validateSigner(signer: Signer): void;
17
- /**
18
- * Ensures that given signerOrProvider is truly a provider or a connected signer
19
- * @param signerOrProvider an ethers provider or signer
20
- * @throws if signerOrProvider is invalid or not connected
21
- */
22
- export declare function validateSignerOrProvider(signerOrProvider: Signer | providers.Provider): void;
23
- /**
24
- * Returns the symbol of an erc20 token
25
- * @param tokenAddr the address of the erc20 token
26
- * @param signerOrProvider an ethers provider or signer
27
- * @returns the symbol of the erc20 token
28
- */
29
- export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<TokenSymbol>;
30
- /**
31
- * Returns the name of an erc20 token
32
- * @param tokenAddr the address of the erc20 token
33
- * @param signerOrProvider an ethers provider or signer
34
- * @returns the name of the erc20 token
35
- */
36
- export declare function getNameFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<string>;
37
- /**
38
- * Returns the decimals of an erc20 token
39
- * @param tokenAddr the address of the erc20 token
40
- * @param signerOrProvider an ethers provider or signer
41
- * @returns the decimals of the erc20 token
42
- */
43
- export declare function getDecimalsFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<number>;
44
- /**
45
- * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
46
- * @param tokenAddr the address of the erc20 token
47
- * @param spender the address of the spender
48
- * @param amount the amount to increase the allowance by
49
- * @param signerOrProvider an ethers signer or provider
50
- * @returns the populated TransactionRequest object
51
- */
52
- export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;
53
- /**
54
- * Find a token address by its symbol from tradable pairs
55
- * @param pairs array of tradable pairs to search through
56
- * @param symbol the token symbol to find (case-insensitive)
57
- * @returns the token address if found, null otherwise
58
- */
59
- export declare function findTokenAddressBySymbolInTradablePairs(symbol: TokenSymbol, pairs: readonly TradablePair[]): Address | null;
60
- export declare function capitalize(str: string): string; /**
61
- * Helper function to get token address by symbol for a specific chain
62
- * @param symbol - The token symbol
63
- * @param chainId - The chain ID
64
- * @returns The token address or undefined if not found
65
- */
66
- export declare function getTokenAddress(symbol: TokenSymbol, chainId: number): string | undefined;
67
- /**
68
- * Helper function to find a token by symbol in the cached tokens
69
- * @param symbol - The token symbol to search for
70
- * @param chainId - The chain ID
71
- * @returns The token object or undefined if not found
72
- */
73
- export declare function findTokenBySymbol(symbol: string, chainId: number): Token | undefined;
74
- /**
75
- * Computes the rate feed ID from a rate feed identifier string.
76
- * This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
77
- * @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
78
- * @returns the computed rate feed address
79
- */
80
- export declare function toRateFeedId(rateFeed: string): Address;
package/dist/cjs/utils.js DELETED
@@ -1,177 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.toRateFeedId = exports.findTokenBySymbol = exports.getTokenAddress = exports.capitalize = exports.findTokenAddressBySymbolInTradablePairs = exports.increaseAllowance = exports.getDecimalsFromTokenAddress = exports.getNameFromTokenAddress = exports.getSymbolFromTokenAddress = exports.validateSignerOrProvider = exports.validateSigner = exports.getChainId = void 0;
13
- const ethers_1 = require("ethers");
14
- const tokens_1 = require("./constants/tokens");
15
- /**
16
- * Gets the chain ID from a signer or provider
17
- * @param signerOrProvider an ethers provider or signer
18
- * @returns the chain ID
19
- */
20
- function getChainId(signerOrProvider) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const provider = ethers_1.Signer.isSigner(signerOrProvider)
23
- ? signerOrProvider.provider
24
- : signerOrProvider;
25
- return (yield provider.getNetwork()).chainId;
26
- });
27
- }
28
- exports.getChainId = getChainId;
29
- /**
30
- * Ensures that given signer is truly a a connected signer
31
- * @param signer an ethers signer
32
- * @throws if signer is invalid or not connected
33
- */
34
- function validateSigner(signer) {
35
- if (!ethers_1.Signer.isSigner(signer)) {
36
- throw new Error('A valid signer must be provided');
37
- }
38
- if (!ethers_1.providers.Provider.isProvider(signer.provider)) {
39
- throw new Error('Signer must be connected to a provider');
40
- }
41
- }
42
- exports.validateSigner = validateSigner;
43
- /**
44
- * Ensures that given signerOrProvider is truly a provider or a connected signer
45
- * @param signerOrProvider an ethers provider or signer
46
- * @throws if signerOrProvider is invalid or not connected
47
- */
48
- function validateSignerOrProvider(signerOrProvider) {
49
- const isSigner = ethers_1.Signer.isSigner(signerOrProvider);
50
- const isProvider = ethers_1.providers.Provider.isProvider(signerOrProvider);
51
- if (!isSigner && !isProvider) {
52
- throw new Error('A valid signer or provider must be provided');
53
- }
54
- if (isSigner && !ethers_1.providers.Provider.isProvider(signerOrProvider.provider)) {
55
- throw new Error('Signer must be connected to a provider');
56
- }
57
- }
58
- exports.validateSignerOrProvider = validateSignerOrProvider;
59
- /**
60
- * Returns the symbol of an erc20 token
61
- * @param tokenAddr the address of the erc20 token
62
- * @param signerOrProvider an ethers provider or signer
63
- * @returns the symbol of the erc20 token
64
- */
65
- function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const erc20Abi = ['function symbol() external view returns (string memory)'];
68
- const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
69
- return contract.symbol();
70
- });
71
- }
72
- exports.getSymbolFromTokenAddress = getSymbolFromTokenAddress;
73
- /**
74
- * Returns the name of an erc20 token
75
- * @param tokenAddr the address of the erc20 token
76
- * @param signerOrProvider an ethers provider or signer
77
- * @returns the name of the erc20 token
78
- */
79
- function getNameFromTokenAddress(tokenAddr, signerOrProvider) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const erc20Abi = ['function name() external view returns (string memory)'];
82
- const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
83
- return contract.name();
84
- });
85
- }
86
- exports.getNameFromTokenAddress = getNameFromTokenAddress;
87
- /**
88
- * Returns the decimals of an erc20 token
89
- * @param tokenAddr the address of the erc20 token
90
- * @param signerOrProvider an ethers provider or signer
91
- * @returns the decimals of the erc20 token
92
- */
93
- function getDecimalsFromTokenAddress(tokenAddr, signerOrProvider) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- const erc20Abi = ['function decimals() external view returns (uint8)'];
96
- const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
97
- return contract.decimals();
98
- });
99
- }
100
- exports.getDecimalsFromTokenAddress = getDecimalsFromTokenAddress;
101
- /**
102
- * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
103
- * @param tokenAddr the address of the erc20 token
104
- * @param spender the address of the spender
105
- * @param amount the amount to increase the allowance by
106
- * @param signerOrProvider an ethers signer or provider
107
- * @returns the populated TransactionRequest object
108
- */
109
- function increaseAllowance(tokenAddr, spender, amount, signerOrProvider) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const abi = [
112
- 'function increaseAllowance(address spender, uint256 value) external returns (bool)',
113
- ];
114
- // TODO, not all ERC-20 contracts support increaseAllowance
115
- // Add a check for that here
116
- const contract = new ethers_1.Contract(tokenAddr, abi, signerOrProvider);
117
- return yield contract.populateTransaction.increaseAllowance(spender, amount);
118
- });
119
- }
120
- exports.increaseAllowance = increaseAllowance;
121
- /**
122
- * Find a token address by its symbol from tradable pairs
123
- * @param pairs array of tradable pairs to search through
124
- * @param symbol the token symbol to find (case-insensitive)
125
- * @returns the token address if found, null otherwise
126
- */
127
- function findTokenAddressBySymbolInTradablePairs(symbol, pairs) {
128
- var _a, _b;
129
- return ((_b = (_a = pairs
130
- .flatMap((pair) => pair.assets)
131
- .find((asset) => asset.symbol.toLowerCase() === symbol.toLowerCase())) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b : null);
132
- }
133
- exports.findTokenAddressBySymbolInTradablePairs = findTokenAddressBySymbolInTradablePairs;
134
- function capitalize(str) {
135
- return str.charAt(0).toUpperCase() + str.slice(1);
136
- } /**
137
- * Helper function to get token address by symbol for a specific chain
138
- * @param symbol - The token symbol
139
- * @param chainId - The chain ID
140
- * @returns The token address or undefined if not found
141
- */
142
- exports.capitalize = capitalize;
143
- function getTokenAddress(symbol, chainId) {
144
- var _a;
145
- return (_a = tokens_1.TOKEN_ADDRESSES_BY_CHAIN[chainId]) === null || _a === void 0 ? void 0 : _a[symbol];
146
- }
147
- exports.getTokenAddress = getTokenAddress;
148
- /**
149
- * Helper function to find a token by symbol in the cached tokens
150
- * @param symbol - The token symbol to search for
151
- * @param chainId - The chain ID
152
- * @returns The token object or undefined if not found
153
- */
154
- function findTokenBySymbol(symbol, chainId) {
155
- const tokens = (0, tokens_1.getCachedTokensSync)(chainId);
156
- return tokens.find((token) => token.symbol === symbol);
157
- }
158
- exports.findTokenBySymbol = findTokenBySymbol;
159
- /**
160
- * Computes the rate feed ID from a rate feed identifier string.
161
- * This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
162
- * @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
163
- * @returns the computed rate feed address
164
- */
165
- function toRateFeedId(rateFeed) {
166
- // 1. Calculate keccak256 hash
167
- const hashedBytes = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.toUtf8Bytes(rateFeed));
168
- // 2. Convert to BigInt (equivalent to uint256)
169
- const hashAsBigInt = BigInt(hashedBytes);
170
- // 3. Mask to 160 bits (equivalent to uint160)
171
- const maskedToUint160 = hashAsBigInt & ((BigInt(1) << BigInt(160)) - BigInt(1));
172
- // 4. Convert to address (hex string)
173
- const addressHex = '0x' + maskedToUint160.toString(16).padStart(40, '0');
174
- // 5. Return calculated rate feed ID
175
- return addressHex;
176
- }
177
- exports.toRateFeedId = toRateFeedId;
@@ -1,9 +0,0 @@
1
- import { PopulatedTransaction, ethers, providers } from 'ethers';
2
- import { IChainClient } from './interfaces';
3
- export declare class ChainClient implements IChainClient {
4
- private readonly signerOrProvider;
5
- constructor(signerOrProvider: ethers.Signer | providers.Provider);
6
- getSigner(): Promise<ethers.Signer | providers.Provider>;
7
- getChainId(): Promise<number>;
8
- populateTransaction(tx: PopulatedTransaction): Promise<providers.TransactionRequest>;
9
- }
@@ -1,54 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Signer, providers } from 'ethers';
11
- import { validateSignerOrProvider } from './utils';
12
- export class ChainClient {
13
- constructor(signerOrProvider) {
14
- validateSignerOrProvider(signerOrProvider);
15
- this.signerOrProvider = signerOrProvider;
16
- }
17
- getSigner() {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- return this.signerOrProvider;
20
- });
21
- }
22
- getChainId() {
23
- var _a;
24
- return __awaiter(this, void 0, void 0, function* () {
25
- let chainId = 0;
26
- if (Signer.isSigner(this.signerOrProvider)) {
27
- const network = yield ((_a = this.signerOrProvider.provider) === null || _a === void 0 ? void 0 : _a.getNetwork());
28
- if (network) {
29
- chainId = network.chainId;
30
- }
31
- }
32
- else if (providers.Provider.isProvider(this.signerOrProvider)) {
33
- const network = yield this.signerOrProvider.getNetwork();
34
- if (network) {
35
- chainId = network.chainId;
36
- }
37
- }
38
- if (chainId === 0) {
39
- throw new Error('Could not get chainId from signer or provider');
40
- }
41
- return chainId;
42
- });
43
- }
44
- populateTransaction(tx) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- if (Signer.isSigner(this.signerOrProvider)) {
47
- return this.signerOrProvider.populateTransaction(tx);
48
- }
49
- else {
50
- return tx;
51
- }
52
- });
53
- }
54
- }
@@ -1,7 +0,0 @@
1
- import { PopulatedTransaction, ethers, providers } from 'ethers';
2
- import { IChainClient } from './interfaces';
3
- export declare class TestChainClient implements IChainClient {
4
- getSigner(): Promise<ethers.Signer | providers.Provider>;
5
- getChainId(): Promise<number>;
6
- populateTransaction(tx: PopulatedTransaction): Promise<providers.TransactionRequest>;
7
- }