@seljs/runtime 1.0.0 → 1.0.1-beta.9

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 (128) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/analysis/call-collector.cjs +233 -0
  3. package/dist/analysis/call-collector.mjs +232 -0
  4. package/dist/analysis/dependency-analyzer.cjs +68 -0
  5. package/dist/analysis/dependency-analyzer.mjs +68 -0
  6. package/dist/analysis/round-planner.cjs +65 -0
  7. package/dist/analysis/round-planner.mjs +65 -0
  8. package/dist/analysis/types.d.cts +115 -0
  9. package/dist/analysis/types.d.mts +115 -0
  10. package/dist/debug.cjs +17 -0
  11. package/dist/debug.mjs +15 -0
  12. package/dist/environment/context.cjs +11 -0
  13. package/dist/environment/context.mjs +11 -0
  14. package/dist/environment/contract-caller.cjs +81 -0
  15. package/dist/environment/contract-caller.mjs +77 -0
  16. package/dist/environment/environment.cjs +254 -0
  17. package/dist/environment/environment.d.cts +84 -0
  18. package/dist/environment/environment.d.mts +84 -0
  19. package/dist/environment/environment.mjs +252 -0
  20. package/dist/environment/error-wrapper.cjs +29 -0
  21. package/dist/environment/error-wrapper.mjs +27 -0
  22. package/dist/environment/index.cjs +1 -0
  23. package/dist/environment/index.d.mts +2 -0
  24. package/dist/environment/index.mjs +2 -0
  25. package/dist/environment/replay-cache.cjs +48 -0
  26. package/dist/environment/replay-cache.mjs +47 -0
  27. package/dist/environment/types.d.cts +60 -0
  28. package/dist/environment/types.d.mts +60 -0
  29. package/dist/errors/errors.cjs +68 -0
  30. package/dist/errors/errors.d.cts +64 -0
  31. package/dist/errors/errors.d.mts +64 -0
  32. package/dist/errors/errors.mjs +63 -0
  33. package/dist/errors/index.cjs +3 -0
  34. package/dist/errors/index.d.mts +1 -0
  35. package/dist/errors/index.mjs +2 -0
  36. package/dist/execution/multi-round-executor.cjs +45 -0
  37. package/dist/execution/multi-round-executor.mjs +44 -0
  38. package/dist/execution/multicall-batcher.cjs +51 -0
  39. package/dist/execution/multicall-batcher.mjs +50 -0
  40. package/dist/execution/multicall.cjs +39 -0
  41. package/dist/execution/multicall.mjs +38 -0
  42. package/dist/execution/result-cache.cjs +63 -0
  43. package/dist/execution/result-cache.mjs +63 -0
  44. package/dist/execution/round-executor.cjs +81 -0
  45. package/dist/execution/round-executor.mjs +80 -0
  46. package/dist/execution/types.d.cts +58 -0
  47. package/dist/execution/types.d.mts +58 -0
  48. package/dist/factory.cjs +6 -0
  49. package/dist/factory.d.cts +7 -0
  50. package/dist/factory.d.mts +6 -0
  51. package/dist/factory.mjs +6 -0
  52. package/dist/index.cjs +18 -0
  53. package/dist/index.d.cts +7 -0
  54. package/dist/index.d.mts +7 -0
  55. package/dist/index.mjs +6 -0
  56. package/package.json +26 -19
  57. package/dist/analysis/call-collector.d.ts +0 -20
  58. package/dist/analysis/call-collector.d.ts.map +0 -1
  59. package/dist/analysis/call-collector.js +0 -272
  60. package/dist/analysis/dependency-analyzer.d.ts +0 -14
  61. package/dist/analysis/dependency-analyzer.d.ts.map +0 -1
  62. package/dist/analysis/dependency-analyzer.js +0 -76
  63. package/dist/analysis/index.d.ts +0 -2
  64. package/dist/analysis/index.d.ts.map +0 -1
  65. package/dist/analysis/index.js +0 -1
  66. package/dist/analysis/round-planner.d.ts +0 -32
  67. package/dist/analysis/round-planner.d.ts.map +0 -1
  68. package/dist/analysis/round-planner.js +0 -69
  69. package/dist/analysis/types.d.ts +0 -113
  70. package/dist/analysis/types.d.ts.map +0 -1
  71. package/dist/analysis/types.js +0 -1
  72. package/dist/debug.d.ts +0 -13
  73. package/dist/debug.d.ts.map +0 -1
  74. package/dist/debug.js +0 -12
  75. package/dist/environment/context.d.ts +0 -3
  76. package/dist/environment/context.d.ts.map +0 -1
  77. package/dist/environment/context.js +0 -8
  78. package/dist/environment/contract-caller.d.ts +0 -25
  79. package/dist/environment/contract-caller.d.ts.map +0 -1
  80. package/dist/environment/contract-caller.js +0 -85
  81. package/dist/environment/environment.d.ts +0 -81
  82. package/dist/environment/environment.d.ts.map +0 -1
  83. package/dist/environment/environment.js +0 -279
  84. package/dist/environment/error-wrapper.d.ts +0 -11
  85. package/dist/environment/error-wrapper.d.ts.map +0 -1
  86. package/dist/environment/error-wrapper.js +0 -33
  87. package/dist/environment/index.d.ts +0 -3
  88. package/dist/environment/index.d.ts.map +0 -1
  89. package/dist/environment/index.js +0 -2
  90. package/dist/environment/replay-cache.d.ts +0 -23
  91. package/dist/environment/replay-cache.d.ts.map +0 -1
  92. package/dist/environment/replay-cache.js +0 -51
  93. package/dist/environment/types.d.ts +0 -57
  94. package/dist/environment/types.d.ts.map +0 -1
  95. package/dist/environment/types.js +0 -1
  96. package/dist/errors/errors.d.ts +0 -63
  97. package/dist/errors/errors.d.ts.map +0 -1
  98. package/dist/errors/errors.js +0 -63
  99. package/dist/errors/index.d.ts +0 -2
  100. package/dist/errors/index.d.ts.map +0 -1
  101. package/dist/errors/index.js +0 -1
  102. package/dist/execution/index.d.ts +0 -2
  103. package/dist/execution/index.d.ts.map +0 -1
  104. package/dist/execution/index.js +0 -1
  105. package/dist/execution/multi-round-executor.d.ts +0 -17
  106. package/dist/execution/multi-round-executor.d.ts.map +0 -1
  107. package/dist/execution/multi-round-executor.js +0 -47
  108. package/dist/execution/multicall-batcher.d.ts +0 -14
  109. package/dist/execution/multicall-batcher.d.ts.map +0 -1
  110. package/dist/execution/multicall-batcher.js +0 -53
  111. package/dist/execution/multicall.d.ts +0 -42
  112. package/dist/execution/multicall.d.ts.map +0 -1
  113. package/dist/execution/multicall.js +0 -29
  114. package/dist/execution/result-cache.d.ts +0 -47
  115. package/dist/execution/result-cache.d.ts.map +0 -1
  116. package/dist/execution/result-cache.js +0 -65
  117. package/dist/execution/round-executor.d.ts +0 -18
  118. package/dist/execution/round-executor.d.ts.map +0 -1
  119. package/dist/execution/round-executor.js +0 -95
  120. package/dist/execution/types.d.ts +0 -55
  121. package/dist/execution/types.d.ts.map +0 -1
  122. package/dist/execution/types.js +0 -1
  123. package/dist/factory.d.ts +0 -3
  124. package/dist/factory.d.ts.map +0 -1
  125. package/dist/factory.js +0 -2
  126. package/dist/index.d.ts +0 -10
  127. package/dist/index.d.ts.map +0 -1
  128. package/dist/index.js +0 -7
@@ -0,0 +1,29 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_errors = require("../errors/errors.cjs");
3
+ require("../errors/index.cjs");
4
+ let _marcbachmann_cel_js = require("@marcbachmann/cel-js");
5
+ let _seljs_common = require("@seljs/common");
6
+ //#region src/environment/error-wrapper.ts
7
+ /**
8
+ * Wraps an unknown error into a known SEL error type.
9
+ * - If the error is already a SEL error, it is returned as is.
10
+ * - If the error is a CEL error, it is wrapped into the corresponding SEL error type.
11
+ * - If the error is an unknown type, it is wrapped into a generic Error.
12
+ *
13
+ * @param error The error to wrap.
14
+ * @returns The wrapped error.
15
+ */
16
+ const wrapError = (error) => {
17
+ if (error instanceof require_errors.SELContractError) return error;
18
+ if (error instanceof _marcbachmann_cel_js.ParseError) return new _seljs_common.SELParseError(error.message, { cause: error });
19
+ if (error instanceof _marcbachmann_cel_js.EvaluationError) {
20
+ const cause = error.cause;
21
+ if (cause instanceof require_errors.SELContractError) return cause;
22
+ return new require_errors.SELEvaluationError(error.message, { cause: error });
23
+ }
24
+ if (error instanceof _marcbachmann_cel_js.TypeError) return new _seljs_common.SELTypeError(error.message, { cause: error });
25
+ if (error instanceof Error) return error;
26
+ return new Error(String(error));
27
+ };
28
+ //#endregion
29
+ exports.wrapError = wrapError;
@@ -0,0 +1,27 @@
1
+ import { SELContractError, SELEvaluationError, SELParseError, SELTypeError } from "../errors/errors.mjs";
2
+ import "../errors/index.mjs";
3
+ import { EvaluationError, ParseError, TypeError } from "@marcbachmann/cel-js";
4
+ //#region src/environment/error-wrapper.ts
5
+ /**
6
+ * Wraps an unknown error into a known SEL error type.
7
+ * - If the error is already a SEL error, it is returned as is.
8
+ * - If the error is a CEL error, it is wrapped into the corresponding SEL error type.
9
+ * - If the error is an unknown type, it is wrapped into a generic Error.
10
+ *
11
+ * @param error The error to wrap.
12
+ * @returns The wrapped error.
13
+ */
14
+ const wrapError = (error) => {
15
+ if (error instanceof SELContractError) return error;
16
+ if (error instanceof ParseError) return new SELParseError(error.message, { cause: error });
17
+ if (error instanceof EvaluationError) {
18
+ const cause = error.cause;
19
+ if (cause instanceof SELContractError) return cause;
20
+ return new SELEvaluationError(error.message, { cause: error });
21
+ }
22
+ if (error instanceof TypeError) return new SELTypeError(error.message, { cause: error });
23
+ if (error instanceof Error) return error;
24
+ return new Error(String(error));
25
+ };
26
+ //#endregion
27
+ export { wrapError };
@@ -0,0 +1 @@
1
+ require("./environment.cjs");
@@ -0,0 +1,2 @@
1
+ import { MulticallOptions, SELLimits, SELRuntimeConfig } from "./types.mjs";
2
+ import { SELRuntime } from "./environment.mjs";
@@ -0,0 +1,2 @@
1
+ import "./environment.mjs";
2
+ export {};
@@ -0,0 +1,48 @@
1
+ //#region src/environment/replay-cache.ts
2
+ const resolveReplayArgs = (args, variables, results, paramTypes, codecRegistry) => args.map((arg, i) => {
3
+ const celType = paramTypes[i] ?? "dyn";
4
+ if (arg.type === "literal") return codecRegistry.encode(celType, arg.value);
5
+ if (arg.type === "variable") {
6
+ const name = arg.variableName;
7
+ if (!name) return;
8
+ return codecRegistry.encode(celType, variables[name]);
9
+ }
10
+ const id = arg.dependsOnCallId;
11
+ if (!id) return;
12
+ return codecRegistry.encode(celType, results.get(id));
13
+ });
14
+ /**
15
+ * Builds a replay cache that maps unique identifiers for contract calls to their results.
16
+ * This allows for efficient retrieval of results during execution replay, ensuring that the same inputs yield the same outputs without needing to re-execute the calls.
17
+ *
18
+ * @param calls An array of collected contract calls, each containing information about the contract, method, arguments, and dependencies.
19
+ * @param results A map of call IDs to their corresponding results, which will be used to resolve arguments that depend on previous calls.
20
+ * @param variables A record of variable names to their values, which will be used to resolve arguments that depend on variables.
21
+ */
22
+ const buildExecutionReplayCache = (calls, results, variables, codecRegistry, getParamTypes) => {
23
+ const replayCache = /* @__PURE__ */ new Map();
24
+ for (const call of calls) {
25
+ const result = results.get(call.id);
26
+ const paramTypes = getParamTypes(call.contract, call.method);
27
+ const resolvedArgs = resolveReplayArgs(call.args, variables, results, paramTypes, codecRegistry);
28
+ const replayCallId = createReplayCallId(call.contract, call.method, resolvedArgs);
29
+ replayCache.set(replayCallId, result);
30
+ }
31
+ return replayCache;
32
+ };
33
+ /**
34
+ * Creates a unique identifier for a contract call based on contract name,
35
+ * method, and arguments.
36
+ *
37
+ * IMPORTANT: Args must be pre-encoded via codecRegistry.encode() before
38
+ * calling this function. The encode step normalizes types (e.g., sol_int
39
+ * always produces bigint, sol_address always produces string), which
40
+ * prevents type collisions in String() serialization. If args are NOT
41
+ * pre-encoded, String(42n) === String(42) would cause cache key collisions.
42
+ */
43
+ const createReplayCallId = (contract, method, args) => {
44
+ return `${contract}:${method}:${args.map((arg) => String(arg)).join(",")}`;
45
+ };
46
+ //#endregion
47
+ exports.buildExecutionReplayCache = buildExecutionReplayCache;
48
+ exports.createReplayCallId = createReplayCallId;
@@ -0,0 +1,47 @@
1
+ //#region src/environment/replay-cache.ts
2
+ const resolveReplayArgs = (args, variables, results, paramTypes, codecRegistry) => args.map((arg, i) => {
3
+ const celType = paramTypes[i] ?? "dyn";
4
+ if (arg.type === "literal") return codecRegistry.encode(celType, arg.value);
5
+ if (arg.type === "variable") {
6
+ const name = arg.variableName;
7
+ if (!name) return;
8
+ return codecRegistry.encode(celType, variables[name]);
9
+ }
10
+ const id = arg.dependsOnCallId;
11
+ if (!id) return;
12
+ return codecRegistry.encode(celType, results.get(id));
13
+ });
14
+ /**
15
+ * Builds a replay cache that maps unique identifiers for contract calls to their results.
16
+ * This allows for efficient retrieval of results during execution replay, ensuring that the same inputs yield the same outputs without needing to re-execute the calls.
17
+ *
18
+ * @param calls An array of collected contract calls, each containing information about the contract, method, arguments, and dependencies.
19
+ * @param results A map of call IDs to their corresponding results, which will be used to resolve arguments that depend on previous calls.
20
+ * @param variables A record of variable names to their values, which will be used to resolve arguments that depend on variables.
21
+ */
22
+ const buildExecutionReplayCache = (calls, results, variables, codecRegistry, getParamTypes) => {
23
+ const replayCache = /* @__PURE__ */ new Map();
24
+ for (const call of calls) {
25
+ const result = results.get(call.id);
26
+ const paramTypes = getParamTypes(call.contract, call.method);
27
+ const resolvedArgs = resolveReplayArgs(call.args, variables, results, paramTypes, codecRegistry);
28
+ const replayCallId = createReplayCallId(call.contract, call.method, resolvedArgs);
29
+ replayCache.set(replayCallId, result);
30
+ }
31
+ return replayCache;
32
+ };
33
+ /**
34
+ * Creates a unique identifier for a contract call based on contract name,
35
+ * method, and arguments.
36
+ *
37
+ * IMPORTANT: Args must be pre-encoded via codecRegistry.encode() before
38
+ * calling this function. The encode step normalizes types (e.g., sol_int
39
+ * always produces bigint, sol_address always produces string), which
40
+ * prevents type collisions in String() serialization. If args are NOT
41
+ * pre-encoded, String(42n) === String(42) would cause cache key collisions.
42
+ */
43
+ const createReplayCallId = (contract, method, args) => {
44
+ return `${contract}:${method}:${args.map((arg) => String(arg)).join(",")}`;
45
+ };
46
+ //#endregion
47
+ export { buildExecutionReplayCache, createReplayCallId };
@@ -0,0 +1,60 @@
1
+ import { SELSchema } from "@seljs/schema";
2
+ import { Address, PublicClient } from "viem";
3
+
4
+ //#region src/environment/types.d.ts
5
+ /**
6
+ * Options for multicall3 batching of contract calls.
7
+ *
8
+ * When multiple independent contract calls are executed in the same round,
9
+ * they are batched into a single multicall3 RPC request for efficiency.
10
+ */
11
+ interface MulticallOptions {
12
+ /** Maximum number of calls per multicall3 batch. Unbounded if omitted. */
13
+ batchSize?: number;
14
+ /** Custom multicall3 contract address. Defaults to the canonical deployment. */
15
+ address?: Address;
16
+ }
17
+ /**
18
+ * Limits for expression parsing and contract call execution.
19
+ *
20
+ * AST limits (`maxAstNodes`, `maxDepth`, `maxListElements`, `maxMapEntries`,
21
+ * `maxCallArguments`) are forwarded to the underlying CEL parser to constrain
22
+ * expression complexity.
23
+ *
24
+ * Execution limits (`maxRounds`, `maxCalls`) bound the multi-round contract
25
+ * execution engine. An {@link ExecutionLimitError} is thrown when exceeded.
26
+ */
27
+ interface SELLimits {
28
+ /** Maximum number of AST nodes allowed in a parsed expression */
29
+ maxAstNodes?: number;
30
+ /** Maximum nesting depth of the AST */
31
+ maxDepth?: number;
32
+ /** Maximum number of elements in a list literal */
33
+ maxListElements?: number;
34
+ /** Maximum number of entries in a map literal */
35
+ maxMapEntries?: number;
36
+ /** Maximum number of arguments in a single function call */
37
+ maxCallArguments?: number;
38
+ /** Maximum number of dependency-ordered execution rounds (default: 10) */
39
+ maxRounds?: number;
40
+ /** Maximum total number of contract calls across all rounds (default: 100) */
41
+ maxCalls?: number;
42
+ }
43
+ /**
44
+ * Configuration for creating an immutable {@link SELRuntime}.
45
+ *
46
+ * All contracts and context must be declared here — the environment
47
+ * cannot be mutated after construction.
48
+ */
49
+ interface SELRuntimeConfig {
50
+ /** SEL schema describing contracts, variables, types, functions, and macros */
51
+ schema: SELSchema;
52
+ /** Viem public client for executing on-chain contract reads */
53
+ client?: PublicClient;
54
+ /** Multicall3 batching options for contract call execution */
55
+ multicall?: MulticallOptions;
56
+ /** AST parsing and execution limits */
57
+ limits?: SELLimits;
58
+ }
59
+ //#endregion
60
+ export { MulticallOptions, SELLimits, SELRuntimeConfig };
@@ -0,0 +1,60 @@
1
+ import { Address, PublicClient } from "viem";
2
+ import { SELSchema } from "@seljs/schema";
3
+
4
+ //#region src/environment/types.d.ts
5
+ /**
6
+ * Options for multicall3 batching of contract calls.
7
+ *
8
+ * When multiple independent contract calls are executed in the same round,
9
+ * they are batched into a single multicall3 RPC request for efficiency.
10
+ */
11
+ interface MulticallOptions {
12
+ /** Maximum number of calls per multicall3 batch. Unbounded if omitted. */
13
+ batchSize?: number;
14
+ /** Custom multicall3 contract address. Defaults to the canonical deployment. */
15
+ address?: Address;
16
+ }
17
+ /**
18
+ * Limits for expression parsing and contract call execution.
19
+ *
20
+ * AST limits (`maxAstNodes`, `maxDepth`, `maxListElements`, `maxMapEntries`,
21
+ * `maxCallArguments`) are forwarded to the underlying CEL parser to constrain
22
+ * expression complexity.
23
+ *
24
+ * Execution limits (`maxRounds`, `maxCalls`) bound the multi-round contract
25
+ * execution engine. An {@link ExecutionLimitError} is thrown when exceeded.
26
+ */
27
+ interface SELLimits {
28
+ /** Maximum number of AST nodes allowed in a parsed expression */
29
+ maxAstNodes?: number;
30
+ /** Maximum nesting depth of the AST */
31
+ maxDepth?: number;
32
+ /** Maximum number of elements in a list literal */
33
+ maxListElements?: number;
34
+ /** Maximum number of entries in a map literal */
35
+ maxMapEntries?: number;
36
+ /** Maximum number of arguments in a single function call */
37
+ maxCallArguments?: number;
38
+ /** Maximum number of dependency-ordered execution rounds (default: 10) */
39
+ maxRounds?: number;
40
+ /** Maximum total number of contract calls across all rounds (default: 100) */
41
+ maxCalls?: number;
42
+ }
43
+ /**
44
+ * Configuration for creating an immutable {@link SELRuntime}.
45
+ *
46
+ * All contracts and context must be declared here — the environment
47
+ * cannot be mutated after construction.
48
+ */
49
+ interface SELRuntimeConfig {
50
+ /** SEL schema describing contracts, variables, types, functions, and macros */
51
+ schema: SELSchema;
52
+ /** Viem public client for executing on-chain contract reads */
53
+ client?: PublicClient;
54
+ /** Multicall3 batching options for contract call execution */
55
+ multicall?: MulticallOptions;
56
+ /** AST parsing and execution limits */
57
+ limits?: SELLimits;
58
+ }
59
+ //#endregion
60
+ export { MulticallOptions, SELLimits, SELRuntimeConfig };
@@ -0,0 +1,68 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ let _seljs_common = require("@seljs/common");
3
+ //#region src/errors/errors.ts
4
+ /**
5
+ * Thrown when CEL expression evaluation fails.
6
+ * Wraps cel-js EvaluationError with additional context.
7
+ */
8
+ var SELEvaluationError = class extends _seljs_common.SELError {};
9
+ /**
10
+ * Thrown when contract validation or execution fails.
11
+ * Includes optional contract name and method name for context.
12
+ */
13
+ var SELContractError = class extends _seljs_common.SELError {
14
+ contractName;
15
+ methodName;
16
+ constructor(message, options) {
17
+ super(message, { cause: options?.cause });
18
+ this.contractName = options?.contractName;
19
+ this.methodName = options?.methodName;
20
+ }
21
+ };
22
+ /**
23
+ * Thrown when a circular dependency is detected in the call dependency graph.
24
+ * Indicates that call A depends on call B which depends on call A (directly or transitively).
25
+ */
26
+ var CircularDependencyError = class extends _seljs_common.SELError {
27
+ callIds;
28
+ constructor(message, options) {
29
+ super(message, { cause: options?.cause });
30
+ this.callIds = options?.callIds ?? [];
31
+ }
32
+ };
33
+ /**
34
+ * Thrown when execution limits are exceeded (maxRounds or maxCalls).
35
+ * Prevents infinite loops and runaway execution.
36
+ */
37
+ var ExecutionLimitError = class extends _seljs_common.SELError {
38
+ limitType;
39
+ limit;
40
+ actual;
41
+ constructor(message, options) {
42
+ super(message, { cause: options?.cause });
43
+ this.limitType = options?.limitType ?? "maxRounds";
44
+ this.limit = options?.limit ?? 0;
45
+ this.actual = options?.actual ?? 0;
46
+ }
47
+ };
48
+ /**
49
+ * Thrown when a Multicall3 batch execution fails.
50
+ * Includes the failed call index and optional contract name/method name for context.
51
+ */
52
+ var MulticallBatchError = class extends _seljs_common.SELError {
53
+ failedCallIndex;
54
+ contractName;
55
+ methodName;
56
+ constructor(message, options) {
57
+ super(message, { cause: options?.cause });
58
+ this.failedCallIndex = options?.failedCallIndex;
59
+ this.contractName = options?.contractName;
60
+ this.methodName = options?.methodName;
61
+ }
62
+ };
63
+ //#endregion
64
+ exports.CircularDependencyError = CircularDependencyError;
65
+ exports.ExecutionLimitError = ExecutionLimitError;
66
+ exports.MulticallBatchError = MulticallBatchError;
67
+ exports.SELContractError = SELContractError;
68
+ exports.SELEvaluationError = SELEvaluationError;
@@ -0,0 +1,64 @@
1
+ import { SELError, SELParseError, SELTypeError } from "@seljs/common";
2
+
3
+ //#region src/errors/errors.d.ts
4
+ /**
5
+ * Thrown when CEL expression evaluation fails.
6
+ * Wraps cel-js EvaluationError with additional context.
7
+ */
8
+ declare class SELEvaluationError extends SELError {}
9
+ /**
10
+ * Thrown when contract validation or execution fails.
11
+ * Includes optional contract name and method name for context.
12
+ */
13
+ declare class SELContractError extends SELError {
14
+ readonly contractName?: string;
15
+ readonly methodName?: string;
16
+ constructor(message: string, options?: {
17
+ cause?: unknown;
18
+ contractName?: string;
19
+ methodName?: string;
20
+ });
21
+ }
22
+ /**
23
+ * Thrown when a circular dependency is detected in the call dependency graph.
24
+ * Indicates that call A depends on call B which depends on call A (directly or transitively).
25
+ */
26
+ declare class CircularDependencyError extends SELError {
27
+ readonly callIds: string[];
28
+ constructor(message: string, options?: {
29
+ cause?: unknown;
30
+ callIds?: string[];
31
+ });
32
+ }
33
+ /**
34
+ * Thrown when execution limits are exceeded (maxRounds or maxCalls).
35
+ * Prevents infinite loops and runaway execution.
36
+ */
37
+ declare class ExecutionLimitError extends SELError {
38
+ readonly limitType: "maxRounds" | "maxCalls";
39
+ readonly limit: number;
40
+ readonly actual: number;
41
+ constructor(message: string, options?: {
42
+ cause?: unknown;
43
+ limitType?: "maxRounds" | "maxCalls";
44
+ limit?: number;
45
+ actual?: number;
46
+ });
47
+ }
48
+ /**
49
+ * Thrown when a Multicall3 batch execution fails.
50
+ * Includes the failed call index and optional contract name/method name for context.
51
+ */
52
+ declare class MulticallBatchError extends SELError {
53
+ readonly failedCallIndex?: number;
54
+ readonly contractName?: string;
55
+ readonly methodName?: string;
56
+ constructor(message: string, options?: {
57
+ cause?: unknown;
58
+ failedCallIndex?: number;
59
+ contractName?: string;
60
+ methodName?: string;
61
+ });
62
+ }
63
+ //#endregion
64
+ export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELParseError, SELTypeError };
@@ -0,0 +1,64 @@
1
+ import { SELError, SELParseError, SELTypeError } from "@seljs/common";
2
+
3
+ //#region src/errors/errors.d.ts
4
+ /**
5
+ * Thrown when CEL expression evaluation fails.
6
+ * Wraps cel-js EvaluationError with additional context.
7
+ */
8
+ declare class SELEvaluationError extends SELError {}
9
+ /**
10
+ * Thrown when contract validation or execution fails.
11
+ * Includes optional contract name and method name for context.
12
+ */
13
+ declare class SELContractError extends SELError {
14
+ readonly contractName?: string;
15
+ readonly methodName?: string;
16
+ constructor(message: string, options?: {
17
+ cause?: unknown;
18
+ contractName?: string;
19
+ methodName?: string;
20
+ });
21
+ }
22
+ /**
23
+ * Thrown when a circular dependency is detected in the call dependency graph.
24
+ * Indicates that call A depends on call B which depends on call A (directly or transitively).
25
+ */
26
+ declare class CircularDependencyError extends SELError {
27
+ readonly callIds: string[];
28
+ constructor(message: string, options?: {
29
+ cause?: unknown;
30
+ callIds?: string[];
31
+ });
32
+ }
33
+ /**
34
+ * Thrown when execution limits are exceeded (maxRounds or maxCalls).
35
+ * Prevents infinite loops and runaway execution.
36
+ */
37
+ declare class ExecutionLimitError extends SELError {
38
+ readonly limitType: "maxRounds" | "maxCalls";
39
+ readonly limit: number;
40
+ readonly actual: number;
41
+ constructor(message: string, options?: {
42
+ cause?: unknown;
43
+ limitType?: "maxRounds" | "maxCalls";
44
+ limit?: number;
45
+ actual?: number;
46
+ });
47
+ }
48
+ /**
49
+ * Thrown when a Multicall3 batch execution fails.
50
+ * Includes the failed call index and optional contract name/method name for context.
51
+ */
52
+ declare class MulticallBatchError extends SELError {
53
+ readonly failedCallIndex?: number;
54
+ readonly contractName?: string;
55
+ readonly methodName?: string;
56
+ constructor(message: string, options?: {
57
+ cause?: unknown;
58
+ failedCallIndex?: number;
59
+ contractName?: string;
60
+ methodName?: string;
61
+ });
62
+ }
63
+ //#endregion
64
+ export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELParseError, SELTypeError };
@@ -0,0 +1,63 @@
1
+ import { SELError, SELParseError, SELTypeError } from "@seljs/common";
2
+ //#region src/errors/errors.ts
3
+ /**
4
+ * Thrown when CEL expression evaluation fails.
5
+ * Wraps cel-js EvaluationError with additional context.
6
+ */
7
+ var SELEvaluationError = class extends SELError {};
8
+ /**
9
+ * Thrown when contract validation or execution fails.
10
+ * Includes optional contract name and method name for context.
11
+ */
12
+ var SELContractError = class extends SELError {
13
+ contractName;
14
+ methodName;
15
+ constructor(message, options) {
16
+ super(message, { cause: options?.cause });
17
+ this.contractName = options?.contractName;
18
+ this.methodName = options?.methodName;
19
+ }
20
+ };
21
+ /**
22
+ * Thrown when a circular dependency is detected in the call dependency graph.
23
+ * Indicates that call A depends on call B which depends on call A (directly or transitively).
24
+ */
25
+ var CircularDependencyError = class extends SELError {
26
+ callIds;
27
+ constructor(message, options) {
28
+ super(message, { cause: options?.cause });
29
+ this.callIds = options?.callIds ?? [];
30
+ }
31
+ };
32
+ /**
33
+ * Thrown when execution limits are exceeded (maxRounds or maxCalls).
34
+ * Prevents infinite loops and runaway execution.
35
+ */
36
+ var ExecutionLimitError = class extends SELError {
37
+ limitType;
38
+ limit;
39
+ actual;
40
+ constructor(message, options) {
41
+ super(message, { cause: options?.cause });
42
+ this.limitType = options?.limitType ?? "maxRounds";
43
+ this.limit = options?.limit ?? 0;
44
+ this.actual = options?.actual ?? 0;
45
+ }
46
+ };
47
+ /**
48
+ * Thrown when a Multicall3 batch execution fails.
49
+ * Includes the failed call index and optional contract name/method name for context.
50
+ */
51
+ var MulticallBatchError = class extends SELError {
52
+ failedCallIndex;
53
+ contractName;
54
+ methodName;
55
+ constructor(message, options) {
56
+ super(message, { cause: options?.cause });
57
+ this.failedCallIndex = options?.failedCallIndex;
58
+ this.contractName = options?.contractName;
59
+ this.methodName = options?.methodName;
60
+ }
61
+ };
62
+ //#endregion
63
+ export { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELParseError, SELTypeError };
@@ -0,0 +1,3 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ require("./errors.cjs");
3
+ require("@seljs/common");
@@ -0,0 +1 @@
1
+ import { CircularDependencyError, ExecutionLimitError, MulticallBatchError, SELContractError, SELError, SELEvaluationError, SELParseError, SELTypeError } from "./errors.mjs";
@@ -0,0 +1,2 @@
1
+ import "./errors.mjs";
2
+ export {};
@@ -0,0 +1,45 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_debug = require("../debug.cjs");
3
+ const require_multicall_batcher = require("./multicall-batcher.cjs");
4
+ const require_result_cache = require("./result-cache.cjs");
5
+ const require_round_executor = require("./round-executor.cjs");
6
+ let viem_actions = require("viem/actions");
7
+ //#region src/execution/multi-round-executor.ts
8
+ const debug = require_debug.createLogger("execute");
9
+ var MultiRoundExecutor = class {
10
+ contracts;
11
+ constructor(client, contracts, multicallOptions) {
12
+ this.client = client;
13
+ this.multicallOptions = multicallOptions;
14
+ this.contracts = contracts;
15
+ }
16
+ async execute(plan, variables = {}, blockNumber) {
17
+ const lockedBlockNumber = blockNumber ?? await (0, viem_actions.getBlockNumber)(this.client);
18
+ debug("start: %d rounds, %d calls, block=%s", plan.rounds.length, plan.totalCalls, String(lockedBlockNumber));
19
+ const cache = new require_result_cache.ResultCache();
20
+ const batcher = new require_multicall_batcher.MulticallBatcher(this.client, this.multicallOptions);
21
+ const executor = new require_round_executor.RoundExecutor(this.contracts, cache, batcher);
22
+ const context = {
23
+ client: this.client,
24
+ blockNumber: lockedBlockNumber,
25
+ variables
26
+ };
27
+ for (const round of plan.rounds) {
28
+ debug("round %d: %d calls", round.roundNumber, round.calls.length);
29
+ await executor.executeRound(round, context);
30
+ }
31
+ const results = /* @__PURE__ */ new Map();
32
+ for (const round of plan.rounds) for (const call of round.calls) results.set(call.id, cache.get(call.id));
33
+ debug("complete: %d results collected", results.size);
34
+ return {
35
+ results,
36
+ meta: {
37
+ roundsExecuted: plan.rounds.length,
38
+ totalCalls: plan.totalCalls,
39
+ blockNumber: lockedBlockNumber
40
+ }
41
+ };
42
+ }
43
+ };
44
+ //#endregion
45
+ exports.MultiRoundExecutor = MultiRoundExecutor;
@@ -0,0 +1,44 @@
1
+ import { createLogger } from "../debug.mjs";
2
+ import { MulticallBatcher } from "./multicall-batcher.mjs";
3
+ import { ResultCache } from "./result-cache.mjs";
4
+ import { RoundExecutor } from "./round-executor.mjs";
5
+ import { getBlockNumber } from "viem/actions";
6
+ //#region src/execution/multi-round-executor.ts
7
+ const debug = createLogger("execute");
8
+ var MultiRoundExecutor = class {
9
+ contracts;
10
+ constructor(client, contracts, multicallOptions) {
11
+ this.client = client;
12
+ this.multicallOptions = multicallOptions;
13
+ this.contracts = contracts;
14
+ }
15
+ async execute(plan, variables = {}, blockNumber) {
16
+ const lockedBlockNumber = blockNumber ?? await getBlockNumber(this.client);
17
+ debug("start: %d rounds, %d calls, block=%s", plan.rounds.length, plan.totalCalls, String(lockedBlockNumber));
18
+ const cache = new ResultCache();
19
+ const batcher = new MulticallBatcher(this.client, this.multicallOptions);
20
+ const executor = new RoundExecutor(this.contracts, cache, batcher);
21
+ const context = {
22
+ client: this.client,
23
+ blockNumber: lockedBlockNumber,
24
+ variables
25
+ };
26
+ for (const round of plan.rounds) {
27
+ debug("round %d: %d calls", round.roundNumber, round.calls.length);
28
+ await executor.executeRound(round, context);
29
+ }
30
+ const results = /* @__PURE__ */ new Map();
31
+ for (const round of plan.rounds) for (const call of round.calls) results.set(call.id, cache.get(call.id));
32
+ debug("complete: %d results collected", results.size);
33
+ return {
34
+ results,
35
+ meta: {
36
+ roundsExecuted: plan.rounds.length,
37
+ totalCalls: plan.totalCalls,
38
+ blockNumber: lockedBlockNumber
39
+ }
40
+ };
41
+ }
42
+ };
43
+ //#endregion
44
+ export { MultiRoundExecutor };