@gmx-io/sdk 0.1.1 → 0.2.0

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 (94) hide show
  1. package/README.md +31 -5
  2. package/build/src/configs/batch.d.ts +2 -3
  3. package/build/src/configs/chains.d.ts +5 -1
  4. package/build/src/configs/chains.js +9 -2
  5. package/build/src/configs/contracts.d.ts +220 -1
  6. package/build/src/configs/contracts.js +67 -8
  7. package/build/src/configs/markets.js +70 -0
  8. package/build/src/configs/tokens.js +128 -5
  9. package/build/src/modules/accounts/accounts.spec.js +1 -0
  10. package/build/src/modules/markets/index.js +2 -8
  11. package/build/src/modules/markets/markets.spec.js +1 -0
  12. package/build/src/modules/markets/query-builders.d.ts +1 -1
  13. package/build/src/modules/markets/query-builders.js +1 -1
  14. package/build/src/modules/markets/types.d.ts +4 -1
  15. package/build/src/modules/orders/orders.spec.js +1 -0
  16. package/build/src/modules/orders/utils.js +1 -1
  17. package/build/src/modules/positions/positions.d.ts +2 -2
  18. package/build/src/modules/positions/positions.js +21 -8
  19. package/build/src/modules/positions/positions.spec.js +2 -1
  20. package/build/src/modules/tokens/tokens.spec.js +1 -0
  21. package/build/src/modules/trades/trades.spec.js +1 -0
  22. package/build/src/modules/utils/utils.d.ts +1 -1
  23. package/build/src/modules/utils/utils.js +1 -1
  24. package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +80 -0
  25. package/build/src/prebuilt/hashedMarketConfigKeys.json +500 -0
  26. package/build/src/prebuilt/hashedMarketValuesKeys.json +150 -0
  27. package/build/src/types/common.d.ts +1 -0
  28. package/build/src/types/fees.d.ts +2 -1
  29. package/build/src/types/markets.d.ts +7 -19
  30. package/build/src/types/orders.d.ts +3 -5
  31. package/build/src/types/positions.d.ts +11 -4
  32. package/build/src/types/trade.d.ts +1 -0
  33. package/build/src/types/tradeHistory.d.ts +4 -1
  34. package/build/src/utils/__tests__/LruCache.spec.d.ts +1 -0
  35. package/build/src/utils/__tests__/LruCache.spec.js +43 -0
  36. package/build/src/utils/__tests__/bigmath.spec.d.ts +1 -0
  37. package/build/src/utils/__tests__/bigmath.spec.js +38 -0
  38. package/build/src/utils/__tests__/fees.spec.d.ts +1 -0
  39. package/build/src/utils/__tests__/fees.spec.js +62 -0
  40. package/build/src/utils/__tests__/hash.spec.d.ts +1 -0
  41. package/build/src/utils/__tests__/hash.spec.js +41 -0
  42. package/build/src/utils/__tests__/markets.spec.d.ts +1 -0
  43. package/build/src/utils/__tests__/markets.spec.js +265 -0
  44. package/build/src/utils/__tests__/numbers.spec.d.ts +1 -0
  45. package/build/src/utils/__tests__/numbers.spec.js +81 -0
  46. package/build/src/utils/__tests__/objects.spec.d.ts +1 -0
  47. package/build/src/utils/__tests__/objects.spec.js +59 -0
  48. package/build/src/utils/__tests__/positions.spec.d.ts +1 -0
  49. package/build/src/utils/__tests__/positions.spec.js +178 -0
  50. package/build/src/utils/__tests__/prices.spec.d.ts +1 -0
  51. package/build/src/utils/__tests__/prices.spec.js +59 -0
  52. package/build/src/utils/__tests__/referrals.spec.d.ts +1 -0
  53. package/build/src/utils/__tests__/referrals.spec.js +18 -0
  54. package/build/src/utils/__tests__/subgraph.spec.d.ts +1 -0
  55. package/build/src/utils/__tests__/subgraph.spec.js +163 -0
  56. package/build/src/utils/__tests__/tokens.spec.d.ts +1 -0
  57. package/build/src/utils/__tests__/tokens.spec.js +83 -0
  58. package/build/src/utils/__tests__/trade.spec.d.ts +1 -0
  59. package/build/src/utils/__tests__/trade.spec.js +36 -0
  60. package/build/src/utils/bigmath.d.ts +1 -1
  61. package/build/src/utils/bigmath.js +6 -1
  62. package/build/src/utils/callContract.js +5 -1
  63. package/build/src/utils/common.d.ts +6 -1
  64. package/build/src/utils/common.js +9 -1
  65. package/build/src/utils/contracts.d.ts +4 -0
  66. package/build/src/utils/contracts.js +2 -0
  67. package/build/src/utils/fees/executionFee.d.ts +22 -21
  68. package/build/src/utils/fees/executionFee.js +26 -26
  69. package/build/src/utils/fees/executionFee.spec.d.ts +1 -0
  70. package/build/src/utils/fees/executionFee.spec.js +64 -0
  71. package/build/src/utils/fees/index.d.ts +2 -0
  72. package/build/src/utils/fees/index.js +21 -9
  73. package/build/src/utils/markets.d.ts +9 -2
  74. package/build/src/utils/markets.js +33 -10
  75. package/build/src/utils/multicall.js +4 -3
  76. package/build/src/utils/numbers.d.ts +2 -0
  77. package/build/src/utils/numbers.js +28 -0
  78. package/build/src/utils/orders.js +0 -8
  79. package/build/src/utils/positions.js +3 -3
  80. package/build/src/utils/prices.d.ts +1 -6
  81. package/build/src/utils/prices.js +0 -9
  82. package/build/src/utils/referrals.d.ts +2 -0
  83. package/build/src/utils/referrals.js +17 -15
  84. package/build/src/utils/swapStats.d.ts +1 -0
  85. package/build/src/utils/swapStats.js +12 -1
  86. package/build/src/utils/testUtil.d.ts +14314 -326
  87. package/build/src/utils/tokens.d.ts +4 -0
  88. package/build/src/utils/tokens.js +4 -0
  89. package/build/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +6 -29
  91. package/build/src/types/amounts.d.ts +0 -223
  92. package/build/src/types/amounts.js +0 -17
  93. package/build/src/types/syntheticsEvents.d.ts +0 -88
  94. /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.2.0",
4
4
  "type": "module",
5
5
  "main": "build/src/index.js",
6
6
  "exports": {
@@ -18,32 +18,11 @@
18
18
  "prebuild": "yarn tsx scripts/prebuild",
19
19
  "prepare": "ts-patch install -s",
20
20
  "copy:jsons": "cp -r src/abis build/src && cp -r src/prebuilt build/src",
21
- "test": "jest",
21
+ "test": "vitest",
22
+ "test:ci": "vitest run",
22
23
  "tscheck": "tsc -p tsconfig.json --noEmit",
23
24
  "build": "rm -rf build && tsc -p tsconfig.json && yarn copy:jsons"
24
25
  },
25
- "jest": {
26
- "preset": "ts-jest/presets/default-esm",
27
- "testEnvironment": "node",
28
- "testTimeout": 15000,
29
- "testPathIgnorePatterns": [
30
- "/build/",
31
- "/node_modules/"
32
- ],
33
- "moduleFileExtensions": [
34
- "ts",
35
- "js",
36
- "json"
37
- ],
38
- "moduleNameMapper": {
39
- "^configs/(.*)$": "<rootDir>/src/configs/$1",
40
- "^modules/(.*)$": "<rootDir>/src/modules/$1",
41
- "^utils/(.*)$": "<rootDir>/src/utils/$1",
42
- "^types/(.*)$": "<rootDir>/src/types/$1",
43
- "prebuilt": "<rootDir>/src/prebuilt/index.ts",
44
- "^abis/(.*)$": "<rootDir>/src/abis/$1"
45
- }
46
- },
47
26
  "publishConfig": {
48
27
  "access": "public"
49
28
  },
@@ -58,19 +37,17 @@
58
37
  "query-string": "7.1.1",
59
38
  "typescript": "5.4.2",
60
39
  "universal-perf-hooks": "1.0.1",
61
- "viem": "2.7.20"
40
+ "viem": "^2.7.20"
62
41
  },
63
42
  "devDependencies": {
64
43
  "@babel/plugin-proposal-private-property-in-object": "7.21.11",
65
- "@types/jest": "29.5.13",
66
44
  "@types/lodash": "4.14.198",
67
45
  "@types/node": "18.7.13",
68
- "jest": "29.7.0",
69
46
  "lint-staged": "12.3.4",
70
- "ts-jest": "29.2.5",
71
47
  "ts-patch": "3.2.1",
72
48
  "tsx": "4.19.0",
73
- "typescript-transform-paths": "3.5.1"
49
+ "typescript-transform-paths": "3.5.1",
50
+ "vitest": "3.0.4"
74
51
  },
75
52
  "files": [
76
53
  "build"
@@ -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
- };