@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.
- package/README.md +369 -142
- package/dist/config/testnets.d.ts.map +1 -1
- package/dist/config/testnets.js +14 -8
- package/dist/config/testnets.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/parser/classifiers/intent-classifier.d.ts +0 -12
- package/dist/parser/classifiers/intent-classifier.d.ts.map +1 -1
- package/dist/parser/classifiers/intent-classifier.js +0 -14
- package/dist/parser/classifiers/intent-classifier.js.map +1 -1
- package/dist/parser/extractors/action.d.ts +1 -1
- package/dist/parser/extractors/action.d.ts.map +1 -1
- package/dist/parser/extractors/action.js +1 -2
- package/dist/parser/extractors/action.js.map +1 -1
- package/dist/parser/extractors/token.d.ts.map +1 -1
- package/dist/parser/extractors/token.js +12 -2
- package/dist/parser/extractors/token.js.map +1 -1
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/parser/index.js +26 -3
- package/dist/parser/index.js.map +1 -1
- package/dist/parser/utils/normalize.d.ts +1 -3
- package/dist/parser/utils/normalize.d.ts.map +1 -1
- package/dist/parser/utils/normalize.js +3 -7
- package/dist/parser/utils/normalize.js.map +1 -1
- package/dist/parser/utils/parser-helpers.d.ts +25 -2
- package/dist/parser/utils/parser-helpers.d.ts.map +1 -1
- package/dist/parser/utils/parser-helpers.js +21 -6
- package/dist/parser/utils/parser-helpers.js.map +1 -1
- package/dist/parser/validators/schema.d.ts +1 -3
- package/dist/parser/validators/schema.d.ts.map +1 -1
- package/dist/parser/validators/schema.js +2 -5
- package/dist/parser/validators/schema.js.map +1 -1
- package/dist/solver/agent/liquidity-agent.d.ts +2 -0
- package/dist/solver/agent/liquidity-agent.d.ts.map +1 -1
- package/dist/solver/agent/liquidity-agent.js +33 -10
- package/dist/solver/agent/liquidity-agent.js.map +1 -1
- package/dist/solver/contracts/intent-settlement/viem-settlement-contract.d.ts.map +1 -1
- package/dist/solver/contracts/intent-settlement/viem-settlement-contract.js +1 -3
- package/dist/solver/contracts/intent-settlement/viem-settlement-contract.js.map +1 -1
- package/dist/solver/mempool/intent-filter.d.ts +13 -1
- package/dist/solver/mempool/intent-filter.d.ts.map +1 -1
- package/dist/solver/mempool/intent-filter.js +29 -3
- package/dist/solver/mempool/intent-filter.js.map +1 -1
- package/dist/solver/pricing/dynamic-pricing.d.ts.map +1 -1
- package/dist/solver/pricing/dynamic-pricing.js +18 -2
- package/dist/solver/pricing/dynamic-pricing.js.map +1 -1
- package/dist/solver/protocols/aggregators/lifi.d.ts +13 -4
- package/dist/solver/protocols/aggregators/lifi.d.ts.map +1 -1
- package/dist/solver/protocols/aggregators/lifi.js +1 -1
- package/dist/solver/protocols/aggregators/lifi.js.map +1 -1
- package/dist/solver/protocols/aggregators/swing.d.ts +36 -4
- package/dist/solver/protocols/aggregators/swing.d.ts.map +1 -1
- package/dist/solver/protocols/aggregators/swing.js +0 -1
- package/dist/solver/protocols/aggregators/swing.js.map +1 -1
- package/dist/solver/protocols/lending/aave.d.ts.map +1 -1
- package/dist/solver/protocols/lending/aave.js +4 -3
- package/dist/solver/protocols/lending/aave.js.map +1 -1
- package/dist/solver/settlement/settlement-manager.d.ts +7 -1
- package/dist/solver/settlement/settlement-manager.d.ts.map +1 -1
- package/dist/solver/settlement/settlement-manager.js +16 -6
- package/dist/solver/settlement/settlement-manager.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,258 +1,485 @@
|
|
|
1
|
-
# Intent Parser SDK
|
|
1
|
+
# π Intent Parser SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Parse natural language blockchain intents. Solve them cross-chain. Automatically.**
|
|
4
4
|
|
|
5
|
-
|
|
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
|
+
[](https://www.npmjs.com/package/@terkoizmy/intent-sdk)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](#)
|
|
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
|
-
|
|
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
|
-
|
|
43
|
+
**Requirements:** Node.js β₯ 18 or Bun β₯ 1.0
|
|
14
44
|
|
|
15
|
-
|
|
45
|
+
---
|
|
16
46
|
|
|
17
|
-
|
|
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 =
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## π§ Supported Intent Types
|
|
78
154
|
|
|
79
|
-
| Type | Example |
|
|
80
|
-
|
|
81
|
-
|
|
|
82
|
-
|
|
|
83
|
-
|
|
|
84
|
-
|
|
|
85
|
-
|
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
207
|
+
> Add any EVM chain by supplying its `chainId` in `supportedChains` and an RPC URL.
|
|
107
208
|
|
|
108
|
-
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## πΈ Fee Structure
|
|
212
|
+
|
|
213
|
+
The solver earns fees on every successful solve:
|
|
109
214
|
|
|
110
|
-
```
|
|
111
|
-
|
|
215
|
+
```
|
|
216
|
+
totalFee = baseFee + gasCost + slippageCapture
|
|
112
217
|
```
|
|
113
218
|
|
|
114
|
-
|
|
|
115
|
-
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
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
|
-
|
|
271
|
+
---
|
|
126
272
|
|
|
127
|
-
|
|
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
|
-
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## βοΈ Environment Variables
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
cp .env.example .env
|
|
131
321
|
```
|
|
132
322
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
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)` | `
|
|
150
|
-
| `parseBatch(texts)` | `
|
|
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
|
|
161
|
-
| `start(
|
|
162
|
-
| `stop()` |
|
|
163
|
-
| `canSolve(intent)` |
|
|
164
|
-
| `getQuote(intent)` |
|
|
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
|
|
363
|
+
| `getStats()` | Returns `{ profitStats, mempoolStats }` |
|
|
168
364
|
|
|
169
|
-
### `createIntentSDK(config)`
|
|
365
|
+
### `createIntentSDK(config)` β Factory
|
|
170
366
|
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
193
|
-
| `examples/autonomous-agent.ts` |
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
-
#
|
|
215
|
-
bun test tests/
|
|
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
|
-
#
|
|
218
|
-
bun test tests/
|
|
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
|
-
#
|
|
221
|
-
|
|
468
|
+
# Type check only
|
|
469
|
+
bun run build --noEmit
|
|
222
470
|
```
|
|
223
471
|
|
|
224
|
-
|
|
472
|
+
---
|
|
225
473
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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,
|
|
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"}
|