ault-sdk-ts 0.0.2-alpha.17 → 0.0.2-alpha.18

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.cjs CHANGED
@@ -130,6 +130,7 @@ __export(index_exports, {
130
130
  buildEip712TypedData: () => buildEip712TypedData,
131
131
  buildFetchOptions: () => buildFetchOptions,
132
132
  bytesToBase64: () => bytesToBase64,
133
+ computeEvmFeesPerGas: () => computeEvmFeesPerGas,
133
134
  computeFeeFreeGas: () => computeFeeFreeGas,
134
135
  computeFeeFreeGasCompound: () => computeFeeFreeGasCompound,
135
136
  computeRequiredFee: () => computeRequiredFee,
@@ -255,6 +256,7 @@ __export(index_exports, {
255
256
  pollTxInclusion: () => pollTxInclusion,
256
257
  postJson: () => postJson,
257
258
  queryAccount: () => queryAccount,
259
+ resolveEvmFeesPerGas: () => resolveEvmFeesPerGas,
258
260
  resolveSignerAddress: () => resolveSignerAddress,
259
261
  signAndBroadcastAgentTx: () => signAndBroadcastAgentTx,
260
262
  signAndBroadcastEip712: () => signAndBroadcastEip712,
@@ -14073,18 +14075,24 @@ async function fetchFeeMarketParams(network, fetchFn, fetchOptions) {
14073
14075
  };
14074
14076
  }
14075
14077
  var ONE_E18 = 1000000000000000000n;
14076
- function computeRequiredFee(params, gas, options) {
14077
- const marginPercent = options?.marginPercent ?? 20;
14078
+ var DEFAULT_FEE_MARGIN_PERCENT = 20;
14079
+ function marginFactorScaled(marginPercent) {
14080
+ if (!Number.isFinite(marginPercent) || !Number.isInteger(marginPercent)) {
14081
+ throw new Error(`marginPercent must be a non-negative integer, got ${marginPercent}`);
14082
+ }
14078
14083
  if (marginPercent < 0) {
14079
14084
  throw new Error(`marginPercent must be >= 0, got ${marginPercent}`);
14080
14085
  }
14086
+ return BigInt(100 + marginPercent);
14087
+ }
14088
+ function computeRequiredFee(params, gas, options) {
14089
+ const margin = marginFactorScaled(options?.marginPercent ?? DEFAULT_FEE_MARGIN_PERCENT);
14081
14090
  const minGasPriceI = BigInt(cosmosDecToProtoInt(params.minGasPrice || "0"));
14082
14091
  const baseFeeI = params.noBaseFee ? 0n : BigInt(cosmosDecToProtoInt(params.baseFee || "0"));
14083
14092
  const effectiveI = baseFeeI > minGasPriceI ? baseFeeI : minGasPriceI;
14084
14093
  if (effectiveI <= 0n) return "0";
14085
14094
  const gasI = BigInt(gas);
14086
14095
  if (gasI <= 0n) return "0";
14087
- const margin = BigInt(100 + marginPercent);
14088
14096
  const numerator = effectiveI * gasI * margin;
14089
14097
  const denominator = ONE_E18 * 100n;
14090
14098
  return ((numerator + denominator - 1n) / denominator).toString();
@@ -14117,6 +14125,36 @@ async function getCachedFeeMarketParams(cache, network, fetchFn, fetchOptions) {
14117
14125
  function isGatewayUnsupportedError(error) {
14118
14126
  return error instanceof ApiError && (error.status === 404 || error.status === 501);
14119
14127
  }
14128
+ function computeEvmFeesPerGas(params, options) {
14129
+ const margin = marginFactorScaled(options?.marginPercent ?? DEFAULT_FEE_MARGIN_PERCENT);
14130
+ const minGasPriceI = BigInt(cosmosDecToProtoInt(params.minGasPrice || "0"));
14131
+ const baseFeeI = params.noBaseFee ? 0n : BigInt(cosmosDecToProtoInt(params.baseFee || "0"));
14132
+ const effectiveI = baseFeeI > minGasPriceI ? baseFeeI : minGasPriceI;
14133
+ if (effectiveI <= 0n) {
14134
+ return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
14135
+ }
14136
+ const numerator = effectiveI * margin;
14137
+ const denominator = ONE_E18 * 100n;
14138
+ const gasPriceWei = (numerator + denominator - 1n) / denominator;
14139
+ return { maxFeePerGas: gasPriceWei, maxPriorityFeePerGas: gasPriceWei };
14140
+ }
14141
+ async function resolveEvmFeesPerGas(network, options) {
14142
+ const params = await getCachedFeeMarketParams(
14143
+ options?.cache,
14144
+ network,
14145
+ options?.fetchFn,
14146
+ options?.fetchOptions
14147
+ );
14148
+ if (!params) return null;
14149
+ let fees;
14150
+ try {
14151
+ fees = computeEvmFeesPerGas(params, { marginPercent: options?.marginPercent });
14152
+ } catch {
14153
+ return null;
14154
+ }
14155
+ if (fees.maxFeePerGas === 0n && fees.maxPriorityFeePerGas === 0n) return null;
14156
+ return fees;
14157
+ }
14120
14158
 
14121
14159
  // src/eip712/signers.ts
14122
14160
  var import_accounts = require("viem/accounts");
@@ -24325,7 +24363,7 @@ function createDexWs(url, options) {
24325
24363
  }
24326
24364
 
24327
24365
  // src/index.ts
24328
- var SDK_VERSION = "0.0.2-alpha.17";
24366
+ var SDK_VERSION = "0.0.2-alpha.18";
24329
24367
  // Annotate the CommonJS export names for ESM import in node:
24330
24368
  0 && (module.exports = {
24331
24369
  AGENT_DEFAULTS,
@@ -24428,6 +24466,7 @@ var SDK_VERSION = "0.0.2-alpha.17";
24428
24466
  buildEip712TypedData,
24429
24467
  buildFetchOptions,
24430
24468
  bytesToBase64,
24469
+ computeEvmFeesPerGas,
24431
24470
  computeFeeFreeGas,
24432
24471
  computeFeeFreeGasCompound,
24433
24472
  computeRequiredFee,
@@ -24553,6 +24592,7 @@ var SDK_VERSION = "0.0.2-alpha.17";
24553
24592
  pollTxInclusion,
24554
24593
  postJson,
24555
24594
  queryAccount,
24595
+ resolveEvmFeesPerGas,
24556
24596
  resolveSignerAddress,
24557
24597
  signAndBroadcastAgentTx,
24558
24598
  signAndBroadcastEip712,