@claude-flow/plugin-gastown-bridge 0.1.3 → 0.1.4
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/bd-bridge-C9wTbkhi.d.cts +318 -0
- package/dist/bd-bridge-C9wTbkhi.d.ts +318 -0
- package/dist/bridges.cjs +1 -1
- package/dist/bridges.d.cts +13 -612
- package/dist/bridges.d.ts +13 -612
- package/dist/bridges.js +1 -1
- package/dist/chunk-2KNTWGUX.js +12 -0
- package/dist/chunk-2KNTWGUX.js.map +1 -0
- package/dist/chunk-46PJFOMY.cjs +11 -0
- package/dist/chunk-46PJFOMY.cjs.map +1 -0
- package/dist/chunk-7UPWLRZX.js +11 -0
- package/dist/chunk-7UPWLRZX.js.map +1 -0
- package/dist/chunk-7VD5N6NG.cjs +11 -0
- package/dist/chunk-7VD5N6NG.cjs.map +1 -0
- package/dist/chunk-EBOVUTYL.js +12 -0
- package/dist/chunk-EBOVUTYL.js.map +1 -0
- package/dist/chunk-I2TLUPMJ.cjs +12 -0
- package/dist/chunk-I2TLUPMJ.cjs.map +1 -0
- package/dist/chunk-Q7MLH722.cjs +11 -0
- package/dist/chunk-Q7MLH722.cjs.map +1 -0
- package/dist/chunk-QFMFM7NE.cjs +13 -0
- package/dist/chunk-QFMFM7NE.cjs.map +1 -0
- package/dist/chunk-SUKPSMVK.cjs +12 -0
- package/dist/chunk-SUKPSMVK.cjs.map +1 -0
- package/dist/chunk-TGFYZY3C.js +11 -0
- package/dist/chunk-TGFYZY3C.js.map +1 -0
- package/dist/chunk-U74VYTRV.js +11 -0
- package/dist/chunk-U74VYTRV.js.map +1 -0
- package/dist/chunk-UJ56JMNG.js +13 -0
- package/dist/chunk-UJ56JMNG.js.map +1 -0
- package/dist/convoy.cjs +2 -0
- package/dist/convoy.cjs.map +1 -0
- package/dist/convoy.d.cts +6 -0
- package/dist/convoy.d.ts +6 -0
- package/dist/convoy.js +2 -0
- package/dist/convoy.js.map +1 -0
- package/dist/formula.cjs +2 -0
- package/dist/formula.cjs.map +1 -0
- package/dist/formula.d.cts +317 -0
- package/dist/formula.d.ts +317 -0
- package/dist/formula.js +2 -0
- package/dist/formula.js.map +1 -0
- package/dist/gt-bridge-B7hZz5vC.d.cts +291 -0
- package/dist/gt-bridge-B7hZz5vC.d.ts +291 -0
- package/dist/index-BzkAx4ho.d.ts +785 -0
- package/dist/index-CGJs8eMa.d.cts +785 -0
- package/dist/index.cjs +8 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2241
- package/dist/index.d.ts +17 -2241
- package/dist/index.js +8 -9
- package/dist/index.js.map +1 -1
- package/dist/types-CMoOZXrm.d.cts +1146 -0
- package/dist/types-CMoOZXrm.d.ts +1146 -0
- package/dist/wasm-loader.js +1 -1
- package/package.json +16 -18
- package/dist/chunk-IBKUMYUL.js +0 -14
- package/dist/chunk-IBKUMYUL.js.map +0 -1
- package/dist/chunk-JF2GA7QE.cjs +0 -14
- package/dist/chunk-JF2GA7QE.cjs.map +0 -1
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { b as FormulaType, S as Step, x as CookedFormula, F as Formula } from './types-CMoOZXrm.js';
|
|
3
|
+
import { G as GtBridge } from './gt-bridge-B7hZz5vC.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gas Town Formula Executor - Hybrid WASM/CLI Implementation
|
|
8
|
+
*
|
|
9
|
+
* Provides formula execution with:
|
|
10
|
+
* - WASM acceleration for parsing and cooking (352x faster)
|
|
11
|
+
* - CLI bridge fallback for I/O operations
|
|
12
|
+
* - Progress tracking with event emission
|
|
13
|
+
* - Step dependency resolution
|
|
14
|
+
* - Molecule generation from cooked formulas
|
|
15
|
+
* - Cancellation support
|
|
16
|
+
*
|
|
17
|
+
* @module v3/plugins/gastown-bridge/formula/executor
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* WASM loader interface for formula operations
|
|
22
|
+
*/
|
|
23
|
+
interface IWasmLoader {
|
|
24
|
+
/** Check if WASM is initialized */
|
|
25
|
+
isInitialized(): boolean;
|
|
26
|
+
/** Parse TOML formula content to AST */
|
|
27
|
+
parseFormula(content: string): Formula;
|
|
28
|
+
/** Cook formula with variable substitution */
|
|
29
|
+
cookFormula(formula: Formula, vars: Record<string, string>): CookedFormula;
|
|
30
|
+
/** Batch cook multiple formulas */
|
|
31
|
+
batchCook(formulas: Formula[], varsArray: Record<string, string>[]): CookedFormula[];
|
|
32
|
+
/** Resolve step dependencies (topological sort) */
|
|
33
|
+
resolveStepDependencies(steps: Step[]): Step[];
|
|
34
|
+
/** Detect cycles in step dependencies */
|
|
35
|
+
detectCycle(steps: Step[]): {
|
|
36
|
+
hasCycle: boolean;
|
|
37
|
+
cycleSteps?: string[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Execution options
|
|
42
|
+
*/
|
|
43
|
+
interface ExecuteOptions {
|
|
44
|
+
/** Target agent for execution */
|
|
45
|
+
targetAgent?: string;
|
|
46
|
+
/** Whether to run in dry-run mode (no actual execution) */
|
|
47
|
+
dryRun?: boolean;
|
|
48
|
+
/** Timeout per step in milliseconds */
|
|
49
|
+
stepTimeout?: number;
|
|
50
|
+
/** Maximum parallel steps */
|
|
51
|
+
maxParallel?: number;
|
|
52
|
+
/** Abort signal for cancellation */
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
/** Custom step handler */
|
|
55
|
+
stepHandler?: (step: Step, context: StepContext) => Promise<StepResult>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Step execution context
|
|
59
|
+
*/
|
|
60
|
+
interface StepContext {
|
|
61
|
+
/** Execution ID */
|
|
62
|
+
executionId: string;
|
|
63
|
+
/** Formula being executed */
|
|
64
|
+
formula: CookedFormula;
|
|
65
|
+
/** Current step index */
|
|
66
|
+
stepIndex: number;
|
|
67
|
+
/** Total steps */
|
|
68
|
+
totalSteps: number;
|
|
69
|
+
/** Variables available to the step */
|
|
70
|
+
variables: Record<string, string>;
|
|
71
|
+
/** Results from previous steps */
|
|
72
|
+
previousResults: Map<string, StepResult>;
|
|
73
|
+
/** Abort signal */
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
/** Execution start time */
|
|
76
|
+
startTime: Date;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Step execution result
|
|
80
|
+
*/
|
|
81
|
+
interface StepResult {
|
|
82
|
+
/** Step ID */
|
|
83
|
+
stepId: string;
|
|
84
|
+
/** Whether step succeeded */
|
|
85
|
+
success: boolean;
|
|
86
|
+
/** Step output data */
|
|
87
|
+
output?: unknown;
|
|
88
|
+
/** Error message if failed */
|
|
89
|
+
error?: string;
|
|
90
|
+
/** Duration in milliseconds */
|
|
91
|
+
durationMs: number;
|
|
92
|
+
/** Step metadata */
|
|
93
|
+
metadata?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Molecule - Generated work unit from cooked formula
|
|
97
|
+
*/
|
|
98
|
+
interface Molecule {
|
|
99
|
+
/** Unique molecule ID */
|
|
100
|
+
id: string;
|
|
101
|
+
/** Parent formula name */
|
|
102
|
+
formulaName: string;
|
|
103
|
+
/** Molecule title */
|
|
104
|
+
title: string;
|
|
105
|
+
/** Molecule description */
|
|
106
|
+
description: string;
|
|
107
|
+
/** Molecule type (from formula type) */
|
|
108
|
+
type: FormulaType;
|
|
109
|
+
/** Associated step or leg */
|
|
110
|
+
sourceId: string;
|
|
111
|
+
/** Assigned agent */
|
|
112
|
+
agent?: string;
|
|
113
|
+
/** Dependencies (other molecule IDs) */
|
|
114
|
+
dependencies: string[];
|
|
115
|
+
/** Execution order */
|
|
116
|
+
order: number;
|
|
117
|
+
/** Molecule metadata */
|
|
118
|
+
metadata: Record<string, unknown>;
|
|
119
|
+
/** Creation timestamp */
|
|
120
|
+
createdAt: Date;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Execution progress
|
|
124
|
+
*/
|
|
125
|
+
interface ExecutionProgress {
|
|
126
|
+
/** Execution ID */
|
|
127
|
+
executionId: string;
|
|
128
|
+
/** Formula name */
|
|
129
|
+
formulaName: string;
|
|
130
|
+
/** Current status */
|
|
131
|
+
status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
132
|
+
/** Total steps/legs */
|
|
133
|
+
totalSteps: number;
|
|
134
|
+
/** Completed steps */
|
|
135
|
+
completedSteps: number;
|
|
136
|
+
/** Failed steps */
|
|
137
|
+
failedSteps: number;
|
|
138
|
+
/** Current step being executed */
|
|
139
|
+
currentStep?: string;
|
|
140
|
+
/** Start time */
|
|
141
|
+
startTime: Date;
|
|
142
|
+
/** End time (if completed) */
|
|
143
|
+
endTime?: Date;
|
|
144
|
+
/** Step results */
|
|
145
|
+
stepResults: StepResult[];
|
|
146
|
+
/** Error message (if failed) */
|
|
147
|
+
error?: string;
|
|
148
|
+
/** Progress percentage (0-100) */
|
|
149
|
+
percentage: number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Executor events
|
|
153
|
+
*/
|
|
154
|
+
interface ExecutorEvents {
|
|
155
|
+
'execution:start': (executionId: string, formula: CookedFormula) => void;
|
|
156
|
+
'execution:progress': (progress: ExecutionProgress) => void;
|
|
157
|
+
'execution:complete': (executionId: string, results: StepResult[]) => void;
|
|
158
|
+
'execution:error': (executionId: string, error: Error) => void;
|
|
159
|
+
'execution:cancelled': (executionId: string) => void;
|
|
160
|
+
'step:start': (executionId: string, step: Step) => void;
|
|
161
|
+
'step:complete': (executionId: string, result: StepResult) => void;
|
|
162
|
+
'step:error': (executionId: string, stepId: string, error: Error) => void;
|
|
163
|
+
'molecule:created': (molecule: Molecule) => void;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Logger interface
|
|
167
|
+
*/
|
|
168
|
+
interface ExecutorLogger {
|
|
169
|
+
debug: (msg: string, meta?: Record<string, unknown>) => void;
|
|
170
|
+
info: (msg: string, meta?: Record<string, unknown>) => void;
|
|
171
|
+
warn: (msg: string, meta?: Record<string, unknown>) => void;
|
|
172
|
+
error: (msg: string, meta?: Record<string, unknown>) => void;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Hybrid Formula Executor
|
|
176
|
+
*
|
|
177
|
+
* Uses WASM for fast parsing and cooking operations,
|
|
178
|
+
* falls back to CLI bridge for I/O operations.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const executor = new FormulaExecutor(gtBridge, wasmLoader);
|
|
183
|
+
*
|
|
184
|
+
* // Full execution
|
|
185
|
+
* const results = await executor.execute('my-formula', { feature: 'auth' });
|
|
186
|
+
*
|
|
187
|
+
* // Just cook (WASM-accelerated)
|
|
188
|
+
* const cooked = await executor.cook('my-formula', { feature: 'auth' });
|
|
189
|
+
*
|
|
190
|
+
* // Generate molecules
|
|
191
|
+
* const molecules = await executor.generateMolecules(cooked);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare class FormulaExecutor extends EventEmitter {
|
|
195
|
+
private readonly gtBridge;
|
|
196
|
+
private readonly wasmLoader;
|
|
197
|
+
private readonly logger;
|
|
198
|
+
private readonly jsFallback;
|
|
199
|
+
/** Active executions for progress tracking */
|
|
200
|
+
private readonly executions;
|
|
201
|
+
/** Cancellation controllers */
|
|
202
|
+
private readonly cancellations;
|
|
203
|
+
/** Debounced progress emitters per execution */
|
|
204
|
+
private readonly progressEmitters;
|
|
205
|
+
/** Default max parallel workers */
|
|
206
|
+
private readonly defaultMaxParallel;
|
|
207
|
+
constructor(gtBridge: GtBridge, wasmLoader?: IWasmLoader, logger?: ExecutorLogger);
|
|
208
|
+
/**
|
|
209
|
+
* Execute a formula with full lifecycle
|
|
210
|
+
*
|
|
211
|
+
* @param formulaName - Name of the formula to execute
|
|
212
|
+
* @param vars - Variables for substitution
|
|
213
|
+
* @param options - Execution options
|
|
214
|
+
* @returns Array of step results
|
|
215
|
+
*/
|
|
216
|
+
execute(formulaName: string, vars: Record<string, string>, options?: ExecuteOptions): Promise<StepResult[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Cook a formula with variable substitution (WASM-accelerated)
|
|
219
|
+
*
|
|
220
|
+
* @param formulaName - Name of the formula or TOML content
|
|
221
|
+
* @param vars - Variables for substitution
|
|
222
|
+
* @returns Cooked formula with substituted variables
|
|
223
|
+
*/
|
|
224
|
+
cook(formulaName: string, vars: Record<string, string>): Promise<CookedFormula>;
|
|
225
|
+
/**
|
|
226
|
+
* Generate molecules from a cooked formula
|
|
227
|
+
*
|
|
228
|
+
* Molecules are executable work units derived from formula steps/legs.
|
|
229
|
+
* Uses object pooling for reduced allocations.
|
|
230
|
+
*
|
|
231
|
+
* @param cookedFormula - The cooked formula to generate molecules from
|
|
232
|
+
* @returns Array of molecules
|
|
233
|
+
*/
|
|
234
|
+
generateMolecules(cookedFormula: CookedFormula): Promise<Molecule[]>;
|
|
235
|
+
/**
|
|
236
|
+
* Run a single step
|
|
237
|
+
*
|
|
238
|
+
* @param step - Step to execute
|
|
239
|
+
* @param context - Execution context
|
|
240
|
+
* @param options - Execution options
|
|
241
|
+
* @returns Step result
|
|
242
|
+
*/
|
|
243
|
+
runStep(step: Step, context: StepContext, options?: ExecuteOptions): Promise<StepResult>;
|
|
244
|
+
/**
|
|
245
|
+
* Get execution progress
|
|
246
|
+
*
|
|
247
|
+
* @param executionId - Execution ID to get progress for
|
|
248
|
+
* @returns Execution progress or undefined
|
|
249
|
+
*/
|
|
250
|
+
getProgress(executionId: string): ExecutionProgress | undefined;
|
|
251
|
+
/**
|
|
252
|
+
* Cancel an execution
|
|
253
|
+
*
|
|
254
|
+
* @param executionId - Execution ID to cancel
|
|
255
|
+
* @returns Whether cancellation was initiated
|
|
256
|
+
*/
|
|
257
|
+
cancel(executionId: string): boolean;
|
|
258
|
+
/**
|
|
259
|
+
* List all active executions
|
|
260
|
+
*/
|
|
261
|
+
getActiveExecutions(): ExecutionProgress[];
|
|
262
|
+
/**
|
|
263
|
+
* Check if WASM is available for acceleration
|
|
264
|
+
*/
|
|
265
|
+
isWasmAvailable(): boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Get cache statistics for performance monitoring
|
|
268
|
+
*/
|
|
269
|
+
getCacheStats(): {
|
|
270
|
+
stepResultCache: {
|
|
271
|
+
entries: number;
|
|
272
|
+
sizeBytes: number;
|
|
273
|
+
};
|
|
274
|
+
cookCache: {
|
|
275
|
+
entries: number;
|
|
276
|
+
sizeBytes: number;
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Clear all executor caches
|
|
281
|
+
*/
|
|
282
|
+
clearCaches(): void;
|
|
283
|
+
/**
|
|
284
|
+
* Parse formula content using WASM or JS fallback
|
|
285
|
+
*/
|
|
286
|
+
private parseFormula;
|
|
287
|
+
/**
|
|
288
|
+
* Fetch formula from CLI
|
|
289
|
+
*/
|
|
290
|
+
private fetchFormula;
|
|
291
|
+
/**
|
|
292
|
+
* Validate required variables are provided
|
|
293
|
+
*/
|
|
294
|
+
private validateVariables;
|
|
295
|
+
/**
|
|
296
|
+
* Resolve step dependencies using WASM or JS fallback
|
|
297
|
+
*/
|
|
298
|
+
private resolveStepDependencies;
|
|
299
|
+
/**
|
|
300
|
+
* Get ordered execution units (steps or legs) from formula
|
|
301
|
+
*/
|
|
302
|
+
private getOrderedExecutionUnits;
|
|
303
|
+
/**
|
|
304
|
+
* Execute step via CLI bridge
|
|
305
|
+
*/
|
|
306
|
+
private executeStepViaCli;
|
|
307
|
+
/**
|
|
308
|
+
* Merge multiple abort signals
|
|
309
|
+
*/
|
|
310
|
+
private mergeSignals;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Create a new FormulaExecutor instance
|
|
314
|
+
*/
|
|
315
|
+
declare function createFormulaExecutor(gtBridge: GtBridge, wasmLoader?: IWasmLoader, logger?: ExecutorLogger): FormulaExecutor;
|
|
316
|
+
|
|
317
|
+
export { type ExecuteOptions, type ExecutionProgress, type ExecutorEvents, type ExecutorLogger, FormulaExecutor, type IWasmLoader, type Molecule, type StepContext, type StepResult, createFormulaExecutor, FormulaExecutor as default };
|
package/dist/formula.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"formula.js"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gas Town CLI Bridge
|
|
5
|
+
*
|
|
6
|
+
* Provides a secure wrapper around the `gt` (Gas Town) CLI tool.
|
|
7
|
+
* Implements command execution with proper input sanitization,
|
|
8
|
+
* argument validation, and error handling.
|
|
9
|
+
*
|
|
10
|
+
* Security Features:
|
|
11
|
+
* - All inputs validated with Zod schemas
|
|
12
|
+
* - No shell execution (uses execFile)
|
|
13
|
+
* - Command allowlist enforcement
|
|
14
|
+
* - Argument sanitization
|
|
15
|
+
*
|
|
16
|
+
* @module v3/plugins/gastown-bridge/bridges/gt-bridge
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Safe string pattern - no shell metacharacters
|
|
21
|
+
*/
|
|
22
|
+
declare const SafeStringSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Safe identifier pattern - alphanumeric with underscore/hyphen
|
|
25
|
+
*/
|
|
26
|
+
declare const IdentifierSchema: z.ZodString;
|
|
27
|
+
/**
|
|
28
|
+
* Gas price schema
|
|
29
|
+
*/
|
|
30
|
+
declare const GasPriceSchema: z.ZodNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Gas limit schema
|
|
33
|
+
*/
|
|
34
|
+
declare const GasLimitSchema: z.ZodNumber;
|
|
35
|
+
/**
|
|
36
|
+
* Transaction hash schema (0x prefixed hex)
|
|
37
|
+
*/
|
|
38
|
+
declare const TxHashSchema: z.ZodString;
|
|
39
|
+
/**
|
|
40
|
+
* Address schema (0x prefixed hex)
|
|
41
|
+
*/
|
|
42
|
+
declare const AddressSchema: z.ZodString;
|
|
43
|
+
/**
|
|
44
|
+
* Network schema
|
|
45
|
+
*/
|
|
46
|
+
declare const NetworkSchema: z.ZodEnum<["mainnet", "goerli", "sepolia", "polygon", "arbitrum", "optimism", "base", "local"]>;
|
|
47
|
+
/**
|
|
48
|
+
* GT command argument schema
|
|
49
|
+
*/
|
|
50
|
+
declare const GtArgumentSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* Gas Town executor configuration
|
|
53
|
+
*/
|
|
54
|
+
interface GtBridgeConfig {
|
|
55
|
+
/**
|
|
56
|
+
* Path to gt executable
|
|
57
|
+
* Default: 'gt' (assumes in PATH)
|
|
58
|
+
*/
|
|
59
|
+
gtPath?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Working directory for execution
|
|
62
|
+
*/
|
|
63
|
+
cwd?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Execution timeout in milliseconds
|
|
66
|
+
* Default: 30000 (30 seconds)
|
|
67
|
+
*/
|
|
68
|
+
timeout?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Maximum buffer size for output
|
|
71
|
+
* Default: 10MB
|
|
72
|
+
*/
|
|
73
|
+
maxBuffer?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Environment variables
|
|
76
|
+
*/
|
|
77
|
+
env?: NodeJS.ProcessEnv;
|
|
78
|
+
/**
|
|
79
|
+
* Default network
|
|
80
|
+
*/
|
|
81
|
+
defaultNetwork?: z.infer<typeof NetworkSchema>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Gas estimation result
|
|
85
|
+
*/
|
|
86
|
+
interface GasEstimate {
|
|
87
|
+
gasLimit: number;
|
|
88
|
+
gasPrice: string;
|
|
89
|
+
maxFeePerGas?: string;
|
|
90
|
+
maxPriorityFeePerGas?: string;
|
|
91
|
+
estimatedCost: string;
|
|
92
|
+
estimatedCostUsd?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Transaction status
|
|
96
|
+
*/
|
|
97
|
+
interface TxStatus {
|
|
98
|
+
hash: string;
|
|
99
|
+
status: 'pending' | 'confirmed' | 'failed' | 'dropped';
|
|
100
|
+
blockNumber?: number;
|
|
101
|
+
confirmations?: number;
|
|
102
|
+
gasUsed?: number;
|
|
103
|
+
effectiveGasPrice?: string;
|
|
104
|
+
error?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Network status
|
|
108
|
+
*/
|
|
109
|
+
interface NetworkStatus {
|
|
110
|
+
network: string;
|
|
111
|
+
chainId: number;
|
|
112
|
+
blockNumber: number;
|
|
113
|
+
baseFee?: string;
|
|
114
|
+
gasPrice?: string;
|
|
115
|
+
connected: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* GT execution result
|
|
119
|
+
*/
|
|
120
|
+
interface GtResult<T = unknown> {
|
|
121
|
+
success: boolean;
|
|
122
|
+
data?: T;
|
|
123
|
+
error?: string;
|
|
124
|
+
command: string;
|
|
125
|
+
args: string[];
|
|
126
|
+
durationMs: number;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Logger interface
|
|
130
|
+
*/
|
|
131
|
+
interface GtLogger {
|
|
132
|
+
debug: (msg: string, meta?: Record<string, unknown>) => void;
|
|
133
|
+
info: (msg: string, meta?: Record<string, unknown>) => void;
|
|
134
|
+
warn: (msg: string, meta?: Record<string, unknown>) => void;
|
|
135
|
+
error: (msg: string, meta?: Record<string, unknown>) => void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Gas Town bridge error codes
|
|
139
|
+
*/
|
|
140
|
+
type GtErrorCode = 'COMMAND_NOT_FOUND' | 'EXECUTION_FAILED' | 'TIMEOUT' | 'INVALID_ARGUMENT' | 'INVALID_OUTPUT' | 'NETWORK_ERROR' | 'VALIDATION_ERROR';
|
|
141
|
+
/**
|
|
142
|
+
* Gas Town bridge error
|
|
143
|
+
*/
|
|
144
|
+
declare class GtBridgeError extends Error {
|
|
145
|
+
readonly code: GtErrorCode;
|
|
146
|
+
readonly command?: string | undefined;
|
|
147
|
+
readonly args?: string[] | undefined;
|
|
148
|
+
readonly cause?: Error | undefined;
|
|
149
|
+
constructor(message: string, code: GtErrorCode, command?: string | undefined, args?: string[] | undefined, cause?: Error | undefined);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Gas Town CLI Bridge
|
|
153
|
+
*
|
|
154
|
+
* Secure wrapper around the `gt` CLI tool for gas estimation
|
|
155
|
+
* and transaction management.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const gtBridge = new GtBridge({ gtPath: '/usr/local/bin/gt' });
|
|
160
|
+
* await gtBridge.initialize();
|
|
161
|
+
*
|
|
162
|
+
* const estimate = await gtBridge.estimateGas({
|
|
163
|
+
* to: '0x...',
|
|
164
|
+
* data: '0x...',
|
|
165
|
+
* network: 'mainnet',
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
declare class GtBridge {
|
|
170
|
+
private config;
|
|
171
|
+
private logger;
|
|
172
|
+
private initialized;
|
|
173
|
+
/** Commands that can be cached (read-only, no side effects) */
|
|
174
|
+
private static readonly CACHEABLE_COMMANDS;
|
|
175
|
+
/** Commands that should use longer cache (static data) */
|
|
176
|
+
private static readonly STATIC_COMMANDS;
|
|
177
|
+
constructor(config?: GtBridgeConfig, logger?: GtLogger);
|
|
178
|
+
/**
|
|
179
|
+
* Initialize the bridge and verify gt is available
|
|
180
|
+
*/
|
|
181
|
+
initialize(): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Execute a gt command with validated arguments
|
|
184
|
+
*
|
|
185
|
+
* @param args - Command arguments (validated and sanitized)
|
|
186
|
+
* @returns Command output
|
|
187
|
+
*/
|
|
188
|
+
execGt(args: string[], skipCache?: boolean): Promise<GtResult<string>>;
|
|
189
|
+
/**
|
|
190
|
+
* Parse JSON output from gt command
|
|
191
|
+
*
|
|
192
|
+
* @param output - Raw command output
|
|
193
|
+
* @returns Parsed JSON object
|
|
194
|
+
*/
|
|
195
|
+
parseGtOutput<T>(output: string): T;
|
|
196
|
+
/**
|
|
197
|
+
* Estimate gas for a transaction
|
|
198
|
+
*/
|
|
199
|
+
estimateGas(params: {
|
|
200
|
+
to: string;
|
|
201
|
+
data?: string;
|
|
202
|
+
value?: string;
|
|
203
|
+
from?: string;
|
|
204
|
+
network?: z.infer<typeof NetworkSchema>;
|
|
205
|
+
}): Promise<GasEstimate>;
|
|
206
|
+
/**
|
|
207
|
+
* Get transaction status
|
|
208
|
+
*/
|
|
209
|
+
getTxStatus(txHash: string, network?: z.infer<typeof NetworkSchema>): Promise<TxStatus>;
|
|
210
|
+
/**
|
|
211
|
+
* Get network status
|
|
212
|
+
*/
|
|
213
|
+
getNetworkStatus(network?: z.infer<typeof NetworkSchema>): Promise<NetworkStatus>;
|
|
214
|
+
/**
|
|
215
|
+
* Get current gas price
|
|
216
|
+
*/
|
|
217
|
+
getGasPrice(network?: z.infer<typeof NetworkSchema>): Promise<{
|
|
218
|
+
gasPrice: string;
|
|
219
|
+
maxFeePerGas?: string;
|
|
220
|
+
maxPriorityFeePerGas?: string;
|
|
221
|
+
baseFee?: string;
|
|
222
|
+
}>;
|
|
223
|
+
/**
|
|
224
|
+
* Simulate a transaction
|
|
225
|
+
*/
|
|
226
|
+
simulate(params: {
|
|
227
|
+
to: string;
|
|
228
|
+
data: string;
|
|
229
|
+
value?: string;
|
|
230
|
+
from?: string;
|
|
231
|
+
network?: z.infer<typeof NetworkSchema>;
|
|
232
|
+
blockNumber?: number;
|
|
233
|
+
}): Promise<{
|
|
234
|
+
success: boolean;
|
|
235
|
+
returnData?: string;
|
|
236
|
+
gasUsed?: number;
|
|
237
|
+
logs?: unknown[];
|
|
238
|
+
error?: string;
|
|
239
|
+
}>;
|
|
240
|
+
/**
|
|
241
|
+
* Decode transaction data
|
|
242
|
+
*/
|
|
243
|
+
decode(data: string, abi?: string): Promise<{
|
|
244
|
+
method: string;
|
|
245
|
+
args: unknown[];
|
|
246
|
+
signature: string;
|
|
247
|
+
}>;
|
|
248
|
+
/**
|
|
249
|
+
* Validate and sanitize command arguments
|
|
250
|
+
*/
|
|
251
|
+
private validateAndSanitizeArgs;
|
|
252
|
+
/**
|
|
253
|
+
* Ensure bridge is initialized
|
|
254
|
+
*/
|
|
255
|
+
private ensureInitialized;
|
|
256
|
+
/**
|
|
257
|
+
* Check if bridge is initialized
|
|
258
|
+
*/
|
|
259
|
+
isInitialized(): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Get current configuration
|
|
262
|
+
*/
|
|
263
|
+
getConfig(): Readonly<Required<GtBridgeConfig>>;
|
|
264
|
+
/**
|
|
265
|
+
* Get cache statistics for performance monitoring
|
|
266
|
+
*/
|
|
267
|
+
getCacheStats(): {
|
|
268
|
+
resultCache: {
|
|
269
|
+
entries: number;
|
|
270
|
+
sizeBytes: number;
|
|
271
|
+
};
|
|
272
|
+
staticCache: {
|
|
273
|
+
entries: number;
|
|
274
|
+
sizeBytes: number;
|
|
275
|
+
};
|
|
276
|
+
parsedCache: {
|
|
277
|
+
entries: number;
|
|
278
|
+
sizeBytes: number;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Clear all caches (useful for testing or memory pressure)
|
|
283
|
+
*/
|
|
284
|
+
clearCaches(): void;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Create a new Gas Town bridge instance
|
|
288
|
+
*/
|
|
289
|
+
declare function createGtBridge(config?: GtBridgeConfig, logger?: GtLogger): GtBridge;
|
|
290
|
+
|
|
291
|
+
export { AddressSchema as A, GtBridge as G, IdentifierSchema as I, NetworkSchema as N, SafeStringSchema as S, TxHashSchema as T, type GasEstimate as a, GasLimitSchema as b, GasPriceSchema as c, GtArgumentSchema as d, type GtBridgeConfig as e, GtBridgeError as f, type GtErrorCode as g, type GtLogger as h, type GtResult as i, type NetworkStatus as j, type TxStatus as k, createGtBridge as l };
|