@totalis/hip4-client 0.129.0 → 0.131.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/dist/singles.d.ts CHANGED
@@ -236,7 +236,10 @@ export declare function approveBuilderFeeTypedData(action: ApproveBuilderFeeActi
236
236
  * An agent key for `account` under `agentName`: it can place and cancel
237
237
  * orders, never withdraw or transfer. Approving a name the account already
238
238
  * uses replaces that agent; an account holds a few named agents at most. The
239
- * Totalis app uses `Totalis` and `TotalisCLI`; pick your own name.
239
+ * Totalis app uses `Totalis` and `TotalisCLI`; pick your own name. Approve a
240
+ * freshly generated key each time, never one approved before: once
241
+ * Hyperliquid prunes an agent its used nonces may go too, and anything the key
242
+ * signed before can then be replayed.
240
243
  */
241
244
  export declare function approveAgentAction(network: HyperliquidNetwork, agentAddress: string, agentName: string, nonce?: number): ApproveAgentAction;
242
245
  export declare function approveAgentTypedData(action: ApproveAgentAction): TypedData;
package/dist/singles.js CHANGED
@@ -326,7 +326,10 @@ export function approveBuilderFeeTypedData(action) {
326
326
  * An agent key for `account` under `agentName`: it can place and cancel
327
327
  * orders, never withdraw or transfer. Approving a name the account already
328
328
  * uses replaces that agent; an account holds a few named agents at most. The
329
- * Totalis app uses `Totalis` and `TotalisCLI`; pick your own name.
329
+ * Totalis app uses `Totalis` and `TotalisCLI`; pick your own name. Approve a
330
+ * freshly generated key each time, never one approved before: once
331
+ * Hyperliquid prunes an agent its used nonces may go too, and anything the key
332
+ * signed before can then be replayed.
330
333
  */
331
334
  export function approveAgentAction(network, agentAddress, agentName, nonce = hypercoreNonce()) {
332
335
  if (!/^0x[0-9a-fA-F]{40}$/.test(agentAddress))
package/dist/totalis.d.ts CHANGED
@@ -6,6 +6,7 @@ import { BalanceUnknownError, EntryError, ExitUnavailableError, WalletApprovalEr
6
6
  import { ApiError, NetworkError, type RetryPolicy } from "./request.js";
7
7
  import { type SignerInput } from "./signer.js";
8
8
  import { TotalisStream, type StreamEvent, type StreamOptions, type StreamSubscription } from "./stream.js";
9
+ import { type OrderHistoryCursor, type SingleOrderOutcome, type SingleOrderRecord } from "./single-orders.js";
9
10
  import { type Hex } from "./typed-data.js";
10
11
  type Json<T> = T extends {
11
12
  readonly content: {
@@ -356,6 +357,11 @@ export declare function createTotalis(options: TotalisOptions): {
356
357
  readonly info?: HyperliquidInfo;
357
358
  readonly signal?: AbortSignal;
358
359
  }) => Promise<ComboCash>;
360
+ readOrderHistory: (signal?: AbortSignal) => Promise<OrderHistoryCursor>;
361
+ settleSingleOrder: (record: SingleOrderRecord, options?: {
362
+ readonly info?: HyperliquidInfo;
363
+ readonly signal?: AbortSignal;
364
+ }) => Promise<SingleOrderOutcome>;
359
365
  openPosition: (request: {
360
366
  readonly legs: readonly Leg[];
361
367
  readonly stake: Amount;
package/dist/totalis.js CHANGED
@@ -9,6 +9,8 @@ import { abortReason, anySignal, timeoutSignal } from "./runtime.js";
9
9
  import { toTotalisSigner } from "./signer.js";
10
10
  import { TotalisStream } from "./stream.js";
11
11
  import { items } from "./pagination.js";
12
+ import { orderHistoryCursor, outcomeOf, proofWindow } from "./single-orders.js";
13
+ import { outcomeCoin, readSingleOrder } from "./singles.js";
12
14
  import { address, agentGrantTypedData, exitTypedData, receiveWithAuthorizationTypedData, sellBackTypedData, takerAcceptTypedData, payoutNonce, transferWithAuthorizationTypedData, walletPermitTypedData, } from "./typed-data.js";
13
15
  /** The approval asked when the approval left falls short: 10,000 USDC, or the shortfall when it is larger. */
14
16
  export const defaultWalletApproval = 10000000000n;
@@ -467,6 +469,36 @@ export function createTotalis(options) {
467
469
  offeredCore: offered, allowance: comboAllowance({ vault: venue.vault, wallet: venue.wallet, core: offered }),
468
470
  };
469
471
  }
472
+ /**
473
+ * Where the node order history that proves IOCs stands for this session's
474
+ * account on this deployment's network (`GET /v1/hypercore/order-history`).
475
+ * Read it in the background and keep the latest for `placeSingleIoc`'s
476
+ * `history`, never on the way to signing; drop it when the account or
477
+ * network changes.
478
+ */
479
+ async function readOrderHistory(signal) {
480
+ const [chain, cursor] = await Promise.all([deployment(), client.GET("/v1/hypercore/order-history", signal === undefined ? {} : { signal }).then(unwrap)]);
481
+ return orderHistoryCursor(cursor, chain.chain_id);
482
+ }
483
+ /**
484
+ * Settle a saved IOC by evidence, signing and sending nothing: the venue's
485
+ * proof from its node order history, then Hyperliquid's `orderStatus` by
486
+ * its cloid (through `info`), read after it so that a lookup counted after
487
+ * the deadline was made after it (`singleOrderOutcome`). The session must
488
+ * be the record's account. Throws when neither read answered.
489
+ */
490
+ async function settleSingleOrder(record, options = {}) {
491
+ if ((await deployment()).chain_id !== String(record.chainId))
492
+ throw new Error(`this order was placed on chain ${record.chainId}, not this deployment's`);
493
+ const signal = options.signal === undefined ? {} : { signal: options.signal };
494
+ const { nonce, afterHeight } = proofWindow(record);
495
+ const query = { coin: outcomeCoin(record.outcomeId, record.side), nonce, expires_after: record.expiresAfter, ...(afterHeight === null ? {} : { after_height: afterHeight }) };
496
+ const proof = await client.GET("/v1/hypercore/orders/{cloid}", { params: { path: { cloid: record.cloid }, query }, ...signal }).then(unwrap).then((value) => ({ value }), (error) => ({ error }));
497
+ const status = await readSingleOrder(hyperliquidNetwork(record.chainId), record.account, record.cloid, options.info, options.signal).then((value) => ({ value }), (error) => ({ error }));
498
+ if ("error" in proof && "error" in status)
499
+ throw proof.error;
500
+ return outcomeOf(record, { ...("value" in status ? { status: status.value } : {}), ...("value" in proof ? { proof: proof.value } : {}) }, "value" in status);
501
+ }
470
502
  /** The wallet's USDC authorization of `value` into the vault; the venue fills `account` and `from` with the same wallet. */
471
503
  /** The body names the signed ReceiveWithAuthorization's `value` `amount`. */
472
504
  async function depositAuthorization(chain, account, value) {
@@ -1608,6 +1640,8 @@ export function createTotalis(options) {
1608
1640
  /** What the account holds at Totalis, every amount read at one block (`GET /v1/me/account-value`). */
1609
1641
  accountValue: readAccountValue,
1610
1642
  readComboCash,
1643
+ readOrderHistory,
1644
+ settleSingleOrder,
1611
1645
  openPosition,
1612
1646
  cashOut,
1613
1647
  prepareEntryFunding,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totalis/hip4-client",
3
- "version": "0.129.0",
3
+ "version": "0.131.0",
4
4
  "description": "Totalis HIP-4 SDK: typed HTTP clients, signer-agnostic typed data, a retrying request layer, pagination, a realtime stream and taker/maker flows",
5
5
  "type": "module",
6
6
  "files": [
@@ -85,6 +85,7 @@
85
85
  "directory": "clients/typescript"
86
86
  },
87
87
  "dependencies": {
88
+ "@noble/curves": "1.9.7",
88
89
  "@noble/hashes": "1.8.0",
89
90
  "openapi-fetch": "0.17.0"
90
91
  },