@grimoirelabs/core 0.1.0
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.
- package/dist/builders/expressions.d.ts +33 -0
- package/dist/builders/expressions.d.ts.map +1 -0
- package/dist/builders/expressions.js +57 -0
- package/dist/builders/expressions.js.map +1 -0
- package/dist/builders/index.d.ts +44 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +32 -0
- package/dist/builders/index.js.map +1 -0
- package/dist/builders/spell-builder.d.ts +124 -0
- package/dist/builders/spell-builder.d.ts.map +1 -0
- package/dist/builders/spell-builder.js +299 -0
- package/dist/builders/spell-builder.js.map +1 -0
- package/dist/builders/step-builder.d.ts +212 -0
- package/dist/builders/step-builder.d.ts.map +1 -0
- package/dist/builders/step-builder.js +499 -0
- package/dist/builders/step-builder.js.map +1 -0
- package/dist/compiler/expression-parser.d.ts +14 -0
- package/dist/compiler/expression-parser.d.ts.map +1 -0
- package/dist/compiler/expression-parser.js +460 -0
- package/dist/compiler/expression-parser.js.map +1 -0
- package/dist/compiler/grimoire/ast.d.ts +450 -0
- package/dist/compiler/grimoire/ast.d.ts.map +1 -0
- package/dist/compiler/grimoire/ast.js +19 -0
- package/dist/compiler/grimoire/ast.js.map +1 -0
- package/dist/compiler/grimoire/errors.d.ts +65 -0
- package/dist/compiler/grimoire/errors.d.ts.map +1 -0
- package/dist/compiler/grimoire/errors.js +86 -0
- package/dist/compiler/grimoire/errors.js.map +1 -0
- package/dist/compiler/grimoire/index.d.ts +24 -0
- package/dist/compiler/grimoire/index.d.ts.map +1 -0
- package/dist/compiler/grimoire/index.js +63 -0
- package/dist/compiler/grimoire/index.js.map +1 -0
- package/dist/compiler/grimoire/parser.d.ts +135 -0
- package/dist/compiler/grimoire/parser.d.ts.map +1 -0
- package/dist/compiler/grimoire/parser.js +2148 -0
- package/dist/compiler/grimoire/parser.js.map +1 -0
- package/dist/compiler/grimoire/tokenizer.d.ts +59 -0
- package/dist/compiler/grimoire/tokenizer.d.ts.map +1 -0
- package/dist/compiler/grimoire/tokenizer.js +509 -0
- package/dist/compiler/grimoire/tokenizer.js.map +1 -0
- package/dist/compiler/grimoire/transformer.d.ts +71 -0
- package/dist/compiler/grimoire/transformer.d.ts.map +1 -0
- package/dist/compiler/grimoire/transformer.js +1011 -0
- package/dist/compiler/grimoire/transformer.js.map +1 -0
- package/dist/compiler/index.d.ts +45 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +97 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/ir-generator.d.ts +16 -0
- package/dist/compiler/ir-generator.d.ts.map +1 -0
- package/dist/compiler/ir-generator.js +997 -0
- package/dist/compiler/ir-generator.js.map +1 -0
- package/dist/compiler/validator.d.ts +15 -0
- package/dist/compiler/validator.d.ts.map +1 -0
- package/dist/compiler/validator.js +401 -0
- package/dist/compiler/validator.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/circuit-breaker.d.ts +59 -0
- package/dist/runtime/circuit-breaker.d.ts.map +1 -0
- package/dist/runtime/circuit-breaker.js +155 -0
- package/dist/runtime/circuit-breaker.js.map +1 -0
- package/dist/runtime/context.d.ts +92 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/context.js +219 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/error-classifier.d.ts +16 -0
- package/dist/runtime/error-classifier.d.ts.map +1 -0
- package/dist/runtime/error-classifier.js +38 -0
- package/dist/runtime/error-classifier.js.map +1 -0
- package/dist/runtime/expression-evaluator.d.ts +36 -0
- package/dist/runtime/expression-evaluator.d.ts.map +1 -0
- package/dist/runtime/expression-evaluator.js +391 -0
- package/dist/runtime/expression-evaluator.js.map +1 -0
- package/dist/runtime/index.d.ts +12 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +11 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/interpreter.d.ts +59 -0
- package/dist/runtime/interpreter.d.ts.map +1 -0
- package/dist/runtime/interpreter.js +414 -0
- package/dist/runtime/interpreter.js.map +1 -0
- package/dist/runtime/skills/registry.d.ts +11 -0
- package/dist/runtime/skills/registry.d.ts.map +1 -0
- package/dist/runtime/skills/registry.js +73 -0
- package/dist/runtime/skills/registry.js.map +1 -0
- package/dist/runtime/sqlite-state-store.d.ts +28 -0
- package/dist/runtime/sqlite-state-store.d.ts.map +1 -0
- package/dist/runtime/sqlite-state-store.js +180 -0
- package/dist/runtime/sqlite-state-store.js.map +1 -0
- package/dist/runtime/state-store.d.ts +52 -0
- package/dist/runtime/state-store.d.ts.map +1 -0
- package/dist/runtime/state-store.js +32 -0
- package/dist/runtime/state-store.js.map +1 -0
- package/dist/runtime/steps/action.d.ts +17 -0
- package/dist/runtime/steps/action.d.ts.map +1 -0
- package/dist/runtime/steps/action.js +430 -0
- package/dist/runtime/steps/action.js.map +1 -0
- package/dist/runtime/steps/advisory.d.ts +28 -0
- package/dist/runtime/steps/advisory.d.ts.map +1 -0
- package/dist/runtime/steps/advisory.js +209 -0
- package/dist/runtime/steps/advisory.js.map +1 -0
- package/dist/runtime/steps/compute.d.ts +9 -0
- package/dist/runtime/steps/compute.d.ts.map +1 -0
- package/dist/runtime/steps/compute.js +74 -0
- package/dist/runtime/steps/compute.js.map +1 -0
- package/dist/runtime/steps/conditional.d.ts +14 -0
- package/dist/runtime/steps/conditional.d.ts.map +1 -0
- package/dist/runtime/steps/conditional.js +58 -0
- package/dist/runtime/steps/conditional.js.map +1 -0
- package/dist/runtime/steps/emit.d.ts +9 -0
- package/dist/runtime/steps/emit.d.ts.map +1 -0
- package/dist/runtime/steps/emit.js +70 -0
- package/dist/runtime/steps/emit.js.map +1 -0
- package/dist/runtime/steps/halt.d.ts +9 -0
- package/dist/runtime/steps/halt.d.ts.map +1 -0
- package/dist/runtime/steps/halt.js +19 -0
- package/dist/runtime/steps/halt.js.map +1 -0
- package/dist/runtime/steps/loop.d.ts +14 -0
- package/dist/runtime/steps/loop.d.ts.map +1 -0
- package/dist/runtime/steps/loop.js +109 -0
- package/dist/runtime/steps/loop.js.map +1 -0
- package/dist/runtime/steps/parallel.d.ts +9 -0
- package/dist/runtime/steps/parallel.d.ts.map +1 -0
- package/dist/runtime/steps/parallel.js +87 -0
- package/dist/runtime/steps/parallel.js.map +1 -0
- package/dist/runtime/steps/pipeline.d.ts +9 -0
- package/dist/runtime/steps/pipeline.d.ts.map +1 -0
- package/dist/runtime/steps/pipeline.js +125 -0
- package/dist/runtime/steps/pipeline.js.map +1 -0
- package/dist/runtime/steps/try.d.ts +13 -0
- package/dist/runtime/steps/try.d.ts.map +1 -0
- package/dist/runtime/steps/try.js +222 -0
- package/dist/runtime/steps/try.js.map +1 -0
- package/dist/runtime/steps/wait.d.ts +9 -0
- package/dist/runtime/steps/wait.d.ts.map +1 -0
- package/dist/runtime/steps/wait.js +38 -0
- package/dist/runtime/steps/wait.js.map +1 -0
- package/dist/types/actions.d.ts +162 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/actions.js +5 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/execution.d.ts +276 -0
- package/dist/types/execution.d.ts.map +1 -0
- package/dist/types/execution.js +5 -0
- package/dist/types/execution.js.map +1 -0
- package/dist/types/expressions.d.ts +100 -0
- package/dist/types/expressions.d.ts.map +1 -0
- package/dist/types/expressions.js +48 -0
- package/dist/types/expressions.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/ir.d.ts +187 -0
- package/dist/types/ir.d.ts.map +1 -0
- package/dist/types/ir.js +5 -0
- package/dist/types/ir.js.map +1 -0
- package/dist/types/policy.d.ts +123 -0
- package/dist/types/policy.d.ts.map +1 -0
- package/dist/types/policy.js +5 -0
- package/dist/types/policy.js.map +1 -0
- package/dist/types/primitives.d.ts +76 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/primitives.js +10 -0
- package/dist/types/primitives.js.map +1 -0
- package/dist/types/steps.d.ts +226 -0
- package/dist/types/steps.d.ts.map +1 -0
- package/dist/types/steps.js +5 -0
- package/dist/types/steps.js.map +1 -0
- package/dist/venues/index.d.ts +6 -0
- package/dist/venues/index.d.ts.map +1 -0
- package/dist/venues/index.js +26 -0
- package/dist/venues/index.js.map +1 -0
- package/dist/venues/types.d.ts +40 -0
- package/dist/venues/types.d.ts.map +1 -0
- package/dist/venues/types.js +5 -0
- package/dist/venues/types.js.map +1 -0
- package/dist/wallet/executor.d.ts +109 -0
- package/dist/wallet/executor.d.ts.map +1 -0
- package/dist/wallet/executor.js +354 -0
- package/dist/wallet/executor.js.map +1 -0
- package/dist/wallet/index.d.ts +14 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +13 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/keystore.d.ts +44 -0
- package/dist/wallet/keystore.d.ts.map +1 -0
- package/dist/wallet/keystore.js +296 -0
- package/dist/wallet/keystore.js.map +1 -0
- package/dist/wallet/provider.d.ts +111 -0
- package/dist/wallet/provider.d.ts.map +1 -0
- package/dist/wallet/provider.js +309 -0
- package/dist/wallet/provider.js.map +1 -0
- package/dist/wallet/tx-builder.d.ts +85 -0
- package/dist/wallet/tx-builder.d.ts.map +1 -0
- package/dist/wallet/tx-builder.js +290 -0
- package/dist/wallet/tx-builder.js.map +1 -0
- package/dist/wallet/types.d.ts +116 -0
- package/dist/wallet/types.d.ts.map +1 -0
- package/dist/wallet/types.js +86 -0
- package/dist/wallet/types.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Circuit Breaker Runtime
|
|
3
|
+
*
|
|
4
|
+
* Implements the CLOSED -> OPEN -> HALF_OPEN state machine for runtime
|
|
5
|
+
* risk controls. Tracks events within time windows and triggers breakers
|
|
6
|
+
* when thresholds are exceeded.
|
|
7
|
+
*/
|
|
8
|
+
export class CircuitBreakerManager {
|
|
9
|
+
breakers;
|
|
10
|
+
now;
|
|
11
|
+
constructor(definitions, nowFn) {
|
|
12
|
+
this.now = nowFn ?? (() => Date.now());
|
|
13
|
+
this.breakers = new Map();
|
|
14
|
+
for (const def of definitions) {
|
|
15
|
+
this.breakers.set(def.id, {
|
|
16
|
+
id: def.id,
|
|
17
|
+
state: "closed",
|
|
18
|
+
definition: def,
|
|
19
|
+
events: [],
|
|
20
|
+
actionCount: 0,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Check if any breaker is OPEN - call before executing an action */
|
|
25
|
+
check() {
|
|
26
|
+
const blockedBy = [];
|
|
27
|
+
for (const record of this.breakers.values()) {
|
|
28
|
+
// Transition OPEN -> HALF_OPEN if cooldown elapsed
|
|
29
|
+
if (record.state === "open" && record.openedAt !== undefined) {
|
|
30
|
+
const cooldown = record.definition.cooldown ?? 0;
|
|
31
|
+
if (cooldown > 0 && this.now() - record.openedAt >= cooldown * 1000) {
|
|
32
|
+
record.state = "half_open";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (record.state === "open") {
|
|
36
|
+
blockedBy.push({ id: record.id, action: record.definition.action });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
allowed: blockedBy.length === 0,
|
|
41
|
+
blockedBy,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Record a successful action (for rate tracking) */
|
|
45
|
+
recordSuccess() {
|
|
46
|
+
for (const record of this.breakers.values()) {
|
|
47
|
+
record.actionCount++;
|
|
48
|
+
// HALF_OPEN -> CLOSED on success
|
|
49
|
+
if (record.state === "half_open") {
|
|
50
|
+
record.state = "closed";
|
|
51
|
+
record.openedAt = undefined;
|
|
52
|
+
record.events = [];
|
|
53
|
+
record.actionCount = 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Record an event (action failure, slippage, gas spike) */
|
|
58
|
+
recordEvent(event) {
|
|
59
|
+
let triggered = null;
|
|
60
|
+
for (const record of this.breakers.values()) {
|
|
61
|
+
record.events.push(event);
|
|
62
|
+
record.actionCount++;
|
|
63
|
+
// HALF_OPEN -> OPEN on failure
|
|
64
|
+
if (record.state === "half_open") {
|
|
65
|
+
record.state = "open";
|
|
66
|
+
record.openedAt = this.now();
|
|
67
|
+
triggered = {
|
|
68
|
+
breakerId: record.id,
|
|
69
|
+
trigger: record.definition.trigger,
|
|
70
|
+
action: record.definition.action,
|
|
71
|
+
};
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Only evaluate triggers when CLOSED
|
|
75
|
+
if (record.state !== "closed")
|
|
76
|
+
continue;
|
|
77
|
+
this.pruneEvents(record);
|
|
78
|
+
if (this.evaluateTrigger(record)) {
|
|
79
|
+
record.state = "open";
|
|
80
|
+
record.openedAt = this.now();
|
|
81
|
+
triggered = {
|
|
82
|
+
breakerId: record.id,
|
|
83
|
+
trigger: record.definition.trigger,
|
|
84
|
+
action: record.definition.action,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return triggered;
|
|
89
|
+
}
|
|
90
|
+
/** Get current state of all breakers */
|
|
91
|
+
getStates() {
|
|
92
|
+
const states = [];
|
|
93
|
+
for (const record of this.breakers.values()) {
|
|
94
|
+
states.push({ id: record.id, state: record.state });
|
|
95
|
+
}
|
|
96
|
+
return states;
|
|
97
|
+
}
|
|
98
|
+
/** Prune events outside the time window */
|
|
99
|
+
pruneEvents(record) {
|
|
100
|
+
const trigger = record.definition.trigger;
|
|
101
|
+
if (!("window" in trigger))
|
|
102
|
+
return;
|
|
103
|
+
const windowMs = trigger.window * 1000;
|
|
104
|
+
const cutoff = this.now() - windowMs;
|
|
105
|
+
record.events = record.events.filter((e) => e.timestamp >= cutoff);
|
|
106
|
+
}
|
|
107
|
+
/** Evaluate whether a trigger condition has been met */
|
|
108
|
+
evaluateTrigger(record) {
|
|
109
|
+
const trigger = record.definition.trigger;
|
|
110
|
+
switch (trigger.type) {
|
|
111
|
+
case "revert_rate":
|
|
112
|
+
return this.evaluateRevertRate(record, trigger);
|
|
113
|
+
case "cumulative_slippage":
|
|
114
|
+
return this.evaluateCumulativeSlippage(record, trigger);
|
|
115
|
+
case "gas_spike":
|
|
116
|
+
return this.evaluateGasSpike(record, trigger);
|
|
117
|
+
case "oracle_deviation":
|
|
118
|
+
case "nav_drawdown":
|
|
119
|
+
// TODO: These require external price feeds
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
evaluateRevertRate(record, trigger) {
|
|
124
|
+
const windowMs = trigger.window * 1000;
|
|
125
|
+
const cutoff = this.now() - windowMs;
|
|
126
|
+
const recentReverts = record.events.filter((e) => e.type === "revert" && e.timestamp >= cutoff).length;
|
|
127
|
+
// Need at least 1 action to compute a rate
|
|
128
|
+
if (record.actionCount === 0)
|
|
129
|
+
return false;
|
|
130
|
+
const rate = recentReverts / record.actionCount;
|
|
131
|
+
return rate > trigger.maxPercent;
|
|
132
|
+
}
|
|
133
|
+
evaluateCumulativeSlippage(record, trigger) {
|
|
134
|
+
const windowMs = trigger.window * 1000;
|
|
135
|
+
const cutoff = this.now() - windowMs;
|
|
136
|
+
const totalSlippage = record.events
|
|
137
|
+
.filter((e) => e.type === "slippage" && e.timestamp >= cutoff)
|
|
138
|
+
.reduce((sum, e) => sum + (e.value ?? 0), 0);
|
|
139
|
+
return totalSlippage > trigger.maxBps;
|
|
140
|
+
}
|
|
141
|
+
evaluateGasSpike(record, trigger) {
|
|
142
|
+
const gasEvents = record.events.filter((e) => e.type === "gas");
|
|
143
|
+
if (gasEvents.length < 2)
|
|
144
|
+
return false;
|
|
145
|
+
const latest = gasEvents[gasEvents.length - 1];
|
|
146
|
+
if (!latest)
|
|
147
|
+
return false;
|
|
148
|
+
const previous = gasEvents.slice(0, -1);
|
|
149
|
+
const avg = previous.reduce((sum, e) => sum + (e.value ?? 0), 0) / previous.length;
|
|
150
|
+
if (avg === 0)
|
|
151
|
+
return false;
|
|
152
|
+
return (latest.value ?? 0) / avg > trigger.maxMultiple;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=circuit-breaker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../../src/runtime/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiCH,MAAM,OAAO,qBAAqB;IACxB,QAAQ,CAA6B;IACrC,GAAG,CAAe;IAE1B,YAAY,WAA6B,EAAE,KAAoB;QAC7D,IAAI,CAAC,GAAG,GAAG,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE;gBACxB,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,KAAK,EAAE,QAAQ;gBACf,UAAU,EAAE,GAAG;gBACf,MAAM,EAAE,EAAE;gBACV,WAAW,EAAE,CAAC;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,qEAAqE;IACrE,KAAK;QACH,MAAM,SAAS,GAA4D,EAAE,CAAC;QAE9E,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC5C,mDAAmD;YACnD,IAAI,MAAM,CAAC,KAAK,KAAK,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC7D,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,IAAI,CA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CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;QAEnF,IAAI,GAAG,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Context
|
|
3
|
+
* Manages state during spell execution
|
|
4
|
+
*/
|
|
5
|
+
import type { CallFrame, ExecutionContext, LedgerEntry, LedgerEvent } from "../types/execution.js";
|
|
6
|
+
import type { SpellIR } from "../types/ir.js";
|
|
7
|
+
import type { PolicySet } from "../types/policy.js";
|
|
8
|
+
import type { Address, ChainId } from "../types/primitives.js";
|
|
9
|
+
/**
|
|
10
|
+
* Options for creating an execution context
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateContextOptions {
|
|
13
|
+
spell: SpellIR;
|
|
14
|
+
policy?: PolicySet;
|
|
15
|
+
vault: Address;
|
|
16
|
+
chain: ChainId;
|
|
17
|
+
params?: Record<string, unknown>;
|
|
18
|
+
persistentState?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a new execution context
|
|
22
|
+
*/
|
|
23
|
+
export declare function createContext(options: CreateContextOptions): ExecutionContext;
|
|
24
|
+
/**
|
|
25
|
+
* Push a call frame onto the stack
|
|
26
|
+
*/
|
|
27
|
+
export declare function pushFrame(ctx: ExecutionContext, stepId: string, iteration?: number, branch?: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Pop a call frame from the stack
|
|
30
|
+
*/
|
|
31
|
+
export declare function popFrame(ctx: ExecutionContext): CallFrame | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Set a binding value
|
|
34
|
+
*/
|
|
35
|
+
export declare function setBinding(ctx: ExecutionContext, name: string, value: unknown): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get a binding value
|
|
38
|
+
*/
|
|
39
|
+
export declare function getBinding(ctx: ExecutionContext, name: string): unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Update persistent state
|
|
42
|
+
*/
|
|
43
|
+
export declare function setPersistentState(ctx: ExecutionContext, key: string, value: unknown): void;
|
|
44
|
+
/**
|
|
45
|
+
* Update ephemeral state
|
|
46
|
+
*/
|
|
47
|
+
export declare function setEphemeralState(ctx: ExecutionContext, key: string, value: unknown): void;
|
|
48
|
+
/**
|
|
49
|
+
* Mark a step as executed
|
|
50
|
+
*/
|
|
51
|
+
export declare function markStepExecuted(ctx: ExecutionContext, stepId: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Increment action counter
|
|
54
|
+
*/
|
|
55
|
+
export declare function incrementActions(ctx: ExecutionContext): void;
|
|
56
|
+
/**
|
|
57
|
+
* Add gas used
|
|
58
|
+
*/
|
|
59
|
+
export declare function addGasUsed(ctx: ExecutionContext, gas: bigint): void;
|
|
60
|
+
/**
|
|
61
|
+
* Increment error counter
|
|
62
|
+
*/
|
|
63
|
+
export declare function incrementErrors(ctx: ExecutionContext): void;
|
|
64
|
+
/**
|
|
65
|
+
* Increment retry counter
|
|
66
|
+
*/
|
|
67
|
+
export declare function incrementRetries(ctx: ExecutionContext): void;
|
|
68
|
+
/**
|
|
69
|
+
* Increment advisory call counter
|
|
70
|
+
*/
|
|
71
|
+
export declare function incrementAdvisoryCalls(ctx: ExecutionContext): void;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a step has been executed
|
|
74
|
+
*/
|
|
75
|
+
export declare function isStepExecuted(ctx: ExecutionContext, stepId: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Get persistent state as a plain object
|
|
78
|
+
*/
|
|
79
|
+
export declare function getPersistentStateObject(ctx: ExecutionContext): Record<string, unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* Simple in-memory ledger for Mode 1
|
|
82
|
+
*/
|
|
83
|
+
export declare class InMemoryLedger {
|
|
84
|
+
private entries;
|
|
85
|
+
private runId;
|
|
86
|
+
private spellId;
|
|
87
|
+
constructor(runId: string, spellId: string);
|
|
88
|
+
emit(event: LedgerEvent): void;
|
|
89
|
+
getEntries(): LedgerEntry[];
|
|
90
|
+
toJSON(): object;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACnG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CAqF7E;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI,CAON;AA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,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMvF;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAS;gBAEZ,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK1C,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAU9B,UAAU,IAAI,WAAW,EAAE;IAI3B,MAAM,IAAI,MAAM;CAWjB"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Context
|
|
3
|
+
* Manages state during spell execution
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Create a new execution context
|
|
7
|
+
*/
|
|
8
|
+
export function createContext(options) {
|
|
9
|
+
const { spell, policy, vault, chain, params = {}, persistentState = {} } = options;
|
|
10
|
+
// Generate run ID
|
|
11
|
+
const now = new Date();
|
|
12
|
+
const timestamp = now
|
|
13
|
+
.toISOString()
|
|
14
|
+
.replace(/[-:]/g, "")
|
|
15
|
+
.replace(/\.\d+Z$/, "");
|
|
16
|
+
const random = Math.random().toString(36).slice(2, 8);
|
|
17
|
+
const runId = `${timestamp}-${random}`;
|
|
18
|
+
// Initialize state from schema
|
|
19
|
+
const persistent = new Map();
|
|
20
|
+
const ephemeral = new Map();
|
|
21
|
+
// Load persistent state schema defaults
|
|
22
|
+
for (const [key, field] of Object.entries(spell.state.persistent)) {
|
|
23
|
+
persistent.set(key, persistentState[key] ?? field.initialValue);
|
|
24
|
+
}
|
|
25
|
+
// Initialize ephemeral state from schema
|
|
26
|
+
for (const [key, field] of Object.entries(spell.state.ephemeral)) {
|
|
27
|
+
ephemeral.set(key, field.initialValue);
|
|
28
|
+
}
|
|
29
|
+
// Initialize bindings with state defaults first
|
|
30
|
+
const bindings = new Map();
|
|
31
|
+
for (const [key, value] of persistent.entries()) {
|
|
32
|
+
bindings.set(key, value);
|
|
33
|
+
}
|
|
34
|
+
for (const [key, value] of ephemeral.entries()) {
|
|
35
|
+
bindings.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
// Initialize bindings with params (override state keys if same name)
|
|
38
|
+
for (const param of spell.params) {
|
|
39
|
+
const value = params[param.name] ?? param.default;
|
|
40
|
+
bindings.set(param.name, value);
|
|
41
|
+
}
|
|
42
|
+
// Make asset symbols available as string bindings (e.g., ETH → "ETH")
|
|
43
|
+
// and the "assets" array itself for `for asset in assets:` loops
|
|
44
|
+
for (const asset of spell.assets) {
|
|
45
|
+
bindings.set(asset.symbol, asset.symbol);
|
|
46
|
+
}
|
|
47
|
+
bindings.set("assets", spell.assets.map((a) => a.symbol));
|
|
48
|
+
// Make limits available as a "limits" object binding so `limits.x` property
|
|
49
|
+
// access works at runtime (limits are stored as params with "limit_" prefix)
|
|
50
|
+
const limitsObj = {};
|
|
51
|
+
for (const param of spell.params) {
|
|
52
|
+
if (param.name.startsWith("limit_")) {
|
|
53
|
+
const key = param.name.slice("limit_".length);
|
|
54
|
+
limitsObj[key] = params[param.name] ?? param.default;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (Object.keys(limitsObj).length > 0) {
|
|
58
|
+
bindings.set("limits", limitsObj);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
spell,
|
|
62
|
+
policy,
|
|
63
|
+
runId,
|
|
64
|
+
startTime: now.getTime(),
|
|
65
|
+
trigger: { type: "manual" },
|
|
66
|
+
vault,
|
|
67
|
+
chain,
|
|
68
|
+
state: { persistent, ephemeral },
|
|
69
|
+
bindings,
|
|
70
|
+
callStack: [],
|
|
71
|
+
executedSteps: [],
|
|
72
|
+
metrics: {
|
|
73
|
+
stepsExecuted: 0,
|
|
74
|
+
actionsExecuted: 0,
|
|
75
|
+
gasUsed: 0n,
|
|
76
|
+
advisoryCalls: 0,
|
|
77
|
+
errors: 0,
|
|
78
|
+
retries: 0,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Push a call frame onto the stack
|
|
84
|
+
*/
|
|
85
|
+
export function pushFrame(ctx, stepId, iteration, branch) {
|
|
86
|
+
ctx.callStack.push({
|
|
87
|
+
stepId,
|
|
88
|
+
startTime: Date.now(),
|
|
89
|
+
iteration,
|
|
90
|
+
branch,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Pop a call frame from the stack
|
|
95
|
+
*/
|
|
96
|
+
export function popFrame(ctx) {
|
|
97
|
+
return ctx.callStack.pop();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Set a binding value
|
|
101
|
+
*/
|
|
102
|
+
export function setBinding(ctx, name, value) {
|
|
103
|
+
ctx.bindings.set(name, value);
|
|
104
|
+
if (ctx.state.persistent.has(name)) {
|
|
105
|
+
ctx.state.persistent.set(name, value);
|
|
106
|
+
}
|
|
107
|
+
else if (ctx.state.ephemeral.has(name)) {
|
|
108
|
+
ctx.state.ephemeral.set(name, value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get a binding value
|
|
113
|
+
*/
|
|
114
|
+
export function getBinding(ctx, name) {
|
|
115
|
+
return ctx.bindings.get(name);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Update persistent state
|
|
119
|
+
*/
|
|
120
|
+
export function setPersistentState(ctx, key, value) {
|
|
121
|
+
ctx.state.persistent.set(key, value);
|
|
122
|
+
ctx.bindings.set(key, value);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Update ephemeral state
|
|
126
|
+
*/
|
|
127
|
+
export function setEphemeralState(ctx, key, value) {
|
|
128
|
+
ctx.state.ephemeral.set(key, value);
|
|
129
|
+
ctx.bindings.set(key, value);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Mark a step as executed
|
|
133
|
+
*/
|
|
134
|
+
export function markStepExecuted(ctx, stepId) {
|
|
135
|
+
ctx.executedSteps.push(stepId);
|
|
136
|
+
ctx.metrics.stepsExecuted++;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Increment action counter
|
|
140
|
+
*/
|
|
141
|
+
export function incrementActions(ctx) {
|
|
142
|
+
ctx.metrics.actionsExecuted++;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Add gas used
|
|
146
|
+
*/
|
|
147
|
+
export function addGasUsed(ctx, gas) {
|
|
148
|
+
ctx.metrics.gasUsed += gas;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Increment error counter
|
|
152
|
+
*/
|
|
153
|
+
export function incrementErrors(ctx) {
|
|
154
|
+
ctx.metrics.errors++;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Increment retry counter
|
|
158
|
+
*/
|
|
159
|
+
export function incrementRetries(ctx) {
|
|
160
|
+
ctx.metrics.retries++;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Increment advisory call counter
|
|
164
|
+
*/
|
|
165
|
+
export function incrementAdvisoryCalls(ctx) {
|
|
166
|
+
ctx.metrics.advisoryCalls++;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Check if a step has been executed
|
|
170
|
+
*/
|
|
171
|
+
export function isStepExecuted(ctx, stepId) {
|
|
172
|
+
return ctx.executedSteps.includes(stepId);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get persistent state as a plain object
|
|
176
|
+
*/
|
|
177
|
+
export function getPersistentStateObject(ctx) {
|
|
178
|
+
const obj = {};
|
|
179
|
+
for (const [key, value] of ctx.state.persistent) {
|
|
180
|
+
obj[key] = value;
|
|
181
|
+
}
|
|
182
|
+
return obj;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Simple in-memory ledger for Mode 1
|
|
186
|
+
*/
|
|
187
|
+
export class InMemoryLedger {
|
|
188
|
+
entries = [];
|
|
189
|
+
runId;
|
|
190
|
+
spellId;
|
|
191
|
+
constructor(runId, spellId) {
|
|
192
|
+
this.runId = runId;
|
|
193
|
+
this.spellId = spellId;
|
|
194
|
+
}
|
|
195
|
+
emit(event) {
|
|
196
|
+
this.entries.push({
|
|
197
|
+
id: `evt_${this.entries.length.toString().padStart(3, "0")}`,
|
|
198
|
+
timestamp: Date.now(),
|
|
199
|
+
runId: this.runId,
|
|
200
|
+
spellId: this.spellId,
|
|
201
|
+
event,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
getEntries() {
|
|
205
|
+
return [...this.entries];
|
|
206
|
+
}
|
|
207
|
+
toJSON() {
|
|
208
|
+
return {
|
|
209
|
+
runId: this.runId,
|
|
210
|
+
spellId: this.spellId,
|
|
211
|
+
events: this.entries.map((e) => ({
|
|
212
|
+
id: e.id,
|
|
213
|
+
timestamp: new Date(e.timestamp).toISOString(),
|
|
214
|
+
event: e.event,
|
|
215
|
+
})),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAEnF,kBAAkB;IAClB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,SAAS,GAAG,GAAG;SAClB,WAAW,EAAE;SACb,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;SACpB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CA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IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC/B,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;gBAC9C,KAAK,EAAE,CAAC,CAAC,KAAK;aACf,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Classifier
|
|
3
|
+
* Maps error messages to typed ErrorType values for catch block matching
|
|
4
|
+
*/
|
|
5
|
+
import type { ErrorType } from "../types/steps.js";
|
|
6
|
+
/**
|
|
7
|
+
* Classify an error message into a typed ErrorType.
|
|
8
|
+
* Returns null if no pattern matches.
|
|
9
|
+
*/
|
|
10
|
+
export declare function classifyError(error: string): ErrorType | null;
|
|
11
|
+
/**
|
|
12
|
+
* Check whether an error type matches a catch block's error type filter.
|
|
13
|
+
* Wildcard "*" matches any error (including unclassified ones).
|
|
14
|
+
*/
|
|
15
|
+
export declare function matchesCatchBlock(errorType: ErrorType | null, catchErrorType: ErrorType | "*"): boolean;
|
|
16
|
+
//# sourceMappingURL=error-classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-classifier.d.ts","sourceRoot":"","sources":["../../src/runtime/error-classifier.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAenD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAO7D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,SAAS,GAAG,IAAI,EAC3B,cAAc,EAAE,SAAS,GAAG,GAAG,GAC9B,OAAO,CAGT"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Classifier
|
|
3
|
+
* Maps error messages to typed ErrorType values for catch block matching
|
|
4
|
+
*/
|
|
5
|
+
const ERROR_PATTERNS = [
|
|
6
|
+
[/slippage/i, "slippage_exceeded"],
|
|
7
|
+
[/insufficient.*liquidity/i, "insufficient_liquidity"],
|
|
8
|
+
[/insufficient.*(?:balance|funds)/i, "insufficient_balance"],
|
|
9
|
+
[/venue.*(?:unavailable|down)/i, "venue_unavailable"],
|
|
10
|
+
[/deadline/i, "deadline_exceeded"],
|
|
11
|
+
[/simulation.*fail/i, "simulation_failed"],
|
|
12
|
+
[/policy.*violation/i, "policy_violation"],
|
|
13
|
+
[/guard.*fail/i, "guard_failed"],
|
|
14
|
+
[/revert/i, "tx_reverted"],
|
|
15
|
+
[/(?:gas.*exceed|out.*gas)/i, "gas_exceeded"],
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* Classify an error message into a typed ErrorType.
|
|
19
|
+
* Returns null if no pattern matches.
|
|
20
|
+
*/
|
|
21
|
+
export function classifyError(error) {
|
|
22
|
+
for (const [pattern, errorType] of ERROR_PATTERNS) {
|
|
23
|
+
if (pattern.test(error)) {
|
|
24
|
+
return errorType;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check whether an error type matches a catch block's error type filter.
|
|
31
|
+
* Wildcard "*" matches any error (including unclassified ones).
|
|
32
|
+
*/
|
|
33
|
+
export function matchesCatchBlock(errorType, catchErrorType) {
|
|
34
|
+
if (catchErrorType === "*")
|
|
35
|
+
return true;
|
|
36
|
+
return errorType === catchErrorType;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=error-classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-classifier.js","sourceRoot":"","sources":["../../src/runtime/error-classifier.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,cAAc,GAA+B;IACjD,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAClC,CAAC,0BAA0B,EAAE,wBAAwB,CAAC;IACtD,CAAC,kCAAkC,EAAE,sBAAsB,CAAC;IAC5D,CAAC,8BAA8B,EAAE,mBAAmB,CAAC;IACrD,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAClC,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAC1C,CAAC,oBAAoB,EAAE,kBAAkB,CAAC;IAC1C,CAAC,cAAc,EAAE,cAAc,CAAC;IAChC,CAAC,SAAS,EAAE,aAAa,CAAC;IAC1B,CAAC,2BAA2B,EAAE,cAAc,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,KAAK,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,cAAc,EAAE,CAAC;QAClD,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAA2B,EAC3B,cAA+B;IAE/B,IAAI,cAAc,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,SAAS,KAAK,cAAc,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expression Evaluator
|
|
3
|
+
* Evaluates Expression IR nodes to concrete values
|
|
4
|
+
*/
|
|
5
|
+
import type { ExecutionContext } from "../types/execution.js";
|
|
6
|
+
import type { Expression } from "../types/expressions.js";
|
|
7
|
+
export type EvalValue = string | number | boolean | bigint | unknown[] | Record<string, unknown> | null;
|
|
8
|
+
export interface EvalContext {
|
|
9
|
+
params: Map<string, unknown>;
|
|
10
|
+
bindings: Map<string, unknown>;
|
|
11
|
+
state: {
|
|
12
|
+
persistent: Map<string, unknown>;
|
|
13
|
+
ephemeral: Map<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
item?: unknown;
|
|
16
|
+
index?: number;
|
|
17
|
+
queryBalance?: (asset: string, address?: string) => Promise<bigint>;
|
|
18
|
+
queryPrice?: (base: string, quote: string, source?: string) => Promise<number>;
|
|
19
|
+
queryApy?: (venue: string, asset: string) => Promise<number>;
|
|
20
|
+
queryHealthFactor?: (venue: string) => Promise<number>;
|
|
21
|
+
queryPosition?: (venue: string, asset: string) => Promise<unknown>;
|
|
22
|
+
queryDebt?: (venue: string, asset: string) => Promise<bigint>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Evaluate an expression synchronously (for non-async expressions)
|
|
26
|
+
*/
|
|
27
|
+
export declare function evaluate(expr: Expression, ctx: EvalContext): EvalValue;
|
|
28
|
+
/**
|
|
29
|
+
* Evaluate an expression asynchronously (for blockchain queries)
|
|
30
|
+
*/
|
|
31
|
+
export declare function evaluateAsync(expr: Expression, ctx: EvalContext): Promise<EvalValue>;
|
|
32
|
+
/**
|
|
33
|
+
* Create an evaluation context from execution context
|
|
34
|
+
*/
|
|
35
|
+
export declare function createEvalContext(execCtx: ExecutionContext): EvalContext;
|
|
36
|
+
//# sourceMappingURL=expression-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-evaluator.d.ts","sourceRoot":"","sources":["../../src/runtime/expression-evaluator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErE,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,OAAO,EAAE,GACT,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,IAAI,CAAC;AAET,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,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