@lifi/perps-sdk-provider-hyperliquid 0.0.0-preview-414653a → 0.0.0-preview-e1b82a0
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/types/ws.d.ts +2 -2
- package/dist/cjs/types/ws.d.ts.map +1 -1
- package/dist/cjs/utils/decimal.d.ts +0 -1
- package/dist/cjs/utils/decimal.d.ts.map +1 -1
- package/dist/cjs/utils/decimal.js +1 -8
- package/dist/cjs/utils/decimal.js.map +1 -1
- package/dist/cjs/utils/mapMarketContext.d.ts.map +1 -1
- package/dist/cjs/utils/mapMarketContext.js +2 -3
- package/dist/cjs/utils/mapMarketContext.js.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.js +3 -2
- package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js +26 -22
- package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/esm/services/getWithdrawableBalances.d.ts +1 -1
- package/dist/esm/services/getWithdrawableBalances.js +1 -1
- package/dist/esm/types/ws.d.ts +3 -4
- package/dist/esm/types/ws.d.ts.map +1 -1
- package/dist/esm/utils/decimal.d.ts +0 -5
- package/dist/esm/utils/decimal.d.ts.map +1 -1
- package/dist/esm/utils/decimal.js +1 -11
- package/dist/esm/utils/decimal.js.map +1 -1
- package/dist/esm/utils/mapMarketContext.d.ts.map +1 -1
- package/dist/esm/utils/mapMarketContext.js +2 -3
- package/dist/esm/utils/mapMarketContext.js.map +1 -1
- package/dist/esm/utils/withdrawableBalances.d.ts +4 -4
- package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/esm/utils/withdrawableBalances.js +7 -6
- package/dist/esm/utils/withdrawableBalances.js.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.js +15 -11
- package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/types/services/getWithdrawableBalances.d.ts +1 -1
- package/dist/types/types/ws.d.ts +3 -4
- package/dist/types/types/ws.d.ts.map +1 -1
- package/dist/types/utils/decimal.d.ts +0 -5
- package/dist/types/utils/decimal.d.ts.map +1 -1
- package/dist/types/utils/mapMarketContext.d.ts.map +1 -1
- package/dist/types/utils/withdrawableBalances.d.ts +4 -4
- package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/services/getWithdrawableBalances.ts +1 -1
- package/src/types/ws.ts +3 -4
- package/src/utils/decimal.ts +1 -12
- package/src/utils/mapMarketContext.ts +2 -3
- package/src/utils/withdrawableBalances.ts +7 -6
- package/src/websocket/HyperliquidWsProvider.ts +16 -11
package/src/utils/decimal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PerpsError } from '@lifi/perps-sdk'
|
|
2
2
|
import { PerpsErrorCode } from '@lifi/perps-types'
|
|
3
3
|
import Big from 'big.js'
|
|
4
4
|
|
|
@@ -19,14 +19,3 @@ export const toWireBig = (value: string, field: string): Big => {
|
|
|
19
19
|
)
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Decimal string for a Hyperliquid context field that the venue sends as a
|
|
25
|
-
* string or a number. Any other value is absent.
|
|
26
|
-
*/
|
|
27
|
-
export const toMarketContextString = (value: unknown): string | undefined => {
|
|
28
|
-
if (typeof value === 'number') {
|
|
29
|
-
return numberToDecimalString(value)
|
|
30
|
-
}
|
|
31
|
-
return typeof value === 'string' ? value : undefined
|
|
32
|
-
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { MarketContext } from '@lifi/perps-types'
|
|
2
2
|
import Big from 'big.js'
|
|
3
3
|
import type { HlWsFastAssetCtx, HlWsPerpAssetCtx } from '../types/index.js'
|
|
4
|
-
import { toMarketContextString } from './decimal.js'
|
|
5
4
|
|
|
6
5
|
const NEXT_FUNDING_INTERVAL_MS = 60 * 60 * 1000 // 1 hour
|
|
7
6
|
|
|
@@ -41,11 +40,11 @@ export const mapMarketContext = (
|
|
|
41
40
|
const now = Date.now()
|
|
42
41
|
const nextFundingTime =
|
|
43
42
|
Math.ceil(now / NEXT_FUNDING_INTERVAL_MS) * NEXT_FUNDING_INTERVAL_MS
|
|
44
|
-
const markPrice =
|
|
43
|
+
const markPrice = fast?.markPx != null ? fast.markPx : ctx.markPx
|
|
45
44
|
|
|
46
45
|
return {
|
|
47
46
|
marketId,
|
|
48
|
-
midPrice:
|
|
47
|
+
midPrice: fast?.midPx != null ? fast.midPx : (ctx.midPx ?? ctx.markPx),
|
|
49
48
|
markPrice,
|
|
50
49
|
oraclePrice: ctx.oraclePx,
|
|
51
50
|
prevDayPrice: ctx.prevDayPx,
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
calculateWithdrawMax,
|
|
3
3
|
type ProviderWithdrawableBalance,
|
|
4
4
|
} from '@lifi/perps-sdk'
|
|
5
|
+
import { PROVIDER_KEY, SPOT_MARKET_ID } from '../constants.js'
|
|
5
6
|
import type {
|
|
6
7
|
HlAbstractionMode,
|
|
7
8
|
HlClearinghouseState,
|
|
@@ -12,13 +13,13 @@ import { assetIsOutcome } from './assetId.js'
|
|
|
12
13
|
import { toWireBig } from './decimal.js'
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
* Split a Hyperliquid account's venue figures into the
|
|
16
|
-
* draws on. A unified or portfolio-margin account holds its collateral in spot,
|
|
16
|
+
* Split a Hyperliquid account's venue figures into the categories a
|
|
17
|
+
* withdrawal draws on. A unified or portfolio-margin account holds its collateral in spot,
|
|
17
18
|
* so each spot token adds the part of `total` that no order or margin holds. A
|
|
18
|
-
*
|
|
19
|
+
* category with nothing left to draw carries no row, and the caller applies the
|
|
19
20
|
* per-asset venue minimum.
|
|
20
21
|
*
|
|
21
|
-
* @param quoteAssetId - `Asset.id` the perps-
|
|
22
|
+
* @param quoteAssetId - `Asset.id` the perps-category row is keyed by.
|
|
22
23
|
* @param withdrawalFee - Flat venue fee in quote-asset units, set on every
|
|
23
24
|
* quote-asset row. Hyperliquid deducts it from the requested amount. Absent
|
|
24
25
|
* leaves every row without a fee.
|
|
@@ -55,7 +56,7 @@ export const hyperliquidWithdrawableBalances = (
|
|
|
55
56
|
const assetId = String(balance.token)
|
|
56
57
|
const row = {
|
|
57
58
|
assetId,
|
|
58
|
-
|
|
59
|
+
categoryId: SPOT_MARKET_ID,
|
|
59
60
|
available: spot.toFixed(),
|
|
60
61
|
...feeFor(assetId),
|
|
61
62
|
}
|
|
@@ -68,7 +69,7 @@ export const hyperliquidWithdrawableBalances = (
|
|
|
68
69
|
if (perps.gt(0)) {
|
|
69
70
|
const row = {
|
|
70
71
|
assetId: quoteAssetId,
|
|
71
|
-
|
|
72
|
+
categoryId: PROVIDER_KEY,
|
|
72
73
|
available: perps.toFixed(),
|
|
73
74
|
...feeFor(quoteAssetId),
|
|
74
75
|
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
isActiveMarket,
|
|
6
6
|
isActiveOrderStatus,
|
|
7
7
|
type MarketRegistry,
|
|
8
|
+
numberToDecimalString,
|
|
8
9
|
PerpsError,
|
|
9
10
|
type PerpsSDKClient,
|
|
10
11
|
type ProviderGetQuoteParams,
|
|
@@ -66,7 +67,7 @@ import type {
|
|
|
66
67
|
HlWsUserFillsData,
|
|
67
68
|
} from '../types/index.js'
|
|
68
69
|
import { HlAbstractionMode } from '../types/index.js'
|
|
69
|
-
import {
|
|
70
|
+
import { toWireBig } from '../utils/decimal.js'
|
|
70
71
|
import {
|
|
71
72
|
assetIsOutcome,
|
|
72
73
|
decodeCompressedJson,
|
|
@@ -915,11 +916,9 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
915
916
|
if (perpCtx !== undefined) {
|
|
916
917
|
return mapMarketContext(marketId, perpCtx, fast)
|
|
917
918
|
}
|
|
918
|
-
const
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
const markPrice = fastMark ?? fastMid
|
|
922
|
-
if (midPrice !== undefined && markPrice !== undefined) {
|
|
919
|
+
const midPrice = fast?.midPx ?? fast?.markPx
|
|
920
|
+
const markPrice = fast?.markPx ?? fast?.midPx
|
|
921
|
+
if (midPrice != null && markPrice != null) {
|
|
923
922
|
return { marketId, midPrice, markPrice }
|
|
924
923
|
}
|
|
925
924
|
return undefined
|
|
@@ -970,9 +969,8 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
970
969
|
}
|
|
971
970
|
}
|
|
972
971
|
for (const [id, fast] of Object.entries(this.fastCtxByMarketId)) {
|
|
973
|
-
const mid =
|
|
974
|
-
|
|
975
|
-
if (mid !== undefined) {
|
|
972
|
+
const mid = fast.midPx ?? fast.markPx
|
|
973
|
+
if (mid != null) {
|
|
976
974
|
map.set(id, Number(mid))
|
|
977
975
|
}
|
|
978
976
|
}
|
|
@@ -1611,6 +1609,13 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
|
|
|
1611
1609
|
const isObject = (v: unknown): v is Record<string, unknown> =>
|
|
1612
1610
|
typeof v === 'object' && v !== null
|
|
1613
1611
|
|
|
1612
|
+
const toMarketContextString = (value: unknown): string | undefined => {
|
|
1613
|
+
if (typeof value === 'number') {
|
|
1614
|
+
return numberToDecimalString(value)
|
|
1615
|
+
}
|
|
1616
|
+
return typeof value === 'string' ? value : undefined
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1614
1619
|
const toMarketCapString = (
|
|
1615
1620
|
price: unknown,
|
|
1616
1621
|
circulatingSupply: unknown
|
|
@@ -1725,10 +1730,10 @@ function mapSpotMarketContext(
|
|
|
1725
1730
|
return undefined
|
|
1726
1731
|
}
|
|
1727
1732
|
|
|
1728
|
-
const emittedMarkPrice =
|
|
1733
|
+
const emittedMarkPrice = fast?.markPx != null ? fast.markPx : markPrice
|
|
1729
1734
|
return {
|
|
1730
1735
|
marketId,
|
|
1731
|
-
midPrice:
|
|
1736
|
+
midPrice: fast?.midPx != null ? fast.midPx : midPrice,
|
|
1732
1737
|
markPrice: emittedMarkPrice,
|
|
1733
1738
|
prevDayPrice: toMarketContextString(ctx.prevDayPx),
|
|
1734
1739
|
volume24h: toMarketContextString(ctx.dayNtlVlm),
|