@lifi/perps-sdk-provider-hyperliquid 36.0.0 → 37.0.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/dist/cjs/services/fillLeverages.d.ts +6 -0
- package/dist/cjs/services/fillLeverages.d.ts.map +1 -0
- package/dist/cjs/services/fillLeverages.js +29 -0
- package/dist/cjs/services/fillLeverages.js.map +1 -0
- package/dist/cjs/services/getFills.d.ts +1 -1
- package/dist/cjs/services/getFills.d.ts.map +1 -1
- package/dist/cjs/services/getFills.js +9 -2
- package/dist/cjs/services/getFills.js.map +1 -1
- package/dist/cjs/utils/explorer.d.ts.map +1 -1
- package/dist/cjs/utils/explorer.js +2 -1
- package/dist/cjs/utils/explorer.js.map +1 -1
- package/dist/cjs/utils/infoClient.d.ts.map +1 -1
- package/dist/cjs/utils/infoClient.js +2 -1
- package/dist/cjs/utils/infoClient.js.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js +2 -2
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts +1 -0
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js +12 -3
- package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/esm/services/fillLeverages.d.ts +14 -0
- package/dist/esm/services/fillLeverages.d.ts.map +1 -0
- package/dist/esm/services/fillLeverages.js +33 -0
- package/dist/esm/services/fillLeverages.js.map +1 -0
- package/dist/esm/services/getFills.d.ts +3 -2
- package/dist/esm/services/getFills.d.ts.map +1 -1
- package/dist/esm/services/getFills.js +12 -4
- package/dist/esm/services/getFills.js.map +1 -1
- package/dist/esm/utils/explorer.d.ts.map +1 -1
- package/dist/esm/utils/explorer.js +5 -4
- package/dist/esm/utils/explorer.js.map +1 -1
- package/dist/esm/utils/infoClient.d.ts.map +1 -1
- package/dist/esm/utils/infoClient.js +3 -2
- package/dist/esm/utils/infoClient.js.map +1 -1
- package/dist/esm/utils/mapFill.d.ts +2 -0
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +5 -3
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts +1 -0
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.js +14 -4
- package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/types/services/fillLeverages.d.ts +14 -0
- package/dist/types/services/fillLeverages.d.ts.map +1 -0
- package/dist/types/services/getFills.d.ts +3 -2
- package/dist/types/services/getFills.d.ts.map +1 -1
- package/dist/types/utils/explorer.d.ts.map +1 -1
- package/dist/types/utils/infoClient.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts +2 -0
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/websocket/HyperliquidWsProvider.d.ts +1 -0
- package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/fillLeverages.ts +60 -0
- package/src/services/getFills.ts +23 -4
- package/src/utils/explorer.ts +7 -3
- package/src/utils/infoClient.ts +5 -2
- package/src/utils/mapFill.ts +40 -34
- package/src/websocket/HyperliquidWsProvider.ts +27 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../../src/utils/explorer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGzD,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,C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,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"infoClient.d.ts","sourceRoot":"","sources":["../../../src/utils/infoClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAExB,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AA4BxB,gBAAgB;AAChB,eAAO,MAAM,0BAA0B,EAAE,mBAmBxC,CAAA;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,cAAc,EACtB,UAAU,iBAAiB,KAC1B,kBAQD,CAAA;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,CAAC,CAAC,CA8CZ;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAEZ"}
|
|
@@ -5,6 +5,8 @@ import type { HlUserFill } from '../types/index.js';
|
|
|
5
5
|
export { classifyFillFromPosition };
|
|
6
6
|
/** Maps a fill using the market category; the order type stays absent.
|
|
7
7
|
* Invalid times return `undefined`. The venue does not report the order type.
|
|
8
|
+
* A closing fill gets `closedSize` and `entryPrice`, but no `returnOnEquity`:
|
|
9
|
+
* the fill carries no leverage.
|
|
8
10
|
* @param address - Fill owner; only the liquidated account carries `liquidation`.
|
|
9
11
|
* @public
|
|
10
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EAKzB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,IAAI,EAAmB,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAS7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAInD,0FAA0F;AAC1F,OAAO,EAAE,wBAAwB,EAAE,CAAA;AA+BnC;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAClB,MAAM,UAAU,EAChB,QAAQ,aAAa,EACrB,SAAS,MAAM,KACd,IAAI,GAAG,SAqDT,CAAA"}
|
|
@@ -55,6 +55,7 @@ export declare class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
55
55
|
private readonly sacDecodeChain;
|
|
56
56
|
private readonly orderbookDecodeChain;
|
|
57
57
|
private readonly orderUpdateChain;
|
|
58
|
+
private readonly fillChain;
|
|
58
59
|
constructor(wsUrl: string, providerKey: string, client?: PerpsSDKClient);
|
|
59
60
|
private ensureAccountExists;
|
|
60
61
|
subscribe(sub: Subscription, listener: SubscriptionListener, onStatus?: WsStatusListener, onError?: SubscriptionErrorListener): Promise<() => void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperliquidWsProvider.d.ts","sourceRoot":"","sources":["../../../src/websocket/HyperliquidWsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"HyperliquidWsProvider.d.ts","sourceRoot":"","sources":["../../../src/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,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAM;IAEjD,OAAO,CAAC,uBAAuB;IA4C/B,OAAO,CAAC,oBAAoB;IAsD5B,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,gBAAgB;IAuDxB,0EAA0E;IAC1E,OAAO,CAAC,8BAA8B;CAsCvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk-provider-hyperliquid",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "37.0.0",
|
|
4
4
|
"description": "Hyperliquid provider plugin for @lifi/perps-sdk",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"big.js": "^7.0.1",
|
|
51
|
-
"@lifi/perps-types": "^
|
|
51
|
+
"@lifi/perps-types": "^30.0.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"viem": ">=2.57.11 <2.57.12",
|
|
55
|
-
"@lifi/perps-sdk": "^
|
|
55
|
+
"@lifi/perps-sdk": "^34.0.0"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWarnOnce,
|
|
3
|
+
numberToDecimalString,
|
|
4
|
+
type SDKRequestOptions,
|
|
5
|
+
} from '@lifi/perps-sdk'
|
|
6
|
+
import type { DecimalString, Fill } from '@lifi/perps-types'
|
|
7
|
+
import type { Address } from 'viem'
|
|
8
|
+
import { PROVIDER_KEY } from '../constants.js'
|
|
9
|
+
import type { HyperliquidContext } from '../context.js'
|
|
10
|
+
import { fetchActiveAssetData } from './activeAssetData.js'
|
|
11
|
+
|
|
12
|
+
const warnLeverageReadOnce = createWarnOnce()
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Current leverage setting of each market that a fill with a `closedSize`
|
|
16
|
+
* trades, keyed by `Market.id`. Reads `activeAssetData` once for each such
|
|
17
|
+
* market. A failed read leaves its market out, so the ROE of its fills stays
|
|
18
|
+
* absent.
|
|
19
|
+
*
|
|
20
|
+
* @throws The abort reason when `options.signal` aborts.
|
|
21
|
+
*/
|
|
22
|
+
export const fetchFillLeverages = async (
|
|
23
|
+
context: HyperliquidContext,
|
|
24
|
+
address: Address,
|
|
25
|
+
fills: readonly Fill[],
|
|
26
|
+
options?: SDKRequestOptions
|
|
27
|
+
): Promise<Map<string, DecimalString>> => {
|
|
28
|
+
const marketIds = [
|
|
29
|
+
...new Set(
|
|
30
|
+
fills.flatMap((fill) =>
|
|
31
|
+
fill.closedSize === undefined ? [] : [fill.market.id]
|
|
32
|
+
)
|
|
33
|
+
),
|
|
34
|
+
]
|
|
35
|
+
const reads = await Promise.allSettled(
|
|
36
|
+
marketIds.map(async (marketId) => {
|
|
37
|
+
const data = await fetchActiveAssetData(
|
|
38
|
+
context,
|
|
39
|
+
address,
|
|
40
|
+
marketId,
|
|
41
|
+
options
|
|
42
|
+
)
|
|
43
|
+
return numberToDecimalString(data.leverage.value)
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
options?.signal?.throwIfAborted()
|
|
47
|
+
const leverages = new Map<string, DecimalString>()
|
|
48
|
+
reads.forEach((read, index) => {
|
|
49
|
+
const marketId = marketIds[index]
|
|
50
|
+
if (read.status === 'fulfilled') {
|
|
51
|
+
leverages.set(marketId, read.value)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
warnLeverageReadOnce(
|
|
55
|
+
marketId,
|
|
56
|
+
`[${PROVIDER_KEY}] leverage read failed for market '${marketId}'; its fills carry no returnOnEquity: ${String(read.reason)}`
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
return leverages
|
|
60
|
+
}
|
package/src/services/getFills.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
buildFill,
|
|
3
|
+
getMarketRegistry,
|
|
4
|
+
type SDKRequestOptions,
|
|
5
|
+
} from '@lifi/perps-sdk'
|
|
2
6
|
import type { Fill, FillsResponse } from '@lifi/perps-types'
|
|
3
7
|
import type { Address } from 'viem'
|
|
4
8
|
import { FILL_ROWS_CAP, PROVIDER_KEY } from '../constants.js'
|
|
@@ -6,6 +10,7 @@ import type { HyperliquidContext } from '../context.js'
|
|
|
6
10
|
import type { HlTwapSliceFill, HlUserFills } from '../types/index.js'
|
|
7
11
|
import { assetIsOutcome, mapFill } from '../utils/index.js'
|
|
8
12
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
13
|
+
import { fetchFillLeverages } from './fillLeverages.js'
|
|
9
14
|
import { requireAccountExists } from './getAccountExists.js'
|
|
10
15
|
import { getHistoryLimit, historyPage } from './historyPagination.js'
|
|
11
16
|
|
|
@@ -28,13 +33,15 @@ export interface GetFillsParams {
|
|
|
28
33
|
|
|
29
34
|
/**
|
|
30
35
|
* Fetch retained regular and TWAP slice fills newest-first, using opaque
|
|
31
|
-
* cursors across inclusive time ranges.
|
|
36
|
+
* cursors across inclusive time ranges. The ROE of a closing fill uses the
|
|
37
|
+
* current leverage setting of its market.
|
|
32
38
|
*/
|
|
33
39
|
export const getFills = async (
|
|
34
|
-
|
|
40
|
+
context: HyperliquidContext,
|
|
35
41
|
params: GetFillsParams,
|
|
36
42
|
options?: SDKRequestOptions
|
|
37
43
|
): Promise<FillsResponse> => {
|
|
44
|
+
const { client, apiUrl } = context
|
|
38
45
|
const limit = getHistoryLimit(params.limit)
|
|
39
46
|
const infoOpts = hlInfoOptions(client, options)
|
|
40
47
|
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
@@ -90,5 +97,17 @@ export const getFills = async (
|
|
|
90
97
|
}),
|
|
91
98
|
options?.signal
|
|
92
99
|
)
|
|
93
|
-
|
|
100
|
+
const leverages = await fetchFillLeverages(
|
|
101
|
+
context,
|
|
102
|
+
params.address,
|
|
103
|
+
page.items,
|
|
104
|
+
options
|
|
105
|
+
)
|
|
106
|
+
return {
|
|
107
|
+
provider: PROVIDER_KEY,
|
|
108
|
+
...page,
|
|
109
|
+
items: page.items.map((fill) =>
|
|
110
|
+
buildFill(fill, leverages.get(fill.market.id))
|
|
111
|
+
),
|
|
112
|
+
}
|
|
94
113
|
}
|
package/src/utils/explorer.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
createWarnOnce,
|
|
3
3
|
ExplorerChainId,
|
|
4
4
|
explorerTxUrl,
|
|
5
|
+
isAbortRejection,
|
|
5
6
|
PerpsError,
|
|
6
7
|
} from '@lifi/perps-sdk'
|
|
7
8
|
import type { Order, OrderBase } from '@lifi/perps-types'
|
|
@@ -119,9 +120,12 @@ export const withExplorerLinks = async (
|
|
|
119
120
|
try {
|
|
120
121
|
txs = await fetchUserTransactions(address, options)
|
|
121
122
|
} catch (error) {
|
|
122
|
-
//
|
|
123
|
-
// not
|
|
124
|
-
if (
|
|
123
|
+
// A caller can abort with a `PerpsError` reason, so the type alone does
|
|
124
|
+
// not tell a cancel from an explorer failure.
|
|
125
|
+
if (
|
|
126
|
+
isAbortRejection(error, options.signal) ||
|
|
127
|
+
!(error instanceof PerpsError)
|
|
128
|
+
) {
|
|
125
129
|
throw error
|
|
126
130
|
}
|
|
127
131
|
// The message stays out of the key: a transport failure names hosts and
|
package/src/utils/infoClient.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
errorCodeFromStatus,
|
|
3
3
|
fetchWithRetry,
|
|
4
|
-
|
|
4
|
+
isAbortRejection,
|
|
5
5
|
PerpsError,
|
|
6
6
|
type PerpsSDKClient,
|
|
7
7
|
type ResolvedRetryPolicy,
|
|
@@ -143,7 +143,10 @@ export async function hlPostJson<T>(
|
|
|
143
143
|
|
|
144
144
|
return (await response.json()) as T
|
|
145
145
|
} catch (error) {
|
|
146
|
-
if (
|
|
146
|
+
if (
|
|
147
|
+
error instanceof PerpsError ||
|
|
148
|
+
isAbortRejection(error, options?.signal)
|
|
149
|
+
) {
|
|
147
150
|
throw error
|
|
148
151
|
}
|
|
149
152
|
const err = new PerpsError(
|
package/src/utils/mapFill.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
buildFill,
|
|
2
3
|
classifyFillFromPosition,
|
|
3
4
|
ExplorerChainId,
|
|
4
5
|
explorerTxUrl,
|
|
@@ -52,6 +53,8 @@ const mapFillLiquidation = (
|
|
|
52
53
|
|
|
53
54
|
/** Maps a fill using the market category; the order type stays absent.
|
|
54
55
|
* Invalid times return `undefined`. The venue does not report the order type.
|
|
56
|
+
* A closing fill gets `closedSize` and `entryPrice`, but no `returnOnEquity`:
|
|
57
|
+
* the fill carries no leverage.
|
|
55
58
|
* @param address - Fill owner; only the liquidated account carries `liquidation`.
|
|
56
59
|
* @public
|
|
57
60
|
*/
|
|
@@ -74,39 +77,42 @@ export const mapFill = (
|
|
|
74
77
|
const side = fill.side === 'B' ? OrderSide.BUY : OrderSide.SELL
|
|
75
78
|
const liquidation = mapFillLiquidation(fill, address)
|
|
76
79
|
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
return buildFill(
|
|
81
|
+
{
|
|
82
|
+
...(isSpotCategory(market.categoryId)
|
|
83
|
+
? { realizedPnl: fill.closedPnl }
|
|
84
|
+
: { realizedPnl: fill.closedPnl === '0' ? null : fill.closedPnl }),
|
|
85
|
+
id: String(fill.tid),
|
|
86
|
+
orderId: String(fill.oid),
|
|
87
|
+
clientOrderId: fill.cloid,
|
|
88
|
+
market,
|
|
89
|
+
side,
|
|
90
|
+
size,
|
|
91
|
+
price: fill.px,
|
|
92
|
+
liquidity: fill.crossed ? LiquidityRole.TAKER : LiquidityRole.MAKER,
|
|
93
|
+
filledSize: size,
|
|
94
|
+
fee: {
|
|
95
|
+
amount: fill.fee,
|
|
96
|
+
asset: feeAsset,
|
|
97
|
+
},
|
|
98
|
+
builderFee:
|
|
99
|
+
fill.builderFee === undefined
|
|
100
|
+
? undefined
|
|
101
|
+
: { amount: fill.builderFee, asset: feeAsset },
|
|
102
|
+
startPosition: fill.startPosition,
|
|
103
|
+
// A TWAP slice fill carries the zero hash: no venue transaction to link.
|
|
104
|
+
explorerLink: explorerTxUrl(
|
|
105
|
+
ExplorerChainId.HYPERLIQUID,
|
|
106
|
+
fill.hash === zeroHash ? undefined : fill.hash
|
|
107
|
+
),
|
|
108
|
+
classification: isSpotCategory(market.categoryId)
|
|
109
|
+
? side === OrderSide.BUY
|
|
110
|
+
? FillClassification.SPOT_BUY
|
|
111
|
+
: FillClassification.SPOT_SELL
|
|
112
|
+
: classifyFillFromPosition(fill.startPosition, side, size),
|
|
113
|
+
createdAt,
|
|
114
|
+
...(liquidation === undefined ? {} : { liquidation }),
|
|
93
115
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
? undefined
|
|
97
|
-
: { amount: fill.builderFee, asset: feeAsset },
|
|
98
|
-
startPosition: fill.startPosition,
|
|
99
|
-
// A TWAP slice fill carries the zero hash: no venue transaction to link.
|
|
100
|
-
explorerLink: explorerTxUrl(
|
|
101
|
-
ExplorerChainId.HYPERLIQUID,
|
|
102
|
-
fill.hash === zeroHash ? undefined : fill.hash
|
|
103
|
-
),
|
|
104
|
-
classification: isSpotCategory(market.categoryId)
|
|
105
|
-
? side === OrderSide.BUY
|
|
106
|
-
? FillClassification.SPOT_BUY
|
|
107
|
-
: FillClassification.SPOT_SELL
|
|
108
|
-
: classifyFillFromPosition(fill.startPosition, side, size),
|
|
109
|
-
createdAt,
|
|
110
|
-
...(liquidation === undefined ? {} : { liquidation }),
|
|
111
|
-
}
|
|
116
|
+
undefined
|
|
117
|
+
)
|
|
112
118
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AssetRegistry,
|
|
3
3
|
addDecimalString,
|
|
4
|
+
buildFill,
|
|
4
5
|
calculateTransferable,
|
|
5
6
|
compareDecimalStrings,
|
|
6
7
|
DecodeChain,
|
|
@@ -56,6 +57,7 @@ import {
|
|
|
56
57
|
HYPERLIQUID_FEE_TIER_FALLBACK,
|
|
57
58
|
PROVIDER_KEY,
|
|
58
59
|
} from '../constants.js'
|
|
60
|
+
import { fetchFillLeverages } from '../services/fillLeverages.js'
|
|
59
61
|
import { requireAccountExists } from '../services/getAccountExists.js'
|
|
60
62
|
import type {
|
|
61
63
|
HlActiveAssetData,
|
|
@@ -240,6 +242,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
240
242
|
'every',
|
|
241
243
|
this.reportDecodeFailure
|
|
242
244
|
)
|
|
245
|
+
// A closing fill waits for a leverage read, so fills frames emit in order.
|
|
246
|
+
private readonly fillChain = new DecodeChain(
|
|
247
|
+
'every',
|
|
248
|
+
this.reportDecodeFailure
|
|
249
|
+
)
|
|
243
250
|
|
|
244
251
|
constructor(wsUrl: string, providerKey: string, client?: PerpsSDKClient) {
|
|
245
252
|
super(
|
|
@@ -611,6 +618,7 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
611
618
|
this.sacDecodeChain.reset()
|
|
612
619
|
this.orderbookDecodeChain.reset()
|
|
613
620
|
this.orderUpdateChain.reset()
|
|
621
|
+
this.fillChain.reset()
|
|
614
622
|
this.orderUpdatesEpoch++
|
|
615
623
|
this.orderUpdatesKey = undefined
|
|
616
624
|
}
|
|
@@ -1304,9 +1312,25 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
1304
1312
|
const mapped = market && mapFill(f, market, user)
|
|
1305
1313
|
return mapped ? [mapped] : []
|
|
1306
1314
|
})
|
|
1307
|
-
this.
|
|
1308
|
-
|
|
1309
|
-
|
|
1315
|
+
const client = this.client
|
|
1316
|
+
this.fillChain.push(async () => {
|
|
1317
|
+
const leverages =
|
|
1318
|
+
client === undefined || !isAddress(user, { strict: false })
|
|
1319
|
+
? undefined
|
|
1320
|
+
: await this.readFrameEnrichment('fill leverage', (signal) =>
|
|
1321
|
+
fetchFillLeverages(
|
|
1322
|
+
{ client, apiUrl: this.orderApiUrl },
|
|
1323
|
+
user,
|
|
1324
|
+
items,
|
|
1325
|
+
{ signal }
|
|
1326
|
+
)
|
|
1327
|
+
)
|
|
1328
|
+
this.emit(`fills:${user.toLowerCase()}`, {
|
|
1329
|
+
channel: 'fills',
|
|
1330
|
+
data: items.map((fill) =>
|
|
1331
|
+
buildFill(fill, leverages?.get(fill.market.id))
|
|
1332
|
+
),
|
|
1333
|
+
})
|
|
1310
1334
|
})
|
|
1311
1335
|
}
|
|
1312
1336
|
|