@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.
- package/dist/cjs/browser.js +1 -1
- package/dist/cjs/{farms-router-C8V_F0vY.js → farms-router-Cg0-zSMT.js} +68 -115
- package/dist/cjs/farms-router-Cg0-zSMT.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/utils/transaction-utils.d.ts +1 -0
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{farms-router-C_7Ys4An.js → farms-router-PZUo1LyW.js} +68 -115
- package/dist/esm/farms-router-PZUo1LyW.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/transaction-utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/constants/addresses.ts +2 -2
- package/src/lib/hooks/use-forwarder.ts +16 -4
- package/src/utils/transaction-utils.ts +61 -154
- package/dist/cjs/farms-router-C8V_F0vY.js.map +0 -1
- package/dist/esm/farms-router-C_7Ys4An.js.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var viem = require('viem');
|
|
|
15
15
|
var merkletreejs = require('merkletreejs');
|
|
16
16
|
var ethers = require('ethers');
|
|
17
17
|
var Decimal = require('decimal.js');
|
|
18
|
-
var farmsRouter = require('./farms-router-
|
|
18
|
+
var farmsRouter = require('./farms-router-Cg0-zSMT.js');
|
|
19
19
|
|
|
20
20
|
const GENESIS_TIMESTAMP = 1700352000;
|
|
21
21
|
|
package/dist/esm/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TRANSFER_TYPES } from './farms-router-
|
|
2
|
-
export { C as ControlRouter, D as DECIMALS_BY_TOKEN, j as FORWARDER_ABI, F as FarmsRouter, e as ForwarderError, m as GCA_URLS, G as GLOW_WEIGHT_DECIMAL_PRECISION, H as HUB_URL, d as KICKSTARTER_STATUS, K as KickstarterRouter, M as MAX_WEIGHT, k as OFFCHAIN_FRACTIONS_ABI, O as OFF_CHAIN_PAYMENT_CURRENCIES, f as OffchainFractionsError, P as PAYMENT_CURRENCIES, b as REGIONS, R as RegionRouter, S as STAKING_DIRECTIONS, U as USDG_WEIGHT_DECIMAL_PRECISION, W as WalletsRouter, g as allRegions, c as configureSentry, i as countries, l as getAddresses, n as parseEthersError, p as parseViemError, r as regionMetadata, h as usStates, u as useForwarder, a as useOffchainFractions, o as waitForEthersTransactionWithRetry, w as waitForViemTransactionWithRetry } from './farms-router-
|
|
1
|
+
import { T as TRANSFER_TYPES } from './farms-router-PZUo1LyW.js';
|
|
2
|
+
export { C as ControlRouter, D as DECIMALS_BY_TOKEN, j as FORWARDER_ABI, F as FarmsRouter, e as ForwarderError, m as GCA_URLS, G as GLOW_WEIGHT_DECIMAL_PRECISION, H as HUB_URL, d as KICKSTARTER_STATUS, K as KickstarterRouter, M as MAX_WEIGHT, k as OFFCHAIN_FRACTIONS_ABI, O as OFF_CHAIN_PAYMENT_CURRENCIES, f as OffchainFractionsError, P as PAYMENT_CURRENCIES, b as REGIONS, R as RegionRouter, S as STAKING_DIRECTIONS, U as USDG_WEIGHT_DECIMAL_PRECISION, W as WalletsRouter, g as allRegions, c as configureSentry, i as countries, l as getAddresses, n as parseEthersError, p as parseViemError, r as regionMetadata, h as usStates, u as useForwarder, a as useOffchainFractions, o as waitForEthersTransactionWithRetry, w as waitForViemTransactionWithRetry } from './farms-router-PZUo1LyW.js';
|
|
3
3
|
import { verifyTypedData, checksumAddress } from 'viem';
|
|
4
4
|
import 'ethers';
|
|
5
5
|
|
|
@@ -272,8 +272,8 @@ const sepoliaAddresses = {
|
|
|
272
272
|
USDC: "0x93c898be98cd2618ba84a6dccf5003d3bbe40356",
|
|
273
273
|
USDG_UNISWAP: "0x2a085A3aEA8982396533327c854753Ce521B666d",
|
|
274
274
|
GLW_UNISWAP: "0x8e27016D0B866a56CE74A1a280c749dD679bb0Fa",
|
|
275
|
-
FORWARDER: "
|
|
276
|
-
OFFCHAIN_FRACTIONS: "
|
|
275
|
+
FORWARDER: "0xe7A366482899e2Ed29c9504F4792B8D1c67066ff",
|
|
276
|
+
OFFCHAIN_FRACTIONS: "0x5Ad30F90AFEf1279157A5055AAd2d8c1529a05D2",
|
|
277
277
|
COUNTERFACTUAL_HOLDER_FACTORY: "0x2c3AB887746F6f4a8a4b9Db6aC800eb71945509A",
|
|
278
278
|
FOUNDATION_WALLET: "0x5e230FED487c86B90f6508104149F087d9B1B0A7",
|
|
279
279
|
FOUNDATION_HUB_MANAGER_WALLET: "0x5252FdA14A149c01EA5A1D6514a9c1369E4C70b4",
|
|
@@ -352,6 +352,7 @@ const DEFAULT_OPTIONS = {
|
|
|
352
352
|
maxRetries: 3,
|
|
353
353
|
timeoutMs: 60000,
|
|
354
354
|
enableLogging: true,
|
|
355
|
+
pollIntervalMs: 2000,
|
|
355
356
|
};
|
|
356
357
|
/**
|
|
357
358
|
* Enhanced transaction receipt handler with retry logic for viem
|
|
@@ -360,66 +361,46 @@ const DEFAULT_OPTIONS = {
|
|
|
360
361
|
* @param options Retry configuration options
|
|
361
362
|
*/
|
|
362
363
|
async function waitForViemTransactionWithRetry(publicClient, hash, options = {}) {
|
|
363
|
-
const { maxRetries, timeoutMs, enableLogging } = {
|
|
364
|
+
const { maxRetries, timeoutMs, enableLogging, pollIntervalMs } = {
|
|
364
365
|
...DEFAULT_OPTIONS,
|
|
365
366
|
...options,
|
|
366
367
|
};
|
|
367
|
-
|
|
368
|
-
|
|
368
|
+
const deadline = Date.now() + timeoutMs;
|
|
369
|
+
let consecutiveErrors = 0;
|
|
370
|
+
while (Date.now() < deadline) {
|
|
369
371
|
try {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (enableLogging) {
|
|
380
|
-
console.log(`Transaction ${hash} confirmed successfully in block ${receipt.blockNumber}`);
|
|
372
|
+
const receipt = await publicClient.getTransactionReceipt({ hash });
|
|
373
|
+
if (receipt) {
|
|
374
|
+
if (receipt.status === "reverted") {
|
|
375
|
+
throw new Error(`Transaction ${hash} was reverted on-chain`);
|
|
376
|
+
}
|
|
377
|
+
if (enableLogging) {
|
|
378
|
+
console.log(`Transaction ${hash} confirmed successfully in block ${receipt.blockNumber}`);
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
381
|
}
|
|
382
|
-
return; // Success, exit the function
|
|
383
382
|
}
|
|
384
383
|
catch (error) {
|
|
385
|
-
lastError = error;
|
|
386
|
-
// Check if it's a timeout or not found error
|
|
387
384
|
const errorMessage = parseViemError(error);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
errorMessage.includes("
|
|
385
|
+
// Treat not found/receipt missing as retryable without counting towards errors
|
|
386
|
+
const isNotFound = errorMessage.includes("not found") ||
|
|
387
|
+
errorMessage.includes("could not be found") ||
|
|
391
388
|
errorMessage.includes("receipt") ||
|
|
392
|
-
errorMessage.includes("not
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const delay = Math.min(2000 * Math.pow(2, attempt - 1), 10000);
|
|
399
|
-
if (enableLogging) {
|
|
400
|
-
console.warn(`Transaction receipt not found (attempt ${attempt}/${maxRetries}), retrying in ${delay}ms...`);
|
|
401
|
-
}
|
|
402
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
403
|
-
// Check transaction status before retrying
|
|
404
|
-
try {
|
|
405
|
-
const transaction = await publicClient.getTransaction({ hash });
|
|
406
|
-
if (!transaction) {
|
|
407
|
-
throw new Error("Transaction not found in mempool or blockchain");
|
|
408
|
-
}
|
|
409
|
-
if (enableLogging) {
|
|
410
|
-
console.log(`Transaction ${hash} found in ${transaction.blockNumber ? "block" : "mempool"}, waiting for confirmation...`);
|
|
389
|
+
errorMessage.includes("not confirmed") ||
|
|
390
|
+
errorMessage.includes("TransactionReceiptNotFound");
|
|
391
|
+
if (!isNotFound) {
|
|
392
|
+
consecutiveErrors++;
|
|
393
|
+
if (consecutiveErrors >= maxRetries) {
|
|
394
|
+
throw new Error(`Transaction failed after ${consecutiveErrors} attempts: ${errorMessage}`);
|
|
411
395
|
}
|
|
412
|
-
}
|
|
413
|
-
catch (txError) {
|
|
414
396
|
if (enableLogging) {
|
|
415
|
-
console.warn(`
|
|
397
|
+
console.warn(`Error fetching receipt (attempt ${consecutiveErrors}/${maxRetries}), retrying in ${pollIntervalMs}ms...`);
|
|
416
398
|
}
|
|
417
|
-
// Continue with retry anyway in case it's just an RPC issue
|
|
418
399
|
}
|
|
419
400
|
}
|
|
401
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
420
402
|
}
|
|
421
|
-
|
|
422
|
-
throw new Error(`Transaction failed after ${maxRetries} attempts: ${parseViemError(lastError)}`);
|
|
403
|
+
throw new Error(`Transaction receipt not found within ${timeoutMs}ms`);
|
|
423
404
|
}
|
|
424
405
|
/**
|
|
425
406
|
* Enhanced transaction receipt handler with retry logic for ethers.js
|
|
@@ -428,82 +409,42 @@ async function waitForViemTransactionWithRetry(publicClient, hash, options = {})
|
|
|
428
409
|
* @param options Retry configuration options
|
|
429
410
|
*/
|
|
430
411
|
async function waitForEthersTransactionWithRetry(signer, txHash, options = {}) {
|
|
431
|
-
const { maxRetries, timeoutMs, enableLogging } = {
|
|
412
|
+
const { maxRetries, timeoutMs, enableLogging, pollIntervalMs } = {
|
|
432
413
|
...DEFAULT_OPTIONS,
|
|
433
414
|
...options,
|
|
434
415
|
};
|
|
435
|
-
|
|
436
|
-
|
|
416
|
+
const provider = signer.provider;
|
|
417
|
+
if (!provider) {
|
|
418
|
+
throw new Error("Provider not available");
|
|
419
|
+
}
|
|
420
|
+
const deadline = Date.now() + timeoutMs;
|
|
421
|
+
let consecutiveErrors = 0;
|
|
422
|
+
while (Date.now() < deadline) {
|
|
437
423
|
try {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
// Race between waiting for receipt and timeout
|
|
448
|
-
const receipt = await Promise.race([
|
|
449
|
-
provider.waitForTransaction(txHash, 1, timeoutMs),
|
|
450
|
-
timeoutPromise,
|
|
451
|
-
]);
|
|
452
|
-
if (!receipt) {
|
|
453
|
-
throw new Error("Transaction receipt not found");
|
|
454
|
-
}
|
|
455
|
-
// Check transaction status (ethers.js uses status: 0 for failed, 1 for success)
|
|
456
|
-
if (receipt.status === 0) {
|
|
457
|
-
throw new Error(`Transaction ${txHash} was reverted on-chain`);
|
|
458
|
-
}
|
|
459
|
-
if (enableLogging) {
|
|
460
|
-
console.log(`Transaction ${txHash} confirmed successfully in block ${receipt.blockNumber}`);
|
|
424
|
+
const receipt = await provider.getTransactionReceipt(txHash);
|
|
425
|
+
if (receipt) {
|
|
426
|
+
if (receipt.status === 0) {
|
|
427
|
+
throw new Error(`Transaction ${txHash} was reverted on-chain`);
|
|
428
|
+
}
|
|
429
|
+
if (enableLogging) {
|
|
430
|
+
console.log(`Transaction ${txHash} confirmed successfully in block ${receipt.blockNumber}`);
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
461
433
|
}
|
|
462
|
-
return; // Success, exit the function
|
|
463
434
|
}
|
|
464
435
|
catch (error) {
|
|
465
|
-
lastError = error;
|
|
466
|
-
// Check if it's a timeout or not found error
|
|
467
436
|
const errorMessage = parseEthersError(error);
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
errorMessage.includes("receipt") ||
|
|
472
|
-
errorMessage.includes("not be processed") ||
|
|
473
|
-
errorMessage.includes("Transaction receipt timeout");
|
|
474
|
-
if (!isRetryableError || attempt === maxRetries) {
|
|
475
|
-
// If it's not a retryable error or we've exhausted retries, throw
|
|
476
|
-
throw new Error(`Transaction failed after ${attempt} attempts: ${errorMessage}`);
|
|
437
|
+
consecutiveErrors++;
|
|
438
|
+
if (consecutiveErrors >= maxRetries) {
|
|
439
|
+
throw new Error(`Transaction failed after ${consecutiveErrors} attempts: ${errorMessage}`);
|
|
477
440
|
}
|
|
478
|
-
// Wait before retrying (exponential backoff)
|
|
479
|
-
const delay = Math.min(2000 * Math.pow(2, attempt - 1), 10000);
|
|
480
441
|
if (enableLogging) {
|
|
481
|
-
console.warn(`
|
|
482
|
-
}
|
|
483
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
484
|
-
// Check transaction status before retrying
|
|
485
|
-
try {
|
|
486
|
-
const provider = signer.provider;
|
|
487
|
-
if (provider) {
|
|
488
|
-
const transaction = await provider.getTransaction(txHash);
|
|
489
|
-
if (!transaction) {
|
|
490
|
-
throw new Error("Transaction not found in mempool or blockchain");
|
|
491
|
-
}
|
|
492
|
-
if (enableLogging) {
|
|
493
|
-
console.log(`Transaction ${txHash} found in ${transaction.blockNumber ? "block" : "mempool"}, waiting for confirmation...`);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
catch (txError) {
|
|
498
|
-
if (enableLogging) {
|
|
499
|
-
console.warn(`Could not fetch transaction ${txHash}: ${parseEthersError(txError)}`);
|
|
500
|
-
}
|
|
501
|
-
// Continue with retry anyway in case it's just an RPC issue
|
|
442
|
+
console.warn(`Error fetching receipt (attempt ${consecutiveErrors}/${maxRetries}), retrying in ${pollIntervalMs}ms...`);
|
|
502
443
|
}
|
|
503
444
|
}
|
|
445
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
504
446
|
}
|
|
505
|
-
|
|
506
|
-
throw new Error(`Transaction failed after ${maxRetries} attempts: ${parseEthersError(lastError)}`);
|
|
447
|
+
throw new Error(`Transaction receipt not found within ${timeoutMs}ms`);
|
|
507
448
|
}
|
|
508
449
|
|
|
509
450
|
let configuredClient = null;
|
|
@@ -723,7 +664,10 @@ function useForwarder(signer, CHAIN_ID) {
|
|
|
723
664
|
setIsProcessing(true);
|
|
724
665
|
// Approve only the specific amount needed
|
|
725
666
|
const approveTx = await tokenContract.approve(ADDRESSES.FORWARDER, amount);
|
|
726
|
-
await waitForEthersTransactionWithRetry(signer, approveTx.hash
|
|
667
|
+
await waitForEthersTransactionWithRetry(signer, approveTx.hash, {
|
|
668
|
+
timeoutMs: 30000,
|
|
669
|
+
pollIntervalMs: 2000,
|
|
670
|
+
});
|
|
727
671
|
return true;
|
|
728
672
|
}
|
|
729
673
|
catch (error) {
|
|
@@ -783,7 +727,10 @@ function useForwarder(signer, CHAIN_ID) {
|
|
|
783
727
|
if (allowance < amount) {
|
|
784
728
|
try {
|
|
785
729
|
const approveTx = await tokenContract.approve(ADDRESSES.FORWARDER, MaxUint256);
|
|
786
|
-
await waitForEthersTransactionWithRetry(signer, approveTx.hash
|
|
730
|
+
await waitForEthersTransactionWithRetry(signer, approveTx.hash, {
|
|
731
|
+
timeoutMs: 30000,
|
|
732
|
+
pollIntervalMs: 2000,
|
|
733
|
+
});
|
|
787
734
|
}
|
|
788
735
|
catch (approveError) {
|
|
789
736
|
sentryCaptureException(approveError, {
|
|
@@ -854,7 +801,10 @@ function useForwarder(signer, CHAIN_ID) {
|
|
|
854
801
|
? ADDRESSES.AUDIT_FEE_WALLET
|
|
855
802
|
: ADDRESSES.FOUNDATION_WALLET, amount, sendToCounterfactualWallet, message);
|
|
856
803
|
}
|
|
857
|
-
await waitForEthersTransactionWithRetry(signer, tx.hash
|
|
804
|
+
await waitForEthersTransactionWithRetry(signer, tx.hash, {
|
|
805
|
+
timeoutMs: 30000,
|
|
806
|
+
pollIntervalMs: 2000,
|
|
807
|
+
});
|
|
858
808
|
return tx.hash;
|
|
859
809
|
}
|
|
860
810
|
catch (txError) {
|
|
@@ -1089,7 +1039,10 @@ function useForwarder(signer, CHAIN_ID) {
|
|
|
1089
1039
|
setIsProcessing(true);
|
|
1090
1040
|
// Try to call mint function (common for test tokens)
|
|
1091
1041
|
const tx = await usdcContract.mint(recipient, amount);
|
|
1092
|
-
await waitForEthersTransactionWithRetry(signer, tx.hash
|
|
1042
|
+
await waitForEthersTransactionWithRetry(signer, tx.hash, {
|
|
1043
|
+
timeoutMs: 30000,
|
|
1044
|
+
pollIntervalMs: 2000,
|
|
1045
|
+
});
|
|
1093
1046
|
return tx.hash;
|
|
1094
1047
|
}
|
|
1095
1048
|
catch (error) {
|
|
@@ -4254,4 +4207,4 @@ function FarmsRouter(baseUrl) {
|
|
|
4254
4207
|
}
|
|
4255
4208
|
|
|
4256
4209
|
export { ControlRouter as C, DECIMALS_BY_TOKEN as D, FarmsRouter as F, GLOW_WEIGHT_DECIMAL_PRECISION as G, HUB_URL as H, KickstarterRouter as K, MAX_WEIGHT as M, OFF_CHAIN_PAYMENT_CURRENCIES as O, PAYMENT_CURRENCIES as P, RegionRouter as R, STAKING_DIRECTIONS as S, TRANSFER_TYPES as T, USDG_WEIGHT_DECIMAL_PRECISION as U, WalletsRouter as W, useOffchainFractions as a, REGIONS as b, configureSentry as c, KICKSTARTER_STATUS as d, ForwarderError as e, OffchainFractionsError as f, allRegions as g, usStates as h, countries as i, FORWARDER_ABI as j, OFFCHAIN_FRACTIONS_ABI as k, getAddresses as l, GCA_URLS as m, parseEthersError as n, waitForEthersTransactionWithRetry as o, parseViemError as p, regionMetadata as r, useForwarder as u, waitForViemTransactionWithRetry as w };
|
|
4257
|
-
//# sourceMappingURL=farms-router-
|
|
4210
|
+
//# sourceMappingURL=farms-router-PZUo1LyW.js.map
|