@terkoizmy/intent-sdk 1.0.0 β†’ 1.0.2

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 (64) hide show
  1. package/README.md +369 -142
  2. package/dist/config/testnets.d.ts.map +1 -1
  3. package/dist/config/testnets.js +14 -8
  4. package/dist/config/testnets.js.map +1 -1
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +0 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/parser/classifiers/intent-classifier.d.ts +0 -12
  10. package/dist/parser/classifiers/intent-classifier.d.ts.map +1 -1
  11. package/dist/parser/classifiers/intent-classifier.js +0 -14
  12. package/dist/parser/classifiers/intent-classifier.js.map +1 -1
  13. package/dist/parser/extractors/action.d.ts +1 -1
  14. package/dist/parser/extractors/action.d.ts.map +1 -1
  15. package/dist/parser/extractors/action.js +1 -2
  16. package/dist/parser/extractors/action.js.map +1 -1
  17. package/dist/parser/extractors/token.d.ts.map +1 -1
  18. package/dist/parser/extractors/token.js +12 -2
  19. package/dist/parser/extractors/token.js.map +1 -1
  20. package/dist/parser/index.d.ts.map +1 -1
  21. package/dist/parser/index.js +26 -3
  22. package/dist/parser/index.js.map +1 -1
  23. package/dist/parser/utils/normalize.d.ts +1 -3
  24. package/dist/parser/utils/normalize.d.ts.map +1 -1
  25. package/dist/parser/utils/normalize.js +3 -7
  26. package/dist/parser/utils/normalize.js.map +1 -1
  27. package/dist/parser/utils/parser-helpers.d.ts +25 -2
  28. package/dist/parser/utils/parser-helpers.d.ts.map +1 -1
  29. package/dist/parser/utils/parser-helpers.js +21 -6
  30. package/dist/parser/utils/parser-helpers.js.map +1 -1
  31. package/dist/parser/validators/schema.d.ts +1 -3
  32. package/dist/parser/validators/schema.d.ts.map +1 -1
  33. package/dist/parser/validators/schema.js +2 -5
  34. package/dist/parser/validators/schema.js.map +1 -1
  35. package/dist/solver/agent/liquidity-agent.d.ts +2 -0
  36. package/dist/solver/agent/liquidity-agent.d.ts.map +1 -1
  37. package/dist/solver/agent/liquidity-agent.js +33 -10
  38. package/dist/solver/agent/liquidity-agent.js.map +1 -1
  39. package/dist/solver/contracts/intent-settlement/viem-settlement-contract.d.ts.map +1 -1
  40. package/dist/solver/contracts/intent-settlement/viem-settlement-contract.js +1 -3
  41. package/dist/solver/contracts/intent-settlement/viem-settlement-contract.js.map +1 -1
  42. package/dist/solver/mempool/intent-filter.d.ts +13 -1
  43. package/dist/solver/mempool/intent-filter.d.ts.map +1 -1
  44. package/dist/solver/mempool/intent-filter.js +29 -3
  45. package/dist/solver/mempool/intent-filter.js.map +1 -1
  46. package/dist/solver/pricing/dynamic-pricing.d.ts.map +1 -1
  47. package/dist/solver/pricing/dynamic-pricing.js +18 -2
  48. package/dist/solver/pricing/dynamic-pricing.js.map +1 -1
  49. package/dist/solver/protocols/aggregators/lifi.d.ts +13 -4
  50. package/dist/solver/protocols/aggregators/lifi.d.ts.map +1 -1
  51. package/dist/solver/protocols/aggregators/lifi.js +1 -1
  52. package/dist/solver/protocols/aggregators/lifi.js.map +1 -1
  53. package/dist/solver/protocols/aggregators/swing.d.ts +36 -4
  54. package/dist/solver/protocols/aggregators/swing.d.ts.map +1 -1
  55. package/dist/solver/protocols/aggregators/swing.js +0 -1
  56. package/dist/solver/protocols/aggregators/swing.js.map +1 -1
  57. package/dist/solver/protocols/lending/aave.d.ts.map +1 -1
  58. package/dist/solver/protocols/lending/aave.js +4 -3
  59. package/dist/solver/protocols/lending/aave.js.map +1 -1
  60. package/dist/solver/settlement/settlement-manager.d.ts +7 -1
  61. package/dist/solver/settlement/settlement-manager.d.ts.map +1 -1
  62. package/dist/solver/settlement/settlement-manager.js +16 -6
  63. package/dist/solver/settlement/settlement-manager.js.map +1 -1
  64. package/package.json +2 -2
package/README.md CHANGED
@@ -1,258 +1,485 @@
1
- # Intent Parser SDK
1
+ # πŸ”— Intent Parser SDK
2
2
 
3
- Lightweight natural language parser and autonomous solver SDK for blockchain intents.
3
+ > **Parse natural language blockchain intents. Solve them cross-chain. Automatically.**
4
4
 
5
- ## Installation
5
+ `@terkoizmy/intent-sdk` is a TypeScript SDK that converts everyday language like *"Bridge 500 USDC from Ethereum to Polygon"* into structured, executable blockchain transactions β€” while an autonomous solver agent handles the cross-chain execution, fee optimization, and settlement proof on your behalf.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@terkoizmy/intent-sdk)](https://www.npmjs.com/package/@terkoizmy/intent-sdk)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
9
+ [![Build](https://img.shields.io/badge/build-passing-brightgreen)](#)
10
+
11
+ ---
12
+
13
+ ## ✨ What It Does
14
+
15
+ | Capability | Description |
16
+ |-----------|-------------|
17
+ | 🧠 **Natural Language Parsing** | Turn plain English into structured `StructuredIntent` objects |
18
+ | ⚑ **Cross-Chain Bridging** | Autonomous solver executes bridge intents across EVM chains |
19
+ | πŸ’° **Dynamic Fee Pricing** | Fee scales with inventory levels, gas costs, and user slippage tolerance |
20
+ | πŸ”’ **Settlement Proofs** | ERC-7683–compliant on-chain settlement with signature proof verification |
21
+ | πŸ“Š **Monitoring & Alerting** | Built-in `ProfitTracker`, `HealthChecker`, and `AlertManager` |
22
+ | πŸ”„ **Auto-Rebalancing** | Inventory rebalancer uses Li.Fi or Swing to keep liquidity optimally distributed |
23
+ | πŸ›‘οΈ **Battle-Tested Error Handling** | Domain-specific error classes and retry logic with exponential backoff |
24
+
25
+ ---
26
+
27
+ ## πŸ“¦ Installation
6
28
 
7
29
  ```bash
30
+ # npm
8
31
  npm install @terkoizmy/intent-sdk
9
- # or
32
+
33
+ # bun
10
34
  bun add @terkoizmy/intent-sdk
35
+
36
+ # yarn
37
+ yarn add @terkoizmy/intent-sdk
38
+
39
+ # pnpm
40
+ pnpm add @terkoizmy/intent-sdk
11
41
  ```
12
42
 
13
- ## Quick Start
43
+ **Requirements:** Node.js β‰₯ 18 or Bun β‰₯ 1.0
14
44
 
15
- > **For the full, comprehensive guide, please see [docs/USAGE.md](./docs/USAGE.md).**
45
+ ---
16
46
 
17
- ### Parser Only
47
+ ## πŸš€ Quick Start
48
+
49
+ ### 1. Parse-Only (No Solver)
18
50
 
19
51
  ```typescript
20
52
  import { IntentParser } from "@terkoizmy/intent-sdk";
21
53
 
22
54
  const parser = new IntentParser();
23
- const result = await parser.parse("Bridge 100 USDC from Ethereum to Arbitrum");
24
-
25
- // { success: true, data: { intentType: 'bridge', parameters: { ... } } }
55
+ const result = parser.parse("Bridge 500 USDC from Ethereum to Polygon");
56
+
57
+ if (result.success) {
58
+ console.log(result.data);
59
+ // {
60
+ // intentType: "bridge",
61
+ // parameters: {
62
+ // inputToken: "USDC",
63
+ // inputAmount: "500",
64
+ // sourceChain: "1",
65
+ // targetChain: "137",
66
+ // recipient: undefined
67
+ // },
68
+ // constraints: { maxSlippage: 50 },
69
+ // metadata: { confidence: 0.92, parsedAt: 1709123456789 }
70
+ // }
71
+ }
26
72
  ```
27
73
 
28
- ### SDK Factory (Parser + Solver)
74
+ ### 2. Parser + Solver (Simulate Mode)
29
75
 
30
76
  ```typescript
31
77
  import { createIntentSDK } from "@terkoizmy/intent-sdk";
32
78
 
33
79
  const { parser, solver } = createIntentSDK({
34
80
  solver: {
35
- privateKey: process.env.SOLVER_PRIVATE_KEY!,
36
- supportedChains: [1, 10, 42161],
37
- supportedTokens: ["USDC", "USDT"],
38
- mode: "simulate" // use "live" for real execution
81
+ agent: {
82
+ privateKey: process.env.SOLVER_PRIVATE_KEY!,
83
+ mode: "simulate", // No real transactions
84
+ supportedChains: [1, 10, 42161, 137], // ETH, OP, ARB, Polygon
85
+ supportedTokens: ["USDC", "USDT"],
86
+ maxConcurrentIntents: 5,
87
+ },
88
+ contractAddress: "0xYOUR_SETTLEMENT_CONTRACT",
39
89
  },
40
- }
41
90
  });
42
91
 
43
92
  await solver.initialize();
44
93
 
45
- if (solver.canSolve(intent)) {
46
- const result = await solver.solve(intent);
47
- console.log(result); // { success: true, txHash: "0x...", profit: "..." }
94
+ // Parse + solve in one flow
95
+ const { data: intent } = parser.parse("Bridge 200 USDC from Ethereum to Arbitrum");
96
+ const solverIntent = buildSolverIntent(intent, userAddress, deadline);
97
+
98
+ if (solver.canSolve(solverIntent)) {
99
+ const quote = solver.getQuote(solverIntent);
100
+ console.log(`Fee: ${quote.totalFee} | User gets: ${quote.userReceives}`);
101
+
102
+ const result = await solver.solve(solverIntent);
103
+ console.log(result);
104
+ // { success: true, txHash: "0x...", profit: "4500000", metadata: { ... } }
48
105
  }
49
106
  ```
50
107
 
51
- ### Autonomous Mode
52
-
53
- Connect to a mempool server and solve intents automatically in the background:
108
+ ### 3. Autonomous Mode (Live Mempool Listener)
54
109
 
55
110
  ```typescript
56
111
  import { createIntentSDK } from "@terkoizmy/intent-sdk";
57
112
 
58
113
  const { solver } = createIntentSDK({
59
114
  solver: {
60
- privateKey: process.env.SOLVER_PRIVATE_KEY!,
61
- supportedChains: [1, 10, 42161],
62
- supportedTokens: ["USDC"],
63
- mode: "live"
115
+ agent: {
116
+ privateKey: process.env.SOLVER_PRIVATE_KEY!,
117
+ mode: "live", // Real ERC-20 transfers
118
+ supportedChains: [1, 10, 42161],
119
+ supportedTokens: ["USDC", "USDT"],
120
+ },
121
+ contractAddress: process.env.SETTLEMENT_CONTRACT!,
122
+ settlement: {
123
+ onPermanentFailure: (intentId, error, attempts) => {
124
+ console.error(`Intent ${intentId} failed permanently after ${attempts} tries: ${error}`);
125
+ // Send alert, page on-call, etc.
126
+ },
127
+ },
64
128
  },
65
- }
66
129
  });
67
130
 
68
131
  await solver.initialize();
132
+
133
+ // Connect to mempool β€” solver handles everything automatically
69
134
  solver.start("wss://mempool.yourprotocol.com/ws");
70
135
 
136
+ // Poll stats every 30s
71
137
  setInterval(() => {
72
138
  const stats = solver.getStats();
73
139
  console.log("Solved:", stats.mempoolStats.solved);
74
- }, 5000);
140
+ console.log("Total Profit:", stats.profitStats.totalProfit);
141
+ console.log("Success Rate:", `${(stats.profitStats.successCount / stats.profitStats.totalAttempts * 100).toFixed(1)}%`);
142
+ }, 30_000);
143
+
144
+ // Graceful shutdown
145
+ process.on("SIGINT", () => {
146
+ solver.stop();
147
+ process.exit(0);
148
+ });
75
149
  ```
76
150
 
77
- ## Supported Intent Types
151
+ ---
152
+
153
+ ## 🧠 Supported Intent Types
78
154
 
79
- | Type | Example |
80
- |------|---------|
81
- | **bridge** | "Bridge 100 USDC from Ethereum to Arbitrum" |
82
- | **send** | "Send 50 USDT to 0xAbc..." |
83
- | **swap** | "Swap 1 ETH for USDC on Uniswap" |
84
- | **claim** | "Claim rewards from staking" |
85
- | **yield_strategy** | "Deposit 1000 USDC into yield strategy with low risk" |
155
+ | Type | Example Phrases |
156
+ |------|----------------|
157
+ | **`bridge`** | *"Bridge 100 USDC from Ethereum to Arbitrum"* |
158
+ | **`send`** | *"Send 50 USDT to 0xAbc..."* or *"Transfer 0.1 ETH to alice.eth"* |
159
+ | **`swap`** | *"Swap 1 ETH for USDC on Uniswap with max 1% slippage"* |
160
+ | **`claim`** | *"Claim my ARB airdrop"* / *"Claim staking rewards from Aave"* |
161
+ | **`yield_strategy`** | *"Deposit 1000 USDC for safe yield"* / *"degen high APY"* |
86
162
 
87
- ## Supported Chains
163
+ ### Parser Output Shape
164
+
165
+ ```typescript
166
+ interface StructuredIntent {
167
+ intentType: "bridge" | "send" | "swap" | "claim" | "yield_strategy" | "unknown";
168
+ parameters: IntentParameters; // inputToken, inputAmount, sourceChain, targetChain, recipient, etc.
169
+ constraints: {
170
+ maxSlippage?: number; // basis points (100 = 1%)
171
+ deadline?: number; // unix timestamp
172
+ maxGasCost?: string; // in native token
173
+ preferredDEXs?: string[];
174
+ minProtocols?: number;
175
+ // ... and more
176
+ };
177
+ metadata: {
178
+ confidence: number; // 0 to 1 β€” how confident the parser is
179
+ parsedAt: number; // unix ms timestamp
180
+ rawText?: string; // original user input
181
+ };
182
+ }
183
+ ```
184
+
185
+ ---
186
+
187
+ ## 🌐 Supported Chains
88
188
 
89
189
  ### Mainnets
90
190
 
91
- | Chain | ID |
92
- |-------|----|
93
- | Ethereum Mainnet | 1 |
94
- | Optimism | 10 |
95
- | Arbitrum One | 42161 |
191
+ | Chain | ID | Notes |
192
+ |-------|----|----|
193
+ | Ethereum | `1` | Primary liquidity hub |
194
+ | Optimism | `10` | L2 β€” low gas |
195
+ | Arbitrum One | `42161` | L2 β€” low gas |
196
+ | Polygon | `137` | Fast finality |
96
197
 
97
198
  ### Testnets
98
199
 
99
200
  | Chain | ID | Settlement Contract |
100
- |-------|----|--------------------|
101
- | Unichain Sepolia | 1301 | [`0x7066f6...`](https://unichain-sepolia.blockscout.com/address/0x7066f6dFc1C652c165Bc9BB10085fD95719b5eA6) |
102
- | Ethereum Sepolia | 11155111 | β€” |
103
- | Arbitrum Sepolia | 421614 | β€” |
104
- | Base Sepolia | 84532 | β€” |
201
+ |-------|----|---------------------|
202
+ | Unichain Sepolia | `1301` | [`0x7066f6...`](https://unichain-sepolia.blockscout.com/address/0x7066f6dFc1C652c165Bc9BB10085fD95719b5eA6) βœ… Deployed |
203
+ | Ethereum Sepolia | `11155111` | β€” |
204
+ | Arbitrum Sepolia | `421614` | β€” |
205
+ | Base Sepolia | `84532` | β€” |
105
206
 
106
- Configure additional chains by adding their IDs to `supportedChains` and providing RPC URLs.
207
+ > Add any EVM chain by supplying its `chainId` in `supportedChains` and an RPC URL.
107
208
 
108
- ## Environment Configuration
209
+ ---
210
+
211
+ ## πŸ’Έ Fee Structure
212
+
213
+ The solver earns fees on every successful solve:
109
214
 
110
- ```bash
111
- cp .env.example .env
215
+ ```
216
+ totalFee = baseFee + gasCost + slippageCapture
112
217
  ```
113
218
 
114
- | Variable | Required | Description |
115
- |----------|----------|-------------|
116
- | `SOLVER_PRIVATE_KEY` | βœ… | Solver wallet private key (hex, with `0x`) |
117
- | `UNICHAIN_SEPOLIA_RPC_URL` | βœ… | RPC for Unichain Sepolia (1301) |
118
- | `SEPOLIA_RPC_URL` | Optional | RPC for Ethereum Sepolia |
119
- | `ARB_SEPOLIA_RPC_URL` | Optional | RPC for Arbitrum Sepolia |
120
- | `ETH_RPC_URL` | Optional | Ethereum Mainnet RPC (Aave reads) |
121
- | `SETTLEMENT_CONTRACT_UNICHAIN_SEPOLIA` | For live settlement | Deployed proxy address |
219
+ | Component | Default | Description |
220
+ |-----------|---------|-------------|
221
+ | `baseFee` | 0.5% | Service charge on bridge amount |
222
+ | `gasCost` | Dynamic | Estimated destination-chain gas |
223
+ | `slippageCapture` | 50% of user's tolerance | Profit from unused slippage |
224
+
225
+ ### Dynamic Inventory Multiplier
226
+
227
+ When liquidity on the target chain is low, fees adjust automatically:
228
+
229
+ | Capacity | Multiplier | Behavior |
230
+ |----------|-----------|----------|
231
+ | β‰₯ 80% | **0.8Γ—** | Discount β€” aggressively fill to rebalance |
232
+ | 50–79% | **1.0Γ—** | Normal pricing |
233
+ | 20–49% | **1.5Γ—** | Premium β€” inventory getting scarce |
234
+ | 5–19% | **2.0Γ—** | High premium |
235
+ | < 5% | **Rejected** | Intent declined β€” not enough liquidity |
236
+
237
+ ---
238
+
239
+ ## πŸ›‘οΈ Error Handling
240
+
241
+ The SDK exposes typed error classes for precise catch handling:
122
242
 
123
- See [.env.example](./.env.example) for the full list.
243
+ ```typescript
244
+ import {
245
+ IntentExpiredError,
246
+ InsufficientInventoryError,
247
+ UnsupportedIntentError,
248
+ ClaimFailedError,
249
+ ProofGenerationError,
250
+ SettlementError,
251
+ } from "@terkoizmy/intent-sdk";
252
+
253
+ try {
254
+ const result = await solver.solve(intent);
255
+ } catch (error) {
256
+ if (error instanceof IntentExpiredError) {
257
+ // Intent deadline passed β€” ignore or notify user
258
+ console.warn("Deadline passed, skipping intent.");
259
+ } else if (error instanceof InsufficientInventoryError) {
260
+ // Not enough tokens on target chain
261
+ console.error(`Low inventory on chain ${error.chainId}`);
262
+ } else if (error instanceof ClaimFailedError) {
263
+ // Settlement claim on source chain failed
264
+ console.error(`Claim failed: ${error.reason}`);
265
+ } else {
266
+ throw error; // Rethrow unexpected errors
267
+ }
268
+ }
269
+ ```
124
270
 
125
- ## Solver Economics
271
+ ---
126
272
 
127
- The solver earns a fee on every successful solve:
273
+ ## πŸ”§ Configuration Reference
128
274
 
275
+ ```typescript
276
+ createIntentSDK({
277
+ solver: {
278
+ agent: {
279
+ privateKey: "0x...", // Required β€” solver wallet private key
280
+ mode: "simulate" | "live", // Required β€” simulate or real transactions
281
+ name?: "MySolver", // Optional name
282
+ supportedChains: [1, 137], // Which chain IDs to service
283
+ supportedTokens: ["USDC"], // Which tokens to handle
284
+ maxConcurrentIntents?: 5, // Parallel solve limit (default: 5)
285
+ },
286
+ contractAddress: "0x...", // IntentSettlement.sol proxy address
287
+
288
+ rpcUrls?: { // Optional override β€” fallback to public RPCs
289
+ 1: "https://eth.rpc.example.com",
290
+ 137: "https://polygon.rpc.example.com",
291
+ },
292
+
293
+ pricing?: {
294
+ baseFeePercent?: 0.005, // 0.5% base fee (default)
295
+ minFeeUSD?: 1, // Minimum $1 USDC (default)
296
+ maxFeePercent?: 0.03, // 3% cap (default)
297
+ slippageSharePercent?: 0.5, // Capture 50% of user's tolerance (default)
298
+ },
299
+
300
+ inventory?: {
301
+ minReservePercent?: 0.10, // Keep 10% in reserve (default)
302
+ rebalanceThreshold?: 0.15, // Trigger rebalance at 15% imbalance (default)
303
+ },
304
+
305
+ settlement?: {
306
+ requiredConfirmations?: 3, // Blocks before proof is generated (default: 3)
307
+ maxClaimRetries?: 3, // Max retry attempts (default: 3)
308
+ watchIntervalMs?: 30_000, // Watcher poll interval (default: 30s)
309
+ onPermanentFailure?: (intentId, error, attempts) => void, // Failure callback
310
+ },
311
+ },
312
+ });
129
313
  ```
130
- totalFee = baseFee + gasCost + slippageCapture
314
+
315
+ ---
316
+
317
+ ## βš™οΈ Environment Variables
318
+
319
+ ```bash
320
+ cp .env.example .env
131
321
  ```
132
322
 
133
- - **baseFee** β€” fixed % of the bridge amount (configurable, default 0.05%)
134
- - **gasCost** β€” estimated gas cost on the destination chain
135
- - **slippageCapture** β€” profit from unused slippage tolerance
323
+ | Variable | Required | Description |
324
+ |----------|----------|-------------|
325
+ | `SOLVER_PRIVATE_KEY` | βœ… | Solver wallet private key (hex, with `0x`) |
326
+ | `UNICHAIN_SEPOLIA_RPC_URL` | βœ… for testnet | RPC endpoint for Unichain Sepolia |
327
+ | `SEPOLIA_RPC_URL` | Optional | Ethereum Sepolia RPC |
328
+ | `ARB_SEPOLIA_RPC_URL` | Optional | Arbitrum Sepolia RPC |
329
+ | `BASE_SEPOLIA_RPC_URL` | Optional | Base Sepolia RPC |
330
+ | `ETH_RPC_URL` | Optional | Ethereum Mainnet (Aave reads) |
331
+ | `SETTLEMENT_CONTRACT_UNICHAIN_SEPOLIA` | For live settlement | Deployed contract proxy address |
136
332
 
137
- The solver receives `userPays = inputAmount` from the source chain settlement and pays the user `userReceives = inputAmount - totalFee` on the target chain. The difference is solver profit.
333
+ ---
138
334
 
139
- ## API
335
+ ## πŸ“– API Reference
140
336
 
141
337
  ### `IntentParser`
142
338
 
143
339
  ```typescript
144
- new IntentParser(config?: ParserConfig)
340
+ const parser = new IntentParser(config?: ParserConfig);
145
341
  ```
146
342
 
147
343
  | Method | Returns | Description |
148
344
  |--------|---------|-------------|
149
- | `parse(text)` | `Promise<ParseResult>` | Parse a natural language intent |
150
- | `parseBatch(texts)` | `Promise<ParseResult[]>` | Parse multiple intents |
345
+ | `parse(text)` | `ParseResult` | Parse a single natural language intent (sync) |
346
+ | `parseBatch(texts[])` | `ParseResult[]` | Parse multiple intents at once (sync) |
151
347
 
152
348
  ### `IntentSolver`
153
349
 
154
350
  ```typescript
155
- new IntentSolver(config: LiquidityAgentConfig)
351
+ const solver = new IntentSolver(config: LiquidityAgentConfig);
156
352
  ```
157
353
 
158
354
  | Method | Description |
159
355
  |--------|-------------|
160
- | `initialize()` | Load balances and derive solver address |
161
- | `start(url)` | Connect to mempool WebSocket |
162
- | `stop()` | Disconnect and stop all background work |
163
- | `canSolve(intent)` | Check if this intent can be solved |
164
- | `getQuote(intent)` | Get fee breakdown without executing |
165
- | `solve(intent)` | Execute full solve β†’ settlement flow |
356
+ | `initialize()` | Load on-chain balances, derive solver address. **Call before anything else.** |
357
+ | `start(mempoolUrl)` | Connect to mempool WebSocket and autonomously solve intents |
358
+ | `stop()` | Gracefully disconnect and stop all background work |
359
+ | `canSolve(intent)` | Returns `true` if the solver supports this intent type, chain, token, and has enough inventory |
360
+ | `getQuote(intent)` | Returns full `PricingResult` fee breakdown without executing anything |
361
+ | `solve(intent)` | Execute full solve β†’ settlement flow. Returns `SolutionResult` |
166
362
  | `getStatus()` | Returns `"idle"` or `"processing"` |
167
- | `getStats()` | Returns profit + mempool statistics |
363
+ | `getStats()` | Returns `{ profitStats, mempoolStats }` |
168
364
 
169
- ### `createIntentSDK(config)`
365
+ ### `createIntentSDK(config)` β€” Factory
170
366
 
171
- Factory that creates both `parser` and `solver` in one call:
367
+ Returns `{ parser, solver }` β€” the easiest way to get started:
172
368
 
173
369
  ```typescript
174
370
  const { parser, solver } = createIntentSDK(config);
371
+ // parser β†’ IntentParser
372
+ // solver β†’ IntentSolver (wraps LiquidityAgent + all subsystems)
373
+ ```
374
+
375
+ ---
376
+
377
+ ## πŸ“‚ Project Structure
378
+
379
+ ```
380
+ src/
381
+ β”œβ”€β”€ parser/ ← IntentParser β€” NLP-to-structured-intent engine
382
+ β”‚ β”œβ”€β”€ classifiers/ ← Intent type detection (bridge/send/swap/...)
383
+ β”‚ β”œβ”€β”€ extractors/ ← Amount, token, chain, action extraction
384
+ β”‚ β”œβ”€β”€ validators/ ← Zod schema validation
385
+ β”‚ └── utils/ ← Normalization, confidence scoring
386
+ β”œβ”€β”€ solver/ ← IntentSolver β€” autonomous liquidity agent
387
+ β”‚ β”œβ”€β”€ agent/ ← LiquidityAgent, AgentConfig
388
+ β”‚ β”œβ”€β”€ contracts/ ← ViemSettlementContract (ERC-7683 wrapper)
389
+ β”‚ β”œβ”€β”€ inventory/ ← InventoryManager, Rebalancer (Li.Fi / Swing)
390
+ β”‚ β”œβ”€β”€ mempool/ ← MempoolClient, IntentFilter, SolutionSubmitter
391
+ β”‚ β”œβ”€β”€ monitoring/ ← ProfitTracker, HealthChecker, AlertManager
392
+ β”‚ β”œβ”€β”€ pricing/ ← DynamicPricing, FeeCalculator, SlippageCapture
393
+ β”‚ β”œβ”€β”€ protocols/ ← Li.Fi (bridge aggregator), Aave (lending), Swing
394
+ β”‚ └── settlement/ ← ProofGenerator, ProofVerifier, SettlementManager
395
+ β”œβ”€β”€ shared/ ← Reusable utilities
396
+ β”‚ β”œβ”€β”€ rpc/ ← ViemProvider (with retry backoff), RPCProviderManager
397
+ β”‚ β”œβ”€β”€ utils/ ← ERC-20 ABI utils, withRetry
398
+ β”‚ β”œβ”€β”€ chain-registry/ ← Chain configs, name resolvers
399
+ β”‚ β”œβ”€β”€ token-registry/ ← Token metadata
400
+ β”‚ └── wallet-manager/ ← WalletManager (sign, transfer)
401
+ β”œβ”€β”€ errors/ ← Domain-specific typed error classes
402
+ β”œβ”€β”€ types/ ← Shared TypeScript interfaces
403
+ └── config/ ← Chain configs, default pricing, testnet RPC URLs
404
+ contracts/ ← IntentSettlement.sol (ERC-7683 + UUPS upgradeable)
405
+ tests/
406
+ β”œβ”€β”€ parser/ ← Parser unit tests
407
+ β”œβ”€β”€ solver/ ← Solver unit tests (pricing, settlement, protocols)
408
+ β”œβ”€β”€ shared/ ← Shared utility tests (retry, viem, chain registry)
409
+ β”œβ”€β”€ integration/ ← Mock-based full pipeline tests
410
+ β”œβ”€β”€ live/ ← Live testnet tests (requires funded wallet + RPC)
411
+ └── e2e/ ← End-to-end testnet tests
412
+ docs/ ← Full documentation
413
+ examples/ ← Runnable code examples
175
414
  ```
176
415
 
177
- ## Documentation
416
+ ---
417
+
418
+ ## πŸ“š Documentation
419
+
420
+ | Document | What You'll Find |
421
+ |----------|-----------------|
422
+ | [docs/USAGE.md](./docs/USAGE.md) | Full usage guide with all features and code samples |
423
+ | [docs/SOLVER.md](./docs/SOLVER.md) | Solver architecture, config reference, fee structure, API |
424
+ | [docs/SDK_WORKFLOW.md](./docs/SDK_WORKFLOW.md) | End-to-end workflow diagrams (Parser β†’ Solver β†’ Settlement) |
425
+ | [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md) | System architecture, component map, data flows |
426
+ | [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md) | Deploy the IntentSettlement smart contract |
427
+ | [docs/TESTNET_GUIDE.md](./docs/TESTNET_GUIDE.md) | Faucets, wallet funding, troubleshooting on testnets |
428
+ | [docs/ERC_STANDARDS.md](./docs/ERC_STANDARDS.md) | ERC-7683, ERC-712 standards used in settlement |
178
429
 
179
- | Document | Contents |
180
- |----------|----------|
181
- | [docs/USAGE.md](./docs/USAGE.md) | Comprehensive How-To Guide for using the SDK |
182
- | [docs/SOLVER.md](./docs/SOLVER.md) | Architecture, config reference, fee structure, API details |
183
- | [docs/SDK_WORKFLOW.md](./docs/SDK_WORKFLOW.md) | End-to-end workflow diagrams |
184
- | [docs/ERC_STANDARDS.md](./docs/ERC_STANDARDS.md) | ERC-7683, ERC-712 standards used |
185
- | [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md) | Step-by-step testnet deployment guide |
186
- | [docs/TESTNET_GUIDE.md](./docs/TESTNET_GUIDE.md) | Faucets, funding, troubleshooting |
430
+ ---
187
431
 
188
- ## Examples
432
+ ## πŸ’‘ Examples
189
433
 
190
434
  | File | Description |
191
435
  |------|-------------|
192
- | `examples/basic-bridge.ts` | Parse + manual solve |
193
- | `examples/autonomous-agent.ts` | Autonomous mempool listener |
194
- | `examples/inventory-management.ts` | Inventory snapshot + rebalancing |
436
+ | [`examples/basic-bridge.ts`](./examples/basic-bridge.ts) | Parse and manually solve a bridge intent |
437
+ | [`examples/autonomous-agent.ts`](./examples/autonomous-agent.ts) | Fully autonomous mempool listener agent |
438
+ | [`examples/inventory-management.ts`](./examples/inventory-management.ts) | Inventory snapshot + auto-rebalancing |
439
+
440
+ ```bash
441
+ # Run an example
442
+ npx tsx examples/basic-bridge.ts
443
+ ```
195
444
 
196
- ## Development
445
+ ---
446
+
447
+ ## πŸ§ͺ Development
197
448
 
198
449
  ```bash
199
450
  # Install dependencies
200
451
  bun install
201
452
 
202
- # Build
453
+ # Build TypeScript
203
454
  bun run build
204
455
 
205
- # Test all (parser + solver units + integration)
206
- bun test
207
-
208
- # Run specific test suites
209
- bun test tests/parser/
210
- bun test tests/solver/
211
- bun test tests/integration/
212
- bun test tests/shared/
456
+ # Run all tests (no network needed)
457
+ bun test tests/parser/ tests/solver/ tests/shared/ tests/integration/
213
458
 
214
- # Live tests (requires funded wallet + RPC)
215
- bun test tests/live/
459
+ # Run specific suites
460
+ bun test tests/parser/ # parser unit tests
461
+ bun test tests/solver/ # solver unit tests
462
+ bun test tests/integration/ # integration pipeline tests
216
463
 
217
- # E2E testnet tests (full pipeline)
218
- bun test tests/e2e/
464
+ # Tests requiring a funded wallet + RPC
465
+ bun test tests/live/ # live testnet tests
466
+ bun test tests/e2e/ # full E2E pipeline
219
467
 
220
- # Run an example
221
- npx tsx examples/basic-bridge.ts
468
+ # Type check only
469
+ bun run build --noEmit
222
470
  ```
223
471
 
224
- ## Project Structure
472
+ ---
225
473
 
226
- ```
227
- src/
228
- β”œβ”€β”€ parser/ ← IntentParser (Stage 1)
229
- β”œβ”€β”€ solver/ ← IntentSolver / LiquidityAgent (Stage 2+3)
230
- β”‚ β”œβ”€β”€ agent/ ← LiquidityAgent, AgentConfig
231
- β”‚ β”œβ”€β”€ contracts/ ← IntentSettlement viem wrapper
232
- β”‚ β”œβ”€β”€ inventory/ ← InventoryManager, Rebalancer
233
- β”‚ β”œβ”€β”€ pricing/ ← DynamicPricing, FeeCalculator
234
- β”‚ β”œβ”€β”€ settlement/ ← ProofGenerator, SettlementManager
235
- β”‚ β”œβ”€β”€ mempool/ ← MempoolClient, IntentFilter
236
- β”‚ β”œβ”€β”€ monitoring/ ← ProfitTracker, HealthChecker
237
- β”‚ └── protocols/ ← LiFi (aggregator), Aave (lending)
238
- β”œβ”€β”€ shared/ ← WalletManager, ChainRegistry, RPC, TokenRegistry
239
- β”‚ β”œβ”€β”€ rpc/ ← RPCProviderManager, ViemProvider (with retry)
240
- β”‚ β”œβ”€β”€ utils/ ← ERC-20 utils, retry with backoff
241
- β”‚ └── chain-registry/ ← Chain configs, chain names
242
- β”œβ”€β”€ errors/ ← Domain-specific error classes
243
- └── types/ ← Shared types
244
- contracts/ ← IntentSettlement.sol (ERC-7683, UUPS)
245
- tests/
246
- β”œβ”€β”€ parser/ ← Parser unit tests
247
- β”œβ”€β”€ solver/ ← Solver unit tests
248
- β”œβ”€β”€ shared/ ← Shared util tests (retry, viem, enrichment)
249
- β”œβ”€β”€ integration/ ← Mock-based integration tests
250
- β”œβ”€β”€ live/ ← Live testnet tests (guarded)
251
- └── e2e/ ← Full E2E pipeline tests (guarded)
252
- docs/ ← Documentation
253
- examples/ ← Runnable usage examples
254
- ```
474
+ ## 🀝 Contributing
475
+
476
+ Pull requests are welcome! Please:
477
+ 1. Run `bun test` and confirm all non-live tests pass
478
+ 2. Run `bun run build` and confirm no TypeScript errors
479
+ 3. Follow the existing code style (typed catch blocks, no `any`, typed interfaces)
480
+
481
+ ---
255
482
 
256
- ## License
483
+ ## πŸ“„ License
257
484
 
258
- MIT
485
+ MIT Β© 2024 [@terkoizmy](https://github.com/terkoizmy)
@@ -1 +1 @@
1
- {"version":3,"file":"testnets.d.ts","sourceRoot":"","sources":["../../src/config/testnets.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,WAgB5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAgBrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAgBrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,WAgBjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,EAK3C,CAAC"}
1
+ {"version":3,"file":"testnets.d.ts","sourceRoot":"","sources":["../../src/config/testnets.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,WAkB5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAkBrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAgBrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,WAkBjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,EAK3C,CAAC"}