@gmx-io/sdk 0.1.2 → 1.0.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 (441) hide show
  1. package/README.md +59 -6
  2. package/build/cjs/scripts/prebuild/index.js +11 -0
  3. package/build/cjs/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +51 -0
  4. package/build/cjs/scripts/prebuild/prebuildMarketConfigKeys.js +25 -0
  5. package/build/cjs/scripts/prebuild/prebuildMarketValuesKeys.js +25 -0
  6. package/build/cjs/src/abis/CustomErrors.json +3254 -0
  7. package/build/cjs/src/abis/DataStore.json +1440 -0
  8. package/build/cjs/src/abis/ERC721.json +442 -0
  9. package/build/cjs/src/abis/EventEmitter.json +2065 -0
  10. package/build/cjs/src/abis/ExchangeRouter.json +1801 -0
  11. package/build/cjs/src/abis/GMT.json +522 -0
  12. package/build/cjs/src/abis/GlpManager.json +591 -0
  13. package/build/cjs/src/abis/GlvReader.json +1414 -0
  14. package/build/cjs/src/abis/GlvRouter.json +706 -0
  15. package/build/cjs/src/abis/GmxMigrator.json +657 -0
  16. package/build/cjs/src/abis/GovToken.json +1121 -0
  17. package/build/cjs/src/abis/MintableBaseToken.json +696 -0
  18. package/build/cjs/src/abis/Multicall.json +333 -0
  19. package/build/cjs/src/abis/OrderBook.json +1997 -0
  20. package/build/cjs/src/abis/OrderBookReader.json +111 -0
  21. package/build/cjs/src/abis/OrderExecutor.json +122 -0
  22. package/build/cjs/src/abis/PositionManager.json +1165 -0
  23. package/build/cjs/src/abis/PositionRouter.json +2030 -0
  24. package/build/cjs/src/abis/Reader.json +355 -0
  25. package/build/cjs/src/abis/ReaderV2.json +630 -0
  26. package/build/cjs/src/abis/ReferralStorage.json +507 -0
  27. package/build/cjs/src/abis/RewardReader.json +86 -0
  28. package/build/cjs/src/abis/RewardRouter.json +1024 -0
  29. package/build/cjs/src/abis/RewardTracker.json +918 -0
  30. package/build/cjs/src/abis/Router-v2.json +605 -0
  31. package/build/cjs/src/abis/Router.json +605 -0
  32. package/build/cjs/src/abis/SubaccountRouter.json +658 -0
  33. package/build/cjs/src/abis/SyntheticsReader.json +4706 -0
  34. package/build/cjs/src/abis/SyntheticsRouter.json +77 -0
  35. package/build/cjs/src/abis/Timelock.json +1737 -0
  36. package/build/cjs/src/abis/Token.json +345 -0
  37. package/build/cjs/src/abis/Treasury.json +411 -0
  38. package/build/cjs/src/abis/UniPool.json +89 -0
  39. package/build/cjs/src/abis/UniswapV2.json +1 -0
  40. package/build/cjs/src/abis/Vault.json +3220 -0
  41. package/build/cjs/src/abis/VaultReader.json +87 -0
  42. package/build/cjs/src/abis/VaultV2.json +3019 -0
  43. package/build/cjs/src/abis/VaultV2b.json +3220 -0
  44. package/build/cjs/src/abis/Vester.json +1031 -0
  45. package/build/cjs/src/abis/WETH.json +320 -0
  46. package/build/cjs/src/abis/YieldFarm.json +599 -0
  47. package/build/cjs/src/abis/YieldToken.json +560 -0
  48. package/build/cjs/src/abis/index.js +94 -0
  49. package/build/cjs/src/configs/__tests__/markets.spec.js +32 -0
  50. package/build/cjs/src/configs/__tests__/tokens.spec.js +40 -0
  51. package/build/cjs/src/configs/batch.js +42 -0
  52. package/build/cjs/src/configs/chains.js +98 -0
  53. package/build/cjs/src/configs/contracts.js +248 -0
  54. package/build/cjs/src/configs/dataStore.js +348 -0
  55. package/build/cjs/src/configs/factors.js +14 -0
  56. package/build/cjs/src/configs/markets.js +840 -0
  57. package/build/cjs/src/configs/oracleKeeper.js +45 -0
  58. package/build/cjs/src/configs/tokens.js +1635 -0
  59. package/build/cjs/src/index.js +75 -0
  60. package/build/cjs/src/modules/accounts/accounts.js +39 -0
  61. package/build/cjs/src/modules/accounts/accounts.spec.js +10 -0
  62. package/build/cjs/src/modules/base.js +19 -0
  63. package/build/cjs/src/modules/markets/index.js +334 -0
  64. package/build/cjs/src/modules/markets/markets.spec.js +40 -0
  65. package/build/cjs/src/modules/markets/query-builders.js +385 -0
  66. package/build/cjs/src/modules/markets/types.js +2 -0
  67. package/build/cjs/src/modules/oracle.js +45 -0
  68. package/build/cjs/src/modules/orders/helpers.js +225 -0
  69. package/build/cjs/src/modules/orders/helpers.spec.js +131 -0
  70. package/build/cjs/src/modules/orders/orders.js +293 -0
  71. package/build/cjs/src/modules/orders/orders.spec.js +19 -0
  72. package/build/cjs/src/modules/orders/transactions/cancelOrdersTxn.js +20 -0
  73. package/build/cjs/src/modules/orders/transactions/createDecreaseOrderTxn.js +104 -0
  74. package/build/cjs/src/modules/orders/transactions/createIncreaseOrderTxn.js +174 -0
  75. package/build/cjs/src/modules/orders/transactions/createSwapOrderTxn.js +84 -0
  76. package/build/cjs/src/modules/orders/transactions/createWrapOrUnwrapTxn.js +17 -0
  77. package/build/cjs/src/modules/orders/transactions/updateOrderTxn.js +51 -0
  78. package/build/cjs/src/modules/orders/utils.js +157 -0
  79. package/build/cjs/src/modules/positions/positions.js +501 -0
  80. package/build/cjs/src/modules/positions/positions.spec.js +28 -0
  81. package/build/cjs/src/modules/tokens/tokens.js +135 -0
  82. package/build/cjs/src/modules/tokens/tokens.spec.js +29 -0
  83. package/build/cjs/src/modules/trades/trades.js +395 -0
  84. package/build/cjs/src/modules/trades/trades.spec.js +17 -0
  85. package/build/cjs/src/modules/utils/utils.js +211 -0
  86. package/build/cjs/src/package.json +1 -0
  87. package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +944 -0
  88. package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +5858 -0
  89. package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +1763 -0
  90. package/build/cjs/src/prebuilt/index.js +15 -0
  91. package/build/cjs/src/test/mock.js +246 -0
  92. package/build/cjs/src/types/common.js +2 -0
  93. package/build/cjs/src/types/fees.js +2 -0
  94. package/build/cjs/src/types/markets.js +2 -0
  95. package/build/cjs/src/types/orders.js +38 -0
  96. package/build/cjs/src/types/positions.js +2 -0
  97. package/build/cjs/src/types/referrals.js +12 -0
  98. package/build/cjs/src/types/sdk.js +2 -0
  99. package/build/cjs/src/types/sidecarOrders.js +2 -0
  100. package/build/cjs/src/types/tokens.js +2 -0
  101. package/build/cjs/src/types/trade.js +25 -0
  102. package/build/cjs/src/types/tradeHistory.js +11 -0
  103. package/build/cjs/src/utils/LruCache.js +49 -0
  104. package/build/cjs/src/utils/__tests__/LruCache.spec.js +45 -0
  105. package/build/cjs/src/utils/__tests__/bigmath.spec.js +40 -0
  106. package/build/cjs/src/utils/__tests__/fees.spec.js +64 -0
  107. package/build/cjs/src/utils/__tests__/hash.spec.js +43 -0
  108. package/build/cjs/src/utils/__tests__/markets.spec.js +267 -0
  109. package/build/cjs/src/utils/__tests__/numbers.spec.js +83 -0
  110. package/build/cjs/src/utils/__tests__/objects.spec.js +139 -0
  111. package/build/cjs/src/utils/__tests__/positions.spec.js +180 -0
  112. package/build/cjs/src/utils/__tests__/prices.spec.js +69 -0
  113. package/build/cjs/src/utils/__tests__/referrals.spec.js +20 -0
  114. package/build/cjs/src/utils/__tests__/subgraph.spec.js +165 -0
  115. package/build/cjs/src/utils/__tests__/tokens.spec.js +115 -0
  116. package/build/cjs/src/utils/__tests__/trade.spec.js +38 -0
  117. package/build/cjs/src/utils/bigmath.js +34 -0
  118. package/build/cjs/src/utils/buildUrl.js +12 -0
  119. package/build/cjs/src/utils/callContract.js +143 -0
  120. package/build/cjs/src/utils/common.js +14 -0
  121. package/build/cjs/src/utils/contracts.js +93 -0
  122. package/build/cjs/src/utils/fees/estimateOraclePriceCount.js +28 -0
  123. package/build/cjs/src/utils/fees/executionFee.js +113 -0
  124. package/build/cjs/src/utils/fees/executionFee.spec.js +66 -0
  125. package/build/cjs/src/utils/fees/getNaiveEstimatedGasBySwapCount.js +8 -0
  126. package/build/cjs/src/utils/fees/index.js +128 -0
  127. package/build/cjs/src/utils/fees/priceImpact.js +300 -0
  128. package/build/cjs/src/utils/graphqlFetcher.js +24 -0
  129. package/build/cjs/src/utils/hash.js +41 -0
  130. package/build/cjs/src/utils/marketKeysAndConfigs.js +262 -0
  131. package/build/cjs/src/utils/markets.js +169 -0
  132. package/build/cjs/src/utils/multicall.js +125 -0
  133. package/build/cjs/src/utils/numbers.js +73 -0
  134. package/build/cjs/src/utils/objects.js +47 -0
  135. package/build/cjs/src/utils/orders.js +210 -0
  136. package/build/cjs/src/utils/positions.js +145 -0
  137. package/build/cjs/src/utils/prices.js +141 -0
  138. package/build/cjs/src/utils/referrals.js +34 -0
  139. package/build/cjs/src/utils/simulateExecuteOrder.js +143 -0
  140. package/build/cjs/src/utils/subgraph.js +76 -0
  141. package/build/cjs/src/utils/swap/__tests__/buildMarketsAdjacencyGraph.spec.js +118 -0
  142. package/build/cjs/src/utils/swap/__tests__/findReachableTokens.spec.js +118 -0
  143. package/build/cjs/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +150 -0
  144. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +429 -0
  145. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +617 -0
  146. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +388 -0
  147. package/build/cjs/src/utils/swap/buildMarketsAdjacencyGraph.js +25 -0
  148. package/build/cjs/src/utils/swap/constants.js +5 -0
  149. package/build/cjs/src/utils/swap/findReachableTokens.js +37 -0
  150. package/build/cjs/src/utils/swap/findSwapPathsBetweenTokens.js +75 -0
  151. package/build/cjs/src/utils/swap/index.js +18 -0
  152. package/build/cjs/src/utils/swap/preparedSwapData.js +28 -0
  153. package/build/cjs/src/utils/swap/swapPath.js +132 -0
  154. package/build/cjs/src/utils/swap/swapRouting.js +359 -0
  155. package/build/cjs/src/utils/swap/swapStats.js +258 -0
  156. package/build/cjs/src/utils/swap/swapValues.js +190 -0
  157. package/build/cjs/src/utils/testUtil.js +23 -0
  158. package/build/cjs/src/utils/tokens.js +144 -0
  159. package/build/cjs/src/utils/trade/amounts.js +317 -0
  160. package/build/cjs/src/utils/trade/index.js +17 -0
  161. package/build/cjs/src/utils/trade/trade.js +61 -0
  162. package/build/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  163. package/build/esm/src/abis/CustomErrors.json +3254 -0
  164. package/build/esm/src/abis/DataStore.json +1440 -0
  165. package/build/esm/src/abis/ERC721.json +442 -0
  166. package/build/esm/src/abis/EventEmitter.json +2065 -0
  167. package/build/esm/src/abis/ExchangeRouter.json +1801 -0
  168. package/build/esm/src/abis/GMT.json +522 -0
  169. package/build/esm/src/abis/GlpManager.json +591 -0
  170. package/build/esm/src/abis/GlvReader.json +1414 -0
  171. package/build/esm/src/abis/GlvRouter.json +706 -0
  172. package/build/esm/src/abis/GmxMigrator.json +657 -0
  173. package/build/esm/src/abis/GovToken.json +1121 -0
  174. package/build/esm/src/abis/MintableBaseToken.json +696 -0
  175. package/build/esm/src/abis/Multicall.json +333 -0
  176. package/build/esm/src/abis/OrderBook.json +1997 -0
  177. package/build/esm/src/abis/OrderBookReader.json +111 -0
  178. package/build/esm/src/abis/OrderExecutor.json +122 -0
  179. package/build/esm/src/abis/PositionManager.json +1165 -0
  180. package/build/esm/src/abis/PositionRouter.json +2030 -0
  181. package/build/esm/src/abis/Reader.json +355 -0
  182. package/build/esm/src/abis/ReaderV2.json +630 -0
  183. package/build/esm/src/abis/ReferralStorage.json +507 -0
  184. package/build/esm/src/abis/RewardReader.json +86 -0
  185. package/build/esm/src/abis/RewardRouter.json +1024 -0
  186. package/build/esm/src/abis/RewardTracker.json +918 -0
  187. package/build/esm/src/abis/Router-v2.json +605 -0
  188. package/build/esm/src/abis/Router.json +605 -0
  189. package/build/esm/src/abis/SubaccountRouter.json +658 -0
  190. package/build/esm/src/abis/SyntheticsReader.json +4706 -0
  191. package/build/esm/src/abis/SyntheticsRouter.json +77 -0
  192. package/build/esm/src/abis/Timelock.json +1737 -0
  193. package/build/esm/src/abis/Token.json +345 -0
  194. package/build/esm/src/abis/Treasury.json +411 -0
  195. package/build/esm/src/abis/UniPool.json +89 -0
  196. package/build/esm/src/abis/UniswapV2.json +1 -0
  197. package/build/esm/src/abis/Vault.json +3220 -0
  198. package/build/esm/src/abis/VaultReader.json +87 -0
  199. package/build/esm/src/abis/VaultV2.json +3019 -0
  200. package/build/esm/src/abis/VaultV2b.json +3220 -0
  201. package/build/esm/src/abis/Vester.json +1031 -0
  202. package/build/esm/src/abis/WETH.json +320 -0
  203. package/build/esm/src/abis/YieldFarm.json +599 -0
  204. package/build/esm/src/abis/YieldToken.json +560 -0
  205. package/build/esm/src/abis/index.js +88 -0
  206. package/build/esm/src/configs/__tests__/markets.spec.js +30 -0
  207. package/build/esm/src/configs/__tests__/tokens.spec.js +38 -0
  208. package/build/{src → esm/src}/configs/chains.js +4 -3
  209. package/build/{src → esm/src}/configs/contracts.js +10 -4
  210. package/build/{src → esm/src}/configs/factors.js +3 -1
  211. package/build/{src → esm/src}/configs/markets.js +148 -0
  212. package/build/esm/src/configs/oracleKeeper.js +36 -0
  213. package/build/{src → esm/src}/configs/tokens.js +242 -13
  214. package/build/{src → esm/src}/modules/accounts/accounts.js +1 -2
  215. package/build/{src → esm/src}/modules/accounts/accounts.spec.js +1 -0
  216. package/build/{src → esm/src}/modules/markets/index.js +2 -3
  217. package/build/{src → esm/src}/modules/markets/markets.spec.js +2 -1
  218. package/build/{src → esm/src}/modules/markets/query-builders.js +9 -11
  219. package/build/esm/src/modules/orders/helpers.js +220 -0
  220. package/build/esm/src/modules/orders/helpers.spec.js +106 -0
  221. package/build/{src → esm/src}/modules/orders/orders.js +20 -2
  222. package/build/{src → esm/src}/modules/orders/orders.spec.js +1 -0
  223. package/build/{src → esm/src}/modules/orders/transactions/cancelOrdersTxn.js +3 -3
  224. package/build/{src → esm/src}/modules/orders/transactions/createDecreaseOrderTxn.js +5 -5
  225. package/build/{src → esm/src}/modules/orders/transactions/createIncreaseOrderTxn.js +8 -7
  226. package/build/{src → esm/src}/modules/orders/transactions/createSwapOrderTxn.js +5 -5
  227. package/build/{src → esm/src}/modules/orders/transactions/createWrapOrUnwrapTxn.js +3 -3
  228. package/build/{src → esm/src}/modules/orders/transactions/updateOrderTxn.js +4 -4
  229. package/build/{src → esm/src}/modules/orders/utils.js +4 -6
  230. package/build/{src → esm/src}/modules/positions/positions.js +15 -18
  231. package/build/{src → esm/src}/modules/positions/positions.spec.js +2 -1
  232. package/build/{src → esm/src}/modules/tokens/tokens.js +4 -10
  233. package/build/{src → esm/src}/modules/tokens/tokens.spec.js +2 -1
  234. package/build/{src → esm/src}/modules/trades/trades.js +3 -3
  235. package/build/{src → esm/src}/modules/trades/trades.spec.js +1 -0
  236. package/build/{src → esm/src}/modules/utils/utils.js +27 -3
  237. package/build/esm/src/package.json +1 -0
  238. package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +944 -0
  239. package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +5858 -0
  240. package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +1763 -0
  241. package/build/{src → esm/src}/prebuilt/index.js +3 -7
  242. package/build/esm/src/test/mock.js +238 -0
  243. package/build/{src → esm/src}/types/orders.js +2 -0
  244. package/build/{src → esm/src}/types/trade.js +5 -0
  245. package/build/{src → esm/src}/utils/__tests__/LruCache.spec.js +1 -0
  246. package/build/{src → esm/src}/utils/__tests__/bigmath.spec.js +1 -0
  247. package/build/esm/src/utils/__tests__/fees.spec.js +62 -0
  248. package/build/{src → esm/src}/utils/__tests__/hash.spec.js +1 -0
  249. package/build/{src → esm/src}/utils/__tests__/markets.spec.js +5 -4
  250. package/build/{src → esm/src}/utils/__tests__/numbers.spec.js +27 -2
  251. package/build/esm/src/utils/__tests__/objects.spec.js +137 -0
  252. package/build/{src → esm/src}/utils/__tests__/positions.spec.js +13 -12
  253. package/build/{src → esm/src}/utils/__tests__/prices.spec.js +17 -8
  254. package/build/{src → esm/src}/utils/__tests__/referrals.spec.js +2 -1
  255. package/build/{src → esm/src}/utils/__tests__/subgraph.spec.js +1 -0
  256. package/build/{src → esm/src}/utils/__tests__/tokens.spec.js +34 -3
  257. package/build/{src → esm/src}/utils/__tests__/trade.spec.js +1 -0
  258. package/build/{src → esm/src}/utils/bigmath.js +3 -0
  259. package/build/esm/src/utils/common.js +10 -0
  260. package/build/{src → esm/src}/utils/fees/executionFee.js +49 -1
  261. package/build/{src → esm/src}/utils/fees/executionFee.spec.js +3 -3
  262. package/build/esm/src/utils/fees/getNaiveEstimatedGasBySwapCount.js +4 -0
  263. package/build/{src → esm/src}/utils/fees/index.js +17 -10
  264. package/build/{src → esm/src}/utils/markets.js +0 -3
  265. package/build/{src → esm/src}/utils/multicall.js +9 -6
  266. package/build/esm/src/utils/numbers.js +62 -0
  267. package/build/esm/src/utils/objects.js +36 -0
  268. package/build/{src → esm/src}/utils/orders.js +42 -13
  269. package/build/esm/src/utils/prices.js +132 -0
  270. package/build/{src → esm/src}/utils/simulateExecuteOrder.js +14 -10
  271. package/build/esm/src/utils/swap/__tests__/buildMarketsAdjacencyGraph.spec.js +116 -0
  272. package/build/esm/src/utils/swap/__tests__/findReachableTokens.spec.js +116 -0
  273. package/build/esm/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +148 -0
  274. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +427 -0
  275. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +615 -0
  276. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +386 -0
  277. package/build/esm/src/utils/swap/buildMarketsAdjacencyGraph.js +21 -0
  278. package/build/esm/src/utils/swap/constants.js +2 -0
  279. package/build/esm/src/utils/swap/findReachableTokens.js +33 -0
  280. package/build/esm/src/utils/swap/findSwapPathsBetweenTokens.js +71 -0
  281. package/build/esm/src/utils/swap/index.js +2 -0
  282. package/build/esm/src/utils/swap/preparedSwapData.js +23 -0
  283. package/build/esm/src/utils/swap/swapPath.js +127 -0
  284. package/build/esm/src/utils/swap/swapRouting.js +341 -0
  285. package/build/{src/utils → esm/src/utils/swap}/swapStats.js +49 -7
  286. package/build/esm/src/utils/swap/swapValues.js +184 -0
  287. package/build/esm/src/utils/tokens.js +127 -0
  288. package/build/esm/src/utils/trade/amounts.js +310 -0
  289. package/build/esm/src/utils/trade/index.js +1 -0
  290. package/build/{src/utils → esm/src/utils/trade}/trade.js +26 -4
  291. package/build/esm/tsconfig.esm.tsbuildinfo +1 -0
  292. package/build/src/abis/index.d.ts +4 -0
  293. package/build/src/configs/__tests__/markets.spec.d.ts +1 -0
  294. package/build/src/configs/__tests__/tokens.spec.d.ts +1 -0
  295. package/build/src/configs/batch.d.ts +2 -3
  296. package/build/src/configs/chains.d.ts +9 -23
  297. package/build/src/configs/contracts.d.ts +1 -220
  298. package/build/src/configs/factors.d.ts +3 -1
  299. package/build/src/configs/markets.d.ts +2 -1
  300. package/build/src/configs/oracleKeeper.d.ts +3 -0
  301. package/build/src/configs/tokens.d.ts +4 -4
  302. package/build/src/modules/markets/query-builders.d.ts +5 -4
  303. package/build/src/modules/oracle.d.ts +7 -3
  304. package/build/src/modules/orders/helpers.d.ts +50 -0
  305. package/build/src/modules/orders/helpers.spec.d.ts +1 -0
  306. package/build/src/modules/orders/orders.d.ts +6 -1
  307. package/build/src/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -1
  308. package/build/src/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -0
  309. package/build/src/modules/orders/transactions/updateOrderTxn.d.ts +2 -2
  310. package/build/src/modules/orders/utils.d.ts +5 -200
  311. package/build/src/modules/positions/positions.d.ts +3 -3
  312. package/build/src/modules/tokens/tokens.d.ts +2 -2
  313. package/build/src/modules/trades/trades.d.ts +2 -2
  314. package/build/src/modules/utils/utils.d.ts +4 -2
  315. package/build/src/prebuilt/index.d.ts +6 -2
  316. package/build/src/test/mock.d.ts +14 -0
  317. package/build/src/types/fees.d.ts +6 -0
  318. package/build/src/types/orders.d.ts +4 -3
  319. package/build/src/types/sdk.d.ts +4 -1
  320. package/build/src/types/tokens.d.ts +5 -0
  321. package/build/src/types/trade.d.ts +84 -9
  322. package/build/src/utils/__tests__/fees.spec.d.ts +1 -0
  323. package/build/src/utils/bigmath.d.ts +1 -0
  324. package/build/src/utils/common.d.ts +6 -1
  325. package/build/src/utils/fees/executionFee.d.ts +33 -0
  326. package/build/src/utils/fees/getNaiveEstimatedGasBySwapCount.d.ts +2 -0
  327. package/build/src/utils/fees/index.d.ts +1 -1
  328. package/build/src/utils/hash.d.ts +1 -1
  329. package/build/src/utils/multicall.d.ts +2 -1
  330. package/build/src/utils/numbers.d.ts +4 -0
  331. package/build/src/utils/objects.d.ts +6 -0
  332. package/build/src/utils/orders.d.ts +1 -0
  333. package/build/src/utils/positions.d.ts +1 -1
  334. package/build/src/utils/prices.d.ts +35 -1
  335. package/build/src/utils/swap/__tests__/buildMarketsAdjacencyGraph.spec.d.ts +1 -0
  336. package/build/src/utils/swap/__tests__/findReachableTokens.spec.d.ts +1 -0
  337. package/build/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.d.ts +1 -0
  338. package/build/src/utils/swap/__tests__/mockRouting.spec.d.ts +1 -0
  339. package/build/src/utils/swap/__tests__/swapRouting.spec.d.ts +1 -0
  340. package/build/src/utils/swap/__tests__/swapStats.spec.d.ts +1 -0
  341. package/build/src/utils/swap/buildMarketsAdjacencyGraph.d.ts +11 -0
  342. package/build/src/utils/swap/constants.d.ts +2 -0
  343. package/build/src/utils/swap/findReachableTokens.d.ts +2 -0
  344. package/build/src/utils/swap/findSwapPathsBetweenTokens.d.ts +3 -0
  345. package/build/src/utils/swap/index.d.ts +2 -0
  346. package/build/src/utils/swap/preparedSwapData.d.ts +14 -0
  347. package/build/src/utils/swap/swapPath.d.ts +23 -0
  348. package/build/src/utils/swap/swapRouting.d.ts +67 -0
  349. package/build/src/utils/{swapStats.d.ts → swap/swapStats.d.ts} +7 -2
  350. package/build/src/utils/swap/swapValues.d.ts +26 -0
  351. package/build/src/utils/testUtil.d.ts +2 -572
  352. package/build/src/utils/tokens.d.ts +25 -1
  353. package/build/src/utils/trade/amounts.d.ts +70 -0
  354. package/build/src/utils/trade/index.d.ts +1 -0
  355. package/build/src/utils/{trade.d.ts → trade/trade.d.ts} +2 -1
  356. package/package.json +48 -40
  357. package/build/src/abis/CustomErrors.json +0 -3254
  358. package/build/src/abis/DataStore.json +0 -1440
  359. package/build/src/abis/ERC721.json +0 -442
  360. package/build/src/abis/EventEmitter.json +0 -2065
  361. package/build/src/abis/ExchangeRouter.json +0 -1801
  362. package/build/src/abis/GMT.json +0 -522
  363. package/build/src/abis/GlpManager.json +0 -592
  364. package/build/src/abis/GlvReader.json +0 -1415
  365. package/build/src/abis/GlvRouter.json +0 -707
  366. package/build/src/abis/GmxMigrator.json +0 -657
  367. package/build/src/abis/GovToken.json +0 -1121
  368. package/build/src/abis/MintableBaseToken.json +0 -696
  369. package/build/src/abis/Multicall.json +0 -333
  370. package/build/src/abis/OrderBook.json +0 -1997
  371. package/build/src/abis/OrderBookReader.json +0 -111
  372. package/build/src/abis/OrderExecutor.json +0 -122
  373. package/build/src/abis/PositionManager.json +0 -1165
  374. package/build/src/abis/PositionRouter.json +0 -2030
  375. package/build/src/abis/Reader.json +0 -355
  376. package/build/src/abis/ReaderV2.json +0 -630
  377. package/build/src/abis/ReferralStorage.json +0 -507
  378. package/build/src/abis/RewardReader.json +0 -86
  379. package/build/src/abis/RewardRouter.json +0 -1024
  380. package/build/src/abis/RewardTracker.json +0 -918
  381. package/build/src/abis/Router-v2.json +0 -605
  382. package/build/src/abis/Router.json +0 -605
  383. package/build/src/abis/SubaccountRouter.json +0 -658
  384. package/build/src/abis/SyntheticsReader.json +0 -4709
  385. package/build/src/abis/SyntheticsRouter.json +0 -77
  386. package/build/src/abis/Timelock.json +0 -1737
  387. package/build/src/abis/Token.json +0 -345
  388. package/build/src/abis/Treasury.json +0 -411
  389. package/build/src/abis/UniPool.json +0 -89
  390. package/build/src/abis/UniswapV2.json +0 -1
  391. package/build/src/abis/Vault.json +0 -3220
  392. package/build/src/abis/VaultReader.json +0 -87
  393. package/build/src/abis/VaultV2.json +0 -3019
  394. package/build/src/abis/VaultV2b.json +0 -3220
  395. package/build/src/abis/Vester.json +0 -1031
  396. package/build/src/abis/WETH.json +0 -320
  397. package/build/src/abis/YieldFarm.json +0 -599
  398. package/build/src/abis/YieldToken.json +0 -560
  399. package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +0 -776
  400. package/build/src/prebuilt/hashedMarketConfigKeys.json +0 -4808
  401. package/build/src/prebuilt/hashedMarketValuesKeys.json +0 -1448
  402. package/build/src/prebuilt/index.ts +0 -45
  403. package/build/src/utils/__tests__/objects.spec.js +0 -58
  404. package/build/src/utils/common.js +0 -2
  405. package/build/src/utils/numbers.js +0 -30
  406. package/build/src/utils/objects.js +0 -13
  407. package/build/src/utils/prices.js +0 -25
  408. package/build/src/utils/tokens.js +0 -68
  409. package/build/tsconfig.tsbuildinfo +0 -1
  410. package/build/{scripts → esm/scripts}/prebuild/index.js +2 -2
  411. package/build/{scripts → esm/scripts}/prebuild/prebuildKinkModelMarketRatesKeys.js +1 -1
  412. package/build/{scripts → esm/scripts}/prebuild/prebuildMarketConfigKeys.js +1 -1
  413. package/build/{scripts → esm/scripts}/prebuild/prebuildMarketValuesKeys.js +0 -0
  414. package/build/{src → esm/src}/configs/batch.js +0 -0
  415. package/build/{src → esm/src}/configs/dataStore.js +0 -0
  416. package/build/{src → esm/src}/index.js +2 -2
  417. package/build/{src → esm/src}/modules/base.js +0 -0
  418. package/build/{src → esm/src}/modules/markets/types.js +0 -0
  419. package/build/{src → esm/src}/modules/oracle.js +0 -0
  420. package/build/{src → esm/src}/types/common.js +0 -0
  421. package/build/{src → esm/src}/types/fees.js +0 -0
  422. package/build/{src → esm/src}/types/markets.js +0 -0
  423. package/build/{src → esm/src}/types/positions.js +0 -0
  424. package/build/{src → esm/src}/types/referrals.js +0 -0
  425. package/build/{src → esm/src}/types/sdk.js +0 -0
  426. package/build/{src → esm/src}/types/sidecarOrders.js +0 -0
  427. package/build/{src → esm/src}/types/tokens.js +0 -0
  428. package/build/{src → esm/src}/types/tradeHistory.js +0 -0
  429. package/build/{src → esm/src}/utils/LruCache.js +0 -0
  430. package/build/{src → esm/src}/utils/buildUrl.js +0 -0
  431. package/build/{src → esm/src}/utils/callContract.js +0 -0
  432. package/build/{src → esm/src}/utils/contracts.js +0 -0
  433. package/build/{src → esm/src}/utils/fees/estimateOraclePriceCount.js +0 -0
  434. package/build/{src → esm/src}/utils/fees/priceImpact.js +0 -0
  435. package/build/{src → esm/src}/utils/graphqlFetcher.js +0 -0
  436. package/build/{src → esm/src}/utils/hash.js +0 -0
  437. package/build/{src → esm/src}/utils/marketKeysAndConfigs.js +1 -1
  438. package/build/{src → esm/src}/utils/positions.js +3 -3
  439. /package/build/{src → esm/src}/utils/referrals.js +0 -0
  440. /package/build/{src → esm/src}/utils/subgraph.js +0 -0
  441. /package/build/{src → esm/src}/utils/testUtil.js +0 -0
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HASHED_MARKET_VALUES_KEYS = exports.HASHED_MARKET_CONFIG_KEYS = exports.HASHED_KINK_MODEL_MARKET_RATES_KEYS = void 0;
7
+ const hashedKinkModelMarketRatesKeys_json_1 = __importDefault(require("./hashedKinkModelMarketRatesKeys.json"));
8
+ const hashedMarketConfigKeys_json_1 = __importDefault(require("./hashedMarketConfigKeys.json"));
9
+ const hashedMarketValuesKeys_json_1 = __importDefault(require("./hashedMarketValuesKeys.json"));
10
+ const HASHED_MARKET_VALUES_KEYS = hashedMarketValuesKeys_json_1.default;
11
+ exports.HASHED_MARKET_VALUES_KEYS = HASHED_MARKET_VALUES_KEYS;
12
+ const HASHED_MARKET_CONFIG_KEYS = hashedMarketConfigKeys_json_1.default;
13
+ exports.HASHED_MARKET_CONFIG_KEYS = HASHED_MARKET_CONFIG_KEYS;
14
+ const HASHED_KINK_MODEL_MARKET_RATES_KEYS = hashedKinkModelMarketRatesKeys_json_1.default;
15
+ exports.HASHED_KINK_MODEL_MARKET_RATES_KEYS = HASHED_KINK_MODEL_MARKET_RATES_KEYS;
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockMarketsInfoData = exports.mockMarketsData = exports.mockTokensData = exports.mockMarketKeys = exports.usdToToken = void 0;
4
+ const viem_1 = require("viem");
5
+ const factors_1 = require("../configs/factors");
6
+ const markets_1 = require("../utils/markets");
7
+ const numbers_1 = require("../utils/numbers");
8
+ const tokens_1 = require("../utils/tokens");
9
+ function usdToToken(usd, token) {
10
+ return (0, tokens_1.convertToTokenAmount)((0, numbers_1.expandDecimals)(usd, factors_1.USD_DECIMALS), token.decimals, token.prices?.minPrice);
11
+ }
12
+ exports.usdToToken = usdToToken;
13
+ function mockMarketKeys() {
14
+ return [
15
+ "AVAX-AVAX-USDC",
16
+ "ETH-ETH-USDC",
17
+ "ETH-ETH-DAI",
18
+ "SOL-ETH-USDC",
19
+ "BTC-BTC-DAI",
20
+ "SPOT-USDC-DAI",
21
+ "SPOT-DAI-USDC",
22
+ // same collaterals, should be disabled for swaps
23
+ "ETH-USDC-USDC",
24
+ // Unreachable markets
25
+ "TBTC-TBTC-TBTC",
26
+ "TETH_A-TETH_A-TETH_B",
27
+ // Partially unreachable markets
28
+ "TEST_B-TEST_B-TEST_A",
29
+ "TEST_C-TEST_C-TEST_A",
30
+ ];
31
+ }
32
+ exports.mockMarketKeys = mockMarketKeys;
33
+ function mockTokensData(overrides = {}) {
34
+ const tokens = {
35
+ ...overrides,
36
+ AVAX: {
37
+ address: "AVAX",
38
+ wrappedAddress: "WAVAX",
39
+ name: "Avalanche",
40
+ symbol: "AVAX",
41
+ decimals: 18,
42
+ isNative: true,
43
+ prices: {
44
+ minPrice: (0, numbers_1.expandDecimals)(12, 30),
45
+ maxPrice: (0, numbers_1.expandDecimals)(12, 30),
46
+ },
47
+ ...(overrides.AVAX || {}),
48
+ },
49
+ WAVAX: {
50
+ address: "WAVAX",
51
+ name: "Wrapped Avalanche",
52
+ symbol: "WAVAX",
53
+ decimals: 18,
54
+ isNative: true,
55
+ prices: {
56
+ minPrice: (0, numbers_1.expandDecimals)(12, 30),
57
+ maxPrice: (0, numbers_1.expandDecimals)(12, 30),
58
+ },
59
+ ...(overrides.AVAX || {}),
60
+ },
61
+ USDC: {
62
+ address: "USDC",
63
+ name: "USD Coin",
64
+ symbol: "USDC",
65
+ decimals: 6,
66
+ isStable: true,
67
+ prices: {
68
+ minPrice: (0, numbers_1.expandDecimals)(1, 30),
69
+ maxPrice: (0, numbers_1.expandDecimals)(1, 30),
70
+ },
71
+ ...(overrides.USDC || {}),
72
+ },
73
+ ETH: {
74
+ address: "ETH",
75
+ name: "Ethereum",
76
+ symbol: "ETH",
77
+ decimals: 18,
78
+ prices: {
79
+ minPrice: (0, numbers_1.expandDecimals)(1200, 30),
80
+ maxPrice: (0, numbers_1.expandDecimals)(1200, 30),
81
+ },
82
+ ...(overrides.ETH || {}),
83
+ },
84
+ BTC: {
85
+ address: "BTC",
86
+ name: "Bitcoin",
87
+ symbol: "BTC",
88
+ decimals: 8,
89
+ prices: {
90
+ minPrice: (0, numbers_1.expandDecimals)(20000, 30),
91
+ maxPrice: (0, numbers_1.expandDecimals)(20000, 30),
92
+ },
93
+ ...(overrides.BTC || {}),
94
+ },
95
+ DAI: {
96
+ address: "DAI",
97
+ name: "Dai",
98
+ symbol: "DAI",
99
+ decimals: 30,
100
+ isStable: true,
101
+ prices: {
102
+ minPrice: (0, numbers_1.expandDecimals)(1, 30),
103
+ maxPrice: (0, numbers_1.expandDecimals)(1, 30),
104
+ },
105
+ ...(overrides.DAI || {}),
106
+ },
107
+ SOL: {
108
+ address: "SOL",
109
+ name: "Solana",
110
+ symbol: "SOL",
111
+ decimals: 18,
112
+ isSynthetic: true,
113
+ prices: {
114
+ minPrice: (0, numbers_1.expandDecimals)(16, 30),
115
+ maxPrice: (0, numbers_1.expandDecimals)(16, 30),
116
+ },
117
+ ...(overrides.SOL || {}),
118
+ },
119
+ SPOT: {
120
+ address: "SPOT",
121
+ name: "SPOT",
122
+ decimals: 30,
123
+ symbol: "SPOT",
124
+ prices: {
125
+ minPrice: BigInt(1),
126
+ maxPrice: BigInt(1),
127
+ },
128
+ ...(overrides.SPOT || {}),
129
+ },
130
+ };
131
+ return tokens;
132
+ }
133
+ exports.mockTokensData = mockTokensData;
134
+ /**
135
+ * @param marketKeys - array of market keys in the following format: indexToken-longToken-shortToken
136
+ */
137
+ function mockMarketsData(marketKeys) {
138
+ return marketKeys.reduce((acc, key) => {
139
+ const [indexTokenAddress, longTokenAddress, shortTokenAddress] = key.split("-");
140
+ acc[key] = {
141
+ marketTokenAddress: key,
142
+ indexTokenAddress,
143
+ longTokenAddress,
144
+ shortTokenAddress,
145
+ isSameCollaterals: longTokenAddress === shortTokenAddress,
146
+ isSpotOnly: indexTokenAddress === "SPOT",
147
+ data: "",
148
+ name: "Test Market",
149
+ };
150
+ return acc;
151
+ }, {});
152
+ }
153
+ exports.mockMarketsData = mockMarketsData;
154
+ function mockMarketsInfoData(tokensData, marketKeys, overrides = {}) {
155
+ return marketKeys.reduce((acc, key) => {
156
+ const [indexTokenAddress, longTokenAddress, shortTokenAddress] = key.split("-");
157
+ const indexToken = (0, tokens_1.getTokenData)(tokensData, indexTokenAddress);
158
+ const longToken = (0, tokens_1.getTokenData)(tokensData, longTokenAddress);
159
+ const shortToken = (0, tokens_1.getTokenData)(tokensData, shortTokenAddress);
160
+ const isSpotOnly = indexTokenAddress === "SPOT";
161
+ acc[key] = {
162
+ isDisabled: false,
163
+ marketTokenAddress: key,
164
+ indexTokenAddress,
165
+ longTokenAddress,
166
+ shortTokenAddress,
167
+ isSameCollaterals: longTokenAddress === shortTokenAddress,
168
+ isSpotOnly,
169
+ name: (0, markets_1.getMarketFullName)({ longToken, shortToken, indexToken, isSpotOnly }),
170
+ longToken,
171
+ shortToken,
172
+ indexToken,
173
+ longPoolAmount: usdToToken(1000, longToken),
174
+ shortPoolAmount: usdToToken(1000, shortToken),
175
+ maxLongPoolAmount: usdToToken(10000, longToken),
176
+ maxShortPoolAmount: usdToToken(10000, shortToken),
177
+ maxLongPoolUsdForDeposit: usdToToken(10000, longToken),
178
+ maxShortPoolUsdForDeposit: usdToToken(10000, shortToken),
179
+ poolValueMax: (0, numbers_1.expandDecimals)(2000, factors_1.USD_DECIMALS),
180
+ poolValueMin: (0, numbers_1.expandDecimals)(2000, factors_1.USD_DECIMALS),
181
+ reserveFactorLong: (0, numbers_1.expandDecimals)(5, 29),
182
+ reserveFactorShort: (0, numbers_1.expandDecimals)(5, 29),
183
+ openInterestReserveFactorLong: (0, numbers_1.expandDecimals)(5, 29),
184
+ openInterestReserveFactorShort: (0, numbers_1.expandDecimals)(5, 29),
185
+ maxOpenInterestLong: (0, numbers_1.expandDecimals)(5, 29),
186
+ maxOpenInterestShort: (0, numbers_1.expandDecimals)(5, 29),
187
+ positionImpactPoolAmount: usdToToken(1000, indexToken),
188
+ positionImpactPoolDistributionRate: 0n,
189
+ minPositionImpactPoolAmount: 0n,
190
+ swapImpactPoolAmountLong: usdToToken(1000, longToken),
191
+ swapImpactPoolAmountShort: usdToToken(1000, shortToken),
192
+ positionFeeFactorForPositiveImpact: (0, numbers_1.expandDecimals)(5, 26),
193
+ positionFeeFactorForNegativeImpact: (0, numbers_1.expandDecimals)(5, 26),
194
+ positionImpactFactorPositive: (0, numbers_1.expandDecimals)(2, 23),
195
+ positionImpactFactorNegative: (0, numbers_1.expandDecimals)(1, 23),
196
+ maxPositionImpactFactorPositive: (0, numbers_1.expandDecimals)(2, 23),
197
+ maxPositionImpactFactorNegative: (0, numbers_1.expandDecimals)(1, 23),
198
+ maxPositionImpactFactorForLiquidations: (0, numbers_1.expandDecimals)(1, 23),
199
+ positionImpactExponentFactor: (0, numbers_1.expandDecimals)(2, 30),
200
+ swapFeeFactorForPositiveImpact: (0, numbers_1.expandDecimals)(2, 27),
201
+ swapFeeFactorForNegativeImpact: (0, numbers_1.expandDecimals)(2, 27),
202
+ swapImpactFactorPositive: (0, numbers_1.expandDecimals)(2, 23),
203
+ swapImpactFactorNegative: (0, numbers_1.expandDecimals)(1, 23),
204
+ swapImpactExponentFactor: (0, numbers_1.expandDecimals)(2, 30),
205
+ // MarketInfo
206
+ borrowingFactorPerSecondForLongs: 0n,
207
+ borrowingFactorPerSecondForShorts: 0n,
208
+ borrowingExponentFactorLong: 0n,
209
+ borrowingExponentFactorShort: 0n,
210
+ fundingFactor: 0n,
211
+ fundingExponentFactor: 0n,
212
+ fundingIncreaseFactorPerSecond: 0n,
213
+ fundingDecreaseFactorPerSecond: 0n,
214
+ maxFundingFactorPerSecond: 0n,
215
+ minFundingFactorPerSecond: 0n,
216
+ thresholdForDecreaseFunding: 0n,
217
+ thresholdForStableFunding: 0n,
218
+ totalBorrowingFees: 0n,
219
+ minCollateralFactor: 0n,
220
+ minCollateralFactorForOpenInterestLong: 0n,
221
+ minCollateralFactorForOpenInterestShort: 0n,
222
+ longPoolAmountAdjustment: 0n,
223
+ shortPoolAmountAdjustment: 0n,
224
+ borrowingFactorLong: 0n,
225
+ borrowingFactorShort: 0n,
226
+ fundingFactorPerSecond: 0n,
227
+ longsPayShorts: false,
228
+ longInterestUsd: (0, numbers_1.expandDecimals)(500, factors_1.USD_DECIMALS),
229
+ shortInterestUsd: (0, numbers_1.expandDecimals)(500, factors_1.USD_DECIMALS),
230
+ longInterestInTokens: usdToToken(500, indexToken),
231
+ shortInterestInTokens: usdToToken(500, indexToken),
232
+ maxPnlFactorForTradersLong: (0, numbers_1.expandDecimals)(1, 30),
233
+ maxPnlFactorForTradersShort: (0, numbers_1.expandDecimals)(1, 30),
234
+ data: "",
235
+ virtualPoolAmountForLongToken: 0n,
236
+ virtualPoolAmountForShortToken: 0n,
237
+ virtualInventoryForPositions: 0n,
238
+ virtualMarketId: viem_1.zeroAddress,
239
+ virtualLongTokenId: viem_1.zeroAddress,
240
+ virtualShortTokenId: viem_1.zeroAddress,
241
+ ...(overrides[key] || {}),
242
+ };
243
+ return acc;
244
+ }, {});
245
+ }
246
+ exports.mockMarketsInfoData = mockMarketsInfoData;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DecreasePositionSwapType = exports.SwapPricingType = exports.OrderType = void 0;
4
+ var OrderType;
5
+ (function (OrderType) {
6
+ // the order will be cancelled if the minOutputAmount cannot be fulfilled
7
+ OrderType[OrderType["MarketSwap"] = 0] = "MarketSwap";
8
+ // @dev LimitSwap: swap token A to token B if the minOutputAmount can be fulfilled
9
+ OrderType[OrderType["LimitSwap"] = 1] = "LimitSwap";
10
+ // @dev MarketIncrease: increase position at the current market price
11
+ // the order will be cancelled if the position cannot be increased at the acceptablePrice
12
+ OrderType[OrderType["MarketIncrease"] = 2] = "MarketIncrease";
13
+ // @dev LimitIncrease: increase position if the triggerPrice is reached and the acceptablePrice can be fulfilled
14
+ OrderType[OrderType["LimitIncrease"] = 3] = "LimitIncrease";
15
+ // @dev MarketDecrease: decrease position at the curent market price
16
+ // the order will be cancelled if the position cannot be decreased at the acceptablePrice
17
+ OrderType[OrderType["MarketDecrease"] = 4] = "MarketDecrease";
18
+ // @dev LimitDecrease: decrease position if the triggerPrice is reached and the acceptablePrice can be fulfilled
19
+ OrderType[OrderType["LimitDecrease"] = 5] = "LimitDecrease";
20
+ // @dev StopLossDecrease: decrease position if the triggerPrice is reached and the acceptablePrice can be fulfilled
21
+ OrderType[OrderType["StopLossDecrease"] = 6] = "StopLossDecrease";
22
+ // @dev Liquidation: allows liquidation of positions if the criteria for liquidation are met
23
+ OrderType[OrderType["Liquidation"] = 7] = "Liquidation";
24
+ // @dev StopIncrease: increase position if the triggerPrice is reached and the acceptablePrice can be fulfilled
25
+ OrderType[OrderType["StopIncrease"] = 8] = "StopIncrease";
26
+ })(OrderType || (exports.OrderType = OrderType = {}));
27
+ var SwapPricingType;
28
+ (function (SwapPricingType) {
29
+ SwapPricingType[SwapPricingType["TwoStep"] = 0] = "TwoStep";
30
+ SwapPricingType[SwapPricingType["Shift"] = 1] = "Shift";
31
+ SwapPricingType[SwapPricingType["Atomic"] = 2] = "Atomic";
32
+ })(SwapPricingType || (exports.SwapPricingType = SwapPricingType = {}));
33
+ var DecreasePositionSwapType;
34
+ (function (DecreasePositionSwapType) {
35
+ DecreasePositionSwapType[DecreasePositionSwapType["NoSwap"] = 0] = "NoSwap";
36
+ DecreasePositionSwapType[DecreasePositionSwapType["SwapPnlTokenToCollateralToken"] = 1] = "SwapPnlTokenToCollateralToken";
37
+ DecreasePositionSwapType[DecreasePositionSwapType["SwapCollateralTokenToPnlToken"] = 2] = "SwapCollateralTokenToPnlToken";
38
+ })(DecreasePositionSwapType || (exports.DecreasePositionSwapType = DecreasePositionSwapType = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RebateDistributionType = void 0;
4
+ var RebateDistributionType;
5
+ (function (RebateDistributionType) {
6
+ // V1 Airdrop for Affiliates
7
+ RebateDistributionType["Rebate"] = "1";
8
+ // V2 Claim for Affiliates
9
+ RebateDistributionType["Claim"] = "1000";
10
+ // V1 Airdrop for Traders
11
+ RebateDistributionType["Discount"] = "2";
12
+ })(RebateDistributionType || (exports.RebateDistributionType = RebateDistributionType = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExternalSwapAggregator = exports.TriggerThresholdType = exports.TradeMode = exports.TradeType = void 0;
4
+ var TradeType;
5
+ (function (TradeType) {
6
+ TradeType["Long"] = "Long";
7
+ TradeType["Short"] = "Short";
8
+ TradeType["Swap"] = "Swap";
9
+ })(TradeType || (exports.TradeType = TradeType = {}));
10
+ var TradeMode;
11
+ (function (TradeMode) {
12
+ TradeMode["Market"] = "Market";
13
+ TradeMode["Limit"] = "Limit";
14
+ TradeMode["StopMarket"] = "StopMarket";
15
+ TradeMode["Trigger"] = "Trigger";
16
+ })(TradeMode || (exports.TradeMode = TradeMode = {}));
17
+ var TriggerThresholdType;
18
+ (function (TriggerThresholdType) {
19
+ TriggerThresholdType["Above"] = ">";
20
+ TriggerThresholdType["Below"] = "<";
21
+ })(TriggerThresholdType || (exports.TriggerThresholdType = TriggerThresholdType = {}));
22
+ var ExternalSwapAggregator;
23
+ (function (ExternalSwapAggregator) {
24
+ ExternalSwapAggregator["OpenOcean"] = "openOcean";
25
+ })(ExternalSwapAggregator || (exports.ExternalSwapAggregator = ExternalSwapAggregator = {}));
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TradeActionType = void 0;
4
+ var TradeActionType;
5
+ (function (TradeActionType) {
6
+ TradeActionType["OrderCreated"] = "OrderCreated";
7
+ TradeActionType["OrderExecuted"] = "OrderExecuted";
8
+ TradeActionType["OrderCancelled"] = "OrderCancelled";
9
+ TradeActionType["OrderUpdated"] = "OrderUpdated";
10
+ TradeActionType["OrderFrozen"] = "OrderFrozen";
11
+ })(TradeActionType || (exports.TradeActionType = TradeActionType = {}));
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LRUCache = void 0;
4
+ class LRUCache {
5
+ constructor(capacity) {
6
+ this.capacity = capacity;
7
+ this.cache = new Map();
8
+ this.recentKeys = [];
9
+ }
10
+ has(key) {
11
+ return this.cache.has(key);
12
+ }
13
+ get(key) {
14
+ if (this.cache.has(key)) {
15
+ // Update recentKeys to reflect the usage
16
+ this.updateRecentKeys(key);
17
+ return this.cache.get(key);
18
+ }
19
+ return undefined;
20
+ }
21
+ set(key, value) {
22
+ if (typeof key !== "string") {
23
+ throw new Error("Key must be a string");
24
+ }
25
+ // If key exists, update its value and move it to the front of recentKeys
26
+ if (this.cache.has(key)) {
27
+ this.cache.set(key, value);
28
+ this.updateRecentKeys(key);
29
+ }
30
+ else {
31
+ // If capacity is reached, remove least recently used item
32
+ if (this.cache.size === this.capacity) {
33
+ const lruKey = this.recentKeys.shift();
34
+ if (lruKey) {
35
+ this.cache.delete(lruKey);
36
+ }
37
+ }
38
+ // Add the new key-value pair to the cache and recentKeys
39
+ this.cache.set(key, value);
40
+ this.recentKeys.push(key);
41
+ }
42
+ }
43
+ updateRecentKeys(key) {
44
+ // Move the key to the end (most recently used) of recentKeys
45
+ this.recentKeys = this.recentKeys.filter((k) => k !== key);
46
+ this.recentKeys.push(key);
47
+ }
48
+ }
49
+ exports.LRUCache = LRUCache;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const LruCache_1 = require("../LruCache");
5
+ (0, vitest_1.describe)("LruCache", () => {
6
+ (0, vitest_1.it)("should store and retrieve values", () => {
7
+ const cache = new LruCache_1.LRUCache(2);
8
+ cache.set("a", 1);
9
+ (0, vitest_1.expect)(cache.get("a")).toBe(1);
10
+ });
11
+ (0, vitest_1.it)("should return undefined for non-existing keys", () => {
12
+ const cache = new LruCache_1.LRUCache(2);
13
+ (0, vitest_1.expect)(cache.get("x")).toBeUndefined();
14
+ });
15
+ (0, vitest_1.it)("should update recent usage when getting a key", () => {
16
+ const cache = new LruCache_1.LRUCache(2);
17
+ cache.set("a", 1);
18
+ cache.set("b", 2);
19
+ cache.get("a"); // 'a' is now the most recently used
20
+ cache.set("c", 3); // 'b' should be evicted
21
+ (0, vitest_1.expect)(cache.has("b")).toBe(false);
22
+ (0, vitest_1.expect)(cache.has("a")).toBe(true);
23
+ });
24
+ (0, vitest_1.it)("should evict the least recently used key when capacity is exceeded", () => {
25
+ const cache = new LruCache_1.LRUCache(2);
26
+ cache.set("a", 1);
27
+ cache.set("b", 2);
28
+ cache.set("c", 3); // 'a' is removed
29
+ (0, vitest_1.expect)(cache.has("a")).toBe(false);
30
+ (0, vitest_1.expect)(cache.has("b")).toBe(true);
31
+ (0, vitest_1.expect)(cache.get("c")).toBe(3);
32
+ });
33
+ (0, vitest_1.it)("should update existing keys without eviction", () => {
34
+ const cache = new LruCache_1.LRUCache(2);
35
+ cache.set("a", 1);
36
+ cache.set("b", 2);
37
+ cache.set("a", 10); // update 'a'
38
+ (0, vitest_1.expect)(cache.get("a")).toBe(10);
39
+ (0, vitest_1.expect)(cache.has("b")).toBe(true);
40
+ });
41
+ (0, vitest_1.it)("should throw error if key is not a string", () => {
42
+ const cache = new LruCache_1.LRUCache(2);
43
+ (0, vitest_1.expect)(() => cache.set(123, 1)).toThrow("Key must be a string");
44
+ });
45
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const bigmath_1 = require("../bigmath");
5
+ (0, vitest_1.describe)("bigMath", () => {
6
+ (0, vitest_1.describe)("abs", () => {
7
+ (0, vitest_1.it)("should return the absolute value of a number", () => {
8
+ (0, vitest_1.expect)(bigmath_1.bigMath.abs(10n)).toBe(10n);
9
+ (0, vitest_1.expect)(bigmath_1.bigMath.abs(-10n)).toBe(10n);
10
+ });
11
+ });
12
+ (0, vitest_1.describe)("mulDiv", () => {
13
+ (0, vitest_1.it)("should return the result of multiplying two numbers and dividing by a third", () => {
14
+ (0, vitest_1.expect)(bigmath_1.bigMath.mulDiv(10n, 10n, 2n)).toBe(50n);
15
+ (0, vitest_1.expect)(bigmath_1.bigMath.mulDiv(10n, 10n, 3n)).toBe(33n);
16
+ });
17
+ });
18
+ (0, vitest_1.describe)("max", () => {
19
+ (0, vitest_1.it)("should return the maximum value of a list of numbers", () => {
20
+ (0, vitest_1.expect)(bigmath_1.bigMath.max(10n, 20n, -30n)).toBe(20n);
21
+ (0, vitest_1.expect)(bigmath_1.bigMath.max(30n, 20n, 10n)).toBe(30n);
22
+ });
23
+ });
24
+ (0, vitest_1.describe)("min", () => {
25
+ (0, vitest_1.it)("should return the minimum value of a list of numbers", () => {
26
+ (0, vitest_1.expect)(bigmath_1.bigMath.min(10n, 20n, -30n)).toBe(-30n);
27
+ (0, vitest_1.expect)(bigmath_1.bigMath.min(30n, 20n, 10n)).toBe(10n);
28
+ });
29
+ });
30
+ (0, vitest_1.describe)("avg", () => {
31
+ (0, vitest_1.it)("should return the average value of a list of numbers", () => {
32
+ (0, vitest_1.expect)(bigmath_1.bigMath.avg(10n, 20n, 30n)).toBe(20n);
33
+ (0, vitest_1.expect)(bigmath_1.bigMath.avg(10n, 20n, 30n, 40n, undefined)).toBe(25n);
34
+ });
35
+ (0, vitest_1.it)("should return undefined if no values are provided", () => {
36
+ (0, vitest_1.expect)(bigmath_1.bigMath.avg()).toBe(undefined);
37
+ (0, vitest_1.expect)(bigmath_1.bigMath.avg(undefined, undefined)).toBe(undefined);
38
+ });
39
+ });
40
+ });
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const factors_1 = require("../../configs/factors");
5
+ const numbers_1 = require("../numbers");
6
+ const fees_1 = require("../fees");
7
+ const dollar = 10n ** BigInt(factors_1.USD_DECIMALS);
8
+ const eightMillion = 8000000n;
9
+ const tenMillion = 10000000n;
10
+ function toFactor(percent) {
11
+ const value = parseFloat(percent.replace("%", ""));
12
+ return (0, numbers_1.numberToBigint)(value, 30 - 2);
13
+ }
14
+ const second = 1;
15
+ (0, vitest_1.describe)("getFundingFactorPerPeriod", () => {
16
+ (0, vitest_1.it)("works when short pay, shorts OI bigger", () => {
17
+ const marketInfo = {
18
+ fundingFactorPerSecond: toFactor("50%"),
19
+ longsPayShorts: false,
20
+ longInterestUsd: eightMillion * dollar,
21
+ shortInterestUsd: tenMillion * dollar,
22
+ };
23
+ const forLongs = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, true, second);
24
+ (0, vitest_1.expect)(forLongs.toString()).toBe(toFactor("62.5%").toString());
25
+ const forShorts = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, false, second);
26
+ (0, vitest_1.expect)(forShorts.toString()).toBe(toFactor("-50%").toString());
27
+ });
28
+ (0, vitest_1.it)("works when short pay, longs OI bigger", () => {
29
+ const marketInfo = {
30
+ fundingFactorPerSecond: toFactor("50%"),
31
+ longsPayShorts: false,
32
+ longInterestUsd: tenMillion * dollar,
33
+ shortInterestUsd: eightMillion * dollar,
34
+ };
35
+ const forLongs = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, true, second);
36
+ (0, vitest_1.expect)(forLongs.toString()).toBe(toFactor("50%").toString());
37
+ const forShorts = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, false, second);
38
+ (0, vitest_1.expect)(forShorts.toString()).toBe(toFactor("-62.5%").toString());
39
+ });
40
+ (0, vitest_1.it)("works when long pay, shorts OI bigger", () => {
41
+ const marketInfo = {
42
+ fundingFactorPerSecond: toFactor("50%"),
43
+ longsPayShorts: true,
44
+ longInterestUsd: eightMillion * dollar,
45
+ shortInterestUsd: tenMillion * dollar,
46
+ };
47
+ const forLongs = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, true, second);
48
+ (0, vitest_1.expect)(forLongs.toString()).toBe(toFactor("-62.5%").toString());
49
+ const forShorts = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, false, second);
50
+ (0, vitest_1.expect)(forShorts.toString()).toBe(toFactor("50%").toString());
51
+ });
52
+ (0, vitest_1.it)("works when long pay, longs OI bigger", () => {
53
+ const marketInfo = {
54
+ fundingFactorPerSecond: toFactor("50%"),
55
+ longsPayShorts: true,
56
+ longInterestUsd: tenMillion * dollar,
57
+ shortInterestUsd: eightMillion * dollar,
58
+ };
59
+ const forLongs = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, true, second);
60
+ (0, vitest_1.expect)(forLongs.toString()).toBe(toFactor("-50%").toString());
61
+ const forShorts = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, false, second);
62
+ (0, vitest_1.expect)(forShorts.toString()).toBe(toFactor("62.5%").toString());
63
+ });
64
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const hash_1 = require("../hash");
5
+ const LruCache_1 = require("../LruCache");
6
+ (0, vitest_1.describe)("hashData", () => {
7
+ (0, vitest_1.it)("returns a valid hash and caches it", () => {
8
+ const inputTypes = ["uint256", "string"];
9
+ const inputValues = [123n, "hello"];
10
+ const result = (0, hash_1.hashData)(inputTypes, inputValues);
11
+ (0, vitest_1.expect)(result).toBe("0x18a25ed45d79546dfca2565caa2ee3102fb46159dea4fde1d0a9c0cc78ce94e3");
12
+ // Check cache
13
+ const key = JSON.stringify({ dataTypes: inputTypes, dataValues: ["123", "hello"] });
14
+ (0, vitest_1.expect)(new LruCache_1.LRUCache(10000).has(key)).toBe(false);
15
+ });
16
+ (0, vitest_1.it)("returns cached hash if already computed", () => {
17
+ const inputTypes = ["bool"];
18
+ const inputValues = [true];
19
+ const result1 = (0, hash_1.hashData)(inputTypes, inputValues);
20
+ const result2 = (0, hash_1.hashData)(inputTypes, inputValues);
21
+ (0, vitest_1.expect)(result1).toBe(result2);
22
+ });
23
+ });
24
+ (0, vitest_1.describe)("hashString", () => {
25
+ (0, vitest_1.it)("returns a valid hash for a string and caches it", () => {
26
+ const str = "test-string";
27
+ const hash1 = (0, hash_1.hashString)(str);
28
+ const hash2 = (0, hash_1.hashString)(str);
29
+ (0, vitest_1.expect)(hash1).toBe(hash2);
30
+ });
31
+ });
32
+ (0, vitest_1.describe)("hashDataMap", () => {
33
+ (0, vitest_1.it)("returns hashes for a given record map", () => {
34
+ const result = (0, hash_1.hashDataMap)({
35
+ first: [["string"], ["hello"]],
36
+ second: [["uint256"], [42n]],
37
+ empty: undefined,
38
+ });
39
+ (0, vitest_1.expect)(Object.keys(result)).toContain("first");
40
+ (0, vitest_1.expect)(Object.keys(result)).toContain("second");
41
+ (0, vitest_1.expect)(Object.keys(result)).not.toContain("empty");
42
+ });
43
+ });