@gmx-io/sdk 0.1.1 → 0.1.2

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 (77) hide show
  1. package/build/src/configs/chains.d.ts +3 -0
  2. package/build/src/configs/chains.js +6 -0
  3. package/build/src/configs/contracts.d.ts +220 -1
  4. package/build/src/configs/contracts.js +67 -8
  5. package/build/src/configs/markets.js +14 -0
  6. package/build/src/configs/tokens.js +40 -5
  7. package/build/src/modules/markets/index.js +1 -7
  8. package/build/src/modules/markets/query-builders.d.ts +1 -1
  9. package/build/src/modules/markets/types.d.ts +4 -1
  10. package/build/src/modules/orders/utils.js +1 -1
  11. package/build/src/modules/positions/positions.js +17 -4
  12. package/build/src/modules/utils/utils.d.ts +1 -1
  13. package/build/src/modules/utils/utils.js +1 -1
  14. package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -0
  15. package/build/src/prebuilt/hashedMarketConfigKeys.json +100 -0
  16. package/build/src/prebuilt/hashedMarketValuesKeys.json +30 -0
  17. package/build/src/types/common.d.ts +1 -0
  18. package/build/src/types/fees.d.ts +2 -1
  19. package/build/src/types/markets.d.ts +7 -19
  20. package/build/src/types/orders.d.ts +3 -5
  21. package/build/src/types/positions.d.ts +11 -4
  22. package/build/src/types/trade.d.ts +1 -0
  23. package/build/src/types/tradeHistory.d.ts +4 -1
  24. package/build/src/utils/__tests__/LruCache.spec.d.ts +1 -0
  25. package/build/src/utils/__tests__/LruCache.spec.js +42 -0
  26. package/build/src/utils/__tests__/bigmath.spec.d.ts +1 -0
  27. package/build/src/utils/__tests__/bigmath.spec.js +37 -0
  28. package/build/src/utils/__tests__/hash.spec.d.ts +1 -0
  29. package/build/src/utils/__tests__/hash.spec.js +40 -0
  30. package/build/src/utils/__tests__/markets.spec.d.ts +1 -0
  31. package/build/src/utils/__tests__/markets.spec.js +264 -0
  32. package/build/src/utils/__tests__/numbers.spec.d.ts +1 -0
  33. package/build/src/utils/__tests__/numbers.spec.js +56 -0
  34. package/build/src/utils/__tests__/objects.spec.d.ts +1 -0
  35. package/build/src/utils/__tests__/objects.spec.js +58 -0
  36. package/build/src/utils/__tests__/positions.spec.d.ts +1 -0
  37. package/build/src/utils/__tests__/positions.spec.js +177 -0
  38. package/build/src/utils/__tests__/prices.spec.d.ts +1 -0
  39. package/build/src/utils/__tests__/prices.spec.js +58 -0
  40. package/build/src/utils/__tests__/referrals.spec.d.ts +1 -0
  41. package/build/src/utils/__tests__/referrals.spec.js +17 -0
  42. package/build/src/utils/__tests__/subgraph.spec.d.ts +1 -0
  43. package/build/src/utils/__tests__/subgraph.spec.js +162 -0
  44. package/build/src/utils/__tests__/tokens.spec.d.ts +1 -0
  45. package/build/src/utils/__tests__/tokens.spec.js +82 -0
  46. package/build/src/utils/__tests__/trade.spec.d.ts +1 -0
  47. package/build/src/utils/__tests__/trade.spec.js +35 -0
  48. package/build/src/utils/bigmath.d.ts +1 -1
  49. package/build/src/utils/bigmath.js +6 -1
  50. package/build/src/utils/callContract.js +5 -1
  51. package/build/src/utils/contracts.d.ts +4 -0
  52. package/build/src/utils/contracts.js +2 -0
  53. package/build/src/utils/fees/executionFee.d.ts +1 -33
  54. package/build/src/utils/fees/executionFee.js +2 -48
  55. package/build/src/utils/fees/executionFee.spec.d.ts +1 -0
  56. package/build/src/utils/fees/executionFee.spec.js +64 -0
  57. package/build/src/utils/fees/index.d.ts +2 -0
  58. package/build/src/utils/fees/index.js +5 -0
  59. package/build/src/utils/markets.d.ts +9 -2
  60. package/build/src/utils/markets.js +33 -10
  61. package/build/src/utils/orders.js +0 -8
  62. package/build/src/utils/positions.js +3 -3
  63. package/build/src/utils/prices.d.ts +1 -6
  64. package/build/src/utils/prices.js +0 -9
  65. package/build/src/utils/referrals.d.ts +2 -0
  66. package/build/src/utils/referrals.js +17 -15
  67. package/build/src/utils/swapStats.d.ts +1 -0
  68. package/build/src/utils/swapStats.js +12 -1
  69. package/build/src/utils/testUtil.d.ts +5 -5
  70. package/build/src/utils/tokens.d.ts +4 -0
  71. package/build/src/utils/tokens.js +4 -0
  72. package/build/tsconfig.tsbuildinfo +1 -1
  73. package/package.json +1 -1
  74. package/build/src/types/amounts.d.ts +0 -223
  75. package/build/src/types/amounts.js +0 -17
  76. package/build/src/types/syntheticsEvents.d.ts +0 -88
  77. /package/build/src/types/{syntheticsEvents.js → common.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmx-io/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "build/src/index.js",
6
6
  "exports": {
@@ -1,223 +0,0 @@
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
- edges: 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
- };
@@ -1,17 +0,0 @@
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 = {}));
@@ -1,88 +0,0 @@
1
- import { OrderType } from "./orders";
2
- export type MultiTransactionStatus<TEventData> = {
3
- key: string;
4
- data?: TEventData;
5
- createdTxnHash?: string;
6
- cancelledTxnHash?: string;
7
- updatedTxnHash?: string;
8
- executedTxnHash?: string;
9
- createdAt: number;
10
- isViewed?: boolean;
11
- };
12
- export type PositionIncreaseEvent = {
13
- positionKey: string;
14
- contractPositionKey: string;
15
- account: string;
16
- marketAddress: string;
17
- collateralTokenAddress: string;
18
- sizeInUsd: bigint;
19
- sizeInTokens: bigint;
20
- collateralAmount: bigint;
21
- borrowingFactor: bigint;
22
- executionPrice: bigint;
23
- sizeDeltaUsd: bigint;
24
- sizeDeltaInTokens: bigint;
25
- longTokenFundingAmountPerSize: bigint;
26
- shortTokenFundingAmountPerSize: bigint;
27
- collateralDeltaAmount: bigint;
28
- isLong: boolean;
29
- orderType: OrderType;
30
- orderKey: string;
31
- increasedAtTime: bigint;
32
- };
33
- export type PositionDecreaseEvent = {
34
- positionKey: string;
35
- contractPositionKey: string;
36
- account: string;
37
- marketAddress: string;
38
- collateralTokenAddress: string;
39
- sizeInUsd: bigint;
40
- sizeInTokens: bigint;
41
- sizeDeltaUsd: bigint;
42
- sizeDeltaInTokens: bigint;
43
- collateralAmount: bigint;
44
- collateralDeltaAmount: bigint;
45
- borrowingFactor: bigint;
46
- longTokenFundingAmountPerSize: bigint;
47
- shortTokenFundingAmountPerSize: bigint;
48
- pnlUsd: bigint;
49
- isLong: boolean;
50
- orderType: OrderType;
51
- orderKey: string;
52
- decreasedAtTime: bigint;
53
- };
54
- export type PendingPositionUpdate = {
55
- isIncrease: boolean;
56
- positionKey: string;
57
- sizeDeltaUsd: bigint;
58
- sizeDeltaInTokens: bigint;
59
- collateralDeltaAmount: bigint;
60
- updatedAt: number;
61
- updatedAtTime: bigint;
62
- };
63
- export type PendingPositionsUpdates = {
64
- [key: string]: PendingPositionUpdate | undefined;
65
- };
66
- export type EventLogItems<T> = {
67
- [key: string]: T;
68
- };
69
- export type EventLogArrayItems<T> = {
70
- [key: string]: T[];
71
- };
72
- export type EventLogSection<T> = {
73
- items: EventLogItems<T>;
74
- arrayItems: EventLogArrayItems<T>;
75
- };
76
- export type EventLogData = {
77
- addressItems: EventLogSection<string>;
78
- uintItems: EventLogSection<bigint>;
79
- intItems: EventLogSection<bigint>;
80
- boolItems: EventLogSection<boolean>;
81
- bytes32Items: EventLogSection<string>;
82
- bytesItems: EventLogSection<string>;
83
- stringItems: EventLogSection<string>;
84
- };
85
- export type EventTxnParams = {
86
- transactionHash: string;
87
- blockNumber: number;
88
- };