@lifi/perps-sdk-provider-hyperliquid 0.0.0-preview-b10f0cd → 0.0.0-preview-a5dca06
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 +9 -2
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/getAccount.d.ts.map +1 -1
- package/dist/cjs/services/getAccount.js +5 -2
- package/dist/cjs/services/getAccount.js.map +1 -1
- package/dist/cjs/services/getFills.d.ts.map +1 -1
- package/dist/cjs/services/getFills.js +3 -0
- package/dist/cjs/services/getFills.js.map +1 -1
- package/dist/cjs/services/getOrder.d.ts.map +1 -1
- package/dist/cjs/services/getOrder.js +3 -1
- package/dist/cjs/services/getOrder.js.map +1 -1
- package/dist/cjs/services/getOrders.d.ts.map +1 -1
- package/dist/cjs/services/getOrders.js +31 -7
- package/dist/cjs/services/getOrders.js.map +1 -1
- package/dist/cjs/services/getPositions.d.ts.map +1 -1
- package/dist/cjs/services/getPositions.js +1 -1
- package/dist/cjs/services/getPositions.js.map +1 -1
- package/dist/cjs/types/explorer.d.ts +10 -0
- package/dist/cjs/types/explorer.d.ts.map +1 -0
- package/dist/cjs/types/explorer.js +17 -0
- package/dist/cjs/types/explorer.js.map +1 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/assetId.d.ts +1 -0
- package/dist/cjs/utils/assetId.d.ts.map +1 -1
- package/dist/cjs/utils/assetId.js +6 -1
- package/dist/cjs/utils/assetId.js.map +1 -1
- package/dist/cjs/utils/explorer.d.ts +7 -0
- package/dist/cjs/utils/explorer.d.ts.map +1 -0
- package/dist/cjs/utils/explorer.js +49 -0
- package/dist/cjs/utils/explorer.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +2 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +6 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/infoClient.d.ts +1 -0
- package/dist/cjs/utils/infoClient.d.ts.map +1 -1
- package/dist/cjs/utils/infoClient.js +16 -10
- package/dist/cjs/utils/infoClient.js.map +1 -1
- package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
- package/dist/cjs/utils/spotBalance.js +10 -6
- package/dist/cjs/utils/spotBalance.js.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js +37 -7
- package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/esm/constants.d.ts +8 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +8 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/getAccount.d.ts.map +1 -1
- package/dist/esm/services/getAccount.js +6 -3
- package/dist/esm/services/getAccount.js.map +1 -1
- package/dist/esm/services/getFills.d.ts.map +1 -1
- package/dist/esm/services/getFills.js +4 -1
- package/dist/esm/services/getFills.js.map +1 -1
- package/dist/esm/services/getOrder.d.ts.map +1 -1
- package/dist/esm/services/getOrder.js +4 -2
- package/dist/esm/services/getOrder.js.map +1 -1
- package/dist/esm/services/getOrders.d.ts.map +1 -1
- package/dist/esm/services/getOrders.js +47 -13
- package/dist/esm/services/getOrders.js.map +1 -1
- package/dist/esm/services/getPositions.d.ts.map +1 -1
- package/dist/esm/services/getPositions.js +2 -2
- package/dist/esm/services/getPositions.js.map +1 -1
- package/dist/esm/types/explorer.d.ts +27 -0
- package/dist/esm/types/explorer.d.ts.map +1 -0
- package/dist/esm/types/explorer.js +20 -0
- package/dist/esm/types/explorer.js.map +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/utils/assetId.d.ts +9 -0
- package/dist/esm/utils/assetId.d.ts.map +1 -1
- package/dist/esm/utils/assetId.js +13 -0
- package/dist/esm/utils/assetId.js.map +1 -1
- package/dist/esm/utils/explorer.d.ts +31 -0
- package/dist/esm/utils/explorer.d.ts.map +1 -0
- package/dist/esm/utils/explorer.js +68 -0
- package/dist/esm/utils/explorer.js.map +1 -0
- package/dist/esm/utils/index.d.ts +2 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +2 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/infoClient.d.ts +14 -3
- package/dist/esm/utils/infoClient.d.ts.map +1 -1
- package/dist/esm/utils/infoClient.js +29 -14
- package/dist/esm/utils/infoClient.js.map +1 -1
- package/dist/esm/utils/spotBalance.d.ts +1 -1
- package/dist/esm/utils/spotBalance.d.ts.map +1 -1
- package/dist/esm/utils/spotBalance.js +12 -7
- package/dist/esm/utils/spotBalance.js.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts +2 -1
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.js +40 -9
- package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/types/constants.d.ts +8 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/getAccount.d.ts.map +1 -1
- package/dist/types/services/getFills.d.ts.map +1 -1
- package/dist/types/services/getOrder.d.ts.map +1 -1
- package/dist/types/services/getOrders.d.ts.map +1 -1
- package/dist/types/services/getPositions.d.ts.map +1 -1
- package/dist/types/types/explorer.d.ts +27 -0
- package/dist/types/types/explorer.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/utils/assetId.d.ts +9 -0
- package/dist/types/utils/assetId.d.ts.map +1 -1
- package/dist/types/utils/explorer.d.ts +31 -0
- package/dist/types/utils/explorer.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/infoClient.d.ts +14 -3
- package/dist/types/utils/infoClient.d.ts.map +1 -1
- package/dist/types/utils/spotBalance.d.ts +1 -1
- package/dist/types/utils/spotBalance.d.ts.map +1 -1
- package/dist/types/websocket/HyperliquidWsProvider.d.ts +2 -1
- package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/constants.ts +10 -0
- package/src/index.ts +1 -0
- package/src/services/getAccount.ts +8 -4
- package/src/services/getFills.ts +4 -1
- package/src/services/getOrder.ts +8 -2
- package/src/services/getOrders.ts +71 -12
- package/src/services/getPositions.ts +4 -1
- package/src/types/explorer.ts +39 -0
- package/src/types/index.ts +1 -0
- package/src/utils/assetId.ts +16 -0
- package/src/utils/explorer.ts +93 -0
- package/src/utils/index.ts +11 -1
- package/src/utils/infoClient.ts +46 -24
- package/src/utils/spotBalance.ts +12 -7
- package/src/websocket/HyperliquidWsProvider.ts +44 -9
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { OrderBase } from '@lifi/perps-types'
|
|
2
|
+
import { isHex } from 'viem'
|
|
3
|
+
import { HYPERLIQUID_EXPLORER_RPC_URL } from '../constants.js'
|
|
4
|
+
import { type HlExplorerTx, isHlExplorerTx } from '../types/explorer.js'
|
|
5
|
+
import { hlPostJson, type InfoRequestOptions } from './infoClient.js'
|
|
6
|
+
|
|
7
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
8
|
+
typeof value === 'object' && value !== null
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Read the address's recent HyperCore transactions from the explorer RPC.
|
|
12
|
+
*
|
|
13
|
+
* The surface is undocumented, so it is read defensively: an address the
|
|
14
|
+
* explorer has never indexed answers `200` with no `txs` array, and each entry
|
|
15
|
+
* is checked on its own so one drifted entry cannot drop the rest.
|
|
16
|
+
*
|
|
17
|
+
* @throws {PerpsError} On a non-2xx status or a transport failure.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export const fetchUserTransactions = async (
|
|
21
|
+
address: string,
|
|
22
|
+
options?: InfoRequestOptions
|
|
23
|
+
): Promise<HlExplorerTx[]> => {
|
|
24
|
+
const body = await hlPostJson<{ txs?: unknown } | null>(
|
|
25
|
+
HYPERLIQUID_EXPLORER_RPC_URL,
|
|
26
|
+
'explorer userDetails',
|
|
27
|
+
{ type: 'userDetails', user: address },
|
|
28
|
+
options
|
|
29
|
+
)
|
|
30
|
+
const txs = body?.txs
|
|
31
|
+
return Array.isArray(txs) ? txs.filter(isHlExplorerTx) : []
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Every client order id an action names: `orders[].c` on a placement, `order.c`
|
|
36
|
+
* on a single modify, and `modifies[].order.c` on a batch modify. A batched
|
|
37
|
+
* placement names one id per leg, so every id is returned, not just the first.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export const getClientOrderIds = (
|
|
42
|
+
action: Record<string, unknown>
|
|
43
|
+
): string[] => {
|
|
44
|
+
const wires: unknown[] = [
|
|
45
|
+
...(Array.isArray(action.orders) ? action.orders : []),
|
|
46
|
+
...(Array.isArray(action.modifies)
|
|
47
|
+
? action.modifies.map((modify) =>
|
|
48
|
+
isRecord(modify) ? modify.order : undefined
|
|
49
|
+
)
|
|
50
|
+
: []),
|
|
51
|
+
action.order,
|
|
52
|
+
]
|
|
53
|
+
const ids: string[] = []
|
|
54
|
+
for (const wire of wires) {
|
|
55
|
+
if (!isRecord(wire)) {
|
|
56
|
+
continue
|
|
57
|
+
}
|
|
58
|
+
const cloid = wire.c
|
|
59
|
+
if (
|
|
60
|
+
typeof cloid === 'string' &&
|
|
61
|
+
cloid !== '0x' &&
|
|
62
|
+
isHex(cloid, { strict: true })
|
|
63
|
+
) {
|
|
64
|
+
ids.push(cloid)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return ids
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The hash of the transaction whose action names the order's client order id.
|
|
72
|
+
*
|
|
73
|
+
* @returns The transaction hash, or `undefined` when the order carries no
|
|
74
|
+
* client order id or no transaction in the window names it.
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export const matchOrderActionHash = (
|
|
78
|
+
txs: HlExplorerTx[],
|
|
79
|
+
order: Pick<OrderBase, 'clientOrderId'>
|
|
80
|
+
): string | undefined => {
|
|
81
|
+
const { clientOrderId } = order
|
|
82
|
+
if (clientOrderId === undefined) {
|
|
83
|
+
return undefined
|
|
84
|
+
}
|
|
85
|
+
// A client order id is hex, so the venue may echo a case the placer did not send.
|
|
86
|
+
const wanted = clientOrderId.toLowerCase()
|
|
87
|
+
const match = txs.find(
|
|
88
|
+
(tx) =>
|
|
89
|
+
isRecord(tx.action) &&
|
|
90
|
+
getClientOrderIds(tx.action).some((id) => id.toLowerCase() === wanted)
|
|
91
|
+
)
|
|
92
|
+
return match?.hash
|
|
93
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
// for the package's utility surface. Internal modules import per-file paths
|
|
3
3
|
// (e.g. `./assetId.js`, `./mapFill.js`) directly.
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export {
|
|
6
|
+
assetIsOutcome,
|
|
7
|
+
assetIsSpot,
|
|
8
|
+
calculateAssetId,
|
|
9
|
+
getProviderIndex,
|
|
10
|
+
} from './assetId.js'
|
|
6
11
|
export {
|
|
7
12
|
applyLogoOverride,
|
|
8
13
|
spotLogoURI,
|
|
@@ -12,6 +17,11 @@ export {
|
|
|
12
17
|
decodeCompressedJson,
|
|
13
18
|
decodeFastAssetCtxs,
|
|
14
19
|
} from './decodeFastAssetCtxs.js'
|
|
20
|
+
export {
|
|
21
|
+
fetchUserTransactions,
|
|
22
|
+
getClientOrderIds,
|
|
23
|
+
matchOrderActionHash,
|
|
24
|
+
} from './explorer.js'
|
|
15
25
|
export type { InfoRequestOptions } from './infoClient.js'
|
|
16
26
|
export { hlInfoOptions, infoRequest } from './infoClient.js'
|
|
17
27
|
export {
|
package/src/utils/infoClient.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
errorCodeFromStatus,
|
|
3
3
|
fetchWithRetry,
|
|
4
|
+
isAbortError,
|
|
4
5
|
PerpsError,
|
|
5
6
|
type PerpsSDKClient,
|
|
6
7
|
type ResolvedRetryPolicy,
|
|
@@ -57,7 +58,7 @@ export const HYPERLIQUID_RETRY_DEFAULTS: ResolvedRetryPolicy = {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
|
-
* Transport options for a direct Hyperliquid
|
|
61
|
+
* Transport options for a direct Hyperliquid REST request. `policy`
|
|
61
62
|
* controls retries, `signal` cancels the request, and `fetchImpl` overrides
|
|
62
63
|
* the runtime's global `fetch` implementation.
|
|
63
64
|
* @public
|
|
@@ -87,7 +88,7 @@ export const hlInfoOptions = (
|
|
|
87
88
|
})
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
|
-
* POST to
|
|
91
|
+
* POST a JSON body to a Hyperliquid REST surface and return the parsed body.
|
|
91
92
|
*
|
|
92
93
|
* Direct-to-venue: no proxy, no AJV validation, no cache. The caller's type
|
|
93
94
|
* parameter is trusted; consumers should treat the response shape as
|
|
@@ -97,20 +98,24 @@ export const hlInfoOptions = (
|
|
|
97
98
|
* Non-2xx responses raise a {@link PerpsError} tagged with the Hyperliquid
|
|
98
99
|
* provider key, carrying the code the status resolves to: `RateLimitExceeded`
|
|
99
100
|
* for a 429, `Unauthorized` for a 401, `AgentUnauthorized` for a 403, and
|
|
100
|
-
* `ThirdPartyError` for every other status.
|
|
101
|
-
*
|
|
101
|
+
* `ThirdPartyError` for every other status. A transport failure and a 2xx body
|
|
102
|
+
* that is not JSON both raise `ServerError`, so every failure but a caller
|
|
103
|
+
* abort reaches the caller as a `PerpsError`. An abort rejects untouched.
|
|
104
|
+
*
|
|
105
|
+
* @param label - Names the surface in the error message, e.g. `info request`.
|
|
106
|
+
* @internal
|
|
102
107
|
*/
|
|
103
|
-
export async function
|
|
104
|
-
|
|
108
|
+
export async function hlPostJson<T>(
|
|
109
|
+
url: string,
|
|
110
|
+
label: string,
|
|
105
111
|
body: Record<string, unknown>,
|
|
106
112
|
options?: InfoRequestOptions
|
|
107
113
|
): Promise<T> {
|
|
108
114
|
const policy = options?.policy ?? HYPERLIQUID_RETRY_DEFAULTS
|
|
109
115
|
|
|
110
|
-
let response: Response
|
|
111
116
|
try {
|
|
112
|
-
response = await fetchWithRetry(
|
|
113
|
-
|
|
117
|
+
const response = await fetchWithRetry(
|
|
118
|
+
url,
|
|
114
119
|
{
|
|
115
120
|
method: 'POST',
|
|
116
121
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -122,27 +127,44 @@ export async function infoRequest<T>(
|
|
|
122
127
|
signal: options?.signal,
|
|
123
128
|
}
|
|
124
129
|
)
|
|
130
|
+
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
const err = new PerpsError(
|
|
133
|
+
errorCodeFromStatus(
|
|
134
|
+
response.status,
|
|
135
|
+
PerpsErrorCode.ThirdPartyError,
|
|
136
|
+
HYPERLIQUID_STATUS_ERROR_CODES
|
|
137
|
+
),
|
|
138
|
+
`Hyperliquid ${label} failed: ${response.status}`
|
|
139
|
+
)
|
|
140
|
+
err.tool = PROVIDER_KEY
|
|
141
|
+
throw err
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (await response.json()) as T
|
|
125
145
|
} catch (error) {
|
|
146
|
+
if (error instanceof PerpsError || isAbortError(error)) {
|
|
147
|
+
throw error
|
|
148
|
+
}
|
|
126
149
|
const err = new PerpsError(
|
|
127
150
|
PerpsErrorCode.ServerError,
|
|
128
|
-
error instanceof Error ? error.message :
|
|
129
|
-
)
|
|
130
|
-
err.tool = PROVIDER_KEY
|
|
131
|
-
throw err
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!response.ok) {
|
|
135
|
-
const err = new PerpsError(
|
|
136
|
-
errorCodeFromStatus(
|
|
137
|
-
response.status,
|
|
138
|
-
PerpsErrorCode.ThirdPartyError,
|
|
139
|
-
HYPERLIQUID_STATUS_ERROR_CODES
|
|
140
|
-
),
|
|
141
|
-
`Hyperliquid info request failed: ${response.status}`
|
|
151
|
+
error instanceof Error ? error.message : `Hyperliquid ${label} failed`
|
|
142
152
|
)
|
|
143
153
|
err.tool = PROVIDER_KEY
|
|
144
154
|
throw err
|
|
145
155
|
}
|
|
156
|
+
}
|
|
146
157
|
|
|
147
|
-
|
|
158
|
+
/**
|
|
159
|
+
* POST to the Hyperliquid `/info` endpoint and return the parsed JSON body.
|
|
160
|
+
* See {@link hlPostJson} for the transport and error contract.
|
|
161
|
+
*
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
export function infoRequest<T>(
|
|
165
|
+
apiUrl: string,
|
|
166
|
+
body: Record<string, unknown>,
|
|
167
|
+
options?: InfoRequestOptions
|
|
168
|
+
): Promise<T> {
|
|
169
|
+
return hlPostJson<T>(`${apiUrl}/info`, 'info request', body, options)
|
|
148
170
|
}
|
package/src/utils/spotBalance.ts
CHANGED
|
@@ -41,14 +41,19 @@ export const spotAssetFromToken = (b: HlSpotBalance): Asset => ({
|
|
|
41
41
|
logoURI: spotLogoURI(b.coin),
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
/** Assemble a typed spot {@link Balance}; `total` is native token units and its USD value
|
|
44
|
+
/** Assemble a typed spot {@link Balance}; `total` is native token units and its unit price and USD value use `priceById`. @public */
|
|
45
45
|
export const spotBalance = (
|
|
46
46
|
asset: Asset,
|
|
47
47
|
total: string,
|
|
48
48
|
priceById: Map<string, number>
|
|
49
|
-
): Balance =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
): Balance => {
|
|
50
|
+
const price = priceById.get(asset.id) ?? 0
|
|
51
|
+
return {
|
|
52
|
+
categoryId: SPOT_MARKET_ID,
|
|
53
|
+
asset,
|
|
54
|
+
units: total,
|
|
55
|
+
valueUsd: (stringToFloat(total) * price).toString(),
|
|
56
|
+
// A zero entry means the map holds no mark for the asset, not a free asset.
|
|
57
|
+
...(price > 0 ? { price: price.toString() } : {}),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -64,6 +64,7 @@ import type {
|
|
|
64
64
|
import { HlAbstractionMode } from '../types/index.js'
|
|
65
65
|
import { toWireBig } from '../utils/decimal.js'
|
|
66
66
|
import {
|
|
67
|
+
assetIsOutcome,
|
|
67
68
|
decodeCompressedJson,
|
|
68
69
|
decodeFastAssetCtxs,
|
|
69
70
|
hlInfoOptions,
|
|
@@ -690,7 +691,7 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
690
691
|
}
|
|
691
692
|
for (const ctx of ctxs) {
|
|
692
693
|
const marketId = ctx.coin
|
|
693
|
-
if (marketId === undefined) {
|
|
694
|
+
if (marketId === undefined || assetIsOutcome(marketId)) {
|
|
694
695
|
continue
|
|
695
696
|
}
|
|
696
697
|
const merged = mergePerpAssetCtx(byMarketId[marketId], marketId, ctx)
|
|
@@ -709,6 +710,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
709
710
|
const ctxs = await decodeCompressedJson<HlWsSacData>(base64)
|
|
710
711
|
const touched = new Set<string>()
|
|
711
712
|
for (const [sacKey, ctx] of Object.entries(ctxs)) {
|
|
713
|
+
if (assetIsOutcome(sacKey)) {
|
|
714
|
+
continue
|
|
715
|
+
}
|
|
712
716
|
const marketId = spotMarketIdBySacKey.get(sacKey)
|
|
713
717
|
if (marketId === undefined) {
|
|
714
718
|
continue
|
|
@@ -748,14 +752,19 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
748
752
|
private handleFastAssetCtxs(base64: string) {
|
|
749
753
|
this.fastDecodeChain.push(async () => {
|
|
750
754
|
const ctxs = await decodeFastAssetCtxs(base64)
|
|
755
|
+
const touched: string[] = []
|
|
751
756
|
for (const [marketId, ctx] of Object.entries(ctxs)) {
|
|
757
|
+
if (assetIsOutcome(marketId)) {
|
|
758
|
+
continue
|
|
759
|
+
}
|
|
752
760
|
const prev = this.fastCtxByMarketId[marketId]
|
|
753
761
|
this.fastCtxByMarketId[marketId] = {
|
|
754
762
|
markPx: 'markPx' in ctx ? ctx.markPx : prev?.markPx,
|
|
755
763
|
midPx: 'midPx' in ctx ? ctx.midPx : prev?.midPx,
|
|
756
764
|
}
|
|
765
|
+
touched.push(marketId)
|
|
757
766
|
}
|
|
758
|
-
this.emitMarketsContext(
|
|
767
|
+
this.emitMarketsContext(touched)
|
|
759
768
|
})
|
|
760
769
|
}
|
|
761
770
|
|
|
@@ -785,12 +794,15 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
785
794
|
* Context for one market from the cached feeds: spot asset context when it
|
|
786
795
|
* maps, else perp asset context with mid + mark overlaid from
|
|
787
796
|
* `fastAssetCtxs`, else the fast feed alone — each price standing in for the
|
|
788
|
-
* other where it carries only one of mid/mark.
|
|
797
|
+
* other where it carries only one of mid/mark. An attached registry gates the
|
|
798
|
+
* market id: an id it does not list, or lists as delisted, yields no context.
|
|
789
799
|
*/
|
|
790
800
|
private computeMarketContext(marketId: string): MarketContext | undefined {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
801
|
+
if (this.registry !== undefined) {
|
|
802
|
+
const market = this.registry.get(marketId)
|
|
803
|
+
if (market === undefined || !isActiveMarket(market)) {
|
|
804
|
+
return undefined
|
|
805
|
+
}
|
|
794
806
|
}
|
|
795
807
|
const fast = this.fastCtxByMarketId[marketId]
|
|
796
808
|
const spotCtx = this.spotCtxByMarketId[marketId]
|
|
@@ -816,6 +828,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
816
828
|
}
|
|
817
829
|
|
|
818
830
|
private handleActiveAssetCtx(data: HlWsActiveAssetCtxData, raw: string) {
|
|
831
|
+
if (assetIsOutcome(data.coin)) {
|
|
832
|
+
return
|
|
833
|
+
}
|
|
819
834
|
const ctx = activePerpAssetCtx(data.coin, data.ctx)
|
|
820
835
|
if (ctx === undefined) {
|
|
821
836
|
wsLog.parseFailure(this.providerKey, raw)
|
|
@@ -828,6 +843,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
828
843
|
}
|
|
829
844
|
|
|
830
845
|
private handleActiveSpotAssetCtx(data: HlWsActiveSpotAssetCtxData) {
|
|
846
|
+
if (assetIsOutcome(data.coin)) {
|
|
847
|
+
return
|
|
848
|
+
}
|
|
831
849
|
const context = mapSpotMarketContext(data.coin, data.ctx)
|
|
832
850
|
if (context === undefined) {
|
|
833
851
|
return
|
|
@@ -958,6 +976,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
958
976
|
}
|
|
959
977
|
|
|
960
978
|
private handleCandle(data: HlWsCandleData) {
|
|
979
|
+
if (assetIsOutcome(data.s)) {
|
|
980
|
+
return
|
|
981
|
+
}
|
|
961
982
|
this.emit(`candle:${data.s}:${data.i}`, {
|
|
962
983
|
channel: 'candle',
|
|
963
984
|
data: {
|
|
@@ -973,6 +994,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
973
994
|
|
|
974
995
|
private handleTrades(data: HlWsTrade[]) {
|
|
975
996
|
for (const trade of data) {
|
|
997
|
+
if (assetIsOutcome(trade.coin)) {
|
|
998
|
+
continue
|
|
999
|
+
}
|
|
976
1000
|
this.emit(`trades:${trade.coin}`, {
|
|
977
1001
|
channel: 'trades',
|
|
978
1002
|
data: [
|
|
@@ -1004,6 +1028,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
1004
1028
|
const mapped = await Promise.all(
|
|
1005
1029
|
data.map(async (update) => {
|
|
1006
1030
|
const basic = update.order
|
|
1031
|
+
if (assetIsOutcome(basic.coin)) {
|
|
1032
|
+
return undefined
|
|
1033
|
+
}
|
|
1007
1034
|
const market = this.registry?.get(basic.coin)
|
|
1008
1035
|
if (market === undefined) {
|
|
1009
1036
|
return undefined
|
|
@@ -1069,6 +1096,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
1069
1096
|
const items = data.isSnapshot
|
|
1070
1097
|
? []
|
|
1071
1098
|
: data.fills.flatMap((f) => {
|
|
1099
|
+
if (assetIsOutcome(f.coin)) {
|
|
1100
|
+
return []
|
|
1101
|
+
}
|
|
1072
1102
|
const market = this.registry?.get(f.coin)
|
|
1073
1103
|
return market ? [mapFill(f as HlUserFill, market)] : []
|
|
1074
1104
|
})
|
|
@@ -1083,7 +1113,10 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
1083
1113
|
) {
|
|
1084
1114
|
const positions = data.clearinghouseStates.flatMap(([, state]) =>
|
|
1085
1115
|
state.assetPositions.flatMap((ap) => {
|
|
1086
|
-
if (
|
|
1116
|
+
if (
|
|
1117
|
+
assetIsOutcome(ap.position.coin) ||
|
|
1118
|
+
!isOpenAssetPosition(ap as HlAssetPosition)
|
|
1119
|
+
) {
|
|
1087
1120
|
return []
|
|
1088
1121
|
}
|
|
1089
1122
|
const market = this.registry?.get(ap.position.coin)
|
|
@@ -1306,8 +1339,10 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
1306
1339
|
const markets = this.registry?.activeMarkets ?? []
|
|
1307
1340
|
const priceById = spotPriceById(markets, this.mergedMids())
|
|
1308
1341
|
const rows = data.spotState.balances
|
|
1309
|
-
.filter(
|
|
1310
|
-
|
|
1342
|
+
.filter(
|
|
1343
|
+
(balance) =>
|
|
1344
|
+
!assetIsOutcome(balance.coin) &&
|
|
1345
|
+
toWireBig(balance.total, 'spotState.balances.total').gt(0)
|
|
1311
1346
|
)
|
|
1312
1347
|
.map((balance) => ({
|
|
1313
1348
|
balance: spotBalance(
|