@seljs/runtime 1.3.0-beta.33 → 1.3.0-beta.34

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.
@@ -3,8 +3,18 @@ const require_errors = require("../errors/errors.cjs");
3
3
  require("../errors/index.cjs");
4
4
  const require_replay_cache = require("./replay-cache.cjs");
5
5
  const require_debug = require("../debug.cjs");
6
+ const require_decode_revert = require("../execution/decode-revert.cjs");
6
7
  let ox = require("ox");
8
+ let viem = require("viem");
7
9
  //#region src/environment/contract-caller.ts
10
+ const extractRevertData = (error) => {
11
+ if (!(error instanceof viem.BaseError)) return;
12
+ return error.walk((e) => {
13
+ if (typeof e !== "object" || e === null) return false;
14
+ const data = e.data;
15
+ return typeof data === "string" && data.startsWith("0x");
16
+ })?.data;
17
+ };
8
18
  const debug = require_debug.createLogger("contract-caller");
9
19
  /**
10
20
  * Tracks total RPC calls (pre-executed + live) across a single evaluation.
@@ -54,7 +64,21 @@ const executeContractCall = async (contract, method, args, options) => {
54
64
  return ox.AbiFunction.decodeResult([method.abi], method.name, result.data);
55
65
  } catch (error) {
56
66
  if (error instanceof require_errors.SELContractError) throw error;
57
- throw new require_errors.SELContractError(`Contract call failed: ${contract.name}.${method.name}`, {
67
+ const revertData = extractRevertData(error);
68
+ if (revertData !== void 0) {
69
+ const decoded = require_decode_revert.decodeRevertData(revertData, [method.abi]);
70
+ const suffix = decoded.reason ? ` — ${decoded.reason}` : "";
71
+ throw new require_errors.SELContractRevertError(`Call reverted: ${contract.name}.${method.name}${suffix}`, {
72
+ cause: error,
73
+ contractName: contract.name,
74
+ methodName: method.name,
75
+ revertReason: decoded.reason,
76
+ revertData: decoded.data,
77
+ decodedError: decoded.decodedError
78
+ });
79
+ }
80
+ const detail = error instanceof Error ? error.message : String(error);
81
+ throw new require_errors.SELContractError(`Contract call failed: ${contract.name}.${method.name}: ${detail}`, {
58
82
  cause: error,
59
83
  contractName: contract.name,
60
84
  methodName: method.name
@@ -1,9 +1,19 @@
1
- import { SELContractError, SELExecutionLimitError } from "../errors/errors.mjs";
1
+ import { SELContractError, SELContractRevertError, SELExecutionLimitError } from "../errors/errors.mjs";
2
2
  import "../errors/index.mjs";
3
3
  import { createReplayCallId } from "./replay-cache.mjs";
4
4
  import { createLogger } from "../debug.mjs";
5
+ import { decodeRevertData } from "../execution/decode-revert.mjs";
5
6
  import { AbiFunction } from "ox";
7
+ import { BaseError } from "viem";
6
8
  //#region src/environment/contract-caller.ts
9
+ const extractRevertData = (error) => {
10
+ if (!(error instanceof BaseError)) return;
11
+ return error.walk((e) => {
12
+ if (typeof e !== "object" || e === null) return false;
13
+ const data = e.data;
14
+ return typeof data === "string" && data.startsWith("0x");
15
+ })?.data;
16
+ };
7
17
  const debug = createLogger("contract-caller");
8
18
  /**
9
19
  * Tracks total RPC calls (pre-executed + live) across a single evaluation.
@@ -53,7 +63,21 @@ const executeContractCall = async (contract, method, args, options) => {
53
63
  return AbiFunction.decodeResult([method.abi], method.name, result.data);
54
64
  } catch (error) {
55
65
  if (error instanceof SELContractError) throw error;
56
- throw new SELContractError(`Contract call failed: ${contract.name}.${method.name}`, {
66
+ const revertData = extractRevertData(error);
67
+ if (revertData !== void 0) {
68
+ const decoded = decodeRevertData(revertData, [method.abi]);
69
+ const suffix = decoded.reason ? ` — ${decoded.reason}` : "";
70
+ throw new SELContractRevertError(`Call reverted: ${contract.name}.${method.name}${suffix}`, {
71
+ cause: error,
72
+ contractName: contract.name,
73
+ methodName: method.name,
74
+ revertReason: decoded.reason,
75
+ revertData: decoded.data,
76
+ decodedError: decoded.decodedError
77
+ });
78
+ }
79
+ const detail = error instanceof Error ? error.message : String(error);
80
+ throw new SELContractError(`Contract call failed: ${contract.name}.${method.name}: ${detail}`, {
57
81
  cause: error,
58
82
  contractName: contract.name,
59
83
  methodName: method.name
@@ -207,7 +207,8 @@ var SELRuntime = class {
207
207
  } else if (typeof error.failedCallIndex === "number") failedCall = collectedCalls[error.failedCallIndex] ?? failedCall;
208
208
  }
209
209
  if (!failedCall) throw error;
210
- throw new require_errors.SELContractError(`Contract call failed: ${failedCall.contract}.${failedCall.method}`, {
210
+ const detail = error instanceof Error ? error.message : String(error);
211
+ throw new require_errors.SELContractError(`Contract call failed: ${failedCall.contract}.${failedCall.method}: ${detail}`, {
211
212
  cause: error,
212
213
  contractName: failedCall.contract,
213
214
  methodName: failedCall.method
@@ -206,7 +206,8 @@ var SELRuntime = class {
206
206
  } else if (typeof error.failedCallIndex === "number") failedCall = collectedCalls[error.failedCallIndex] ?? failedCall;
207
207
  }
208
208
  if (!failedCall) throw error;
209
- throw new SELContractError(`Contract call failed: ${failedCall.contract}.${failedCall.method}`, {
209
+ const detail = error instanceof Error ? error.message : String(error);
210
+ throw new SELContractError(`Contract call failed: ${failedCall.contract}.${failedCall.method}: ${detail}`, {
210
211
  cause: error,
211
212
  contractName: failedCall.contract,
212
213
  methodName: failedCall.method
@@ -2,8 +2,8 @@ require("../_virtual/_rolldown/runtime.cjs");
2
2
  const require_errors = require("../errors/errors.cjs");
3
3
  require("../errors/index.cjs");
4
4
  let _seljs_common = require("@seljs/common");
5
- let _marcbachmann_cel_js = require("@marcbachmann/cel-js");
6
5
  let viem = require("viem");
6
+ let _marcbachmann_cel_js = require("@marcbachmann/cel-js");
7
7
  //#region src/environment/error-wrapper.ts
8
8
  /**
9
9
  * Compose a human-readable message from a viem error. Uses `shortMessage`
@@ -1,8 +1,8 @@
1
1
  import { SELContractError, SELContractRevertError, SELProviderError, SELProviderRpcError, SELProviderTransportError } from "../errors/errors.mjs";
2
2
  import "../errors/index.mjs";
3
3
  import { SELError, SELEvaluationError, SELParseError, SELTypeCheckError } from "@seljs/common";
4
- import { EvaluationError, ParseError, TypeError } from "@marcbachmann/cel-js";
5
4
  import { AbiDecodingDataSizeInvalidError, AbiDecodingZeroDataError, AbiErrorSignatureNotFoundError, BaseError, ContractFunctionExecutionError, ContractFunctionRevertedError, HttpRequestError, RpcError, TimeoutError, WebSocketRequestError } from "viem";
5
+ import { EvaluationError, ParseError, TypeError } from "@marcbachmann/cel-js";
6
6
  //#region src/environment/error-wrapper.ts
7
7
  /**
8
8
  * Compose a human-readable message from a viem error. Uses `shortMessage`
@@ -18,7 +18,10 @@ const PANIC_CODES = {
18
18
  const errorStringAbi = ox.AbiError.from("error Error(string reason)");
19
19
  const panicAbi = ox.AbiError.from("error Panic(uint256 code)");
20
20
  function decodeRevertData(data, abi) {
21
- if (data === "0x" || data.length < 10) return { data };
21
+ if (data === "0x" || data.length < 10) return {
22
+ data,
23
+ reason: "reverted without data"
24
+ };
22
25
  const selector = data.slice(0, 10).toLowerCase();
23
26
  if (selector === ERROR_STRING_SELECTOR) try {
24
27
  return {
@@ -17,7 +17,10 @@ const PANIC_CODES = {
17
17
  const errorStringAbi = AbiError.from("error Error(string reason)");
18
18
  const panicAbi = AbiError.from("error Panic(uint256 code)");
19
19
  function decodeRevertData(data, abi) {
20
- if (data === "0x" || data.length < 10) return { data };
20
+ if (data === "0x" || data.length < 10) return {
21
+ data,
22
+ reason: "reverted without data"
23
+ };
21
24
  const selector = data.slice(0, 10).toLowerCase();
22
25
  if (selector === ERROR_STRING_SELECTOR) try {
23
26
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seljs/runtime",
3
- "version": "1.3.0-beta.33",
3
+ "version": "1.3.0-beta.34",
4
4
  "repository": {
5
5
  "url": "https://github.com/abinnovision/seljs"
6
6
  },
@@ -50,11 +50,11 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@marcbachmann/cel-js": "^7.5.3",
53
- "@seljs/checker": "1.3.0-beta.33",
54
- "@seljs/common": "1.3.0-beta.33",
55
- "@seljs/env": "1.3.0-beta.33",
53
+ "@seljs/checker": "1.3.0-beta.34",
54
+ "@seljs/common": "1.3.0-beta.34",
55
+ "@seljs/env": "1.3.0-beta.34",
56
56
  "@seljs/schema": "1.2.0",
57
- "@seljs/types": "1.3.0-beta.33",
57
+ "@seljs/types": "1.3.0-beta.34",
58
58
  "debug": "^4.4.3",
59
59
  "ox": "^0.14.10",
60
60
  "viem": "^2.47.6"