@glowlabs-org/utils 0.2.145 → 0.2.147

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
 
3
- var farmsRouter = require('./farms-router-C8V_F0vY.js');
3
+ var farmsRouter = require('./farms-router-Cg0-zSMT.js');
4
4
  var viem = require('viem');
5
5
  require('ethers');
6
6
 
@@ -274,8 +274,8 @@ const sepoliaAddresses = {
274
274
  USDC: "0x93c898be98cd2618ba84a6dccf5003d3bbe40356",
275
275
  USDG_UNISWAP: "0x2a085A3aEA8982396533327c854753Ce521B666d",
276
276
  GLW_UNISWAP: "0x8e27016D0B866a56CE74A1a280c749dD679bb0Fa",
277
- FORWARDER: "0xDaC24F18171224eeaf6a9B38f5C5081aDbDff969",
278
- OFFCHAIN_FRACTIONS: "0x7D97528eeF8B8D17AA1Ba3307Ed39b07b3A1b69B",
277
+ FORWARDER: "0xe7A366482899e2Ed29c9504F4792B8D1c67066ff",
278
+ OFFCHAIN_FRACTIONS: "0x5Ad30F90AFEf1279157A5055AAd2d8c1529a05D2",
279
279
  COUNTERFACTUAL_HOLDER_FACTORY: "0x2c3AB887746F6f4a8a4b9Db6aC800eb71945509A",
280
280
  FOUNDATION_WALLET: "0x5e230FED487c86B90f6508104149F087d9B1B0A7",
281
281
  FOUNDATION_HUB_MANAGER_WALLET: "0x5252FdA14A149c01EA5A1D6514a9c1369E4C70b4",
@@ -354,6 +354,7 @@ const DEFAULT_OPTIONS = {
354
354
  maxRetries: 3,
355
355
  timeoutMs: 60000,
356
356
  enableLogging: true,
357
+ pollIntervalMs: 2000,
357
358
  };
358
359
  /**
359
360
  * Enhanced transaction receipt handler with retry logic for viem
@@ -362,66 +363,46 @@ const DEFAULT_OPTIONS = {
362
363
  * @param options Retry configuration options
363
364
  */
364
365
  async function waitForViemTransactionWithRetry(publicClient, hash, options = {}) {
365
- const { maxRetries, timeoutMs, enableLogging } = {
366
+ const { maxRetries, timeoutMs, enableLogging, pollIntervalMs } = {
366
367
  ...DEFAULT_OPTIONS,
367
368
  ...options,
368
369
  };
369
- let lastError = null;
370
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
370
+ const deadline = Date.now() + timeoutMs;
371
+ let consecutiveErrors = 0;
372
+ while (Date.now() < deadline) {
371
373
  try {
372
- // Wait for transaction receipt with timeout
373
- const receipt = await publicClient.waitForTransactionReceipt({
374
- hash,
375
- timeout: timeoutMs,
376
- });
377
- // Check transaction status
378
- if (receipt.status === "reverted") {
379
- throw new Error(`Transaction ${hash} was reverted on-chain`);
380
- }
381
- if (enableLogging) {
382
- console.log(`Transaction ${hash} confirmed successfully in block ${receipt.blockNumber}`);
374
+ const receipt = await publicClient.getTransactionReceipt({ hash });
375
+ if (receipt) {
376
+ if (receipt.status === "reverted") {
377
+ throw new Error(`Transaction ${hash} was reverted on-chain`);
378
+ }
379
+ if (enableLogging) {
380
+ console.log(`Transaction ${hash} confirmed successfully in block ${receipt.blockNumber}`);
381
+ }
382
+ return;
383
383
  }
384
- return; // Success, exit the function
385
384
  }
386
385
  catch (error) {
387
- lastError = error;
388
- // Check if it's a timeout or not found error
389
386
  const errorMessage = parseViemError(error);
390
- const isRetryableError = errorMessage.includes("could not be found") ||
391
- errorMessage.includes("timeout") ||
392
- errorMessage.includes("timed out") ||
387
+ // Treat not found/receipt missing as retryable without counting towards errors
388
+ const isNotFound = errorMessage.includes("not found") ||
389
+ errorMessage.includes("could not be found") ||
393
390
  errorMessage.includes("receipt") ||
394
- errorMessage.includes("not be processed");
395
- if (!isRetryableError || attempt === maxRetries) {
396
- // If it's not a retryable error or we've exhausted retries, throw
397
- throw new Error(`Transaction failed after ${attempt} attempts: ${errorMessage}`);
398
- }
399
- // Wait before retrying (exponential backoff)
400
- const delay = Math.min(2000 * Math.pow(2, attempt - 1), 10000);
401
- if (enableLogging) {
402
- console.warn(`Transaction receipt not found (attempt ${attempt}/${maxRetries}), retrying in ${delay}ms...`);
403
- }
404
- await new Promise((resolve) => setTimeout(resolve, delay));
405
- // Check transaction status before retrying
406
- try {
407
- const transaction = await publicClient.getTransaction({ hash });
408
- if (!transaction) {
409
- throw new Error("Transaction not found in mempool or blockchain");
410
- }
411
- if (enableLogging) {
412
- console.log(`Transaction ${hash} found in ${transaction.blockNumber ? "block" : "mempool"}, waiting for confirmation...`);
391
+ errorMessage.includes("not confirmed") ||
392
+ errorMessage.includes("TransactionReceiptNotFound");
393
+ if (!isNotFound) {
394
+ consecutiveErrors++;
395
+ if (consecutiveErrors >= maxRetries) {
396
+ throw new Error(`Transaction failed after ${consecutiveErrors} attempts: ${errorMessage}`);
413
397
  }
414
- }
415
- catch (txError) {
416
398
  if (enableLogging) {
417
- console.warn(`Could not fetch transaction ${hash}: ${parseViemError(txError)}`);
399
+ console.warn(`Error fetching receipt (attempt ${consecutiveErrors}/${maxRetries}), retrying in ${pollIntervalMs}ms...`);
418
400
  }
419
- // Continue with retry anyway in case it's just an RPC issue
420
401
  }
421
402
  }
403
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
422
404
  }
423
- // This should never be reached, but just in case
424
- throw new Error(`Transaction failed after ${maxRetries} attempts: ${parseViemError(lastError)}`);
405
+ throw new Error(`Transaction receipt not found within ${timeoutMs}ms`);
425
406
  }
426
407
  /**
427
408
  * Enhanced transaction receipt handler with retry logic for ethers.js
@@ -430,82 +411,42 @@ async function waitForViemTransactionWithRetry(publicClient, hash, options = {})
430
411
  * @param options Retry configuration options
431
412
  */
432
413
  async function waitForEthersTransactionWithRetry(signer, txHash, options = {}) {
433
- const { maxRetries, timeoutMs, enableLogging } = {
414
+ const { maxRetries, timeoutMs, enableLogging, pollIntervalMs } = {
434
415
  ...DEFAULT_OPTIONS,
435
416
  ...options,
436
417
  };
437
- let lastError = null;
438
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
418
+ const provider = signer.provider;
419
+ if (!provider) {
420
+ throw new Error("Provider not available");
421
+ }
422
+ const deadline = Date.now() + timeoutMs;
423
+ let consecutiveErrors = 0;
424
+ while (Date.now() < deadline) {
439
425
  try {
440
- // Wait for transaction receipt with timeout
441
- const provider = signer.provider;
442
- if (!provider) {
443
- throw new Error("Provider not available");
444
- }
445
- // Create a timeout promise
446
- const timeoutPromise = new Promise((_, reject) => {
447
- setTimeout(() => reject(new Error("Transaction receipt timeout")), timeoutMs);
448
- });
449
- // Race between waiting for receipt and timeout
450
- const receipt = await Promise.race([
451
- provider.waitForTransaction(txHash, 1, timeoutMs),
452
- timeoutPromise,
453
- ]);
454
- if (!receipt) {
455
- throw new Error("Transaction receipt not found");
456
- }
457
- // Check transaction status (ethers.js uses status: 0 for failed, 1 for success)
458
- if (receipt.status === 0) {
459
- throw new Error(`Transaction ${txHash} was reverted on-chain`);
460
- }
461
- if (enableLogging) {
462
- console.log(`Transaction ${txHash} confirmed successfully in block ${receipt.blockNumber}`);
426
+ const receipt = await provider.getTransactionReceipt(txHash);
427
+ if (receipt) {
428
+ if (receipt.status === 0) {
429
+ throw new Error(`Transaction ${txHash} was reverted on-chain`);
430
+ }
431
+ if (enableLogging) {
432
+ console.log(`Transaction ${txHash} confirmed successfully in block ${receipt.blockNumber}`);
433
+ }
434
+ return;
463
435
  }
464
- return; // Success, exit the function
465
436
  }
466
437
  catch (error) {
467
- lastError = error;
468
- // Check if it's a timeout or not found error
469
438
  const errorMessage = parseEthersError(error);
470
- const isRetryableError = errorMessage.includes("could not be found") ||
471
- errorMessage.includes("timeout") ||
472
- errorMessage.includes("timed out") ||
473
- errorMessage.includes("receipt") ||
474
- errorMessage.includes("not be processed") ||
475
- errorMessage.includes("Transaction receipt timeout");
476
- if (!isRetryableError || attempt === maxRetries) {
477
- // If it's not a retryable error or we've exhausted retries, throw
478
- throw new Error(`Transaction failed after ${attempt} attempts: ${errorMessage}`);
439
+ consecutiveErrors++;
440
+ if (consecutiveErrors >= maxRetries) {
441
+ throw new Error(`Transaction failed after ${consecutiveErrors} attempts: ${errorMessage}`);
479
442
  }
480
- // Wait before retrying (exponential backoff)
481
- const delay = Math.min(2000 * Math.pow(2, attempt - 1), 10000);
482
443
  if (enableLogging) {
483
- console.warn(`Transaction receipt not found (attempt ${attempt}/${maxRetries}), retrying in ${delay}ms...`);
484
- }
485
- await new Promise((resolve) => setTimeout(resolve, delay));
486
- // Check transaction status before retrying
487
- try {
488
- const provider = signer.provider;
489
- if (provider) {
490
- const transaction = await provider.getTransaction(txHash);
491
- if (!transaction) {
492
- throw new Error("Transaction not found in mempool or blockchain");
493
- }
494
- if (enableLogging) {
495
- console.log(`Transaction ${txHash} found in ${transaction.blockNumber ? "block" : "mempool"}, waiting for confirmation...`);
496
- }
497
- }
498
- }
499
- catch (txError) {
500
- if (enableLogging) {
501
- console.warn(`Could not fetch transaction ${txHash}: ${parseEthersError(txError)}`);
502
- }
503
- // Continue with retry anyway in case it's just an RPC issue
444
+ console.warn(`Error fetching receipt (attempt ${consecutiveErrors}/${maxRetries}), retrying in ${pollIntervalMs}ms...`);
504
445
  }
505
446
  }
447
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
506
448
  }
507
- // This should never be reached, but just in case
508
- throw new Error(`Transaction failed after ${maxRetries} attempts: ${parseEthersError(lastError)}`);
449
+ throw new Error(`Transaction receipt not found within ${timeoutMs}ms`);
509
450
  }
510
451
 
511
452
  let configuredClient = null;
@@ -725,7 +666,10 @@ function useForwarder(signer, CHAIN_ID) {
725
666
  setIsProcessing(true);
726
667
  // Approve only the specific amount needed
727
668
  const approveTx = await tokenContract.approve(ADDRESSES.FORWARDER, amount);
728
- await waitForEthersTransactionWithRetry(signer, approveTx.hash);
669
+ await waitForEthersTransactionWithRetry(signer, approveTx.hash, {
670
+ timeoutMs: 30000,
671
+ pollIntervalMs: 2000,
672
+ });
729
673
  return true;
730
674
  }
731
675
  catch (error) {
@@ -785,7 +729,10 @@ function useForwarder(signer, CHAIN_ID) {
785
729
  if (allowance < amount) {
786
730
  try {
787
731
  const approveTx = await tokenContract.approve(ADDRESSES.FORWARDER, ethers.MaxUint256);
788
- await waitForEthersTransactionWithRetry(signer, approveTx.hash);
732
+ await waitForEthersTransactionWithRetry(signer, approveTx.hash, {
733
+ timeoutMs: 30000,
734
+ pollIntervalMs: 2000,
735
+ });
789
736
  }
790
737
  catch (approveError) {
791
738
  sentryCaptureException(approveError, {
@@ -856,7 +803,10 @@ function useForwarder(signer, CHAIN_ID) {
856
803
  ? ADDRESSES.AUDIT_FEE_WALLET
857
804
  : ADDRESSES.FOUNDATION_WALLET, amount, sendToCounterfactualWallet, message);
858
805
  }
859
- await waitForEthersTransactionWithRetry(signer, tx.hash);
806
+ await waitForEthersTransactionWithRetry(signer, tx.hash, {
807
+ timeoutMs: 30000,
808
+ pollIntervalMs: 2000,
809
+ });
860
810
  return tx.hash;
861
811
  }
862
812
  catch (txError) {
@@ -1091,7 +1041,10 @@ function useForwarder(signer, CHAIN_ID) {
1091
1041
  setIsProcessing(true);
1092
1042
  // Try to call mint function (common for test tokens)
1093
1043
  const tx = await usdcContract.mint(recipient, amount);
1094
- await waitForEthersTransactionWithRetry(signer, tx.hash);
1044
+ await waitForEthersTransactionWithRetry(signer, tx.hash, {
1045
+ timeoutMs: 30000,
1046
+ pollIntervalMs: 2000,
1047
+ });
1095
1048
  return tx.hash;
1096
1049
  }
1097
1050
  catch (error) {
@@ -4283,4 +4236,4 @@ exports.useForwarder = useForwarder;
4283
4236
  exports.useOffchainFractions = useOffchainFractions;
4284
4237
  exports.waitForEthersTransactionWithRetry = waitForEthersTransactionWithRetry;
4285
4238
  exports.waitForViemTransactionWithRetry = waitForViemTransactionWithRetry;
4286
- //# sourceMappingURL=farms-router-C8V_F0vY.js.map
4239
+ //# sourceMappingURL=farms-router-Cg0-zSMT.js.map