@gmx-io/sdk 0.0.1-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 (237) hide show
  1. package/LICENSE +40 -0
  2. package/README.md +79 -0
  3. package/build/abis/CustomErrors.json +3254 -0
  4. package/build/abis/DataStore.json +1440 -0
  5. package/build/abis/ERC721.json +442 -0
  6. package/build/abis/EventEmitter.json +2065 -0
  7. package/build/abis/ExchangeRouter.json +1598 -0
  8. package/build/abis/GMT.json +522 -0
  9. package/build/abis/GlpManager.json +592 -0
  10. package/build/abis/GlvReader.json +1425 -0
  11. package/build/abis/GlvRouter.json +613 -0
  12. package/build/abis/GmxMigrator.json +657 -0
  13. package/build/abis/GovToken.json +1121 -0
  14. package/build/abis/MintableBaseToken.json +696 -0
  15. package/build/abis/Multicall.json +333 -0
  16. package/build/abis/OrderBook.json +1997 -0
  17. package/build/abis/OrderBookReader.json +111 -0
  18. package/build/abis/OrderExecutor.json +122 -0
  19. package/build/abis/PositionManager.json +1165 -0
  20. package/build/abis/PositionRouter.json +2030 -0
  21. package/build/abis/Reader.json +355 -0
  22. package/build/abis/ReaderV2.json +630 -0
  23. package/build/abis/ReferralStorage.json +507 -0
  24. package/build/abis/RewardReader.json +86 -0
  25. package/build/abis/RewardRouter.json +769 -0
  26. package/build/abis/RewardTracker.json +918 -0
  27. package/build/abis/Router-v2.json +605 -0
  28. package/build/abis/Router.json +605 -0
  29. package/build/abis/SubaccountRouter.json +648 -0
  30. package/build/abis/SyntheticsReader.json +4577 -0
  31. package/build/abis/SyntheticsRouter.json +77 -0
  32. package/build/abis/Timelock.json +1737 -0
  33. package/build/abis/Token.json +345 -0
  34. package/build/abis/Treasury.json +411 -0
  35. package/build/abis/UniPool.json +89 -0
  36. package/build/abis/UniswapV2.json +1 -0
  37. package/build/abis/Vault.json +3220 -0
  38. package/build/abis/VaultReader.json +87 -0
  39. package/build/abis/VaultV2.json +3019 -0
  40. package/build/abis/VaultV2b.json +3220 -0
  41. package/build/abis/Vester.json +1031 -0
  42. package/build/abis/WETH.json +320 -0
  43. package/build/abis/YieldFarm.json +599 -0
  44. package/build/abis/YieldToken.json +560 -0
  45. package/build/prebuilt/hashedMarketConfigKeys.json +3658 -0
  46. package/build/prebuilt/hashedMarketValuesKeys.json +1103 -0
  47. package/build/prebuilt/index.ts +28 -0
  48. package/build/src/abis/CustomErrors.json +3254 -0
  49. package/build/src/abis/DataStore.json +1440 -0
  50. package/build/src/abis/ERC721.json +442 -0
  51. package/build/src/abis/EventEmitter.json +2065 -0
  52. package/build/src/abis/ExchangeRouter.json +1598 -0
  53. package/build/src/abis/GMT.json +522 -0
  54. package/build/src/abis/GlpManager.json +591 -0
  55. package/build/src/abis/GlvReader.json +1424 -0
  56. package/build/src/abis/GlvRouter.json +612 -0
  57. package/build/src/abis/GmxMigrator.json +657 -0
  58. package/build/src/abis/GovToken.json +1121 -0
  59. package/build/src/abis/MintableBaseToken.json +696 -0
  60. package/build/src/abis/Multicall.json +333 -0
  61. package/build/src/abis/OrderBook.json +1997 -0
  62. package/build/src/abis/OrderBookReader.json +111 -0
  63. package/build/src/abis/OrderExecutor.json +122 -0
  64. package/build/src/abis/PositionManager.json +1165 -0
  65. package/build/src/abis/PositionRouter.json +2030 -0
  66. package/build/src/abis/Reader.json +355 -0
  67. package/build/src/abis/ReaderV2.json +630 -0
  68. package/build/src/abis/ReferralStorage.json +507 -0
  69. package/build/src/abis/RewardReader.json +86 -0
  70. package/build/src/abis/RewardRouter.json +769 -0
  71. package/build/src/abis/RewardTracker.json +918 -0
  72. package/build/src/abis/Router-v2.json +605 -0
  73. package/build/src/abis/Router.json +605 -0
  74. package/build/src/abis/SubaccountRouter.json +648 -0
  75. package/build/src/abis/SyntheticsReader.json +4577 -0
  76. package/build/src/abis/SyntheticsRouter.json +77 -0
  77. package/build/src/abis/Timelock.json +1737 -0
  78. package/build/src/abis/Token.json +345 -0
  79. package/build/src/abis/Treasury.json +411 -0
  80. package/build/src/abis/UniPool.json +89 -0
  81. package/build/src/abis/UniswapV2.json +1 -0
  82. package/build/src/abis/Vault.json +3220 -0
  83. package/build/src/abis/VaultReader.json +87 -0
  84. package/build/src/abis/VaultV2.json +3019 -0
  85. package/build/src/abis/VaultV2b.json +3220 -0
  86. package/build/src/abis/Vester.json +1031 -0
  87. package/build/src/abis/WETH.json +320 -0
  88. package/build/src/abis/YieldFarm.json +599 -0
  89. package/build/src/abis/YieldToken.json +560 -0
  90. package/build/src/configs/batch.d.ts +6 -0
  91. package/build/src/configs/batch.js +51 -0
  92. package/build/src/configs/chains.d.ts +37 -0
  93. package/build/src/configs/chains.js +90 -0
  94. package/build/src/configs/contracts.d.ts +2 -0
  95. package/build/src/configs/contracts.js +218 -0
  96. package/build/src/configs/dataStore.d.ts +149 -0
  97. package/build/src/configs/dataStore.js +276 -0
  98. package/build/src/configs/factors.d.ts +20 -0
  99. package/build/src/configs/factors.js +21 -0
  100. package/build/src/configs/markets.d.ts +8 -0
  101. package/build/src/configs/markets.js +528 -0
  102. package/build/src/configs/subgraph.d.ts +3 -0
  103. package/build/src/configs/subgraph.js +3 -0
  104. package/build/src/configs/tokens.d.ts +89 -0
  105. package/build/src/configs/tokens.js +1269 -0
  106. package/build/src/index.d.ts +44 -0
  107. package/build/src/index.js +245 -0
  108. package/build/src/modules/accounts/accounts.d.ts +5 -0
  109. package/build/src/modules/accounts/accounts.js +36 -0
  110. package/build/src/modules/accounts/accounts.spec.d.ts +1 -0
  111. package/build/src/modules/accounts/accounts.spec.js +7 -0
  112. package/build/src/modules/base.d.ts +9 -0
  113. package/build/src/modules/base.js +15 -0
  114. package/build/src/modules/markets/index.d.ts +26 -0
  115. package/build/src/modules/markets/index.js +339 -0
  116. package/build/src/modules/markets/markets.spec.d.ts +1 -0
  117. package/build/src/modules/markets/markets.spec.js +38 -0
  118. package/build/src/modules/markets/query-builders.d.ts +40 -0
  119. package/build/src/modules/markets/query-builders.js +379 -0
  120. package/build/src/modules/markets/types.d.ts +42 -0
  121. package/build/src/modules/markets/types.js +1 -0
  122. package/build/src/modules/oracle.d.ts +31 -0
  123. package/build/src/modules/oracle.js +53 -0
  124. package/build/src/modules/orders/orders.d.ts +60 -0
  125. package/build/src/modules/orders/orders.js +270 -0
  126. package/build/src/modules/orders/orders.spec.d.ts +1 -0
  127. package/build/src/modules/orders/orders.spec.js +16 -0
  128. package/build/src/modules/orders/transactions/cancelOrdersTxn.d.ts +6 -0
  129. package/build/src/modules/orders/transactions/cancelOrdersTxn.js +15 -0
  130. package/build/src/modules/orders/transactions/createDecreaseOrderTxn.d.ts +32 -0
  131. package/build/src/modules/orders/transactions/createDecreaseOrderTxn.js +98 -0
  132. package/build/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +77 -0
  133. package/build/src/modules/orders/transactions/createIncreaseOrderTxn.js +164 -0
  134. package/build/src/modules/orders/transactions/createSwapOrderTxn.d.ts +16 -0
  135. package/build/src/modules/orders/transactions/createSwapOrderTxn.js +97 -0
  136. package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +6 -0
  137. package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.js +13 -0
  138. package/build/src/modules/orders/transactions/updateOrderTxn.d.ts +23 -0
  139. package/build/src/modules/orders/transactions/updateOrderTxn.js +44 -0
  140. package/build/src/modules/orders/utils.d.ts +248 -0
  141. package/build/src/modules/orders/utils.js +151 -0
  142. package/build/src/modules/positions/positions.d.ts +48 -0
  143. package/build/src/modules/positions/positions.js +563 -0
  144. package/build/src/modules/positions/positions.spec.d.ts +1 -0
  145. package/build/src/modules/positions/positions.spec.js +25 -0
  146. package/build/src/modules/tokens/tokens.d.ts +26 -0
  147. package/build/src/modules/tokens/tokens.js +132 -0
  148. package/build/src/modules/tokens/tokens.spec.d.ts +1 -0
  149. package/build/src/modules/tokens/tokens.spec.js +19 -0
  150. package/build/src/modules/trades/trades.d.ts +48 -0
  151. package/build/src/modules/trades/trades.js +390 -0
  152. package/build/src/modules/trades/trades.spec.d.ts +1 -0
  153. package/build/src/modules/trades/trades.spec.js +14 -0
  154. package/build/src/prebuilt/hashedMarketConfigKeys.json +3658 -0
  155. package/build/src/prebuilt/hashedMarketValuesKeys.json +1103 -0
  156. package/build/src/prebuilt/index.d.ts +14 -0
  157. package/build/src/prebuilt/index.js +9 -0
  158. package/build/src/types/amounts.d.ts +223 -0
  159. package/build/src/types/amounts.js +17 -0
  160. package/build/src/types/fees.d.ts +34 -0
  161. package/build/src/types/fees.js +1 -0
  162. package/build/src/types/markets.d.ts +143 -0
  163. package/build/src/types/markets.js +1 -0
  164. package/build/src/types/orders.d.ts +74 -0
  165. package/build/src/types/orders.js +33 -0
  166. package/build/src/types/positions.d.ts +53 -0
  167. package/build/src/types/positions.js +1 -0
  168. package/build/src/types/referrals.d.ts +124 -0
  169. package/build/src/types/referrals.js +9 -0
  170. package/build/src/types/sdk.d.ts +32 -0
  171. package/build/src/types/sdk.js +1 -0
  172. package/build/src/types/sidecarOrders.d.ts +54 -0
  173. package/build/src/types/sidecarOrders.js +1 -0
  174. package/build/src/types/syntheticsEvents.d.ts +88 -0
  175. package/build/src/types/syntheticsEvents.js +1 -0
  176. package/build/src/types/tokens.d.ts +89 -0
  177. package/build/src/types/tokens.js +1 -0
  178. package/build/src/types/trade.d.ts +223 -0
  179. package/build/src/types/trade.js +17 -0
  180. package/build/src/types/tradeHistory.d.ts +107 -0
  181. package/build/src/types/tradeHistory.js +8 -0
  182. package/build/src/utils/LruCache.d.ts +10 -0
  183. package/build/src/utils/LruCache.js +45 -0
  184. package/build/src/utils/bigmath.d.ts +7 -0
  185. package/build/src/utils/bigmath.js +23 -0
  186. package/build/src/utils/buildUrl.d.ts +1 -0
  187. package/build/src/utils/buildUrl.js +5 -0
  188. package/build/src/utils/callContract.d.ts +17 -0
  189. package/build/src/utils/callContract.js +133 -0
  190. package/build/src/utils/common.d.ts +2 -0
  191. package/build/src/utils/common.js +2 -0
  192. package/build/src/utils/fees/estimateOraclePriceCount.d.ts +6 -0
  193. package/build/src/utils/fees/estimateOraclePriceCount.js +19 -0
  194. package/build/src/utils/fees/executionFee.d.ts +59 -0
  195. package/build/src/utils/fees/executionFee.js +108 -0
  196. package/build/src/utils/fees/index.d.ts +29 -0
  197. package/build/src/utils/fees/index.js +89 -0
  198. package/build/src/utils/fees/priceImpact.d.ts +75 -0
  199. package/build/src/utils/fees/priceImpact.js +287 -0
  200. package/build/src/utils/graphqlFetcher.d.ts +1 -0
  201. package/build/src/utils/graphqlFetcher.js +18 -0
  202. package/build/src/utils/hash.d.ts +5 -0
  203. package/build/src/utils/hash.js +35 -0
  204. package/build/src/utils/marketKeysAndConfigs.d.ts +66 -0
  205. package/build/src/utils/marketKeysAndConfigs.js +257 -0
  206. package/build/src/utils/markets.d.ts +40 -0
  207. package/build/src/utils/markets.js +129 -0
  208. package/build/src/utils/multicall.d.ts +64 -0
  209. package/build/src/utils/multicall.js +116 -0
  210. package/build/src/utils/numbers.d.ts +9 -0
  211. package/build/src/utils/numbers.js +30 -0
  212. package/build/src/utils/objects.d.ts +18 -0
  213. package/build/src/utils/objects.js +30 -0
  214. package/build/src/utils/orders.d.ts +28 -0
  215. package/build/src/utils/orders.js +178 -0
  216. package/build/src/utils/positions.d.ts +60 -0
  217. package/build/src/utils/positions.js +133 -0
  218. package/build/src/utils/prices.d.ts +15 -0
  219. package/build/src/utils/prices.js +34 -0
  220. package/build/src/utils/referrals.d.ts +2 -0
  221. package/build/src/utils/referrals.js +27 -0
  222. package/build/src/utils/simulateExecuteOrder.d.ts +16 -0
  223. package/build/src/utils/simulateExecuteOrder.js +143 -0
  224. package/build/src/utils/slidingWindowFallbackSwitcher.d.ts +24 -0
  225. package/build/src/utils/slidingWindowFallbackSwitcher.js +40 -0
  226. package/build/src/utils/subgraph.d.ts +21 -0
  227. package/build/src/utils/subgraph.js +72 -0
  228. package/build/src/utils/swapStats.d.ts +35 -0
  229. package/build/src/utils/swapStats.js +197 -0
  230. package/build/src/utils/test.d.ts +2 -0
  231. package/build/src/utils/test.js +24 -0
  232. package/build/src/utils/tokens.d.ts +18 -0
  233. package/build/src/utils/tokens.js +64 -0
  234. package/build/src/utils/trade.d.ts +10 -0
  235. package/build/src/utils/trade.js +32 -0
  236. package/build/tsconfig.tsbuildinfo +1 -0
  237. package/package.json +96 -0
@@ -0,0 +1,14 @@
1
+ import { MarketConfigMulticallRequestConfig, MarketValuesMulticallRequestConfig } from "modules/markets/types";
2
+ type HashedMarketValuesKeys = Omit<Record<keyof MarketValuesMulticallRequestConfig[`${string}-dataStore`]["calls"], string>, "claimableFundingAmountLong" | "claimableFundingAmountShort">;
3
+ declare const HASHED_MARKET_VALUES_KEYS: {
4
+ [chainId: number]: {
5
+ [marketToken: string]: HashedMarketValuesKeys;
6
+ };
7
+ };
8
+ type HashedMarketConfigKeys = Record<keyof MarketConfigMulticallRequestConfig[`${string}-dataStore`]["calls"], string>;
9
+ declare const HASHED_MARKET_CONFIG_KEYS: {
10
+ [chainId: number]: {
11
+ [marketToken: string]: HashedMarketConfigKeys;
12
+ };
13
+ };
14
+ export { HASHED_MARKET_VALUES_KEYS, HASHED_MARKET_CONFIG_KEYS };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Json files in this directory are prebuild by scripts from the `scripts/prebuild` directory.
3
+ * No need to edit them manually, use `yarn run prebuild` command instead.
4
+ */
5
+ import hashedMarketValuesKeysJson from "./hashedMarketValuesKeys.json";
6
+ import hashedMarketConfigKeysJson from "./hashedMarketConfigKeys.json";
7
+ const HASHED_MARKET_VALUES_KEYS = hashedMarketValuesKeysJson;
8
+ const HASHED_MARKET_CONFIG_KEYS = hashedMarketConfigKeysJson;
9
+ export { HASHED_MARKET_VALUES_KEYS, HASHED_MARKET_CONFIG_KEYS };
@@ -0,0 +1,223 @@
1
+ import { FeeItem, SwapFeeItem } from "./fees";
2
+ import { MarketInfo } from "./markets";
3
+ import { DecreasePositionSwapType, OrderType } from "./orders";
4
+ export declare enum TradeType {
5
+ Long = "Long",
6
+ Short = "Short",
7
+ Swap = "Swap"
8
+ }
9
+ export declare enum TradeMode {
10
+ Market = "Market",
11
+ Limit = "Limit",
12
+ Trigger = "Trigger"
13
+ }
14
+ export declare enum TriggerThresholdType {
15
+ Above = ">",
16
+ Below = "<"
17
+ }
18
+ export type TradeFlags = {
19
+ isLong: boolean;
20
+ isShort: boolean;
21
+ isSwap: boolean;
22
+ /**
23
+ * ```ts
24
+ * isLong || isShort
25
+ * ```
26
+ */
27
+ isPosition: boolean;
28
+ isIncrease: boolean;
29
+ isTrigger: boolean;
30
+ isMarket: boolean;
31
+ isLimit: boolean;
32
+ };
33
+ export type SwapAmounts = {
34
+ amountIn: bigint;
35
+ usdIn: bigint;
36
+ amountOut: bigint;
37
+ usdOut: bigint;
38
+ priceIn: bigint;
39
+ priceOut: bigint;
40
+ swapPathStats: SwapPathStats | undefined;
41
+ minOutputAmount: bigint;
42
+ uiFeeUsd?: bigint;
43
+ };
44
+ export type IncreasePositionAmounts = {
45
+ initialCollateralAmount: bigint;
46
+ initialCollateralUsd: bigint;
47
+ collateralDeltaAmount: bigint;
48
+ collateralDeltaUsd: bigint;
49
+ swapPathStats: SwapPathStats | undefined;
50
+ indexTokenAmount: bigint;
51
+ sizeDeltaUsd: bigint;
52
+ sizeDeltaInTokens: bigint;
53
+ estimatedLeverage?: bigint;
54
+ indexPrice: bigint;
55
+ initialCollateralPrice: bigint;
56
+ collateralPrice: bigint;
57
+ triggerPrice?: bigint;
58
+ triggerThresholdType?: TriggerThresholdType;
59
+ acceptablePrice: bigint;
60
+ acceptablePriceDeltaBps: bigint;
61
+ positionFeeUsd: bigint;
62
+ uiFeeUsd: bigint;
63
+ swapUiFeeUsd: bigint;
64
+ feeDiscountUsd: bigint;
65
+ borrowingFeeUsd: bigint;
66
+ fundingFeeUsd: bigint;
67
+ positionPriceImpactDeltaUsd: bigint;
68
+ };
69
+ export type DecreasePositionAmounts = {
70
+ isFullClose: boolean;
71
+ sizeDeltaUsd: bigint;
72
+ sizeDeltaInTokens: bigint;
73
+ collateralDeltaUsd: bigint;
74
+ collateralDeltaAmount: bigint;
75
+ indexPrice: bigint;
76
+ collateralPrice: bigint;
77
+ triggerPrice?: bigint;
78
+ acceptablePrice: bigint;
79
+ acceptablePriceDeltaBps: bigint;
80
+ recommendedAcceptablePriceDeltaBps: bigint;
81
+ estimatedPnl: bigint;
82
+ estimatedPnlPercentage: bigint;
83
+ realizedPnl: bigint;
84
+ realizedPnlPercentage: bigint;
85
+ positionFeeUsd: bigint;
86
+ uiFeeUsd: bigint;
87
+ swapUiFeeUsd: bigint;
88
+ feeDiscountUsd: bigint;
89
+ borrowingFeeUsd: bigint;
90
+ fundingFeeUsd: bigint;
91
+ swapProfitFeeUsd: bigint;
92
+ positionPriceImpactDeltaUsd: bigint;
93
+ priceImpactDiffUsd: bigint;
94
+ payedRemainingCollateralAmount: bigint;
95
+ payedOutputUsd: bigint;
96
+ payedRemainingCollateralUsd: bigint;
97
+ receiveTokenAmount: bigint;
98
+ receiveUsd: bigint;
99
+ triggerOrderType?: OrderType.LimitDecrease | OrderType.StopLossDecrease;
100
+ triggerThresholdType?: TriggerThresholdType;
101
+ decreaseSwapType: DecreasePositionSwapType;
102
+ };
103
+ export type DepositAmounts = {
104
+ marketTokenAmount: bigint;
105
+ marketTokenUsd: bigint;
106
+ longTokenAmount: bigint;
107
+ longTokenUsd: bigint;
108
+ glvTokenAmount: bigint;
109
+ glvTokenUsd: bigint;
110
+ shortTokenAmount: bigint;
111
+ shortTokenUsd: bigint;
112
+ swapFeeUsd: bigint;
113
+ uiFeeUsd: bigint;
114
+ swapPriceImpactDeltaUsd: bigint;
115
+ };
116
+ export type WithdrawalAmounts = {
117
+ marketTokenAmount: bigint;
118
+ marketTokenUsd: bigint;
119
+ longTokenAmount: bigint;
120
+ shortTokenAmount: bigint;
121
+ longTokenUsd: bigint;
122
+ shortTokenUsd: bigint;
123
+ glvTokenAmount: bigint;
124
+ glvTokenUsd: bigint;
125
+ swapFeeUsd: bigint;
126
+ uiFeeUsd: bigint;
127
+ swapPriceImpactDeltaUsd: bigint;
128
+ };
129
+ export type NextPositionValues = {
130
+ nextLeverage?: bigint;
131
+ nextLiqPrice?: bigint;
132
+ nextCollateralUsd?: bigint;
133
+ nextSizeUsd?: bigint;
134
+ nextPnl?: bigint;
135
+ nextPnlPercentage?: bigint;
136
+ nextEntryPrice?: bigint;
137
+ remainingCollateralFeesUsd?: bigint;
138
+ };
139
+ export type SwapStats = {
140
+ marketAddress: string;
141
+ tokenInAddress: string;
142
+ tokenOutAddress: string;
143
+ isWrap: boolean;
144
+ isUnwrap: boolean;
145
+ isOutLiquidity?: boolean;
146
+ swapFeeAmount: bigint;
147
+ swapFeeUsd: bigint;
148
+ priceImpactDeltaUsd: bigint;
149
+ amountIn: bigint;
150
+ amountInAfterFees: bigint;
151
+ usdIn: bigint;
152
+ amountOut: bigint;
153
+ usdOut: bigint;
154
+ };
155
+ export type SwapPathStats = {
156
+ swapPath: string[];
157
+ swapSteps: SwapStats[];
158
+ targetMarketAddress?: string;
159
+ totalSwapPriceImpactDeltaUsd: bigint;
160
+ totalSwapFeeUsd: bigint;
161
+ totalFeesDeltaUsd: bigint;
162
+ tokenInAddress: string;
163
+ tokenOutAddress: string;
164
+ usdOut: bigint;
165
+ amountOut: bigint;
166
+ };
167
+ export type MarketEdge = {
168
+ marketAddress: string;
169
+ marketInfo: MarketInfo;
170
+ from: string;
171
+ to: string;
172
+ };
173
+ export type SwapRoute = {
174
+ edged: MarketEdge[];
175
+ path: string[];
176
+ liquidity: bigint;
177
+ };
178
+ export type MarketsGraph = {
179
+ abjacencyList: {
180
+ [token: string]: MarketEdge[];
181
+ };
182
+ edges: MarketEdge[];
183
+ };
184
+ export type SwapEstimator = (e: MarketEdge, usdIn: bigint) => {
185
+ usdOut: bigint;
186
+ };
187
+ export type FindSwapPath = (usdIn: bigint, opts: {
188
+ byLiquidity?: boolean;
189
+ }) => SwapPathStats | undefined;
190
+ export type TradeFeesType = "swap" | "increase" | "decrease" | "edit";
191
+ export type TradeFees = {
192
+ totalFees?: FeeItem;
193
+ payTotalFees?: FeeItem;
194
+ swapFees?: SwapFeeItem[];
195
+ positionFee?: FeeItem;
196
+ swapPriceImpact?: FeeItem;
197
+ positionPriceImpact?: FeeItem;
198
+ priceImpactDiff?: FeeItem;
199
+ positionCollateralPriceImpact?: FeeItem;
200
+ collateralPriceImpactDiff?: FeeItem;
201
+ positionFeeFactor?: bigint;
202
+ borrowFee?: FeeItem;
203
+ fundingFee?: FeeItem;
204
+ uiFee?: FeeItem;
205
+ uiSwapFee?: FeeItem;
206
+ feeDiscountUsd?: bigint;
207
+ swapProfitFee?: FeeItem;
208
+ };
209
+ export type GmSwapFees = {
210
+ totalFees?: FeeItem;
211
+ swapFee?: FeeItem;
212
+ swapPriceImpact?: FeeItem;
213
+ uiFee?: FeeItem;
214
+ shiftFee?: FeeItem;
215
+ };
216
+ export type TradeSearchParams = {
217
+ from?: string;
218
+ to?: string;
219
+ mode?: string;
220
+ pool?: string;
221
+ collateral?: string;
222
+ market?: string;
223
+ };
@@ -0,0 +1,17 @@
1
+ export var TradeType;
2
+ (function (TradeType) {
3
+ TradeType["Long"] = "Long";
4
+ TradeType["Short"] = "Short";
5
+ TradeType["Swap"] = "Swap";
6
+ })(TradeType || (TradeType = {}));
7
+ export var TradeMode;
8
+ (function (TradeMode) {
9
+ TradeMode["Market"] = "Market";
10
+ TradeMode["Limit"] = "Limit";
11
+ TradeMode["Trigger"] = "Trigger";
12
+ })(TradeMode || (TradeMode = {}));
13
+ export var TriggerThresholdType;
14
+ (function (TriggerThresholdType) {
15
+ TriggerThresholdType["Above"] = ">";
16
+ TriggerThresholdType["Below"] = "<";
17
+ })(TriggerThresholdType || (TriggerThresholdType = {}));
@@ -0,0 +1,34 @@
1
+ import { Token } from "types/tokens";
2
+ export type ExecutionFee = {
3
+ feeUsd: bigint;
4
+ feeTokenAmount: bigint;
5
+ feeToken: Token;
6
+ warning?: string;
7
+ isFeeHigh: boolean;
8
+ isFeeVeryHigh: boolean;
9
+ };
10
+ export type FeeItem = {
11
+ deltaUsd: bigint;
12
+ bps: bigint;
13
+ };
14
+ export type SwapFeeItem = FeeItem & {
15
+ marketAddress: string;
16
+ tokenInAddress: string;
17
+ tokenOutAddress: string;
18
+ };
19
+ export type GasLimitsConfig = {
20
+ depositSingleToken: bigint;
21
+ depositMultiToken: bigint;
22
+ withdrawalMultiToken: bigint;
23
+ shift: bigint;
24
+ singleSwap: bigint;
25
+ swapOrder: bigint;
26
+ increaseOrder: bigint;
27
+ decreaseOrder: bigint;
28
+ estimatedGasFeeBaseAmount: bigint;
29
+ estimatedGasFeePerOraclePrice: bigint;
30
+ estimatedFeeMultiplierFactor: bigint;
31
+ glvDepositGasLimit: bigint;
32
+ glvWithdrawalGasLimit: bigint;
33
+ glvPerMarketGasLimit: bigint;
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,143 @@
1
+ import { TokenData } from "./tokens";
2
+ export type PnlFactorType = "FOR_DEPOSITS" | "FOR_WITHDRAWALS" | "FOR_TRADERS";
3
+ export type Market = {
4
+ marketTokenAddress: string;
5
+ indexTokenAddress: string;
6
+ longTokenAddress: string;
7
+ shortTokenAddress: string;
8
+ isSameCollaterals: boolean;
9
+ isSpotOnly: boolean;
10
+ name: string;
11
+ data: string;
12
+ };
13
+ export type MarketPoolTokens = {
14
+ longToken: TokenData;
15
+ shortToken: TokenData;
16
+ indexToken: TokenData;
17
+ };
18
+ export type MarketInfo = Market & MarketPoolTokens & {
19
+ isDisabled: boolean;
20
+ longPoolAmount: bigint;
21
+ shortPoolAmount: bigint;
22
+ maxLongPoolAmount: bigint;
23
+ maxShortPoolAmount: bigint;
24
+ maxLongPoolUsdForDeposit: bigint;
25
+ maxShortPoolUsdForDeposit: bigint;
26
+ longPoolAmountAdjustment: bigint;
27
+ shortPoolAmountAdjustment: bigint;
28
+ poolValueMax: bigint;
29
+ poolValueMin: bigint;
30
+ pnlLongMin: bigint;
31
+ pnlLongMax: bigint;
32
+ pnlShortMin: bigint;
33
+ pnlShortMax: bigint;
34
+ netPnlMin: bigint;
35
+ netPnlMax: bigint;
36
+ reserveFactorLong: bigint;
37
+ reserveFactorShort: bigint;
38
+ openInterestReserveFactorLong: bigint;
39
+ openInterestReserveFactorShort: bigint;
40
+ maxOpenInterestLong: bigint;
41
+ maxOpenInterestShort: bigint;
42
+ borrowingFactorLong: bigint;
43
+ borrowingFactorShort: bigint;
44
+ borrowingExponentFactorLong: bigint;
45
+ borrowingExponentFactorShort: bigint;
46
+ fundingFactor: bigint;
47
+ fundingExponentFactor: bigint;
48
+ fundingIncreaseFactorPerSecond: bigint;
49
+ fundingDecreaseFactorPerSecond: bigint;
50
+ thresholdForStableFunding: bigint;
51
+ thresholdForDecreaseFunding: bigint;
52
+ minFundingFactorPerSecond: bigint;
53
+ maxFundingFactorPerSecond: bigint;
54
+ totalBorrowingFees: bigint;
55
+ positionImpactPoolAmount: bigint;
56
+ minPositionImpactPoolAmount: bigint;
57
+ positionImpactPoolDistributionRate: bigint;
58
+ minCollateralFactor: bigint;
59
+ minCollateralFactorForOpenInterestLong: bigint;
60
+ minCollateralFactorForOpenInterestShort: bigint;
61
+ swapImpactPoolAmountLong: bigint;
62
+ swapImpactPoolAmountShort: bigint;
63
+ maxPnlFactorForTradersLong: bigint;
64
+ maxPnlFactorForTradersShort: bigint;
65
+ claimableFundingAmountLong?: bigint;
66
+ claimableFundingAmountShort?: bigint;
67
+ longInterestUsd: bigint;
68
+ shortInterestUsd: bigint;
69
+ longInterestInTokens: bigint;
70
+ shortInterestInTokens: bigint;
71
+ positionFeeFactorForPositiveImpact: bigint;
72
+ positionFeeFactorForNegativeImpact: bigint;
73
+ positionImpactFactorPositive: bigint;
74
+ positionImpactFactorNegative: bigint;
75
+ maxPositionImpactFactorPositive: bigint;
76
+ maxPositionImpactFactorNegative: bigint;
77
+ maxPositionImpactFactorForLiquidations: bigint;
78
+ positionImpactExponentFactor: bigint;
79
+ swapFeeFactorForPositiveImpact: bigint;
80
+ swapFeeFactorForNegativeImpact: bigint;
81
+ swapImpactFactorPositive: bigint;
82
+ swapImpactFactorNegative: bigint;
83
+ swapImpactExponentFactor: bigint;
84
+ borrowingFactorPerSecondForLongs: bigint;
85
+ borrowingFactorPerSecondForShorts: bigint;
86
+ fundingFactorPerSecond: bigint;
87
+ longsPayShorts: boolean;
88
+ virtualPoolAmountForLongToken: bigint;
89
+ virtualPoolAmountForShortToken: bigint;
90
+ virtualInventoryForPositions: bigint;
91
+ virtualMarketId: string;
92
+ virtualLongTokenId: string;
93
+ virtualShortTokenId: string;
94
+ };
95
+ export type FastMarketInfo = Omit<MarketInfo, keyof MarketPoolTokens | keyof Market> & {
96
+ marketTokenAddress: string;
97
+ longTokenAddress: string;
98
+ shortTokenAddress: string;
99
+ indexTokenAddress: string;
100
+ };
101
+ export type ClaimableFunding = {
102
+ claimableFundingAmountLong: bigint;
103
+ claimableFundingAmountShort: bigint;
104
+ };
105
+ export type ClaimableFundingData = {
106
+ [marketAddress: string]: ClaimableFunding;
107
+ };
108
+ export type MarketsData = {
109
+ [marketTokenAddress: string]: Market;
110
+ };
111
+ export type MarketsInfoData = {
112
+ [marketAddress: string]: MarketInfo;
113
+ };
114
+ export type MarketTokensAPRData = {
115
+ [marketTokenAddress: string]: bigint;
116
+ };
117
+ export type UserEarningsData = {
118
+ byMarketAddress: {
119
+ [marketTokenAddress: string]: {
120
+ total: bigint;
121
+ recent: bigint;
122
+ };
123
+ };
124
+ allMarkets: {
125
+ total: bigint;
126
+ recent: bigint;
127
+ expected365d: bigint;
128
+ };
129
+ };
130
+ export type ContractMarketPrices = {
131
+ indexTokenPrice: {
132
+ min: bigint;
133
+ max: bigint;
134
+ };
135
+ longTokenPrice: {
136
+ min: bigint;
137
+ max: bigint;
138
+ };
139
+ shortTokenPrice: {
140
+ min: bigint;
141
+ max: bigint;
142
+ };
143
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import { Address } from "viem";
2
+ import { MarketInfo } from "./markets";
3
+ import { TokenData, TokensRatio } from "./tokens";
4
+ import { SwapPathStats, TriggerThresholdType } from "./trade";
5
+ export declare enum OrderType {
6
+ MarketSwap = 0,
7
+ LimitSwap = 1,
8
+ MarketIncrease = 2,
9
+ LimitIncrease = 3,
10
+ MarketDecrease = 4,
11
+ LimitDecrease = 5,
12
+ StopLossDecrease = 6,
13
+ Liquidation = 7
14
+ }
15
+ export declare enum SwapPricingType {
16
+ TwoStep = 0,
17
+ Shift = 1,
18
+ Atomic = 2
19
+ }
20
+ export declare enum DecreasePositionSwapType {
21
+ NoSwap = 0,
22
+ SwapPnlTokenToCollateralToken = 1,
23
+ SwapCollateralTokenToPnlToken = 2
24
+ }
25
+ export type Order = {
26
+ key: string;
27
+ account: string;
28
+ callbackContract: string;
29
+ initialCollateralTokenAddress: Address;
30
+ marketAddress: string;
31
+ decreasePositionSwapType: DecreasePositionSwapType;
32
+ receiver: string;
33
+ swapPath: string[];
34
+ contractAcceptablePrice: bigint;
35
+ contractTriggerPrice: bigint;
36
+ callbackGasLimit: bigint;
37
+ executionFee: bigint;
38
+ initialCollateralDeltaAmount: bigint;
39
+ minOutputAmount: bigint;
40
+ sizeDeltaUsd: bigint;
41
+ updatedAtBlock: bigint;
42
+ isFrozen: boolean;
43
+ isLong: boolean;
44
+ orderType: OrderType;
45
+ shouldUnwrapNativeToken: boolean;
46
+ data: string;
47
+ autoCancel: boolean;
48
+ };
49
+ export type SwapOrderInfo = Order & {
50
+ title: string;
51
+ swapPathStats?: SwapPathStats;
52
+ triggerRatio?: TokensRatio;
53
+ initialCollateralToken: TokenData;
54
+ targetCollateralToken: TokenData;
55
+ };
56
+ export type PositionOrderInfo = Order & {
57
+ title: string;
58
+ marketInfo: MarketInfo;
59
+ swapPathStats?: SwapPathStats;
60
+ indexToken: TokenData;
61
+ initialCollateralToken: TokenData;
62
+ targetCollateralToken: TokenData;
63
+ acceptablePrice: bigint;
64
+ triggerPrice: bigint;
65
+ triggerThresholdType: TriggerThresholdType;
66
+ };
67
+ export type OrderInfo = SwapOrderInfo | PositionOrderInfo;
68
+ export type OrdersData = {
69
+ [orderKey: string]: Order;
70
+ };
71
+ export type OrdersInfoData = {
72
+ [orderKey: string]: OrderInfo;
73
+ };
74
+ export type OrderTxnType = "create" | "update" | "cancel";
@@ -0,0 +1,33 @@
1
+ export var OrderType;
2
+ (function (OrderType) {
3
+ // the order will be cancelled if the minOutputAmount cannot be fulfilled
4
+ OrderType[OrderType["MarketSwap"] = 0] = "MarketSwap";
5
+ // @dev LimitSwap: swap token A to token B if the minOutputAmount can be fulfilled
6
+ OrderType[OrderType["LimitSwap"] = 1] = "LimitSwap";
7
+ // @dev MarketIncrease: increase position at the current market price
8
+ // the order will be cancelled if the position cannot be increased at the acceptablePrice
9
+ OrderType[OrderType["MarketIncrease"] = 2] = "MarketIncrease";
10
+ // @dev LimitIncrease: increase position if the triggerPrice is reached and the acceptablePrice can be fulfilled
11
+ OrderType[OrderType["LimitIncrease"] = 3] = "LimitIncrease";
12
+ // @dev MarketDecrease: decrease position at the curent market price
13
+ // the order will be cancelled if the position cannot be decreased at the acceptablePrice
14
+ OrderType[OrderType["MarketDecrease"] = 4] = "MarketDecrease";
15
+ // @dev LimitDecrease: decrease position if the triggerPrice is reached and the acceptablePrice can be fulfilled
16
+ OrderType[OrderType["LimitDecrease"] = 5] = "LimitDecrease";
17
+ // @dev StopLossDecrease: decrease position if the triggerPrice is reached and the acceptablePrice can be fulfilled
18
+ OrderType[OrderType["StopLossDecrease"] = 6] = "StopLossDecrease";
19
+ // @dev Liquidation: allows liquidation of positions if the criteria for liquidation are met
20
+ OrderType[OrderType["Liquidation"] = 7] = "Liquidation";
21
+ })(OrderType || (OrderType = {}));
22
+ export var SwapPricingType;
23
+ (function (SwapPricingType) {
24
+ SwapPricingType[SwapPricingType["TwoStep"] = 0] = "TwoStep";
25
+ SwapPricingType[SwapPricingType["Shift"] = 1] = "Shift";
26
+ SwapPricingType[SwapPricingType["Atomic"] = 2] = "Atomic";
27
+ })(SwapPricingType || (SwapPricingType = {}));
28
+ export var DecreasePositionSwapType;
29
+ (function (DecreasePositionSwapType) {
30
+ DecreasePositionSwapType[DecreasePositionSwapType["NoSwap"] = 0] = "NoSwap";
31
+ DecreasePositionSwapType[DecreasePositionSwapType["SwapPnlTokenToCollateralToken"] = 1] = "SwapPnlTokenToCollateralToken";
32
+ DecreasePositionSwapType[DecreasePositionSwapType["SwapCollateralTokenToPnlToken"] = 2] = "SwapCollateralTokenToPnlToken";
33
+ })(DecreasePositionSwapType || (DecreasePositionSwapType = {}));
@@ -0,0 +1,53 @@
1
+ import { MarketInfo } from "./markets";
2
+ import { PendingPositionUpdate } from "./syntheticsEvents";
3
+ import { TokenData } from "./tokens";
4
+ export type Position = {
5
+ key: string;
6
+ contractKey: string;
7
+ account: string;
8
+ marketAddress: string;
9
+ collateralTokenAddress: string;
10
+ sizeInUsd: bigint;
11
+ sizeInTokens: bigint;
12
+ collateralAmount: bigint;
13
+ pendingBorrowingFeesUsd: bigint;
14
+ increasedAtBlock: bigint;
15
+ decreasedAtBlock: bigint;
16
+ isLong: boolean;
17
+ fundingFeeAmount: bigint;
18
+ claimableLongTokenAmount: bigint;
19
+ claimableShortTokenAmount: bigint;
20
+ isOpening?: boolean;
21
+ pendingUpdate?: PendingPositionUpdate;
22
+ data: string;
23
+ };
24
+ export type PositionInfo = Position & {
25
+ marketInfo: MarketInfo;
26
+ indexToken: TokenData;
27
+ collateralToken: TokenData;
28
+ pnlToken: TokenData;
29
+ markPrice: bigint;
30
+ entryPrice: bigint | undefined;
31
+ liquidationPrice: bigint | undefined;
32
+ collateralUsd: bigint;
33
+ remainingCollateralUsd: bigint;
34
+ remainingCollateralAmount: bigint;
35
+ hasLowCollateral: boolean;
36
+ pnl: bigint;
37
+ pnlPercentage: bigint;
38
+ pnlAfterFees: bigint;
39
+ pnlAfterFeesPercentage: bigint;
40
+ leverage: bigint | undefined;
41
+ leverageWithPnl: bigint | undefined;
42
+ netValue: bigint;
43
+ closingFeeUsd: bigint;
44
+ uiFeeUsd: bigint;
45
+ pendingFundingFeesUsd: bigint;
46
+ pendingClaimableFundingFeesUsd: bigint;
47
+ };
48
+ export type PositionsData = {
49
+ [positionKey: string]: Position;
50
+ };
51
+ export type PositionsInfoData = {
52
+ [positionKey: string]: PositionInfo;
53
+ };
@@ -0,0 +1 @@
1
+ export {};