ault-sdk-ts 0.0.2-alpha.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +375 -50
- package/dist/agent/attach.d.ts +26 -0
- package/dist/agent/sign-and-broadcast.d.ts +9 -2
- package/dist/agent/tx/clob.d.ts +8 -1
- package/dist/agent/tx-executor.d.ts +24 -2
- package/dist/client.d.ts +6 -7
- package/dist/core/clob-gas.d.ts +28 -0
- package/dist/core/clob-msgs.d.ts +31 -5
- package/dist/core/clob-responses.d.ts +20 -0
- package/dist/core/cloid.d.ts +4 -0
- package/dist/core/errors.d.ts +79 -0
- package/dist/core/manifest-fetcher.d.ts +12 -0
- package/dist/core/manifest-resolver.d.ts +121 -0
- package/dist/core/manifest-types.d.ts +102 -0
- package/dist/core/network.d.ts +42 -13
- package/dist/eip712/msg.generated.d.ts +26 -10
- package/dist/eip712/registry.d.ts +2 -0
- package/dist/eip712/sign-and-broadcast.d.ts +27 -3
- package/dist/high-level/cloid-lookup.d.ts +9 -0
- package/dist/high-level/create-client.d.ts +15 -11
- package/dist/high-level/tx/accountx.d.ts +3 -0
- package/dist/high-level/tx/agent.d.ts +1 -1
- package/dist/high-level/tx/clob.d.ts +1 -1
- package/dist/high-level/tx/context.d.ts +8 -0
- package/dist/high-level/tx/license.d.ts +1 -1
- package/dist/high-level/tx/miner.d.ts +1 -1
- package/dist/high-level/tx/reward.d.ts +1 -1
- package/dist/high-level/tx/staking.d.ts +1 -1
- package/dist/high-level/tx-executor.d.ts +23 -3
- package/dist/high-level/types.d.ts +356 -100
- package/dist/high-level-client.d.ts +1 -1
- package/dist/index.cjs +16101 -7908
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +15860 -7678
- package/dist/index.js.map +1 -1
- package/dist/proto/gen/ault/accountx/v1/genesis.d.ts +38 -0
- package/dist/proto/gen/ault/accountx/v1/params.d.ts +32 -0
- package/dist/proto/gen/ault/accountx/v1/query.d.ts +88 -0
- package/dist/proto/gen/ault/accountx/v1/tx.d.ts +52 -0
- package/dist/proto/gen/ault/agent/v1/tx.d.ts +4 -5
- package/dist/proto/gen/ault/authority/v1/authority.d.ts +2 -0
- package/dist/proto/gen/ault/clob/v1/genesis.d.ts +6 -5
- package/dist/proto/gen/ault/clob/v1/query.d.ts +14 -0
- package/dist/proto/gen/ault/clob/v1/tx.d.ts +30 -3
- package/dist/proto/gen/ault/common/v1/system.d.ts +31 -0
- package/dist/proto/gen/ault/license/v1/genesis.d.ts +1 -26
- package/dist/proto/gen/ault/license/v1/license.d.ts +0 -26
- package/dist/proto/gen/ault/license/v1/query.d.ts +44 -18
- package/dist/proto/gen/ault/market/v1/market.d.ts +1 -0
- package/dist/proto/gen/ault/market/v1/tx.d.ts +9 -0
- package/dist/proto/gen/ault/miner/v1/genesis.d.ts +52 -84
- package/dist/proto/gen/ault/miner/v1/miner.d.ts +10 -45
- package/dist/proto/gen/ault/miner/v1/query.d.ts +0 -13
- package/dist/proto/gen/ault/spot/v1/genesis.d.ts +2 -2
- package/dist/proto/gen/ault/spot/v1/order.d.ts +12 -4
- package/dist/proto/gen/ault/systemtx/v1/genesis.d.ts +37 -0
- package/dist/proto/gen/ault/tokenregistry/v1/genesis.d.ts +3 -3
- package/dist/proto/gen/ault/tokenregistry/v1/query.d.ts +2 -2
- package/dist/proto/gen/ault/tokenregistry/v1/tokenregistry.d.ts +24 -15
- package/dist/proto/gen/ault/tokenregistry/v1/tx.d.ts +1 -16
- package/dist/proto/gen/cosmos/bank/v1beta1/bank.d.ts +119 -0
- package/dist/proto/gen/cosmos/bank/v1beta1/query.d.ts +264 -0
- package/dist/proto/gen/cosmos/distribution/v1beta1/query.d.ts +203 -0
- package/dist/proto/gen/cosmos/query/v1/query.d.ts +1 -0
- package/dist/proto/gen/cosmos/staking/v1beta1/query.d.ts +275 -0
- package/dist/proto/gen/google/api/http.d.ts +20 -28
- package/dist/proto/gen/tendermint/abci/types.d.ts +23 -0
- package/dist/proto/tx-decode.d.ts +18 -0
- package/dist/rest/accountx.d.ts +8 -0
- package/dist/rest/bank.d.ts +15 -0
- package/dist/rest/clob.d.ts +9 -1
- package/dist/rest/context.d.ts +4 -4
- package/dist/rest/dex-types.generated.d.ts +363 -120
- package/dist/rest/dex.d.ts +6 -0
- package/dist/rest/dex.generated.d.ts +599 -83
- package/dist/rest/feemarket.d.ts +114 -0
- package/dist/rest/license.d.ts +21 -59
- package/dist/rest/miner.d.ts +16 -46
- package/dist/rest/portfolio.d.ts +103 -0
- package/dist/rest/staking.d.ts +14 -28
- package/dist/rest/tokenregistry.d.ts +3 -1
- package/dist/rest/types.d.ts +82 -858
- package/dist/utils/address.d.ts +2 -0
- package/dist/utils/opaque-id.d.ts +25 -0
- package/dist/utils/tx-hash.d.ts +1 -0
- package/dist/ws/client.d.ts +45 -5
- package/dist/ws/types.d.ts +380 -21
- package/package.json +2 -1
- package/dist/agent/create-agent-client.d.ts +0 -3
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:
|
|
@@ -238,8 +377,18 @@ const candles = await dex.getOHLCV("AULT/USDT", {
|
|
|
238
377
|
timeframe: "1h",
|
|
239
378
|
limit: 100,
|
|
240
379
|
});
|
|
380
|
+
|
|
381
|
+
// Protocol stats (24h window)
|
|
382
|
+
const stats = await dex.getStats(); // defaults to { window: "24h" }
|
|
383
|
+
console.log(stats.totals.quoteVolume); // "1234567.89" or null when markets span multiple quotes
|
|
384
|
+
console.log(stats.totals.tradeCount, stats.totals.traderCount);
|
|
385
|
+
for (const m of stats.markets) {
|
|
386
|
+
console.log(m.symbol, m.quoteVolume, m.tradeCount);
|
|
387
|
+
}
|
|
241
388
|
```
|
|
242
389
|
|
|
390
|
+
Monetary fields like `quoteVolume`, `estimatedFee`, and `averageSlippageBps` come back as canonical decimal strings, so parse them with a decimal library rather than `parseFloat`. `totals.quoteVolume` and its related fee fields are `null` when the markets that traded in the window span more than one quote asset, since summing notionals across quotes is meaningless. `markets[]` can briefly lag `totals` while the symbol map updates, so the per-market trade counts need not add up to `totals.tradeCount`.
|
|
391
|
+
|
|
243
392
|
### User Queries
|
|
244
393
|
|
|
245
394
|
```typescript
|
|
@@ -295,7 +444,7 @@ const tsMarks = await dex.getUDFTimescaleMarks({
|
|
|
295
444
|
|
|
296
445
|
## DEX WebSocket
|
|
297
446
|
|
|
298
|
-
The SDK
|
|
447
|
+
The SDK ships a WebSocket client for streaming live data from the DEX API. It speaks the v2 subscription protocol: open one connection, subscribe to channels, and receive `{ channel, data }` frames. The payload types are WebSocket-native (they differ from the REST shapes) and are exported from the SDK.
|
|
299
448
|
|
|
300
449
|
### Connecting
|
|
301
450
|
|
|
@@ -319,34 +468,39 @@ const ws = createDexWs("wss://my-dex-api.example.com/ws");
|
|
|
319
468
|
await ws.connect();
|
|
320
469
|
```
|
|
321
470
|
|
|
322
|
-
### Subscribing to
|
|
471
|
+
### Subscribing to Channels
|
|
323
472
|
|
|
324
|
-
|
|
473
|
+
Pass a subscription descriptor and the `onData` callback is typed from its `type`. Market channels need a `coin`; the `candle` channel also needs an `interval`. Frames flow through `onData` as they arrive. For snapshot-gated channels the first frame is the snapshot and the rest are deltas, so don't assume the first frame is a delta.
|
|
325
474
|
|
|
326
475
|
```typescript
|
|
327
|
-
//
|
|
328
|
-
const sub = client.ws.subscribe(
|
|
329
|
-
|
|
330
|
-
|
|
476
|
+
// L2 order book — snapshot first, then per-block deltas (data typed as WsBook)
|
|
477
|
+
const sub = client.ws.subscribe(
|
|
478
|
+
{ type: "l2Book", coin: "AULT/USDC" },
|
|
479
|
+
{
|
|
480
|
+
onData: (book) => {
|
|
481
|
+
const [bids, asks] = book.levels;
|
|
482
|
+
console.log(bids[0], asks[0]); // { px, sz, n }
|
|
483
|
+
},
|
|
331
484
|
},
|
|
332
|
-
|
|
485
|
+
);
|
|
333
486
|
|
|
334
|
-
// Trades (data typed as
|
|
335
|
-
client.ws.subscribe(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
});
|
|
487
|
+
// Trades in each block (data typed as WsTrade[])
|
|
488
|
+
client.ws.subscribe(
|
|
489
|
+
{ type: "trades", coin: "AULT/USDC" },
|
|
490
|
+
{ onData: (trades) => trades.forEach((t) => console.log(t.side, t.px, t.sz)) },
|
|
491
|
+
);
|
|
340
492
|
|
|
341
|
-
//
|
|
342
|
-
client.ws.subscribe(
|
|
343
|
-
|
|
344
|
-
}
|
|
493
|
+
// Best bid / offer (data typed as WsBbo)
|
|
494
|
+
client.ws.subscribe(
|
|
495
|
+
{ type: "bbo", coin: "AULT/USDC" },
|
|
496
|
+
{ onData: (b) => console.log(b.bbo[0], b.bbo[1]) },
|
|
497
|
+
);
|
|
345
498
|
|
|
346
|
-
//
|
|
347
|
-
client.ws.subscribe(
|
|
348
|
-
|
|
349
|
-
}
|
|
499
|
+
// Candles (data typed as WsCandle[])
|
|
500
|
+
client.ws.subscribe(
|
|
501
|
+
{ type: "candle", coin: "AULT/USDC", interval: "1m" },
|
|
502
|
+
{ onData: (bars) => console.log(bars[bars.length - 1]) },
|
|
503
|
+
);
|
|
350
504
|
|
|
351
505
|
// Unsubscribe
|
|
352
506
|
sub.unsubscribe();
|
|
@@ -354,15 +508,16 @@ sub.unsubscribe();
|
|
|
354
508
|
|
|
355
509
|
### Subscription Options
|
|
356
510
|
|
|
511
|
+
`ttl` sets a subscription lifetime in seconds (the server caps it at 3,600). The ack carries the effective, clamped value.
|
|
512
|
+
|
|
357
513
|
```typescript
|
|
358
|
-
// TTL: auto-expire after 300 seconds
|
|
359
514
|
client.ws.subscribe(
|
|
360
|
-
"
|
|
515
|
+
{ type: "l2Book", coin: "AULT/USDC" },
|
|
361
516
|
{
|
|
362
517
|
onData: (data) => {
|
|
363
518
|
/* ... */
|
|
364
519
|
},
|
|
365
|
-
onSubscribed: () => console.log("subscribed
|
|
520
|
+
onSubscribed: (ack) => console.log("subscribed; effective ttl", ack.ttl),
|
|
366
521
|
onExpired: () => console.log("subscription expired"),
|
|
367
522
|
onError: (err) => console.error(err),
|
|
368
523
|
},
|
|
@@ -370,28 +525,33 @@ client.ws.subscribe(
|
|
|
370
525
|
);
|
|
371
526
|
```
|
|
372
527
|
|
|
373
|
-
###
|
|
528
|
+
### User channels
|
|
374
529
|
|
|
375
|
-
|
|
376
|
-
of public on-chain state — no authentication is required:
|
|
530
|
+
User channels key on an address (`ault1...` or `0x...`, either case) and expose read-only projections of public on-chain state, so no authentication is required. The address round-trips in the ack in the format you sent.
|
|
377
531
|
|
|
378
532
|
```typescript
|
|
379
|
-
//
|
|
380
|
-
client.ws.subscribe(
|
|
381
|
-
|
|
382
|
-
|
|
533
|
+
// Order updates (data typed as WsOrderUpdate[])
|
|
534
|
+
client.ws.subscribe(
|
|
535
|
+
{ type: "orderUpdates", user: "ault1..." },
|
|
536
|
+
{
|
|
537
|
+
onData: (orders) => orders.forEach((o) => console.log(o.order.oid, o.status, o.chainStatus)),
|
|
383
538
|
},
|
|
384
|
-
|
|
539
|
+
);
|
|
385
540
|
|
|
386
|
-
//
|
|
387
|
-
client.ws.subscribe(
|
|
388
|
-
|
|
389
|
-
}
|
|
541
|
+
// Spot balances — first frame is the full set, later frames are per-coin deltas
|
|
542
|
+
client.ws.subscribe(
|
|
543
|
+
{ type: "spotState", user: "ault1..." },
|
|
544
|
+
{ onData: (state) => console.log(state.spotState.balances) },
|
|
545
|
+
);
|
|
390
546
|
|
|
391
|
-
//
|
|
392
|
-
client.ws.subscribe(
|
|
393
|
-
|
|
394
|
-
}
|
|
547
|
+
// Fills — the snapshot frame carries isSnapshot: true, live frames false
|
|
548
|
+
client.ws.subscribe(
|
|
549
|
+
{ type: "userFills", user: "ault1..." },
|
|
550
|
+
{ onData: (f) => console.log(f.isSnapshot, f.fills) },
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
// userEvents data arrives on the wire "user" channel; the SDK routes it back here
|
|
554
|
+
client.ws.subscribe({ type: "userEvents", user: "ault1..." }, { onData: (ev) => console.log(ev) });
|
|
395
555
|
```
|
|
396
556
|
|
|
397
557
|
### Connection Events
|
|
@@ -404,12 +564,12 @@ client.ws.on("reconnecting", (attempt) => console.log("reconnecting...", attempt
|
|
|
404
564
|
client.ws.on("reconnected", () => console.log("reconnected"));
|
|
405
565
|
|
|
406
566
|
// Raw message listener
|
|
407
|
-
client.ws.on("message", (msg) => console.log(msg.
|
|
567
|
+
client.ws.on("message", (msg) => console.log(msg.channel, msg.data));
|
|
408
568
|
```
|
|
409
569
|
|
|
410
570
|
### Reconnection
|
|
411
571
|
|
|
412
|
-
Auto-reconnect is enabled by default with exponential backoff. On reconnect,
|
|
572
|
+
Auto-reconnect is enabled by default with exponential backoff. On reconnect, every active subscription is re-sent with its original TTL.
|
|
413
573
|
|
|
414
574
|
```typescript
|
|
415
575
|
const ws = createDexWs("wss://my-dex-api.example.com/ws", {
|
|
@@ -477,11 +637,18 @@ interface TxResult {
|
|
|
477
637
|
txHash: string; // Transaction hash
|
|
478
638
|
code: number; // Result code (0 = success)
|
|
479
639
|
rawLog?: string; // Raw log from transaction
|
|
480
|
-
confirmed?: boolean; // true =
|
|
640
|
+
confirmed?: boolean; // true = DeliverTx observed; false = broadcast-only or poll timeout; undefined = confirmation lookup unavailable
|
|
481
641
|
success: boolean; // True only when DeliverTx success was confirmed
|
|
482
642
|
}
|
|
483
643
|
```
|
|
484
644
|
|
|
645
|
+
The CLOB order methods (`placeLimitOrder`, `placeMarketOrder`,
|
|
646
|
+
`placeScaleOrder`, `cancelOrders`) default to broadcast-only: they return once
|
|
647
|
+
CheckTx accepts the transaction, so the result has `confirmed: false` and
|
|
648
|
+
`success: false`. Pass `wait: true` to poll for DeliverTx and get back the
|
|
649
|
+
decoded order IDs. See [Market And CLOB
|
|
650
|
+
Transactions](#market-and-clob-transactions).
|
|
651
|
+
|
|
485
652
|
### License Transactions
|
|
486
653
|
|
|
487
654
|
```typescript
|
|
@@ -582,25 +749,62 @@ await client.updateOperatorInfo({
|
|
|
582
749
|
```typescript
|
|
583
750
|
import { base64ToBytes } from "ault-sdk-ts";
|
|
584
751
|
|
|
585
|
-
|
|
752
|
+
const marketId = base64ToBytes("base64MarketId...");
|
|
753
|
+
|
|
754
|
+
// Place a limit order (broadcast-only: returns once CheckTx accepts it).
|
|
586
755
|
await client.placeLimitOrder({
|
|
587
|
-
marketId
|
|
756
|
+
marketId,
|
|
588
757
|
isBuy: true,
|
|
589
758
|
price: "1.5",
|
|
590
759
|
quantity: "100",
|
|
591
760
|
lifespan: { seconds: 3600n, nanos: 0 }, // 1 hour
|
|
592
761
|
});
|
|
593
762
|
|
|
763
|
+
// Pass `wait: true` to poll for DeliverTx and read back the order ID.
|
|
764
|
+
const placed = await client.placeLimitOrder({
|
|
765
|
+
marketId,
|
|
766
|
+
isBuy: true,
|
|
767
|
+
price: "1.5",
|
|
768
|
+
quantity: "100",
|
|
769
|
+
lifespan: { seconds: 3600n, nanos: 0 },
|
|
770
|
+
wait: true,
|
|
771
|
+
});
|
|
772
|
+
console.log(placed.orderId);
|
|
773
|
+
|
|
594
774
|
// Place a market order
|
|
595
775
|
await client.placeMarketOrder({
|
|
596
|
-
marketId
|
|
776
|
+
marketId,
|
|
597
777
|
isBuy: true,
|
|
598
778
|
deposit: "100",
|
|
599
779
|
});
|
|
600
780
|
|
|
601
|
-
// Cancel specific orders
|
|
781
|
+
// Cancel specific orders. With `wait: true` the result lists which IDs
|
|
782
|
+
// succeeded and which failed.
|
|
602
783
|
await client.cancelOrders({ orderIds: [base64ToBytes("base64OrderId...")] });
|
|
603
784
|
|
|
785
|
+
// Client order id (cloid): attach an 8-byte id to an order so you can address
|
|
786
|
+
// it without the chain-assigned order id. It is echoed back (as hex) on the
|
|
787
|
+
// wait-mode result, and cancelOrders accepts a cloid or an order id
|
|
788
|
+
// interchangeably.
|
|
789
|
+
const cloid = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
790
|
+
const withCloid = await client.placeLimitOrder({
|
|
791
|
+
marketId,
|
|
792
|
+
isBuy: true,
|
|
793
|
+
price: "1.5",
|
|
794
|
+
quantity: "100",
|
|
795
|
+
deadline: new Date(Date.now() + 3600_000),
|
|
796
|
+
cloid,
|
|
797
|
+
wait: true,
|
|
798
|
+
});
|
|
799
|
+
console.log(withCloid.cloid); // "0102030405060708"
|
|
800
|
+
|
|
801
|
+
await client.cancelOrders({ orderIds: [cloid] });
|
|
802
|
+
|
|
803
|
+
// Look up an order by (orderer, cloid), chain-first with a dex-api fallback.
|
|
804
|
+
// Live orders resolve from the chain; filled/cancelled ones from the indexer.
|
|
805
|
+
const found = await client.findOrderByCloid(client.address, cloid);
|
|
806
|
+
if (found.source !== "none") console.log(found.source, found.order);
|
|
807
|
+
|
|
604
808
|
// Create a market
|
|
605
809
|
await client.createMarket({
|
|
606
810
|
marketType: MarketType.MARKET_TYPE_SPOT,
|
|
@@ -648,6 +852,119 @@ await client.delegateMining({
|
|
|
648
852
|
});
|
|
649
853
|
```
|
|
650
854
|
|
|
855
|
+
## Agent-Signed Transactions
|
|
856
|
+
|
|
857
|
+
The chain's `agent` module lets a master account approve a separate keypair to
|
|
858
|
+
submit a restricted set of CLOB transactions on its behalf, without prompting
|
|
859
|
+
the master signer for each one. Typical use cases: market-making bots that
|
|
860
|
+
sign hot orders with a short-lived key, or trading UIs that sign orders
|
|
861
|
+
without a wallet popup per click.
|
|
862
|
+
|
|
863
|
+
The SDK exposes this through `client.attachAgent(...)` rather than a separate
|
|
864
|
+
client. The agent surface reuses the master client's manifest resolver, REST
|
|
865
|
+
contexts, and account-info cache — one network state, one of every cached
|
|
866
|
+
resource, no chance of drift between wallet-signed and agent-signed paths.
|
|
867
|
+
|
|
868
|
+
### Approve and attach an agent
|
|
869
|
+
|
|
870
|
+
```typescript
|
|
871
|
+
import { createClient, encodeEthSecp256k1PubKey, deriveAgentAddress } from "ault-sdk-ts";
|
|
872
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
873
|
+
import { hexToBytes } from "viem";
|
|
874
|
+
|
|
875
|
+
const client = await createClient({ network, signer: masterSigner });
|
|
876
|
+
|
|
877
|
+
// 1. Generate (or load) the agent keypair.
|
|
878
|
+
const agentPrivateKey = `0x${"a".repeat(64)}`; // load from secret store in real usage
|
|
879
|
+
const compressed = secp256k1.getPublicKey(hexToBytes(agentPrivateKey), true);
|
|
880
|
+
const agentPubkey = {
|
|
881
|
+
typeUrl: "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey",
|
|
882
|
+
value: encodeEthSecp256k1PubKey(compressed),
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
// 2. Master approves the agent on-chain (wallet-signed).
|
|
886
|
+
await client.approveAgent({
|
|
887
|
+
agentPubkey,
|
|
888
|
+
name: "market-maker-bot",
|
|
889
|
+
expiry: { seconds: 86_400n * 30n, nanos: 0 }, // 30 days
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
// 3. Attach the agent surface to this client.
|
|
893
|
+
const agent = client.attachAgent({ agentPrivateKey });
|
|
894
|
+
console.log(agent.address); // bech32 agent address
|
|
895
|
+
console.log(agent.masterAddress); // = client.address
|
|
896
|
+
console.log(client.asAgent === agent); // true
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
### Place agent-signed orders
|
|
900
|
+
|
|
901
|
+
```typescript
|
|
902
|
+
// Same shape as the wallet-signed equivalents on `client.*`, including the
|
|
903
|
+
// broadcast-only default and the `wait: true` opt-in for a result with the
|
|
904
|
+
// decoded order ID.
|
|
905
|
+
const placed = await client.asAgent!.placeLimitOrder({
|
|
906
|
+
marketId,
|
|
907
|
+
isBuy: true,
|
|
908
|
+
price: "1.0",
|
|
909
|
+
quantity: "1000000000000000000",
|
|
910
|
+
lifespan: { seconds: 3600n, nanos: 0 },
|
|
911
|
+
wait: true,
|
|
912
|
+
});
|
|
913
|
+
console.log(placed.orderId);
|
|
914
|
+
|
|
915
|
+
await client.asAgent!.placeMarketOrder({
|
|
916
|
+
marketId,
|
|
917
|
+
isBuy: true,
|
|
918
|
+
deposit: "5000000000000000000",
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
await client.asAgent!.cancelOrders({ orderIds: [...] });
|
|
922
|
+
|
|
923
|
+
await client.asAgent!.placeScaleOrder({
|
|
924
|
+
marketId,
|
|
925
|
+
isBuy: true,
|
|
926
|
+
lowPrice: "0.9",
|
|
927
|
+
highPrice: "1.1",
|
|
928
|
+
totalQuantity: "10000000000000000000",
|
|
929
|
+
weights: [3333, 3334, 3333],
|
|
930
|
+
lifespan: { seconds: 3600n, nanos: 0 },
|
|
931
|
+
});
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
### Rotate or detach the agent
|
|
935
|
+
|
|
936
|
+
```typescript
|
|
937
|
+
// Rotate: attachAgent replaces the prior agent in place. The previous
|
|
938
|
+
// surface is overwritten — read from `client.asAgent` after attaching.
|
|
939
|
+
client.attachAgent({ agentPrivateKey: newKey });
|
|
940
|
+
|
|
941
|
+
// Detach: clears `client.asAgent`. Idempotent.
|
|
942
|
+
client.detachAgent();
|
|
943
|
+
|
|
944
|
+
// Revoke on-chain (wallet-signed) when the agent should no longer sign.
|
|
945
|
+
await client.revokeAgent({ agentAddress: agent.address });
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
### What `attachAgent` shares with the master client
|
|
949
|
+
|
|
950
|
+
| Resource | Behavior |
|
|
951
|
+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
952
|
+
| `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. |
|
|
953
|
+
| `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`). |
|
|
954
|
+
| REST/WS contexts | The master client's `client.<module>` query APIs are the only query surface — the agent surface is tx-only. |
|
|
955
|
+
| Lifecycle | `client.dispose()` clears `asAgent` and stops the manifest refresh timer. Calling `attachAgent` after `dispose()` throws. |
|
|
956
|
+
|
|
957
|
+
### Notes
|
|
958
|
+
|
|
959
|
+
- `client.asAgent` is `null` until `attachAgent` is called. After detach or
|
|
960
|
+
dispose it is `null` again. Always read it fresh; do not cache references
|
|
961
|
+
across rotations.
|
|
962
|
+
- `attachAgent` is synchronous (no network I/O). The first agent tx may
|
|
963
|
+
trigger one `queryAccount` RPC if the cache is cold; subsequent agent
|
|
964
|
+
txs reuse the cached `accountNumber`.
|
|
965
|
+
- Two concurrent agents from the same master require two `Client`
|
|
966
|
+
instances — `attachAgent` replaces, it does not coexist.
|
|
967
|
+
|
|
651
968
|
## Development
|
|
652
969
|
|
|
653
970
|
### Generating Protos
|
|
@@ -874,12 +1191,20 @@ Pre-release tags publish to a separate npm dist-tag so they never become the def
|
|
|
874
1191
|
|
|
875
1192
|
```bash
|
|
876
1193
|
# Set the pre-release version
|
|
1194
|
+
git checkout master
|
|
1195
|
+
git pull
|
|
1196
|
+
git checkout -b "release/v0.1.0-alpha.1"
|
|
877
1197
|
npm version 0.1.0-alpha.1 --no-git-tag-version
|
|
878
|
-
|
|
879
1198
|
git add package.json
|
|
880
1199
|
git commit -m "chore: release v0.1.0-alpha.1"
|
|
1200
|
+
git push origin release/v0.1.0-alpha.1
|
|
1201
|
+
|
|
1202
|
+
# Create PR and merge to master
|
|
1203
|
+
|
|
1204
|
+
git checkout master
|
|
1205
|
+
git pull
|
|
881
1206
|
git tag v0.1.0-alpha.1
|
|
882
|
-
git push origin
|
|
1207
|
+
git push origin v0.1.0-alpha.1
|
|
883
1208
|
```
|
|
884
1209
|
|
|
885
1210
|
Consumers install with the corresponding tag:
|
|
@@ -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;
|
|
@@ -21,6 +21,12 @@ export interface AgentSignAndBroadcastParams {
|
|
|
21
21
|
memo?: string;
|
|
22
22
|
gasLimit?: string;
|
|
23
23
|
confirmationTimeoutMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* When `true` (default), poll for DeliverTx after a successful CheckTx. When
|
|
26
|
+
* `false`, return immediately after CheckTx acceptance with `confirmed: false`.
|
|
27
|
+
* A CheckTx rejection throws in both modes.
|
|
28
|
+
*/
|
|
29
|
+
wait?: boolean;
|
|
24
30
|
timeoutSeconds?: number;
|
|
25
31
|
timeoutTimestamp?: {
|
|
26
32
|
seconds: bigint;
|
|
@@ -30,9 +36,10 @@ export interface AgentSignAndBroadcastParams {
|
|
|
30
36
|
fetchOptions?: FetchWithRetryOptions;
|
|
31
37
|
cache?: AccountCache;
|
|
32
38
|
}
|
|
33
|
-
export declare function signAndBroadcastAgentTx({ network, keyMaterial, masterAddress, msgs, memo, gasLimit, confirmationTimeoutMs, timeoutSeconds, timeoutTimestamp, fetchFn, fetchOptions, cache, }: AgentSignAndBroadcastParams): Promise<{
|
|
39
|
+
export declare function signAndBroadcastAgentTx({ network, keyMaterial, masterAddress, msgs, memo, gasLimit, confirmationTimeoutMs, wait, timeoutSeconds, timeoutTimestamp, fetchFn, fetchOptions, cache, }: AgentSignAndBroadcastParams): Promise<{
|
|
34
40
|
txHash: string;
|
|
35
41
|
code: number;
|
|
36
42
|
rawLog?: string;
|
|
37
|
-
|
|
43
|
+
data?: string;
|
|
44
|
+
confirmed: boolean;
|
|
38
45
|
}>;
|
package/dist/agent/tx/clob.d.ts
CHANGED
|
@@ -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,21 @@ 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";
|
|
6
|
+
/**
|
|
7
|
+
* Internal exec options: the public {@link AgentTxOptions} plus the per-call
|
|
8
|
+
* `wait` flag threaded through by the CLOB order methods.
|
|
9
|
+
*/
|
|
10
|
+
type AgentExecOptions = AgentTxOptions & {
|
|
11
|
+
wait?: boolean;
|
|
12
|
+
};
|
|
5
13
|
export interface AgentTxExecutorOptions {
|
|
6
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Returns the network with the latest manifest URL/eip712 overrides applied.
|
|
16
|
+
* Called fresh on every tx so a hot-swap takes effect on the next call
|
|
17
|
+
* without re-creating the executor.
|
|
18
|
+
*/
|
|
19
|
+
getNetwork: () => NetworkConfig;
|
|
7
20
|
agentPrivateKey: string;
|
|
8
21
|
masterAddress: string;
|
|
9
22
|
fetchFn?: FetchFn;
|
|
@@ -12,6 +25,15 @@ export interface AgentTxExecutorOptions {
|
|
|
12
25
|
defaultMemo?: string;
|
|
13
26
|
defaultConfirmationTimeoutMs?: number;
|
|
14
27
|
defaultTimeoutSeconds?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Optional shared account cache. When the agent shares a `Client` with the
|
|
30
|
+
* wallet path, pass the wallet's cache here so both executors read the
|
|
31
|
+
* master's accountNumber from the same memo. The agent path only reads
|
|
32
|
+
* `accountNumber`, never writes `nextSequence`, so it's safe to share.
|
|
33
|
+
* Without sharing, the agent executor maintains its own cache.
|
|
34
|
+
*/
|
|
35
|
+
cache?: AccountCache;
|
|
15
36
|
}
|
|
16
|
-
export type AgentTxExecutor = (msgs: AnyEip712Msg[], txOptions?:
|
|
37
|
+
export type AgentTxExecutor = (msgs: AnyEip712Msg[], txOptions?: AgentExecOptions) => Promise<TxResult>;
|
|
17
38
|
export declare function createAgentTxExecutor(options: AgentTxExecutorOptions): AgentTxExecutor;
|
|
39
|
+
export {};
|