ault-sdk-ts 0.18.0 → 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 +50 -6
- package/dist/agent/attach.d.ts +3 -1
- package/dist/client.d.ts +5 -0
- package/dist/core/clob-msgs.d.ts +18 -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 +43 -10
- 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
|
```
|
|
@@ -554,8 +555,11 @@ await client.depositToVault({ vaultAddress, amount: usdc });
|
|
|
554
555
|
await client.redeemFromVault({ vaultAddress, shares: "1000000000000000000" });
|
|
555
556
|
```
|
|
556
557
|
|
|
557
|
-
A vault you own is created and reconfigured from the wallet
|
|
558
|
-
|
|
558
|
+
A vault you own is created and reconfigured from the wallet.
|
|
559
|
+
The chain doesn't take vault management from a trading key:
|
|
560
|
+
`createVault`, `updateVaultConfig`, `cancelVaultConfigUpdate` and
|
|
561
|
+
`setVaultStatus` on `client.asAgent` are rejected with "vault management is
|
|
562
|
+
not available on the agent route". A lending vault names its denom and a management fee; a trading vault
|
|
559
563
|
holds the chain's perpetual collateral denom, takes a performance and an exit
|
|
560
564
|
fee, and starts with your initial deposit:
|
|
561
565
|
|
|
@@ -609,9 +613,11 @@ of vault:
|
|
|
609
613
|
included.
|
|
610
614
|
- A normal lending vault can move supply between its pools with
|
|
611
615
|
`reallocateVault`.
|
|
612
|
-
- A parent vault can create child vaults, update or cancel their config
|
|
613
|
-
their status,
|
|
614
|
-
|
|
616
|
+
- A parent vault can create child vaults, update or cancel their config and
|
|
617
|
+
set their status, which need the manager's own key (the
|
|
618
|
+
chain rejects a registered agent's). It can also move capital to and from
|
|
619
|
+
them with `transferChildVault`, and hand a perpetual account that
|
|
620
|
+
liquidation cannot close (the derived account,
|
|
615
621
|
`perpAccountAddress(owner)`) to a child holding the `backstop` action with
|
|
616
622
|
`backstopTransfer`. It can't trade.
|
|
617
623
|
|
|
@@ -640,7 +646,9 @@ await child.placeLimitOrder({
|
|
|
640
646
|
```
|
|
641
647
|
|
|
642
648
|
Status changes and config updates come from the vault's owner, not its
|
|
643
|
-
manager
|
|
649
|
+
manager: an account that owns a normal vault signs them from the wallet, and
|
|
650
|
+
a parent vault sends them for its children from its manager surface. The
|
|
651
|
+
builders reject what x/vault would reject before anything is
|
|
644
652
|
signed: fees the vault kind doesn't take, an exit fee that doesn't match the
|
|
645
653
|
fund window, a fund window out of order, bad pool or queue lists, actions the
|
|
646
654
|
vault's relationship doesn't allow, spot markets quoted in different denoms,
|
|
@@ -1404,6 +1412,42 @@ ECDSA signatures. `error.signerAddress` is the account you asked to sign with
|
|
|
1404
1412
|
and `error.recoveredAddress` is the one the signature belongs to. Nothing was
|
|
1405
1413
|
sent, so there is no transaction to look up.
|
|
1406
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
|
+
|
|
1407
1451
|
## Advanced Usage
|
|
1408
1452
|
|
|
1409
1453
|
For advanced use cases, you can access the low-level client:
|
package/dist/agent/attach.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ export type BuildVaultManagerSurfaceContext = Omit<BuildAgentSurfaceContext, "ma
|
|
|
29
29
|
* Builds the surface a vault manager uses to act as the vault. Every message
|
|
30
30
|
* names the vault as its account; x/vault's account control accepts the
|
|
31
31
|
* manager's key (or the manager's registered agent) as the signer, and the
|
|
32
|
-
* agent ante signs with the vault's account number.
|
|
32
|
+
* agent ante signs with the vault's account number. Creating a child vault,
|
|
33
|
+
* changing or cancelling its config and setting its status are the exception:
|
|
34
|
+
* they need the manager's own key. The vault gets its own
|
|
33
35
|
* account cache: it is a different account from the client's master.
|
|
34
36
|
*/
|
|
35
37
|
export declare function buildVaultManagerSurface(options: AttachVaultManagerOptions, ctx: BuildVaultManagerSurfaceContext): VaultManagerSurface;
|
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/clob-msgs.d.ts
CHANGED
|
@@ -2,7 +2,18 @@ import { type MarginOrderOptions } from "./margin-msgs";
|
|
|
2
2
|
export declare function buildLimitOrderMsg(sender: string, params: {
|
|
3
3
|
marketId: Uint8Array;
|
|
4
4
|
isBuy: boolean;
|
|
5
|
+
/** A plain decimal of quote per base, such as `"0.0088"`. */
|
|
5
6
|
price: string;
|
|
7
|
+
/**
|
|
8
|
+
* An integer in base units, not tokens. Every bank denom has 18 decimals,
|
|
9
|
+
* so 1 token is `"1000000000000000000"`; `parseUnits("1", 18).toString()`
|
|
10
|
+
* from viem builds it. A token amount passed as it is (`"2000"`) means
|
|
11
|
+
* 2000 base units. The chain checks the order's quote notional, quantity
|
|
12
|
+
* times price, against the market's minimum, and at any realistic price
|
|
13
|
+
* that order falls far short. The minimum is `min_order_quote_amount` in
|
|
14
|
+
* the spot or perpetual params; read it from there, because governance
|
|
15
|
+
* can change it.
|
|
16
|
+
*/
|
|
6
17
|
quantity: string;
|
|
7
18
|
deadline: Date;
|
|
8
19
|
postOnly?: boolean;
|
|
@@ -34,6 +45,7 @@ export declare function buildLimitOrderMsg(sender: string, params: {
|
|
|
34
45
|
export declare function buildTwapOrderMsg(sender: string, params: {
|
|
35
46
|
marketId: Uint8Array;
|
|
36
47
|
isBuy: boolean;
|
|
48
|
+
/** An integer in base units (18 decimals), like a limit order's `quantity`. */
|
|
37
49
|
totalDeposit: string;
|
|
38
50
|
deadline: Date;
|
|
39
51
|
worstPrice?: string;
|
|
@@ -51,7 +63,12 @@ export declare function buildTwapOrderMsg(sender: string, params: {
|
|
|
51
63
|
export declare function buildMarketOrderMsg(sender: string, params: {
|
|
52
64
|
marketId: Uint8Array;
|
|
53
65
|
isBuy: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* An integer in base units (18 decimals), like a limit order's `quantity`:
|
|
68
|
+
* quote on a buy, base on a sell.
|
|
69
|
+
*/
|
|
54
70
|
deposit: string;
|
|
71
|
+
/** A plain decimal of quote per base. */
|
|
55
72
|
worstPrice?: string;
|
|
56
73
|
priceTolerance?: string;
|
|
57
74
|
builderAddress?: string;
|
|
@@ -91,6 +108,7 @@ export declare function buildScaleOrderMsg(sender: string, params: {
|
|
|
91
108
|
isBuy: boolean;
|
|
92
109
|
lowPrice: string;
|
|
93
110
|
highPrice: string;
|
|
111
|
+
/** An integer in base units (18 decimals), like a limit order's `quantity`. */
|
|
94
112
|
totalQuantity: string;
|
|
95
113
|
weights: number[];
|
|
96
114
|
deadline: Date;
|
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
|
|
@@ -321,7 +328,17 @@ export interface AccountxTxApi {
|
|
|
321
328
|
export type LimitOrderParams = {
|
|
322
329
|
marketId: Uint8Array;
|
|
323
330
|
isBuy: boolean;
|
|
331
|
+
/** A plain decimal of quote per base, such as `"0.0088"`. */
|
|
324
332
|
price: string;
|
|
333
|
+
/**
|
|
334
|
+
* An integer in base units, not tokens. Every bank denom has 18 decimals, so
|
|
335
|
+
* 1 token is `"1000000000000000000"`; `parseUnits("1", 18).toString()` from
|
|
336
|
+
* viem builds it. A token amount passed as it is (`"2000"`) means 2000 base
|
|
337
|
+
* units. The chain checks the order's quote notional, quantity times price,
|
|
338
|
+
* against the market's minimum, and at any realistic price that order falls
|
|
339
|
+
* far short. The minimum is `min_order_quote_amount` in the spot or
|
|
340
|
+
* perpetual params; read it from there, because governance can change it.
|
|
341
|
+
*/
|
|
325
342
|
quantity: string;
|
|
326
343
|
deadline: Date;
|
|
327
344
|
postOnly?: boolean;
|
|
@@ -362,6 +379,7 @@ export type LimitOrderParams = {
|
|
|
362
379
|
export type TwapOrderParams = {
|
|
363
380
|
marketId: Uint8Array;
|
|
364
381
|
isBuy: boolean;
|
|
382
|
+
/** An integer in base units (18 decimals), like a limit order's `quantity`. */
|
|
365
383
|
totalDeposit: string;
|
|
366
384
|
/** Absolute end of the execution window (not a duration). */
|
|
367
385
|
deadline: Date;
|
|
@@ -377,7 +395,12 @@ export type TwapOrderParams = {
|
|
|
377
395
|
export type MarketOrderParams = {
|
|
378
396
|
marketId: Uint8Array;
|
|
379
397
|
isBuy: boolean;
|
|
398
|
+
/**
|
|
399
|
+
* An integer in base units (18 decimals), like a limit order's `quantity`:
|
|
400
|
+
* quote on a buy, base on a sell.
|
|
401
|
+
*/
|
|
380
402
|
deposit: string;
|
|
403
|
+
/** A plain decimal of quote per base. */
|
|
381
404
|
worstPrice?: string;
|
|
382
405
|
priceTolerance?: string;
|
|
383
406
|
builderAddress?: string;
|
|
@@ -392,6 +415,7 @@ export type ScaleOrderParams = {
|
|
|
392
415
|
isBuy: boolean;
|
|
393
416
|
lowPrice: string;
|
|
394
417
|
highPrice: string;
|
|
418
|
+
/** An integer in base units (18 decimals), like a limit order's `quantity`. */
|
|
395
419
|
totalQuantity: string;
|
|
396
420
|
weights: number[];
|
|
397
421
|
deadline: Date;
|
|
@@ -580,9 +604,10 @@ export interface MarginTxApi {
|
|
|
580
604
|
} & TxOptions): Promise<TxResult>;
|
|
581
605
|
}
|
|
582
606
|
/**
|
|
583
|
-
* x/vault operations a wallet signs over EIP-712.
|
|
584
|
-
*
|
|
585
|
-
* `client.attachVaultManager` for
|
|
607
|
+
* x/vault operations a wallet signs over EIP-712. This
|
|
608
|
+
* is the only route for administering a vault you own: the chain rejects
|
|
609
|
+
* vault management from `client.asAgent`. `client.attachVaultManager` is for
|
|
610
|
+
* a vault account's own messages.
|
|
586
611
|
*/
|
|
587
612
|
export interface VaultTxApi {
|
|
588
613
|
/** Deposit into a vault; mints shares at the current share price. */
|
|
@@ -658,12 +683,17 @@ export interface CreateVaultParams {
|
|
|
658
683
|
relationship?: "normal" | "parent" | "child";
|
|
659
684
|
}
|
|
660
685
|
/**
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
686
|
+
* Vault administration over the agent route. These
|
|
687
|
+
* four only work on the manager surface of a parent vault
|
|
688
|
+
* (`attachVaultManager`), signed with the manager's own key: `createVault`
|
|
689
|
+
* makes a child and the rest act on its children. A registered agent of the
|
|
690
|
+
* manager is rejected with "vault management requires the manager's own
|
|
691
|
+
* signature".
|
|
692
|
+
*
|
|
693
|
+
* On `client.asAgent` the chain rejects them with "vault management is not
|
|
694
|
+
* available on the agent route". An ordinary account creates and administers
|
|
695
|
+
* its vaults from the wallet: `client.createVault`, `client.updateVaultConfig`,
|
|
696
|
+
* `client.cancelVaultConfigUpdate` and `client.setVaultStatus`.
|
|
667
697
|
*/
|
|
668
698
|
export interface AgentVaultTxApi {
|
|
669
699
|
createVault(params: CreateVaultParams & AgentTxOptions): Promise<TxResult>;
|
|
@@ -948,7 +978,10 @@ export interface AgentSurface extends AgentClobTxApi, AgentPerpetualTxApi, Agent
|
|
|
948
978
|
* Surface for acting as a vault account: every message is sent from the
|
|
949
979
|
* vault's own account and signed by the key that controls it (the manager of
|
|
950
980
|
* a normal or parent vault, the parent's manager for a child) or that key's
|
|
951
|
-
* registered agent.
|
|
981
|
+
* registered agent. The exception is a parent vault's administration of its
|
|
982
|
+
* children (`createVault`, `updateVaultConfig`, `cancelVaultConfigUpdate`,
|
|
983
|
+
* `setVaultStatus`): it needs the manager's own key.
|
|
984
|
+
* Build it with `client.attachVaultManager(...)`.
|
|
952
985
|
*
|
|
953
986
|
* x/vault accepts a different set per vault (v3.0.0-rc.4 account control):
|
|
954
987
|
* - normal trading vault, child vault: limit, market and scale orders,
|
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,
|