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/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/core/user-agent.ts
8
- var SDK_VERSION = "0.18.1";
8
+ var SDK_VERSION = "0.19.0";
9
9
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
10
10
  function isServerRuntime() {
11
11
  if (typeof document !== "undefined") return false;
@@ -163,6 +163,17 @@ var TxSimulationError = class extends Error {
163
163
  this.rawLog = params.rawLog;
164
164
  }
165
165
  };
166
+ var FeeCapExceededError = class extends Error {
167
+ constructor(params) {
168
+ super(
169
+ 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.`
170
+ );
171
+ this.name = "FeeCapExceededError";
172
+ this.feeAmount = params.feeAmount;
173
+ this.feeDenom = params.feeDenom;
174
+ this.maxFeeAmount = params.maxFeeAmount;
175
+ }
176
+ };
166
177
  var TxNotConfirmedError = class extends TxError {
167
178
  constructor(params) {
168
179
  super(
@@ -576,6 +587,7 @@ var GAS_CONSTANTS = {
576
587
  BEGIN_REDELEGATE: 4e5,
577
588
  WITHDRAW_DELEGATOR_REWARD: 22e4
578
589
  };
590
+ var DEFAULT_MAX_FEE_AMOUNT = "25000000000000000000";
579
591
  function computeSimulatedGas(gasUsed, multiplier = GAS_CONSTANTS.SIMULATED_GAS_MULTIPLIER) {
580
592
  if (!Number.isInteger(multiplier) || multiplier < 100) {
581
593
  throw new Error(`simulated gas multiplier must be an integer >= 100, got ${multiplier}`);
@@ -35059,6 +35071,14 @@ async function resolveDynamicFeeAmount(network, gas, feeMarketCache, fetchFn, fe
35059
35071
  const staticI = BigInt(staticFloor);
35060
35072
  return dynamicI > staticI ? dynamicI.toString() : staticFloor;
35061
35073
  }
35074
+ function assertFeeWithinCap(amount, denom, maxFeeAmount) {
35075
+ if (denom !== GAS_CONSTANTS.DENOM) {
35076
+ throw new FeeCapExceededError({ feeAmount: amount, feeDenom: denom });
35077
+ }
35078
+ if (BigInt(amount) > BigInt(maxFeeAmount)) {
35079
+ throw new FeeCapExceededError({ feeAmount: amount, feeDenom: denom, maxFeeAmount });
35080
+ }
35081
+ }
35062
35082
  async function recoverSignerPubkey(typedData, signature, signerAddress) {
35063
35083
  const signerEvmAddress = isValidEvmAddress(signerAddress) ? signerAddress : aultToEvm(signerAddress);
35064
35084
  let sigBytes;
@@ -35256,6 +35276,7 @@ async function signAndBroadcastEip712({
35256
35276
  gasLimit,
35257
35277
  feeDenom,
35258
35278
  feeAmount,
35279
+ maxFeeAmount = DEFAULT_MAX_FEE_AMOUNT,
35259
35280
  confirmationTimeoutMs,
35260
35281
  simulateGas = false,
35261
35282
  simulatedGasMultiplier,
@@ -35321,6 +35342,9 @@ async function signAndBroadcastEip712({
35321
35342
  }
35322
35343
  }
35323
35344
  resolvedFeeAmount = await feeFor(resolvedGas);
35345
+ if (feeAmount === void 0 && maxFeeAmount !== null) {
35346
+ assertFeeWithinCap(resolvedFeeAmount, resolvedFeeDenom, maxFeeAmount);
35347
+ }
35324
35348
  const context = {
35325
35349
  chainId: network.chainId,
35326
35350
  accountNumber,
@@ -35509,7 +35533,9 @@ function createAultClient(options) {
35509
35533
  signerAddress,
35510
35534
  cache,
35511
35535
  feeMarketCache,
35512
- confirmationTimeoutMs: params.confirmationTimeoutMs ?? options.defaultConfirmationTimeoutMs
35536
+ confirmationTimeoutMs: params.confirmationTimeoutMs ?? options.defaultConfirmationTimeoutMs,
35537
+ // `null` on the call turns the limit off, so only `undefined` falls back.
35538
+ maxFeeAmount: params.maxFeeAmount === void 0 ? options.maxFeeAmount : params.maxFeeAmount
35513
35539
  });
35514
35540
  },
35515
35541
  registry: EIP712_MSG_TYPES
@@ -37917,6 +37943,7 @@ function createTxExecutor(options) {
37917
37943
  gasLimit: txOptions?.gasLimit ?? defaultGasLimit,
37918
37944
  feeDenom: txOptions?.feeDenom,
37919
37945
  feeAmount: txOptions?.feeAmount,
37946
+ maxFeeAmount: options.maxFeeAmount,
37920
37947
  memo: txOptions?.memo ?? defaultMemo,
37921
37948
  confirmationTimeoutMs: txOptions?.confirmationTimeoutMs ?? defaultConfirmationTimeoutMs,
37922
37949
  simulateGas: txOptions?.simulateGas ?? false,
@@ -39019,6 +39046,7 @@ async function buildClient(options, resolver) {
39019
39046
  const lowLevel = createAultClient({
39020
39047
  network: getNetwork(),
39021
39048
  defaultConfirmationTimeoutMs: options.defaultConfirmationTimeoutMs,
39049
+ maxFeeAmount: options.maxFeeAmount,
39022
39050
  fetchFn: options.fetchFn,
39023
39051
  fetchOptions: options.fetchOptions
39024
39052
  });
@@ -39033,6 +39061,7 @@ async function buildClient(options, resolver) {
39033
39061
  defaultGasLimit: options.defaultGasLimit,
39034
39062
  defaultMemo: options.defaultMemo,
39035
39063
  defaultConfirmationTimeoutMs: options.defaultConfirmationTimeoutMs,
39064
+ maxFeeAmount: options.maxFeeAmount,
39036
39065
  cache: accountCache,
39037
39066
  feeMarketCache
39038
39067
  });
@@ -42307,12 +42336,14 @@ export {
42307
42336
  COIN_TYPE,
42308
42337
  DEC_PRECISION,
42309
42338
  DEFAULT_CHAIN_ID,
42339
+ DEFAULT_MAX_FEE_AMOUNT,
42310
42340
  DEFAULT_RETRYABLE_STATUSES,
42311
42341
  DEFAULT_TOKEN_PAIRS_LIMIT,
42312
42342
  DexWsClient,
42313
42343
  EIP712_DOMAIN_TYPE,
42314
42344
  EIP712_MSG_TYPES,
42315
42345
  FEE_TYPE,
42346
+ FeeCapExceededError,
42316
42347
  GAS_CONSTANTS,
42317
42348
  GetAllTickersResponse,
42318
42349
  GetBalanceQueryParams,