ault-sdk-ts 0.16.1 → 0.17.1
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 +20 -3
- package/dist/agent/sign-and-broadcast.d.ts +1 -1
- package/dist/core/errors.d.ts +21 -3
- package/dist/eip712/sign-and-broadcast.d.ts +15 -0
- package/dist/index.cjs +130 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +129 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1018,7 +1018,7 @@ interface TxResult {
|
|
|
1018
1018
|
txHash: string; // Transaction hash
|
|
1019
1019
|
code: number; // Result code (0 = success)
|
|
1020
1020
|
rawLog?: string; // Raw log from transaction
|
|
1021
|
-
confirmed?: boolean; // true = DeliverTx observed; false = broadcast-only or poll timeout; undefined =
|
|
1021
|
+
confirmed?: boolean; // true = DeliverTx observed; false = broadcast-only or poll timeout; undefined = outcome unknown
|
|
1022
1022
|
success: boolean; // True only when DeliverTx success was confirmed
|
|
1023
1023
|
}
|
|
1024
1024
|
```
|
|
@@ -1355,7 +1355,7 @@ Note: `pnpm gen:eip712` also reads Cosmos SDK protos (staking/distribution) and
|
|
|
1355
1355
|
## Error Handling
|
|
1356
1356
|
|
|
1357
1357
|
```typescript
|
|
1358
|
-
import { ApiError, NetworkError, TimeoutError } from "ault-sdk-ts";
|
|
1358
|
+
import { ApiError, NetworkError, TimeoutError, TxConfirmationUnavailableError } from "ault-sdk-ts";
|
|
1359
1359
|
|
|
1360
1360
|
try {
|
|
1361
1361
|
const result = await client.transferLicense({ licenseId: 1, to: "0x..." });
|
|
@@ -1371,7 +1371,9 @@ try {
|
|
|
1371
1371
|
console.error(`Transaction failed: ${result.rawLog}`);
|
|
1372
1372
|
}
|
|
1373
1373
|
} catch (error) {
|
|
1374
|
-
if (error instanceof
|
|
1374
|
+
if (error instanceof TxConfirmationUnavailableError) {
|
|
1375
|
+
console.warn(`Outcome unknown, look the transaction up first: ${error.txHash}`);
|
|
1376
|
+
} else if (error instanceof ApiError) {
|
|
1375
1377
|
console.error(`API Error (${error.status}): ${error.message}`);
|
|
1376
1378
|
} else if (error instanceof NetworkError) {
|
|
1377
1379
|
console.error(`Network Error: ${error.message}`);
|
|
@@ -1381,6 +1383,21 @@ try {
|
|
|
1381
1383
|
}
|
|
1382
1384
|
```
|
|
1383
1385
|
|
|
1386
|
+
A send can also end with the outcome unknown. If the broadcast response is lost
|
|
1387
|
+
or unreadable, or the node cannot answer the confirmation lookup, the SDK
|
|
1388
|
+
throws `TxConfirmationUnavailableError`. The chain may have accepted the
|
|
1389
|
+
transaction, so look it up by `error.txHash` before you sign and send it again.
|
|
1390
|
+
A `TxNotConfirmedError` means the broadcast was accepted but the transaction
|
|
1391
|
+
did not show up in a block before the timeout.
|
|
1392
|
+
|
|
1393
|
+
A wallet send can fail before anything is broadcast with `SignerMismatchError`.
|
|
1394
|
+
The SDK checks that the signature the wallet returned was made by the signer's
|
|
1395
|
+
own key. It was not if the wallet signed with another account, hashes EIP-712
|
|
1396
|
+
typed data in a non-standard way, or is a contract wallet that does not produce
|
|
1397
|
+
ECDSA signatures. `error.signerAddress` is the account you asked to sign with
|
|
1398
|
+
and `error.recoveredAddress` is the one the signature belongs to. Nothing was
|
|
1399
|
+
sent, so there is no transaction to look up.
|
|
1400
|
+
|
|
1384
1401
|
## Advanced Usage
|
|
1385
1402
|
|
|
1386
1403
|
For advanced use cases, you can access the low-level client:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AccountCache } from "../eip712/sign-and-broadcast";
|
|
2
2
|
import type { AnyEip712Msg } from "../eip712/builder";
|
|
3
|
-
import {
|
|
3
|
+
import type { FetchFn, FetchWithRetryOptions } from "../core/http";
|
|
4
4
|
import type { NetworkConfig } from "../core/network";
|
|
5
5
|
export declare const AGENT_DEFAULTS: {
|
|
6
6
|
readonly GAS_LIMIT: "186000";
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface TxErrorParams {
|
|
|
22
22
|
/**
|
|
23
23
|
* - `true` -- chain returned a definitive non-zero code (CheckTx or DeliverTx).
|
|
24
24
|
* - `false` -- broadcast accepted but inclusion never observed within the timeout.
|
|
25
|
-
* - `undefined` -- broadcast
|
|
25
|
+
* - `undefined` -- broadcast or confirmation response unavailable; acceptance is unknown.
|
|
26
26
|
*/
|
|
27
27
|
confirmed: boolean | undefined;
|
|
28
28
|
}
|
|
@@ -60,14 +60,32 @@ export declare class TxNotConfirmedError extends TxError {
|
|
|
60
60
|
constructor(params: TxErrorParams);
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Thrown when
|
|
64
|
-
*
|
|
63
|
+
* Thrown when the signed broadcast response or the confirmation lookup was
|
|
64
|
+
* unavailable or returned an unrecognized payload. The tx may or may not have
|
|
65
|
+
* been accepted; `txHash` is always set so it can be looked up. Distinct from
|
|
65
66
|
* `TxNotConfirmedError` so callers can distinguish "still pending" from
|
|
66
67
|
* "we cannot tell at all".
|
|
67
68
|
*/
|
|
68
69
|
export declare class TxConfirmationUnavailableError extends TxError {
|
|
69
70
|
constructor(params: TxErrorParams);
|
|
70
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Thrown before anything is broadcast when the wallet's signature was not made
|
|
74
|
+
* by the signer's key: it signed with another account, hashed the EIP-712
|
|
75
|
+
* payload its own way, or is not an ECDSA wallet at all (a contract wallet).
|
|
76
|
+
* `recoveredAddress` is the address the signature does recover to, when one
|
|
77
|
+
* could be recovered. Nothing was sent, so the sequence is untouched.
|
|
78
|
+
*/
|
|
79
|
+
export declare class SignerMismatchError extends Error {
|
|
80
|
+
/** The signer's address, in 0x form. */
|
|
81
|
+
signerAddress: string;
|
|
82
|
+
recoveredAddress?: string;
|
|
83
|
+
constructor(params: {
|
|
84
|
+
signerAddress: string;
|
|
85
|
+
recoveredAddress?: string;
|
|
86
|
+
message?: string;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
71
89
|
/**
|
|
72
90
|
* Thrown in wait mode when the tx committed successfully (DeliverTx code 0) but
|
|
73
91
|
* the expected per-message response was missing from `tx_response.data` — e.g. a
|
|
@@ -15,6 +15,21 @@ export interface AccountCache {
|
|
|
15
15
|
nextSequence: string | null;
|
|
16
16
|
}
|
|
17
17
|
export declare function createAccountCache(): AccountCache;
|
|
18
|
+
/**
|
|
19
|
+
* Posts signed tx bytes and returns the CheckTx result.
|
|
20
|
+
*
|
|
21
|
+
* The request is never retried: once the bytes are signed, a lost or
|
|
22
|
+
* unreadable response does not mean the chain rejected them. Any failure to
|
|
23
|
+
* get a recognizable response throws `TxConfirmationUnavailableError` carrying
|
|
24
|
+
* the hash computed from the signed bytes, so the caller can look the tx up.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function broadcastSignedTx(network: NetworkConfig, txRawBytes: Uint8Array, fetchFn?: FetchFn, fetchOptions?: FetchWithRetryOptions): Promise<{
|
|
29
|
+
txHash: string;
|
|
30
|
+
code: number;
|
|
31
|
+
rawLog?: string;
|
|
32
|
+
}>;
|
|
18
33
|
/** @internal Retained for compatibility; polling is now stateless. */
|
|
19
34
|
export declare function _resetIndexingCache(): void;
|
|
20
35
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -261,6 +261,7 @@ __export(index_exports, {
|
|
|
261
261
|
SearchUDFSymbolsQueryParams: () => SearchUDFSymbolsQueryParams,
|
|
262
262
|
SearchUDFSymbolsResponse: () => SearchUDFSymbolsResponse,
|
|
263
263
|
SearchUDFSymbolsResponseItem: () => SearchUDFSymbolsResponseItem,
|
|
264
|
+
SignerMismatchError: () => SignerMismatchError,
|
|
264
265
|
TIMING_CONSTANTS: () => TIMING_CONSTANTS,
|
|
265
266
|
TX_BASE_FIELDS: () => TX_BASE_FIELDS,
|
|
266
267
|
TimeoutError: () => TimeoutError,
|
|
@@ -281,6 +282,7 @@ __export(index_exports, {
|
|
|
281
282
|
aultToEvm: () => aultToEvm,
|
|
282
283
|
averagePremium: () => averagePremium,
|
|
283
284
|
base64ToBytes: () => base64ToBytes,
|
|
285
|
+
broadcastSignedTx: () => broadcastSignedTx,
|
|
284
286
|
buildBorrowMarginMsg: () => buildBorrowMarginMsg,
|
|
285
287
|
buildConditionalOrderMsg: () => buildConditionalOrderMsg,
|
|
286
288
|
buildDepositMarginMsg: () => buildDepositMarginMsg,
|
|
@@ -635,7 +637,7 @@ __export(index_exports, {
|
|
|
635
637
|
module.exports = __toCommonJS(index_exports);
|
|
636
638
|
|
|
637
639
|
// src/core/user-agent.ts
|
|
638
|
-
var SDK_VERSION = "0.
|
|
640
|
+
var SDK_VERSION = "0.17.1";
|
|
639
641
|
var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
|
|
640
642
|
function isServerRuntime() {
|
|
641
643
|
if (typeof document !== "undefined") return false;
|
|
@@ -811,6 +813,16 @@ var TxConfirmationUnavailableError = class extends TxError {
|
|
|
811
813
|
this.name = "TxConfirmationUnavailableError";
|
|
812
814
|
}
|
|
813
815
|
};
|
|
816
|
+
var SignerMismatchError = class extends Error {
|
|
817
|
+
constructor(params) {
|
|
818
|
+
super(
|
|
819
|
+
params.message ?? `The wallet's signature does not match ${params.signerAddress}` + (params.recoveredAddress ? `: it recovers to ${params.recoveredAddress}.` : ".") + " The wallet signed with another account or hashed the EIP-712 payload differently."
|
|
820
|
+
);
|
|
821
|
+
this.name = "SignerMismatchError";
|
|
822
|
+
this.signerAddress = params.signerAddress;
|
|
823
|
+
this.recoveredAddress = params.recoveredAddress;
|
|
824
|
+
}
|
|
825
|
+
};
|
|
814
826
|
var MissingMsgResponseError = class extends Error {
|
|
815
827
|
constructor(typeUrl, txHash) {
|
|
816
828
|
super(
|
|
@@ -34938,6 +34950,8 @@ function createVaultApi(context) {
|
|
|
34938
34950
|
|
|
34939
34951
|
// src/eip712/sign-and-broadcast.ts
|
|
34940
34952
|
var import_viem5 = require("viem");
|
|
34953
|
+
var import_accounts2 = require("viem/accounts");
|
|
34954
|
+
var import_secp256k1 = require("@noble/curves/secp256k1");
|
|
34941
34955
|
|
|
34942
34956
|
// src/proto/tx-encode.ts
|
|
34943
34957
|
var WIRE_VARINT = 0;
|
|
@@ -35540,22 +35554,63 @@ async function resolveDynamicFeeAmount(network, gas, feeMarketCache, fetchFn, fe
|
|
|
35540
35554
|
const staticI = BigInt(staticFloor);
|
|
35541
35555
|
return dynamicI > staticI ? dynamicI.toString() : staticFloor;
|
|
35542
35556
|
}
|
|
35543
|
-
async function
|
|
35557
|
+
async function recoverSignerPubkey(typedData, signature, signerAddress) {
|
|
35558
|
+
const signerEvmAddress = isValidEvmAddress(signerAddress) ? signerAddress : aultToEvm(signerAddress);
|
|
35559
|
+
let sigBytes;
|
|
35560
|
+
try {
|
|
35561
|
+
sigBytes = (0, import_viem5.hexToBytes)(signature);
|
|
35562
|
+
} catch {
|
|
35563
|
+
sigBytes = new Uint8Array();
|
|
35564
|
+
}
|
|
35565
|
+
if (sigBytes.length !== 64 && sigBytes.length !== 65) {
|
|
35566
|
+
throw new SignerMismatchError({
|
|
35567
|
+
signerAddress: signerEvmAddress,
|
|
35568
|
+
message: `The wallet returned a ${sigBytes.length}-byte signature for ${signerEvmAddress}; expected 64 or 65 bytes.`
|
|
35569
|
+
});
|
|
35570
|
+
}
|
|
35544
35571
|
const hash = (0, import_viem5.hashTypedData)({
|
|
35545
35572
|
domain: typedData.domain,
|
|
35546
35573
|
types: typedData.types,
|
|
35547
35574
|
primaryType: typedData.primaryType,
|
|
35548
35575
|
message: typedData.message
|
|
35549
35576
|
});
|
|
35550
|
-
const
|
|
35551
|
-
|
|
35552
|
-
|
|
35553
|
-
|
|
35554
|
-
|
|
35555
|
-
|
|
35556
|
-
|
|
35557
|
-
|
|
35558
|
-
|
|
35577
|
+
const rs = sigBytes.slice(0, 64);
|
|
35578
|
+
let v = sigBytes[64];
|
|
35579
|
+
if (v === void 0 && rs[32] & 128) {
|
|
35580
|
+
rs[32] &= 127;
|
|
35581
|
+
v = 1;
|
|
35582
|
+
}
|
|
35583
|
+
const r = (0, import_viem5.bytesToHex)(rs.slice(0, 32));
|
|
35584
|
+
const s = (0, import_viem5.bytesToHex)(rs.slice(32));
|
|
35585
|
+
const parities = v === 1 || v === 28 ? [1, 0] : [0, 1];
|
|
35586
|
+
let recoveredAddress;
|
|
35587
|
+
for (const yParity of parities) {
|
|
35588
|
+
let publicKey;
|
|
35589
|
+
try {
|
|
35590
|
+
publicKey = await (0, import_viem5.recoverPublicKey)({ hash, signature: { r, s, yParity } });
|
|
35591
|
+
} catch {
|
|
35592
|
+
continue;
|
|
35593
|
+
}
|
|
35594
|
+
const address = (0, import_accounts2.publicKeyToAddress)(publicKey);
|
|
35595
|
+
recoveredAddress ?? (recoveredAddress = address);
|
|
35596
|
+
if (!addressEquals(address, signerEvmAddress)) continue;
|
|
35597
|
+
const uncompressed = (0, import_viem5.hexToBytes)(publicKey);
|
|
35598
|
+
const compressed = new Uint8Array(33);
|
|
35599
|
+
compressed[0] = uncompressed[64] % 2 === 0 ? 2 : 3;
|
|
35600
|
+
compressed.set(uncompressed.slice(1, 33), 1);
|
|
35601
|
+
return { pubkeyBase64: bytesToBase64(compressed), signature: rs };
|
|
35602
|
+
}
|
|
35603
|
+
throw new SignerMismatchError({ signerAddress: signerEvmAddress, recoveredAddress });
|
|
35604
|
+
}
|
|
35605
|
+
function pubkeyBelongsToSigner(pubkeyBase64, signerAddress) {
|
|
35606
|
+
try {
|
|
35607
|
+
const uncompressed = import_secp256k1.secp256k1.ProjectivePoint.fromHex(base64ToBytes(pubkeyBase64)).toRawBytes(
|
|
35608
|
+
false
|
|
35609
|
+
);
|
|
35610
|
+
return addressEquals((0, import_accounts2.publicKeyToAddress)((0, import_viem5.bytesToHex)(uncompressed)), signerAddress);
|
|
35611
|
+
} catch {
|
|
35612
|
+
return false;
|
|
35613
|
+
}
|
|
35559
35614
|
}
|
|
35560
35615
|
function createAccountCache() {
|
|
35561
35616
|
return { accountNumber: null, pubkeyBase64: null, nextSequence: null };
|
|
@@ -35593,6 +35648,34 @@ function getConfirmationUnavailableLog(txHash, error) {
|
|
|
35593
35648
|
}
|
|
35594
35649
|
return `Transaction ${txHash} was broadcast but could not be confirmed.`;
|
|
35595
35650
|
}
|
|
35651
|
+
async function broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions) {
|
|
35652
|
+
const txHash = normalizeTxHash((0, import_viem5.sha256)(txRawBytes));
|
|
35653
|
+
try {
|
|
35654
|
+
const result = await postJson(
|
|
35655
|
+
`${network.restUrl}/cosmos/tx/v1beta1/txs`,
|
|
35656
|
+
{ tx_bytes: bytesToBase64(txRawBytes), mode: "BROADCAST_MODE_SYNC" },
|
|
35657
|
+
{ ...fetchOptions, retries: 0 },
|
|
35658
|
+
fetchFn
|
|
35659
|
+
);
|
|
35660
|
+
const response = result?.tx_response;
|
|
35661
|
+
const code = response?.code;
|
|
35662
|
+
const rawHash = response?.txhash;
|
|
35663
|
+
if (typeof code !== "number" || !Number.isSafeInteger(code) || code < 0 || typeof rawHash !== "string" || !rawHash) {
|
|
35664
|
+
throw new Error("Unrecognized broadcast response");
|
|
35665
|
+
}
|
|
35666
|
+
if (normalizeTxHash(rawHash) !== txHash) {
|
|
35667
|
+
throw new Error("Broadcast response is for a different transaction");
|
|
35668
|
+
}
|
|
35669
|
+
return { txHash, code, rawLog: response?.raw_log };
|
|
35670
|
+
} catch (error) {
|
|
35671
|
+
throw new TxConfirmationUnavailableError({
|
|
35672
|
+
txHash,
|
|
35673
|
+
code: -1,
|
|
35674
|
+
rawLog: error instanceof Error ? error.message : "Broadcast response unavailable",
|
|
35675
|
+
confirmed: void 0
|
|
35676
|
+
});
|
|
35677
|
+
}
|
|
35678
|
+
}
|
|
35596
35679
|
function _resetIndexingCache() {
|
|
35597
35680
|
}
|
|
35598
35681
|
async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs = TIMING_CONSTANTS.TX_POLL_TIMEOUT_MS, intervalMs = 1500) {
|
|
@@ -35609,7 +35692,8 @@ async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs
|
|
|
35609
35692
|
{ ...fetchOptions, retries: 0, timeout: perRequestTimeout },
|
|
35610
35693
|
fetchFn
|
|
35611
35694
|
);
|
|
35612
|
-
|
|
35695
|
+
const receipt = result?.tx_response;
|
|
35696
|
+
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) {
|
|
35613
35697
|
return {
|
|
35614
35698
|
code: -1,
|
|
35615
35699
|
rawLog: `Transaction ${txHash} was broadcast but the confirmation response was invalid.`,
|
|
@@ -35617,9 +35701,9 @@ async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs
|
|
|
35617
35701
|
};
|
|
35618
35702
|
}
|
|
35619
35703
|
return {
|
|
35620
|
-
code:
|
|
35621
|
-
rawLog:
|
|
35622
|
-
data:
|
|
35704
|
+
code: receipt.code,
|
|
35705
|
+
rawLog: receipt.raw_log,
|
|
35706
|
+
data: receipt.data,
|
|
35623
35707
|
confirmed: true
|
|
35624
35708
|
};
|
|
35625
35709
|
} catch (error) {
|
|
@@ -35681,6 +35765,9 @@ async function signAndBroadcastEip712({
|
|
|
35681
35765
|
throw new Error("signer is required to sign EIP-712 typed data.");
|
|
35682
35766
|
}
|
|
35683
35767
|
const resolvedSignerAddress = signerAddress ? isValidEvmAddress(signerAddress) ? evmToAult(signerAddress) : signerAddress : await resolveSignerAddress(resolvedSigner);
|
|
35768
|
+
if (cache?.pubkeyBase64 && !pubkeyBelongsToSigner(cache.pubkeyBase64, resolvedSignerAddress)) {
|
|
35769
|
+
cache.pubkeyBase64 = null;
|
|
35770
|
+
}
|
|
35684
35771
|
const cacheIsWarm = cache?.accountNumber != null && cache.nextSequence != null;
|
|
35685
35772
|
const accountInfo = cacheIsWarm ? null : await queryAccount(network, resolvedSignerAddress, fetchFn, fetchOptions);
|
|
35686
35773
|
if (cache && accountInfo) {
|
|
@@ -35742,13 +35829,12 @@ async function signAndBroadcastEip712({
|
|
|
35742
35829
|
};
|
|
35743
35830
|
const typedData = buildEip712TypedData(context, msgs, network.evmChainId);
|
|
35744
35831
|
const signature = normalizeSignature(await resolvedSigner.signTypedData(typedData));
|
|
35745
|
-
|
|
35746
|
-
|
|
35747
|
-
|
|
35748
|
-
|
|
35749
|
-
|
|
35750
|
-
|
|
35751
|
-
const sigWithoutRecovery = sigBytes.slice(0, 64);
|
|
35832
|
+
const { pubkeyBase64: pubkey, signature: sigWithoutRecovery } = await recoverSignerPubkey(
|
|
35833
|
+
typedData,
|
|
35834
|
+
signature,
|
|
35835
|
+
resolvedSignerAddress
|
|
35836
|
+
);
|
|
35837
|
+
if (cache) cache.pubkeyBase64 = pubkey;
|
|
35752
35838
|
const encodedMessages = msgs.map((msg2) => {
|
|
35753
35839
|
const encoder = MSG_ENCODERS[msg2.typeUrl];
|
|
35754
35840
|
if (!encoder) {
|
|
@@ -35777,26 +35863,20 @@ async function signAndBroadcastEip712({
|
|
|
35777
35863
|
authInfoBytes,
|
|
35778
35864
|
signatures: [sigWithoutRecovery]
|
|
35779
35865
|
});
|
|
35780
|
-
|
|
35781
|
-
let result;
|
|
35866
|
+
let checkTx;
|
|
35782
35867
|
try {
|
|
35783
|
-
|
|
35784
|
-
`${network.restUrl}/cosmos/tx/v1beta1/txs`,
|
|
35785
|
-
{ tx_bytes: txBytesBase64, mode: "BROADCAST_MODE_SYNC" },
|
|
35786
|
-
{ ...fetchOptions, retries: 0 },
|
|
35787
|
-
fetchFn
|
|
35788
|
-
);
|
|
35868
|
+
checkTx = await broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions);
|
|
35789
35869
|
} catch (error) {
|
|
35790
35870
|
clearCachedSequence(cache);
|
|
35791
35871
|
throw error;
|
|
35792
35872
|
}
|
|
35793
|
-
const txHash =
|
|
35794
|
-
if (
|
|
35873
|
+
const { txHash } = checkTx;
|
|
35874
|
+
if (checkTx.code !== 0) {
|
|
35795
35875
|
clearCachedSequence(cache);
|
|
35796
35876
|
throw new TxError({
|
|
35797
35877
|
txHash,
|
|
35798
|
-
code:
|
|
35799
|
-
rawLog:
|
|
35878
|
+
code: checkTx.code,
|
|
35879
|
+
rawLog: checkTx.rawLog,
|
|
35800
35880
|
confirmed: true
|
|
35801
35881
|
});
|
|
35802
35882
|
}
|
|
@@ -35805,7 +35885,7 @@ async function signAndBroadcastEip712({
|
|
|
35805
35885
|
return {
|
|
35806
35886
|
txHash,
|
|
35807
35887
|
code: 0,
|
|
35808
|
-
rawLog:
|
|
35888
|
+
rawLog: checkTx.rawLog,
|
|
35809
35889
|
confirmed: false
|
|
35810
35890
|
};
|
|
35811
35891
|
}
|
|
@@ -35827,7 +35907,7 @@ async function signAndBroadcastEip712({
|
|
|
35827
35907
|
throw new TxConfirmationUnavailableError({
|
|
35828
35908
|
txHash,
|
|
35829
35909
|
code: deliverResult.code,
|
|
35830
|
-
rawLog: deliverResult.rawLog ??
|
|
35910
|
+
rawLog: deliverResult.rawLog ?? checkTx.rawLog,
|
|
35831
35911
|
confirmed: void 0
|
|
35832
35912
|
});
|
|
35833
35913
|
}
|
|
@@ -38750,12 +38830,12 @@ function createStaticResolver(optsOrNetwork, legacyManifest) {
|
|
|
38750
38830
|
}
|
|
38751
38831
|
|
|
38752
38832
|
// src/agent/attach.ts
|
|
38753
|
-
var
|
|
38833
|
+
var import_secp256k13 = require("@noble/curves/secp256k1");
|
|
38754
38834
|
var import_viem7 = require("viem");
|
|
38755
38835
|
var import_encoding9 = require("@cosmjs/encoding");
|
|
38756
38836
|
|
|
38757
38837
|
// src/agent/sign-and-broadcast.ts
|
|
38758
|
-
var
|
|
38838
|
+
var import_secp256k12 = require("@noble/curves/secp256k1");
|
|
38759
38839
|
var import_viem6 = require("viem");
|
|
38760
38840
|
var AGENT_DEFAULTS = {
|
|
38761
38841
|
GAS_LIMIT: "186000",
|
|
@@ -38766,7 +38846,7 @@ var AGENT_DEFAULTS = {
|
|
|
38766
38846
|
function computeAgentKeyMaterial(agentPrivateKey) {
|
|
38767
38847
|
const normalized = agentPrivateKey.startsWith("0x") ? agentPrivateKey : `0x${agentPrivateKey}`;
|
|
38768
38848
|
const privKeyBytes = (0, import_viem6.hexToBytes)(normalized);
|
|
38769
|
-
const compressedPubkey =
|
|
38849
|
+
const compressedPubkey = import_secp256k12.secp256k1.getPublicKey(privKeyBytes, true);
|
|
38770
38850
|
return { privKeyBytes, compressedPubkey };
|
|
38771
38851
|
}
|
|
38772
38852
|
function computeTimeoutTimestamp(timeoutSeconds) {
|
|
@@ -38847,26 +38927,20 @@ async function signAndBroadcastAgentTx({
|
|
|
38847
38927
|
accountNumber: BigInt(accountNumber)
|
|
38848
38928
|
});
|
|
38849
38929
|
const hash = (0, import_viem6.hexToBytes)((0, import_viem6.keccak256)(signDocBytes));
|
|
38850
|
-
const sig =
|
|
38930
|
+
const sig = import_secp256k12.secp256k1.sign(hash, privKeyBytes);
|
|
38851
38931
|
const signatureBytes = sig.toCompactRawBytes();
|
|
38852
38932
|
const txRawBytes = encodeTxRaw({
|
|
38853
38933
|
bodyBytes,
|
|
38854
38934
|
authInfoBytes,
|
|
38855
38935
|
signatures: [signatureBytes]
|
|
38856
38936
|
});
|
|
38857
|
-
const
|
|
38858
|
-
const
|
|
38859
|
-
|
|
38860
|
-
{ tx_bytes: txBytesBase64, mode: "BROADCAST_MODE_SYNC" },
|
|
38861
|
-
fetchOptions,
|
|
38862
|
-
fetchFn
|
|
38863
|
-
);
|
|
38864
|
-
const txHash = normalizeTxHash(result.tx_response.txhash);
|
|
38865
|
-
if (result.tx_response.code !== 0) {
|
|
38937
|
+
const checkTx = await broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions);
|
|
38938
|
+
const { txHash } = checkTx;
|
|
38939
|
+
if (checkTx.code !== 0) {
|
|
38866
38940
|
throw new TxError({
|
|
38867
38941
|
txHash,
|
|
38868
|
-
code:
|
|
38869
|
-
rawLog:
|
|
38942
|
+
code: checkTx.code,
|
|
38943
|
+
rawLog: checkTx.rawLog,
|
|
38870
38944
|
confirmed: true
|
|
38871
38945
|
});
|
|
38872
38946
|
}
|
|
@@ -38874,7 +38948,7 @@ async function signAndBroadcastAgentTx({
|
|
|
38874
38948
|
return {
|
|
38875
38949
|
txHash,
|
|
38876
38950
|
code: 0,
|
|
38877
|
-
rawLog:
|
|
38951
|
+
rawLog: checkTx.rawLog,
|
|
38878
38952
|
confirmed: false
|
|
38879
38953
|
};
|
|
38880
38954
|
}
|
|
@@ -38889,7 +38963,7 @@ async function signAndBroadcastAgentTx({
|
|
|
38889
38963
|
throw new TxConfirmationUnavailableError({
|
|
38890
38964
|
txHash,
|
|
38891
38965
|
code: deliverResult.code,
|
|
38892
|
-
rawLog: deliverResult.rawLog ??
|
|
38966
|
+
rawLog: deliverResult.rawLog ?? checkTx.rawLog,
|
|
38893
38967
|
confirmed: void 0
|
|
38894
38968
|
});
|
|
38895
38969
|
}
|
|
@@ -39347,7 +39421,7 @@ function deriveAgentAddress(privateKeyHex) {
|
|
|
39347
39421
|
const privKeyBytes = (0, import_viem7.hexToBytes)(
|
|
39348
39422
|
privateKeyHex.startsWith("0x") ? privateKeyHex : `0x${privateKeyHex}`
|
|
39349
39423
|
);
|
|
39350
|
-
const uncompressedPubkey =
|
|
39424
|
+
const uncompressedPubkey = import_secp256k13.secp256k1.getPublicKey(privKeyBytes, false);
|
|
39351
39425
|
const pubkeyHash = (0, import_viem7.hexToBytes)((0, import_viem7.keccak256)(uncompressedPubkey.slice(1)));
|
|
39352
39426
|
const evmAddressBytes = pubkeyHash.slice(12);
|
|
39353
39427
|
const evmHex = `0x${(0, import_encoding9.toHex)(evmAddressBytes)}`;
|
|
@@ -42935,6 +43009,7 @@ function createDexWs(url, options) {
|
|
|
42935
43009
|
SearchUDFSymbolsQueryParams,
|
|
42936
43010
|
SearchUDFSymbolsResponse,
|
|
42937
43011
|
SearchUDFSymbolsResponseItem,
|
|
43012
|
+
SignerMismatchError,
|
|
42938
43013
|
TIMING_CONSTANTS,
|
|
42939
43014
|
TX_BASE_FIELDS,
|
|
42940
43015
|
TimeoutError,
|
|
@@ -42955,6 +43030,7 @@ function createDexWs(url, options) {
|
|
|
42955
43030
|
aultToEvm,
|
|
42956
43031
|
averagePremium,
|
|
42957
43032
|
base64ToBytes,
|
|
43033
|
+
broadcastSignedTx,
|
|
42958
43034
|
buildBorrowMarginMsg,
|
|
42959
43035
|
buildConditionalOrderMsg,
|
|
42960
43036
|
buildDepositMarginMsg,
|