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/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { NetworkConfig } from "./core/network";
|
|
2
2
|
import type { FetchWithRetryOptions, FetchFn } from "./core/http";
|
|
3
|
+
import { type AccountxApi } from "./rest/accountx";
|
|
3
4
|
import { type AgentApi } from "./rest/agent";
|
|
4
5
|
import { type AuthorityApi } from "./rest/authority";
|
|
6
|
+
import { type BankApi } from "./rest/bank";
|
|
5
7
|
import { type ClobApi } from "./rest/clob";
|
|
6
8
|
import { type LicenseApi } from "./rest/license";
|
|
7
9
|
import { type MarketApi } from "./rest/market";
|
|
@@ -14,7 +16,7 @@ import { DexWsClient } from "./ws/client";
|
|
|
14
16
|
import type { DexWsOptions } from "./ws/types";
|
|
15
17
|
import { type TokenRegistryApi } from "./rest/tokenregistry";
|
|
16
18
|
import type { AnyEip712Msg, Eip712TxContext } from "./eip712/builder";
|
|
17
|
-
import type { SignAndBroadcastParams } from "./eip712/sign-and-broadcast";
|
|
19
|
+
import type { SignAndBroadcastParams, SignAndBroadcastResult } from "./eip712/sign-and-broadcast";
|
|
18
20
|
import { EIP712_MSG_TYPES } from "./eip712/registry";
|
|
19
21
|
import { type SignerInput } from "./eip712/signers";
|
|
20
22
|
export interface AultClientOptions {
|
|
@@ -29,8 +31,10 @@ export interface AultClientOptions {
|
|
|
29
31
|
export interface AultClient {
|
|
30
32
|
network: NetworkConfig;
|
|
31
33
|
rest: {
|
|
34
|
+
accountx: AccountxApi;
|
|
32
35
|
agent: AgentApi;
|
|
33
36
|
authority: AuthorityApi;
|
|
37
|
+
bank: BankApi;
|
|
34
38
|
clob: ClobApi;
|
|
35
39
|
license: LicenseApi;
|
|
36
40
|
market: MarketApi;
|
|
@@ -49,12 +53,7 @@ export interface AultClient {
|
|
|
49
53
|
domain: Record<string, unknown>;
|
|
50
54
|
message: Record<string, unknown>;
|
|
51
55
|
};
|
|
52
|
-
signAndBroadcast: (params: Omit<SignAndBroadcastParams, "network" | "fetchFn">) => Promise<
|
|
53
|
-
txHash: string;
|
|
54
|
-
code: number;
|
|
55
|
-
rawLog?: string;
|
|
56
|
-
confirmed?: boolean;
|
|
57
|
-
}>;
|
|
56
|
+
signAndBroadcast: (params: Omit<SignAndBroadcastParams, "network" | "fetchFn">) => Promise<SignAndBroadcastResult>;
|
|
58
57
|
registry: typeof EIP712_MSG_TYPES;
|
|
59
58
|
};
|
|
60
59
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type GAS_CONSTANTS } from "./network";
|
|
2
|
+
/**
|
|
3
|
+
* Per-op fee-free gas formulas for the CLOB order methods, shared by the
|
|
4
|
+
* high-level (wallet) and agent factories. The formulas are identical across
|
|
5
|
+
* both paths; the only delta is the cancel EIP-712 ante, which is wallet-only
|
|
6
|
+
* (see {@link cancelOrdersGas}). Each takes an explicit `gas` snapshot so a
|
|
7
|
+
* manifest hot-swap is honored on the next call.
|
|
8
|
+
*/
|
|
9
|
+
type Gas = typeof GAS_CONSTANTS;
|
|
10
|
+
export declare function limitOrderGas(gas: Gas): string;
|
|
11
|
+
export declare function marketOrderGas(gas: Gas): string;
|
|
12
|
+
export declare function scaleOrderGas(gas: Gas, subOrderCount: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Cancel gas. `includeAnte` adds the EIP-712 ante on top of the fee-free
|
|
15
|
+
* allowance: cancel's base (`CANCEL_ORDER_BASE`) is the smallest CLOB op, so the
|
|
16
|
+
* fee-free multiplier doesn't absorb the ante the way limit/market/scale do.
|
|
17
|
+
* Wallet (EIP-712) cancels pass `true`; agent cancels are gas-capped and pass
|
|
18
|
+
* `false`. If chain `MinGasLimits` change, revisit whether the other ops also
|
|
19
|
+
* need the ante.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cancelOrdersGas(gas: Gas, orderCount: number, includeAnte: boolean): string;
|
|
22
|
+
/**
|
|
23
|
+
* Modify gas: per-order minimum with no base (chain `MinGasPerModifyOrder`).
|
|
24
|
+
* Same ante reasoning as {@link cancelOrdersGas} — wallet modifies pass
|
|
25
|
+
* `includeAnte: true`; agent modifies are gas-capped and pass `false`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function modifyOrdersGas(gas: Gas, orderCount: number, includeAnte: boolean): string;
|
|
28
|
+
export {};
|
package/dist/core/clob-msgs.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Duration } from "../proto/gen/google/protobuf/duration";
|
|
2
1
|
export declare function buildLimitOrderMsg(sender: string, params: {
|
|
3
2
|
marketId: Uint8Array;
|
|
4
3
|
isBuy: boolean;
|
|
5
4
|
price: string;
|
|
6
5
|
quantity: string;
|
|
7
|
-
|
|
6
|
+
deadline: Date;
|
|
8
7
|
postOnly?: boolean;
|
|
9
8
|
builderAddress?: string;
|
|
10
9
|
builderFeeRate?: string;
|
|
11
|
-
|
|
10
|
+
cloid?: Uint8Array;
|
|
11
|
+
}): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "builderFeeRate" | "cloid" | "postOnly" | "builderAddress"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceLimitOrder, "builderFeeRate" | "cloid" | "postOnly" | "builderAddress">>, "/ault.clob.v1.MsgPlaceLimitOrder">;
|
|
12
12
|
export declare function buildMarketOrderMsg(sender: string, params: {
|
|
13
13
|
marketId: Uint8Array;
|
|
14
14
|
isBuy: boolean;
|
|
@@ -17,8 +17,34 @@ export declare function buildMarketOrderMsg(sender: string, params: {
|
|
|
17
17
|
priceTolerance?: string;
|
|
18
18
|
builderAddress?: string;
|
|
19
19
|
builderFeeRate?: string;
|
|
20
|
-
|
|
20
|
+
cloid?: Uint8Array;
|
|
21
|
+
}): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "builderFeeRate" | "cloid" | "builderAddress" | "worstPrice" | "priceTolerance"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").MsgPlaceMarketOrder, "builderFeeRate" | "cloid" | "builderAddress" | "worstPrice" | "priceTolerance">>, "/ault.clob.v1.MsgPlaceMarketOrder">;
|
|
22
|
+
/** Each `orderIds` entry may be an 8-byte cloid or a 16-byte chain order_id. */
|
|
21
23
|
export declare function buildCancelOrdersMsg(sender: string, orderIds: Uint8Array[]): import("../index.js").Eip712Msg<import("../proto/gen/ault/clob/v1/tx").MsgCancelOrders, "/ault.clob.v1.MsgCancelOrders">;
|
|
24
|
+
/**
|
|
25
|
+
* One entry in a modifyOrders batch. `orderId` may be an 8-byte cloid or a
|
|
26
|
+
* 16-byte chain order_id; an omitted field keeps the order's current value.
|
|
27
|
+
*/
|
|
28
|
+
export type ModifyOrderEntry = {
|
|
29
|
+
orderId: Uint8Array;
|
|
30
|
+
newPrice?: string;
|
|
31
|
+
newQuantity?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* At least one of `newPrice`/`newQuantity` must be set per entry — enforced
|
|
35
|
+
* here, mirroring the chain's ValidateBasic, so a no-op modify never reaches
|
|
36
|
+
* the EIP-712 typed data.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildModifyOrdersMsg(sender: string, orders: ModifyOrderEntry[]): import("../index.js").Eip712Msg<Omit<import("../proto/gen/ault/clob/v1/tx").MsgModifyOrders, "orders"> & {
|
|
39
|
+
orders: (Omit<import("../proto/gen/ault/clob/v1/tx").ModifyOrder, "newQuantity" | "newPrice"> & Partial<Pick<import("../proto/gen/ault/clob/v1/tx").ModifyOrder, "newQuantity" | "newPrice">>)[];
|
|
40
|
+
}, "/ault.clob.v1.MsgModifyOrders">;
|
|
41
|
+
/**
|
|
42
|
+
* EIP-712 constraint, wallet path only: typed data assigns a single struct
|
|
43
|
+
* type to every element of the `orders` array, so a batch mixing price-only
|
|
44
|
+
* and quantity-only entries cannot be represented. The agent path signs raw
|
|
45
|
+
* proto (SIGN_MODE_DIRECT) and does not call this.
|
|
46
|
+
*/
|
|
47
|
+
export declare function assertUniformModifyShape(orders: ModifyOrderEntry[]): void;
|
|
22
48
|
export declare function buildScaleOrderMsg(sender: string, params: {
|
|
23
49
|
marketId: Uint8Array;
|
|
24
50
|
isBuy: boolean;
|
|
@@ -26,7 +52,7 @@ export declare function buildScaleOrderMsg(sender: string, params: {
|
|
|
26
52
|
highPrice: string;
|
|
27
53
|
totalQuantity: string;
|
|
28
54
|
weights: number[];
|
|
29
|
-
|
|
55
|
+
deadline: Date;
|
|
30
56
|
postOnly?: boolean;
|
|
31
57
|
builderAddress?: string;
|
|
32
58
|
builderFeeRate?: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PlaceOrderResult, PlaceScaleOrderResult, CancelOrdersResult, ModifyOrdersResult, TxResult } from "../high-level/types";
|
|
2
|
+
type MsgResponse = {
|
|
3
|
+
typeUrl: string;
|
|
4
|
+
value: Uint8Array;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Shared wait/decode plumbing for the CLOB order methods (high-level and
|
|
8
|
+
* agent). Resolves the `wait` default once, runs the broadcast, and either
|
|
9
|
+
* returns the raw {@link TxResult} (broadcast-only) or feeds the committed
|
|
10
|
+
* `msg_responses` to the per-op decoder. Keeps the `wait ?? false` default and
|
|
11
|
+
* the broadcast-vs-decode branch in one place; callers supply the gas/options
|
|
12
|
+
* (which genuinely differ per op) via the `run` thunk.
|
|
13
|
+
*/
|
|
14
|
+
export declare function withWaitDecode<R extends TxResult>(wait: boolean | undefined, run: (wait: boolean) => Promise<TxResult>, decode: (msgResponses: MsgResponse[] | undefined, base: TxResult) => R): Promise<TxResult | R>;
|
|
15
|
+
export declare const decodeLimitOrderResult: (msgResponses: MsgResponse[] | undefined, base: TxResult) => PlaceOrderResult;
|
|
16
|
+
export declare const decodeMarketOrderResult: (msgResponses: MsgResponse[] | undefined, base: TxResult) => PlaceOrderResult;
|
|
17
|
+
export declare function decodeScaleOrderResult(msgResponses: MsgResponse[] | undefined, base: TxResult): PlaceScaleOrderResult;
|
|
18
|
+
export declare function decodeModifyOrdersResult(msgResponses: MsgResponse[] | undefined, base: TxResult): ModifyOrdersResult;
|
|
19
|
+
export declare function decodeCancelOrdersResult(msgResponses: MsgResponse[] | undefined, base: TxResult): CancelOrdersResult;
|
|
20
|
+
export {};
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -15,3 +15,82 @@ export declare class WebSocketError extends Error {
|
|
|
15
15
|
reason?: string;
|
|
16
16
|
constructor(message: string, code?: number, reason?: string);
|
|
17
17
|
}
|
|
18
|
+
export interface TxErrorParams {
|
|
19
|
+
txHash: string;
|
|
20
|
+
code: number;
|
|
21
|
+
rawLog?: string;
|
|
22
|
+
/**
|
|
23
|
+
* - `true` -- chain returned a definitive non-zero code (CheckTx or DeliverTx).
|
|
24
|
+
* - `false` -- broadcast accepted but inclusion never observed within the timeout.
|
|
25
|
+
* - `undefined` -- broadcast accepted but the confirmation lookup endpoint failed.
|
|
26
|
+
*/
|
|
27
|
+
confirmed: boolean | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when a tx broadcast resolves to a definitive on-chain failure
|
|
31
|
+
* (CheckTx or DeliverTx returned a non-zero code). Callers should catch
|
|
32
|
+
* this and surface the failure (e.g. UI toasts).
|
|
33
|
+
*/
|
|
34
|
+
export declare class TxError extends Error {
|
|
35
|
+
txHash: string;
|
|
36
|
+
code: number;
|
|
37
|
+
rawLog?: string;
|
|
38
|
+
confirmed: boolean | undefined;
|
|
39
|
+
constructor(params: TxErrorParams, message?: string);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown when a tx was broadcast but block inclusion could not be confirmed
|
|
43
|
+
* within the deadline. The tx may still commit later — callers can re-query
|
|
44
|
+
* by `txHash` to recover the final result.
|
|
45
|
+
*/
|
|
46
|
+
export declare class TxNotConfirmedError extends TxError {
|
|
47
|
+
constructor(params: TxErrorParams);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Thrown when a tx was broadcast but the confirmation lookup endpoint was
|
|
51
|
+
* unreachable or returned an unrecognized payload. Distinct from
|
|
52
|
+
* `TxNotConfirmedError` so callers can distinguish "still pending" from
|
|
53
|
+
* "we cannot tell at all".
|
|
54
|
+
*/
|
|
55
|
+
export declare class TxConfirmationUnavailableError extends TxError {
|
|
56
|
+
constructor(params: TxErrorParams);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Thrown in wait mode when the tx committed successfully (DeliverTx code 0) but
|
|
60
|
+
* the expected per-message response was missing from `tx_response.data` — e.g. a
|
|
61
|
+
* lagging LCD node that returns a confirmed tx without `data`. Distinct from
|
|
62
|
+
* `TxError` so callers can tell "the order failed" from "the order succeeded but
|
|
63
|
+
* I could not decode its id". The tx is on-chain; re-query by `txHash` to recover
|
|
64
|
+
* the response.
|
|
65
|
+
*/
|
|
66
|
+
export declare class MissingMsgResponseError extends Error {
|
|
67
|
+
txHash?: string;
|
|
68
|
+
typeUrl: string;
|
|
69
|
+
constructor(typeUrl: string, txHash?: string);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Thrown by `withdrawRewards` when a mid-loop tx fails AFTER one or more
|
|
73
|
+
* validators have already been withdrawn on-chain. Carries the txs that
|
|
74
|
+
* already committed so callers can reconcile the partial state.
|
|
75
|
+
*
|
|
76
|
+
* `cause` is the underlying error for the failed validator — typically a
|
|
77
|
+
* `TxError` (chain rejection) but it can also be a transport-level failure
|
|
78
|
+
* (`NetworkError`, `TimeoutError`, `ApiError`) raised by the broadcast
|
|
79
|
+
* helper before the chain ever sees the tx.
|
|
80
|
+
*/
|
|
81
|
+
export declare class WithdrawRewardsPartialError extends Error {
|
|
82
|
+
failedValidatorAddress: string;
|
|
83
|
+
partialResults: ReadonlyArray<{
|
|
84
|
+
txHash: string;
|
|
85
|
+
validatorAddress: string;
|
|
86
|
+
}>;
|
|
87
|
+
cause: Error;
|
|
88
|
+
constructor(params: {
|
|
89
|
+
failedValidatorAddress: string;
|
|
90
|
+
partialResults: ReadonlyArray<{
|
|
91
|
+
txHash: string;
|
|
92
|
+
validatorAddress: string;
|
|
93
|
+
}>;
|
|
94
|
+
cause: Error;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -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,121 @@
|
|
|
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
|
+
* `DENOM`, and `EIP712_ANTE_GAS` so the embedded values stay authoritative for
|
|
40
|
+
* the gas-constants object — the broadcast layer reads the fee/gas/denom off
|
|
41
|
+
* `network.eip712*`, and `EIP712_ANTE_GAS` is a fixed chain-ante constant the
|
|
42
|
+
* manifest is not allowed to override.
|
|
43
|
+
*
|
|
44
|
+
* The cast widens the zod-partial back to the concrete `GAS_CONSTANTS` type:
|
|
45
|
+
* every field has a baseline value, so any key the manifest omits keeps the
|
|
46
|
+
* embedded one.
|
|
47
|
+
*/
|
|
48
|
+
export declare function applyGasOverrides(gas: ManifestGas | undefined): typeof GAS_CONSTANTS;
|
|
49
|
+
export interface ManifestResolverOptions {
|
|
50
|
+
network: NetworkConfig;
|
|
51
|
+
fetchFn?: FetchFn;
|
|
52
|
+
fetchOptions?: FetchWithRetryOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Milliseconds between background refreshes. Default: 5 minutes.
|
|
55
|
+
* 0 disables hot-swap (the initial fetch still runs).
|
|
56
|
+
*/
|
|
57
|
+
refreshIntervalMs?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Caller-supplied override applied on top of the fetched manifest. Frozen
|
|
60
|
+
* at construction time (deep-cloned) so post-`createClient` mutation by the
|
|
61
|
+
* caller cannot poison resolver state. Must validate against
|
|
62
|
+
* `ManifestSchema`; otherwise `createManifestResolver` throws.
|
|
63
|
+
*/
|
|
64
|
+
override?: Manifest;
|
|
65
|
+
}
|
|
66
|
+
export interface ManifestResolver {
|
|
67
|
+
/** The base network the resolver was created against. Stable. */
|
|
68
|
+
readonly baseNetwork: NetworkConfig;
|
|
69
|
+
/** Returns the most recently fetched manifest, or null if none has succeeded. */
|
|
70
|
+
currentManifest(): Manifest | null;
|
|
71
|
+
/** Network with the latest manifest URL/eip712 overrides applied. */
|
|
72
|
+
currentNetwork(): NetworkConfig;
|
|
73
|
+
/** Gas constants with the latest manifest gas overrides applied. */
|
|
74
|
+
currentGas(): typeof GAS_CONSTANTS;
|
|
75
|
+
/** Triggers an out-of-band refresh. Resolves regardless of fetch outcome. */
|
|
76
|
+
refresh(): Promise<void>;
|
|
77
|
+
/** Stops the background refresh. Safe to call multiple times. */
|
|
78
|
+
dispose(): void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Builds a manifest resolver bound to a network.
|
|
82
|
+
*
|
|
83
|
+
* Performs an initial fetch (best-effort, tight timeout: failure leaves the
|
|
84
|
+
* manifest empty) and starts a background refresh loop unless
|
|
85
|
+
* `refreshIntervalMs` is 0 or `dexApiUrl` is unset. The promise resolves
|
|
86
|
+
* once the initial fetch attempt has completed.
|
|
87
|
+
*
|
|
88
|
+
* Background refreshes are jittered ±10% around `refreshIntervalMs` to keep
|
|
89
|
+
* a fleet of SDK consumers from hitting the dex-api in lockstep.
|
|
90
|
+
*/
|
|
91
|
+
export declare function createManifestResolver(opts: ManifestResolverOptions): Promise<ManifestResolver>;
|
|
92
|
+
/**
|
|
93
|
+
* Options for {@link createStaticResolver}. Mirrors the `network`/`override`
|
|
94
|
+
* shape of {@link ManifestResolverOptions} so callers can move between the
|
|
95
|
+
* two without re-ordering arguments. The `manifest` field is the static
|
|
96
|
+
* fetched-layer stand-in (typically `null` in tests that want the embedded
|
|
97
|
+
* baseline; non-null when injecting a fixed manifest).
|
|
98
|
+
*/
|
|
99
|
+
export interface StaticResolverOptions {
|
|
100
|
+
network: NetworkConfig;
|
|
101
|
+
/** Static stand-in for the fetched manifest. Defaults to `null`. */
|
|
102
|
+
manifest?: Manifest | null;
|
|
103
|
+
/** Caller-supplied override, validated and frozen at construction. */
|
|
104
|
+
override?: Manifest;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Static resolver — does not fetch, does not run a timer. Useful as the
|
|
108
|
+
* embedded-only path (no `dexApiUrl`) or in tests where you want to inject a
|
|
109
|
+
* fixed manifest. The `override` is treated identically to the
|
|
110
|
+
* `createManifestResolver` override: validated, deep-cloned, merged on top.
|
|
111
|
+
*
|
|
112
|
+
* Two call shapes are supported:
|
|
113
|
+
*
|
|
114
|
+
* 1. Options bag (preferred): `createStaticResolver({ network, manifest, override })`.
|
|
115
|
+
* 2. Legacy positional `(network, manifest)`: kept for backward compatibility
|
|
116
|
+
* with the pre-override signature. Untyped JS callers using the old shape
|
|
117
|
+
* keep working; TypeScript callers see the typed overload and pick whichever
|
|
118
|
+
* matches their argument shape.
|
|
119
|
+
*/
|
|
120
|
+
export declare function createStaticResolver(opts: StaticResolverOptions): ManifestResolver;
|
|
121
|
+
export declare function createStaticResolver(network: NetworkConfig, manifest?: Manifest | null): ManifestResolver;
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
DELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
UNDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
WITHDRAW_DELEGATOR_REWARD: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
export declare const ManifestEip712Schema: z.ZodObject<{
|
|
36
|
+
feeDenom: z.ZodOptional<z.ZodString>;
|
|
37
|
+
feeAmount: z.ZodOptional<z.ZodString>;
|
|
38
|
+
gasLimit: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
/**
|
|
41
|
+
* URL overrides applied at boot of `createClient`. The dex-api is the trust
|
|
42
|
+
* root for these values; they are NOT URL-validated here on purpose — the
|
|
43
|
+
* dex-api already sits inside the SDK's trust boundary, and a stricter
|
|
44
|
+
* validator would force us to mirror operator expectations (trailing slashes,
|
|
45
|
+
* non-https envs, internal hostnames) in the SDK schema.
|
|
46
|
+
*
|
|
47
|
+
* Hot-swap semantics: subsequent rotations only reach the tx executor's
|
|
48
|
+
* network getter on the next tx call. Long-lived REST/WS contexts captured
|
|
49
|
+
* by `createAultClient` at boot do NOT pick up URL changes. Consumers that
|
|
50
|
+
* need fresh URLs after a rotation must re-create the client.
|
|
51
|
+
*/
|
|
52
|
+
export declare const ManifestUrlsSchema: z.ZodObject<{
|
|
53
|
+
rpc: z.ZodOptional<z.ZodString>;
|
|
54
|
+
rest: z.ZodOptional<z.ZodString>;
|
|
55
|
+
evm: z.ZodOptional<z.ZodString>;
|
|
56
|
+
explorer: z.ZodOptional<z.ZodString>;
|
|
57
|
+
dexWs: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
export declare const ManifestSchema: z.ZodObject<{
|
|
60
|
+
schemaVersion: z.ZodNumber;
|
|
61
|
+
gas: z.ZodOptional<z.ZodObject<{
|
|
62
|
+
FEE_FREE_GAS_MULTIPLIER: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
PER_LICENSE: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
PER_KYC_MEMBER: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
PER_DELEGATE_MINING: z.ZodOptional<z.ZodNumber>;
|
|
66
|
+
PER_SUBMIT_WORK: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
SET_OWNER_VRF_KEY: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
APPROVE_AGENT: z.ZodOptional<z.ZodNumber>;
|
|
69
|
+
REVOKE_AGENT: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
APPROVE_BUILDER: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
REVOKE_BUILDER: z.ZodOptional<z.ZodNumber>;
|
|
72
|
+
SET_REFERRAL_CODE: z.ZodOptional<z.ZodNumber>;
|
|
73
|
+
SET_REFERRAL: z.ZodOptional<z.ZodNumber>;
|
|
74
|
+
LIMIT_ORDER: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
MARKET_ORDER: z.ZodOptional<z.ZodNumber>;
|
|
76
|
+
SCALE_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
SCALE_ORDER_PER_SUB: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
CANCEL_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
|
|
80
|
+
OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
DELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
UNDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
WITHDRAW_DELEGATOR_REWARD: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
eip712: z.ZodOptional<z.ZodObject<{
|
|
87
|
+
feeDenom: z.ZodOptional<z.ZodString>;
|
|
88
|
+
feeAmount: z.ZodOptional<z.ZodString>;
|
|
89
|
+
gasLimit: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
urls: z.ZodOptional<z.ZodObject<{
|
|
92
|
+
rpc: z.ZodOptional<z.ZodString>;
|
|
93
|
+
rest: z.ZodOptional<z.ZodString>;
|
|
94
|
+
evm: z.ZodOptional<z.ZodString>;
|
|
95
|
+
explorer: z.ZodOptional<z.ZodString>;
|
|
96
|
+
dexWs: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
}, z.core.$loose>;
|
|
99
|
+
export type ManifestGas = z.infer<typeof ManifestGasSchema>;
|
|
100
|
+
export type ManifestEip712 = z.infer<typeof ManifestEip712Schema>;
|
|
101
|
+
export type ManifestUrls = z.infer<typeof ManifestUrlsSchema>;
|
|
102
|
+
export type Manifest = z.infer<typeof ManifestSchema>;
|
package/dist/core/network.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface NetworkConfig {
|
|
|
12
12
|
dexWsUrl?: string;
|
|
13
13
|
explorerUrl?: string;
|
|
14
14
|
isProduction: boolean;
|
|
15
|
+
/** Default EIP-712 fee denom. Overrides GAS_CONSTANTS.DENOM. */
|
|
16
|
+
eip712FeeDenom?: string;
|
|
15
17
|
/** Default EIP-712 fee amount in smallest denom (e.g. aault). Overrides GAS_CONSTANTS.EIP712_FEE_AMOUNT. */
|
|
16
18
|
eip712FeeAmount?: string;
|
|
17
19
|
/** Default EIP-712 gas limit. Overrides GAS_CONSTANTS.EIP712_GAS_LIMIT. */
|
|
@@ -37,23 +39,50 @@ export declare const GAS_CONSTANTS: {
|
|
|
37
39
|
readonly DENOM: "aault";
|
|
38
40
|
/** Chain multiplier applied to min gas to derive max gas (120 = 1.2×). */
|
|
39
41
|
readonly FEE_FREE_GAS_MULTIPLIER: 120;
|
|
42
|
+
/**
|
|
43
|
+
* EIP-712 ante overhead, in gas. The chain's per-message MinGasLimit values
|
|
44
|
+
* (mirrored below) measure the *handler* cost only; a fee-free EIP-712 tx
|
|
45
|
+
* additionally burns ante gas (sig verification + typed-data decode + tx
|
|
46
|
+
* size) that counts against gasWanted. For small-base ops (cancel) the 1.2×
|
|
47
|
+
* buffer doesn't cover it, so the high-level (EIP-712) path adds this on top.
|
|
48
|
+
* The agent path is capped at MinGasLimit×1.2 and must not add it.
|
|
49
|
+
*/
|
|
50
|
+
readonly EIP712_ANTE_GAS: 30000;
|
|
40
51
|
readonly PER_LICENSE: 200000;
|
|
41
52
|
readonly PER_KYC_MEMBER: 200000;
|
|
42
53
|
readonly PER_DELEGATE_MINING: 200000;
|
|
43
54
|
readonly PER_SUBMIT_WORK: 200000;
|
|
44
55
|
readonly SET_OWNER_VRF_KEY: 200000;
|
|
45
|
-
readonly APPROVE_AGENT:
|
|
46
|
-
readonly REVOKE_AGENT:
|
|
47
|
-
readonly APPROVE_BUILDER:
|
|
48
|
-
readonly REVOKE_BUILDER:
|
|
49
|
-
readonly SET_REFERRAL_CODE:
|
|
50
|
-
readonly SET_REFERRAL:
|
|
51
|
-
readonly LIMIT_ORDER:
|
|
52
|
-
readonly MARKET_ORDER:
|
|
56
|
+
readonly APPROVE_AGENT: 97000;
|
|
57
|
+
readonly REVOKE_AGENT: 61000;
|
|
58
|
+
readonly APPROVE_BUILDER: 81000;
|
|
59
|
+
readonly REVOKE_BUILDER: 57000;
|
|
60
|
+
readonly SET_REFERRAL_CODE: 76000;
|
|
61
|
+
readonly SET_REFERRAL: 80000;
|
|
62
|
+
readonly LIMIT_ORDER: 125000;
|
|
63
|
+
readonly MARKET_ORDER: 119000;
|
|
53
64
|
readonly SCALE_ORDER_BASE: 115000;
|
|
54
|
-
readonly SCALE_ORDER_PER_SUB:
|
|
55
|
-
readonly CANCEL_ORDER_BASE:
|
|
56
|
-
readonly CANCEL_ORDER_PER_ID:
|
|
65
|
+
readonly SCALE_ORDER_PER_SUB: 13000;
|
|
66
|
+
readonly CANCEL_ORDER_BASE: 50000;
|
|
67
|
+
readonly CANCEL_ORDER_PER_ID: 15000;
|
|
68
|
+
readonly MODIFY_ORDER_PER_ID: 113000;
|
|
69
|
+
readonly OPEN_ACCOUNT: 96000;
|
|
70
|
+
readonly DELEGATE: 220000;
|
|
71
|
+
readonly UNDELEGATE: 220000;
|
|
72
|
+
readonly BEGIN_REDELEGATE: 280000;
|
|
73
|
+
readonly WITHDRAW_DELEGATOR_REWARD: 220000;
|
|
57
74
|
};
|
|
58
|
-
|
|
59
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Returns the per-tx gas allowance for a uniform-cost batch (in wire-format
|
|
77
|
+
* integer string). The chain interprets `gas` as an unsigned bigint, so the
|
|
78
|
+
* division by 100 must floor — a fractional result like `"149998.5"` would
|
|
79
|
+
* later crash inside `signAndBroadcastEip712`'s `BigInt(context.fee.gas)`.
|
|
80
|
+
* Use BigInt arithmetic from the start so the floor is exact for any
|
|
81
|
+
* combination of manifest-supplied values.
|
|
82
|
+
*/
|
|
83
|
+
export declare function computeFeeFreeGas(minGasPerOp: number, count: number, multiplier?: number): string;
|
|
84
|
+
/**
|
|
85
|
+
* Same shape as {@link computeFeeFreeGas} but for ops with a base + per-item
|
|
86
|
+
* cost (CLOB cancel / scale orders). Same BigInt-floor reasoning applies.
|
|
87
|
+
*/
|
|
88
|
+
export declare function computeFeeFreeGasCompound(base: number, perItem: number, count: number, multiplier?: number): string;
|