ault-sdk-ts 0.0.2-alpha.12 → 0.0.2-alpha.13
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/eip712/sign-and-broadcast.d.ts +9 -1
- package/dist/index.cjs +93 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +89 -5
- package/dist/index.js.map +1 -1
- package/dist/rest/feemarket.d.ts +58 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type AnyEip712Msg } from "./builder";
|
|
2
2
|
import { type NetworkConfig } from "../core/network";
|
|
3
3
|
import { type FetchFn, type FetchWithRetryOptions } from "../core/http";
|
|
4
|
+
import { type FeeMarketCache } from "../rest/feemarket";
|
|
4
5
|
import { type SignerInput } from "./signers";
|
|
5
6
|
export interface AccountInfo {
|
|
6
7
|
accountNumber: string;
|
|
@@ -47,8 +48,15 @@ export interface SignAndBroadcastParams {
|
|
|
47
48
|
fetchFn?: FetchFn;
|
|
48
49
|
fetchOptions?: import("../core/http").FetchWithRetryOptions;
|
|
49
50
|
cache?: AccountCache;
|
|
51
|
+
/**
|
|
52
|
+
* Optional cache for cosmos-evm feemarket params. When neither `feeAmount`
|
|
53
|
+
* nor `network.eip712FeeAmount` is set, the sign path queries the chain's
|
|
54
|
+
* feemarket params and computes a fee at `effectiveGasPrice * gas` plus a
|
|
55
|
+
* safety margin. Sharing one cache across calls avoids per-tx REST hits.
|
|
56
|
+
*/
|
|
57
|
+
feeMarketCache?: FeeMarketCache;
|
|
50
58
|
}
|
|
51
|
-
export declare function signAndBroadcastEip712({ network, signerAddress, signer, msgs, memo, gasLimit, feeDenom, feeAmount, confirmationTimeoutMs, fetchFn, fetchOptions, cache, }: SignAndBroadcastParams): Promise<{
|
|
59
|
+
export declare function signAndBroadcastEip712({ network, signerAddress, signer, msgs, memo, gasLimit, feeDenom, feeAmount, confirmationTimeoutMs, fetchFn, fetchOptions, cache, feeMarketCache, }: SignAndBroadcastParams): Promise<{
|
|
52
60
|
txHash: string;
|
|
53
61
|
code: number;
|
|
54
62
|
rawLog?: string;
|
package/dist/index.cjs
CHANGED
|
@@ -121,6 +121,7 @@ __export(index_exports, {
|
|
|
121
121
|
bytesToBase64: () => bytesToBase64,
|
|
122
122
|
computeFeeFreeGas: () => computeFeeFreeGas,
|
|
123
123
|
computeFeeFreeGasCompound: () => computeFeeFreeGasCompound,
|
|
124
|
+
computeRequiredFee: () => computeRequiredFee,
|
|
124
125
|
cosmosDecToDecimalString: () => cosmosDecToDecimalString,
|
|
125
126
|
cosmosDecToProtoInt: () => cosmosDecToProtoInt,
|
|
126
127
|
createAccountCache: () => createAccountCache,
|
|
@@ -136,6 +137,7 @@ __export(index_exports, {
|
|
|
136
137
|
createDexWs: () => createDexWs,
|
|
137
138
|
createEip1193Signer: () => createEip1193Signer,
|
|
138
139
|
createEthersSigner: () => createEthersSigner,
|
|
140
|
+
createFeeMarketCache: () => createFeeMarketCache,
|
|
139
141
|
createLicenseApi: () => createLicenseApi,
|
|
140
142
|
createMarketApi: () => createMarketApi,
|
|
141
143
|
createMinerApi: () => createMinerApi,
|
|
@@ -162,12 +164,14 @@ __export(index_exports, {
|
|
|
162
164
|
encodeTxRaw: () => encodeTxRaw,
|
|
163
165
|
evmToAult: () => evmToAult,
|
|
164
166
|
fetchAllPaginatedProto: () => fetchAllPaginatedProto,
|
|
167
|
+
fetchFeeMarketParams: () => fetchFeeMarketParams,
|
|
165
168
|
fetchJson: () => fetchJson,
|
|
166
169
|
fetchProtoJson: () => fetchProtoJson,
|
|
167
170
|
fetchWithRetry: () => fetchWithRetry,
|
|
168
171
|
getBalanceResponseFreeRegExpOne: () => getBalanceResponseFreeRegExpOne,
|
|
169
172
|
getBalanceResponseTotalRegExpOne: () => getBalanceResponseTotalRegExpOne,
|
|
170
173
|
getBalanceResponseUsedRegExpOne: () => getBalanceResponseUsedRegExpOne,
|
|
174
|
+
getCachedFeeMarketParams: () => getCachedFeeMarketParams,
|
|
171
175
|
getNetworkConfig: () => getNetworkConfig,
|
|
172
176
|
getOHLCVQueryLimitDefault: () => getOHLCVQueryLimitDefault,
|
|
173
177
|
getOHLCVQueryLimitMax: () => getOHLCVQueryLimitMax,
|
|
@@ -13788,6 +13792,67 @@ function buildEip712TypedData(context, msgs, evmChainId) {
|
|
|
13788
13792
|
};
|
|
13789
13793
|
}
|
|
13790
13794
|
|
|
13795
|
+
// src/rest/feemarket.ts
|
|
13796
|
+
async function fetchFeeMarketParams(network, fetchFn, fetchOptions) {
|
|
13797
|
+
const data = await fetchJson(
|
|
13798
|
+
`${network.restUrl}/cosmos/evm/feemarket/v1/params`,
|
|
13799
|
+
{},
|
|
13800
|
+
fetchOptions,
|
|
13801
|
+
fetchFn
|
|
13802
|
+
);
|
|
13803
|
+
const raw = data.params ?? {};
|
|
13804
|
+
return {
|
|
13805
|
+
noBaseFee: raw.noBaseFee ?? raw.no_base_fee ?? false,
|
|
13806
|
+
baseFee: raw.baseFee ?? raw.base_fee ?? "0",
|
|
13807
|
+
minGasPrice: raw.minGasPrice ?? raw.min_gas_price ?? "0"
|
|
13808
|
+
};
|
|
13809
|
+
}
|
|
13810
|
+
var ONE_E18 = 1000000000000000000n;
|
|
13811
|
+
function computeRequiredFee(params, gas, options) {
|
|
13812
|
+
const marginPercent = options?.marginPercent ?? 20;
|
|
13813
|
+
if (marginPercent < 0) {
|
|
13814
|
+
throw new Error(`marginPercent must be >= 0, got ${marginPercent}`);
|
|
13815
|
+
}
|
|
13816
|
+
const minGasPriceI = BigInt(cosmosDecToProtoInt(params.minGasPrice || "0"));
|
|
13817
|
+
const baseFeeI = params.noBaseFee ? 0n : BigInt(cosmosDecToProtoInt(params.baseFee || "0"));
|
|
13818
|
+
const effectiveI = baseFeeI > minGasPriceI ? baseFeeI : minGasPriceI;
|
|
13819
|
+
if (effectiveI <= 0n) return "0";
|
|
13820
|
+
const gasI = BigInt(gas);
|
|
13821
|
+
if (gasI <= 0n) return "0";
|
|
13822
|
+
const margin = BigInt(100 + marginPercent);
|
|
13823
|
+
const numerator = effectiveI * gasI * margin;
|
|
13824
|
+
const denominator = ONE_E18 * 100n;
|
|
13825
|
+
return ((numerator + denominator - 1n) / denominator).toString();
|
|
13826
|
+
}
|
|
13827
|
+
var DEFAULT_FEE_MARKET_TTL_MS = 3e3;
|
|
13828
|
+
function createFeeMarketCache(ttlMs = DEFAULT_FEE_MARKET_TTL_MS) {
|
|
13829
|
+
return { ttlMs, entries: /* @__PURE__ */ new Map() };
|
|
13830
|
+
}
|
|
13831
|
+
async function getCachedFeeMarketParams(cache, network, fetchFn, fetchOptions) {
|
|
13832
|
+
const key = network.chainId;
|
|
13833
|
+
const now = Date.now();
|
|
13834
|
+
if (cache) {
|
|
13835
|
+
const existing = cache.entries.get(key);
|
|
13836
|
+
if (existing && now - existing.fetchedAt < cache.ttlMs) {
|
|
13837
|
+
return existing.params;
|
|
13838
|
+
}
|
|
13839
|
+
}
|
|
13840
|
+
let params;
|
|
13841
|
+
try {
|
|
13842
|
+
params = await fetchFeeMarketParams(network, fetchFn, fetchOptions);
|
|
13843
|
+
} catch (error) {
|
|
13844
|
+
if (!isGatewayUnsupportedError(error)) throw error;
|
|
13845
|
+
params = null;
|
|
13846
|
+
}
|
|
13847
|
+
if (cache) {
|
|
13848
|
+
cache.entries.set(key, { params, fetchedAt: now });
|
|
13849
|
+
}
|
|
13850
|
+
return params;
|
|
13851
|
+
}
|
|
13852
|
+
function isGatewayUnsupportedError(error) {
|
|
13853
|
+
return error instanceof ApiError && (error.status === 404 || error.status === 501);
|
|
13854
|
+
}
|
|
13855
|
+
|
|
13791
13856
|
// src/eip712/signers.ts
|
|
13792
13857
|
var import_accounts = require("viem/accounts");
|
|
13793
13858
|
|
|
@@ -21084,6 +21149,18 @@ async function queryAccount(network, address, fetchFn, fetchOptions) {
|
|
|
21084
21149
|
const pubkey = base.pub_key?.key ?? null;
|
|
21085
21150
|
return { accountNumber, sequence, pubkeyBase64: pubkey };
|
|
21086
21151
|
}
|
|
21152
|
+
async function resolveDynamicFeeAmount(network, gas, feeMarketCache, fetchFn, fetchOptions) {
|
|
21153
|
+
const params = await getCachedFeeMarketParams(feeMarketCache, network, fetchFn, fetchOptions);
|
|
21154
|
+
if (!params) return GAS_CONSTANTS.EIP712_FEE_AMOUNT;
|
|
21155
|
+
let dynamicI;
|
|
21156
|
+
try {
|
|
21157
|
+
dynamicI = BigInt(computeRequiredFee(params, gas));
|
|
21158
|
+
} catch {
|
|
21159
|
+
return GAS_CONSTANTS.EIP712_FEE_AMOUNT;
|
|
21160
|
+
}
|
|
21161
|
+
const staticI = BigInt(GAS_CONSTANTS.EIP712_FEE_AMOUNT);
|
|
21162
|
+
return dynamicI > staticI ? dynamicI.toString() : GAS_CONSTANTS.EIP712_FEE_AMOUNT;
|
|
21163
|
+
}
|
|
21087
21164
|
async function recoverPubkeyFromTypedDataSignature(typedData, signature) {
|
|
21088
21165
|
const hash = (0, import_viem3.hashTypedData)({
|
|
21089
21166
|
domain: typedData.domain,
|
|
@@ -21210,7 +21287,8 @@ async function signAndBroadcastEip712({
|
|
|
21210
21287
|
confirmationTimeoutMs,
|
|
21211
21288
|
fetchFn,
|
|
21212
21289
|
fetchOptions,
|
|
21213
|
-
cache
|
|
21290
|
+
cache,
|
|
21291
|
+
feeMarketCache
|
|
21214
21292
|
}) {
|
|
21215
21293
|
const resolvedSigner = normalizeSigner(signer);
|
|
21216
21294
|
if (!resolvedSigner) {
|
|
@@ -21232,14 +21310,16 @@ async function signAndBroadcastEip712({
|
|
|
21232
21310
|
if (!sequence) {
|
|
21233
21311
|
throw new Error(`Unable to resolve account sequence for signer ${resolvedSignerAddress}.`);
|
|
21234
21312
|
}
|
|
21313
|
+
const resolvedGas = gasLimit ?? network.eip712GasLimit ?? GAS_CONSTANTS.EIP712_GAS_LIMIT;
|
|
21314
|
+
const resolvedFeeAmount = feeAmount ?? network.eip712FeeAmount ?? await resolveDynamicFeeAmount(network, resolvedGas, feeMarketCache, fetchFn, fetchOptions);
|
|
21235
21315
|
const context = {
|
|
21236
21316
|
chainId: network.chainId,
|
|
21237
21317
|
accountNumber,
|
|
21238
21318
|
sequence,
|
|
21239
21319
|
fee: {
|
|
21240
|
-
amount:
|
|
21320
|
+
amount: resolvedFeeAmount,
|
|
21241
21321
|
denom: feeDenom ?? network.eip712FeeDenom ?? GAS_CONSTANTS.DENOM,
|
|
21242
|
-
gas:
|
|
21322
|
+
gas: resolvedGas
|
|
21243
21323
|
},
|
|
21244
21324
|
memo
|
|
21245
21325
|
};
|
|
@@ -21337,6 +21417,7 @@ async function signAndBroadcastEip712({
|
|
|
21337
21417
|
function createAultClient(options) {
|
|
21338
21418
|
const context = createRestContext(options.network.restUrl, options.fetchFn, options.fetchOptions);
|
|
21339
21419
|
const eip712Caches = /* @__PURE__ */ new Map();
|
|
21420
|
+
const feeMarketCache = createFeeMarketCache();
|
|
21340
21421
|
const dexApiUrl = options.network.dexApiUrl ?? "";
|
|
21341
21422
|
const dexContext = createRestContext(dexApiUrl, options.fetchFn, options.fetchOptions);
|
|
21342
21423
|
const wsUrl = options.network.dexWsUrl ?? (dexApiUrl ? dexApiUrl.replace(/^http/, "ws").replace(/\/?$/, "/ws") : "");
|
|
@@ -21393,6 +21474,7 @@ function createAultClient(options) {
|
|
|
21393
21474
|
signer,
|
|
21394
21475
|
signerAddress,
|
|
21395
21476
|
cache,
|
|
21477
|
+
feeMarketCache,
|
|
21396
21478
|
confirmationTimeoutMs: params.confirmationTimeoutMs ?? options.defaultConfirmationTimeoutMs
|
|
21397
21479
|
});
|
|
21398
21480
|
},
|
|
@@ -22622,6 +22704,7 @@ function createTxExecutor(options) {
|
|
|
22622
22704
|
const defaultMemo = options.defaultMemo ?? "";
|
|
22623
22705
|
const defaultConfirmationTimeoutMs = options.defaultConfirmationTimeoutMs;
|
|
22624
22706
|
const cache = createAccountCache();
|
|
22707
|
+
const feeMarketCache = createFeeMarketCache();
|
|
22625
22708
|
const fetchOptions = {
|
|
22626
22709
|
timeout: TIMING_CONSTANTS.API_TIMEOUT_MS,
|
|
22627
22710
|
retries: 3,
|
|
@@ -22640,7 +22723,8 @@ function createTxExecutor(options) {
|
|
|
22640
22723
|
confirmationTimeoutMs: txOptions?.confirmationTimeoutMs ?? defaultConfirmationTimeoutMs,
|
|
22641
22724
|
fetchFn: options.fetchFn,
|
|
22642
22725
|
fetchOptions,
|
|
22643
|
-
cache
|
|
22726
|
+
cache,
|
|
22727
|
+
feeMarketCache
|
|
22644
22728
|
});
|
|
22645
22729
|
return {
|
|
22646
22730
|
txHash: result.txHash,
|
|
@@ -23605,7 +23689,7 @@ function createDexWs(url, options) {
|
|
|
23605
23689
|
}
|
|
23606
23690
|
|
|
23607
23691
|
// src/index.ts
|
|
23608
|
-
var SDK_VERSION = "0.0.2-alpha.
|
|
23692
|
+
var SDK_VERSION = "0.0.2-alpha.13";
|
|
23609
23693
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23610
23694
|
0 && (module.exports = {
|
|
23611
23695
|
AGENT_DEFAULTS,
|
|
@@ -23699,6 +23783,7 @@ var SDK_VERSION = "0.0.2-alpha.12";
|
|
|
23699
23783
|
bytesToBase64,
|
|
23700
23784
|
computeFeeFreeGas,
|
|
23701
23785
|
computeFeeFreeGasCompound,
|
|
23786
|
+
computeRequiredFee,
|
|
23702
23787
|
cosmosDecToDecimalString,
|
|
23703
23788
|
cosmosDecToProtoInt,
|
|
23704
23789
|
createAccountCache,
|
|
@@ -23714,6 +23799,7 @@ var SDK_VERSION = "0.0.2-alpha.12";
|
|
|
23714
23799
|
createDexWs,
|
|
23715
23800
|
createEip1193Signer,
|
|
23716
23801
|
createEthersSigner,
|
|
23802
|
+
createFeeMarketCache,
|
|
23717
23803
|
createLicenseApi,
|
|
23718
23804
|
createMarketApi,
|
|
23719
23805
|
createMinerApi,
|
|
@@ -23740,12 +23826,14 @@ var SDK_VERSION = "0.0.2-alpha.12";
|
|
|
23740
23826
|
encodeTxRaw,
|
|
23741
23827
|
evmToAult,
|
|
23742
23828
|
fetchAllPaginatedProto,
|
|
23829
|
+
fetchFeeMarketParams,
|
|
23743
23830
|
fetchJson,
|
|
23744
23831
|
fetchProtoJson,
|
|
23745
23832
|
fetchWithRetry,
|
|
23746
23833
|
getBalanceResponseFreeRegExpOne,
|
|
23747
23834
|
getBalanceResponseTotalRegExpOne,
|
|
23748
23835
|
getBalanceResponseUsedRegExpOne,
|
|
23836
|
+
getCachedFeeMarketParams,
|
|
23749
23837
|
getNetworkConfig,
|
|
23750
23838
|
getOHLCVQueryLimitDefault,
|
|
23751
23839
|
getOHLCVQueryLimitMax,
|