ault-sdk-ts 0.16.1 → 0.17.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 +12 -3
- package/dist/agent/sign-and-broadcast.d.ts +1 -1
- package/dist/core/errors.d.ts +4 -3
- package/dist/eip712/sign-and-broadcast.d.ts +15 -0
- package/dist/index.cjs +51 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
8
|
+
var SDK_VERSION = "0.17.0";
|
|
9
9
|
var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
|
|
10
10
|
function isServerRuntime() {
|
|
11
11
|
if (typeof document !== "undefined") return false;
|
|
@@ -34307,7 +34307,7 @@ function createVaultApi(context) {
|
|
|
34307
34307
|
}
|
|
34308
34308
|
|
|
34309
34309
|
// src/eip712/sign-and-broadcast.ts
|
|
34310
|
-
import { hexToBytes, hashTypedData, recoverPublicKey } from "viem";
|
|
34310
|
+
import { hexToBytes, hashTypedData, recoverPublicKey, sha256 as sha2562 } from "viem";
|
|
34311
34311
|
|
|
34312
34312
|
// src/proto/tx-encode.ts
|
|
34313
34313
|
var WIRE_VARINT = 0;
|
|
@@ -34963,6 +34963,34 @@ function getConfirmationUnavailableLog(txHash, error) {
|
|
|
34963
34963
|
}
|
|
34964
34964
|
return `Transaction ${txHash} was broadcast but could not be confirmed.`;
|
|
34965
34965
|
}
|
|
34966
|
+
async function broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions) {
|
|
34967
|
+
const txHash = normalizeTxHash(sha2562(txRawBytes));
|
|
34968
|
+
try {
|
|
34969
|
+
const result = await postJson(
|
|
34970
|
+
`${network.restUrl}/cosmos/tx/v1beta1/txs`,
|
|
34971
|
+
{ tx_bytes: bytesToBase64(txRawBytes), mode: "BROADCAST_MODE_SYNC" },
|
|
34972
|
+
{ ...fetchOptions, retries: 0 },
|
|
34973
|
+
fetchFn
|
|
34974
|
+
);
|
|
34975
|
+
const response = result?.tx_response;
|
|
34976
|
+
const code = response?.code;
|
|
34977
|
+
const rawHash = response?.txhash;
|
|
34978
|
+
if (typeof code !== "number" || !Number.isSafeInteger(code) || code < 0 || typeof rawHash !== "string" || !rawHash) {
|
|
34979
|
+
throw new Error("Unrecognized broadcast response");
|
|
34980
|
+
}
|
|
34981
|
+
if (normalizeTxHash(rawHash) !== txHash) {
|
|
34982
|
+
throw new Error("Broadcast response is for a different transaction");
|
|
34983
|
+
}
|
|
34984
|
+
return { txHash, code, rawLog: response?.raw_log };
|
|
34985
|
+
} catch (error) {
|
|
34986
|
+
throw new TxConfirmationUnavailableError({
|
|
34987
|
+
txHash,
|
|
34988
|
+
code: -1,
|
|
34989
|
+
rawLog: error instanceof Error ? error.message : "Broadcast response unavailable",
|
|
34990
|
+
confirmed: void 0
|
|
34991
|
+
});
|
|
34992
|
+
}
|
|
34993
|
+
}
|
|
34966
34994
|
function _resetIndexingCache() {
|
|
34967
34995
|
}
|
|
34968
34996
|
async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs = TIMING_CONSTANTS.TX_POLL_TIMEOUT_MS, intervalMs = 1500) {
|
|
@@ -34979,7 +35007,8 @@ async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs
|
|
|
34979
35007
|
{ ...fetchOptions, retries: 0, timeout: perRequestTimeout },
|
|
34980
35008
|
fetchFn
|
|
34981
35009
|
);
|
|
34982
|
-
|
|
35010
|
+
const receipt = result?.tx_response;
|
|
35011
|
+
if (!receipt || !Number.isSafeInteger(receipt.code) || receipt.code < 0 || typeof receipt.txhash !== "string" || normalizeTxHash(receipt.txhash) !== normalizeTxHash(txHash) || typeof receipt.height !== "string" || !/^\d+$/.test(receipt.height) || BigInt(receipt.height) <= 0n) {
|
|
34983
35012
|
return {
|
|
34984
35013
|
code: -1,
|
|
34985
35014
|
rawLog: `Transaction ${txHash} was broadcast but the confirmation response was invalid.`,
|
|
@@ -34987,9 +35016,9 @@ async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs
|
|
|
34987
35016
|
};
|
|
34988
35017
|
}
|
|
34989
35018
|
return {
|
|
34990
|
-
code:
|
|
34991
|
-
rawLog:
|
|
34992
|
-
data:
|
|
35019
|
+
code: receipt.code,
|
|
35020
|
+
rawLog: receipt.raw_log,
|
|
35021
|
+
data: receipt.data,
|
|
34993
35022
|
confirmed: true
|
|
34994
35023
|
};
|
|
34995
35024
|
} catch (error) {
|
|
@@ -35147,26 +35176,20 @@ async function signAndBroadcastEip712({
|
|
|
35147
35176
|
authInfoBytes,
|
|
35148
35177
|
signatures: [sigWithoutRecovery]
|
|
35149
35178
|
});
|
|
35150
|
-
|
|
35151
|
-
let result;
|
|
35179
|
+
let checkTx;
|
|
35152
35180
|
try {
|
|
35153
|
-
|
|
35154
|
-
`${network.restUrl}/cosmos/tx/v1beta1/txs`,
|
|
35155
|
-
{ tx_bytes: txBytesBase64, mode: "BROADCAST_MODE_SYNC" },
|
|
35156
|
-
{ ...fetchOptions, retries: 0 },
|
|
35157
|
-
fetchFn
|
|
35158
|
-
);
|
|
35181
|
+
checkTx = await broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions);
|
|
35159
35182
|
} catch (error) {
|
|
35160
35183
|
clearCachedSequence(cache);
|
|
35161
35184
|
throw error;
|
|
35162
35185
|
}
|
|
35163
|
-
const txHash =
|
|
35164
|
-
if (
|
|
35186
|
+
const { txHash } = checkTx;
|
|
35187
|
+
if (checkTx.code !== 0) {
|
|
35165
35188
|
clearCachedSequence(cache);
|
|
35166
35189
|
throw new TxError({
|
|
35167
35190
|
txHash,
|
|
35168
|
-
code:
|
|
35169
|
-
rawLog:
|
|
35191
|
+
code: checkTx.code,
|
|
35192
|
+
rawLog: checkTx.rawLog,
|
|
35170
35193
|
confirmed: true
|
|
35171
35194
|
});
|
|
35172
35195
|
}
|
|
@@ -35175,7 +35198,7 @@ async function signAndBroadcastEip712({
|
|
|
35175
35198
|
return {
|
|
35176
35199
|
txHash,
|
|
35177
35200
|
code: 0,
|
|
35178
|
-
rawLog:
|
|
35201
|
+
rawLog: checkTx.rawLog,
|
|
35179
35202
|
confirmed: false
|
|
35180
35203
|
};
|
|
35181
35204
|
}
|
|
@@ -35197,7 +35220,7 @@ async function signAndBroadcastEip712({
|
|
|
35197
35220
|
throw new TxConfirmationUnavailableError({
|
|
35198
35221
|
txHash,
|
|
35199
35222
|
code: deliverResult.code,
|
|
35200
|
-
rawLog: deliverResult.rawLog ??
|
|
35223
|
+
rawLog: deliverResult.rawLog ?? checkTx.rawLog,
|
|
35201
35224
|
confirmed: void 0
|
|
35202
35225
|
});
|
|
35203
35226
|
}
|
|
@@ -38224,19 +38247,13 @@ async function signAndBroadcastAgentTx({
|
|
|
38224
38247
|
authInfoBytes,
|
|
38225
38248
|
signatures: [signatureBytes]
|
|
38226
38249
|
});
|
|
38227
|
-
const
|
|
38228
|
-
const
|
|
38229
|
-
|
|
38230
|
-
{ tx_bytes: txBytesBase64, mode: "BROADCAST_MODE_SYNC" },
|
|
38231
|
-
fetchOptions,
|
|
38232
|
-
fetchFn
|
|
38233
|
-
);
|
|
38234
|
-
const txHash = normalizeTxHash(result.tx_response.txhash);
|
|
38235
|
-
if (result.tx_response.code !== 0) {
|
|
38250
|
+
const checkTx = await broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions);
|
|
38251
|
+
const { txHash } = checkTx;
|
|
38252
|
+
if (checkTx.code !== 0) {
|
|
38236
38253
|
throw new TxError({
|
|
38237
38254
|
txHash,
|
|
38238
|
-
code:
|
|
38239
|
-
rawLog:
|
|
38255
|
+
code: checkTx.code,
|
|
38256
|
+
rawLog: checkTx.rawLog,
|
|
38240
38257
|
confirmed: true
|
|
38241
38258
|
});
|
|
38242
38259
|
}
|
|
@@ -38244,7 +38261,7 @@ async function signAndBroadcastAgentTx({
|
|
|
38244
38261
|
return {
|
|
38245
38262
|
txHash,
|
|
38246
38263
|
code: 0,
|
|
38247
|
-
rawLog:
|
|
38264
|
+
rawLog: checkTx.rawLog,
|
|
38248
38265
|
confirmed: false
|
|
38249
38266
|
};
|
|
38250
38267
|
}
|
|
@@ -38259,7 +38276,7 @@ async function signAndBroadcastAgentTx({
|
|
|
38259
38276
|
throw new TxConfirmationUnavailableError({
|
|
38260
38277
|
txHash,
|
|
38261
38278
|
code: deliverResult.code,
|
|
38262
|
-
rawLog: deliverResult.rawLog ??
|
|
38279
|
+
rawLog: deliverResult.rawLog ?? checkTx.rawLog,
|
|
38263
38280
|
confirmed: void 0
|
|
38264
38281
|
});
|
|
38265
38282
|
}
|
|
@@ -42324,6 +42341,7 @@ export {
|
|
|
42324
42341
|
aultToEvm,
|
|
42325
42342
|
averagePremium,
|
|
42326
42343
|
base64ToBytes,
|
|
42344
|
+
broadcastSignedTx,
|
|
42327
42345
|
buildBorrowMarginMsg,
|
|
42328
42346
|
buildConditionalOrderMsg,
|
|
42329
42347
|
buildDepositMarginMsg,
|