@seljs/runtime 1.2.0 → 1.3.0-beta.2

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.
Files changed (37) hide show
  1. package/dist/analysis/dependency-analyzer.cjs +1 -2
  2. package/dist/analysis/dependency-analyzer.mjs +1 -1
  3. package/dist/analysis/round-planner.cjs +1 -2
  4. package/dist/analysis/round-planner.mjs +1 -1
  5. package/dist/environment/client.cjs +16 -0
  6. package/dist/environment/client.d.cts +33 -0
  7. package/dist/environment/client.d.mts +33 -0
  8. package/dist/environment/client.mjs +16 -0
  9. package/dist/environment/contract-caller.cjs +13 -12
  10. package/dist/environment/contract-caller.mjs +13 -12
  11. package/dist/environment/environment.cjs +5 -2
  12. package/dist/environment/environment.mjs +5 -2
  13. package/dist/environment/index.cjs +1 -0
  14. package/dist/environment/index.d.mts +1 -0
  15. package/dist/environment/index.mjs +1 -0
  16. package/dist/environment/types.d.cts +4 -4
  17. package/dist/environment/types.d.mts +4 -4
  18. package/dist/errors/errors.cjs +7 -0
  19. package/dist/errors/errors.d.cts +7 -1
  20. package/dist/errors/errors.d.mts +7 -1
  21. package/dist/errors/errors.mjs +7 -1
  22. package/dist/errors/index.d.mts +1 -1
  23. package/dist/execution/multi-round-executor.cjs +1 -4
  24. package/dist/execution/multi-round-executor.mjs +1 -3
  25. package/dist/execution/multicall-batcher.cjs +10 -8
  26. package/dist/execution/multicall-batcher.mjs +11 -9
  27. package/dist/execution/multicall.cjs +10 -4
  28. package/dist/execution/multicall.mjs +9 -4
  29. package/dist/execution/round-executor.cjs +4 -12
  30. package/dist/execution/round-executor.mjs +4 -12
  31. package/dist/execution/types.d.cts +4 -6
  32. package/dist/execution/types.d.mts +4 -6
  33. package/dist/index.cjs +3 -0
  34. package/dist/index.d.cts +3 -2
  35. package/dist/index.d.mts +3 -2
  36. package/dist/index.mjs +3 -2
  37. package/package.json +6 -6
@@ -1,8 +1,7 @@
1
- const require_debug = require("../debug.cjs");
2
1
  const require_errors = require("../errors/errors.cjs");
3
2
  require("../errors/index.cjs");
4
3
  //#region src/analysis/dependency-analyzer.ts
5
- const debug = require_debug.createLogger("analysis:dependency");
4
+ const debug = require("../debug.cjs").createLogger("analysis:dependency");
6
5
  /**
7
6
  * Detects circular dependencies in the graph using DFS with a recursion stack.
8
7
  *
@@ -1,6 +1,6 @@
1
- import { createLogger } from "../debug.mjs";
2
1
  import { CircularDependencyError } from "../errors/errors.mjs";
3
2
  import "../errors/index.mjs";
3
+ import { createLogger } from "../debug.mjs";
4
4
  //#region src/analysis/dependency-analyzer.ts
5
5
  const debug = createLogger("analysis:dependency");
6
6
  /**
@@ -1,8 +1,7 @@
1
- const require_debug = require("../debug.cjs");
2
1
  const require_errors = require("../errors/errors.cjs");
3
2
  require("../errors/index.cjs");
4
3
  //#region src/analysis/round-planner.ts
5
- const debug = require_debug.createLogger("analysis:plan");
4
+ const debug = require("../debug.cjs").createLogger("analysis:plan");
6
5
  /**
7
6
  * Plans execution rounds from a dependency graph using topological sorting.
8
7
  *
@@ -1,6 +1,6 @@
1
- import { createLogger } from "../debug.mjs";
2
1
  import { ExecutionLimitError } from "../errors/errors.mjs";
3
2
  import "../errors/index.mjs";
3
+ import { createLogger } from "../debug.mjs";
4
4
  //#region src/analysis/round-planner.ts
5
5
  const debug = createLogger("analysis:plan");
6
6
  /**
@@ -0,0 +1,16 @@
1
+ const require_errors = require("../errors/errors.cjs");
2
+ require("../errors/index.cjs");
3
+ //#region src/environment/client.ts
4
+ /**
5
+ * Validates that an object satisfies the SELClient interface.
6
+ * Throws SELClientError if validation fails.
7
+ * Called at construction time for fail-fast behavior.
8
+ */
9
+ function validateClient(client) {
10
+ if (!client || typeof client !== "object") throw new require_errors.SELClientError("Client must be an object");
11
+ const c = client;
12
+ if (typeof c["call"] !== "function") throw new require_errors.SELClientError("Client must implement call({ to, data, blockNumber? }). ");
13
+ if (typeof c["getBlockNumber"] !== "function") throw new require_errors.SELClientError("Client must implement getBlockNumber(). ");
14
+ }
15
+ //#endregion
16
+ exports.validateClient = validateClient;
@@ -0,0 +1,33 @@
1
+ //#region src/environment/client.d.ts
2
+ /**
3
+ * Minimal client interface for SEL runtime contract execution.
4
+ *
5
+ * Framework-agnostic: works with viem PublicClient, ethers.js Provider,
6
+ * web3.js, or any object that can make eth_call and eth_blockNumber requests.
7
+ *
8
+ * A viem PublicClient structurally satisfies this interface.
9
+ */
10
+ interface SELClient {
11
+ /**
12
+ * Execute an eth_call against a contract
13
+ */
14
+ call: (params: {
15
+ to: `0x${string}`;
16
+ data: `0x${string}`;
17
+ blockNumber?: bigint;
18
+ }) => Promise<{
19
+ data?: `0x${string}`;
20
+ }>;
21
+ /**
22
+ * Get the current block number (eth_blockNumber) for pinning reads
23
+ */
24
+ getBlockNumber: () => Promise<bigint>;
25
+ }
26
+ /**
27
+ * Validates that an object satisfies the SELClient interface.
28
+ * Throws SELClientError if validation fails.
29
+ * Called at construction time for fail-fast behavior.
30
+ */
31
+ declare function validateClient(client: unknown): asserts client is SELClient;
32
+ //#endregion
33
+ export { SELClient, validateClient };
@@ -0,0 +1,33 @@
1
+ //#region src/environment/client.d.ts
2
+ /**
3
+ * Minimal client interface for SEL runtime contract execution.
4
+ *
5
+ * Framework-agnostic: works with viem PublicClient, ethers.js Provider,
6
+ * web3.js, or any object that can make eth_call and eth_blockNumber requests.
7
+ *
8
+ * A viem PublicClient structurally satisfies this interface.
9
+ */
10
+ interface SELClient {
11
+ /**
12
+ * Execute an eth_call against a contract
13
+ */
14
+ call: (params: {
15
+ to: `0x${string}`;
16
+ data: `0x${string}`;
17
+ blockNumber?: bigint;
18
+ }) => Promise<{
19
+ data?: `0x${string}`;
20
+ }>;
21
+ /**
22
+ * Get the current block number (eth_blockNumber) for pinning reads
23
+ */
24
+ getBlockNumber: () => Promise<bigint>;
25
+ }
26
+ /**
27
+ * Validates that an object satisfies the SELClient interface.
28
+ * Throws SELClientError if validation fails.
29
+ * Called at construction time for fail-fast behavior.
30
+ */
31
+ declare function validateClient(client: unknown): asserts client is SELClient;
32
+ //#endregion
33
+ export { SELClient, validateClient };
@@ -0,0 +1,16 @@
1
+ import { SELClientError } from "../errors/errors.mjs";
2
+ import "../errors/index.mjs";
3
+ //#region src/environment/client.ts
4
+ /**
5
+ * Validates that an object satisfies the SELClient interface.
6
+ * Throws SELClientError if validation fails.
7
+ * Called at construction time for fail-fast behavior.
8
+ */
9
+ function validateClient(client) {
10
+ if (!client || typeof client !== "object") throw new SELClientError("Client must be an object");
11
+ const c = client;
12
+ if (typeof c["call"] !== "function") throw new SELClientError("Client must implement call({ to, data, blockNumber? }). ");
13
+ if (typeof c["getBlockNumber"] !== "function") throw new SELClientError("Client must implement getBlockNumber(). ");
14
+ }
15
+ //#endregion
16
+ export { validateClient };
@@ -1,9 +1,9 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
- const require_replay_cache = require("./replay-cache.cjs");
3
- const require_debug = require("../debug.cjs");
4
2
  const require_errors = require("../errors/errors.cjs");
5
3
  require("../errors/index.cjs");
6
- let viem_actions = require("viem/actions");
4
+ const require_replay_cache = require("./replay-cache.cjs");
5
+ const require_debug = require("../debug.cjs");
6
+ let ox = require("ox");
7
7
  //#region src/environment/contract-caller.ts
8
8
  const debug = require_debug.createLogger("contract-caller");
9
9
  /**
@@ -42,12 +42,16 @@ const executeContractCall = async (contract, method, args, options) => {
42
42
  });
43
43
  options.callCounter?.increment(contract.name, method.name);
44
44
  try {
45
- return await (0, viem_actions.readContract)(options.client, {
46
- address: contract.address,
47
- abi: [method.abi],
48
- functionName: method.name,
49
- args: normalizedArgs
45
+ const data = ox.AbiFunction.encodeData([method.abi], method.name, normalizedArgs);
46
+ const result = await options.client.call({
47
+ to: contract.address,
48
+ data
49
+ });
50
+ if (!result.data) throw new require_errors.SELContractError(`Contract call returned no data: ${contract.name}.${method.name}`, {
51
+ contractName: contract.name,
52
+ methodName: method.name
50
53
  });
54
+ return ox.AbiFunction.decodeResult([method.abi], method.name, result.data);
51
55
  } catch (error) {
52
56
  if (error instanceof require_errors.SELContractError) throw error;
53
57
  throw new require_errors.SELContractError(`Contract call failed: ${contract.name}.${method.name}`, {
@@ -58,10 +62,7 @@ const executeContractCall = async (contract, method, args, options) => {
58
62
  }
59
63
  };
60
64
  const resolveExecutionBlockNumber = async (client) => {
61
- const clientWithGetBlockNumber = client;
62
- if (typeof clientWithGetBlockNumber.getBlockNumber === "function") return await clientWithGetBlockNumber.getBlockNumber();
63
- if (typeof clientWithGetBlockNumber.request === "function") return;
64
- return 0n;
65
+ return await client.getBlockNumber();
65
66
  };
66
67
  const buildContractInfoMap = (contracts) => {
67
68
  const map = /* @__PURE__ */ new Map();
@@ -1,8 +1,8 @@
1
- import { createReplayCallId } from "./replay-cache.mjs";
2
- import { createLogger } from "../debug.mjs";
3
1
  import { ExecutionLimitError, SELContractError } from "../errors/errors.mjs";
4
2
  import "../errors/index.mjs";
5
- import { readContract } from "viem/actions";
3
+ import { createReplayCallId } from "./replay-cache.mjs";
4
+ import { createLogger } from "../debug.mjs";
5
+ import { AbiFunction } from "ox";
6
6
  //#region src/environment/contract-caller.ts
7
7
  const debug = createLogger("contract-caller");
8
8
  /**
@@ -41,12 +41,16 @@ const executeContractCall = async (contract, method, args, options) => {
41
41
  });
42
42
  options.callCounter?.increment(contract.name, method.name);
43
43
  try {
44
- return await readContract(options.client, {
45
- address: contract.address,
46
- abi: [method.abi],
47
- functionName: method.name,
48
- args: normalizedArgs
44
+ const data = AbiFunction.encodeData([method.abi], method.name, normalizedArgs);
45
+ const result = await options.client.call({
46
+ to: contract.address,
47
+ data
48
+ });
49
+ if (!result.data) throw new SELContractError(`Contract call returned no data: ${contract.name}.${method.name}`, {
50
+ contractName: contract.name,
51
+ methodName: method.name
49
52
  });
53
+ return AbiFunction.decodeResult([method.abi], method.name, result.data);
50
54
  } catch (error) {
51
55
  if (error instanceof SELContractError) throw error;
52
56
  throw new SELContractError(`Contract call failed: ${contract.name}.${method.name}`, {
@@ -57,10 +61,7 @@ const executeContractCall = async (contract, method, args, options) => {
57
61
  }
58
62
  };
59
63
  const resolveExecutionBlockNumber = async (client) => {
60
- const clientWithGetBlockNumber = client;
61
- if (typeof clientWithGetBlockNumber.getBlockNumber === "function") return await clientWithGetBlockNumber.getBlockNumber();
62
- if (typeof clientWithGetBlockNumber.request === "function") return;
63
- return 0n;
64
+ return await client.getBlockNumber();
64
65
  };
65
66
  const buildContractInfoMap = (contracts) => {
66
67
  const map = /* @__PURE__ */ new Map();
@@ -1,9 +1,10 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_errors = require("../errors/errors.cjs");
3
+ require("../errors/index.cjs");
4
+ const require_client = require("./client.cjs");
2
5
  const require_context = require("./context.cjs");
3
6
  const require_replay_cache = require("./replay-cache.cjs");
4
7
  const require_debug = require("../debug.cjs");
5
- const require_errors = require("../errors/errors.cjs");
6
- require("../errors/index.cjs");
7
8
  const require_contract_caller = require("./contract-caller.cjs");
8
9
  const require_error_wrapper = require("./error-wrapper.cjs");
9
10
  const require_call_collector = require("../analysis/call-collector.cjs");
@@ -70,6 +71,7 @@ var SELRuntime = class {
70
71
  this.maxRounds = limits?.maxRounds ?? 10;
71
72
  this.maxCalls = limits?.maxCalls ?? 100;
72
73
  this.multicallOptions = config.multicall;
74
+ if (config.client) require_client.validateClient(config.client);
73
75
  this.client = config.client;
74
76
  this.schema = config.schema;
75
77
  const handler = (contractName, methodName, args) => {
@@ -207,6 +209,7 @@ var SELRuntime = class {
207
209
  async doEvaluate(expression, context, options) {
208
210
  debug("evaluate: %s", expression);
209
211
  const resolvedClient = options?.client ?? this.client;
212
+ if (resolvedClient && resolvedClient !== this.client) require_client.validateClient(resolvedClient);
210
213
  try {
211
214
  const { parseResult, collectedCalls, normalizedContext, executionVariables, typeCheckResult, diagnostics } = this.planExecution(expression, context ?? {});
212
215
  let executionMeta;
@@ -1,8 +1,9 @@
1
+ import { MulticallBatchError, SELContractError, SELLintError, SELTypeError } from "../errors/errors.mjs";
2
+ import "../errors/index.mjs";
3
+ import { validateClient } from "./client.mjs";
1
4
  import { normalizeContextForEvaluation } from "./context.mjs";
2
5
  import { buildExecutionReplayCache } from "./replay-cache.mjs";
3
6
  import { createLogger } from "../debug.mjs";
4
- import { MulticallBatchError, SELContractError, SELLintError, SELTypeError } from "../errors/errors.mjs";
5
- import "../errors/index.mjs";
6
7
  import { CallCounter, buildContractInfoMap, executeContractCall, resolveExecutionBlockNumber } from "./contract-caller.mjs";
7
8
  import { wrapError } from "./error-wrapper.mjs";
8
9
  import { collectCalls } from "../analysis/call-collector.mjs";
@@ -68,6 +69,7 @@ var SELRuntime = class {
68
69
  this.maxRounds = limits?.maxRounds ?? 10;
69
70
  this.maxCalls = limits?.maxCalls ?? 100;
70
71
  this.multicallOptions = config.multicall;
72
+ if (config.client) validateClient(config.client);
71
73
  this.client = config.client;
72
74
  this.schema = config.schema;
73
75
  const handler = (contractName, methodName, args) => {
@@ -205,6 +207,7 @@ var SELRuntime = class {
205
207
  async doEvaluate(expression, context, options) {
206
208
  debug("evaluate: %s", expression);
207
209
  const resolvedClient = options?.client ?? this.client;
210
+ if (resolvedClient && resolvedClient !== this.client) validateClient(resolvedClient);
208
211
  try {
209
212
  const { parseResult, collectedCalls, normalizedContext, executionVariables, typeCheckResult, diagnostics } = this.planExecution(expression, context ?? {});
210
213
  let executionMeta;
@@ -1 +1,2 @@
1
+ require("./client.cjs");
1
2
  require("./environment.cjs");
@@ -1,2 +1,3 @@
1
+ import { SELClient, validateClient } from "./client.mjs";
1
2
  import { MulticallOptions, SELLimits, SELRuntimeConfig } from "./types.mjs";
2
3
  import { SELRuntime } from "./environment.mjs";
@@ -1,2 +1,3 @@
1
+ import "./client.mjs";
1
2
  import "./environment.mjs";
2
3
  export {};
@@ -1,6 +1,6 @@
1
+ import { SELClient } from "./client.cjs";
1
2
  import { SELCheckerOptions } from "@seljs/checker";
2
3
  import { SELSchema } from "@seljs/schema";
3
- import { Address, PublicClient } from "viem";
4
4
 
5
5
  //#region src/environment/types.d.ts
6
6
  /**
@@ -13,7 +13,7 @@ interface MulticallOptions {
13
13
  /** Maximum number of calls per multicall3 batch. Unbounded if omitted. */
14
14
  batchSize?: number;
15
15
  /** Custom multicall3 contract address. Defaults to the canonical deployment. */
16
- address?: Address;
16
+ address?: `0x${string}`;
17
17
  }
18
18
  /**
19
19
  * Limits for contract call execution.
@@ -36,8 +36,8 @@ interface SELLimits {
36
36
  interface SELRuntimeConfig extends SELCheckerOptions {
37
37
  /** SEL schema describing contracts, variables, types, functions, and macros */
38
38
  schema: SELSchema;
39
- /** Viem public client for executing on-chain contract reads */
40
- client?: PublicClient;
39
+ /** Client for on-chain reads. Any viem PublicClient or SELClient-compatible object. */
40
+ client?: SELClient;
41
41
  /** Multicall3 batching options for contract call execution */
42
42
  multicall?: MulticallOptions;
43
43
  /** Execution limits for contract call rounds and total calls */
@@ -1,5 +1,5 @@
1
+ import { SELClient } from "./client.mjs";
1
2
  import { SELCheckerOptions } from "@seljs/checker";
2
- import { Address, PublicClient } from "viem";
3
3
  import { SELSchema } from "@seljs/schema";
4
4
 
5
5
  //#region src/environment/types.d.ts
@@ -13,7 +13,7 @@ interface MulticallOptions {
13
13
  /** Maximum number of calls per multicall3 batch. Unbounded if omitted. */
14
14
  batchSize?: number;
15
15
  /** Custom multicall3 contract address. Defaults to the canonical deployment. */
16
- address?: Address;
16
+ address?: `0x${string}`;
17
17
  }
18
18
  /**
19
19
  * Limits for contract call execution.
@@ -36,8 +36,8 @@ interface SELLimits {
36
36
  interface SELRuntimeConfig extends SELCheckerOptions {
37
37
  /** SEL schema describing contracts, variables, types, functions, and macros */
38
38
  schema: SELSchema;
39
- /** Viem public client for executing on-chain contract reads */
40
- client?: PublicClient;
39
+ /** Client for on-chain reads. Any viem PublicClient or SELClient-compatible object. */
40
+ client?: SELClient;
41
41
  /** Multicall3 batching options for contract call execution */
42
42
  multicall?: MulticallOptions;
43
43
  /** Execution limits for contract call rounds and total calls */
@@ -61,6 +61,12 @@ var MulticallBatchError = class extends _seljs_common.SELError {
61
61
  }
62
62
  };
63
63
  /**
64
+ * Thrown when the provided client fails validation or is misconfigured.
65
+ */
66
+ var SELClientError = class extends _seljs_common.SELError {
67
+ name = "SELClientError";
68
+ };
69
+ /**
64
70
  * Thrown when lint rules with error severity detect violations.
65
71
  * Contains the diagnostics that caused the failure.
66
72
  */
@@ -76,6 +82,7 @@ var SELLintError = class extends _seljs_common.SELError {
76
82
  exports.CircularDependencyError = CircularDependencyError;
77
83
  exports.ExecutionLimitError = ExecutionLimitError;
78
84
  exports.MulticallBatchError = MulticallBatchError;
85
+ exports.SELClientError = SELClientError;
79
86
  exports.SELContractError = SELContractError;
80
87
  exports.SELEvaluationError = SELEvaluationError;
81
88
  exports.SELLintError = SELLintError;
@@ -61,6 +61,12 @@ declare class MulticallBatchError extends SELError {
61
61
  methodName?: string;
62
62
  });
63
63
  }
64
+ /**
65
+ * Thrown when the provided client fails validation or is misconfigured.
66
+ */
67
+ declare class SELClientError extends SELError {
68
+ readonly name = "SELClientError";
69
+ }
64
70
  /**
65
71
  * Thrown when lint rules with error severity detect violations.
66
72
  * Contains the diagnostics that caused the failure.
@@ -72,4 +78,4 @@ declare class SELLintError extends SELError {
72
78
  });
73
79
  }
74
80
  //#endregion
75
- export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError };
81
+ export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError };
@@ -61,6 +61,12 @@ declare class MulticallBatchError extends SELError {
61
61
  methodName?: string;
62
62
  });
63
63
  }
64
+ /**
65
+ * Thrown when the provided client fails validation or is misconfigured.
66
+ */
67
+ declare class SELClientError extends SELError {
68
+ readonly name = "SELClientError";
69
+ }
64
70
  /**
65
71
  * Thrown when lint rules with error severity detect violations.
66
72
  * Contains the diagnostics that caused the failure.
@@ -72,4 +78,4 @@ declare class SELLintError extends SELError {
72
78
  });
73
79
  }
74
80
  //#endregion
75
- export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError };
81
+ export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError };
@@ -60,6 +60,12 @@ var MulticallBatchError = class extends SELError {
60
60
  }
61
61
  };
62
62
  /**
63
+ * Thrown when the provided client fails validation or is misconfigured.
64
+ */
65
+ var SELClientError = class extends SELError {
66
+ name = "SELClientError";
67
+ };
68
+ /**
63
69
  * Thrown when lint rules with error severity detect violations.
64
70
  * Contains the diagnostics that caused the failure.
65
71
  */
@@ -72,4 +78,4 @@ var SELLintError = class extends SELError {
72
78
  }
73
79
  };
74
80
  //#endregion
75
- export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError };
81
+ export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError };
@@ -1 +1 @@
1
- import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors.mjs";
1
+ import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors.mjs";
@@ -1,9 +1,7 @@
1
- require("../_virtual/_rolldown/runtime.cjs");
2
1
  const require_debug = require("../debug.cjs");
3
2
  const require_multicall_batcher = require("./multicall-batcher.cjs");
4
3
  const require_result_cache = require("./result-cache.cjs");
5
4
  const require_round_executor = require("./round-executor.cjs");
6
- let viem_actions = require("viem/actions");
7
5
  //#region src/execution/multi-round-executor.ts
8
6
  const debug = require_debug.createLogger("execute");
9
7
  var MultiRoundExecutor = class {
@@ -14,13 +12,12 @@ var MultiRoundExecutor = class {
14
12
  this.contracts = contracts;
15
13
  }
16
14
  async execute(plan, variables = {}, blockNumber) {
17
- const lockedBlockNumber = blockNumber ?? await (0, viem_actions.getBlockNumber)(this.client);
15
+ const lockedBlockNumber = blockNumber ?? await this.client.getBlockNumber();
18
16
  debug("start: %d rounds, %d calls, block=%s", plan.rounds.length, plan.totalCalls, String(lockedBlockNumber));
19
17
  const cache = new require_result_cache.ResultCache();
20
18
  const batcher = new require_multicall_batcher.MulticallBatcher(this.client, this.multicallOptions);
21
19
  const executor = new require_round_executor.RoundExecutor(this.contracts, cache, batcher);
22
20
  const context = {
23
- client: this.client,
24
21
  blockNumber: lockedBlockNumber,
25
22
  variables
26
23
  };
@@ -2,7 +2,6 @@ import { createLogger } from "../debug.mjs";
2
2
  import { MulticallBatcher } from "./multicall-batcher.mjs";
3
3
  import { ResultCache } from "./result-cache.mjs";
4
4
  import { RoundExecutor } from "./round-executor.mjs";
5
- import { getBlockNumber } from "viem/actions";
6
5
  //#region src/execution/multi-round-executor.ts
7
6
  const debug = createLogger("execute");
8
7
  var MultiRoundExecutor = class {
@@ -13,13 +12,12 @@ var MultiRoundExecutor = class {
13
12
  this.contracts = contracts;
14
13
  }
15
14
  async execute(plan, variables = {}, blockNumber) {
16
- const lockedBlockNumber = blockNumber ?? await getBlockNumber(this.client);
15
+ const lockedBlockNumber = blockNumber ?? await this.client.getBlockNumber();
17
16
  debug("start: %d rounds, %d calls, block=%s", plan.rounds.length, plan.totalCalls, String(lockedBlockNumber));
18
17
  const cache = new ResultCache();
19
18
  const batcher = new MulticallBatcher(this.client, this.multicallOptions);
20
19
  const executor = new RoundExecutor(this.contracts, cache, batcher);
21
20
  const context = {
22
- client: this.client,
23
21
  blockNumber: lockedBlockNumber,
24
22
  variables
25
23
  };
@@ -1,9 +1,9 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
- const require_debug = require("../debug.cjs");
3
2
  const require_errors = require("../errors/errors.cjs");
4
3
  require("../errors/index.cjs");
4
+ const require_debug = require("../debug.cjs");
5
5
  const require_multicall = require("./multicall.cjs");
6
- let viem_actions = require("viem/actions");
6
+ let ox = require("ox");
7
7
  //#region src/execution/multicall-batcher.ts
8
8
  const debug = require_debug.createLogger("execute:multicall");
9
9
  var MulticallBatcher = class {
@@ -32,17 +32,19 @@ var MulticallBatcher = class {
32
32
  }
33
33
  async executeChunk(calls, blockNumber) {
34
34
  try {
35
- return (await (0, viem_actions.readContract)(this.client, {
36
- address: this.address,
37
- abi: require_multicall.multicall3Abi,
38
- functionName: "aggregate3",
39
- args: [calls],
35
+ const data = ox.AbiFunction.encodeData(require_multicall.multicall3Function, [calls]);
36
+ const response = await this.client.call({
37
+ to: this.address,
38
+ data,
40
39
  blockNumber
41
- })).map((r) => ({
40
+ });
41
+ if (!response.data) throw new require_errors.MulticallBatchError("Multicall3 aggregate3 returned no data");
42
+ return ox.AbiFunction.decodeResult(require_multicall.multicall3Function, response.data).map((r) => ({
42
43
  success: r.success,
43
44
  returnData: r.returnData
44
45
  }));
45
46
  } catch (error) {
47
+ if (error instanceof require_errors.MulticallBatchError) throw error;
46
48
  throw new require_errors.MulticallBatchError("Multicall3 aggregate3 call failed", { cause: error });
47
49
  }
48
50
  }
@@ -1,8 +1,8 @@
1
- import { createLogger } from "../debug.mjs";
2
1
  import { MulticallBatchError } from "../errors/errors.mjs";
3
2
  import "../errors/index.mjs";
4
- import { multicall3Abi } from "./multicall.mjs";
5
- import { readContract } from "viem/actions";
3
+ import { createLogger } from "../debug.mjs";
4
+ import { multicall3Function } from "./multicall.mjs";
5
+ import { AbiFunction } from "ox";
6
6
  //#region src/execution/multicall-batcher.ts
7
7
  const debug = createLogger("execute:multicall");
8
8
  var MulticallBatcher = class {
@@ -31,17 +31,19 @@ var MulticallBatcher = class {
31
31
  }
32
32
  async executeChunk(calls, blockNumber) {
33
33
  try {
34
- return (await readContract(this.client, {
35
- address: this.address,
36
- abi: multicall3Abi,
37
- functionName: "aggregate3",
38
- args: [calls],
34
+ const data = AbiFunction.encodeData(multicall3Function, [calls]);
35
+ const response = await this.client.call({
36
+ to: this.address,
37
+ data,
39
38
  blockNumber
40
- })).map((r) => ({
39
+ });
40
+ if (!response.data) throw new MulticallBatchError("Multicall3 aggregate3 returned no data");
41
+ return AbiFunction.decodeResult(multicall3Function, response.data).map((r) => ({
41
42
  success: r.success,
42
43
  returnData: r.returnData
43
44
  }));
44
45
  } catch (error) {
46
+ if (error instanceof MulticallBatchError) throw error;
45
47
  throw new MulticallBatchError("Multicall3 aggregate3 call failed", { cause: error });
46
48
  }
47
49
  }
@@ -1,6 +1,7 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ let ox = require("ox");
1
3
  //#region src/execution/multicall.ts
2
- const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
3
- const multicall3Abi = [{
4
+ const aggregate3Abi = {
4
5
  name: "aggregate3",
5
6
  type: "function",
6
7
  stateMutability: "payable",
@@ -33,7 +34,12 @@ const multicall3Abi = [{
33
34
  type: "bytes"
34
35
  }]
35
36
  }]
36
- }];
37
+ };
38
+ const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
39
+ /**
40
+ * Pre-parsed Multicall3 aggregate3 ABI function for ox encoding/decoding.
41
+ */
42
+ const multicall3Function = ox.AbiFunction.from(aggregate3Abi);
37
43
  //#endregion
38
44
  exports.MULTICALL3_ADDRESS = MULTICALL3_ADDRESS;
39
- exports.multicall3Abi = multicall3Abi;
45
+ exports.multicall3Function = multicall3Function;
@@ -1,6 +1,6 @@
1
+ import { AbiFunction } from "ox";
1
2
  //#region src/execution/multicall.ts
2
- const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
3
- const multicall3Abi = [{
3
+ const aggregate3Abi = {
4
4
  name: "aggregate3",
5
5
  type: "function",
6
6
  stateMutability: "payable",
@@ -33,6 +33,11 @@ const multicall3Abi = [{
33
33
  type: "bytes"
34
34
  }]
35
35
  }]
36
- }];
36
+ };
37
+ const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
38
+ /**
39
+ * Pre-parsed Multicall3 aggregate3 ABI function for ox encoding/decoding.
40
+ */
41
+ const multicall3Function = AbiFunction.from(aggregate3Abi);
37
42
  //#endregion
38
- export { MULTICALL3_ADDRESS, multicall3Abi };
43
+ export { MULTICALL3_ADDRESS, multicall3Function };
@@ -1,8 +1,8 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
- const require_debug = require("../debug.cjs");
3
2
  const require_errors = require("../errors/errors.cjs");
4
3
  require("../errors/index.cjs");
5
- let viem = require("viem");
4
+ const require_debug = require("../debug.cjs");
5
+ let ox = require("ox");
6
6
  //#region src/execution/round-executor.ts
7
7
  const debug = require_debug.createLogger("execute:round");
8
8
  var RoundExecutor = class {
@@ -27,11 +27,7 @@ var RoundExecutor = class {
27
27
  encodedCalls.push({
28
28
  target: contract.address,
29
29
  allowFailure: false,
30
- callData: (0, viem.encodeFunctionData)({
31
- abi: contract.abi,
32
- functionName: call.method,
33
- args: resolvedArgs
34
- })
30
+ callData: ox.AbiFunction.encodeData(contract.abi, call.method, resolvedArgs)
35
31
  });
36
32
  }
37
33
  } catch (error) {
@@ -54,11 +50,7 @@ var RoundExecutor = class {
54
50
  contractName: call.contract,
55
51
  methodName: call.method
56
52
  });
57
- const decoded = (0, viem.decodeFunctionResult)({
58
- abi: contract.abi,
59
- functionName: call.method,
60
- data: result.returnData
61
- });
53
+ const decoded = ox.AbiFunction.decodeResult(contract.abi, call.method, result.returnData);
62
54
  debug("decoded %s.%s -> %o", call.contract, call.method, decoded);
63
55
  this.cache.set(call.id, decoded);
64
56
  }
@@ -1,7 +1,7 @@
1
- import { createLogger } from "../debug.mjs";
2
1
  import { MulticallBatchError } from "../errors/errors.mjs";
3
2
  import "../errors/index.mjs";
4
- import { decodeFunctionResult, encodeFunctionData } from "viem";
3
+ import { createLogger } from "../debug.mjs";
4
+ import { AbiFunction } from "ox";
5
5
  //#region src/execution/round-executor.ts
6
6
  const debug = createLogger("execute:round");
7
7
  var RoundExecutor = class {
@@ -26,11 +26,7 @@ var RoundExecutor = class {
26
26
  encodedCalls.push({
27
27
  target: contract.address,
28
28
  allowFailure: false,
29
- callData: encodeFunctionData({
30
- abi: contract.abi,
31
- functionName: call.method,
32
- args: resolvedArgs
33
- })
29
+ callData: AbiFunction.encodeData(contract.abi, call.method, resolvedArgs)
34
30
  });
35
31
  }
36
32
  } catch (error) {
@@ -53,11 +49,7 @@ var RoundExecutor = class {
53
49
  contractName: call.contract,
54
50
  methodName: call.method
55
51
  });
56
- const decoded = decodeFunctionResult({
57
- abi: contract.abi,
58
- functionName: call.method,
59
- data: result.returnData
60
- });
52
+ const decoded = AbiFunction.decodeResult(contract.abi, call.method, result.returnData);
61
53
  debug("decoded %s.%s -> %o", call.contract, call.method, decoded);
62
54
  this.cache.set(call.id, decoded);
63
55
  }
@@ -1,5 +1,5 @@
1
+ import { SELClient } from "../environment/client.cjs";
1
2
  import { SELDiagnostic } from "@seljs/checker";
2
- import { PublicClient } from "viem";
3
3
 
4
4
  //#region src/execution/types.d.ts
5
5
  /**
@@ -26,11 +26,9 @@ interface ExecutionResult {
26
26
  }
27
27
  /**
28
28
  * Context passed to the executor for running contract calls.
29
- * Contains the client, block number, and variable bindings.
29
+ * Contains the block number and variable bindings.
30
30
  */
31
31
  interface ExecutionContext {
32
- /** Viem public client for making contract calls */
33
- client: PublicClient;
34
32
  /** Block number for consistent reads across all calls */
35
33
  blockNumber: bigint;
36
34
  /** Variable name to value mapping from evaluate() context */
@@ -40,8 +38,8 @@ interface ExecutionContext {
40
38
  * Options for the evaluate() call.
41
39
  */
42
40
  interface EvaluateOptions {
43
- /** Override viem client for this evaluation */
44
- client?: PublicClient;
41
+ /** Override client for this evaluation */
42
+ client?: SELClient;
45
43
  }
46
44
  /**
47
45
  * Result of evaluating a SEL expression.
@@ -1,5 +1,5 @@
1
+ import { SELClient } from "../environment/client.mjs";
1
2
  import { SELDiagnostic } from "@seljs/checker";
2
- import { PublicClient } from "viem";
3
3
 
4
4
  //#region src/execution/types.d.ts
5
5
  /**
@@ -26,11 +26,9 @@ interface ExecutionResult {
26
26
  }
27
27
  /**
28
28
  * Context passed to the executor for running contract calls.
29
- * Contains the client, block number, and variable bindings.
29
+ * Contains the block number and variable bindings.
30
30
  */
31
31
  interface ExecutionContext {
32
- /** Viem public client for making contract calls */
33
- client: PublicClient;
34
32
  /** Block number for consistent reads across all calls */
35
33
  blockNumber: bigint;
36
34
  /** Variable name to value mapping from evaluate() context */
@@ -40,8 +38,8 @@ interface ExecutionContext {
40
38
  * Options for the evaluate() call.
41
39
  */
42
40
  interface EvaluateOptions {
43
- /** Override viem client for this evaluation */
44
- client?: PublicClient;
41
+ /** Override client for this evaluation */
42
+ client?: SELClient;
45
43
  }
46
44
  /**
47
45
  * Result of evaluating a SEL expression.
package/dist/index.cjs CHANGED
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./_virtual/_rolldown/runtime.cjs");
3
3
  const require_errors = require("./errors/errors.cjs");
4
4
  require("./errors/index.cjs");
5
+ const require_client = require("./environment/client.cjs");
5
6
  const require_environment = require("./environment/environment.cjs");
6
7
  require("./environment/index.cjs");
7
8
  const require_factory = require("./factory.cjs");
@@ -9,6 +10,7 @@ let _seljs_common = require("@seljs/common");
9
10
  exports.CircularDependencyError = require_errors.CircularDependencyError;
10
11
  exports.ExecutionLimitError = require_errors.ExecutionLimitError;
11
12
  exports.MulticallBatchError = require_errors.MulticallBatchError;
13
+ exports.SELClientError = require_errors.SELClientError;
12
14
  exports.SELContractError = require_errors.SELContractError;
13
15
  exports.SELError = _seljs_common.SELError;
14
16
  exports.SELEvaluationError = require_errors.SELEvaluationError;
@@ -17,3 +19,4 @@ exports.SELParseError = _seljs_common.SELParseError;
17
19
  exports.SELRuntime = require_environment.SELRuntime;
18
20
  exports.SELTypeError = _seljs_common.SELTypeError;
19
21
  exports.createSEL = require_factory.createSEL;
22
+ exports.validateClient = require_client.validateClient;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
+ import { SELClient, validateClient } from "./environment/client.cjs";
1
2
  import { MulticallOptions, SELLimits, SELRuntimeConfig } from "./environment/types.cjs";
2
3
  import { EvaluateOptions, EvaluateResult, ExecutionContext, ExecutionMeta, ExecutionResult } from "./execution/types.cjs";
3
4
  import { SELRuntime } from "./environment/environment.cjs";
4
- import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors/errors.cjs";
5
+ import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors/errors.cjs";
5
6
  import { createSEL } from "./factory.cjs";
6
7
  import { CallArgument, CollectedCall, DependencyGraph, ExecutionPlan, ExecutionRound, GraphNode } from "./analysis/types.cjs";
7
- export { CallArgument, CircularDependencyError, CollectedCall, DependencyGraph, EvaluateOptions, EvaluateResult, ExecutionContext, ExecutionLimitError, ExecutionMeta, ExecutionPlan, ExecutionResult, ExecutionRound, GraphNode, MulticallBatchError, MulticallOptions, SELContractError, SELError, SELEvaluationError, SELLimits, SELLintError, SELParseError, SELRuntime, SELRuntimeConfig, SELTypeError, createSEL };
8
+ export { CallArgument, CircularDependencyError, CollectedCall, DependencyGraph, EvaluateOptions, EvaluateResult, ExecutionContext, ExecutionLimitError, ExecutionMeta, ExecutionPlan, ExecutionResult, ExecutionRound, GraphNode, MulticallBatchError, MulticallOptions, SELClient, SELClientError, SELContractError, SELError, SELEvaluationError, SELLimits, SELLintError, SELParseError, SELRuntime, SELRuntimeConfig, SELTypeError, createSEL, validateClient };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,8 @@
1
+ import { SELClient, validateClient } from "./environment/client.mjs";
1
2
  import { MulticallOptions, SELLimits, SELRuntimeConfig } from "./environment/types.mjs";
2
3
  import { EvaluateOptions, EvaluateResult, ExecutionContext, ExecutionMeta, ExecutionResult } from "./execution/types.mjs";
3
4
  import { SELRuntime } from "./environment/environment.mjs";
4
- import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors/errors.mjs";
5
+ import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors/errors.mjs";
5
6
  import { createSEL } from "./factory.mjs";
6
7
  import { CallArgument, CollectedCall, DependencyGraph, ExecutionPlan, ExecutionRound, GraphNode } from "./analysis/types.mjs";
7
- export { CallArgument, CircularDependencyError, CollectedCall, DependencyGraph, EvaluateOptions, EvaluateResult, ExecutionContext, ExecutionLimitError, ExecutionMeta, ExecutionPlan, ExecutionResult, ExecutionRound, GraphNode, MulticallBatchError, MulticallOptions, SELContractError, SELError, SELEvaluationError, SELLimits, SELLintError, SELParseError, SELRuntime, SELRuntimeConfig, SELTypeError, createSEL };
8
+ export { CallArgument, CircularDependencyError, CollectedCall, DependencyGraph, EvaluateOptions, EvaluateResult, ExecutionContext, ExecutionLimitError, ExecutionMeta, ExecutionPlan, ExecutionResult, ExecutionRound, GraphNode, MulticallBatchError, MulticallOptions, SELClient, SELClientError, SELContractError, SELError, SELEvaluationError, SELLimits, SELLintError, SELParseError, SELRuntime, SELRuntimeConfig, SELTypeError, createSEL, validateClient };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors/errors.mjs";
1
+ import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELTypeError } from "./errors/errors.mjs";
2
2
  import "./errors/index.mjs";
3
+ import { validateClient } from "./environment/client.mjs";
3
4
  import { SELRuntime } from "./environment/environment.mjs";
4
5
  import "./environment/index.mjs";
5
6
  import { createSEL } from "./factory.mjs";
6
- export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELRuntime, SELTypeError, createSEL };
7
+ export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELClientError, SELContractError, SELError, SELEvaluationError, SELLintError, SELParseError, SELRuntime, SELTypeError, createSEL, validateClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seljs/runtime",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-beta.2",
4
4
  "repository": {
5
5
  "url": "https://github.com/abinnovision/seljs"
6
6
  },
@@ -50,13 +50,13 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@marcbachmann/cel-js": "^7.5.3",
53
- "@seljs/checker": "1.2.0",
54
- "@seljs/common": "1.2.0",
55
- "@seljs/env": "1.2.0",
53
+ "@seljs/checker": "1.3.0-beta.2",
54
+ "@seljs/common": "1.3.0-beta.2",
55
+ "@seljs/env": "1.3.0-beta.2",
56
56
  "@seljs/schema": "1.2.0",
57
- "@seljs/types": "1.2.0",
57
+ "@seljs/types": "1.3.0-beta.2",
58
58
  "debug": "^4.4.3",
59
- "viem": "^2.47.2"
59
+ "ox": "^0.14.7"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@abinnovision/eslint-config-base": "^3.2.0",