@oneie/cli 5.8.0 → 5.9.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 +114 -6
- package/dist/package.json +37 -11
- package/dist/src/age-1k8hs4ec.js +1 -0
- package/dist/src/client-n6fpnd9f.js +1 -0
- package/dist/src/evm-tx-cqhm9rtt.js +1 -0
- package/dist/src/hl-run-0pv1e0p2.js +1 -0
- package/dist/src/index-f5vhzspa.js +12 -0
- package/dist/src/index-h3nrt8bx.js +4 -0
- package/dist/src/index-st6k9vhc.js +2062 -0
- package/dist/src/index.js +1122 -134
- package/dist/src/message-key-yczrxszr.js +1 -0
- package/dist/src/message-lock-thr851d5.js +5 -0
- package/dist/src/sweep-order-jrq2hkye.js +1 -0
- package/dist/src/sweep-runner-jftw9em7.js +1 -0
- package/package.json +37 -11
- package/dist/src/agent.d.ts +0 -75
- package/dist/src/agent.js +0 -1334
- package/dist/src/agentverse.d.ts +0 -26
- package/dist/src/agentverse.js +0 -171
- package/dist/src/args.d.ts +0 -9
- package/dist/src/args.js +0 -61
- package/dist/src/auth.d.ts +0 -6
- package/dist/src/auth.js +0 -121
- package/dist/src/balances.d.ts +0 -89
- package/dist/src/balances.js +0 -202
- package/dist/src/banner.d.ts +0 -1
- package/dist/src/banner.js +0 -17
- package/dist/src/broadcast.d.ts +0 -8
- package/dist/src/broadcast.js +0 -175
- package/dist/src/catalog.d.ts +0 -12
- package/dist/src/catalog.js +0 -76
- package/dist/src/ceiling.d.ts +0 -36
- package/dist/src/ceiling.js +0 -189
- package/dist/src/chat.d.ts +0 -2
- package/dist/src/chat.js +0 -92
- package/dist/src/check.d.ts +0 -11
- package/dist/src/check.js +0 -53
- package/dist/src/client.d.ts +0 -5
- package/dist/src/client.js +0 -157
- package/dist/src/compiler.d.ts +0 -36
- package/dist/src/compiler.js +0 -366
- package/dist/src/config.d.ts +0 -24
- package/dist/src/config.js +0 -70
- package/dist/src/connect.d.ts +0 -2
- package/dist/src/connect.js +0 -64
- package/dist/src/coordinate.d.ts +0 -3
- package/dist/src/coordinate.js +0 -58
- package/dist/src/create.d.ts +0 -2
- package/dist/src/create.js +0 -113
- package/dist/src/credits.d.ts +0 -29
- package/dist/src/credits.js +0 -88
- package/dist/src/deploy.d.ts +0 -2
- package/dist/src/deploy.js +0 -19
- package/dist/src/dev.d.ts +0 -2
- package/dist/src/dev.js +0 -75
- package/dist/src/device-flow.d.ts +0 -57
- package/dist/src/device-flow.js +0 -173
- package/dist/src/doctor.d.ts +0 -26
- package/dist/src/doctor.js +0 -146
- package/dist/src/draw.d.ts +0 -18
- package/dist/src/draw.js +0 -156
- package/dist/src/endpoint.d.ts +0 -2
- package/dist/src/endpoint.js +0 -250
- package/dist/src/env.d.ts +0 -3
- package/dist/src/env.js +0 -37
- package/dist/src/eval.d.ts +0 -2
- package/dist/src/eval.js +0 -43
- package/dist/src/fn.d.ts +0 -2
- package/dist/src/fn.js +0 -70
- package/dist/src/group.d.ts +0 -2
- package/dist/src/group.js +0 -117
- package/dist/src/hl-run.d.ts +0 -119
- package/dist/src/hl-run.js +0 -480
- package/dist/src/hl.d.ts +0 -17
- package/dist/src/hl.js +0 -148
- package/dist/src/index.d.ts +0 -2
- package/dist/src/init.d.ts +0 -76
- package/dist/src/init.js +0 -278
- package/dist/src/join.d.ts +0 -11
- package/dist/src/join.js +0 -297
- package/dist/src/key-publish.d.ts +0 -40
- package/dist/src/key-publish.js +0 -232
- package/dist/src/key-seal.d.ts +0 -21
- package/dist/src/key-seal.js +0 -142
- package/dist/src/key-sweep.d.ts +0 -93
- package/dist/src/key-sweep.js +0 -270
- package/dist/src/key.d.ts +0 -26
- package/dist/src/key.js +0 -338
- package/dist/src/lib/age-plugin.d.ts +0 -51
- package/dist/src/lib/age-plugin.js +0 -130
- package/dist/src/lib/agent-env.d.ts +0 -12
- package/dist/src/lib/agent-env.js +0 -48
- package/dist/src/lib/api-path.d.ts +0 -2
- package/dist/src/lib/api-path.js +0 -40
- package/dist/src/lib/asker.d.ts +0 -34
- package/dist/src/lib/asker.js +0 -126
- package/dist/src/lib/check-words.d.ts +0 -57
- package/dist/src/lib/check-words.js +0 -144
- package/dist/src/lib/client.d.ts +0 -20
- package/dist/src/lib/client.js +0 -71
- package/dist/src/lib/env-sealed.d.ts +0 -53
- package/dist/src/lib/env-sealed.js +0 -184
- package/dist/src/lib/flow-tag.d.ts +0 -86
- package/dist/src/lib/flow-tag.js +0 -230
- package/dist/src/lib/hl-core/actions.d.ts +0 -99
- package/dist/src/lib/hl-core/actions.js +0 -69
- package/dist/src/lib/hl-core/eip712.d.ts +0 -33
- package/dist/src/lib/hl-core/eip712.js +0 -107
- package/dist/src/lib/hl-core/errors.d.ts +0 -10
- package/dist/src/lib/hl-core/errors.js +0 -15
- package/dist/src/lib/hl-core/exchange.d.ts +0 -24
- package/dist/src/lib/hl-core/exchange.js +0 -47
- package/dist/src/lib/hl-core/index.d.ts +0 -13
- package/dist/src/lib/hl-core/index.js +0 -14
- package/dist/src/lib/hl-core/meta.d.ts +0 -57
- package/dist/src/lib/hl-core/meta.js +0 -110
- package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
- package/dist/src/lib/hl-core/msgpack.js +0 -136
- package/dist/src/lib/hl-core/net.d.ts +0 -2
- package/dist/src/lib/hl-core/net.js +0 -7
- package/dist/src/lib/hl-core/signing.d.ts +0 -103
- package/dist/src/lib/hl-core/signing.js +0 -295
- package/dist/src/lib/hl-core/wire.d.ts +0 -34
- package/dist/src/lib/hl-core/wire.js +0 -81
- package/dist/src/lib/invoked-as.d.ts +0 -2
- package/dist/src/lib/invoked-as.js +0 -24
- package/dist/src/lib/journey-words.d.ts +0 -84
- package/dist/src/lib/journey-words.js +0 -363
- package/dist/src/lib/journey.d.ts +0 -150
- package/dist/src/lib/journey.js +0 -264
- package/dist/src/lib/key-receipt.d.ts +0 -48
- package/dist/src/lib/key-receipt.js +0 -116
- package/dist/src/lib/key-source.d.ts +0 -9
- package/dist/src/lib/key-source.js +0 -33
- package/dist/src/lib/keyfile.d.ts +0 -136
- package/dist/src/lib/keyfile.js +0 -397
- package/dist/src/lib/launch-claude.d.ts +0 -5
- package/dist/src/lib/launch-claude.js +0 -45
- package/dist/src/lib/lock-lookup.d.ts +0 -40
- package/dist/src/lib/lock-lookup.js +0 -92
- package/dist/src/lib/message-seal.d.ts +0 -63
- package/dist/src/lib/message-seal.js +0 -150
- package/dist/src/lib/net-choice.d.ts +0 -28
- package/dist/src/lib/net-choice.js +0 -72
- package/dist/src/lib/network.d.ts +0 -22
- package/dist/src/lib/network.js +0 -50
- package/dist/src/lib/next-words.d.ts +0 -105
- package/dist/src/lib/next-words.js +0 -298
- package/dist/src/lib/paths.d.ts +0 -41
- package/dist/src/lib/paths.js +0 -91
- package/dist/src/lib/plan-draw.d.ts +0 -56
- package/dist/src/lib/plan-draw.js +0 -219
- package/dist/src/lib/plan-live.d.ts +0 -20
- package/dist/src/lib/plan-live.js +0 -192
- package/dist/src/lib/qr.d.ts +0 -21
- package/dist/src/lib/qr.js +0 -402
- package/dist/src/lib/roster.d.ts +0 -20
- package/dist/src/lib/roster.js +0 -79
- package/dist/src/lib/sale-card.d.ts +0 -117
- package/dist/src/lib/sale-card.js +0 -261
- package/dist/src/lib/shop-init.d.ts +0 -62
- package/dist/src/lib/shop-init.js +0 -63
- package/dist/src/lib/sui-grpc-send.d.ts +0 -90
- package/dist/src/lib/sui-grpc-send.js +0 -128
- package/dist/src/lib/swap-core.d.ts +0 -163
- package/dist/src/lib/swap-core.js +0 -405
- package/dist/src/lib/tasks-digest.d.ts +0 -66
- package/dist/src/lib/tasks-digest.js +0 -200
- package/dist/src/lib/tasks-graph.d.ts +0 -79
- package/dist/src/lib/tasks-graph.js +0 -463
- package/dist/src/lib/tasks-lens.d.ts +0 -31
- package/dist/src/lib/tasks-lens.js +0 -47
- package/dist/src/lib/tasks-next.d.ts +0 -25
- package/dist/src/lib/tasks-next.js +0 -103
- package/dist/src/lib/tasks-prove.d.ts +0 -15
- package/dist/src/lib/tasks-prove.js +0 -68
- package/dist/src/lib/tasks-route.d.ts +0 -29
- package/dist/src/lib/tasks-route.js +0 -151
- package/dist/src/lib/tasks-score.d.ts +0 -36
- package/dist/src/lib/tasks-score.js +0 -152
- package/dist/src/lib/tasks-workspace.d.ts +0 -18
- package/dist/src/lib/tasks-workspace.js +0 -73
- package/dist/src/lib/timed-fetch.d.ts +0 -33
- package/dist/src/lib/timed-fetch.js +0 -59
- package/dist/src/lib/vault-read.d.ts +0 -24
- package/dist/src/lib/vault-read.js +0 -77
- package/dist/src/lib/vaultfile.d.ts +0 -103
- package/dist/src/lib/vaultfile.js +0 -249
- package/dist/src/lib/wallet-money.d.ts +0 -222
- package/dist/src/lib/wallet-money.js +0 -578
- package/dist/src/lib/wallet-request.d.ts +0 -50
- package/dist/src/lib/wallet-request.js +0 -86
- package/dist/src/links.d.ts +0 -5
- package/dist/src/links.js +0 -45
- package/dist/src/media.d.ts +0 -29
- package/dist/src/media.js +0 -487
- package/dist/src/message-receipt.d.ts +0 -25
- package/dist/src/message-receipt.js +0 -71
- package/dist/src/message.d.ts +0 -13
- package/dist/src/message.js +0 -92
- package/dist/src/move.d.ts +0 -36
- package/dist/src/move.js +0 -152
- package/dist/src/network-cmd.d.ts +0 -17
- package/dist/src/network-cmd.js +0 -74
- package/dist/src/next.d.ts +0 -12
- package/dist/src/next.js +0 -67
- package/dist/src/onboard.d.ts +0 -16
- package/dist/src/onboard.js +0 -149
- package/dist/src/plugin.d.ts +0 -2
- package/dist/src/plugin.js +0 -193
- package/dist/src/push.d.ts +0 -2
- package/dist/src/push.js +0 -115
- package/dist/src/render.d.ts +0 -21
- package/dist/src/render.js +0 -32
- package/dist/src/secrets-device.d.ts +0 -32
- package/dist/src/secrets-device.js +0 -127
- package/dist/src/secrets-give.d.ts +0 -125
- package/dist/src/secrets-give.js +0 -236
- package/dist/src/secrets-list.d.ts +0 -27
- package/dist/src/secrets-list.js +0 -84
- package/dist/src/secrets-run.d.ts +0 -31
- package/dist/src/secrets-run.js +0 -182
- package/dist/src/secrets.d.ts +0 -33
- package/dist/src/secrets.js +0 -200
- package/dist/src/setup.d.ts +0 -6
- package/dist/src/setup.js +0 -127
- package/dist/src/ship.d.ts +0 -2
- package/dist/src/ship.js +0 -18
- package/dist/src/shop-buy.d.ts +0 -16
- package/dist/src/shop-buy.js +0 -101
- package/dist/src/shop.d.ts +0 -10
- package/dist/src/shop.js +0 -112
- package/dist/src/skill-parser.d.ts +0 -14
- package/dist/src/skill-parser.js +0 -113
- package/dist/src/skill.d.ts +0 -2
- package/dist/src/skill.js +0 -493
- package/dist/src/slug.d.ts +0 -2
- package/dist/src/slug.js +0 -6
- package/dist/src/social.d.ts +0 -2
- package/dist/src/social.js +0 -106
- package/dist/src/staff.d.ts +0 -2
- package/dist/src/staff.js +0 -104
- package/dist/src/start.d.ts +0 -27
- package/dist/src/start.js +0 -225
- package/dist/src/status.d.ts +0 -2
- package/dist/src/status.js +0 -52
- package/dist/src/substrate.d.ts +0 -2
- package/dist/src/substrate.js +0 -258
- package/dist/src/swap.d.ts +0 -93
- package/dist/src/swap.js +0 -622
- package/dist/src/tasks.d.ts +0 -2
- package/dist/src/tasks.js +0 -743
- package/dist/src/templates.d.ts +0 -1
- package/dist/src/templates.js +0 -213
- package/dist/src/thread.d.ts +0 -2
- package/dist/src/thread.js +0 -52
- package/dist/src/trade.d.ts +0 -2
- package/dist/src/trade.js +0 -91
- package/dist/src/trail.d.ts +0 -2
- package/dist/src/trail.js +0 -41
- package/dist/src/validate.d.ts +0 -13
- package/dist/src/validate.js +0 -35
- package/dist/src/wallet-money.d.ts +0 -158
- package/dist/src/wallet-money.js +0 -664
- package/dist/src/wallet.d.ts +0 -169
- package/dist/src/wallet.js +0 -973
- package/dist/src/workflow.d.ts +0 -2
- package/dist/src/workflow.js +0 -169
- package/dist/src/write.d.ts +0 -43
- package/dist/src/write.js +0 -180
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid/actions — builders for the four actions ONE prepares (text/hyperliquid-plan.md H2):
|
|
3
|
-
*
|
|
4
|
-
* L1 (msgpack-hashed, phantom-agent signed) order · cancel
|
|
5
|
-
* user-signed (own EIP-712 domain) usdClassTransfer · withdraw3
|
|
6
|
-
*
|
|
7
|
-
* KEY ORDER IS PART OF THE HASH for L1 actions: msgpack keeps insertion order, so each literal
|
|
8
|
-
* below is written in exactly the python SDK's order (`order_request_to_order_wire`,
|
|
9
|
-
* `order_wires_to_order_action`, `bulk_cancel`). Do not "tidy" them.
|
|
10
|
-
*
|
|
11
|
-
* Every builder validates against the asset's tick rules and throws `HlRefusal` before an action
|
|
12
|
-
* exists. Nothing here reads the network or the clock: nonce and mid come in as arguments.
|
|
13
|
-
*/
|
|
14
|
-
import { type AssetInfo } from './meta.js';
|
|
15
|
-
export type Tif = 'Gtc' | 'Ioc' | 'Alo';
|
|
16
|
-
export interface OrderWire {
|
|
17
|
-
a: number;
|
|
18
|
-
b: boolean;
|
|
19
|
-
p: string;
|
|
20
|
-
s: string;
|
|
21
|
-
r: boolean;
|
|
22
|
-
t: {
|
|
23
|
-
limit: {
|
|
24
|
-
tif: Tif;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
c?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface OrderAction {
|
|
30
|
-
type: 'order';
|
|
31
|
-
orders: OrderWire[];
|
|
32
|
-
grouping: 'na';
|
|
33
|
-
}
|
|
34
|
-
export interface CancelAction {
|
|
35
|
-
type: 'cancel';
|
|
36
|
-
cancels: Array<{
|
|
37
|
-
a: number;
|
|
38
|
-
o: number;
|
|
39
|
-
}>;
|
|
40
|
-
}
|
|
41
|
-
export interface UsdClassTransferAction {
|
|
42
|
-
type: 'usdClassTransfer';
|
|
43
|
-
amount: string;
|
|
44
|
-
toPerp: boolean;
|
|
45
|
-
nonce: number;
|
|
46
|
-
}
|
|
47
|
-
export interface Withdraw3Action {
|
|
48
|
-
type: 'withdraw3';
|
|
49
|
-
destination: string;
|
|
50
|
-
amount: string;
|
|
51
|
-
time: number;
|
|
52
|
-
}
|
|
53
|
-
export type L1Action = OrderAction | CancelAction;
|
|
54
|
-
export type UserAction = UsdClassTransferAction | Withdraw3Action;
|
|
55
|
-
export type HlAction = L1Action | UserAction;
|
|
56
|
-
export interface LimitOrderInput {
|
|
57
|
-
asset: AssetInfo;
|
|
58
|
-
isBuy: boolean;
|
|
59
|
-
/** Decimal string, in the asset's units. */
|
|
60
|
-
sz: string;
|
|
61
|
-
/** Decimal string. */
|
|
62
|
-
px: string;
|
|
63
|
-
tif?: Tif;
|
|
64
|
-
reduceOnly?: boolean;
|
|
65
|
-
/** 16-byte client order id, 0x + 32 hex. */
|
|
66
|
-
cloid?: string;
|
|
67
|
-
}
|
|
68
|
-
export declare function orderWire(o: LimitOrderInput): OrderWire;
|
|
69
|
-
export declare function buildOrder(o: LimitOrderInput): OrderAction;
|
|
70
|
-
export interface MarketOrderInput {
|
|
71
|
-
asset: AssetInfo;
|
|
72
|
-
isBuy: boolean;
|
|
73
|
-
sz: string;
|
|
74
|
-
/** The mid the caller read (allMids). The core never fetches it. */
|
|
75
|
-
mid: string;
|
|
76
|
-
/** Default 0.05, the python SDK's DEFAULT_SLIPPAGE. */
|
|
77
|
-
slippage?: number;
|
|
78
|
-
reduceOnly?: boolean;
|
|
79
|
-
cloid?: string;
|
|
80
|
-
}
|
|
81
|
-
/** A market order is an aggressive IOC limit (python `market_open` / `market_close`). */
|
|
82
|
-
export declare function buildMarketOrder(o: MarketOrderInput): OrderAction;
|
|
83
|
-
/** A cancel needs only the asset INDEX; pass the AssetInfo from the table when you have it. */
|
|
84
|
-
export declare function buildCancel(o: {
|
|
85
|
-
asset: Pick<AssetInfo, 'asset'>;
|
|
86
|
-
oid: number;
|
|
87
|
-
}): CancelAction;
|
|
88
|
-
/** Move USDC between the spot and perps balances of the SAME account (toPerp: spot → perps). */
|
|
89
|
-
export declare function buildUsdClassTransfer(o: {
|
|
90
|
-
amount: string;
|
|
91
|
-
toPerp: boolean;
|
|
92
|
-
nonce: number;
|
|
93
|
-
}): UsdClassTransferAction;
|
|
94
|
-
/** Withdraw USDC from the PERPS balance to an address on Arbitrum. */
|
|
95
|
-
export declare function buildWithdraw3(o: {
|
|
96
|
-
destination: string;
|
|
97
|
-
amount: string;
|
|
98
|
-
time: number;
|
|
99
|
-
}): Withdraw3Action;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/actions.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid/actions — builders for the four actions ONE prepares (text/hyperliquid-plan.md H2):
|
|
4
|
-
*
|
|
5
|
-
* L1 (msgpack-hashed, phantom-agent signed) order · cancel
|
|
6
|
-
* user-signed (own EIP-712 domain) usdClassTransfer · withdraw3
|
|
7
|
-
*
|
|
8
|
-
* KEY ORDER IS PART OF THE HASH for L1 actions: msgpack keeps insertion order, so each literal
|
|
9
|
-
* below is written in exactly the python SDK's order (`order_request_to_order_wire`,
|
|
10
|
-
* `order_wires_to_order_action`, `bulk_cancel`). Do not "tidy" them.
|
|
11
|
-
*
|
|
12
|
-
* Every builder validates against the asset's tick rules and throws `HlRefusal` before an action
|
|
13
|
-
* exists. Nothing here reads the network or the clock: nonce and mid come in as arguments.
|
|
14
|
-
*/
|
|
15
|
-
import { HlRefusal } from './errors.js';
|
|
16
|
-
import { BUILDER_DEX_OFFSET } from './meta.js';
|
|
17
|
-
import { checkPrice, checkSize, checkUsd, marketPrice } from './wire.js';
|
|
18
|
-
const TIFS = ['Gtc', 'Ioc', 'Alo'];
|
|
19
|
-
const CLOID = /^0x[0-9a-fA-F]{32}$/;
|
|
20
|
-
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
21
|
-
export function orderWire(o) {
|
|
22
|
-
const tif = o.tif ?? 'Gtc';
|
|
23
|
-
if (!TIFS.includes(tif))
|
|
24
|
-
throw new HlRefusal('bad_tif', String(tif));
|
|
25
|
-
if (o.asset.delisted)
|
|
26
|
-
throw new HlRefusal('asset_delisted', o.asset.coin);
|
|
27
|
-
const s = checkSize(o.sz, o.asset.szDecimals);
|
|
28
|
-
const p = checkPrice(o.px, o.asset.szDecimals, o.asset.kind);
|
|
29
|
-
if (o.cloid !== undefined && !CLOID.test(o.cloid))
|
|
30
|
-
throw new HlRefusal('bad_cloid', o.cloid);
|
|
31
|
-
const w = { a: o.asset.asset, b: o.isBuy, p, s, r: o.reduceOnly ?? false, t: { limit: { tif } } };
|
|
32
|
-
if (o.cloid !== undefined)
|
|
33
|
-
w.c = o.cloid.toLowerCase();
|
|
34
|
-
return w;
|
|
35
|
-
}
|
|
36
|
-
export function buildOrder(o) {
|
|
37
|
-
return { type: 'order', orders: [orderWire(o)], grouping: 'na' };
|
|
38
|
-
}
|
|
39
|
-
/** A market order is an aggressive IOC limit (python `market_open` / `market_close`). */
|
|
40
|
-
export function buildMarketOrder(o) {
|
|
41
|
-
const px = marketPrice(o.mid, o.isBuy, o.slippage ?? 0.05, o.asset.szDecimals, o.asset.kind);
|
|
42
|
-
return buildOrder({ asset: o.asset, isBuy: o.isBuy, sz: o.sz, px, tif: 'Ioc', reduceOnly: o.reduceOnly, cloid: o.cloid });
|
|
43
|
-
}
|
|
44
|
-
/** A cancel needs only the asset INDEX; pass the AssetInfo from the table when you have it. */
|
|
45
|
-
export function buildCancel(o) {
|
|
46
|
-
const a = o.asset.asset;
|
|
47
|
-
if (!Number.isSafeInteger(a) || a < 0)
|
|
48
|
-
throw new HlRefusal('unknown_asset', String(a));
|
|
49
|
-
if (a >= BUILDER_DEX_OFFSET)
|
|
50
|
-
throw new HlRefusal('builder_dex_unsupported', String(a));
|
|
51
|
-
if (!Number.isSafeInteger(o.oid) || o.oid < 0)
|
|
52
|
-
throw new HlRefusal('bad_oid', String(o.oid));
|
|
53
|
-
return { type: 'cancel', cancels: [{ a, o: o.oid }] };
|
|
54
|
-
}
|
|
55
|
-
function checkNonce(n) {
|
|
56
|
-
if (!Number.isSafeInteger(n) || n <= 0)
|
|
57
|
-
throw new HlRefusal('nonce_required', String(n));
|
|
58
|
-
return n;
|
|
59
|
-
}
|
|
60
|
-
/** Move USDC between the spot and perps balances of the SAME account (toPerp: spot → perps). */
|
|
61
|
-
export function buildUsdClassTransfer(o) {
|
|
62
|
-
return { type: 'usdClassTransfer', amount: checkUsd(o.amount), toPerp: o.toPerp, nonce: checkNonce(o.nonce) };
|
|
63
|
-
}
|
|
64
|
-
/** Withdraw USDC from the PERPS balance to an address on Arbitrum. */
|
|
65
|
-
export function buildWithdraw3(o) {
|
|
66
|
-
if (!ADDRESS.test(o.destination))
|
|
67
|
-
throw new HlRefusal('bad_address', o.destination);
|
|
68
|
-
return { type: 'withdraw3', destination: o.destination.toLowerCase(), amount: checkUsd(o.amount), time: checkNonce(o.time) };
|
|
69
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid/eip712 — the EIP-712 digest, in pure keccak, for the flat struct types Hyperliquid
|
|
3
|
-
* signs (text/hyperliquid-plan.md § The signer seam). Only the field types Hyperliquid uses are
|
|
4
|
-
* encoded: string · bytes32 · address · bool · uint64 · uint256. Any other type is refused,
|
|
5
|
-
* never guessed — a wrong encoding is a signature over a different message.
|
|
6
|
-
*
|
|
7
|
-
* Only the DECLARED fields are encoded. A user-signed action also carries `type` and
|
|
8
|
-
* `signatureChainId`; those are on the wire, not in the struct, exactly as eth_account ignores them.
|
|
9
|
-
*/
|
|
10
|
-
export interface TypedField {
|
|
11
|
-
name: string;
|
|
12
|
-
type: 'string' | 'bytes32' | 'address' | 'bool' | 'uint64' | 'uint256';
|
|
13
|
-
}
|
|
14
|
-
export interface Eip712Domain {
|
|
15
|
-
name: string;
|
|
16
|
-
version: string;
|
|
17
|
-
chainId: number;
|
|
18
|
-
verifyingContract: `0x${string}`;
|
|
19
|
-
}
|
|
20
|
-
/** The full eth_signTypedData_v4 shape: `types` INCLUDES EIP712Domain, `primaryType` is named. */
|
|
21
|
-
export interface TypedData {
|
|
22
|
-
domain: Eip712Domain;
|
|
23
|
-
types: Record<string, TypedField[]>;
|
|
24
|
-
primaryType: string;
|
|
25
|
-
message: Record<string, unknown>;
|
|
26
|
-
}
|
|
27
|
-
export declare const EIP712_DOMAIN_FIELDS: TypedField[];
|
|
28
|
-
export declare const toHex: (b: Uint8Array) => string;
|
|
29
|
-
export declare const hex0x: (b: Uint8Array) => `0x${string}`;
|
|
30
|
-
export declare function hexToBytes(h: string): Uint8Array;
|
|
31
|
-
export declare const encodeType: (name: string, fields: TypedField[]) => string;
|
|
32
|
-
export declare function hashStruct(name: string, fields: TypedField[], message: Record<string, unknown>): Uint8Array;
|
|
33
|
-
export declare function typedDataDigest(td: TypedData): Uint8Array;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/eip712.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid/eip712 — the EIP-712 digest, in pure keccak, for the flat struct types Hyperliquid
|
|
4
|
-
* signs (text/hyperliquid-plan.md § The signer seam). Only the field types Hyperliquid uses are
|
|
5
|
-
* encoded: string · bytes32 · address · bool · uint64 · uint256. Any other type is refused,
|
|
6
|
-
* never guessed — a wrong encoding is a signature over a different message.
|
|
7
|
-
*
|
|
8
|
-
* Only the DECLARED fields are encoded. A user-signed action also carries `type` and
|
|
9
|
-
* `signatureChainId`; those are on the wire, not in the struct, exactly as eth_account ignores them.
|
|
10
|
-
*/
|
|
11
|
-
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
12
|
-
import { HlRefusal } from './errors.js';
|
|
13
|
-
export const EIP712_DOMAIN_FIELDS = [
|
|
14
|
-
{ name: 'name', type: 'string' },
|
|
15
|
-
{ name: 'version', type: 'string' },
|
|
16
|
-
{ name: 'chainId', type: 'uint256' },
|
|
17
|
-
{ name: 'verifyingContract', type: 'address' },
|
|
18
|
-
];
|
|
19
|
-
export const toHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('');
|
|
20
|
-
export const hex0x = (b) => `0x${toHex(b)}`;
|
|
21
|
-
export function hexToBytes(h) {
|
|
22
|
-
const s = h.startsWith('0x') ? h.slice(2) : h;
|
|
23
|
-
if (s.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(s))
|
|
24
|
-
throw new HlRefusal('bad_hex', h);
|
|
25
|
-
const out = new Uint8Array(s.length / 2);
|
|
26
|
-
for (let i = 0; i < out.length; i++)
|
|
27
|
-
out[i] = parseInt(s.slice(2 * i, 2 * i + 2), 16);
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
function word(n) {
|
|
31
|
-
if (n < 0n || n >= 1n << 256n)
|
|
32
|
-
throw new HlRefusal('eip712_range', String(n));
|
|
33
|
-
const out = new Uint8Array(32);
|
|
34
|
-
for (let i = 31; i >= 0; i--) {
|
|
35
|
-
out[i] = Number(n & 0xffn);
|
|
36
|
-
n >>= 8n;
|
|
37
|
-
}
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
40
|
-
function toUint(v, bits, at) {
|
|
41
|
-
let n;
|
|
42
|
-
if (typeof v === 'bigint')
|
|
43
|
-
n = v;
|
|
44
|
-
else if (typeof v === 'number' && Number.isSafeInteger(v))
|
|
45
|
-
n = BigInt(v);
|
|
46
|
-
else if (typeof v === 'string' && /^(0x[0-9a-fA-F]+|\d+)$/.test(v))
|
|
47
|
-
n = BigInt(v);
|
|
48
|
-
else
|
|
49
|
-
throw new HlRefusal('eip712_value', `${at} not a uint`);
|
|
50
|
-
if (n < 0n || n >= 1n << BigInt(bits))
|
|
51
|
-
throw new HlRefusal('eip712_range', at);
|
|
52
|
-
return n;
|
|
53
|
-
}
|
|
54
|
-
function encodeValue(f, v) {
|
|
55
|
-
switch (f.type) {
|
|
56
|
-
case 'string':
|
|
57
|
-
if (typeof v !== 'string')
|
|
58
|
-
throw new HlRefusal('eip712_value', `${f.name} not a string`);
|
|
59
|
-
return keccak_256(new TextEncoder().encode(v));
|
|
60
|
-
case 'bytes32': {
|
|
61
|
-
const b = v instanceof Uint8Array ? v : typeof v === 'string' ? hexToBytes(v) : null;
|
|
62
|
-
if (!b || b.length !== 32)
|
|
63
|
-
throw new HlRefusal('eip712_value', `${f.name} not bytes32`);
|
|
64
|
-
return b;
|
|
65
|
-
}
|
|
66
|
-
case 'address': {
|
|
67
|
-
if (typeof v !== 'string' || !/^0x[0-9a-fA-F]{40}$/.test(v))
|
|
68
|
-
throw new HlRefusal('eip712_value', `${f.name} not an address`);
|
|
69
|
-
return word(BigInt(v));
|
|
70
|
-
}
|
|
71
|
-
case 'bool':
|
|
72
|
-
if (typeof v !== 'boolean')
|
|
73
|
-
throw new HlRefusal('eip712_value', `${f.name} not a bool`);
|
|
74
|
-
return word(v ? 1n : 0n);
|
|
75
|
-
case 'uint64':
|
|
76
|
-
return word(toUint(v, 64, f.name));
|
|
77
|
-
case 'uint256':
|
|
78
|
-
return word(toUint(v, 256, f.name));
|
|
79
|
-
default:
|
|
80
|
-
throw new HlRefusal('eip712_type', String(f.type));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export const encodeType = (name, fields) => `${name}(${fields.map((f) => `${f.type} ${f.name}`).join(',')})`;
|
|
84
|
-
export function hashStruct(name, fields, message) {
|
|
85
|
-
const parts = [keccak_256(new TextEncoder().encode(encodeType(name, fields)))];
|
|
86
|
-
for (const f of fields) {
|
|
87
|
-
if (!(f.name in message))
|
|
88
|
-
throw new HlRefusal('eip712_missing', f.name);
|
|
89
|
-
parts.push(encodeValue(f, message[f.name]));
|
|
90
|
-
}
|
|
91
|
-
const buf = new Uint8Array(parts.length * 32);
|
|
92
|
-
parts.forEach((p, i) => buf.set(p, i * 32));
|
|
93
|
-
return keccak_256(buf);
|
|
94
|
-
}
|
|
95
|
-
export function typedDataDigest(td) {
|
|
96
|
-
const fields = td.types[td.primaryType];
|
|
97
|
-
if (!fields)
|
|
98
|
-
throw new HlRefusal('eip712_type', td.primaryType);
|
|
99
|
-
const domainSep = hashStruct('EIP712Domain', EIP712_DOMAIN_FIELDS, td.domain);
|
|
100
|
-
const body = hashStruct(td.primaryType, fields, td.message);
|
|
101
|
-
const buf = new Uint8Array(66);
|
|
102
|
-
buf[0] = 0x19;
|
|
103
|
-
buf[1] = 0x01;
|
|
104
|
-
buf.set(domainSep, 2);
|
|
105
|
-
buf.set(body, 34);
|
|
106
|
-
return keccak_256(buf);
|
|
107
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid/errors — every refusal in the core is a named code, thrown BEFORE any typed data
|
|
3
|
-
* exists or any signer is asked. Callers (CLI, page, receiver) catch `HlRefusal` and show the code.
|
|
4
|
-
*/
|
|
5
|
-
export type HlRefusalCode = 'bad_hex' | 'bad_address' | 'bad_decimal' | 'size_zero' | 'size_too_precise' | 'price_zero' | 'price_sig_figs' | 'price_too_precise' | 'amount_zero' | 'amount_too_precise' | 'bad_slippage' | 'bad_cloid' | 'bad_oid' | 'bad_tif' | 'unknown_asset' | 'asset_delisted' | 'asset_mismatch' | 'builder_dex_unsupported' | 'meta_required' | 'nonce_required' | 'nonce_mismatch' | 'vault_unsupported' | 'expires_unsupported' | 'unsupported_action' | 'signer_mismatch' | 'bad_signature' | 'eip712_type' | 'eip712_value' | 'eip712_range' | 'eip712_missing';
|
|
6
|
-
export declare class HlRefusal extends Error {
|
|
7
|
-
code: HlRefusalCode;
|
|
8
|
-
detail?: string | undefined;
|
|
9
|
-
constructor(code: HlRefusalCode, detail?: string | undefined);
|
|
10
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/errors.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid/errors — every refusal in the core is a named code, thrown BEFORE any typed data
|
|
4
|
-
* exists or any signer is asked. Callers (CLI, page, receiver) catch `HlRefusal` and show the code.
|
|
5
|
-
*/
|
|
6
|
-
export class HlRefusal extends Error {
|
|
7
|
-
code;
|
|
8
|
-
detail;
|
|
9
|
-
constructor(code, detail) {
|
|
10
|
-
super(detail ? `${code}: ${detail}` : code);
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.detail = detail;
|
|
13
|
-
this.name = 'HlRefusal';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid/exchange — the ONE function that POSTs to /exchange (text/hyperliquid-plan.md H7).
|
|
3
|
-
* It takes an already-signed request; it cannot sign and it never builds an action. The server
|
|
4
|
-
* never calls it (R19 / H8): it runs in the browser or the CLI, beside the key that signed.
|
|
5
|
-
*
|
|
6
|
-
* Hyperliquid answers 200 for refusals too: `{status:'err', response:'<reason>'}`, and an order's
|
|
7
|
-
* per-order `statuses[i].error`. Both come back `ok:false` with the exchange's own words.
|
|
8
|
-
*/
|
|
9
|
-
import type { HlNet } from './net.js';
|
|
10
|
-
import { type ExchangeRequest } from './signing.js';
|
|
11
|
-
export type ExchangeResult = {
|
|
12
|
-
ok: true;
|
|
13
|
-
response: unknown;
|
|
14
|
-
} | {
|
|
15
|
-
ok: false;
|
|
16
|
-
error: 'exchange_refused' | 'exchange_unavailable';
|
|
17
|
-
detail: string;
|
|
18
|
-
response?: unknown;
|
|
19
|
-
};
|
|
20
|
-
export declare function readExchangeAnswer(body: unknown): ExchangeResult;
|
|
21
|
-
export declare function postExchange(request: ExchangeRequest, net: HlNet, o?: {
|
|
22
|
-
fetchImpl?: typeof fetch;
|
|
23
|
-
timeoutMs?: number;
|
|
24
|
-
}): Promise<ExchangeResult>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/exchange.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid/exchange — the ONE function that POSTs to /exchange (text/hyperliquid-plan.md H7).
|
|
4
|
-
* It takes an already-signed request; it cannot sign and it never builds an action. The server
|
|
5
|
-
* never calls it (R19 / H8): it runs in the browser or the CLI, beside the key that signed.
|
|
6
|
-
*
|
|
7
|
-
* Hyperliquid answers 200 for refusals too: `{status:'err', response:'<reason>'}`, and an order's
|
|
8
|
-
* per-order `statuses[i].error`. Both come back `ok:false` with the exchange's own words.
|
|
9
|
-
*/
|
|
10
|
-
import { HL_EXCHANGE } from './signing.js';
|
|
11
|
-
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
12
|
-
export function readExchangeAnswer(body) {
|
|
13
|
-
if (!isObj(body))
|
|
14
|
-
return { ok: false, error: 'exchange_unavailable', detail: 'not json' };
|
|
15
|
-
if (body['status'] !== 'ok') {
|
|
16
|
-
return { ok: false, error: 'exchange_refused', detail: typeof body['response'] === 'string' ? body['response'] : 'err', response: body['response'] };
|
|
17
|
-
}
|
|
18
|
-
const resp = body['response'];
|
|
19
|
-
const statuses = isObj(resp) && isObj(resp['data']) && Array.isArray(resp['data']['statuses']) ? resp['data']['statuses'] : [];
|
|
20
|
-
const firstErr = statuses.find((s) => isObj(s) && typeof s['error'] === 'string');
|
|
21
|
-
if (firstErr)
|
|
22
|
-
return { ok: false, error: 'exchange_refused', detail: String(firstErr['error']), response: resp };
|
|
23
|
-
return { ok: true, response: resp };
|
|
24
|
-
}
|
|
25
|
-
export async function postExchange(request, net, o = {}) {
|
|
26
|
-
const f = o.fetchImpl ?? fetch;
|
|
27
|
-
try {
|
|
28
|
-
const res = await f(HL_EXCHANGE[net], {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
headers: { 'content-type': 'application/json' },
|
|
31
|
-
body: JSON.stringify(request),
|
|
32
|
-
signal: AbortSignal.timeout(o.timeoutMs ?? 10_000),
|
|
33
|
-
});
|
|
34
|
-
const text = await res.text();
|
|
35
|
-
let body;
|
|
36
|
-
try {
|
|
37
|
-
body = JSON.parse(text);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return { ok: false, error: 'exchange_unavailable', detail: `status_${res.status}: ${text.slice(0, 200)}` };
|
|
41
|
-
}
|
|
42
|
-
return readExchangeAnswer(body);
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
return { ok: false, error: 'exchange_unavailable', detail: e.message };
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid — the core the CLI and the browser both sign with (text/hyperliquid-plan.md).
|
|
3
|
-
* Pure except `meta.ts` reads and `exchange.ts` posts, both through a `fetchImpl` seam.
|
|
4
|
-
* No key material anywhere: a key is a `Signer` the caller brings.
|
|
5
|
-
*/
|
|
6
|
-
export * from './errors.js';
|
|
7
|
-
export * from './wire.js';
|
|
8
|
-
export * from './meta.js';
|
|
9
|
-
export * from './actions.js';
|
|
10
|
-
export * from './signing.js';
|
|
11
|
-
export * from './exchange.js';
|
|
12
|
-
export { packb } from './msgpack.js';
|
|
13
|
-
export { typedDataDigest, type TypedData, type TypedField, type Eip712Domain } from './eip712.js';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/index.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid — the core the CLI and the browser both sign with (text/hyperliquid-plan.md).
|
|
4
|
-
* Pure except `meta.ts` reads and `exchange.ts` posts, both through a `fetchImpl` seam.
|
|
5
|
-
* No key material anywhere: a key is a `Signer` the caller brings.
|
|
6
|
-
*/
|
|
7
|
-
export * from './errors.js';
|
|
8
|
-
export * from './wire.js';
|
|
9
|
-
export * from './meta.js';
|
|
10
|
-
export * from './actions.js';
|
|
11
|
-
export * from './signing.js';
|
|
12
|
-
export * from './exchange.js';
|
|
13
|
-
export { packb } from './msgpack.js';
|
|
14
|
-
export { typedDataDigest } from './eip712.js';
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid/meta — asset index, szDecimals and tick kind from `meta` (perps) and `spotMeta`
|
|
3
|
-
* (spot), and the keyless info reads behind them (text/hyperliquid-plan.md H5).
|
|
4
|
-
*
|
|
5
|
-
* Indexing, as the python SDK's Info.__init__ does it:
|
|
6
|
-
* perp asset = position in meta.universe (0 = BTC on mainnet)
|
|
7
|
-
* spot asset = 10000 + spotMeta.universe[i].index (the `index` FIELD, not the array position)
|
|
8
|
-
* spot szDecimals = the BASE token's szDecimals
|
|
9
|
-
* spot names = the pair's own name ("PURR/USDC", "@107") plus "BASE/QUOTE" as an alias
|
|
10
|
-
* Builder-deployed perp dexs (110000+) are not read here and are refused by index.
|
|
11
|
-
*
|
|
12
|
-
* Reads go through a `fetchImpl` seam and a failed read is `{ok:false}` — never an empty table.
|
|
13
|
-
*/
|
|
14
|
-
import { type HlNet } from './net.js';
|
|
15
|
-
import type { AssetKind } from './wire.js';
|
|
16
|
-
export interface AssetInfo {
|
|
17
|
-
/** The coin name orders and mids use: "BTC", "PURR/USDC", "@107". */
|
|
18
|
-
coin: string;
|
|
19
|
-
/** Human label: "BTC", "HYPE/USDC". */
|
|
20
|
-
label: string;
|
|
21
|
-
asset: number;
|
|
22
|
-
szDecimals: number;
|
|
23
|
-
kind: AssetKind;
|
|
24
|
-
delisted: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface AssetTable {
|
|
27
|
-
byName: Map<string, AssetInfo>;
|
|
28
|
-
byIndex: Map<number, AssetInfo>;
|
|
29
|
-
}
|
|
30
|
-
export declare const SPOT_OFFSET = 10000;
|
|
31
|
-
export declare const BUILDER_DEX_OFFSET = 110000;
|
|
32
|
-
export declare function buildAssetTable(meta: unknown, spotMeta: unknown): AssetTable;
|
|
33
|
-
/** "BTC" is the perp; spot bitcoin is "UBTC/USDC" (or its "@142" pair name). */
|
|
34
|
-
export declare function resolveCoin(table: AssetTable, coin: string): AssetInfo;
|
|
35
|
-
export declare function assetByIndex(table: AssetTable, asset: number): AssetInfo;
|
|
36
|
-
export type InfoRead<T> = {
|
|
37
|
-
ok: true;
|
|
38
|
-
data: T;
|
|
39
|
-
} | {
|
|
40
|
-
ok: false;
|
|
41
|
-
error: 'hyperliquid_unavailable';
|
|
42
|
-
detail: string;
|
|
43
|
-
};
|
|
44
|
-
export declare function readInfo<T = unknown>(body: Record<string, unknown>, net: HlNet, o?: {
|
|
45
|
-
fetchImpl?: typeof fetch;
|
|
46
|
-
timeoutMs?: number;
|
|
47
|
-
}): Promise<InfoRead<T>>;
|
|
48
|
-
/** meta + spotMeta in one go. Either read failing fails the table — half a table is not a table. */
|
|
49
|
-
export declare function readAssetTable(net: HlNet, o?: {
|
|
50
|
-
fetchImpl?: typeof fetch;
|
|
51
|
-
timeoutMs?: number;
|
|
52
|
-
}): Promise<InfoRead<AssetTable>>;
|
|
53
|
-
/** Mid prices by coin name. A coin absent from the answer is absent here — never 0. */
|
|
54
|
-
export declare function readMids(net: HlNet, o?: {
|
|
55
|
-
fetchImpl?: typeof fetch;
|
|
56
|
-
timeoutMs?: number;
|
|
57
|
-
}): Promise<InfoRead<Record<string, string>>>;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
// VENDORED from one.ie/web/src/lib/hyperliquid/meta.ts by packages/cli/scripts/hl-core-vendor.mjs — do not edit; tests/hl-core-parity.test.ts compares bytes.
|
|
2
|
-
/**
|
|
3
|
-
* hyperliquid/meta — asset index, szDecimals and tick kind from `meta` (perps) and `spotMeta`
|
|
4
|
-
* (spot), and the keyless info reads behind them (text/hyperliquid-plan.md H5).
|
|
5
|
-
*
|
|
6
|
-
* Indexing, as the python SDK's Info.__init__ does it:
|
|
7
|
-
* perp asset = position in meta.universe (0 = BTC on mainnet)
|
|
8
|
-
* spot asset = 10000 + spotMeta.universe[i].index (the `index` FIELD, not the array position)
|
|
9
|
-
* spot szDecimals = the BASE token's szDecimals
|
|
10
|
-
* spot names = the pair's own name ("PURR/USDC", "@107") plus "BASE/QUOTE" as an alias
|
|
11
|
-
* Builder-deployed perp dexs (110000+) are not read here and are refused by index.
|
|
12
|
-
*
|
|
13
|
-
* Reads go through a `fetchImpl` seam and a failed read is `{ok:false}` — never an empty table.
|
|
14
|
-
*/
|
|
15
|
-
import { HL_INFO } from './net.js';
|
|
16
|
-
import { HlRefusal } from './errors.js';
|
|
17
|
-
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
18
|
-
export const SPOT_OFFSET = 10_000;
|
|
19
|
-
export const BUILDER_DEX_OFFSET = 110_000;
|
|
20
|
-
export function buildAssetTable(meta, spotMeta) {
|
|
21
|
-
const byName = new Map();
|
|
22
|
-
const byIndex = new Map();
|
|
23
|
-
const add = (a, ...names) => {
|
|
24
|
-
byIndex.set(a.asset, a);
|
|
25
|
-
for (const n of names)
|
|
26
|
-
if (!byName.has(n))
|
|
27
|
-
byName.set(n, a);
|
|
28
|
-
};
|
|
29
|
-
// Perps first: a perp name wins over any spot alias spelled the same.
|
|
30
|
-
const m = isObj(meta) ? meta : {};
|
|
31
|
-
const universe = Array.isArray(m['universe']) ? m['universe'] : [];
|
|
32
|
-
universe.forEach((p, i) => {
|
|
33
|
-
if (!isObj(p) || typeof p['name'] !== 'string' || typeof p['szDecimals'] !== 'number')
|
|
34
|
-
return;
|
|
35
|
-
add({ coin: p['name'], label: p['name'], asset: i, szDecimals: p['szDecimals'], kind: 'perp', delisted: p['isDelisted'] === true }, p['name']);
|
|
36
|
-
});
|
|
37
|
-
const sm = isObj(spotMeta) ? spotMeta : {};
|
|
38
|
-
const tokens = new Map();
|
|
39
|
-
for (const t of Array.isArray(sm['tokens']) ? sm['tokens'] : []) {
|
|
40
|
-
if (isObj(t) && typeof t['index'] === 'number')
|
|
41
|
-
tokens.set(t['index'], t);
|
|
42
|
-
}
|
|
43
|
-
for (const u of Array.isArray(sm['universe']) ? sm['universe'] : []) {
|
|
44
|
-
if (!isObj(u) || typeof u['index'] !== 'number' || typeof u['name'] !== 'string' || !Array.isArray(u['tokens']))
|
|
45
|
-
continue;
|
|
46
|
-
const [b, q] = u['tokens'];
|
|
47
|
-
const base = tokens.get(b);
|
|
48
|
-
const quote = tokens.get(q);
|
|
49
|
-
if (!base || typeof base['szDecimals'] !== 'number')
|
|
50
|
-
continue;
|
|
51
|
-
const label = `${String(base['name'])}/${String(quote?.['name'] ?? '?')}`;
|
|
52
|
-
add({ coin: u['name'], label, asset: SPOT_OFFSET + u['index'], szDecimals: base['szDecimals'], kind: 'spot', delisted: false }, u['name'], label);
|
|
53
|
-
}
|
|
54
|
-
return { byName, byIndex };
|
|
55
|
-
}
|
|
56
|
-
/** "BTC" is the perp; spot bitcoin is "UBTC/USDC" (or its "@142" pair name). */
|
|
57
|
-
export function resolveCoin(table, coin) {
|
|
58
|
-
const hit = table.byName.get(coin);
|
|
59
|
-
if (!hit)
|
|
60
|
-
throw new HlRefusal('unknown_asset', coin);
|
|
61
|
-
if (hit.delisted)
|
|
62
|
-
throw new HlRefusal('asset_delisted', coin);
|
|
63
|
-
return hit;
|
|
64
|
-
}
|
|
65
|
-
export function assetByIndex(table, asset) {
|
|
66
|
-
if (asset >= BUILDER_DEX_OFFSET)
|
|
67
|
-
throw new HlRefusal('builder_dex_unsupported', String(asset));
|
|
68
|
-
const hit = table.byIndex.get(asset);
|
|
69
|
-
if (!hit)
|
|
70
|
-
throw new HlRefusal('unknown_asset', String(asset));
|
|
71
|
-
return hit;
|
|
72
|
-
}
|
|
73
|
-
export async function readInfo(body, net, o = {}) {
|
|
74
|
-
const f = o.fetchImpl ?? fetch;
|
|
75
|
-
try {
|
|
76
|
-
const res = await f(HL_INFO[net], {
|
|
77
|
-
method: 'POST',
|
|
78
|
-
headers: { 'content-type': 'application/json' },
|
|
79
|
-
body: JSON.stringify(body),
|
|
80
|
-
signal: AbortSignal.timeout(o.timeoutMs ?? 5000),
|
|
81
|
-
});
|
|
82
|
-
if (!res.ok)
|
|
83
|
-
return { ok: false, error: 'hyperliquid_unavailable', detail: `status_${res.status}` };
|
|
84
|
-
return { ok: true, data: (await res.json()) };
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
return { ok: false, error: 'hyperliquid_unavailable', detail: e.message };
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/** meta + spotMeta in one go. Either read failing fails the table — half a table is not a table. */
|
|
91
|
-
export async function readAssetTable(net, o = {}) {
|
|
92
|
-
const [meta, spot] = await Promise.all([readInfo({ type: 'meta' }, net, o), readInfo({ type: 'spotMeta' }, net, o)]);
|
|
93
|
-
if (!meta.ok)
|
|
94
|
-
return meta;
|
|
95
|
-
if (!spot.ok)
|
|
96
|
-
return spot;
|
|
97
|
-
return { ok: true, data: buildAssetTable(meta.data, spot.data) };
|
|
98
|
-
}
|
|
99
|
-
/** Mid prices by coin name. A coin absent from the answer is absent here — never 0. */
|
|
100
|
-
export async function readMids(net, o = {}) {
|
|
101
|
-
const r = await readInfo({ type: 'allMids' }, net, o);
|
|
102
|
-
if (!r.ok)
|
|
103
|
-
return r;
|
|
104
|
-
const out = {};
|
|
105
|
-
if (isObj(r.data))
|
|
106
|
-
for (const [k, v] of Object.entries(r.data))
|
|
107
|
-
if (typeof v === 'string' && /^\d+(\.\d+)?$/.test(v))
|
|
108
|
-
out[k] = v;
|
|
109
|
-
return { ok: true, data: out };
|
|
110
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hyperliquid/msgpack — the exact msgpack bytes Hyperliquid hashes for an L1 action
|
|
3
|
-
* (text/hyperliquid-plan.md § The hash). A port of what python `msgpack.packb(action)` emits
|
|
4
|
-
* for the shapes an action can hold, and nothing else:
|
|
5
|
-
*
|
|
6
|
-
* null → nil · boolean → c2/c3 · integer → smallest fixint/uint/int · string → fixstr/str8/16/32
|
|
7
|
-
* array → fixarray/array16/32 · plain object → fixmap/map16/32, keys in INSERTION order
|
|
8
|
-
*
|
|
9
|
-
* A JS float is REFUSED (`msgpack_float`): Hyperliquid's wire carries prices and sizes as decimal
|
|
10
|
-
* strings, so a float here means a builder bug — and python would emit float64, a different hash.
|
|
11
|
-
* `undefined` is refused too: python never sees it, so silently dropping a key would hash a
|
|
12
|
-
* different action than the one the caller thinks it built.
|
|
13
|
-
*/
|
|
14
|
-
export declare class MsgpackError extends Error {
|
|
15
|
-
code: 'msgpack_float' | 'msgpack_undefined' | 'msgpack_type' | 'msgpack_int_range';
|
|
16
|
-
constructor(code: 'msgpack_float' | 'msgpack_undefined' | 'msgpack_type' | 'msgpack_int_range', detail: string);
|
|
17
|
-
}
|
|
18
|
-
export declare function packb(value: unknown): Uint8Array;
|