@gmx-io/sdk 1.4.1 → 1.5.0-alpha-1

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 (418) hide show
  1. package/build/cjs/scripts/prebuild/index.js +6 -1
  2. package/build/cjs/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +2 -28
  3. package/build/cjs/scripts/prebuild/prebuildMarketConfigKeys.js +2 -2
  4. package/build/cjs/scripts/prebuild/prebuildMarketValuesKeys.js +2 -2
  5. package/build/cjs/scripts/subsquid-codegen.js +26 -0
  6. package/build/cjs/src/{utils → clients/v1}/callContract.js +4 -6
  7. package/build/cjs/src/{index.js → clients/v1/index.js} +4 -4
  8. package/build/cjs/src/{modules → clients/v1/modules}/accounts/accounts.js +1 -1
  9. package/build/cjs/src/{modules → clients/v1/modules}/accounts/accounts.spec.js +1 -1
  10. package/build/cjs/src/clients/v1/modules/markets/index.js +227 -0
  11. package/build/cjs/src/{modules → clients/v1/modules}/markets/markets.spec.js +1 -1
  12. package/build/cjs/src/{modules → clients/v1/modules}/oracle.js +1 -1
  13. package/build/cjs/src/{modules → clients/v1/modules}/orders/helpers.js +11 -9
  14. package/build/cjs/src/{modules → clients/v1/modules}/orders/helpers.spec.js +5 -5
  15. package/build/cjs/src/{modules → clients/v1/modules}/orders/orders.js +11 -11
  16. package/build/cjs/src/{modules → clients/v1/modules}/orders/orders.spec.js +1 -1
  17. package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/cancelOrdersTxn.js +2 -2
  18. package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createDecreaseOrderTxn.js +7 -7
  19. package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createIncreaseOrderTxn.js +11 -11
  20. package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createSwapOrderTxn.js +10 -10
  21. package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createWrapOrUnwrapTxn.js +2 -2
  22. package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/updateOrderTxn.js +3 -3
  23. package/build/cjs/src/{modules → clients/v1/modules}/orders/utils.js +7 -7
  24. package/build/cjs/src/{modules → clients/v1/modules}/positions/positions.js +11 -11
  25. package/build/cjs/src/{modules → clients/v1/modules}/positions/positions.spec.js +1 -1
  26. package/build/cjs/src/{modules → clients/v1/modules}/tokens/tokens.js +3 -3
  27. package/build/cjs/src/{modules → clients/v1/modules}/tokens/tokens.spec.js +1 -1
  28. package/build/cjs/src/{modules → clients/v1/modules}/trades/trades.js +19 -19
  29. package/build/cjs/src/{modules → clients/v1/modules}/trades/trades.spec.js +1 -1
  30. package/build/cjs/src/{modules → clients/v1/modules}/utils/utils.js +8 -8
  31. package/build/cjs/src/{utils → clients/v1}/multicall.js +4 -4
  32. package/build/cjs/src/{utils → clients/v1}/simulateExecuteOrder.js +5 -5
  33. package/build/cjs/src/{utils → clients/v1}/testUtil.js +2 -2
  34. package/build/cjs/src/clients/v2/index.js +21 -0
  35. package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +40 -0
  36. package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +285 -0
  37. package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +75 -0
  38. package/build/cjs/src/codegen/prebuilt/index.js +16 -0
  39. package/build/cjs/src/configs/api.js +15 -0
  40. package/build/cjs/src/configs/chains.js +29 -1
  41. package/build/cjs/src/configs/dataStore.js +6 -2
  42. package/build/cjs/src/configs/markets.js +35 -0
  43. package/build/cjs/src/configs/multichain.js +29 -19
  44. package/build/cjs/src/configs/tokens.js +49 -169
  45. package/build/cjs/src/test/mock.js +5 -122
  46. package/build/cjs/src/utils/24h/index.js +17 -0
  47. package/build/cjs/src/utils/LruCache/index.js +17 -0
  48. package/build/cjs/src/utils/__tests__/fees.spec.js +1 -1
  49. package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +2 -2
  50. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +33 -33
  51. package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +4 -4
  52. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +28 -28
  53. package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +20 -20
  54. package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +3 -3
  55. package/build/cjs/src/utils/__tests__/prices.spec.js +18 -18
  56. package/build/cjs/src/utils/abort/index.js +17 -0
  57. package/build/cjs/src/utils/bigmath/index.js +17 -0
  58. package/build/cjs/src/utils/buildUrl/index.js +17 -0
  59. package/build/cjs/src/utils/chains/index.js +17 -0
  60. package/build/cjs/src/utils/common/index.js +17 -0
  61. package/build/cjs/src/utils/{common.js → common/utils.js} +1 -2
  62. package/build/cjs/src/utils/fees/executionFee.js +2 -2
  63. package/build/cjs/src/utils/fees/index.js +9 -9
  64. package/build/cjs/src/utils/gelatoRelay/index.js +17 -0
  65. package/build/cjs/src/utils/graphqlFetcher/index.js +8 -0
  66. package/build/cjs/src/utils/hash/index.js +17 -0
  67. package/build/cjs/src/utils/{hash.js → hash/utils.js} +1 -1
  68. package/build/cjs/src/utils/http/http.js +33 -0
  69. package/build/cjs/src/utils/indexers/index.js +17 -0
  70. package/build/cjs/src/utils/{indexers.js → indexers/utils.js} +1 -1
  71. package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +129 -0
  72. package/build/cjs/src/utils/markets/api.js +14 -0
  73. package/build/cjs/src/utils/{marketKeysAndConfigs.js → markets/hashKeys.js} +32 -3
  74. package/build/cjs/src/utils/markets/index.js +21 -0
  75. package/build/cjs/src/{modules/markets/query-builders.js → utils/markets/multicall.js} +149 -42
  76. package/build/cjs/src/utils/markets/utils.js +398 -0
  77. package/build/cjs/src/utils/numbers/index.js +17 -0
  78. package/build/cjs/src/utils/{numbers.js → numbers/utils.js} +8 -3
  79. package/build/cjs/src/utils/objects/index.js +17 -0
  80. package/build/cjs/src/utils/{objects.js → objects/utils.js} +9 -1
  81. package/build/cjs/src/utils/orderTransactions/index.js +17 -0
  82. package/build/cjs/src/utils/{orderTransactions.js → orderTransactions/utils.js} +22 -22
  83. package/build/cjs/src/utils/orders/index.js +18 -0
  84. package/build/cjs/src/utils/{orders.js → orders/utils.js} +22 -22
  85. package/build/cjs/src/utils/positions/index.js +18 -0
  86. package/build/cjs/src/utils/{positions.js → positions/utils.js} +6 -6
  87. package/build/cjs/src/utils/prices/index.js +17 -0
  88. package/build/cjs/src/utils/{prices.js → prices/utils.js} +15 -15
  89. package/build/cjs/src/utils/referrals/index.js +18 -0
  90. package/build/cjs/src/utils/sidecarOrders/index.js +17 -0
  91. package/build/cjs/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +22 -0
  92. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +264 -7
  93. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +5 -5
  94. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +10 -10
  95. package/build/cjs/src/utils/swap/botanixStaking.js +3 -3
  96. package/build/cjs/src/utils/swap/buildSwapStrategy.js +13 -5
  97. package/build/cjs/src/utils/swap/externalSwapPath.js +2 -2
  98. package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +2 -2
  99. package/build/cjs/src/utils/swap/findSwapPathsBetweenTokens.js +8 -4
  100. package/build/cjs/src/utils/swap/index.js +12 -0
  101. package/build/cjs/src/utils/swap/swapPath.js +3 -3
  102. package/build/cjs/src/utils/swap/swapValues.js +17 -10
  103. package/build/cjs/src/utils/time/index.js +17 -0
  104. package/build/cjs/src/utils/tokens/index.js +18 -0
  105. package/build/cjs/src/utils/{tokens.js → tokens/utils.js} +4 -4
  106. package/build/cjs/src/utils/trade/decrease.js +8 -8
  107. package/build/cjs/src/utils/trade/increase.js +5 -2
  108. package/build/cjs/src/utils/trade/index.js +3 -0
  109. package/build/cjs/src/utils/trade/trade.js +10 -10
  110. package/build/cjs/src/utils/tradeHistory/index.js +18 -0
  111. package/build/cjs/src/utils/{tradeHistory.js → tradeHistory/utils.js} +4 -4
  112. package/build/cjs/src/utils/twap/index.js +15 -0
  113. package/build/cjs/src/utils/types/index.js +7 -0
  114. package/build/esm/scripts/prebuild/index.js +3 -1
  115. package/build/esm/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +2 -28
  116. package/build/esm/scripts/prebuild/prebuildMarketConfigKeys.js +1 -1
  117. package/build/esm/scripts/prebuild/prebuildMarketValuesKeys.js +1 -1
  118. package/build/esm/scripts/subsquid-codegen.js +24 -0
  119. package/build/esm/src/{utils → clients/v1}/callContract.js +5 -5
  120. package/build/esm/src/{index.js → clients/v1/index.js} +4 -4
  121. package/build/esm/src/{modules → clients/v1/modules}/accounts/accounts.js +1 -1
  122. package/build/esm/src/{modules → clients/v1/modules}/accounts/accounts.spec.js +1 -1
  123. package/build/esm/src/clients/v1/modules/markets/index.js +220 -0
  124. package/build/esm/src/{modules → clients/v1/modules}/markets/markets.spec.js +1 -1
  125. package/build/esm/src/{modules → clients/v1/modules}/oracle.js +1 -1
  126. package/build/esm/src/{modules → clients/v1/modules}/orders/helpers.js +8 -6
  127. package/build/esm/src/{modules → clients/v1/modules}/orders/helpers.spec.js +5 -5
  128. package/build/esm/src/{modules → clients/v1/modules}/orders/orders.js +4 -4
  129. package/build/esm/src/{modules → clients/v1/modules}/orders/orders.spec.js +1 -1
  130. package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/cancelOrdersTxn.js +2 -2
  131. package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createDecreaseOrderTxn.js +7 -7
  132. package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createIncreaseOrderTxn.js +8 -8
  133. package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createSwapOrderTxn.js +7 -7
  134. package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createWrapOrUnwrapTxn.js +2 -2
  135. package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/updateOrderTxn.js +3 -3
  136. package/build/esm/src/{modules → clients/v1/modules}/orders/utils.js +7 -7
  137. package/build/esm/src/{modules → clients/v1/modules}/positions/positions.js +11 -11
  138. package/build/esm/src/{modules → clients/v1/modules}/positions/positions.spec.js +1 -1
  139. package/build/esm/src/{modules → clients/v1/modules}/tokens/tokens.js +3 -3
  140. package/build/esm/src/{modules → clients/v1/modules}/tokens/tokens.spec.js +1 -1
  141. package/build/esm/src/{modules → clients/v1/modules}/trades/trades.js +8 -8
  142. package/build/esm/src/{modules → clients/v1/modules}/trades/trades.spec.js +1 -1
  143. package/build/esm/src/{modules → clients/v1/modules}/utils/utils.js +8 -8
  144. package/build/esm/src/{utils → clients/v1}/multicall.js +4 -4
  145. package/build/esm/src/{utils → clients/v1}/simulateExecuteOrder.js +5 -5
  146. package/build/esm/src/{utils → clients/v1}/testUtil.js +2 -2
  147. package/build/esm/src/clients/v2/index.js +17 -0
  148. package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +40 -0
  149. package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +285 -0
  150. package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +75 -0
  151. package/build/esm/src/codegen/prebuilt/index.js +10 -0
  152. package/build/esm/src/configs/api.js +11 -0
  153. package/build/esm/src/configs/chains.js +29 -1
  154. package/build/esm/src/configs/dataStore.js +3 -0
  155. package/build/esm/src/configs/markets.js +35 -0
  156. package/build/esm/src/configs/multichain.js +28 -19
  157. package/build/esm/src/configs/tokens.js +49 -169
  158. package/build/esm/src/test/mock.js +3 -120
  159. package/build/esm/src/utils/24h/index.js +1 -0
  160. package/build/esm/src/utils/LruCache/index.js +1 -0
  161. package/build/esm/src/utils/__tests__/fees.spec.js +1 -1
  162. package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
  163. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
  164. package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
  165. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
  166. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
  167. package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
  168. package/build/esm/src/utils/__tests__/prices.spec.js +2 -2
  169. package/build/esm/src/utils/abort/index.js +1 -0
  170. package/build/esm/src/utils/bigmath/index.js +1 -0
  171. package/build/esm/src/utils/buildUrl/index.js +1 -0
  172. package/build/esm/src/utils/chains/index.js +1 -0
  173. package/build/esm/src/utils/common/index.js +1 -0
  174. package/build/esm/src/utils/{common.js → common/utils.js} +0 -1
  175. package/build/esm/src/utils/fees/executionFee.js +1 -1
  176. package/build/esm/src/utils/fees/index.js +7 -7
  177. package/build/esm/src/utils/gelatoRelay/index.js +1 -0
  178. package/build/esm/src/utils/graphqlFetcher/index.js +1 -0
  179. package/build/esm/src/utils/hash/index.js +1 -0
  180. package/build/esm/src/utils/{hash.js → hash/utils.js} +1 -1
  181. package/build/esm/src/utils/http/http.js +26 -0
  182. package/build/esm/src/utils/indexers/index.js +1 -0
  183. package/build/esm/src/utils/{indexers.js → indexers/utils.js} +1 -1
  184. package/build/esm/src/utils/markets/__tests__/mockMarkets.js +124 -0
  185. package/build/esm/src/utils/markets/api.js +9 -0
  186. package/build/esm/src/utils/{marketKeysAndConfigs.js → markets/hashKeys.js} +30 -2
  187. package/build/esm/src/utils/markets/index.js +5 -0
  188. package/build/esm/src/{modules/markets/query-builders.js → utils/markets/multicall.js} +146 -41
  189. package/build/esm/src/utils/markets/utils.js +364 -0
  190. package/build/esm/src/utils/numbers/index.js +1 -0
  191. package/build/esm/src/utils/{numbers.js → numbers/utils.js} +8 -3
  192. package/build/esm/src/utils/objects/index.js +1 -0
  193. package/build/esm/src/utils/{objects.js → objects/utils.js} +7 -0
  194. package/build/esm/src/utils/orderTransactions/index.js +1 -0
  195. package/build/esm/src/utils/{orderTransactions.js → orderTransactions/utils.js} +14 -14
  196. package/build/esm/src/utils/orders/index.js +2 -0
  197. package/build/esm/src/utils/{orders.js → orders/utils.js} +8 -8
  198. package/build/esm/src/utils/positions/index.js +2 -0
  199. package/build/esm/src/utils/{positions.js → positions/utils.js} +6 -6
  200. package/build/esm/src/utils/prices/index.js +1 -0
  201. package/build/esm/src/utils/{prices.js → prices/utils.js} +7 -7
  202. package/build/esm/src/utils/referrals/index.js +2 -0
  203. package/build/esm/src/utils/sidecarOrders/index.js +1 -0
  204. package/build/esm/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +22 -0
  205. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +258 -1
  206. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  207. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +1 -1
  208. package/build/esm/src/utils/swap/botanixStaking.js +1 -1
  209. package/build/esm/src/utils/swap/buildSwapStrategy.js +14 -6
  210. package/build/esm/src/utils/swap/externalSwapPath.js +1 -1
  211. package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +1 -1
  212. package/build/esm/src/utils/swap/findSwapPathsBetweenTokens.js +8 -4
  213. package/build/esm/src/utils/swap/index.js +12 -0
  214. package/build/esm/src/utils/swap/swapPath.js +1 -1
  215. package/build/esm/src/utils/swap/swapValues.js +15 -8
  216. package/build/esm/src/utils/time/index.js +1 -0
  217. package/build/esm/src/utils/tokens/index.js +2 -0
  218. package/build/esm/src/utils/{tokens.js → tokens/utils.js} +4 -4
  219. package/build/esm/src/utils/trade/decrease.js +1 -1
  220. package/build/esm/src/utils/trade/increase.js +4 -1
  221. package/build/esm/src/utils/trade/index.js +3 -0
  222. package/build/esm/src/utils/trade/trade.js +2 -2
  223. package/build/esm/src/utils/tradeHistory/index.js +2 -0
  224. package/build/esm/src/utils/{tradeHistory.js → tradeHistory/utils.js} +4 -4
  225. package/build/esm/src/utils/twap/index.js +1 -0
  226. package/build/esm/src/utils/types/index.js +3 -0
  227. package/build/types/scripts/subsquid-codegen.d.ts +3 -0
  228. package/build/types/src/clients/v1/callContract.d.ts +7 -0
  229. package/build/types/src/{index.d.ts → clients/v1/index.d.ts} +3 -3
  230. package/build/types/src/{modules → clients/v1/modules}/markets/index.d.ts +12 -1
  231. package/build/types/src/{modules → clients/v1/modules}/oracle.d.ts +1 -1
  232. package/build/types/src/{modules → clients/v1/modules}/orders/helpers.d.ts +3 -3
  233. package/build/types/src/{modules → clients/v1/modules}/orders/orders.d.ts +5 -5
  234. package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createDecreaseOrderTxn.d.ts +2 -2
  235. package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createIncreaseOrderTxn.d.ts +4 -4
  236. package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createSwapOrderTxn.d.ts +2 -2
  237. package/build/types/src/{modules → clients/v1/modules}/orders/transactions/updateOrderTxn.d.ts +1 -1
  238. package/build/types/src/{modules → clients/v1/modules}/orders/utils.d.ts +8 -8
  239. package/build/types/src/{modules → clients/v1/modules}/positions/positions.d.ts +4 -4
  240. package/build/types/src/{modules → clients/v1/modules}/tokens/tokens.d.ts +1 -1
  241. package/build/types/src/{modules → clients/v1/modules}/trades/trades.d.ts +4 -4
  242. package/build/types/src/{modules → clients/v1/modules}/utils/utils.d.ts +4 -4
  243. package/build/types/src/{utils → clients/v1}/multicall.d.ts +4 -4
  244. package/build/types/src/{utils → clients/v1}/simulateExecuteOrder.d.ts +3 -3
  245. package/build/types/src/{utils → clients/v1}/testUtil.d.ts +2 -2
  246. package/build/types/src/{types/sdk.d.ts → clients/v1/types.d.ts} +3 -3
  247. package/build/types/src/clients/v2/index.d.ts +13 -0
  248. package/build/types/src/codegen/prebuilt/index.d.ts +13636 -0
  249. package/build/types/src/{types → codegen}/subsquid.d.ts +13 -0
  250. package/build/types/src/configs/api.d.ts +1 -0
  251. package/build/types/src/configs/chains.d.ts +26 -2
  252. package/build/types/src/configs/dataStore.d.ts +1 -0
  253. package/build/types/src/configs/express.d.ts +1 -1
  254. package/build/types/src/configs/gasLimits.d.ts +1 -1
  255. package/build/types/src/configs/markets.d.ts +1 -1
  256. package/build/types/src/configs/multichain.d.ts +6 -3
  257. package/build/types/src/configs/tokens.d.ts +1 -1
  258. package/build/types/src/test/mock.d.ts +3 -7
  259. package/build/types/src/utils/24h/index.d.ts +1 -0
  260. package/build/types/src/utils/24h/types.d.ts +7 -0
  261. package/build/types/src/utils/LruCache/index.d.ts +1 -0
  262. package/build/types/src/utils/abort/index.d.ts +1 -0
  263. package/build/types/src/utils/bigmath/index.d.ts +1 -0
  264. package/build/types/src/utils/buildUrl/index.d.ts +1 -0
  265. package/build/types/src/utils/chains/index.d.ts +1 -0
  266. package/build/types/src/utils/common/index.d.ts +1 -0
  267. package/build/types/src/utils/{common.d.ts → common/utils.d.ts} +0 -1
  268. package/build/types/src/utils/fees/executionFee.d.ts +3 -3
  269. package/build/types/src/utils/fees/getNaiveEstimatedGasBySwapCount.d.ts +1 -1
  270. package/build/types/src/utils/fees/index.d.ts +10 -13
  271. package/build/types/src/utils/fees/priceImpact.d.ts +3 -3
  272. package/build/types/src/{types/fees.d.ts → utils/fees/types.d.ts} +2 -2
  273. package/build/types/src/utils/gelatoRelay/index.d.ts +1 -0
  274. package/build/types/src/utils/graphqlFetcher/index.d.ts +1 -0
  275. package/build/types/src/utils/hash/index.d.ts +1 -0
  276. package/build/types/src/utils/http/http.d.ts +9 -0
  277. package/build/types/src/utils/http/types.d.ts +7 -0
  278. package/build/types/src/utils/indexers/index.d.ts +1 -0
  279. package/build/types/src/utils/markets/__tests__/mockMarkets.d.ts +9 -0
  280. package/build/types/src/utils/markets/api.d.ts +9 -0
  281. package/build/types/src/utils/markets/hashKeys.d.ts +23 -0
  282. package/build/types/src/utils/markets/index.d.ts +5 -0
  283. package/build/types/src/utils/markets/multicall.d.ts +25 -0
  284. package/build/types/src/{types/markets.d.ts → utils/markets/types.d.ts} +64 -1
  285. package/build/types/src/utils/markets/utils.d.ts +122 -0
  286. package/build/types/src/utils/numbers/index.d.ts +1 -0
  287. package/build/types/src/utils/{numbers.d.ts → numbers/utils.d.ts} +3 -1
  288. package/build/types/src/utils/objects/index.d.ts +1 -0
  289. package/build/types/src/utils/{objects.d.ts → objects/utils.d.ts} +1 -0
  290. package/build/types/src/utils/orderTransactions/index.d.ts +1 -0
  291. package/build/types/src/utils/{orderTransactions.d.ts → orderTransactions/utils.d.ts} +6 -6
  292. package/build/types/src/utils/orders/index.d.ts +2 -0
  293. package/build/types/src/{types/orders.d.ts → utils/orders/types.d.ts} +3 -3
  294. package/build/types/src/utils/{orders.d.ts → orders/utils.d.ts} +3 -3
  295. package/build/types/src/utils/positions/index.d.ts +2 -0
  296. package/build/types/src/{types/positions.d.ts → utils/positions/types.d.ts} +2 -2
  297. package/build/types/src/utils/{positions.d.ts → positions/utils.d.ts} +4 -4
  298. package/build/types/src/utils/prices/index.d.ts +1 -0
  299. package/build/types/src/utils/{prices.d.ts → prices/utils.d.ts} +4 -4
  300. package/build/types/src/utils/referrals/index.d.ts +2 -0
  301. package/build/types/src/utils/sidecarOrders/index.d.ts +1 -0
  302. package/build/types/src/{types/sidecarOrders.d.ts → utils/sidecarOrders/types.d.ts} +2 -2
  303. package/build/types/src/utils/swap/botanixStaking.d.ts +2 -2
  304. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +9 -7
  305. package/build/types/src/utils/swap/externalSwapPath.d.ts +1 -1
  306. package/build/types/src/utils/swap/externalSwapQuoteByPath.d.ts +1 -1
  307. package/build/types/src/utils/swap/findSwapPathsBetweenTokens.d.ts +1 -1
  308. package/build/types/src/utils/swap/index.d.ts +12 -0
  309. package/build/types/src/utils/swap/preparedSwapData.d.ts +1 -1
  310. package/build/types/src/utils/swap/swapPath.d.ts +6 -6
  311. package/build/types/src/utils/swap/swapRouting.d.ts +5 -5
  312. package/build/types/src/utils/swap/swapStats.d.ts +3 -3
  313. package/build/types/src/utils/swap/swapValues.d.ts +6 -4
  314. package/build/types/src/{types/swapStrategy.d.ts → utils/swap/types.d.ts} +1 -1
  315. package/build/types/src/utils/time/index.d.ts +1 -0
  316. package/build/types/src/utils/tokens/index.d.ts +2 -0
  317. package/build/types/src/{types/tokens.d.ts → utils/tokens/types.d.ts} +0 -3
  318. package/build/types/src/utils/{tokens.d.ts → tokens/utils.d.ts} +2 -2
  319. package/build/types/src/utils/trade/decrease.d.ts +5 -5
  320. package/build/types/src/utils/trade/increase.d.ts +5 -5
  321. package/build/types/src/utils/trade/index.d.ts +3 -0
  322. package/build/types/src/utils/trade/trade.d.ts +1 -1
  323. package/build/types/src/{types/trade.d.ts → utils/trade/types.d.ts} +4 -4
  324. package/build/types/src/utils/tradeHistory/index.d.ts +2 -0
  325. package/build/types/src/{types/tradeHistory.d.ts → utils/tradeHistory/types.d.ts} +3 -3
  326. package/build/types/src/utils/{tradeHistory.d.ts → tradeHistory/utils.d.ts} +4 -4
  327. package/build/types/src/utils/twap/index.d.ts +3 -2
  328. package/build/types/src/utils/{types.d.ts → types/index.d.ts} +0 -1
  329. package/package.json +286 -32
  330. package/build/cjs/src/modules/markets/index.js +0 -366
  331. package/build/cjs/src/prebuilt/index.js +0 -15
  332. package/build/cjs/src/utils/markets.js +0 -195
  333. package/build/cjs/src/utils/types.js +0 -13
  334. package/build/esm/src/modules/markets/index.js +0 -359
  335. package/build/esm/src/prebuilt/index.js +0 -7
  336. package/build/esm/src/utils/markets.js +0 -171
  337. package/build/esm/src/utils/types.js +0 -8
  338. package/build/types/src/modules/markets/query-builders.d.ts +0 -42
  339. package/build/types/src/modules/markets/types.d.ts +0 -51
  340. package/build/types/src/prebuilt/index.d.ts +0 -24
  341. package/build/types/src/types/common.d.ts +0 -1
  342. package/build/types/src/utils/callContract.d.ts +0 -17
  343. package/build/types/src/utils/marketKeysAndConfigs.d.ts +0 -73
  344. package/build/types/src/utils/markets.d.ts +0 -58
  345. /package/build/cjs/src/{modules → clients/v1/modules}/base.js +0 -0
  346. /package/build/cjs/src/{modules/markets → clients/v1}/types.js +0 -0
  347. /package/build/cjs/src/{types → codegen}/subsquid.js +0 -0
  348. /package/build/cjs/src/{types/chains.js → utils/24h/types.js} +0 -0
  349. /package/build/cjs/src/utils/{LruCache.js → LruCache/utils.js} +0 -0
  350. /package/build/cjs/src/utils/{abort.js → abort/utils.js} +0 -0
  351. /package/build/cjs/src/utils/{bigmath.js → bigmath/utils.js} +0 -0
  352. /package/build/cjs/src/utils/{buildUrl.js → buildUrl/utils.js} +0 -0
  353. /package/build/cjs/src/{types/common.js → utils/chains/types.js} +0 -0
  354. /package/build/cjs/src/{types/fees.js → utils/fees/types.js} +0 -0
  355. /package/build/cjs/src/utils/{gelatoRelay.js → gelatoRelay/utils.js} +0 -0
  356. /package/build/cjs/src/utils/{graphqlFetcher.js → graphqlFetcher/utils.js} +0 -0
  357. /package/build/cjs/src/{types/markets.js → utils/http/types.js} +0 -0
  358. /package/build/cjs/src/{types/positions.js → utils/markets/types.js} +0 -0
  359. /package/build/cjs/src/{types/orders.js → utils/orders/types.js} +0 -0
  360. /package/build/cjs/src/{types/sdk.js → utils/positions/types.js} +0 -0
  361. /package/build/cjs/src/{types/referrals.js → utils/referrals/types.js} +0 -0
  362. /package/build/cjs/src/utils/{referrals.js → referrals/utils.js} +0 -0
  363. /package/build/cjs/src/{types/sidecarOrders.js → utils/sidecarOrders/types.js} +0 -0
  364. /package/build/cjs/src/{types/swapStrategy.js → utils/swap/types.js} +0 -0
  365. /package/build/cjs/src/utils/{time.js → time/utils.js} +0 -0
  366. /package/build/cjs/src/{types/tokens.js → utils/tokens/types.js} +0 -0
  367. /package/build/cjs/src/{types/trade.js → utils/trade/types.js} +0 -0
  368. /package/build/cjs/src/{types/tradeHistory.js → utils/tradeHistory/types.js} +0 -0
  369. /package/build/cjs/src/{types/twap.js → utils/twap/types.js} +0 -0
  370. /package/build/esm/src/{modules → clients/v1/modules}/base.js +0 -0
  371. /package/build/esm/src/{modules/markets → clients/v1}/types.js +0 -0
  372. /package/build/esm/src/{types → codegen}/subsquid.js +0 -0
  373. /package/build/esm/src/{types/chains.js → utils/24h/types.js} +0 -0
  374. /package/build/esm/src/utils/{LruCache.js → LruCache/utils.js} +0 -0
  375. /package/build/esm/src/utils/{abort.js → abort/utils.js} +0 -0
  376. /package/build/esm/src/utils/{bigmath.js → bigmath/utils.js} +0 -0
  377. /package/build/esm/src/utils/{buildUrl.js → buildUrl/utils.js} +0 -0
  378. /package/build/esm/src/{types/common.js → utils/chains/types.js} +0 -0
  379. /package/build/esm/src/{types/fees.js → utils/fees/types.js} +0 -0
  380. /package/build/esm/src/utils/{gelatoRelay.js → gelatoRelay/utils.js} +0 -0
  381. /package/build/esm/src/utils/{graphqlFetcher.js → graphqlFetcher/utils.js} +0 -0
  382. /package/build/esm/src/{types/markets.js → utils/http/types.js} +0 -0
  383. /package/build/esm/src/{types/positions.js → utils/markets/types.js} +0 -0
  384. /package/build/esm/src/{types/orders.js → utils/orders/types.js} +0 -0
  385. /package/build/esm/src/{types/sdk.js → utils/positions/types.js} +0 -0
  386. /package/build/esm/src/{types/referrals.js → utils/referrals/types.js} +0 -0
  387. /package/build/esm/src/utils/{referrals.js → referrals/utils.js} +0 -0
  388. /package/build/esm/src/{types/sidecarOrders.js → utils/sidecarOrders/types.js} +0 -0
  389. /package/build/esm/src/{types/swapStrategy.js → utils/swap/types.js} +0 -0
  390. /package/build/esm/src/utils/{time.js → time/utils.js} +0 -0
  391. /package/build/esm/src/{types/tokens.js → utils/tokens/types.js} +0 -0
  392. /package/build/esm/src/{types/trade.js → utils/trade/types.js} +0 -0
  393. /package/build/esm/src/{types/tradeHistory.js → utils/tradeHistory/types.js} +0 -0
  394. /package/build/esm/src/{types/twap.js → utils/twap/types.js} +0 -0
  395. /package/build/types/src/{modules → clients/v1/modules}/accounts/accounts.d.ts +0 -0
  396. /package/build/types/src/{modules → clients/v1/modules}/accounts/accounts.spec.d.ts +0 -0
  397. /package/build/types/src/{modules → clients/v1/modules}/base.d.ts +0 -0
  398. /package/build/types/src/{modules → clients/v1/modules}/markets/markets.spec.d.ts +0 -0
  399. /package/build/types/src/{modules → clients/v1/modules}/orders/helpers.spec.d.ts +0 -0
  400. /package/build/types/src/{modules → clients/v1/modules}/orders/orders.spec.d.ts +0 -0
  401. /package/build/types/src/{modules → clients/v1/modules}/orders/transactions/cancelOrdersTxn.d.ts +0 -0
  402. /package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createWrapOrUnwrapTxn.d.ts +0 -0
  403. /package/build/types/src/{modules → clients/v1/modules}/positions/positions.spec.d.ts +0 -0
  404. /package/build/types/src/{modules → clients/v1/modules}/tokens/tokens.spec.d.ts +0 -0
  405. /package/build/types/src/{modules → clients/v1/modules}/trades/trades.spec.d.ts +0 -0
  406. /package/build/types/src/utils/{LruCache.d.ts → LruCache/utils.d.ts} +0 -0
  407. /package/build/types/src/utils/{abort.d.ts → abort/utils.d.ts} +0 -0
  408. /package/build/types/src/utils/{bigmath.d.ts → bigmath/utils.d.ts} +0 -0
  409. /package/build/types/src/utils/{buildUrl.d.ts → buildUrl/utils.d.ts} +0 -0
  410. /package/build/types/src/{types/chains.d.ts → utils/chains/types.d.ts} +0 -0
  411. /package/build/types/src/utils/{gelatoRelay.d.ts → gelatoRelay/utils.d.ts} +0 -0
  412. /package/build/types/src/utils/{graphqlFetcher.d.ts → graphqlFetcher/utils.d.ts} +0 -0
  413. /package/build/types/src/utils/{hash.d.ts → hash/utils.d.ts} +0 -0
  414. /package/build/types/src/utils/{indexers.d.ts → indexers/utils.d.ts} +0 -0
  415. /package/build/types/src/{types/referrals.d.ts → utils/referrals/types.d.ts} +0 -0
  416. /package/build/types/src/utils/{referrals.d.ts → referrals/utils.d.ts} +0 -0
  417. /package/build/types/src/utils/{time.d.ts → time/utils.d.ts} +0 -0
  418. /package/build/types/src/{types/twap.d.ts → utils/twap/types.d.ts} +0 -0
@@ -1,10 +1,9 @@
1
+ import { HASHED_MARKET_CONFIG_KEYS, HASHED_MARKET_VALUES_KEYS } from "../../codegen/prebuilt";
1
2
  import { getContract } from "../../configs/contracts";
2
3
  import { CLAIMABLE_FUNDING_AMOUNT, MAX_PNL_FACTOR_FOR_TRADERS_KEY } from "../../configs/dataStore";
3
- import { hashDataMap } from "../../utils/hash";
4
- import { hashMarketConfigKeys, hashMarketValuesKeys } from "../../utils/marketKeysAndConfigs";
5
- import { getContractMarketPrices } from "../../utils/markets";
6
- import { getByKey } from "../../utils/objects";
7
- import { HASHED_MARKET_CONFIG_KEYS, HASHED_MARKET_VALUES_KEYS } from "../../prebuilt";
4
+ import { hashDataMap } from "../hash";
5
+ import { getContractMarketPrices, getOiInTokensFromRawValues, getOiUsdFromRawValues } from "./";
6
+ import { getByKey } from "../objects";
8
7
  export function buildClaimableFundingDataRequest({ marketsAddresses, marketsData, chainId, account, }) {
9
8
  if (!marketsAddresses) {
10
9
  return {};
@@ -41,19 +40,17 @@ export function buildClaimableFundingDataRequest({ marketsAddresses, marketsData
41
40
  return request;
42
41
  }, {});
43
42
  }
44
- export async function buildMarketsValuesRequest(chainId, { marketsAddresses, marketsData, tokensData, dataStoreAddress, syntheticsReaderAddress, }) {
43
+ export async function buildMarketsValuesRequest(chainId, { marketsAddresses, marketsData, tokensData, }) {
44
+ const dataStoreAddress = getContract(chainId, "DataStore");
45
+ const syntheticsReaderAddress = getContract(chainId, "SyntheticsReader");
45
46
  const request = {};
46
47
  for (const marketAddress of marketsAddresses || []) {
47
48
  const market = getByKey(marketsData, marketAddress);
48
49
  if (!market) {
49
- // eslint-disable-next-line no-console
50
- console.warn(`No market data found for ${marketAddress}, skipping market values request`);
51
50
  continue;
52
51
  }
53
52
  const marketPrices = getContractMarketPrices(tokensData, market);
54
53
  if (!marketPrices) {
55
- // eslint-disable-next-line no-console
56
- console.warn(`No market prices for ${marketAddress}, skipping market values request`);
57
54
  continue;
58
55
  }
59
56
  const marketProps = {
@@ -96,90 +93,131 @@ export async function buildMarketsValuesRequest(chainId, { marketsAddresses, mar
96
93
  },
97
94
  },
98
95
  };
99
- let prebuiltHashedKeys = HASHED_MARKET_VALUES_KEYS[chainId]?.[marketAddress];
96
+ const prebuiltHashedKeys = HASHED_MARKET_VALUES_KEYS[chainId]?.[marketAddress];
100
97
  if (!prebuiltHashedKeys) {
101
- // eslint-disable-next-line no-console
102
- console.warn(`No pre-built hashed market keys found for the market ${marketAddress}. Run \`yarn prebuild\` to generate them.`);
103
- if (!marketsData?.[marketAddress]) {
104
- throw new Error(`No market data found for the market ${marketAddress}`);
105
- }
106
- prebuiltHashedKeys = hashMarketValuesKeys(marketsData[marketAddress]);
98
+ throw new Error(`No pre-built hashed market keys found for the market ${marketAddress}.`);
107
99
  }
108
- const keys = {
109
- ...prebuiltHashedKeys,
110
- };
111
100
  request[`${marketAddress}-dataStore`] = {
112
101
  contractAddress: dataStoreAddress,
113
102
  abiId: "DataStore",
114
103
  calls: {
115
104
  longPoolAmount: {
116
105
  methodName: "getUint",
117
- params: [keys.longPoolAmount],
106
+ params: [prebuiltHashedKeys.longPoolAmount],
118
107
  },
119
108
  shortPoolAmount: {
120
109
  methodName: "getUint",
121
- params: [keys.shortPoolAmount],
110
+ params: [prebuiltHashedKeys.shortPoolAmount],
122
111
  },
123
112
  positionImpactPoolAmount: {
124
113
  methodName: "getUint",
125
- params: [keys.positionImpactPoolAmount],
114
+ params: [prebuiltHashedKeys.positionImpactPoolAmount],
126
115
  },
127
116
  swapImpactPoolAmountLong: {
128
117
  methodName: "getUint",
129
- params: [keys.swapImpactPoolAmountLong],
118
+ params: [prebuiltHashedKeys.swapImpactPoolAmountLong],
130
119
  },
131
120
  swapImpactPoolAmountShort: {
132
121
  methodName: "getUint",
133
- params: [keys.swapImpactPoolAmountShort],
122
+ params: [prebuiltHashedKeys.swapImpactPoolAmountShort],
134
123
  },
135
124
  longInterestUsingLongToken: {
136
125
  methodName: "getUint",
137
- params: [keys.longInterestUsingLongToken],
126
+ params: [prebuiltHashedKeys.longInterestUsingLongToken],
138
127
  },
139
128
  longInterestUsingShortToken: {
140
129
  methodName: "getUint",
141
- params: [keys.longInterestUsingShortToken],
130
+ params: [prebuiltHashedKeys.longInterestUsingShortToken],
142
131
  },
143
132
  shortInterestUsingLongToken: {
144
133
  methodName: "getUint",
145
- params: [keys.shortInterestUsingLongToken],
134
+ params: [prebuiltHashedKeys.shortInterestUsingLongToken],
146
135
  },
147
136
  shortInterestUsingShortToken: {
148
137
  methodName: "getUint",
149
- params: [keys.shortInterestUsingShortToken],
138
+ params: [prebuiltHashedKeys.shortInterestUsingShortToken],
150
139
  },
151
140
  longInterestInTokensUsingLongToken: {
152
141
  methodName: "getUint",
153
- params: [keys.longInterestInTokensUsingLongToken],
142
+ params: [prebuiltHashedKeys.longInterestInTokensUsingLongToken],
154
143
  },
155
144
  longInterestInTokensUsingShortToken: {
156
145
  methodName: "getUint",
157
- params: [keys.longInterestInTokensUsingShortToken],
146
+ params: [prebuiltHashedKeys.longInterestInTokensUsingShortToken],
158
147
  },
159
148
  shortInterestInTokensUsingLongToken: {
160
149
  methodName: "getUint",
161
- params: [keys.shortInterestInTokensUsingLongToken],
150
+ params: [prebuiltHashedKeys.shortInterestInTokensUsingLongToken],
162
151
  },
163
152
  shortInterestInTokensUsingShortToken: {
164
153
  methodName: "getUint",
165
- params: [keys.shortInterestInTokensUsingShortToken],
154
+ params: [prebuiltHashedKeys.shortInterestInTokensUsingShortToken],
166
155
  },
167
156
  },
168
157
  };
169
158
  }
170
159
  return request;
171
160
  }
172
- export async function buildMarketsConfigsRequest(chainId, { marketsData, marketsAddresses, dataStoreAddress, }) {
161
+ export function parseMarketsValuesResponse(res, marketsAddresses, marketsData, getMarketDivisor) {
162
+ return marketsAddresses.reduce((acc, marketAddress) => {
163
+ const readerErrors = res.errors[`${marketAddress}-reader`];
164
+ const dataStoreErrors = res.errors[`${marketAddress}-dataStore`];
165
+ const readerValues = res.data[`${marketAddress}-reader`];
166
+ const dataStoreValues = res.data[`${marketAddress}-dataStore`];
167
+ if (!readerValues || !dataStoreValues || readerErrors || dataStoreErrors) {
168
+ return acc;
169
+ }
170
+ const market = getByKey(marketsData, marketAddress);
171
+ if (!market) {
172
+ return acc;
173
+ }
174
+ const marketDivisor = getMarketDivisor(market);
175
+ const { longInterestUsd, shortInterestUsd } = getOiUsdFromRawValues({
176
+ longInterestUsingLongToken: BigInt(dataStoreValues.longInterestUsingLongToken.returnValues[0]),
177
+ longInterestUsingShortToken: BigInt(dataStoreValues.longInterestUsingShortToken.returnValues[0]),
178
+ shortInterestUsingLongToken: BigInt(dataStoreValues.shortInterestUsingLongToken.returnValues[0]),
179
+ shortInterestUsingShortToken: BigInt(dataStoreValues.shortInterestUsingShortToken.returnValues[0]),
180
+ }, marketDivisor);
181
+ const { longInterestInTokens, shortInterestInTokens } = getOiInTokensFromRawValues({
182
+ longInterestInTokensUsingLongToken: BigInt(dataStoreValues.longInterestInTokensUsingLongToken.returnValues[0]),
183
+ longInterestInTokensUsingShortToken: BigInt(dataStoreValues.longInterestInTokensUsingShortToken.returnValues[0]),
184
+ shortInterestInTokensUsingLongToken: BigInt(dataStoreValues.shortInterestInTokensUsingLongToken.returnValues[0]),
185
+ shortInterestInTokensUsingShortToken: BigInt(dataStoreValues.shortInterestInTokensUsingShortToken.returnValues[0]),
186
+ }, marketDivisor);
187
+ const { nextFunding, virtualInventory } = readerValues.marketInfo.returnValues;
188
+ const [, poolValueInfoMin] = readerValues.marketTokenPriceMin.returnValues;
189
+ const [, poolValueInfoMax] = readerValues.marketTokenPriceMax.returnValues;
190
+ acc[marketAddress] = {
191
+ longInterestUsd,
192
+ shortInterestUsd,
193
+ longInterestInTokens,
194
+ shortInterestInTokens,
195
+ longPoolAmount: dataStoreValues.longPoolAmount.returnValues[0] / marketDivisor,
196
+ shortPoolAmount: dataStoreValues.shortPoolAmount.returnValues[0] / marketDivisor,
197
+ poolValueMin: poolValueInfoMin.poolValue,
198
+ poolValueMax: poolValueInfoMax.poolValue,
199
+ totalBorrowingFees: poolValueInfoMax.totalBorrowingFees,
200
+ positionImpactPoolAmount: dataStoreValues.positionImpactPoolAmount.returnValues[0],
201
+ swapImpactPoolAmountLong: dataStoreValues.swapImpactPoolAmountLong.returnValues[0],
202
+ swapImpactPoolAmountShort: dataStoreValues.swapImpactPoolAmountShort.returnValues[0],
203
+ borrowingFactorPerSecondForLongs: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForLongs,
204
+ borrowingFactorPerSecondForShorts: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForShorts,
205
+ fundingFactorPerSecond: nextFunding.fundingFactorPerSecond,
206
+ longsPayShorts: nextFunding.longsPayShorts,
207
+ virtualPoolAmountForLongToken: virtualInventory.virtualPoolAmountForLongToken,
208
+ virtualPoolAmountForShortToken: virtualInventory.virtualPoolAmountForShortToken,
209
+ virtualInventoryForPositions: virtualInventory.virtualInventoryForPositions,
210
+ };
211
+ return acc;
212
+ }, {});
213
+ }
214
+ export async function buildMarketsConfigsRequest(chainId, { marketsAddresses, }) {
215
+ const dataStoreAddress = getContract(chainId, "DataStore");
173
216
  const request = {};
174
217
  for (const marketAddress of marketsAddresses || []) {
175
- let prebuiltHashedKeys = HASHED_MARKET_CONFIG_KEYS[chainId]?.[marketAddress];
218
+ const prebuiltHashedKeys = HASHED_MARKET_CONFIG_KEYS[chainId]?.[marketAddress];
176
219
  if (!prebuiltHashedKeys) {
177
- // eslint-disable-next-line no-console
178
- console.warn(`No pre-built hashed config keys found for the market ${marketAddress}. Run \`yarn prebuild\` to generate them.`);
179
- if (!marketsData?.[marketAddress]) {
180
- throw new Error(`No market data found for the market ${marketAddress}`);
181
- }
182
- prebuiltHashedKeys = hashMarketConfigKeys(marketsData[marketAddress]);
220
+ throw new Error(`No pre-built hashed config keys found for the market ${marketAddress}.`);
183
221
  }
184
222
  request[`${marketAddress}-dataStore`] = {
185
223
  contractAddress: dataStoreAddress,
@@ -410,3 +448,70 @@ export async function buildMarketsConfigsRequest(chainId, { marketsData, markets
410
448
  }
411
449
  return request;
412
450
  }
451
+ export function parseMarketsConfigsResponse(res, marketsAddresses) {
452
+ return marketsAddresses.reduce((acc, marketAddress) => {
453
+ const dataStoreErrors = res.errors[`${marketAddress}-dataStore`];
454
+ const dataStoreValues = res.data[`${marketAddress}-dataStore`];
455
+ if (!dataStoreValues || dataStoreErrors) {
456
+ return acc;
457
+ }
458
+ acc[marketAddress] = {
459
+ isDisabled: dataStoreValues.isDisabled.returnValues[0],
460
+ maxLongPoolUsdForDeposit: dataStoreValues.maxLongPoolUsdForDeposit.returnValues[0],
461
+ maxShortPoolUsdForDeposit: dataStoreValues.maxShortPoolUsdForDeposit.returnValues[0],
462
+ maxLongPoolAmount: dataStoreValues.maxLongPoolAmount.returnValues[0],
463
+ maxShortPoolAmount: dataStoreValues.maxShortPoolAmount.returnValues[0],
464
+ reserveFactorLong: dataStoreValues.reserveFactorLong.returnValues[0],
465
+ reserveFactorShort: dataStoreValues.reserveFactorShort.returnValues[0],
466
+ openInterestReserveFactorLong: dataStoreValues.openInterestReserveFactorLong.returnValues[0],
467
+ openInterestReserveFactorShort: dataStoreValues.openInterestReserveFactorShort.returnValues[0],
468
+ maxOpenInterestLong: dataStoreValues.maxOpenInterestLong.returnValues[0],
469
+ maxOpenInterestShort: dataStoreValues.maxOpenInterestShort.returnValues[0],
470
+ minPositionImpactPoolAmount: dataStoreValues.minPositionImpactPoolAmount.returnValues[0],
471
+ positionImpactPoolDistributionRate: dataStoreValues.positionImpactPoolDistributionRate.returnValues[0],
472
+ borrowingFactorLong: dataStoreValues.borrowingFactorLong.returnValues[0],
473
+ borrowingFactorShort: dataStoreValues.borrowingFactorShort.returnValues[0],
474
+ borrowingExponentFactorLong: dataStoreValues.borrowingExponentFactorLong.returnValues[0],
475
+ borrowingExponentFactorShort: dataStoreValues.borrowingExponentFactorShort.returnValues[0],
476
+ fundingFactor: dataStoreValues.fundingFactor.returnValues[0],
477
+ fundingExponentFactor: dataStoreValues.fundingExponentFactor.returnValues[0],
478
+ fundingIncreaseFactorPerSecond: dataStoreValues.fundingIncreaseFactorPerSecond.returnValues[0],
479
+ fundingDecreaseFactorPerSecond: dataStoreValues.fundingDecreaseFactorPerSecond.returnValues[0],
480
+ thresholdForDecreaseFunding: dataStoreValues.thresholdForDecreaseFunding.returnValues[0],
481
+ thresholdForStableFunding: dataStoreValues.thresholdForStableFunding.returnValues[0],
482
+ minFundingFactorPerSecond: dataStoreValues.minFundingFactorPerSecond.returnValues[0],
483
+ maxFundingFactorPerSecond: dataStoreValues.maxFundingFactorPerSecond.returnValues[0],
484
+ maxPnlFactorForTradersLong: dataStoreValues.maxPnlFactorForTradersLong.returnValues[0],
485
+ maxPnlFactorForTradersShort: dataStoreValues.maxPnlFactorForTradersShort.returnValues[0],
486
+ minCollateralFactor: dataStoreValues.minCollateralFactor.returnValues[0],
487
+ minCollateralFactorForOpenInterestLong: dataStoreValues.minCollateralFactorForOpenInterestLong.returnValues[0],
488
+ minCollateralFactorForOpenInterestShort: dataStoreValues.minCollateralFactorForOpenInterestShort.returnValues[0],
489
+ minCollateralFactorForLiquidation: dataStoreValues.minCollateralFactorForLiquidation.returnValues[0],
490
+ positionFeeFactorForBalanceWasImproved: dataStoreValues.positionFeeFactorForBalanceWasImproved.returnValues[0],
491
+ positionFeeFactorForBalanceWasNotImproved: dataStoreValues.positionFeeFactorForBalanceWasNotImproved.returnValues[0],
492
+ positionImpactFactorPositive: dataStoreValues.positionImpactFactorPositive.returnValues[0],
493
+ positionImpactFactorNegative: dataStoreValues.positionImpactFactorNegative.returnValues[0],
494
+ maxPositionImpactFactorPositive: dataStoreValues.maxPositionImpactFactorPositive.returnValues[0],
495
+ maxPositionImpactFactorNegative: dataStoreValues.maxPositionImpactFactorNegative.returnValues[0],
496
+ maxPositionImpactFactorForLiquidations: dataStoreValues.maxPositionImpactFactorForLiquidations.returnValues[0],
497
+ maxLendableImpactFactor: dataStoreValues.maxLendableImpactFactor.returnValues[0],
498
+ maxLendableImpactFactorForWithdrawals: dataStoreValues.maxLendableImpactFactorForWithdrawals.returnValues[0],
499
+ maxLendableImpactUsd: dataStoreValues.maxLendableImpactUsd.returnValues[0],
500
+ lentPositionImpactPoolAmount: dataStoreValues.lentPositionImpactPoolAmount.returnValues[0],
501
+ positionImpactExponentFactorPositive: dataStoreValues.positionImpactExponentFactorPositive.returnValues[0],
502
+ positionImpactExponentFactorNegative: dataStoreValues.positionImpactExponentFactorNegative.returnValues[0],
503
+ swapFeeFactorForBalanceWasImproved: dataStoreValues.swapFeeFactorForBalanceWasImproved.returnValues[0],
504
+ swapFeeFactorForBalanceWasNotImproved: dataStoreValues.swapFeeFactorForBalanceWasNotImproved.returnValues[0],
505
+ swapImpactFactorPositive: dataStoreValues.swapImpactFactorPositive.returnValues[0],
506
+ swapImpactFactorNegative: dataStoreValues.swapImpactFactorNegative.returnValues[0],
507
+ atomicSwapFeeFactor: dataStoreValues.atomicSwapFeeFactor.returnValues[0],
508
+ withdrawalFeeFactorBalanceWasImproved: dataStoreValues.withdrawalFeeFactorBalanceWasImproved.returnValues[0],
509
+ withdrawalFeeFactorBalanceWasNotImproved: dataStoreValues.withdrawalFeeFactorBalanceWasNotImproved.returnValues[0],
510
+ swapImpactExponentFactor: dataStoreValues.swapImpactExponentFactor.returnValues[0],
511
+ virtualMarketId: dataStoreValues.virtualMarketId.returnValues[0],
512
+ virtualLongTokenId: dataStoreValues.virtualLongTokenId.returnValues[0],
513
+ virtualShortTokenId: dataStoreValues.virtualShortTokenId.returnValues[0],
514
+ };
515
+ return acc;
516
+ }, {});
517
+ }
@@ -0,0 +1,364 @@
1
+ import { zeroAddress } from "viem";
2
+ import { BASIS_POINTS_DIVISOR, BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
3
+ import { convertTokenAddress, getTokenVisualMultiplier, NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
4
+ import { getBorrowingFactorPerPeriod, getFundingFactorPerPeriod } from "../fees";
5
+ import { applyFactor, PRECISION } from "../numbers";
6
+ import { getByKey } from "../objects";
7
+ import { periodToSeconds } from "../time";
8
+ import { convertToContractTokenPrices, convertToUsd, getMidPrice } from "../tokens";
9
+ export function getMarketFullName(p) {
10
+ const { indexToken, longToken, shortToken, isSpotOnly } = p;
11
+ return `${getMarketIndexName({ indexToken, isSpotOnly })} [${getMarketPoolName({ longToken, shortToken })}]`;
12
+ }
13
+ export function getMarketIndexName(p) {
14
+ if (p.isSpotOnly) {
15
+ return `SWAP-ONLY`;
16
+ }
17
+ return `${getMarketBaseName(p)}/USD`;
18
+ }
19
+ export function getMarketBaseName(p) {
20
+ const { isSpotOnly } = p;
21
+ const firstToken = "indexToken" in p ? p.indexToken : p.glvToken;
22
+ if (isSpotOnly) {
23
+ return `SWAP-ONLY`;
24
+ }
25
+ const prefix = getTokenVisualMultiplier(firstToken);
26
+ return `${prefix}${firstToken.baseSymbol || firstToken.symbol}`;
27
+ }
28
+ export function getMarketPoolName(p, separator = "-") {
29
+ const { longToken, shortToken } = p;
30
+ return `${longToken.symbol}${separator}${shortToken.symbol}`;
31
+ }
32
+ export function getContractMarketPrices(tokensData, market) {
33
+ const indexToken = getByKey(tokensData, market.indexTokenAddress);
34
+ const longToken = getByKey(tokensData, market.longTokenAddress);
35
+ const shortToken = getByKey(tokensData, market.shortTokenAddress);
36
+ if (!indexToken || !longToken || !shortToken) {
37
+ return undefined;
38
+ }
39
+ return {
40
+ indexTokenPrice: indexToken && convertToContractTokenPrices(indexToken.prices, indexToken.decimals),
41
+ longTokenPrice: longToken && convertToContractTokenPrices(longToken.prices, longToken.decimals),
42
+ shortTokenPrice: shortToken && convertToContractTokenPrices(shortToken.prices, shortToken.decimals),
43
+ };
44
+ }
45
+ /**
46
+ * Apart from usual cases, returns `long` for single token backed markets.
47
+ */
48
+ export function getTokenPoolType(marketInfo, tokenAddress) {
49
+ const { longToken, shortToken } = marketInfo;
50
+ if (longToken.address === shortToken.address && tokenAddress === longToken.address) {
51
+ return "long";
52
+ }
53
+ if (tokenAddress === longToken.address || (tokenAddress === NATIVE_TOKEN_ADDRESS && longToken.isWrapped)) {
54
+ return "long";
55
+ }
56
+ if (tokenAddress === shortToken.address || (tokenAddress === NATIVE_TOKEN_ADDRESS && shortToken.isWrapped)) {
57
+ return "short";
58
+ }
59
+ return undefined;
60
+ }
61
+ export function getPoolUsdWithoutPnl(marketInfo, isLong, priceType) {
62
+ const poolAmount = isLong ? marketInfo.longPoolAmount : marketInfo.shortPoolAmount;
63
+ const token = isLong ? marketInfo.longToken : marketInfo.shortToken;
64
+ let price;
65
+ if (priceType === "minPrice") {
66
+ price = token.prices?.minPrice;
67
+ }
68
+ else if (priceType === "maxPrice") {
69
+ price = token.prices?.maxPrice;
70
+ }
71
+ else {
72
+ price = getMidPrice(token.prices);
73
+ }
74
+ return convertToUsd(poolAmount, token.decimals, price);
75
+ }
76
+ export function getCappedPoolPnl(p) {
77
+ const { marketInfo, poolUsd, poolPnl, isLong } = p;
78
+ if (poolPnl < 0) {
79
+ return poolPnl;
80
+ }
81
+ const maxPnlFactor = isLong ? marketInfo.maxPnlFactorForTradersLong : marketInfo.maxPnlFactorForTradersShort;
82
+ const maxPnl = applyFactor(poolUsd, maxPnlFactor);
83
+ return poolPnl > maxPnl ? maxPnl : poolPnl;
84
+ }
85
+ export function getMaxLeverageByMinCollateralFactor(minCollateralFactor) {
86
+ if (minCollateralFactor === undefined)
87
+ return 100 * BASIS_POINTS_DIVISOR;
88
+ if (minCollateralFactor === 0n)
89
+ return 100 * BASIS_POINTS_DIVISOR;
90
+ const x = Number(PRECISION / minCollateralFactor);
91
+ const rounded = Math.round(x / 10) * 10;
92
+ return rounded * BASIS_POINTS_DIVISOR;
93
+ }
94
+ export function getMaxAllowedLeverageByMinCollateralFactor(minCollateralFactor) {
95
+ return getMaxLeverageByMinCollateralFactor(minCollateralFactor) / 2;
96
+ }
97
+ export function getOppositeCollateral(marketInfo, tokenAddress) {
98
+ const poolType = getTokenPoolType(marketInfo, tokenAddress);
99
+ if (poolType === "long") {
100
+ return marketInfo.shortToken;
101
+ }
102
+ if (poolType === "short") {
103
+ return marketInfo.longToken;
104
+ }
105
+ return undefined;
106
+ }
107
+ export function getOppositeCollateralFromConfig(marketConfig, tokenAddress) {
108
+ return marketConfig.shortTokenAddress === tokenAddress
109
+ ? marketConfig.longTokenAddress
110
+ : marketConfig.shortTokenAddress;
111
+ }
112
+ export function getAvailableUsdLiquidityForCollateral(marketInfo, isLong) {
113
+ const poolUsd = getPoolUsdWithoutPnl(marketInfo, isLong, "minPrice");
114
+ if (marketInfo.isSpotOnly) {
115
+ return poolUsd;
116
+ }
117
+ const reservedUsd = getReservedUsd(marketInfo, isLong);
118
+ const maxReserveFactor = isLong ? marketInfo.reserveFactorLong : marketInfo.reserveFactorShort;
119
+ if (maxReserveFactor === 0n) {
120
+ return 0n;
121
+ }
122
+ const minPoolUsd = (reservedUsd * PRECISION) / maxReserveFactor;
123
+ const liquidity = poolUsd - minPoolUsd;
124
+ return liquidity;
125
+ }
126
+ export function getReservedUsd(marketInfo, isLong) {
127
+ const { indexToken } = marketInfo;
128
+ if (isLong) {
129
+ return convertToUsd(marketInfo.longInterestInTokens, marketInfo.indexToken.decimals, indexToken.prices.maxPrice);
130
+ }
131
+ else {
132
+ return marketInfo.shortInterestUsd;
133
+ }
134
+ }
135
+ export function getMarketDivisor({ longTokenAddress, shortTokenAddress, }) {
136
+ return longTokenAddress === shortTokenAddress ? 2n : 1n;
137
+ }
138
+ export function getOiUsdFromRawValues(rawValues, marketDivisor) {
139
+ const longInterestUsingLongToken = rawValues.longInterestUsingLongToken / marketDivisor;
140
+ const longInterestUsingShortToken = rawValues.longInterestUsingShortToken / marketDivisor;
141
+ const shortInterestUsingLongToken = rawValues.shortInterestUsingLongToken / marketDivisor;
142
+ const shortInterestUsingShortToken = rawValues.shortInterestUsingShortToken / marketDivisor;
143
+ const longInterestUsd = longInterestUsingLongToken + longInterestUsingShortToken;
144
+ const shortInterestUsd = shortInterestUsingLongToken + shortInterestUsingShortToken;
145
+ return { longInterestUsd, shortInterestUsd };
146
+ }
147
+ export function getOiInTokensFromRawValues(rawValues, marketDivisor) {
148
+ const longInterestInTokensUsingLongToken = rawValues.longInterestInTokensUsingLongToken / marketDivisor;
149
+ const longInterestInTokensUsingShortToken = rawValues.longInterestInTokensUsingShortToken / marketDivisor;
150
+ const shortInterestInTokensUsingLongToken = rawValues.shortInterestInTokensUsingLongToken / marketDivisor;
151
+ const shortInterestInTokensUsingShortToken = rawValues.shortInterestInTokensUsingShortToken / marketDivisor;
152
+ const longInterestInTokens = longInterestInTokensUsingLongToken + longInterestInTokensUsingShortToken;
153
+ const shortInterestInTokens = shortInterestInTokensUsingLongToken + shortInterestInTokensUsingShortToken;
154
+ return { longInterestInTokens, shortInterestInTokens };
155
+ }
156
+ export function getMarketPnl(marketInfo, isLong, forMaxPoolValue) {
157
+ const maximize = !forMaxPoolValue;
158
+ const openInterestUsd = getOpenInterestUsd(marketInfo, isLong);
159
+ const openInterestInTokens = getOpenInterestInTokens(marketInfo, isLong);
160
+ if (openInterestUsd === 0n || openInterestInTokens === 0n) {
161
+ return 0n;
162
+ }
163
+ const price = getPriceForPnl(marketInfo.indexToken.prices, isLong, maximize);
164
+ const openInterestValue = convertToUsd(openInterestInTokens, marketInfo.indexToken.decimals, price);
165
+ const pnl = isLong ? openInterestValue - openInterestUsd : openInterestUsd - openInterestValue;
166
+ return pnl;
167
+ }
168
+ export function getOpenInterestUsd(marketInfo, isLong) {
169
+ return isLong ? marketInfo.longInterestUsd : marketInfo.shortInterestUsd;
170
+ }
171
+ export function getOpenInterestInTokens(marketInfo, isLong) {
172
+ return isLong ? marketInfo.longInterestInTokens : marketInfo.shortInterestInTokens;
173
+ }
174
+ export function getOpenInterestForBalance(marketInfo, isLong) {
175
+ if (marketInfo.useOpenInterestInTokensForBalance) {
176
+ const interestInTokens = isLong ? marketInfo.longInterestInTokens : marketInfo.shortInterestInTokens;
177
+ const indexTokenPrice = getMidPrice(marketInfo.indexToken.prices);
178
+ return convertToUsd(interestInTokens, marketInfo.indexToken.decimals, indexTokenPrice);
179
+ }
180
+ return isLong ? marketInfo.longInterestUsd : marketInfo.shortInterestUsd;
181
+ }
182
+ export function getPriceForPnl(prices, isLong, maximize) {
183
+ // for long positions, pick the larger price to maximize pnl
184
+ // for short positions, pick the smaller price to maximize pnl
185
+ if (isLong) {
186
+ return maximize ? prices.maxPrice : prices.minPrice;
187
+ }
188
+ return maximize ? prices.minPrice : prices.maxPrice;
189
+ }
190
+ export function getIsMarketAvailableForExpressSwaps(marketInfo) {
191
+ return [marketInfo.indexToken, marketInfo.longToken, marketInfo.shortToken].every((token) => token.hasPriceFeedProvider);
192
+ }
193
+ export function getMarket24Stats(dayPriceCandle) {
194
+ const open24h = dayPriceCandle.open;
195
+ const high24h = dayPriceCandle.high;
196
+ const low24h = dayPriceCandle.low;
197
+ const close24h = dayPriceCandle.close;
198
+ const priceChange24h = close24h - open24h;
199
+ const priceChangePercent24hBps = open24h !== 0n ? (priceChange24h * BASIS_POINTS_DIVISOR_BIGINT) / open24h : 0n;
200
+ return {
201
+ open24h,
202
+ high24h,
203
+ low24h,
204
+ close24h,
205
+ priceChange24h,
206
+ priceChangePercent24hBps,
207
+ };
208
+ }
209
+ export function getMarketTicker(marketInfo, dayPriceCandle) {
210
+ const markPrice = getMidPrice(marketInfo.indexToken.prices);
211
+ const SECONDS_PER_HOUR = BigInt(periodToSeconds(1, "1h"));
212
+ const fundingRateLong = getFundingFactorPerPeriod(marketInfo, true, SECONDS_PER_HOUR);
213
+ const fundingRateShort = getFundingFactorPerPeriod(marketInfo, false, SECONDS_PER_HOUR);
214
+ const borrowingRateLong = getBorrowingFactorPerPeriod(marketInfo, true, SECONDS_PER_HOUR);
215
+ const borrowingRateShort = getBorrowingFactorPerPeriod(marketInfo, false, SECONDS_PER_HOUR);
216
+ const netRateLong = fundingRateLong - borrowingRateLong;
217
+ const netRateShort = fundingRateShort - borrowingRateShort;
218
+ const openInterestLong = getOpenInterestUsd(marketInfo, true);
219
+ const openInterestShort = getOpenInterestUsd(marketInfo, false);
220
+ const availableLiquidityLong = getAvailableUsdLiquidityForCollateral(marketInfo, true);
221
+ const availableLiquidityShort = getAvailableUsdLiquidityForCollateral(marketInfo, false);
222
+ const poolAmountLongUsd = getPoolUsdWithoutPnl(marketInfo, true, "midPrice");
223
+ const poolAmountShortUsd = getPoolUsdWithoutPnl(marketInfo, false, "midPrice");
224
+ const { high24h, low24h, open24h, close24h, priceChange24h, priceChangePercent24hBps } = getMarket24Stats(dayPriceCandle);
225
+ return {
226
+ symbol: marketInfo.name,
227
+ marketTokenAddress: marketInfo.marketTokenAddress,
228
+ markPrice,
229
+ high24h,
230
+ low24h,
231
+ open24h,
232
+ close24h,
233
+ priceChange24h,
234
+ priceChangePercent24hBps,
235
+ openInterestLong,
236
+ openInterestShort,
237
+ availableLiquidityLong,
238
+ availableLiquidityShort,
239
+ poolAmountLongUsd,
240
+ poolAmountShortUsd,
241
+ fundingRateLong,
242
+ fundingRateShort,
243
+ borrowingRateLong,
244
+ borrowingRateShort,
245
+ netRateLong,
246
+ netRateShort,
247
+ };
248
+ }
249
+ export function composeRawMarketInfo({ market, marketValues, marketConfig, marketsConstants, }) {
250
+ return {
251
+ ...marketValues,
252
+ ...marketConfig,
253
+ ...market,
254
+ ...marketsConstants,
255
+ };
256
+ }
257
+ export function composeRawMarketsInfoData({ marketsAddresses, marketsData, marketsValuesData, marketsConfigsData, marketsConstants, }) {
258
+ const data = {};
259
+ for (const marketAddress of marketsAddresses) {
260
+ const market = getByKey(marketsData, marketAddress);
261
+ const marketValues = getByKey(marketsValuesData, marketAddress);
262
+ const marketConfig = getByKey(marketsConfigsData, marketAddress);
263
+ if (!market || !marketValues || !marketConfig) {
264
+ continue;
265
+ }
266
+ data[marketAddress] = composeRawMarketInfo({
267
+ market,
268
+ marketValues,
269
+ marketConfig,
270
+ marketsConstants,
271
+ });
272
+ }
273
+ return data;
274
+ }
275
+ export function hydrateMarketInfo({ chainId, rawMarketInfo, tokensData, claimableFundingData, }) {
276
+ const longToken = getByKey(tokensData, rawMarketInfo.longTokenAddress);
277
+ const shortToken = getByKey(tokensData, rawMarketInfo.shortTokenAddress);
278
+ const indexToken = getByKey(tokensData, convertTokenAddress(chainId, rawMarketInfo.indexTokenAddress, "native"));
279
+ if (!longToken || !shortToken || !indexToken) {
280
+ return undefined;
281
+ }
282
+ return {
283
+ ...rawMarketInfo,
284
+ ...(claimableFundingData || {}),
285
+ longToken,
286
+ shortToken,
287
+ indexToken,
288
+ };
289
+ }
290
+ export function composeFullMarketsInfoData({ chainId, marketsAddresses, rawMarketsInfoData, tokensData, claimableFundingData, }) {
291
+ const data = {};
292
+ for (const marketAddress of marketsAddresses) {
293
+ const rawMarketInfo = getByKey(rawMarketsInfoData, marketAddress);
294
+ if (!rawMarketInfo) {
295
+ continue;
296
+ }
297
+ const fullMarketInfo = hydrateMarketInfo({
298
+ chainId,
299
+ rawMarketInfo,
300
+ tokensData,
301
+ claimableFundingData: claimableFundingData?.[marketAddress],
302
+ });
303
+ if (fullMarketInfo) {
304
+ data[marketAddress] = fullMarketInfo;
305
+ }
306
+ }
307
+ return data;
308
+ }
309
+ export function getMarketWithTiers(marketInfo, constants) {
310
+ const maxLeverage = getMaxLeverageByMinCollateralFactor(marketInfo.minCollateralFactor);
311
+ const maxLeverageBigint = BigInt(maxLeverage);
312
+ const leverageTiers = [
313
+ {
314
+ maxLeverage: maxLeverageBigint,
315
+ minCollateralFactor: marketInfo.minCollateralFactor,
316
+ maxPositionSize: undefined,
317
+ },
318
+ ];
319
+ return {
320
+ symbol: marketInfo.name,
321
+ marketTokenAddress: marketInfo.marketTokenAddress,
322
+ indexTokenAddress: marketInfo.indexTokenAddress,
323
+ longTokenAddress: marketInfo.longTokenAddress,
324
+ shortTokenAddress: marketInfo.shortTokenAddress,
325
+ isListed: !marketInfo.isDisabled,
326
+ listingDate: undefined,
327
+ isSpotOnly: marketInfo.isSpotOnly,
328
+ leverageTiers,
329
+ minPositionSizeUsd: constants.minPositionSizeUsd,
330
+ minCollateralUsd: constants.minCollateralUsd,
331
+ };
332
+ }
333
+ export function getMarketAddressByName(marketsInfoData, name) {
334
+ const poolMatch = name.match(/\[([^\]]+)\]/);
335
+ if (!poolMatch) {
336
+ return undefined;
337
+ }
338
+ const poolTokens = poolMatch[1].split("-");
339
+ if (poolTokens.length !== 2) {
340
+ return undefined;
341
+ }
342
+ const [longTokenSymbol, shortTokenSymbol] = poolTokens.map((s) => s.trim());
343
+ const isSpotOnly = name.startsWith("SWAP-ONLY");
344
+ let indexTokenSymbol;
345
+ if (!isSpotOnly) {
346
+ const indexMatch = name.match(/^([^/]+)\/USD/);
347
+ if (!indexMatch) {
348
+ return undefined;
349
+ }
350
+ indexTokenSymbol = indexMatch[1].trim();
351
+ }
352
+ for (const [marketAddress, marketInfo] of Object.entries(marketsInfoData)) {
353
+ const matchesLong = marketInfo.longToken.symbol === longTokenSymbol || marketInfo.longToken.baseSymbol === longTokenSymbol;
354
+ const matchesShort = marketInfo.shortToken.symbol === shortTokenSymbol || marketInfo.shortToken.baseSymbol === shortTokenSymbol;
355
+ const matchesIndex = isSpotOnly
356
+ ? marketInfo.isSpotOnly && marketInfo.indexTokenAddress === zeroAddress
357
+ : (marketInfo.indexToken.symbol === indexTokenSymbol || marketInfo.indexToken.baseSymbol === indexTokenSymbol) &&
358
+ !marketInfo.isSpotOnly;
359
+ if (matchesLong && matchesShort && matchesIndex) {
360
+ return marketAddress;
361
+ }
362
+ }
363
+ return undefined;
364
+ }
@@ -0,0 +1 @@
1
+ export * from "./utils";
@@ -1,5 +1,5 @@
1
1
  import { formatUnits, parseUnits } from "viem";
2
- import { bigMath } from "./bigmath";
2
+ import { bigMath } from "../bigmath";
3
3
  export const USD_DECIMALS = 30;
4
4
  export const BASIS_POINTS_DIVISOR = 10000;
5
5
  export const BASIS_POINTS_DIVISOR_BIGINT = 10000n;
@@ -527,7 +527,9 @@ export function serializeBigIntsInObject(obj) {
527
527
  }
528
528
  return result;
529
529
  }
530
- export function deserializeBigIntsInObject(obj) {
530
+ const NUMERIC_STRING_REGEX = /^-?\d+$/;
531
+ export function deserializeBigIntsInObject(obj, opts) {
532
+ const handleInts = opts?.handleInts ?? false;
531
533
  const result = Array.isArray(obj) ? [] : {};
532
534
  for (const key in obj) {
533
535
  const value = obj[key];
@@ -546,8 +548,11 @@ export function deserializeBigIntsInObject(obj) {
546
548
  }
547
549
  }
548
550
  }
551
+ else if (handleInts && typeof value === "string" && NUMERIC_STRING_REGEX.test(value)) {
552
+ result[key] = BigInt(value);
553
+ }
549
554
  else if (value && typeof value === "object") {
550
- result[key] = deserializeBigIntsInObject(value);
555
+ result[key] = deserializeBigIntsInObject(value, opts);
551
556
  }
552
557
  else {
553
558
  result[key] = value;
@@ -0,0 +1 @@
1
+ export * from "./utils";