@mento-protocol/mento-sdk 3.2.2-beta1 → 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
@@ -0,0 +1,16 @@
1
+ import { TradablePair } from '../mento';
2
+ export interface TradablePairWithSpread extends TradablePair {
3
+ spreadData: {
4
+ totalSpreadPercent: number;
5
+ hops: Array<{
6
+ exchangeId: string;
7
+ spreadPercent: number;
8
+ }>;
9
+ };
10
+ }
11
+ /**
12
+ * Gets cached tradable pairs for a specific chain ID
13
+ * @param chainId - The chain ID to get cached pairs for
14
+ * @returns Promise resolving to the cached tradable pairs or undefined if not available
15
+ */
16
+ export declare function getCachedTradablePairs(chainId: number): Promise<readonly (TradablePair | TradablePairWithSpread)[] | undefined>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.getCachedTradablePairs = void 0;
36
+ /**
37
+ * Gets cached tradable pairs for a specific chain ID
38
+ * @param chainId - The chain ID to get cached pairs for
39
+ * @returns Promise resolving to the cached tradable pairs or undefined if not available
40
+ */
41
+ function getCachedTradablePairs(chainId) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ switch (chainId) {
44
+ case 42220:
45
+ return yield Promise.resolve().then(() => __importStar(require('./tradablePairs.42220'))).then((module) => module.tradablePairs42220);
46
+ case 11142220:
47
+ return yield Promise.resolve().then(() => __importStar(require('./tradablePairs.11142220'))).then((module) => module.tradablePairs11142220);
48
+ default:
49
+ return undefined;
50
+ }
51
+ });
52
+ }
53
+ exports.getCachedTradablePairs = getCachedTradablePairs;
@@ -0,0 +1,4 @@
1
+ export declare enum ChainId {
2
+ CELO = 42220,
3
+ CELO_SEPOLIA = 11142220
4
+ }
@@ -5,7 +5,4 @@ var ChainId;
5
5
  (function (ChainId) {
6
6
  ChainId[ChainId["CELO"] = 42220] = "CELO";
7
7
  ChainId[ChainId["CELO_SEPOLIA"] = 11142220] = "CELO_SEPOLIA";
8
- ChainId[ChainId["MONAD_TESTNET"] = 10143] = "MONAD_TESTNET";
9
- ChainId[ChainId["MONAD"] = 143] = "MONAD";
10
- })(ChainId || (exports.ChainId = ChainId = {}));
11
- //# sourceMappingURL=chainId.js.map
8
+ })(ChainId = exports.ChainId || (exports.ChainId = {}));
@@ -0,0 +1,3 @@
1
+ export * from './chainId';
2
+ export * from './proposalState';
3
+ export * from './tradingMode';
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./LiquidityService"), exports);
18
- //# sourceMappingURL=index.js.map
17
+ __exportStar(require("./chainId"), exports);
18
+ __exportStar(require("./proposalState"), exports);
19
+ __exportStar(require("./tradingMode"), exports);
@@ -0,0 +1,10 @@
1
+ export declare enum ProposalState {
2
+ PENDING = 0,
3
+ ACTIVE = 1,
4
+ CANCELED = 2,
5
+ DEFEATED = 3,
6
+ SUCCEEDED = 4,
7
+ QUEUED = 5,
8
+ EXPIRED = 6,
9
+ EXECUTED = 7
10
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProposalState = void 0;
4
+ var ProposalState;
5
+ (function (ProposalState) {
6
+ ProposalState[ProposalState["PENDING"] = 0] = "PENDING";
7
+ ProposalState[ProposalState["ACTIVE"] = 1] = "ACTIVE";
8
+ ProposalState[ProposalState["CANCELED"] = 2] = "CANCELED";
9
+ ProposalState[ProposalState["DEFEATED"] = 3] = "DEFEATED";
10
+ ProposalState[ProposalState["SUCCEEDED"] = 4] = "SUCCEEDED";
11
+ ProposalState[ProposalState["QUEUED"] = 5] = "QUEUED";
12
+ ProposalState[ProposalState["EXPIRED"] = 6] = "EXPIRED";
13
+ ProposalState[ProposalState["EXECUTED"] = 7] = "EXECUTED";
14
+ })(ProposalState = exports.ProposalState || (exports.ProposalState = {}));
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Trading modes for rate feeds in the BreakerBox
3
+ */
4
+ export declare enum TradingMode {
5
+ /**
6
+ * Bidirectional trading is enabled
7
+ */
8
+ BIDIRECTIONAL = 0,
9
+ /**
10
+ * Trading is temporarily halted (circuit breaker tripped)
11
+ */
12
+ HALTED = 1,
13
+ /**
14
+ * Trading is permanently disabled
15
+ */
16
+ DISABLED = 2
17
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TradingMode = void 0;
4
+ /**
5
+ * Trading modes for rate feeds in the BreakerBox
6
+ */
7
+ var TradingMode;
8
+ (function (TradingMode) {
9
+ /**
10
+ * Bidirectional trading is enabled
11
+ */
12
+ TradingMode[TradingMode["BIDIRECTIONAL"] = 0] = "BIDIRECTIONAL";
13
+ /**
14
+ * Trading is temporarily halted (circuit breaker tripped)
15
+ */
16
+ TradingMode[TradingMode["HALTED"] = 1] = "HALTED";
17
+ /**
18
+ * Trading is permanently disabled
19
+ */
20
+ TradingMode[TradingMode["DISABLED"] = 2] = "DISABLED";
21
+ })(TradingMode = exports.TradingMode || (exports.TradingMode = {}));
@@ -0,0 +1,62 @@
1
+ import { BigNumberish, Signer, providers } from 'ethers';
2
+ import { MentoGovernor } from '@mento-protocol/mento-core-ts';
3
+ import { IChainClient } from './interfaces';
4
+ export declare class Governance {
5
+ private chainClient;
6
+ constructor(chainClient: IChainClient);
7
+ constructor(signerOrProvider: Signer | providers.Provider);
8
+ /**
9
+ * This function retrieves the MentoGovernor contract.
10
+ * @returns The MentoGovernor contract.
11
+ */
12
+ getGovernorContract(): Promise<MentoGovernor>;
13
+ /**
14
+ * Generates a transaction that submits a proposal to be created to the Mento Governor contract using the specified values.
15
+ * @param targets The addresses of the contracts to be called during proposal execution.
16
+ * @param values The values to be passed to the calls to the target contracts.
17
+ * @param calldatas The calldata to be passed to the calls to the target contracts.
18
+ * @param description A human readable description of the proposal.
19
+ * @returns The transaction request.
20
+ */
21
+ createProposal(targets: string[], values: BigNumberish[], calldatas: string[], description: string): Promise<providers.TransactionRequest>;
22
+ /**
23
+ * Generates a transaction that will queue the proposal with the specified id to be executed.
24
+ * @param proposalId The id of the proposal to queue.
25
+ * @returns The transaction request.
26
+ */
27
+ queueProposal(proposalId: BigNumberish): Promise<providers.TransactionRequest>;
28
+ /**
29
+ * Executes the proposal with the specified id.
30
+ * @param proposalId The id of the proposal to execute.
31
+ * @returns The transaction request.
32
+ */
33
+ executeProposal(proposalId: BigNumberish): Promise<providers.TransactionRequest>;
34
+ /**
35
+ * Submits a vote to the Mento Governor contract for the specified proposal.
36
+ * @param proposalId The id of the proposal to vote on.
37
+ * @param support Whether or not to support the proposal.
38
+ * @returns The transaction request.
39
+ */
40
+ castVote(proposalId: BigNumberish, support: BigNumberish): Promise<providers.TransactionRequest>;
41
+ /**
42
+ * Cancels the proposal with the specified id.
43
+ * @param proposalId The id of the proposal to vote on.
44
+ * @param support Whether or not to support the proposal.
45
+ * @returns The transaction request.
46
+ */
47
+ cancelProposal(proposalId: BigNumberish): Promise<providers.TransactionRequest>;
48
+ /**
49
+ * Returns the state of the proposal with the specified id.
50
+ * @param proposalId The id of the proposal to get the state of.
51
+ * @returns The state of the proposal.
52
+ */
53
+ getProposalState(proposalId: BigNumberish): Promise<string>;
54
+ /**
55
+ * This function validates the args that are to be used in the createProposal function.
56
+ * @param targets The addresses of the contracts to be called during proposal execution.
57
+ * @param values The values to be passed to the calls to the target contracts.
58
+ * @param calldatas The calldata to be passed to the calls to the target contracts.
59
+ * @param description A human readable description of the proposal.
60
+ */
61
+ private validateProposalArgs;
62
+ }
@@ -0,0 +1,151 @@
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.Governance = void 0;
13
+ const ethers_1 = require("ethers");
14
+ const mento_core_ts_1 = require("@mento-protocol/mento-core-ts");
15
+ const ChainClient_1 = require("./ChainClient");
16
+ const TestChainClient_1 = require("./TestChainClient");
17
+ const enums_1 = require("./enums");
18
+ const constants_1 = require("./constants");
19
+ class Governance {
20
+ constructor(arg) {
21
+ // TODO: Remove use of TestChainClient in future this is only meant for testing
22
+ if (arg instanceof ChainClient_1.ChainClient || arg instanceof TestChainClient_1.TestChainClient) {
23
+ this.chainClient = arg;
24
+ }
25
+ else if (ethers_1.Signer.isSigner(arg) || ethers_1.providers.Provider.isProvider(arg)) {
26
+ this.chainClient = new ChainClient_1.ChainClient(arg);
27
+ }
28
+ else {
29
+ throw new Error('Invalid constructor argument');
30
+ }
31
+ }
32
+ /**
33
+ * This function retrieves the MentoGovernor contract.
34
+ * @returns The MentoGovernor contract.
35
+ */
36
+ getGovernorContract() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const chainId = yield this.chainClient.getChainId();
39
+ const contracts = constants_1.addresses[chainId];
40
+ if (!contracts) {
41
+ throw new Error(`Contracts not deployed on network with chain id ${chainId}`);
42
+ }
43
+ const mentoGovernorAddress = contracts.MentoGovernor;
44
+ return mento_core_ts_1.MentoGovernor__factory.connect(mentoGovernorAddress, yield this.chainClient.getSigner());
45
+ });
46
+ }
47
+ /**
48
+ * Generates a transaction that submits a proposal to be created to the Mento Governor contract using the specified values.
49
+ * @param targets The addresses of the contracts to be called during proposal execution.
50
+ * @param values The values to be passed to the calls to the target contracts.
51
+ * @param calldatas The calldata to be passed to the calls to the target contracts.
52
+ * @param description A human readable description of the proposal.
53
+ * @returns The transaction request.
54
+ */
55
+ createProposal(targets, values, calldatas, description) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ this.validateProposalArgs(targets, values, calldatas, description);
58
+ const governor = yield this.getGovernorContract();
59
+ const tx = yield governor.populateTransaction['propose(address[],uint256[],bytes[],string)'](targets, values, calldatas, description);
60
+ return yield this.chainClient.populateTransaction(tx);
61
+ });
62
+ }
63
+ /**
64
+ * Generates a transaction that will queue the proposal with the specified id to be executed.
65
+ * @param proposalId The id of the proposal to queue.
66
+ * @returns The transaction request.
67
+ */
68
+ queueProposal(proposalId) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const governor = yield this.getGovernorContract();
71
+ const tx = yield governor.populateTransaction['queue(uint256)'](proposalId);
72
+ return yield this.chainClient.populateTransaction(tx);
73
+ });
74
+ }
75
+ /**
76
+ * Executes the proposal with the specified id.
77
+ * @param proposalId The id of the proposal to execute.
78
+ * @returns The transaction request.
79
+ */
80
+ executeProposal(proposalId) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const governor = yield this.getGovernorContract();
83
+ const tx = yield governor.populateTransaction['execute(uint256)'](proposalId);
84
+ return yield this.chainClient.populateTransaction(tx);
85
+ });
86
+ }
87
+ /**
88
+ * Submits a vote to the Mento Governor contract for the specified proposal.
89
+ * @param proposalId The id of the proposal to vote on.
90
+ * @param support Whether or not to support the proposal.
91
+ * @returns The transaction request.
92
+ */
93
+ castVote(proposalId, support) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const governor = yield this.getGovernorContract();
96
+ const tx = yield governor.populateTransaction.castVote(proposalId, support);
97
+ return yield this.chainClient.populateTransaction(tx);
98
+ });
99
+ }
100
+ /**
101
+ * Cancels the proposal with the specified id.
102
+ * @param proposalId The id of the proposal to vote on.
103
+ * @param support Whether or not to support the proposal.
104
+ * @returns The transaction request.
105
+ */
106
+ cancelProposal(proposalId) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const governor = yield this.getGovernorContract();
109
+ const tx = yield governor.populateTransaction.cancel(proposalId);
110
+ return yield this.chainClient.populateTransaction(tx);
111
+ });
112
+ }
113
+ /**
114
+ * Returns the state of the proposal with the specified id.
115
+ * @param proposalId The id of the proposal to get the state of.
116
+ * @returns The state of the proposal.
117
+ */
118
+ getProposalState(proposalId) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ const governor = yield this.getGovernorContract();
121
+ const state = (yield governor.functions.state(proposalId))[0];
122
+ return enums_1.ProposalState[state];
123
+ });
124
+ }
125
+ /**
126
+ * This function validates the args that are to be used in the createProposal function.
127
+ * @param targets The addresses of the contracts to be called during proposal execution.
128
+ * @param values The values to be passed to the calls to the target contracts.
129
+ * @param calldatas The calldata to be passed to the calls to the target contracts.
130
+ * @param description A human readable description of the proposal.
131
+ */
132
+ validateProposalArgs(targets, values, calldatas, description) {
133
+ if (!targets || targets.length === 0) {
134
+ throw new Error('Targets must be specified');
135
+ }
136
+ if (!values || values.length === 0) {
137
+ throw new Error('Values must be specified');
138
+ }
139
+ if (!calldatas || calldatas.length === 0) {
140
+ throw new Error('Calldatas must be specified');
141
+ }
142
+ if (!description) {
143
+ throw new Error('Description must be specified');
144
+ }
145
+ if (targets.length !== values.length ||
146
+ targets.length !== calldatas.length) {
147
+ throw new Error('Targets, values, and calldatas must all have the same length');
148
+ }
149
+ }
150
+ }
151
+ exports.Governance = Governance;
@@ -0,0 +1,7 @@
1
+ export * from './constants';
2
+ export * from './enums';
3
+ export * from './governance';
4
+ export * from './mento';
5
+ export * from './routeUtils';
6
+ export { ContractAddresses } from './types';
7
+ export * from './utils';
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ /* istanbul ignore file */
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
4
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -14,9 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
16
  };
16
17
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./addresses"), exports);
18
- __exportStar(require("./chainId"), exports);
19
- __exportStar(require("./contractNames"), exports);
20
- __exportStar(require("./borrowConstants"), exports);
21
- __exportStar(require("./borrowRegistries"), exports);
22
- //# sourceMappingURL=index.js.map
18
+ __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./enums"), exports);
20
+ __exportStar(require("./governance"), exports);
21
+ __exportStar(require("./mento"), exports);
22
+ __exportStar(require("./routeUtils"), exports);
23
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,6 @@
1
+ import { ethers, providers } from 'ethers';
2
+ export interface IChainClient {
3
+ getSigner(): Promise<ethers.Signer | providers.Provider>;
4
+ getChainId(): Promise<number>;
5
+ populateTransaction(tx: ethers.PopulatedTransaction): Promise<providers.TransactionRequest>;
6
+ }
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=route.js.map
@@ -0,0 +1,4 @@
1
+ export * from './tradingLimit';
2
+ export * from './tradingLimitsConfig';
3
+ export * from './tradingLimitsState';
4
+ export * from './IChainClient';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./base"), exports);
18
- __exportStar(require("./oracle"), exports);
19
- __exportStar(require("./router"), exports);
20
- //# sourceMappingURL=index.js.map
17
+ __exportStar(require("./tradingLimit"), exports);
18
+ __exportStar(require("./tradingLimitsConfig"), exports);
19
+ __exportStar(require("./tradingLimitsState"), exports);
20
+ __exportStar(require("./IChainClient"), exports);
@@ -0,0 +1,7 @@
1
+ export type Address = string;
2
+ export interface TradingLimit {
3
+ asset: Address;
4
+ maxIn: number;
5
+ maxOut: number;
6
+ until: number;
7
+ }
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=token.js.map
@@ -0,0 +1,10 @@
1
+ import { Address } from './tradingLimit';
2
+ export interface TradingLimitsConfig {
3
+ asset: Address;
4
+ timestep0: number;
5
+ timestep1: number;
6
+ limit0: number;
7
+ limit1: number;
8
+ limitGlobal: number;
9
+ flags: number;
10
+ }
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=borrow.js.map
@@ -0,0 +1,9 @@
1
+ import { Address } from './tradingLimit';
2
+ export interface TradingLimitsState {
3
+ asset: Address;
4
+ lastUpdated0: number;
5
+ lastUpdated1: number;
6
+ netflow0: number;
7
+ netflow1: number;
8
+ netflowGlobal: number;
9
+ }
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=provider.js.map
@@ -0,0 +1,33 @@
1
+ import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './interfaces';
2
+ import { Broker } from '@mento-protocol/mento-core-ts';
3
+ /**
4
+ * Returns the limit configuration in the broker for the given exchange and asset
5
+ * @param broker an instance of the broker
6
+ * @param exchangeId the id of the exchange
7
+ * @param asset the address of the limited asset
8
+ * @returns the limit configuration
9
+ */
10
+ export declare function getLimitsConfig(broker: Broker, exchangeId: string, asset: Address): Promise<TradingLimitsConfig>;
11
+ /**
12
+ * Returns the limit state in the broker for the given exchange and asset
13
+ * @param broker an instance of the broker
14
+ * @param exchangeId the id of the exchange
15
+ * @param asset the address of the limited asset
16
+ * @returns the limit state
17
+ */
18
+ export declare function getLimitsState(broker: Broker, exchangeId: string, asset: Address): Promise<TradingLimitsState>;
19
+ /**
20
+ * Returns a human-friendly representation of the limits for the given exchange and asset
21
+ * @param broker an instance of the broker
22
+ * @param exchangeId the id of the exchange
23
+ * @param asset the address of the asset with the limit
24
+ * @returns a list of TradingLimit objects
25
+ */
26
+ export declare function getLimits(broker: Broker, exchangeId: string, asset: Address): Promise<TradingLimit[]>;
27
+ /**
28
+ * Returns the limit id for the given exchange and asset
29
+ * @param exchangeId the id of the exchange
30
+ * @param asset the address of the asset with the limit
31
+ * @returns the limit id
32
+ */
33
+ export declare function getLimitId(exchangeId: string, asset: Address): string;
@@ -0,0 +1,130 @@
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.getLimitId = exports.getLimits = exports.getLimitsState = exports.getLimitsConfig = void 0;
13
+ const assert_1 = require("assert");
14
+ const ethers_1 = require("ethers");
15
+ /**
16
+ * Returns the limit configuration in the broker for the given exchange and asset
17
+ * @param broker an instance of the broker
18
+ * @param exchangeId the id of the exchange
19
+ * @param asset the address of the limited asset
20
+ * @returns the limit configuration
21
+ */
22
+ function getLimitsConfig(broker, exchangeId, asset) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const limitId = getLimitId(exchangeId, asset);
25
+ const cfg = yield broker.tradingLimitsConfig(limitId);
26
+ return {
27
+ asset,
28
+ timestep0: cfg['timestep0'],
29
+ timestep1: cfg['timestep1'],
30
+ limit0: cfg['limit0'],
31
+ limit1: cfg['limit1'],
32
+ limitGlobal: cfg['limitGlobal'],
33
+ flags: cfg['flags'],
34
+ };
35
+ });
36
+ }
37
+ exports.getLimitsConfig = getLimitsConfig;
38
+ /**
39
+ * Returns the limit state in the broker for the given exchange and asset
40
+ * @param broker an instance of the broker
41
+ * @param exchangeId the id of the exchange
42
+ * @param asset the address of the limited asset
43
+ * @returns the limit state
44
+ */
45
+ function getLimitsState(broker, exchangeId, asset) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const limitId = getLimitId(exchangeId, asset);
48
+ const [cfg, state] = yield Promise.all([
49
+ getLimitsConfig(broker, exchangeId, asset),
50
+ broker.tradingLimitsState(limitId),
51
+ ]);
52
+ const isL0Enabled = cfg.timestep0 > 0;
53
+ const isL1Enabled = cfg.timestep1 > 0;
54
+ const nowEpoch = Math.floor(Date.now() / 1000);
55
+ const isL0Outdated = isL0Enabled && nowEpoch > state['lastUpdated0'] + cfg.timestep0;
56
+ const isL1Outdated = isL1Enabled && nowEpoch > state['lastUpdated1'] + cfg.timestep1;
57
+ return {
58
+ asset,
59
+ lastUpdated0: isL0Outdated ? nowEpoch : state['lastUpdated0'],
60
+ lastUpdated1: isL1Outdated ? nowEpoch : state['lastUpdated1'],
61
+ netflow0: isL0Outdated ? 0 : state['netflow0'],
62
+ netflow1: isL1Outdated ? 0 : state['netflow1'],
63
+ netflowGlobal: state['netflowGlobal'],
64
+ };
65
+ });
66
+ }
67
+ exports.getLimitsState = getLimitsState;
68
+ /**
69
+ * Returns a human-friendly representation of the limits for the given exchange and asset
70
+ * @param broker an instance of the broker
71
+ * @param exchangeId the id of the exchange
72
+ * @param asset the address of the asset with the limit
73
+ * @returns a list of TradingLimit objects
74
+ */
75
+ function getLimits(broker, exchangeId, asset) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const [cfg, state] = yield Promise.all([
78
+ getLimitsConfig(broker, exchangeId, asset),
79
+ getLimitsState(broker, exchangeId, asset),
80
+ ]);
81
+ const limits = [];
82
+ if (cfg.limit0 > 0) {
83
+ limits.push({
84
+ asset: asset,
85
+ maxIn: cfg.limit0 - state.netflow0,
86
+ maxOut: cfg.limit0 + state.netflow0,
87
+ until: state.lastUpdated0 + cfg.timestep0,
88
+ });
89
+ }
90
+ if (cfg.limit1 > 0) {
91
+ limits.push({
92
+ asset: asset,
93
+ maxIn: cfg.limit1 - state.netflow1,
94
+ maxOut: cfg.limit1 + state.netflow1,
95
+ until: state.lastUpdated1 + cfg.timestep1,
96
+ });
97
+ }
98
+ if (cfg.limitGlobal > 0) {
99
+ const timestampIn2030 = 1893456000; // a far away timestamp
100
+ limits.push({
101
+ asset: asset,
102
+ maxIn: cfg.limitGlobal - state.netflowGlobal,
103
+ maxOut: cfg.limitGlobal + state.netflowGlobal,
104
+ until: timestampIn2030,
105
+ });
106
+ }
107
+ // Limits with a smaller timeframe are restricted by the ones with a larger one
108
+ // e.g: if maxIn is 0 in LG, it should also be 0 in L1 and L0
109
+ for (let i = limits.length - 1; i > 0; i--) {
110
+ limits[i - 1].maxIn = Math.min(limits[i - 1].maxIn, limits[i].maxIn);
111
+ limits[i - 1].maxOut = Math.min(limits[i - 1].maxOut, limits[i].maxOut);
112
+ }
113
+ return limits;
114
+ });
115
+ }
116
+ exports.getLimits = getLimits;
117
+ /**
118
+ * Returns the limit id for the given exchange and asset
119
+ * @param exchangeId the id of the exchange
120
+ * @param asset the address of the asset with the limit
121
+ * @returns the limit id
122
+ */
123
+ function getLimitId(exchangeId, asset) {
124
+ const assetBytes32 = ethers_1.utils.zeroPad(asset, 32);
125
+ const exchangeIdBytes = ethers_1.utils.arrayify(exchangeId);
126
+ const assetBytes = ethers_1.utils.arrayify(assetBytes32);
127
+ (0, assert_1.strict)(exchangeIdBytes.length === assetBytes.length, 'exchangeId and asset0 must be the same length');
128
+ return ethers_1.utils.hexlify(exchangeIdBytes.map((b, i) => b ^ assetBytes[i]));
129
+ }
130
+ exports.getLimitId = getLimitId;