@nktkas/hyperliquid 0.25.0-beta.3 → 0.25.0-beta.4
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 +108 -116
- package/esm/bin/_utils.d.ts +80 -0
- package/esm/bin/_utils.d.ts.map +1 -0
- package/esm/bin/_utils.js +112 -0
- package/esm/bin/_utils.js.map +1 -0
- package/esm/bin/cli.js +43 -161
- package/esm/bin/cli.js.map +1 -1
- package/esm/src/clients/exchange.d.ts +93 -93
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +63 -58
- package/esm/src/clients/exchange.js.map +1 -1
- package/esm/src/clients/info.d.ts +113 -113
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +70 -73
- package/esm/src/clients/info.js.map +1 -1
- package/esm/src/clients/multiSign.d.ts +3 -3
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +4 -2
- package/esm/src/clients/multiSign.js.map +1 -1
- package/esm/src/clients/subscription.d.ts +23 -23
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +8 -11
- package/esm/src/clients/subscription.js.map +1 -1
- package/esm/src/schemas/_base.d.ts +6 -8
- package/esm/src/schemas/_base.d.ts.map +1 -1
- package/esm/src/schemas/_base.js +5 -28
- package/esm/src/schemas/_base.js.map +1 -1
- package/esm/src/schemas/exchange/requests.d.ts +1676 -1657
- package/esm/src/schemas/exchange/requests.d.ts.map +1 -1
- package/esm/src/schemas/exchange/requests.js +195 -199
- package/esm/src/schemas/exchange/requests.js.map +1 -1
- package/esm/src/schemas/exchange/responses.d.ts +10 -10
- package/esm/src/schemas/exchange/responses.js +3 -3
- package/esm/src/schemas/exchange/responses.js.map +1 -1
- package/esm/src/schemas/explorer/requests.d.ts +2 -2
- package/esm/src/schemas/explorer/requests.js +3 -3
- package/esm/src/schemas/explorer/requests.js.map +1 -1
- package/esm/src/schemas/explorer/responses.d.ts +16 -16
- package/esm/src/schemas/explorer/responses.js +3 -3
- package/esm/src/schemas/explorer/responses.js.map +1 -1
- package/esm/src/schemas/info/accounts.d.ts +298 -298
- package/esm/src/schemas/info/accounts.js +24 -24
- package/esm/src/schemas/info/accounts.js.map +1 -1
- package/esm/src/schemas/info/assets.d.ts +110 -110
- package/esm/src/schemas/info/assets.js +9 -9
- package/esm/src/schemas/info/assets.js.map +1 -1
- package/esm/src/schemas/info/markets.d.ts +25 -25
- package/esm/src/schemas/info/markets.js +3 -3
- package/esm/src/schemas/info/markets.js.map +1 -1
- package/esm/src/schemas/info/orders.d.ts +104 -104
- package/esm/src/schemas/info/orders.js +3 -3
- package/esm/src/schemas/info/orders.js.map +1 -1
- package/esm/src/schemas/info/requests.d.ts +32 -32
- package/esm/src/schemas/info/requests.js +55 -55
- package/esm/src/schemas/info/requests.js.map +1 -1
- package/esm/src/schemas/info/validators.d.ts +27 -27
- package/esm/src/schemas/info/validators.js +6 -6
- package/esm/src/schemas/info/validators.js.map +1 -1
- package/esm/src/schemas/info/vaults.d.ts +46 -46
- package/esm/src/schemas/info/vaults.js +10 -10
- package/esm/src/schemas/info/vaults.js.map +1 -1
- package/esm/src/schemas/subscriptions/requests.d.ts +4 -4
- package/esm/src/schemas/subscriptions/requests.js +17 -17
- package/esm/src/schemas/subscriptions/requests.js.map +1 -1
- package/esm/src/schemas/subscriptions/responses.d.ts +401 -401
- package/esm/src/schemas/subscriptions/responses.js +14 -14
- package/esm/src/schemas/subscriptions/responses.js.map +1 -1
- package/esm/src/signing/mod.js +4 -4
- package/esm/src/signing/mod.js.map +1 -1
- package/esm/src/signing/signTypedData/private_key.js +16 -16
- package/esm/src/signing/signTypedData/private_key.js.map +1 -1
- package/esm/src/transports/_polyfills.d.ts +12 -0
- package/esm/src/transports/_polyfills.d.ts.map +1 -0
- package/esm/src/transports/_polyfills.js +40 -0
- package/esm/src/transports/_polyfills.js.map +1 -0
- package/esm/src/transports/base.d.ts +6 -6
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.d.ts +11 -4
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +17 -6
- package/esm/src/transports/http/http_transport.js.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +8 -7
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +14 -33
- package/esm/src/transports/websocket/_hyperliquid_event_target.js.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +26 -29
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +82 -76
- package/esm/src/transports/websocket/_reconnecting_websocket.js.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.d.ts +6 -0
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +49 -41
- package/esm/src/transports/websocket/_websocket_async_request.js.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.d.ts +48 -70
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +90 -103
- package/esm/src/transports/websocket/websocket_transport.js.map +1 -1
- package/package.json +3 -7
- package/script/bin/_utils.d.ts +80 -0
- package/script/bin/_utils.d.ts.map +1 -0
- package/script/bin/_utils.js +116 -0
- package/script/bin/_utils.js.map +1 -0
- package/script/bin/cli.js +43 -164
- package/script/bin/cli.js.map +1 -1
- package/script/src/clients/exchange.d.ts +93 -93
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +62 -57
- package/script/src/clients/exchange.js.map +1 -1
- package/script/src/clients/info.d.ts +113 -113
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +70 -73
- package/script/src/clients/info.js.map +1 -1
- package/script/src/clients/multiSign.d.ts +3 -3
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +10 -8
- package/script/src/clients/multiSign.js.map +1 -1
- package/script/src/clients/subscription.d.ts +23 -23
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +8 -11
- package/script/src/clients/subscription.js.map +1 -1
- package/script/src/schemas/_base.d.ts +6 -8
- package/script/src/schemas/_base.d.ts.map +1 -1
- package/script/src/schemas/_base.js +6 -29
- package/script/src/schemas/_base.js.map +1 -1
- package/script/src/schemas/exchange/requests.d.ts +1676 -1657
- package/script/src/schemas/exchange/requests.d.ts.map +1 -1
- package/script/src/schemas/exchange/requests.js +194 -198
- package/script/src/schemas/exchange/requests.js.map +1 -1
- package/script/src/schemas/exchange/responses.d.ts +10 -10
- package/script/src/schemas/exchange/responses.js +2 -2
- package/script/src/schemas/exchange/responses.js.map +1 -1
- package/script/src/schemas/explorer/requests.d.ts +2 -2
- package/script/src/schemas/explorer/requests.js +2 -2
- package/script/src/schemas/explorer/requests.js.map +1 -1
- package/script/src/schemas/explorer/responses.d.ts +16 -16
- package/script/src/schemas/explorer/responses.js +2 -2
- package/script/src/schemas/explorer/responses.js.map +1 -1
- package/script/src/schemas/info/accounts.d.ts +298 -298
- package/script/src/schemas/info/accounts.js +23 -23
- package/script/src/schemas/info/accounts.js.map +1 -1
- package/script/src/schemas/info/assets.d.ts +110 -110
- package/script/src/schemas/info/assets.js +8 -8
- package/script/src/schemas/info/assets.js.map +1 -1
- package/script/src/schemas/info/markets.d.ts +25 -25
- package/script/src/schemas/info/markets.js +2 -2
- package/script/src/schemas/info/markets.js.map +1 -1
- package/script/src/schemas/info/orders.d.ts +104 -104
- package/script/src/schemas/info/orders.js +2 -2
- package/script/src/schemas/info/orders.js.map +1 -1
- package/script/src/schemas/info/requests.d.ts +32 -32
- package/script/src/schemas/info/requests.js +54 -54
- package/script/src/schemas/info/requests.js.map +1 -1
- package/script/src/schemas/info/validators.d.ts +27 -27
- package/script/src/schemas/info/validators.js +5 -5
- package/script/src/schemas/info/validators.js.map +1 -1
- package/script/src/schemas/info/vaults.d.ts +46 -46
- package/script/src/schemas/info/vaults.js +9 -9
- package/script/src/schemas/info/vaults.js.map +1 -1
- package/script/src/schemas/subscriptions/requests.d.ts +4 -4
- package/script/src/schemas/subscriptions/requests.js +16 -16
- package/script/src/schemas/subscriptions/requests.js.map +1 -1
- package/script/src/schemas/subscriptions/responses.d.ts +401 -401
- package/script/src/schemas/subscriptions/responses.js +13 -13
- package/script/src/schemas/subscriptions/responses.js.map +1 -1
- package/script/src/signing/mod.js +37 -4
- package/script/src/signing/mod.js.map +1 -1
- package/script/src/signing/signTypedData/private_key.js +49 -16
- package/script/src/signing/signTypedData/private_key.js.map +1 -1
- package/script/src/transports/_polyfills.d.ts +12 -0
- package/script/src/transports/_polyfills.d.ts.map +1 -0
- package/script/src/transports/_polyfills.js +43 -0
- package/script/src/transports/_polyfills.js.map +1 -0
- package/script/src/transports/base.d.ts +6 -6
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.d.ts +11 -4
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +17 -6
- package/script/src/transports/http/http_transport.js.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +8 -7
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +47 -33
- package/script/src/transports/websocket/_hyperliquid_event_target.js.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +26 -29
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +82 -76
- package/script/src/transports/websocket/_reconnecting_websocket.js.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.d.ts +6 -0
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +52 -43
- package/script/src/transports/websocket/_websocket_async_request.js.map +1 -1
- package/script/src/transports/websocket/websocket_transport.d.ts +48 -70
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +92 -105
- package/script/src/transports/websocket/websocket_transport.js.map +1 -1
- package/src/bin/_utils.ts +185 -0
- package/src/bin/cli.ts +49 -171
- package/src/src/clients/exchange.ts +160 -149
- package/src/src/clients/info.ts +128 -128
- package/src/src/clients/multiSign.ts +15 -13
- package/src/src/clients/subscription.ts +32 -32
- package/src/src/schemas/_base.ts +18 -40
- package/src/src/schemas/exchange/requests.ts +202 -199
- package/src/src/schemas/exchange/responses.ts +3 -3
- package/src/src/schemas/explorer/requests.ts +3 -3
- package/src/src/schemas/explorer/responses.ts +3 -3
- package/src/src/schemas/info/accounts.ts +24 -24
- package/src/src/schemas/info/assets.ts +9 -9
- package/src/src/schemas/info/markets.ts +3 -3
- package/src/src/schemas/info/orders.ts +3 -3
- package/src/src/schemas/info/requests.ts +55 -55
- package/src/src/schemas/info/validators.ts +6 -6
- package/src/src/schemas/info/vaults.ts +10 -10
- package/src/src/schemas/subscriptions/requests.ts +17 -17
- package/src/src/schemas/subscriptions/responses.ts +14 -14
- package/src/src/signing/mod.ts +4 -4
- package/src/src/signing/signTypedData/private_key.ts +17 -17
- package/src/src/transports/_polyfills.ts +41 -0
- package/src/src/transports/base.ts +6 -6
- package/src/src/transports/http/http_transport.ts +25 -14
- package/src/src/transports/websocket/_hyperliquid_event_target.ts +24 -51
- package/src/src/transports/websocket/_reconnecting_websocket.ts +107 -119
- package/src/src/transports/websocket/_websocket_async_request.ts +57 -59
- package/src/src/transports/websocket/websocket_transport.ts +126 -167
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { IRequestTransport } from "../transports/base.js";
|
|
2
|
-
import
|
|
3
|
-
CancelSuccessResponse,
|
|
4
|
-
CreateSubAccountResponse,
|
|
5
|
-
CreateVaultResponse,
|
|
6
|
-
MultiSigRequest,
|
|
7
|
-
OrderSuccessResponse,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import {
|
|
3
|
+
type CancelSuccessResponse,
|
|
4
|
+
type CreateSubAccountResponse,
|
|
5
|
+
type CreateVaultResponse,
|
|
6
|
+
type MultiSigRequest,
|
|
7
|
+
type OrderSuccessResponse,
|
|
8
|
+
parser,
|
|
9
|
+
type SuccessResponse,
|
|
10
|
+
type TwapCancelSuccessResponse,
|
|
11
|
+
type TwapOrderSuccessResponse,
|
|
11
12
|
} from "../schemas/mod.js";
|
|
13
|
+
import { Address } from "../schemas/_base.js";
|
|
12
14
|
import { ExchangeClient, type ExchangeClientParameters } from "./exchange.js";
|
|
13
15
|
import {
|
|
14
16
|
type AbstractWallet,
|
|
@@ -24,7 +26,7 @@ export interface MultiSignClientParameters<
|
|
|
24
26
|
S extends readonly AbstractWallet[] = AbstractWallet[],
|
|
25
27
|
> extends Omit<ExchangeClientParameters<T, S[0]>, "wallet"> {
|
|
26
28
|
/** The multi-signature account address. */
|
|
27
|
-
multiSignAddress:
|
|
29
|
+
multiSignAddress: string;
|
|
28
30
|
/** Array of wallets used for multi-signature operations. The first wallet acts as the leader. */
|
|
29
31
|
signers: S;
|
|
30
32
|
}
|
|
@@ -65,7 +67,7 @@ export class MultiSignClient<
|
|
|
65
67
|
*/
|
|
66
68
|
constructor(args: MultiSignClientParameters<T, S>) {
|
|
67
69
|
super({ ...args, wallet: args.signers[0] });
|
|
68
|
-
this.multiSignAddress = args.multiSignAddress;
|
|
70
|
+
this.multiSignAddress = parser(Address)(args.multiSignAddress);
|
|
69
71
|
this.signers = args.signers;
|
|
70
72
|
|
|
71
73
|
Object.defineProperty(this, "wallet", {
|
|
@@ -96,7 +98,7 @@ export class MultiSignClient<
|
|
|
96
98
|
{ type: keyof typeof userSignedActionEip712Types }
|
|
97
99
|
>;
|
|
98
100
|
vaultAddress?: `0x${string}`;
|
|
99
|
-
expiresAfter: number |
|
|
101
|
+
expiresAfter: number | undefined;
|
|
100
102
|
},
|
|
101
103
|
signal?: AbortSignal,
|
|
102
104
|
): Promise<T> {
|
|
@@ -112,7 +114,7 @@ export class MultiSignClient<
|
|
|
112
114
|
nonce,
|
|
113
115
|
isTestnet: this.transport.isTestnet,
|
|
114
116
|
vaultAddress,
|
|
115
|
-
expiresAfter
|
|
117
|
+
expiresAfter,
|
|
116
118
|
});
|
|
117
119
|
}));
|
|
118
120
|
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
type WsWebData2,
|
|
46
46
|
WsWebData2Request,
|
|
47
47
|
} from "../schemas/mod.js";
|
|
48
|
+
import type * as v from "valibot";
|
|
48
49
|
|
|
49
50
|
/** @see https://github.com/microsoft/TypeScript/issues/13923#issuecomment-2191862501 */
|
|
50
51
|
type DeepImmutable<T> = {
|
|
@@ -58,43 +59,46 @@ export interface SubscriptionClientParameters<T extends ISubscriptionTransport =
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/** Subscription parameters for the {@linkcode SubscriptionClient.activeAssetCtx} method. */
|
|
61
|
-
export type WsActiveAssetCtxParameters = Omit<WsActiveAssetCtxRequest
|
|
62
|
+
export type WsActiveAssetCtxParameters = Omit<v.InferInput<typeof WsActiveAssetCtxRequest>, "type">;
|
|
62
63
|
/** Subscription parameters for the {@linkcode SubscriptionClient.activeAssetData} method. */
|
|
63
|
-
export type WsActiveAssetDataParameters = Omit<WsActiveAssetDataRequest
|
|
64
|
+
export type WsActiveAssetDataParameters = Omit<v.InferInput<typeof WsActiveAssetDataRequest>, "type">;
|
|
64
65
|
/** Subscription parameters for the {@linkcode SubscriptionClient.allMids} method. */
|
|
65
|
-
export type WsAllMidsParameters = Omit<WsAllMidsRequest
|
|
66
|
+
export type WsAllMidsParameters = Omit<v.InferInput<typeof WsAllMidsRequest>, "type">;
|
|
66
67
|
/** Subscription parameters for the {@linkcode SubscriptionClient.assetCtxs} method. */
|
|
67
|
-
export type WsAssetCtxsParameters = Omit<WsAssetCtxsRequest
|
|
68
|
+
export type WsAssetCtxsParameters = Omit<v.InferInput<typeof WsAssetCtxsRequest>, "type">;
|
|
68
69
|
/** Subscription parameters for the {@linkcode SubscriptionClient.bbo} method. */
|
|
69
|
-
export type WsBboParameters = Omit<WsBboRequest
|
|
70
|
+
export type WsBboParameters = Omit<v.InferInput<typeof WsBboRequest>, "type">;
|
|
70
71
|
/** Subscription parameters for the {@linkcode SubscriptionClient.candle} method. */
|
|
71
|
-
export type WsCandleParameters = Omit<WsCandleRequest
|
|
72
|
+
export type WsCandleParameters = Omit<v.InferInput<typeof WsCandleRequest>, "type">;
|
|
72
73
|
/** Subscription parameters for the {@linkcode SubscriptionClient.clearinghouseState} method. */
|
|
73
|
-
export type WsClearinghouseStateParameters = Omit<WsClearinghouseStateRequest
|
|
74
|
+
export type WsClearinghouseStateParameters = Omit<v.InferInput<typeof WsClearinghouseStateRequest>, "type">;
|
|
74
75
|
/** Subscription parameters for the {@linkcode SubscriptionClient.l2Book} method. */
|
|
75
|
-
export type WsL2BookParameters = Omit<WsL2BookRequest
|
|
76
|
+
export type WsL2BookParameters = Omit<v.InferInput<typeof WsL2BookRequest>, "type">;
|
|
76
77
|
/** Subscription parameters for the {@linkcode SubscriptionClient.notification} method. */
|
|
77
|
-
export type WsNotificationParameters = Omit<WsNotificationRequest
|
|
78
|
+
export type WsNotificationParameters = Omit<v.InferInput<typeof WsNotificationRequest>, "type">;
|
|
78
79
|
/** Subscription parameters for the {@linkcode SubscriptionClient.openOrders} method. */
|
|
79
|
-
export type WsOpenOrdersParameters = Omit<WsOpenOrdersRequest
|
|
80
|
+
export type WsOpenOrdersParameters = Omit<v.InferInput<typeof WsOpenOrdersRequest>, "type">;
|
|
80
81
|
/** Subscription parameters for the {@linkcode SubscriptionClient.orderUpdates} method. */
|
|
81
|
-
export type WsOrderUpdatesParameters = Omit<WsOrderUpdatesRequest
|
|
82
|
+
export type WsOrderUpdatesParameters = Omit<v.InferInput<typeof WsOrderUpdatesRequest>, "type">;
|
|
82
83
|
/** Subscription parameters for the {@linkcode SubscriptionClient.trades} method. */
|
|
83
|
-
export type WsTradesParameters = Omit<WsTradesRequest
|
|
84
|
+
export type WsTradesParameters = Omit<v.InferInput<typeof WsTradesRequest>, "type">;
|
|
84
85
|
/** Subscription parameters for the {@linkcode SubscriptionClient.userEvents} method. */
|
|
85
|
-
export type WsUserEventsParameters = Omit<WsUserEventsRequest
|
|
86
|
+
export type WsUserEventsParameters = Omit<v.InferInput<typeof WsUserEventsRequest>, "type">;
|
|
86
87
|
/** Subscription parameters for the {@linkcode SubscriptionClient.userFills} method. */
|
|
87
|
-
export type WsUserFillsParameters = Omit<WsUserFillsRequest
|
|
88
|
+
export type WsUserFillsParameters = Omit<v.InferInput<typeof WsUserFillsRequest>, "type">;
|
|
88
89
|
/** Subscription parameters for the {@linkcode SubscriptionClient.userFundings} method. */
|
|
89
|
-
export type WsUserFundingsParameters = Omit<WsUserFundingsRequest
|
|
90
|
+
export type WsUserFundingsParameters = Omit<v.InferInput<typeof WsUserFundingsRequest>, "type">;
|
|
90
91
|
/** Subscription parameters for the {@linkcode SubscriptionClient.userNonFundingLedgerUpdates} method. */
|
|
91
|
-
export type WsUserNonFundingLedgerUpdatesParameters = Omit<
|
|
92
|
+
export type WsUserNonFundingLedgerUpdatesParameters = Omit<
|
|
93
|
+
v.InferInput<typeof WsUserNonFundingLedgerUpdatesRequest>,
|
|
94
|
+
"type"
|
|
95
|
+
>;
|
|
92
96
|
/** Subscription parameters for the {@linkcode SubscriptionClient.userTwapHistory} method. */
|
|
93
|
-
export type WsUserTwapHistoryParameters = Omit<WsUserTwapHistoryRequest
|
|
97
|
+
export type WsUserTwapHistoryParameters = Omit<v.InferInput<typeof WsUserTwapHistoryRequest>, "type">;
|
|
94
98
|
/** Subscription parameters for the {@linkcode SubscriptionClient.userTwapSliceFills} method. */
|
|
95
|
-
export type WsUserTwapSliceFillsParameters = Omit<WsUserTwapSliceFillsRequest
|
|
99
|
+
export type WsUserTwapSliceFillsParameters = Omit<v.InferInput<typeof WsUserTwapSliceFillsRequest>, "type">;
|
|
96
100
|
/** Subscription parameters for the {@linkcode SubscriptionClient.webData2} method. */
|
|
97
|
-
export type WsWebData2Parameters = Omit<WsWebData2Request
|
|
101
|
+
export type WsWebData2Parameters = Omit<v.InferInput<typeof WsWebData2Request>, "type">;
|
|
98
102
|
|
|
99
103
|
/**
|
|
100
104
|
* Subscription client for subscribing to various Hyperliquid events.
|
|
@@ -102,7 +106,7 @@ export type WsWebData2Parameters = Omit<WsWebData2Request, "type">;
|
|
|
102
106
|
*/
|
|
103
107
|
export class SubscriptionClient<
|
|
104
108
|
T extends ISubscriptionTransport = ISubscriptionTransport,
|
|
105
|
-
> implements SubscriptionClientParameters<T
|
|
109
|
+
> implements SubscriptionClientParameters<T> {
|
|
106
110
|
transport: T;
|
|
107
111
|
|
|
108
112
|
/**
|
|
@@ -212,11 +216,11 @@ export class SubscriptionClient<
|
|
|
212
216
|
allMids(listener: (data: WsAllMids) => void): Promise<Subscription>;
|
|
213
217
|
allMids(params: DeepImmutable<WsAllMidsParameters>, listener: (data: WsAllMids) => void): Promise<Subscription>;
|
|
214
218
|
allMids(
|
|
215
|
-
|
|
219
|
+
paramsOrListener: DeepImmutable<WsAllMidsParameters> | ((data: WsAllMids) => void),
|
|
216
220
|
maybeListener?: (data: WsAllMids) => void,
|
|
217
221
|
): Promise<Subscription> {
|
|
218
|
-
const params = typeof
|
|
219
|
-
const listener = typeof
|
|
222
|
+
const params = typeof paramsOrListener === "function" ? {} : paramsOrListener;
|
|
223
|
+
const listener = typeof paramsOrListener === "function" ? paramsOrListener : maybeListener!;
|
|
220
224
|
|
|
221
225
|
const payload = parser(WsAllMidsRequest)({ type: "allMids", ...params });
|
|
222
226
|
return this.transport.subscribe<WsAllMids>(payload.type, payload, (e) => {
|
|
@@ -251,11 +255,11 @@ export class SubscriptionClient<
|
|
|
251
255
|
listener: (data: WsAssetCtxs) => void,
|
|
252
256
|
): Promise<Subscription>;
|
|
253
257
|
assetCtxs(
|
|
254
|
-
|
|
258
|
+
paramsOrListener: DeepImmutable<WsAssetCtxsParameters> | ((data: WsAssetCtxs) => void),
|
|
255
259
|
maybeListener?: (data: WsAssetCtxs) => void,
|
|
256
260
|
): Promise<Subscription> {
|
|
257
|
-
const params = typeof
|
|
258
|
-
const listener = typeof
|
|
261
|
+
const params = typeof paramsOrListener === "function" ? {} : paramsOrListener;
|
|
262
|
+
const listener = typeof paramsOrListener === "function" ? paramsOrListener : maybeListener!;
|
|
259
263
|
|
|
260
264
|
const payload = parser(WsAssetCtxsRequest)({
|
|
261
265
|
type: "assetCtxs",
|
|
@@ -385,7 +389,7 @@ export class SubscriptionClient<
|
|
|
385
389
|
* ```ts
|
|
386
390
|
* import * as hl from "@nktkas/hyperliquid";
|
|
387
391
|
*
|
|
388
|
-
* const transport = new hl.WebSocketTransport();
|
|
392
|
+
* const transport = new hl.WebSocketTransport({ url: "wss://rpc.hyperliquid.xyz/ws" }); // RPC endpoint
|
|
389
393
|
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
390
394
|
*
|
|
391
395
|
* const sub = await subsClient.explorerBlock((data) => {
|
|
@@ -413,7 +417,7 @@ export class SubscriptionClient<
|
|
|
413
417
|
* ```ts
|
|
414
418
|
* import * as hl from "@nktkas/hyperliquid";
|
|
415
419
|
*
|
|
416
|
-
* const transport = new hl.WebSocketTransport();
|
|
420
|
+
* const transport = new hl.WebSocketTransport({ url: "wss://rpc.hyperliquid.xyz/ws" }); // RPC endpoint
|
|
417
421
|
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
418
422
|
*
|
|
419
423
|
* const sub = await subsClient.explorerTxs((data) => {
|
|
@@ -834,8 +838,4 @@ export class SubscriptionClient<
|
|
|
834
838
|
}
|
|
835
839
|
});
|
|
836
840
|
}
|
|
837
|
-
|
|
838
|
-
async [Symbol.asyncDispose](): Promise<void> {
|
|
839
|
-
await this.transport[Symbol.asyncDispose]?.();
|
|
840
|
-
}
|
|
841
841
|
}
|
package/src/src/schemas/_base.ts
CHANGED
|
@@ -1,62 +1,37 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
export const UnsignedDecimal = v.pipe(
|
|
4
|
-
v.string(),
|
|
4
|
+
v.union([v.string(), v.number()]),
|
|
5
|
+
v.transform(String),
|
|
5
6
|
v.trim(),
|
|
6
7
|
v.regex(/^[0-9]+(\.[0-9]+)?$/),
|
|
7
8
|
v.transform((value) => formatDecimal(value)),
|
|
8
9
|
);
|
|
9
10
|
export type UnsignedDecimal = v.InferOutput<typeof UnsignedDecimal>;
|
|
10
|
-
export const UnsignedDecimalMayInputNumber = v.pipe(
|
|
11
|
-
v.unknown(),
|
|
12
|
-
v.transform((x) => {
|
|
13
|
-
const data = v.safeParse(v.number(), x);
|
|
14
|
-
if (data.success) return String(data.output);
|
|
15
|
-
return x;
|
|
16
|
-
}),
|
|
17
|
-
UnsignedDecimal as unknown as v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>,
|
|
18
|
-
);
|
|
19
11
|
|
|
20
12
|
export const Decimal = v.pipe(
|
|
21
|
-
v.string(),
|
|
13
|
+
v.union([v.string(), v.number()]),
|
|
14
|
+
v.transform(String),
|
|
22
15
|
v.trim(),
|
|
23
16
|
v.regex(/^-?[0-9]+(\.[0-9]+)?$/),
|
|
24
17
|
v.transform((value) => formatDecimal(value)),
|
|
25
18
|
);
|
|
26
19
|
export type Decimal = v.InferOutput<typeof Decimal>;
|
|
27
|
-
export const DecimalMayInputNumber = v.pipe(
|
|
28
|
-
v.unknown(),
|
|
29
|
-
v.transform((x) => {
|
|
30
|
-
const data = v.safeParse(v.number(), x);
|
|
31
|
-
if (data.success) return String(data.output);
|
|
32
|
-
return x;
|
|
33
|
-
}),
|
|
34
|
-
Decimal as unknown as v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>,
|
|
35
|
-
);
|
|
36
20
|
|
|
37
|
-
export const Integer = v.pipe(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
v.
|
|
41
|
-
v.transform((x) => {
|
|
42
|
-
const data = v.safeParse(Decimal, x);
|
|
43
|
-
if (data.success) return Number(data.output);
|
|
44
|
-
return x;
|
|
45
|
-
}),
|
|
46
|
-
Integer as unknown as v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, // allow `string | number` in ts, but use a specific type in the JSON schema
|
|
21
|
+
export const Integer = v.pipe(
|
|
22
|
+
v.union([v.string(), v.number()]),
|
|
23
|
+
v.transform(Number),
|
|
24
|
+
v.safeInteger(),
|
|
47
25
|
);
|
|
26
|
+
export type Integer = v.InferOutput<typeof Integer>;
|
|
48
27
|
|
|
49
|
-
export const UnsignedInteger = v.pipe(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
v.
|
|
53
|
-
v.
|
|
54
|
-
const data = v.safeParse(Decimal, x);
|
|
55
|
-
if (data.success) return Number(data.output);
|
|
56
|
-
return x;
|
|
57
|
-
}),
|
|
58
|
-
UnsignedInteger as unknown as v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>,
|
|
28
|
+
export const UnsignedInteger = v.pipe(
|
|
29
|
+
v.union([v.string(), v.number()]),
|
|
30
|
+
v.transform(Number),
|
|
31
|
+
v.safeInteger(),
|
|
32
|
+
v.minValue(0),
|
|
59
33
|
);
|
|
34
|
+
export type UnsignedInteger = v.InferOutput<typeof UnsignedInteger>;
|
|
60
35
|
|
|
61
36
|
export const Hex = v.pipe(
|
|
62
37
|
v.string(),
|
|
@@ -65,6 +40,9 @@ export const Hex = v.pipe(
|
|
|
65
40
|
);
|
|
66
41
|
export type Hex = v.InferOutput<typeof Hex>;
|
|
67
42
|
|
|
43
|
+
export const Address = v.pipe(Hex, v.length(42));
|
|
44
|
+
export type Address = v.InferOutput<typeof Address>;
|
|
45
|
+
|
|
68
46
|
export const TokenId = v.pipe(
|
|
69
47
|
v.string(),
|
|
70
48
|
v.regex(/^[^:]+:0x[0-9a-fA-F]+$/),
|