@rhinestone/sdk 2.0.0-beta.0 → 2.0.0-beta.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 +43 -2
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +6 -34
- package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -1
- package/dist/src/accounts/json-rpc/providers.js +3 -2
- package/dist/src/actions/smart-sessions.d.ts.map +1 -1
- package/dist/src/actions/smart-sessions.js +3 -3
- package/dist/src/errors/index.d.ts +3 -3
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +6 -4
- package/dist/src/execution/compact.d.ts +1 -144
- package/dist/src/execution/compact.d.ts.map +1 -1
- package/dist/src/execution/compact.js +1 -109
- package/dist/src/execution/error.d.ts +10 -1
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +9 -1
- package/dist/src/execution/index.d.ts +5 -7
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +24 -44
- package/dist/src/execution/utils.d.ts +29 -13
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +174 -122
- package/dist/src/index.d.ts +21 -16
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +15 -45
- package/dist/src/modules/index.d.ts +2 -2
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js +2 -2
- package/dist/src/modules/read.d.ts.map +1 -1
- package/dist/src/modules/read.js +2 -4
- package/dist/src/modules/validators/index.d.ts +2 -2
- package/dist/src/modules/validators/index.d.ts.map +1 -1
- package/dist/src/modules/validators/index.js +2 -2
- package/dist/src/modules/validators/permissions.d.ts +5 -0
- package/dist/src/modules/validators/permissions.d.ts.map +1 -0
- package/dist/src/modules/validators/permissions.js +111 -0
- package/dist/src/modules/validators/policies/claim/permit2.d.ts +29 -3
- package/dist/src/modules/validators/policies/claim/permit2.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.d.ts +14 -27
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +74 -22
- package/dist/src/orchestrator/caip2.d.ts +7 -0
- package/dist/src/orchestrator/caip2.d.ts.map +1 -0
- package/dist/src/orchestrator/caip2.js +17 -0
- package/dist/src/orchestrator/client.d.ts +11 -11
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +193 -295
- package/dist/src/orchestrator/consts.d.ts +2 -2
- package/dist/src/orchestrator/consts.d.ts.map +1 -1
- package/dist/src/orchestrator/consts.js +2 -2
- package/dist/src/orchestrator/error.d.ts +72 -217
- package/dist/src/orchestrator/error.d.ts.map +1 -1
- package/dist/src/orchestrator/error.js +117 -195
- package/dist/src/orchestrator/index.d.ts +5 -5
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +3 -3
- package/dist/src/orchestrator/registry.d.ts +1 -8
- package/dist/src/orchestrator/registry.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.js +1 -26
- package/dist/src/orchestrator/types.d.ts +97 -232
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/types.d.ts +101 -32
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/index.d.ts +2 -1
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +2 -1
- package/dist/src/utils/walletClient.d.ts.map +1 -0
- package/dist/src/{accounts → utils}/walletClient.js +1 -1
- package/package.json +1 -5
- package/dist/src/accounts/passport.d.ts +0 -9
- package/dist/src/accounts/passport.d.ts.map +0 -1
- package/dist/src/accounts/passport.js +0 -78
- package/dist/src/accounts/walletClient.d.ts.map +0 -1
- package/dist/src/actions/compact.d.ts +0 -15
- package/dist/src/actions/compact.d.ts.map +0 -1
- package/dist/src/actions/compact.js +0 -200
- package/dist/src/actions/deployment.d.ts +0 -19
- package/dist/src/actions/deployment.d.ts.map +0 -1
- package/dist/src/actions/deployment.js +0 -76
- package/dist/src/execution/permit2.d.ts +0 -143
- package/dist/src/execution/permit2.d.ts.map +0 -1
- package/dist/src/execution/permit2.js +0 -280
- package/dist/src/execution/singleChainOps.d.ts +0 -41
- package/dist/src/execution/singleChainOps.d.ts.map +0 -1
- package/dist/src/execution/singleChainOps.js +0 -42
- package/dist/src/execution/types.d.ts +0 -36
- package/dist/src/execution/types.d.ts.map +0 -1
- package/dist/src/execution/types.js +0 -1
- /package/dist/src/{accounts → utils}/walletClient.d.ts +0 -0
|
@@ -1,12 +1,7 @@
|
|
|
1
|
+
import { fromCaip2, toCaip2 } from './caip2.js';
|
|
1
2
|
import { API_VERSION, SDK_VERSION } from './consts.js';
|
|
2
|
-
import {
|
|
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,90 @@ export class Orchestrator {
|
|
|
16
11
|
this.authProvider = authProvider;
|
|
17
12
|
this.extraHeaders = headers;
|
|
18
13
|
}
|
|
19
|
-
async getPortfolio(
|
|
14
|
+
async getPortfolio(accountAddress, filter) {
|
|
20
15
|
const params = new URLSearchParams();
|
|
21
16
|
if (filter?.chainIds) {
|
|
22
|
-
|
|
17
|
+
for (const id of filter.chainIds) {
|
|
18
|
+
params.append('chainIds', toCaip2(id));
|
|
19
|
+
}
|
|
23
20
|
}
|
|
24
21
|
if (filter?.tokens) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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/${
|
|
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
|
|
35
|
-
|
|
36
|
-
symbol:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
locked: BigInt(c.balance.locked),
|
|
41
|
+
unlocked: BigInt(c.balance.unlocked),
|
|
47
42
|
})),
|
|
48
43
|
}));
|
|
49
|
-
return portfolio;
|
|
50
44
|
}
|
|
51
|
-
async
|
|
52
|
-
const body =
|
|
53
|
-
|
|
45
|
+
async createQuote(input) {
|
|
46
|
+
const body = encodeIntentInput(input);
|
|
47
|
+
const json = await this.fetch(`${this.serverUrl}/quotes`, {
|
|
54
48
|
method: 'POST',
|
|
55
49
|
headers: await this.getHeaders(),
|
|
56
50
|
body: JSON.stringify(body),
|
|
57
51
|
});
|
|
52
|
+
return decodeQuoteResponse(json);
|
|
58
53
|
}
|
|
59
|
-
async
|
|
60
|
-
const
|
|
54
|
+
async getSplit(input) {
|
|
55
|
+
const body = convertBigIntFields({
|
|
56
|
+
chainId: toCaip2(input.chain.id),
|
|
57
|
+
tokens: input.tokens,
|
|
58
|
+
settlementLayers: input.settlementLayers,
|
|
59
|
+
});
|
|
60
|
+
const json = await this.fetch(`${this.serverUrl}/intents/splits`, {
|
|
61
61
|
method: 'POST',
|
|
62
62
|
headers: await this.getHeaders(),
|
|
63
|
-
body: JSON.stringify(
|
|
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
|
-
},
|
|
63
|
+
body: JSON.stringify(body),
|
|
101
64
|
});
|
|
102
|
-
|
|
65
|
+
return {
|
|
66
|
+
intents: json.intents.map(parseTokenAmountsRecord),
|
|
67
|
+
};
|
|
103
68
|
}
|
|
104
|
-
async
|
|
105
|
-
const
|
|
106
|
-
if (dryRun) {
|
|
107
|
-
signedIntentOp.options = {
|
|
108
|
-
dryRun: true,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
const body = { signedIntentOp };
|
|
69
|
+
async createIntent(request, policyContext) {
|
|
70
|
+
const body = convertBigIntFields(request);
|
|
112
71
|
const headers = policyContext
|
|
113
72
|
? await this.getSubmitHeaders(policyContext.intentInput, policyContext.isSponsored)
|
|
114
73
|
: await this.getHeaders();
|
|
115
|
-
return await this.fetch(`${this.serverUrl}/
|
|
74
|
+
return await this.fetch(`${this.serverUrl}/intents`, {
|
|
116
75
|
method: 'POST',
|
|
117
76
|
headers,
|
|
118
77
|
body: JSON.stringify(body),
|
|
119
78
|
});
|
|
120
79
|
}
|
|
121
|
-
async
|
|
122
|
-
|
|
80
|
+
async getIntent(intentId) {
|
|
81
|
+
const json = await this.fetch(`${this.serverUrl}/intents/${intentId}`, {
|
|
123
82
|
headers: await this.getHeaders(),
|
|
124
83
|
});
|
|
84
|
+
return {
|
|
85
|
+
status: json.status,
|
|
86
|
+
claims: (json.claims ?? []).map((claim) => ({
|
|
87
|
+
depositId: claim.depositId !== undefined ? BigInt(claim.depositId) : 0n,
|
|
88
|
+
chainId: parseChainId(claim.chainId),
|
|
89
|
+
status: claim.status,
|
|
90
|
+
claimTimestamp: claim.claimTimestamp,
|
|
91
|
+
claimTransactionHash: claim.claimTransactionHash,
|
|
92
|
+
})),
|
|
93
|
+
destinationChainId: parseChainId(json.destinationChainId),
|
|
94
|
+
accountAddress: json.accountAddress,
|
|
95
|
+
fillTimestamp: json.fillTimestamp,
|
|
96
|
+
fillTransactionHash: json.fillTransactionHash,
|
|
97
|
+
};
|
|
125
98
|
}
|
|
126
99
|
async getHeaders() {
|
|
127
100
|
const auth = await this.authProvider.getHeaders();
|
|
@@ -138,6 +111,7 @@ export class Orchestrator {
|
|
|
138
111
|
return {
|
|
139
112
|
'Content-Type': 'application/json',
|
|
140
113
|
'x-sdk-version': SDK_VERSION,
|
|
114
|
+
'x-api-version': API_VERSION,
|
|
141
115
|
...auth,
|
|
142
116
|
...this.extraHeaders,
|
|
143
117
|
};
|
|
@@ -145,228 +119,152 @@ export class Orchestrator {
|
|
|
145
119
|
async fetch(url, options) {
|
|
146
120
|
const response = await fetch(url, options);
|
|
147
121
|
if (!response.ok) {
|
|
148
|
-
let
|
|
122
|
+
let body;
|
|
149
123
|
try {
|
|
150
|
-
|
|
124
|
+
body = await response.json();
|
|
151
125
|
}
|
|
152
126
|
catch {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
127
|
+
body = {
|
|
128
|
+
code: 'INTERNAL_ERROR',
|
|
129
|
+
message: `Request failed with status ${response.status}`,
|
|
130
|
+
traceId: '',
|
|
131
|
+
};
|
|
158
132
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
response: {
|
|
162
|
-
status: response.status,
|
|
163
|
-
data: errorData,
|
|
164
|
-
headers: {
|
|
165
|
-
retryAfter: retryAfterHeader,
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
});
|
|
133
|
+
const retryAfter = response.headers?.get?.('retry-after') ?? undefined;
|
|
134
|
+
throw parseErrorEnvelope(body, response.status, retryAfter ?? undefined);
|
|
169
135
|
}
|
|
170
136
|
return response.json();
|
|
171
137
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
}
|
|
138
|
+
}
|
|
139
|
+
function parseTokenAmountsRecord(record) {
|
|
140
|
+
return Object.fromEntries(Object.entries(record).map(([addr, amount]) => [
|
|
141
|
+
addr,
|
|
142
|
+
BigInt(amount),
|
|
143
|
+
]));
|
|
144
|
+
}
|
|
145
|
+
function parseChainId(value) {
|
|
146
|
+
if (typeof value === 'number')
|
|
147
|
+
return value;
|
|
148
|
+
if (typeof value === 'string') {
|
|
149
|
+
if (value.startsWith('eip155:'))
|
|
150
|
+
return fromCaip2(value);
|
|
151
|
+
return Number(value);
|
|
273
152
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
153
|
+
throw new OrchestratorError({
|
|
154
|
+
message: `Invalid chain id value: ${String(value)}`,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function encodeIntentInput(input) {
|
|
158
|
+
const { account, destinationChainId, destinationExecutions, destinationGasUnits, tokenRequests, recipient, accountAccessList, options, preClaimExecutions, } = input;
|
|
159
|
+
const wire = {
|
|
160
|
+
account,
|
|
161
|
+
destinationChainId: toCaip2(destinationChainId),
|
|
162
|
+
destinationExecutions,
|
|
163
|
+
tokenRequests,
|
|
164
|
+
recipient,
|
|
165
|
+
accountAccessList: encodeAccountAccessList(accountAccessList),
|
|
166
|
+
options: encodeOptions(options),
|
|
167
|
+
};
|
|
168
|
+
if (destinationGasUnits !== undefined) {
|
|
169
|
+
wire.destinationGasLimit = destinationGasUnits;
|
|
170
|
+
}
|
|
171
|
+
if (preClaimExecutions) {
|
|
172
|
+
wire.preClaimExecutions = Object.fromEntries(Object.entries(preClaimExecutions).map(([chainId, ops]) => [
|
|
173
|
+
toCaip2(Number(chainId)),
|
|
174
|
+
ops,
|
|
175
|
+
]));
|
|
176
|
+
}
|
|
177
|
+
return convertBigIntFields(wire);
|
|
178
|
+
}
|
|
179
|
+
function encodeAccountAccessList(list) {
|
|
180
|
+
if (!list)
|
|
181
|
+
return undefined;
|
|
182
|
+
const out = {};
|
|
183
|
+
if ('chainIds' in list && list.chainIds) {
|
|
184
|
+
out.chainIds = list.chainIds.map(toCaip2);
|
|
185
|
+
}
|
|
186
|
+
if ('tokens' in list && list.tokens) {
|
|
187
|
+
out.tokens = list.tokens;
|
|
188
|
+
}
|
|
189
|
+
if ('chainTokens' in list && list.chainTokens) {
|
|
190
|
+
out.chainTokens = Object.fromEntries(Object.entries(list.chainTokens).map(([chainId, tokens]) => [
|
|
191
|
+
toCaip2(Number(chainId)),
|
|
192
|
+
tokens,
|
|
193
|
+
]));
|
|
194
|
+
}
|
|
195
|
+
if ('chainTokenAmounts' in list && list.chainTokenAmounts) {
|
|
196
|
+
out.chainTokenAmounts = Object.fromEntries(Object.entries(list.chainTokenAmounts).map(([chainId, tokens]) => [
|
|
197
|
+
toCaip2(Number(chainId)),
|
|
198
|
+
tokens,
|
|
199
|
+
]));
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
function encodeAuxiliaryFunds(funds) {
|
|
204
|
+
return Object.fromEntries(Object.entries(funds).map(([chainId, balances]) => [
|
|
205
|
+
toCaip2(Number(chainId)),
|
|
206
|
+
balances,
|
|
207
|
+
]));
|
|
208
|
+
}
|
|
209
|
+
function encodeOptions(options) {
|
|
210
|
+
if (!options.auxiliaryFunds)
|
|
211
|
+
return options;
|
|
212
|
+
return {
|
|
213
|
+
...options,
|
|
214
|
+
auxiliaryFunds: encodeAuxiliaryFunds(options.auxiliaryFunds),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function decodeQuoteResponse(json) {
|
|
218
|
+
const routes = (json.routes ?? []);
|
|
219
|
+
return { routes: routes.map(decodeQuote) };
|
|
220
|
+
}
|
|
221
|
+
function decodeQuote(route) {
|
|
222
|
+
return {
|
|
223
|
+
intentId: route.intentId,
|
|
224
|
+
expiresAt: route.expiresAt,
|
|
225
|
+
estimatedFillTime: route.estimatedFillTime,
|
|
226
|
+
settlementLayer: route.settlementLayer,
|
|
227
|
+
signData: route.signData,
|
|
228
|
+
cost: decodeCost(route.cost),
|
|
229
|
+
tokenRequirements: route.tokenRequirements
|
|
230
|
+
? decodeTokenRequirements(route.tokenRequirements)
|
|
231
|
+
: undefined,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function decodeCost(cost) {
|
|
235
|
+
return {
|
|
236
|
+
input: cost.input.map(decodeCostTokenEntry),
|
|
237
|
+
output: cost.output.map(decodeCostTokenEntry),
|
|
238
|
+
feeToken: cost.feeToken
|
|
239
|
+
? {
|
|
240
|
+
chainId: parseChainId(cost.feeToken.chainId),
|
|
241
|
+
tokenAddress: cost.feeToken.tokenAddress,
|
|
310
242
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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 });
|
|
243
|
+
: undefined,
|
|
244
|
+
fees: cost.fees,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function decodeCostTokenEntry(entry) {
|
|
248
|
+
return {
|
|
249
|
+
chainId: parseChainId(entry.chainId),
|
|
250
|
+
tokenAddress: entry.tokenAddress,
|
|
251
|
+
symbol: entry.symbol,
|
|
252
|
+
decimals: entry.decimals,
|
|
253
|
+
price: entry.price,
|
|
254
|
+
amount: BigInt(entry.amount),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function decodeTokenRequirements(wire) {
|
|
258
|
+
const out = {};
|
|
259
|
+
for (const [chainKey, tokens] of Object.entries(wire)) {
|
|
260
|
+
const chainId = parseChainId(chainKey);
|
|
261
|
+
out[chainId] = {};
|
|
262
|
+
for (const [tokenAddress, requirement] of Object.entries(tokens)) {
|
|
263
|
+
out[chainId][tokenAddress] = {
|
|
264
|
+
...requirement,
|
|
265
|
+
amount: BigInt(requirement.amount),
|
|
266
|
+
};
|
|
370
267
|
}
|
|
371
268
|
}
|
|
269
|
+
return out;
|
|
372
270
|
}
|
|
@@ -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.
|
|
4
|
-
declare const API_VERSION = "2026-
|
|
3
|
+
declare const SDK_VERSION = "2.0.0-beta.2";
|
|
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,
|
|
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,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.
|
|
4
|
-
const API_VERSION = '2026-
|
|
3
|
+
const SDK_VERSION = '2.0.0-beta.2';
|
|
4
|
+
const API_VERSION = '2026-04.blanc';
|
|
5
5
|
export { PROD_ORCHESTRATOR_URL, RHINESTONE_SPOKE_POOL_ADDRESS, SDK_VERSION, API_VERSION, };
|