@lifi/perps-sdk-provider-hyperliquid 5.1.0 → 6.0.1
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/HyperliquidProvider.d.ts.map +1 -1
- package/dist/cjs/HyperliquidProvider.js +4 -0
- package/dist/cjs/HyperliquidProvider.js.map +1 -1
- package/dist/cjs/services/getAccount.d.ts.map +1 -1
- package/dist/cjs/services/getAccount.js +1 -1
- package/dist/cjs/services/getAccount.js.map +1 -1
- package/dist/cjs/services/getActivity.d.ts.map +1 -1
- package/dist/cjs/services/getActivity.js.map +1 -1
- package/dist/cjs/services/getFills.d.ts.map +1 -1
- package/dist/cjs/services/getFills.js.map +1 -1
- package/dist/cjs/services/getMarketSettings.d.ts +10 -0
- package/dist/cjs/services/getMarketSettings.d.ts.map +1 -0
- package/dist/cjs/services/getMarketSettings.js +26 -0
- package/dist/cjs/services/getMarketSettings.js.map +1 -0
- package/dist/cjs/services/getOrders.d.ts.map +1 -1
- 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/signers/HyperliquidAgentStore.d.ts.map +1 -1
- package/dist/cjs/signers/HyperliquidAgentStore.js.map +1 -1
- package/dist/cjs/signers/signActions.d.ts.map +1 -1
- package/dist/cjs/signers/signActions.js.map +1 -1
- package/dist/cjs/types/account.d.ts +11 -0
- package/dist/cjs/types/account.d.ts.map +1 -1
- package/dist/cjs/types/account.js.map +1 -1
- package/dist/cjs/types/action.d.ts.map +1 -1
- package/dist/cjs/types/action.js.map +1 -1
- package/dist/cjs/types/asset.d.ts +1 -0
- package/dist/cjs/types/asset.d.ts.map +1 -1
- package/dist/cjs/types/fill.d.ts.map +1 -1
- package/dist/cjs/types/ledger.d.ts.map +1 -1
- package/dist/cjs/types/ledger.js.map +1 -1
- package/dist/cjs/types/order.d.ts.map +1 -1
- package/dist/cjs/types/ws.d.ts.map +1 -1
- package/dist/cjs/utils/assetId.d.ts.map +1 -1
- package/dist/cjs/utils/assetId.js.map +1 -1
- package/dist/cjs/utils/assetLogo.d.ts.map +1 -1
- package/dist/cjs/utils/assetLogo.js.map +1 -1
- package/dist/cjs/utils/decodeFastAssetCtxs.d.ts.map +1 -1
- package/dist/cjs/utils/decodeFastAssetCtxs.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +3 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/infoClient.d.ts.map +1 -1
- package/dist/cjs/utils/infoClient.js.map +1 -1
- package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
- package/dist/cjs/utils/mapActivity.js +13 -10
- package/dist/cjs/utils/mapActivity.js.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/mapMarket.d.ts.map +1 -1
- package/dist/cjs/utils/mapMarket.js +6 -1
- package/dist/cjs/utils/mapMarket.js.map +1 -1
- package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
- package/dist/cjs/utils/mapOrder.js.map +1 -1
- package/dist/cjs/utils/mapPosition.d.ts +2 -2
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
- package/dist/cjs/utils/mapPosition.js +17 -10
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
- package/dist/cjs/utils/spotBalance.js.map +1 -1
- package/dist/cjs/utils/spotCollateral.d.ts.map +1 -1
- package/dist/cjs/utils/spotCollateral.js.map +1 -1
- package/dist/cjs/utils/transferMargin.d.ts +3 -0
- package/dist/cjs/utils/transferMargin.d.ts.map +1 -0
- package/dist/cjs/utils/transferMargin.js +40 -0
- package/dist/cjs/utils/transferMargin.js.map +1 -0
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js +3 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/esm/HyperliquidProvider.d.ts +14 -4
- package/dist/esm/HyperliquidProvider.d.ts.map +1 -1
- package/dist/esm/HyperliquidProvider.js +4 -0
- package/dist/esm/HyperliquidProvider.js.map +1 -1
- package/dist/esm/services/getAccount.d.ts.map +1 -1
- package/dist/esm/services/getAccount.js +2 -2
- package/dist/esm/services/getAccount.js.map +1 -1
- package/dist/esm/services/getActivity.d.ts +5 -1
- package/dist/esm/services/getActivity.d.ts.map +1 -1
- package/dist/esm/services/getActivity.js.map +1 -1
- package/dist/esm/services/getFills.d.ts +4 -3
- package/dist/esm/services/getFills.d.ts.map +1 -1
- package/dist/esm/services/getFills.js.map +1 -1
- package/dist/esm/services/getMarketSettings.d.ts +21 -0
- package/dist/esm/services/getMarketSettings.d.ts.map +1 -0
- package/dist/esm/services/getMarketSettings.js +29 -0
- package/dist/esm/services/getMarketSettings.js.map +1 -0
- package/dist/esm/services/getOrders.d.ts +2 -1
- package/dist/esm/services/getOrders.d.ts.map +1 -1
- package/dist/esm/services/getOrders.js.map +1 -1
- package/dist/esm/services/getPositions.d.ts +2 -2
- 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/signers/HyperliquidAgentStore.d.ts +3 -3
- package/dist/esm/signers/HyperliquidAgentStore.d.ts.map +1 -1
- package/dist/esm/signers/HyperliquidAgentStore.js +1 -0
- package/dist/esm/signers/HyperliquidAgentStore.js.map +1 -1
- package/dist/esm/signers/signActions.d.ts +8 -6
- package/dist/esm/signers/signActions.d.ts.map +1 -1
- package/dist/esm/signers/signActions.js +8 -6
- package/dist/esm/signers/signActions.js.map +1 -1
- package/dist/esm/types/account.d.ts +68 -8
- package/dist/esm/types/account.d.ts.map +1 -1
- package/dist/esm/types/account.js.map +1 -1
- package/dist/esm/types/action.d.ts +28 -10
- package/dist/esm/types/action.d.ts.map +1 -1
- package/dist/esm/types/action.js +7 -7
- package/dist/esm/types/action.js.map +1 -1
- package/dist/esm/types/asset.d.ts +62 -15
- package/dist/esm/types/asset.d.ts.map +1 -1
- package/dist/esm/types/fill.d.ts +9 -3
- package/dist/esm/types/fill.d.ts.map +1 -1
- package/dist/esm/types/ledger.d.ts +24 -6
- package/dist/esm/types/ledger.d.ts.map +1 -1
- package/dist/esm/types/ledger.js.map +1 -1
- package/dist/esm/types/order.d.ts +19 -5
- package/dist/esm/types/order.d.ts.map +1 -1
- package/dist/esm/types/ws.d.ts +43 -14
- package/dist/esm/types/ws.d.ts.map +1 -1
- package/dist/esm/utils/assetId.d.ts +7 -7
- package/dist/esm/utils/assetId.d.ts.map +1 -1
- package/dist/esm/utils/assetId.js +7 -7
- package/dist/esm/utils/assetId.js.map +1 -1
- package/dist/esm/utils/assetLogo.d.ts +15 -13
- package/dist/esm/utils/assetLogo.d.ts.map +1 -1
- package/dist/esm/utils/assetLogo.js +15 -13
- package/dist/esm/utils/assetLogo.js.map +1 -1
- package/dist/esm/utils/decodeFastAssetCtxs.d.ts +7 -1
- package/dist/esm/utils/decodeFastAssetCtxs.d.ts.map +1 -1
- package/dist/esm/utils/decodeFastAssetCtxs.js +7 -1
- package/dist/esm/utils/decodeFastAssetCtxs.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/infoClient.d.ts +6 -1
- package/dist/esm/utils/infoClient.d.ts.map +1 -1
- package/dist/esm/utils/infoClient.js.map +1 -1
- package/dist/esm/utils/mapActivity.d.ts +10 -1
- package/dist/esm/utils/mapActivity.d.ts.map +1 -1
- package/dist/esm/utils/mapActivity.js +23 -11
- package/dist/esm/utils/mapActivity.js.map +1 -1
- package/dist/esm/utils/mapFill.d.ts +1 -0
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +1 -0
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapMarket.d.ts.map +1 -1
- package/dist/esm/utils/mapMarket.js +8 -1
- package/dist/esm/utils/mapMarket.js.map +1 -1
- package/dist/esm/utils/mapOrder.d.ts +15 -4
- package/dist/esm/utils/mapOrder.d.ts.map +1 -1
- package/dist/esm/utils/mapOrder.js +15 -4
- package/dist/esm/utils/mapOrder.js.map +1 -1
- package/dist/esm/utils/mapPosition.d.ts +8 -3
- package/dist/esm/utils/mapPosition.d.ts.map +1 -1
- package/dist/esm/utils/mapPosition.js +20 -11
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/esm/utils/spotBalance.d.ts +9 -10
- package/dist/esm/utils/spotBalance.d.ts.map +1 -1
- package/dist/esm/utils/spotBalance.js +9 -10
- package/dist/esm/utils/spotBalance.js.map +1 -1
- package/dist/esm/utils/spotCollateral.d.ts +9 -5
- package/dist/esm/utils/spotCollateral.d.ts.map +1 -1
- package/dist/esm/utils/spotCollateral.js +4 -4
- package/dist/esm/utils/spotCollateral.js.map +1 -1
- package/dist/esm/utils/transferMargin.d.ts +14 -0
- package/dist/esm/utils/transferMargin.d.ts.map +1 -0
- package/dist/esm/utils/transferMargin.js +45 -0
- package/dist/esm/utils/transferMargin.js.map +1 -0
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.js +4 -2
- package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/types/HyperliquidProvider.d.ts +14 -4
- package/dist/types/HyperliquidProvider.d.ts.map +1 -1
- package/dist/types/services/getAccount.d.ts.map +1 -1
- package/dist/types/services/getActivity.d.ts +5 -1
- package/dist/types/services/getActivity.d.ts.map +1 -1
- package/dist/types/services/getFills.d.ts +4 -3
- package/dist/types/services/getFills.d.ts.map +1 -1
- package/dist/types/services/getMarketSettings.d.ts +21 -0
- package/dist/types/services/getMarketSettings.d.ts.map +1 -0
- package/dist/types/services/getOrders.d.ts +2 -1
- package/dist/types/services/getOrders.d.ts.map +1 -1
- package/dist/types/services/getPositions.d.ts +2 -2
- package/dist/types/services/getPositions.d.ts.map +1 -1
- package/dist/types/signers/HyperliquidAgentStore.d.ts +3 -3
- package/dist/types/signers/HyperliquidAgentStore.d.ts.map +1 -1
- package/dist/types/signers/signActions.d.ts +8 -6
- package/dist/types/signers/signActions.d.ts.map +1 -1
- package/dist/types/types/account.d.ts +68 -8
- package/dist/types/types/account.d.ts.map +1 -1
- package/dist/types/types/action.d.ts +28 -10
- package/dist/types/types/action.d.ts.map +1 -1
- package/dist/types/types/asset.d.ts +62 -15
- package/dist/types/types/asset.d.ts.map +1 -1
- package/dist/types/types/fill.d.ts +9 -3
- package/dist/types/types/fill.d.ts.map +1 -1
- package/dist/types/types/ledger.d.ts +24 -6
- package/dist/types/types/ledger.d.ts.map +1 -1
- package/dist/types/types/order.d.ts +19 -5
- package/dist/types/types/order.d.ts.map +1 -1
- package/dist/types/types/ws.d.ts +43 -14
- package/dist/types/types/ws.d.ts.map +1 -1
- package/dist/types/utils/assetId.d.ts +7 -7
- package/dist/types/utils/assetId.d.ts.map +1 -1
- package/dist/types/utils/assetLogo.d.ts +15 -13
- package/dist/types/utils/assetLogo.d.ts.map +1 -1
- package/dist/types/utils/decodeFastAssetCtxs.d.ts +7 -1
- package/dist/types/utils/decodeFastAssetCtxs.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/infoClient.d.ts +6 -1
- package/dist/types/utils/infoClient.d.ts.map +1 -1
- package/dist/types/utils/mapActivity.d.ts +10 -1
- package/dist/types/utils/mapActivity.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts +1 -0
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/utils/mapMarket.d.ts.map +1 -1
- package/dist/types/utils/mapOrder.d.ts +15 -4
- package/dist/types/utils/mapOrder.d.ts.map +1 -1
- package/dist/types/utils/mapPosition.d.ts +8 -3
- package/dist/types/utils/mapPosition.d.ts.map +1 -1
- package/dist/types/utils/spotBalance.d.ts +9 -10
- package/dist/types/utils/spotBalance.d.ts.map +1 -1
- package/dist/types/utils/spotCollateral.d.ts +9 -5
- package/dist/types/utils/spotCollateral.d.ts.map +1 -1
- package/dist/types/utils/transferMargin.d.ts +14 -0
- package/dist/types/utils/transferMargin.d.ts.map +1 -0
- package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/HyperliquidProvider.ts +30 -4
- package/src/services/getAccount.ts +7 -1
- package/src/services/getActivity.ts +5 -1
- package/src/services/getFills.ts +4 -3
- package/src/services/getMarketSettings.ts +56 -0
- package/src/services/getOrders.ts +2 -1
- package/src/services/getPositions.ts +13 -4
- package/src/signers/HyperliquidAgentStore.ts +3 -3
- package/src/signers/signActions.ts +8 -6
- package/src/types/account.ts +66 -8
- package/src/types/action.ts +28 -10
- package/src/types/asset.ts +62 -15
- package/src/types/fill.ts +9 -3
- package/src/types/ledger.ts +24 -6
- package/src/types/order.ts +19 -5
- package/src/types/ws.ts +43 -14
- package/src/utils/assetId.ts +7 -7
- package/src/utils/assetLogo.ts +15 -13
- package/src/utils/decodeFastAssetCtxs.ts +7 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/infoClient.ts +6 -1
- package/src/utils/mapActivity.ts +23 -11
- package/src/utils/mapFill.ts +1 -0
- package/src/utils/mapMarket.ts +10 -1
- package/src/utils/mapOrder.ts +15 -4
- package/src/utils/mapPosition.ts +24 -15
- package/src/utils/spotBalance.ts +9 -10
- package/src/utils/spotCollateral.ts +9 -5
- package/src/utils/transferMargin.ts +65 -0
- package/src/websocket/HyperliquidWsProvider.ts +4 -1
package/src/types/ledger.ts
CHANGED
|
@@ -50,7 +50,11 @@ export type HlSendAssetDelta = {
|
|
|
50
50
|
feeToken: string
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Union of known Hyperliquid non-funding ledger deltas plus an open fallback
|
|
55
|
+
* for endpoint variants the provider does not map.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
54
58
|
export type HlLedgerDelta =
|
|
55
59
|
| HlSpotTransferDelta
|
|
56
60
|
| HlSendAssetDelta
|
|
@@ -81,17 +85,26 @@ export const isSendAssetDelta = (
|
|
|
81
85
|
delta: HlLedgerDelta
|
|
82
86
|
): delta is HlSendAssetDelta => delta.type === 'send'
|
|
83
87
|
|
|
84
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* One timestamped non-funding ledger update. `time` is milliseconds since
|
|
90
|
+
* epoch and `hash` is the upstream transaction identifier.
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
85
93
|
export type HlLedgerUpdate = {
|
|
86
94
|
time: number
|
|
87
95
|
hash: string
|
|
88
96
|
delta: HlLedgerDelta
|
|
89
97
|
}
|
|
90
98
|
|
|
91
|
-
/** @public */
|
|
99
|
+
/** Array returned by `userNonFundingLedgerUpdates`. @public */
|
|
92
100
|
export type HlUserNonFundingLedgerUpdates = HlLedgerUpdate[]
|
|
93
101
|
|
|
94
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Funding ledger delta returned by Hyperliquid `userFunding`. `usdc` is the
|
|
104
|
+
* funding payment, `szi` is signed position size, and `fundingRate` is a
|
|
105
|
+
* decimal fraction; all are decimal strings.
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
95
108
|
export type HlFundingDelta = {
|
|
96
109
|
type: 'funding'
|
|
97
110
|
coin: string
|
|
@@ -100,12 +113,17 @@ export type HlFundingDelta = {
|
|
|
100
113
|
fundingRate: string
|
|
101
114
|
}
|
|
102
115
|
|
|
103
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Timestamped funding update. `time` is milliseconds since epoch; `hash` is
|
|
118
|
+
* always the zero hash — funding is a system ledger event with no venue
|
|
119
|
+
* transaction behind it.
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
104
122
|
export type HlFundingUpdate = {
|
|
105
123
|
time: number
|
|
106
124
|
hash: string
|
|
107
125
|
delta: HlFundingDelta
|
|
108
126
|
}
|
|
109
127
|
|
|
110
|
-
/** @public */
|
|
128
|
+
/** Array returned by the `userFunding` info query. @public */
|
|
111
129
|
export type HlUserFunding = HlFundingUpdate[]
|
package/src/types/order.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// Order shapes returned by Hyperliquid `/info`.
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Open order payload returned by Hyperliquid `frontendOpenOrders`.
|
|
5
|
+
* Sizes/prices are decimal strings; timestamps are milliseconds. Trigger
|
|
6
|
+
* flags and optional `children` describe attached TP/SL orders.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
4
9
|
export type HlFrontendOpenOrder = {
|
|
5
10
|
oid: number
|
|
6
11
|
coin: string
|
|
@@ -20,10 +25,15 @@ export type HlFrontendOpenOrder = {
|
|
|
20
25
|
cloid: string | null
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
/** @public */
|
|
28
|
+
/** Array returned by the `frontendOpenOrders` info query. @public */
|
|
24
29
|
export type HlFrontendOpenOrders = HlFrontendOpenOrder[]
|
|
25
30
|
|
|
26
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Order detail nested in an `orderStatus` response. `statusTimestamp` is the
|
|
33
|
+
* last status-change time in milliseconds; `triggerPx` is nullable for orders
|
|
34
|
+
* without a trigger.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
27
37
|
export type HlOrderDetail = {
|
|
28
38
|
order: {
|
|
29
39
|
oid: number
|
|
@@ -44,13 +54,17 @@ export type HlOrderDetail = {
|
|
|
44
54
|
statusTimestamp: number
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
/** @public */
|
|
57
|
+
/** Successful `orderStatus` response containing the requested order. @public */
|
|
48
58
|
export type HlOrderStatusFound = {
|
|
49
59
|
status: 'order'
|
|
50
60
|
order: HlOrderDetail
|
|
51
61
|
}
|
|
52
62
|
|
|
53
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Result of `orderStatus`: either a found order or the exact `'unknownOid'`
|
|
65
|
+
* sentinel when Hyperliquid has no record for the numeric order ID.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
54
68
|
export type HlOrderStatusResponse =
|
|
55
69
|
| HlOrderStatusFound
|
|
56
70
|
| { status: 'unknownOid' }
|
package/src/types/ws.ts
CHANGED
|
@@ -23,7 +23,11 @@ export type HlWsPerpAssetCtx = {
|
|
|
23
23
|
oraclePx: string
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Partial perp context carried by compressed (`pac`) updates. Omitted fields
|
|
28
|
+
* are unchanged from the prior context and must be merged by the consumer.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
27
31
|
export type HlWsPerpAssetCtxPayload = Partial<HlWsPerpAssetCtx>
|
|
28
32
|
|
|
29
33
|
/**
|
|
@@ -44,7 +48,7 @@ export type HlWsAllDexsAssetCtxsData = {
|
|
|
44
48
|
*/
|
|
45
49
|
export type HlWsPacData = [string, HlWsPerpAssetCtxPayload[]][]
|
|
46
50
|
|
|
47
|
-
/** @public */
|
|
51
|
+
/** Generic Hyperliquid WS envelope; `channel` identifies the subscription and `data` is channel-specific. @public */
|
|
48
52
|
export type HlWsMessage = {
|
|
49
53
|
channel: string
|
|
50
54
|
data: unknown
|
|
@@ -61,7 +65,12 @@ export type HlWsFastAssetCtx = {
|
|
|
61
65
|
midPx?: string | null
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Incremental spot asset context. Hyperliquid may encode numeric fields as
|
|
70
|
+
* strings or numbers and omits unchanged fields; `midPx: null` means no book
|
|
71
|
+
* midpoint is available.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
65
74
|
export type HlWsSpotAssetCtx = {
|
|
66
75
|
dayNtlVlm?: HlWsNumberString
|
|
67
76
|
prevDayPx?: HlWsNumberString
|
|
@@ -71,13 +80,13 @@ export type HlWsSpotAssetCtx = {
|
|
|
71
80
|
circulatingSupply?: HlWsNumberString
|
|
72
81
|
}
|
|
73
82
|
|
|
74
|
-
/** @public */
|
|
83
|
+
/** Active perp context event keyed by its Hyperliquid wire coin. @public */
|
|
75
84
|
export type HlWsActiveAssetCtxData = {
|
|
76
85
|
coin: string
|
|
77
86
|
ctx: Partial<Record<keyof HlWsPerpAssetCtx, HlWsNumberString | null>>
|
|
78
87
|
}
|
|
79
88
|
|
|
80
|
-
/** @public */
|
|
89
|
+
/** Active spot context event keyed by its Hyperliquid wire coin. @public */
|
|
81
90
|
export type HlWsActiveSpotAssetCtxData = {
|
|
82
91
|
coin: string
|
|
83
92
|
ctx: HlWsSpotAssetCtx
|
|
@@ -90,23 +99,31 @@ export type HlWsActiveSpotAssetCtxData = {
|
|
|
90
99
|
*/
|
|
91
100
|
export type HlWsSacData = Record<string, HlWsSpotAssetCtx>
|
|
92
101
|
|
|
93
|
-
/** @public */
|
|
102
|
+
/** L2 snapshot envelope with the wire coin attached to {@link HlL2Book}. @public */
|
|
94
103
|
export type HlWsL2BookData = HlL2Book & { coin: string }
|
|
95
104
|
|
|
96
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* L2 channel payload. `s` is a full snapshot, while `u` is a compressed delta;
|
|
107
|
+
* `c` carries the checksum/control value when present.
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
97
110
|
export type HlWsL2Data = {
|
|
98
111
|
s?: HlL2Book & { coin: string }
|
|
99
112
|
c?: string
|
|
100
113
|
u?: HlWsCompressedL2Data
|
|
101
114
|
}
|
|
102
115
|
|
|
103
|
-
/** @public */
|
|
116
|
+
/** One level in a compressed L2 update: `p` is price and `s` is size. @public */
|
|
104
117
|
export type HlWsCompressedL2Level = {
|
|
105
118
|
p: string
|
|
106
119
|
s: string
|
|
107
120
|
}
|
|
108
121
|
|
|
109
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* Compressed L2 delta. `t` is the update timestamp in milliseconds, `l` holds
|
|
124
|
+
* bid/ask levels, and optional `r` describes removals.
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
110
127
|
export type HlWsCompressedL2Data = {
|
|
111
128
|
c: string
|
|
112
129
|
t: number
|
|
@@ -117,7 +134,11 @@ export type HlWsCompressedL2Data = {
|
|
|
117
134
|
]
|
|
118
135
|
}
|
|
119
136
|
|
|
120
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Candle event payload. Inherited `t` is candle-open time; `T` is close time,
|
|
139
|
+
* `s` is the symbol, `i` is interval, and `n` is the trade count.
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
121
142
|
export type HlWsCandleData = HlCandle & {
|
|
122
143
|
T: number
|
|
123
144
|
s: string
|
|
@@ -125,7 +146,11 @@ export type HlWsCandleData = HlCandle & {
|
|
|
125
146
|
n: number
|
|
126
147
|
}
|
|
127
148
|
|
|
128
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Public trade event. Prices and size are decimal strings; `time` is
|
|
151
|
+
* milliseconds since epoch, with optional trade ID and transaction hash.
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
129
154
|
export type HlWsTrade = {
|
|
130
155
|
coin: string
|
|
131
156
|
side: string
|
|
@@ -136,14 +161,18 @@ export type HlWsTrade = {
|
|
|
136
161
|
hash?: string
|
|
137
162
|
}
|
|
138
163
|
|
|
139
|
-
/** @public */
|
|
164
|
+
/** User fills event; `isSnapshot` distinguishes the initial snapshot from updates. @public */
|
|
140
165
|
export type HlWsUserFillsData = {
|
|
141
166
|
isSnapshot: boolean
|
|
142
167
|
user: string
|
|
143
168
|
fills: HlUserFill[]
|
|
144
169
|
}
|
|
145
170
|
|
|
146
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Per-dex clearinghouse event for one user. Each tuple contains a wire DEX name
|
|
173
|
+
* and the perp positions/equity fields supplied by that DEX.
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
147
176
|
export type HlWsAllDexsClearinghouseStateData = {
|
|
148
177
|
user: string
|
|
149
178
|
clearinghouseStates: [
|
|
@@ -152,7 +181,7 @@ export type HlWsAllDexsClearinghouseStateData = {
|
|
|
152
181
|
][]
|
|
153
182
|
}
|
|
154
183
|
|
|
155
|
-
/** @public */
|
|
184
|
+
/** User spot clearinghouse event containing the current spot balances. @public */
|
|
156
185
|
export type HlWsSpotStateData = {
|
|
157
186
|
user: string
|
|
158
187
|
spotState: { balances: HlSpotBalance[] }
|
package/src/utils/assetId.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Return whether a Hyperliquid asset ID identifies spot (`@<pairIndex>`).
|
|
3
|
+
* @param assetId - Raw Hyperliquid asset ID.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
export const assetIsSpot = (assetId: string): boolean => assetId.startsWith('@')
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Calculate
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* HIP-3 providers (provider = 'xyz'): assetId = 100_000 + perpDexIndex * 10_000 + indexInProvider
|
|
9
|
+
* Calculate Hyperliquid's numeric asset ID from a perp DEX index and the
|
|
10
|
+
* asset's zero-based index within that DEX. The main DEX uses the index
|
|
11
|
+
* directly; HIP-3 DEXes use `100000 + dexIndex * 10000 + assetIndex`.
|
|
13
12
|
* @public
|
|
14
13
|
*/
|
|
15
14
|
export const calculateAssetId = (
|
|
@@ -23,7 +22,8 @@ export const calculateAssetId = (
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Find a sub-DEX's zero-based index in the names returned by Hyperliquid.
|
|
26
|
+
* @throws If `provider` is absent from `providerNames`.
|
|
27
27
|
* @public
|
|
28
28
|
*/
|
|
29
29
|
export const getProviderIndex = (
|
package/src/utils/assetLogo.ts
CHANGED
|
@@ -47,7 +47,12 @@ const UNIT_UNDERLYING_SYMBOL: Readonly<Record<string, string>> = {
|
|
|
47
47
|
UANSEM: 'ANSEM',
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Names of Unit-bridged Hyperliquid spot tokens recognized by the logo
|
|
52
|
+
* resolver. The set is read-only and is intended for callers that need to
|
|
53
|
+
* distinguish Unit balances before resolving their icons.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
51
56
|
export const UNIT_TOKEN_NAMES: ReadonlySet<string> = new Set(
|
|
52
57
|
Object.keys(UNIT_UNDERLYING_SYMBOL)
|
|
53
58
|
)
|
|
@@ -58,24 +63,21 @@ const unitSpotLogoURI = (name: string): string => {
|
|
|
58
63
|
return underlying === undefined ? '' : `${HL_COIN_CDN}/${underlying}.svg`
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Apply the provider's known symbol-specific logo corrections to an asset.
|
|
68
|
+
* Returns the original object when no override exists.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
62
71
|
export const applyLogoOverride = (asset: Asset): Asset => {
|
|
63
72
|
const override = BASE_ASSET_LOGO_OVERRIDES[asset.displaySymbol]
|
|
64
73
|
return override === undefined ? asset : { ...asset, logoURI: override }
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* When `fullName` is absent — spot *balances* (`HlSpotBalance`) carry no
|
|
74
|
-
* `fullName` and this issue deliberately does not fetch `spotMeta` on the
|
|
75
|
-
* account path — the derivation degrades to the symbol-keyed override + base
|
|
76
|
-
* `_spot` rule, so a Unit-bridged balance uses the base rule rather than its
|
|
77
|
-
* underlying's icon. The registry path (which has `fullName`) keeps full Unit
|
|
78
|
-
* resolution.
|
|
77
|
+
* Resolve the logo URI for a Hyperliquid spot token. Unit-bridged tokens use
|
|
78
|
+
* the underlying symbol's icon when `fullName` starts with `'Unit'`; otherwise
|
|
79
|
+
* the base URI is `coins/${name}_spot.svg`. Known symbol overrides win.
|
|
80
|
+
* @public
|
|
79
81
|
*/
|
|
80
82
|
export const spotLogoURI = (name: string, fullName?: string | null): string => {
|
|
81
83
|
const base = fullName?.startsWith('Unit')
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { HlWsFastAssetCtx } from '../types/index.js'
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Decode a base64-encoded raw-DEFLATE payload and parse its UTF-8 JSON body.
|
|
5
|
+
* @typeParam T - Expected shape of the decoded JSON value.
|
|
6
|
+
* @throws If decompression or JSON parsing fails.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
4
9
|
export async function decodeCompressedJson<T>(base64: string): Promise<T> {
|
|
5
10
|
const binary = atob(base64)
|
|
6
11
|
const bytes = new Uint8Array(binary.length)
|
|
@@ -24,6 +29,7 @@ export async function decodeCompressedJson<T>(base64: string): Promise<T> {
|
|
|
24
29
|
* (Node 18+, modern browsers), so no dependency is needed.
|
|
25
30
|
*
|
|
26
31
|
* @throws If the input is not valid base64 / raw-DEFLATE / JSON.
|
|
32
|
+
* @public
|
|
27
33
|
*/
|
|
28
34
|
export async function decodeFastAssetCtxs(
|
|
29
35
|
base64: string
|
package/src/utils/index.ts
CHANGED
package/src/utils/infoClient.ts
CHANGED
|
@@ -50,7 +50,12 @@ export const HYPERLIQUID_RETRY_DEFAULTS: ResolvedRetryPolicy = {
|
|
|
50
50
|
},
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Transport options for a direct Hyperliquid `/info` request. `policy`
|
|
55
|
+
* controls retries, `signal` cancels the request, and `fetchImpl` overrides
|
|
56
|
+
* the runtime's global `fetch` implementation.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
54
59
|
export interface InfoRequestOptions {
|
|
55
60
|
signal?: AbortSignal
|
|
56
61
|
policy?: ResolvedRetryPolicy
|
package/src/utils/mapActivity.ts
CHANGED
|
@@ -165,18 +165,30 @@ export const mapLedgerEntry = (
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Map a Hyperliquid funding ledger update to a normalized funding activity.
|
|
170
|
+
* `amount`, `positionSize`, and `fundingRate` retain the upstream decimal
|
|
171
|
+
* strings; `resolveMarket` supplies the provider-agnostic market metadata.
|
|
172
|
+
*
|
|
173
|
+
* `userFunding` entries all carry the zero hash, so a deterministic
|
|
174
|
+
* `funding:<coin>:<ISO time>` id is synthesized — funding accrues at most
|
|
175
|
+
* once per coin per hourly settlement, so the pair is unique per account.
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
169
178
|
export const mapFundingActivity = (
|
|
170
179
|
entry: HlFundingUpdate,
|
|
171
180
|
providerKey: string,
|
|
172
181
|
resolveMarket: (coin: string) => MarketDisplay
|
|
173
|
-
): FundingActivity =>
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
): FundingActivity => {
|
|
183
|
+
const timestamp = new Date(entry.time).toISOString()
|
|
184
|
+
return {
|
|
185
|
+
id: `funding:${entry.delta.coin}:${timestamp}`,
|
|
186
|
+
provider: providerKey,
|
|
187
|
+
timestamp,
|
|
188
|
+
type: ActivityType.FUNDING,
|
|
189
|
+
market: resolveMarket(entry.delta.coin),
|
|
190
|
+
amount: entry.delta.usdc,
|
|
191
|
+
positionSize: entry.delta.szi,
|
|
192
|
+
fundingRate: entry.delta.fundingRate,
|
|
193
|
+
}
|
|
194
|
+
}
|
package/src/utils/mapFill.ts
CHANGED
package/src/utils/mapMarket.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PerpsMarket } from '@lifi/perps-types'
|
|
2
|
+
import { PositionMarginAdjustment } from '@lifi/perps-types'
|
|
2
3
|
import { PROVIDER_KEY } from '../constants.js'
|
|
3
4
|
import type { HlUniverseItem } from '../types/index.js'
|
|
4
5
|
import { calculateMaintenanceMarginRate } from './liquidation.js'
|
|
@@ -31,6 +32,14 @@ export const mapMarket = (
|
|
|
31
32
|
szDecimals: universe.szDecimals,
|
|
32
33
|
priceDecimals: getMaxPriceDecimals(universe.szDecimals),
|
|
33
34
|
maxLeverage: universe.maxLeverage,
|
|
34
|
-
onlyIsolated:
|
|
35
|
+
onlyIsolated:
|
|
36
|
+
universe.marginMode !== undefined || universe.onlyIsolated === true,
|
|
37
|
+
// Deprecated `onlyIsolated` cannot distinguish strict-isolated from
|
|
38
|
+
// no-cross, so the ambiguous legacy shape fails closed as add-only.
|
|
39
|
+
positionMarginAdjustment:
|
|
40
|
+
universe.marginMode === 'noCross' ||
|
|
41
|
+
(universe.marginMode === undefined && universe.onlyIsolated !== true)
|
|
42
|
+
? PositionMarginAdjustment.ADD_AND_REMOVE
|
|
43
|
+
: PositionMarginAdjustment.ADD_ONLY,
|
|
35
44
|
maintenanceMarginRate: calculateMaintenanceMarginRate(universe.maxLeverage),
|
|
36
45
|
})
|
package/src/utils/mapOrder.ts
CHANGED
|
@@ -34,7 +34,7 @@ export const mapOrderType = (orderType: string): OrderType => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/** @public */
|
|
37
|
+
/** Return whether an SDK order type represents a take-profit or stop trigger. @public */
|
|
38
38
|
export const isTriggerType = (type: OrderType): boolean =>
|
|
39
39
|
type === OrderType.TAKE_PROFIT_MARKET ||
|
|
40
40
|
type === OrderType.TAKE_PROFIT_LIMIT ||
|
|
@@ -83,7 +83,11 @@ export const isTriggerOrder = (
|
|
|
83
83
|
return isTriggerType(mapOrderType(o.orderType))
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Map an open Hyperliquid order to the SDK's normalized open-order shape.
|
|
88
|
+
* Numeric IDs become strings and wire millisecond timestamps become ISO dates.
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
87
91
|
export const mapOpenOrder = (
|
|
88
92
|
o: HlFrontendOpenOrder,
|
|
89
93
|
market: MarketDisplay
|
|
@@ -102,7 +106,10 @@ export const mapOpenOrder = (
|
|
|
102
106
|
createdAt: new Date(o.timestamp).toISOString(),
|
|
103
107
|
})
|
|
104
108
|
|
|
105
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Map a Hyperliquid trigger/TP-SL order to the SDK's trigger-order shape.
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
106
113
|
export const mapTriggerOrder = (
|
|
107
114
|
o: HlFrontendOpenOrder,
|
|
108
115
|
market: MarketDisplay
|
|
@@ -232,7 +239,11 @@ const mapTimeInForce = (tif: string | undefined): TimeInForce | undefined => {
|
|
|
232
239
|
}
|
|
233
240
|
}
|
|
234
241
|
|
|
235
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* Map an `orderStatus` detail to the SDK's normalized order shape, preserving
|
|
244
|
+
* decimal size/price strings and translating status, side, and time-in-force.
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
236
247
|
export const mapOrder = (
|
|
237
248
|
detail: HlOrderDetail,
|
|
238
249
|
market: MarketDisplay
|
package/src/utils/mapPosition.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PerpsMarketDisplay, Position } from '@lifi/perps-types'
|
|
2
2
|
import { MarginMode, PositionSide } from '@lifi/perps-types'
|
|
3
|
+
import Big from 'big.js'
|
|
3
4
|
import type { HlAssetPosition } from '../types/index.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -11,30 +12,38 @@ import type { HlAssetPosition } from '../types/index.js'
|
|
|
11
12
|
export const isOpenAssetPosition = (ap: HlAssetPosition): boolean =>
|
|
12
13
|
Number.parseFloat(ap.position.szi) !== 0
|
|
13
14
|
|
|
14
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Map a non-zero Hyperliquid position payload to the SDK's normalized
|
|
17
|
+
* position. Signed wire size determines side; decimal strings remain strings
|
|
18
|
+
* in the normalized response.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
15
21
|
export const mapPosition = (
|
|
16
22
|
ap: HlAssetPosition,
|
|
17
|
-
market:
|
|
23
|
+
market: PerpsMarketDisplay
|
|
18
24
|
): Position => {
|
|
19
25
|
const pos = ap.position
|
|
20
|
-
const szi =
|
|
26
|
+
const szi = new Big(pos.szi)
|
|
27
|
+
const positionValue = new Big(pos.positionValue).abs()
|
|
28
|
+
const leverage = new Big(pos.leverage.value)
|
|
29
|
+
const marginMode =
|
|
30
|
+
pos.leverage.type === 'cross' ? MarginMode.CROSS : MarginMode.ISOLATED
|
|
31
|
+
const marginUsed =
|
|
32
|
+
marginMode === MarginMode.ISOLATED
|
|
33
|
+
? new Big(pos.marginUsed).minus(pos.unrealizedPnl).toFixed()
|
|
34
|
+
: pos.marginUsed
|
|
21
35
|
|
|
22
36
|
return {
|
|
23
37
|
market,
|
|
24
|
-
side: szi
|
|
25
|
-
size:
|
|
38
|
+
side: szi.gte(0) ? PositionSide.LONG : PositionSide.SHORT,
|
|
39
|
+
size: szi.abs().toFixed(),
|
|
26
40
|
entryPrice: pos.entryPx ?? '0',
|
|
27
|
-
markPrice:
|
|
28
|
-
pos.positionValue && szi !== 0
|
|
29
|
-
? (parseFloat(pos.positionValue) / Math.abs(szi)).toString()
|
|
30
|
-
: '0',
|
|
41
|
+
markPrice: szi.eq(0) ? '0' : positionValue.div(szi.abs()).toFixed(),
|
|
31
42
|
liquidationPrice: pos.liquidationPx ?? '0',
|
|
32
43
|
unrealizedPnl: pos.unrealizedPnl,
|
|
33
44
|
leverage: ap.position.leverage.value,
|
|
34
|
-
marginUsed
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
? MarginMode.CROSS
|
|
38
|
-
: MarginMode.ISOLATED,
|
|
45
|
+
marginUsed,
|
|
46
|
+
initialMarginRequirement: positionValue.div(leverage).toFixed(),
|
|
47
|
+
marginMode,
|
|
39
48
|
}
|
|
40
49
|
}
|
package/src/utils/spotBalance.ts
CHANGED
|
@@ -6,10 +6,10 @@ import { spotLogoURI } from './assetLogo.js'
|
|
|
6
6
|
import { coinAsset } from './marketDisplay.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* USD
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Build USD prices keyed by spot token asset ID. Base tokens use the supplied
|
|
10
|
+
* market mark price; quote tokens default to exactly `$1`; missing base prices
|
|
11
|
+
* default to `0`.
|
|
12
|
+
* @public
|
|
13
13
|
*/
|
|
14
14
|
export const spotPriceById = (
|
|
15
15
|
markets: readonly Market[],
|
|
@@ -30,11 +30,10 @@ export const spotPriceById = (
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* `_spot` rule (see {@link spotLogoURI}).
|
|
33
|
+
* Convert a Hyperliquid spot balance's numeric token index into an SDK asset.
|
|
34
|
+
* The balance payload has no `fullName`, so logo resolution uses the base
|
|
35
|
+
* `_spot` URI rule rather than Unit-underlying lookup.
|
|
36
|
+
* @public
|
|
38
37
|
*/
|
|
39
38
|
export const spotAssetFromToken = (b: HlSpotBalance): Asset => ({
|
|
40
39
|
...coinAsset(b.coin),
|
|
@@ -42,7 +41,7 @@ export const spotAssetFromToken = (b: HlSpotBalance): Asset => ({
|
|
|
42
41
|
logoURI: spotLogoURI(b.coin),
|
|
43
42
|
})
|
|
44
43
|
|
|
45
|
-
/** Assemble a typed spot {@link Balance}
|
|
44
|
+
/** Assemble a typed spot {@link Balance}; `total` is native token units and its USD value uses `priceById`. @public */
|
|
46
45
|
export const spotBalance = (
|
|
47
46
|
asset: Asset,
|
|
48
47
|
total: string,
|
|
@@ -13,17 +13,21 @@ const PORTFOLIO_MARGIN_LTV: Readonly<Record<string, number>> = {
|
|
|
13
13
|
UBTC: 0.5,
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Result of {@link partitionSpotBalances}: balances that count toward
|
|
18
|
+
* collateral and balances treated as ordinary holdings.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
17
21
|
export interface SpotPartition {
|
|
18
22
|
collateralBalances: Balance[]
|
|
19
23
|
balances: Balance[]
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
+
* Partition spot balances into collateral and ordinary holdings. Quote assets
|
|
28
|
+
* are full-value collateral; portfolio-margin-supported assets retain their
|
|
29
|
+
* LTV as `collateralWeight`.
|
|
30
|
+
* @public
|
|
27
31
|
*/
|
|
28
32
|
export const partitionSpotBalances = (
|
|
29
33
|
spotBalances: readonly Balance[],
|