@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.
Files changed (205) hide show
  1. package/dist/builders/expressions.d.ts +33 -0
  2. package/dist/builders/expressions.d.ts.map +1 -0
  3. package/dist/builders/expressions.js +57 -0
  4. package/dist/builders/expressions.js.map +1 -0
  5. package/dist/builders/index.d.ts +44 -0
  6. package/dist/builders/index.d.ts.map +1 -0
  7. package/dist/builders/index.js +32 -0
  8. package/dist/builders/index.js.map +1 -0
  9. package/dist/builders/spell-builder.d.ts +124 -0
  10. package/dist/builders/spell-builder.d.ts.map +1 -0
  11. package/dist/builders/spell-builder.js +299 -0
  12. package/dist/builders/spell-builder.js.map +1 -0
  13. package/dist/builders/step-builder.d.ts +212 -0
  14. package/dist/builders/step-builder.d.ts.map +1 -0
  15. package/dist/builders/step-builder.js +499 -0
  16. package/dist/builders/step-builder.js.map +1 -0
  17. package/dist/compiler/expression-parser.d.ts +14 -0
  18. package/dist/compiler/expression-parser.d.ts.map +1 -0
  19. package/dist/compiler/expression-parser.js +460 -0
  20. package/dist/compiler/expression-parser.js.map +1 -0
  21. package/dist/compiler/grimoire/ast.d.ts +450 -0
  22. package/dist/compiler/grimoire/ast.d.ts.map +1 -0
  23. package/dist/compiler/grimoire/ast.js +19 -0
  24. package/dist/compiler/grimoire/ast.js.map +1 -0
  25. package/dist/compiler/grimoire/errors.d.ts +65 -0
  26. package/dist/compiler/grimoire/errors.d.ts.map +1 -0
  27. package/dist/compiler/grimoire/errors.js +86 -0
  28. package/dist/compiler/grimoire/errors.js.map +1 -0
  29. package/dist/compiler/grimoire/index.d.ts +24 -0
  30. package/dist/compiler/grimoire/index.d.ts.map +1 -0
  31. package/dist/compiler/grimoire/index.js +63 -0
  32. package/dist/compiler/grimoire/index.js.map +1 -0
  33. package/dist/compiler/grimoire/parser.d.ts +135 -0
  34. package/dist/compiler/grimoire/parser.d.ts.map +1 -0
  35. package/dist/compiler/grimoire/parser.js +2148 -0
  36. package/dist/compiler/grimoire/parser.js.map +1 -0
  37. package/dist/compiler/grimoire/tokenizer.d.ts +59 -0
  38. package/dist/compiler/grimoire/tokenizer.d.ts.map +1 -0
  39. package/dist/compiler/grimoire/tokenizer.js +509 -0
  40. package/dist/compiler/grimoire/tokenizer.js.map +1 -0
  41. package/dist/compiler/grimoire/transformer.d.ts +71 -0
  42. package/dist/compiler/grimoire/transformer.d.ts.map +1 -0
  43. package/dist/compiler/grimoire/transformer.js +1011 -0
  44. package/dist/compiler/grimoire/transformer.js.map +1 -0
  45. package/dist/compiler/index.d.ts +45 -0
  46. package/dist/compiler/index.d.ts.map +1 -0
  47. package/dist/compiler/index.js +97 -0
  48. package/dist/compiler/index.js.map +1 -0
  49. package/dist/compiler/ir-generator.d.ts +16 -0
  50. package/dist/compiler/ir-generator.d.ts.map +1 -0
  51. package/dist/compiler/ir-generator.js +997 -0
  52. package/dist/compiler/ir-generator.js.map +1 -0
  53. package/dist/compiler/validator.d.ts +15 -0
  54. package/dist/compiler/validator.d.ts.map +1 -0
  55. package/dist/compiler/validator.js +401 -0
  56. package/dist/compiler/validator.js.map +1 -0
  57. package/dist/index.d.ts +16 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +17 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/runtime/circuit-breaker.d.ts +59 -0
  62. package/dist/runtime/circuit-breaker.d.ts.map +1 -0
  63. package/dist/runtime/circuit-breaker.js +155 -0
  64. package/dist/runtime/circuit-breaker.js.map +1 -0
  65. package/dist/runtime/context.d.ts +92 -0
  66. package/dist/runtime/context.d.ts.map +1 -0
  67. package/dist/runtime/context.js +219 -0
  68. package/dist/runtime/context.js.map +1 -0
  69. package/dist/runtime/error-classifier.d.ts +16 -0
  70. package/dist/runtime/error-classifier.d.ts.map +1 -0
  71. package/dist/runtime/error-classifier.js +38 -0
  72. package/dist/runtime/error-classifier.js.map +1 -0
  73. package/dist/runtime/expression-evaluator.d.ts +36 -0
  74. package/dist/runtime/expression-evaluator.d.ts.map +1 -0
  75. package/dist/runtime/expression-evaluator.js +391 -0
  76. package/dist/runtime/expression-evaluator.js.map +1 -0
  77. package/dist/runtime/index.d.ts +12 -0
  78. package/dist/runtime/index.d.ts.map +1 -0
  79. package/dist/runtime/index.js +11 -0
  80. package/dist/runtime/index.js.map +1 -0
  81. package/dist/runtime/interpreter.d.ts +59 -0
  82. package/dist/runtime/interpreter.d.ts.map +1 -0
  83. package/dist/runtime/interpreter.js +414 -0
  84. package/dist/runtime/interpreter.js.map +1 -0
  85. package/dist/runtime/skills/registry.d.ts +11 -0
  86. package/dist/runtime/skills/registry.d.ts.map +1 -0
  87. package/dist/runtime/skills/registry.js +73 -0
  88. package/dist/runtime/skills/registry.js.map +1 -0
  89. package/dist/runtime/sqlite-state-store.d.ts +28 -0
  90. package/dist/runtime/sqlite-state-store.d.ts.map +1 -0
  91. package/dist/runtime/sqlite-state-store.js +180 -0
  92. package/dist/runtime/sqlite-state-store.js.map +1 -0
  93. package/dist/runtime/state-store.d.ts +52 -0
  94. package/dist/runtime/state-store.d.ts.map +1 -0
  95. package/dist/runtime/state-store.js +32 -0
  96. package/dist/runtime/state-store.js.map +1 -0
  97. package/dist/runtime/steps/action.d.ts +17 -0
  98. package/dist/runtime/steps/action.d.ts.map +1 -0
  99. package/dist/runtime/steps/action.js +430 -0
  100. package/dist/runtime/steps/action.js.map +1 -0
  101. package/dist/runtime/steps/advisory.d.ts +28 -0
  102. package/dist/runtime/steps/advisory.d.ts.map +1 -0
  103. package/dist/runtime/steps/advisory.js +209 -0
  104. package/dist/runtime/steps/advisory.js.map +1 -0
  105. package/dist/runtime/steps/compute.d.ts +9 -0
  106. package/dist/runtime/steps/compute.d.ts.map +1 -0
  107. package/dist/runtime/steps/compute.js +74 -0
  108. package/dist/runtime/steps/compute.js.map +1 -0
  109. package/dist/runtime/steps/conditional.d.ts +14 -0
  110. package/dist/runtime/steps/conditional.d.ts.map +1 -0
  111. package/dist/runtime/steps/conditional.js +58 -0
  112. package/dist/runtime/steps/conditional.js.map +1 -0
  113. package/dist/runtime/steps/emit.d.ts +9 -0
  114. package/dist/runtime/steps/emit.d.ts.map +1 -0
  115. package/dist/runtime/steps/emit.js +70 -0
  116. package/dist/runtime/steps/emit.js.map +1 -0
  117. package/dist/runtime/steps/halt.d.ts +9 -0
  118. package/dist/runtime/steps/halt.d.ts.map +1 -0
  119. package/dist/runtime/steps/halt.js +19 -0
  120. package/dist/runtime/steps/halt.js.map +1 -0
  121. package/dist/runtime/steps/loop.d.ts +14 -0
  122. package/dist/runtime/steps/loop.d.ts.map +1 -0
  123. package/dist/runtime/steps/loop.js +109 -0
  124. package/dist/runtime/steps/loop.js.map +1 -0
  125. package/dist/runtime/steps/parallel.d.ts +9 -0
  126. package/dist/runtime/steps/parallel.d.ts.map +1 -0
  127. package/dist/runtime/steps/parallel.js +87 -0
  128. package/dist/runtime/steps/parallel.js.map +1 -0
  129. package/dist/runtime/steps/pipeline.d.ts +9 -0
  130. package/dist/runtime/steps/pipeline.d.ts.map +1 -0
  131. package/dist/runtime/steps/pipeline.js +125 -0
  132. package/dist/runtime/steps/pipeline.js.map +1 -0
  133. package/dist/runtime/steps/try.d.ts +13 -0
  134. package/dist/runtime/steps/try.d.ts.map +1 -0
  135. package/dist/runtime/steps/try.js +222 -0
  136. package/dist/runtime/steps/try.js.map +1 -0
  137. package/dist/runtime/steps/wait.d.ts +9 -0
  138. package/dist/runtime/steps/wait.d.ts.map +1 -0
  139. package/dist/runtime/steps/wait.js +38 -0
  140. package/dist/runtime/steps/wait.js.map +1 -0
  141. package/dist/types/actions.d.ts +162 -0
  142. package/dist/types/actions.d.ts.map +1 -0
  143. package/dist/types/actions.js +5 -0
  144. package/dist/types/actions.js.map +1 -0
  145. package/dist/types/execution.d.ts +276 -0
  146. package/dist/types/execution.d.ts.map +1 -0
  147. package/dist/types/execution.js +5 -0
  148. package/dist/types/execution.js.map +1 -0
  149. package/dist/types/expressions.d.ts +100 -0
  150. package/dist/types/expressions.d.ts.map +1 -0
  151. package/dist/types/expressions.js +48 -0
  152. package/dist/types/expressions.js.map +1 -0
  153. package/dist/types/index.d.ts +14 -0
  154. package/dist/types/index.d.ts.map +1 -0
  155. package/dist/types/index.js +5 -0
  156. package/dist/types/index.js.map +1 -0
  157. package/dist/types/ir.d.ts +187 -0
  158. package/dist/types/ir.d.ts.map +1 -0
  159. package/dist/types/ir.js +5 -0
  160. package/dist/types/ir.js.map +1 -0
  161. package/dist/types/policy.d.ts +123 -0
  162. package/dist/types/policy.d.ts.map +1 -0
  163. package/dist/types/policy.js +5 -0
  164. package/dist/types/policy.js.map +1 -0
  165. package/dist/types/primitives.d.ts +76 -0
  166. package/dist/types/primitives.d.ts.map +1 -0
  167. package/dist/types/primitives.js +10 -0
  168. package/dist/types/primitives.js.map +1 -0
  169. package/dist/types/steps.d.ts +226 -0
  170. package/dist/types/steps.d.ts.map +1 -0
  171. package/dist/types/steps.js +5 -0
  172. package/dist/types/steps.js.map +1 -0
  173. package/dist/venues/index.d.ts +6 -0
  174. package/dist/venues/index.d.ts.map +1 -0
  175. package/dist/venues/index.js +26 -0
  176. package/dist/venues/index.js.map +1 -0
  177. package/dist/venues/types.d.ts +40 -0
  178. package/dist/venues/types.d.ts.map +1 -0
  179. package/dist/venues/types.js +5 -0
  180. package/dist/venues/types.js.map +1 -0
  181. package/dist/wallet/executor.d.ts +109 -0
  182. package/dist/wallet/executor.d.ts.map +1 -0
  183. package/dist/wallet/executor.js +354 -0
  184. package/dist/wallet/executor.js.map +1 -0
  185. package/dist/wallet/index.d.ts +14 -0
  186. package/dist/wallet/index.d.ts.map +1 -0
  187. package/dist/wallet/index.js +13 -0
  188. package/dist/wallet/index.js.map +1 -0
  189. package/dist/wallet/keystore.d.ts +44 -0
  190. package/dist/wallet/keystore.d.ts.map +1 -0
  191. package/dist/wallet/keystore.js +296 -0
  192. package/dist/wallet/keystore.js.map +1 -0
  193. package/dist/wallet/provider.d.ts +111 -0
  194. package/dist/wallet/provider.d.ts.map +1 -0
  195. package/dist/wallet/provider.js +309 -0
  196. package/dist/wallet/provider.js.map +1 -0
  197. package/dist/wallet/tx-builder.d.ts +85 -0
  198. package/dist/wallet/tx-builder.d.ts.map +1 -0
  199. package/dist/wallet/tx-builder.js +290 -0
  200. package/dist/wallet/tx-builder.js.map +1 -0
  201. package/dist/wallet/types.d.ts +116 -0
  202. package/dist/wallet/types.d.ts.map +1 -0
  203. package/dist/wallet/types.js +86 -0
  204. package/dist/wallet/types.js.map +1 -0
  205. package/package.json +39 -0
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Transaction builder
3
+ *
4
+ * Builds transactions from spell actions, supporting:
5
+ * - ERC20 operations (transfer, approve)
6
+ * - Swap operations
7
+ * - Lending operations (deposit, withdraw)
8
+ */
9
+ import { encodeFunctionData, parseAbi } from "viem";
10
+ import { getNativeCurrencySymbol, isNativeCurrency } from "./types.js";
11
+ /** Standard ERC20 ABI */
12
+ const ERC20_ABI = parseAbi([
13
+ "function transfer(address to, uint256 amount) returns (bool)",
14
+ "function approve(address spender, uint256 amount) returns (bool)",
15
+ "function balanceOf(address account) view returns (uint256)",
16
+ "function allowance(address owner, address spender) view returns (uint256)",
17
+ "function decimals() view returns (uint8)",
18
+ "function symbol() view returns (string)",
19
+ ]);
20
+ /**
21
+ * Transaction builder class
22
+ */
23
+ export class TransactionBuilder {
24
+ provider;
25
+ fromAddress;
26
+ constructor(provider, fromAddress) {
27
+ this.provider = provider;
28
+ this.fromAddress = fromAddress;
29
+ }
30
+ /**
31
+ * Build a transaction from an action
32
+ */
33
+ async buildAction(action) {
34
+ switch (action.type) {
35
+ case "transfer":
36
+ return this.buildTransfer(action);
37
+ case "approve":
38
+ return this.buildApprove(action);
39
+ case "swap":
40
+ return this.buildSwap(action);
41
+ case "lend":
42
+ return this.buildLend(action);
43
+ case "withdraw":
44
+ return this.buildWithdraw(action);
45
+ default:
46
+ throw new Error(`Unsupported action type: ${action.type}`);
47
+ }
48
+ }
49
+ /**
50
+ * Build a transfer transaction (native ETH or ERC20)
51
+ */
52
+ async buildTransfer(action) {
53
+ if (action.type !== "transfer") {
54
+ throw new Error("Invalid action type for transfer");
55
+ }
56
+ const toAddress = action.to;
57
+ const amount = BigInt(action.amount?.toString() ?? "0");
58
+ const isNative = isNativeCurrency(action.asset ?? "", this.provider.chainId);
59
+ let tx;
60
+ if (isNative) {
61
+ tx = {
62
+ to: toAddress,
63
+ value: amount,
64
+ };
65
+ }
66
+ else {
67
+ const tokenAddress = this.resolveAssetAddress(action.asset);
68
+ const data = encodeFunctionData({
69
+ abi: ERC20_ABI,
70
+ functionName: "transfer",
71
+ args: [toAddress, amount],
72
+ });
73
+ tx = {
74
+ to: tokenAddress,
75
+ data,
76
+ value: 0n,
77
+ };
78
+ }
79
+ const gasEstimate = await this.provider.getGasEstimate({
80
+ ...tx,
81
+ from: this.fromAddress,
82
+ });
83
+ return {
84
+ tx: {
85
+ ...tx,
86
+ gasLimit: gasEstimate.gasLimit,
87
+ maxFeePerGas: gasEstimate.maxFeePerGas,
88
+ maxPriorityFeePerGas: gasEstimate.maxPriorityFeePerGas,
89
+ },
90
+ description: `Transfer ${formatAmount(amount)} ${action.asset} to ${shortenAddress(toAddress)}`,
91
+ gasEstimate,
92
+ action,
93
+ };
94
+ }
95
+ /**
96
+ * Build an ERC20 approve transaction
97
+ */
98
+ async buildApprove(action) {
99
+ if (action.type !== "approve") {
100
+ throw new Error("Invalid action type for approve");
101
+ }
102
+ const tokenAddress = this.resolveAssetAddress(action.asset);
103
+ const spenderAddress = action.spender;
104
+ const amount = BigInt(action.amount?.toString() ?? "0");
105
+ const data = encodeFunctionData({
106
+ abi: ERC20_ABI,
107
+ functionName: "approve",
108
+ args: [spenderAddress, amount],
109
+ });
110
+ const tx = {
111
+ to: tokenAddress,
112
+ data,
113
+ value: 0n,
114
+ };
115
+ const gasEstimate = await this.provider.getGasEstimate({
116
+ ...tx,
117
+ from: this.fromAddress,
118
+ });
119
+ return {
120
+ tx: {
121
+ ...tx,
122
+ gasLimit: gasEstimate.gasLimit,
123
+ maxFeePerGas: gasEstimate.maxFeePerGas,
124
+ maxPriorityFeePerGas: gasEstimate.maxPriorityFeePerGas,
125
+ },
126
+ description: `Approve ${formatAmount(amount)} ${action.asset} for ${shortenAddress(spenderAddress)}`,
127
+ gasEstimate,
128
+ action,
129
+ };
130
+ }
131
+ /**
132
+ * Build a swap transaction (placeholder - requires venue adapter)
133
+ */
134
+ async buildSwap(action) {
135
+ if (action.type !== "swap") {
136
+ throw new Error("Invalid action type for swap");
137
+ }
138
+ // TODO: Implement with venue adapters in Phase 2
139
+ throw new Error(`Swap transactions require venue adapters. Venue: ${action.venue}, ` +
140
+ `${action.assetIn} → ${action.assetOut}`);
141
+ }
142
+ /**
143
+ * Build a lending deposit transaction (placeholder - requires venue adapter)
144
+ */
145
+ async buildLend(action) {
146
+ if (action.type !== "lend") {
147
+ throw new Error("Invalid action type for lend");
148
+ }
149
+ // TODO: Implement with venue adapters in Phase 2
150
+ throw new Error(`Lend transactions require venue adapters. Venue: ${action.venue}, ` +
151
+ `Asset: ${action.asset}`);
152
+ }
153
+ /**
154
+ * Build a withdrawal transaction (placeholder - requires venue adapter)
155
+ */
156
+ async buildWithdraw(action) {
157
+ if (action.type !== "withdraw") {
158
+ throw new Error("Invalid action type for withdraw");
159
+ }
160
+ // TODO: Implement with venue adapters in Phase 2
161
+ throw new Error(`Withdraw transactions require venue adapters. Venue: ${action.venue}, ` +
162
+ `Asset: ${action.asset}`);
163
+ }
164
+ /**
165
+ * Build a raw transaction
166
+ */
167
+ async buildRaw(to, data, value = 0n, description = "Raw transaction") {
168
+ const tx = {
169
+ to,
170
+ data,
171
+ value,
172
+ };
173
+ const gasEstimate = await this.provider.getGasEstimate({
174
+ ...tx,
175
+ from: this.fromAddress,
176
+ });
177
+ const action = {
178
+ type: "transfer",
179
+ asset: getNativeCurrencySymbol(this.provider.chainId),
180
+ amount: { kind: "literal", value: 0n, type: "int" },
181
+ to,
182
+ };
183
+ return {
184
+ tx: {
185
+ ...tx,
186
+ gasLimit: gasEstimate.gasLimit,
187
+ maxFeePerGas: gasEstimate.maxFeePerGas,
188
+ maxPriorityFeePerGas: gasEstimate.maxPriorityFeePerGas,
189
+ },
190
+ description,
191
+ gasEstimate,
192
+ action,
193
+ };
194
+ }
195
+ /**
196
+ * Check ERC20 allowance
197
+ */
198
+ async checkAllowance(tokenAddress, spenderAddress) {
199
+ return await this.provider.readContract({
200
+ address: tokenAddress,
201
+ abi: ERC20_ABI,
202
+ functionName: "allowance",
203
+ args: [this.fromAddress, spenderAddress],
204
+ });
205
+ }
206
+ /**
207
+ * Check ERC20 balance
208
+ */
209
+ async checkBalance(tokenAddress) {
210
+ return await this.provider.readContract({
211
+ address: tokenAddress,
212
+ abi: ERC20_ABI,
213
+ functionName: "balanceOf",
214
+ args: [this.fromAddress],
215
+ });
216
+ }
217
+ /**
218
+ * Get token decimals
219
+ */
220
+ async getTokenDecimals(tokenAddress) {
221
+ return await this.provider.readContract({
222
+ address: tokenAddress,
223
+ abi: ERC20_ABI,
224
+ functionName: "decimals",
225
+ });
226
+ }
227
+ /**
228
+ * Get token symbol
229
+ */
230
+ async getTokenSymbol(tokenAddress) {
231
+ return await this.provider.readContract({
232
+ address: tokenAddress,
233
+ abi: ERC20_ABI,
234
+ functionName: "symbol",
235
+ });
236
+ }
237
+ /**
238
+ * Resolve asset symbol to address
239
+ * TODO: Implement proper asset registry
240
+ */
241
+ resolveAssetAddress(asset) {
242
+ if (!asset) {
243
+ throw new Error("Asset is required");
244
+ }
245
+ // If it's already an address, return it
246
+ if (asset.startsWith("0x") && asset.length === 42) {
247
+ return asset;
248
+ }
249
+ // Known token addresses (mainnet)
250
+ const KNOWN_TOKENS = {
251
+ USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
252
+ USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
253
+ DAI: "0x6B175474E89094C44Da98b954EescdeCB5cB92c0",
254
+ WETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
255
+ WBTC: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
256
+ };
257
+ const address = KNOWN_TOKENS[asset.toUpperCase()];
258
+ if (!address) {
259
+ throw new Error(`Unknown asset: ${asset}. Provide address directly.`);
260
+ }
261
+ return address;
262
+ }
263
+ }
264
+ /**
265
+ * Shorten an address for display
266
+ */
267
+ function shortenAddress(address) {
268
+ return `${address.slice(0, 6)}...${address.slice(-4)}`;
269
+ }
270
+ /**
271
+ * Format an amount for display
272
+ */
273
+ function formatAmount(amount, decimals = 18) {
274
+ const divisor = 10n ** BigInt(decimals);
275
+ const integerPart = amount / divisor;
276
+ const fractionalPart = amount % divisor;
277
+ if (fractionalPart === 0n) {
278
+ return integerPart.toString();
279
+ }
280
+ const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
281
+ const trimmed = fractionalStr.slice(0, 4).replace(/0+$/, "") || "0";
282
+ return `${integerPart}.${trimmed}`;
283
+ }
284
+ /**
285
+ * Create a transaction builder
286
+ */
287
+ export function createTransactionBuilder(provider, fromAddress) {
288
+ return new TransactionBuilder(provider, fromAddress);
289
+ }
290
+ //# sourceMappingURL=tx-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx-builder.js","sourceRoot":"","sources":["../../src/wallet/tx-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAIpD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGvE,yBAAyB;AACzB,MAAM,SAAS,GAAG,QAAQ,CAAC;IACzB,8DAA8D;IAC9D,kEAAkE;IAClE,4DAA4D;IAC5D,2EAA2E;IAC3E,0CAA0C;IAC1C,yCAAyC;CAC1C,CAAC,CAAC;AAcH;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACrB,QA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AACH,MAAM,UAAU,wBAAwB,CACtC,QAAkB,EAClB,WAAoB;IAEpB,OAAO,IAAI,kBAAkB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACvD,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Wallet and transaction types
3
+ */
4
+ import type { Address } from "../types/primitives.js";
5
+ /** Supported key source types */
6
+ export type KeySourceType = "raw" | "env" | "mnemonic" | "keystore";
7
+ /** Configuration for loading a private key */
8
+ export interface KeyConfig {
9
+ /** Type of key source */
10
+ type: KeySourceType;
11
+ /** Source value - env var name, file path, or raw hex */
12
+ source: string;
13
+ /** Password for keystore files */
14
+ password?: string;
15
+ /** Derivation path for mnemonic (default: m/44'/60'/0'/0/0) */
16
+ derivationPath?: string;
17
+ }
18
+ /** Wallet interface for signing operations */
19
+ export interface Wallet {
20
+ /** Get the wallet's address */
21
+ readonly address: Address;
22
+ /** Get the chain ID this wallet is connected to */
23
+ readonly chainId: number;
24
+ /** Sign a transaction */
25
+ signTransaction(tx: TransactionRequest): Promise<string>;
26
+ /** Sign a message */
27
+ signMessage(message: string): Promise<string>;
28
+ /** Send a signed transaction */
29
+ sendTransaction(tx: TransactionRequest): Promise<TransactionReceipt>;
30
+ }
31
+ /** Transaction request parameters */
32
+ export interface TransactionRequest {
33
+ /** Recipient address */
34
+ to: Address;
35
+ /** Transaction value in wei */
36
+ value?: bigint;
37
+ /** Encoded calldata */
38
+ data?: string;
39
+ /** Gas limit */
40
+ gasLimit?: bigint;
41
+ /** Max fee per gas (EIP-1559) */
42
+ maxFeePerGas?: bigint;
43
+ /** Max priority fee per gas (EIP-1559) */
44
+ maxPriorityFeePerGas?: bigint;
45
+ /** Legacy gas price */
46
+ gasPrice?: bigint;
47
+ /** Transaction nonce */
48
+ nonce?: number;
49
+ /** Chain ID */
50
+ chainId?: number;
51
+ }
52
+ /** Transaction receipt after confirmation */
53
+ export interface TransactionReceipt {
54
+ /** Transaction hash */
55
+ hash: string;
56
+ /** Block number */
57
+ blockNumber: bigint;
58
+ /** Block hash */
59
+ blockHash: string;
60
+ /** Gas used */
61
+ gasUsed: bigint;
62
+ /** Effective gas price */
63
+ effectiveGasPrice: bigint;
64
+ /** Transaction status (1 = success, 0 = failure) */
65
+ status: "success" | "reverted";
66
+ /** Contract address if deployment */
67
+ contractAddress?: Address;
68
+ /** Transaction logs */
69
+ logs: TransactionLog[];
70
+ }
71
+ /** Transaction log entry */
72
+ export interface TransactionLog {
73
+ /** Contract address that emitted the log */
74
+ address: Address;
75
+ /** Log topics */
76
+ topics: string[];
77
+ /** Log data */
78
+ data: string;
79
+ /** Log index in the block */
80
+ logIndex: number;
81
+ }
82
+ /** RPC provider configuration */
83
+ export interface ProviderConfig {
84
+ /** Chain ID */
85
+ chainId: number;
86
+ /** Primary RPC URL */
87
+ rpcUrl: string;
88
+ /** Fallback RPC URLs */
89
+ fallbackUrls?: string[];
90
+ /** Request timeout in ms */
91
+ timeout?: number;
92
+ /** Retry attempts */
93
+ retries?: number;
94
+ }
95
+ /** Gas estimation result */
96
+ export interface GasEstimate {
97
+ /** Estimated gas limit */
98
+ gasLimit: bigint;
99
+ /** Current max fee per gas */
100
+ maxFeePerGas: bigint;
101
+ /** Current max priority fee */
102
+ maxPriorityFeePerGas: bigint;
103
+ /** Estimated total cost in wei */
104
+ estimatedCost: bigint;
105
+ }
106
+ /** Supported chains with default configurations */
107
+ export declare const CHAIN_CONFIGS: Record<number, ProviderConfig>;
108
+ /** Check if a chain ID is a testnet */
109
+ export declare function isTestnet(chainId: number): boolean;
110
+ /** Get chain name from ID */
111
+ export declare function getChainName(chainId: number): string;
112
+ /** Get the native currency symbol for a chain */
113
+ export declare function getNativeCurrencySymbol(chainId: number): string;
114
+ /** Check if an asset is the native currency for a given chain */
115
+ export declare function isNativeCurrency(asset: string, chainId: number): boolean;
116
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/wallet/types.ts"],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AC;IAC7B,kCAAkC;IAClC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,mDAAmD;AACnD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAqCxD,CAAC;AAEF,uCAAuC;AACvC,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGlD;AAED,6BAA6B;AAC7B,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAepD;AAED,iDAAiD;AACjD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAe/D;AAED,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAExE"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Wallet and transaction types
3
+ */
4
+ /** Supported chains with default configurations */
5
+ export const CHAIN_CONFIGS = {
6
+ // Mainnets
7
+ 1: {
8
+ chainId: 1,
9
+ rpcUrl: "https://eth.llamarpc.com",
10
+ fallbackUrls: ["https://rpc.ankr.com/eth", "https://ethereum.publicnode.com"],
11
+ },
12
+ 10: {
13
+ chainId: 10,
14
+ rpcUrl: "https://mainnet.optimism.io",
15
+ fallbackUrls: ["https://rpc.ankr.com/optimism"],
16
+ },
17
+ 137: {
18
+ chainId: 137,
19
+ rpcUrl: "https://polygon-rpc.com",
20
+ fallbackUrls: ["https://rpc.ankr.com/polygon"],
21
+ },
22
+ 42161: {
23
+ chainId: 42161,
24
+ rpcUrl: "https://arb1.arbitrum.io/rpc",
25
+ fallbackUrls: ["https://rpc.ankr.com/arbitrum"],
26
+ },
27
+ 8453: {
28
+ chainId: 8453,
29
+ rpcUrl: "https://mainnet.base.org",
30
+ fallbackUrls: ["https://base.llamarpc.com"],
31
+ },
32
+ 999: {
33
+ chainId: 999,
34
+ rpcUrl: "https://rpc.hyperliquid.xyz/evm",
35
+ },
36
+ // Testnets
37
+ 11155111: {
38
+ chainId: 11155111,
39
+ rpcUrl: "https://rpc.sepolia.org",
40
+ fallbackUrls: ["https://ethereum-sepolia.publicnode.com"],
41
+ },
42
+ };
43
+ /** Check if a chain ID is a testnet */
44
+ export function isTestnet(chainId) {
45
+ const testnets = [11155111, 5, 80001, 421613, 84531];
46
+ return testnets.includes(chainId);
47
+ }
48
+ /** Get chain name from ID */
49
+ export function getChainName(chainId) {
50
+ const names = {
51
+ 1: "Ethereum Mainnet",
52
+ 10: "Optimism",
53
+ 137: "Polygon",
54
+ 42161: "Arbitrum One",
55
+ 8453: "Base",
56
+ 999: "HyperEVM",
57
+ 11155111: "Sepolia",
58
+ 5: "Goerli",
59
+ 80001: "Mumbai",
60
+ 421613: "Arbitrum Goerli",
61
+ 84531: "Base Goerli",
62
+ };
63
+ return names[chainId] ?? `Chain ${chainId}`;
64
+ }
65
+ /** Get the native currency symbol for a chain */
66
+ export function getNativeCurrencySymbol(chainId) {
67
+ const symbols = {
68
+ 1: "ETH",
69
+ 10: "ETH",
70
+ 137: "POL",
71
+ 42161: "ETH",
72
+ 8453: "ETH",
73
+ 999: "ETH",
74
+ 11155111: "ETH",
75
+ 5: "ETH",
76
+ 80001: "POL",
77
+ 421613: "ETH",
78
+ 84531: "ETH",
79
+ };
80
+ return symbols[chainId] ?? "ETH";
81
+ }
82
+ /** Check if an asset is the native currency for a given chain */
83
+ export function isNativeCurrency(asset, chainId) {
84
+ return asset.toUpperCase() === getNativeCurrencySymbol(chainId).toUpperCase();
85
+ }
86
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/wallet/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiHH,mDAAmD;AACnD,MAAM,CAAC,MAAM,aAAa,GAAmC;IAC3D,WAAW;IACX,CAAC,EAAE;QACD,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,0BAA0B;QAClC,YAAY,EAAE,CAAC,0BAA0B,EAAE,iCAAiC,CAAC;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;IACF,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,SAAS,OAAO,EAAE,CAAC;AAC9C,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,MAAM,OAAO,GAA2B;QACtC,CAAC,EAAE,KAAK;QACR,EAAE,EAAE,KAAK;QACT,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,KAAK;QACV,QAAQ,EAAE,KAAK;QACf,CAAC,EAAE,KAAK;QACR,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,KAAK;KACb,CAAC;IACF,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;AACnC,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,OAAe;IAC7D,OAAO,KAAK,CAAC,WAAW,EAAE,KAAK,uBAAuB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;AAChF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@grimoirelabs/core",
3
+ "version": "0.1.0",
4
+ "description": "Core compiler and runtime for Grimoire",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js",
10
+ "./types": "./dist/types/index.js",
11
+ "./compiler": "./dist/compiler/index.js",
12
+ "./runtime": "./dist/runtime/index.js",
13
+ "./builders": "./dist/builders/index.js",
14
+ "./venues": "./dist/venues/index.js"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.build.json",
18
+ "test": "bun test",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "files": ["dist"],
22
+ "dependencies": {
23
+ "ethers": "^6.12.1",
24
+ "viem": "^2.21.0",
25
+ "yaml": "^2.6.0",
26
+ "zod": "^3.23.0"
27
+ },
28
+ "peerDependencies": {
29
+ "better-sqlite3": "^9.6.0"
30
+ },
31
+ "peerDependenciesMeta": {
32
+ "better-sqlite3": {
33
+ "optional": true
34
+ }
35
+ },
36
+ "devDependencies": {
37
+ "typescript": "^5.6.3"
38
+ }
39
+ }