@glowlabs-org/utils 0.2.176 → 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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var calculateFarmEfficiency = require('./calculate-farm-efficiency-z9p1HOmd.js');
3
+ var calculateFarmEfficiency = require('./calculate-farm-efficiency-DQqLqk0-.js');
4
4
  require('decimal.js');
5
5
  var viem = require('viem');
6
6
  require('ethers');
@@ -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
- // For contract revert errors
320
- if (error.cause?.reason) {
321
- return error.cause.reason;
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 (error.shortMessage) {
325
- return error.shortMessage;
378
+ if (shortMessage) {
379
+ return shortMessage;
326
380
  }
327
381
  // Fallback to regular message
328
382
  if (error.message) {
@@ -5534,4 +5588,4 @@ exports.useOffchainFractions = useOffchainFractions;
5534
5588
  exports.useRewardsKernel = useRewardsKernel;
5535
5589
  exports.waitForEthersTransactionWithRetry = waitForEthersTransactionWithRetry;
5536
5590
  exports.waitForViemTransactionWithRetry = waitForViemTransactionWithRetry;
5537
- //# sourceMappingURL=calculate-farm-efficiency-z9p1HOmd.js.map
5591
+ //# sourceMappingURL=calculate-farm-efficiency-DQqLqk0-.js.map