@candledottv/agent-sdk 0.6.2 → 0.6.3

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 CHANGED
@@ -134,6 +134,14 @@ const fill = await candle.trade({ mint: "9dXSV8...CNDL", side: "buy", amountRaw:
134
134
  - The `perps*` methods (`perpsSetup`, `perpsOpen`, `perpsClose`, `perpsOrders`,
135
135
  `perpsPositions`, ...) drive Hyperliquid perps.
136
136
 
137
+ Perps setup and signing use this release's builder pin,
138
+ `0xc43ff1f6ad9f93fc94558e07c2071b8458e7470b`, independently of the API.
139
+ `hyperliquidBuilder` deliberately replaces that trust anchor with an explicit nonzero EVM
140
+ address; empty or invalid overrides refuse rather than fall back. The local
141
+ `preview.builderTrust` records the expected address and whether it came from the release or
142
+ an override. Setup answers (including `ready`) and fee-bearing actions naming another builder
143
+ are refused before signing. Builder rotation requires a reviewed client release.
144
+
137
145
  Limit orders are a REST surface only (`/api/v1/trade/agent/orders`); the SDK has no method for
138
146
  them.
139
147
 
package/dist/client.d.ts CHANGED
@@ -39,8 +39,13 @@
39
39
  * The README's "Retrying a write that failed or timed out" is the caller-facing procedure.
40
40
  */
41
41
  import { type SignedTradeLeg } from "./errors";
42
- import { type HyperliquidNetwork, type HyperliquidTypedData } from "./hyperliquid";
42
+ import { type HyperliquidNetwork, type HyperliquidSubmitOutcome, type HyperliquidTypedData } from "./hyperliquid";
43
+ import { type PerpsTpslParams, type PerpsWorkflowResult } from "./hyperliquid-manage";
44
+ import { type PerpsBookOptions, type PerpsBookResult, type PerpsCandlesOptions, type PerpsCandlesResult, type PerpsMarketResult, type PerpsMarketsOptions, type PerpsMarketsResult } from "./hyperliquid-markets";
43
45
  import type { HyperliquidPnlSection } from "./hyperliquid-pnl";
46
+ import { type PerpsAccountLine, type PerpsAccountReport, type PerpsPortfolioSection, type PerpsPositionRow, type PerpsRiskReport, type PerpsRiskSettings, type PerpsRiskThresholds, type PerpsRiskThresholdsReport, type PerpsWatchEvent } from "./hyperliquid-risk";
47
+ import { type PerpsWithdrawAuthorization, type PerpsWithdrawBuild, type PerpsWithdrawPins } from "./hyperliquid-withdraw";
48
+ import { type PerpsFillsPage, type PerpsFundingPage, type PerpsHistoryOptions } from "./perps-history";
44
49
  import type { AgentPlansResult, PlanPrice, PlanTable } from "./plans";
45
50
  import type { SecretStore } from "./secret-store";
46
51
  import type { CandleStaking } from "./staking";
@@ -108,13 +113,20 @@ export interface CandleClientOptions {
108
113
  /**
109
114
  * Candle's Hyperliquid builder address, pinned by the caller. Every perps build is checked
110
115
  * against it before signing: an order must name exactly this builder (or none, on a Max order),
111
- * and setup must approve exactly it. Unset, the client uses `CANDLE_HYPERLIQUID_BUILDER_ADDRESS`
112
- * when this release carries one, and otherwise trusts the builder `GET /agent/perps/config`
113
- * reports the first time and holds every later build to that same address.
116
+ * and setup must approve exactly it. This deliberately replaces the release trust anchor and
117
+ * is shown as `preview.builderTrust.source: "override"`. Must be a nonzero EVM address; an
118
+ * invalid override refuses setup/signing. Unset uses the release pin, never `/perps/config`.
114
119
  */
115
120
  hyperliquidBuilder?: string;
116
121
  /** The Hyperliquid network this client trades on. Default mainnet; a build for another is refused. */
117
122
  hyperliquidNetwork?: HyperliquidNetwork;
123
+ /**
124
+ * The withdrawal pins every withdrawal is checked against before anything is signed: the
125
+ * perps-USDC `token`, `destinationDex`, Relay's depository allow-list and the amount's string
126
+ * form. Unset, this release's `CANDLE_PERPS_WITHDRAW_PINS` applies (the values V-A recorded on
127
+ * 2026-10-18). Pins of null would refuse every withdrawal with nothing signed.
128
+ */
129
+ perpsWithdrawPins?: PerpsWithdrawPins;
118
130
  }
119
131
  /** The bonding-curve terms of one (chain, quote asset, tier) cell. */
120
132
  export interface CurveTerms {
@@ -1799,12 +1811,29 @@ export interface PerpsOpenParams extends PerpsWalletRef {
1799
1811
  takeProfit?: string;
1800
1812
  /** Optional reduce-only stop-loss trigger price. */
1801
1813
  stopLoss?: string;
1814
+ /**
1815
+ * Optional client order id: `0x` and 32 hex digits, chosen by the caller and used as the order's
1816
+ * cloid. A retry with the same id and the same request returns the original operation
1817
+ * (`replayed: true`) instead of placing another order; the same id with a different request is
1818
+ * refused (`PERPS_CLIENT_ID_CONFLICT`). It deduplicates, it does not resume: a retry never signs or
1819
+ * submits, so a build-only first call stays unsubmitted. Use a new id for a genuinely new order.
1820
+ */
1821
+ clientId?: string;
1802
1822
  }
1803
1823
  export interface PerpsCloseParams extends PerpsWalletRef {
1804
1824
  coin: string;
1805
1825
  /** Part of the position to close; the whole position when omitted. */
1806
1826
  size?: string;
1827
+ /**
1828
+ * Phase 1 D (spec 2026-10-17 D, section 8): a percentage of the position instead of a size, a
1829
+ * decimal string above 0 and at most 100 with at most four decimals. Sized by both the server and
1830
+ * this client from a direct position read: `floor(|szi| * pct / 100)` at the market's size step,
1831
+ * never rounded up. Exclusive with `size`.
1832
+ */
1833
+ pct?: string;
1807
1834
  slippageBps?: number;
1835
+ /** Optional client order id, as on `PerpsOpenParams.clientId`. */
1836
+ clientId?: string;
1808
1837
  }
1809
1838
  export interface PerpsCancelParams extends PerpsWalletRef {
1810
1839
  /** The cloid of an order Candle built (an open, or one of its take-profit / stop-loss legs). */
@@ -1818,7 +1847,12 @@ export interface PerpsModifyParams extends PerpsWalletRef {
1818
1847
  }
1819
1848
  export interface PerpsLeverageParams extends PerpsWalletRef {
1820
1849
  coin: string;
1821
- leverage: number;
1850
+ /**
1851
+ * Whole-number leverage. Phase 1 D (spec D, section 5): may be omitted when `mode` is named, and
1852
+ * then the account's current leverage is kept (read from Hyperliquid), never defaulted to 1. A
1853
+ * mode change needs no position and no resting order in the coin.
1854
+ */
1855
+ leverage?: number;
1822
1856
  mode?: "cross" | "isolated";
1823
1857
  }
1824
1858
  export interface PerpsMarginParams extends PerpsWalletRef {
@@ -1826,11 +1860,19 @@ export interface PerpsMarginParams extends PerpsWalletRef {
1826
1860
  /** USD, up to 6 decimals; negative removes isolated margin. */
1827
1861
  amount: string;
1828
1862
  }
1863
+ /** BE-1584: a scheduled cancel (spec D, section 7). `seconds` sets the venue's timer; `clear` disarms it. */
1864
+ export type PerpsScheduleCancelParams = PerpsWalletRef & ({
1865
+ seconds: number;
1866
+ clear?: undefined;
1867
+ } | {
1868
+ clear: true;
1869
+ seconds?: undefined;
1870
+ });
1829
1871
  /** What a perps build route returns: the plaintext action, its nonce, and the stamped typed data. */
1830
1872
  export interface PerpsBuild {
1831
1873
  success: true;
1832
1874
  perpOrderId: string;
1833
- kind: "open" | "close" | "modify" | "cancel" | "leverage" | "margin" | "setup";
1875
+ kind: "open" | "close" | "modify" | "cancel" | "leverage" | "margin" | "setup" | "tpsl" | "scheduleCancel";
1834
1876
  network: HyperliquidNetwork;
1835
1877
  walletId: string;
1836
1878
  address: string;
@@ -1849,6 +1891,9 @@ export interface PerpsBuild {
1849
1891
  feeTenthsBps: number;
1850
1892
  } | null;
1851
1893
  exchangeUrl: string;
1894
+ /** BE-1584: the key's reduce-only setting and policy version this build was judged under. Absent from an older API. */
1895
+ perpsReduceOnly?: boolean;
1896
+ perpsPolicyVersion?: number;
1852
1897
  preview: Record<string, unknown>;
1853
1898
  }
1854
1899
  /**
@@ -1858,11 +1903,150 @@ export interface PerpsBuild {
1858
1903
  * statuses for an order).
1859
1904
  */
1860
1905
  export interface PerpsActionResult {
1906
+ replayed?: false;
1861
1907
  build: PerpsBuild;
1862
1908
  signature: string | null;
1863
1909
  submitted: boolean;
1864
1910
  exchange: unknown | null;
1865
1911
  submitError?: string;
1912
+ /**
1913
+ * BE-1584 (spec D, section 3): Hyperliquid's answer judged per leg. `confirmed` only when the venue
1914
+ * said ok and no leg carries an error; HTTP 200 alone is not confirmation. Absent when nothing was
1915
+ * submitted.
1916
+ */
1917
+ outcome?: HyperliquidSubmitOutcome;
1918
+ /** A scheduled cancel: Candle recorded the venue's acknowledgement (not proof the timer will fire). */
1919
+ acknowledged?: boolean;
1920
+ /** A margin-mode change: the mode asked for, and the one Hyperliquid shows after the submit (null when unread). */
1921
+ requestedMode?: "cross" | "isolated";
1922
+ confirmedMode?: "cross" | "isolated" | null;
1923
+ }
1924
+ /** BE-1584 (spec D, section 9): the key's reduce-only setting. */
1925
+ export interface PerpsReduceOnlyResult {
1926
+ success: true;
1927
+ keyPrefix: string;
1928
+ perpsReduceOnly: boolean;
1929
+ perpsPolicyVersion: number;
1930
+ changed?: boolean;
1931
+ /** On enabling: what the setting does not do (no cancel, no revocation of signed actions, no other keys). */
1932
+ limits?: string[];
1933
+ }
1934
+ /**
1935
+ * The original operation a client order id already names, as `POST /perps/open` or `/perps/close`
1936
+ * returns it for a retry (spec 2026-10-17 C, section 8). Nothing signable: `status` is Candle's
1937
+ * record (`building` / `built` mean not yet seen on the venue), `venueStatus` what reconcile observed.
1938
+ */
1939
+ export interface PerpsReplay {
1940
+ success: true;
1941
+ replayed: true;
1942
+ perpOrderId: string;
1943
+ kind: "open" | "close";
1944
+ network: HyperliquidNetwork;
1945
+ walletId: string;
1946
+ address: string;
1947
+ clientId: string;
1948
+ cloid: string;
1949
+ childCloids: string[];
1950
+ nonce: number;
1951
+ status: string;
1952
+ venueStatus: string | null;
1953
+ filledSz: string | null;
1954
+ notionalUsdMicros: number | null;
1955
+ builtAt: number;
1956
+ settledAt: number | null;
1957
+ preview: Record<string, unknown> | null;
1958
+ }
1959
+ /** A retry under a client order id: the original operation, and nothing signed, submitted or charged. */
1960
+ export interface PerpsReplayResult {
1961
+ replayed: true;
1962
+ replay: PerpsReplay;
1963
+ build: null;
1964
+ signature: null;
1965
+ submitted: false;
1966
+ exchange: null;
1967
+ }
1968
+ /** `POST /agent/perps/withdraw`: a quote for a withdrawal to this key's own Solana or Hood TEE wallet. */
1969
+ export interface PerpsWithdrawBuildRequest {
1970
+ clientWithdrawalId: string;
1971
+ /**
1972
+ * USDC, a decimal string with at most 6 decimals, at least 10 USDC. The server refuses
1973
+ * `PERPS_WITHDRAW_BELOW_MINIMUM` under 10 USDC (`limit: "minimumAmount"`), and when Relay guarantees
1974
+ * under 5 USDC or its fees are above 5% of the amount (`limit: "minimum"`); Hyperliquid's one-time
1975
+ * 1 USDC activation fee on the account's first withdrawal or transfer does not count toward the 5%.
1976
+ */
1977
+ amountUsdc: string;
1978
+ to: "solana" | "hood";
1979
+ /** The key's EVM TEE wallet row id; the key's only one when omitted. */
1980
+ wallet?: string;
1981
+ }
1982
+ /** One withdrawal as the server records it, with Relay's live status on a read. */
1983
+ export interface PerpsWithdrawStatus {
1984
+ success: true;
1985
+ id: string;
1986
+ status: "quoted" | "authorized" | "submitted" | "settled" | "refunded" | "failed";
1987
+ from: {
1988
+ walletId: string;
1989
+ address: string;
1990
+ network: string;
1991
+ };
1992
+ to: {
1993
+ chain: "solana" | "hood";
1994
+ walletId: string;
1995
+ address: string;
1996
+ };
1997
+ amountUsdc: string;
1998
+ feesUsdc: string;
1999
+ netUsdc: string;
2000
+ minimumOutUsdc: string;
2001
+ relayRequestId: string;
2002
+ nonce: number;
2003
+ failureReason: string | null;
2004
+ relay?: {
2005
+ status: string | null;
2006
+ txHashes: string[];
2007
+ } | null;
2008
+ [key: string]: unknown;
2009
+ }
2010
+ /** The four withdraw routes, one call each. No check runs here: `perpsWithdraw()` runs them. */
2011
+ export interface CandlePerpsWithdraw {
2012
+ build(request: PerpsWithdrawBuildRequest): Promise<PerpsWithdrawBuild>;
2013
+ authorize(request: {
2014
+ clientWithdrawalId: string;
2015
+ signature: string;
2016
+ }): Promise<PerpsWithdrawAuthorization>;
2017
+ reportSubmitted(request: {
2018
+ clientWithdrawalId: string;
2019
+ exchangeResponse: unknown;
2020
+ }): Promise<PerpsWithdrawStatus>;
2021
+ get(clientWithdrawalId: string): Promise<PerpsWithdrawStatus>;
2022
+ }
2023
+ export interface CandlePerps {
2024
+ withdraw: CandlePerpsWithdraw;
2025
+ }
2026
+ export interface PerpsWithdrawParams extends Omit<PerpsWalletRef, "submit"> {
2027
+ amountUsdc: string;
2028
+ to: "solana" | "hood";
2029
+ /** Reuse on retry. A new id is generated when omitted. */
2030
+ clientWithdrawalId?: string;
2031
+ /** This key's EVM TEE wallet address: the HyperCore account the USDC leaves. */
2032
+ account: string;
2033
+ /**
2034
+ * This key's own wallet addresses on the chain asked for: its Solana TEE wallet for `solana`,
2035
+ * the EVM TEE wallet itself for `hood`. A build landing anywhere else is refused.
2036
+ */
2037
+ ownDestinations: string[];
2038
+ }
2039
+ /**
2040
+ * The outcome of `perpsWithdraw()`. `signature` is the SendAsset's, valid for resubmission until
2041
+ * its nonce leaves Hyperliquid's two-day window; a failed submit keeps it.
2042
+ */
2043
+ export interface PerpsWithdrawResult {
2044
+ build: PerpsWithdrawBuild;
2045
+ authorization: PerpsWithdrawAuthorization;
2046
+ signature: string;
2047
+ submitted: boolean;
2048
+ exchange: unknown | null;
2049
+ submitError?: string;
1866
2050
  }
1867
2051
  export interface PerpsAccountStatus {
1868
2052
  walletId: string;
@@ -1879,6 +2063,7 @@ export interface PerpsAccountStatus {
1879
2063
  export type PerpsSetupResult = PerpsAccountStatus & {
1880
2064
  ready: boolean;
1881
2065
  action?: PerpsActionResult;
2066
+ preview?: Record<string, unknown>;
1882
2067
  };
1883
2068
  export interface PerpsConfig {
1884
2069
  success: true;
@@ -1900,7 +2085,34 @@ export interface PerpsPositions {
1900
2085
  account: Record<string, string>;
1901
2086
  withdrawable: string;
1902
2087
  positions: Record<string, unknown>[];
2088
+ /**
2089
+ * BE-1582 (spec A-3): the section 4 table, account line and risk report, from a direct read of
2090
+ * Hyperliquid on this machine (the fields above are Candle's server read, unchanged). `rows` is
2091
+ * empty and `accountLine` null when that read failed or no level could be computed, and `risk`
2092
+ * then says why (`level: "unknown"`).
2093
+ */
2094
+ rows: PerpsPositionRow[];
2095
+ accountLine: PerpsAccountLine | null;
2096
+ risk: Omit<PerpsRiskReport, "positions">;
1903
2097
  }
2098
+ /** `GET /keys/self/limits`'s risk thresholds for the calling key (BE-1582, spec A-4). */
2099
+ export interface PerpsRiskSettingsResult {
2100
+ /** What the key stores, or null. */
2101
+ perpsRisk: PerpsRiskSettings | null;
2102
+ /** What the engine applies, and where it came from (`defaults (server did not report)` on an older API). */
2103
+ effective: PerpsRiskThresholdsReport;
2104
+ }
2105
+ /** `PUT /keys/self/perps-risk` or `/keys/:prefix/perps-risk`. */
2106
+ export interface PerpsRiskWriteResult {
2107
+ success: true;
2108
+ keyPrefix: string;
2109
+ perpsRisk: PerpsRiskSettings | null;
2110
+ effective: PerpsRiskThresholds;
2111
+ }
2112
+ /** A threshold write: each named field set (`null` clears that field), or `null` to clear them all. */
2113
+ export type PerpsRiskWrite = {
2114
+ [K in keyof PerpsRiskThresholds]?: number | null;
2115
+ } | null;
1904
2116
  export interface PerpsOrderRecord {
1905
2117
  perpOrderId: string;
1906
2118
  kind: PerpsBuild["kind"];
@@ -1908,6 +2120,8 @@ export interface PerpsOrderRecord {
1908
2120
  coin: string | null;
1909
2121
  nonce: number;
1910
2122
  cloid: string | null;
2123
+ /** The caller's client order id, on rows built with one (absent from an older API). */
2124
+ clientId?: string | null;
1911
2125
  childCloids: string[];
1912
2126
  targetCloid: string | null;
1913
2127
  status: string;
@@ -2016,7 +2230,6 @@ export interface PerpsDepositResult {
2016
2230
  /** `/perps/deposit/submit`'s final answer: `status: "submitted"` and the chain hashes. */
2017
2231
  result: Record<string, unknown> | null;
2018
2232
  }
2019
- /** Why a deposit build must not be signed, or null. */
2020
2233
  export declare function perpsDepositProblem(build: PerpsDepositBuild, params: PerpsDepositParams): string | null;
2021
2234
  /**
2022
2235
  * The base assets `swap()` converts between. Inlined rather than imported from `@candle/shared`'s
@@ -2537,7 +2750,14 @@ export declare class CandleClient {
2537
2750
  private readonly solanaRpcUrl?;
2538
2751
  private readonly evmRpcUrl?;
2539
2752
  private readonly hyperliquidNetwork;
2753
+ private perpsMarketReader?;
2540
2754
  private hyperliquidBuilder?;
2755
+ private readonly perpsWithdrawPins;
2756
+ /**
2757
+ * Hyperliquid withdrawals (spec 2026-10-17-hyperliquid-withdrawals-design.md): the routes, one call
2758
+ * each. Needs `perps:withdraw` on the key. `perpsWithdraw()` is the checked flow.
2759
+ */
2760
+ readonly perps: CandlePerps;
2541
2761
  /** Reads scoped to what this key may spend: a one-shot swap's receipt, and spendable balances. */
2542
2762
  readonly wallets: CandleWallets;
2543
2763
  /** The creator fees this account's launched tokens can pay, and the claim (FE-438). */
@@ -3246,6 +3466,14 @@ export declare class CandleClient {
3246
3466
  */
3247
3467
  private signBroadcastAndWaitEvmLeg;
3248
3468
  private broadcastAndWaitEvmLeg;
3469
+ /** Public Hyperliquid reads on this machine. A Candle key of any scope is required.
3470
+ * The only Candle call is perpsConfig(), once per client; market data is cached for 5 seconds.
3471
+ */
3472
+ private marketReader;
3473
+ perpsMarkets(opts?: PerpsMarketsOptions): Promise<PerpsMarketsResult>;
3474
+ perpsMarket(coin: string): Promise<PerpsMarketResult>;
3475
+ perpsBook(coin: string, opts?: PerpsBookOptions): Promise<PerpsBookResult>;
3476
+ perpsCandles(coin: string, opts?: PerpsCandlesOptions): Promise<PerpsCandlesResult>;
3249
3477
  /** The server's perps settings: network, Candle's builder, this key's fee, and its limits. */
3250
3478
  perpsConfig(): Promise<PerpsConfig>;
3251
3479
  /**
@@ -3253,24 +3481,56 @@ export declare class CandleClient {
3253
3481
  * it, and reports the account's mode and balance. Idempotent.
3254
3482
  */
3255
3483
  perpsSetup(params: PerpsWalletRef): Promise<PerpsSetupResult>;
3256
- /** Open (or add to) a position: build, check, sign through the relay, submit to Hyperliquid. */
3257
- perpsOpen(params: PerpsOpenParams): Promise<PerpsActionResult>;
3258
- /** Close all or part of a position with a reduce-only IOC order. Reserves nothing. */
3259
- perpsClose(params: PerpsCloseParams): Promise<PerpsActionResult>;
3484
+ /**
3485
+ * Open (or add to) a position: build, check, sign through the relay, submit to Hyperliquid. With
3486
+ * `clientId`, a retry of the same request returns the original operation (`replayed: true`).
3487
+ */
3488
+ perpsOpen(params: PerpsOpenParams & {
3489
+ clientId?: undefined;
3490
+ }): Promise<PerpsActionResult>;
3491
+ perpsOpen(params: PerpsOpenParams): Promise<PerpsActionResult | PerpsReplayResult>;
3492
+ /** Close all or part of a position with a reduce-only IOC order. Reserves nothing. Takes `clientId` as open does. */
3493
+ perpsClose(params: PerpsCloseParams & {
3494
+ clientId?: undefined;
3495
+ }): Promise<PerpsActionResult>;
3496
+ perpsClose(params: PerpsCloseParams): Promise<PerpsActionResult | PerpsReplayResult>;
3260
3497
  /** Cancel an order Candle built, by its cloid. */
3261
3498
  perpsCancel(params: PerpsCancelParams): Promise<PerpsActionResult>;
3262
3499
  /** Change a resting order's price or size. The replacement gets a new cloid. */
3263
3500
  perpsModify(params: PerpsModifyParams): Promise<PerpsActionResult>;
3264
- /** Set a market's leverage and margin mode on the account, within the key's maxLeverage. */
3501
+ /**
3502
+ * Set a market's leverage and margin mode on the account, within the key's maxLeverage. With
3503
+ * `mode` and no `leverage`, the current leverage is kept (spec D, section 5); a mode change needs
3504
+ * no position and no resting order in the coin. The answer reports the mode asked for and the one
3505
+ * Hyperliquid shows after the submit, separately.
3506
+ */
3265
3507
  perpsLeverage(params: PerpsLeverageParams): Promise<PerpsActionResult>;
3266
3508
  /** Add (positive) or remove (negative) isolated margin on an isolated position. */
3267
3509
  perpsMargin(params: PerpsMarginParams): Promise<PerpsActionResult>;
3268
- /** Positions and account value, read live from Hyperliquid by the wallet's address. */
3510
+ /**
3511
+ * Positions and account value, read live from Hyperliquid by the wallet's address. The server's
3512
+ * fields are unchanged; `rows`, `accountLine` and `risk` (BE-1582, spec A-3) come from a direct
3513
+ * read on this machine at the key's thresholds.
3514
+ */
3269
3515
  perpsPositions(walletId: string): Promise<PerpsPositions>;
3270
3516
  /** Open orders on Hyperliquid, and Candle's record of every action it built, settled first. */
3271
3517
  perpsOrders(walletId: string, opts?: {
3272
3518
  limit?: number;
3273
3519
  }): Promise<PerpsOrders>;
3520
+ /**
3521
+ * One page of the wallet's fills, read directly from Hyperliquid's `/info` (spec 2026-10-17 C,
3522
+ * sections 3 and 4). Candle resolves only the wallet's address; no Candle credential reaches
3523
+ * Hyperliquid, and a read-capable key is enough. Default window: the last seven days, fixed on the
3524
+ * first page; pass `nextCursor` back as `cursor` for the next one. Live venue data for this wallet,
3525
+ * not Candle's ledger and not an all-time total: Hyperliquid serves only the 10,000 most recent
3526
+ * fills. `closedPnl` is gross and `fee` already includes `builderFee`. Throws `PerpsHistoryError`.
3527
+ */
3528
+ perpsFillsPage(walletId: string, options?: PerpsHistoryOptions): Promise<PerpsFillsPage>;
3529
+ /** One page of the wallet's funding payments, as `perpsFillsPage()` reads fills. `delta.usdc` is signed: negative was paid. */
3530
+ perpsFundingPage(walletId: string, options?: PerpsHistoryOptions): Promise<PerpsFundingPage>;
3531
+ private perpsHistoryPage;
3532
+ /** The address of an EVM TEE wallet bound to this key, from Candle's own list of the key's wallets. */
3533
+ private perpsWalletAddress;
3274
3534
  /** Fills, read live from Hyperliquid by the wallet's address. */
3275
3535
  perpsFills(walletId: string): Promise<{
3276
3536
  success: true;
@@ -3282,6 +3542,70 @@ export declare class CandleClient {
3282
3542
  startTime: number;
3283
3543
  funding: Record<string, unknown>[];
3284
3544
  }>;
3545
+ /** The key's risk thresholds: stored and effective. An older API reports none: the defaults, sourced so. */
3546
+ getPerpsRisk(): Promise<PerpsRiskSettingsResult>;
3547
+ /**
3548
+ * Tighten the calling key's own thresholds (`PUT /keys/self/perps-risk`). Anything looser than
3549
+ * the effective set, including clearing a field stored stricter than its default, is refused with
3550
+ * 403 LOOSEN_REQUIRES_SESSION: the owner loosens with `setKeyPerpsRisk()`.
3551
+ */
3552
+ setPerpsRisk(fields: PerpsRiskWrite): Promise<PerpsRiskWriteResult>;
3553
+ /**
3554
+ * The owner's write on any of the account's keys (`PUT /keys/:prefix/perps-risk`): may loosen or
3555
+ * clear. Needs an owner credential, the CLI's device token or a Privy session token, sent as a
3556
+ * bearer token; the client's API key is not sent and would be refused.
3557
+ */
3558
+ setKeyPerpsRisk(keyPrefix: string, fields: PerpsRiskWrite, owner: {
3559
+ bearerToken: string;
3560
+ }): Promise<PerpsRiskWriteResult>;
3561
+ /**
3562
+ * One-shot risk (spec A-8): `ok`, `warn` or `critical` with its drivers, from a direct read of
3563
+ * Hyperliquid at the key's thresholds. `unknown` for a non-standard account mode or a stale read.
3564
+ * A failed venue read throws `HyperliquidReadError` (`code: "PERPS_READ_FAILED"`). Stateless: no
3565
+ * hysteresis (that is `watchPerpsRisk()`).
3566
+ */
3567
+ perpsRisk(params: {
3568
+ walletId: string;
3569
+ address?: string;
3570
+ }): Promise<PerpsRiskReport>;
3571
+ /**
3572
+ * The account line (spec A-10): account value, margin, free margin, withdrawable, the margin
3573
+ * ratio, and realized P&L, fees and funding over a recent window (`since`, epoch ms; default the
3574
+ * last 24 hours, at most 30 days).
3575
+ */
3576
+ perpsAccount(params: {
3577
+ walletId: string;
3578
+ address?: string;
3579
+ since?: number;
3580
+ }): Promise<PerpsAccountReport>;
3581
+ /**
3582
+ * The loop `candle perps watch` runs (spec A-9): polls Hyperliquid every `intervalMs` (default
3583
+ * 10 s), calls `onEvent` with a start event, one event per level change (rising immediately,
3584
+ * falling past the clear band), heartbeats and errors, and resolves with the last level when
3585
+ * `signal` aborts. Candle is asked for thresholds at start and every 5 minutes only.
3586
+ */
3587
+ watchPerpsRisk(params: {
3588
+ walletId: string;
3589
+ address?: string;
3590
+ intervalMs?: number;
3591
+ heartbeatMs?: number;
3592
+ signal?: AbortSignal;
3593
+ onceLevelChange?: boolean;
3594
+ onEvent: (event: PerpsWatchEvent) => void | Promise<void>;
3595
+ }): Promise<{
3596
+ level: PerpsRiskReport["level"];
3597
+ }>;
3598
+ /**
3599
+ * The portfolio's Hyperliquid section (spec A-11) for EVM TEE addresses: account value, unrealized
3600
+ * P&L, positions and level at the default thresholds per account, and a subtotal. Live from
3601
+ * Hyperliquid and never part of any portfolio total.
3602
+ */
3603
+ perpsPortfolioSection(wallets: readonly {
3604
+ address: string;
3605
+ label?: string;
3606
+ walletId?: string;
3607
+ }[]): Promise<PerpsPortfolioSection>;
3608
+ private perpsThresholdsOrDefaults;
3285
3609
  /**
3286
3610
  * Deposit onto the key's Hyperliquid account through Relay (Perps C, HL-ED-8): build, check the
3287
3611
  * build names `account` on chain 1337 with no Candle fee, then sign through the relay and submit.
@@ -3298,11 +3622,65 @@ export declare class CandleClient {
3298
3622
  }>;
3299
3623
  /** The builder every perps build is checked against (see `hyperliquidBuilder` in the options). */
3300
3624
  private perpsBuilder;
3625
+ private perpsBuilderTrust;
3301
3626
  /**
3302
3627
  * Check, sign, submit (HL-ED-2, HL-ED-5). The check runs before the relay is called; a build
3303
- * that fails it is refused with nothing signed.
3628
+ * that fails it is refused with nothing signed. BE-1584: every method is checked against this
3629
+ * machine's own read of Hyperliquid (`verifyPerpsBuildAgainstVenue`), and the venue's answer is
3630
+ * judged per leg (`outcome`).
3304
3631
  */
3305
3632
  private perpsComplete;
3633
+ /**
3634
+ * Schedule Hyperliquid's cancel-all timer `seconds` from now (at least 5), or clear it. The timer
3635
+ * is wallet-wide: it cancels every open order on the account, protection included, and no
3636
+ * positions. Candle fixes the time at build and this client refuses to sign one less than five
3637
+ * seconds ahead. An acknowledged set is recorded on Candle (`acknowledged`); no public read can
3638
+ * confirm the timer, and Hyperliquid's 10 triggers per UTC day are never counted here.
3639
+ */
3640
+ perpsScheduleCancel(params: PerpsScheduleCancelParams): Promise<PerpsActionResult>;
3641
+ /**
3642
+ * Attach, change or remove the position's take-profit and stop-loss (spec D, section 6): each leg
3643
+ * a reducing market trigger sized to the position now. A change cancels the old leg first (a
3644
+ * protection gap, named in `warnings`), confirms it gone, re-reads, then places the new one; a
3645
+ * partial result is reported as `complete: false`. Legs Candle did not build are listed in
3646
+ * `unowned` and never touched. Calling this is the caller's intent; there is no prompt.
3647
+ */
3648
+ perpsTpsl(params: PerpsWalletRef & PerpsTpslParams): Promise<PerpsWorkflowResult>;
3649
+ /**
3650
+ * Cancel every open main-perp order on the wallet, then close every main-perp position (spec D,
3651
+ * section 8). At most 100 signed steps per call; `complete` only when a final read shows nothing
3652
+ * left. Spot, HIP-3 and vault exposure is out of scope (`scope: "main-perps"`).
3653
+ */
3654
+ perpsFlatten(params: PerpsWalletRef): Promise<PerpsWorkflowResult>;
3655
+ private perpsWorkflowIo;
3656
+ /** The calling key's perps reduce-only setting (`GET /keys/self/perps-reduce-only`). Throws on a failed read. */
3657
+ getPerpsReduceOnly(): Promise<PerpsReduceOnlyResult>;
3658
+ /**
3659
+ * Turn the calling key's perps reduce-only on (`PUT /keys/self/perps-reduce-only`). The key can
3660
+ * never turn it off (403 LOOSEN_REQUIRES_SESSION): the owner does that with `setKeyPerpsReduceOnly()`.
3661
+ * It constrains future Candle builds only: resting orders stay, signed actions stay valid.
3662
+ */
3663
+ setPerpsReduceOnly(perpsReduceOnly: true): Promise<PerpsReduceOnlyResult>;
3664
+ /**
3665
+ * The owner's write on any of the account's keys (`PUT /keys/:prefix/perps-reduce-only`): on or
3666
+ * off. Needs an owner credential (the CLI's device token or a Privy session token), sent as a
3667
+ * bearer token; the client's API key is not sent and would be refused.
3668
+ */
3669
+ setKeyPerpsReduceOnly(keyPrefix: string, perpsReduceOnly: boolean, owner: {
3670
+ bearerToken: string;
3671
+ }): Promise<PerpsReduceOnlyResult>;
3672
+ /**
3673
+ * Withdraw USDC from the key's Hyperliquid account to the same key's own Solana or Hood TEE wallet
3674
+ * through Relay (spec 2026-10-17, route A). MOVES REAL FUNDS. Needs `perps:withdraw`.
3675
+ *
3676
+ * Every signature is checked first, and a mismatch throws with nothing signed: the NonceMapping
3677
+ * names this key's account and Relay's request, the build lands on one of `ownDestinations`, and
3678
+ * Relay's own record of the request names that same recipient; then the SendAsset carries the
3679
+ * mapping's nonce, the exact amount asked for, and the pinned token, dex and depository. The
3680
+ * client posts the SendAsset to Hyperliquid itself and reports the answer. There is no
3681
+ * confirmation gate here: the CLI has one (`candle perps withdraw`).
3682
+ */
3683
+ perpsWithdraw(params: PerpsWithdrawParams): Promise<PerpsWithdrawResult>;
3306
3684
  /**
3307
3685
  * Sign EIP-712 typed data with a linked EVM TEE wallet through the relay
3308
3686
  * (`eth_signTypedData_v4`). The relay signs only typed data a perps build stamped.
@@ -3351,7 +3729,7 @@ export declare function __setEvmReceiptWaitForTest(opts: {
3351
3729
  pollMs?: number;
3352
3730
  } | null): void;
3353
3731
  /** This build's own version. Kept in lockstep with package.json by the release-bump CI guard. */
3354
- export declare const SDK_VERSION = "0.6.2";
3732
+ export declare const SDK_VERSION = "0.6.3";
3355
3733
  /** Test seam: the once-per-process latch would otherwise weld the suite's first case to the rest. */
3356
3734
  export declare function __resetSdkUpdateNoticeForTest(): void;
3357
3735
  //# sourceMappingURL=client.d.ts.map