ault-sdk-ts 0.0.2-alpha.15 → 0.0.2-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -164,9 +164,148 @@ interface ClientOptions {
164
164
  fetchOptions?: FetchWithRetryOptions;
165
165
  defaultGasLimit?: string; // Optional: default gas limit
166
166
  defaultMemo?: string; // Optional: default memo
167
+ defaultConfirmationTimeoutMs?: number;
168
+ manifestOverride?: Manifest; // Optional: caller-supplied manifest layer (see "SDK Manifest")
167
169
  }
168
170
  ```
169
171
 
172
+ ## SDK Manifest
173
+
174
+ `createClient` resolves network endpoints and gas/EIP-712 defaults from three
175
+ layers, in increasing precedence:
176
+
177
+ 1. The embedded baseline shipped with the SDK (`NetworkConfig` plus
178
+ `GAS_CONSTANTS`).
179
+ 2. The manifest fetched from `<dexApiUrl>/api/v1/sdk-manifest` at bootstrap
180
+ and refreshed every five minutes in the background. The operator
181
+ rotates URLs, EIP-712 fee defaults, and per-module gas constants by
182
+ editing the dex-api `SDK_MANIFEST_JSON` env var; older SDK versions
183
+ pick up the new values within one refresh window without a package
184
+ bump.
185
+ 3. An optional `manifestOverride` you pass to `createClient`. The
186
+ override sits on top of both other layers, is frozen for the
187
+ lifetime of the client, and is not touched by background refreshes.
188
+
189
+ The override layer covers cases the fetched manifest cannot: pointing the
190
+ client at a private RPC during local development, pinning a deterministic
191
+ manifest in tests, surviving a URL rotation cutover by keeping the old
192
+ endpoint until you redeploy, or tuning gas constants without waiting on a
193
+ manifest deploy.
194
+
195
+ ```typescript
196
+ import { createClient, getNetworkConfig, type Manifest } from "ault-sdk-ts";
197
+
198
+ const manifestOverride: Manifest = {
199
+ schemaVersion: 1,
200
+ urls: {
201
+ rpc: "https://rpc.internal.example.com",
202
+ },
203
+ gas: {
204
+ LIMIT_ORDER: 250000,
205
+ },
206
+ };
207
+
208
+ const client = await createClient({
209
+ network: getNetworkConfig("ault_10904-1"),
210
+ signer: account,
211
+ manifestOverride,
212
+ });
213
+ ```
214
+
215
+ The override is sparse — every field is optional and only the keys you set
216
+ take effect. Disjoint keys still flow through from the fetched manifest, so
217
+ `{gas: {LIMIT_ORDER: 250000}}` does not erase a `MARKET_ORDER` value the
218
+ dex-api emits. Unknown top-level keys pass through untouched for forward
219
+ compatibility with future manifest fields.
220
+
221
+ ### Supported fields
222
+
223
+ The `Manifest` type has four top-level keys. `schemaVersion` is required; the
224
+ three sub-objects are optional and each one is itself sparse.
225
+
226
+ ```typescript
227
+ interface Manifest {
228
+ schemaVersion: number; // required, integer >= 1
229
+ urls?: Partial<ManifestUrls>;
230
+ eip712?: Partial<ManifestEip712>;
231
+ gas?: Partial<ManifestGas>;
232
+ // unknown top-level keys are preserved for forward compatibility
233
+ }
234
+ ```
235
+
236
+ **`urls`** — endpoint overrides. Each value is a string and applies only if
237
+ non-empty. The `dexApiUrl` itself is not overridable here (it is the trust
238
+ root for the fetched manifest).
239
+
240
+ | Key | Maps to `NetworkConfig` field |
241
+ | ---------- | ----------------------------- |
242
+ | `rpc` | `rpcUrl` |
243
+ | `rest` | `restUrl` |
244
+ | `evm` | `evmRpcUrl` |
245
+ | `explorer` | `explorerUrl` |
246
+ | `dexWs` | `dexWsUrl` |
247
+
248
+ URL rotations propagate to the tx executor on the next call but not to the
249
+ REST/WS contexts captured at `createClient` time. Re-create the client to
250
+ pick up new endpoints across the board.
251
+
252
+ **`eip712`** — fee defaults applied to every transaction unless per-call
253
+ options override them.
254
+
255
+ | Key | Type | Notes |
256
+ | ----------- | -------------------------------- | ------------------------------ |
257
+ | `feeDenom` | non-empty string | replaces `GAS_CONSTANTS.DENOM` |
258
+ | `feeAmount` | non-negative integer string | raw `aault`, `"0"` allowed |
259
+ | `gasLimit` | strictly positive integer string | gas units, `"0"` rejected |
260
+
261
+ **`gas`** — per-message-type gas constants and the fee-free multiplier.
262
+ Every value is a positive integer. Keys outside the supported list are
263
+ dropped silently and the embedded baseline keeps applying.
264
+
265
+ The keys most consumers will touch are the CLOB ones plus the fee-free
266
+ multiplier:
267
+
268
+ | Key | Used by |
269
+ | ------------------------- | ---------------------------------------- |
270
+ | `FEE_FREE_GAS_MULTIPLIER` | fee-free gas computation across all msgs |
271
+ | `LIMIT_ORDER` | `placeLimitOrder` |
272
+ | `MARKET_ORDER` | `placeMarketOrder` |
273
+ | `SCALE_ORDER_BASE` | `placeScaleOrder` (base cost) |
274
+ | `SCALE_ORDER_PER_SUB` | `placeScaleOrder` (per sub-order) |
275
+ | `CANCEL_ORDER_BASE` | `cancelOrders` (base cost) |
276
+ | `CANCEL_ORDER_PER_ID` | `cancelOrders` (per order id) |
277
+
278
+ The schema also accepts per-message gas constants for the license,
279
+ miner, agent, reward, and accountx modules (`PER_LICENSE`,
280
+ `PER_DELEGATE_MINING`, `APPROVE_AGENT`, `SET_REFERRAL_CODE`,
281
+ `OPEN_ACCOUNT`, and the rest). These exist for operator-side
282
+ deploy-cycle bypass and are rarely needed in consumer code. The full
283
+ list lives in `ManifestGasSchema` in `src/core/manifest-types.ts`.
284
+
285
+ The `gas` blob never accepts `EIP712_FEE_AMOUNT`, `EIP712_GAS_LIMIT`, or
286
+ `DENOM` — those live on `eip712` as `feeAmount`, `gasLimit`, and
287
+ `feeDenom`. Smuggling them through `gas` is dropped defensively because
288
+ the broadcast layer never reads them off the gas object.
289
+
290
+ The value validates against `ManifestSchema` synchronously at `createClient`
291
+ time. A malformed override throws straight away with the schema error
292
+ instead of falling back to the baseline the way a broken fetched manifest
293
+ does, since override data comes from your code and a typo is a bug worth
294
+ surfacing loudly. The caller's object is deep-cloned at construction, so
295
+ mutating it after `createClient` returns does not affect resolver state.
296
+
297
+ When a non-empty override is present, the resolver emits one
298
+ `console.info` line at boot listing the override key paths (never values,
299
+ since `urls` may carry private endpoints).
300
+
301
+ If you also use `client.attachAgent(...)`, the agent surface reuses the
302
+ same manifest resolver, so the override flows through to agent-signed
303
+ transactions without separate plumbing.
304
+
305
+ The package also re-exports the low-level helpers if you need them:
306
+ `mergeManifests`, `fetchManifest`, `applyNetworkOverrides`,
307
+ `applyGasOverrides`, `createManifestResolver`, `createStaticResolver`.
308
+
170
309
  ## Query Methods
171
310
 
172
311
  The client provides pass-through access to all REST API methods:
@@ -648,6 +787,115 @@ await client.delegateMining({
648
787
  });
649
788
  ```
650
789
 
790
+ ## Agent-Signed Transactions
791
+
792
+ The chain's `agent` module lets a master account approve a separate keypair to
793
+ submit a restricted set of CLOB transactions on its behalf, without prompting
794
+ the master signer for each one. Typical use cases: market-making bots that
795
+ sign hot orders with a short-lived key, or trading UIs that sign orders
796
+ without a wallet popup per click.
797
+
798
+ The SDK exposes this through `client.attachAgent(...)` rather than a separate
799
+ client. The agent surface reuses the master client's manifest resolver, REST
800
+ contexts, and account-info cache — one network state, one of every cached
801
+ resource, no chance of drift between wallet-signed and agent-signed paths.
802
+
803
+ ### Approve and attach an agent
804
+
805
+ ```typescript
806
+ import { createClient, encodeEthSecp256k1PubKey, deriveAgentAddress } from "ault-sdk-ts";
807
+ import { secp256k1 } from "@noble/curves/secp256k1";
808
+ import { hexToBytes } from "viem";
809
+
810
+ const client = await createClient({ network, signer: masterSigner });
811
+
812
+ // 1. Generate (or load) the agent keypair.
813
+ const agentPrivateKey = `0x${"a".repeat(64)}`; // load from secret store in real usage
814
+ const compressed = secp256k1.getPublicKey(hexToBytes(agentPrivateKey), true);
815
+ const agentPubkey = {
816
+ typeUrl: "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey",
817
+ value: encodeEthSecp256k1PubKey(compressed),
818
+ };
819
+
820
+ // 2. Master approves the agent on-chain (wallet-signed).
821
+ await client.approveAgent({
822
+ agentPubkey,
823
+ name: "market-maker-bot",
824
+ expiry: { seconds: 86_400n * 30n, nanos: 0 }, // 30 days
825
+ });
826
+
827
+ // 3. Attach the agent surface to this client.
828
+ const agent = client.attachAgent({ agentPrivateKey });
829
+ console.log(agent.address); // bech32 agent address
830
+ console.log(agent.masterAddress); // = client.address
831
+ console.log(client.asAgent === agent); // true
832
+ ```
833
+
834
+ ### Place agent-signed orders
835
+
836
+ ```typescript
837
+ // Same shape as the wallet-signed equivalents on `client.*`.
838
+ await client.asAgent!.placeLimitOrder({
839
+ marketId,
840
+ isBuy: true,
841
+ price: "1.0",
842
+ quantity: "1000000000000000000",
843
+ lifespan: { seconds: 3600n, nanos: 0 },
844
+ });
845
+
846
+ await client.asAgent!.placeMarketOrder({
847
+ marketId,
848
+ isBuy: true,
849
+ deposit: "5000000000000000000",
850
+ });
851
+
852
+ await client.asAgent!.cancelOrders({ orderIds: [...] });
853
+
854
+ await client.asAgent!.placeScaleOrder({
855
+ marketId,
856
+ isBuy: true,
857
+ lowPrice: "0.9",
858
+ highPrice: "1.1",
859
+ totalQuantity: "10000000000000000000",
860
+ weights: [3333, 3334, 3333],
861
+ lifespan: { seconds: 3600n, nanos: 0 },
862
+ });
863
+ ```
864
+
865
+ ### Rotate or detach the agent
866
+
867
+ ```typescript
868
+ // Rotate: attachAgent replaces the prior agent in place. The previous
869
+ // surface is overwritten — read from `client.asAgent` after attaching.
870
+ client.attachAgent({ agentPrivateKey: newKey });
871
+
872
+ // Detach: clears `client.asAgent`. Idempotent.
873
+ client.detachAgent();
874
+
875
+ // Revoke on-chain (wallet-signed) when the agent should no longer sign.
876
+ await client.revokeAgent({ agentAddress: agent.address });
877
+ ```
878
+
879
+ ### What `attachAgent` shares with the master client
880
+
881
+ | Resource | Behavior |
882
+ | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
883
+ | `ManifestResolver` | One per `Client`. The agent path reads `getNetwork()` / `getGas()` from the same resolver, so URL and EIP-712 manifest overrides reach both signing paths atomically. |
884
+ | `AccountCache` | The master's `accountNumber` is fetched once. The agent path reads it from the shared cache; it never increments `nextSequence` (agent txs always sign with `sequence=0`). |
885
+ | REST/WS contexts | The master client's `client.<module>` query APIs are the only query surface — the agent surface is tx-only. |
886
+ | Lifecycle | `client.dispose()` clears `asAgent` and stops the manifest refresh timer. Calling `attachAgent` after `dispose()` throws. |
887
+
888
+ ### Notes
889
+
890
+ - `client.asAgent` is `null` until `attachAgent` is called. After detach or
891
+ dispose it is `null` again. Always read it fresh; do not cache references
892
+ across rotations.
893
+ - `attachAgent` is synchronous (no network I/O). The first agent tx may
894
+ trigger one `queryAccount` RPC if the cache is cold; subsequent agent
895
+ txs reuse the cached `accountNumber`.
896
+ - Two concurrent agents from the same master require two `Client`
897
+ instances — `attachAgent` replaces, it does not coexist.
898
+
651
899
  ## Development
652
900
 
653
901
  ### Generating Protos
@@ -0,0 +1,26 @@
1
+ import type { AccountCache } from "../eip712/sign-and-broadcast";
2
+ import type { FetchFn, FetchWithRetryOptions } from "../core/http";
3
+ import type { GAS_CONSTANTS, NetworkConfig } from "../core/network";
4
+ import type { AgentSurface, AttachAgentOptions } from "../high-level/types";
5
+ export { AGENT_DEFAULTS } from "./sign-and-broadcast";
6
+ /**
7
+ * Derives the agent's bech32 address from its private key. Mirrors the
8
+ * EVM-style derivation used by the chain's agent module: keccak256 of the
9
+ * uncompressed pubkey, take the lower 20 bytes, encode as bech32.
10
+ */
11
+ export declare function deriveAgentAddress(privateKeyHex: string): string;
12
+ export interface BuildAgentSurfaceContext {
13
+ masterAddress: string;
14
+ getNetwork: () => NetworkConfig;
15
+ getGas: () => typeof GAS_CONSTANTS;
16
+ cache: AccountCache;
17
+ fetchFn?: FetchFn;
18
+ fetchOptions?: FetchWithRetryOptions;
19
+ }
20
+ /**
21
+ * Builds the agent-signed CLOB tx surface attached to a `Client`. Reuses
22
+ * the client's manifest resolver (via `getNetwork` / `getGas`) and master
23
+ * account-info cache (via `cache`) so attaching does not trigger a manifest
24
+ * fetch or a duplicate account RPC.
25
+ */
26
+ export declare function buildAgentSurface(options: AttachAgentOptions, ctx: BuildAgentSurfaceContext): AgentSurface;
@@ -1,7 +1,14 @@
1
+ import { type GAS_CONSTANTS } from "../../core/network";
1
2
  import type { AgentClobTxApi } from "../../high-level/types";
2
3
  import type { AgentTxExecutor } from "../tx-executor";
3
4
  export interface AgentClobTxContext {
4
5
  masterAddress: string;
5
6
  exec: AgentTxExecutor;
7
+ /**
8
+ * Returns the current gas constants — base GAS_CONSTANTS overlaid with any
9
+ * manifest overrides for the active client. Read on each tx so a hot-swap
10
+ * (manifest refresh) takes effect on the next call.
11
+ */
12
+ getGas: () => typeof GAS_CONSTANTS;
6
13
  }
7
- export declare function createAgentClobTxApi({ masterAddress, exec }: AgentClobTxContext): AgentClobTxApi;
14
+ export declare function createAgentClobTxApi({ masterAddress, exec, getGas, }: AgentClobTxContext): AgentClobTxApi;
@@ -2,8 +2,14 @@ import type { FetchFn, FetchWithRetryOptions } from "../core/http";
2
2
  import { type NetworkConfig } from "../core/network";
3
3
  import type { AnyEip712Msg } from "../eip712/builder";
4
4
  import type { AgentTxOptions, TxResult } from "../high-level/types";
5
+ import { type AccountCache } from "../eip712/sign-and-broadcast";
5
6
  export interface AgentTxExecutorOptions {
6
- network: NetworkConfig;
7
+ /**
8
+ * Returns the network with the latest manifest URL/eip712 overrides applied.
9
+ * Called fresh on every tx so a hot-swap takes effect on the next call
10
+ * without re-creating the executor.
11
+ */
12
+ getNetwork: () => NetworkConfig;
7
13
  agentPrivateKey: string;
8
14
  masterAddress: string;
9
15
  fetchFn?: FetchFn;
@@ -12,6 +18,14 @@ export interface AgentTxExecutorOptions {
12
18
  defaultMemo?: string;
13
19
  defaultConfirmationTimeoutMs?: number;
14
20
  defaultTimeoutSeconds?: number;
21
+ /**
22
+ * Optional shared account cache. When the agent shares a `Client` with the
23
+ * wallet path, pass the wallet's cache here so both executors read the
24
+ * master's accountNumber from the same memo. The agent path only reads
25
+ * `accountNumber`, never writes `nextSequence`, so it's safe to share.
26
+ * Without sharing, the agent executor maintains its own cache.
27
+ */
28
+ cache?: AccountCache;
15
29
  }
16
30
  export type AgentTxExecutor = (msgs: AnyEip712Msg[], txOptions?: AgentTxOptions) => Promise<TxResult>;
17
31
  export declare function createAgentTxExecutor(options: AgentTxExecutorOptions): AgentTxExecutor;
@@ -0,0 +1,12 @@
1
+ import { type FetchFn, type FetchWithRetryOptions } from "./http";
2
+ import { type Manifest } from "./manifest-types";
3
+ /**
4
+ * Fetches the SDK manifest from the dex-api at `<dexApiUrl>/api/v1/sdk-manifest`.
5
+ *
6
+ * Returns the parsed manifest on success, or `null` on any failure:
7
+ * network error, non-2xx response, JSON parse error, or schema mismatch.
8
+ * The resolver treats `null` as "stay with the embedded baseline" and never
9
+ * propagates the failure to the caller — the SDK is expected to keep working
10
+ * when the manifest endpoint is unavailable.
11
+ */
12
+ export declare function fetchManifest(dexApiUrl: string, fetchFn?: FetchFn, fetchOptions?: FetchWithRetryOptions): Promise<Manifest | null>;
@@ -0,0 +1,120 @@
1
+ import { GAS_CONSTANTS, type NetworkConfig } from "./network";
2
+ import type { FetchFn, FetchWithRetryOptions } from "./http";
3
+ import { type Manifest, type ManifestGas } from "./manifest-types";
4
+ /**
5
+ * Sparse field-level merge of two manifests. The right operand wins on every
6
+ * key it provides. Returns null only when both inputs are null.
7
+ *
8
+ * `schemaVersion` is taken from `top` when present so a caller override can
9
+ * declare a future schema version while the SDK keeps validating per the
10
+ * version it knows. Sub-objects (`gas`, `eip712`, `urls`) are merged at the
11
+ * leaf-key level, not replaced wholesale — passing `{gas: {LIMIT_ORDER: 1}}`
12
+ * does not erase a fetched `MARKET_ORDER`.
13
+ *
14
+ * Unknown top-level keys (anything outside `schemaVersion / gas / eip712 / urls`)
15
+ * pass through with `top` winning on overlap. The manifest schema is a zod
16
+ * looseObject so a future dex-api emitting additional fields keeps working
17
+ * with older SDKs; reconstructing only the four known fields here would have
18
+ * silently dropped those forward-compat keys whenever a caller-side override
19
+ * was present.
20
+ */
21
+ export declare function mergeManifests(base: Manifest | null, top: Manifest | null): Manifest | null;
22
+ /**
23
+ * Returns a NetworkConfig with manifest URL and eip712 overrides applied.
24
+ * Fields the manifest does not specify pass through unchanged. URL values
25
+ * are required to be non-empty strings — defense in depth for callers that
26
+ * bypass zod with a hand-rolled blob (a non-string URL would otherwise crash
27
+ * `String.prototype.endsWith` etc. inside the REST/WS context). EIP-712
28
+ * numerics are pre-validated by `ManifestEip712Schema`.
29
+ */
30
+ export declare function applyNetworkOverrides(network: NetworkConfig, manifest: Manifest | null): NetworkConfig;
31
+ /**
32
+ * Returns a GAS_CONSTANTS-shaped object with manifest gas overrides applied.
33
+ *
34
+ * The manifest schema (see `ManifestGasSchema`) only exposes per-msg-type
35
+ * gas and the fee-free multiplier; EIP-712 fee/gas/denom defaults travel via
36
+ * `ManifestEip712Schema` and apply through `applyNetworkOverrides`. As
37
+ * defense in depth (in case a caller bypasses zod and passes a hand-rolled
38
+ * blob), this helper actively drops `EIP712_FEE_AMOUNT`, `EIP712_GAS_LIMIT`,
39
+ * and `DENOM` so the embedded values stay authoritative for the gas-constants
40
+ * object — the broadcast layer reads those off `network.eip712*`, never off
41
+ * the gas blob.
42
+ *
43
+ * The cast widens the zod-partial back to the concrete `GAS_CONSTANTS` type:
44
+ * every field has a baseline value, so any key the manifest omits keeps the
45
+ * embedded one.
46
+ */
47
+ export declare function applyGasOverrides(gas: ManifestGas | undefined): typeof GAS_CONSTANTS;
48
+ export interface ManifestResolverOptions {
49
+ network: NetworkConfig;
50
+ fetchFn?: FetchFn;
51
+ fetchOptions?: FetchWithRetryOptions;
52
+ /**
53
+ * Milliseconds between background refreshes. Default: 5 minutes.
54
+ * 0 disables hot-swap (the initial fetch still runs).
55
+ */
56
+ refreshIntervalMs?: number;
57
+ /**
58
+ * Caller-supplied override applied on top of the fetched manifest. Frozen
59
+ * at construction time (deep-cloned) so post-`createClient` mutation by the
60
+ * caller cannot poison resolver state. Must validate against
61
+ * `ManifestSchema`; otherwise `createManifestResolver` throws.
62
+ */
63
+ override?: Manifest;
64
+ }
65
+ export interface ManifestResolver {
66
+ /** The base network the resolver was created against. Stable. */
67
+ readonly baseNetwork: NetworkConfig;
68
+ /** Returns the most recently fetched manifest, or null if none has succeeded. */
69
+ currentManifest(): Manifest | null;
70
+ /** Network with the latest manifest URL/eip712 overrides applied. */
71
+ currentNetwork(): NetworkConfig;
72
+ /** Gas constants with the latest manifest gas overrides applied. */
73
+ currentGas(): typeof GAS_CONSTANTS;
74
+ /** Triggers an out-of-band refresh. Resolves regardless of fetch outcome. */
75
+ refresh(): Promise<void>;
76
+ /** Stops the background refresh. Safe to call multiple times. */
77
+ dispose(): void;
78
+ }
79
+ /**
80
+ * Builds a manifest resolver bound to a network.
81
+ *
82
+ * Performs an initial fetch (best-effort, tight timeout: failure leaves the
83
+ * manifest empty) and starts a background refresh loop unless
84
+ * `refreshIntervalMs` is 0 or `dexApiUrl` is unset. The promise resolves
85
+ * once the initial fetch attempt has completed.
86
+ *
87
+ * Background refreshes are jittered ±10% around `refreshIntervalMs` to keep
88
+ * a fleet of SDK consumers from hitting the dex-api in lockstep.
89
+ */
90
+ export declare function createManifestResolver(opts: ManifestResolverOptions): Promise<ManifestResolver>;
91
+ /**
92
+ * Options for {@link createStaticResolver}. Mirrors the `network`/`override`
93
+ * shape of {@link ManifestResolverOptions} so callers can move between the
94
+ * two without re-ordering arguments. The `manifest` field is the static
95
+ * fetched-layer stand-in (typically `null` in tests that want the embedded
96
+ * baseline; non-null when injecting a fixed manifest).
97
+ */
98
+ export interface StaticResolverOptions {
99
+ network: NetworkConfig;
100
+ /** Static stand-in for the fetched manifest. Defaults to `null`. */
101
+ manifest?: Manifest | null;
102
+ /** Caller-supplied override, validated and frozen at construction. */
103
+ override?: Manifest;
104
+ }
105
+ /**
106
+ * Static resolver — does not fetch, does not run a timer. Useful as the
107
+ * embedded-only path (no `dexApiUrl`) or in tests where you want to inject a
108
+ * fixed manifest. The `override` is treated identically to the
109
+ * `createManifestResolver` override: validated, deep-cloned, merged on top.
110
+ *
111
+ * Two call shapes are supported:
112
+ *
113
+ * 1. Options bag (preferred): `createStaticResolver({ network, manifest, override })`.
114
+ * 2. Legacy positional `(network, manifest)`: kept for backward compatibility
115
+ * with the pre-override signature. Untyped JS callers using the old shape
116
+ * keep working; TypeScript callers see the typed overload and pick whichever
117
+ * matches their argument shape.
118
+ */
119
+ export declare function createStaticResolver(opts: StaticResolverOptions): ManifestResolver;
120
+ export declare function createStaticResolver(network: NetworkConfig, manifest?: Manifest | null): ManifestResolver;
@@ -0,0 +1,94 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Per-message-type gas constants and the fee-free multiplier. This schema
4
+ * intentionally does NOT include `EIP712_FEE_AMOUNT`, `EIP712_GAS_LIMIT`, or
5
+ * `DENOM` — those live on `ManifestEip712Schema` (`feeAmount`, `gasLimit`,
6
+ * `feeDenom`) which is the only path read by the broadcast layer. Keeping
7
+ * both would create a silent no-op surface where overrides land in the gas
8
+ * blob and never get honored.
9
+ */
10
+ export declare const ManifestGasSchema: z.ZodObject<{
11
+ FEE_FREE_GAS_MULTIPLIER: z.ZodOptional<z.ZodNumber>;
12
+ PER_LICENSE: z.ZodOptional<z.ZodNumber>;
13
+ PER_KYC_MEMBER: z.ZodOptional<z.ZodNumber>;
14
+ PER_DELEGATE_MINING: z.ZodOptional<z.ZodNumber>;
15
+ PER_SUBMIT_WORK: z.ZodOptional<z.ZodNumber>;
16
+ SET_OWNER_VRF_KEY: z.ZodOptional<z.ZodNumber>;
17
+ APPROVE_AGENT: z.ZodOptional<z.ZodNumber>;
18
+ REVOKE_AGENT: z.ZodOptional<z.ZodNumber>;
19
+ APPROVE_BUILDER: z.ZodOptional<z.ZodNumber>;
20
+ REVOKE_BUILDER: z.ZodOptional<z.ZodNumber>;
21
+ SET_REFERRAL_CODE: z.ZodOptional<z.ZodNumber>;
22
+ SET_REFERRAL: z.ZodOptional<z.ZodNumber>;
23
+ LIMIT_ORDER: z.ZodOptional<z.ZodNumber>;
24
+ MARKET_ORDER: z.ZodOptional<z.ZodNumber>;
25
+ SCALE_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
26
+ SCALE_ORDER_PER_SUB: z.ZodOptional<z.ZodNumber>;
27
+ CANCEL_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
28
+ CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
29
+ OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
30
+ }, z.core.$strip>;
31
+ export declare const ManifestEip712Schema: z.ZodObject<{
32
+ feeDenom: z.ZodOptional<z.ZodString>;
33
+ feeAmount: z.ZodOptional<z.ZodString>;
34
+ gasLimit: z.ZodOptional<z.ZodString>;
35
+ }, z.core.$strip>;
36
+ /**
37
+ * URL overrides applied at boot of `createClient`. The dex-api is the trust
38
+ * root for these values; they are NOT URL-validated here on purpose — the
39
+ * dex-api already sits inside the SDK's trust boundary, and a stricter
40
+ * validator would force us to mirror operator expectations (trailing slashes,
41
+ * non-https envs, internal hostnames) in the SDK schema.
42
+ *
43
+ * Hot-swap semantics: subsequent rotations only reach the tx executor's
44
+ * network getter on the next tx call. Long-lived REST/WS contexts captured
45
+ * by `createAultClient` at boot do NOT pick up URL changes. Consumers that
46
+ * need fresh URLs after a rotation must re-create the client.
47
+ */
48
+ export declare const ManifestUrlsSchema: z.ZodObject<{
49
+ rpc: z.ZodOptional<z.ZodString>;
50
+ rest: z.ZodOptional<z.ZodString>;
51
+ evm: z.ZodOptional<z.ZodString>;
52
+ explorer: z.ZodOptional<z.ZodString>;
53
+ dexWs: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strip>;
55
+ export declare const ManifestSchema: z.ZodObject<{
56
+ schemaVersion: z.ZodNumber;
57
+ gas: z.ZodOptional<z.ZodObject<{
58
+ FEE_FREE_GAS_MULTIPLIER: z.ZodOptional<z.ZodNumber>;
59
+ PER_LICENSE: z.ZodOptional<z.ZodNumber>;
60
+ PER_KYC_MEMBER: z.ZodOptional<z.ZodNumber>;
61
+ PER_DELEGATE_MINING: z.ZodOptional<z.ZodNumber>;
62
+ PER_SUBMIT_WORK: z.ZodOptional<z.ZodNumber>;
63
+ SET_OWNER_VRF_KEY: z.ZodOptional<z.ZodNumber>;
64
+ APPROVE_AGENT: z.ZodOptional<z.ZodNumber>;
65
+ REVOKE_AGENT: z.ZodOptional<z.ZodNumber>;
66
+ APPROVE_BUILDER: z.ZodOptional<z.ZodNumber>;
67
+ REVOKE_BUILDER: z.ZodOptional<z.ZodNumber>;
68
+ SET_REFERRAL_CODE: z.ZodOptional<z.ZodNumber>;
69
+ SET_REFERRAL: z.ZodOptional<z.ZodNumber>;
70
+ LIMIT_ORDER: z.ZodOptional<z.ZodNumber>;
71
+ MARKET_ORDER: z.ZodOptional<z.ZodNumber>;
72
+ SCALE_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
73
+ SCALE_ORDER_PER_SUB: z.ZodOptional<z.ZodNumber>;
74
+ CANCEL_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
75
+ CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
76
+ OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
77
+ }, z.core.$strip>>;
78
+ eip712: z.ZodOptional<z.ZodObject<{
79
+ feeDenom: z.ZodOptional<z.ZodString>;
80
+ feeAmount: z.ZodOptional<z.ZodString>;
81
+ gasLimit: z.ZodOptional<z.ZodString>;
82
+ }, z.core.$strip>>;
83
+ urls: z.ZodOptional<z.ZodObject<{
84
+ rpc: z.ZodOptional<z.ZodString>;
85
+ rest: z.ZodOptional<z.ZodString>;
86
+ evm: z.ZodOptional<z.ZodString>;
87
+ explorer: z.ZodOptional<z.ZodString>;
88
+ dexWs: z.ZodOptional<z.ZodString>;
89
+ }, z.core.$strip>>;
90
+ }, z.core.$loose>;
91
+ export type ManifestGas = z.infer<typeof ManifestGasSchema>;
92
+ export type ManifestEip712 = z.infer<typeof ManifestEip712Schema>;
93
+ export type ManifestUrls = z.infer<typeof ManifestUrlsSchema>;
94
+ export type Manifest = z.infer<typeof ManifestSchema>;
@@ -50,7 +50,7 @@ export declare const GAS_CONSTANTS: {
50
50
  readonly REVOKE_BUILDER: 57000;
51
51
  readonly SET_REFERRAL_CODE: 76000;
52
52
  readonly SET_REFERRAL: 90000;
53
- readonly LIMIT_ORDER: 126000;
53
+ readonly LIMIT_ORDER: 124000;
54
54
  readonly MARKET_ORDER: 116000;
55
55
  readonly SCALE_ORDER_BASE: 115000;
56
56
  readonly SCALE_ORDER_PER_SUB: 11000;
@@ -58,5 +58,17 @@ export declare const GAS_CONSTANTS: {
58
58
  readonly CANCEL_ORDER_PER_ID: 22000;
59
59
  readonly OPEN_ACCOUNT: 96000;
60
60
  };
61
- export declare function computeFeeFreeGas(minGasPerOp: number, count: number): string;
62
- export declare function computeFeeFreeGasCompound(base: number, perItem: number, count: number): string;
61
+ /**
62
+ * Returns the per-tx gas allowance for a uniform-cost batch (in wire-format
63
+ * integer string). The chain interprets `gas` as an unsigned bigint, so the
64
+ * division by 100 must floor — a fractional result like `"149998.5"` would
65
+ * later crash inside `signAndBroadcastEip712`'s `BigInt(context.fee.gas)`.
66
+ * Use BigInt arithmetic from the start so the floor is exact for any
67
+ * combination of manifest-supplied values.
68
+ */
69
+ export declare function computeFeeFreeGas(minGasPerOp: number, count: number, multiplier?: number): string;
70
+ /**
71
+ * Same shape as {@link computeFeeFreeGas} but for ops with a base + per-item
72
+ * cost (CLOB cancel / scale orders). Same BigInt-floor reasoning applies.
73
+ */
74
+ export declare function computeFeeFreeGasCompound(base: number, perItem: number, count: number, multiplier?: number): string;
@@ -2,25 +2,29 @@ import type { Client, ClientOptions } from "./types";
2
2
  /**
3
3
  * Create a high-level client for the Ault SDK.
4
4
  *
5
+ * One client per master identity. The client owns:
6
+ * - the manifest resolver (fetched once at boot, refreshed in background)
7
+ * - the master account-info cache (sequence / accountNumber)
8
+ * - the fee-market cache
9
+ * - the wallet-signed tx executor (used by all `client.<method>(...)` calls)
10
+ *
11
+ * Agent-signed CLOB orders piggyback on the same infrastructure via
12
+ * `client.attachAgent(...)` — no second resolver, no second account RPC,
13
+ * no chance of URL/EIP-712 drift between paths.
14
+ *
5
15
  * @example
6
16
  * ```typescript
7
- * import { createClient, getNetworkConfig } from 'ault-sdk-ts';
8
- * import { privateKeyToAccount } from 'viem/accounts';
9
- *
10
- * const account = privateKeyToAccount('0x...');
11
17
  * const client = await createClient({
12
18
  * network: getNetworkConfig('ault_10904-1'),
13
19
  * signer: account,
14
20
  * });
15
21
  *
16
- * // Query
17
- * const licenses = await client.license.getOwnedBy(client.address);
22
+ * await client.placeLimitOrder({...}); // signed by the master signer
18
23
  *
19
- * // Transactions
20
- * const result = await client.delegateMining({
21
- * licenseIds: [1, 2, 3],
22
- * operator: '0xOperator...',
23
- * });
24
+ * client.attachAgent({ agentPrivateKey });
25
+ * await client.asAgent!.placeLimitOrder({...}); // signed by the agent key
26
+ *
27
+ * client.dispose(); // stops manifest refresh timer
24
28
  * ```
25
29
  */
26
30
  export declare function createClient(options: ClientOptions): Promise<Client>;
@@ -1,3 +1,3 @@
1
1
  import type { AccountxTxApi } from "../types";
2
2
  import type { TxModuleContext } from "./context";
3
- export declare function createAccountxTxApi({ signerAddress, exec }: TxModuleContext): AccountxTxApi;
3
+ export declare function createAccountxTxApi({ signerAddress, exec, getGas, }: TxModuleContext): AccountxTxApi;
@@ -1,3 +1,3 @@
1
1
  import type { AgentTxApi } from "../types";
2
2
  import type { TxModuleContext } from "./context";
3
- export declare function createAgentTxApi({ signerAddress, exec }: TxModuleContext): AgentTxApi;
3
+ export declare function createAgentTxApi({ signerAddress, exec, getGas }: TxModuleContext): AgentTxApi;
@@ -1,3 +1,3 @@
1
1
  import type { ClobTxApi } from "../types";
2
2
  import type { TxModuleContext } from "./context";
3
- export declare function createClobTxApi({ signerAddress, exec }: TxModuleContext): ClobTxApi;
3
+ export declare function createClobTxApi({ signerAddress, exec, getGas }: TxModuleContext): ClobTxApi;