src/transport/types.ts
v0.2.0 · 2.4 KB
// Networks, gateway URLs and the request / response contract of the gateway.
export type Network = 'mainnet' | 'testnet';
/** Gateway base URLs (`/query` and `/execute` are appended). */
export const GATEWAY_URL: Record<Network, string> = {
mainnet: 'https://gateway.prod.nado.xyz/v1',
testnet: 'https://gateway.test.nado.xyz/v1',
};
/** Chain ids confirmed by the `contracts` query (2026-07-24): Ink mainnet and Ink Sepolia. */
export const CHAIN_ID: Record<Network, number> = {
mainnet: 57073,
testnet: 763373,
};
/** Body of `POST /query`: `{ type, ...params }`. No signature. */
export interface QueryRequest {
type: string;
[key: string]: unknown;
}
/** Body of `POST /execute`: `{ <action>: { ..., signature } }` with exactly one action key. */
export type ExecuteRequest = Record<string, unknown>;
/** Success envelope. */
export interface SuccessEnvelope<T = unknown> {
status: 'success';
data: T;
request_type?: string;
}
/** Failure envelope: for an execute this is the sequencer's definitive refusal (nothing was applied). */
export interface FailureEnvelope {
status: 'failure';
error: string;
error_code: number;
request_type?: string;
}
export type Envelope<T = unknown> = SuccessEnvelope<T> | FailureEnvelope;
/** Options shared by query and execute calls. */
export interface GatewayCallOptions {
/** Request weight for the throttle; derived from the body when omitted. */
weight?: number;
/** Free-form label for telemetry counters (`orders`, `order:close`, ...). */
label?: string;
/** Abort signal combined with the client's own timeout. */
signal?: AbortSignal;
/** Per-call timeout override, ms. */
timeoutMs?: number;
}
/** Options of an execute call. */
export interface ExecuteCallOptions extends GatewayCallOptions {
/**
* `true` only for actions whose repetition cannot change the outcome: `cancel_orders`, a FULL
* reduce-only close. Opens, increases and partial reductions are NOT idempotent: after a timeout the
* order may have been applied, and a retry doubles the position. Default `false`.
*/
idempotent?: boolean;
}
/** Performs one `POST /query` and resolves with the unwrapped `data`. */
export type QueryRequester = <T = unknown>(body: QueryRequest, opts?: GatewayCallOptions) => Promise<T>;
/** Performs one `POST /execute` and resolves with the unwrapped `data`. */
export type ExecuteRequester = <T = unknown>(body: ExecuteRequest, opts?: ExecuteCallOptions) => Promise<T>;