ault-sdk-ts 0.18.1 → 0.19.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 +37 -0
- package/dist/client.d.ts +5 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/network.d.ts +8 -0
- package/dist/eip712/sign-and-broadcast.d.ts +9 -1
- package/dist/high-level/tx-executor.d.ts +2 -0
- package/dist/high-level/types.d.ts +7 -0
- package/dist/index.cjs +35 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -167,6 +167,7 @@ interface ClientOptions {
|
|
|
167
167
|
defaultGasLimit?: string; // Optional: default gas limit
|
|
168
168
|
defaultMemo?: string; // Optional: default memo
|
|
169
169
|
defaultConfirmationTimeoutMs?: number;
|
|
170
|
+
maxFeeAmount?: string | null; // Optional: fee limit in raw aault (see "Fee limit"), null to turn it off
|
|
170
171
|
manifestOverride?: Manifest; // Optional: caller-supplied manifest layer (see "SDK Manifest")
|
|
171
172
|
}
|
|
172
173
|
```
|
|
@@ -1411,6 +1412,42 @@ ECDSA signatures. `error.signerAddress` is the account you asked to sign with
|
|
|
1411
1412
|
and `error.recoveredAddress` is the one the signature belongs to. Nothing was
|
|
1412
1413
|
sent, so there is no transaction to look up.
|
|
1413
1414
|
|
|
1415
|
+
### Fee limit
|
|
1416
|
+
|
|
1417
|
+
When a call does not pass `feeAmount`, the SDK works the fee out by itself:
|
|
1418
|
+
from the manifest if it sets one, otherwise from the feemarket params the REST
|
|
1419
|
+
endpoint reports. Neither value comes from you, so the SDK checks it before
|
|
1420
|
+
signing. A fee over the limit throws `FeeCapExceededError` and nothing is
|
|
1421
|
+
signed or sent.
|
|
1422
|
+
|
|
1423
|
+
The limit is 25 AULT (`DEFAULT_MAX_FEE_AMOUNT`, in raw `aault`). A normal
|
|
1424
|
+
transaction pays a few hundredths of an AULT, and a transaction that fills a
|
|
1425
|
+
whole block costs about 15 AULT at the current gas price, so the limit is only
|
|
1426
|
+
reached when the manifest or the endpoint returns a wrong or hostile value, or
|
|
1427
|
+
when the gas price has risen and the batch is very large.
|
|
1428
|
+
|
|
1429
|
+
```typescript
|
|
1430
|
+
import { createClient, FeeCapExceededError } from "ault-sdk-ts";
|
|
1431
|
+
|
|
1432
|
+
// Raise or lower the limit for the whole client, or pass null to turn it off.
|
|
1433
|
+
const client = await createClient({ network, signer, maxFeeAmount: "50000000000000000000" });
|
|
1434
|
+
|
|
1435
|
+
try {
|
|
1436
|
+
await client.delegate({ validatorAddress, amount });
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
if (error instanceof FeeCapExceededError) {
|
|
1439
|
+
console.error(`Fee ${error.feeAmount} is over the limit ${error.maxFeeAmount}`);
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
```
|
|
1443
|
+
|
|
1444
|
+
A fee you pass yourself as `feeAmount` is never checked, so that is also the
|
|
1445
|
+
way to let one call through. For a large batch, splitting it works too.
|
|
1446
|
+
|
|
1447
|
+
The limit is in `aault`. If the fee denom is anything else and you did not pass
|
|
1448
|
+
`feeAmount`, the SDK cannot compare the two and refuses to sign. Pass the
|
|
1449
|
+
amount explicitly, as `openAccount` already asks you to.
|
|
1450
|
+
|
|
1414
1451
|
## Advanced Usage
|
|
1415
1452
|
|
|
1416
1453
|
For advanced use cases, you can access the low-level client:
|
package/dist/client.d.ts
CHANGED
|
@@ -30,6 +30,11 @@ export interface AultClientOptions {
|
|
|
30
30
|
signer?: SignerInput;
|
|
31
31
|
signerAddress?: string;
|
|
32
32
|
defaultConfirmationTimeoutMs?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Fee limit for `eip712.signAndBroadcast` calls that do not set their own;
|
|
35
|
+
* see `SignAndBroadcastParams.maxFeeAmount`.
|
|
36
|
+
*/
|
|
37
|
+
maxFeeAmount?: string | null;
|
|
33
38
|
fetchFn?: FetchFn;
|
|
34
39
|
fetchOptions?: FetchWithRetryOptions;
|
|
35
40
|
wsOptions?: DexWsOptions;
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -51,6 +51,33 @@ export declare class TxSimulationError extends Error {
|
|
|
51
51
|
chainCode?: number;
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Thrown before anything is signed when the fee the SDK was about to sign is
|
|
56
|
+
* over the client-side limit. Only fees the caller did not choose are checked:
|
|
57
|
+
* one set by the manifest, or one priced from the feemarket params the REST
|
|
58
|
+
* endpoint reports. A limit this far above a normal fee is only reached when
|
|
59
|
+
* one of those sources is wrong or hostile, or by a batch large enough to
|
|
60
|
+
* fill most of a block.
|
|
61
|
+
*
|
|
62
|
+
* To send anyway, pass an explicit `feeAmount` on the call, split the batch,
|
|
63
|
+
* or raise `maxFeeAmount` on the client.
|
|
64
|
+
*
|
|
65
|
+
* `maxFeeAmount` is `undefined` here when the fee could not be bounded at all:
|
|
66
|
+
* its denom is not the native one, so the limit (in raw aault) does not apply.
|
|
67
|
+
* Raising the limit does not help in that case. Pass an explicit `feeAmount`,
|
|
68
|
+
* or set `maxFeeAmount` to `null` on the client.
|
|
69
|
+
*/
|
|
70
|
+
export declare class FeeCapExceededError extends Error {
|
|
71
|
+
/** The fee that was about to be signed, in raw units of `feeDenom`. */
|
|
72
|
+
feeAmount: string;
|
|
73
|
+
feeDenom: string;
|
|
74
|
+
maxFeeAmount?: string;
|
|
75
|
+
constructor(params: {
|
|
76
|
+
feeAmount: string;
|
|
77
|
+
feeDenom: string;
|
|
78
|
+
maxFeeAmount?: string;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
54
81
|
/**
|
|
55
82
|
* Thrown when a tx was broadcast but block inclusion could not be confirmed
|
|
56
83
|
* within the deadline. The tx may still commit later — callers can re-query
|
package/dist/core/network.d.ts
CHANGED
|
@@ -107,6 +107,14 @@ export declare const GAS_CONSTANTS: {
|
|
|
107
107
|
readonly BEGIN_REDELEGATE: 400000;
|
|
108
108
|
readonly WITHDRAW_DELEGATOR_REWARD: 220000;
|
|
109
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* Largest fee, in raw aault, the SDK signs when the amount comes from the
|
|
112
|
+
* manifest or the chain's feemarket instead of the caller: 25 AULT. That is
|
|
113
|
+
* above what a tx filling a whole block costs at the current gas price, so no
|
|
114
|
+
* tx that fits in a block reaches it today. Deliberately outside
|
|
115
|
+
* `GAS_CONSTANTS`, which a manifest can override.
|
|
116
|
+
*/
|
|
117
|
+
export declare const DEFAULT_MAX_FEE_AMOUNT = "25000000000000000000";
|
|
110
118
|
/** Gas limit to sign for a simulated `gas_used` (percent multiplier, floored). */
|
|
111
119
|
export declare function computeSimulatedGas(gasUsed: bigint, multiplier?: number): string;
|
|
112
120
|
/**
|
|
@@ -60,6 +60,14 @@ export interface SignAndBroadcastParams {
|
|
|
60
60
|
gasLimit?: string;
|
|
61
61
|
feeDenom?: string;
|
|
62
62
|
feeAmount?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Largest fee, in raw aault, to sign when `feeAmount` is not passed and the
|
|
65
|
+
* amount comes from the manifest or the feemarket. Over it the call throws
|
|
66
|
+
* `FeeCapExceededError` before signing. Default `DEFAULT_MAX_FEE_AMOUNT`
|
|
67
|
+
* (25 AULT); `null` turns the check off. An explicit `feeAmount` is never
|
|
68
|
+
* checked.
|
|
69
|
+
*/
|
|
70
|
+
maxFeeAmount?: string | null;
|
|
63
71
|
confirmationTimeoutMs?: number;
|
|
64
72
|
/**
|
|
65
73
|
* Simulate before signing and sign `gas_used × multiplier / 100`; `gasLimit`
|
|
@@ -100,4 +108,4 @@ export interface SignAndBroadcastResult {
|
|
|
100
108
|
data?: string;
|
|
101
109
|
confirmed: boolean;
|
|
102
110
|
}
|
|
103
|
-
export declare function signAndBroadcastEip712({ network, signerAddress, signer, msgs, memo, gasLimit, feeDenom, feeAmount, confirmationTimeoutMs, simulateGas, simulatedGasMultiplier, wait, fetchFn, fetchOptions, cache, feeMarketCache, }: SignAndBroadcastParams): Promise<SignAndBroadcastResult>;
|
|
111
|
+
export declare function signAndBroadcastEip712({ network, signerAddress, signer, msgs, memo, gasLimit, feeDenom, feeAmount, maxFeeAmount, confirmationTimeoutMs, simulateGas, simulatedGasMultiplier, wait, fetchFn, fetchOptions, cache, feeMarketCache, }: SignAndBroadcastParams): Promise<SignAndBroadcastResult>;
|
|
@@ -29,6 +29,8 @@ interface TxExecutorOptions {
|
|
|
29
29
|
fetchOptions?: FetchWithRetryOptions;
|
|
30
30
|
defaultMemo?: string;
|
|
31
31
|
defaultConfirmationTimeoutMs?: number;
|
|
32
|
+
/** Fee limit for fees the caller did not set; see `SignAndBroadcastParams.maxFeeAmount`. */
|
|
33
|
+
maxFeeAmount?: string | null;
|
|
32
34
|
/** Optional shared account cache (lets the agent executor read the same accountNumber). */
|
|
33
35
|
cache?: AccountCache;
|
|
34
36
|
/** Optional shared fee-market cache. */
|
|
@@ -103,6 +103,13 @@ export interface ClientOptions {
|
|
|
103
103
|
defaultMemo?: string;
|
|
104
104
|
/** Optional: default time to wait for DeliverTx confirmation before returning a provisional result */
|
|
105
105
|
defaultConfirmationTimeoutMs?: number;
|
|
106
|
+
/**
|
|
107
|
+
* Optional: largest fee, in raw aault, the client signs when a call does not
|
|
108
|
+
* pass `feeAmount` and the fee comes from the manifest or the chain's
|
|
109
|
+
* feemarket. Over it the call throws `FeeCapExceededError` before signing.
|
|
110
|
+
* Default 25 AULT (`DEFAULT_MAX_FEE_AMOUNT`); `null` turns the check off.
|
|
111
|
+
*/
|
|
112
|
+
maxFeeAmount?: string | null;
|
|
106
113
|
/**
|
|
107
114
|
* Optional sparse manifest applied on top of the fetched manifest and the
|
|
108
115
|
* embedded baseline. Frozen for the lifetime of the client; not affected
|
package/dist/index.cjs
CHANGED
|
@@ -39,12 +39,14 @@ __export(index_exports, {
|
|
|
39
39
|
COIN_TYPE: () => COIN_TYPE,
|
|
40
40
|
DEC_PRECISION: () => DEC_PRECISION,
|
|
41
41
|
DEFAULT_CHAIN_ID: () => DEFAULT_CHAIN_ID,
|
|
42
|
+
DEFAULT_MAX_FEE_AMOUNT: () => DEFAULT_MAX_FEE_AMOUNT,
|
|
42
43
|
DEFAULT_RETRYABLE_STATUSES: () => DEFAULT_RETRYABLE_STATUSES,
|
|
43
44
|
DEFAULT_TOKEN_PAIRS_LIMIT: () => DEFAULT_TOKEN_PAIRS_LIMIT,
|
|
44
45
|
DexWsClient: () => DexWsClient,
|
|
45
46
|
EIP712_DOMAIN_TYPE: () => EIP712_DOMAIN_TYPE,
|
|
46
47
|
EIP712_MSG_TYPES: () => EIP712_MSG_TYPES,
|
|
47
48
|
FEE_TYPE: () => FEE_TYPE,
|
|
49
|
+
FeeCapExceededError: () => FeeCapExceededError,
|
|
48
50
|
GAS_CONSTANTS: () => GAS_CONSTANTS,
|
|
49
51
|
GetAllTickersResponse: () => GetAllTickersResponse,
|
|
50
52
|
GetBalanceQueryParams: () => GetBalanceQueryParams,
|
|
@@ -637,7 +639,7 @@ __export(index_exports, {
|
|
|
637
639
|
module.exports = __toCommonJS(index_exports);
|
|
638
640
|
|
|
639
641
|
// src/core/user-agent.ts
|
|
640
|
-
var SDK_VERSION = "0.
|
|
642
|
+
var SDK_VERSION = "0.19.0";
|
|
641
643
|
var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
|
|
642
644
|
function isServerRuntime() {
|
|
643
645
|
if (typeof document !== "undefined") return false;
|
|
@@ -795,6 +797,17 @@ var TxSimulationError = class extends Error {
|
|
|
795
797
|
this.rawLog = params.rawLog;
|
|
796
798
|
}
|
|
797
799
|
};
|
|
800
|
+
var FeeCapExceededError = class extends Error {
|
|
801
|
+
constructor(params) {
|
|
802
|
+
super(
|
|
803
|
+
params.maxFeeAmount === void 0 ? `Refusing to sign a fee of ${params.feeAmount}${params.feeDenom}: it was not set by the caller and a fee in ${params.feeDenom} cannot be checked against the fee limit. Pass feeAmount explicitly, or set maxFeeAmount to null to turn the limit off.` : `Refusing to sign a fee of ${params.feeAmount}${params.feeDenom}: it is over the limit of ${params.maxFeeAmount}${params.feeDenom}. Pass feeAmount explicitly, split the batch, or raise maxFeeAmount.`
|
|
804
|
+
);
|
|
805
|
+
this.name = "FeeCapExceededError";
|
|
806
|
+
this.feeAmount = params.feeAmount;
|
|
807
|
+
this.feeDenom = params.feeDenom;
|
|
808
|
+
this.maxFeeAmount = params.maxFeeAmount;
|
|
809
|
+
}
|
|
810
|
+
};
|
|
798
811
|
var TxNotConfirmedError = class extends TxError {
|
|
799
812
|
constructor(params) {
|
|
800
813
|
super(
|
|
@@ -1208,6 +1221,7 @@ var GAS_CONSTANTS = {
|
|
|
1208
1221
|
BEGIN_REDELEGATE: 4e5,
|
|
1209
1222
|
WITHDRAW_DELEGATOR_REWARD: 22e4
|
|
1210
1223
|
};
|
|
1224
|
+
var DEFAULT_MAX_FEE_AMOUNT = "25000000000000000000";
|
|
1211
1225
|
function computeSimulatedGas(gasUsed, multiplier = GAS_CONSTANTS.SIMULATED_GAS_MULTIPLIER) {
|
|
1212
1226
|
if (!Number.isInteger(multiplier) || multiplier < 100) {
|
|
1213
1227
|
throw new Error(`simulated gas multiplier must be an integer >= 100, got ${multiplier}`);
|
|
@@ -35691,6 +35705,14 @@ async function resolveDynamicFeeAmount(network, gas, feeMarketCache, fetchFn, fe
|
|
|
35691
35705
|
const staticI = BigInt(staticFloor);
|
|
35692
35706
|
return dynamicI > staticI ? dynamicI.toString() : staticFloor;
|
|
35693
35707
|
}
|
|
35708
|
+
function assertFeeWithinCap(amount, denom, maxFeeAmount) {
|
|
35709
|
+
if (denom !== GAS_CONSTANTS.DENOM) {
|
|
35710
|
+
throw new FeeCapExceededError({ feeAmount: amount, feeDenom: denom });
|
|
35711
|
+
}
|
|
35712
|
+
if (BigInt(amount) > BigInt(maxFeeAmount)) {
|
|
35713
|
+
throw new FeeCapExceededError({ feeAmount: amount, feeDenom: denom, maxFeeAmount });
|
|
35714
|
+
}
|
|
35715
|
+
}
|
|
35694
35716
|
async function recoverSignerPubkey(typedData, signature, signerAddress) {
|
|
35695
35717
|
const signerEvmAddress = isValidEvmAddress(signerAddress) ? signerAddress : aultToEvm(signerAddress);
|
|
35696
35718
|
let sigBytes;
|
|
@@ -35888,6 +35910,7 @@ async function signAndBroadcastEip712({
|
|
|
35888
35910
|
gasLimit,
|
|
35889
35911
|
feeDenom,
|
|
35890
35912
|
feeAmount,
|
|
35913
|
+
maxFeeAmount = DEFAULT_MAX_FEE_AMOUNT,
|
|
35891
35914
|
confirmationTimeoutMs,
|
|
35892
35915
|
simulateGas = false,
|
|
35893
35916
|
simulatedGasMultiplier,
|
|
@@ -35953,6 +35976,9 @@ async function signAndBroadcastEip712({
|
|
|
35953
35976
|
}
|
|
35954
35977
|
}
|
|
35955
35978
|
resolvedFeeAmount = await feeFor(resolvedGas);
|
|
35979
|
+
if (feeAmount === void 0 && maxFeeAmount !== null) {
|
|
35980
|
+
assertFeeWithinCap(resolvedFeeAmount, resolvedFeeDenom, maxFeeAmount);
|
|
35981
|
+
}
|
|
35956
35982
|
const context = {
|
|
35957
35983
|
chainId: network.chainId,
|
|
35958
35984
|
accountNumber,
|
|
@@ -36141,7 +36167,9 @@ function createAultClient(options) {
|
|
|
36141
36167
|
signerAddress,
|
|
36142
36168
|
cache,
|
|
36143
36169
|
feeMarketCache,
|
|
36144
|
-
confirmationTimeoutMs: params.confirmationTimeoutMs ?? options.defaultConfirmationTimeoutMs
|
|
36170
|
+
confirmationTimeoutMs: params.confirmationTimeoutMs ?? options.defaultConfirmationTimeoutMs,
|
|
36171
|
+
// `null` on the call turns the limit off, so only `undefined` falls back.
|
|
36172
|
+
maxFeeAmount: params.maxFeeAmount === void 0 ? options.maxFeeAmount : params.maxFeeAmount
|
|
36145
36173
|
});
|
|
36146
36174
|
},
|
|
36147
36175
|
registry: EIP712_MSG_TYPES
|
|
@@ -38549,6 +38577,7 @@ function createTxExecutor(options) {
|
|
|
38549
38577
|
gasLimit: txOptions?.gasLimit ?? defaultGasLimit,
|
|
38550
38578
|
feeDenom: txOptions?.feeDenom,
|
|
38551
38579
|
feeAmount: txOptions?.feeAmount,
|
|
38580
|
+
maxFeeAmount: options.maxFeeAmount,
|
|
38552
38581
|
memo: txOptions?.memo ?? defaultMemo,
|
|
38553
38582
|
confirmationTimeoutMs: txOptions?.confirmationTimeoutMs ?? defaultConfirmationTimeoutMs,
|
|
38554
38583
|
simulateGas: txOptions?.simulateGas ?? false,
|
|
@@ -39651,6 +39680,7 @@ async function buildClient(options, resolver) {
|
|
|
39651
39680
|
const lowLevel = createAultClient({
|
|
39652
39681
|
network: getNetwork(),
|
|
39653
39682
|
defaultConfirmationTimeoutMs: options.defaultConfirmationTimeoutMs,
|
|
39683
|
+
maxFeeAmount: options.maxFeeAmount,
|
|
39654
39684
|
fetchFn: options.fetchFn,
|
|
39655
39685
|
fetchOptions: options.fetchOptions
|
|
39656
39686
|
});
|
|
@@ -39665,6 +39695,7 @@ async function buildClient(options, resolver) {
|
|
|
39665
39695
|
defaultGasLimit: options.defaultGasLimit,
|
|
39666
39696
|
defaultMemo: options.defaultMemo,
|
|
39667
39697
|
defaultConfirmationTimeoutMs: options.defaultConfirmationTimeoutMs,
|
|
39698
|
+
maxFeeAmount: options.maxFeeAmount,
|
|
39668
39699
|
cache: accountCache,
|
|
39669
39700
|
feeMarketCache
|
|
39670
39701
|
});
|
|
@@ -42940,12 +42971,14 @@ function createDexWs(url, options) {
|
|
|
42940
42971
|
COIN_TYPE,
|
|
42941
42972
|
DEC_PRECISION,
|
|
42942
42973
|
DEFAULT_CHAIN_ID,
|
|
42974
|
+
DEFAULT_MAX_FEE_AMOUNT,
|
|
42943
42975
|
DEFAULT_RETRYABLE_STATUSES,
|
|
42944
42976
|
DEFAULT_TOKEN_PAIRS_LIMIT,
|
|
42945
42977
|
DexWsClient,
|
|
42946
42978
|
EIP712_DOMAIN_TYPE,
|
|
42947
42979
|
EIP712_MSG_TYPES,
|
|
42948
42980
|
FEE_TYPE,
|
|
42981
|
+
FeeCapExceededError,
|
|
42949
42982
|
GAS_CONSTANTS,
|
|
42950
42983
|
GetAllTickersResponse,
|
|
42951
42984
|
GetBalanceQueryParams,
|