@seljs/runtime 1.0.0 → 1.0.1

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 (129) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/dist/analysis/call-collector.cjs +233 -0
  4. package/dist/analysis/call-collector.mjs +232 -0
  5. package/dist/analysis/dependency-analyzer.cjs +68 -0
  6. package/dist/analysis/dependency-analyzer.mjs +68 -0
  7. package/dist/analysis/round-planner.cjs +65 -0
  8. package/dist/analysis/round-planner.mjs +65 -0
  9. package/dist/analysis/types.d.cts +115 -0
  10. package/dist/analysis/types.d.mts +115 -0
  11. package/dist/debug.cjs +17 -0
  12. package/dist/debug.mjs +15 -0
  13. package/dist/environment/context.cjs +11 -0
  14. package/dist/environment/context.mjs +11 -0
  15. package/dist/environment/contract-caller.cjs +81 -0
  16. package/dist/environment/contract-caller.mjs +77 -0
  17. package/dist/environment/environment.cjs +254 -0
  18. package/dist/environment/environment.d.cts +84 -0
  19. package/dist/environment/environment.d.mts +84 -0
  20. package/dist/environment/environment.mjs +252 -0
  21. package/dist/environment/error-wrapper.cjs +29 -0
  22. package/dist/environment/error-wrapper.mjs +27 -0
  23. package/dist/environment/index.cjs +1 -0
  24. package/dist/environment/index.d.mts +2 -0
  25. package/dist/environment/index.mjs +2 -0
  26. package/dist/environment/replay-cache.cjs +48 -0
  27. package/dist/environment/replay-cache.mjs +47 -0
  28. package/dist/environment/types.d.cts +60 -0
  29. package/dist/environment/types.d.mts +60 -0
  30. package/dist/errors/errors.cjs +68 -0
  31. package/dist/errors/errors.d.cts +64 -0
  32. package/dist/errors/errors.d.mts +64 -0
  33. package/dist/errors/errors.mjs +63 -0
  34. package/dist/errors/index.cjs +3 -0
  35. package/dist/errors/index.d.mts +1 -0
  36. package/dist/errors/index.mjs +2 -0
  37. package/dist/execution/multi-round-executor.cjs +45 -0
  38. package/dist/execution/multi-round-executor.mjs +44 -0
  39. package/dist/execution/multicall-batcher.cjs +51 -0
  40. package/dist/execution/multicall-batcher.mjs +50 -0
  41. package/dist/execution/multicall.cjs +39 -0
  42. package/dist/execution/multicall.mjs +38 -0
  43. package/dist/execution/result-cache.cjs +63 -0
  44. package/dist/execution/result-cache.mjs +63 -0
  45. package/dist/execution/round-executor.cjs +81 -0
  46. package/dist/execution/round-executor.mjs +80 -0
  47. package/dist/execution/types.d.cts +58 -0
  48. package/dist/execution/types.d.mts +58 -0
  49. package/dist/factory.cjs +6 -0
  50. package/dist/factory.d.cts +7 -0
  51. package/dist/factory.d.mts +6 -0
  52. package/dist/factory.mjs +6 -0
  53. package/dist/index.cjs +18 -0
  54. package/dist/index.d.cts +7 -0
  55. package/dist/index.d.mts +7 -0
  56. package/dist/index.mjs +6 -0
  57. package/package.json +26 -19
  58. package/dist/analysis/call-collector.d.ts +0 -20
  59. package/dist/analysis/call-collector.d.ts.map +0 -1
  60. package/dist/analysis/call-collector.js +0 -272
  61. package/dist/analysis/dependency-analyzer.d.ts +0 -14
  62. package/dist/analysis/dependency-analyzer.d.ts.map +0 -1
  63. package/dist/analysis/dependency-analyzer.js +0 -76
  64. package/dist/analysis/index.d.ts +0 -2
  65. package/dist/analysis/index.d.ts.map +0 -1
  66. package/dist/analysis/index.js +0 -1
  67. package/dist/analysis/round-planner.d.ts +0 -32
  68. package/dist/analysis/round-planner.d.ts.map +0 -1
  69. package/dist/analysis/round-planner.js +0 -69
  70. package/dist/analysis/types.d.ts +0 -113
  71. package/dist/analysis/types.d.ts.map +0 -1
  72. package/dist/analysis/types.js +0 -1
  73. package/dist/debug.d.ts +0 -13
  74. package/dist/debug.d.ts.map +0 -1
  75. package/dist/debug.js +0 -12
  76. package/dist/environment/context.d.ts +0 -3
  77. package/dist/environment/context.d.ts.map +0 -1
  78. package/dist/environment/context.js +0 -8
  79. package/dist/environment/contract-caller.d.ts +0 -25
  80. package/dist/environment/contract-caller.d.ts.map +0 -1
  81. package/dist/environment/contract-caller.js +0 -85
  82. package/dist/environment/environment.d.ts +0 -81
  83. package/dist/environment/environment.d.ts.map +0 -1
  84. package/dist/environment/environment.js +0 -279
  85. package/dist/environment/error-wrapper.d.ts +0 -11
  86. package/dist/environment/error-wrapper.d.ts.map +0 -1
  87. package/dist/environment/error-wrapper.js +0 -33
  88. package/dist/environment/index.d.ts +0 -3
  89. package/dist/environment/index.d.ts.map +0 -1
  90. package/dist/environment/index.js +0 -2
  91. package/dist/environment/replay-cache.d.ts +0 -23
  92. package/dist/environment/replay-cache.d.ts.map +0 -1
  93. package/dist/environment/replay-cache.js +0 -51
  94. package/dist/environment/types.d.ts +0 -57
  95. package/dist/environment/types.d.ts.map +0 -1
  96. package/dist/environment/types.js +0 -1
  97. package/dist/errors/errors.d.ts +0 -63
  98. package/dist/errors/errors.d.ts.map +0 -1
  99. package/dist/errors/errors.js +0 -63
  100. package/dist/errors/index.d.ts +0 -2
  101. package/dist/errors/index.d.ts.map +0 -1
  102. package/dist/errors/index.js +0 -1
  103. package/dist/execution/index.d.ts +0 -2
  104. package/dist/execution/index.d.ts.map +0 -1
  105. package/dist/execution/index.js +0 -1
  106. package/dist/execution/multi-round-executor.d.ts +0 -17
  107. package/dist/execution/multi-round-executor.d.ts.map +0 -1
  108. package/dist/execution/multi-round-executor.js +0 -47
  109. package/dist/execution/multicall-batcher.d.ts +0 -14
  110. package/dist/execution/multicall-batcher.d.ts.map +0 -1
  111. package/dist/execution/multicall-batcher.js +0 -53
  112. package/dist/execution/multicall.d.ts +0 -42
  113. package/dist/execution/multicall.d.ts.map +0 -1
  114. package/dist/execution/multicall.js +0 -29
  115. package/dist/execution/result-cache.d.ts +0 -47
  116. package/dist/execution/result-cache.d.ts.map +0 -1
  117. package/dist/execution/result-cache.js +0 -65
  118. package/dist/execution/round-executor.d.ts +0 -18
  119. package/dist/execution/round-executor.d.ts.map +0 -1
  120. package/dist/execution/round-executor.js +0 -95
  121. package/dist/execution/types.d.ts +0 -55
  122. package/dist/execution/types.d.ts.map +0 -1
  123. package/dist/execution/types.js +0 -1
  124. package/dist/factory.d.ts +0 -3
  125. package/dist/factory.d.ts.map +0 -1
  126. package/dist/factory.js +0 -2
  127. package/dist/index.d.ts +0 -10
  128. package/dist/index.d.ts.map +0 -1
  129. package/dist/index.js +0 -7
@@ -1,33 +0,0 @@
1
- import { TypeError as CelTypeError, EvaluationError, ParseError, } from "@marcbachmann/cel-js";
2
- import { SELContractError, SELEvaluationError, SELParseError, SELTypeError, } from "../errors/index.js";
3
- /**
4
- * Wraps an unknown error into a known SEL error type.
5
- * - If the error is already a SEL error, it is returned as is.
6
- * - If the error is a CEL error, it is wrapped into the corresponding SEL error type.
7
- * - If the error is an unknown type, it is wrapped into a generic Error.
8
- *
9
- * @param error The error to wrap.
10
- * @returns The wrapped error.
11
- */
12
- export const wrapError = (error) => {
13
- if (error instanceof SELContractError) {
14
- return error;
15
- }
16
- if (error instanceof ParseError) {
17
- return new SELParseError(error.message, { cause: error });
18
- }
19
- if (error instanceof EvaluationError) {
20
- const cause = error.cause;
21
- if (cause instanceof SELContractError) {
22
- return cause;
23
- }
24
- return new SELEvaluationError(error.message, { cause: error });
25
- }
26
- if (error instanceof CelTypeError) {
27
- return new SELTypeError(error.message, { cause: error });
28
- }
29
- if (error instanceof Error) {
30
- return error;
31
- }
32
- return new Error(String(error));
33
- };
@@ -1,3 +0,0 @@
1
- export * from "./environment.js";
2
- export * from "./types.js";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/environment/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from "./environment.js";
2
- export * from "./types.js";
@@ -1,23 +0,0 @@
1
- import type { CollectedCall } from "../analysis/types.js";
2
- import type { CelCodecRegistry } from "@seljs/checker";
3
- /**
4
- * Builds a replay cache that maps unique identifiers for contract calls to their results.
5
- * 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.
6
- *
7
- * @param calls An array of collected contract calls, each containing information about the contract, method, arguments, and dependencies.
8
- * @param results A map of call IDs to their corresponding results, which will be used to resolve arguments that depend on previous calls.
9
- * @param variables A record of variable names to their values, which will be used to resolve arguments that depend on variables.
10
- */
11
- export declare const buildExecutionReplayCache: (calls: CollectedCall[], results: Map<string, unknown>, variables: Record<string, unknown>, codecRegistry: CelCodecRegistry, getParamTypes: (contract: string, method: string) => string[]) => Map<string, unknown>;
12
- /**
13
- * Creates a unique identifier for a contract call based on contract name,
14
- * method, and arguments.
15
- *
16
- * IMPORTANT: Args must be pre-encoded via codecRegistry.encode() before
17
- * calling this function. The encode step normalizes types (e.g., sol_int
18
- * always produces bigint, sol_address always produces string), which
19
- * prevents type collisions in String() serialization. If args are NOT
20
- * pre-encoded, String(42n) === String(42) would cause cache key collisions.
21
- */
22
- export declare const createReplayCallId: (contract: string, method: string, args: unknown[]) => string;
23
- //# sourceMappingURL=replay-cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replay-cache.d.ts","sourceRoot":"","sources":["../../src/environment/replay-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAiCvD;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACrC,OAAO,aAAa,EAAE,EACtB,SAAS,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,eAAe,gBAAgB,EAC/B,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,EAAE,KAE3D,GAAG,CAAC,MAAM,EAAE,OAAO,CAsBrB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC9B,UAAU,MAAM,EAChB,QAAQ,MAAM,EACd,MAAM,OAAO,EAAE,KACb,MAIF,CAAC"}
@@ -1,51 +0,0 @@
1
- const resolveReplayArgs = (args, variables, results, paramTypes, codecRegistry) => args.map((arg, i) => {
2
- const celType = paramTypes[i] ?? "dyn";
3
- if (arg.type === "literal") {
4
- return codecRegistry.encode(celType, arg.value);
5
- }
6
- if (arg.type === "variable") {
7
- const name = arg.variableName;
8
- if (!name) {
9
- return undefined;
10
- }
11
- return codecRegistry.encode(celType, variables[name]);
12
- }
13
- const id = arg.dependsOnCallId;
14
- if (!id) {
15
- return undefined;
16
- }
17
- return codecRegistry.encode(celType, results.get(id));
18
- });
19
- /**
20
- * Builds a replay cache that maps unique identifiers for contract calls to their results.
21
- * 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.
22
- *
23
- * @param calls An array of collected contract calls, each containing information about the contract, method, arguments, and dependencies.
24
- * @param results A map of call IDs to their corresponding results, which will be used to resolve arguments that depend on previous calls.
25
- * @param variables A record of variable names to their values, which will be used to resolve arguments that depend on variables.
26
- */
27
- export const buildExecutionReplayCache = (calls, results, variables, codecRegistry, getParamTypes) => {
28
- const replayCache = new Map();
29
- for (const call of calls) {
30
- const result = results.get(call.id);
31
- const paramTypes = getParamTypes(call.contract, call.method);
32
- const resolvedArgs = resolveReplayArgs(call.args, variables, results, paramTypes, codecRegistry);
33
- const replayCallId = createReplayCallId(call.contract, call.method, resolvedArgs);
34
- replayCache.set(replayCallId, result);
35
- }
36
- return replayCache;
37
- };
38
- /**
39
- * Creates a unique identifier for a contract call based on contract name,
40
- * method, and arguments.
41
- *
42
- * IMPORTANT: Args must be pre-encoded via codecRegistry.encode() before
43
- * calling this function. The encode step normalizes types (e.g., sol_int
44
- * always produces bigint, sol_address always produces string), which
45
- * prevents type collisions in String() serialization. If args are NOT
46
- * pre-encoded, String(42n) === String(42) would cause cache key collisions.
47
- */
48
- export const createReplayCallId = (contract, method, args) => {
49
- const argKey = args.map((arg) => String(arg)).join(",");
50
- return `${contract}:${method}:${argKey}`;
51
- };
@@ -1,57 +0,0 @@
1
- import type { SELSchema } from "@seljs/schema";
2
- import type { Address, PublicClient } from "viem";
3
- /**
4
- * Options for multicall3 batching of contract calls.
5
- *
6
- * When multiple independent contract calls are executed in the same round,
7
- * they are batched into a single multicall3 RPC request for efficiency.
8
- */
9
- export interface MulticallOptions {
10
- /** Maximum number of calls per multicall3 batch. Unbounded if omitted. */
11
- batchSize?: number;
12
- /** Custom multicall3 contract address. Defaults to the canonical deployment. */
13
- address?: Address;
14
- }
15
- /**
16
- * Limits for expression parsing and contract call execution.
17
- *
18
- * AST limits (`maxAstNodes`, `maxDepth`, `maxListElements`, `maxMapEntries`,
19
- * `maxCallArguments`) are forwarded to the underlying CEL parser to constrain
20
- * expression complexity.
21
- *
22
- * Execution limits (`maxRounds`, `maxCalls`) bound the multi-round contract
23
- * execution engine. An {@link ExecutionLimitError} is thrown when exceeded.
24
- */
25
- export interface SELLimits {
26
- /** Maximum number of AST nodes allowed in a parsed expression */
27
- maxAstNodes?: number;
28
- /** Maximum nesting depth of the AST */
29
- maxDepth?: number;
30
- /** Maximum number of elements in a list literal */
31
- maxListElements?: number;
32
- /** Maximum number of entries in a map literal */
33
- maxMapEntries?: number;
34
- /** Maximum number of arguments in a single function call */
35
- maxCallArguments?: number;
36
- /** Maximum number of dependency-ordered execution rounds (default: 10) */
37
- maxRounds?: number;
38
- /** Maximum total number of contract calls across all rounds (default: 100) */
39
- maxCalls?: number;
40
- }
41
- /**
42
- * Configuration for creating an immutable {@link SELRuntime}.
43
- *
44
- * All contracts and context must be declared here — the environment
45
- * cannot be mutated after construction.
46
- */
47
- export interface SELRuntimeConfig {
48
- /** SEL schema describing contracts, variables, types, functions, and macros */
49
- schema: SELSchema;
50
- /** Viem public client for executing on-chain contract reads */
51
- client?: PublicClient;
52
- /** Multicall3 batching options for contract call execution */
53
- multicall?: MulticallOptions;
54
- /** AST parsing and execution limits */
55
- limits?: SELLimits;
56
- }
57
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/environment/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,gFAAgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS;IACzB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,mDAAmD;IACnD,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,+EAA+E;IAC/E,MAAM,EAAE,SAAS,CAAC;IAElB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAE7B,uCAAuC;IACvC,MAAM,CAAC,EAAE,SAAS,CAAC;CACnB"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
1
- import { SELError, SELParseError, SELTypeError } from "@seljs/common";
2
- export { SELError, SELParseError, SELTypeError };
3
- /**
4
- * Thrown when CEL expression evaluation fails.
5
- * Wraps cel-js EvaluationError with additional context.
6
- */
7
- export declare class SELEvaluationError extends SELError {
8
- }
9
- /**
10
- * Thrown when contract validation or execution fails.
11
- * Includes optional contract name and method name for context.
12
- */
13
- export 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
- export 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
- export 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
- export 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
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AAEjD;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,QAAQ;CAAG;AAEnD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC7C,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtC,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAGnC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;CAM1E;AAED;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,QAAQ;IACpD,SAAgB,OAAO,EAAE,MAAM,EAAE,CAAC;gBAGjC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;CAKlD;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;IAChD,SAAgB,SAAS,EAAE,WAAW,GAAG,UAAU,CAAC;IACpD,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAG9B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,SAAS,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;QACrC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KAChB;CAOF;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;IAChD,SAAgB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzC,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtC,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAGnC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB;CAOF"}
@@ -1,63 +0,0 @@
1
- import { SELError, SELParseError, SELTypeError } from "@seljs/common";
2
- // Re-export shared errors from @seljs/common
3
- export { SELError, SELParseError, SELTypeError };
4
- /**
5
- * Thrown when CEL expression evaluation fails.
6
- * Wraps cel-js EvaluationError with additional context.
7
- */
8
- export class SELEvaluationError extends SELError {
9
- }
10
- /**
11
- * Thrown when contract validation or execution fails.
12
- * Includes optional contract name and method name for context.
13
- */
14
- export class SELContractError extends SELError {
15
- contractName;
16
- methodName;
17
- constructor(message, options) {
18
- super(message, { cause: options?.cause });
19
- this.contractName = options?.contractName;
20
- this.methodName = options?.methodName;
21
- }
22
- }
23
- /**
24
- * Thrown when a circular dependency is detected in the call dependency graph.
25
- * Indicates that call A depends on call B which depends on call A (directly or transitively).
26
- */
27
- export class CircularDependencyError extends SELError {
28
- callIds;
29
- constructor(message, options) {
30
- super(message, { cause: options?.cause });
31
- this.callIds = options?.callIds ?? [];
32
- }
33
- }
34
- /**
35
- * Thrown when execution limits are exceeded (maxRounds or maxCalls).
36
- * Prevents infinite loops and runaway execution.
37
- */
38
- export class ExecutionLimitError extends SELError {
39
- limitType;
40
- limit;
41
- actual;
42
- constructor(message, options) {
43
- super(message, { cause: options?.cause });
44
- this.limitType = options?.limitType ?? "maxRounds";
45
- this.limit = options?.limit ?? 0;
46
- this.actual = options?.actual ?? 0;
47
- }
48
- }
49
- /**
50
- * Thrown when a Multicall3 batch execution fails.
51
- * Includes the failed call index and optional contract name/method name for context.
52
- */
53
- export class MulticallBatchError extends SELError {
54
- failedCallIndex;
55
- contractName;
56
- methodName;
57
- constructor(message, options) {
58
- super(message, { cause: options?.cause });
59
- this.failedCallIndex = options?.failedCallIndex;
60
- this.contractName = options?.contractName;
61
- this.methodName = options?.methodName;
62
- }
63
- }
@@ -1,2 +0,0 @@
1
- export * from "./errors.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -1 +0,0 @@
1
- export * from "./errors.js";
@@ -1,2 +0,0 @@
1
- export type * from "./types.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/execution/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import type { ExecutionResult } from "./types.js";
2
- import type { ExecutionPlan } from "../analysis/types.js";
3
- import type { Abi, Address, PublicClient } from "viem";
4
- export declare class MultiRoundExecutor {
5
- private readonly client;
6
- private readonly multicallOptions?;
7
- private readonly contracts;
8
- constructor(client: PublicClient, contracts: Map<string, {
9
- abi: Abi;
10
- address: Address;
11
- }>, multicallOptions?: {
12
- address?: Address;
13
- batchSize?: number;
14
- } | undefined);
15
- execute(plan: ExecutionPlan, variables?: Record<string, unknown>, blockNumber?: bigint): Promise<ExecutionResult>;
16
- }
17
- //# sourceMappingURL=multi-round-executor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multi-round-executor.d.ts","sourceRoot":"","sources":["../../src/execution/multi-round-executor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAIvD,qBAAa,kBAAkB;IAI7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IALnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;gBAGpC,MAAM,EAAE,YAAY,EACrC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,EACrC,gBAAgB,CAAC,EAAE;QACnC,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,YAAA;IAKW,OAAO,CACnB,IAAI,EAAE,aAAa,EACnB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACvC,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,eAAe,CAAC;CA4C3B"}
@@ -1,47 +0,0 @@
1
- import { getBlockNumber } from "viem/actions";
2
- import { MulticallBatcher } from "./multicall-batcher.js";
3
- import { ResultCache } from "./result-cache.js";
4
- import { RoundExecutor } from "./round-executor.js";
5
- import { createLogger } from "../debug.js";
6
- const debug = createLogger("execute");
7
- export class MultiRoundExecutor {
8
- client;
9
- multicallOptions;
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 getBlockNumber(this.client));
18
- debug("start: %d rounds, %d calls, block=%s", plan.rounds.length, plan.totalCalls, String(lockedBlockNumber));
19
- const cache = new ResultCache();
20
- const batcher = new MulticallBatcher(this.client, this.multicallOptions);
21
- const executor = new 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 = new Map();
32
- for (const round of plan.rounds) {
33
- for (const call of round.calls) {
34
- results.set(call.id, cache.get(call.id));
35
- }
36
- }
37
- debug("complete: %d results collected", results.size);
38
- return {
39
- results,
40
- meta: {
41
- roundsExecuted: plan.rounds.length,
42
- totalCalls: plan.totalCalls,
43
- blockNumber: lockedBlockNumber,
44
- },
45
- };
46
- }
47
- }
@@ -1,14 +0,0 @@
1
- import { type MulticallCall, type MulticallResult } from "./multicall.js";
2
- import type { Address, PublicClient } from "viem";
3
- export declare class MulticallBatcher {
4
- private readonly client;
5
- private readonly address;
6
- private readonly batchSize;
7
- constructor(client: PublicClient, options?: {
8
- address?: Address;
9
- batchSize?: number;
10
- });
11
- executeBatch(calls: MulticallCall[], blockNumber: bigint): Promise<MulticallResult[]>;
12
- private executeChunk;
13
- }
14
- //# sourceMappingURL=multicall-batcher.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multicall-batcher.d.ts","sourceRoot":"","sources":["../../src/execution/multicall-batcher.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,aAAa,EAClB,KAAK,eAAe,EAEpB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,OAAO,EAAO,YAAY,EAAE,MAAM,MAAM,CAAC;AAIvD,qBAAa,gBAAgB;IAK3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAGjB,MAAM,EAAE,YAAY,EACrC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAMvC,YAAY,CACxB,KAAK,EAAE,aAAa,EAAE,EACtB,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC;YA+Bf,YAAY;CAuB1B"}
@@ -1,53 +0,0 @@
1
- import { readContract } from "viem/actions";
2
- import { MULTICALL3_ADDRESS, multicall3Abi, } from "./multicall.js";
3
- import { createLogger } from "../debug.js";
4
- import { MulticallBatchError } from "../errors/index.js";
5
- const debug = createLogger("execute:multicall");
6
- export class MulticallBatcher {
7
- client;
8
- address;
9
- batchSize;
10
- constructor(client, options) {
11
- this.client = client;
12
- this.address = options?.address ?? MULTICALL3_ADDRESS;
13
- this.batchSize = options?.batchSize ?? 200;
14
- }
15
- async executeBatch(calls, blockNumber) {
16
- if (calls.length === 0) {
17
- return [];
18
- }
19
- if (calls.length <= this.batchSize) {
20
- debug("batch: %d calls (single chunk)", calls.length);
21
- return await this.executeChunk(calls, blockNumber);
22
- }
23
- debug("batch: %d calls (chunked, batchSize=%d)", calls.length, this.batchSize);
24
- const results = [];
25
- for (let i = 0; i < calls.length; i += this.batchSize) {
26
- const chunk = calls.slice(i, i + this.batchSize);
27
- debug("chunk %d/%d", i / this.batchSize + 1, Math.ceil(calls.length / this.batchSize));
28
- const chunkResults = await this.executeChunk(chunk, blockNumber);
29
- results.push(...chunkResults);
30
- }
31
- return results;
32
- }
33
- async executeChunk(calls, blockNumber) {
34
- try {
35
- const result = (await readContract(this.client, {
36
- address: this.address,
37
- abi: multicall3Abi,
38
- functionName: "aggregate3",
39
- args: [calls],
40
- blockNumber,
41
- }));
42
- return result.map((r) => ({
43
- success: r.success,
44
- returnData: r.returnData,
45
- }));
46
- }
47
- catch (error) {
48
- throw new MulticallBatchError("Multicall3 aggregate3 call failed", {
49
- cause: error,
50
- });
51
- }
52
- }
53
- }
@@ -1,42 +0,0 @@
1
- import type { Address, Hex } from "viem";
2
- export declare const MULTICALL3_ADDRESS: Address;
3
- export declare const multicall3Abi: readonly [{
4
- readonly name: "aggregate3";
5
- readonly type: "function";
6
- readonly stateMutability: "payable";
7
- readonly inputs: readonly [{
8
- readonly name: "calls";
9
- readonly type: "tuple[]";
10
- readonly components: readonly [{
11
- readonly name: "target";
12
- readonly type: "address";
13
- }, {
14
- readonly name: "allowFailure";
15
- readonly type: "bool";
16
- }, {
17
- readonly name: "callData";
18
- readonly type: "bytes";
19
- }];
20
- }];
21
- readonly outputs: readonly [{
22
- readonly name: "returnData";
23
- readonly type: "tuple[]";
24
- readonly components: readonly [{
25
- readonly name: "success";
26
- readonly type: "bool";
27
- }, {
28
- readonly name: "returnData";
29
- readonly type: "bytes";
30
- }];
31
- }];
32
- }];
33
- export interface MulticallCall {
34
- target: Address;
35
- allowFailure: boolean;
36
- callData: Hex;
37
- }
38
- export interface MulticallResult {
39
- success: boolean;
40
- returnData: Hex;
41
- }
42
- //# sourceMappingURL=multicall.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multicall.d.ts","sourceRoot":"","sources":["../../src/execution/multicall.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,eAAO,MAAM,kBAAkB,EAAE,OACY,CAAC;AAE9C,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BhB,CAAC;AAEX,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,GAAG,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,GAAG,CAAC;CAChB"}
@@ -1,29 +0,0 @@
1
- export const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
2
- export const multicall3Abi = [
3
- {
4
- name: "aggregate3",
5
- type: "function",
6
- stateMutability: "payable",
7
- inputs: [
8
- {
9
- name: "calls",
10
- type: "tuple[]",
11
- components: [
12
- { name: "target", type: "address" },
13
- { name: "allowFailure", type: "bool" },
14
- { name: "callData", type: "bytes" },
15
- ],
16
- },
17
- ],
18
- outputs: [
19
- {
20
- name: "returnData",
21
- type: "tuple[]",
22
- components: [
23
- { name: "success", type: "bool" },
24
- { name: "returnData", type: "bytes" },
25
- ],
26
- },
27
- ],
28
- },
29
- ];
@@ -1,47 +0,0 @@
1
- /**
2
- * Cache for storing contract call results during expression evaluation.
3
- *
4
- * Uses Map-based storage with deterministic call IDs for efficient
5
- * lookup and deduplication of repeated contract calls.
6
- */
7
- export declare class ResultCache {
8
- private readonly cache;
9
- /**
10
- * Generate a deterministic call ID from contract details.
11
- *
12
- * The ID format is `contract:method:serializedArgs` where args are
13
- * JSON-stringified with special handling for bigint values.
14
- *
15
- * @param contract - Contract name (e.g., "token", "vault")
16
- * @param method - Method name (e.g., "balanceOf", "totalSupply")
17
- * @param args - Method arguments
18
- * @returns Deterministic call ID string
19
- */
20
- generateCallId(contract: string, method: string, args: unknown[]): string;
21
- /**
22
- * Store a result in the cache.
23
- *
24
- * @param callId - The call ID (from generateCallId)
25
- * @param result - The result to cache
26
- */
27
- set(callId: string, result: unknown): void;
28
- /**
29
- * Retrieve a cached result.
30
- *
31
- * @param callId - The call ID to look up
32
- * @returns The cached result, or undefined if not found
33
- */
34
- get(callId: string): unknown;
35
- /**
36
- * Check if a result is cached.
37
- *
38
- * @param callId - The call ID to check
39
- * @returns true if cached, false otherwise
40
- */
41
- has(callId: string): boolean;
42
- /**
43
- * Clear all cached results.
44
- */
45
- clear(): void;
46
- }
47
- //# sourceMappingURL=result-cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"result-cache.d.ts","sourceRoot":"","sources":["../../src/execution/result-cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,WAAW;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8B;IAEpD;;;;;;;;;;OAUG;IACI,cAAc,CACpB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EAAE,GACb,MAAM;IAoBT;;;;;OAKG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAIjD;;;;;OAKG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAInC;;;;;OAKG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAInC;;OAEG;IACI,KAAK,IAAI,IAAI;CAGpB"}