@rash2x/bridge-widget 0.8.9 → 0.8.10

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-BLnE8fLp.cjs");
3
+ const index = require("./index-CEYZ1mEJ.cjs");
4
4
  exports.DEFAULT_SLIPPAGE_BPS = index.DEFAULT_SLIPPAGE_BPS;
5
5
  exports.EvaaBridge = index.EvaaBridge;
6
6
  exports.RoutePriority = index.RoutePriority;
@@ -1,4 +1,4 @@
1
- import { P, d, f, e, D, U, H, y, B, W, w, s, v, r, p, q, G, $, a8, a1, a5, x, z, a2, A, a0, a6, a7, Z, _, V, a3, S, I, X, a4, Y, a9, aa, N, L, J, K, F, Q, t, o, i, u, l, m, j, n, h, k } from "./index-IZ7t2PGj.js";
1
+ import { P, d, f, e, D, U, H, y, B, W, w, s, v, r, p, q, G, $, a8, a1, a5, x, z, a2, A, a0, a6, a7, Z, _, V, a3, S, I, X, a4, Y, a9, aa, N, L, J, K, F, Q, t, o, i, u, l, m, j, n, h, k } from "./index-DLlaTmxx.js";
2
2
  export {
3
3
  P as DEFAULT_SLIPPAGE_BPS,
4
4
  d as EvaaBridge,
@@ -5979,6 +5979,39 @@ class EvmChainStrategy {
5979
5979
  ...rpcError
5980
5980
  });
5981
5981
  }
5982
+ isNonceResubmissionError(error) {
5983
+ const rpcError = this.getRpcErrorDetails(error);
5984
+ const combined = [rpcError.message, rpcError.shortMessage, rpcError.details].filter(Boolean).join(" ").toLowerCase();
5985
+ return combined.includes("nonce too low") || combined.includes("replacement transaction underpriced");
5986
+ }
5987
+ async sendTransactionWithNonceRetry(walletClient, params) {
5988
+ try {
5989
+ return await walletClient.sendTransaction(params);
5990
+ } catch (error) {
5991
+ if (!this.isNonceResubmissionError(error)) {
5992
+ throw error;
5993
+ }
5994
+ this.logRpcWarning(
5995
+ "Retrying transaction after nonce-related error",
5996
+ error
5997
+ );
5998
+ return await walletClient.sendTransaction(params);
5999
+ }
6000
+ }
6001
+ async writeContractWithNonceRetry(walletClient, params) {
6002
+ try {
6003
+ return await walletClient.writeContract(params);
6004
+ } catch (error) {
6005
+ if (!this.isNonceResubmissionError(error)) {
6006
+ throw error;
6007
+ }
6008
+ this.logRpcWarning(
6009
+ "Retrying contract write after nonce-related error",
6010
+ error
6011
+ );
6012
+ return await walletClient.writeContract(params);
6013
+ }
6014
+ }
5982
6015
  async getBalances(address, tokens) {
5983
6016
  const chainKey = tokens[0]?.chainKey;
5984
6017
  const client = this.resolvePublicClientForChain(chainKey);
@@ -6043,12 +6076,16 @@ class EvmChainStrategy {
6043
6076
  if (!tx?.to) continue;
6044
6077
  const client = this.resolvePublicClientForChain(step.chainKey);
6045
6078
  if (!client) {
6046
- this.logRpcWarning("Skipped network fee estimation: no public client", "no-client", {
6047
- chainKey: step.chainKey,
6048
- stepType: step.type,
6049
- stepIndex: i3 + 1,
6050
- totalSteps: txSteps.length
6051
- });
6079
+ this.logRpcWarning(
6080
+ "Skipped network fee estimation: no public client",
6081
+ "no-client",
6082
+ {
6083
+ chainKey: step.chainKey,
6084
+ stepType: step.type,
6085
+ stepIndex: i3 + 1,
6086
+ totalSteps: txSteps.length
6087
+ }
6088
+ );
6052
6089
  continue;
6053
6090
  }
6054
6091
  try {
@@ -6076,12 +6113,16 @@ class EvmChainStrategy {
6076
6113
  try {
6077
6114
  feePerGas = await client.getGasPrice();
6078
6115
  } catch (gasPriceError) {
6079
- this.logRpcWarning("Failed to get gas price for network fee estimation", gasPriceError, {
6080
- chainKey: step.chainKey,
6081
- stepType: step.type,
6082
- stepIndex: i3 + 1,
6083
- totalSteps: txSteps.length
6084
- });
6116
+ this.logRpcWarning(
6117
+ "Failed to get gas price for network fee estimation",
6118
+ gasPriceError,
6119
+ {
6120
+ chainKey: step.chainKey,
6121
+ stepType: step.type,
6122
+ stepIndex: i3 + 1,
6123
+ totalSteps: txSteps.length
6124
+ }
6125
+ );
6085
6126
  }
6086
6127
  }
6087
6128
  if (gas && feePerGas) {
@@ -6160,7 +6201,9 @@ class EvmChainStrategy {
6160
6201
  const requiredChainId = this.config.chainKeyToId[firstChainKey.toLowerCase()];
6161
6202
  const currentChainId = this.walletClient.chain?.id;
6162
6203
  if (requiredChainId && currentChainId !== requiredChainId) {
6163
- console.log(`Switching from chain ${currentChainId} to ${requiredChainId}`);
6204
+ console.log(
6205
+ `Switching from chain ${currentChainId} to ${requiredChainId}`
6206
+ );
6164
6207
  await this.switchToChain(requiredChainId);
6165
6208
  } else {
6166
6209
  console.log(`Already on correct chain ${currentChainId}`);
@@ -6189,6 +6232,16 @@ class EvmChainStrategy {
6189
6232
  bridgeTxHash = hash;
6190
6233
  }
6191
6234
  lastTxHash = hash;
6235
+ if (step.type === "approve") {
6236
+ const receiptClient = this.resolvePublicClientForChain(step.chainKey);
6237
+ if (!receiptClient) {
6238
+ throw new WalletNotConnectedError("evm");
6239
+ }
6240
+ await receiptClient.waitForTransactionReceipt({
6241
+ hash,
6242
+ confirmations: 1
6243
+ });
6244
+ }
6192
6245
  onStepComplete?.(hash, step.type, i3, totalSteps);
6193
6246
  }
6194
6247
  const hashForTracking = bridgeTxHash ?? lastTxHash;
@@ -6206,15 +6259,6 @@ class EvmChainStrategy {
6206
6259
  throw toChainStrategyError(error, "evm", "transaction");
6207
6260
  }
6208
6261
  }
6209
- async getNextNonce() {
6210
- if (!this.publicClient || !this.config.evmAddress) {
6211
- throw new WalletNotConnectedError("evm");
6212
- }
6213
- return await this.publicClient.getTransactionCount({
6214
- address: this.config.evmAddress,
6215
- blockTag: "pending"
6216
- });
6217
- }
6218
6262
  async executeTransaction(step) {
6219
6263
  const walletClient = this.walletClient;
6220
6264
  if (!walletClient) {
@@ -6227,14 +6271,12 @@ class EvmChainStrategy {
6227
6271
  );
6228
6272
  }
6229
6273
  const tx = step.transaction;
6230
- const nonce = await this.getNextNonce();
6231
- const hash = await walletClient.sendTransaction({
6274
+ const hash = await this.sendTransactionWithNonceRetry(walletClient, {
6232
6275
  to: tx.to,
6233
6276
  data: tx.data,
6234
6277
  account: tx.from || this.config.evmAddress,
6235
6278
  value: tx.value ? BigInt(tx.value) : void 0,
6236
- chain: walletClient.chain,
6237
- nonce
6279
+ chain: walletClient.chain
6238
6280
  });
6239
6281
  return hash;
6240
6282
  }
@@ -6276,16 +6318,17 @@ class EvmChainStrategy {
6276
6318
  });
6277
6319
  if (currentAllowance > 0n) {
6278
6320
  try {
6279
- const resetNonce = await this.getNextNonce();
6280
- const resetHash = await walletClient.writeContract({
6281
- address: tokenAddress,
6282
- abi: ERC20_ABI,
6283
- functionName: "approve",
6284
- args: [spenderAddress, 0n],
6285
- account: this.config.evmAddress,
6286
- chain: walletClient.chain,
6287
- nonce: resetNonce
6288
- });
6321
+ const resetHash = await this.writeContractWithNonceRetry(
6322
+ walletClient,
6323
+ {
6324
+ address: tokenAddress,
6325
+ abi: ERC20_ABI,
6326
+ functionName: "approve",
6327
+ args: [spenderAddress, 0n],
6328
+ account: this.config.evmAddress,
6329
+ chain: walletClient.chain
6330
+ }
6331
+ );
6289
6332
  await publicClient.waitForTransactionReceipt({
6290
6333
  hash: resetHash
6291
6334
  });
@@ -6301,16 +6344,17 @@ class EvmChainStrategy {
6301
6344
  console.log("USDT allowance is 0, no reset needed");
6302
6345
  }
6303
6346
  try {
6304
- const approveNonce = await this.getNextNonce();
6305
- const approveHash = await walletClient.writeContract({
6306
- address: tokenAddress,
6307
- abi: ERC20_ABI,
6308
- functionName: "approve",
6309
- args: [spenderAddress, amount],
6310
- account: this.config.evmAddress,
6311
- chain: walletClient.chain,
6312
- nonce: approveNonce
6313
- });
6347
+ const approveHash = await this.writeContractWithNonceRetry(
6348
+ walletClient,
6349
+ {
6350
+ address: tokenAddress,
6351
+ abi: ERC20_ABI,
6352
+ functionName: "approve",
6353
+ args: [spenderAddress, amount],
6354
+ account: this.config.evmAddress,
6355
+ chain: walletClient.chain
6356
+ }
6357
+ );
6314
6358
  return approveHash;
6315
6359
  } catch (approveError) {
6316
6360
  throw new TransactionFailedError(
@@ -26765,7 +26809,7 @@ class WalletConnectModal {
26765
26809
  }
26766
26810
  async initUi() {
26767
26811
  if (typeof window !== "undefined") {
26768
- await Promise.resolve().then(() => require("./index--9cCU23B.cjs"));
26812
+ await Promise.resolve().then(() => require("./index-D4aCX9t_.cjs"));
26769
26813
  const modal = document.createElement("wcm-modal");
26770
26814
  document.body.insertAdjacentElement("beforeend", modal);
26771
26815
  OptionsCtrl.setIsUiLoaded(true);
@@ -27687,4 +27731,4 @@ exports.useSettingsStore = useSettingsStore;
27687
27731
  exports.useSwapModel = useSwapModel;
27688
27732
  exports.useTokensStore = useTokensStore;
27689
27733
  exports.useTransactionStore = useTransactionStore;
27690
- //# sourceMappingURL=index-BLnE8fLp.cjs.map
27734
+ //# sourceMappingURL=index-CEYZ1mEJ.cjs.map