ault-sdk-ts 0.0.2-alpha.17 → 0.0.2-alpha.19
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/core/manifest-types.d.ts +8 -0
- package/dist/core/network.d.ts +4 -0
- package/dist/high-level/tx/staking.d.ts +1 -1
- package/dist/index.cjs +80 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +78 -11
- package/dist/index.js.map +1 -1
- package/dist/rest/feemarket.d.ts +56 -0
- package/package.json +1 -1
|
@@ -27,6 +27,10 @@ export declare const ManifestGasSchema: z.ZodObject<{
|
|
|
27
27
|
CANCEL_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
|
|
28
28
|
CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
|
|
29
29
|
OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
DELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
UNDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
WITHDRAW_DELEGATOR_REWARD: z.ZodOptional<z.ZodNumber>;
|
|
30
34
|
}, z.core.$strip>;
|
|
31
35
|
export declare const ManifestEip712Schema: z.ZodObject<{
|
|
32
36
|
feeDenom: z.ZodOptional<z.ZodString>;
|
|
@@ -74,6 +78,10 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
74
78
|
CANCEL_ORDER_BASE: z.ZodOptional<z.ZodNumber>;
|
|
75
79
|
CANCEL_ORDER_PER_ID: z.ZodOptional<z.ZodNumber>;
|
|
76
80
|
OPEN_ACCOUNT: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
DELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
UNDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
BEGIN_REDELEGATE: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
WITHDRAW_DELEGATOR_REWARD: z.ZodOptional<z.ZodNumber>;
|
|
77
85
|
}, z.core.$strip>>;
|
|
78
86
|
eip712: z.ZodOptional<z.ZodObject<{
|
|
79
87
|
feeDenom: z.ZodOptional<z.ZodString>;
|
package/dist/core/network.d.ts
CHANGED
|
@@ -57,6 +57,10 @@ export declare const GAS_CONSTANTS: {
|
|
|
57
57
|
readonly CANCEL_ORDER_BASE: 49000;
|
|
58
58
|
readonly CANCEL_ORDER_PER_ID: 22000;
|
|
59
59
|
readonly OPEN_ACCOUNT: 96000;
|
|
60
|
+
readonly DELEGATE: 220000;
|
|
61
|
+
readonly UNDELEGATE: 220000;
|
|
62
|
+
readonly BEGIN_REDELEGATE: 280000;
|
|
63
|
+
readonly WITHDRAW_DELEGATOR_REWARD: 220000;
|
|
60
64
|
};
|
|
61
65
|
/**
|
|
62
66
|
* Returns the per-tx gas allowance for a uniform-cost batch (in wire-format
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { StakingTxApi } from "../types";
|
|
2
2
|
import type { TxModuleContext } from "./context";
|
|
3
|
-
export declare function createStakingTxApi({ signerAddress, exec }: TxModuleContext): StakingTxApi;
|
|
3
|
+
export declare function createStakingTxApi({ signerAddress, exec, getGas }: TxModuleContext): StakingTxApi;
|
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,
|
|
@@ -701,7 +703,12 @@ var GAS_CONSTANTS = {
|
|
|
701
703
|
CANCEL_ORDER_BASE: 49e3,
|
|
702
704
|
CANCEL_ORDER_PER_ID: 22e3,
|
|
703
705
|
// Accountx module
|
|
704
|
-
OPEN_ACCOUNT: 96e3
|
|
706
|
+
OPEN_ACCOUNT: 96e3,
|
|
707
|
+
// Staking module (cosmos-sdk standard, NOT fee-free — user pays gas).
|
|
708
|
+
DELEGATE: 22e4,
|
|
709
|
+
UNDELEGATE: 22e4,
|
|
710
|
+
BEGIN_REDELEGATE: 28e4,
|
|
711
|
+
WITHDRAW_DELEGATOR_REWARD: 22e4
|
|
705
712
|
};
|
|
706
713
|
function computeFeeFreeGas(minGasPerOp, count, multiplier = GAS_CONSTANTS.FEE_FREE_GAS_MULTIPLIER) {
|
|
707
714
|
return (BigInt(minGasPerOp) * BigInt(count) * BigInt(multiplier) / 100n).toString();
|
|
@@ -14073,18 +14080,24 @@ async function fetchFeeMarketParams(network, fetchFn, fetchOptions) {
|
|
|
14073
14080
|
};
|
|
14074
14081
|
}
|
|
14075
14082
|
var ONE_E18 = 1000000000000000000n;
|
|
14076
|
-
|
|
14077
|
-
|
|
14083
|
+
var DEFAULT_FEE_MARGIN_PERCENT = 20;
|
|
14084
|
+
function marginFactorScaled(marginPercent) {
|
|
14085
|
+
if (!Number.isFinite(marginPercent) || !Number.isInteger(marginPercent)) {
|
|
14086
|
+
throw new Error(`marginPercent must be a non-negative integer, got ${marginPercent}`);
|
|
14087
|
+
}
|
|
14078
14088
|
if (marginPercent < 0) {
|
|
14079
14089
|
throw new Error(`marginPercent must be >= 0, got ${marginPercent}`);
|
|
14080
14090
|
}
|
|
14091
|
+
return BigInt(100 + marginPercent);
|
|
14092
|
+
}
|
|
14093
|
+
function computeRequiredFee(params, gas, options) {
|
|
14094
|
+
const margin = marginFactorScaled(options?.marginPercent ?? DEFAULT_FEE_MARGIN_PERCENT);
|
|
14081
14095
|
const minGasPriceI = BigInt(cosmosDecToProtoInt(params.minGasPrice || "0"));
|
|
14082
14096
|
const baseFeeI = params.noBaseFee ? 0n : BigInt(cosmosDecToProtoInt(params.baseFee || "0"));
|
|
14083
14097
|
const effectiveI = baseFeeI > minGasPriceI ? baseFeeI : minGasPriceI;
|
|
14084
14098
|
if (effectiveI <= 0n) return "0";
|
|
14085
14099
|
const gasI = BigInt(gas);
|
|
14086
14100
|
if (gasI <= 0n) return "0";
|
|
14087
|
-
const margin = BigInt(100 + marginPercent);
|
|
14088
14101
|
const numerator = effectiveI * gasI * margin;
|
|
14089
14102
|
const denominator = ONE_E18 * 100n;
|
|
14090
14103
|
return ((numerator + denominator - 1n) / denominator).toString();
|
|
@@ -14117,6 +14130,36 @@ async function getCachedFeeMarketParams(cache, network, fetchFn, fetchOptions) {
|
|
|
14117
14130
|
function isGatewayUnsupportedError(error) {
|
|
14118
14131
|
return error instanceof ApiError && (error.status === 404 || error.status === 501);
|
|
14119
14132
|
}
|
|
14133
|
+
function computeEvmFeesPerGas(params, options) {
|
|
14134
|
+
const margin = marginFactorScaled(options?.marginPercent ?? DEFAULT_FEE_MARGIN_PERCENT);
|
|
14135
|
+
const minGasPriceI = BigInt(cosmosDecToProtoInt(params.minGasPrice || "0"));
|
|
14136
|
+
const baseFeeI = params.noBaseFee ? 0n : BigInt(cosmosDecToProtoInt(params.baseFee || "0"));
|
|
14137
|
+
const effectiveI = baseFeeI > minGasPriceI ? baseFeeI : minGasPriceI;
|
|
14138
|
+
if (effectiveI <= 0n) {
|
|
14139
|
+
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
14140
|
+
}
|
|
14141
|
+
const numerator = effectiveI * margin;
|
|
14142
|
+
const denominator = ONE_E18 * 100n;
|
|
14143
|
+
const gasPriceWei = (numerator + denominator - 1n) / denominator;
|
|
14144
|
+
return { maxFeePerGas: gasPriceWei, maxPriorityFeePerGas: gasPriceWei };
|
|
14145
|
+
}
|
|
14146
|
+
async function resolveEvmFeesPerGas(network, options) {
|
|
14147
|
+
const params = await getCachedFeeMarketParams(
|
|
14148
|
+
options?.cache,
|
|
14149
|
+
network,
|
|
14150
|
+
options?.fetchFn,
|
|
14151
|
+
options?.fetchOptions
|
|
14152
|
+
);
|
|
14153
|
+
if (!params) return null;
|
|
14154
|
+
let fees;
|
|
14155
|
+
try {
|
|
14156
|
+
fees = computeEvmFeesPerGas(params, { marginPercent: options?.marginPercent });
|
|
14157
|
+
} catch {
|
|
14158
|
+
return null;
|
|
14159
|
+
}
|
|
14160
|
+
if (fees.maxFeePerGas === 0n && fees.maxPriorityFeePerGas === 0n) return null;
|
|
14161
|
+
return fees;
|
|
14162
|
+
}
|
|
14120
14163
|
|
|
14121
14164
|
// src/eip712/signers.ts
|
|
14122
14165
|
var import_accounts = require("viem/accounts");
|
|
@@ -22752,9 +22795,10 @@ function createRewardTxApi({ signerAddress, exec, getGas }) {
|
|
|
22752
22795
|
}
|
|
22753
22796
|
|
|
22754
22797
|
// src/high-level/tx/staking.ts
|
|
22755
|
-
function createStakingTxApi({ signerAddress, exec }) {
|
|
22798
|
+
function createStakingTxApi({ signerAddress, exec, getGas }) {
|
|
22756
22799
|
return {
|
|
22757
22800
|
async delegate({ validatorAddress, amount, gasLimit, feeAmount, memo, confirmationTimeoutMs }) {
|
|
22801
|
+
const gas = getGas();
|
|
22758
22802
|
return exec(
|
|
22759
22803
|
[
|
|
22760
22804
|
msg.staking.delegate({
|
|
@@ -22763,7 +22807,12 @@ function createStakingTxApi({ signerAddress, exec }) {
|
|
|
22763
22807
|
amount
|
|
22764
22808
|
})
|
|
22765
22809
|
],
|
|
22766
|
-
{
|
|
22810
|
+
{
|
|
22811
|
+
gasLimit: gasLimit ?? computeFeeFreeGas(gas.DELEGATE, 1, gas.FEE_FREE_GAS_MULTIPLIER),
|
|
22812
|
+
feeAmount,
|
|
22813
|
+
memo,
|
|
22814
|
+
confirmationTimeoutMs
|
|
22815
|
+
}
|
|
22767
22816
|
);
|
|
22768
22817
|
},
|
|
22769
22818
|
async undelegate({
|
|
@@ -22774,6 +22823,7 @@ function createStakingTxApi({ signerAddress, exec }) {
|
|
|
22774
22823
|
memo,
|
|
22775
22824
|
confirmationTimeoutMs
|
|
22776
22825
|
}) {
|
|
22826
|
+
const gas = getGas();
|
|
22777
22827
|
return exec(
|
|
22778
22828
|
[
|
|
22779
22829
|
msg.staking.undelegate({
|
|
@@ -22782,7 +22832,12 @@ function createStakingTxApi({ signerAddress, exec }) {
|
|
|
22782
22832
|
amount
|
|
22783
22833
|
})
|
|
22784
22834
|
],
|
|
22785
|
-
{
|
|
22835
|
+
{
|
|
22836
|
+
gasLimit: gasLimit ?? computeFeeFreeGas(gas.UNDELEGATE, 1, gas.FEE_FREE_GAS_MULTIPLIER),
|
|
22837
|
+
feeAmount,
|
|
22838
|
+
memo,
|
|
22839
|
+
confirmationTimeoutMs
|
|
22840
|
+
}
|
|
22786
22841
|
);
|
|
22787
22842
|
},
|
|
22788
22843
|
async redelegate({
|
|
@@ -22794,6 +22849,7 @@ function createStakingTxApi({ signerAddress, exec }) {
|
|
|
22794
22849
|
memo,
|
|
22795
22850
|
confirmationTimeoutMs
|
|
22796
22851
|
}) {
|
|
22852
|
+
const gas = getGas();
|
|
22797
22853
|
return exec(
|
|
22798
22854
|
[
|
|
22799
22855
|
msg.staking.beginRedelegate({
|
|
@@ -22803,7 +22859,12 @@ function createStakingTxApi({ signerAddress, exec }) {
|
|
|
22803
22859
|
amount
|
|
22804
22860
|
})
|
|
22805
22861
|
],
|
|
22806
|
-
{
|
|
22862
|
+
{
|
|
22863
|
+
gasLimit: gasLimit ?? computeFeeFreeGas(gas.BEGIN_REDELEGATE, 1, gas.FEE_FREE_GAS_MULTIPLIER),
|
|
22864
|
+
feeAmount,
|
|
22865
|
+
memo,
|
|
22866
|
+
confirmationTimeoutMs
|
|
22867
|
+
}
|
|
22807
22868
|
);
|
|
22808
22869
|
},
|
|
22809
22870
|
async withdrawRewards({
|
|
@@ -22817,6 +22878,8 @@ function createStakingTxApi({ signerAddress, exec }) {
|
|
|
22817
22878
|
throw new Error("validatorAddresses must include at least one validator address.");
|
|
22818
22879
|
}
|
|
22819
22880
|
const normalized = validatorAddresses.map(assertValidatorAddress);
|
|
22881
|
+
const gas = getGas();
|
|
22882
|
+
const resolvedGasLimit = gasLimit ?? computeFeeFreeGas(gas.WITHDRAW_DELEGATOR_REWARD, 1, gas.FEE_FREE_GAS_MULTIPLIER);
|
|
22820
22883
|
const results = [];
|
|
22821
22884
|
const partial = [];
|
|
22822
22885
|
for (let i = 0; i < normalized.length; i++) {
|
|
@@ -22829,7 +22892,7 @@ function createStakingTxApi({ signerAddress, exec }) {
|
|
|
22829
22892
|
validatorAddress
|
|
22830
22893
|
})
|
|
22831
22894
|
],
|
|
22832
|
-
{ gasLimit, feeAmount, memo, confirmationTimeoutMs }
|
|
22895
|
+
{ gasLimit: resolvedGasLimit, feeAmount, memo, confirmationTimeoutMs }
|
|
22833
22896
|
);
|
|
22834
22897
|
results.push(result);
|
|
22835
22898
|
partial.push({ txHash: result.txHash, validatorAddress });
|
|
@@ -22987,7 +23050,11 @@ var ManifestGasSchema = import_zod.z.object({
|
|
|
22987
23050
|
SCALE_ORDER_PER_SUB: import_zod.z.number().int().positive(),
|
|
22988
23051
|
CANCEL_ORDER_BASE: import_zod.z.number().int().positive(),
|
|
22989
23052
|
CANCEL_ORDER_PER_ID: import_zod.z.number().int().positive(),
|
|
22990
|
-
OPEN_ACCOUNT: import_zod.z.number().int().positive()
|
|
23053
|
+
OPEN_ACCOUNT: import_zod.z.number().int().positive(),
|
|
23054
|
+
DELEGATE: import_zod.z.number().int().positive(),
|
|
23055
|
+
UNDELEGATE: import_zod.z.number().int().positive(),
|
|
23056
|
+
BEGIN_REDELEGATE: import_zod.z.number().int().positive(),
|
|
23057
|
+
WITHDRAW_DELEGATOR_REWARD: import_zod.z.number().int().positive()
|
|
22991
23058
|
}).partial();
|
|
22992
23059
|
var positiveIntegerString = import_zod.z.string().regex(/^[1-9]\d*$/, "must be a positive integer string (chain-side BigInt, > 0)");
|
|
22993
23060
|
var nonNegativeIntegerString = import_zod.z.string().regex(/^\d+$/, "must be a non-negative integer string (chain-side BigInt)");
|
|
@@ -24325,7 +24392,7 @@ function createDexWs(url, options) {
|
|
|
24325
24392
|
}
|
|
24326
24393
|
|
|
24327
24394
|
// src/index.ts
|
|
24328
|
-
var SDK_VERSION = "0.0.2-alpha.
|
|
24395
|
+
var SDK_VERSION = "0.0.2-alpha.19";
|
|
24329
24396
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24330
24397
|
0 && (module.exports = {
|
|
24331
24398
|
AGENT_DEFAULTS,
|
|
@@ -24428,6 +24495,7 @@ var SDK_VERSION = "0.0.2-alpha.17";
|
|
|
24428
24495
|
buildEip712TypedData,
|
|
24429
24496
|
buildFetchOptions,
|
|
24430
24497
|
bytesToBase64,
|
|
24498
|
+
computeEvmFeesPerGas,
|
|
24431
24499
|
computeFeeFreeGas,
|
|
24432
24500
|
computeFeeFreeGasCompound,
|
|
24433
24501
|
computeRequiredFee,
|
|
@@ -24553,6 +24621,7 @@ var SDK_VERSION = "0.0.2-alpha.17";
|
|
|
24553
24621
|
pollTxInclusion,
|
|
24554
24622
|
postJson,
|
|
24555
24623
|
queryAccount,
|
|
24624
|
+
resolveEvmFeesPerGas,
|
|
24556
24625
|
resolveSignerAddress,
|
|
24557
24626
|
signAndBroadcastAgentTx,
|
|
24558
24627
|
signAndBroadcastEip712,
|