@sodax/sdk 1.2.2-beta → 1.2.4-beta
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 +123 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -3
- package/dist/index.d.ts +46 -3
- package/dist/index.mjs +123 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -10767,6 +10767,33 @@ var StellarSpokeService = class _StellarSpokeService {
|
|
|
10767
10767
|
raw
|
|
10768
10768
|
);
|
|
10769
10769
|
}
|
|
10770
|
+
static async waitForTransactionRaw(params) {
|
|
10771
|
+
const defaultParams = {
|
|
10772
|
+
pollingTimeout: 750,
|
|
10773
|
+
maxAttempts: 40
|
|
10774
|
+
};
|
|
10775
|
+
const { pollingTimeout, maxAttempts, sorobanRpcConfig, txHash } = { ...defaultParams, ...params };
|
|
10776
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
10777
|
+
try {
|
|
10778
|
+
const sorobanServer = new CustomSorobanServer(sorobanRpcConfig.sorobanRpcUrl, sorobanRpcConfig.customHeaders);
|
|
10779
|
+
const tx = await sorobanServer.getTransaction(txHash);
|
|
10780
|
+
if (tx && tx.status === "SUCCESS") {
|
|
10781
|
+
return { ok: true, value: true };
|
|
10782
|
+
}
|
|
10783
|
+
if (tx && tx.status === "FAILED") {
|
|
10784
|
+
return { ok: false, error: new Error(`Transaction failed: ${JSON.stringify(tx)}`) };
|
|
10785
|
+
}
|
|
10786
|
+
if (tx && tx.status === "NOT_FOUND") {
|
|
10787
|
+
await sleep(pollingTimeout);
|
|
10788
|
+
continue;
|
|
10789
|
+
}
|
|
10790
|
+
await sleep(pollingTimeout);
|
|
10791
|
+
} catch (err) {
|
|
10792
|
+
await sleep(pollingTimeout);
|
|
10793
|
+
}
|
|
10794
|
+
}
|
|
10795
|
+
return { ok: false, error: new Error("Transaction was not confirmed within the max attempts") };
|
|
10796
|
+
}
|
|
10770
10797
|
static async waitForTransaction(spokeProvider, txHash, pollingTimeout = 750, maxAttempts = 40) {
|
|
10771
10798
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
10772
10799
|
try {
|
|
@@ -11576,6 +11603,42 @@ var EvmSpokeService = class _EvmSpokeService {
|
|
|
11576
11603
|
}
|
|
11577
11604
|
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
11578
11605
|
}
|
|
11606
|
+
static async waitForTransactionReceipt(params) {
|
|
11607
|
+
try {
|
|
11608
|
+
const { txHash, chainId, rpcUrl, confirmations, pollingInterval, retryCount, retryDelay, timeout } = params;
|
|
11609
|
+
const evmChain = getEvmViemChain(chainId);
|
|
11610
|
+
const publicClient = viem.createPublicClient({
|
|
11611
|
+
chain: evmChain,
|
|
11612
|
+
transport: viem.http(rpcUrl ?? evmChain.rpcUrls.default.http[0])
|
|
11613
|
+
});
|
|
11614
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
11615
|
+
hash: txHash,
|
|
11616
|
+
confirmations,
|
|
11617
|
+
pollingInterval,
|
|
11618
|
+
retryCount,
|
|
11619
|
+
retryDelay,
|
|
11620
|
+
timeout
|
|
11621
|
+
});
|
|
11622
|
+
const response = {
|
|
11623
|
+
...receipt,
|
|
11624
|
+
transactionIndex: receipt.transactionIndex.toString(),
|
|
11625
|
+
blockNumber: receipt.blockNumber.toString(),
|
|
11626
|
+
cumulativeGasUsed: receipt.cumulativeGasUsed.toString(),
|
|
11627
|
+
gasUsed: receipt.gasUsed.toString(),
|
|
11628
|
+
contractAddress: receipt.contractAddress?.toString() ?? null,
|
|
11629
|
+
logs: receipt.logs.map((log) => ({
|
|
11630
|
+
...log,
|
|
11631
|
+
blockNumber: log.blockNumber.toString(),
|
|
11632
|
+
logIndex: log.logIndex.toString(),
|
|
11633
|
+
transactionIndex: log.transactionIndex.toString()
|
|
11634
|
+
})),
|
|
11635
|
+
effectiveGasPrice: receipt.effectiveGasPrice?.toString()
|
|
11636
|
+
};
|
|
11637
|
+
return { ok: true, value: response };
|
|
11638
|
+
} catch (error) {
|
|
11639
|
+
return { ok: false, error: new Error(`Failed to get transaction receipt: ${JSON.stringify(error)}`) };
|
|
11640
|
+
}
|
|
11641
|
+
}
|
|
11579
11642
|
};
|
|
11580
11643
|
|
|
11581
11644
|
// src/shared/utils/icon-utils.ts
|
|
@@ -12037,7 +12100,40 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
12037
12100
|
}
|
|
12038
12101
|
return spokeProvider.walletProvider.sendTransaction(serializedTransaction);
|
|
12039
12102
|
}
|
|
12040
|
-
static async
|
|
12103
|
+
static async waitForConfirmationRaw(params) {
|
|
12104
|
+
try {
|
|
12105
|
+
const defaultParams = {
|
|
12106
|
+
commitment: "finalized",
|
|
12107
|
+
timeoutMs: 6e4,
|
|
12108
|
+
// total time to wait
|
|
12109
|
+
pollingTimeout: 750
|
|
12110
|
+
// 750ms retry interval
|
|
12111
|
+
};
|
|
12112
|
+
const { rpcUrl, signature, commitment, timeoutMs, pollingTimeout } = { ...defaultParams, ...params };
|
|
12113
|
+
const connection = new web3_js.Connection(rpcUrl, commitment);
|
|
12114
|
+
const deadline = Date.now() + timeoutMs;
|
|
12115
|
+
while (Date.now() < deadline) {
|
|
12116
|
+
try {
|
|
12117
|
+
const tx = await connection.getTransaction(signature, { commitment, maxSupportedTransactionVersion: 0 });
|
|
12118
|
+
if (tx) {
|
|
12119
|
+
if (tx.meta?.err) {
|
|
12120
|
+
return { ok: false, error: new Error(JSON.stringify(tx.meta.err)) };
|
|
12121
|
+
}
|
|
12122
|
+
return { ok: true, value: true };
|
|
12123
|
+
}
|
|
12124
|
+
} catch {
|
|
12125
|
+
}
|
|
12126
|
+
await new Promise((r) => setTimeout(r, pollingTimeout));
|
|
12127
|
+
}
|
|
12128
|
+
return {
|
|
12129
|
+
ok: false,
|
|
12130
|
+
error: new Error(`Timed out after ${timeoutMs}ms waiting for ${commitment} confirmation for ${signature}`)
|
|
12131
|
+
};
|
|
12132
|
+
} catch (error) {
|
|
12133
|
+
return { ok: false, error: new Error(`Failed to get transaction confirmation: ${JSON.stringify(error)}`) };
|
|
12134
|
+
}
|
|
12135
|
+
}
|
|
12136
|
+
static async waitForConfirmation(spokeProvider, signature, commitment = "finalized", timeoutMs = 6e4, pollingTimeout = 750) {
|
|
12041
12137
|
try {
|
|
12042
12138
|
const connection = new web3_js.Connection(spokeProvider.chainConfig.rpcUrl, commitment);
|
|
12043
12139
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -12052,7 +12148,7 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
12052
12148
|
}
|
|
12053
12149
|
} catch {
|
|
12054
12150
|
}
|
|
12055
|
-
await new Promise((r) => setTimeout(r,
|
|
12151
|
+
await new Promise((r) => setTimeout(r, pollingTimeout));
|
|
12056
12152
|
}
|
|
12057
12153
|
return {
|
|
12058
12154
|
ok: false,
|
|
@@ -12474,6 +12570,31 @@ var SpokeService = class _SpokeService {
|
|
|
12474
12570
|
value: true
|
|
12475
12571
|
};
|
|
12476
12572
|
}
|
|
12573
|
+
/**
|
|
12574
|
+
* Verifies the transaction hash for the spoke chain to exist on chain.
|
|
12575
|
+
* @param {VerifyTxHashRawConfig} params - The parameters for the verification.
|
|
12576
|
+
* @returns {Promise<Result<boolean>>} A promise that resolves to the result of the verification.
|
|
12577
|
+
*/
|
|
12578
|
+
static async verifyTxHashRaw(params) {
|
|
12579
|
+
switch (params.chainType) {
|
|
12580
|
+
case "SOLANA":
|
|
12581
|
+
return SolanaSpokeService.waitForConfirmationRaw(params);
|
|
12582
|
+
case "STELLAR":
|
|
12583
|
+
return StellarSpokeService.waitForTransactionRaw(params);
|
|
12584
|
+
case "EVM": {
|
|
12585
|
+
const result = await EvmSpokeService.waitForTransactionReceipt(params);
|
|
12586
|
+
if (!result.ok) {
|
|
12587
|
+
return result;
|
|
12588
|
+
}
|
|
12589
|
+
if (result.value.status && result.value.status !== "0x1") {
|
|
12590
|
+
return { ok: false, error: new Error("Transaction reverted") };
|
|
12591
|
+
}
|
|
12592
|
+
return { ok: true, value: true };
|
|
12593
|
+
}
|
|
12594
|
+
default:
|
|
12595
|
+
return { ok: true, value: true };
|
|
12596
|
+
}
|
|
12597
|
+
}
|
|
12477
12598
|
};
|
|
12478
12599
|
var IntentDataType = /* @__PURE__ */ ((IntentDataType2) => {
|
|
12479
12600
|
IntentDataType2[IntentDataType2["FEE"] = 1] = "FEE";
|