@polyester/sdk 0.35.0-devnet-20261111024759 → 0.35.0-devnet-20261111031027
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/CHANGELOG.md +19 -1
- package/dist/catalogs/index.d.ts +2 -2
- package/dist/catalogs/snapshot-validation.js +5 -2
- package/dist/catalogs/snapshot-validation.js.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.d.ts +5 -1
- package/dist/gen/auth/v1/api_keys_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
- package/dist/gen/auth/v1/auth_pb.d.ts +8 -1
- package/dist/gen/auth/v1/auth_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/auth_pb.js +8 -1
- package/dist/gen/auth/v1/auth_pb.js.map +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +116 -8
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js +102 -3
- package/dist/gen/auth/v1/policies_pb.js.map +1 -1
- package/dist/gen/auth/v1/profile_pb.d.ts +4 -2
- package/dist/gen/auth/v1/profile_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/profile_pb.js.map +1 -1
- package/dist/gen/auth/v1/resolve_pb.d.ts +1 -0
- package/dist/gen/auth/v1/resolve_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/resolve_pb.js.map +1 -1
- package/dist/gen/auth/v1/social_verification_pb.d.ts +3 -0
- package/dist/gen/auth/v1/social_verification_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/social_verification_pb.js.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.d.ts +8 -3
- package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +2 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts.map +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js.map +1 -1
- package/dist/gen/chain/zipper/v1/zipper_pb.d.ts +57 -3
- package/dist/gen/chain/zipper/v1/zipper_pb.d.ts.map +1 -1
- package/dist/gen/chain/zipper/v1/zipper_pb.js +41 -3
- package/dist/gen/chain/zipper/v1/zipper_pb.js.map +1 -1
- package/dist/gen/checkpoints/v1/checkpoints_pb.d.ts +2 -1
- package/dist/gen/checkpoints/v1/checkpoints_pb.d.ts.map +1 -1
- package/dist/gen/checkpoints/v1/checkpoints_pb.js.map +1 -1
- package/dist/gen/claims/v1/claims_pb.d.ts +19 -2
- package/dist/gen/claims/v1/claims_pb.d.ts.map +1 -1
- package/dist/gen/claims/v1/claims_pb.js +11 -2
- package/dist/gen/claims/v1/claims_pb.js.map +1 -1
- package/dist/gen/ledger/v1/catalog_pb.d.ts +44 -1
- package/dist/gen/ledger/v1/catalog_pb.d.ts.map +1 -1
- package/dist/gen/ledger/v1/catalog_pb.js +44 -1
- package/dist/gen/ledger/v1/catalog_pb.js.map +1 -1
- package/dist/gen/marketdata/v1/heatmap_pb.d.ts +6 -0
- package/dist/gen/marketdata/v1/heatmap_pb.d.ts.map +1 -1
- package/dist/gen/marketdata/v1/heatmap_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +25 -4
- package/dist/gen/orders/v1/orders_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_pb.js +18 -5
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/rewards/v1/rewards_pb.d.ts +74 -3
- package/dist/gen/rewards/v1/rewards_pb.d.ts.map +1 -1
- package/dist/gen/rewards/v1/rewards_pb.js +16 -4
- package/dist/gen/rewards/v1/rewards_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts +145 -3
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js +27 -3
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts +48 -19
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js +3 -1
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js.map +1 -1
- package/dist/gen/transfer/v1/internal_transfer_pb.d.ts +101 -2
- package/dist/gen/transfer/v1/internal_transfer_pb.d.ts.map +1 -1
- package/dist/gen/transfer/v1/internal_transfer_pb.js +14 -2
- package/dist/gen/transfer/v1/internal_transfer_pb.js.map +1 -1
- package/dist/gen/vip/v1/vip_pb.d.ts +1 -0
- package/dist/gen/vip/v1/vip_pb.d.ts.map +1 -1
- package/dist/gen/vip/v1/vip_pb.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/realtime/private-orders.d.ts.map +1 -1
- package/dist/realtime/private-orders.js +24 -3
- package/dist/realtime/private-orders.js.map +1 -1
- package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +19 -19
- package/dist/services/checkpoints/checkpoints.schemas.d.ts +2 -2
- package/dist/services/claims/claims.d.ts +5 -2
- package/dist/services/claims/claims.d.ts.map +1 -1
- package/dist/services/claims/claims.js +5 -2
- package/dist/services/claims/claims.js.map +1 -1
- package/dist/services/heatmap/heatmap.schemas.d.ts +4 -4
- package/dist/services/internal-transfers/internal-transfers.d.ts +13 -4
- package/dist/services/internal-transfers/internal-transfers.d.ts.map +1 -1
- package/dist/services/internal-transfers/internal-transfers.js +17 -3
- package/dist/services/internal-transfers/internal-transfers.js.map +1 -1
- package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +59 -4
- package/dist/services/internal-transfers/internal-transfers.schemas.d.ts.map +1 -1
- package/dist/services/internal-transfers/internal-transfers.schemas.js +32 -2
- package/dist/services/internal-transfers/internal-transfers.schemas.js.map +1 -1
- package/dist/services/internal-transfers/internal-transfers.types.d.ts +2 -2
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +2 -2
- package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
- package/dist/services/orders/order-errors.schemas.d.ts +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +27 -27
- package/dist/services/orders/orders-input.schemas.d.ts +3 -3
- package/dist/services/orders/orders-output.schemas.d.ts +19 -19
- package/dist/services/orders/orders.d.ts +2 -0
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +2 -0
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -15
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.js +1 -1
- package/dist/services/policies/shared.codecs.js +64 -3
- package/dist/services/policies/shared.codecs.js.map +1 -1
- package/dist/services/policies/shared.d.ts +1 -1
- package/dist/services/policies/shared.d.ts.map +1 -1
- package/dist/services/policies/shared.js +5 -14
- package/dist/services/policies/shared.js.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +3 -3
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js +3 -3
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js.map +1 -1
- package/dist/services/rewards/rewards.d.ts +13 -3
- package/dist/services/rewards/rewards.d.ts.map +1 -1
- package/dist/services/rewards/rewards.js +17 -3
- package/dist/services/rewards/rewards.js.map +1 -1
- package/dist/services/rewards/rewards.schemas.d.ts +98 -1
- package/dist/services/rewards/rewards.schemas.d.ts.map +1 -1
- package/dist/services/rewards/rewards.schemas.js +12 -2
- package/dist/services/rewards/rewards.schemas.js.map +1 -1
- package/dist/services/rewards/rewards.types.d.ts +2 -2
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +7 -7
- package/dist/services/trades/trades.schemas.d.ts +2 -2
- package/dist/services/transfers/transfers.schemas.d.ts +4 -4
- package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
- package/dist/services/triggers/triggers-output.schemas.d.ts +30 -30
- package/dist/services/zipper/zipper.schemas.d.ts +2 -2
- package/dist/services/zipper/zipper.schemas.d.ts.map +1 -1
- package/dist/services/zipper/zipper.schemas.js +13 -2
- package/dist/services/zipper/zipper.schemas.js.map +1 -1
- package/dist/services/zipper/zipper.types.d.ts +2 -2
- package/dist/shared/catalog-config.d.ts +13 -1
- package/dist/shared/catalog-config.d.ts.map +1 -1
- package/dist/shared/catalog-config.js +7 -1
- package/dist/shared/catalog-config.js.map +1 -1
- package/dist/shared/connect-error-mapping.d.ts.map +1 -1
- package/dist/shared/connect-error-mapping.js +5 -1
- package/dist/shared/connect-error-mapping.js.map +1 -1
- package/dist/shared/error-detail.d.ts +2 -0
- package/dist/shared/error-detail.d.ts.map +1 -1
- package/dist/shared/error-detail.js.map +1 -1
- package/dist/shared/error-details/claims.js +7 -2
- package/dist/shared/error-details/claims.js.map +1 -1
- package/dist/shared/errors.d.ts +20 -3
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +17 -1
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/ledger-codes.d.ts +5 -1
- package/dist/shared/ledger-codes.d.ts.map +1 -1
- package/dist/shared/ledger-codes.js +24 -3
- package/dist/shared/ledger-codes.js.map +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,11 @@ const BACKOFF_MAX_MS = 1e4;
|
|
|
12
12
|
const STABLE_CONNECTION_MS = 1e4;
|
|
13
13
|
/** A malformed frame (4400) and a rejected connect token (4403) recur on every reconnect. */
|
|
14
14
|
const TERMINAL_CLOSE_CODES = /* @__PURE__ */ new Set([4400, 4403]);
|
|
15
|
+
/** Larger frames are dropped undecoded with the connection; a full 256-order page is far smaller. */
|
|
16
|
+
const MAX_PRIVATE_FRAME_BYTES = 4194304;
|
|
17
|
+
/** A snapshot staging more pages than this ends its subscription, so a snapshot never ending stays bounded. */
|
|
18
|
+
const MAX_SNAPSHOT_BYTES = 67108864;
|
|
19
|
+
const MAX_SNAPSHOT_ORDERS = 1e5;
|
|
15
20
|
/** 0.5 s doubling to 10 s, jittered over the upper half of each step. */
|
|
16
21
|
function backoffMs(attempt) {
|
|
17
22
|
const ceiling = Math.min(BACKOFF_MAX_MS, BACKOFF_BASE_MS * 2 ** (attempt + 1));
|
|
@@ -73,6 +78,7 @@ var PrivateOrderStream = class {
|
|
|
73
78
|
seq: 0n,
|
|
74
79
|
cursor: "",
|
|
75
80
|
staged: null,
|
|
81
|
+
stagedBytes: 0,
|
|
76
82
|
orders: null,
|
|
77
83
|
state: "pending",
|
|
78
84
|
stale: null,
|
|
@@ -293,6 +299,11 @@ var PrivateOrderStream = class {
|
|
|
293
299
|
this.#reportAll("decode", new RealtimeError("Expected a binary private WebSocket frame"));
|
|
294
300
|
return;
|
|
295
301
|
}
|
|
302
|
+
if (data.byteLength > 4194304) {
|
|
303
|
+
this.#reportAll("decode", new RealtimeError(`Private WebSocket frame of ${data.byteLength} bytes exceeds ${MAX_PRIVATE_FRAME_BYTES}`));
|
|
304
|
+
this.#drop(ws, 1009, "frame too large");
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
296
307
|
let msg;
|
|
297
308
|
try {
|
|
298
309
|
msg = fromBinary(ServerMessageSchema, new Uint8Array(data));
|
|
@@ -351,10 +362,20 @@ var PrivateOrderStream = class {
|
|
|
351
362
|
switch (frame.case) {
|
|
352
363
|
case "snapshotBegin":
|
|
353
364
|
s.staged = [];
|
|
365
|
+
s.stagedBytes = 0;
|
|
354
366
|
return;
|
|
355
|
-
case "snapshotPage":
|
|
356
|
-
s.staged
|
|
367
|
+
case "snapshotPage": {
|
|
368
|
+
if (!s.staged) return;
|
|
369
|
+
s.stagedBytes += data.byteLength;
|
|
370
|
+
const count = s.staged.length + frame.value.orders.length;
|
|
371
|
+
if (s.stagedBytes > 67108864 || count > 1e5) {
|
|
372
|
+
s.staged = null;
|
|
373
|
+
this.#terminate(s, "snapshot", new RealtimeError(`Private order snapshot exceeds ${MAX_SNAPSHOT_ORDERS} orders or ${MAX_SNAPSHOT_BYTES} bytes`));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
s.staged.push(...frame.value.orders);
|
|
357
377
|
return;
|
|
378
|
+
}
|
|
358
379
|
case "snapshotEnd": {
|
|
359
380
|
const orders = s.staged;
|
|
360
381
|
s.staged = null;
|
|
@@ -589,6 +610,6 @@ var PrivateOrderStream = class {
|
|
|
589
610
|
}
|
|
590
611
|
};
|
|
591
612
|
//#endregion
|
|
592
|
-
export { PRIVATE_WS_SUBPROTOCOL, PrivateOrderStream };
|
|
613
|
+
export { MAX_PRIVATE_FRAME_BYTES, MAX_SNAPSHOT_BYTES, MAX_SNAPSHOT_ORDERS, PRIVATE_WS_SUBPROTOCOL, PrivateOrderStream };
|
|
593
614
|
|
|
594
615
|
//# sourceMappingURL=private-orders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-orders.js","names":["#config","#subs","#pending","#bySub","#unsubscribing","#catchUp","#remove","#ws","#authSent","#subscribe","#connecting","#reconnectTimer","#open","#clearRetry","#shutdown","#isCurrent","#deliverTo","#terminateAll","#generation","#authenticate","#onFrame","#onClosed","#reportAll","#scheduleReconnect","#send","#authSentAt","#armHeartbeat","#reauthenticate","#nextRequestId","#terminate","#report","#retrySubscribe","#refresh","#unsubscribe","#deliver","#onRequestError","#resubscribe","#detach","#reconnectAttempt","#heartbeatTimer","#drop","#teardown","#call","#requestSeq"],"sources":["../../src/realtime/private-orders.ts"],"sourcesContent":["import { create, fromBinary, toBinary, type MessageInitShape } from \"@bufbuild/protobuf\";\nimport type { Order } from \"../gen/orders/v1/orders_read_pb.js\";\nimport {\n Channel,\n ClientMessageSchema,\n RequestError_Code,\n ServerMessageSchema,\n type Unit,\n} from \"../gen/privatews/v1/private_ws_pb.js\";\nimport { ConfigurationError, PolyesterError, RealtimeError } from \"../shared/errors.js\";\nimport {\n createSdkSubscriptionErrorContext,\n publicationHandlerErrorContext,\n type SdkSubscriptionErrorContext,\n} from \"../shared/subscription-errors.js\";\nimport { idToBigInt } from \"../utils/base58-id.js\";\n\nexport const PRIVATE_WS_SUBPROTOCOL = \"polyester.v1.proto\";\nconst HEARTBEAT_TIMEOUT_MS = 3_000;\nconst BACKOFF_BASE_MS = 500;\nconst BACKOFF_MAX_MS = 10_000;\n/** A connection that stayed up this long resets the reconnect backoff. */\nconst STABLE_CONNECTION_MS = 10_000;\n/** A malformed frame (4400) and a rejected connect token (4403) recur on every reconnect. */\nconst TERMINAL_CLOSE_CODES = new Set([4400, 4403]);\n\n/** One delivery of an account's order stream. */\nexport type PrivateOrdersEvent =\n /** The account's full live view; replace local state with it. */\n | { type: \"snapshot\"; orders: Order[] }\n /** One change, applied whole. */\n | { type: \"unit\"; unit: Unit }\n /**\n * The account's live view is temporarily behind (`true`) or caught up (`false`).\n * `orderIds`, when set, names the only orders behind; the rest of the view is current.\n */\n | { type: \"stale\"; stale: boolean; orderIds?: bigint[] };\n\nexport interface ConnectPrivateOrdersParams {\n /** The account's base58 public ID. */\n accountId: string;\n onEvent: (event: PrivateOrdersEvent) => void;\n /** Called when the server confirms the subscription, again after each reconnect. */\n onConnected?: () => void;\n /** Called when the connection carrying the subscription drops. */\n onDisconnected?: () => void;\n onError?: (ctx: SdkSubscriptionErrorContext) => void;\n}\n\nexport interface PrivateOrderStreamConfig {\n url: string;\n fetchConnectToken: () => Promise<string>;\n fetchSubscribeToken: (channel: string) => Promise<string>;\n}\n\ntype ClientOp = MessageInitShape<typeof ClientMessageSchema>[\"op\"];\n\ninterface Consumer {\n params: ConnectPrivateOrdersParams;\n /** False until a consumer that joined a running subscription received its current state. */\n caughtUp: boolean;\n}\n\n/** One server subscription per account, shared by every consumer of that account. */\ninterface StreamSubscription {\n consumers: Set<Consumer>;\n channel: string;\n account: bigint;\n /** Server subscription ID; empty until Subscribed. */\n sub: string;\n seq: bigint;\n /** Last applied resume position, carried across resubscribes and reconnects. */\n cursor: string;\n staged: Order[] | null;\n /** The account's live view as last applied, for consumers that join later; null before the first snapshot. */\n orders: Map<bigint, Order> | null;\n /** The last connection state consumers were told about. */\n state: \"pending\" | \"connected\" | \"disconnected\";\n /** What consumers were last told is stale, until they are told it caught up. */\n stale: { orderIds?: bigint[] } | null;\n /** Subscribe attempts since the subscription last delivered data; drives retry backoff. */\n retries: number;\n retryTimer: ReturnType<typeof setTimeout> | null;\n}\n\ntype PendingRequest = { kind: \"subscribe\" | \"refresh\"; s: StreamSubscription };\n\n/** 0.5 s doubling to 10 s, jittered over the upper half of each step. */\nfunction backoffMs(attempt: number): number {\n const ceiling = Math.min(BACKOFF_MAX_MS, BACKOFF_BASE_MS * 2 ** (attempt + 1));\n return ceiling / 2 + Math.random() * (ceiling / 2);\n}\n\nfunction isTerminalTokenError(error: unknown): boolean {\n return error instanceof PolyesterError && !error.retryable;\n}\n\n/**\n * Account order streams over the private WebSocket (`/v1/ws/private`). One\n * connection carries every subscription; each resumes from its last cursor\n * after a gap, an expired token, or a reconnect.\n */\nexport class PrivateOrderStream {\n readonly #config: PrivateOrderStreamConfig;\n /** Keyed by channel. A subscription whose last consumer left stays until the next microtask. */\n readonly #subs = new Map<string, StreamSubscription>();\n readonly #pending = new Map<string, PendingRequest>();\n readonly #bySub = new Map<string, StreamSubscription>();\n /** IDs of Unsubscribe requests awaiting their answer. */\n readonly #unsubscribing = new Set<string>();\n #ws: WebSocket | null = null;\n /** A connect token fetch for the next socket is in flight. */\n #connecting = false;\n /** Bumped on shutdown so a token fetch that outlived it opens nothing. */\n #generation = 0;\n #authSent = false;\n #authSentAt = 0;\n #reconnectAttempt = 0;\n #reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n #heartbeatTimer: ReturnType<typeof setTimeout> | null = null;\n #requestSeq = 0;\n\n constructor(config: PrivateOrderStreamConfig) {\n this.#config = config;\n }\n\n /** Throws ValidationError when accountId is not a base58 public ID. */\n connect(params: ConnectPrivateOrdersParams): () => void {\n const channel = `private:spot:orders:${params.accountId}`;\n const account = idToBigInt(params.accountId, \"accountId\");\n const existing = this.#subs.get(channel);\n if (existing) {\n const consumer: Consumer = { params, caughtUp: false };\n existing.consumers.add(consumer);\n queueMicrotask(() => this.#catchUp(existing, consumer));\n return () => this.#remove(existing, consumer);\n }\n const consumer: Consumer = { params, caughtUp: true };\n const s: StreamSubscription = {\n consumers: new Set([consumer]),\n channel,\n account,\n sub: \"\",\n seq: 0n,\n cursor: \"\",\n staged: null,\n orders: null,\n state: \"pending\",\n stale: null,\n retries: 0,\n retryTimer: null,\n };\n this.#subs.set(channel, s);\n if (this.#ws && this.#authSent) void this.#subscribe(this.#ws, s);\n else if (!this.#ws && !this.#connecting && !this.#reconnectTimer) this.#open();\n return () => this.#remove(s, consumer);\n }\n\n /** Closes the connection and drops every subscription without callbacks. */\n disconnect(): void {\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n // A consumer that disconnects mid-delivery stops deliveries to the rest.\n s.consumers.clear();\n }\n this.#subs.clear();\n this.#shutdown();\n }\n\n /** Accounts with at least one consumer. */\n get activeChannels(): number {\n let count = 0;\n for (const s of this.#subs.values()) if (s.consumers.size > 0) count++;\n return count;\n }\n\n get totalConsumers(): number {\n let count = 0;\n for (const s of this.#subs.values()) count += s.consumers.size;\n return count;\n }\n\n /** Gives a consumer that joined a running subscription what the others already know. */\n #catchUp(s: StreamSubscription, c: Consumer): void {\n if (!this.#isCurrent(s) || !s.consumers.has(c)) return;\n c.caughtUp = true;\n const { params } = c;\n if (s.state === \"connected\") this.#deliverTo(s, c, () => params.onConnected?.());\n const orders = s.orders && [...s.orders.values()];\n if (orders) this.#deliverTo(s, c, () => params.onEvent({ type: \"snapshot\", orders }));\n const { stale } = s;\n if (stale)\n this.#deliverTo(s, c, () => params.onEvent({ type: \"stale\", stale: true, ...stale }));\n }\n\n /** Fetches the connect token first: the server closes a socket that sends no Auth within 5 seconds. */\n #open(): void {\n const WebSocketCtor = globalThis.WebSocket;\n if (!WebSocketCtor) {\n // Reported after connect() returns, like every other connection failure.\n queueMicrotask(() =>\n this.#terminateAll(\n \"connection_token\",\n new ConfigurationError(\"The private order stream requires a global WebSocket.\"),\n ),\n );\n return;\n }\n const generation = this.#generation;\n this.#connecting = true;\n this.#config.fetchConnectToken().then(\n (token) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n let ws: WebSocket;\n try {\n ws = new WebSocketCtor(this.#config.url, PRIVATE_WS_SUBPROTOCOL);\n } catch (error) {\n // A bad URL or a blocked insecure socket fails the same way on every retry.\n this.#terminateAll(\"connection\", error);\n return;\n }\n ws.binaryType = \"arraybuffer\";\n this.#ws = ws;\n this.#authSent = false;\n ws.onopen = () => this.#authenticate(ws, token);\n ws.onmessage = (event: MessageEvent) => this.#onFrame(ws, event.data);\n ws.onclose = (event: CloseEvent) => this.#onClosed(ws, event.code, event.reason);\n },\n (error: unknown) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n if (isTerminalTokenError(error)) {\n this.#terminateAll(\"connection_token\", error);\n return;\n }\n this.#reportAll(\"connection_token\", error);\n this.#scheduleReconnect();\n },\n );\n }\n\n #authenticate(ws: WebSocket, token: string): void {\n this.#send(ws, { case: \"auth\", value: { token } });\n this.#authSent = true;\n this.#authSentAt = Date.now();\n this.#armHeartbeat(ws);\n for (const s of this.#subs.values()) void this.#subscribe(ws, s);\n }\n\n async #reauthenticate(ws: WebSocket): Promise<void> {\n try {\n const token = await this.#config.fetchConnectToken();\n if (this.#ws === ws) this.#send(ws, { case: \"auth\", value: { token } });\n } catch (error) {\n if (this.#ws !== ws) return;\n if (isTerminalTokenError(error)) this.#terminateAll(\"connection_token\", error);\n else this.#reportAll(\"connection_token\", error);\n }\n }\n\n #isCurrent(s: StreamSubscription): boolean {\n return this.#subs.get(s.channel) === s;\n }\n\n async #subscribe(ws: WebSocket, s: StreamSubscription): Promise<void> {\n if (!this.#isCurrent(s)) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"subscribe\", s });\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n if (this.#pending.get(id)?.s !== s) return;\n this.#pending.delete(id);\n if (isTerminalTokenError(error)) {\n this.#terminate(s, \"subscription_token\", error);\n return;\n }\n this.#report(s, \"subscription_token\", error);\n this.#retrySubscribe(ws, s);\n return;\n }\n if (this.#ws !== ws || this.#pending.get(id)?.s !== s) return;\n this.#send(ws, {\n case: \"subscribe\",\n value: { id, channel: Channel.ORDERS, account: s.account, token, cursor: s.cursor },\n });\n }\n\n /** Subscribes again after a backoff that grows until the subscription delivers data. */\n #retrySubscribe(ws: WebSocket, s: StreamSubscription): void {\n this.#clearRetry(s);\n s.retryTimer = setTimeout(\n () => {\n s.retryTimer = null;\n if (this.#ws === ws && this.#isCurrent(s) && !s.sub) void this.#subscribe(ws, s);\n },\n backoffMs(s.retries++),\n );\n }\n\n #clearRetry(s: StreamSubscription): void {\n if (s.retryTimer) clearTimeout(s.retryTimer);\n s.retryTimer = null;\n }\n\n async #refresh(ws: WebSocket, s: StreamSubscription): Promise<void> {\n const sub = s.sub;\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n // An unrefreshed subscription ends with TOKEN_EXPIRED and resubscribes.\n if (this.#ws === ws && s.sub === sub) this.#report(s, \"subscription_token\", error);\n return;\n }\n if (this.#ws !== ws || s.sub !== sub) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"refresh\", s });\n this.#send(ws, { case: \"subscribeRefresh\", value: { id, sub, token } });\n }\n\n /**\n * Drops the server subscription and subscribes again from the last applied cursor:\n * at once the first time, then with backoff until the subscription delivers data.\n */\n #resubscribe(ws: WebSocket, s: StreamSubscription): void {\n if (s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n if (s.retries > 0) {\n this.#retrySubscribe(ws, s);\n } else {\n s.retries = 1;\n void this.#subscribe(ws, s);\n }\n // Consumers see the gap as a close and the replacement's Subscribed as a reopen.\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n\n #unsubscribe(ws: WebSocket, sub: string): void {\n const id = this.#nextRequestId();\n this.#unsubscribing.add(id);\n this.#send(ws, { case: \"unsubscribe\", value: { id, sub } });\n }\n\n #onFrame(ws: WebSocket, data: unknown): void {\n if (this.#ws !== ws) return;\n this.#armHeartbeat(ws);\n if (!(data instanceof ArrayBuffer)) {\n this.#reportAll(\n \"decode\",\n new RealtimeError(\"Expected a binary private WebSocket frame\"),\n );\n return;\n }\n let msg;\n try {\n msg = fromBinary(ServerMessageSchema, new Uint8Array(data));\n } catch (error) {\n this.#reportAll(\"decode\", error);\n return;\n }\n const frame = msg.frame;\n\n switch (frame.case) {\n case \"subscribed\": {\n const request = this.#pending.get(frame.value.id);\n if (request?.kind !== \"subscribe\") {\n // Its consumer left before the server confirmed it.\n if (msg.sub) this.#unsubscribe(ws, msg.sub);\n return;\n }\n this.#pending.delete(frame.value.id);\n const s = request.s;\n s.sub = msg.sub;\n s.seq = 0n;\n this.#bySub.set(msg.sub, s);\n if (s.state !== \"connected\") {\n s.state = \"connected\";\n this.#deliver(s, (p) => p.onConnected?.());\n }\n // A new subscription reports Unavailable itself if its view is still behind.\n if (s.stale) {\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n }\n return;\n }\n case \"subscribeRefreshed\":\n this.#pending.delete(frame.value.id);\n return;\n case \"unsubscribed\":\n if (this.#unsubscribing.delete(frame.value.id)) return;\n break;\n case \"error\":\n this.#onRequestError(ws, msg.sub, frame.value);\n return;\n case \"tokenExpiring\":\n void this.#reauthenticate(ws);\n return;\n }\n\n const s = this.#bySub.get(msg.sub);\n if (!s) return;\n if (msg.seq > 0n) {\n if (msg.seq !== s.seq + 1n) {\n this.#resubscribe(ws, s);\n return;\n }\n s.seq = msg.seq;\n }\n\n switch (frame.case) {\n case \"snapshotBegin\":\n s.staged = [];\n return;\n case \"snapshotPage\":\n s.staged?.push(...frame.value.orders);\n return;\n case \"snapshotEnd\": {\n const orders = s.staged;\n s.staged = null;\n if (!orders || orders.length !== frame.value.count) {\n s.cursor = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n s.cursor = frame.value.cursor;\n s.retries = 0;\n s.orders = new Map(orders.map((o) => [o.orderId, o]));\n this.#deliver(s, (p) => p.onEvent({ type: \"snapshot\", orders }));\n return;\n }\n case \"unit\": {\n const unit = frame.value;\n s.cursor = unit.nextCursor;\n s.retries = 0;\n for (const o of unit.orders) s.orders?.set(o.orderId, o);\n for (const id of unit.removedOrderIds) s.orders?.delete(id);\n this.#deliver(s, (p) => p.onEvent({ type: \"unit\", unit }));\n return;\n }\n case \"covered\":\n s.cursor = frame.value.cursor;\n s.retries = 0;\n return;\n case \"ready\":\n // A resumed subscription on a quiet account delivers no data, only this.\n s.retries = 0;\n return;\n case \"unavailable\": {\n // A later Unavailable replaces the earlier one; order IDs narrow it to those orders.\n const { orderIds } = frame.value;\n const stale = orderIds.length > 0 ? { orderIds } : {};\n s.stale = stale;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: true, ...stale }));\n return;\n }\n case \"available\":\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n return;\n case \"subscribeExpiring\":\n void this.#refresh(ws, s);\n return;\n case \"unsubscribed\":\n // The server ended it: its token expired, or for a reason this client does not know.\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n }\n\n #onRequestError(\n ws: WebSocket,\n sub: string,\n error: { id: string; code: RequestError_Code; message: string },\n ): void {\n if (error.id && this.#unsubscribing.delete(error.id)) return;\n const request = error.id ? this.#pending.get(error.id) : undefined;\n // The answer to a request already answered, or whose subscription has since gone.\n if (error.id && !request) return;\n if (request) this.#pending.delete(error.id);\n const s = request?.s ?? this.#bySub.get(sub);\n const realtimeError = new RealtimeError(\n error.message ||\n `Private order stream request failed: ${RequestError_Code[error.code]}`,\n { realtimeCode: error.code },\n );\n if (!s) {\n this.#reportAll(\"request\", realtimeError);\n return;\n }\n if (request?.kind === \"subscribe\") {\n if (error.code === RequestError_Code.CURSOR_INVALID) {\n s.cursor = \"\";\n void this.#subscribe(ws, s);\n return;\n }\n this.#terminate(s, \"subscribe\", realtimeError);\n return;\n }\n if (error.code === RequestError_Code.SUBSCRIPTION_UNKNOWN && s.sub === sub) {\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n this.#report(s, request?.kind ?? \"request\", realtimeError);\n }\n\n #onClosed(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n const stable = this.#authSent && Date.now() - this.#authSentAt >= STABLE_CONNECTION_MS;\n this.#detach();\n if (stable) this.#reconnectAttempt = 0;\n if (this.#subs.size === 0) return;\n\n if (TERMINAL_CLOSE_CODES.has(code)) {\n const error = new RealtimeError(\n reason || `Private WebSocket closed with code ${code}`,\n {\n realtimeCode: code,\n retryable: false,\n },\n );\n this.#terminateAll(\"disconnected\", error);\n return;\n }\n // Scheduled first, so a subscription opened from onDisconnected waits for it.\n this.#scheduleReconnect();\n // A close that reconnects is not an error, like a Centrifugo reconnect.\n for (const s of this.#subs.values()) {\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n }\n\n #scheduleReconnect(): void {\n this.#reconnectTimer = setTimeout(\n () => {\n this.#reconnectTimer = null;\n if (this.#subs.size > 0 && !this.#ws && !this.#connecting) this.#open();\n },\n backoffMs(this.#reconnectAttempt++),\n );\n }\n\n #armHeartbeat(ws: WebSocket): void {\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = setTimeout(\n () => this.#drop(ws, 4000, \"heartbeat timeout\"),\n HEARTBEAT_TIMEOUT_MS,\n );\n }\n\n /** Treats the socket as closed now; a stale socket may not emit close for a long time. */\n #drop(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n try {\n ws.close(code, reason);\n } catch {\n // noop\n }\n this.#onClosed(ws, code, reason);\n }\n\n #detach(): void {\n const ws = this.#ws;\n this.#ws = null;\n this.#authSent = false;\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = null;\n this.#pending.clear();\n this.#bySub.clear();\n this.#unsubscribing.clear();\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n }\n if (ws) {\n ws.onopen = null;\n ws.onmessage = null;\n ws.onclose = null;\n }\n }\n\n #shutdown(): void {\n const ws = this.#ws;\n this.#detach();\n this.#generation++;\n this.#connecting = false;\n if (this.#reconnectTimer) clearTimeout(this.#reconnectTimer);\n this.#reconnectTimer = null;\n this.#reconnectAttempt = 0;\n try {\n ws?.close(1000);\n } catch {\n // noop\n }\n }\n\n /** Drops a consumer; the server subscription goes a microtask later unless another joined. */\n #remove(s: StreamSubscription, c: Consumer): void {\n if (!s.consumers.delete(c) || s.consumers.size > 0) return;\n queueMicrotask(() => {\n if (s.consumers.size === 0) this.#teardown(s);\n });\n }\n\n #teardown(s: StreamSubscription): void {\n if (!this.#isCurrent(s)) return;\n this.#subs.delete(s.channel);\n s.consumers.clear();\n this.#clearRetry(s);\n const ws = this.#ws;\n if (ws && s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n for (const [id, request] of this.#pending) {\n if (request.s === s) this.#pending.delete(id);\n }\n if (this.#subs.size === 0) this.#shutdown();\n }\n\n #terminate(s: StreamSubscription, type: string, error: unknown): void {\n if (!this.#isCurrent(s)) return;\n this.#report(s, type, error);\n // Tell every consumer that has not been told it is disconnected.\n const told = s.state === \"disconnected\";\n const consumers = [...s.consumers].filter((c) => !c.caughtUp || !told);\n s.state = \"disconnected\";\n this.#teardown(s);\n for (const c of consumers) this.#call(s.channel, c, () => c.params.onDisconnected?.());\n }\n\n /** Spares subscriptions that consumers open from its callbacks. */\n #terminateAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#terminate(s, type, error);\n }\n\n #send(ws: WebSocket, op: ClientOp): void {\n if (ws.readyState !== 1) return;\n ws.send(toBinary(ClientMessageSchema, create(ClientMessageSchema, { op })));\n }\n\n #nextRequestId(): string {\n return String(++this.#requestSeq);\n }\n\n #report(s: StreamSubscription, type: string, error: unknown): void {\n const ctx = createSdkSubscriptionErrorContext(s.channel, type, error);\n // Only consumers present when the error happened, and still attached.\n for (const c of [...s.consumers]) {\n if (!s.consumers.has(c)) continue;\n try {\n c.params.onError?.(ctx);\n } catch {\n // Keep consumer error-handler failures isolated from the stream.\n }\n }\n }\n\n #reportAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#report(s, type, error);\n }\n\n /** Delivers to each caught-up consumer still attached when its turn comes. */\n #deliver(s: StreamSubscription, deliver: (params: ConnectPrivateOrdersParams) => void): void {\n for (const c of s.consumers) {\n if (c.caughtUp) this.#deliverTo(s, c, () => deliver(c.params));\n }\n }\n\n #deliverTo(s: StreamSubscription, c: Consumer, deliver: () => void): void {\n if (s.consumers.has(c)) this.#call(s.channel, c, deliver);\n }\n\n #call(channel: string, c: Consumer, deliver: () => void): void {\n try {\n deliver();\n } catch (error) {\n try {\n c.params.onError?.(publicationHandlerErrorContext(channel, error));\n } catch {\n // noop\n }\n }\n }\n}\n"],"mappings":";;;;;;AAiBA,MAAa,yBAAyB;AACtC,MAAM,uBAAuB;AAC7B,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;;AAEvB,MAAM,uBAAuB;;AAE7B,MAAM,uCAAuB,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;;AAgEjD,SAAS,UAAU,SAAyB;CACxC,MAAM,UAAU,KAAK,IAAI,gBAAgB,kBAAkB,MAAM,UAAU,EAAE;CAC7E,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,UAAU;AACpD;AAEA,SAAS,qBAAqB,OAAyB;CACnD,OAAO,i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|
|
1
|
+
{"version":3,"file":"private-orders.js","names":["#config","#subs","#pending","#bySub","#unsubscribing","#catchUp","#remove","#ws","#authSent","#subscribe","#connecting","#reconnectTimer","#open","#clearRetry","#shutdown","#isCurrent","#deliverTo","#terminateAll","#generation","#authenticate","#onFrame","#onClosed","#reportAll","#scheduleReconnect","#send","#authSentAt","#armHeartbeat","#reauthenticate","#nextRequestId","#terminate","#report","#retrySubscribe","#refresh","#unsubscribe","#deliver","#drop","#onRequestError","#resubscribe","#detach","#reconnectAttempt","#heartbeatTimer","#teardown","#call","#requestSeq"],"sources":["../../src/realtime/private-orders.ts"],"sourcesContent":["import { create, fromBinary, toBinary, type MessageInitShape } from \"@bufbuild/protobuf\";\nimport type { Order } from \"../gen/orders/v1/orders_read_pb.js\";\nimport {\n Channel,\n ClientMessageSchema,\n RequestError_Code,\n ServerMessageSchema,\n type Unit,\n} from \"../gen/privatews/v1/private_ws_pb.js\";\nimport { ConfigurationError, PolyesterError, RealtimeError } from \"../shared/errors.js\";\nimport {\n createSdkSubscriptionErrorContext,\n publicationHandlerErrorContext,\n type SdkSubscriptionErrorContext,\n} from \"../shared/subscription-errors.js\";\nimport { idToBigInt } from \"../utils/base58-id.js\";\n\nexport const PRIVATE_WS_SUBPROTOCOL = \"polyester.v1.proto\";\nconst HEARTBEAT_TIMEOUT_MS = 3_000;\nconst BACKOFF_BASE_MS = 500;\nconst BACKOFF_MAX_MS = 10_000;\n/** A connection that stayed up this long resets the reconnect backoff. */\nconst STABLE_CONNECTION_MS = 10_000;\n/** A malformed frame (4400) and a rejected connect token (4403) recur on every reconnect. */\nconst TERMINAL_CLOSE_CODES = new Set([4400, 4403]);\n/** Larger frames are dropped undecoded with the connection; a full 256-order page is far smaller. */\nexport const MAX_PRIVATE_FRAME_BYTES = 4 * 1024 * 1024;\n/** A snapshot staging more pages than this ends its subscription, so a snapshot never ending stays bounded. */\nexport const MAX_SNAPSHOT_BYTES = 64 * 1024 * 1024;\nexport const MAX_SNAPSHOT_ORDERS = 100_000;\n\n/** One delivery of an account's order stream. */\nexport type PrivateOrdersEvent =\n /** The account's full live view; replace local state with it. */\n | { type: \"snapshot\"; orders: Order[] }\n /** One change, applied whole. */\n | { type: \"unit\"; unit: Unit }\n /**\n * The account's live view is temporarily behind (`true`) or caught up (`false`).\n * `orderIds`, when set, names the only orders behind; the rest of the view is current.\n */\n | { type: \"stale\"; stale: boolean; orderIds?: bigint[] };\n\nexport interface ConnectPrivateOrdersParams {\n /** The account's base58 public ID. */\n accountId: string;\n onEvent: (event: PrivateOrdersEvent) => void;\n /** Called when the server confirms the subscription, again after each reconnect. */\n onConnected?: () => void;\n /** Called when the connection carrying the subscription drops. */\n onDisconnected?: () => void;\n onError?: (ctx: SdkSubscriptionErrorContext) => void;\n}\n\nexport interface PrivateOrderStreamConfig {\n url: string;\n fetchConnectToken: () => Promise<string>;\n fetchSubscribeToken: (channel: string) => Promise<string>;\n}\n\ntype ClientOp = MessageInitShape<typeof ClientMessageSchema>[\"op\"];\n\ninterface Consumer {\n params: ConnectPrivateOrdersParams;\n /** False until a consumer that joined a running subscription received its current state. */\n caughtUp: boolean;\n}\n\n/** One server subscription per account, shared by every consumer of that account. */\ninterface StreamSubscription {\n consumers: Set<Consumer>;\n channel: string;\n account: bigint;\n /** Server subscription ID; empty until Subscribed. */\n sub: string;\n seq: bigint;\n /** Last applied resume position, carried across resubscribes and reconnects. */\n cursor: string;\n staged: Order[] | null;\n /** Frame bytes of the staged pages. */\n stagedBytes: number;\n /** The account's live view as last applied, for consumers that join later; null before the first snapshot. */\n orders: Map<bigint, Order> | null;\n /** The last connection state consumers were told about. */\n state: \"pending\" | \"connected\" | \"disconnected\";\n /** What consumers were last told is stale, until they are told it caught up. */\n stale: { orderIds?: bigint[] } | null;\n /** Subscribe attempts since the subscription last delivered data; drives retry backoff. */\n retries: number;\n retryTimer: ReturnType<typeof setTimeout> | null;\n}\n\ntype PendingRequest = { kind: \"subscribe\" | \"refresh\"; s: StreamSubscription };\n\n/** 0.5 s doubling to 10 s, jittered over the upper half of each step. */\nfunction backoffMs(attempt: number): number {\n const ceiling = Math.min(BACKOFF_MAX_MS, BACKOFF_BASE_MS * 2 ** (attempt + 1));\n return ceiling / 2 + Math.random() * (ceiling / 2);\n}\n\nfunction isTerminalTokenError(error: unknown): boolean {\n return error instanceof PolyesterError && !error.retryable;\n}\n\n/**\n * Account order streams over the private WebSocket (`/v1/ws/private`). One\n * connection carries every subscription; each resumes from its last cursor\n * after a gap, an expired token, or a reconnect.\n */\nexport class PrivateOrderStream {\n readonly #config: PrivateOrderStreamConfig;\n /** Keyed by channel. A subscription whose last consumer left stays until the next microtask. */\n readonly #subs = new Map<string, StreamSubscription>();\n readonly #pending = new Map<string, PendingRequest>();\n readonly #bySub = new Map<string, StreamSubscription>();\n /** IDs of Unsubscribe requests awaiting their answer. */\n readonly #unsubscribing = new Set<string>();\n #ws: WebSocket | null = null;\n /** A connect token fetch for the next socket is in flight. */\n #connecting = false;\n /** Bumped on shutdown so a token fetch that outlived it opens nothing. */\n #generation = 0;\n #authSent = false;\n #authSentAt = 0;\n #reconnectAttempt = 0;\n #reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n #heartbeatTimer: ReturnType<typeof setTimeout> | null = null;\n #requestSeq = 0;\n\n constructor(config: PrivateOrderStreamConfig) {\n this.#config = config;\n }\n\n /** Throws ValidationError when accountId is not a base58 public ID. */\n connect(params: ConnectPrivateOrdersParams): () => void {\n const channel = `private:spot:orders:${params.accountId}`;\n const account = idToBigInt(params.accountId, \"accountId\");\n const existing = this.#subs.get(channel);\n if (existing) {\n const consumer: Consumer = { params, caughtUp: false };\n existing.consumers.add(consumer);\n queueMicrotask(() => this.#catchUp(existing, consumer));\n return () => this.#remove(existing, consumer);\n }\n const consumer: Consumer = { params, caughtUp: true };\n const s: StreamSubscription = {\n consumers: new Set([consumer]),\n channel,\n account,\n sub: \"\",\n seq: 0n,\n cursor: \"\",\n staged: null,\n stagedBytes: 0,\n orders: null,\n state: \"pending\",\n stale: null,\n retries: 0,\n retryTimer: null,\n };\n this.#subs.set(channel, s);\n if (this.#ws && this.#authSent) void this.#subscribe(this.#ws, s);\n else if (!this.#ws && !this.#connecting && !this.#reconnectTimer) this.#open();\n return () => this.#remove(s, consumer);\n }\n\n /** Closes the connection and drops every subscription without callbacks. */\n disconnect(): void {\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n // A consumer that disconnects mid-delivery stops deliveries to the rest.\n s.consumers.clear();\n }\n this.#subs.clear();\n this.#shutdown();\n }\n\n /** Accounts with at least one consumer. */\n get activeChannels(): number {\n let count = 0;\n for (const s of this.#subs.values()) if (s.consumers.size > 0) count++;\n return count;\n }\n\n get totalConsumers(): number {\n let count = 0;\n for (const s of this.#subs.values()) count += s.consumers.size;\n return count;\n }\n\n /** Gives a consumer that joined a running subscription what the others already know. */\n #catchUp(s: StreamSubscription, c: Consumer): void {\n if (!this.#isCurrent(s) || !s.consumers.has(c)) return;\n c.caughtUp = true;\n const { params } = c;\n if (s.state === \"connected\") this.#deliverTo(s, c, () => params.onConnected?.());\n const orders = s.orders && [...s.orders.values()];\n if (orders) this.#deliverTo(s, c, () => params.onEvent({ type: \"snapshot\", orders }));\n const { stale } = s;\n if (stale)\n this.#deliverTo(s, c, () => params.onEvent({ type: \"stale\", stale: true, ...stale }));\n }\n\n /** Fetches the connect token first: the server closes a socket that sends no Auth within 5 seconds. */\n #open(): void {\n const WebSocketCtor = globalThis.WebSocket;\n if (!WebSocketCtor) {\n // Reported after connect() returns, like every other connection failure.\n queueMicrotask(() =>\n this.#terminateAll(\n \"connection_token\",\n new ConfigurationError(\"The private order stream requires a global WebSocket.\"),\n ),\n );\n return;\n }\n const generation = this.#generation;\n this.#connecting = true;\n this.#config.fetchConnectToken().then(\n (token) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n let ws: WebSocket;\n try {\n ws = new WebSocketCtor(this.#config.url, PRIVATE_WS_SUBPROTOCOL);\n } catch (error) {\n // A bad URL or a blocked insecure socket fails the same way on every retry.\n this.#terminateAll(\"connection\", error);\n return;\n }\n ws.binaryType = \"arraybuffer\";\n this.#ws = ws;\n this.#authSent = false;\n ws.onopen = () => this.#authenticate(ws, token);\n ws.onmessage = (event: MessageEvent) => this.#onFrame(ws, event.data);\n ws.onclose = (event: CloseEvent) => this.#onClosed(ws, event.code, event.reason);\n },\n (error: unknown) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n if (isTerminalTokenError(error)) {\n this.#terminateAll(\"connection_token\", error);\n return;\n }\n this.#reportAll(\"connection_token\", error);\n this.#scheduleReconnect();\n },\n );\n }\n\n #authenticate(ws: WebSocket, token: string): void {\n this.#send(ws, { case: \"auth\", value: { token } });\n this.#authSent = true;\n this.#authSentAt = Date.now();\n this.#armHeartbeat(ws);\n for (const s of this.#subs.values()) void this.#subscribe(ws, s);\n }\n\n async #reauthenticate(ws: WebSocket): Promise<void> {\n try {\n const token = await this.#config.fetchConnectToken();\n if (this.#ws === ws) this.#send(ws, { case: \"auth\", value: { token } });\n } catch (error) {\n if (this.#ws !== ws) return;\n if (isTerminalTokenError(error)) this.#terminateAll(\"connection_token\", error);\n else this.#reportAll(\"connection_token\", error);\n }\n }\n\n #isCurrent(s: StreamSubscription): boolean {\n return this.#subs.get(s.channel) === s;\n }\n\n async #subscribe(ws: WebSocket, s: StreamSubscription): Promise<void> {\n if (!this.#isCurrent(s)) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"subscribe\", s });\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n if (this.#pending.get(id)?.s !== s) return;\n this.#pending.delete(id);\n if (isTerminalTokenError(error)) {\n this.#terminate(s, \"subscription_token\", error);\n return;\n }\n this.#report(s, \"subscription_token\", error);\n this.#retrySubscribe(ws, s);\n return;\n }\n if (this.#ws !== ws || this.#pending.get(id)?.s !== s) return;\n this.#send(ws, {\n case: \"subscribe\",\n value: { id, channel: Channel.ORDERS, account: s.account, token, cursor: s.cursor },\n });\n }\n\n /** Subscribes again after a backoff that grows until the subscription delivers data. */\n #retrySubscribe(ws: WebSocket, s: StreamSubscription): void {\n this.#clearRetry(s);\n s.retryTimer = setTimeout(\n () => {\n s.retryTimer = null;\n if (this.#ws === ws && this.#isCurrent(s) && !s.sub) void this.#subscribe(ws, s);\n },\n backoffMs(s.retries++),\n );\n }\n\n #clearRetry(s: StreamSubscription): void {\n if (s.retryTimer) clearTimeout(s.retryTimer);\n s.retryTimer = null;\n }\n\n async #refresh(ws: WebSocket, s: StreamSubscription): Promise<void> {\n const sub = s.sub;\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n // An unrefreshed subscription ends with TOKEN_EXPIRED and resubscribes.\n if (this.#ws === ws && s.sub === sub) this.#report(s, \"subscription_token\", error);\n return;\n }\n if (this.#ws !== ws || s.sub !== sub) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"refresh\", s });\n this.#send(ws, { case: \"subscribeRefresh\", value: { id, sub, token } });\n }\n\n /**\n * Drops the server subscription and subscribes again from the last applied cursor:\n * at once the first time, then with backoff until the subscription delivers data.\n */\n #resubscribe(ws: WebSocket, s: StreamSubscription): void {\n if (s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n if (s.retries > 0) {\n this.#retrySubscribe(ws, s);\n } else {\n s.retries = 1;\n void this.#subscribe(ws, s);\n }\n // Consumers see the gap as a close and the replacement's Subscribed as a reopen.\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n\n #unsubscribe(ws: WebSocket, sub: string): void {\n const id = this.#nextRequestId();\n this.#unsubscribing.add(id);\n this.#send(ws, { case: \"unsubscribe\", value: { id, sub } });\n }\n\n #onFrame(ws: WebSocket, data: unknown): void {\n if (this.#ws !== ws) return;\n this.#armHeartbeat(ws);\n if (!(data instanceof ArrayBuffer)) {\n this.#reportAll(\n \"decode\",\n new RealtimeError(\"Expected a binary private WebSocket frame\"),\n );\n return;\n }\n if (data.byteLength > MAX_PRIVATE_FRAME_BYTES) {\n this.#reportAll(\n \"decode\",\n new RealtimeError(\n `Private WebSocket frame of ${data.byteLength} bytes exceeds ${MAX_PRIVATE_FRAME_BYTES}`,\n ),\n );\n // Reconnects with backoff; dropping the socket releases every staged snapshot.\n this.#drop(ws, 1009, \"frame too large\");\n return;\n }\n let msg;\n try {\n msg = fromBinary(ServerMessageSchema, new Uint8Array(data));\n } catch (error) {\n this.#reportAll(\"decode\", error);\n return;\n }\n const frame = msg.frame;\n\n switch (frame.case) {\n case \"subscribed\": {\n const request = this.#pending.get(frame.value.id);\n if (request?.kind !== \"subscribe\") {\n // Its consumer left before the server confirmed it.\n if (msg.sub) this.#unsubscribe(ws, msg.sub);\n return;\n }\n this.#pending.delete(frame.value.id);\n const s = request.s;\n s.sub = msg.sub;\n s.seq = 0n;\n this.#bySub.set(msg.sub, s);\n if (s.state !== \"connected\") {\n s.state = \"connected\";\n this.#deliver(s, (p) => p.onConnected?.());\n }\n // A new subscription reports Unavailable itself if its view is still behind.\n if (s.stale) {\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n }\n return;\n }\n case \"subscribeRefreshed\":\n this.#pending.delete(frame.value.id);\n return;\n case \"unsubscribed\":\n if (this.#unsubscribing.delete(frame.value.id)) return;\n break;\n case \"error\":\n this.#onRequestError(ws, msg.sub, frame.value);\n return;\n case \"tokenExpiring\":\n void this.#reauthenticate(ws);\n return;\n }\n\n const s = this.#bySub.get(msg.sub);\n if (!s) return;\n if (msg.seq > 0n) {\n if (msg.seq !== s.seq + 1n) {\n this.#resubscribe(ws, s);\n return;\n }\n s.seq = msg.seq;\n }\n\n switch (frame.case) {\n case \"snapshotBegin\":\n s.staged = [];\n s.stagedBytes = 0;\n return;\n case \"snapshotPage\": {\n if (!s.staged) return;\n s.stagedBytes += data.byteLength;\n const count = s.staged.length + frame.value.orders.length;\n if (s.stagedBytes > MAX_SNAPSHOT_BYTES || count > MAX_SNAPSHOT_ORDERS) {\n s.staged = null;\n // The same account sends the same snapshot again, so retrying cannot help.\n this.#terminate(\n s,\n \"snapshot\",\n new RealtimeError(\n `Private order snapshot exceeds ${MAX_SNAPSHOT_ORDERS} orders or ${MAX_SNAPSHOT_BYTES} bytes`,\n ),\n );\n return;\n }\n s.staged.push(...frame.value.orders);\n return;\n }\n case \"snapshotEnd\": {\n const orders = s.staged;\n s.staged = null;\n if (!orders || orders.length !== frame.value.count) {\n s.cursor = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n s.cursor = frame.value.cursor;\n s.retries = 0;\n s.orders = new Map(orders.map((o) => [o.orderId, o]));\n this.#deliver(s, (p) => p.onEvent({ type: \"snapshot\", orders }));\n return;\n }\n case \"unit\": {\n const unit = frame.value;\n s.cursor = unit.nextCursor;\n s.retries = 0;\n for (const o of unit.orders) s.orders?.set(o.orderId, o);\n for (const id of unit.removedOrderIds) s.orders?.delete(id);\n this.#deliver(s, (p) => p.onEvent({ type: \"unit\", unit }));\n return;\n }\n case \"covered\":\n s.cursor = frame.value.cursor;\n s.retries = 0;\n return;\n case \"ready\":\n // A resumed subscription on a quiet account delivers no data, only this.\n s.retries = 0;\n return;\n case \"unavailable\": {\n // A later Unavailable replaces the earlier one; order IDs narrow it to those orders.\n const { orderIds } = frame.value;\n const stale = orderIds.length > 0 ? { orderIds } : {};\n s.stale = stale;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: true, ...stale }));\n return;\n }\n case \"available\":\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n return;\n case \"subscribeExpiring\":\n void this.#refresh(ws, s);\n return;\n case \"unsubscribed\":\n // The server ended it: its token expired, or for a reason this client does not know.\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n }\n\n #onRequestError(\n ws: WebSocket,\n sub: string,\n error: { id: string; code: RequestError_Code; message: string },\n ): void {\n if (error.id && this.#unsubscribing.delete(error.id)) return;\n const request = error.id ? this.#pending.get(error.id) : undefined;\n // The answer to a request already answered, or whose subscription has since gone.\n if (error.id && !request) return;\n if (request) this.#pending.delete(error.id);\n const s = request?.s ?? this.#bySub.get(sub);\n const realtimeError = new RealtimeError(\n error.message ||\n `Private order stream request failed: ${RequestError_Code[error.code]}`,\n { realtimeCode: error.code },\n );\n if (!s) {\n this.#reportAll(\"request\", realtimeError);\n return;\n }\n if (request?.kind === \"subscribe\") {\n if (error.code === RequestError_Code.CURSOR_INVALID) {\n s.cursor = \"\";\n void this.#subscribe(ws, s);\n return;\n }\n this.#terminate(s, \"subscribe\", realtimeError);\n return;\n }\n if (error.code === RequestError_Code.SUBSCRIPTION_UNKNOWN && s.sub === sub) {\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n this.#report(s, request?.kind ?? \"request\", realtimeError);\n }\n\n #onClosed(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n const stable = this.#authSent && Date.now() - this.#authSentAt >= STABLE_CONNECTION_MS;\n this.#detach();\n if (stable) this.#reconnectAttempt = 0;\n if (this.#subs.size === 0) return;\n\n if (TERMINAL_CLOSE_CODES.has(code)) {\n const error = new RealtimeError(\n reason || `Private WebSocket closed with code ${code}`,\n {\n realtimeCode: code,\n retryable: false,\n },\n );\n this.#terminateAll(\"disconnected\", error);\n return;\n }\n // Scheduled first, so a subscription opened from onDisconnected waits for it.\n this.#scheduleReconnect();\n // A close that reconnects is not an error, like a Centrifugo reconnect.\n for (const s of this.#subs.values()) {\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n }\n\n #scheduleReconnect(): void {\n this.#reconnectTimer = setTimeout(\n () => {\n this.#reconnectTimer = null;\n if (this.#subs.size > 0 && !this.#ws && !this.#connecting) this.#open();\n },\n backoffMs(this.#reconnectAttempt++),\n );\n }\n\n #armHeartbeat(ws: WebSocket): void {\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = setTimeout(\n () => this.#drop(ws, 4000, \"heartbeat timeout\"),\n HEARTBEAT_TIMEOUT_MS,\n );\n }\n\n /** Treats the socket as closed now; a stale socket may not emit close for a long time. */\n #drop(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n try {\n ws.close(code, reason);\n } catch {\n // noop\n }\n this.#onClosed(ws, code, reason);\n }\n\n #detach(): void {\n const ws = this.#ws;\n this.#ws = null;\n this.#authSent = false;\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = null;\n this.#pending.clear();\n this.#bySub.clear();\n this.#unsubscribing.clear();\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n }\n if (ws) {\n ws.onopen = null;\n ws.onmessage = null;\n ws.onclose = null;\n }\n }\n\n #shutdown(): void {\n const ws = this.#ws;\n this.#detach();\n this.#generation++;\n this.#connecting = false;\n if (this.#reconnectTimer) clearTimeout(this.#reconnectTimer);\n this.#reconnectTimer = null;\n this.#reconnectAttempt = 0;\n try {\n ws?.close(1000);\n } catch {\n // noop\n }\n }\n\n /** Drops a consumer; the server subscription goes a microtask later unless another joined. */\n #remove(s: StreamSubscription, c: Consumer): void {\n if (!s.consumers.delete(c) || s.consumers.size > 0) return;\n queueMicrotask(() => {\n if (s.consumers.size === 0) this.#teardown(s);\n });\n }\n\n #teardown(s: StreamSubscription): void {\n if (!this.#isCurrent(s)) return;\n this.#subs.delete(s.channel);\n s.consumers.clear();\n this.#clearRetry(s);\n const ws = this.#ws;\n if (ws && s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n for (const [id, request] of this.#pending) {\n if (request.s === s) this.#pending.delete(id);\n }\n if (this.#subs.size === 0) this.#shutdown();\n }\n\n #terminate(s: StreamSubscription, type: string, error: unknown): void {\n if (!this.#isCurrent(s)) return;\n this.#report(s, type, error);\n // Tell every consumer that has not been told it is disconnected.\n const told = s.state === \"disconnected\";\n const consumers = [...s.consumers].filter((c) => !c.caughtUp || !told);\n s.state = \"disconnected\";\n this.#teardown(s);\n for (const c of consumers) this.#call(s.channel, c, () => c.params.onDisconnected?.());\n }\n\n /** Spares subscriptions that consumers open from its callbacks. */\n #terminateAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#terminate(s, type, error);\n }\n\n #send(ws: WebSocket, op: ClientOp): void {\n if (ws.readyState !== 1) return;\n ws.send(toBinary(ClientMessageSchema, create(ClientMessageSchema, { op })));\n }\n\n #nextRequestId(): string {\n return String(++this.#requestSeq);\n }\n\n #report(s: StreamSubscription, type: string, error: unknown): void {\n const ctx = createSdkSubscriptionErrorContext(s.channel, type, error);\n // Only consumers present when the error happened, and still attached.\n for (const c of [...s.consumers]) {\n if (!s.consumers.has(c)) continue;\n try {\n c.params.onError?.(ctx);\n } catch {\n // Keep consumer error-handler failures isolated from the stream.\n }\n }\n }\n\n #reportAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#report(s, type, error);\n }\n\n /** Delivers to each caught-up consumer still attached when its turn comes. */\n #deliver(s: StreamSubscription, deliver: (params: ConnectPrivateOrdersParams) => void): void {\n for (const c of s.consumers) {\n if (c.caughtUp) this.#deliverTo(s, c, () => deliver(c.params));\n }\n }\n\n #deliverTo(s: StreamSubscription, c: Consumer, deliver: () => void): void {\n if (s.consumers.has(c)) this.#call(s.channel, c, deliver);\n }\n\n #call(channel: string, c: Consumer, deliver: () => void): void {\n try {\n deliver();\n } catch (error) {\n try {\n c.params.onError?.(publicationHandlerErrorContext(channel, error));\n } catch {\n // noop\n }\n }\n }\n}\n"],"mappings":";;;;;;AAiBA,MAAa,yBAAyB;AACtC,MAAM,uBAAuB;AAC7B,MAAM,kBAAkB;AACxB,MAA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AAuB,MAAc,OAAsB;EAC/D,MAAM,MAAM,kCAAkC,EAAE,SAAS,MAAM,KAAK;EAEpE,KAAK,MAAM,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG;GAC9B,IAAI,CAAC,EAAE,UAAU,IAAI,CAAC,GAAG;GACzB,IAAI;IACA,EAAE,OAAO,UAAU,GAAG;GAC1B,QAAQ,CAER;EACJ;CACJ;CAEA,WAAW,MAAc,OAAsB;EAC3C,KAAK,MAAM,KAAK,CAAC,GAAG,KAAK1C,MAAM,OAAO,CAAC,GAAG,KAAK6B,QAAQ,GAAG,MAAM,KAAK;CACzE;;CAGA,SAAS,GAAuB,SAA6D;EACzF,KAAK,MAAM,KAAK,EAAE,WACd,IAAI,EAAE,UAAU,KAAKd,WAAW,GAAG,SAAS,QAAQ,EAAE,MAAM,CAAC;CAErE;CAEA,WAAW,GAAuB,GAAa,SAA2B;EACtE,IAAI,EAAE,UAAU,IAAI,CAAC,GAAG,KAAK0B,MAAM,EAAE,SAAS,GAAG,OAAO;CAC5D;CAEA,MAAM,SAAiB,GAAa,SAA2B;EAC3D,IAAI;GACA,QAAQ;EACZ,SAAS,OAAO;GACZ,IAAI;IACA,EAAE,OAAO,UAAU,+BAA+B,SAAS,KAAK,CAAC;GACrE,QAAQ,CAER;EACJ;CACJ;AACJ"}
|
|
@@ -460,7 +460,7 @@ declare const AutoWithdrawStepSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
460
460
|
readonly hi: v.BigintSchema<undefined>;
|
|
461
461
|
readonly lo: v.BigintSchema<undefined>;
|
|
462
462
|
}, undefined>, undefined>;
|
|
463
|
-
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
463
|
+
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted">]>;
|
|
464
464
|
readonly reason: v.SchemaWithPipe<readonly [v.OptionalSchema<v.StringSchema<undefined>, "">, v.TransformAction<string, AutoWithdrawStepReason | null>]>;
|
|
465
465
|
readonly intentId: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
466
466
|
readonly txHash: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
@@ -480,7 +480,7 @@ declare const AutoWithdrawStepSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
480
480
|
hi: bigint;
|
|
481
481
|
lo: bigint;
|
|
482
482
|
} | undefined;
|
|
483
|
-
state: "unspecified" | "
|
|
483
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
484
484
|
reason: AutoWithdrawStepReason | null;
|
|
485
485
|
intentId: string;
|
|
486
486
|
txHash: string;
|
|
@@ -493,7 +493,7 @@ declare const AutoWithdrawStepSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
493
493
|
txHash: string | null;
|
|
494
494
|
assetId: number;
|
|
495
495
|
destinationAddress: string;
|
|
496
|
-
state: "unspecified" | "
|
|
496
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
497
497
|
reason: AutoWithdrawStepReason | null;
|
|
498
498
|
}>]>;
|
|
499
499
|
/**
|
|
@@ -511,7 +511,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
511
511
|
seconds: bigint;
|
|
512
512
|
nanos: number;
|
|
513
513
|
}, number>]>;
|
|
514
|
-
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
514
|
+
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "planned" | "paying" | "completed" | "partially_failed" | "failed" | "skipped">]>;
|
|
515
515
|
readonly reason: v.SchemaWithPipe<readonly [v.OptionalSchema<v.StringSchema<undefined>, "">, v.TransformAction<string, AutoWithdrawRunReason | null>]>;
|
|
516
516
|
readonly steps: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
517
517
|
readonly assetId: v.NumberSchema<undefined>;
|
|
@@ -529,7 +529,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
529
529
|
readonly hi: v.BigintSchema<undefined>;
|
|
530
530
|
readonly lo: v.BigintSchema<undefined>;
|
|
531
531
|
}, undefined>, undefined>;
|
|
532
|
-
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
532
|
+
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted">]>;
|
|
533
533
|
readonly reason: v.SchemaWithPipe<readonly [v.OptionalSchema<v.StringSchema<undefined>, "">, v.TransformAction<string, AutoWithdrawStepReason | null>]>;
|
|
534
534
|
readonly intentId: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
535
535
|
readonly txHash: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
@@ -549,7 +549,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
549
549
|
hi: bigint;
|
|
550
550
|
lo: bigint;
|
|
551
551
|
} | undefined;
|
|
552
|
-
state: "unspecified" | "
|
|
552
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
553
553
|
reason: AutoWithdrawStepReason | null;
|
|
554
554
|
intentId: string;
|
|
555
555
|
txHash: string;
|
|
@@ -562,7 +562,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
562
562
|
txHash: string | null;
|
|
563
563
|
assetId: number;
|
|
564
564
|
destinationAddress: string;
|
|
565
|
-
state: "unspecified" | "
|
|
565
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
566
566
|
reason: AutoWithdrawStepReason | null;
|
|
567
567
|
}>]>, undefined>;
|
|
568
568
|
readonly createdAt: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
@@ -583,7 +583,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
583
583
|
runSeq: string;
|
|
584
584
|
ruleVersion: number;
|
|
585
585
|
scheduledFor: number;
|
|
586
|
-
state: "unspecified" | "
|
|
586
|
+
state: "unspecified" | "planned" | "paying" | "completed" | "partially_failed" | "failed" | "skipped";
|
|
587
587
|
reason: AutoWithdrawRunReason | null;
|
|
588
588
|
steps: {
|
|
589
589
|
destinationChainId: number;
|
|
@@ -594,7 +594,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
594
594
|
txHash: string | null;
|
|
595
595
|
assetId: number;
|
|
596
596
|
destinationAddress: string;
|
|
597
|
-
state: "unspecified" | "
|
|
597
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
598
598
|
reason: AutoWithdrawStepReason | null;
|
|
599
599
|
}[];
|
|
600
600
|
createdAt: number;
|
|
@@ -604,7 +604,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
604
604
|
runSeq: string;
|
|
605
605
|
ruleVersion: number;
|
|
606
606
|
scheduledFor: number;
|
|
607
|
-
state: "unspecified" | "
|
|
607
|
+
state: "unspecified" | "planned" | "paying" | "completed" | "partially_failed" | "failed" | "skipped";
|
|
608
608
|
reason: AutoWithdrawRunReason | null;
|
|
609
609
|
steps: {
|
|
610
610
|
destinationChainId: number;
|
|
@@ -615,7 +615,7 @@ declare const AutoWithdrawRunSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
615
615
|
txHash: string | null;
|
|
616
616
|
assetId: number;
|
|
617
617
|
destinationAddress: string;
|
|
618
|
-
state: "unspecified" | "
|
|
618
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
619
619
|
reason: AutoWithdrawStepReason | null;
|
|
620
620
|
}[];
|
|
621
621
|
createdAt: number;
|
|
@@ -633,7 +633,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
633
633
|
seconds: bigint;
|
|
634
634
|
nanos: number;
|
|
635
635
|
}, number>]>;
|
|
636
|
-
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
636
|
+
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "planned" | "paying" | "completed" | "partially_failed" | "failed" | "skipped">]>;
|
|
637
637
|
readonly reason: v.SchemaWithPipe<readonly [v.OptionalSchema<v.StringSchema<undefined>, "">, v.TransformAction<string, AutoWithdrawRunReason | null>]>;
|
|
638
638
|
readonly steps: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
639
639
|
readonly assetId: v.NumberSchema<undefined>;
|
|
@@ -651,7 +651,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
651
651
|
readonly hi: v.BigintSchema<undefined>;
|
|
652
652
|
readonly lo: v.BigintSchema<undefined>;
|
|
653
653
|
}, undefined>, undefined>;
|
|
654
|
-
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
654
|
+
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted">]>;
|
|
655
655
|
readonly reason: v.SchemaWithPipe<readonly [v.OptionalSchema<v.StringSchema<undefined>, "">, v.TransformAction<string, AutoWithdrawStepReason | null>]>;
|
|
656
656
|
readonly intentId: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
657
657
|
readonly txHash: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
@@ -671,7 +671,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
671
671
|
hi: bigint;
|
|
672
672
|
lo: bigint;
|
|
673
673
|
} | undefined;
|
|
674
|
-
state: "unspecified" | "
|
|
674
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
675
675
|
reason: AutoWithdrawStepReason | null;
|
|
676
676
|
intentId: string;
|
|
677
677
|
txHash: string;
|
|
@@ -684,7 +684,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
684
684
|
txHash: string | null;
|
|
685
685
|
assetId: number;
|
|
686
686
|
destinationAddress: string;
|
|
687
|
-
state: "unspecified" | "
|
|
687
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
688
688
|
reason: AutoWithdrawStepReason | null;
|
|
689
689
|
}>]>, undefined>;
|
|
690
690
|
readonly createdAt: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
@@ -705,7 +705,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
705
705
|
runSeq: string;
|
|
706
706
|
ruleVersion: number;
|
|
707
707
|
scheduledFor: number;
|
|
708
|
-
state: "unspecified" | "
|
|
708
|
+
state: "unspecified" | "planned" | "paying" | "completed" | "partially_failed" | "failed" | "skipped";
|
|
709
709
|
reason: AutoWithdrawRunReason | null;
|
|
710
710
|
steps: {
|
|
711
711
|
destinationChainId: number;
|
|
@@ -716,7 +716,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
716
716
|
txHash: string | null;
|
|
717
717
|
assetId: number;
|
|
718
718
|
destinationAddress: string;
|
|
719
|
-
state: "unspecified" | "
|
|
719
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
720
720
|
reason: AutoWithdrawStepReason | null;
|
|
721
721
|
}[];
|
|
722
722
|
createdAt: number;
|
|
@@ -726,7 +726,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
726
726
|
runSeq: string;
|
|
727
727
|
ruleVersion: number;
|
|
728
728
|
scheduledFor: number;
|
|
729
|
-
state: "unspecified" | "
|
|
729
|
+
state: "unspecified" | "planned" | "paying" | "completed" | "partially_failed" | "failed" | "skipped";
|
|
730
730
|
reason: AutoWithdrawRunReason | null;
|
|
731
731
|
steps: {
|
|
732
732
|
destinationChainId: number;
|
|
@@ -737,7 +737,7 @@ declare const ListAutoWithdrawRunsResultSchema: v.ObjectSchema<{
|
|
|
737
737
|
txHash: string | null;
|
|
738
738
|
assetId: number;
|
|
739
739
|
destinationAddress: string;
|
|
740
|
-
state: "unspecified" | "
|
|
740
|
+
state: "unspecified" | "completed" | "failed" | "skipped" | "pending" | "submitting" | "submitted";
|
|
741
741
|
reason: AutoWithdrawStepReason | null;
|
|
742
742
|
}[];
|
|
743
743
|
createdAt: number;
|
|
@@ -49,7 +49,7 @@ declare const CheckpointBiggestTradeSchema: v.SchemaWithPipe<readonly [v.ObjectS
|
|
|
49
49
|
side: number;
|
|
50
50
|
at: number;
|
|
51
51
|
}, {
|
|
52
|
-
side: "
|
|
52
|
+
side: "unspecified" | "buy" | "sell";
|
|
53
53
|
symbolId: number;
|
|
54
54
|
symbol: string;
|
|
55
55
|
at: number;
|
|
@@ -229,7 +229,7 @@ declare const CheckpointSchema: v.ObjectSchema<{
|
|
|
229
229
|
side: number;
|
|
230
230
|
at: number;
|
|
231
231
|
}, {
|
|
232
|
-
side: "
|
|
232
|
+
side: "unspecified" | "buy" | "sell";
|
|
233
233
|
symbolId: number;
|
|
234
234
|
symbol: string;
|
|
235
235
|
at: number;
|
|
@@ -4,7 +4,8 @@ import { ClaimDailyRewardInput, ClaimDailyRewardResult, DailyClaimStatus } from
|
|
|
4
4
|
//#region src/services/claims/claims.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Reads and claims daily campaign rewards for the authenticated root account or a subaccount it owns.
|
|
7
|
-
*
|
|
7
|
+
* Calls accept a session JWT, or an API key scoped to the main account whose policy grants
|
|
8
|
+
* `read-daily-claims` (status) or `claim-daily-reward` (claim).
|
|
8
9
|
*/
|
|
9
10
|
declare class ClaimsService {
|
|
10
11
|
#private;
|
|
@@ -18,7 +19,9 @@ declare class ClaimsService {
|
|
|
18
19
|
/**
|
|
19
20
|
* Claims the current UTC day's reward, paid to the root account or to `subaccountId` when it
|
|
20
21
|
* names a subaccount the root account owns. The destination is fixed by the first claim of the
|
|
21
|
-
* day; retrying returns the same claim and destination.
|
|
22
|
+
* day; retrying returns the same claim and destination. A `ClaimOutcomeUnknownError` means the
|
|
23
|
+
* claim is recorded and its payout submitted but not yet confirmed: show it as pending, then
|
|
24
|
+
* poll `getDailyClaimStatus` until its `claimId` is `claimed`, or retry this call.
|
|
22
25
|
*/
|
|
23
26
|
claimDailyReward(input?: ClaimDailyRewardInput, options?: PolyesterMutationOptions): Promise<ClaimDailyRewardResult>;
|
|
24
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claims.d.ts","names":[],"sources":["../../../src/services/claims/claims.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"claims.d.ts","names":[],"sources":["../../../src/services/claims/claims.ts"],"mappings":";;;;;;;;;cAuBa;;EAGG,YAAA,YAAY;;;;;;EASlB,oBAAoB,UAAU,0BAA0B,QAAQ;;;;;;;;EAYhE,iBACF,QAAO,uBACP,UAAU,2BACX,QAAQ"}
|
|
@@ -6,7 +6,8 @@ import { createClient } from "@connectrpc/connect";
|
|
|
6
6
|
//#region src/services/claims/claims.ts
|
|
7
7
|
/**
|
|
8
8
|
* Reads and claims daily campaign rewards for the authenticated root account or a subaccount it owns.
|
|
9
|
-
*
|
|
9
|
+
* Calls accept a session JWT, or an API key scoped to the main account whose policy grants
|
|
10
|
+
* `read-daily-claims` (status) or `claim-daily-reward` (claim).
|
|
10
11
|
*/
|
|
11
12
|
var ClaimsService = class {
|
|
12
13
|
#client;
|
|
@@ -25,7 +26,9 @@ var ClaimsService = class {
|
|
|
25
26
|
/**
|
|
26
27
|
* Claims the current UTC day's reward, paid to the root account or to `subaccountId` when it
|
|
27
28
|
* names a subaccount the root account owns. The destination is fixed by the first claim of the
|
|
28
|
-
* day; retrying returns the same claim and destination.
|
|
29
|
+
* day; retrying returns the same claim and destination. A `ClaimOutcomeUnknownError` means the
|
|
30
|
+
* claim is recorded and its payout submitted but not yet confirmed: show it as pending, then
|
|
31
|
+
* poll `getDailyClaimStatus` until its `claimId` is `claimed`, or retry this call.
|
|
29
32
|
*/
|
|
30
33
|
async claimDailyReward(input = {}, options) {
|
|
31
34
|
const { subaccountId } = parse(ClaimDailyRewardInputSchema, input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claims.js","names":["#client","Proto.ClaimsService"],"sources":["../../../src/services/claims/claims.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/claims/v1/claims_pb.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n ClaimDailyRewardInputSchema,\n ClaimDailyRewardResultSchema,\n DailyClaimStatusSchema,\n type ClaimDailyRewardInput,\n type ClaimDailyRewardResult,\n type DailyClaimStatus,\n} from \"./claims.schemas.js\";\n\n/**\n * Reads and claims daily campaign rewards for the authenticated root account or a subaccount it owns.\n *
|
|
1
|
+
{"version":3,"file":"claims.js","names":["#client","Proto.ClaimsService"],"sources":["../../../src/services/claims/claims.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/claims/v1/claims_pb.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n ClaimDailyRewardInputSchema,\n ClaimDailyRewardResultSchema,\n DailyClaimStatusSchema,\n type ClaimDailyRewardInput,\n type ClaimDailyRewardResult,\n type DailyClaimStatus,\n} from \"./claims.schemas.js\";\n\n/**\n * Reads and claims daily campaign rewards for the authenticated root account or a subaccount it owns.\n * Calls accept a session JWT, or an API key scoped to the main account whose policy grants\n * `read-daily-claims` (status) or `claim-daily-reward` (claim).\n */\nexport class ClaimsService {\n #client: Client<typeof Proto.ClaimsService>;\n\n constructor(transports: AuthApiTransports) {\n this.#client = createClient(Proto.ClaimsService, transports.authApi);\n }\n\n /**\n * Returns the current UTC day's available or existing claim and its reset time. A\n * `payout_delayed` claim is recorded and paid automatically once payouts resume;\n * `payoutDelayReason` names the cause, such as `CLAIM_PAYOUT_UNAVAILABLE`.\n */\n async getDailyClaimStatus(options?: PolyesterRequestOptions): Promise<DailyClaimStatus> {\n const response = await this.#client.getDailyClaimStatus({}, toConnectCallOptions(options));\n return parse(DailyClaimStatusSchema, response);\n }\n\n /**\n * Claims the current UTC day's reward, paid to the root account or to `subaccountId` when it\n * names a subaccount the root account owns. The destination is fixed by the first claim of the\n * day; retrying returns the same claim and destination. A `ClaimOutcomeUnknownError` means the\n * claim is recorded and its payout submitted but not yet confirmed: show it as pending, then\n * poll `getDailyClaimStatus` until its `claimId` is `claimed`, or retry this call.\n */\n async claimDailyReward(\n input: ClaimDailyRewardInput = {},\n options?: PolyesterMutationOptions,\n ): Promise<ClaimDailyRewardResult> {\n const { subaccountId } = parse(ClaimDailyRewardInputSchema, input);\n const response = await this.#client.claimDailyReward(\n { subaccountId },\n toConnectCallOptions(options),\n );\n return parse(ClaimDailyRewardResultSchema, response);\n }\n}\n"],"mappings":";;;;;;;;;;;AAuBA,IAAa,gBAAb,MAA2B;CACvB;CAEA,YAAY,YAA+B;EACvC,KAAKA,UAAU,aAAaC,iBAAqB,WAAW,OAAO;CACvE;;;;;;CAOA,MAAM,oBAAoB,SAA8D;EACpF,MAAM,WAAW,MAAM,KAAKD,QAAQ,oBAAoB,CAAC,GAAG,qBAAqB,OAAO,CAAC;EACzF,OAAO,MAAM,wBAAwB,QAAQ;CACjD;;;;;;;;CASA,MAAM,iBACF,QAA+B,CAAC,GAChC,SAC+B;EAC/B,MAAM,EAAE,iBAAiB,MAAM,6BAA6B,KAAK;EACjE,MAAM,WAAW,MAAM,KAAKA,QAAQ,iBAChC,EAAE,aAAa,GACf,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,8BAA8B,QAAQ;CACvD;AACJ"}
|
|
@@ -14,7 +14,7 @@ type TimestampInit = {
|
|
|
14
14
|
declare const GetOrderbookHeatmapInputSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
15
15
|
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
16
16
|
readonly interval: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["1s", "1m", "5m", "1h"], undefined>, "1s">, v.TransformAction<"1h" | "1m" | "1s" | "5m", HeatmapInterval>]>;
|
|
17
|
-
readonly depth: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly [1, 5, 10, 20, 50, 100, 200, 500, 1000], undefined>, 50>, v.TransformAction<1 | 5 | 10 | 20 | 100 | 500 |
|
|
17
|
+
readonly depth: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly [1, 5, 10, 20, 50, 100, 200, 500, 1000], undefined>, 50>, v.TransformAction<1 | 5 | 10 | 20 | 100 | 500 | 200 | 50 | 1000, HeatmapDepth>]>;
|
|
18
18
|
readonly quantityMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["close", "peak"], undefined>, "close">, v.TransformAction<"close" | "peak", HeatmapQuantityMode>]>;
|
|
19
19
|
readonly limit: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 20000, undefined>]>;
|
|
20
20
|
readonly startTsSec: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, number, undefined>, v.TransformAction<number, bigint>]>, undefined>;
|
|
@@ -227,7 +227,7 @@ type OrderbookHeatmapDeltaChain = ReturnType<typeof convertHeatmapDeltaChain>;
|
|
|
227
227
|
declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
228
228
|
readonly symbolId: v.NumberSchema<undefined>;
|
|
229
229
|
readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1h" | "1m" | "1s" | "5m">>]>;
|
|
230
|
-
readonly depth: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, 1 | 5 | 10 | 20 | "unspecified" | 100 | 500 |
|
|
230
|
+
readonly depth: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, 1 | 5 | 10 | 20 | "unspecified" | 100 | 500 | 200 | 50 | 1000>]>;
|
|
231
231
|
readonly chain: v.OptionalSchema<v.ObjectSchema<{
|
|
232
232
|
readonly baseKeyframe: v.OptionalSchema<v.ObjectSchema<{
|
|
233
233
|
readonly tsSec: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, number>]>;
|
|
@@ -287,7 +287,7 @@ declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.Sche
|
|
|
287
287
|
}, undefined>, v.TransformAction<{
|
|
288
288
|
symbolId: number;
|
|
289
289
|
interval: DecodedEnum<"1h" | "1m" | "1s" | "5m">;
|
|
290
|
-
depth: 1 | 5 | 10 | 20 | "unspecified" | 100 | 500 |
|
|
290
|
+
depth: 1 | 5 | 10 | 20 | "unspecified" | 100 | 500 | 200 | 50 | 1000;
|
|
291
291
|
chain?: {
|
|
292
292
|
baseKeyframe?: {
|
|
293
293
|
tsSec: number;
|
|
@@ -347,7 +347,7 @@ declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.Sche
|
|
|
347
347
|
}, {
|
|
348
348
|
symbolId: number;
|
|
349
349
|
interval: DecodedEnum<"1h" | "1m" | "1s" | "5m">;
|
|
350
|
-
depth: 1 | 5 | 10 | 20 | "unspecified" | 100 | 500 |
|
|
350
|
+
depth: 1 | 5 | 10 | 20 | "unspecified" | 100 | 500 | 200 | 50 | 1000;
|
|
351
351
|
chain: {
|
|
352
352
|
baseKeyframe: {
|
|
353
353
|
tsSec: number;
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { AuthApiTransports } from "../../shared/transports.js";
|
|
2
|
-
import { PolyesterMutationOptions } from "../../shared/request-options.js";
|
|
2
|
+
import { PolyesterMutationOptions, PolyesterRequestOptions } from "../../shared/request-options.js";
|
|
3
3
|
import { SubaccountResolver } from "../subaccount-resolver.js";
|
|
4
4
|
import { SdkScales } from "../../shared/decimal-surface.js";
|
|
5
|
-
import { CreateInternalTransferInput, CreateInternalTransferResult } from "./internal-transfers.schemas.js";
|
|
5
|
+
import { CreateInternalTransferInput, CreateInternalTransferResult, GetInternalTransferInput, GetInternalTransferResult } from "./internal-transfers.schemas.js";
|
|
6
6
|
//#region src/services/internal-transfers/internal-transfers.d.ts
|
|
7
7
|
/**
|
|
8
|
-
* Creates authenticated Trading-to-Trading internal transfer requests.
|
|
8
|
+
* Creates and reads authenticated Trading-to-Trading internal transfer requests.
|
|
9
9
|
*/
|
|
10
10
|
declare class InternalTransfersService {
|
|
11
11
|
#private;
|
|
12
12
|
constructor(transports: AuthApiTransports, resolver: SubaccountResolver | undefined, scales: SdkScales);
|
|
13
13
|
/**
|
|
14
|
-
* Creates or returns an idempotent internal transfer from the resolved source account to a destination root account, subaccount, or smart-account address. The request carries asset id, a decimal quantity, and a stable idempotency key; the response includes request/transfer ids, resolved destination, and status. Rejections and failures, such as insufficient funds or a missing step-up, raise errors instead of returning a result.
|
|
14
|
+
* Creates or returns an idempotent internal transfer from the resolved source account to a destination root account, subaccount, or smart-account address. The request carries asset id, a decimal quantity, and a stable idempotency key; the response includes request/transfer ids, the lifecycle `flowId`, resolved destination, and status. Rejections and failures, such as insufficient funds or a missing step-up, raise errors instead of returning a result.
|
|
15
15
|
*/
|
|
16
16
|
create(input: CreateInternalTransferInput, options?: PolyesterMutationOptions): Promise<CreateInternalTransferResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Reads an accepted transfer of the resolved source account by exactly one of `requestId` or
|
|
19
|
+
* `transferId`, and returns both IDs, the lifecycle `flowId` and the acceptance time. Use it
|
|
20
|
+
* to reconcile a transfer without resubmitting it; pass `flowId` to `lifecycle.getFlow`,
|
|
21
|
+
* whose ledger settlement step carries the transfer ID. An unknown, pending or inaccessible
|
|
22
|
+
* transfer is a `ResourceNotFoundError`, including briefly after a delegate is granted access.
|
|
23
|
+
* Session JWT only; API keys are refused. Moves no money and needs no step-up.
|
|
24
|
+
*/
|
|
25
|
+
get(input: GetInternalTransferInput, options?: PolyesterRequestOptions): Promise<GetInternalTransferResult>;
|
|
17
26
|
}
|
|
18
27
|
//#endregion
|
|
19
28
|
export { InternalTransfersService };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-transfers.d.ts","names":[],"sources":["../../../src/services/internal-transfers/internal-transfers.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"internal-transfers.d.ts","names":[],"sources":["../../../src/services/internal-transfers/internal-transfers.ts"],"mappings":";;;;;;;;;cA0Ba;;EAQL,YAAA,YAAY,mBACZ,UAAU,gCACV,QAAQ;;;;EAYN,OACF,OAAO,6BACP,UAAU,2BACX,QAAQ;;;;;;;;;EAmBL,IACF,OAAO,0BACP,UAAU,0BACX,QAAQ"}
|