@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
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Intent management for the JACK SDK
3
+ *
4
+ * This module provides the IntentManager class for creating, submitting,
5
+ * and querying intents through the JACK API.
6
+ *
7
+ * Requirements: 1.1, 1.2, 1.3, 1.4
8
+ */
9
+ import { getTypedData } from './serialization.js';
10
+ import { validateIntentParams } from './validation.js';
11
+ import { ValidationError } from './errors.js';
12
+ /**
13
+ * Manager for intent operations
14
+ *
15
+ * Provides methods to create EIP-712 typed data, validate parameters,
16
+ * submit signed intents, and query intent status.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const client = new JackClient({ baseUrl: 'https://api.jack.example' });
21
+ * const manager = new IntentManager(client);
22
+ *
23
+ * // Create typed data for signing
24
+ * const typedData = manager.getTypedData(params);
25
+ * const signature = await wallet.signTypedData(typedData);
26
+ *
27
+ * // Submit the signed intent
28
+ * const intentId = await manager.submit(params, signature);
29
+ *
30
+ * // Query the intent
31
+ * const intent = await manager.get(intentId);
32
+ * ```
33
+ */
34
+ export class IntentManager {
35
+ client;
36
+ /**
37
+ * Creates a new IntentManager
38
+ *
39
+ * @param client - The JackClient instance to use for API requests
40
+ */
41
+ constructor(client) {
42
+ this.client = client;
43
+ }
44
+ /**
45
+ * Get EIP-712 typed data for intent signing
46
+ *
47
+ * Constructs properly formatted EIP-712 TypedData that can be signed
48
+ * by a wallet. This method delegates to the serialization module.
49
+ *
50
+ * @param params - Intent parameters to serialize
51
+ * @param chainId - Chain ID for the domain separator (default: 1)
52
+ * @param verifyingContract - Address of the verifying contract
53
+ * @returns EIP-712 TypedData object ready for signing
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const typedData = manager.getTypedData({
58
+ * sourceChain: 'arbitrum',
59
+ * destinationChain: 'base',
60
+ * tokenIn: '0xUSDC...',
61
+ * tokenOut: '0xWETH...',
62
+ * amountIn: '1000000',
63
+ * minAmountOut: '42000000000000000',
64
+ * deadline: Date.now() + 3600000
65
+ * });
66
+ *
67
+ * const signature = await wallet.signTypedData(typedData);
68
+ * ```
69
+ *
70
+ * **Validates: Requirement 1.1**
71
+ */
72
+ getTypedData(params, chainId = 1, verifyingContract = '0x0000000000000000000000000000000000000000') {
73
+ return getTypedData(params, chainId, verifyingContract);
74
+ }
75
+ /**
76
+ * Validate intent parameters
77
+ *
78
+ * Checks that all required fields are present, amounts are positive,
79
+ * deadline is in the future, and addresses are valid format.
80
+ * This method delegates to the validation module.
81
+ *
82
+ * @param params - Intent parameters to validate
83
+ * @returns ValidationResult with valid flag and error messages
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const result = manager.validate(params);
88
+ * if (!result.valid) {
89
+ * console.error('Validation errors:', result.errors);
90
+ * }
91
+ * ```
92
+ *
93
+ * **Validates: Requirement 5.4**
94
+ */
95
+ validate(params) {
96
+ return validateIntentParams(params);
97
+ }
98
+ /**
99
+ * Submit a signed intent to the JACK API
100
+ *
101
+ * Validates the intent parameters before submission. If validation fails,
102
+ * throws a ValidationError without making any network request. On success,
103
+ * returns the intent ID.
104
+ *
105
+ * @param params - Intent parameters
106
+ * @param signature - EIP-712 signature from the user's wallet
107
+ * @returns Promise resolving to the intent ID (format: JK-[A-Z0-9]{9})
108
+ * @throws ValidationError if parameters are invalid
109
+ * @throws APIError if the API returns an error
110
+ * @throws NetworkError if the network request fails
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const intentId = await manager.submit(params, signature);
115
+ * console.log('Intent submitted:', intentId); // "JK-ABC123456"
116
+ * ```
117
+ *
118
+ * **Validates: Requirement 1.2**
119
+ */
120
+ async submit(params, signature) {
121
+ // Validate parameters before making network request
122
+ const validation = this.validate(params);
123
+ if (!validation.valid) {
124
+ throw new ValidationError('Invalid intent parameters', validation.errors);
125
+ }
126
+ // Submit to API
127
+ const response = await this.client.post('/api/intents', {
128
+ params,
129
+ signature
130
+ });
131
+ return response.intentId;
132
+ }
133
+ /**
134
+ * Get a single intent by ID
135
+ *
136
+ * Queries the JACK API for the complete intent object including
137
+ * current status, execution steps, and settlement transaction (if settled).
138
+ *
139
+ * @param intentId - The intent ID to query (format: JK-[A-Z0-9]{9})
140
+ * @returns Promise resolving to the complete Intent object
141
+ * @throws APIError if the intent is not found (404) or other API error
142
+ * @throws NetworkError if the network request fails
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const intent = await manager.get('JK-ABC123456');
147
+ * console.log('Status:', intent.status);
148
+ * console.log('Settlement tx:', intent.settlementTx);
149
+ * ```
150
+ *
151
+ * **Validates: Requirement 1.3**
152
+ */
153
+ async get(intentId) {
154
+ return this.client.get(`/api/intents/${intentId}`);
155
+ }
156
+ /**
157
+ * List all intents
158
+ *
159
+ * Queries the JACK API for all intents. The API may implement pagination
160
+ * or filtering in the future, but currently returns all intents.
161
+ *
162
+ * @returns Promise resolving to an array of Intent objects
163
+ * @throws APIError if the API returns an error
164
+ * @throws NetworkError if the network request fails
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * const intents = await manager.list();
169
+ * console.log(`Found ${intents.length} intents`);
170
+ * intents.forEach(intent => {
171
+ * console.log(`${intent.id}: ${intent.status}`);
172
+ * });
173
+ * ```
174
+ *
175
+ * **Validates: Requirement 1.4**
176
+ */
177
+ async list() {
178
+ return this.client.get('/api/intents');
179
+ }
180
+ }
181
+ //# sourceMappingURL=intents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intents.js","sourceRoot":"","sources":["../../src/intents.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,aAAa;IACP,MAAM,CAAa;IAEpC;;;;OAIG;IACH,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YAAY,CACV,MAAoB,EACpB,UAAkB,CAAC,EACnB,oBAAmC,4CAA4C;QAE/E,OAAO,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,CAAC,MAAoB;QAC3B,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,MAAM,CAAC,MAAoB,EAAE,SAAiB;QAClD,oDAAoD;QACpD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACtB,MAAM,IAAI,eAAe,CACvB,2BAA2B,EAC3B,UAAU,CAAC,MAAM,CAClB,CAAC;QACJ,CAAC;QAED,gBAAgB;QAChB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACrC,cAAc,EACd;YACE,MAAM;YACN,SAAS;SACV,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,GAAG,CAAC,QAAgB;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAS,gBAAgB,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAW,cAAc,CAAC,CAAC;IACnD,CAAC;CACF"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * EIP-712 serialization for JACK intents
3
+ *
4
+ * This module provides functions to construct EIP-712 typed data for intent signing.
5
+ * The typed data follows the EIP-712 standard for structured data hashing and signing.
6
+ *
7
+ * Requirements: 1.1, 14.1
8
+ */
9
+ /**
10
+ * Get EIP-712 typed data for an intent
11
+ *
12
+ * Constructs a properly formatted EIP-712 TypedData object that can be used
13
+ * with wallet signing methods (e.g., eth_signTypedData_v4). The typed data
14
+ * includes the domain separator, type definitions, and the intent message.
15
+ *
16
+ * @param params - Intent parameters to serialize
17
+ * @param chainId - Chain ID for the domain separator (default: 1 for Ethereum mainnet)
18
+ * @param verifyingContract - Address of the verifying contract
19
+ * @returns EIP-712 TypedData object ready for signing
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const params = {
24
+ * sourceChain: 'arbitrum',
25
+ * destinationChain: 'base',
26
+ * tokenIn: '0xUSDC...',
27
+ * tokenOut: '0xWETH...',
28
+ * amountIn: '1000000',
29
+ * minAmountOut: '42000000000000000',
30
+ * deadline: Date.now() + 3600000
31
+ * };
32
+ *
33
+ * const typedData = getTypedData(
34
+ * params,
35
+ * 1,
36
+ * '0x1234567890123456789012345678901234567890'
37
+ * );
38
+ *
39
+ * // Sign with wallet
40
+ * const signature = await wallet.signTypedData(typedData);
41
+ * ```
42
+ *
43
+ * Validates: Requirements 1.1, 14.1
44
+ */
45
+ export function getTypedData(params, chainId = 1, verifyingContract = '0x0000000000000000000000000000000000000000') {
46
+ // Define the EIP-712 domain
47
+ const domain = {
48
+ name: 'JACK',
49
+ version: '1',
50
+ chainId,
51
+ verifyingContract,
52
+ };
53
+ // Define the Intent type structure
54
+ // This must match the on-chain struct definition
55
+ const types = {
56
+ Intent: [
57
+ { name: 'sourceChain', type: 'string' },
58
+ { name: 'destinationChain', type: 'string' },
59
+ { name: 'tokenIn', type: 'string' },
60
+ { name: 'tokenOut', type: 'string' },
61
+ { name: 'amountIn', type: 'string' },
62
+ { name: 'minAmountOut', type: 'string' },
63
+ { name: 'deadline', type: 'uint256' },
64
+ ],
65
+ };
66
+ // Construct the message from intent parameters
67
+ // Only include the fields defined in the Intent type
68
+ const message = {
69
+ sourceChain: params.sourceChain,
70
+ destinationChain: params.destinationChain,
71
+ tokenIn: params.tokenIn,
72
+ tokenOut: params.tokenOut,
73
+ amountIn: params.amountIn,
74
+ minAmountOut: params.minAmountOut,
75
+ deadline: params.deadline,
76
+ };
77
+ // Return the complete TypedData structure
78
+ return {
79
+ domain,
80
+ types,
81
+ message,
82
+ primaryType: 'Intent',
83
+ };
84
+ }
85
+ /**
86
+ * Serialize intent parameters to a consistent string representation
87
+ *
88
+ * This function is useful for generating cache keys, logging, or debugging.
89
+ * It produces a deterministic string representation of the intent parameters.
90
+ *
91
+ * @param params - Intent parameters to serialize
92
+ * @returns JSON string representation of the parameters
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const params = { sourceChain: 'arbitrum', ... };
97
+ * const serialized = serializeIntentParams(params);
98
+ * console.log(serialized); // {"sourceChain":"arbitrum",...}
99
+ * ```
100
+ */
101
+ export function serializeIntentParams(params) {
102
+ // Create a clean object with only the core intent fields
103
+ const cleanParams = {
104
+ sourceChain: params.sourceChain,
105
+ destinationChain: params.destinationChain,
106
+ tokenIn: params.tokenIn,
107
+ tokenOut: params.tokenOut,
108
+ amountIn: params.amountIn,
109
+ minAmountOut: params.minAmountOut,
110
+ deadline: params.deadline,
111
+ };
112
+ // Return deterministic JSON string (sorted keys)
113
+ return JSON.stringify(cleanParams, Object.keys(cleanParams).sort());
114
+ }
115
+ /**
116
+ * Parse a serialized intent parameters string back to IntentParams
117
+ *
118
+ * This is the inverse of serializeIntentParams(). It parses a JSON string
119
+ * back into an IntentParams object.
120
+ *
121
+ * @param serialized - JSON string representation of intent parameters
122
+ * @returns Parsed IntentParams object
123
+ * @throws Error if the string cannot be parsed or is missing required fields
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const serialized = '{"sourceChain":"arbitrum",...}';
128
+ * const params = parseIntentParams(serialized);
129
+ * console.log(params.sourceChain); // 'arbitrum'
130
+ * ```
131
+ */
132
+ export function parseIntentParams(serialized) {
133
+ try {
134
+ const parsed = JSON.parse(serialized);
135
+ // Validate required fields are present
136
+ const requiredFields = [
137
+ 'sourceChain',
138
+ 'destinationChain',
139
+ 'tokenIn',
140
+ 'tokenOut',
141
+ 'amountIn',
142
+ 'minAmountOut',
143
+ 'deadline',
144
+ ];
145
+ for (const field of requiredFields) {
146
+ if (!(field in parsed)) {
147
+ throw new Error(`Missing required field: ${field}`);
148
+ }
149
+ }
150
+ return parsed;
151
+ }
152
+ catch (error) {
153
+ if (error instanceof Error) {
154
+ throw new Error(`Failed to parse intent parameters: ${error.message}`);
155
+ }
156
+ throw new Error('Failed to parse intent parameters: Unknown error');
157
+ }
158
+ }
159
+ //# sourceMappingURL=serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../src/serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;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AAC;AACH,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Core TypeScript types for the JACK SDK
3
+ *
4
+ * This module exports all interfaces, types, and enums used in the public API.
5
+ * Requirements: 1.5, 3.4, 4.3, 5.1
6
+ */
7
+ /**
8
+ * Execution status of an intent
9
+ * Requirement 1.5
10
+ */
11
+ export var ExecutionStatus;
12
+ (function (ExecutionStatus) {
13
+ /** Intent created but not yet quoted */
14
+ ExecutionStatus["CREATED"] = "CREATED";
15
+ /** Solver quotes received */
16
+ ExecutionStatus["QUOTED"] = "QUOTED";
17
+ /** Intent is being executed */
18
+ ExecutionStatus["EXECUTING"] = "EXECUTING";
19
+ /** Settlement transaction is being processed */
20
+ ExecutionStatus["SETTLING"] = "SETTLING";
21
+ /** Intent successfully settled on-chain */
22
+ ExecutionStatus["SETTLED"] = "SETTLED";
23
+ /** Intent execution was aborted */
24
+ ExecutionStatus["ABORTED"] = "ABORTED";
25
+ /** Intent expired before completion */
26
+ ExecutionStatus["EXPIRED"] = "EXPIRED";
27
+ })(ExecutionStatus || (ExecutionStatus = {}));
28
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH;;;GAGG;AACH,MAAM,CAAN,IAAY,eAeX;AAfD,WAAY,eAAe;IACzB,wCAAwC;IACxC,sCAAmB,CAAA;IACnB,6BAA6B;IAC7B,oCAAiB,CAAA;IACjB,+BAA+B;IAC/B,0CAAuB,CAAA;IACvB,gDAAgD;IAChD,wCAAqB,CAAA;IACrB,2CAA2C;IAC3C,sCAAmB,CAAA;IACnB,mCAAmC;IACnC,sCAAmB,CAAA;IACnB,uCAAuC;IACvC,sCAAmB,CAAA;AACrB,CAAC,EAfW,eAAe,KAAf,eAAe,QAe1B"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Input validation helpers for the JACK SDK
3
+ *
4
+ * This module provides validation functions for intent parameters and other inputs.
5
+ * Requirements: 5.4, 8.5
6
+ */
7
+ /**
8
+ * Validates that a string is a valid Ethereum address format
9
+ * @param address - The address string to validate
10
+ * @returns true if the address is valid, false otherwise
11
+ */
12
+ function isValidAddress(address) {
13
+ // Check if it's a valid hex string starting with 0x and has 40 hex characters
14
+ return /^0x[a-fA-F0-9]{40}$/.test(address);
15
+ }
16
+ /**
17
+ * Validates that a string represents a positive number
18
+ * @param value - The string value to validate
19
+ * @returns true if the value is a positive number, false otherwise
20
+ */
21
+ function isPositiveAmount(value) {
22
+ try {
23
+ const num = BigInt(value);
24
+ return num > 0n;
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ }
30
+ /**
31
+ * Validates intent parameters before submission
32
+ *
33
+ * This function checks:
34
+ * - All required fields are present and non-empty
35
+ * - Amounts (amountIn, minAmountOut) are positive numbers
36
+ * - Deadline is in the future
37
+ * - Token addresses are valid Ethereum address format
38
+ *
39
+ * @param params - The intent parameters to validate
40
+ * @returns ValidationResult with valid flag and array of error messages
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const result = validateIntentParams({
45
+ * sourceChain: 'arbitrum',
46
+ * destinationChain: 'base',
47
+ * tokenIn: '0x...',
48
+ * tokenOut: '0x...',
49
+ * amountIn: '1000000',
50
+ * minAmountOut: '950000',
51
+ * deadline: Date.now() + 3600000
52
+ * });
53
+ *
54
+ * if (!result.valid) {
55
+ * console.error('Validation errors:', result.errors);
56
+ * }
57
+ * ```
58
+ *
59
+ * **Validates: Requirements 5.4, 8.5**
60
+ */
61
+ export function validateIntentParams(params) {
62
+ const errors = [];
63
+ // Validate required fields are present and non-empty
64
+ if (!params.sourceChain || params.sourceChain.trim() === '') {
65
+ errors.push('sourceChain is required and must not be empty');
66
+ }
67
+ if (!params.destinationChain || params.destinationChain.trim() === '') {
68
+ errors.push('destinationChain is required and must not be empty');
69
+ }
70
+ if (!params.tokenIn || params.tokenIn.trim() === '') {
71
+ errors.push('tokenIn is required and must not be empty');
72
+ }
73
+ if (!params.tokenOut || params.tokenOut.trim() === '') {
74
+ errors.push('tokenOut is required and must not be empty');
75
+ }
76
+ if (!params.amountIn || params.amountIn.trim() === '') {
77
+ errors.push('amountIn is required and must not be empty');
78
+ }
79
+ if (!params.minAmountOut || params.minAmountOut.trim() === '') {
80
+ errors.push('minAmountOut is required and must not be empty');
81
+ }
82
+ if (params.deadline === undefined || params.deadline === null) {
83
+ errors.push('deadline is required');
84
+ }
85
+ // Validate amounts are positive
86
+ if (params.amountIn && !isPositiveAmount(params.amountIn)) {
87
+ errors.push('amountIn must be a positive number');
88
+ }
89
+ if (params.minAmountOut && !isPositiveAmount(params.minAmountOut)) {
90
+ errors.push('minAmountOut must be a positive number');
91
+ }
92
+ // Validate deadline is in the future
93
+ if (typeof params.deadline === 'number') {
94
+ const now = Date.now();
95
+ if (params.deadline <= now) {
96
+ errors.push('deadline must be in the future');
97
+ }
98
+ }
99
+ // Validate addresses are valid format
100
+ if (params.tokenIn && !isValidAddress(params.tokenIn)) {
101
+ errors.push('tokenIn must be a valid Ethereum address (0x followed by 40 hex characters)');
102
+ }
103
+ if (params.tokenOut && !isValidAddress(params.tokenOut)) {
104
+ errors.push('tokenOut must be a valid Ethereum address (0x followed by 40 hex characters)');
105
+ }
106
+ return {
107
+ valid: errors.length === 0,
108
+ errors
109
+ };
110
+ }
111
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;GAIG;AACH,SAAS,cAAc,CAAC,OAAe;IACrC,8EAA8E;IAC9E,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,KAAa;IACrC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,GAAG,GAAG,EAAE,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ractions
5
+ * for batch operations, dry-run validation, policy enforcement, and
6
+ * event subscriptions for automated agent systems.
7
+ *
8
+ * Requirements: 8.1, 8.2, 8.3, 8.4, 8.5
9
+ */
10
+ import type { IntentParams, Intent, BatchSubmitResult, DryRunResult, ValidationResult, Policy, Subscription, PollOptions } from './types.js';
11
+ import type { JackClient } from './client.js';
12
+ /**
13
+ * Utilities for agent-based intent orchestration
14
+ *
15
+ * Provides batch operations, dry-run validation, policy enforcement,
16
+ * and multi-intent subscriptions for automated systems.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const client = new JackClient({ baseUrl: 'https://api.jack.example' });
21
+ * const agent = new AgentUtils(client);
22
+ *
23
+ * // Batch submit multiple intents
24
+ * const results = await agent.batchSubmit([
25
+ * { params: intent1, signature: sig1 },
26
+ * { params: intent2, signature: sig2 }
27
+ * ]);
28
+ *
29
+ * results.forEach(result => {
30
+ * if (result.success) {
31
+ * console.log('Submitted:', result.intentId);
32
+ * } else {
33
+ * console.error('Failed:', result.error);
34
+ * }
35
+ * });
36
+ * ```
37
+ */
38
+ export declare class AgentUtils {
39
+ private readonly client;
40
+ private readonly intentManager;
41
+ private readonly executionTracker;
42
+ /**
43
+ * Creates a new AgentUtils instance
44
+ *
45
+ * @param client - The JackClient instance to use for API requests
46
+ */
47
+ constructor(client: JackClient);
48
+ /**
49
+ * Submit multiple intents in parallel
50
+ *
51
+ * Uses Promise.allSettled() to submit all intents concurrently,
52
+ * ensuring that failures in individual submissions don't affect others.
53
+ * The result array length always matches the input array length,
54
+ * with each result corresponding to the same index in the input.
55
+ *
56
+ * @param intents - Array of intent parameters and signatures to submit
57
+ * @returns Promise resolving to array of BatchSubmitResult objects
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const results = await agent.batchSubmit([
62
+ * { params: intent1, signature: sig1 },
63
+ * { params: intent2, signature: sig2 },
64
+ * { params: intent3, signature: sig3 }
65
+ * ]);
66
+ *
67
+ * // Results array has same length as input
68
+ * console.log(results.length); // 3
69
+ *
70
+ * // Check individual results
71
+ * results.forEach((result, index) => {
72
+ * if (result.success) {
73
+ * console.log(`Intent ${index} submitted: ${result.intentId}`);
74
+ * } else {
75
+ * console.error(`Intent ${index} failed:`, result.error?.message);
76
+ * }
77
+ * });
78
+ *
79
+ * // Count successes and failures
80
+ * const successes = results.filter(r => r.success).length;
81
+ * const failures = results.filter(r => !r.success).length;
82
+ * console.log(`${successes} succeeded, ${failures} failed`);
83
+ * ```
84
+ *
85
+ * **Validates: Requirements 8.1, 8.2**
86
+ */
87
+ batchSubmit(intents: Array<{
88
+ params: IntentParams;
89
+ signature: string;
90
+ }>): Promise<BatchSubmitResult[]>;
91
+ /**
92
+ * Simulate intent execution without submission
93
+ *
94
+ * Validates intent parameters and estimates costs without actually
95
+ * submitting the intent to the API. Useful for testing and validation.
96
+ *
97
+ * @param params - Intent parameters to validate
98
+ * @returns Promise resolving to DryRunResult with validation status
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const result = await agent.dryRun(params);
103
+ * if (result.valid) {
104
+ * console.log('Estimated cost:', result.estimatedCost);
105
+ * } else {
106
+ * console.error('Validation errors:', result.errors);
107
+ * }
108
+ * ```
109
+ *
110
+ * **Validates: Requirement 8.4**
111
+ */
112
+ dryRun(params: IntentParams): Promise<DryRunResult>;
113
+ /**
114
+ * Validate intent parameters against policy rules
115
+ *
116
+ * Checks that intent parameters comply with the specified policy,
117
+ * including amount limits, allowed chains, tokens, and deadline constraints.
118
+ *
119
+ * @param params - Intent parameters to validate
120
+ * @param policy - Policy rules to enforce
121
+ * @returns ValidationResult with valid flag and error messages
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const policy: Policy = {
126
+ * maxAmountIn: '1000000000',
127
+ * allowedSourceChains: ['arbitrum', 'optimism'],
128
+ * allowedDestinationChains: ['base', 'ethereum'],
129
+ * maxDeadlineOffset: 3600000 // 1 hour
130
+ * };
131
+ *
132
+ * const result = agent.validatePolicy(params, policy);
133
+ * if (!result.valid) {
134
+ * console.error('Policy violations:', result.errors);
135
+ * }
136
+ * ```
137
+ *
138
+ * **Validates: Requirement 8.5**
139
+ */
140
+ validatePolicy(params: IntentParams, policy: Policy): ValidationResult;
141
+ /**
142
+ * Subscribe to status changes for multiple intents
143
+ *
144
+ * Polls multiple intents in parallel and invokes the callback whenever
145
+ * any intent's status changes. Returns a Subscription object that can
146
+ * be used to unsubscribe and stop polling.
147
+ *
148
+ * @param intentIds - Array of intent IDs to monitor
149
+ * @param callback - Function to call when any intent status changes
150
+ * @param options - Polling options (interval, timeout)
151
+ * @returns Subscription object with unsubscribe() method
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const subscription = agent.subscribeToUpdates(
156
+ * ['JK-ABC123456', 'JK-DEF789012'],
157
+ * (intentId, intent) => {
158
+ * console.log(`${intentId} status changed to ${intent.status}`);
159
+ * },
160
+ * { interval: 5000 }
161
+ * );
162
+ *
163
+ * // Later, stop polling
164
+ * subscription.unsubscribe();
165
+ * ```
166
+ *
167
+ * **Validates: Requirement 8.3**
168
+ */
169
+ subscribeToUpdates(intentIds: string[], callback: (intentId: string, intent: Intent) => void, options?: PollOptions): Subscription;
170
+ }
171
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK9C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IACpC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,gBAAg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