perp-cli 0.12.17 → 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 +247 -27
- package/dist/_stderr-filter.js +0 -1
- package/dist/agent-wallet/lighter-keystore.d.ts +11 -0
- package/dist/agent-wallet/lighter-keystore.js +92 -10
- package/dist/agent-wallet/passphrase.d.ts +1 -1
- package/dist/agent-wallet/passphrase.js +16 -3
- package/dist/agent-wallet/store.d.ts +37 -4
- package/dist/agent-wallet/store.js +132 -0
- package/dist/agent-wallet/venue-keystore.d.ts +14 -0
- package/dist/agent-wallet/venue-keystore.js +121 -0
- package/dist/api/public/hyperliquid.js +4 -4
- package/dist/api/public/lighter.js +5 -5
- package/dist/api/public/pacifica.d.ts +0 -1
- package/dist/api/public/pacifica.js +4 -13
- package/dist/api/public/urls.d.ts +9 -1
- package/dist/api/public/urls.js +35 -13
- package/dist/arb/file-lock.d.ts +11 -0
- package/dist/arb/file-lock.js +74 -0
- package/dist/arb/index.d.ts +2 -2
- package/dist/arb/index.js +2 -2
- package/dist/arb/pending-entry.d.ts +32 -0
- package/dist/arb/pending-entry.js +77 -0
- package/dist/arb/sizing.d.ts +6 -13
- package/dist/arb/sizing.js +12 -51
- package/dist/arb/state.d.ts +45 -12
- package/dist/arb/state.js +214 -42
- package/dist/arb/utils.d.ts +20 -6
- package/dist/arb/utils.js +43 -39
- package/dist/bot/conditions.d.ts +4 -4
- package/dist/bot/conditions.js +11 -6
- package/dist/bot/config.d.ts +17 -1
- package/dist/bot/config.js +48 -12
- package/dist/bot/engine.d.ts +61 -2
- package/dist/bot/engine.js +610 -144
- package/dist/bot/fill-size.d.ts +7 -0
- package/dist/bot/fill-size.js +18 -0
- package/dist/bot/index.d.ts +1 -1
- package/dist/bot/index.js +1 -1
- package/dist/bot/perp-order.d.ts +99 -0
- package/dist/bot/perp-order.js +299 -0
- package/dist/bot/presets.d.ts +7 -0
- package/dist/bot/presets.js +17 -0
- package/dist/bot/quarantine.d.ts +75 -0
- package/dist/bot/quarantine.js +190 -0
- package/dist/bot/quote-rules.d.ts +23 -0
- package/dist/bot/quote-rules.js +69 -0
- package/dist/bot/strategies/avellaneda-mm.d.ts +32 -2
- package/dist/bot/strategies/avellaneda-mm.js +72 -70
- package/dist/bot/strategies/basis-arb.js +2 -0
- package/dist/bot/strategies/dca-strategy.d.ts +2 -0
- package/dist/bot/strategies/dca-strategy.js +5 -0
- package/dist/bot/strategies/funding-arb-strategy.d.ts +43 -3
- package/dist/bot/strategies/funding-arb-strategy.js +571 -380
- package/dist/bot/strategies/funding-arb-utils.d.ts +48 -23
- package/dist/bot/strategies/funding-arb-utils.js +159 -195
- package/dist/bot/strategies/funding-arb-v2.d.ts +32 -0
- package/dist/bot/strategies/funding-arb-v2.js +258 -47
- package/dist/bot/strategies/funding-auto.js +215 -194
- package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +14 -0
- package/dist/bot/strategies/spot-perp-arb-strategy.js +217 -50
- package/dist/bot/strategies/spot-perp-executor.d.ts +73 -19
- package/dist/bot/strategies/spot-perp-executor.js +319 -120
- package/dist/bot/strategies/spot-perp-state.d.ts +43 -0
- package/dist/bot/strategies/spot-perp-state.js +70 -0
- package/dist/bot/strategy-types.d.ts +6 -0
- package/dist/bot/tui/BotDashboard.d.ts +7 -2
- package/dist/bot/tui/BotDashboard.js +6 -3
- package/dist/bridge-engine.d.ts +120 -19
- package/dist/bridge-engine.js +710 -422
- package/dist/bridge-signers.d.ts +54 -0
- package/dist/bridge-signers.js +161 -0
- package/dist/cache.d.ts +4 -1
- package/dist/cache.js +11 -0
- package/dist/cli-flags.d.ts +50 -0
- package/dist/cli-flags.js +104 -0
- package/dist/cli-program.d.ts +35 -0
- package/dist/cli-program.js +286 -0
- package/dist/cli-spec.js +1 -1
- package/dist/client-id-tracker.js +11 -2
- package/dist/commands/account.d.ts +7 -1
- package/dist/commands/account.js +70 -92
- package/dist/commands/agent-import.d.ts +114 -0
- package/dist/commands/agent-import.js +794 -0
- package/dist/commands/agent.d.ts +232 -2
- package/dist/commands/agent.js +1858 -955
- package/dist/commands/alerts.d.ts +1 -0
- package/dist/commands/alerts.js +31 -28
- package/dist/commands/arb/index.d.ts +60 -1
- package/dist/commands/arb/index.js +381 -384
- package/dist/commands/arb-auto.d.ts +132 -4
- package/dist/commands/arb-auto.js +1474 -967
- package/dist/commands/arb.d.ts +3 -1
- package/dist/commands/arb.js +62 -30
- package/dist/commands/bot.js +127 -47
- package/dist/commands/bridge.d.ts +2 -1
- package/dist/commands/bridge.js +339 -192
- package/dist/commands/builder.d.ts +55 -0
- package/dist/commands/builder.js +387 -0
- package/dist/commands/funds-onchain.d.ts +32 -0
- package/dist/commands/funds-onchain.js +286 -0
- package/dist/commands/funds.d.ts +25 -0
- package/dist/commands/funds.js +939 -245
- package/dist/commands/history.js +72 -45
- package/dist/commands/init.d.ts +107 -15
- package/dist/commands/init.js +1116 -249
- package/dist/commands/jobs.d.ts +2 -1
- package/dist/commands/jobs.js +77 -15
- package/dist/commands/manage.js +136 -91
- package/dist/commands/market.d.ts +4 -1
- package/dist/commands/market.js +35 -32
- package/dist/commands/outcome.d.ts +10 -0
- package/dist/commands/outcome.js +396 -0
- package/dist/commands/plan.js +52 -12
- package/dist/commands/portfolio.d.ts +1 -0
- package/dist/commands/portfolio.js +60 -72
- package/dist/commands/rebalance.d.ts +2 -1
- package/dist/commands/rebalance.js +33 -43
- package/dist/commands/risk.js +46 -19
- package/dist/commands/settings.d.ts +1 -0
- package/dist/commands/settings.js +246 -51
- package/dist/commands/trade.d.ts +50 -0
- package/dist/commands/trade.js +1943 -695
- package/dist/commands/wallet.d.ts +30 -1
- package/dist/commands/wallet.js +316 -337
- package/dist/config.d.ts +60 -9
- package/dist/config.js +252 -82
- package/dist/constants.d.ts +29 -4
- package/dist/constants.js +62 -20
- package/dist/dashboard/server.d.ts +2 -0
- package/dist/dashboard/server.js +9 -6
- package/dist/dashboard/ui.js +6 -4
- package/dist/dashboard/ws-feeds.js +20 -8
- package/dist/dex-asset-map.js +5 -3
- package/dist/errors.d.ts +122 -0
- package/dist/errors.js +194 -0
- package/dist/event-stream.js +75 -19
- package/dist/evm-master-tx.d.ts +59 -0
- package/dist/evm-master-tx.js +154 -0
- package/dist/exchanges/adapter-network.d.ts +10 -0
- package/dist/exchanges/adapter-network.js +10 -0
- package/dist/exchanges/arcus/adapter.d.ts +196 -0
- package/dist/exchanges/arcus/adapter.js +1092 -0
- package/dist/exchanges/arcus/agent.d.ts +55 -0
- package/dist/exchanges/arcus/agent.js +188 -0
- package/dist/exchanges/arcus/client.d.ts +63 -0
- package/dist/exchanges/arcus/client.js +285 -0
- package/dist/exchanges/arcus/public.d.ts +65 -0
- package/dist/exchanges/arcus/public.js +138 -0
- package/dist/exchanges/arcus/signing.d.ts +176 -0
- package/dist/exchanges/arcus/signing.js +288 -0
- package/dist/exchanges/arcus/spot-chain.d.ts +60 -0
- package/dist/exchanges/arcus/spot-chain.js +241 -0
- package/dist/exchanges/arcus/spot-router.d.ts +177 -0
- package/dist/exchanges/arcus/spot-router.js +183 -0
- package/dist/exchanges/arcus/spot.d.ts +109 -0
- package/dist/exchanges/arcus/spot.js +645 -0
- package/dist/exchanges/aster-funds.d.ts +127 -0
- package/dist/exchanges/aster-funds.js +252 -0
- package/dist/exchanges/aster-nonce.d.ts +2 -0
- package/dist/exchanges/aster-nonce.js +107 -0
- package/dist/exchanges/aster-spot.d.ts +117 -0
- package/dist/exchanges/aster-spot.js +686 -0
- package/dist/exchanges/aster-typed-data.d.ts +133 -7
- package/dist/exchanges/aster-typed-data.js +121 -7
- package/dist/exchanges/aster.d.ts +219 -6
- package/dist/exchanges/aster.js +1023 -153
- package/dist/exchanges/builder-fee.d.ts +254 -0
- package/dist/exchanges/builder-fee.js +421 -0
- package/dist/exchanges/canonical-symbols.d.ts +32 -0
- package/dist/exchanges/canonical-symbols.js +96 -0
- package/dist/exchanges/capabilities.d.ts +7 -1
- package/dist/exchanges/capabilities.js +7 -0
- package/dist/exchanges/hl-signing.d.ts +165 -0
- package/dist/exchanges/hl-signing.js +158 -0
- package/dist/exchanges/hyperliquid-outcome.d.ts +211 -0
- package/dist/exchanges/hyperliquid-outcome.js +646 -0
- package/dist/exchanges/hyperliquid-spot.d.ts +44 -5
- package/dist/exchanges/hyperliquid-spot.js +308 -117
- package/dist/exchanges/hyperliquid.d.ts +462 -57
- package/dist/exchanges/hyperliquid.js +1575 -449
- package/dist/exchanges/index.d.ts +6 -0
- package/dist/exchanges/index.js +4 -0
- package/dist/exchanges/interface.d.ts +63 -10
- package/dist/exchanges/interface.js +18 -3
- package/dist/exchanges/ioc-outcome.d.ts +44 -0
- package/dist/exchanges/ioc-outcome.js +57 -0
- package/dist/exchanges/legacy-trading-v2.d.ts +39 -0
- package/dist/exchanges/legacy-trading-v2.js +940 -0
- package/dist/exchanges/lighter-public.d.ts +43 -0
- package/dist/exchanges/lighter-public.js +276 -0
- package/dist/exchanges/lighter-rh-deposit.d.ts +62 -0
- package/dist/exchanges/lighter-rh-deposit.js +185 -0
- package/dist/exchanges/lighter-signer.d.ts +123 -0
- package/dist/exchanges/lighter-signer.js +215 -0
- package/dist/exchanges/lighter-spot.d.ts +91 -13
- package/dist/exchanges/lighter-spot.js +595 -233
- package/dist/exchanges/lighter.d.ts +611 -39
- package/dist/exchanges/lighter.js +1890 -649
- package/dist/exchanges/ondo/adapter.d.ts +166 -0
- package/dist/exchanges/ondo/adapter.js +835 -0
- package/dist/exchanges/ondo/agent.d.ts +31 -0
- package/dist/exchanges/ondo/agent.js +101 -0
- package/dist/exchanges/ondo/client.d.ts +60 -0
- package/dist/exchanges/ondo/client.js +297 -0
- package/dist/exchanges/ondo/funds.d.ts +122 -0
- package/dist/exchanges/ondo/funds.js +290 -0
- package/dist/exchanges/ondo/public.d.ts +95 -0
- package/dist/exchanges/ondo/public.js +214 -0
- package/dist/exchanges/ondo/spot.d.ts +127 -0
- package/dist/exchanges/ondo/spot.js +392 -0
- package/dist/exchanges/outcome-interface.d.ts +140 -0
- package/dist/exchanges/outcome-interface.js +16 -0
- package/dist/exchanges/pacifica-spot.d.ts +83 -0
- package/dist/exchanges/pacifica-spot.js +324 -0
- package/dist/exchanges/pacifica-typed-data.d.ts +30 -13
- package/dist/exchanges/pacifica-typed-data.js +57 -9
- package/dist/exchanges/pacifica.d.ts +288 -4
- package/dist/exchanges/pacifica.js +1013 -76
- package/dist/exchanges/precision.d.ts +47 -0
- package/dist/exchanges/precision.js +209 -0
- package/dist/exchanges/qfex/adapter.d.ts +341 -0
- package/dist/exchanges/qfex/adapter.js +1383 -0
- package/dist/exchanges/qfex/agent.d.ts +58 -0
- package/dist/exchanges/qfex/agent.js +188 -0
- package/dist/exchanges/qfex/client.d.ts +54 -0
- package/dist/exchanges/qfex/client.js +138 -0
- package/dist/exchanges/qfex/errors.d.ts +70 -0
- package/dist/exchanges/qfex/errors.js +236 -0
- package/dist/exchanges/qfex/public.d.ts +122 -0
- package/dist/exchanges/qfex/public.js +268 -0
- package/dist/exchanges/qfex/signing.d.ts +160 -0
- package/dist/exchanges/qfex/signing.js +283 -0
- package/dist/exchanges/qfex/ws-transport.d.ts +294 -0
- package/dist/exchanges/qfex/ws-transport.js +798 -0
- package/dist/exchanges/rate-limiter.d.ts +12 -0
- package/dist/exchanges/rate-limiter.js +64 -0
- package/dist/exchanges/registry.d.ts +14 -2
- package/dist/exchanges/registry.js +20 -32
- package/dist/exchanges/slippage.d.ts +37 -0
- package/dist/exchanges/slippage.js +70 -0
- package/dist/exchanges/spot-factory.d.ts +166 -0
- package/dist/exchanges/spot-factory.js +431 -0
- package/dist/exchanges/spot-interface.d.ts +98 -4
- package/dist/exchanges/spot-interface.js +27 -1
- package/dist/exchanges/spot-result.d.ts +79 -0
- package/dist/exchanges/spot-result.js +273 -0
- package/dist/exchanges/trading-v2.d.ts +117 -0
- package/dist/exchanges/trading-v2.js +301 -0
- package/dist/exchanges/venue-types.d.ts +231 -0
- package/dist/exchanges/venue-types.js +87 -0
- package/dist/exchanges/venue.d.ts +211 -0
- package/dist/exchanges/venue.js +132 -0
- package/dist/exchanges/venues/arcus.d.ts +8 -0
- package/dist/exchanges/venues/arcus.js +109 -0
- package/dist/exchanges/venues/aster.d.ts +49 -0
- package/dist/exchanges/venues/aster.js +176 -0
- package/dist/exchanges/venues/create-helpers.d.ts +18 -0
- package/dist/exchanges/venues/create-helpers.js +199 -0
- package/dist/exchanges/venues/hyperliquid.d.ts +23 -0
- package/dist/exchanges/venues/hyperliquid.js +126 -0
- package/dist/exchanges/venues/index.d.ts +16 -0
- package/dist/exchanges/venues/index.js +26 -0
- package/dist/exchanges/venues/lighter-family.d.ts +92 -0
- package/dist/exchanges/venues/lighter-family.js +166 -0
- package/dist/exchanges/venues/lighter-rh.d.ts +7 -0
- package/dist/exchanges/venues/lighter-rh.js +58 -0
- package/dist/exchanges/venues/lighter.d.ts +6 -0
- package/dist/exchanges/venues/lighter.js +55 -0
- package/dist/exchanges/venues/ondo.d.ts +34 -0
- package/dist/exchanges/venues/ondo.js +140 -0
- package/dist/exchanges/venues/pacifica.d.ts +8 -0
- package/dist/exchanges/venues/pacifica.js +95 -0
- package/dist/exchanges/venues/qfex.d.ts +28 -0
- package/dist/exchanges/venues/qfex.js +132 -0
- package/dist/execution-log.js +10 -2
- package/dist/funding/legacy-public.d.ts +31 -0
- package/dist/funding/legacy-public.js +369 -0
- package/dist/funding/normalize.d.ts +28 -16
- package/dist/funding/normalize.js +61 -29
- package/dist/funding/rates.d.ts +46 -11
- package/dist/funding/rates.js +228 -277
- package/dist/guardrail/perp-guardrail.js +0 -0
- package/dist/index.js +156 -684
- package/dist/jobs.d.ts +84 -6
- package/dist/jobs.js +239 -41
- package/dist/landing.d.ts +7 -2
- package/dist/landing.js +19 -3
- package/dist/mcp-server.d.ts +14 -4
- package/dist/mcp-server.js +820 -402
- package/dist/mcp-trade-guard.d.ts +16 -0
- package/dist/mcp-trade-guard.js +59 -0
- package/dist/pacifica/client.d.ts +41 -10
- package/dist/pacifica/client.js +167 -63
- package/dist/pacifica/constants.d.ts +0 -1
- package/dist/pacifica/constants.js +0 -5
- package/dist/pacifica/deposit.d.ts +30 -3
- package/dist/pacifica/deposit.js +119 -2
- package/dist/pacifica/faucet.d.ts +29 -0
- package/dist/pacifica/faucet.js +100 -0
- package/dist/pacifica/sign-tx.d.ts +15 -0
- package/dist/pacifica/sign-tx.js +41 -0
- package/dist/pacifica/types/account.d.ts +28 -4
- package/dist/pacifica/types/lake.d.ts +20 -5
- package/dist/pacifica/types/lake.js +4 -0
- package/dist/pacifica/types/market.d.ts +5 -0
- package/dist/pacifica/types/order.d.ts +4 -1
- package/dist/pacifica/types/position.d.ts +9 -1
- package/dist/plan-executor.d.ts +10 -5
- package/dist/plan-executor.js +165 -54
- package/dist/position-history.js +13 -0
- package/dist/rebalance.d.ts +26 -2
- package/dist/rebalance.js +86 -7
- package/dist/relay-swap.d.ts +232 -0
- package/dist/relay-swap.js +630 -0
- package/dist/risk.js +5 -1
- package/dist/secret-env.d.ts +15 -0
- package/dist/secret-env.js +36 -0
- package/dist/settings.d.ts +169 -6
- package/dist/settings.js +219 -38
- package/dist/signer/ows-evm.d.ts +13 -0
- package/dist/signer/ows-evm.js +22 -0
- package/dist/smart-order.d.ts +9 -0
- package/dist/smart-order.js +53 -8
- package/dist/strategies/dca.d.ts +6 -2
- package/dist/strategies/dca.js +66 -26
- package/dist/strategies/funding-arb.d.ts +11 -1
- package/dist/strategies/funding-arb.js +202 -89
- package/dist/strategies/grid.d.ts +31 -0
- package/dist/strategies/grid.js +89 -11
- package/dist/strategies/pending-stop.d.ts +8 -0
- package/dist/strategies/pending-stop.js +12 -0
- package/dist/strategies/split-order.d.ts +45 -17
- package/dist/strategies/split-order.js +157 -91
- package/dist/strategies/trailing-stop.d.ts +2 -1
- package/dist/strategies/trailing-stop.js +52 -6
- package/dist/strategies/twap.d.ts +6 -1
- package/dist/strategies/twap.js +39 -11
- package/dist/trade-validator.d.ts +22 -0
- package/dist/trade-validator.js +119 -15
- package/dist/utils/numeric.d.ts +46 -0
- package/dist/utils/numeric.js +79 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +96 -19
- package/dist/withdraw-gate.d.ts +49 -0
- package/dist/withdraw-gate.js +131 -0
- package/package.json +15 -6
- package/skills/perp-cli/SKILL.md +142 -55
- package/skills/perp-cli/references/agent-operations.md +110 -56
- package/skills/perp-cli/references/commands.md +266 -71
- package/skills/perp-cli/references/strategies.md +34 -31
- package/skills/perp-cli/scripts/arb-monitor.sh +10 -5
- package/skills/perp-cli/scripts/funding-analysis.sh +14 -9
- package/skills/perp-cli/scripts/preflight.sh +21 -14
- package/skills/perp-cli/scripts/spot-perp-scan.sh +12 -7
- package/skills/perp-cli/scripts/validate-arb.sh +31 -15
- package/vendor/lighter-signer/SHA256SUMS +2 -0
- package/vendor/lighter-signer/VERSION +8 -0
- package/vendor/lighter-signer/lighter-signer.wasm +0 -0
- package/vendor/lighter-signer/wasm_exec.js +575 -0
- package/dist/bot/strategies/funding-arb-v2-strategy.d.ts +0 -42
- package/dist/bot/strategies/funding-arb-v2-strategy.js +0 -864
|
@@ -1,20 +1,183 @@
|
|
|
1
|
-
import { Hyperliquid } from "hyperliquid";
|
|
2
1
|
import type { ExchangeAdapter, ExchangeMarketInfo, ExchangePosition, ExchangeOrder, ExchangeBalance, ExchangeTrade, ExchangeFundingPayment, ExchangeKline } from "./interface.js";
|
|
2
|
+
import type { ResolvedSlippage } from "./slippage.js";
|
|
3
3
|
import type { EvmSigner } from "../signer/index.js";
|
|
4
4
|
import type { AgentMeta } from "../settings.js";
|
|
5
|
+
import { type BuilderApproval, type BuilderDecision, type BuilderFeeGate, type BuilderTarget } from "./builder-fee.js";
|
|
6
|
+
/** HL native time-in-force values. */
|
|
7
|
+
export type HlTif = "Gtc" | "Ioc" | "Alo";
|
|
8
|
+
/**
|
|
9
|
+
* Map a TIF input to HL's native value (design §13.3). Accepts the common names
|
|
10
|
+
* GTC/IOC/ALO and the native spellings case-insensitively. FOK is not offered by
|
|
11
|
+
* HL (no FOK emulation, §13.3) → CAPABILITY_UNSUPPORTED; anything else likewise.
|
|
12
|
+
*/
|
|
13
|
+
export declare function hlTif(raw: string): HlTif;
|
|
14
|
+
/** HL lot step implied by szDecimals ("1" for 0, "0.001" for 3) — sizes are floored to it (floorSize). */
|
|
15
|
+
export declare function hlSizeStep(szDecimals: number): string;
|
|
16
|
+
/**
|
|
17
|
+
* Slippage-bounded IOC protection price (design §13.2, §13.10 #5).
|
|
18
|
+
*
|
|
19
|
+
* `reference` × (1 ± bps/10000), then aligned TOWARD CROSSING (buy → up, sell →
|
|
20
|
+
* down) on HL's price grid: at most 5 significant figures and at most
|
|
21
|
+
* `maxDecimals − szDecimals` decimals (maxDecimals 6 perps / 8 spot); integer
|
|
22
|
+
* prices are always valid. The returned `appliedBps` is the bound actually sent
|
|
23
|
+
* (after rounding) relative to the reference — it can exceed the requested bps
|
|
24
|
+
* by up to one grid step because alignment never narrows the bound toward
|
|
25
|
+
* not-crossing.
|
|
26
|
+
*/
|
|
27
|
+
export declare function hlProtectionPrice(reference: number, side: "buy" | "sell", bps: number, szDecimals: number, maxDecimals: 6 | 8): {
|
|
28
|
+
protectionPrice: string;
|
|
29
|
+
appliedBps: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A USER-SUPPLIED limit / trigger / modify price checked against HL's price grid (design §10.10:
|
|
33
|
+
* an off-grid limit price is refused, never rounded — rounding to nearest can move a buy price UP).
|
|
34
|
+
* HL docs (trading/tick-and-lot-size): "Prices can have up to 5 significant figures, but no more
|
|
35
|
+
* than MAX_DECIMALS - szDecimals decimal places where MAX_DECIMALS is 6 for perps and 8 for spot.
|
|
36
|
+
* Integer prices are always allowed, regardless of the number of significant figures."
|
|
37
|
+
* Non-numeric / non-positive → INVALID_PARAMS; off-grid → INVALID_TICK (with the nearest on-grid
|
|
38
|
+
* prices below / above). Returns the price normalized (no leading / trailing zeros). Computed
|
|
39
|
+
* prices (protection, market-trigger `p`) are aligned with hlProtectionPrice instead.
|
|
40
|
+
*/
|
|
41
|
+
export declare function hlRequirePriceOnGrid(price: string, szDecimals: number, maxDecimals: 6 | 8, what: string): string;
|
|
42
|
+
/** CCTP destinations for Hyperliquid withdrawals (Circle CCTP domain ids: Ethereum 0, Arbitrum 3, Base 6). */
|
|
43
|
+
export type HlCctpChain = "arbitrum" | "ethereum" | "base";
|
|
44
|
+
export declare const HL_CCTP_ROUTES: Record<HlCctpChain, {
|
|
45
|
+
cctpDomain: number;
|
|
46
|
+
forwardingFeeUsdc: string | null;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* A COMPUTED price (strategy quote, grid level, slice limit) moved onto the HL price grid in the
|
|
50
|
+
* passive direction: "down" for a buy, "up" for a sell — never more aggressive than computed.
|
|
51
|
+
* User-supplied prices are never aligned (hlRequirePriceOnGrid refuses them instead).
|
|
52
|
+
*/
|
|
53
|
+
export declare function hlAlignPriceToGrid(price: string, szDecimals: number, maxDecimals: 6 | 8, direction: "down" | "up"): string;
|
|
54
|
+
/**
|
|
55
|
+
* Grid rounding (toward crossing) can widen the bound past the requested bps; a bound
|
|
56
|
+
* actually sent above the venue's maxSlippageBps → INVALID_PARAMS before anything is sent.
|
|
57
|
+
* (slippage.js is imported lazily: it loads settings and the venue registry.)
|
|
58
|
+
*/
|
|
59
|
+
export declare function assertHlAppliedBps(appliedBps: number, what: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Definite IOC outcome of a raw HL `order` response (shared contract with the
|
|
62
|
+
* perp-order lane, design §13.10 #4). Reads `response.data.statuses[0]`:
|
|
63
|
+
* - `{ filled: { totalSz } }` with a plain decimal totalSz → that size, final;
|
|
64
|
+
* - `{ error }` that is HL's IOC no-match cancel ("could not immediately match")
|
|
65
|
+
* → the venue explicitly cancelled the IOC with nothing filled → "0", final;
|
|
66
|
+
* - anything else (resting, other errors, unexpected shape) → null: the shape
|
|
67
|
+
* does not prove a final fill size.
|
|
68
|
+
*/
|
|
69
|
+
export declare function hlIocOutcome(raw: unknown): {
|
|
70
|
+
filledSize: string;
|
|
71
|
+
final: true;
|
|
72
|
+
} | null;
|
|
73
|
+
/**
|
|
74
|
+
* Decimal amount string for HL actions ("12.50" → "12.5"). Non-positive / non-numeric → INVALID_PARAMS
|
|
75
|
+
* (nothing is rounded or substituted).
|
|
76
|
+
*/
|
|
77
|
+
export declare function hlAmountString(amount: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* Verdict of a twapOrder / twapCancel response. The envelope is "ok" even when the TWAP was
|
|
80
|
+
* refused: the verdict is `response.data.status` — `{ running: { twapId } }` (placed), the string
|
|
81
|
+
* "success" (cancelled) or `{ error }` (refused → ORDER_REJECTED). Any other shape → ORDER_PENDING.
|
|
82
|
+
*/
|
|
83
|
+
export declare function hlValidateTwapResult(result: unknown, what: string): void;
|
|
84
|
+
/** HL TWAP running time bounds in minutes: "from 5 minutes to 7 days" (docs trading/order-types, TWAP details). */
|
|
85
|
+
export declare const HL_TWAP_MIN_MINUTES = 5;
|
|
86
|
+
export declare const HL_TWAP_MAX_MINUTES: number;
|
|
87
|
+
/** HL TWAP "$100 minimum total order size" (same page). */
|
|
88
|
+
export declare const HL_TWAP_MIN_NOTIONAL_USD = 100;
|
|
89
|
+
/**
|
|
90
|
+
* Pre-check of a native TWAP against the venue's documented bounds — docs trading/order-types:
|
|
91
|
+
* "Running time can be set from 5 minutes to 7 days, with a $100 minimum total order size."
|
|
92
|
+
* The total order size is valued at the mark price. Nothing is sent when it throws.
|
|
93
|
+
*/
|
|
94
|
+
export declare function hlAssertTwapBounds(symbol: string, size: string, durationMinutes: number, markPrice: number): void;
|
|
95
|
+
/**
|
|
96
|
+
* "sl" when the trigger is on the adverse side of the reference (buy ≥ ref, sell ≤ ref), else "tp".
|
|
97
|
+
* The reference must be the MARK price — docs trading/take-profit-and-stop-loss-orders-tp-sl:
|
|
98
|
+
* "The mark price is used to trigger TP/SL orders."
|
|
99
|
+
*/
|
|
100
|
+
export declare function hlTriggerKind(side: "buy" | "sell", trigger: number, reference: number): "tp" | "sl";
|
|
101
|
+
/** HL spot coin names: "@<pair index>" or "<BASE>/<QUOTE>" (e.g. "@107", "PURR/USDC"). Perp coins are neither. */
|
|
102
|
+
/** Markets without a position whose setting `account settings` reads (recent fills, activeAssetData weight 20 each). */
|
|
103
|
+
export declare const HL_SETTINGS_FILL_MARKETS = 5;
|
|
104
|
+
export declare function hlIsSpotCoin(coin: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Destination of a withdraw3 / usdSend: a 20-byte hex address, sent lower-cased (the venue
|
|
107
|
+
* hashes the string as signed; the official SDKs send lower-case). Anything else → INVALID_PARAMS.
|
|
108
|
+
*/
|
|
109
|
+
export declare function hlDestination(destination: string): string;
|
|
110
|
+
/**
|
|
111
|
+
* On-disk lifetime of the public market metadata (info `meta`, `perpDexs`) shared by every CLI
|
|
112
|
+
* process (cache.ts). Asset ids are universe positions; a market listed inside this window is
|
|
113
|
+
* unknown (SYMBOL_NOT_FOUND) until the entry expires.
|
|
114
|
+
*/
|
|
115
|
+
export declare const HL_MARKET_META_TTL_MS: number;
|
|
116
|
+
/**
|
|
117
|
+
* On-disk lifetime of the user's account abstraction mode (info `userAbstraction`), shared by
|
|
118
|
+
* every CLI process of the same network + address. Docs ("Rate limits and user limits"): "REST
|
|
119
|
+
* requests share an aggregated weight limit of 1200 per minute" and `userAbstraction` is one of
|
|
120
|
+
* "All other documented `info` requests [that] have weight 20" — read on every invocation it was
|
|
121
|
+
* the largest fixed cost of a command. The mode is a per-user setting that only changes by an
|
|
122
|
+
* explicit `userSetAbstraction`; `perp wallet manage account-mode` drops the entry when it sets
|
|
123
|
+
* one and always reads it fresh. A change made outside this CLI (web app) is seen after at most
|
|
124
|
+
* this window. The key is outside the `acct:` prefix, so the per-command account-cache
|
|
125
|
+
* invalidation does not force a re-read.
|
|
126
|
+
*/
|
|
127
|
+
export declare const HL_ABSTRACTION_TTL_MS = 60000;
|
|
128
|
+
/** Cache-key prefix of the abstraction mode for a network (invalidateCache prefix: every address). */
|
|
129
|
+
export declare function hlAbstractionCachePrefix(network: string): string;
|
|
130
|
+
/** Venue margin restriction of a universe entry: strictIsolated (no margin removal) / noCross; null = unrestricted. */
|
|
131
|
+
export declare function hlMarginModeOf(asset: {
|
|
132
|
+
marginMode?: string;
|
|
133
|
+
onlyIsolated?: boolean;
|
|
134
|
+
}): "strictIsolated" | "noCross" | null;
|
|
135
|
+
/** HIP-3 (builder-deployed) asset ids start at 110000 (110000 + dexIndex × 10000 + universe index). */
|
|
136
|
+
export declare const HIP3_MIN_ASSET_ID = 110000;
|
|
137
|
+
/**
|
|
138
|
+
* HL's documented slippage tolerance for MARKET TP/SL triggers ("TP/SL market orders have a
|
|
139
|
+
* slippage tolerance of 10%", docs trading/take-profit-and-stop-loss-orders-tp-sl). A market
|
|
140
|
+
* trigger's `p` is sent at trigger ± this bound (the official SDK / app send a wide limit, never
|
|
141
|
+
* the trigger itself): if the venue honours `p` as a limit, a `p` equal to the trigger could
|
|
142
|
+
* rest unfilled once the stop fires.
|
|
143
|
+
*/
|
|
144
|
+
export declare const HL_MARKET_TPSL_SLIPPAGE_BPS = 1000;
|
|
145
|
+
/** A `{"status":"err","response":…}` envelope from POST /exchange: the venue processed the request and refused it. */
|
|
146
|
+
export declare class HlErrResponse extends Error {
|
|
147
|
+
constructor(message: string);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A user-signed action (withdraw3 / usdSend / usdClassTransfer / approveBuilderFee / tokenDelegate)
|
|
151
|
+
* the venue answered with an `err` envelope executed nothing (live testnet 2026-10-02:
|
|
152
|
+
* withdraw3 → {"status":"err","response":"Error withdrawing from bridge"}, ledger and balance
|
|
153
|
+
* unchanged). A balance / margin refusal keeps its code (INSUFFICIENT_BALANCE — callers size from
|
|
154
|
+
* it); any other refusal → ACTION_REJECTED (definite, non-retryable). Transport / parse failures
|
|
155
|
+
* (no envelope) are returned unchanged — their outcome is unknown.
|
|
156
|
+
*/
|
|
157
|
+
export declare function hlUserActionRejection(type: string, e: unknown): unknown;
|
|
158
|
+
/**
|
|
159
|
+
* An L1 action (order / cancel / updateLeverage / agentSendAsset / …) answered with a top-level
|
|
160
|
+
* `err` envelope was refused as a whole and executed nothing — docs for-developers/api/error-responses:
|
|
161
|
+
* "Some errors are a deterministic function of the payload itself, and these are instead returned
|
|
162
|
+
* earlier as part of pre-validation. In this case only one error is returned for the entire payload".
|
|
163
|
+
* A balance / margin refusal keeps its code; any other refusal → ORDER_REJECTED (order actions) or
|
|
164
|
+
* ACTION_REJECTED — definite and non-retryable, never the retryable EXCHANGE_ERROR. Transport /
|
|
165
|
+
* parse failures (no envelope) are returned unchanged.
|
|
166
|
+
*/
|
|
167
|
+
export declare function hlL1ActionRejection(type: string, e: unknown): unknown;
|
|
5
168
|
export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
6
169
|
readonly name = "hyperliquid";
|
|
7
170
|
readonly chain = "evm";
|
|
8
171
|
readonly aliases: readonly ["hl"];
|
|
9
172
|
/**
|
|
10
|
-
* Reflects whether perp + spot share the same
|
|
11
|
-
* portfolio mode
|
|
12
|
-
*
|
|
173
|
+
* Reflects whether perp + spot share the same collateral pool (true for unified /
|
|
174
|
+
* portfolio mode — a per-user setting, HIP-3 dexes included) or are separately
|
|
175
|
+
* margined (false for standard / unset "default"). Populated during init() from _getAbstractionMode()
|
|
176
|
+
* (disk-cached for HL_ABSTRACTION_TTL_MS, so init reads the venue at most once per window);
|
|
13
177
|
* defaults to false until init resolves so callers never assume unified
|
|
14
178
|
* semantics for accounts that have never opted in. Codex v0.12.12 final QA #1.
|
|
15
179
|
*/
|
|
16
180
|
isUnifiedAccount: boolean;
|
|
17
|
-
private sdk;
|
|
18
181
|
private _address;
|
|
19
182
|
private _privateKey;
|
|
20
183
|
private _testnet;
|
|
@@ -25,18 +188,41 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
25
188
|
private _assetMap;
|
|
26
189
|
private _assetMapReverse;
|
|
27
190
|
private _szDecimalsMap;
|
|
191
|
+
/** symbol → venue marginMode restriction (meta universe `marginMode` / `onlyIsolated`); absent = none. */
|
|
192
|
+
private _marginModeMap;
|
|
28
193
|
/** HIP-3 deployed perp dex name. Empty string = native (validator) perps. */
|
|
29
194
|
private _dex;
|
|
195
|
+
/** Why the last asset-map load refused to map the dex (unknown dex / asset id below the HIP-3 range). */
|
|
196
|
+
private _assetMapError;
|
|
30
197
|
private static _lastNonce;
|
|
31
198
|
private _marketsCache;
|
|
32
199
|
private _marketsCacheTime;
|
|
33
200
|
private static readonly CACHE_TTL;
|
|
201
|
+
/**
|
|
202
|
+
* Builder-fee gate (settings builder.hyperliquid + confirmed master approval); null = not
|
|
203
|
+
* configured. Set by createHyperliquid — the adapter never reads settings.
|
|
204
|
+
*/
|
|
205
|
+
builderFee: BuilderFeeGate | null;
|
|
34
206
|
constructor(privateKey?: string, testnet?: boolean);
|
|
35
207
|
/** Set the HIP-3 deployed perp dex to query/trade on. */
|
|
36
208
|
setDex(dex: string): void;
|
|
37
209
|
get dex(): string;
|
|
38
|
-
get client(): Hyperliquid;
|
|
39
210
|
get address(): string;
|
|
211
|
+
/**
|
|
212
|
+
* Builder decision for an order on `assetIndex` (null = adapter-level, e.g. dry-run).
|
|
213
|
+
* HIP-3 (this adapter's dex, or a builder-deployed asset id ≥ 100000) never carries it.
|
|
214
|
+
*/
|
|
215
|
+
builderDecision(assetIndex: number | null): Promise<BuilderDecision>;
|
|
216
|
+
/**
|
|
217
|
+
* HL `order` action. `builder: { b, f }` (f = tenths of a bp, builder-codes docs) is appended
|
|
218
|
+
* only when the gate approves it — key order type, orders, grouping, builder (msgpack hash).
|
|
219
|
+
*/
|
|
220
|
+
private _orderAction;
|
|
221
|
+
/**
|
|
222
|
+
* Master approval for `target` (info maxBuilderFee: the approved ceiling in tenths of a bp,
|
|
223
|
+
* 0 = none). Read for this adapter's account address (the master — agents cannot approve).
|
|
224
|
+
*/
|
|
225
|
+
builderApprovalOf(target: BuilderTarget): Promise<BuilderApproval>;
|
|
40
226
|
get isTestnet(): boolean;
|
|
41
227
|
/** Inject an external EVM signer. Call before init() to skip LocalEvmSigner creation. */
|
|
42
228
|
setSigner(signer: EvmSigner): void;
|
|
@@ -57,6 +243,15 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
57
243
|
/** Resolve the active signer across three tiers. */
|
|
58
244
|
private _resolveSigner;
|
|
59
245
|
init(): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* info `meta` of this adapter's perp dex (universe: names, szDecimals, margin restrictions;
|
|
248
|
+
* collateralToken) — public static metadata, shared on disk by every CLI process for
|
|
249
|
+
* HL_MARKET_META_TTL_MS. Docs ("Rate limits and user limits"): "REST requests share an
|
|
250
|
+
* aggregated weight limit of 1200 per minute" and `meta` is one of "All other documented `info`
|
|
251
|
+
* requests [that] have weight 20" — re-reading it on every invocation (twice on a balance read)
|
|
252
|
+
* was most of a command's weight. Account state is never cached here.
|
|
253
|
+
*/
|
|
254
|
+
private _metaCached;
|
|
60
255
|
/** Load asset index map — supports native and HIP-3 dex. */
|
|
61
256
|
private _loadAssetMap;
|
|
62
257
|
/**
|
|
@@ -64,43 +259,105 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
64
259
|
* Handles: "ICP" → "ICP-PERP", "BTC-PERP" → "BTC-PERP", "km:GOOGL" → "km:GOOGL"
|
|
65
260
|
*/
|
|
66
261
|
resolveSymbol(symbol: string): string;
|
|
67
|
-
/**
|
|
262
|
+
/** The asset-map key equal to `upper` ignoring case, when exactly one exists (kPEPE-PERP for KPEPE-PERP). */
|
|
263
|
+
private _caseInsensitive;
|
|
264
|
+
/**
|
|
265
|
+
* szDecimals for a symbol (cached from init/getMeta). Rule #2: never assumed —
|
|
266
|
+
* meta not loaded → PRICE_STALE (retryable); loaded but no entry → SYMBOL_NOT_FOUND.
|
|
267
|
+
*/
|
|
68
268
|
getSzDecimals(symbol: string): number;
|
|
69
|
-
/**
|
|
70
|
-
|
|
269
|
+
/** Lot step of a market from the loaded `meta` szDecimals (precision.lotStepOf) — no metaAndAssetCtxs / allMids read per order. */
|
|
270
|
+
lotStepOf(symbol: string): string;
|
|
71
271
|
getAssetIndex(symbol: string): Promise<number>;
|
|
72
272
|
getMarkets(): Promise<ExchangeMarketInfo[]>;
|
|
73
273
|
getOrderbook(symbol: string): Promise<{
|
|
74
274
|
bids: [string, string][];
|
|
75
275
|
asks: [string, string][];
|
|
76
276
|
}>;
|
|
277
|
+
/**
|
|
278
|
+
* Venue coin for a symbol: native perps drop the "-PERP" display suffix ("BTC-PERP" →
|
|
279
|
+
* "BTC"); HIP-3 coins carry the dex prefix ("US500" → "km:US500").
|
|
280
|
+
*/
|
|
281
|
+
private _venueCoin;
|
|
282
|
+
/** Display symbol for a venue coin: a native perp coin "BTC" → "BTC-PERP"; anything else unchanged. */
|
|
283
|
+
private _displaySymbol;
|
|
77
284
|
private ensureAddress;
|
|
285
|
+
/** The in-flight clearinghouseState read: parallel callers (getBalance + getPositions) share one request. */
|
|
286
|
+
private _chsInFlight;
|
|
78
287
|
/** Read-through cached clearinghouseState — returns cached data if fresh */
|
|
79
288
|
private _getClearinghouseState;
|
|
80
289
|
/**
|
|
81
290
|
* Read the user's account abstraction mode from HL.
|
|
82
291
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* - "
|
|
89
|
-
*
|
|
292
|
+
* Abstraction is a property of the USER (not of a dex): it is always queried,
|
|
293
|
+
* HIP-3 dex adapters included.
|
|
294
|
+
* - "unified" → spot clearinghouseState is the truth source (one balance per
|
|
295
|
+
* collateral token, shared by spot and every perp dex).
|
|
296
|
+
* - "portfolio" → multi-asset cross-collateral; balances also live in spot state.
|
|
297
|
+
* - "standard" → perp clearinghouseState is the truth source (venue "disabled").
|
|
298
|
+
* - "default" → the user never set a mode. Not assumed to be either: balances
|
|
299
|
+
* are read from the perp state and getBalance() warns when that
|
|
300
|
+
* reads 0 while spot holds the collateral token.
|
|
90
301
|
*
|
|
91
|
-
* Per SSOT Rule #2: an unrecognized venue response throws — no silent
|
|
92
|
-
* default. HIP-3 dex accounts (`this._dex` set) bypass the lookup since
|
|
93
|
-
* cross margin scopes per-DEX in standard semantics.
|
|
302
|
+
* Per SSOT Rule #2: an unrecognized venue response throws — no silent default.
|
|
94
303
|
*
|
|
95
|
-
* Endpoint: `POST /info {"type":"userAbstraction","user":"0x..."}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
304
|
+
* Endpoint: `POST /info {"type":"userAbstraction","user":"0x..."}`.
|
|
305
|
+
*/
|
|
306
|
+
_getAbstractionMode(opts?: {
|
|
307
|
+
fresh?: boolean;
|
|
308
|
+
}): Promise<"unified" | "standard" | "portfolio" | "default" | "dexAbstraction">;
|
|
309
|
+
/** Collateral token index of this adapter's perp dex (info `meta{dex}.collateralToken`; 0 = USDC on native perps). */
|
|
310
|
+
private _collateralTokenIdx;
|
|
311
|
+
_getCollateralToken(): Promise<number>;
|
|
312
|
+
/** Cached spot clearinghouse state (raw venue shape) — shared between getBalance() and HyperliquidSpotAdapter */
|
|
313
|
+
_getSpotClearinghouseState(opts?: {
|
|
314
|
+
fresh?: boolean;
|
|
315
|
+
}): Promise<Record<string, unknown>>;
|
|
316
|
+
/** Spot balance row of this dex's collateral token (matched by token index, not by coin name); null = none held. */
|
|
317
|
+
private _spotCollateralRow;
|
|
101
318
|
getBalance(): Promise<ExchangeBalance>;
|
|
102
319
|
getPositions(): Promise<ExchangePosition[]>;
|
|
320
|
+
/**
|
|
321
|
+
* The leverage this account applies to `symbol`, position or not — info `activeAssetData`
|
|
322
|
+
* {user, coin} → `"leverage": { "type": "cross", "value": 3 }` (docs info-endpoint/perpetuals).
|
|
323
|
+
* Unreadable → EXCHANGE_ERROR.
|
|
324
|
+
*/
|
|
325
|
+
marketLeverage(symbol: string): Promise<number>;
|
|
326
|
+
/**
|
|
327
|
+
* Per-market leverage / margin mode:
|
|
328
|
+
* - every market with a position: the `leverage` object of its `assetPositions` entry of info
|
|
329
|
+
* `clearinghouseState` (docs info-endpoint/perpetuals: `"leverage": { "rawUsd": "-95.059824",
|
|
330
|
+
* "type": "isolated", "value": 20 }`);
|
|
331
|
+
* - markets WITHOUT a position the account traded: the HL_SETTINGS_FILL_MARKETS most recently
|
|
332
|
+
* traded perp markets of this adapter's dex in info `userFills` ("at most 2000 most recent
|
|
333
|
+
* fills"; spot "@<i>" / "BASE/QUOTE", HIP-4 "#<enc>", other dexes and delisted coins are not
|
|
334
|
+
* markets of this adapter and are skipped), each read with info `activeAssetData` {user, coin}
|
|
335
|
+
* → `"leverage": { "type": "cross", "value": 3 }` (docs info-endpoint/perpetuals; live
|
|
336
|
+
* 2026-10-13 `{"type":"cross","value":20}` for an account that never set ETH).
|
|
337
|
+
* Weight (docs "Rate limits and user limits"): clearinghouseState 2 + userFills 20 (+1 per 20
|
|
338
|
+
* fills) + activeAssetData 20 per market — bounded by HL_SETTINGS_FILL_MARKETS.
|
|
339
|
+
* An unreadable leverage → EXCHANGE_ERROR.
|
|
340
|
+
*/
|
|
341
|
+
getMarketSettings(): Promise<Array<{
|
|
342
|
+
symbol: string;
|
|
343
|
+
leverage: number;
|
|
344
|
+
marginMode: "cross" | "isolated";
|
|
345
|
+
}>>;
|
|
346
|
+
/**
|
|
347
|
+
* Open orders from info `frontendOpenOrders` (native perps, or the HIP-3 dex): unlike
|
|
348
|
+
* `openOrders` it labels trigger orders (isTrigger, orderType "Stop Market" / "Take Profit
|
|
349
|
+
* Limit" …, triggerPx), so stops / TP / SL are listed as such and cancel-all / flatten cancel
|
|
350
|
+
* them. `type` = the venue orderType for a trigger order, else "limit".
|
|
351
|
+
*/
|
|
103
352
|
getOpenOrders(): Promise<ExchangeOrder[]>;
|
|
353
|
+
/** HL order id for a cancel: a decimal integer that is exactly representable (else INVALID_PARAMS, nothing sent). */
|
|
354
|
+
/**
|
|
355
|
+
* A Hyperliquid client order id (cloid) as sent / queried: "0x" + 32 lowercase hex chars
|
|
356
|
+
* (exchange-endpoint docs: `c` "an optional 128 bit hex string, e.g.
|
|
357
|
+
* 0x1234567890abcdef1234567890abcdef"). Anything else → INVALID_PARAMS, nothing sent.
|
|
358
|
+
*/
|
|
359
|
+
static requireCloid(cloid: string): string;
|
|
360
|
+
private _oidOf;
|
|
104
361
|
private _invalidateAccountCache;
|
|
105
362
|
/**
|
|
106
363
|
* Validate that an HL order actually filled.
|
|
@@ -109,15 +366,60 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
109
366
|
* Each status is one of: { filled: { totalSz, avgPx, oid } }, { resting: { oid } }, { error: "msg" }
|
|
110
367
|
*/
|
|
111
368
|
private _validateOrderFill;
|
|
112
|
-
marketOrder(symbol: string, side: "buy" | "sell", size: string, opts?: {
|
|
113
|
-
reduceOnly?: boolean;
|
|
114
|
-
}): Promise<unknown>;
|
|
115
369
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
370
|
+
* Market order = slippage-bounded IOC limit (design §13.2, §13.10 #1/#5) for
|
|
371
|
+
* native perps and HIP-3 dexes alike. Replaces the SDK's marketOpen/marketClose
|
|
372
|
+
* (hidden built-in slippage) and the former HIP-3 5% constant.
|
|
373
|
+
*
|
|
374
|
+
* Reference price (the single declared source, §13.10 #5): the l2Book mid
|
|
375
|
+
* (best bid + best ask) / 2 of this coin — see referencePrice(). No runtime
|
|
376
|
+
* substitute (mark, allMids, last trade): a missing side → PRICE_STALE before
|
|
377
|
+
* anything is sent. Protection = reference ± opts.slippage.bps, aligned toward
|
|
378
|
+
* crossing on HL's price grid (hlProtectionPrice, max 6 − szDecimals decimals).
|
|
379
|
+
*
|
|
380
|
+
* reduceOnly is sent as the order's `r` flag: the venue can only reduce the
|
|
381
|
+
* position with it (never open/flip), so the caller's side is used as given.
|
|
382
|
+
*/
|
|
383
|
+
marketOrder(symbol: string, side: "buy" | "sell", size: string, opts: {
|
|
384
|
+
reduceOnly: boolean;
|
|
385
|
+
slippage: ResolvedSlippage;
|
|
386
|
+
clientOrderId?: string;
|
|
387
|
+
}): Promise<{
|
|
388
|
+
clientOrderId?: string | undefined;
|
|
389
|
+
protection: {
|
|
390
|
+
referencePrice: string;
|
|
391
|
+
protectionPrice: string;
|
|
392
|
+
appliedBps: number;
|
|
393
|
+
};
|
|
394
|
+
sentSize: string;
|
|
395
|
+
}>;
|
|
396
|
+
/**
|
|
397
|
+
* The single declared reference price for market-type protection prices:
|
|
398
|
+
* l2Book mid = (best bid + best ask) / 2. Works for native perps and HIP-3
|
|
399
|
+
* (getOrderbook passes the dex). Either side missing / non-positive → PRICE_STALE.
|
|
119
400
|
*/
|
|
120
|
-
|
|
401
|
+
referencePrice(symbol: string): Promise<number>;
|
|
402
|
+
/**
|
|
403
|
+
* Venue mark price of `symbol` (info `metaAndAssetCtxs` → `markPx`; passes the dex for HIP-3).
|
|
404
|
+
* Read fresh (never the markets cache, whose markPrice may be an allMids substitute).
|
|
405
|
+
* Missing / non-positive → PRICE_STALE.
|
|
406
|
+
*/
|
|
407
|
+
markPrice(symbol: string): Promise<number>;
|
|
408
|
+
/**
|
|
409
|
+
* Protection price an IOC market order on `symbol` would be sent with now.
|
|
410
|
+
* Exposed so a TradingV2 wrapper can record execution.{protectionPrice, slippageBps}
|
|
411
|
+
* (appliedBps = the bound after HL rounding).
|
|
412
|
+
*/
|
|
413
|
+
computeProtectionPrice(symbol: string, side: "buy" | "sell", slippage: ResolvedSlippage): Promise<{
|
|
414
|
+
referencePrice: string;
|
|
415
|
+
protectionPrice: string;
|
|
416
|
+
appliedBps: number;
|
|
417
|
+
}>;
|
|
418
|
+
/** Definite IOC outcome of a raw order response (see hlIocOutcome). */
|
|
419
|
+
iocOutcomeOf(raw: unknown): {
|
|
420
|
+
filledSize: string;
|
|
421
|
+
final: true;
|
|
422
|
+
} | null;
|
|
121
423
|
/**
|
|
122
424
|
* Sign and send any exchange action via raw EIP-712 signing.
|
|
123
425
|
* Bypasses the SDK entirely — works for order, batchModify, twapOrder, etc.
|
|
@@ -132,20 +434,62 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
132
434
|
* does not exist" error.
|
|
133
435
|
*/
|
|
134
436
|
private static _normalizeAction;
|
|
437
|
+
/** Monotonic ms nonce: unique even for rapid-fire requests in the same millisecond. */
|
|
438
|
+
private static _nextNonce;
|
|
439
|
+
private get _network();
|
|
440
|
+
/**
|
|
441
|
+
* Sign an L1 action with the active signer tier (agent or master) and POST it.
|
|
442
|
+
* `nonce` must be passed when the action itself carries it (agentSendAsset).
|
|
443
|
+
*/
|
|
135
444
|
private _signAndSendAction;
|
|
445
|
+
/**
|
|
446
|
+
* Sign a USER-signed action (HyperliquidSignTransaction EIP-712) with the MASTER
|
|
447
|
+
* signer and POST it. Agents cannot sign these — no agent fallback: without a
|
|
448
|
+
* master signer this throws NO_SIGNER_AVAILABLE before anything is sent.
|
|
449
|
+
*/
|
|
450
|
+
private _signAndSendUserAction;
|
|
451
|
+
/** POST /exchange request timeout: a request the venue never answers must not hang the CLI. */
|
|
452
|
+
static readonly EXCHANGE_TIMEOUT_MS = 30000;
|
|
453
|
+
/**
|
|
454
|
+
* POST /exchange; an `err` envelope or a 4xx non-JSON body throws (the venue refused it).
|
|
455
|
+
* Once the signed action is on the wire its outcome is unknown unless the venue answers:
|
|
456
|
+
* a connection reset, timeout, 5xx or unreadable 2xx body → ORDER_PENDING (sendFailure),
|
|
457
|
+
* never a retryable EXCHANGE_UNREACHABLE / TIMEOUT. No connection at all → not sent.
|
|
458
|
+
*/
|
|
459
|
+
private _postExchange;
|
|
460
|
+
/** One order wire (HL `order` action entry); p/s trailing zeros removed (HL API requirement). */
|
|
461
|
+
private _orderWire;
|
|
136
462
|
/**
|
|
137
463
|
* Place an order via raw exchange API with EIP-712 signing.
|
|
138
464
|
* This bypasses the SDK's symbolConversion and supports dex-specific orders.
|
|
139
465
|
*/
|
|
140
466
|
private _rawPlaceOrder;
|
|
467
|
+
/**
|
|
468
|
+
* A computed limit price for `symbol` on the HL grid, aligned passively for `side` (buy ↓,
|
|
469
|
+
* sell ↑). For strategy / grid / slice prices — limitOrder itself refuses off-grid input.
|
|
470
|
+
*/
|
|
471
|
+
alignComputedPrice(symbol: string, side: "buy" | "sell", price: string): Promise<string>;
|
|
141
472
|
limitOrder(symbol: string, side: "buy" | "sell", price: string, size: string, opts?: {
|
|
142
473
|
reduceOnly?: boolean;
|
|
143
474
|
tif?: string;
|
|
475
|
+
clientOrderId?: string;
|
|
144
476
|
}): Promise<unknown>;
|
|
477
|
+
/**
|
|
478
|
+
* Cancel one order by client order id — exchange-endpoint docs "Cancel order(s) by cloid":
|
|
479
|
+
* `{ "type": "cancelByCloid", "cancels": [{ "asset": Number, "cloid": String }] }`. The asset is
|
|
480
|
+
* the global id, so a HIP-3 dex order is addressed the same way. Per-entry error → ORDER_REJECTED.
|
|
481
|
+
*/
|
|
482
|
+
cancelByCloid(symbol: string, cloid: string): Promise<unknown>;
|
|
145
483
|
cancelOrder(symbol: string, orderId: string): Promise<unknown>;
|
|
146
484
|
cancelAllOrders(symbol?: string): Promise<unknown[]>;
|
|
485
|
+
/**
|
|
486
|
+
* Amend (design §13.4, §13.10 #10) via HL native batchModify. `size` = the NEW
|
|
487
|
+
* open (unfilled) size — native-modify semantics, not the original total. The
|
|
488
|
+
* order's own tif (Gtc/Alo) and reduceOnly are read from frontendOpenOrders
|
|
489
|
+
* and preserved; nothing is hardcoded.
|
|
490
|
+
*/
|
|
147
491
|
editOrder(symbol: string, orderId: string, price: string, size: string): Promise<unknown>;
|
|
148
|
-
setLeverage(symbol: string, leverage: number, marginMode?: "cross" | "isolated"): Promise<
|
|
492
|
+
setLeverage(symbol: string, leverage: number, marginMode?: "cross" | "isolated"): Promise<unknown>;
|
|
149
493
|
stopOrder(symbol: string, side: "buy" | "sell", size: string, triggerPrice: string, opts?: {
|
|
150
494
|
limitPrice?: string;
|
|
151
495
|
reduceOnly?: boolean;
|
|
@@ -163,12 +507,30 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
163
507
|
/**
|
|
164
508
|
* Place a trigger order (stop loss / take profit).
|
|
165
509
|
* Python SDK: order() with trigger type {"trigger": {triggerPx, isMarket, tpsl: "tp"|"sl"}}
|
|
510
|
+
*
|
|
511
|
+
* Pricing (design §13.10 #3):
|
|
512
|
+
* - isMarket (default): HL native market trigger; `p` = trigger ± 10 % (the venue's documented
|
|
513
|
+
* market TP/SL slippage tolerance, HL_MARKET_TPSL_SLIPPAGE_BPS), aligned toward crossing.
|
|
514
|
+
* - limit trigger with an explicit `limitPrice`: that price, rounded to HL's grid.
|
|
515
|
+
* - limit trigger without `limitPrice`: protection = TRIGGER price ± opts.slippage.bps
|
|
516
|
+
* (reference = trigger, not mark), aligned toward crossing. Missing slippage →
|
|
517
|
+
* INVALID_PARAMS (no implicit zero-slippage limit at the trigger).
|
|
166
518
|
*/
|
|
167
519
|
triggerOrder(symbol: string, side: "buy" | "sell", size: string, triggerPrice: string, tpsl: "tp" | "sl", opts?: {
|
|
168
520
|
isMarket?: boolean;
|
|
521
|
+
limitPrice?: string;
|
|
169
522
|
reduceOnly?: boolean;
|
|
170
523
|
grouping?: string;
|
|
524
|
+
slippage?: ResolvedSlippage;
|
|
171
525
|
}): Promise<unknown>;
|
|
526
|
+
/** Open trigger orders of `coin` (frontendOpenOrders rows with isTrigger), by oid. */
|
|
527
|
+
private _triggerOids;
|
|
528
|
+
/**
|
|
529
|
+
* The oid of the trigger order just placed: the single open trigger order of `coin` not listed
|
|
530
|
+
* before, with the side / trigger price / size / reduce-only sent. Several reads (500 ms apart);
|
|
531
|
+
* none or more than one candidate → null (never guessed).
|
|
532
|
+
*/
|
|
533
|
+
private _newTriggerOid;
|
|
172
534
|
/**
|
|
173
535
|
* Place a TWAP order.
|
|
174
536
|
* Python SDK: not available in old SDK, available via raw exchange action.
|
|
@@ -182,29 +544,52 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
182
544
|
* Cancel a TWAP order.
|
|
183
545
|
*/
|
|
184
546
|
twapCancel(symbol: string, twapId: number): Promise<unknown>;
|
|
547
|
+
/** Venue margin restriction of `symbol` (meta marginMode / onlyIsolated); null = unrestricted. */
|
|
548
|
+
marginModeOf(symbol: string): "strictIsolated" | "noCross" | null;
|
|
185
549
|
/**
|
|
186
|
-
* Update leverage for a symbol
|
|
187
|
-
*
|
|
550
|
+
* Update leverage for a symbol — L1 action `updateLeverage` (agent-signable),
|
|
551
|
+
* python SDK update_leverage. Cross is refused up front on isolated-only assets.
|
|
188
552
|
*/
|
|
189
|
-
updateLeverage(symbol: string, leverage: number, isCross?: boolean): Promise<
|
|
553
|
+
updateLeverage(symbol: string, leverage: number, isCross?: boolean): Promise<unknown>;
|
|
190
554
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
555
|
+
* Add (amount > 0) or remove (amount < 0) isolated margin — L1 action
|
|
556
|
+
* `updateIsolatedMargin`, python SDK update_isolated_margin: `isBuy` is always
|
|
557
|
+
* true and the SIGNED `ntli` (USDC × 1e6) carries the direction.
|
|
193
558
|
*/
|
|
194
|
-
updateIsolatedMargin(symbol: string, amount: number): Promise<
|
|
559
|
+
updateIsolatedMargin(symbol: string, amount: number): Promise<unknown>;
|
|
195
560
|
/**
|
|
196
|
-
* Withdraw
|
|
197
|
-
*
|
|
561
|
+
* Withdraw USDC over CCTP (native USDC) — user-signed `sendToEvmWithData` (master only):
|
|
562
|
+
* HyperCore is debited, the USDC is burned on HyperEVM and CCTP mints it on `chain`
|
|
563
|
+
* (default Arbitrum). The Arbitrum Bridge2 `withdraw3` path is no longer used.
|
|
564
|
+
* Docs: developers.circle.com/cctp/howtos/withdraw-usdc-from-hypercore-to-evm —
|
|
565
|
+
* sourceDex "spot" (unified accounts hold USDC in spot) or "" (standard accounts' perp
|
|
566
|
+
* balance); data "0x" = automatic forwarding, which CCTP charges a fixed fee for
|
|
567
|
+
* (Arbitrum 0.2 USDC; an amount below the fee reverts).
|
|
198
568
|
*/
|
|
199
|
-
withdraw(amount: string, destination: string,
|
|
569
|
+
withdraw(amount: string, destination: string, opts?: {
|
|
200
570
|
assetId?: number;
|
|
201
571
|
routeType?: number;
|
|
202
|
-
|
|
572
|
+
chain?: HlCctpChain;
|
|
573
|
+
}): Promise<unknown>;
|
|
574
|
+
/**
|
|
575
|
+
* Send USDC to another Hyperliquid account — user-signed `usdSend` (master only),
|
|
576
|
+
* python SDK usd_transfer.
|
|
577
|
+
*/
|
|
578
|
+
usdTransfer(amount: number, destination: string): Promise<unknown>;
|
|
203
579
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
580
|
+
* Move USDC between this account's spot and perp balances — user-signed
|
|
581
|
+
* `usdClassTransfer` (master only), python SDK usd_class_transfer.
|
|
206
582
|
*/
|
|
207
|
-
|
|
583
|
+
usdClassTransfer(amount: string, toPerp: boolean): Promise<unknown>;
|
|
584
|
+
/**
|
|
585
|
+
* Move this dex's collateral token between spot and this adapter's perp dex as an
|
|
586
|
+
* L1 action `agentSendAsset` (agent-signable; destination = own account). Spot →
|
|
587
|
+
* perp when `toPerp`, else perp → spot. The token is "<name>:<tokenId>" of the
|
|
588
|
+
* dex collateral token, read from spotMeta (never hardcoded).
|
|
589
|
+
*/
|
|
590
|
+
agentSendAsset(amount: string, toPerp: boolean): Promise<unknown>;
|
|
591
|
+
/** "<name>:<tokenId>" of this dex's collateral token (meta{dex}.collateralToken → spotMeta tokens). */
|
|
592
|
+
private _collateralTokenWire;
|
|
208
593
|
/**
|
|
209
594
|
* Create a sub-account.
|
|
210
595
|
*/
|
|
@@ -214,20 +599,42 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
214
599
|
*/
|
|
215
600
|
subAccountTransfer(subAccountUser: string, isDeposit: boolean, amount: number): Promise<unknown>;
|
|
216
601
|
/**
|
|
217
|
-
* Modify an existing order.
|
|
602
|
+
* Modify an existing order (native batchModify). `newSize` = new open size.
|
|
603
|
+
* `tif`/`reduceOnly` must be the original order's (editOrder reads them from
|
|
604
|
+
* frontendOpenOrders) — a modify otherwise silently changes the order's TIF.
|
|
218
605
|
*/
|
|
219
|
-
modifyOrder(symbol: string, orderId: number, newSide: "buy" | "sell", newPrice: string, newSize: string, opts
|
|
220
|
-
reduceOnly
|
|
606
|
+
modifyOrder(symbol: string, orderId: number, newSide: "buy" | "sell", newPrice: string, newSize: string, opts: {
|
|
607
|
+
reduceOnly: boolean;
|
|
608
|
+
tif: HlTif;
|
|
609
|
+
cloid?: string | null;
|
|
221
610
|
}): Promise<unknown>;
|
|
611
|
+
/**
|
|
612
|
+
* Validate that the venue actually accepted an order/cancel/modify action.
|
|
613
|
+
*
|
|
614
|
+
* HL returns the envelope `status: "ok"` even when the individual entry was
|
|
615
|
+
* rejected — the real verdict is per-entry in `response.data.statuses[]`,
|
|
616
|
+
* where an accepted entry is `{filled}` / `{resting}` / the string "success"
|
|
617
|
+
* and a rejected one is `{error: "..."}`. `_signAndSendAction` only throws on
|
|
618
|
+
* the ENVELOPE, so every path that skipped this check reported a rejection to
|
|
619
|
+
* the user as a green success.
|
|
620
|
+
* A per-entry `{error}` is the venue's definite verdict on that entry — including an
|
|
621
|
+
* IOC's "could not immediately match" (cancelled with nothing filled) — so it is
|
|
622
|
+
* ORDER_REJECTED (definite, never quarantined as an unknown outcome).
|
|
623
|
+
* Also used by HyperliquidSpotAdapter (spot limit orders).
|
|
624
|
+
*/
|
|
625
|
+
_validateVenueAck(result: unknown, what: string): void;
|
|
626
|
+
private _validateModifyResult;
|
|
222
627
|
/**
|
|
223
628
|
* Schedule cancel: cancel all orders at a future time.
|
|
224
629
|
* Max 10 triggers per day.
|
|
225
630
|
*/
|
|
226
631
|
scheduleCancel(timeMs?: number): Promise<unknown>;
|
|
227
632
|
/**
|
|
228
|
-
* Set
|
|
633
|
+
* Set the account's referrer (one HL `setReferrer` action, signed + sent).
|
|
634
|
+
* Called only from the explicit `wallet manage referral set` command — never on
|
|
635
|
+
* adapter creation. Throws on a venue rejection (SSOT Rule #2).
|
|
229
636
|
*/
|
|
230
|
-
|
|
637
|
+
setReferrer(code: string): Promise<unknown>;
|
|
231
638
|
/**
|
|
232
639
|
* Get funding history for a symbol.
|
|
233
640
|
*/
|
|
@@ -243,7 +650,8 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
243
650
|
/**
|
|
244
651
|
* Query a specific order by OID.
|
|
245
652
|
*/
|
|
246
|
-
|
|
653
|
+
/** info `orderStatus`: `oid` "Either u64 representing the order id or 16-byte hex string representing the client order id". */
|
|
654
|
+
queryOrder(orderId: number | string): Promise<any>;
|
|
247
655
|
/**
|
|
248
656
|
* Approve a builder fee.
|
|
249
657
|
* Action type: approveBuilderFee
|
|
@@ -298,7 +706,7 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
298
706
|
*/
|
|
299
707
|
getDelegations(): Promise<unknown>;
|
|
300
708
|
/**
|
|
301
|
-
* POST to /info endpoint.
|
|
709
|
+
* POST to /info endpoint (all reads — no SDK). A non-2xx response throws.
|
|
302
710
|
*/
|
|
303
711
|
private _infoPost;
|
|
304
712
|
/**
|
|
@@ -306,9 +714,6 @@ export declare class HyperliquidAdapter implements ExchangeAdapter {
|
|
|
306
714
|
* Used by HyperliquidSpotAdapter to delegate signing.
|
|
307
715
|
*/
|
|
308
716
|
exchangeAction(action: Record<string, unknown>): Promise<unknown>;
|
|
309
|
-
/**
|
|
310
|
-
* Send a raw exchange action through the SDK.
|
|
311
|
-
* Used for methods not directly exposed by the SDK.
|
|
312
|
-
*/
|
|
717
|
+
/** Sign (L1 scheme, active signer tier) and send an exchange action. */
|
|
313
718
|
private _sendExchangeAction;
|
|
314
719
|
}
|