@jack-kernel/sdk 1.0.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 (68) hide show
  1. package/README.md +757 -0
  2. package/dist/cjs/agent.js +321 -0
  3. package/dist/cjs/agent.js.map +1 -0
  4. package/dist/cjs/cache.js +58 -0
  5. package/dist/cjs/cache.js.map +1 -0
  6. package/dist/cjs/client.js +196 -0
  7. package/dist/cjs/client.js.map +1 -0
  8. package/dist/cjs/costs.js +104 -0
  9. package/dist/cjs/costs.js.map +1 -0
  10. package/dist/cjs/errors.js +287 -0
  11. package/dist/cjs/errors.js.map +1 -0
  12. package/dist/cjs/execution.js +385 -0
  13. package/dist/cjs/execution.js.map +1 -0
  14. package/dist/cjs/index.js +256 -0
  15. package/dist/cjs/index.js.map +1 -0
  16. package/dist/cjs/intents.js +185 -0
  17. package/dist/cjs/intents.js.map +1 -0
  18. package/dist/cjs/serialization.js +164 -0
  19. package/dist/cjs/serialization.js.map +1 -0
  20. package/dist/cjs/types.js +31 -0
  21. package/dist/cjs/types.js.map +1 -0
  22. package/dist/cjs/validation.js +114 -0
  23. package/dist/cjs/validation.js.map +1 -0
  24. package/dist/esm/agent.js +317 -0
  25. package/dist/esm/agent.js.map +1 -0
  26. package/dist/esm/cache.js +54 -0
  27. package/dist/esm/cache.js.map +1 -0
  28. package/dist/esm/client.js +192 -0
  29. package/dist/esm/client.js.map +1 -0
  30. package/dist/esm/costs.js +100 -0
  31. package/dist/esm/costs.js.map +1 -0
  32. package/dist/esm/errors.js +278 -0
  33. package/dist/esm/errors.js.map +1 -0
  34. package/dist/esm/execution.js +381 -0
  35. package/dist/esm/execution.js.map +1 -0
  36. package/dist/esm/index.js +236 -0
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/intents.js +181 -0
  39. package/dist/esm/intents.js.map +1 -0
  40. package/dist/esm/serialization.js +159 -0
  41. package/dist/esm/serialization.js.map +1 -0
  42. package/dist/esm/types.js +28 -0
  43. package/dist/esm/types.js.map +1 -0
  44. package/dist/esm/validation.js +111 -0
  45. package/dist/esm/validation.js.map +1 -0
  46. package/dist/types/agent.d.ts +171 -0
  47. package/dist/types/agent.d.ts.map +1 -0
  48. package/dist/types/cache.d.ts +25 -0
  49. package/dist/types/cache.d.ts.map +1 -0
  50. package/dist/types/client.d.ts +46 -0
  51. package/dist/types/client.d.ts.map +1 -0
  52. package/dist/types/costs.d.ts +91 -0
  53. package/dist/types/costs.d.ts.map +1 -0
  54. package/dist/types/errors.d.ts +242 -0
  55. package/dist/types/errors.d.ts.map +1 -0
  56. package/dist/types/execution.d.ts +145 -0
  57. package/dist/types/execution.d.ts.map +1 -0
  58. package/dist/types/index.d.ts +205 -0
  59. package/dist/types/index.d.ts.map +1 -0
  60. package/dist/types/intents.d.ts +158 -0
  61. package/dist/types/intents.d.ts.map +1 -0
  62. package/dist/types/serialization.d.ts +82 -0
  63. package/dist/types/serialization.d.ts.map +1 -0
  64. package/dist/types/types.d.ts +302 -0
  65. package/dist/types/types.d.ts.map +1 -0
  66. package/dist/types/validation.d.ts +40 -0
  67. package/dist/types/validation.d.ts.map +1 -0
  68. package/package.json +56 -0
package/README.md ADDED
@@ -0,0 +1,757 @@
1
+ # JACK TypeScript SDK
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@jack/sdk.svg)](https://www.npmjs.com/package/@jack/sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ TypeScript SDK for the JACK cross-chain execution kernel. Provides a comprehensive, type-safe interface for creating and managing cross-chain intents, tracking execution, and monitoring costs.
7
+
8
+ ## Features
9
+
10
+ - 🔒 **Type-Safe**: Full TypeScript support with comprehensive type definitions
11
+ - 🔄 **Automatic Retries**: Built-in exponential backoff for transient failures
12
+ - 💾 **Smart Caching**: Optional response caching to reduce API calls
13
+ - 📊 **Execution Tracking**: Real-time polling and event-based status updates
14
+ - 🚀 **Batch Operations**: Submit and track multiple intents efficiently
15
+ - 🛡️ **Error Handling**: Detailed error types with context for debugging
16
+ - 📦 **Dual Module Support**: Works with both ESM and CommonJS
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @jack/sdk
22
+ ```
23
+
24
+ Or with pnpm:
25
+
26
+ ```bash
27
+ pnpm add @jack/sdk
28
+ ```
29
+
30
+ ### Peer Dependencies
31
+
32
+ The SDK requires `viem` for EIP-712 signing:
33
+
34
+ ```bash
35
+ npm install viem
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### Basic Usage
41
+
42
+ ```typescript
43
+ import { JACK_SDK } from '@jack/sdk';
44
+
45
+ // Initialize the SDK
46
+ const sdk = new JACK_SDK({
47
+ baseUrl: 'https://api.jack.example'
48
+ });
49
+
50
+ // Create intent parameters
51
+ const params = {
52
+ sourceChain: 'arbitrum',
53
+ destinationChain: 'base',
54
+ tokenIn: '0xUSDC...',
55
+ tokenOut: '0xWETH...',
56
+ amountIn: '1000000', // 1 USDC (6 decimals)
57
+ minAmountOut: '42000000000000000', // 0.042 WETH (18 decimals)
58
+ deadline: Date.now() + 3600000 // 1 hour from now
59
+ };
60
+
61
+ // Get EIP-712 typed data for signing
62
+ const typedData = sdk.intents.getTypedData(params);
63
+
64
+ // Sign with your wallet (using viem, ethers, or any EIP-712 compatible wallet)
65
+ const signature = await wallet.signTypedData(typedData);
66
+
67
+ // Submit the signed intent
68
+ const intentId = await sdk.submitIntent(params, signature);
69
+ console.log('Intent submitted:', intentId); // "JK-ABC123456"
70
+
71
+ // Wait for settlement
72
+ const intent = await sdk.waitForSettlement(intentId);
73
+ console.log('Settlement tx:', intent.settlementTx);
74
+ ```
75
+
76
+ ### Track Execution Progress
77
+
78
+ ```typescript
79
+ import { ExecutionStatus } from '@jack/sdk';
80
+
81
+ // Poll until specific status is reached
82
+ const intent = await sdk.execution.waitForStatus(
83
+ intentId,
84
+ ExecutionStatus.SETTLED,
85
+ {
86
+ interval: 3000, // Poll every 3 seconds
87
+ timeout: 120000 // Timeout after 2 minutes
88
+ }
89
+ );
90
+
91
+ // Watch for real-time updates
92
+ const watcher = sdk.execution.watch(intentId, { interval: 2000 });
93
+
94
+ watcher.onUpdate((intent) => {
95
+ console.log('Status updated:', intent.status);
96
+ console.log('Execution steps:', intent.executionSteps);
97
+ });
98
+
99
+ watcher.onComplete((intent) => {
100
+ console.log('Intent completed!');
101
+ console.log('Settlement tx:', intent.settlementTx);
102
+ watcher.stop();
103
+ });
104
+
105
+ watcher.onError((error) => {
106
+ console.error('Polling error:', error);
107
+ });
108
+ ```
109
+
110
+ ## Configuration
111
+
112
+ ### ClientConfig Options
113
+
114
+ The SDK accepts the following configuration options:
115
+
116
+ ```typescript
117
+ interface ClientConfig {
118
+ /** Base URL for the JACK API (required) */
119
+ baseUrl: string;
120
+
121
+ /** Request timeout in milliseconds (default: 30000) */
122
+ timeout?: number;
123
+
124
+ /** Maximum number of retry attempts (default: 3) */
125
+ maxRetries?: number;
126
+
127
+ /** Initial delay between retries in milliseconds (default: 1000) */
128
+ retryDelay?: number;
129
+
130
+ /** Backoff multiplier for exponential retry (default: 2) */
131
+ retryBackoff?: number;
132
+
133
+ /** Enable response caching for GET requests (default: true) */
134
+ enableCache?: boolean;
135
+
136
+ /** Cache time-to-live in milliseconds (default: 60000) */
137
+ cacheTTL?: number;
138
+
139
+ /** Custom HTTP headers for all requests */
140
+ headers?: Record<string, string>;
141
+ }
142
+ ```
143
+
144
+ ### Example Configurations
145
+
146
+ **Production with authentication:**
147
+
148
+ ```typescript
149
+ const sdk = new JACK_SDK({
150
+ baseUrl: 'https://api.jack.example',
151
+ timeout: 60000,
152
+ maxRetries: 5,
153
+ headers: {
154
+ 'Authorization': 'Bearer your-api-token',
155
+ 'X-Client-Version': '1.0.0'
156
+ }
157
+ });
158
+ ```
159
+
160
+ **Development with aggressive caching:**
161
+
162
+ ```typescript
163
+ const sdk = new JACK_SDK({
164
+ baseUrl: 'http://localhost:3000',
165
+ enableCache: true,
166
+ cacheTTL: 300000, // 5 minutes
167
+ maxRetries: 1
168
+ });
169
+ ```
170
+
171
+ **High-reliability configuration:**
172
+
173
+ ```typescript
174
+ const sdk = new JACK_SDK({
175
+ baseUrl: 'https://api.jack.example',
176
+ timeout: 90000,
177
+ maxRetries: 10,
178
+ retryDelay: 2000,
179
+ retryBackoff: 1.5,
180
+ enableCache: false // Always fetch fresh data
181
+ });
182
+ ```
183
+
184
+ ## Error Handling
185
+
186
+ The SDK provides detailed error types for different failure scenarios:
187
+
188
+ ### Error Types
189
+
190
+ ```typescript
191
+ import {
192
+ JackError, // Base error class
193
+ APIError, // API returned an error response
194
+ NetworkError, // Network-level failure
195
+ ValidationError,// Client-side validation failed
196
+ TimeoutError, // Operation timed out
197
+ RetryError // All retry attempts exhausted
198
+ } from '@jack/sdk';
199
+ ```
200
+
201
+ ### Handling Errors
202
+
203
+ ```typescript
204
+ try {
205
+ const intentId = await sdk.submitIntent(params, signature);
206
+ } catch (error) {
207
+ if (error instanceof ValidationError) {
208
+ // Client-side validation failed
209
+ console.error('Invalid parameters:', error.errors);
210
+ // error.errors is an array of specific validation messages
211
+
212
+ } else if (error instanceof APIError) {
213
+ // API returned an error
214
+ console.error('API error:', error.message);
215
+ console.error('Status code:', error.statusCode);
216
+ console.error('Response:', error.response);
217
+
218
+ if (error.statusCode === 404) {
219
+ console.log('Intent not found');
220
+ } else if (error.isServerError()) {
221
+ console.log('Server error - may be retried');
222
+ }
223
+
224
+ } else if (error instanceof NetworkError) {
225
+ // Network failure (connection, DNS, etc.)
226
+ console.error('Network error:', error.message);
227
+ console.error('Original error:', error.originalError);
228
+
229
+ } else if (error instanceof TimeoutError) {
230
+ // Operation timed out
231
+ console.error('Timeout after', error.timeoutMs, 'ms');
232
+
233
+ } else if (error instanceof RetryError) {
234
+ // All retries exhausted
235
+ console.error('Failed after', error.attempts, 'attempts');
236
+ console.error('Last error:', error.lastError);
237
+ }
238
+ }
239
+ ```
240
+
241
+ ### Validation Before Submission
242
+
243
+ Validate parameters before making network requests:
244
+
245
+ ```typescript
246
+ // Validate parameters
247
+ const validation = sdk.intents.validate(params);
248
+
249
+ if (!validation.valid) {
250
+ console.error('Validation errors:', validation.errors);
251
+ // Handle validation errors without making API call
252
+ return;
253
+ }
254
+
255
+ // Proceed with submission
256
+ const intentId = await sdk.submitIntent(params, signature);
257
+ ```
258
+
259
+ ## Advanced Usage
260
+
261
+ ### Batch Operations
262
+
263
+ Submit multiple intents in parallel:
264
+
265
+ ```typescript
266
+ const intents = [
267
+ { params: intent1Params, signature: sig1 },
268
+ { params: intent2Params, signature: sig2 },
269
+ { params: intent3Params, signature: sig3 }
270
+ ];
271
+
272
+ const results = await sdk.agent.batchSubmit(intents);
273
+
274
+ // Check results
275
+ results.forEach((result, index) => {
276
+ if (result.success) {
277
+ console.log(`Intent ${index} submitted: ${result.intentId}`);
278
+ } else {
279
+ console.error(`Intent ${index} failed:`, result.error?.message);
280
+ }
281
+ });
282
+
283
+ // Count successes and failures
284
+ const successes = results.filter(r => r.success).length;
285
+ const failures = results.filter(r => !r.success).length;
286
+ console.log(`${successes} succeeded, ${failures} failed`);
287
+ ```
288
+
289
+ ### Multi-Intent Subscriptions
290
+
291
+ Monitor multiple intents simultaneously:
292
+
293
+ ```typescript
294
+ const intentIds = ['JK-ABC123456', 'JK-DEF789012', 'JK-GHI345678'];
295
+
296
+ const subscription = sdk.agent.subscribeToUpdates(
297
+ intentIds,
298
+ (intentId, intent) => {
299
+ console.log(`${intentId} status: ${intent.status}`);
300
+ },
301
+ { interval: 5000 }
302
+ );
303
+
304
+ // Later, stop monitoring
305
+ subscription.unsubscribe();
306
+ ```
307
+
308
+ ### Policy Validation
309
+
310
+ Enforce custom policies on intent parameters:
311
+
312
+ ```typescript
313
+ import { Policy } from '@jack/sdk';
314
+
315
+ const policy: Policy = {
316
+ maxAmountIn: '1000000000', // Max 1000 USDC
317
+ allowedSourceChains: ['arbitrum', 'optimism'],
318
+ allowedDestinationChains: ['base', 'ethereum'],
319
+ allowedTokensIn: ['0xUSDC...', '0xUSDT...'],
320
+ maxDeadlineOffset: 3600000 // Max 1 hour
321
+ };
322
+
323
+ const result = sdk.agent.validatePolicy(params, policy);
324
+
325
+ if (!result.valid) {
326
+ console.error('Policy violations:', result.errors);
327
+ return;
328
+ }
329
+
330
+ // Proceed with submission
331
+ const intentId = await sdk.submitIntent(params, signature);
332
+ ```
333
+
334
+ ### Dry Run Validation
335
+
336
+ Test intent parameters without submission:
337
+
338
+ ```typescript
339
+ const dryRunResult = await sdk.agent.dryRun(params);
340
+
341
+ if (dryRunResult.valid) {
342
+ console.log('Parameters are valid');
343
+ if (dryRunResult.estimatedCost) {
344
+ console.log('Estimated cost:', dryRunResult.estimatedCost);
345
+ }
346
+ } else {
347
+ console.error('Validation errors:', dryRunResult.errors);
348
+ }
349
+ ```
350
+
351
+ ### Cost Tracking
352
+
353
+ Monitor execution costs and budgets:
354
+
355
+ ```typescript
356
+ // Get all issue costs
357
+ const costs = await sdk.costs.getCosts();
358
+
359
+ costs.issueCosts.forEach(issueCost => {
360
+ console.log(`Issue ${issueCost.issueId}:`);
361
+ console.log(` Total cost: ${issueCost.totalCost}`);
362
+ console.log(` Budget: ${issueCost.budget}`);
363
+ console.log(` Over budget: ${issueCost.overBudget}`);
364
+ });
365
+
366
+ // Get costs for specific issue
367
+ const issueCost = await sdk.costs.getIssueCost('ISSUE-123');
368
+ if (issueCost) {
369
+ console.log('Total cost:', issueCost.totalCost);
370
+ }
371
+
372
+ // Get all over-budget issues
373
+ const overBudget = await sdk.costs.getOverBudgetIssues();
374
+ console.log(`${overBudget.length} issues are over budget`);
375
+ ```
376
+
377
+ ### Cache Management
378
+
379
+ Control response caching:
380
+
381
+ ```typescript
382
+ // Clear all cached responses
383
+ sdk.client.clearCache();
384
+
385
+ // Clear cache entries matching a pattern
386
+ sdk.client.clearCache('/api/intents');
387
+
388
+ // Disable cache for specific request
389
+ const intent = await sdk.intents.get(intentId, { skipCache: true });
390
+ ```
391
+
392
+ ### Custom Request Options
393
+
394
+ Override default settings for individual requests:
395
+
396
+ ```typescript
397
+ // Longer timeout for specific request
398
+ const intent = await sdk.intents.get(intentId, {
399
+ timeout: 60000
400
+ });
401
+
402
+ // Disable retries for specific request
403
+ const intents = await sdk.intents.list({
404
+ noRetry: true
405
+ });
406
+
407
+ // Skip cache for specific request
408
+ const freshIntent = await sdk.intents.get(intentId, {
409
+ skipCache: true
410
+ });
411
+ ```
412
+
413
+ ## TypeScript Usage
414
+
415
+ ### Type Exports
416
+
417
+ The SDK exports all types for use in your application:
418
+
419
+ ```typescript
420
+ import type {
421
+ // Core Intent Types
422
+ IntentParams,
423
+ Intent,
424
+ ExecutionStatus,
425
+ ExecutionStep,
426
+
427
+ // Quote Types
428
+ Quote,
429
+ RouteStep,
430
+
431
+ // Cost Types
432
+ CostEntry,
433
+ IssueCost,
434
+ CostsResponse,
435
+
436
+ // Configuration Types
437
+ ClientConfig,
438
+ RequestOptions,
439
+ PollOptions,
440
+
441
+ // Result Types
442
+ BatchSubmitResult,
443
+ DryRunResult,
444
+ ValidationResult,
445
+
446
+ // EIP-712 Types
447
+ EIP712Domain,
448
+ TypedData,
449
+
450
+ // Subscription Types
451
+ Subscription,
452
+ ExecutionWatcher,
453
+
454
+ // Policy Types
455
+ Policy
456
+ } from '@jack/sdk';
457
+ ```
458
+
459
+ ### Type-Safe Intent Creation
460
+
461
+ ```typescript
462
+ import type { IntentParams } from '@jack/sdk';
463
+
464
+ function createIntent(
465
+ sourceChain: string,
466
+ destinationChain: string,
467
+ amountIn: string
468
+ ): IntentParams {
469
+ return {
470
+ sourceChain,
471
+ destinationChain,
472
+ tokenIn: '0xUSDC...',
473
+ tokenOut: '0xWETH...',
474
+ amountIn,
475
+ minAmountOut: calculateMinAmount(amountIn),
476
+ deadline: Date.now() + 3600000
477
+ };
478
+ }
479
+ ```
480
+
481
+ ### Type Guards
482
+
483
+ ```typescript
484
+ import { ExecutionStatus } from '@jack/sdk';
485
+
486
+ function isTerminalStatus(status: ExecutionStatus): boolean {
487
+ return [
488
+ ExecutionStatus.SETTLED,
489
+ ExecutionStatus.ABORTED,
490
+ ExecutionStatus.EXPIRED
491
+ ].includes(status);
492
+ }
493
+
494
+ function isSuccessful(status: ExecutionStatus): boolean {
495
+ return status === ExecutionStatus.SETTLED;
496
+ }
497
+ ```
498
+
499
+ ## API Reference
500
+
501
+ ### JACK_SDK
502
+
503
+ Main SDK class that provides access to all managers.
504
+
505
+ ```typescript
506
+ class JACK_SDK {
507
+ constructor(config: ClientConfig);
508
+
509
+ // Manager instances
510
+ readonly intents: IntentManager;
511
+ readonly execution: ExecutionTracker;
512
+ readonly costs: CostTracker;
513
+ readonly agent: AgentUtils;
514
+
515
+ // Convenience methods
516
+ submitIntent(params: IntentParams, signature: string): Promise<string>;
517
+ getIntent(intentId: string): Promise<Intent>;
518
+ listIntents(): Promise<Intent[]>;
519
+ waitForSettlement(intentId: string, timeout?: number): Promise<Intent>;
520
+ }
521
+ ```
522
+
523
+ ### IntentManager
524
+
525
+ Manages intent creation, validation, and submission.
526
+
527
+ ```typescript
528
+ class IntentManager {
529
+ // Get EIP-712 typed data for signing
530
+ getTypedData(params: IntentParams, chainId?: number, verifyingContract?: string): TypedData;
531
+
532
+ // Validate intent parameters
533
+ validate(params: IntentParams): ValidationResult;
534
+
535
+ // Submit signed intent
536
+ submit(params: IntentParams, signature: string): Promise<string>;
537
+
538
+ // Get single intent
539
+ get(intentId: string): Promise<Intent>;
540
+
541
+ // List all intents
542
+ list(): Promise<Intent[]>;
543
+ }
544
+ ```
545
+
546
+ ### ExecutionTracker
547
+
548
+ Tracks intent execution status and progress.
549
+
550
+ ```typescript
551
+ class ExecutionTracker {
552
+ // Get current status
553
+ getStatus(intentId: string): Promise<Intent>;
554
+
555
+ // Wait for specific status
556
+ waitForStatus(
557
+ intentId: string,
558
+ targetStatus: ExecutionStatus | ExecutionStatus[],
559
+ options?: PollOptions
560
+ ): Promise<Intent>;
561
+
562
+ // Watch for continuous updates
563
+ watch(intentId: string, options?: PollOptions): ExecutionWatcher;
564
+ }
565
+ ```
566
+
567
+ ### CostTracker
568
+
569
+ Monitors execution costs and budgets.
570
+
571
+ ```typescript
572
+ class CostTracker {
573
+ // Get all issue costs
574
+ getCosts(): Promise<CostsResponse>;
575
+
576
+ // Get costs for specific issue
577
+ getIssueCost(issueId: string): Promise<IssueCost | null>;
578
+
579
+ // Get over-budget issues
580
+ getOverBudgetIssues(): Promise<IssueCost[]>;
581
+ }
582
+ ```
583
+
584
+ ### AgentUtils
585
+
586
+ High-level utilities for automated systems.
587
+
588
+ ```typescript
589
+ class AgentUtils {
590
+ // Submit multiple intents in parallel
591
+ batchSubmit(
592
+ intents: Array<{ params: IntentParams; signature: string }>
593
+ ): Promise<BatchSubmitResult[]>;
594
+
595
+ // Validate without submission
596
+ dryRun(params: IntentParams): Promise<DryRunResult>;
597
+
598
+ // Validate against policy
599
+ validatePolicy(params: IntentParams, policy: Policy): ValidationResult;
600
+
601
+ // Subscribe to multiple intents
602
+ subscribeToUpdates(
603
+ intentIds: string[],
604
+ callback: (intentId: string, intent: Intent) => void,
605
+ options?: PollOptions
606
+ ): Subscription;
607
+ }
608
+ ```
609
+
610
+ ## Examples
611
+
612
+ ### Complete Intent Lifecycle
613
+
614
+ ```typescript
615
+ import { JACK_SDK, ExecutionStatus } from '@jack/sdk';
616
+
617
+ async function executeIntent() {
618
+ const sdk = new JACK_SDK({ baseUrl: 'https://api.jack.example' });
619
+
620
+ // 1. Create intent parameters
621
+ const params = {
622
+ sourceChain: 'arbitrum',
623
+ destinationChain: 'base',
624
+ tokenIn: '0xUSDC...',
625
+ tokenOut: '0xWETH...',
626
+ amountIn: '1000000',
627
+ minAmountOut: '42000000000000000',
628
+ deadline: Date.now() + 3600000
629
+ };
630
+
631
+ // 2. Validate parameters
632
+ const validation = sdk.intents.validate(params);
633
+ if (!validation.valid) {
634
+ throw new Error(`Validation failed: ${validation.errors.join(', ')}`);
635
+ }
636
+
637
+ // 3. Get typed data and sign
638
+ const typedData = sdk.intents.getTypedData(params);
639
+ const signature = await wallet.signTypedData(typedData);
640
+
641
+ // 4. Submit intent
642
+ const intentId = await sdk.submitIntent(params, signature);
643
+ console.log('Intent submitted:', intentId);
644
+
645
+ // 5. Track execution
646
+ const watcher = sdk.execution.watch(intentId);
647
+
648
+ watcher.onUpdate((intent) => {
649
+ console.log(`Status: ${intent.status}`);
650
+ intent.executionSteps.forEach(step => {
651
+ console.log(` ${step.step}: ${step.status}`);
652
+ });
653
+ });
654
+
655
+ watcher.onComplete((intent) => {
656
+ if (intent.status === ExecutionStatus.SETTLED) {
657
+ console.log('✅ Intent settled successfully!');
658
+ console.log('Settlement tx:', intent.settlementTx);
659
+ } else {
660
+ console.log('❌ Intent failed:', intent.status);
661
+ }
662
+ watcher.stop();
663
+ });
664
+
665
+ watcher.onError((error) => {
666
+ console.error('Tracking error:', error);
667
+ });
668
+ }
669
+ ```
670
+
671
+ ### Agent with Batch Processing
672
+
673
+ ```typescript
674
+ import { JACK_SDK } from '@jack/sdk';
675
+
676
+ async function processIntentBatch(intentRequests: IntentRequest[]) {
677
+ const sdk = new JACK_SDK({ baseUrl: 'https://api.jack.example' });
678
+
679
+ // Prepare intents with signatures
680
+ const intents = await Promise.all(
681
+ intentRequests.map(async (req) => ({
682
+ params: req.params,
683
+ signature: await wallet.signTypedData(
684
+ sdk.intents.getTypedData(req.params)
685
+ )
686
+ }))
687
+ );
688
+
689
+ // Submit batch
690
+ const results = await sdk.agent.batchSubmit(intents);
691
+
692
+ // Track all successful submissions
693
+ const successfulIds = results
694
+ .filter(r => r.success)
695
+ .map(r => r.intentId);
696
+
697
+ if (successfulIds.length > 0) {
698
+ const subscription = sdk.agent.subscribeToUpdates(
699
+ successfulIds,
700
+ (intentId, intent) => {
701
+ console.log(`${intentId}: ${intent.status}`);
702
+ }
703
+ );
704
+
705
+ // Unsubscribe after 5 minutes
706
+ setTimeout(() => subscription.unsubscribe(), 300000);
707
+ }
708
+
709
+ return results;
710
+ }
711
+ ```
712
+
713
+ ## Migration from Legacy SDK
714
+
715
+ If you're upgrading from an older version of the SDK:
716
+
717
+ ### Import Changes
718
+
719
+ ```typescript
720
+ // Old
721
+ import JACK_SDK from '@jack/sdk';
722
+
723
+ // New (both work)
724
+ import { JACK_SDK } from '@jack/sdk';
725
+ // or
726
+ import JACK_SDK from '@jack/sdk';
727
+ ```
728
+
729
+ ### Method Changes
730
+
731
+ ```typescript
732
+ // Old
733
+ const typedData = sdk.getIntentTypedData(params);
734
+ const intent = await sdk.getExecutionStatus(intentId);
735
+
736
+ // New (old methods still work but are deprecated)
737
+ const typedData = sdk.intents.getTypedData(params);
738
+ const intent = await sdk.execution.getStatus(intentId);
739
+ ```
740
+
741
+ ## Contributing
742
+
743
+ Contributions are welcome! Please see the [contribution guidelines](../../CONTRIBUTING.md) for details.
744
+
745
+ ## License
746
+
747
+ MIT © JACK Team
748
+
749
+ ## Support
750
+
751
+ - **Documentation**: [Full API Documentation](https://docs.jack.example)
752
+ - **Issues**: [GitHub Issues](https://github.com/your-org/jack/issues)
753
+ - **Discord**: [Join our community](https://discord.gg/jack)
754
+
755
+ ## Changelog
756
+
757
+ See [CHANGELOG.md](./CHANGELOG.md) for release history and migration guides.