@gmx-io/sdk 1.6.1 → 1.6.3
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 +270 -0
- package/build/cjs/src/clients/v2/__tests__/testUtil.js +92 -1
- package/build/cjs/src/clients/v2/index.js +34 -57
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +8 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +61 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +15 -0
- package/build/cjs/src/configs/markets.js +11 -1
- package/build/cjs/src/configs/tokens.js +11 -0
- package/build/cjs/src/utils/__tests__/markets.spec.js +30 -0
- package/build/cjs/src/utils/markets/utils.js +16 -12
- package/build/cjs/src/utils/positions/utils.js +1 -0
- package/build/cjs/src/utils/subaccount/index.js +11 -1
- package/build/cjs/src/utils/subaccount/sdkClient.js +367 -0
- package/build/cjs/src/utils/subaccount/state.js +76 -0
- package/build/esm/src/clients/v2/__tests__/subaccount.spec.js +271 -1
- package/build/esm/src/clients/v2/__tests__/testUtil.js +87 -0
- package/build/esm/src/clients/v2/index.js +33 -56
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +8 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +61 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +15 -0
- package/build/esm/src/configs/markets.js +10 -0
- package/build/esm/src/configs/tokens.js +11 -0
- package/build/esm/src/utils/__tests__/markets.spec.js +30 -0
- package/build/esm/src/utils/markets/utils.js +16 -12
- package/build/esm/src/utils/positions/utils.js +1 -0
- package/build/esm/src/utils/subaccount/index.js +1 -0
- package/build/esm/src/utils/subaccount/sdkClient.js +352 -0
- package/build/esm/src/utils/subaccount/state.js +64 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/clients/v2/__tests__/testUtil.d.ts +37 -1
- package/build/types/src/clients/v2/index.d.ts +8 -2
- package/build/types/src/codegen/prebuilt/index.d.ts +84 -0
- package/build/types/src/configs/markets.d.ts +1 -0
- package/build/types/src/utils/markets/utils.d.ts +4 -3
- package/build/types/src/utils/subaccount/index.d.ts +1 -0
- package/build/types/src/utils/subaccount/sdkClient.d.ts +36 -0
- package/build/types/src/utils/subaccount/state.d.ts +11 -0
- package/build/types/src/utils/subaccount/types.d.ts +18 -0
- package/build/types/src/utils/tokens/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { toBigInt } from "../numbers";
|
|
2
|
+
import { nowInSeconds } from "../time";
|
|
3
|
+
export function parseSubaccountStatus(status) {
|
|
4
|
+
return {
|
|
5
|
+
active: status.active,
|
|
6
|
+
maxAllowedCount: toBigInt(status.maxAllowedCount) ?? 0n,
|
|
7
|
+
currentActionsCount: toBigInt(status.currentActionsCount) ?? 0n,
|
|
8
|
+
remainingActions: toBigInt(status.remainingActions) ?? 0n,
|
|
9
|
+
expiresAt: toBigInt(status.expiresAt) ?? 0n,
|
|
10
|
+
approvalNonce: toBigInt(status.approvalNonce) ?? 0n,
|
|
11
|
+
multichainApprovalNonce: toBigInt(status.multichainApprovalNonce) ?? 0n,
|
|
12
|
+
integrationId: status.integrationId ?? undefined,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function isSubaccountStatusUsable(status) {
|
|
16
|
+
return (status !== undefined && status.active && status.remainingActions > 0n && status.expiresAt > BigInt(nowInSeconds()));
|
|
17
|
+
}
|
|
18
|
+
export function isEmptySubaccountApproval(approval) {
|
|
19
|
+
return approval.signature === "0x";
|
|
20
|
+
}
|
|
21
|
+
export function isSameSubaccountApproval(a, b) {
|
|
22
|
+
return a.signature === b.signature && toBigInt(a.nonce) === toBigInt(b.nonce);
|
|
23
|
+
}
|
|
24
|
+
export function shouldRefreshExplicitSubaccountApproval(approval, status, pendingApproval) {
|
|
25
|
+
if (isEmptySubaccountApproval(approval)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (pendingApproval?.submittedRequestId && isSameSubaccountApproval(approval, pendingApproval.message)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return (status !== undefined &&
|
|
32
|
+
(isSubaccountApprovalSynced(approval, status) ||
|
|
33
|
+
isSubaccountApprovalNonceExpired(approval, status) ||
|
|
34
|
+
isSubaccountApprovalExpired(approval)));
|
|
35
|
+
}
|
|
36
|
+
export function isSubaccountApprovalNonceExpired(approval, status) {
|
|
37
|
+
return toBigInt(approval.nonce) !== status.approvalNonce;
|
|
38
|
+
}
|
|
39
|
+
export function isSubaccountApprovalSynced(approval, status) {
|
|
40
|
+
return (status.active &&
|
|
41
|
+
status.maxAllowedCount === toBigInt(approval.maxAllowedCount) &&
|
|
42
|
+
status.expiresAt === toBigInt(approval.expiresAt));
|
|
43
|
+
}
|
|
44
|
+
export function isSubaccountApprovalExpired(approval) {
|
|
45
|
+
const now = BigInt(nowInSeconds());
|
|
46
|
+
return (toBigInt(approval.expiresAt) ?? 0n) <= now || (toBigInt(approval.deadline) ?? 0n) <= now;
|
|
47
|
+
}
|
|
48
|
+
export function toSignedSubaccountApproval(prepared, signature) {
|
|
49
|
+
return {
|
|
50
|
+
subaccount: prepared.message.subaccount,
|
|
51
|
+
shouldAdd: Boolean(prepared.message.shouldAdd),
|
|
52
|
+
expiresAt: toBigInt(prepared.message.expiresAt) ?? 0n,
|
|
53
|
+
maxAllowedCount: toBigInt(prepared.message.maxAllowedCount) ?? 0n,
|
|
54
|
+
actionType: prepared.message.actionType,
|
|
55
|
+
nonce: toBigInt(prepared.message.nonce ?? prepared.nonce) ?? 0n,
|
|
56
|
+
desChainId: toBigInt(prepared.message.desChainId) ?? 0n,
|
|
57
|
+
deadline: toBigInt(prepared.message.deadline) ?? 0n,
|
|
58
|
+
integrationId: prepared.message.integrationId,
|
|
59
|
+
signature,
|
|
60
|
+
signedAt: Date.now(),
|
|
61
|
+
signatureChainId: prepared.domain.chainId,
|
|
62
|
+
subaccountRouterAddress: prepared.relayRouterAddress,
|
|
63
|
+
};
|
|
64
|
+
}
|