@rhinestone/sdk 2.0.0-beta.0 → 2.0.0-beta.10

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 (92) hide show
  1. package/README.md +43 -2
  2. package/dist/src/accounts/index.d.ts.map +1 -1
  3. package/dist/src/accounts/index.js +6 -34
  4. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -1
  5. package/dist/src/accounts/json-rpc/providers.js +3 -2
  6. package/dist/src/actions/smart-sessions.d.ts.map +1 -1
  7. package/dist/src/actions/smart-sessions.js +3 -3
  8. package/dist/src/errors/index.d.ts +3 -3
  9. package/dist/src/errors/index.d.ts.map +1 -1
  10. package/dist/src/errors/index.js +6 -4
  11. package/dist/src/execution/compact.d.ts +1 -144
  12. package/dist/src/execution/compact.d.ts.map +1 -1
  13. package/dist/src/execution/compact.js +1 -109
  14. package/dist/src/execution/error.d.ts +11 -2
  15. package/dist/src/execution/error.d.ts.map +1 -1
  16. package/dist/src/execution/error.js +11 -3
  17. package/dist/src/execution/index.d.ts +10 -11
  18. package/dist/src/execution/index.d.ts.map +1 -1
  19. package/dist/src/execution/index.js +37 -47
  20. package/dist/src/execution/utils.d.ts +34 -16
  21. package/dist/src/execution/utils.d.ts.map +1 -1
  22. package/dist/src/execution/utils.js +259 -144
  23. package/dist/src/index.d.ts +22 -16
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/index.js +18 -45
  26. package/dist/src/modules/index.d.ts +2 -2
  27. package/dist/src/modules/index.d.ts.map +1 -1
  28. package/dist/src/modules/index.js +2 -2
  29. package/dist/src/modules/read.d.ts.map +1 -1
  30. package/dist/src/modules/read.js +2 -4
  31. package/dist/src/modules/validators/index.d.ts +2 -2
  32. package/dist/src/modules/validators/index.d.ts.map +1 -1
  33. package/dist/src/modules/validators/index.js +2 -2
  34. package/dist/src/modules/validators/permissions.d.ts +5 -0
  35. package/dist/src/modules/validators/permissions.d.ts.map +1 -0
  36. package/dist/src/modules/validators/permissions.js +111 -0
  37. package/dist/src/modules/validators/policies/claim/permit2.d.ts +29 -3
  38. package/dist/src/modules/validators/policies/claim/permit2.d.ts.map +1 -1
  39. package/dist/src/modules/validators/smart-sessions.d.ts +14 -27
  40. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
  41. package/dist/src/modules/validators/smart-sessions.js +74 -22
  42. package/dist/src/orchestrator/caip2.d.ts +13 -0
  43. package/dist/src/orchestrator/caip2.d.ts.map +1 -0
  44. package/dist/src/orchestrator/caip2.js +52 -0
  45. package/dist/src/orchestrator/client.d.ts +12 -11
  46. package/dist/src/orchestrator/client.d.ts.map +1 -1
  47. package/dist/src/orchestrator/client.js +217 -296
  48. package/dist/src/orchestrator/consts.d.ts +2 -2
  49. package/dist/src/orchestrator/consts.d.ts.map +1 -1
  50. package/dist/src/orchestrator/consts.js +2 -2
  51. package/dist/src/orchestrator/destinations.d.ts +23 -0
  52. package/dist/src/orchestrator/destinations.d.ts.map +1 -0
  53. package/dist/src/orchestrator/destinations.js +36 -0
  54. package/dist/src/orchestrator/error.d.ts +72 -217
  55. package/dist/src/orchestrator/error.d.ts.map +1 -1
  56. package/dist/src/orchestrator/error.js +117 -195
  57. package/dist/src/orchestrator/index.d.ts +6 -5
  58. package/dist/src/orchestrator/index.d.ts.map +1 -1
  59. package/dist/src/orchestrator/index.js +4 -3
  60. package/dist/src/orchestrator/registry.d.ts +3 -9
  61. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  62. package/dist/src/orchestrator/registry.js +11 -26
  63. package/dist/src/orchestrator/types.d.ts +136 -239
  64. package/dist/src/orchestrator/types.d.ts.map +1 -1
  65. package/dist/src/types.d.ts +126 -37
  66. package/dist/src/types.d.ts.map +1 -1
  67. package/dist/src/utils/index.d.ts +2 -1
  68. package/dist/src/utils/index.d.ts.map +1 -1
  69. package/dist/src/utils/index.js +2 -1
  70. package/dist/src/utils/walletClient.d.ts.map +1 -0
  71. package/dist/src/{accounts → utils}/walletClient.js +1 -1
  72. package/package.json +2 -6
  73. package/dist/src/accounts/passport.d.ts +0 -9
  74. package/dist/src/accounts/passport.d.ts.map +0 -1
  75. package/dist/src/accounts/passport.js +0 -78
  76. package/dist/src/accounts/walletClient.d.ts.map +0 -1
  77. package/dist/src/actions/compact.d.ts +0 -15
  78. package/dist/src/actions/compact.d.ts.map +0 -1
  79. package/dist/src/actions/compact.js +0 -200
  80. package/dist/src/actions/deployment.d.ts +0 -19
  81. package/dist/src/actions/deployment.d.ts.map +0 -1
  82. package/dist/src/actions/deployment.js +0 -76
  83. package/dist/src/execution/permit2.d.ts +0 -143
  84. package/dist/src/execution/permit2.d.ts.map +0 -1
  85. package/dist/src/execution/permit2.js +0 -280
  86. package/dist/src/execution/singleChainOps.d.ts +0 -41
  87. package/dist/src/execution/singleChainOps.d.ts.map +0 -1
  88. package/dist/src/execution/singleChainOps.js +0 -42
  89. package/dist/src/execution/types.d.ts +0 -36
  90. package/dist/src/execution/types.d.ts.map +0 -1
  91. package/dist/src/execution/types.js +0 -1
  92. /package/dist/src/{accounts → utils}/walletClient.d.ts +0 -0
@@ -1,12 +1,7 @@
1
+ import { fromCaip2, isCaip2, toCaip2 } from './caip2.js';
1
2
  import { API_VERSION, SDK_VERSION } from './consts.js';
2
- import { AuthenticationRequiredError, BadRequestError, BodyParserError, ConflictError, ForbiddenError, InsufficientBalanceError, InsufficientLiquidityError, IntentNotFoundError, InternalServerError, InvalidApiKeyError, InvalidIntentSignatureError, NoPathFoundError, OnlyOneTargetTokenAmountCanBeUnsetError, OrchestratorError, RateLimitedError, ResourceNotFoundError, ServiceUnavailableError, SimulationFailedError, TokenNotSupportedError, UnauthorizedError, UnsupportedChainError, UnsupportedChainIdError, UnsupportedTokenError, } from './error.js';
3
+ import { OrchestratorError, parseErrorEnvelope, } from './error.js';
3
4
  import { convertBigIntFields } from './utils.js';
4
- function parseTokenAmountsRecord(record) {
5
- return Object.fromEntries(Object.entries(record).map(([addr, amount]) => [
6
- addr,
7
- BigInt(amount),
8
- ]));
9
- }
10
5
  export class Orchestrator {
11
6
  serverUrl;
12
7
  authProvider;
@@ -16,112 +11,91 @@ export class Orchestrator {
16
11
  this.authProvider = authProvider;
17
12
  this.extraHeaders = headers;
18
13
  }
19
- async getPortfolio(userAddress, filter) {
14
+ async getPortfolio(accountAddress, filter) {
20
15
  const params = new URLSearchParams();
21
16
  if (filter?.chainIds) {
22
- params.set('chainIds', filter.chainIds.join(','));
17
+ for (const id of filter.chainIds) {
18
+ params.append('chainIds', toCaip2(id));
19
+ }
23
20
  }
24
21
  if (filter?.tokens) {
25
- params.set('tokens', Object.entries(filter.tokens)
26
- .flatMap(([chainId, tokens]) => tokens.map((token) => `${chainId}:${token}`))
27
- .join(','));
22
+ for (const [chainId, tokens] of Object.entries(filter.tokens)) {
23
+ for (const token of tokens) {
24
+ params.append('tokens', `${toCaip2(Number(chainId))}:${token}`);
25
+ }
26
+ }
28
27
  }
29
- const url = new URL(`${this.serverUrl}/accounts/${userAddress}/portfolio`);
28
+ const url = new URL(`${this.serverUrl}/accounts/${accountAddress}/portfolio`);
30
29
  url.search = params.toString();
31
30
  const json = await this.fetch(url.toString(), {
32
31
  headers: await this.getHeaders(),
33
32
  });
34
- const portfolioResponse = json.portfolio;
35
- const portfolio = portfolioResponse.map((tokenResponse) => ({
36
- symbol: tokenResponse.tokenName,
37
- decimals: tokenResponse.tokenDecimals,
38
- balances: {
39
- locked: BigInt(tokenResponse.balance.locked),
40
- unlocked: BigInt(tokenResponse.balance.unlocked),
41
- },
42
- chains: tokenResponse.tokenChainBalance.map((chainBalance) => ({
43
- chain: chainBalance.chainId,
44
- address: chainBalance.tokenAddress,
45
- locked: BigInt(chainBalance.balance.locked),
46
- unlocked: BigInt(chainBalance.balance.unlocked),
33
+ const portfolioWire = json.portfolio;
34
+ return portfolioWire.map((token) => ({
35
+ symbol: token.symbol,
36
+ chains: token.chains.map((c) => ({
37
+ chain: parseChainId(c.chainId),
38
+ address: c.address,
39
+ decimals: c.decimals,
40
+ amount: BigInt(c.amount),
47
41
  })),
48
42
  }));
49
- return portfolio;
50
43
  }
51
- async getIntentRoute(input) {
52
- const body = convertBigIntFields(input);
53
- return await this.fetch(`${this.serverUrl}/intents/route`, {
44
+ async createQuote(input) {
45
+ const body = encodeIntentInput(input);
46
+ const json = await this.fetch(`${this.serverUrl}/quotes`, {
54
47
  method: 'POST',
55
48
  headers: await this.getHeaders(),
56
49
  body: JSON.stringify(body),
57
50
  });
51
+ return decodeQuoteResponse(json);
58
52
  }
59
- async splitIntents(input) {
60
- const response = await fetch(`${this.serverUrl}/intents/split`, {
53
+ async getSplit(input) {
54
+ const body = convertBigIntFields({
55
+ chainId: toCaip2(input.chain.id),
56
+ tokens: input.tokens,
57
+ settlementLayers: input.settlementLayers
58
+ ? encodeSettlementLayers(input.settlementLayers)
59
+ : undefined,
60
+ });
61
+ const json = await this.fetch(`${this.serverUrl}/intents/splits`, {
61
62
  method: 'POST',
62
63
  headers: await this.getHeaders(),
63
- body: JSON.stringify(convertBigIntFields({
64
- chainId: input.chain.id,
65
- tokens: input.tokens,
66
- settlementLayers: input.settlementLayers,
67
- })),
68
- });
69
- if (response.ok) {
70
- const json = await response.json();
71
- return {
72
- intents: json.intents.map(parseTokenAmountsRecord),
73
- };
74
- }
75
- let errorData = {};
76
- try {
77
- errorData = await response.json();
78
- }
79
- catch {
80
- try {
81
- const text = await response.text();
82
- errorData = { message: text };
83
- }
84
- catch { }
85
- }
86
- if (response.status === 422 &&
87
- errorData.error === 'INSUFFICIENT_LIQUIDITY') {
88
- throw new InsufficientLiquidityError({
89
- availableIntents: errorData.availableIntents.map(parseTokenAmountsRecord),
90
- unfillable: parseTokenAmountsRecord(errorData.unfillable),
91
- traceId: errorData.traceId,
92
- statusCode: 422,
93
- });
94
- }
95
- this.parseError({
96
- response: {
97
- status: response.status,
98
- data: errorData,
99
- headers: {},
100
- },
64
+ body: JSON.stringify(body),
101
65
  });
102
- throw new OrchestratorError({ message: 'Unexpected error' });
66
+ return {
67
+ intents: json.intents.map(parseTokenAmountsRecord),
68
+ };
103
69
  }
104
- async submitIntent(signedIntentOpUnformatted, dryRun, policyContext) {
105
- const signedIntentOp = convertBigIntFields(signedIntentOpUnformatted);
106
- if (dryRun) {
107
- signedIntentOp.options = {
108
- dryRun: true,
109
- };
110
- }
111
- const body = { signedIntentOp };
70
+ async createIntent(request, policyContext) {
71
+ const body = convertBigIntFields(request);
112
72
  const headers = policyContext
113
73
  ? await this.getSubmitHeaders(policyContext.intentInput, policyContext.isSponsored)
114
74
  : await this.getHeaders();
115
- return await this.fetch(`${this.serverUrl}/intent-operations`, {
75
+ return await this.fetch(`${this.serverUrl}/intents`, {
116
76
  method: 'POST',
117
77
  headers,
118
78
  body: JSON.stringify(body),
119
79
  });
120
80
  }
121
- async getIntentOpStatus(intentId) {
122
- return await this.fetch(`${this.serverUrl}/intent-operation/${intentId.toString()}`, {
81
+ async getIntent(intentId) {
82
+ const json = await this.fetch(`${this.serverUrl}/intents/${intentId}`, {
123
83
  headers: await this.getHeaders(),
124
84
  });
85
+ return {
86
+ status: json.status,
87
+ claims: (json.claims ?? []).map((claim) => ({
88
+ depositId: claim.depositId !== undefined ? BigInt(claim.depositId) : 0n,
89
+ chainId: parseChainId(claim.chainId),
90
+ status: claim.status,
91
+ claimTimestamp: claim.claimTimestamp,
92
+ claimTransactionHash: claim.claimTransactionHash,
93
+ })),
94
+ destinationChainId: parseChainId(json.destinationChainId),
95
+ accountAddress: json.accountAddress,
96
+ fillTimestamp: json.fillTimestamp,
97
+ fillTransactionHash: json.fillTransactionHash,
98
+ };
125
99
  }
126
100
  async getHeaders() {
127
101
  const auth = await this.authProvider.getHeaders();
@@ -138,6 +112,7 @@ export class Orchestrator {
138
112
  return {
139
113
  'Content-Type': 'application/json',
140
114
  'x-sdk-version': SDK_VERSION,
115
+ 'x-api-version': API_VERSION,
141
116
  ...auth,
142
117
  ...this.extraHeaders,
143
118
  };
@@ -145,228 +120,174 @@ export class Orchestrator {
145
120
  async fetch(url, options) {
146
121
  const response = await fetch(url, options);
147
122
  if (!response.ok) {
148
- let errorData = {};
123
+ let body;
149
124
  try {
150
- errorData = await response.json();
125
+ body = await response.json();
151
126
  }
152
127
  catch {
153
- try {
154
- const text = await response.text();
155
- errorData = { message: text };
156
- }
157
- catch { }
128
+ body = {
129
+ code: 'INTERNAL_ERROR',
130
+ message: `Request failed with status ${response.status}`,
131
+ traceId: '',
132
+ };
158
133
  }
159
- const retryAfterHeader = response.headers?.get?.('retry-after') || undefined;
160
- this.parseError({
161
- response: {
162
- status: response.status,
163
- data: errorData,
164
- headers: {
165
- retryAfter: retryAfterHeader,
166
- },
167
- },
168
- });
134
+ const retryAfter = response.headers?.get?.('retry-after') ?? undefined;
135
+ throw parseErrorEnvelope(body, response.status, retryAfter ?? undefined);
169
136
  }
170
137
  return response.json();
171
138
  }
172
- parseError(error) {
173
- if (error.response) {
174
- const status = error.response.status;
175
- const { headers } = error.response;
176
- const { errors = [], traceId, message } = error.response.data || {};
177
- let errorType = 'Unknown';
178
- switch (status) {
179
- case 400:
180
- errorType = 'Bad Request';
181
- break;
182
- case 401:
183
- errorType = 'Unauthorized';
184
- break;
185
- case 403:
186
- errorType = 'Forbidden';
187
- break;
188
- case 404:
189
- errorType = 'Not Found';
190
- break;
191
- case 409:
192
- errorType = 'Conflict';
193
- break;
194
- case 422:
195
- errorType = 'Unprocessable Entity';
196
- break;
197
- case 429:
198
- errorType = 'Too Many Requests';
199
- break;
200
- case 500:
201
- errorType = 'Internal Server Error';
202
- break;
203
- case 503:
204
- errorType = 'Service Unavailable';
205
- break;
206
- default:
207
- errorType = 'Unknown';
208
- }
209
- const baseParams = {
210
- context: { traceId },
211
- errorType,
212
- traceId,
213
- statusCode: status,
214
- };
215
- if (status === 429) {
216
- const retryAfter = headers?.retryAfter;
217
- const context = { traceId, retryAfter };
218
- throw new RateLimitedError({
219
- ...baseParams,
220
- context,
221
- });
222
- }
223
- if (status === 503) {
224
- throw new ServiceUnavailableError(baseParams);
225
- }
226
- if (message) {
227
- this.parseErrorMessage(message, baseParams);
228
- }
229
- for (const err of errors) {
230
- const mergedParams = {
231
- ...baseParams,
232
- context: { ...err.context, traceId },
233
- };
234
- this.parseErrorMessage(err.message, mergedParams);
235
- }
236
- switch (status) {
237
- case 400:
238
- throw new BadRequestError({
239
- ...baseParams,
240
- context: { traceId, errors },
241
- message: message,
242
- });
243
- case 401:
244
- if (message === 'Authentication is required') {
245
- throw new AuthenticationRequiredError(baseParams);
246
- }
247
- throw new UnauthorizedError(baseParams);
248
- case 403:
249
- throw new ForbiddenError(baseParams);
250
- case 404:
251
- throw new ResourceNotFoundError(baseParams);
252
- case 409:
253
- throw new ConflictError(baseParams);
254
- case 500:
255
- if (errors && errors.length > 0) {
256
- const mergedParams = {
257
- ...baseParams,
258
- context: { ...errors[0].context, traceId },
259
- };
260
- throw new OrchestratorError({
261
- ...mergedParams,
262
- message: errors[0].message || 'Internal Server Error',
263
- });
264
- }
265
- throw new InternalServerError(baseParams);
266
- default:
267
- throw new OrchestratorError({
268
- ...baseParams,
269
- message: message || errorType,
270
- });
271
- }
272
- }
139
+ }
140
+ function parseTokenAmountsRecord(record) {
141
+ return Object.fromEntries(Object.entries(record).map(([addr, amount]) => [
142
+ addr,
143
+ BigInt(amount),
144
+ ]));
145
+ }
146
+ function parseChainId(value) {
147
+ if (typeof value === 'number')
148
+ return value;
149
+ if (typeof value === 'string') {
150
+ if (isCaip2(value))
151
+ return fromCaip2(value);
152
+ const numeric = Number(value);
153
+ if (Number.isFinite(numeric))
154
+ return numeric;
273
155
  }
274
- parseErrorMessage(message, errorParams) {
275
- if (message === 'Insufficient balance') {
276
- throw new InsufficientBalanceError(errorParams);
277
- }
278
- else if (message === 'Unsupported chain id' ||
279
- message === 'Unsupported chain ids') {
280
- throw new UnsupportedChainIdError(errorParams);
281
- }
282
- else if (message.startsWith('Unsupported chain ')) {
283
- const chainIdMatch = message.match(/Unsupported chain (\d+)/);
284
- if (chainIdMatch) {
285
- const chainId = parseInt(chainIdMatch[1], 10);
286
- throw new UnsupportedChainError(chainId, errorParams);
287
- }
288
- throw new UnsupportedChainIdError(errorParams);
289
- }
290
- else if (message.includes('Unsupported token') &&
291
- message.includes('for chain')) {
292
- const tokenMatch = message.match(/Unsupported token (\w+) for chain (\d+)/);
293
- if (tokenMatch) {
294
- const tokenSymbol = tokenMatch[1];
295
- const chainId = parseInt(tokenMatch[2], 10);
296
- throw new UnsupportedTokenError(tokenSymbol, chainId, errorParams);
297
- }
298
- throw new OrchestratorError({ message, ...errorParams });
299
- }
300
- else if (message === 'Unsupported token addresses') {
301
- // generic unsupported tokens without specific symbol/chain context
302
- throw new BadRequestError({ message, ...errorParams });
303
- }
304
- else if (message.includes('not supported on chain')) {
305
- const tokenMatch = message.match(/Token (.+) not supported on chain (\d+)/);
306
- if (tokenMatch) {
307
- const tokenAddress = tokenMatch[1];
308
- const chainId = parseInt(tokenMatch[2], 10);
309
- throw new TokenNotSupportedError(tokenAddress, chainId, errorParams);
310
- }
311
- throw new OrchestratorError({ message, ...errorParams });
312
- }
313
- else if (message === 'Authentication is required') {
314
- throw new AuthenticationRequiredError(errorParams);
315
- }
316
- else if (message === 'Invalid API key') {
317
- throw new InvalidApiKeyError(errorParams);
318
- }
319
- else if (message === 'Insufficient permissions') {
320
- throw new ForbiddenError(errorParams);
321
- }
322
- else if (message === 'Invalid bundle signature') {
323
- throw new InvalidIntentSignatureError(errorParams);
324
- }
325
- else if (message === 'Invalid checksum signature') {
326
- throw new InvalidIntentSignatureError(errorParams);
327
- }
328
- else if (message === 'Only one target token amount can be unset' ||
329
- message === 'Only one max-out transfer is allowed') {
330
- throw new OnlyOneTargetTokenAmountCanBeUnsetError(errorParams);
331
- }
332
- else if (message === 'No valid settlement plan found for the given transfers' ||
333
- message === 'No valid transfers sent for settlement quotes' ||
334
- message === 'No Path Found') {
335
- throw new NoPathFoundError(errorParams);
336
- }
337
- else if (message === 'Emissary is not enabled' ||
338
- message === 'Emissary is not the expected address') {
339
- throw new ForbiddenError(errorParams);
340
- }
341
- else if (message.includes('No such intent with nonce') ||
342
- message === 'Order bundle not found') {
343
- throw new IntentNotFoundError(errorParams);
344
- }
345
- else if (message === 'Could not retrieve a valid quote from any aggregator') {
346
- throw new NoPathFoundError(errorParams);
347
- }
348
- else if (message === 'No aggregators available for swap') {
349
- throw new InternalServerError(errorParams);
350
- }
351
- else if (message === 'entity.parse.failed' ||
352
- message === 'entity.too.large' ||
353
- message === 'encoding.unsupported') {
354
- throw new BodyParserError({ message, ...errorParams });
355
- }
356
- else if (message === 'Bundle simulation failed') {
357
- const simulations = errorParams.context.error.simulations;
358
- const { traceId, errorType, statusCode, context } = errorParams;
359
- throw new SimulationFailedError({
360
- message,
361
- context,
362
- errorType,
363
- traceId,
364
- statusCode,
365
- simulations,
366
- });
367
- }
368
- else {
369
- throw new OrchestratorError({ message, ...errorParams });
156
+ throw new OrchestratorError({
157
+ message: `Invalid chain id value: ${String(value)}`,
158
+ });
159
+ }
160
+ function encodeIntentInput(input) {
161
+ const { account, destinationChainId, destinationExecutions, destinationGasUnits, tokenRequests, recipient, accountAccessList, options, preClaimExecutions, } = input;
162
+ const wire = {
163
+ account,
164
+ destinationChainId: toCaip2(destinationChainId),
165
+ destinationExecutions,
166
+ tokenRequests,
167
+ recipient,
168
+ accountAccessList: encodeAccountAccessList(accountAccessList),
169
+ options: encodeOptions(options),
170
+ };
171
+ if (destinationGasUnits !== undefined) {
172
+ wire.destinationGasLimit = destinationGasUnits;
173
+ }
174
+ if (preClaimExecutions) {
175
+ wire.preClaimExecutions = Object.fromEntries(Object.entries(preClaimExecutions).map(([chainId, ops]) => [
176
+ toCaip2(Number(chainId)),
177
+ ops,
178
+ ]));
179
+ }
180
+ return convertBigIntFields(wire);
181
+ }
182
+ function encodeAccountAccessList(list) {
183
+ if (!list)
184
+ return undefined;
185
+ const out = {};
186
+ if ('chainIds' in list && list.chainIds) {
187
+ out.chainIds = list.chainIds.map(toCaip2);
188
+ }
189
+ if ('tokens' in list && list.tokens) {
190
+ out.tokens = list.tokens;
191
+ }
192
+ if ('chainTokens' in list && list.chainTokens) {
193
+ out.chainTokens = Object.fromEntries(Object.entries(list.chainTokens).map(([chainId, tokens]) => [
194
+ toCaip2(Number(chainId)),
195
+ tokens,
196
+ ]));
197
+ }
198
+ if ('chainTokenAmounts' in list && list.chainTokenAmounts) {
199
+ out.chainTokenAmounts = Object.fromEntries(Object.entries(list.chainTokenAmounts).map(([chainId, tokens]) => [
200
+ toCaip2(Number(chainId)),
201
+ tokens,
202
+ ]));
203
+ }
204
+ return out;
205
+ }
206
+ function encodeAuxiliaryFunds(funds) {
207
+ return Object.fromEntries(Object.entries(funds).map(([chainId, balances]) => [
208
+ toCaip2(Number(chainId)),
209
+ balances,
210
+ ]));
211
+ }
212
+ function encodeOptions(options) {
213
+ const wire = { ...options };
214
+ if (options.auxiliaryFunds) {
215
+ wire.auxiliaryFunds = encodeAuxiliaryFunds(options.auxiliaryFunds);
216
+ }
217
+ if (options.settlementLayers) {
218
+ wire.settlementLayers = encodeSettlementLayers(options.settlementLayers);
219
+ }
220
+ return wire;
221
+ }
222
+ // Inversion universe for `{ exclude }`. Drop once the orchestrator accepts the
223
+ // union natively; RHINO/CCTP are listed despite not being in `SettlementLayer`.
224
+ const KNOWN_SETTLEMENT_LAYERS = [
225
+ 'ACROSS',
226
+ 'ECO',
227
+ 'RELAY',
228
+ 'OFT',
229
+ 'NEAR',
230
+ 'RHINO',
231
+ 'CCTP',
232
+ ];
233
+ export function encodeSettlementLayers(filter) {
234
+ if ('include' in filter)
235
+ return filter.include;
236
+ const excluded = new Set(filter.exclude);
237
+ return KNOWN_SETTLEMENT_LAYERS.filter((layer) => !excluded.has(layer));
238
+ }
239
+ function decodeQuoteResponse(json) {
240
+ const routes = (json.routes ?? []);
241
+ return { routes: routes.map(decodeQuote) };
242
+ }
243
+ function decodeQuote(route) {
244
+ return {
245
+ intentId: route.intentId,
246
+ expiresAt: route.expiresAt,
247
+ estimatedFillTime: route.estimatedFillTime,
248
+ settlementLayer: route.settlementLayer,
249
+ signData: route.signData,
250
+ cost: decodeCost(route.cost),
251
+ tokenRequirements: route.tokenRequirements
252
+ ? decodeTokenRequirements(route.tokenRequirements)
253
+ : undefined,
254
+ bridgeFill: decodeBridgeFill(route.bridgeFill),
255
+ };
256
+ }
257
+ // Normalizes CAIP-2 strings to numeric IDs for consistency with BridgeFill decodeCostTokenEntry, and getIntent
258
+ function decodeBridgeFill(bf) {
259
+ if (!bf)
260
+ return undefined;
261
+ return { ...bf, destinationChainId: parseChainId(bf.destinationChainId) };
262
+ }
263
+ function decodeCost(cost) {
264
+ return {
265
+ input: cost.input.map(decodeCostTokenEntry),
266
+ output: cost.output.map(decodeCostTokenEntry),
267
+ fees: cost.fees,
268
+ };
269
+ }
270
+ function decodeCostTokenEntry(entry) {
271
+ return {
272
+ chainId: parseChainId(entry.chainId),
273
+ tokenAddress: entry.tokenAddress,
274
+ symbol: entry.symbol,
275
+ decimals: entry.decimals,
276
+ price: entry.price,
277
+ amount: BigInt(entry.amount),
278
+ };
279
+ }
280
+ function decodeTokenRequirements(wire) {
281
+ const out = {};
282
+ for (const [chainKey, tokens] of Object.entries(wire)) {
283
+ const chainId = parseChainId(chainKey);
284
+ out[chainId] = {};
285
+ for (const [tokenAddress, requirement] of Object.entries(tokens)) {
286
+ out[chainId][tokenAddress] = {
287
+ ...requirement,
288
+ amount: BigInt(requirement.amount),
289
+ };
370
290
  }
371
291
  }
292
+ return out;
372
293
  }
@@ -1,6 +1,6 @@
1
1
  declare const PROD_ORCHESTRATOR_URL = "https://v1.orchestrator.rhinestone.dev";
2
2
  declare const RHINESTONE_SPOKE_POOL_ADDRESS = "0x000000000060f6e853447881951574cdd0663530";
3
- declare const SDK_VERSION = "2.0.0-beta.0";
4
- declare const API_VERSION = "2026-01.alps";
3
+ declare const SDK_VERSION = "2.0.0-beta.10";
4
+ declare const API_VERSION = "2026-04.blanc";
5
5
  export { PROD_ORCHESTRATOR_URL, RHINESTONE_SPOKE_POOL_ADDRESS, SDK_VERSION, API_VERSION, };
6
6
  //# sourceMappingURL=consts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../orchestrator/consts.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,qBAAqB,2CAA2C,CAAA;AACtE,QAAA,MAAM,6BAA6B,+CACW,CAAA;AAE9C,QAAA,MAAM,WAAW,iBAAiB,CAAA;AAClC,QAAA,MAAM,WAAW,iBAAiB,CAAA;AAElC,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,WAAW,EACX,WAAW,GACZ,CAAA"}
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../orchestrator/consts.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,qBAAqB,2CAA2C,CAAA;AACtE,QAAA,MAAM,6BAA6B,+CACW,CAAA;AAE9C,QAAA,MAAM,WAAW,kBAAkB,CAAA;AACnC,QAAA,MAAM,WAAW,kBAAkB,CAAA;AAEnC,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,WAAW,EACX,WAAW,GACZ,CAAA"}
@@ -1,5 +1,5 @@
1
1
  const PROD_ORCHESTRATOR_URL = 'https://v1.orchestrator.rhinestone.dev';
2
2
  const RHINESTONE_SPOKE_POOL_ADDRESS = '0x000000000060f6e853447881951574cdd0663530';
3
- const SDK_VERSION = '2.0.0-beta.0';
4
- const API_VERSION = '2026-01.alps';
3
+ const SDK_VERSION = '2.0.0-beta.10';
4
+ const API_VERSION = '2026-04.blanc';
5
5
  export { PROD_ORCHESTRATOR_URL, RHINESTONE_SPOKE_POOL_ADDRESS, SDK_VERSION, API_VERSION, };
@@ -0,0 +1,23 @@
1
+ import type { Chain } from 'viem';
2
+ import type { Caip2ChainId } from './caip2.js';
3
+ interface NativeCurrency {
4
+ readonly name: string;
5
+ readonly symbol: string;
6
+ readonly decimals: number;
7
+ }
8
+ type NonEvmAddress = string;
9
+ interface NonEvmChain {
10
+ readonly name: string;
11
+ readonly caip2: Caip2ChainId;
12
+ readonly kind: 'svm' | 'tvm';
13
+ readonly nativeCurrency: NativeCurrency;
14
+ readonly testnet?: boolean;
15
+ }
16
+ type DestinationChain = Chain | NonEvmChain;
17
+ declare const solanaMainnet: NonEvmChain;
18
+ declare const tronMainnet: NonEvmChain;
19
+ declare function isNonEvmChain(chain: DestinationChain): chain is NonEvmChain;
20
+ declare function getChainId(chain: DestinationChain): number;
21
+ export type { DestinationChain, NativeCurrency, NonEvmAddress, NonEvmChain };
22
+ export { getChainId, isNonEvmChain, solanaMainnet, tronMainnet };
23
+ //# sourceMappingURL=destinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destinations.d.ts","sourceRoot":"","sources":["../../../orchestrator/destinations.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,UAAU,cAAc;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAMD,KAAK,aAAa,GAAG,MAAM,CAAA;AAE3B,UAAU,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;IAC5B,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAA;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,KAAK,gBAAgB,GAAG,KAAK,GAAG,WAAW,CAAA;AAE3C,QAAA,MAAM,aAAa,EAAE,WAKpB,CAAA;AAED,QAAA,MAAM,WAAW,EAAE,WAKlB,CAAA;AAED,iBAAS,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,KAAK,IAAI,WAAW,CAEpE;AAKD,iBAAS,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAEnD;AAED,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,CAAA"}