@gmx-io/sdk 2.9.0 → 2.9.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.
- package/build/cjs/src/clients/v2/__tests__/subaccount.spec.js +2 -2
- package/build/cjs/src/clients/v2/__tests__/testUtil.js +8 -8
- package/build/cjs/src/utils/gmxAccountApi/api.js +4 -4
- package/build/cjs/src/utils/http/__tests__/chainPins.spec.js +3 -3
- package/build/cjs/src/utils/orderTransactions/api.js +6 -6
- package/build/cjs/src/utils/subaccount/api.js +2 -2
- package/build/esm/src/clients/v2/__tests__/subaccount.spec.js +2 -2
- package/build/esm/src/clients/v2/__tests__/testUtil.js +8 -8
- package/build/esm/src/utils/gmxAccountApi/api.js +4 -4
- package/build/esm/src/utils/http/__tests__/chainPins.spec.js +3 -3
- package/build/esm/src/utils/orderTransactions/api.js +6 -6
- package/build/esm/src/utils/subaccount/api.js +2 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -192,7 +192,7 @@ function buildTestPrepareRequest(from) {
|
|
|
192
192
|
(0, vitest_1.expect)(sdk.subaccountAddress).toBeUndefined();
|
|
193
193
|
(0, vitest_1.expect)(sdk.hasActiveSubaccount).toBe(false);
|
|
194
194
|
});
|
|
195
|
-
vitest_1.it
|
|
195
|
+
(0, vitest_1.it)("activateSubaccount prepares and signs approval", async () => {
|
|
196
196
|
const sdk = (0, testUtil_1.getTestSdk)();
|
|
197
197
|
const address = await sdk.activateSubaccount(signer, {
|
|
198
198
|
expiresInSeconds: 86400,
|
|
@@ -213,7 +213,7 @@ function buildTestPrepareRequest(from) {
|
|
|
213
213
|
(0, vitest_1.expect)(typeof status.active).toBe("boolean");
|
|
214
214
|
(0, vitest_1.expect)(status.approvalNonce).toBeDefined();
|
|
215
215
|
});
|
|
216
|
-
vitest_1.it
|
|
216
|
+
(0, vitest_1.it)("signOrder uses subaccount signer when active", async () => {
|
|
217
217
|
const sdk = (0, testUtil_1.getTestSdk)();
|
|
218
218
|
await sdk.activateSubaccount(signer, {
|
|
219
219
|
expiresInSeconds: 86400,
|
|
@@ -16,10 +16,10 @@ const TERMINAL_STATUSES = new Set(["executed", "cancelled", "relay_failed", "rel
|
|
|
16
16
|
const PLACED_STATUSES = new Set([...TERMINAL_STATUSES, "created"]);
|
|
17
17
|
exports.PLACED_OK_STATUSES = ["created", "executed"];
|
|
18
18
|
const ORDER_PREPARE_PATHS = new Set([
|
|
19
|
-
"/
|
|
20
|
-
"/
|
|
21
|
-
"/
|
|
22
|
-
"/
|
|
19
|
+
"/v2/orders/txns/prepare",
|
|
20
|
+
"/v2/orders/txns/edit/prepare",
|
|
21
|
+
"/v2/orders/txns/cancel/prepare",
|
|
22
|
+
"/v2/orders/txns/collateral/prepare",
|
|
23
23
|
]);
|
|
24
24
|
class RecordingApi {
|
|
25
25
|
constructor(delegate) {
|
|
@@ -35,7 +35,7 @@ class RecordingApi {
|
|
|
35
35
|
if (ORDER_PREPARE_PATHS.has(path)) {
|
|
36
36
|
this.orderPrepareRequests.push(body);
|
|
37
37
|
}
|
|
38
|
-
else if (path === "/
|
|
38
|
+
else if (path === "/v2/orders/txns/submit") {
|
|
39
39
|
this.orderSubmitRequests.push(body);
|
|
40
40
|
}
|
|
41
41
|
return this.delegate.postJson(path, body, opts);
|
|
@@ -68,11 +68,11 @@ class ScriptedOrderApi {
|
|
|
68
68
|
return Promise.reject(new Error(`Unexpected fetchJson call ${path}`));
|
|
69
69
|
}
|
|
70
70
|
postJson(path, body, opts) {
|
|
71
|
-
if (path === "/
|
|
71
|
+
if (path === "/v2/orders/txns/prepare") {
|
|
72
72
|
this.prepareRequests.push(body);
|
|
73
73
|
return Promise.resolve(opts?.transform ? opts.transform(this.prepareResponse) : this.prepareResponse);
|
|
74
74
|
}
|
|
75
|
-
if (path === "/
|
|
75
|
+
if (path === "/v2/orders/txns/submit") {
|
|
76
76
|
this.submitRequests.push(body);
|
|
77
77
|
const response = this.submitResponses.shift();
|
|
78
78
|
if (!response) {
|
|
@@ -80,7 +80,7 @@ class ScriptedOrderApi {
|
|
|
80
80
|
}
|
|
81
81
|
return Promise.resolve(response);
|
|
82
82
|
}
|
|
83
|
-
if (path === "/
|
|
83
|
+
if (path === "/v2/subaccounts/status") {
|
|
84
84
|
this.subaccountStatusRequests.push(body);
|
|
85
85
|
const response = this.subaccountStatusResponses.shift();
|
|
86
86
|
if (!response) {
|
|
@@ -35,7 +35,7 @@ function parseWithdrawPrepareResponse(raw) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
async function prepareCrossChainDeposit(ctx, request) {
|
|
38
|
-
return ctx.api.postJson("/
|
|
38
|
+
return ctx.api.postJson("/v2/gmx-account/deposit/cross-chain/prepare", request, {
|
|
39
39
|
transform: parseDepositPrepareResponse,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -58,11 +58,11 @@ async function executeCrossChainDeposit(ctx, signer, request) {
|
|
|
58
58
|
}
|
|
59
59
|
exports.executeCrossChainDeposit = executeCrossChainDeposit;
|
|
60
60
|
async function prepareCrossChainWithdraw(ctx, request) {
|
|
61
|
-
return (0, chainPins_1.postJsonPinning)(ctx.api, "/
|
|
61
|
+
return (0, chainPins_1.postJsonPinning)(ctx.api, "/v2/gmx-account/withdraw/cross-chain/prepare", request, (prepared) => [prepared.requestId], { transform: parseWithdrawPrepareResponse });
|
|
62
62
|
}
|
|
63
63
|
exports.prepareCrossChainWithdraw = prepareCrossChainWithdraw;
|
|
64
64
|
async function submitCrossChainWithdraw(ctx, request) {
|
|
65
|
-
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/
|
|
65
|
+
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/v2/gmx-account/withdraw/cross-chain/submit", request);
|
|
66
66
|
}
|
|
67
67
|
exports.submitCrossChainWithdraw = submitCrossChainWithdraw;
|
|
68
68
|
async function signCrossChainWithdrawPrepared(prepared, signer) {
|
|
@@ -86,6 +86,6 @@ async function executeCrossChainWithdraw(ctx, signer, request) {
|
|
|
86
86
|
}
|
|
87
87
|
exports.executeCrossChainWithdraw = executeCrossChainWithdraw;
|
|
88
88
|
async function getCrossChainWithdrawStatus(ctx, requestId) {
|
|
89
|
-
return (0, chainPins_1.postJsonPinned)(ctx.api, [requestId], "/
|
|
89
|
+
return (0, chainPins_1.postJsonPinned)(ctx.api, [requestId], "/v2/gmx-account/withdraw/cross-chain/status", { requestId });
|
|
90
90
|
}
|
|
91
91
|
exports.getCrossChainWithdrawStatus = getCrossChainWithdrawStatus;
|
|
@@ -5,9 +5,9 @@ const httpFallback_1 = require("../httpFallback");
|
|
|
5
5
|
const api_1 = require("../../orderTransactions/api");
|
|
6
6
|
const fetchMock = vitest_1.vi.hoisted(() => vitest_1.vi.fn());
|
|
7
7
|
vitest_1.vi.mock("cross-fetch", () => ({ default: fetchMock }));
|
|
8
|
-
const PREPARE = "/
|
|
9
|
-
const SUBMIT = "/
|
|
10
|
-
const STATUS = "/
|
|
8
|
+
const PREPARE = "/v2/orders/txns/prepare";
|
|
9
|
+
const SUBMIT = "/v2/orders/txns/submit";
|
|
10
|
+
const STATUS = "/v2/orders/txns/status";
|
|
11
11
|
function jsonResponse(status, body) {
|
|
12
12
|
return new Response(JSON.stringify(body), { status, headers: { "Content-Type": "application/json" } });
|
|
13
13
|
}
|
|
@@ -183,35 +183,35 @@ function chainKeys(prepared) {
|
|
|
183
183
|
return [prepared.requestId];
|
|
184
184
|
}
|
|
185
185
|
async function prepareOrder(ctx, request) {
|
|
186
|
-
return (0, chainPins_1.postJsonPinning)(ctx.api, "/
|
|
186
|
+
return (0, chainPins_1.postJsonPinning)(ctx.api, "/v2/orders/txns/prepare", request, chainKeys, {
|
|
187
187
|
transform: parsePrepareResponse,
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
exports.prepareOrder = prepareOrder;
|
|
191
191
|
async function submitOrder(ctx, request) {
|
|
192
|
-
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/
|
|
192
|
+
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/v2/orders/txns/submit", request);
|
|
193
193
|
}
|
|
194
194
|
exports.submitOrder = submitOrder;
|
|
195
195
|
async function prepareEditOrder(ctx, request) {
|
|
196
|
-
return (0, chainPins_1.postJsonPinning)(ctx.api, "/
|
|
196
|
+
return (0, chainPins_1.postJsonPinning)(ctx.api, "/v2/orders/txns/edit/prepare", request, chainKeys, {
|
|
197
197
|
transform: parsePrepareResponse,
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
exports.prepareEditOrder = prepareEditOrder;
|
|
201
201
|
async function prepareCancelOrder(ctx, request) {
|
|
202
|
-
return (0, chainPins_1.postJsonPinning)(ctx.api, "/
|
|
202
|
+
return (0, chainPins_1.postJsonPinning)(ctx.api, "/v2/orders/txns/cancel/prepare", request, chainKeys, {
|
|
203
203
|
transform: parsePrepareResponse,
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
exports.prepareCancelOrder = prepareCancelOrder;
|
|
207
207
|
async function prepareCollateral(ctx, request) {
|
|
208
|
-
return (0, chainPins_1.postJsonPinning)(ctx.api, "/
|
|
208
|
+
return (0, chainPins_1.postJsonPinning)(ctx.api, "/v2/orders/txns/collateral/prepare", request, chainKeys, {
|
|
209
209
|
transform: parsePrepareResponse,
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
exports.prepareCollateral = prepareCollateral;
|
|
213
213
|
async function fetchOrderStatus(ctx, request) {
|
|
214
|
-
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/
|
|
214
|
+
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/v2/orders/txns/status", request);
|
|
215
215
|
}
|
|
216
216
|
exports.fetchOrderStatus = fetchOrderStatus;
|
|
217
217
|
async function signPreparedOrder(prepared, signer, chainId, accountAddress) {
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.signSubaccountApproval = exports.prepareSubaccountApproval = exports.fetchSubaccountStatus = void 0;
|
|
4
4
|
const validateTypedData_1 = require("../orderTransactions/validateTypedData");
|
|
5
5
|
async function fetchSubaccountStatus(ctx, request) {
|
|
6
|
-
return ctx.api.postJson("/
|
|
6
|
+
return ctx.api.postJson("/v2/subaccounts/status", request);
|
|
7
7
|
}
|
|
8
8
|
exports.fetchSubaccountStatus = fetchSubaccountStatus;
|
|
9
9
|
async function prepareSubaccountApproval(ctx, request) {
|
|
10
|
-
return ctx.api.postJson("/
|
|
10
|
+
return ctx.api.postJson("/v2/subaccounts/approval/prepare", request);
|
|
11
11
|
}
|
|
12
12
|
exports.prepareSubaccountApproval = prepareSubaccountApproval;
|
|
13
13
|
async function signSubaccountApproval(prepared, signer, options) {
|
|
@@ -190,7 +190,7 @@ describe("GmxApiSdk — subaccount (1CT)", () => {
|
|
|
190
190
|
expect(sdk.subaccountAddress).toBeUndefined();
|
|
191
191
|
expect(sdk.hasActiveSubaccount).toBe(false);
|
|
192
192
|
});
|
|
193
|
-
it
|
|
193
|
+
it("activateSubaccount prepares and signs approval", async () => {
|
|
194
194
|
const sdk = getTestSdk();
|
|
195
195
|
const address = await sdk.activateSubaccount(signer, {
|
|
196
196
|
expiresInSeconds: 86400,
|
|
@@ -211,7 +211,7 @@ describe("GmxApiSdk — subaccount (1CT)", () => {
|
|
|
211
211
|
expect(typeof status.active).toBe("boolean");
|
|
212
212
|
expect(status.approvalNonce).toBeDefined();
|
|
213
213
|
});
|
|
214
|
-
it
|
|
214
|
+
it("signOrder uses subaccount signer when active", async () => {
|
|
215
215
|
const sdk = getTestSdk();
|
|
216
216
|
await sdk.activateSubaccount(signer, {
|
|
217
217
|
expiresInSeconds: 86400,
|
|
@@ -13,10 +13,10 @@ const TERMINAL_STATUSES = new Set(["executed", "cancelled", "relay_failed", "rel
|
|
|
13
13
|
const PLACED_STATUSES = new Set([...TERMINAL_STATUSES, "created"]);
|
|
14
14
|
export const PLACED_OK_STATUSES = ["created", "executed"];
|
|
15
15
|
const ORDER_PREPARE_PATHS = new Set([
|
|
16
|
-
"/
|
|
17
|
-
"/
|
|
18
|
-
"/
|
|
19
|
-
"/
|
|
16
|
+
"/v2/orders/txns/prepare",
|
|
17
|
+
"/v2/orders/txns/edit/prepare",
|
|
18
|
+
"/v2/orders/txns/cancel/prepare",
|
|
19
|
+
"/v2/orders/txns/collateral/prepare",
|
|
20
20
|
]);
|
|
21
21
|
export class RecordingApi {
|
|
22
22
|
constructor(delegate) {
|
|
@@ -32,7 +32,7 @@ export class RecordingApi {
|
|
|
32
32
|
if (ORDER_PREPARE_PATHS.has(path)) {
|
|
33
33
|
this.orderPrepareRequests.push(body);
|
|
34
34
|
}
|
|
35
|
-
else if (path === "/
|
|
35
|
+
else if (path === "/v2/orders/txns/submit") {
|
|
36
36
|
this.orderSubmitRequests.push(body);
|
|
37
37
|
}
|
|
38
38
|
return this.delegate.postJson(path, body, opts);
|
|
@@ -63,11 +63,11 @@ export class ScriptedOrderApi {
|
|
|
63
63
|
return Promise.reject(new Error(`Unexpected fetchJson call ${path}`));
|
|
64
64
|
}
|
|
65
65
|
postJson(path, body, opts) {
|
|
66
|
-
if (path === "/
|
|
66
|
+
if (path === "/v2/orders/txns/prepare") {
|
|
67
67
|
this.prepareRequests.push(body);
|
|
68
68
|
return Promise.resolve(opts?.transform ? opts.transform(this.prepareResponse) : this.prepareResponse);
|
|
69
69
|
}
|
|
70
|
-
if (path === "/
|
|
70
|
+
if (path === "/v2/orders/txns/submit") {
|
|
71
71
|
this.submitRequests.push(body);
|
|
72
72
|
const response = this.submitResponses.shift();
|
|
73
73
|
if (!response) {
|
|
@@ -75,7 +75,7 @@ export class ScriptedOrderApi {
|
|
|
75
75
|
}
|
|
76
76
|
return Promise.resolve(response);
|
|
77
77
|
}
|
|
78
|
-
if (path === "/
|
|
78
|
+
if (path === "/v2/subaccounts/status") {
|
|
79
79
|
this.subaccountStatusRequests.push(body);
|
|
80
80
|
const response = this.subaccountStatusResponses.shift();
|
|
81
81
|
if (!response) {
|
|
@@ -32,7 +32,7 @@ function parseWithdrawPrepareResponse(raw) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
export async function prepareCrossChainDeposit(ctx, request) {
|
|
35
|
-
return ctx.api.postJson("/
|
|
35
|
+
return ctx.api.postJson("/v2/gmx-account/deposit/cross-chain/prepare", request, {
|
|
36
36
|
transform: parseDepositPrepareResponse,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -53,10 +53,10 @@ export async function executeCrossChainDeposit(ctx, signer, request) {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
export async function prepareCrossChainWithdraw(ctx, request) {
|
|
56
|
-
return postJsonPinning(ctx.api, "/
|
|
56
|
+
return postJsonPinning(ctx.api, "/v2/gmx-account/withdraw/cross-chain/prepare", request, (prepared) => [prepared.requestId], { transform: parseWithdrawPrepareResponse });
|
|
57
57
|
}
|
|
58
58
|
export async function submitCrossChainWithdraw(ctx, request) {
|
|
59
|
-
return postJsonPinned(ctx.api, [request.requestId], "/
|
|
59
|
+
return postJsonPinned(ctx.api, [request.requestId], "/v2/gmx-account/withdraw/cross-chain/submit", request);
|
|
60
60
|
}
|
|
61
61
|
export async function signCrossChainWithdrawPrepared(prepared, signer) {
|
|
62
62
|
const td = prepared.payload.typedData;
|
|
@@ -77,5 +77,5 @@ export async function executeCrossChainWithdraw(ctx, signer, request) {
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
export async function getCrossChainWithdrawStatus(ctx, requestId) {
|
|
80
|
-
return postJsonPinned(ctx.api, [requestId], "/
|
|
80
|
+
return postJsonPinned(ctx.api, [requestId], "/v2/gmx-account/withdraw/cross-chain/status", { requestId });
|
|
81
81
|
}
|
|
@@ -3,9 +3,9 @@ import { HttpClientWithFallback } from "../httpFallback";
|
|
|
3
3
|
import { fetchOrderStatus, prepareOrder, submitOrder } from "../../orderTransactions/api";
|
|
4
4
|
const fetchMock = vi.hoisted(() => vi.fn());
|
|
5
5
|
vi.mock("cross-fetch", () => ({ default: fetchMock }));
|
|
6
|
-
const PREPARE = "/
|
|
7
|
-
const SUBMIT = "/
|
|
8
|
-
const STATUS = "/
|
|
6
|
+
const PREPARE = "/v2/orders/txns/prepare";
|
|
7
|
+
const SUBMIT = "/v2/orders/txns/submit";
|
|
8
|
+
const STATUS = "/v2/orders/txns/status";
|
|
9
9
|
function jsonResponse(status, body) {
|
|
10
10
|
return new Response(JSON.stringify(body), { status, headers: { "Content-Type": "application/json" } });
|
|
11
11
|
}
|
|
@@ -178,30 +178,30 @@ function chainKeys(prepared) {
|
|
|
178
178
|
return [prepared.requestId];
|
|
179
179
|
}
|
|
180
180
|
export async function prepareOrder(ctx, request) {
|
|
181
|
-
return postJsonPinning(ctx.api, "/
|
|
181
|
+
return postJsonPinning(ctx.api, "/v2/orders/txns/prepare", request, chainKeys, {
|
|
182
182
|
transform: parsePrepareResponse,
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
export async function submitOrder(ctx, request) {
|
|
186
|
-
return postJsonPinned(ctx.api, [request.requestId], "/
|
|
186
|
+
return postJsonPinned(ctx.api, [request.requestId], "/v2/orders/txns/submit", request);
|
|
187
187
|
}
|
|
188
188
|
export async function prepareEditOrder(ctx, request) {
|
|
189
|
-
return postJsonPinning(ctx.api, "/
|
|
189
|
+
return postJsonPinning(ctx.api, "/v2/orders/txns/edit/prepare", request, chainKeys, {
|
|
190
190
|
transform: parsePrepareResponse,
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
export async function prepareCancelOrder(ctx, request) {
|
|
194
|
-
return postJsonPinning(ctx.api, "/
|
|
194
|
+
return postJsonPinning(ctx.api, "/v2/orders/txns/cancel/prepare", request, chainKeys, {
|
|
195
195
|
transform: parsePrepareResponse,
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
export async function prepareCollateral(ctx, request) {
|
|
199
|
-
return postJsonPinning(ctx.api, "/
|
|
199
|
+
return postJsonPinning(ctx.api, "/v2/orders/txns/collateral/prepare", request, chainKeys, {
|
|
200
200
|
transform: parsePrepareResponse,
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
export async function fetchOrderStatus(ctx, request) {
|
|
204
|
-
return postJsonPinned(ctx.api, [request.requestId], "/
|
|
204
|
+
return postJsonPinned(ctx.api, [request.requestId], "/v2/orders/txns/status", request);
|
|
205
205
|
}
|
|
206
206
|
export async function signPreparedOrder(prepared, signer, chainId, accountAddress) {
|
|
207
207
|
if (prepared.payloadType !== "typed-data") {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { validateSubaccountApprovalTypedData } from "../orderTransactions/validateTypedData";
|
|
2
2
|
export async function fetchSubaccountStatus(ctx, request) {
|
|
3
|
-
return ctx.api.postJson("/
|
|
3
|
+
return ctx.api.postJson("/v2/subaccounts/status", request);
|
|
4
4
|
}
|
|
5
5
|
export async function prepareSubaccountApproval(ctx, request) {
|
|
6
|
-
return ctx.api.postJson("/
|
|
6
|
+
return ctx.api.postJson("/v2/subaccounts/approval/prepare", request);
|
|
7
7
|
}
|
|
8
8
|
export async function signSubaccountApproval(prepared, signer, options) {
|
|
9
9
|
const domain = prepared.domain;
|