@lifi/perps-sdk-provider-hyperliquid 20.1.0 → 22.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/README.md +15 -0
- package/dist/cjs/HyperliquidProvider.d.ts.map +1 -1
- package/dist/cjs/HyperliquidProvider.js +2 -2
- package/dist/cjs/HyperliquidProvider.js.map +1 -1
- package/dist/cjs/services/getAccount.d.ts.map +1 -1
- package/dist/cjs/services/getAccount.js +8 -8
- package/dist/cjs/services/getAccount.js.map +1 -1
- package/dist/cjs/services/getAccountExists.d.ts +3 -1
- package/dist/cjs/services/getAccountExists.d.ts.map +1 -1
- package/dist/cjs/services/getAccountExists.js +27 -6
- package/dist/cjs/services/getAccountExists.js.map +1 -1
- package/dist/cjs/services/getActivity.d.ts.map +1 -1
- package/dist/cjs/services/getActivity.js +3 -1
- package/dist/cjs/services/getActivity.js.map +1 -1
- package/dist/cjs/services/getAvailableToTrade.d.ts.map +1 -1
- package/dist/cjs/services/getAvailableToTrade.js +3 -0
- package/dist/cjs/services/getAvailableToTrade.js.map +1 -1
- package/dist/cjs/services/getFills.d.ts.map +1 -1
- package/dist/cjs/services/getFills.js +3 -1
- package/dist/cjs/services/getFills.js.map +1 -1
- package/dist/cjs/services/getMarketSettings.d.ts.map +1 -1
- package/dist/cjs/services/getMarketSettings.js +3 -0
- package/dist/cjs/services/getMarketSettings.js.map +1 -1
- package/dist/cjs/services/getOrder.d.ts.map +1 -1
- package/dist/cjs/services/getOrder.js +2 -0
- 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 +3 -1
- package/dist/cjs/services/getOrders.js.map +1 -1
- package/dist/cjs/services/getPortfolioHistory.d.ts.map +1 -1
- package/dist/cjs/services/getPortfolioHistory.js +2 -0
- package/dist/cjs/services/getPortfolioHistory.js.map +1 -1
- package/dist/cjs/services/getPositions.d.ts.map +1 -1
- package/dist/cjs/services/getPositions.js +3 -1
- package/dist/cjs/services/getPositions.js.map +1 -1
- package/dist/cjs/services/getWithdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/services/getWithdrawableBalances.js +3 -1
- package/dist/cjs/services/getWithdrawableBalances.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +3 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/liquidation.js +1 -1
- package/dist/cjs/utils/liquidation.js.map +1 -1
- package/dist/cjs/utils/orderFormatting.d.ts +3 -2
- package/dist/cjs/utils/orderFormatting.d.ts.map +1 -1
- package/dist/cjs/utils/orderFormatting.js +4 -4
- package/dist/cjs/utils/orderFormatting.js.map +1 -1
- package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
- package/dist/cjs/utils/spotBalance.js +2 -2
- package/dist/cjs/utils/spotBalance.js.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts +1 -1
- package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/cjs/utils/withdrawableBalances.js +7 -4
- package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts +2 -0
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js +42 -10
- package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/esm/HyperliquidProvider.d.ts.map +1 -1
- package/dist/esm/HyperliquidProvider.js +3 -3
- package/dist/esm/HyperliquidProvider.js.map +1 -1
- package/dist/esm/services/getAccount.d.ts.map +1 -1
- package/dist/esm/services/getAccount.js +9 -6
- package/dist/esm/services/getAccount.js.map +1 -1
- package/dist/esm/services/getAccountExists.d.ts +3 -1
- package/dist/esm/services/getAccountExists.d.ts.map +1 -1
- package/dist/esm/services/getAccountExists.js +29 -9
- package/dist/esm/services/getAccountExists.js.map +1 -1
- package/dist/esm/services/getActivity.d.ts.map +1 -1
- package/dist/esm/services/getActivity.js +3 -1
- package/dist/esm/services/getActivity.js.map +1 -1
- package/dist/esm/services/getAvailableToTrade.d.ts.map +1 -1
- package/dist/esm/services/getAvailableToTrade.js +3 -0
- package/dist/esm/services/getAvailableToTrade.js.map +1 -1
- package/dist/esm/services/getFills.d.ts.map +1 -1
- package/dist/esm/services/getFills.js +3 -1
- package/dist/esm/services/getFills.js.map +1 -1
- package/dist/esm/services/getMarketSettings.d.ts.map +1 -1
- package/dist/esm/services/getMarketSettings.js +3 -0
- package/dist/esm/services/getMarketSettings.js.map +1 -1
- package/dist/esm/services/getOrder.d.ts.map +1 -1
- package/dist/esm/services/getOrder.js +2 -0
- 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 +3 -1
- package/dist/esm/services/getOrders.js.map +1 -1
- package/dist/esm/services/getPortfolioHistory.d.ts.map +1 -1
- package/dist/esm/services/getPortfolioHistory.js +2 -0
- package/dist/esm/services/getPortfolioHistory.js.map +1 -1
- package/dist/esm/services/getPositions.d.ts.map +1 -1
- package/dist/esm/services/getPositions.js +3 -1
- package/dist/esm/services/getPositions.js.map +1 -1
- package/dist/esm/services/getWithdrawableBalances.d.ts.map +1 -1
- package/dist/esm/services/getWithdrawableBalances.js +3 -1
- package/dist/esm/services/getWithdrawableBalances.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/liquidation.js +2 -2
- package/dist/esm/utils/liquidation.js.map +1 -1
- package/dist/esm/utils/orderFormatting.d.ts +14 -12
- package/dist/esm/utils/orderFormatting.d.ts.map +1 -1
- package/dist/esm/utils/orderFormatting.js +14 -14
- package/dist/esm/utils/orderFormatting.js.map +1 -1
- package/dist/esm/utils/spotBalance.d.ts.map +1 -1
- package/dist/esm/utils/spotBalance.js +3 -3
- package/dist/esm/utils/spotBalance.js.map +1 -1
- package/dist/esm/utils/withdrawableBalances.d.ts +1 -1
- package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/esm/utils/withdrawableBalances.js +7 -4
- package/dist/esm/utils/withdrawableBalances.js.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts +2 -0
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.js +43 -13
- package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/types/HyperliquidProvider.d.ts.map +1 -1
- package/dist/types/services/getAccount.d.ts.map +1 -1
- package/dist/types/services/getAccountExists.d.ts +3 -1
- package/dist/types/services/getAccountExists.d.ts.map +1 -1
- package/dist/types/services/getActivity.d.ts.map +1 -1
- package/dist/types/services/getAvailableToTrade.d.ts.map +1 -1
- package/dist/types/services/getFills.d.ts.map +1 -1
- package/dist/types/services/getMarketSettings.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/getPortfolioHistory.d.ts.map +1 -1
- package/dist/types/services/getPositions.d.ts.map +1 -1
- package/dist/types/services/getWithdrawableBalances.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/orderFormatting.d.ts +14 -12
- package/dist/types/utils/orderFormatting.d.ts.map +1 -1
- package/dist/types/utils/spotBalance.d.ts.map +1 -1
- package/dist/types/utils/withdrawableBalances.d.ts +1 -1
- package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
- package/dist/types/websocket/HyperliquidWsProvider.d.ts +2 -0
- package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/HyperliquidProvider.ts +6 -5
- package/src/services/getAccount.ts +21 -19
- package/src/services/getAccountExists.ts +55 -14
- package/src/services/getActivity.ts +3 -1
- package/src/services/getAvailableToTrade.ts +7 -0
- package/src/services/getFills.ts +3 -1
- package/src/services/getMarketSettings.ts +7 -0
- package/src/services/getOrder.ts +2 -0
- package/src/services/getOrders.ts +3 -1
- package/src/services/getPortfolioHistory.ts +2 -0
- package/src/services/getPositions.ts +3 -1
- package/src/services/getWithdrawableBalances.ts +3 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/liquidation.ts +2 -2
- package/src/utils/orderFormatting.ts +20 -16
- package/src/utils/spotBalance.ts +5 -3
- package/src/utils/withdrawableBalances.ts +12 -7
- package/src/websocket/HyperliquidWsProvider.ts +55 -15
|
@@ -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/websocket/HyperliquidWsProvider.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk-provider-hyperliquid",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"description": "Hyperliquid provider plugin for @lifi/perps-sdk",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"big.js": "^7.0.1",
|
|
51
51
|
"viem": "^2.55.18",
|
|
52
|
-
"@lifi/perps-types": "^
|
|
52
|
+
"@lifi/perps-types": "^19.0.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@lifi/perps-sdk": "^
|
|
55
|
+
"@lifi/perps-sdk": "^21.1.0"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
ActionType,
|
|
36
36
|
type ActivitiesResponse,
|
|
37
37
|
type AvailableToTrade,
|
|
38
|
+
type DecimalString,
|
|
38
39
|
type FillsResponse,
|
|
39
40
|
type Market,
|
|
40
41
|
type MarketSettings,
|
|
@@ -80,7 +81,7 @@ import { hyperliquidSignActions } from './signers/signActions.js'
|
|
|
80
81
|
import type { HlExtraAgents } from './types/index.js'
|
|
81
82
|
import { hlInfoOptions, infoRequest } from './utils/infoClient.js'
|
|
82
83
|
import { calculateLiquidationPrice } from './utils/liquidation.js'
|
|
83
|
-
import {
|
|
84
|
+
import { snapOrderPrice, snapOrderSize } from './utils/orderFormatting.js'
|
|
84
85
|
import { positionRemovableMargin } from './utils/transferMargin.js'
|
|
85
86
|
|
|
86
87
|
/**
|
|
@@ -465,15 +466,15 @@ export function hyperliquidProvider(
|
|
|
465
466
|
positions: Position[]
|
|
466
467
|
): AccountSummary => getAccountSummary(account, positions),
|
|
467
468
|
|
|
468
|
-
|
|
469
|
-
|
|
469
|
+
snapOrderPrice: (market: Market, price: DecimalString): DecimalString =>
|
|
470
|
+
snapOrderPrice(
|
|
470
471
|
price,
|
|
471
472
|
market.szDecimals,
|
|
472
473
|
market.categoryId === SPOT_MARKET_ID ? 'spot' : undefined
|
|
473
474
|
),
|
|
474
475
|
|
|
475
|
-
|
|
476
|
-
|
|
476
|
+
snapOrderSize: (market: Market, size: DecimalString): DecimalString =>
|
|
477
|
+
snapOrderSize(size, market.szDecimals),
|
|
477
478
|
|
|
478
479
|
estimateLiquidationPrice: (
|
|
479
480
|
market: PerpsMarket,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
calculateTransferable,
|
|
2
3
|
getMarketRegistry,
|
|
3
4
|
getMarketsContext,
|
|
4
|
-
maxOf,
|
|
5
|
-
minOf,
|
|
6
5
|
type ProviderGetAccountParams,
|
|
6
|
+
parseDecimal,
|
|
7
7
|
type SDKRequestOptions,
|
|
8
|
-
stringToFloat,
|
|
9
8
|
toPerpsMarketDisplay,
|
|
10
9
|
} from '@lifi/perps-sdk'
|
|
11
10
|
import type {
|
|
@@ -16,7 +15,7 @@ import type {
|
|
|
16
15
|
HyperliquidDexAccountState,
|
|
17
16
|
Position,
|
|
18
17
|
} from '@lifi/perps-types'
|
|
19
|
-
import Big from 'big.js'
|
|
18
|
+
import type Big from 'big.js'
|
|
20
19
|
import { PROVIDER_KEY } from '../constants.js'
|
|
21
20
|
import type { HyperliquidContext } from '../context.js'
|
|
22
21
|
import type {
|
|
@@ -40,6 +39,7 @@ import {
|
|
|
40
39
|
} from '../utils/index.js'
|
|
41
40
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
42
41
|
import { isOpenAssetPosition, mapPosition } from '../utils/mapPosition.js'
|
|
42
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Parameters for {@link getAccount}.
|
|
@@ -83,13 +83,12 @@ const buildBalances = (
|
|
|
83
83
|
const total = toWireBig(b.total, 'spotClearinghouseState.total')
|
|
84
84
|
return {
|
|
85
85
|
...spotBalance(spotAssetFromToken(b), b.total, priceById),
|
|
86
|
-
transferable:
|
|
87
|
-
maxOf(
|
|
88
|
-
total.minus(toWireBig(b.hold, 'spotClearinghouseState.hold')),
|
|
89
|
-
new Big(0)
|
|
90
|
-
),
|
|
86
|
+
transferable: calculateTransferable(
|
|
91
87
|
total
|
|
92
|
-
|
|
88
|
+
.minus(toWireBig(b.hold, 'spotClearinghouseState.hold'))
|
|
89
|
+
.toFixed(),
|
|
90
|
+
total.toFixed()
|
|
91
|
+
),
|
|
93
92
|
}
|
|
94
93
|
}),
|
|
95
94
|
quoteAssetIds
|
|
@@ -114,13 +113,13 @@ const buildBalances = (
|
|
|
114
113
|
units: value.toFixed(),
|
|
115
114
|
valueUsd: value.toFixed(),
|
|
116
115
|
price: '1',
|
|
117
|
-
transferable:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
),
|
|
122
|
-
value
|
|
123
|
-
)
|
|
116
|
+
transferable: calculateTransferable(
|
|
117
|
+
toWireBig(
|
|
118
|
+
state.withdrawable,
|
|
119
|
+
'clearinghouseState.withdrawable'
|
|
120
|
+
).toFixed(),
|
|
121
|
+
value.toFixed()
|
|
122
|
+
),
|
|
124
123
|
})
|
|
125
124
|
}
|
|
126
125
|
}
|
|
@@ -151,6 +150,8 @@ export const getAccount = async (
|
|
|
151
150
|
params: GetAccountParams,
|
|
152
151
|
options?: SDKRequestOptions
|
|
153
152
|
): Promise<AccountResponse> => {
|
|
153
|
+
const infoOpts = hlInfoOptions(client, options)
|
|
154
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
154
155
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
155
156
|
const markets = await registry.sync()
|
|
156
157
|
const dexNames = perpsDexNames(markets)
|
|
@@ -158,7 +159,6 @@ export const getAccount = async (
|
|
|
158
159
|
const quoteAssetByCategory = new Map(
|
|
159
160
|
markets.map((m) => [m.categoryId, m.quoteAsset])
|
|
160
161
|
)
|
|
161
|
-
const infoOpts = hlInfoOptions(client, options)
|
|
162
162
|
|
|
163
163
|
const [
|
|
164
164
|
feesResult,
|
|
@@ -209,7 +209,9 @@ export const getAccount = async (
|
|
|
209
209
|
|
|
210
210
|
const priceById = spotPriceById(
|
|
211
211
|
markets,
|
|
212
|
-
new Map(
|
|
212
|
+
new Map(
|
|
213
|
+
prices.map((p) => [p.marketId, parseDecimal(p.markPrice) ?? Number.NaN])
|
|
214
|
+
)
|
|
213
215
|
)
|
|
214
216
|
|
|
215
217
|
const positions: Position[] = stateResults.flatMap((state) =>
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { PerpsError, type SDKRequestOptions } from '@lifi/perps-sdk'
|
|
2
|
+
import { PerpsErrorCode } from '@lifi/perps-types'
|
|
2
3
|
import { type Address, zeroAddress } from 'viem'
|
|
4
|
+
import { PROVIDER_KEY } from '../constants.js'
|
|
3
5
|
import type { HyperliquidContext } from '../context.js'
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
+
import {
|
|
7
|
+
hlInfoOptions,
|
|
8
|
+
type InfoRequestOptions,
|
|
9
|
+
infoRequest,
|
|
10
|
+
} from '../utils/infoClient.js'
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Parameters for {@link getAccountExists}.
|
|
@@ -13,6 +18,36 @@ export interface GetAccountExistsParams {
|
|
|
13
18
|
address: Address
|
|
14
19
|
}
|
|
15
20
|
|
|
21
|
+
async function readAccountExists(
|
|
22
|
+
apiUrl: string,
|
|
23
|
+
address: Address,
|
|
24
|
+
options?: InfoRequestOptions
|
|
25
|
+
): Promise<boolean> {
|
|
26
|
+
const response = await infoRequest<unknown>(
|
|
27
|
+
apiUrl,
|
|
28
|
+
{
|
|
29
|
+
type: 'preTransferCheck',
|
|
30
|
+
user: address,
|
|
31
|
+
source: zeroAddress,
|
|
32
|
+
},
|
|
33
|
+
options
|
|
34
|
+
)
|
|
35
|
+
if (
|
|
36
|
+
typeof response === 'object' &&
|
|
37
|
+
response !== null &&
|
|
38
|
+
'userExists' in response &&
|
|
39
|
+
typeof response.userExists === 'boolean'
|
|
40
|
+
) {
|
|
41
|
+
return response.userExists
|
|
42
|
+
}
|
|
43
|
+
const error = new PerpsError(
|
|
44
|
+
PerpsErrorCode.ThirdPartyError,
|
|
45
|
+
'Hyperliquid preTransferCheck response has no boolean userExists field'
|
|
46
|
+
)
|
|
47
|
+
error.tool = PROVIDER_KEY
|
|
48
|
+
throw error
|
|
49
|
+
}
|
|
50
|
+
|
|
16
51
|
/**
|
|
17
52
|
* Resolve whether a Hyperliquid Core account exists for `address` via a
|
|
18
53
|
* `preTransferCheck` info query. An account exists only after its first
|
|
@@ -22,19 +57,25 @@ export interface GetAccountExistsParams {
|
|
|
22
57
|
* @throws {PerpsError} On Hyperliquid REST error, network, or parsing failures.
|
|
23
58
|
* @public
|
|
24
59
|
*/
|
|
25
|
-
export const getAccountExists =
|
|
60
|
+
export const getAccountExists = (
|
|
26
61
|
{ client, apiUrl }: HyperliquidContext,
|
|
27
62
|
params: GetAccountExistsParams,
|
|
28
63
|
options?: SDKRequestOptions
|
|
29
|
-
): Promise<boolean> =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
64
|
+
): Promise<boolean> =>
|
|
65
|
+
readAccountExists(apiUrl, params.address, hlInfoOptions(client, options))
|
|
66
|
+
|
|
67
|
+
export async function requireAccountExists(
|
|
68
|
+
apiUrl: string,
|
|
69
|
+
address: Address,
|
|
70
|
+
options?: InfoRequestOptions
|
|
71
|
+
): Promise<void> {
|
|
72
|
+
if (await readAccountExists(apiUrl, address, options)) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
const error = new PerpsError(
|
|
76
|
+
PerpsErrorCode.AccountNotFound,
|
|
77
|
+
`No Hyperliquid account found for address: ${address}`
|
|
38
78
|
)
|
|
39
|
-
|
|
79
|
+
error.tool = PROVIDER_KEY
|
|
80
|
+
throw error
|
|
40
81
|
}
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
type InfoRequestOptions,
|
|
42
42
|
infoRequest,
|
|
43
43
|
} from '../utils/infoClient.js'
|
|
44
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
44
45
|
import { getHistoryLimit, historyPage } from './historyPagination.js'
|
|
45
46
|
|
|
46
47
|
/**
|
|
@@ -240,6 +241,8 @@ export const getActivity = async (
|
|
|
240
241
|
options?: SDKRequestOptions
|
|
241
242
|
): Promise<ActivitiesResponse> => {
|
|
242
243
|
const limit = getHistoryLimit(params.limit)
|
|
244
|
+
const infoOpts = hlInfoOptions(client, options)
|
|
245
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
243
246
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
244
247
|
// Only funding and liquidation rows carry a market, so a Ledger-only
|
|
245
248
|
// request must not pull the market list.
|
|
@@ -253,7 +256,6 @@ export const getActivity = async (
|
|
|
253
256
|
) {
|
|
254
257
|
await assetRegistry.sync()
|
|
255
258
|
}
|
|
256
|
-
const infoOpts = hlInfoOptions(client, options)
|
|
257
259
|
|
|
258
260
|
const needLiquidationFills =
|
|
259
261
|
!params.type || params.type.includes(ActivityType.LIQUIDATION)
|
|
@@ -9,7 +9,9 @@ import { PerpsErrorCode } from '@lifi/perps-types'
|
|
|
9
9
|
import type { Address } from 'viem'
|
|
10
10
|
import { PROVIDER_KEY, SPOT_MARKET_ID } from '../constants.js'
|
|
11
11
|
import type { HyperliquidContext } from '../context.js'
|
|
12
|
+
import { hlInfoOptions } from '../utils/infoClient.js'
|
|
12
13
|
import { fetchActiveAssetData } from './activeAssetData.js'
|
|
14
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Parameters for {@link getAvailableToTrade}.
|
|
@@ -43,6 +45,11 @@ export const getAvailableToTrade = async (
|
|
|
43
45
|
if (market.categoryId === SPOT_MARKET_ID) {
|
|
44
46
|
return undefined
|
|
45
47
|
}
|
|
48
|
+
await requireAccountExists(
|
|
49
|
+
context.apiUrl,
|
|
50
|
+
params.address,
|
|
51
|
+
hlInfoOptions(context.client, options)
|
|
52
|
+
)
|
|
46
53
|
const data = await fetchActiveAssetData(
|
|
47
54
|
context,
|
|
48
55
|
params.address,
|
package/src/services/getFills.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { HyperliquidContext } from '../context.js'
|
|
|
6
6
|
import type { HlUserFills } from '../types/index.js'
|
|
7
7
|
import { assetIsOutcome, mapFill } from '../utils/index.js'
|
|
8
8
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
9
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
9
10
|
import { getHistoryLimit, historyPage } from './historyPagination.js'
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -32,9 +33,10 @@ export const getFills = async (
|
|
|
32
33
|
options?: SDKRequestOptions
|
|
33
34
|
): Promise<FillsResponse> => {
|
|
34
35
|
const limit = getHistoryLimit(params.limit)
|
|
36
|
+
const infoOpts = hlInfoOptions(client, options)
|
|
37
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
35
38
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
36
39
|
await registry.sync()
|
|
37
|
-
const infoOpts = hlInfoOptions(client, options)
|
|
38
40
|
|
|
39
41
|
let useRecent =
|
|
40
42
|
params.cursor === undefined &&
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
import type { Address } from 'viem'
|
|
9
9
|
import { PROVIDER_KEY, SPOT_MARKET_ID } from '../constants.js'
|
|
10
10
|
import type { HyperliquidContext } from '../context.js'
|
|
11
|
+
import { hlInfoOptions } from '../utils/infoClient.js'
|
|
11
12
|
import { fetchActiveAssetData } from './activeAssetData.js'
|
|
13
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Parameters for {@link getMarketSettings}.
|
|
@@ -41,6 +43,11 @@ export const getMarketSettings = async (
|
|
|
41
43
|
error.tool = PROVIDER_KEY
|
|
42
44
|
throw error
|
|
43
45
|
}
|
|
46
|
+
await requireAccountExists(
|
|
47
|
+
context.apiUrl,
|
|
48
|
+
params.address,
|
|
49
|
+
hlInfoOptions(context.client, options)
|
|
50
|
+
)
|
|
44
51
|
const data = await fetchActiveAssetData(
|
|
45
52
|
context,
|
|
46
53
|
params.address,
|
package/src/services/getOrder.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
import { withExplorerLinks } from '../utils/explorer.js'
|
|
16
16
|
import { assetIsOutcome, mapOrder } from '../utils/index.js'
|
|
17
17
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
18
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Parameters for {@link getOrder}.
|
|
@@ -49,6 +50,7 @@ export const getOrder = async (
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
const infoOpts = hlInfoOptions(client, options)
|
|
53
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
52
54
|
const status = await infoRequest<HlOrderStatusResponse>(
|
|
53
55
|
apiUrl,
|
|
54
56
|
{ type: 'orderStatus', user: params.address, oid },
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
import { withExplorerLinks } from '../utils/explorer.js'
|
|
20
20
|
import { assetIsOutcome, mapOrder, perpsDexNames } from '../utils/index.js'
|
|
21
21
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
22
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
22
23
|
|
|
23
24
|
/** Parameters for a lifecycle-filtered Hyperliquid order read. */
|
|
24
25
|
export type GetOrdersParams = ProviderGetOrdersParams
|
|
@@ -65,6 +66,8 @@ export const getOrders = async (
|
|
|
65
66
|
options?: SDKRequestOptions
|
|
66
67
|
): Promise<OrdersResponse> => {
|
|
67
68
|
const statuses = params.statuses ?? [...ACTIVE_ORDER_STATUSES]
|
|
69
|
+
const infoOpts = hlInfoOptions(client, options)
|
|
70
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
68
71
|
if (statuses.length === 0) {
|
|
69
72
|
return {
|
|
70
73
|
provider: PROVIDER_KEY,
|
|
@@ -74,7 +77,6 @@ export const getOrders = async (
|
|
|
74
77
|
}
|
|
75
78
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
76
79
|
const markets = await registry.sync()
|
|
77
|
-
const infoOpts = hlInfoOptions(client, options)
|
|
78
80
|
const active = statuses.some(isActiveOrderStatus)
|
|
79
81
|
const terminal = statuses.some((status) => !isActiveOrderStatus(status))
|
|
80
82
|
const [open, historical, twaps] = await Promise.all([
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
} from '../types/index.js'
|
|
16
16
|
import { isUnifiedAbstraction } from '../utils/abstractionMode.js'
|
|
17
17
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
18
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
18
19
|
|
|
19
20
|
/** Parameters for {@link getPortfolioHistory}. @public */
|
|
20
21
|
export interface GetPortfolioHistoryParams {
|
|
@@ -83,6 +84,7 @@ export async function getPortfolioHistory(
|
|
|
83
84
|
): Promise<PortfolioHistoryResponse> {
|
|
84
85
|
const { client, apiUrl } = ctx
|
|
85
86
|
const infoOpts = hlInfoOptions(client, options)
|
|
87
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
86
88
|
const [portfolio, abstraction] = await Promise.all([
|
|
87
89
|
infoRequest<HlPortfolio>(
|
|
88
90
|
apiUrl,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
perpsDexNames,
|
|
16
16
|
} from '../utils/index.js'
|
|
17
17
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
18
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Parameters for {@link getPositions}.
|
|
@@ -42,9 +43,10 @@ export const getPositions = async (
|
|
|
42
43
|
params: GetPositionsParams,
|
|
43
44
|
options?: SDKRequestOptions
|
|
44
45
|
): Promise<PositionsResponse> => {
|
|
46
|
+
const infoOpts = hlInfoOptions(client, options)
|
|
47
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
45
48
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
46
49
|
const markets = await registry.sync()
|
|
47
|
-
const infoOpts = hlInfoOptions(client, options)
|
|
48
50
|
|
|
49
51
|
const stateResults = await Promise.all(
|
|
50
52
|
perpsDexNames(markets).map((name) =>
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
} from '../types/index.js'
|
|
17
17
|
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
18
18
|
import { hyperliquidWithdrawableBalances } from '../utils/withdrawableBalances.js'
|
|
19
|
+
import { requireAccountExists } from './getAccountExists.js'
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Parameters for {@link getWithdrawableBalances}.
|
|
@@ -46,6 +47,7 @@ export const getWithdrawableBalances = async (
|
|
|
46
47
|
): Promise<ProviderWithdrawableBalance[]> => {
|
|
47
48
|
const registry = getMarketRegistry(client, PROVIDER_KEY)
|
|
48
49
|
const infoOpts = hlInfoOptions(client, options)
|
|
50
|
+
await requireAccountExists(apiUrl, params.address, infoOpts)
|
|
49
51
|
|
|
50
52
|
const [{ providers }, markets, abstraction, state, spotState] =
|
|
51
53
|
await Promise.all([
|
|
@@ -89,6 +91,6 @@ export const getWithdrawableBalances = async (
|
|
|
89
91
|
state,
|
|
90
92
|
spotState,
|
|
91
93
|
quoteAsset.id,
|
|
92
|
-
feeUsd
|
|
94
|
+
feeUsd
|
|
93
95
|
)
|
|
94
96
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -45,9 +45,9 @@ export {
|
|
|
45
45
|
export { isOpenAssetPosition, mapPosition } from './mapPosition.js'
|
|
46
46
|
export { coinAsset, perpsDexNames } from './marketDisplay.js'
|
|
47
47
|
export {
|
|
48
|
-
formatOrderPrice,
|
|
49
|
-
formatOrderSize,
|
|
50
48
|
getMaxPriceDecimals,
|
|
49
|
+
snapOrderPrice,
|
|
50
|
+
snapOrderSize,
|
|
51
51
|
} from './orderFormatting.js'
|
|
52
52
|
export { priceStepToAggregation } from './priceStepToAggregation.js'
|
|
53
53
|
export {
|
package/src/utils/liquidation.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - margin_available = isolated_margin - maintenance_margin_required
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { estimateLiquidationPrice } from '@lifi/perps-sdk'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Calculate the maintenance margin fraction for a Hyperliquid asset.
|
|
@@ -65,7 +65,7 @@ export function calculateLiquidationPrice(
|
|
|
65
65
|
if (mmr === undefined) {
|
|
66
66
|
return undefined
|
|
67
67
|
}
|
|
68
|
-
return
|
|
68
|
+
return estimateLiquidationPrice({
|
|
69
69
|
entryPrice,
|
|
70
70
|
leverage,
|
|
71
71
|
isLong,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hyperliquid order size and price
|
|
2
|
+
* Hyperliquid order size and price snapping for exchange submission.
|
|
3
3
|
*
|
|
4
|
-
* These encode Hyperliquid-specific order submission rules.
|
|
5
|
-
*
|
|
4
|
+
* These encode Hyperliquid-specific order submission rules. Snapping a size or
|
|
5
|
+
* a price onto the wrong grid causes rejected orders.
|
|
6
6
|
*
|
|
7
7
|
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import type { DecimalString } from '@lifi/perps-types'
|
|
10
11
|
import Big from 'big.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -36,28 +37,30 @@ export function getMaxPriceDecimals(
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
|
-
*
|
|
40
|
+
* Snap a size onto the asset's lot grid for order submission.
|
|
40
41
|
*
|
|
41
42
|
* Per Hyperliquid docs (tick-and-lot-size):
|
|
42
43
|
* - Size must be rounded to the asset's szDecimals
|
|
43
44
|
* - Trailing zeroes must be removed for signing
|
|
44
45
|
*
|
|
45
|
-
* @param size - The size
|
|
46
|
+
* @param size - The size to snap, as a decimal string
|
|
46
47
|
* @param szDecimals - Number of decimal places allowed for this asset (from meta)
|
|
47
|
-
* @returns Size as a string with correct precision, no trailing zeros
|
|
48
|
+
* @returns Size as a decimal string with correct precision, no trailing zeros
|
|
48
49
|
* @public
|
|
49
50
|
*/
|
|
50
|
-
export function
|
|
51
|
+
export function snapOrderSize(
|
|
52
|
+
size: DecimalString,
|
|
53
|
+
szDecimals: number
|
|
54
|
+
): DecimalString {
|
|
51
55
|
// Big.roundDown truncates toward zero — never round a size up, it could
|
|
52
|
-
// exceed available balance.
|
|
53
|
-
// product dropped a lot step (0.29 * 100 === 28.999999999999996).
|
|
56
|
+
// exceed available balance.
|
|
54
57
|
const truncated = new Big(size).round(szDecimals, Big.roundDown)
|
|
55
58
|
// toFixed() with no dp always emits plain notation; eq(0) guards '-0'
|
|
56
59
|
return truncated.eq(0) ? '0' : truncated.toFixed()
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
/**
|
|
60
|
-
*
|
|
63
|
+
* Snap a price onto the asset's tick grid for order submission.
|
|
61
64
|
*
|
|
62
65
|
* Per Hyperliquid docs (tick-and-lot-size):
|
|
63
66
|
* - Maximum 5 significant figures
|
|
@@ -66,19 +69,20 @@ export function formatOrderSize(size: number, szDecimals: number): string {
|
|
|
66
69
|
* - Trailing zeroes must be removed for signing
|
|
67
70
|
*
|
|
68
71
|
* Rounding is half-up (away from zero at exact halfway) on the true decimal
|
|
69
|
-
* value,
|
|
72
|
+
* value, which is why the price arrives as a string: `(1.005).toFixed(2)`
|
|
73
|
+
* would give `'1.00'`.
|
|
70
74
|
*
|
|
71
|
-
* @param price - The price
|
|
75
|
+
* @param price - The price to snap, as a decimal string
|
|
72
76
|
* @param szDecimals - The asset's szDecimals (affects max price decimals)
|
|
73
77
|
* @param market - Optional market type (e.g. 'spot'). Defaults to perps rules.
|
|
74
|
-
* @returns Price as a string with correct precision, no trailing zeros
|
|
78
|
+
* @returns Price as a decimal string with correct precision, no trailing zeros
|
|
75
79
|
* @public
|
|
76
80
|
*/
|
|
77
|
-
export function
|
|
78
|
-
price:
|
|
81
|
+
export function snapOrderPrice(
|
|
82
|
+
price: DecimalString,
|
|
79
83
|
szDecimals: number,
|
|
80
84
|
market?: string
|
|
81
|
-
):
|
|
85
|
+
): DecimalString {
|
|
82
86
|
const maxPriceDecimals = getMaxPriceDecimals(szDecimals, market)
|
|
83
87
|
|
|
84
88
|
let rounded = new Big(price).round(maxPriceDecimals, Big.roundHalfUp)
|
package/src/utils/spotBalance.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { numberToDecimalString, parseDecimal } from '@lifi/perps-sdk'
|
|
2
2
|
import type { Asset, Balance, Market } from '@lifi/perps-types'
|
|
3
3
|
import { SPOT_MARKET_ID } from '../constants.js'
|
|
4
4
|
import type { HlSpotBalance } from '../types/index.js'
|
|
@@ -52,8 +52,10 @@ export const spotBalance = (
|
|
|
52
52
|
categoryId: SPOT_MARKET_ID,
|
|
53
53
|
asset,
|
|
54
54
|
units: total,
|
|
55
|
-
valueUsd: (
|
|
55
|
+
valueUsd: numberToDecimalString(
|
|
56
|
+
(parseDecimal(total) ?? Number.NaN) * price
|
|
57
|
+
),
|
|
56
58
|
// A zero entry means the map holds no mark for the asset, not a free asset.
|
|
57
|
-
...(price > 0 ? { price: price
|
|
59
|
+
...(price > 0 ? { price: numberToDecimalString(price) } : {}),
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
calculateWithdrawMax,
|
|
3
|
+
type ProviderWithdrawableBalance,
|
|
4
|
+
} from '@lifi/perps-sdk'
|
|
2
5
|
import type {
|
|
3
6
|
HlAbstractionMode,
|
|
4
7
|
HlClearinghouseState,
|
|
@@ -50,24 +53,26 @@ export const hyperliquidWithdrawableBalances = (
|
|
|
50
53
|
)
|
|
51
54
|
if (spot.gt(0)) {
|
|
52
55
|
const assetId = String(balance.token)
|
|
53
|
-
|
|
56
|
+
const row = {
|
|
54
57
|
assetId,
|
|
55
|
-
route: 'spot',
|
|
58
|
+
route: 'spot' as const,
|
|
56
59
|
available: spot.toFixed(),
|
|
57
60
|
...feeFor(assetId),
|
|
58
|
-
}
|
|
61
|
+
}
|
|
62
|
+
rows.push({ ...row, max: calculateWithdrawMax(row) })
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
const perps = toWireBig(state.withdrawable, 'clearinghouseState.withdrawable')
|
|
64
68
|
if (perps.gt(0)) {
|
|
65
|
-
|
|
69
|
+
const row = {
|
|
66
70
|
assetId: quoteAssetId,
|
|
67
|
-
route: 'perps',
|
|
71
|
+
route: 'perps' as const,
|
|
68
72
|
available: perps.toFixed(),
|
|
69
73
|
...feeFor(quoteAssetId),
|
|
70
|
-
}
|
|
74
|
+
}
|
|
75
|
+
rows.push({ ...row, max: calculateWithdrawMax(row) })
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
return rows
|