@glowlabs-org/utils 0.2.175 → 0.2.177
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/{calculate-farm-efficiency-psH9YXnF.js → calculate-farm-efficiency-DQqLqk0-.js} +74 -7
- package/dist/cjs/calculate-farm-efficiency-DQqLqk0-.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{calculate-farm-efficiency-DvqnF04d.js → calculate-farm-efficiency-BjXQqtxI.js} +74 -7
- package/dist/esm/calculate-farm-efficiency-BjXQqtxI.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/package.json +1 -1
- package/src/lib/hooks/use-forwarder.ts +12 -10
- package/src/lib/hooks/use-offchain-fractions.ts +14 -0
- package/src/utils/transaction-utils.ts +68 -5
- package/dist/cjs/calculate-farm-efficiency-psH9YXnF.js.map +0 -1
- package/dist/esm/calculate-farm-efficiency-DvqnF04d.js.map +0 -1
package/dist/cjs/browser.js
CHANGED
package/dist/cjs/{calculate-farm-efficiency-psH9YXnF.js → calculate-farm-efficiency-DQqLqk0-.js}
RENAMED
|
@@ -316,13 +316,67 @@ function parseViemError(error) {
|
|
|
316
316
|
return "Unknown error";
|
|
317
317
|
// Check if it's a viem BaseError
|
|
318
318
|
if (error instanceof Error) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
319
|
+
const anyError = error;
|
|
320
|
+
// Use viem's walk() method if available to find ContractFunctionRevertedError
|
|
321
|
+
if (typeof anyError.walk === "function") {
|
|
322
|
+
let foundErrorName = null;
|
|
323
|
+
anyError.walk((err) => {
|
|
324
|
+
if (err?.data?.errorName && !foundErrorName) {
|
|
325
|
+
foundErrorName = err.data.errorName;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
if (foundErrorName) {
|
|
329
|
+
return foundErrorName;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// For viem ContractFunctionRevertedError - extract the custom error name
|
|
333
|
+
// This handles Solidity custom errors like `InsufficientSharesAvailable()`
|
|
334
|
+
if (anyError.cause?.data?.errorName) {
|
|
335
|
+
return anyError.cause.data.errorName;
|
|
336
|
+
}
|
|
337
|
+
// Check direct data.errorName (viem 2.x structure)
|
|
338
|
+
if (anyError.data?.errorName) {
|
|
339
|
+
return anyError.data.errorName;
|
|
340
|
+
}
|
|
341
|
+
// Check for error name in the cause directly (some viem versions)
|
|
342
|
+
if (anyError.cause?.name && anyError.cause.name !== "Error") {
|
|
343
|
+
return anyError.cause.name;
|
|
344
|
+
}
|
|
345
|
+
// For contract revert errors with reason
|
|
346
|
+
if (anyError.cause?.reason) {
|
|
347
|
+
return anyError.cause.reason;
|
|
348
|
+
}
|
|
349
|
+
// Check metaMessages for custom error info (viem includes this sometimes)
|
|
350
|
+
if (anyError.metaMessages && Array.isArray(anyError.metaMessages)) {
|
|
351
|
+
for (const meta of anyError.metaMessages) {
|
|
352
|
+
if (typeof meta === "string" && meta.includes("Error:")) {
|
|
353
|
+
const match = meta.match(/Error:\s*(\w+)\(/);
|
|
354
|
+
if (match?.[1]) {
|
|
355
|
+
return match[1];
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// Check if the error message contains a custom error signature
|
|
361
|
+
// viem sometimes formats it as: reverted with the following reason: ErrorName()
|
|
362
|
+
const fullMessage = anyError.message || "";
|
|
363
|
+
const shortMessage = anyError.shortMessage || "";
|
|
364
|
+
// Pattern: "Error: ErrorName()" in message
|
|
365
|
+
const errorPatterns = [
|
|
366
|
+
/Error:\s*(\w+)\(\)/,
|
|
367
|
+
/reverted with the following reason:\s*(\w+)\(\)/,
|
|
368
|
+
/reverted\.\s*(\w+)\(\)/,
|
|
369
|
+
/execution reverted:\s*(\w+)/i,
|
|
370
|
+
];
|
|
371
|
+
for (const pattern of errorPatterns) {
|
|
372
|
+
const match = fullMessage.match(pattern) || shortMessage.match(pattern);
|
|
373
|
+
if (match?.[1]) {
|
|
374
|
+
return match[1];
|
|
375
|
+
}
|
|
322
376
|
}
|
|
323
377
|
// For viem's shortMessage
|
|
324
|
-
if (
|
|
325
|
-
return
|
|
378
|
+
if (shortMessage) {
|
|
379
|
+
return shortMessage;
|
|
326
380
|
}
|
|
327
381
|
// Fallback to regular message
|
|
328
382
|
if (error.message) {
|
|
@@ -954,7 +1008,9 @@ function useForwarder(signer, CHAIN_ID, publicClient, walletClient) {
|
|
|
954
1008
|
.staticCall(amount, ADDRESSES.FOUNDATION_WALLET, sendToCounterfactualWallet, message, { from: owner });
|
|
955
1009
|
}
|
|
956
1010
|
else {
|
|
957
|
-
await forwarderContract
|
|
1011
|
+
await forwarderContract
|
|
1012
|
+
.getFunction("forward")
|
|
1013
|
+
.staticCall(tokenAddress, isAuditFees
|
|
958
1014
|
? ADDRESSES.AUDIT_FEE_WALLET
|
|
959
1015
|
: ADDRESSES.FOUNDATION_WALLET, amount, sendToCounterfactualWallet, message, { from: owner });
|
|
960
1016
|
}
|
|
@@ -2014,6 +2070,17 @@ function useOffchainFractions(walletClient, publicClient, CHAIN_ID) {
|
|
|
2014
2070
|
account: walletClient.account,
|
|
2015
2071
|
});
|
|
2016
2072
|
await waitForViemTransactionWithRetry(publicClient, approveHash);
|
|
2073
|
+
// Verify allowance is reflected before proceeding (RPC lag mitigation)
|
|
2074
|
+
const maxAllowanceChecks = 5;
|
|
2075
|
+
const allowanceCheckDelayMs = 500;
|
|
2076
|
+
for (let i = 0; i < maxAllowanceChecks; i++) {
|
|
2077
|
+
const updatedAllowance = await checkTokenAllowance(owner, fractionData.token);
|
|
2078
|
+
if (updatedAllowance >= requiredAmount)
|
|
2079
|
+
break;
|
|
2080
|
+
if (i < maxAllowanceChecks - 1) {
|
|
2081
|
+
await new Promise((r) => setTimeout(r, allowanceCheckDelayMs));
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2017
2084
|
}
|
|
2018
2085
|
// Run a simulation first to surface any revert reason
|
|
2019
2086
|
try {
|
|
@@ -5521,4 +5588,4 @@ exports.useOffchainFractions = useOffchainFractions;
|
|
|
5521
5588
|
exports.useRewardsKernel = useRewardsKernel;
|
|
5522
5589
|
exports.waitForEthersTransactionWithRetry = waitForEthersTransactionWithRetry;
|
|
5523
5590
|
exports.waitForViemTransactionWithRetry = waitForViemTransactionWithRetry;
|
|
5524
|
-
//# sourceMappingURL=calculate-farm-efficiency-
|
|
5591
|
+
//# sourceMappingURL=calculate-farm-efficiency-DQqLqk0-.js.map
|