@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.
- 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 +11 -2
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +11 -3
- package/dist/src/execution/index.d.ts +10 -11
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +37 -47
- package/dist/src/execution/utils.d.ts +34 -16
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +259 -144
- package/dist/src/index.d.ts +22 -16
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -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 +13 -0
- package/dist/src/orchestrator/caip2.d.ts.map +1 -0
- package/dist/src/orchestrator/caip2.js +52 -0
- package/dist/src/orchestrator/client.d.ts +12 -11
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +217 -296
- 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/destinations.d.ts +23 -0
- package/dist/src/orchestrator/destinations.d.ts.map +1 -0
- package/dist/src/orchestrator/destinations.js +36 -0
- 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 +6 -5
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +4 -3
- package/dist/src/orchestrator/registry.d.ts +3 -9
- package/dist/src/orchestrator/registry.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.js +11 -26
- package/dist/src/orchestrator/types.d.ts +136 -239
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/types.d.ts +126 -37
- 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 +2 -6
- 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, isCaip2, 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,91 @@ 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
|
-
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
|
|
52
|
-
const body =
|
|
53
|
-
|
|
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
|
|
60
|
-
const
|
|
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(
|
|
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
|
-
|
|
66
|
+
return {
|
|
67
|
+
intents: json.intents.map(parseTokenAmountsRecord),
|
|
68
|
+
};
|
|
103
69
|
}
|
|
104
|
-
async
|
|
105
|
-
const
|
|
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}/
|
|
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
|
|
122
|
-
|
|
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
|
|
123
|
+
let body;
|
|
149
124
|
try {
|
|
150
|
-
|
|
125
|
+
body = await response.json();
|
|
151
126
|
}
|
|
152
127
|
catch {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
128
|
+
body = {
|
|
129
|
+
code: 'INTERNAL_ERROR',
|
|
130
|
+
message: `Request failed with status ${response.status}`,
|
|
131
|
+
traceId: '',
|
|
132
|
+
};
|
|
158
133
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
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
|
-
|
|
310
|
-
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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.
|
|
4
|
-
declare const API_VERSION = "2026-
|
|
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,
|
|
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.
|
|
4
|
-
const API_VERSION = '2026-
|
|
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"}
|