@qntx/wallet-engine 0.12.0 → 0.14.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 +1057 -20
- package/dist/apps-fiat24.d.mts +202 -0
- package/dist/apps-fiat24.mjs +1378 -0
- package/dist/apps-fiat24.mjs.map +1 -0
- package/dist/apps-hyperliquid.d.mts +549 -0
- package/dist/apps-hyperliquid.mjs +2742 -0
- package/dist/apps-hyperliquid.mjs.map +1 -0
- package/dist/apps-polymarket.d.mts +729 -0
- package/dist/apps-polymarket.mjs +3786 -0
- package/dist/apps-polymarket.mjs.map +1 -0
- package/dist/apps.d.mts +136 -0
- package/dist/apps.mjs +535 -0
- package/dist/apps.mjs.map +1 -0
- package/dist/connect-BY1C5ZRI.mjs +210 -0
- package/dist/connect-BY1C5ZRI.mjs.map +1 -0
- package/dist/connect.d.mts +17 -9
- package/dist/connect.mjs +3 -185
- package/dist/controller-DpNVHVsj.d.mts +2295 -0
- package/dist/controller-rMnaxKAH.mjs +46 -0
- package/dist/controller-rMnaxKAH.mjs.map +1 -0
- package/dist/decimal-COJ4g8qy.mjs +38 -0
- package/dist/decimal-COJ4g8qy.mjs.map +1 -0
- package/dist/eligibility-BfM9ybYZ.mjs +48 -0
- package/dist/eligibility-BfM9ybYZ.mjs.map +1 -0
- package/dist/engine-Dic_kkEr.d.mts +1829 -0
- package/dist/errors-B8W-hoYW.d.mts +7 -0
- package/dist/errors-horUy5k1.mjs +24 -0
- package/dist/errors-horUy5k1.mjs.map +1 -0
- package/dist/gateway-contract.d.mts +3 -362
- package/dist/gateway-contract.mjs +1531 -81
- package/dist/gateway-contract.mjs.map +1 -1
- package/dist/idb.d.mts +5 -0
- package/dist/idb.mjs +122 -46
- package/dist/idb.mjs.map +1 -1
- package/dist/index-vBgfOFIh.d.mts +2227 -0
- package/dist/index.d.mts +58 -515
- package/dist/index.mjs +22314 -4901
- package/dist/index.mjs.map +1 -1
- package/dist/json-BDwV38cj.mjs +15 -0
- package/dist/json-BDwV38cj.mjs.map +1 -0
- package/dist/link-Ceq8Dggp.mjs +139 -0
- package/dist/link-Ceq8Dggp.mjs.map +1 -0
- package/dist/primitives-DbSHLZKq.mjs +31 -0
- package/dist/primitives-DbSHLZKq.mjs.map +1 -0
- package/dist/push-message-AQuzoNFY.d.mts +84 -0
- package/dist/push-message-kbnH1A5w.mjs +142 -0
- package/dist/push-message-kbnH1A5w.mjs.map +1 -0
- package/dist/push.d.mts +13 -0
- package/dist/push.mjs +70 -0
- package/dist/push.mjs.map +1 -0
- package/dist/qr.d.mts +292 -0
- package/dist/qr.mjs +1725 -0
- package/dist/qr.mjs.map +1 -0
- package/dist/registry-CbtwcxkX.mjs +374 -0
- package/dist/registry-CbtwcxkX.mjs.map +1 -0
- package/dist/risk-DyABgg4W.mjs +757 -0
- package/dist/risk-DyABgg4W.mjs.map +1 -0
- package/dist/session-CNJFLarP.mjs +18 -0
- package/dist/session-CNJFLarP.mjs.map +1 -0
- package/dist/socket-ChG9JRT_.mjs +110 -0
- package/dist/socket-ChG9JRT_.mjs.map +1 -0
- package/dist/spi-BrTw5s98.d.mts +3 -0
- package/dist/timer-Cdk5rGM2.mjs +43 -0
- package/dist/timer-Cdk5rGM2.mjs.map +1 -0
- package/dist/types-BpvioFGo.d.mts +258 -0
- package/dist/types-DbftVZ3I.mjs +90 -0
- package/dist/types-DbftVZ3I.mjs.map +1 -0
- package/dist/walletconnect.d.mts +86 -0
- package/dist/walletconnect.mjs +1507 -0
- package/dist/walletconnect.mjs.map +1 -0
- package/dist/webln-BgrtPXpG.mjs +2593 -0
- package/dist/webln-BgrtPXpG.mjs.map +1 -0
- package/dist/webln-Bllk_xJ2.d.mts +666 -0
- package/package.json +94 -19
- package/dist/connect.mjs.map +0 -1
- package/dist/errors-DpkJneDe.d.mts +0 -1696
- package/dist/registry-Deo5WQe1.d.mts +0 -25
- package/dist/registry-wYrcuFNc.mjs +0 -99
- package/dist/registry-wYrcuFNc.mjs.map +0 -1
- package/dist/webln-DzsI7jVb.mjs +0 -3629
- package/dist/webln-DzsI7jVb.mjs.map +0 -1
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { ln as EvmFeeTier } from "./controller-DpNVHVsj.mjs";
|
|
2
|
+
import { d as AppGroupState, i as AppDefinition, w as AppSocketStatus } from "./types-BpvioFGo.mjs";
|
|
3
|
+
import "./spi-BrTw5s98.mjs";
|
|
4
|
+
import { PublicClient } from "viem";
|
|
5
|
+
import { VerifyFactor, Wallet } from "@qntx/wallet";
|
|
6
|
+
import { ChainsApi } from "@qntx/wallet/chains";
|
|
7
|
+
import { AllMidsParameters, AllMidsResponse, AllMidsResponse as AllMidsResponse$1, CandleSnapshotParameters, CandleSnapshotResponse, CandleSnapshotResponse as CandleSnapshotResponse$1, ClearinghouseStateParameters, ClearinghouseStateResponse, ClearinghouseStateResponse as ClearinghouseStateResponse$1, ExtraAgentsResponse, ExtraAgentsResponse as ExtraAgentsResponse$1, FrontendOpenOrdersParameters, FrontendOpenOrdersResponse, FrontendOpenOrdersResponse as FrontendOpenOrdersResponse$1, FundingHistoryParameters, FundingHistoryResponse, FundingHistoryResponse as FundingHistoryResponse$1, L2BookParameters, L2BookResponse, L2BookResponse as L2BookResponse$1, MaxBuilderFeeResponse, MaxBuilderFeeResponse as MaxBuilderFeeResponse$1, MetaAndAssetCtxsParameters, MetaAndAssetCtxsResponse, MetaAndAssetCtxsResponse as MetaAndAssetCtxsResponse$1, OrderStatusParameters, OrderStatusResponse, OrderStatusResponse as OrderStatusResponse$1, PortfolioResponse, PortfolioResponse as PortfolioResponse$1, PredictedFundingsResponse, PredictedFundingsResponse as PredictedFundingsResponse$1, RecentTradesParameters, RecentTradesResponse, RecentTradesResponse as RecentTradesResponse$1, SpotClearinghouseStateParameters, SpotClearinghouseStateResponse, SpotClearinghouseStateResponse as SpotClearinghouseStateResponse$1, SpotMetaAndAssetCtxsResponse, SpotMetaAndAssetCtxsResponse as SpotMetaAndAssetCtxsResponse$1, UserFeesResponse, UserFeesResponse as UserFeesResponse$1, UserFillsParameters, UserFillsResponse, UserFillsResponse as UserFillsResponse$1, UserFundingParameters, UserFundingResponse, UserFundingResponse as UserFundingResponse$1, UserRateLimitResponse, UserRateLimitResponse as UserRateLimitResponse$1, UserRoleResponse, UserRoleResponse as UserRoleResponse$1 } from "@nktkas/hyperliquid/api/info";
|
|
8
|
+
import { CandleParameters, ClearinghouseStateEvent, L2BookEvent, OpenOrdersEvent, SpotStateEvent, UserFillsEvent } from "@nktkas/hyperliquid/api/subscription";
|
|
9
|
+
import { ISubscriptionTransport } from "@nktkas/hyperliquid";
|
|
10
|
+
import { HyperliquidNetwork, SessionInfo } from "@qntx/wallet/protocol";
|
|
11
|
+
/**
|
|
12
|
+
* Account reads over the injected transport — thin pass-throughs to the SDK request functions with
|
|
13
|
+
* the user always spelled as the lowercase master address.
|
|
14
|
+
*/
|
|
15
|
+
type HyperliquidAccount = {
|
|
16
|
+
/** Perpetual margin summary and open positions. */
|
|
17
|
+
readonly state: (params: ClearinghouseStateParameters) => Promise<ClearinghouseStateResponse$1>;
|
|
18
|
+
/** Spot balances. */
|
|
19
|
+
readonly spot: (params: SpotClearinghouseStateParameters) => Promise<SpotClearinghouseStateResponse$1>;
|
|
20
|
+
/** Open orders with frontend display fields (triggers, TP/SL info). */
|
|
21
|
+
readonly openOrders: (params: FrontendOpenOrdersParameters) => Promise<FrontendOpenOrdersResponse$1>;
|
|
22
|
+
/** The account's fills, optionally aggregated by time. */
|
|
23
|
+
readonly fills: (params: UserFillsParameters) => Promise<UserFillsResponse$1>;
|
|
24
|
+
/** Funding payments and non-funding ledger updates over `[startTime, endTime)`. */
|
|
25
|
+
readonly funding: (params: UserFundingParameters) => Promise<UserFundingResponse$1>;
|
|
26
|
+
/** The account's portfolio breakdown over the standard windows. */
|
|
27
|
+
readonly portfolio: (user: string) => Promise<PortfolioResponse$1>;
|
|
28
|
+
/** The account's REST rate-limit standing. */
|
|
29
|
+
readonly rateLimit: (user: string) => Promise<UserRateLimitResponse$1>;
|
|
30
|
+
/** Fee schedule and discounts for the account. */
|
|
31
|
+
readonly fees: (user: string) => Promise<UserFeesResponse$1>;
|
|
32
|
+
/** Order status by oid or cloid — `{status:"order"}` or `{status:"unknownOid"}`. */
|
|
33
|
+
readonly orderStatus: (params: OrderStatusParameters) => Promise<OrderStatusResponse$1>;
|
|
34
|
+
/** Named API wallets (agents) the account has approved. */
|
|
35
|
+
readonly extraAgents: (user: string) => Promise<ExtraAgentsResponse$1>;
|
|
36
|
+
/** The builder fee the account approved for `builder`, in tenths of a bp. */
|
|
37
|
+
readonly maxBuilderFee: (user: string, builder: string) => Promise<MaxBuilderFeeResponse$1>;
|
|
38
|
+
/** `missing`/`user`/`agent`/`vault`/`subAccount` — gates enabling an agent. */
|
|
39
|
+
readonly role: (user: string) => Promise<UserRoleResponse$1>;
|
|
40
|
+
};
|
|
41
|
+
/** The account identity every trade method takes first — a wallet group, nothing more. */
|
|
42
|
+
type HyperliquidGroup = {
|
|
43
|
+
readonly walletId: string;
|
|
44
|
+
readonly groupIndex: number;
|
|
45
|
+
};
|
|
46
|
+
/** The agent `require` hands to the signer: the kernel-held agent address and its owner. */
|
|
47
|
+
type HyperliquidAgent = {
|
|
48
|
+
readonly address: string;
|
|
49
|
+
readonly owner: string;
|
|
50
|
+
readonly validUntil: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The device/server clock agreement: one estimate per response, computed from the HTTP `Date`
|
|
54
|
+
* header (1 s resolution, so +500 centres it) against the midpoint of the request — the same
|
|
55
|
+
* single-sample estimate Cristian's algorithm gives. Nonces are device milliseconds, strictly
|
|
56
|
+
* increasing per signer; the estimate never adjusts them — it only gates.
|
|
57
|
+
*/
|
|
58
|
+
type HyperliquidClock = {
|
|
59
|
+
/** Feed one response's server time (ms) and the local request bounds (ms). */
|
|
60
|
+
readonly record: (serverMs: number, requestStart: number, responseEnd: number) => void;
|
|
61
|
+
/** The latest skew estimate in ms — positive when the server is ahead — or `undefined`. */
|
|
62
|
+
readonly skew: () => number | undefined;
|
|
63
|
+
/** Throws `clock-skew` once an estimate shows |skew| > {@link MAX_SKEW_MS}. */
|
|
64
|
+
readonly assertSkew: () => void;
|
|
65
|
+
/** The next nonce for `signer` (lowercased address): `max(now, last + 1)`. */
|
|
66
|
+
readonly nextNonce: (signer: string) => number;
|
|
67
|
+
};
|
|
68
|
+
type HyperliquidSocketStatus = AppSocketStatus;
|
|
69
|
+
type HyperliquidSocket = ISubscriptionTransport & {
|
|
70
|
+
readonly isTestnet: boolean;
|
|
71
|
+
/** Current connection status. */
|
|
72
|
+
readonly status: () => HyperliquidSocketStatus;
|
|
73
|
+
/** Subscribe to status transitions; returns an unsubscribe. */
|
|
74
|
+
readonly onStatus: (listener: (status: HyperliquidSocketStatus) => void) => () => void;
|
|
75
|
+
/**
|
|
76
|
+
* Per-subscription `confirmed` transitions — initial AND every re-confirmation after a reconnect.
|
|
77
|
+
* The listener gets the channel and the subscribed payload.
|
|
78
|
+
*/
|
|
79
|
+
readonly onConfirmed: (listener: (channel: string, payload: unknown) => void) => () => void;
|
|
80
|
+
/** Ends every subscription and prevents reconnects. */
|
|
81
|
+
readonly close: () => void;
|
|
82
|
+
};
|
|
83
|
+
/** What a live view reports — `data` is kept while `stale`, never while absent. */
|
|
84
|
+
type LiveState<T> = {
|
|
85
|
+
readonly status: "connecting" | "live" | "stale";
|
|
86
|
+
readonly data: T | undefined;
|
|
87
|
+
readonly updatedAt: number | undefined;
|
|
88
|
+
};
|
|
89
|
+
type LiveView<T> = {
|
|
90
|
+
readonly getState: () => LiveState<T>;
|
|
91
|
+
/** Listener on every state change; returns an unsubscribe. */
|
|
92
|
+
readonly subscribe: (listener: (state: LiveState<T>) => void) => () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Drops the subscription and never updates again. Market views keep their last state; account
|
|
95
|
+
* views (`account`, `spotState`, `openOrders`, `fills`) report `stale` with no data.
|
|
96
|
+
*/
|
|
97
|
+
readonly close: () => Promise<void>;
|
|
98
|
+
};
|
|
99
|
+
type HyperliquidLive = {
|
|
100
|
+
/** Full L2 book — every `l2Book` frame is a complete snapshot and replaces `data`. */
|
|
101
|
+
readonly book: (coin: string, params?: {
|
|
102
|
+
readonly nSigFigs?: 2 | 3 | 4 | 5 | null;
|
|
103
|
+
}) => LiveView<L2BookEvent>;
|
|
104
|
+
/**
|
|
105
|
+
* Trades — deltas over an HTTP `recentTrades` snapshot; deltas arriving before the snapshot
|
|
106
|
+
* buffer, merge/dedupe by `tid`, newest first, capped at {@link TRADES_CAP}.
|
|
107
|
+
*/
|
|
108
|
+
readonly trades: (coin: string) => LiveView<RecentTradesResponse$1>;
|
|
109
|
+
/** Candles — `candle` frames upserted by `t` over an HTTP `candleSnapshot` window. */
|
|
110
|
+
readonly candles: (coin: string, interval: CandleParameters["interval"]) => LiveView<CandleSnapshotResponse$1>;
|
|
111
|
+
/** Full margin state — every `clearinghouseState` frame replaces `data`. */
|
|
112
|
+
readonly account: (group: HyperliquidGroup) => LiveView<ClearinghouseStateEvent>;
|
|
113
|
+
/** Full spot state — every `spotState` frame replaces `data`. */
|
|
114
|
+
readonly spotState: (group: HyperliquidGroup) => LiveView<SpotStateEvent>;
|
|
115
|
+
/** Full open-orders state — every `openOrders` frame replaces `data`. */
|
|
116
|
+
readonly openOrders: (group: HyperliquidGroup) => LiveView<OpenOrdersEvent>;
|
|
117
|
+
/**
|
|
118
|
+
* Fills — the first `userFills` frame of a (re)subscription carries `isSnapshot: true` and
|
|
119
|
+
* replaces `data`; later frames append deduplicated by `tid`.
|
|
120
|
+
*/
|
|
121
|
+
readonly fills: (group: HyperliquidGroup) => LiveView<UserFillsEvent["fills"]>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Market data reads over the injected transport — thin pass-throughs to the SDK request functions
|
|
125
|
+
* so response validation, parameter schemas and return types stay the SDK's.
|
|
126
|
+
*/
|
|
127
|
+
type HyperliquidMarkets = {
|
|
128
|
+
/** Perpetual universe and per-asset contexts (mark price, funding, open interest). */
|
|
129
|
+
readonly perps: (params?: MetaAndAssetCtxsParameters) => Promise<MetaAndAssetCtxsResponse$1>;
|
|
130
|
+
/** Spot universe and per-token contexts. */
|
|
131
|
+
readonly spot: () => Promise<SpotMetaAndAssetCtxsResponse$1>;
|
|
132
|
+
/** The level-2 book snapshot for one coin. */
|
|
133
|
+
readonly book: (params: L2BookParameters) => Promise<L2BookResponse$1>;
|
|
134
|
+
/** Candles for one coin and interval over `[startTime, endTime)`. */
|
|
135
|
+
readonly candles: (params: CandleSnapshotParameters) => Promise<CandleSnapshotResponse$1>;
|
|
136
|
+
/** The most recent trades for one coin. */
|
|
137
|
+
readonly trades: (params: RecentTradesParameters) => Promise<RecentTradesResponse$1>;
|
|
138
|
+
/** Historical funding rates for one coin over `[startTime, endTime)`. */
|
|
139
|
+
readonly fundingHistory: (params: FundingHistoryParameters) => Promise<FundingHistoryResponse$1>;
|
|
140
|
+
/** Predicted funding for the next interval across all coins. */
|
|
141
|
+
readonly predictedFundings: () => Promise<PredictedFundingsResponse$1>;
|
|
142
|
+
/** All mid prices, optionally for one DEX. */
|
|
143
|
+
readonly mids: (params?: AllMidsParameters) => Promise<AllMidsResponse$1>;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Exact decimal arithmetic for Hyperliquid tick and lot rules — bigint units only, no float ever
|
|
147
|
+
* touches a price or size. Prices admit at most 5 significant figures unless they are integers, and
|
|
148
|
+
* at most 6 (perp) or 8 (spot) − `szDecimals` fractional decimals; sizes admit at most `szDecimals`
|
|
149
|
+
* decimals. Rounded output is always the kernel's canonical decimal form.
|
|
150
|
+
*/
|
|
151
|
+
type HyperliquidMarket = "perp" | "spot";
|
|
152
|
+
type OrderSide = "buy" | "sell";
|
|
153
|
+
type RoundDirection = "down" | "up";
|
|
154
|
+
/** An asset the main DEX can trade — the wire `a` plus the market's rounding context. */
|
|
155
|
+
type HyperliquidAsset = {
|
|
156
|
+
readonly asset: number;
|
|
157
|
+
readonly szDecimals: number;
|
|
158
|
+
readonly market: HyperliquidMarket;
|
|
159
|
+
readonly maxLeverage?: number;
|
|
160
|
+
};
|
|
161
|
+
/** TP/SL parameters shared by attached children and standalone trigger orders. */
|
|
162
|
+
type HyperliquidTriggerParams = {
|
|
163
|
+
readonly triggerPx: string;
|
|
164
|
+
/** `true` (default): a market trigger — the fill cap is the slippage price. */
|
|
165
|
+
readonly market?: boolean;
|
|
166
|
+
/** The cap `p` on the wire. Optional for market triggers; required for limit triggers. */
|
|
167
|
+
readonly price?: string;
|
|
168
|
+
/** Cap distance for market triggers without an explicit `price` — required then. */
|
|
169
|
+
readonly slippageBps?: number;
|
|
170
|
+
};
|
|
171
|
+
/** What kind of order `place` builds. `market` is an IOC limit at a slippage cap. */
|
|
172
|
+
type HyperliquidOrderKind = {
|
|
173
|
+
readonly kind: "limit";
|
|
174
|
+
readonly price: string;
|
|
175
|
+
readonly tif?: "Gtc" | "Ioc" | "Alo";
|
|
176
|
+
} | {
|
|
177
|
+
readonly kind: "market";
|
|
178
|
+
readonly slippageBps: number;
|
|
179
|
+
} | ({
|
|
180
|
+
readonly kind: "trigger";
|
|
181
|
+
readonly tpsl: "tp" | "sl";
|
|
182
|
+
} & HyperliquidTriggerParams);
|
|
183
|
+
/** One order to place — the entry; `takeProfit`/`stopLoss` attach reduce-only children. */
|
|
184
|
+
type HyperliquidOrderParams = {
|
|
185
|
+
readonly coin: string;
|
|
186
|
+
readonly side: OrderSide;
|
|
187
|
+
readonly size: string;
|
|
188
|
+
readonly reduceOnly?: boolean;
|
|
189
|
+
readonly order: HyperliquidOrderKind;
|
|
190
|
+
readonly takeProfit?: HyperliquidTriggerParams;
|
|
191
|
+
readonly stopLoss?: HyperliquidTriggerParams;
|
|
192
|
+
/** Position TP/SL: the trigger sizes to the whole position (`positionTpsl` grouping). */
|
|
193
|
+
readonly positionTpsl?: boolean;
|
|
194
|
+
};
|
|
195
|
+
/** `modify`/`batchModify` change a resting order — no attached children, no grouping. */
|
|
196
|
+
type HyperliquidModifyParams = {
|
|
197
|
+
readonly coin: string;
|
|
198
|
+
readonly side: OrderSide;
|
|
199
|
+
readonly size: string;
|
|
200
|
+
readonly reduceOnly?: boolean;
|
|
201
|
+
readonly order: HyperliquidOrderKind;
|
|
202
|
+
};
|
|
203
|
+
/** Why Hyperliquid refused an order — the docs error table plus the wire status names. */
|
|
204
|
+
type HyperliquidRejectReason = "tick" | "min-notional" | "margin" | "reduce-only" | "post-only-would-match" | "ioc-no-match" | "bad-trigger" | "no-liquidity" | "open-interest-cap" | "insufficient-spot-balance" | "oracle" | "max-position" | "other";
|
|
205
|
+
/** What happened to one order of an order action, on the wire or after reconciliation. */
|
|
206
|
+
type HyperliquidOrderOutcome = {
|
|
207
|
+
readonly kind: "resting";
|
|
208
|
+
/** Absent for `waitingForFill`/`waitingForTrigger` statuses, which carry no oid. */
|
|
209
|
+
readonly oid?: number | undefined;
|
|
210
|
+
readonly cloid?: string | undefined;
|
|
211
|
+
/** Size already filled while still resting — only from `orderStatus` reconciliation. */
|
|
212
|
+
readonly filledSz?: string | undefined;
|
|
213
|
+
} | {
|
|
214
|
+
readonly kind: "filled";
|
|
215
|
+
readonly oid?: number | undefined;
|
|
216
|
+
readonly cloid?: string | undefined;
|
|
217
|
+
readonly totalSz: string;
|
|
218
|
+
/** `orderStatus` carries no fill price — absent on reconciled fills, never fabricated. */
|
|
219
|
+
readonly avgPx?: string | undefined;
|
|
220
|
+
} | {
|
|
221
|
+
readonly kind: "rejected";
|
|
222
|
+
readonly cloid?: string | undefined;
|
|
223
|
+
readonly reason: HyperliquidRejectReason;
|
|
224
|
+
readonly message: string;
|
|
225
|
+
} | {
|
|
226
|
+
readonly kind: "unknown";
|
|
227
|
+
readonly cloid?: string | undefined;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* An `unknown` order outcome proven later — by the late reconciler or by a live user-view frame
|
|
231
|
+
* that saw the cloid. `unknown` can never be proven "not placed": Hyperliquid documents no
|
|
232
|
+
* consistency between an info read and L1 state, so only a definite later answer counts.
|
|
233
|
+
*/
|
|
234
|
+
type HyperliquidOutcomeCorrection = {
|
|
235
|
+
readonly group: HyperliquidGroup;
|
|
236
|
+
readonly cloid: string;
|
|
237
|
+
readonly outcome: HyperliquidOrderOutcome;
|
|
238
|
+
};
|
|
239
|
+
/** What happened to one entry of a cancel action. */
|
|
240
|
+
type HyperliquidCancelOutcome = {
|
|
241
|
+
readonly kind: "cancelled";
|
|
242
|
+
} | {
|
|
243
|
+
readonly kind: "rejected";
|
|
244
|
+
readonly message: string;
|
|
245
|
+
} | {
|
|
246
|
+
readonly kind: "unknown";
|
|
247
|
+
};
|
|
248
|
+
/** What happened to an action without per-element statuses; `twapId` when a TWAP started. */
|
|
249
|
+
type HyperliquidActionOutcome = {
|
|
250
|
+
readonly kind: "ok";
|
|
251
|
+
readonly twapId?: number;
|
|
252
|
+
} | {
|
|
253
|
+
readonly kind: "unknown";
|
|
254
|
+
};
|
|
255
|
+
/** `place`/`close` results: the order outcomes plus the entry cap to show the user. */
|
|
256
|
+
type HyperliquidPlaceResult = {
|
|
257
|
+
readonly outcomes: ReadonlyArray<HyperliquidOrderOutcome>;
|
|
258
|
+
/** The entry order's wire price — for a market order or close, the slippage cap. */
|
|
259
|
+
readonly price: string;
|
|
260
|
+
};
|
|
261
|
+
type HyperliquidTrade = {
|
|
262
|
+
/** Place one order — entry plus optional attached TP/SL children. */
|
|
263
|
+
readonly place: (group: HyperliquidGroup, params: HyperliquidOrderParams) => Promise<HyperliquidPlaceResult>;
|
|
264
|
+
/** Replace a resting order by oid or cloid. */
|
|
265
|
+
readonly modify: (group: HyperliquidGroup, params: {
|
|
266
|
+
readonly oid: number | string;
|
|
267
|
+
} & HyperliquidModifyParams) => Promise<HyperliquidActionOutcome>;
|
|
268
|
+
/** Replace many resting orders in one signed action. */
|
|
269
|
+
readonly batchModify: (group: HyperliquidGroup, modifies: ReadonlyArray<{
|
|
270
|
+
readonly oid: number | string;
|
|
271
|
+
} & HyperliquidModifyParams>) => Promise<ReadonlyArray<HyperliquidOrderOutcome>>;
|
|
272
|
+
/** Cancel open orders by oid. */
|
|
273
|
+
readonly cancel: (group: HyperliquidGroup, cancels: ReadonlyArray<{
|
|
274
|
+
readonly coin: string;
|
|
275
|
+
readonly oid: number;
|
|
276
|
+
}>) => Promise<ReadonlyArray<HyperliquidCancelOutcome>>;
|
|
277
|
+
/** Cancel open orders by cloid. */
|
|
278
|
+
readonly cancelByCloid: (group: HyperliquidGroup, cancels: ReadonlyArray<{
|
|
279
|
+
readonly coin: string;
|
|
280
|
+
readonly cloid: string;
|
|
281
|
+
}>) => Promise<ReadonlyArray<HyperliquidCancelOutcome>>;
|
|
282
|
+
/** Cancel every open order of the account — one batch action per ≤64-order chunk. */
|
|
283
|
+
readonly cancelAll: (group: HyperliquidGroup) => Promise<ReadonlyArray<HyperliquidCancelOutcome>>;
|
|
284
|
+
/**
|
|
285
|
+
* Stop a running TWAP — starting one needs no price-less action the kernel could not meter, so it
|
|
286
|
+
* is not offered.
|
|
287
|
+
*/
|
|
288
|
+
readonly twapCancel: (group: HyperliquidGroup, params: {
|
|
289
|
+
readonly coin: string;
|
|
290
|
+
readonly twapId: number;
|
|
291
|
+
}) => Promise<HyperliquidActionOutcome>;
|
|
292
|
+
/** Set cross or isolated leverage within the market's maximum. */
|
|
293
|
+
readonly setLeverage: (group: HyperliquidGroup, params: {
|
|
294
|
+
readonly coin: string;
|
|
295
|
+
readonly leverage: number;
|
|
296
|
+
readonly marginMode: "cross" | "isolated";
|
|
297
|
+
}) => Promise<HyperliquidActionOutcome>;
|
|
298
|
+
/** Add to (positive) or remove from (negative) an isolated position's margin, in USD. */
|
|
299
|
+
readonly adjustMargin: (group: HyperliquidGroup, params: {
|
|
300
|
+
readonly coin: string;
|
|
301
|
+
readonly amount: string;
|
|
302
|
+
}) => Promise<HyperliquidActionOutcome>;
|
|
303
|
+
/** Market-close the whole position of `coin` — reduce-only IOC at the slippage cap. */
|
|
304
|
+
readonly close: (group: HyperliquidGroup, params: {
|
|
305
|
+
readonly coin: string;
|
|
306
|
+
readonly slippageBps: number;
|
|
307
|
+
}) => Promise<HyperliquidPlaceResult>;
|
|
308
|
+
/**
|
|
309
|
+
* Corrections for orders whose outcome was `unknown`: the exchange re-asks them by cloid for ten
|
|
310
|
+
* minutes after the call returned and learns others from live user-view frames. Nothing is ever
|
|
311
|
+
* re-sent.
|
|
312
|
+
*/
|
|
313
|
+
readonly corrections: {
|
|
314
|
+
readonly subscribe: (listener: (correction: HyperliquidOutcomeCorrection) => void) => () => void;
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
/** A user-signed action waiting on approval — the host presents `requestId`'s prompt. */
|
|
318
|
+
type HyperliquidPendingAction = {
|
|
319
|
+
/** The approval request the host shows; the prompt is the kernel-described typed data. */
|
|
320
|
+
readonly requestId: string;
|
|
321
|
+
/**
|
|
322
|
+
* Resolves once the approval resolved and the signed action was posted: `ok`, or `unknown` when
|
|
323
|
+
* the POST's outcome is unknowable (the action may have committed — refresh the account). Rejects
|
|
324
|
+
* with `approval-rejected` when the request is refused/expired and `rejected` when Hyperliquid
|
|
325
|
+
* answers `status: "err"`.
|
|
326
|
+
*/
|
|
327
|
+
readonly outcome: Promise<HyperliquidActionOutcome>;
|
|
328
|
+
};
|
|
329
|
+
/** What a quote preview shows the interface: the wire-ready order and its value checks. */
|
|
330
|
+
type HyperliquidQuotePreview = {
|
|
331
|
+
/** The rounded price that would go on the wire (for a market order, the slippage cap). */
|
|
332
|
+
readonly price: string;
|
|
333
|
+
/** The rounded size that would go on the wire. */
|
|
334
|
+
readonly size: string;
|
|
335
|
+
/** `price` × `size` exactly. */
|
|
336
|
+
readonly notional: string;
|
|
337
|
+
/** Whether the order clears Hyperliquid's 10-quote minimum. */
|
|
338
|
+
readonly meetsMinimum: boolean;
|
|
339
|
+
};
|
|
340
|
+
/** Pure order preview helpers — no I/O, safe to call on every render. */
|
|
341
|
+
type HyperliquidQuote = {
|
|
342
|
+
/** Preview a limit order: price rounded the user's way (buy down, sell up). */
|
|
343
|
+
readonly limit: (params: {
|
|
344
|
+
readonly price: string;
|
|
345
|
+
readonly size: string;
|
|
346
|
+
readonly side: OrderSide;
|
|
347
|
+
readonly szDecimals: number;
|
|
348
|
+
readonly market: HyperliquidMarket;
|
|
349
|
+
}) => HyperliquidQuotePreview;
|
|
350
|
+
/** Preview a market order: the IOC cap at `slippageBps` from `reference`. */
|
|
351
|
+
readonly market: (params: {
|
|
352
|
+
readonly reference: string;
|
|
353
|
+
readonly size: string;
|
|
354
|
+
readonly side: OrderSide;
|
|
355
|
+
readonly slippageBps: number;
|
|
356
|
+
readonly szDecimals: number;
|
|
357
|
+
readonly market: HyperliquidMarket;
|
|
358
|
+
}) => HyperliquidQuotePreview;
|
|
359
|
+
};
|
|
360
|
+
type HyperliquidProvider = {
|
|
361
|
+
readonly markets: HyperliquidMarkets;
|
|
362
|
+
readonly account: HyperliquidAccount;
|
|
363
|
+
readonly quote: HyperliquidQuote;
|
|
364
|
+
/** The skew/nonce clock the transport feeds — exposed so callers can gate signing on it. */
|
|
365
|
+
readonly clock: HyperliquidClock;
|
|
366
|
+
/**
|
|
367
|
+
* Ask an enabled group for the builder fee approval it declined or never gave — `invalid-input`
|
|
368
|
+
* while the group is not `enabled` or no builder is configured.
|
|
369
|
+
*/
|
|
370
|
+
readonly approveBuilder: (group: HyperliquidGroup) => Promise<void>;
|
|
371
|
+
/**
|
|
372
|
+
* Re-approves the group's enabled agent in the kernel after a lock: the kernel shows the
|
|
373
|
+
* session's limits and remaining budget in its verification prompt and the session signs again
|
|
374
|
+
* until the next lock. Trading answers `reopen-required` while the session is unopened.
|
|
375
|
+
*/
|
|
376
|
+
readonly reopen: (group: HyperliquidGroup, verify: VerifyFactor) => Promise<void>;
|
|
377
|
+
/**
|
|
378
|
+
* L1 trading: every method signs the exact action it posts through `sessions(wallet).sign` with
|
|
379
|
+
* the group's enabled, owner-verified agent, and reconciles an unknown order outcome by cloid.
|
|
380
|
+
*/
|
|
381
|
+
readonly trade: HyperliquidTrade;
|
|
382
|
+
/** Funding moves on the signature chain: the CCTP deposit into Hyperliquid. */
|
|
383
|
+
readonly fund: HyperliquidFund;
|
|
384
|
+
/**
|
|
385
|
+
* Move balances the user-signed way — every method opens an approval request and posts the action
|
|
386
|
+
* once the signature resolves.
|
|
387
|
+
*/
|
|
388
|
+
readonly transfer: {
|
|
389
|
+
/** Perp-account USDC → spot account of the same owner. */
|
|
390
|
+
readonly toSpot: (group: HyperliquidGroup, amount: string) => Promise<HyperliquidPendingAction>;
|
|
391
|
+
/** Spot-account USDC → perp account of the same owner. */
|
|
392
|
+
readonly toPerp: (group: HyperliquidGroup, amount: string) => Promise<HyperliquidPendingAction>;
|
|
393
|
+
/** Perp-account USDC to another address (`destination` lowercased). */
|
|
394
|
+
readonly usdSend: (group: HyperliquidGroup, params: {
|
|
395
|
+
readonly destination: string;
|
|
396
|
+
readonly amount: string;
|
|
397
|
+
}) => Promise<HyperliquidPendingAction>;
|
|
398
|
+
/** A spot balance to another address — `token` is the `"NAME:0x<id>"` pair id. */
|
|
399
|
+
readonly spotSend: (group: HyperliquidGroup, params: {
|
|
400
|
+
readonly destination: string;
|
|
401
|
+
readonly token: string;
|
|
402
|
+
readonly amount: string;
|
|
403
|
+
}) => Promise<HyperliquidPendingAction>;
|
|
404
|
+
/** Withdraw USDC to the owner's Arbitrum address — the bridge fee applies at the bridge. */
|
|
405
|
+
readonly withdraw: (group: HyperliquidGroup, params: {
|
|
406
|
+
readonly destination: string;
|
|
407
|
+
readonly amount: string;
|
|
408
|
+
}) => Promise<HyperliquidPendingAction>;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Streaming views over the WebSocket transport — present only when the provider was built with a
|
|
412
|
+
* `socket` (createApps always wires one). Market views need no unlocked wallet; user views
|
|
413
|
+
* resolve the group to its owner and close on lock.
|
|
414
|
+
*/
|
|
415
|
+
readonly live?: HyperliquidLive;
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* The CCTP deposit: a `depositForBurnWithHook` on this chain's TokenMessengerV2 burns USDC and
|
|
419
|
+
* Circle's CctpForwarder on HyperEVM (destination domain 19) mints it into the Hyperliquid account
|
|
420
|
+
* — the legacy Bridge2 route is deprecated (docs §Deposits; research §H-1). Sources:
|
|
421
|
+
*
|
|
422
|
+
* - TokenMessengerV2 — https://developers.circle.com/cctp/references/contract-addresses
|
|
423
|
+
* - USDC — https://developers.circle.com/stablecoins/usdc-contract-addresses
|
|
424
|
+
* - CctpForwarder — https://developers.circle.com/cctp/references/hypercore-contract-addresses
|
|
425
|
+
*/
|
|
426
|
+
type HyperliquidDepositInfo = {
|
|
427
|
+
/** The CCTP TokenMessengerV2 the deposit burns USDC through. */
|
|
428
|
+
readonly tokenMessenger: string;
|
|
429
|
+
/** The USDC contract the deposit spends. */
|
|
430
|
+
readonly usdc: string;
|
|
431
|
+
/** Circle's CctpForwarder on HyperEVM — mint recipient and destination caller. */
|
|
432
|
+
readonly forwarder: string;
|
|
433
|
+
/** The signature chain, CAIP-2. */
|
|
434
|
+
readonly network: string;
|
|
435
|
+
/** The Hyperliquid CCTP destination domain. */
|
|
436
|
+
readonly destinationDomain: number;
|
|
437
|
+
/** The confirmed-finality threshold the deposit requests (Circle's Fast Transfer 1000). */
|
|
438
|
+
readonly minFinalityThreshold: number;
|
|
439
|
+
/** The hook's dex selector for the account the deposit funds. */
|
|
440
|
+
readonly dex: "perps" | "spot";
|
|
441
|
+
};
|
|
442
|
+
export declare const HYPERLIQUID_DEPOSIT: Record<"Mainnet" | "Testnet", HyperliquidDepositInfo>;
|
|
443
|
+
/**
|
|
444
|
+
* The two-call CCTP deposit flow. When the messenger's USDC allowance is short, only the
|
|
445
|
+
* exact-amount approve opens — the deposit call cannot be prepared yet (`eth_estimateGas` would
|
|
446
|
+
* revert on-chain while the approval is unmined), so the host approves it and calls `deposit` again
|
|
447
|
+
* once the approval confirmed; the re-read allowance then covers the amount and only the burn
|
|
448
|
+
* request opens.
|
|
449
|
+
*/
|
|
450
|
+
type HyperliquidDeposit = {
|
|
451
|
+
readonly kind: "approval-required";
|
|
452
|
+
/** The exact-amount USDC approve for the TokenMessengerV2. */
|
|
453
|
+
readonly approval: HyperliquidPendingAction;
|
|
454
|
+
} | {
|
|
455
|
+
readonly kind: "deposit";
|
|
456
|
+
/** The `depositForBurnWithHook` transaction. */
|
|
457
|
+
readonly deposit: HyperliquidPendingAction;
|
|
458
|
+
};
|
|
459
|
+
type HyperliquidFund = {
|
|
460
|
+
/** The CCTP route constants for the provider's network. */
|
|
461
|
+
readonly depositInfo: HyperliquidDepositInfo;
|
|
462
|
+
/**
|
|
463
|
+
* Fund the Hyperliquid account from the group's Arbitrum USDC through Circle's CCTP: an
|
|
464
|
+
* exact-amount `approve` to the TokenMessengerV2 when the allowance is short, then a
|
|
465
|
+
* `depositForBurnWithHook` routed to the CctpForwarder (domain 19, finality 1000). `amount` is
|
|
466
|
+
* USDC base units (6 decimals); it must exceed the Circle fee and fit the per-message burn limit.
|
|
467
|
+
* Both request outcomes are reported.
|
|
468
|
+
*/
|
|
469
|
+
readonly deposit: (group: HyperliquidGroup, params: {
|
|
470
|
+
readonly amount: bigint;
|
|
471
|
+
readonly fee: EvmFeeTier;
|
|
472
|
+
/** Which Hyperliquid account the deposit funds — `depositInfo.dex` when omitted. */
|
|
473
|
+
readonly dex?: "perps" | "spot";
|
|
474
|
+
}) => Promise<HyperliquidDeposit>;
|
|
475
|
+
};
|
|
476
|
+
/** The resumable enablement step a group is in; absent when `status` is terminal. */
|
|
477
|
+
type HyperliquidStep = "create-agent" | "approve-agent" | "approve-builder" | "verify" | "revoke";
|
|
478
|
+
type HyperliquidGroupAgent = {
|
|
479
|
+
readonly address: string;
|
|
480
|
+
readonly name: string;
|
|
481
|
+
readonly validUntil: number;
|
|
482
|
+
readonly network: string;
|
|
483
|
+
};
|
|
484
|
+
/** Hyperliquid's own group-state fields on top of the controller's base. */
|
|
485
|
+
type HyperliquidDetail = {
|
|
486
|
+
/** The agent the group is enabling or enabled with. */
|
|
487
|
+
readonly agent?: HyperliquidGroupAgent;
|
|
488
|
+
/** The step an `enabling` flow is at — `verify` also marks a lost-POST re-check. */
|
|
489
|
+
readonly step?: HyperliquidStep;
|
|
490
|
+
/** `validUntil - now < 14 days` — the host surfaces a renew prompt. */
|
|
491
|
+
readonly renewalDue?: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* `approved` once `maxBuilderFee(owner, builder) >= f` was confirmed on Hyperliquid; `declined`
|
|
494
|
+
* when the user refused the approval — trades go out without a builder either way the fee is
|
|
495
|
+
* unconfirmed.
|
|
496
|
+
*/
|
|
497
|
+
readonly builder?: "approved" | "declined";
|
|
498
|
+
};
|
|
499
|
+
/** One wallet group's Hyperliquid app state. */
|
|
500
|
+
type HyperliquidGroupState = AppGroupState<HyperliquidDetail>;
|
|
501
|
+
type AppsBuilderConfig = {
|
|
502
|
+
/** The builder address the trades attach once `maxBuilderFee` confirms `feeRateTenthsBps`. */
|
|
503
|
+
readonly address: string;
|
|
504
|
+
/** Tenths of a basis point: 1..100 (the perps cap is 0.1 %). */
|
|
505
|
+
readonly feeRateTenthsBps: number;
|
|
506
|
+
};
|
|
507
|
+
type AppsHyperliquidConfig = {
|
|
508
|
+
readonly network: HyperliquidNetwork;
|
|
509
|
+
/** The agent name — `^[A-Za-z0-9._-]{1,16}$`, the exchange's limit. */
|
|
510
|
+
readonly agentName: string;
|
|
511
|
+
readonly builder?: AppsBuilderConfig;
|
|
512
|
+
};
|
|
513
|
+
export declare function hyperliquid(config: AppsHyperliquidConfig): AppDefinition<"hyperliquid", HyperliquidProvider, HyperliquidDetail>;
|
|
514
|
+
/** Hyperliquid provider error categories — never carry request payloads or secrets. */
|
|
515
|
+
type HyperliquidErrorCategory = "network" |
|
|
516
|
+
/** The request may have reached the server; an /exchange post's outcome is unknown. */
|
|
517
|
+
"timeout" |
|
|
518
|
+
/** The server answered with a non-2xx status. */
|
|
519
|
+
"unavailable" |
|
|
520
|
+
/** The device clock disagrees with the server beyond the bound — signing would be refused. */
|
|
521
|
+
"clock-skew" |
|
|
522
|
+
/** A price, size or other caller input fails the tick/lot/canonical rules. */
|
|
523
|
+
"invalid-input" |
|
|
524
|
+
/** Hyperliquid rejected the signed action itself (a `status: "err"` exchange answer). */
|
|
525
|
+
"rejected" |
|
|
526
|
+
/** The vault is locked — the kernel refused to sign; nothing was posted. */
|
|
527
|
+
"unlock-required" |
|
|
528
|
+
/** The enabled agent expired, was rejected by Hyperliquid, or is gone — re-enable is required. */
|
|
529
|
+
"reauthorization-required" |
|
|
530
|
+
/** The kernel session is closed since the last lock — `reopen` must verify the user again. */
|
|
531
|
+
"reopen-required" |
|
|
532
|
+
/** The vault has a device factor — the app lock must be on for a value-moving session. */
|
|
533
|
+
"app-lock-required" |
|
|
534
|
+
/** The action exceeds the agent's approved limits — the kernel refused to sign it. */
|
|
535
|
+
"limit-exceeded" |
|
|
536
|
+
/** The account has no enabled, owner-verified agent on this network. */
|
|
537
|
+
"not-enabled" |
|
|
538
|
+
/** The account has no Hyperliquid presence yet — a deposit must land before enabling. */
|
|
539
|
+
"deposit-required" |
|
|
540
|
+
/** The user refused, or the approval request expired or was invalidated. */
|
|
541
|
+
"approval-rejected" |
|
|
542
|
+
/** An enablement flow is already running for the group — wait or cancel it. */
|
|
543
|
+
"busy";
|
|
544
|
+
export declare class HyperliquidError extends Error {
|
|
545
|
+
readonly category: HyperliquidErrorCategory;
|
|
546
|
+
constructor(category: HyperliquidErrorCategory, message: string, cause?: unknown);
|
|
547
|
+
}
|
|
548
|
+
export type { AllMidsResponse, AppsBuilderConfig, AppsHyperliquidConfig, CandleSnapshotResponse, ClearinghouseStateResponse, ExtraAgentsResponse, FrontendOpenOrdersResponse, FundingHistoryResponse, HyperliquidAccount, HyperliquidActionOutcome, HyperliquidAgent, HyperliquidAsset, HyperliquidCancelOutcome, HyperliquidClock, HyperliquidDepositInfo, HyperliquidDetail, HyperliquidErrorCategory, HyperliquidFund, HyperliquidGroup, HyperliquidGroupAgent, HyperliquidGroupState, HyperliquidLive, HyperliquidMarket, HyperliquidMarkets, HyperliquidModifyParams, HyperliquidOrderKind, HyperliquidOrderOutcome, HyperliquidOrderParams, HyperliquidOutcomeCorrection, HyperliquidPendingAction, HyperliquidPlaceResult, HyperliquidProvider, HyperliquidQuote, HyperliquidQuotePreview, HyperliquidRejectReason, HyperliquidSocket, HyperliquidSocketStatus, HyperliquidStep, HyperliquidTrade, HyperliquidTriggerParams, L2BookResponse, LiveState, LiveView, MaxBuilderFeeResponse, MetaAndAssetCtxsResponse, OrderSide, OrderStatusResponse, PortfolioResponse, PredictedFundingsResponse, RecentTradesResponse, RoundDirection, SpotClearinghouseStateResponse, SpotMetaAndAssetCtxsResponse, UserFeesResponse, UserFillsResponse, UserFundingResponse, UserRateLimitResponse, UserRoleResponse };
|
|
549
|
+
//# sourceMappingURL=apps-hyperliquid.d.mts.map
|