ault-sdk-ts 0.0.2-alpha.16 → 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:
@@ -1,6 +1,24 @@
1
1
  import { GAS_CONSTANTS, type NetworkConfig } from "./network";
2
2
  import type { FetchFn, FetchWithRetryOptions } from "./http";
3
- import type { Manifest, ManifestGas } from "./manifest-types";
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;
4
22
  /**
5
23
  * Returns a NetworkConfig with manifest URL and eip712 overrides applied.
6
24
  * Fields the manifest does not specify pass through unchanged. URL values
@@ -36,6 +54,13 @@ export interface ManifestResolverOptions {
36
54
  * 0 disables hot-swap (the initial fetch still runs).
37
55
  */
38
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;
39
64
  }
40
65
  export interface ManifestResolver {
41
66
  /** The base network the resolver was created against. Stable. */
@@ -63,9 +88,33 @@ export interface ManifestResolver {
63
88
  * a fleet of SDK consumers from hitting the dex-api in lockstep.
64
89
  */
65
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
+ }
66
105
  /**
67
106
  * Static resolver — does not fetch, does not run a timer. Useful as the
68
107
  * embedded-only path (no `dexApiUrl`) or in tests where you want to inject a
69
- * fixed manifest.
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.
70
118
  */
119
+ export declare function createStaticResolver(opts: StaticResolverOptions): ManifestResolver;
71
120
  export declare function createStaticResolver(network: NetworkConfig, manifest?: Manifest | null): ManifestResolver;
@@ -2,6 +2,7 @@ import type { NetworkConfig } from "../core/network";
2
2
  import type { FetchWithRetryOptions, FetchFn } from "../core/http";
3
3
  import type { AultClient } from "../client";
4
4
  import type { ManifestResolver } from "../core/manifest-resolver";
5
+ import type { Manifest } from "../core/manifest-types";
5
6
  import type { AccountxApi } from "../rest/accountx";
6
7
  import type { AgentApi } from "../rest/agent";
7
8
  import type { AuthorityApi, AuthorityRoleInput } from "../rest/authority";
@@ -86,6 +87,15 @@ export interface ClientOptions {
86
87
  defaultMemo?: string;
87
88
  /** Optional: default time to wait for DeliverTx confirmation before returning a provisional result */
88
89
  defaultConfirmationTimeoutMs?: number;
90
+ /**
91
+ * Optional sparse manifest applied on top of the fetched manifest and the
92
+ * embedded baseline. Frozen for the lifetime of the client; not affected
93
+ * by background refreshes. The caller's reference is deep-cloned at
94
+ * construction so post-`createClient` mutation does not poison resolver
95
+ * state. Throws synchronously at `createClient` time if the value does not
96
+ * validate against `ManifestSchema`.
97
+ */
98
+ manifestOverride?: Manifest;
89
99
  }
90
100
  /**
91
101
  * Result of a transaction.
package/dist/index.cjs CHANGED
@@ -245,6 +245,7 @@ __export(index_exports, {
245
245
  listTradesResponseInfoAddressOneRegExp: () => listTradesResponseInfoAddressOneRegExp,
246
246
  listTradesResponseInfoBlockHeightRegExp: () => listTradesResponseInfoBlockHeightRegExp,
247
247
  listTradesResponsePriceRegExp: () => listTradesResponsePriceRegExp,
248
+ mergeManifests: () => mergeManifests,
248
249
  msg: () => msg,
249
250
  normalizeSignature: () => normalizeSignature,
250
251
  normalizeSigner: () => normalizeSigner,
@@ -23047,6 +23048,17 @@ function stripTrailingSlash(s) {
23047
23048
  }
23048
23049
 
23049
23050
  // src/core/manifest-resolver.ts
23051
+ function mergeManifests(base, top) {
23052
+ if (!base && !top) return null;
23053
+ if (!base) return top;
23054
+ if (!top) return base;
23055
+ const merged = { ...base, ...top };
23056
+ merged.schemaVersion = top.schemaVersion ?? base.schemaVersion;
23057
+ if (base.gas || top.gas) merged.gas = { ...base.gas, ...top.gas };
23058
+ if (base.eip712 || top.eip712) merged.eip712 = { ...base.eip712, ...top.eip712 };
23059
+ if (base.urls || top.urls) merged.urls = { ...base.urls, ...top.urls };
23060
+ return merged;
23061
+ }
23050
23062
  function applyNetworkOverrides(network, manifest) {
23051
23063
  if (!manifest) return network;
23052
23064
  const isUrl = (v) => typeof v === "string" && v.length > 0;
@@ -23078,6 +23090,25 @@ function applyGasOverrides(gas) {
23078
23090
  }
23079
23091
  return Object.assign({}, GAS_CONSTANTS, safeRest);
23080
23092
  }
23093
+ function prepareOverride(override) {
23094
+ if (override === void 0) return null;
23095
+ const parsed = ManifestSchema.safeParse(override);
23096
+ if (!parsed.success) {
23097
+ throw new Error(
23098
+ `manifestOverride failed schema validation: ${JSON.stringify(parsed.error.issues)}`
23099
+ );
23100
+ }
23101
+ const frozen = structuredClone(parsed.data);
23102
+ const gasKeys = frozen.gas ? Object.keys(frozen.gas) : [];
23103
+ const eip712Keys = frozen.eip712 ? Object.keys(frozen.eip712) : [];
23104
+ const urlsKeys = frozen.urls ? Object.keys(frozen.urls) : [];
23105
+ if (gasKeys.length || eip712Keys.length || urlsKeys.length) {
23106
+ console.info(
23107
+ `[ault-sdk] manifest override active: gas keys=[${gasKeys.join(", ")}], eip712 keys=[${eip712Keys.join(", ")}], urls keys=[${urlsKeys.join(", ")}]`
23108
+ );
23109
+ }
23110
+ return frozen;
23111
+ }
23081
23112
  var DEFAULT_REFRESH_INTERVAL_MS = 5 * 60 * 1e3;
23082
23113
  var INITIAL_FETCH_TIMEOUT_MS = 2e3;
23083
23114
  var MAX_REFRESH_INTERVAL_MS = 2147483647;
@@ -23091,8 +23122,10 @@ async function createManifestResolver(opts) {
23091
23122
  const refreshIntervalMs = normalizeRefreshIntervalMs(
23092
23123
  opts.refreshIntervalMs ?? DEFAULT_REFRESH_INTERVAL_MS
23093
23124
  );
23125
+ const frozenOverride = prepareOverride(opts.override);
23094
23126
  let manifest = null;
23095
23127
  let disposed = false;
23128
+ const resolved = () => mergeManifests(manifest, frozenOverride);
23096
23129
  let pullSeq = 0;
23097
23130
  async function pull(isInitial) {
23098
23131
  if (disposed || !network.dexApiUrl) return;
@@ -23121,9 +23154,9 @@ async function createManifestResolver(opts) {
23121
23154
  scheduleNext();
23122
23155
  return {
23123
23156
  baseNetwork: network,
23124
- currentManifest: () => manifest,
23125
- currentNetwork: () => applyNetworkOverrides(network, manifest),
23126
- currentGas: () => applyGasOverrides(manifest?.gas),
23157
+ currentManifest: resolved,
23158
+ currentNetwork: () => applyNetworkOverrides(network, resolved()),
23159
+ currentGas: () => applyGasOverrides(resolved()?.gas),
23127
23160
  async refresh() {
23128
23161
  await pull(false);
23129
23162
  },
@@ -23136,12 +23169,17 @@ async function createManifestResolver(opts) {
23136
23169
  }
23137
23170
  };
23138
23171
  }
23139
- function createStaticResolver(network, manifest = null) {
23172
+ function createStaticResolver(optsOrNetwork, legacyManifest) {
23173
+ const opts = "network" in optsOrNetwork && optsOrNetwork.network !== void 0 ? optsOrNetwork : { network: optsOrNetwork, manifest: legacyManifest ?? null };
23174
+ const { network } = opts;
23175
+ const manifest = opts.manifest ?? null;
23176
+ const frozenOverride = prepareOverride(opts.override);
23177
+ const resolved = () => mergeManifests(manifest, frozenOverride);
23140
23178
  return {
23141
23179
  baseNetwork: network,
23142
- currentManifest: () => manifest,
23143
- currentNetwork: () => applyNetworkOverrides(network, manifest),
23144
- currentGas: () => applyGasOverrides(manifest?.gas),
23180
+ currentManifest: resolved,
23181
+ currentNetwork: () => applyNetworkOverrides(network, resolved()),
23182
+ currentGas: () => applyGasOverrides(resolved()?.gas),
23145
23183
  refresh: async () => {
23146
23184
  },
23147
23185
  dispose: () => {
@@ -23438,7 +23476,8 @@ async function createClient(options) {
23438
23476
  const resolver = await createManifestResolver({
23439
23477
  network: options.network,
23440
23478
  fetchFn: options.fetchFn,
23441
- fetchOptions: options.fetchOptions
23479
+ fetchOptions: options.fetchOptions,
23480
+ override: options.manifestOverride
23442
23481
  });
23443
23482
  try {
23444
23483
  return await buildClient(options, resolver);
@@ -24286,7 +24325,7 @@ function createDexWs(url, options) {
24286
24325
  }
24287
24326
 
24288
24327
  // src/index.ts
24289
- var SDK_VERSION = "0.0.2-alpha.16";
24328
+ var SDK_VERSION = "0.0.2-alpha.17";
24290
24329
  // Annotate the CommonJS export names for ESM import in node:
24291
24330
  0 && (module.exports = {
24292
24331
  AGENT_DEFAULTS,
@@ -24504,6 +24543,7 @@ var SDK_VERSION = "0.0.2-alpha.16";
24504
24543
  listTradesResponseInfoAddressOneRegExp,
24505
24544
  listTradesResponseInfoBlockHeightRegExp,
24506
24545
  listTradesResponsePriceRegExp,
24546
+ mergeManifests,
24507
24547
  msg,
24508
24548
  normalizeSignature,
24509
24549
  normalizeSigner,