ault-sdk-ts 0.0.2-alpha.15 → 0.0.2-alpha.16
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 +109 -0
- package/dist/agent/attach.d.ts +26 -0
- package/dist/agent/tx/clob.d.ts +8 -1
- package/dist/agent/tx-executor.d.ts +15 -1
- package/dist/core/manifest-fetcher.d.ts +12 -0
- package/dist/core/manifest-resolver.d.ts +71 -0
- package/dist/core/manifest-types.d.ts +94 -0
- package/dist/core/network.d.ts +15 -3
- package/dist/high-level/create-client.d.ts +15 -11
- package/dist/high-level/tx/accountx.d.ts +1 -1
- 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-executor.d.ts +14 -2
- package/dist/high-level/types.d.ts +77 -51
- package/dist/high-level-client.d.ts +1 -1
- package/dist/index.cjs +452 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +441 -128
- package/dist/index.js.map +1 -1
- package/dist/rest/dex-types.generated.d.ts +21 -0
- package/dist/rest/dex.generated.d.ts +85 -0
- package/package.json +1 -1
- package/dist/agent/create-agent-client.d.ts +0 -3
package/README.md
CHANGED
|
@@ -648,6 +648,115 @@ await client.delegateMining({
|
|
|
648
648
|
});
|
|
649
649
|
```
|
|
650
650
|
|
|
651
|
+
## Agent-Signed Transactions
|
|
652
|
+
|
|
653
|
+
The chain's `agent` module lets a master account approve a separate keypair to
|
|
654
|
+
submit a restricted set of CLOB transactions on its behalf, without prompting
|
|
655
|
+
the master signer for each one. Typical use cases: market-making bots that
|
|
656
|
+
sign hot orders with a short-lived key, or trading UIs that sign orders
|
|
657
|
+
without a wallet popup per click.
|
|
658
|
+
|
|
659
|
+
The SDK exposes this through `client.attachAgent(...)` rather than a separate
|
|
660
|
+
client. The agent surface reuses the master client's manifest resolver, REST
|
|
661
|
+
contexts, and account-info cache — one network state, one of every cached
|
|
662
|
+
resource, no chance of drift between wallet-signed and agent-signed paths.
|
|
663
|
+
|
|
664
|
+
### Approve and attach an agent
|
|
665
|
+
|
|
666
|
+
```typescript
|
|
667
|
+
import { createClient, encodeEthSecp256k1PubKey, deriveAgentAddress } from "ault-sdk-ts";
|
|
668
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
669
|
+
import { hexToBytes } from "viem";
|
|
670
|
+
|
|
671
|
+
const client = await createClient({ network, signer: masterSigner });
|
|
672
|
+
|
|
673
|
+
// 1. Generate (or load) the agent keypair.
|
|
674
|
+
const agentPrivateKey = `0x${"a".repeat(64)}`; // load from secret store in real usage
|
|
675
|
+
const compressed = secp256k1.getPublicKey(hexToBytes(agentPrivateKey), true);
|
|
676
|
+
const agentPubkey = {
|
|
677
|
+
typeUrl: "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey",
|
|
678
|
+
value: encodeEthSecp256k1PubKey(compressed),
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// 2. Master approves the agent on-chain (wallet-signed).
|
|
682
|
+
await client.approveAgent({
|
|
683
|
+
agentPubkey,
|
|
684
|
+
name: "market-maker-bot",
|
|
685
|
+
expiry: { seconds: 86_400n * 30n, nanos: 0 }, // 30 days
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
// 3. Attach the agent surface to this client.
|
|
689
|
+
const agent = client.attachAgent({ agentPrivateKey });
|
|
690
|
+
console.log(agent.address); // bech32 agent address
|
|
691
|
+
console.log(agent.masterAddress); // = client.address
|
|
692
|
+
console.log(client.asAgent === agent); // true
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
### Place agent-signed orders
|
|
696
|
+
|
|
697
|
+
```typescript
|
|
698
|
+
// Same shape as the wallet-signed equivalents on `client.*`.
|
|
699
|
+
await client.asAgent!.placeLimitOrder({
|
|
700
|
+
marketId,
|
|
701
|
+
isBuy: true,
|
|
702
|
+
price: "1.0",
|
|
703
|
+
quantity: "1000000000000000000",
|
|
704
|
+
lifespan: { seconds: 3600n, nanos: 0 },
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
await client.asAgent!.placeMarketOrder({
|
|
708
|
+
marketId,
|
|
709
|
+
isBuy: true,
|
|
710
|
+
deposit: "5000000000000000000",
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
await client.asAgent!.cancelOrders({ orderIds: [...] });
|
|
714
|
+
|
|
715
|
+
await client.asAgent!.placeScaleOrder({
|
|
716
|
+
marketId,
|
|
717
|
+
isBuy: true,
|
|
718
|
+
lowPrice: "0.9",
|
|
719
|
+
highPrice: "1.1",
|
|
720
|
+
totalQuantity: "10000000000000000000",
|
|
721
|
+
weights: [3333, 3334, 3333],
|
|
722
|
+
lifespan: { seconds: 3600n, nanos: 0 },
|
|
723
|
+
});
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### Rotate or detach the agent
|
|
727
|
+
|
|
728
|
+
```typescript
|
|
729
|
+
// Rotate: attachAgent replaces the prior agent in place. The previous
|
|
730
|
+
// surface is overwritten — read from `client.asAgent` after attaching.
|
|
731
|
+
client.attachAgent({ agentPrivateKey: newKey });
|
|
732
|
+
|
|
733
|
+
// Detach: clears `client.asAgent`. Idempotent.
|
|
734
|
+
client.detachAgent();
|
|
735
|
+
|
|
736
|
+
// Revoke on-chain (wallet-signed) when the agent should no longer sign.
|
|
737
|
+
await client.revokeAgent({ agentAddress: agent.address });
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
### What `attachAgent` shares with the master client
|
|
741
|
+
|
|
742
|
+
| Resource | Behavior |
|
|
743
|
+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
744
|
+
| `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. |
|
|
745
|
+
| `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`). |
|
|
746
|
+
| REST/WS contexts | The master client's `client.<module>` query APIs are the only query surface — the agent surface is tx-only. |
|
|
747
|
+
| Lifecycle | `client.dispose()` clears `asAgent` and stops the manifest refresh timer. Calling `attachAgent` after `dispose()` throws. |
|
|
748
|
+
|
|
749
|
+
### Notes
|
|
750
|
+
|
|
751
|
+
- `client.asAgent` is `null` until `attachAgent` is called. After detach or
|
|
752
|
+
dispose it is `null` again. Always read it fresh; do not cache references
|
|
753
|
+
across rotations.
|
|
754
|
+
- `attachAgent` is synchronous (no network I/O). The first agent tx may
|
|
755
|
+
trigger one `queryAccount` RPC if the cache is cold; subsequent agent
|
|
756
|
+
txs reuse the cached `accountNumber`.
|
|
757
|
+
- Two concurrent agents from the same master require two `Client`
|
|
758
|
+
instances — `attachAgent` replaces, it does not coexist.
|
|
759
|
+
|
|
651
760
|
## Development
|
|
652
761
|
|
|
653
762
|
### 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;
|
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,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
|
-
|
|
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,71 @@
|
|
|
1
|
+
import { GAS_CONSTANTS, type NetworkConfig } from "./network";
|
|
2
|
+
import type { FetchFn, FetchWithRetryOptions } from "./http";
|
|
3
|
+
import type { Manifest, ManifestGas } from "./manifest-types";
|
|
4
|
+
/**
|
|
5
|
+
* Returns a NetworkConfig with manifest URL and eip712 overrides applied.
|
|
6
|
+
* Fields the manifest does not specify pass through unchanged. URL values
|
|
7
|
+
* are required to be non-empty strings — defense in depth for callers that
|
|
8
|
+
* bypass zod with a hand-rolled blob (a non-string URL would otherwise crash
|
|
9
|
+
* `String.prototype.endsWith` etc. inside the REST/WS context). EIP-712
|
|
10
|
+
* numerics are pre-validated by `ManifestEip712Schema`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyNetworkOverrides(network: NetworkConfig, manifest: Manifest | null): NetworkConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a GAS_CONSTANTS-shaped object with manifest gas overrides applied.
|
|
15
|
+
*
|
|
16
|
+
* The manifest schema (see `ManifestGasSchema`) only exposes per-msg-type
|
|
17
|
+
* gas and the fee-free multiplier; EIP-712 fee/gas/denom defaults travel via
|
|
18
|
+
* `ManifestEip712Schema` and apply through `applyNetworkOverrides`. As
|
|
19
|
+
* defense in depth (in case a caller bypasses zod and passes a hand-rolled
|
|
20
|
+
* blob), this helper actively drops `EIP712_FEE_AMOUNT`, `EIP712_GAS_LIMIT`,
|
|
21
|
+
* and `DENOM` so the embedded values stay authoritative for the gas-constants
|
|
22
|
+
* object — the broadcast layer reads those off `network.eip712*`, never off
|
|
23
|
+
* the gas blob.
|
|
24
|
+
*
|
|
25
|
+
* The cast widens the zod-partial back to the concrete `GAS_CONSTANTS` type:
|
|
26
|
+
* every field has a baseline value, so any key the manifest omits keeps the
|
|
27
|
+
* embedded one.
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyGasOverrides(gas: ManifestGas | undefined): typeof GAS_CONSTANTS;
|
|
30
|
+
export interface ManifestResolverOptions {
|
|
31
|
+
network: NetworkConfig;
|
|
32
|
+
fetchFn?: FetchFn;
|
|
33
|
+
fetchOptions?: FetchWithRetryOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Milliseconds between background refreshes. Default: 5 minutes.
|
|
36
|
+
* 0 disables hot-swap (the initial fetch still runs).
|
|
37
|
+
*/
|
|
38
|
+
refreshIntervalMs?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface ManifestResolver {
|
|
41
|
+
/** The base network the resolver was created against. Stable. */
|
|
42
|
+
readonly baseNetwork: NetworkConfig;
|
|
43
|
+
/** Returns the most recently fetched manifest, or null if none has succeeded. */
|
|
44
|
+
currentManifest(): Manifest | null;
|
|
45
|
+
/** Network with the latest manifest URL/eip712 overrides applied. */
|
|
46
|
+
currentNetwork(): NetworkConfig;
|
|
47
|
+
/** Gas constants with the latest manifest gas overrides applied. */
|
|
48
|
+
currentGas(): typeof GAS_CONSTANTS;
|
|
49
|
+
/** Triggers an out-of-band refresh. Resolves regardless of fetch outcome. */
|
|
50
|
+
refresh(): Promise<void>;
|
|
51
|
+
/** Stops the background refresh. Safe to call multiple times. */
|
|
52
|
+
dispose(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Builds a manifest resolver bound to a network.
|
|
56
|
+
*
|
|
57
|
+
* Performs an initial fetch (best-effort, tight timeout: failure leaves the
|
|
58
|
+
* manifest empty) and starts a background refresh loop unless
|
|
59
|
+
* `refreshIntervalMs` is 0 or `dexApiUrl` is unset. The promise resolves
|
|
60
|
+
* once the initial fetch attempt has completed.
|
|
61
|
+
*
|
|
62
|
+
* Background refreshes are jittered ±10% around `refreshIntervalMs` to keep
|
|
63
|
+
* a fleet of SDK consumers from hitting the dex-api in lockstep.
|
|
64
|
+
*/
|
|
65
|
+
export declare function createManifestResolver(opts: ManifestResolverOptions): Promise<ManifestResolver>;
|
|
66
|
+
/**
|
|
67
|
+
* Static resolver — does not fetch, does not run a timer. Useful as the
|
|
68
|
+
* embedded-only path (no `dexApiUrl`) or in tests where you want to inject a
|
|
69
|
+
* fixed manifest.
|
|
70
|
+
*/
|
|
71
|
+
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>;
|
package/dist/core/network.d.ts
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
* //
|
|
17
|
-
* const licenses = await client.license.getOwnedBy(client.address);
|
|
22
|
+
* await client.placeLimitOrder({...}); // signed by the master signer
|
|
18
23
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { TxExecutor } from "../tx-executor";
|
|
2
|
+
import type { GAS_CONSTANTS } from "../../core/network";
|
|
2
3
|
export interface TxModuleContext {
|
|
3
4
|
signerAddress: string;
|
|
4
5
|
exec: TxExecutor;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the current gas constants — base GAS_CONSTANTS overlaid with any
|
|
8
|
+
* manifest overrides for the active client. Tx builders call this on each
|
|
9
|
+
* invocation so a hot-swap (manifest refresh) takes effect on the next tx
|
|
10
|
+
* without re-creating the client.
|
|
11
|
+
*/
|
|
12
|
+
getGas: () => typeof GAS_CONSTANTS;
|
|
5
13
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LicenseTxApi } from "../types";
|
|
2
2
|
import type { TxModuleContext } from "./context";
|
|
3
|
-
export declare function createLicenseTxApi({ signerAddress, exec }: TxModuleContext): LicenseTxApi;
|
|
3
|
+
export declare function createLicenseTxApi({ signerAddress, exec, getGas }: TxModuleContext): LicenseTxApi;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { MinerTxApi } from "../types";
|
|
2
2
|
import type { TxModuleContext } from "./context";
|
|
3
|
-
export declare function createMinerTxApi({ signerAddress, exec }: TxModuleContext): MinerTxApi;
|
|
3
|
+
export declare function createMinerTxApi({ signerAddress, exec, getGas }: TxModuleContext): MinerTxApi;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RewardTxApi } from "../types";
|
|
2
2
|
import type { TxModuleContext } from "./context";
|
|
3
|
-
export declare function createRewardTxApi({ signerAddress, exec }: TxModuleContext): RewardTxApi;
|
|
3
|
+
export declare function createRewardTxApi({ signerAddress, exec, getGas }: TxModuleContext): RewardTxApi;
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import type { FetchFn, FetchWithRetryOptions } from "../core/http";
|
|
2
2
|
import { type NetworkConfig } from "../core/network";
|
|
3
|
+
import { type AccountCache } from "../eip712/sign-and-broadcast";
|
|
3
4
|
import type { AnyEip712Msg } from "../eip712/builder";
|
|
4
5
|
import type { AultSigner } from "../eip712/signers";
|
|
6
|
+
import { type FeeMarketCache } from "../rest/feemarket";
|
|
5
7
|
import type { TxOptions, TxResult } from "./types";
|
|
6
8
|
interface TxExecutorOptions {
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Returns the network with the latest manifest URL/eip712 overrides applied.
|
|
11
|
+
* Called fresh on every tx so a hot-swap takes effect on the next call
|
|
12
|
+
* without re-creating the executor.
|
|
13
|
+
*/
|
|
14
|
+
getNetwork: () => NetworkConfig;
|
|
15
|
+
/** Default EIP-712 gas limit. Resolved per-call via the network getter. */
|
|
16
|
+
defaultGasLimit?: string;
|
|
8
17
|
signer: AultSigner;
|
|
9
18
|
signerAddress: string;
|
|
10
19
|
fetchFn?: FetchFn;
|
|
11
20
|
fetchOptions?: FetchWithRetryOptions;
|
|
12
|
-
defaultGasLimit?: string;
|
|
13
21
|
defaultMemo?: string;
|
|
14
22
|
defaultConfirmationTimeoutMs?: number;
|
|
23
|
+
/** Optional shared account cache (lets the agent executor read the same accountNumber). */
|
|
24
|
+
cache?: AccountCache;
|
|
25
|
+
/** Optional shared fee-market cache. */
|
|
26
|
+
feeMarketCache?: FeeMarketCache;
|
|
15
27
|
}
|
|
16
28
|
export type TxExecutor = (msgs: AnyEip712Msg[], txOptions?: TxOptions) => Promise<TxResult>;
|
|
17
29
|
export declare function createTxExecutor(options: TxExecutorOptions): TxExecutor;
|