@veridex/sdk 1.1.1 → 1.1.2

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.
@@ -23,6 +23,8 @@ declare class EVMClient implements ChainClient {
23
23
  private hubContract;
24
24
  private factoryContract;
25
25
  private cachedImplementation;
26
+ private cachedWormholeAddress;
27
+ private cachedMessageFee;
26
28
  constructor(config: EVMClientConfig);
27
29
  getConfig(): ChainConfig;
28
30
  getNonce(userKeyHash: string): Promise<bigint>;
@@ -1,4 +1,4 @@
1
- import { E as EVMClient, a as EVMClientConfig } from '../../EVMClient-DtqvdfUP.mjs';
1
+ import { E as EVMClient, a as EVMClientConfig } from '../../EVMClient-Bmy9czkE.mjs';
2
2
  import '../../types.mjs';
3
3
  import 'ethers';
4
4
  import '../../types-DP2CQT8p.mjs';
@@ -119,7 +119,9 @@ var ERC20_ABI = [
119
119
  var HUB_ABI = [
120
120
  "function dispatch(tuple(bytes authenticatorData, string clientDataJSON, uint256 challengeIndex, uint256 typeIndex, uint256 r, uint256 s) signature, uint256 publicKeyX, uint256 publicKeyY, uint16 targetChain, bytes actionPayload, uint256 nonce) payable returns (uint64 sequence)",
121
121
  "function userNonces(bytes32 userKeyHash) view returns (uint256)",
122
- "function getMessageFee() view returns (uint256)",
122
+ // Hub exposes the Wormhole core bridge address; message fee is read from the
123
+ // bridge directly (getMessageFee() was removed from the Hub).
124
+ "function wormhole() view returns (address)",
123
125
  "function getVaultAddress(bytes32 userKeyHash) view returns (address)",
124
126
  "function vaultExists(bytes32 userKeyHash) view returns (bool)",
125
127
  "function createVault(bytes32 userKeyHash) returns (address)",
@@ -176,6 +178,8 @@ var EVMClient = class {
176
178
  hubContract;
177
179
  factoryContract = null;
178
180
  cachedImplementation = null;
181
+ cachedWormholeAddress = null;
182
+ cachedMessageFee = null;
179
183
  constructor(config) {
180
184
  this.config = {
181
185
  name: config.name ?? `EVM Chain ${config.chainId}`,
@@ -348,8 +352,24 @@ var EVMClient = class {
348
352
  return Number(count);
349
353
  }
350
354
  async getMessageFee() {
351
- const fee = await this.hubContract.getMessageFee();
352
- return BigInt(fee.toString());
355
+ const now = Date.now();
356
+ if (this.cachedMessageFee && this.cachedMessageFee.expiresAt > now) {
357
+ return this.cachedMessageFee.value;
358
+ }
359
+ let wormholeAddress = this.config.contracts.wormholeCoreBridge ?? this.cachedWormholeAddress;
360
+ if (!wormholeAddress) {
361
+ wormholeAddress = await this.hubContract.wormhole();
362
+ this.cachedWormholeAddress = wormholeAddress;
363
+ }
364
+ const wormhole = new import_ethers2.ethers.Contract(
365
+ wormholeAddress,
366
+ ["function messageFee() view returns (uint256)"],
367
+ this.provider
368
+ );
369
+ const fee = await wormhole.messageFee();
370
+ const value = BigInt(fee.toString());
371
+ this.cachedMessageFee = { value, expiresAt: now + 3e4 };
372
+ return value;
353
373
  }
354
374
  async buildTransferPayload(params) {
355
375
  return encodeTransferAction(
@@ -448,13 +468,41 @@ var EVMClient = class {
448
468
  actionPayload,
449
469
  nonce: Number(nonce)
450
470
  };
451
- const response = await fetch(`${relayerUrl}/api/v1/submit`, {
452
- method: "POST",
453
- headers: {
454
- "Content-Type": "application/json"
455
- },
456
- body: JSON.stringify(request)
457
- });
471
+ const MAX_ATTEMPTS = 3;
472
+ const baseDelayMs = 1e3;
473
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
474
+ let response;
475
+ let lastError;
476
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
477
+ try {
478
+ response = await fetch(`${relayerUrl}/api/v1/submit`, {
479
+ method: "POST",
480
+ headers: {
481
+ "Content-Type": "application/json"
482
+ },
483
+ body: JSON.stringify(request)
484
+ });
485
+ const retryable = response.status >= 500 || response.status === 408 || response.status === 429;
486
+ if (!retryable) {
487
+ break;
488
+ }
489
+ if (attempt === MAX_ATTEMPTS) break;
490
+ const retryAfter = response.headers.get("retry-after");
491
+ const explicitDelay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : 0;
492
+ const backoff = explicitDelay > 0 ? explicitDelay : baseDelayMs * 2 ** (attempt - 1) + Math.floor(Math.random() * 200);
493
+ await sleep(backoff);
494
+ } catch (err) {
495
+ lastError = err;
496
+ if (attempt === MAX_ATTEMPTS) break;
497
+ const backoff = baseDelayMs * 2 ** (attempt - 1) + Math.floor(Math.random() * 200);
498
+ await sleep(backoff);
499
+ }
500
+ }
501
+ if (!response) {
502
+ throw new Error(
503
+ `Relayer submission failed after ${MAX_ATTEMPTS} attempts: ${lastError instanceof Error ? lastError.message : String(lastError)}`
504
+ );
505
+ }
458
506
  if (!response.ok) {
459
507
  const error = await response.json().catch(() => ({ error: response.statusText }));
460
508
  throw new Error(`Relayer submission failed: ${error.error || response.statusText}`);
@@ -1285,7 +1333,7 @@ var EVMClient = class {
1285
1333
  async executeTransactionProposal(proposalId, signer) {
1286
1334
  const s = signer;
1287
1335
  const hub = this.hubContract.connect(s);
1288
- const fee = await this.hubContract.getMessageFee();
1336
+ const fee = await this.getMessageFee();
1289
1337
  const tx = await hub.executeTransactionProposal(proposalId, { value: fee });
1290
1338
  const receipt = await tx.wait();
1291
1339
  const sequence = this._extractSequenceFromReceipt(receipt);