@gmx-io/sdk 1.6.4 → 1.7.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.
- package/README.md +48 -0
- package/build/cjs/scripts/subsquid-codegen.js +1 -1
- package/build/cjs/src/clients/v1/testUtil.js +1 -1
- package/build/cjs/src/clients/v2/__tests__/data.spec.js +5 -5
- package/build/cjs/src/clients/v2/__tests__/decrease.spec.js +6 -6
- package/build/cjs/src/clients/v2/__tests__/editCancel.spec.js +12 -12
- package/build/cjs/src/clients/v2/__tests__/errors.spec.js +1 -47
- package/build/cjs/src/clients/v2/__tests__/errorsLifecycle.spec.js +53 -0
- package/build/cjs/src/clients/v2/__tests__/globalCleanup.js +80 -0
- package/build/cjs/src/clients/v2/__tests__/increase.spec.js +14 -14
- package/build/cjs/src/clients/v2/__tests__/multichain.spec.js +5 -6
- package/build/cjs/src/clients/v2/__tests__/prepareErrors.spec.js +167 -0
- package/build/cjs/src/clients/v2/__tests__/setupAllowance.js +32 -0
- package/build/cjs/src/clients/v2/__tests__/subaccount.spec.js +16 -123
- package/build/cjs/src/clients/v2/__tests__/subaccountLifecycle.spec.js +108 -0
- package/build/cjs/src/clients/v2/__tests__/testUtil.js +38 -5
- package/build/cjs/src/clients/v2/__tests__/tradingCapacity.spec.js +371 -0
- package/build/cjs/src/clients/v2/index.js +6 -1
- package/build/cjs/src/codegen/subsquid.js +284 -20
- package/build/cjs/src/configs/__tests__/markets.spec.js +8 -0
- package/build/cjs/src/utils/__tests__/markets.spec.js +60 -0
- package/build/cjs/src/utils/__tests__/numbers.spec.js +39 -0
- package/build/cjs/src/utils/__tests__/positionPnlCap.spec.js +78 -0
- package/build/cjs/src/utils/__tests__/positions.spec.js +16 -4
- package/build/cjs/src/utils/markets/api.js +90 -2
- package/build/cjs/src/utils/markets/multicall.js +4 -6
- package/build/cjs/src/utils/markets/types.js +8 -0
- package/build/cjs/src/utils/markets/utils.js +67 -9
- package/build/cjs/src/utils/numbers/utils.js +28 -9
- package/build/cjs/src/utils/orderTransactions/api.js +160 -2
- package/build/cjs/src/utils/positions/utils.js +1 -1
- package/build/cjs/src/utils/tradeHistory/__tests__/utils.spec.js +64 -0
- package/build/cjs/src/utils/tradeHistory/utils.js +2 -0
- package/build/esm/scripts/subsquid-codegen.js +1 -1
- package/build/esm/src/clients/v1/testUtil.js +1 -1
- package/build/esm/src/clients/v2/__tests__/data.spec.js +6 -6
- package/build/esm/src/clients/v2/__tests__/decrease.spec.js +7 -7
- package/build/esm/src/clients/v2/__tests__/editCancel.spec.js +13 -13
- package/build/esm/src/clients/v2/__tests__/errors.spec.js +2 -48
- package/build/esm/src/clients/v2/__tests__/errorsLifecycle.spec.js +51 -0
- package/build/esm/src/clients/v2/__tests__/globalCleanup.js +77 -0
- package/build/esm/src/clients/v2/__tests__/increase.spec.js +15 -15
- package/build/esm/src/clients/v2/__tests__/multichain.spec.js +6 -7
- package/build/esm/src/clients/v2/__tests__/prepareErrors.spec.js +165 -0
- package/build/esm/src/clients/v2/__tests__/setupAllowance.js +30 -0
- package/build/esm/src/clients/v2/__tests__/subaccount.spec.js +17 -124
- package/build/esm/src/clients/v2/__tests__/subaccountLifecycle.spec.js +106 -0
- package/build/esm/src/clients/v2/__tests__/testUtil.js +33 -4
- package/build/esm/src/clients/v2/__tests__/tradingCapacity.spec.js +369 -0
- package/build/esm/src/clients/v2/index.js +6 -2
- package/build/esm/src/codegen/subsquid.js +282 -18
- package/build/esm/src/configs/__tests__/markets.spec.js +9 -1
- package/build/esm/src/utils/__tests__/markets.spec.js +61 -1
- package/build/esm/src/utils/__tests__/numbers.spec.js +40 -1
- package/build/esm/src/utils/__tests__/positionPnlCap.spec.js +76 -0
- package/build/esm/src/utils/__tests__/positions.spec.js +17 -5
- package/build/esm/src/utils/markets/api.js +88 -2
- package/build/esm/src/utils/markets/multicall.js +4 -6
- package/build/esm/src/utils/markets/types.js +8 -0
- package/build/esm/src/utils/markets/utils.js +65 -8
- package/build/esm/src/utils/numbers/utils.js +24 -7
- package/build/esm/src/utils/orderTransactions/api.js +157 -1
- package/build/esm/src/utils/positions/utils.js +2 -2
- package/build/esm/src/utils/tradeHistory/__tests__/utils.spec.js +62 -0
- package/build/esm/src/utils/tradeHistory/utils.js +2 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/clients/v2/__tests__/errorsLifecycle.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/globalCleanup.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/prepareErrors.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/setupAllowance.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/subaccountLifecycle.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/testUtil.d.ts +7 -1
- package/build/types/src/clients/v2/__tests__/tradingCapacity.spec.d.ts +1 -0
- package/build/types/src/clients/v2/index.d.ts +8 -5
- package/build/types/src/codegen/subsquid.d.ts +1141 -51
- package/build/types/src/utils/__tests__/positionPnlCap.spec.d.ts +1 -0
- package/build/types/src/utils/markets/api.d.ts +6 -2
- package/build/types/src/utils/markets/types.d.ts +28 -1
- package/build/types/src/utils/markets/utils.d.ts +7 -8
- package/build/types/src/utils/numbers/utils.d.ts +2 -0
- package/build/types/src/utils/orderTransactions/api.d.ts +50 -0
- package/build/types/src/utils/tradeHistory/__tests__/utils.spec.d.ts +1 -0
- package/build/types/src/utils/tradeHistory/types.d.ts +2 -0
- package/package.json +2 -1
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { describe, expect, expectTypeOf, it } from "vitest";
|
|
2
|
+
import { ARBITRUM } from "../../../configs/chains";
|
|
3
|
+
import { GmxApiSdk } from "../index";
|
|
4
|
+
const ACCOUNT = "0x1111111111111111111111111111111111111111";
|
|
5
|
+
const SYMBOL = "ETH/USD [WETH-USDC]";
|
|
6
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
7
|
+
class TradingCapacityApi {
|
|
8
|
+
constructor(response) {
|
|
9
|
+
this.response = response;
|
|
10
|
+
this.url = "http://test";
|
|
11
|
+
this.fetchCalls = [];
|
|
12
|
+
}
|
|
13
|
+
fetchJson(path, opts) {
|
|
14
|
+
this.fetchCalls.push({ path, query: opts?.query });
|
|
15
|
+
if (this.response instanceof Error) {
|
|
16
|
+
return Promise.reject(this.response);
|
|
17
|
+
}
|
|
18
|
+
const result = this.response;
|
|
19
|
+
return Promise.resolve(opts?.transform ? opts.transform(result) : result);
|
|
20
|
+
}
|
|
21
|
+
postJson() {
|
|
22
|
+
return Promise.reject(new Error("Unexpected postJson call"));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class PrepareCapacityApi {
|
|
26
|
+
constructor(response) {
|
|
27
|
+
this.response = response;
|
|
28
|
+
this.url = "http://test";
|
|
29
|
+
}
|
|
30
|
+
fetchJson() {
|
|
31
|
+
return Promise.reject(new Error("Unexpected fetchJson call"));
|
|
32
|
+
}
|
|
33
|
+
postJson(_path, _body, opts) {
|
|
34
|
+
const result = this.response;
|
|
35
|
+
return Promise.resolve(opts?.transform ? opts.transform(result) : result);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function buildCapacity() {
|
|
39
|
+
return {
|
|
40
|
+
availableLiquidity: MAX_UINT256.toString(),
|
|
41
|
+
baseAvailableLiquidity: (MAX_UINT256 - 2n).toString(),
|
|
42
|
+
jitAvailableLiquidity: "2",
|
|
43
|
+
limitingFactor: "reserve",
|
|
44
|
+
jitDataStatus: "available",
|
|
45
|
+
marketDataStatus: "fresh",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
describe("GmxApiSdk.getTradingCapacity", () => {
|
|
49
|
+
it("reads the dedicated capacity endpoint and parses bigint values", async () => {
|
|
50
|
+
const api = new TradingCapacityApi(buildCapacity());
|
|
51
|
+
const sdk = new GmxApiSdk({ chainId: ARBITRUM, api });
|
|
52
|
+
const capacity = await sdk.getTradingCapacity({ symbol: SYMBOL, direction: "long" });
|
|
53
|
+
expect(api.fetchCalls).toEqual([
|
|
54
|
+
{
|
|
55
|
+
path: "/v1/markets/trading-capacity",
|
|
56
|
+
query: { symbol: SYMBOL, direction: "long" },
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
expect(capacity).toEqual({
|
|
60
|
+
availableLiquidity: MAX_UINT256,
|
|
61
|
+
baseAvailableLiquidity: MAX_UINT256 - 2n,
|
|
62
|
+
jitAvailableLiquidity: 2n,
|
|
63
|
+
limitingFactor: "reserve",
|
|
64
|
+
jitDataStatus: "available",
|
|
65
|
+
marketDataStatus: "fresh",
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it("accepts safe integer, bigint, and decimal string capacity amounts", async () => {
|
|
69
|
+
const sdk = new GmxApiSdk({
|
|
70
|
+
chainId: ARBITRUM,
|
|
71
|
+
api: new TradingCapacityApi({
|
|
72
|
+
...buildCapacity(),
|
|
73
|
+
availableLiquidity: 100,
|
|
74
|
+
baseAvailableLiquidity: 80n,
|
|
75
|
+
jitAvailableLiquidity: "20",
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
await expect(sdk.getTradingCapacity({ symbol: SYMBOL, direction: "long" })).resolves.toMatchObject({
|
|
79
|
+
availableLiquidity: 100n,
|
|
80
|
+
baseAvailableLiquidity: 80n,
|
|
81
|
+
jitAvailableLiquidity: 20n,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it.each([
|
|
85
|
+
["a negative amount", { availableLiquidity: "-1" }],
|
|
86
|
+
["a non-canonical amount", { availableLiquidity: "01" }],
|
|
87
|
+
["a fractional amount", { availableLiquidity: 1.5 }],
|
|
88
|
+
["an unsafe integer amount", { availableLiquidity: Number.MAX_SAFE_INTEGER + 1 }],
|
|
89
|
+
["an overflowing amount", { availableLiquidity: (MAX_UINT256 + 1n).toString() }],
|
|
90
|
+
["an unknown limiting factor", { limitingFactor: "futureFactor" }],
|
|
91
|
+
["an unknown JIT data status", { jitDataStatus: "futureStatus" }],
|
|
92
|
+
["an unknown market data status", { marketDataStatus: "futureStatus" }],
|
|
93
|
+
])("rejects %s", async (_description, override) => {
|
|
94
|
+
const sdk = new GmxApiSdk({
|
|
95
|
+
chainId: ARBITRUM,
|
|
96
|
+
api: new TradingCapacityApi({ ...buildCapacity(), ...override }),
|
|
97
|
+
});
|
|
98
|
+
await expect(sdk.getTradingCapacity({ symbol: SYMBOL, direction: "long" })).rejects.toThrow("Invalid trading capacity response");
|
|
99
|
+
});
|
|
100
|
+
it.each(["available", "stale", "unavailable"])("preserves the %s JIT status", async (jitDataStatus) => {
|
|
101
|
+
const response = { ...buildCapacity(), jitDataStatus };
|
|
102
|
+
const sdk = new GmxApiSdk({ chainId: ARBITRUM, api: new TradingCapacityApi(response) });
|
|
103
|
+
const capacity = await sdk.getTradingCapacity({ symbol: SYMBOL, direction: "short" });
|
|
104
|
+
expect(capacity.jitDataStatus).toBe(jitDataStatus);
|
|
105
|
+
});
|
|
106
|
+
it("passes a market alias to the dedicated endpoint", async () => {
|
|
107
|
+
const api = new TradingCapacityApi(buildCapacity());
|
|
108
|
+
const sdk = new GmxApiSdk({ chainId: ARBITRUM, api });
|
|
109
|
+
await expect(sdk.getTradingCapacity({ symbol: "ETH/USD", direction: "long" })).resolves.toMatchObject({
|
|
110
|
+
availableLiquidity: MAX_UINT256,
|
|
111
|
+
});
|
|
112
|
+
expect(api.fetchCalls).toEqual([
|
|
113
|
+
{
|
|
114
|
+
path: "/v1/markets/trading-capacity",
|
|
115
|
+
query: { symbol: "ETH/USD", direction: "long" },
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
it("propagates API errors", async () => {
|
|
120
|
+
const sdk = new GmxApiSdk({
|
|
121
|
+
chainId: ARBITRUM,
|
|
122
|
+
api: new TradingCapacityApi(new Error("Market not found")),
|
|
123
|
+
});
|
|
124
|
+
await expect(sdk.getTradingCapacity({ symbol: SYMBOL, direction: "long" })).rejects.toThrow("Market not found");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe("GmxApiSdk.fetchMarketsTickers trading capacity", () => {
|
|
128
|
+
it("parses valid capacities and drops malformed capacities", async () => {
|
|
129
|
+
const sdk = new GmxApiSdk({
|
|
130
|
+
chainId: ARBITRUM,
|
|
131
|
+
api: new TradingCapacityApi([
|
|
132
|
+
{
|
|
133
|
+
symbol: SYMBOL,
|
|
134
|
+
capacityLong: buildCapacity(),
|
|
135
|
+
capacityShort: { ...buildCapacity(), jitAvailableLiquidity: "-1" },
|
|
136
|
+
},
|
|
137
|
+
]),
|
|
138
|
+
});
|
|
139
|
+
await expect(sdk.fetchMarketsTickers()).resolves.toEqual([
|
|
140
|
+
{
|
|
141
|
+
symbol: SYMBOL,
|
|
142
|
+
capacityLong: {
|
|
143
|
+
availableLiquidity: MAX_UINT256,
|
|
144
|
+
baseAvailableLiquidity: MAX_UINT256 - 2n,
|
|
145
|
+
jitAvailableLiquidity: 2n,
|
|
146
|
+
limitingFactor: "reserve",
|
|
147
|
+
jitDataStatus: "available",
|
|
148
|
+
marketDataStatus: "fresh",
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe("GmxApiSdk.prepareOrder trading capacity", () => {
|
|
155
|
+
it("parses capacity estimates and both typed validation warnings", async () => {
|
|
156
|
+
const capacity = buildCapacity();
|
|
157
|
+
const sdk = new GmxApiSdk({
|
|
158
|
+
chainId: ARBITRUM,
|
|
159
|
+
api: new PrepareCapacityApi({
|
|
160
|
+
requestId: "request-1",
|
|
161
|
+
payloadType: "transaction",
|
|
162
|
+
mode: "classic",
|
|
163
|
+
payload: {},
|
|
164
|
+
estimates: {
|
|
165
|
+
positionPriceImpactDeltaUsd: "1",
|
|
166
|
+
swapPriceImpactDeltaUsd: "2",
|
|
167
|
+
executionFeeAmount: "3",
|
|
168
|
+
acceptablePrice: "4",
|
|
169
|
+
sizeDeltaUsd: "5",
|
|
170
|
+
positionFeeUsd: "6",
|
|
171
|
+
borrowingFeeUsd: "7",
|
|
172
|
+
fundingFeeUsd: "8",
|
|
173
|
+
tradingCapacity: capacity,
|
|
174
|
+
},
|
|
175
|
+
validationWarnings: [
|
|
176
|
+
{
|
|
177
|
+
code: "INSUFFICIENT_LIQUIDITY",
|
|
178
|
+
message: "Order may not execute",
|
|
179
|
+
details: { ...capacity, requestedSizeUsd: MAX_UINT256.toString() },
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
code: "TRADING_CAPACITY_UNAVAILABLE",
|
|
183
|
+
message: "Capacity is unavailable",
|
|
184
|
+
details: { reason: "JIT_DATA_UNAVAILABLE" },
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
}),
|
|
188
|
+
});
|
|
189
|
+
const prepared = await sdk.prepareOrder({
|
|
190
|
+
kind: "increase",
|
|
191
|
+
symbol: SYMBOL,
|
|
192
|
+
direction: "long",
|
|
193
|
+
orderType: "limit",
|
|
194
|
+
size: 5n,
|
|
195
|
+
mode: "classic",
|
|
196
|
+
from: ACCOUNT,
|
|
197
|
+
});
|
|
198
|
+
expect(prepared.estimates?.tradingCapacity).toEqual({
|
|
199
|
+
availableLiquidity: MAX_UINT256,
|
|
200
|
+
baseAvailableLiquidity: MAX_UINT256 - 2n,
|
|
201
|
+
jitAvailableLiquidity: 2n,
|
|
202
|
+
limitingFactor: "reserve",
|
|
203
|
+
jitDataStatus: "available",
|
|
204
|
+
marketDataStatus: "fresh",
|
|
205
|
+
});
|
|
206
|
+
expect(prepared.validationWarnings).toEqual([
|
|
207
|
+
{
|
|
208
|
+
code: "INSUFFICIENT_LIQUIDITY",
|
|
209
|
+
message: "Order may not execute",
|
|
210
|
+
details: {
|
|
211
|
+
availableLiquidity: MAX_UINT256,
|
|
212
|
+
baseAvailableLiquidity: MAX_UINT256 - 2n,
|
|
213
|
+
jitAvailableLiquidity: 2n,
|
|
214
|
+
limitingFactor: "reserve",
|
|
215
|
+
jitDataStatus: "available",
|
|
216
|
+
marketDataStatus: "fresh",
|
|
217
|
+
requestedSizeUsd: MAX_UINT256,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
code: "TRADING_CAPACITY_UNAVAILABLE",
|
|
222
|
+
message: "Capacity is unavailable",
|
|
223
|
+
details: { reason: "JIT_DATA_UNAVAILABLE" },
|
|
224
|
+
},
|
|
225
|
+
]);
|
|
226
|
+
});
|
|
227
|
+
it("drops a malformed capacity estimate", async () => {
|
|
228
|
+
const sdk = new GmxApiSdk({
|
|
229
|
+
chainId: ARBITRUM,
|
|
230
|
+
api: new PrepareCapacityApi({
|
|
231
|
+
requestId: "request-1",
|
|
232
|
+
payloadType: "transaction",
|
|
233
|
+
mode: "classic",
|
|
234
|
+
payload: {},
|
|
235
|
+
estimates: {
|
|
236
|
+
tradingCapacity: { ...buildCapacity(), marketDataStatus: "futureStatus" },
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
});
|
|
240
|
+
const prepared = await sdk.prepareOrder({
|
|
241
|
+
kind: "increase",
|
|
242
|
+
symbol: SYMBOL,
|
|
243
|
+
direction: "long",
|
|
244
|
+
orderType: "limit",
|
|
245
|
+
size: 1n,
|
|
246
|
+
mode: "classic",
|
|
247
|
+
from: ACCOUNT,
|
|
248
|
+
});
|
|
249
|
+
expect(prepared.estimates?.tradingCapacity).toBeUndefined();
|
|
250
|
+
});
|
|
251
|
+
it("degrades malformed capacity warning details to an unknown warning", async () => {
|
|
252
|
+
const sdk = new GmxApiSdk({
|
|
253
|
+
chainId: ARBITRUM,
|
|
254
|
+
api: new PrepareCapacityApi({
|
|
255
|
+
requestId: "request-1",
|
|
256
|
+
payloadType: "transaction",
|
|
257
|
+
mode: "classic",
|
|
258
|
+
payload: {},
|
|
259
|
+
validationWarnings: [
|
|
260
|
+
{
|
|
261
|
+
code: "INSUFFICIENT_LIQUIDITY",
|
|
262
|
+
message: "Order may not execute",
|
|
263
|
+
details: { requestedSizeUsd: "1" },
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
}),
|
|
267
|
+
});
|
|
268
|
+
const prepared = await sdk.prepareOrder({
|
|
269
|
+
kind: "increase",
|
|
270
|
+
symbol: SYMBOL,
|
|
271
|
+
direction: "long",
|
|
272
|
+
orderType: "limit",
|
|
273
|
+
size: 1n,
|
|
274
|
+
mode: "classic",
|
|
275
|
+
from: ACCOUNT,
|
|
276
|
+
});
|
|
277
|
+
expect(prepared.validationWarnings).toEqual([
|
|
278
|
+
{
|
|
279
|
+
code: "UNKNOWN_VALIDATION_WARNING",
|
|
280
|
+
originalCode: "INSUFFICIENT_LIQUIDITY",
|
|
281
|
+
message: "Order may not execute",
|
|
282
|
+
details: { requestedSizeUsd: "1" },
|
|
283
|
+
},
|
|
284
|
+
]);
|
|
285
|
+
});
|
|
286
|
+
it.each([null, true, {}, { code: "", message: "Missing code" }, { code: "FUTURE_WARNING", message: "" }])("drops a structurally invalid warning %p", async (warning) => {
|
|
287
|
+
const sdk = new GmxApiSdk({
|
|
288
|
+
chainId: ARBITRUM,
|
|
289
|
+
api: new PrepareCapacityApi({
|
|
290
|
+
requestId: "request-1",
|
|
291
|
+
payloadType: "transaction",
|
|
292
|
+
mode: "classic",
|
|
293
|
+
payload: {},
|
|
294
|
+
validationWarnings: [warning],
|
|
295
|
+
}),
|
|
296
|
+
});
|
|
297
|
+
const prepared = await sdk.prepareOrder({
|
|
298
|
+
kind: "increase",
|
|
299
|
+
symbol: SYMBOL,
|
|
300
|
+
direction: "long",
|
|
301
|
+
orderType: "limit",
|
|
302
|
+
size: 1n,
|
|
303
|
+
mode: "classic",
|
|
304
|
+
from: ACCOUNT,
|
|
305
|
+
});
|
|
306
|
+
expect(prepared.validationWarnings).toEqual([]);
|
|
307
|
+
});
|
|
308
|
+
it("drops a non-array validationWarnings value", async () => {
|
|
309
|
+
const sdk = new GmxApiSdk({
|
|
310
|
+
chainId: ARBITRUM,
|
|
311
|
+
api: new PrepareCapacityApi({
|
|
312
|
+
requestId: "request-1",
|
|
313
|
+
payloadType: "transaction",
|
|
314
|
+
mode: "classic",
|
|
315
|
+
payload: {},
|
|
316
|
+
validationWarnings: { code: "FUTURE_WARNING", message: "A newer API warning" },
|
|
317
|
+
}),
|
|
318
|
+
});
|
|
319
|
+
const prepared = await sdk.prepareOrder({
|
|
320
|
+
kind: "increase",
|
|
321
|
+
symbol: SYMBOL,
|
|
322
|
+
direction: "long",
|
|
323
|
+
orderType: "limit",
|
|
324
|
+
size: 1n,
|
|
325
|
+
mode: "classic",
|
|
326
|
+
from: ACCOUNT,
|
|
327
|
+
});
|
|
328
|
+
expect(prepared.validationWarnings).toBeUndefined();
|
|
329
|
+
});
|
|
330
|
+
it("preserves unknown validation warnings for forward compatibility", async () => {
|
|
331
|
+
const sdk = new GmxApiSdk({
|
|
332
|
+
chainId: ARBITRUM,
|
|
333
|
+
api: new PrepareCapacityApi({
|
|
334
|
+
requestId: "request-1",
|
|
335
|
+
payloadType: "transaction",
|
|
336
|
+
mode: "classic",
|
|
337
|
+
payload: {},
|
|
338
|
+
validationWarnings: [
|
|
339
|
+
{
|
|
340
|
+
code: "FUTURE_WARNING",
|
|
341
|
+
message: "A newer API warning",
|
|
342
|
+
details: { retryAfter: 10 },
|
|
343
|
+
},
|
|
344
|
+
],
|
|
345
|
+
}),
|
|
346
|
+
});
|
|
347
|
+
const prepared = await sdk.prepareOrder({
|
|
348
|
+
kind: "increase",
|
|
349
|
+
symbol: SYMBOL,
|
|
350
|
+
direction: "long",
|
|
351
|
+
orderType: "limit",
|
|
352
|
+
size: 1n,
|
|
353
|
+
mode: "classic",
|
|
354
|
+
from: ACCOUNT,
|
|
355
|
+
});
|
|
356
|
+
expect(prepared.validationWarnings).toEqual([
|
|
357
|
+
{
|
|
358
|
+
code: "UNKNOWN_VALIDATION_WARNING",
|
|
359
|
+
originalCode: "FUTURE_WARNING",
|
|
360
|
+
message: "A newer API warning",
|
|
361
|
+
details: { retryAfter: 10 },
|
|
362
|
+
},
|
|
363
|
+
]);
|
|
364
|
+
});
|
|
365
|
+
it("keeps known warning codes as a discriminated union", () => {
|
|
366
|
+
expectTypeOf().toEqualTypeOf();
|
|
367
|
+
expectTypeOf().toEqualTypeOf();
|
|
368
|
+
});
|
|
369
|
+
});
|
|
@@ -7,10 +7,10 @@ import { executeCrossChainDeposit, executeCrossChainWithdraw, getCrossChainWithd
|
|
|
7
7
|
import { HttpClient } from "../../utils/http/http";
|
|
8
8
|
import { HttpClientWithFallback } from "../../utils/http/httpFallback";
|
|
9
9
|
import { fetchApiJitLiquidityInfo } from "../../utils/jitLiquidity/api";
|
|
10
|
-
import { fetchApiMarkets, fetchApiMarketsConfig, fetchApiMarketsInfo, fetchApiMarketsValues, fetchApiMarketsTickers, fetchApiTokensData, } from "../../utils/markets/api";
|
|
10
|
+
import { fetchApiMarkets, fetchApiMarketsConfig, fetchApiMarketsInfo, fetchApiMarketsValues, fetchApiMarketsTickers, fetchApiTradingCapacity, fetchApiTokensData, } from "../../utils/markets/api";
|
|
11
11
|
import { buildCrossChainWithdrawBridgeOutParams, buildSameChainDepositTxn, buildSameChainWithdrawBridgeOutParams, buildSameChainWithdrawTxn, executeSameChainDeposit, executeSameChainWithdraw, } from "../../utils/multichain";
|
|
12
12
|
import { fetchApiOrders } from "../../utils/orders/api";
|
|
13
|
-
import { prepareOrder, prepareEditOrder, prepareCancelOrder, prepareCollateral, fetchOrderStatus as fetchOrderStatusRaw, } from "../../utils/orderTransactions/api";
|
|
13
|
+
import { prepareOrder, prepareEditOrder, prepareCancelOrder, prepareCollateral, fetchOrderStatus as fetchOrderStatusRaw, isPrepareOrderError, parsePrepareOrderError, } from "../../utils/orderTransactions/api";
|
|
14
14
|
import { fetchApiPairs } from "../../utils/pairs/api";
|
|
15
15
|
import { fetchApiPerformanceAnnualized, fetchApiPerformanceSnapshots } from "../../utils/performance/api";
|
|
16
16
|
import { fetchApiPositionsInfo } from "../../utils/positions/api";
|
|
@@ -21,6 +21,7 @@ import { fetchSubaccountStatus, prepareSubaccountApproval, signSubaccountApprova
|
|
|
21
21
|
import { activateSdkSubaccount, clearSdkSubaccount, executeExpressOrderWithSubaccount, generateSdkSubaccount, getSdkSubaccountApprovalMessage, hasActiveSdkSubaccount, prepareWithSubaccount, refreshSdkSubaccountState, signOrderWithSubaccount, submitOrderWithSubaccount, } from "../../utils/subaccount/sdkClient";
|
|
22
22
|
import { fetchApiTokens } from "../../utils/tokens/api";
|
|
23
23
|
import { fetchApiTrades, searchApiTrades } from "../../utils/trades/api";
|
|
24
|
+
export { isPrepareOrderError, parsePrepareOrderError };
|
|
24
25
|
export { PrivateKeySigner } from "../../utils/signer";
|
|
25
26
|
export { HttpError } from "../../utils/http/http";
|
|
26
27
|
export { HttpClientWithFallback } from "../../utils/http/httpFallback";
|
|
@@ -81,6 +82,9 @@ export class GmxApiSdk {
|
|
|
81
82
|
fetchMarketsTickers(params) {
|
|
82
83
|
return fetchApiMarketsTickers(this.ctx, params);
|
|
83
84
|
}
|
|
85
|
+
getTradingCapacity(params) {
|
|
86
|
+
return fetchApiTradingCapacity(this.ctx, params);
|
|
87
|
+
}
|
|
84
88
|
fetchTokensData() {
|
|
85
89
|
return fetchApiTokensData(this.ctx);
|
|
86
90
|
}
|