@nktkas/hyperliquid 0.23.1 → 0.24.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/CONTRIBUTING.md +3 -2
- package/README.md +154 -170
- package/esm/mod.d.ts +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/base.d.ts +0 -5
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/clients/exchange.d.ts +430 -393
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +467 -927
- package/esm/src/clients/info.d.ts +228 -203
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +236 -368
- package/esm/src/clients/multiSign.d.ts +14 -1184
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +37 -2004
- package/esm/src/clients/subscription.d.ts +95 -93
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +101 -146
- package/esm/src/signing/_signTypedData/ethers.d.ts +16 -4
- package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/ethers.js +1 -1
- package/esm/src/signing/_signTypedData/mod.d.ts +12 -12
- package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/mod.js +52 -24
- package/esm/src/signing/_signTypedData/private_key.d.ts +6 -5
- package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/private_key.js +40 -19
- package/esm/src/signing/_signTypedData/viem.d.ts +27 -6
- package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/viem.js +1 -1
- package/esm/src/signing/_sorter.d.ts +12 -21
- package/esm/src/signing/_sorter.d.ts.map +1 -1
- package/esm/src/signing/_sorter.js +30 -63
- package/esm/src/signing/mod.d.ts +177 -127
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +182 -130
- package/esm/src/transports/base.d.ts +2 -1
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.d.ts +3 -2
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +4 -4
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -2
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +17 -21
- package/esm/src/transports/websocket/websocket_transport.d.ts +4 -4
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +6 -6
- package/esm/src/types/exchange/requests.d.ts +492 -306
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +105 -25
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +3 -3
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +1 -1
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +403 -98
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +131 -35
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +29 -8
- package/esm/src/types/info/markets.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +62 -17
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +117 -51
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/validators.d.ts +44 -14
- package/esm/src/types/info/validators.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +25 -10
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +1 -1
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +21 -66
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/types/subscriptions/responses.d.ts +46 -55
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
- package/package.json +2 -3
- package/script/mod.d.ts +1 -1
- package/script/mod.d.ts.map +1 -1
- package/script/src/base.d.ts +0 -5
- package/script/src/base.d.ts.map +1 -1
- package/script/src/clients/exchange.d.ts +430 -393
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +466 -926
- package/script/src/clients/info.d.ts +228 -203
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +236 -368
- package/script/src/clients/multiSign.d.ts +14 -1184
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +38 -2005
- package/script/src/clients/subscription.d.ts +95 -93
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +101 -146
- package/script/src/signing/_signTypedData/ethers.d.ts +16 -4
- package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/ethers.js +2 -2
- package/script/src/signing/_signTypedData/mod.d.ts +12 -12
- package/script/src/signing/_signTypedData/mod.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/mod.js +51 -26
- package/script/src/signing/_signTypedData/private_key.d.ts +6 -5
- package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/private_key.js +40 -18
- package/script/src/signing/_signTypedData/viem.d.ts +27 -6
- package/script/src/signing/_signTypedData/viem.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/viem.js +2 -2
- package/script/src/signing/_sorter.d.ts +12 -21
- package/script/src/signing/_sorter.d.ts.map +1 -1
- package/script/src/signing/_sorter.js +30 -63
- package/script/src/signing/mod.d.ts +177 -127
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +185 -148
- package/script/src/transports/base.d.ts +2 -1
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.d.ts +3 -2
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +4 -4
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +1 -2
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +17 -21
- package/script/src/transports/websocket/websocket_transport.d.ts +4 -4
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +6 -6
- package/script/src/types/exchange/requests.d.ts +492 -306
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/responses.d.ts +105 -25
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/explorer/requests.d.ts +3 -3
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/responses.d.ts +1 -1
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +403 -98
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +131 -35
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/markets.d.ts +29 -8
- package/script/src/types/info/markets.d.ts.map +1 -1
- package/script/src/types/info/orders.d.ts +62 -17
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +117 -51
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/validators.d.ts +44 -14
- package/script/src/types/info/validators.d.ts.map +1 -1
- package/script/src/types/info/vaults.d.ts +25 -10
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +1 -1
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.d.ts +21 -66
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/responses.d.ts +46 -55
- package/script/src/types/subscriptions/responses.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/window.d.ts +0 -29
- package/esm/src/signing/_signTypedData/window.d.ts.map +0 -1
- package/esm/src/signing/_signTypedData/window.js +0 -30
- package/script/src/signing/_signTypedData/window.d.ts +0 -29
- package/script/src/signing/_signTypedData/window.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/window.js +0 -34
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidPrivateKey = exports.isAbstractWindowEthereum = exports.isAbstractViemWalletClient = exports.isAbstractEthersV5Signer = exports.isAbstractEthersSigner = void 0;
|
|
4
3
|
exports.signTypedData = signTypedData;
|
|
4
|
+
exports.getWalletChainId = getWalletChainId;
|
|
5
|
+
exports.getWalletAddress = getWalletAddress;
|
|
5
6
|
const ethers_js_1 = require("./ethers.js");
|
|
6
|
-
Object.defineProperty(exports, "isAbstractEthersSigner", { enumerable: true, get: function () { return ethers_js_1.isAbstractEthersSigner; } });
|
|
7
|
-
Object.defineProperty(exports, "isAbstractEthersV5Signer", { enumerable: true, get: function () { return ethers_js_1.isAbstractEthersV5Signer; } });
|
|
8
7
|
const private_key_js_1 = require("./private_key.js");
|
|
9
|
-
Object.defineProperty(exports, "isValidPrivateKey", { enumerable: true, get: function () { return private_key_js_1.isValidPrivateKey; } });
|
|
10
8
|
const viem_js_1 = require("./viem.js");
|
|
11
|
-
Object.defineProperty(exports, "isAbstractViemWalletClient", { enumerable: true, get: function () { return viem_js_1.isAbstractViemWalletClient; } });
|
|
12
|
-
const window_js_1 = require("./window.js");
|
|
13
|
-
Object.defineProperty(exports, "isAbstractWindowEthereum", { enumerable: true, get: function () { return window_js_1.isAbstractWindowEthereum; } });
|
|
14
9
|
async function signTypedData(args) {
|
|
15
10
|
const { wallet, domain, types, primaryType, message } = args;
|
|
16
11
|
let signature;
|
|
17
|
-
if ((0,
|
|
18
|
-
signature = await (0, private_key_js_1.signTypedData)({
|
|
19
|
-
privateKey: wallet,
|
|
20
|
-
domain,
|
|
21
|
-
types,
|
|
22
|
-
primaryType,
|
|
23
|
-
message,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else if ((0, viem_js_1.isAbstractViemWalletClient)(wallet)) {
|
|
12
|
+
if ((0, viem_js_1.isAbstractViemWallet)(wallet)) {
|
|
27
13
|
signature = await wallet.signTypedData({
|
|
28
14
|
domain,
|
|
29
15
|
types: {
|
|
@@ -39,20 +25,14 @@ async function signTypedData(args) {
|
|
|
39
25
|
message,
|
|
40
26
|
});
|
|
41
27
|
}
|
|
42
|
-
else if ((0, ethers_js_1.
|
|
28
|
+
else if ((0, ethers_js_1.isAbstractEthersV6Signer)(wallet)) {
|
|
43
29
|
signature = await wallet.signTypedData(domain, types, message);
|
|
44
30
|
}
|
|
45
31
|
else if ((0, ethers_js_1.isAbstractEthersV5Signer)(wallet)) {
|
|
46
32
|
signature = await wallet._signTypedData(domain, types, message);
|
|
47
33
|
}
|
|
48
|
-
else if ((0,
|
|
49
|
-
signature = await (0,
|
|
50
|
-
ethereum: wallet,
|
|
51
|
-
domain,
|
|
52
|
-
types,
|
|
53
|
-
primaryType,
|
|
54
|
-
message,
|
|
55
|
-
});
|
|
34
|
+
else if ((0, private_key_js_1.isValidPrivateKey)(wallet)) {
|
|
35
|
+
signature = await (0, private_key_js_1.signTypedData)({ privateKey: wallet, domain, types, primaryType, message });
|
|
56
36
|
}
|
|
57
37
|
else {
|
|
58
38
|
throw new Error("Unsupported wallet for signing typed data");
|
|
@@ -65,3 +45,48 @@ function splitSignature(signature) {
|
|
|
65
45
|
const v = parseInt(signature.slice(130, 132), 16);
|
|
66
46
|
return { r, s, v };
|
|
67
47
|
}
|
|
48
|
+
/** Get the chain ID of the wallet. */
|
|
49
|
+
async function getWalletChainId(wallet) {
|
|
50
|
+
if ((0, viem_js_1.isAbstractViemWallet)(wallet)) {
|
|
51
|
+
if ("getChainId" in wallet && wallet.getChainId) {
|
|
52
|
+
const chainId = await wallet.getChainId();
|
|
53
|
+
return `0x${chainId.toString(16)}`;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return "0x1";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if ((0, ethers_js_1.isAbstractEthersV6Signer)(wallet) || (0, ethers_js_1.isAbstractEthersV5Signer)(wallet)) {
|
|
60
|
+
if ("provider" in wallet && wallet.provider) {
|
|
61
|
+
const network = await wallet.provider.getNetwork();
|
|
62
|
+
return `0x${network.chainId.toString(16)}`;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return "0x1";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return "0x1";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Get the wallet address from various wallet types. */
|
|
73
|
+
async function getWalletAddress(wallet) {
|
|
74
|
+
if ((0, viem_js_1.isAbstractViemWallet)(wallet)) {
|
|
75
|
+
if ("address" in wallet && wallet.address) {
|
|
76
|
+
return wallet.address;
|
|
77
|
+
}
|
|
78
|
+
else if ("getAddresses" in wallet && wallet.getAddresses) {
|
|
79
|
+
const addresses = await wallet.getAddresses();
|
|
80
|
+
return addresses[0];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if ((0, ethers_js_1.isAbstractEthersV6Signer)(wallet) || (0, ethers_js_1.isAbstractEthersV5Signer)(wallet)) {
|
|
84
|
+
if ("getAddress" in wallet && wallet.getAddress) {
|
|
85
|
+
return await wallet.getAddress();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if ((0, private_key_js_1.isValidPrivateKey)(wallet)) {
|
|
89
|
+
return (0, private_key_js_1.privateKeyToAddress)(wallet);
|
|
90
|
+
}
|
|
91
|
+
throw new Error("Unsupported wallet for getting address");
|
|
92
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
type Hex = `0x${string}`;
|
|
2
1
|
interface Types {
|
|
3
2
|
[type: string]: {
|
|
4
3
|
name: string;
|
|
@@ -8,9 +7,9 @@ interface Types {
|
|
|
8
7
|
interface Domain extends Record<string, unknown> {
|
|
9
8
|
name?: string;
|
|
10
9
|
version?: string;
|
|
11
|
-
chainId?: number | string | bigint |
|
|
12
|
-
verifyingContract?:
|
|
13
|
-
salt?:
|
|
10
|
+
chainId?: number | string | bigint | `0x${string}`;
|
|
11
|
+
verifyingContract?: `0x${string}`;
|
|
12
|
+
salt?: `0x${string}`;
|
|
14
13
|
}
|
|
15
14
|
/** Signs typed data with a private key. */
|
|
16
15
|
export declare function signTypedData(args: {
|
|
@@ -19,8 +18,10 @@ export declare function signTypedData(args: {
|
|
|
19
18
|
types: Types;
|
|
20
19
|
primaryType: string;
|
|
21
20
|
message: Record<string, unknown>;
|
|
22
|
-
}): Promise
|
|
21
|
+
}): Promise<`0x${string}`>;
|
|
23
22
|
/** Validates if a string is a valid secp256k1 private key. */
|
|
24
23
|
export declare function isValidPrivateKey(privateKey: unknown): privateKey is string;
|
|
24
|
+
/** Converts a private key to an Ethereum address. */
|
|
25
|
+
export declare function privateKeyToAddress(privateKey: string): `0x${string}`;
|
|
25
26
|
export {};
|
|
26
27
|
//# sourceMappingURL=private_key.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private_key.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/private_key.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"private_key.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/private_key.ts"],"names":[],"mappings":"AAGA,UAAU,KAAK;IACX,CAAC,IAAI,EAAE,MAAM,GAAG;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KAChB,EAAE,CAAC;CACP;AAED,UAAU,MAAO,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;IACnD,iBAAiB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAClC,IAAI,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CACxB;AAED,2CAA2C;AAC3C,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAkBzB;AAsKD,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,MAAM,CAG3E;AAED,qDAAqD;AACrD,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAYrE"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.signTypedData = signTypedData;
|
|
4
4
|
exports.isValidPrivateKey = isValidPrivateKey;
|
|
5
|
+
exports.privateKeyToAddress = privateKeyToAddress;
|
|
5
6
|
const sha3_1 = require("@noble/hashes/sha3");
|
|
6
7
|
const secp256k1_1 = require("@noble/secp256k1");
|
|
7
8
|
/** Signs typed data with a private key. */
|
|
@@ -51,20 +52,27 @@ function encodeType(primaryType, types) {
|
|
|
51
52
|
const deps = findTypeDependencies(primaryType, types);
|
|
52
53
|
const sortedDeps = [primaryType, ...deps.filter((d) => d !== primaryType).sort()];
|
|
53
54
|
return sortedDeps
|
|
54
|
-
.map((type) => `${type}(${types[type].map((field) => `${field.type} ${field.name}`).join(",")})`)
|
|
55
|
+
.map((type) => `${type}(${types[type].map((field) => `${resolveTypeAlias(field.type)} ${field.name}`).join(",")})`)
|
|
55
56
|
.join("");
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
if (
|
|
58
|
+
function resolveTypeAlias(type) {
|
|
59
|
+
if (type === "uint")
|
|
60
|
+
return "uint256";
|
|
61
|
+
if (type === "int")
|
|
62
|
+
return "int256";
|
|
63
|
+
return type;
|
|
64
|
+
}
|
|
65
|
+
function findTypeDependencies(primaryType, types, _found = new Set()) {
|
|
66
|
+
if (_found.has(primaryType) || !types[primaryType])
|
|
59
67
|
return [];
|
|
60
|
-
|
|
68
|
+
_found.add(primaryType);
|
|
61
69
|
for (const field of types[primaryType]) {
|
|
62
|
-
const baseType = field.type.replace(/\[
|
|
70
|
+
const baseType = field.type.replace(/\[.*?\]/g, "");
|
|
63
71
|
if (types[baseType]) {
|
|
64
|
-
findTypeDependencies(baseType, types,
|
|
72
|
+
findTypeDependencies(baseType, types, _found);
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
|
-
return Array.from(
|
|
75
|
+
return Array.from(_found);
|
|
68
76
|
}
|
|
69
77
|
function encodeValue(type, value, types) {
|
|
70
78
|
const arrayMatch = type.match(/^(.*)\[(\d*)\]$/);
|
|
@@ -72,10 +80,10 @@ function encodeValue(type, value, types) {
|
|
|
72
80
|
// Extract type info: base type and optional length
|
|
73
81
|
const [, baseType, len] = arrayMatch;
|
|
74
82
|
if (!Array.isArray(value)) {
|
|
75
|
-
throw new Error(`Expected array for ${type}
|
|
83
|
+
throw new Error(`Expected array for ${type}. Received: ${typeof value}`);
|
|
76
84
|
}
|
|
77
85
|
if (len && value.length !== +len) {
|
|
78
|
-
throw new Error(`Invalid length for ${type}: expected ${len}
|
|
86
|
+
throw new Error(`Invalid length for ${type}: expected ${len}. Received: ${value.length}`);
|
|
79
87
|
}
|
|
80
88
|
// Encode each element in the array and hash them together
|
|
81
89
|
const encodedElements = value.map((v) => encodeValue(baseType, v, types));
|
|
@@ -91,8 +99,9 @@ function encodeValue(type, value, types) {
|
|
|
91
99
|
}
|
|
92
100
|
if (type === "address") {
|
|
93
101
|
const bytes = secp256k1_1.etc.hexToBytes(cleanHex(value));
|
|
94
|
-
if (bytes.length !== 20)
|
|
95
|
-
throw new Error(
|
|
102
|
+
if (bytes.length !== 20) {
|
|
103
|
+
throw new Error(`Address must be 20 bytes.`);
|
|
104
|
+
}
|
|
96
105
|
const padded = new Uint8Array(32);
|
|
97
106
|
padded.set(bytes, 12);
|
|
98
107
|
return padded;
|
|
@@ -100,9 +109,10 @@ function encodeValue(type, value, types) {
|
|
|
100
109
|
if (type.startsWith("uint") || type.startsWith("int")) {
|
|
101
110
|
// Extract type info: uint/int and bit size
|
|
102
111
|
const isUint = type.startsWith("uint");
|
|
103
|
-
const
|
|
112
|
+
const bitsStr = type.slice(isUint ? 4 : 3);
|
|
113
|
+
const bits = parseInt(bitsStr || "256");
|
|
104
114
|
if (bits > 256 || bits % 8 !== 0) {
|
|
105
|
-
throw new Error(`
|
|
115
|
+
throw new Error(`Invalid ${isUint ? "uint" : "int"} size: ${bitsStr}. Must be 8-256 in steps of 8`);
|
|
106
116
|
}
|
|
107
117
|
// Apply Two's complement for specified bit size
|
|
108
118
|
const bigIntValue = BigInt(value);
|
|
@@ -124,18 +134,20 @@ function encodeValue(type, value, types) {
|
|
|
124
134
|
if (bytesMatch) {
|
|
125
135
|
// Extract type info: bytes size
|
|
126
136
|
const size = parseInt(bytesMatch[1]);
|
|
127
|
-
if (size === 0 || size > 32)
|
|
128
|
-
throw new Error(`
|
|
137
|
+
if (size === 0 || size > 32) {
|
|
138
|
+
throw new Error(`bytesN size must be 1-32. Received: ${size}`);
|
|
139
|
+
}
|
|
129
140
|
// Convert hex to bytes
|
|
130
141
|
const bytes = secp256k1_1.etc.hexToBytes(cleanHex(value));
|
|
131
|
-
if (bytes.length !== size)
|
|
132
|
-
throw new Error(
|
|
142
|
+
if (bytes.length !== size) {
|
|
143
|
+
throw new Error(`${type} requires exactly ${size} bytes. Received: ${bytes.length} from '${value}'`);
|
|
144
|
+
}
|
|
133
145
|
// Pad to 32 bytes
|
|
134
146
|
const padded = new Uint8Array(32);
|
|
135
147
|
padded.set(bytes, 0);
|
|
136
148
|
return padded;
|
|
137
149
|
}
|
|
138
|
-
throw new Error(`Unsupported type: ${type}
|
|
150
|
+
throw new Error(`Unsupported type: '${type}'.`);
|
|
139
151
|
}
|
|
140
152
|
function cleanHex(hex) {
|
|
141
153
|
return hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
@@ -146,3 +158,13 @@ function isValidPrivateKey(privateKey) {
|
|
|
146
158
|
return false;
|
|
147
159
|
return secp256k1_1.utils.isValidPrivateKey(cleanHex(privateKey));
|
|
148
160
|
}
|
|
161
|
+
/** Converts a private key to an Ethereum address. */
|
|
162
|
+
function privateKeyToAddress(privateKey) {
|
|
163
|
+
const cleanPrivKey = cleanHex(privateKey);
|
|
164
|
+
const publicKey = (0, secp256k1_1.getPublicKey)(cleanPrivKey, false);
|
|
165
|
+
const publicKeyWithoutPrefix = publicKey.slice(1);
|
|
166
|
+
const hash = (0, sha3_1.keccak_256)(publicKeyWithoutPrefix);
|
|
167
|
+
const addressBytes = hash.slice(-20);
|
|
168
|
+
const address = secp256k1_1.etc.bytesToHex(addressBytes);
|
|
169
|
+
return `0x${address}`;
|
|
170
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface AbstractViemWalletClient {
|
|
1
|
+
/** Abstract interface for a viem {@link https://viem.sh/docs/accounts/jsonRpc#json-rpc-account | JSON-RPC Account}. */
|
|
2
|
+
export interface AbstractViemJsonRpcAccount {
|
|
4
3
|
signTypedData(params: {
|
|
5
4
|
domain: {
|
|
6
5
|
name: string;
|
|
7
6
|
version: string;
|
|
8
7
|
chainId: number;
|
|
9
|
-
verifyingContract:
|
|
8
|
+
verifyingContract: `0x${string}`;
|
|
10
9
|
};
|
|
11
10
|
types: {
|
|
12
11
|
[key: string]: {
|
|
@@ -16,8 +15,30 @@ export interface AbstractViemWalletClient {
|
|
|
16
15
|
};
|
|
17
16
|
primaryType: string;
|
|
18
17
|
message: Record<string, unknown>;
|
|
19
|
-
}, options?: unknown): Promise
|
|
18
|
+
}, options?: unknown): Promise<`0x${string}`>;
|
|
19
|
+
getAddresses?(): Promise<`0x${string}`[]>;
|
|
20
|
+
getChainId?(): Promise<number>;
|
|
21
|
+
}
|
|
22
|
+
/** Abstract interface for a viem {@link https://viem.sh/docs/accounts/local | Local Account}. */
|
|
23
|
+
export interface AbstractViemLocalAccount {
|
|
24
|
+
signTypedData(params: {
|
|
25
|
+
domain: {
|
|
26
|
+
name: string;
|
|
27
|
+
version: string;
|
|
28
|
+
chainId: number;
|
|
29
|
+
verifyingContract: `0x${string}`;
|
|
30
|
+
};
|
|
31
|
+
types: {
|
|
32
|
+
[key: string]: {
|
|
33
|
+
name: string;
|
|
34
|
+
type: string;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
primaryType: string;
|
|
38
|
+
message: Record<string, unknown>;
|
|
39
|
+
}, options?: unknown): Promise<`0x${string}`>;
|
|
40
|
+
address?: `0x${string}`;
|
|
20
41
|
}
|
|
21
42
|
/** Checks if the given value is an abstract viem wallet. */
|
|
22
|
-
export declare function
|
|
43
|
+
export declare function isAbstractViemWallet(client: unknown): client is AbstractViemJsonRpcAccount | AbstractViemLocalAccount;
|
|
23
44
|
//# sourceMappingURL=viem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/viem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/viem.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,MAAM,WAAW,0BAA0B;IACvC,aAAa,CACT,MAAM,EAAE;QACJ,MAAM,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAC;SACpC,CAAC;QACF,KAAK,EAAE;YACH,CAAC,GAAG,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,IAAI,EAAE,MAAM,CAAC;aAChB,EAAE,CAAC;SACP,CAAC;QACF,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,EACD,OAAO,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IAC1B,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1C,UAAU,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAClC;AAED,iGAAiG;AACjG,MAAM,WAAW,wBAAwB;IACrC,aAAa,CACT,MAAM,EAAE;QACJ,MAAM,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAC;SACpC,CAAC;QACF,KAAK,EAAE;YACH,CAAC,GAAG,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,IAAI,EAAE,MAAM,CAAC;aAChB,EAAE,CAAC;SACP,CAAC;QACF,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,EACD,OAAO,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IAC1B,OAAO,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CAC3B;AAED,4DAA4D;AAC5D,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,0BAA0B,GAAG,wBAAwB,CAIrH"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isAbstractViemWallet = isAbstractViemWallet;
|
|
4
4
|
/** Checks if the given value is an abstract viem wallet. */
|
|
5
|
-
function
|
|
5
|
+
function isAbstractViemWallet(client) {
|
|
6
6
|
return typeof client === "object" && client !== null &&
|
|
7
7
|
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
8
8
|
(client.signTypedData.length === 1 || client.signTypedData.length === 2);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ApproveAgentRequest, ApproveBuilderFeeRequest, BatchModifyRequest, CancelByCloidRequest, CancelRequest, CDepositRequest, ClaimRewardsRequest, ConvertToMultiSigUserRequest, ConvertToMultiSigUserRequestWithoutStringify, CreateSubAccountRequest, CreateVaultRequest, CSignerActionRequest, CValidatorActionRequest, CWithdrawRequest, EvmUserModifyRequest, ModifyRequest, MultiSigRequest, OrderRequest, PerpDeployRequest, RegisterReferrerRequest, ReserveRequestWeightRequest, ScheduleCancelRequest, SetDisplayNameRequest, SetReferrerRequest, SpotDeployRequest, SpotSendRequest, SpotUserRequest, SubAccountModifyRequest, SubAccountSpotTransferRequest, SubAccountTransferRequest, TokenDelegateRequest, TwapCancelRequest, TwapOrderRequest, UpdateIsolatedMarginRequest, UpdateLeverageRequest, UsdClassTransferRequest, UsdSendRequest, VaultDistributeRequest, VaultModifyRequest, VaultTransferRequest, Withdraw3Request } from "../types/mod.js";
|
|
2
|
+
/** @see https://github.com/microsoft/TypeScript/issues/13923#issuecomment-2191862501 */
|
|
3
|
+
type DeepImmutable<T> = {
|
|
4
|
+
readonly [K in keyof T]: DeepImmutable<T[K]>;
|
|
5
|
+
};
|
|
3
6
|
/** Action sorter and formatter for correct signature generation. */
|
|
4
7
|
export declare const actionSorter: {
|
|
5
8
|
approveAgent: (action: DeepImmutable<ApproveAgentRequest["action"]>) => ApproveAgentRequest["action"];
|
|
@@ -9,27 +12,26 @@ export declare const actionSorter: {
|
|
|
9
12
|
cancelByCloid: (action: DeepImmutable<CancelByCloidRequest["action"]>) => CancelByCloidRequest["action"];
|
|
10
13
|
cDeposit: (action: DeepImmutable<CDepositRequest["action"]>) => CDepositRequest["action"];
|
|
11
14
|
claimRewards: (action: DeepImmutable<ClaimRewardsRequest["action"]>) => ClaimRewardsRequest["action"];
|
|
12
|
-
convertToMultiSigUser: (action: DeepImmutable<ConvertToMultiSigUserRequest["action"]>) => ConvertToMultiSigUserRequest["action"];
|
|
15
|
+
convertToMultiSigUser: (action: DeepImmutable<ConvertToMultiSigUserRequest["action"] | ConvertToMultiSigUserRequestWithoutStringify["action"]>) => ConvertToMultiSigUserRequest["action"];
|
|
13
16
|
createSubAccount: (action: DeepImmutable<CreateSubAccountRequest["action"]>) => CreateSubAccountRequest["action"];
|
|
14
17
|
createVault: (action: DeepImmutable<CreateVaultRequest["action"]>) => CreateVaultRequest["action"];
|
|
15
|
-
CSignerAction: (action: DeepImmutable<
|
|
16
|
-
CValidatorAction: (action: DeepImmutable<
|
|
18
|
+
CSignerAction: (action: DeepImmutable<CSignerActionRequest["action"]>) => CSignerActionRequest["action"];
|
|
19
|
+
CValidatorAction: (action: DeepImmutable<CValidatorActionRequest["action"]>) => CValidatorActionRequest["action"];
|
|
17
20
|
cWithdraw: (action: DeepImmutable<CWithdrawRequest["action"]>) => CWithdrawRequest["action"];
|
|
18
21
|
evmUserModify: (action: DeepImmutable<EvmUserModifyRequest["action"]>) => EvmUserModifyRequest["action"];
|
|
19
22
|
modify: (action: DeepImmutable<ModifyRequest["action"]>) => ModifyRequest["action"];
|
|
20
23
|
multiSig: (action: DeepImmutable<MultiSigRequest["action"]>) => MultiSigRequest["action"];
|
|
21
24
|
order: (action: DeepImmutable<OrderRequest["action"]>) => OrderRequest["action"];
|
|
22
|
-
perpDeploy: (action: DeepImmutable<
|
|
23
|
-
PerpDexClassTransfer: (action: DeepImmutable<PerpDexClassTransferRequest["action"]>) => PerpDexClassTransferRequest["action"];
|
|
24
|
-
PerpDexTransfer: (action: DeepImmutable<PerpDexTransferRequest["action"]>) => PerpDexTransferRequest["action"];
|
|
25
|
+
perpDeploy: (action: DeepImmutable<PerpDeployRequest["action"]>) => PerpDeployRequest["action"];
|
|
25
26
|
registerReferrer: (action: DeepImmutable<RegisterReferrerRequest["action"]>) => RegisterReferrerRequest["action"];
|
|
26
27
|
reserveRequestWeight: (action: DeepImmutable<ReserveRequestWeightRequest["action"]>) => ReserveRequestWeightRequest["action"];
|
|
27
28
|
scheduleCancel: (action: DeepImmutable<ScheduleCancelRequest["action"]>) => ScheduleCancelRequest["action"];
|
|
28
29
|
setDisplayName: (action: DeepImmutable<SetDisplayNameRequest["action"]>) => SetDisplayNameRequest["action"];
|
|
29
30
|
setReferrer: (action: DeepImmutable<SetReferrerRequest["action"]>) => SetReferrerRequest["action"];
|
|
30
|
-
spotDeploy: (action: DeepImmutable<
|
|
31
|
+
spotDeploy: (action: DeepImmutable<SpotDeployRequest["action"]>) => SpotDeployRequest["action"];
|
|
31
32
|
spotSend: (action: DeepImmutable<SpotSendRequest["action"]>) => SpotSendRequest["action"];
|
|
32
33
|
spotUser: (action: DeepImmutable<SpotUserRequest["action"]>) => SpotUserRequest["action"];
|
|
34
|
+
subAccountModify: (action: DeepImmutable<SubAccountModifyRequest["action"]>) => SubAccountModifyRequest["action"];
|
|
33
35
|
subAccountSpotTransfer: (action: DeepImmutable<SubAccountSpotTransferRequest["action"]>) => SubAccountSpotTransferRequest["action"];
|
|
34
36
|
subAccountTransfer: (action: DeepImmutable<SubAccountTransferRequest["action"]>) => SubAccountTransferRequest["action"];
|
|
35
37
|
tokenDelegate: (action: DeepImmutable<TokenDelegateRequest["action"]>) => TokenDelegateRequest["action"];
|
|
@@ -76,18 +78,6 @@ export declare const userSignedActionEip712Types: {
|
|
|
76
78
|
type: string;
|
|
77
79
|
}[];
|
|
78
80
|
};
|
|
79
|
-
PerpDexClassTransfer: {
|
|
80
|
-
"HyperliquidTransaction:PerpDexClassTransfer": {
|
|
81
|
-
name: string;
|
|
82
|
-
type: string;
|
|
83
|
-
}[];
|
|
84
|
-
};
|
|
85
|
-
PerpDexTransfer: {
|
|
86
|
-
"HyperliquidTransaction:PerpDexTransfer": {
|
|
87
|
-
name: string;
|
|
88
|
-
type: string;
|
|
89
|
-
}[];
|
|
90
|
-
};
|
|
91
81
|
multiSig: {
|
|
92
82
|
"HyperliquidTransaction:SendMultiSig": {
|
|
93
83
|
name: string;
|
|
@@ -125,4 +115,5 @@ export declare const userSignedActionEip712Types: {
|
|
|
125
115
|
}[];
|
|
126
116
|
};
|
|
127
117
|
};
|
|
118
|
+
export {};
|
|
128
119
|
//# sourceMappingURL=_sorter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_sorter.d.ts","sourceRoot":"","sources":["../../../src/src/signing/_sorter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"_sorter.d.ts","sourceRoot":"","sources":["../../../src/src/signing/_sorter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB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AAG,qBAAqB,CAAC,QAAQ,CAAC;+BAQ9E,aAAa,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,KAAG,uBAAuB,CAAC,QAAQ,CAAC;sBAU7F,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,KAAG,cAAc,CAAC,QAAQ,CAAC;8BAU1D,aAAa,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,KAAG,sBAAsB,CAAC,QAAQ,CAAC;0BAOtF,aAAa,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,KAAG,kBAAkB,CAAC,QAAQ,CAAC;4BAQxE,aAAa,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,KAAG,oBAAoB,CAAC,QAAQ,CAAC;wBAQlF,aAAa,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,KAAG,gBAAgB,CAAC,QAAQ,CAAC;CAU7F,CAAC;AAYF,wDAAwD;AACxD,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFvC,CAAC"}
|
|
@@ -9,7 +9,7 @@ exports.actionSorter = {
|
|
|
9
9
|
signatureChainId: action.signatureChainId,
|
|
10
10
|
hyperliquidChain: action.hyperliquidChain,
|
|
11
11
|
agentAddress: action.agentAddress.toLowerCase(),
|
|
12
|
-
agentName: action.agentName
|
|
12
|
+
agentName: action.agentName,
|
|
13
13
|
nonce: action.nonce,
|
|
14
14
|
};
|
|
15
15
|
},
|
|
@@ -94,7 +94,10 @@ exports.actionSorter = {
|
|
|
94
94
|
type: action.type,
|
|
95
95
|
signatureChainId: action.signatureChainId,
|
|
96
96
|
hyperliquidChain: action.hyperliquidChain,
|
|
97
|
-
signers: action.signers
|
|
97
|
+
signers: typeof action.signers === "string" ? action.signers : JSON.stringify(action.signers === null ? action.signers : {
|
|
98
|
+
authorizedUsers: action.signers.authorizedUsers,
|
|
99
|
+
threshold: action.signers.threshold,
|
|
100
|
+
}),
|
|
98
101
|
nonce: action.nonce,
|
|
99
102
|
};
|
|
100
103
|
},
|
|
@@ -132,13 +135,13 @@ exports.actionSorter = {
|
|
|
132
135
|
return {
|
|
133
136
|
type: action.type,
|
|
134
137
|
changeProfile: {
|
|
135
|
-
node_ip: action.changeProfile.node_ip
|
|
136
|
-
name: action.changeProfile.name
|
|
137
|
-
description: action.changeProfile.description
|
|
138
|
+
node_ip: action.changeProfile.node_ip,
|
|
139
|
+
name: action.changeProfile.name,
|
|
140
|
+
description: action.changeProfile.description,
|
|
138
141
|
unjailed: action.changeProfile.unjailed,
|
|
139
|
-
disable_delegations: action.changeProfile.disable_delegations
|
|
140
|
-
commission_bps: action.changeProfile.commission_bps
|
|
141
|
-
signer: action.changeProfile.signer?.toLowerCase()
|
|
142
|
+
disable_delegations: action.changeProfile.disable_delegations,
|
|
143
|
+
commission_bps: action.changeProfile.commission_bps,
|
|
144
|
+
signer: action.changeProfile.signer?.toLowerCase(),
|
|
142
145
|
},
|
|
143
146
|
};
|
|
144
147
|
}
|
|
@@ -161,7 +164,7 @@ exports.actionSorter = {
|
|
|
161
164
|
},
|
|
162
165
|
};
|
|
163
166
|
}
|
|
164
|
-
else {
|
|
167
|
+
else {
|
|
165
168
|
return {
|
|
166
169
|
type: action.type,
|
|
167
170
|
unregister: action.unregister,
|
|
@@ -225,7 +228,9 @@ exports.actionSorter = {
|
|
|
225
228
|
payload: {
|
|
226
229
|
multiSigUser: action.payload.multiSigUser.toLowerCase(),
|
|
227
230
|
outerSigner: action.payload.outerSigner.toLowerCase(),
|
|
228
|
-
action:
|
|
231
|
+
action: exports.actionSorter[action.payload.action.type](
|
|
232
|
+
// @ts-ignore - TypeScript cannot infer the type correctly
|
|
233
|
+
action.payload.action),
|
|
229
234
|
},
|
|
230
235
|
};
|
|
231
236
|
},
|
|
@@ -275,7 +280,7 @@ exports.actionSorter = {
|
|
|
275
280
|
return {
|
|
276
281
|
type: action.type,
|
|
277
282
|
registerAsset: {
|
|
278
|
-
maxGas: action.registerAsset.maxGas
|
|
283
|
+
maxGas: action.registerAsset.maxGas,
|
|
279
284
|
assetRequest: {
|
|
280
285
|
coin: action.registerAsset.assetRequest.coin,
|
|
281
286
|
szDecimals: action.registerAsset.assetRequest.szDecimals,
|
|
@@ -288,9 +293,9 @@ exports.actionSorter = {
|
|
|
288
293
|
? {
|
|
289
294
|
fullName: action.registerAsset.schema.fullName,
|
|
290
295
|
collateralToken: action.registerAsset.schema.collateralToken,
|
|
291
|
-
oracleUpdater: action.registerAsset.schema.oracleUpdater?.toLowerCase()
|
|
296
|
+
oracleUpdater: action.registerAsset.schema.oracleUpdater?.toLowerCase(),
|
|
292
297
|
}
|
|
293
|
-
:
|
|
298
|
+
: action.registerAsset.schema,
|
|
294
299
|
},
|
|
295
300
|
};
|
|
296
301
|
}
|
|
@@ -300,34 +305,11 @@ exports.actionSorter = {
|
|
|
300
305
|
setOracle: {
|
|
301
306
|
dex: action.setOracle.dex,
|
|
302
307
|
oraclePxs: action.setOracle.oraclePxs.map((el) => [...el]),
|
|
303
|
-
markPxs: action.setOracle.markPxs.map((el) => [...
|
|
308
|
+
markPxs: action.setOracle.markPxs.map((el) => el.map((el2) => [...el2])),
|
|
304
309
|
},
|
|
305
310
|
};
|
|
306
311
|
}
|
|
307
312
|
},
|
|
308
|
-
PerpDexClassTransfer: (action) => {
|
|
309
|
-
return {
|
|
310
|
-
type: action.type,
|
|
311
|
-
signatureChainId: action.signatureChainId,
|
|
312
|
-
hyperliquidChain: action.hyperliquidChain,
|
|
313
|
-
dex: action.dex,
|
|
314
|
-
token: action.token,
|
|
315
|
-
amount: action.amount,
|
|
316
|
-
toPerp: action.toPerp,
|
|
317
|
-
nonce: action.nonce,
|
|
318
|
-
};
|
|
319
|
-
},
|
|
320
|
-
PerpDexTransfer: (action) => {
|
|
321
|
-
return {
|
|
322
|
-
type: action.type,
|
|
323
|
-
signatureChainId: action.signatureChainId,
|
|
324
|
-
hyperliquidChain: action.hyperliquidChain,
|
|
325
|
-
sourceDex: action.sourceDex,
|
|
326
|
-
destinationDex: action.destinationDex,
|
|
327
|
-
amount: action.amount,
|
|
328
|
-
nonce: action.nonce,
|
|
329
|
-
};
|
|
330
|
-
},
|
|
331
313
|
registerReferrer: (action) => {
|
|
332
314
|
return {
|
|
333
315
|
type: action.type,
|
|
@@ -371,9 +353,8 @@ exports.actionSorter = {
|
|
|
371
353
|
noHyperliquidity: action.genesis.noHyperliquidity,
|
|
372
354
|
},
|
|
373
355
|
};
|
|
374
|
-
if (sortedAction.genesis.noHyperliquidity === undefined)
|
|
356
|
+
if (sortedAction.genesis.noHyperliquidity === undefined)
|
|
375
357
|
delete sortedAction.genesis.noHyperliquidity;
|
|
376
|
-
}
|
|
377
358
|
return sortedAction;
|
|
378
359
|
}
|
|
379
360
|
else if ("registerHyperliquidity" in action) {
|
|
@@ -413,9 +394,8 @@ exports.actionSorter = {
|
|
|
413
394
|
fullName: action.registerToken2.fullName,
|
|
414
395
|
},
|
|
415
396
|
};
|
|
416
|
-
if (sortedAction.registerToken2.fullName === undefined)
|
|
397
|
+
if (sortedAction.registerToken2.fullName === undefined)
|
|
417
398
|
delete sortedAction.registerToken2.fullName;
|
|
418
|
-
}
|
|
419
399
|
return sortedAction;
|
|
420
400
|
}
|
|
421
401
|
else if ("setDeployerTradingFeeShare" in action) {
|
|
@@ -427,7 +407,7 @@ exports.actionSorter = {
|
|
|
427
407
|
},
|
|
428
408
|
};
|
|
429
409
|
}
|
|
430
|
-
else {
|
|
410
|
+
else {
|
|
431
411
|
const sortedAction = {
|
|
432
412
|
type: action.type,
|
|
433
413
|
userGenesis: {
|
|
@@ -437,9 +417,8 @@ exports.actionSorter = {
|
|
|
437
417
|
blacklistUsers: action.userGenesis.blacklistUsers?.map((el) => [...el]),
|
|
438
418
|
},
|
|
439
419
|
};
|
|
440
|
-
if (sortedAction.userGenesis.blacklistUsers === undefined)
|
|
420
|
+
if (sortedAction.userGenesis.blacklistUsers === undefined)
|
|
441
421
|
delete sortedAction.userGenesis.blacklistUsers;
|
|
442
|
-
}
|
|
443
422
|
return sortedAction;
|
|
444
423
|
}
|
|
445
424
|
},
|
|
@@ -462,6 +441,13 @@ exports.actionSorter = {
|
|
|
462
441
|
},
|
|
463
442
|
};
|
|
464
443
|
},
|
|
444
|
+
subAccountModify: (action) => {
|
|
445
|
+
return {
|
|
446
|
+
type: action.type,
|
|
447
|
+
subAccountUser: action.subAccountUser.toLowerCase(),
|
|
448
|
+
name: action.name,
|
|
449
|
+
};
|
|
450
|
+
},
|
|
465
451
|
subAccountSpotTransfer: (action) => {
|
|
466
452
|
return {
|
|
467
453
|
type: action.type,
|
|
@@ -627,25 +613,6 @@ exports.userSignedActionEip712Types = {
|
|
|
627
613
|
{ name: "nonce", type: "uint64" },
|
|
628
614
|
],
|
|
629
615
|
},
|
|
630
|
-
PerpDexClassTransfer: {
|
|
631
|
-
"HyperliquidTransaction:PerpDexClassTransfer": [
|
|
632
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
633
|
-
{ name: "dex", type: "string" },
|
|
634
|
-
{ name: "token", type: "string" },
|
|
635
|
-
{ name: "amount", type: "string" },
|
|
636
|
-
{ name: "toPerp", type: "bool" },
|
|
637
|
-
{ name: "nonce", type: "uint64" },
|
|
638
|
-
],
|
|
639
|
-
},
|
|
640
|
-
PerpDexTransfer: {
|
|
641
|
-
"HyperliquidTransaction:PerpDexTransfer": [
|
|
642
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
643
|
-
{ name: "sourceDex", type: "string" },
|
|
644
|
-
{ name: "destinationDex", type: "string" },
|
|
645
|
-
{ name: "amount", type: "string" },
|
|
646
|
-
{ name: "nonce", type: "uint64" },
|
|
647
|
-
],
|
|
648
|
-
},
|
|
649
616
|
multiSig: {
|
|
650
617
|
"HyperliquidTransaction:SendMultiSig": [
|
|
651
618
|
{ name: "hyperliquidChain", type: "string" },
|