@rhinestone/sdk 1.5.1 → 2.0.0-beta.1
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 +1 -1
- package/dist/src/accounts/error.d.ts +1 -1
- package/dist/src/accounts/error.js +1 -19
- package/dist/src/accounts/index.d.ts +5 -5
- package/dist/src/accounts/index.js +121 -157
- package/dist/src/accounts/json-rpc/index.d.ts +1 -1
- package/dist/src/accounts/json-rpc/index.js +8 -10
- package/dist/src/accounts/json-rpc/providers.d.ts +1 -1
- package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -1
- package/dist/src/accounts/json-rpc/providers.js +7 -9
- package/dist/src/accounts/kernel.d.ts +3 -3
- package/dist/src/accounts/kernel.js +66 -75
- package/dist/src/accounts/nexus.d.ts +3 -3
- package/dist/src/accounts/nexus.js +62 -73
- package/dist/src/accounts/passport.d.ts +3 -3
- package/dist/src/accounts/passport.js +9 -13
- package/dist/src/accounts/safe.d.ts +3 -3
- package/dist/src/accounts/safe.js +54 -63
- package/dist/src/accounts/signing/common.d.ts +2 -2
- package/dist/src/accounts/signing/common.js +30 -36
- package/dist/src/accounts/signing/message.d.ts +2 -2
- package/dist/src/accounts/signing/message.js +10 -12
- package/dist/src/accounts/signing/passkeys.js +11 -17
- package/dist/src/accounts/signing/typedData.d.ts +1 -1
- package/dist/src/accounts/signing/typedData.js +6 -8
- package/dist/src/accounts/startale.d.ts +3 -3
- package/dist/src/accounts/startale.js +37 -47
- package/dist/src/accounts/utils.d.ts +2 -2
- package/dist/src/accounts/utils.js +22 -28
- package/dist/src/accounts/walletClient.js +4 -8
- package/dist/src/actions/compact.d.ts +1 -1
- package/dist/src/actions/compact.js +22 -35
- package/dist/src/actions/deployment.d.ts +1 -1
- package/dist/src/actions/deployment.js +11 -13
- package/dist/src/actions/ecdsa.d.ts +1 -1
- package/dist/src/actions/ecdsa.js +14 -20
- package/dist/src/actions/index.d.ts +2 -2
- package/dist/src/actions/index.js +6 -10
- package/dist/src/actions/mfa.d.ts +1 -1
- package/dist/src/actions/mfa.js +18 -24
- package/dist/src/actions/passkeys.d.ts +2 -2
- package/dist/src/actions/passkeys.js +14 -20
- package/dist/src/actions/recovery.d.ts +1 -1
- package/dist/src/actions/recovery.js +25 -29
- package/dist/src/actions/smart-sessions.d.ts +1 -1
- package/dist/src/actions/smart-sessions.js +8 -12
- package/dist/src/auth/provider.d.ts +1 -1
- package/dist/src/auth/provider.js +1 -4
- package/dist/src/errors/index.d.ts +4 -4
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +12 -54
- 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 -117
- 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 -11
- 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 +64 -75
- package/dist/src/execution/permit2.d.ts +2 -138
- package/dist/src/execution/permit2.d.ts.map +1 -1
- package/dist/src/execution/permit2.js +5 -239
- package/dist/src/execution/utils.d.ts +31 -15
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +283 -256
- package/dist/src/index.d.ts +15 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +57 -68
- package/dist/src/jwt-server/digest.js +3 -6
- package/dist/src/jwt-server/express.d.ts +1 -1
- package/dist/src/jwt-server/express.d.ts.map +1 -1
- package/dist/src/jwt-server/express.js +6 -7
- package/dist/src/jwt-server/handlers.d.ts +1 -1
- package/dist/src/jwt-server/handlers.js +7 -11
- package/dist/src/jwt-server/index.d.ts +7 -7
- package/dist/src/jwt-server/index.js +6 -17
- package/dist/src/jwt-server/jcs.js +1 -4
- package/dist/src/jwt-server/signer.d.ts +1 -1
- package/dist/src/jwt-server/signer.js +10 -13
- package/dist/src/jwt-server/sponsorship.js +2 -7
- package/dist/src/jwt-server/web.d.ts +1 -1
- package/dist/src/jwt-server/web.js +5 -9
- package/dist/src/modules/abi/smart-session-emissary.js +1 -3
- package/dist/src/modules/abi/smart-sessions.js +1 -4
- package/dist/src/modules/chain-abstraction.js +1 -5
- package/dist/src/modules/common.d.ts +1 -1
- package/dist/src/modules/common.js +1 -13
- package/dist/src/modules/index.d.ts +5 -5
- package/dist/src/modules/index.js +35 -50
- package/dist/src/modules/legacy.d.ts +2 -2
- package/dist/src/modules/legacy.js +11 -14
- package/dist/src/modules/read.d.ts +1 -1
- package/dist/src/modules/read.js +11 -15
- package/dist/src/modules/validators/core.d.ts +2 -2
- package/dist/src/modules/validators/core.js +26 -44
- package/dist/src/modules/validators/index.d.ts +2 -2
- package/dist/src/modules/validators/index.js +3 -19
- package/dist/src/modules/validators/policies/claim/permit2.d.ts +1 -1
- package/dist/src/modules/validators/policies/claim/permit2.js +39 -44
- package/dist/src/modules/validators/policies/claim/types.js +11 -14
- package/dist/src/modules/validators/smart-sessions.d.ts +3 -3
- package/dist/src/modules/validators/smart-sessions.js +65 -94
- 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 +12 -12
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +199 -305
- 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 +3 -9
- 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 -227
- package/dist/src/orchestrator/index.d.ts +9 -9
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +7 -56
- package/dist/src/orchestrator/registry.d.ts +2 -2
- package/dist/src/orchestrator/registry.js +19 -33
- package/dist/src/orchestrator/types.d.ts +97 -232
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/orchestrator/types.js +1 -17
- package/dist/src/orchestrator/utils.js +1 -3
- package/dist/src/types.d.ts +5 -7
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +1 -2
- package/dist/src/utils/index.d.ts +2 -2
- package/dist/src/utils/index.js +9 -15
- package/package.json +15 -98
- 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 -44
- 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 -2
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
function parseTokenAmountsRecord(record) {
|
|
8
|
-
return Object.fromEntries(Object.entries(record).map(([addr, amount]) => [
|
|
9
|
-
addr,
|
|
10
|
-
BigInt(amount),
|
|
11
|
-
]));
|
|
12
|
-
}
|
|
13
|
-
class Orchestrator {
|
|
1
|
+
import { fromCaip2, toCaip2 } from './caip2.js';
|
|
2
|
+
import { API_VERSION, SDK_VERSION } from './consts.js';
|
|
3
|
+
import { OrchestratorError, parseErrorEnvelope, } from './error.js';
|
|
4
|
+
import { convertBigIntFields } from './utils.js';
|
|
5
|
+
export class Orchestrator {
|
|
14
6
|
serverUrl;
|
|
15
7
|
authProvider;
|
|
16
8
|
extraHeaders;
|
|
@@ -19,119 +11,97 @@ class Orchestrator {
|
|
|
19
11
|
this.authProvider = authProvider;
|
|
20
12
|
this.extraHeaders = headers;
|
|
21
13
|
}
|
|
22
|
-
async getPortfolio(
|
|
14
|
+
async getPortfolio(accountAddress, filter) {
|
|
23
15
|
const params = new URLSearchParams();
|
|
24
16
|
if (filter?.chainIds) {
|
|
25
|
-
|
|
17
|
+
for (const id of filter.chainIds) {
|
|
18
|
+
params.append('chainIds', toCaip2(id));
|
|
19
|
+
}
|
|
26
20
|
}
|
|
27
21
|
if (filter?.tokens) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
31
27
|
}
|
|
32
|
-
const url = new URL(`${this.serverUrl}/accounts/${
|
|
28
|
+
const url = new URL(`${this.serverUrl}/accounts/${accountAddress}/portfolio`);
|
|
33
29
|
url.search = params.toString();
|
|
34
30
|
const json = await this.fetch(url.toString(), {
|
|
35
31
|
headers: await this.getHeaders(),
|
|
36
32
|
});
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
symbol:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
chain: chainBalance.chainId,
|
|
47
|
-
address: chainBalance.tokenAddress,
|
|
48
|
-
locked: BigInt(chainBalance.balance.locked),
|
|
49
|
-
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),
|
|
50
42
|
})),
|
|
51
43
|
}));
|
|
52
|
-
return portfolio;
|
|
53
44
|
}
|
|
54
|
-
async
|
|
55
|
-
const body = (
|
|
56
|
-
|
|
45
|
+
async createQuote(input) {
|
|
46
|
+
const body = encodeIntentInput(input);
|
|
47
|
+
const json = await this.fetch(`${this.serverUrl}/quotes`, {
|
|
57
48
|
method: 'POST',
|
|
58
49
|
headers: await this.getHeaders(),
|
|
59
50
|
body: JSON.stringify(body),
|
|
60
51
|
});
|
|
52
|
+
return decodeQuoteResponse(json);
|
|
61
53
|
}
|
|
62
|
-
async
|
|
63
|
-
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`, {
|
|
64
61
|
method: 'POST',
|
|
65
62
|
headers: await this.getHeaders(),
|
|
66
|
-
body: JSON.stringify(
|
|
67
|
-
chainId: input.chain.id,
|
|
68
|
-
tokens: input.tokens,
|
|
69
|
-
settlementLayers: input.settlementLayers,
|
|
70
|
-
})),
|
|
71
|
-
});
|
|
72
|
-
if (response.ok) {
|
|
73
|
-
const json = await response.json();
|
|
74
|
-
return {
|
|
75
|
-
intents: json.intents.map(parseTokenAmountsRecord),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
let errorData = {};
|
|
79
|
-
try {
|
|
80
|
-
errorData = await response.json();
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
try {
|
|
84
|
-
const text = await response.text();
|
|
85
|
-
errorData = { message: text };
|
|
86
|
-
}
|
|
87
|
-
catch { }
|
|
88
|
-
}
|
|
89
|
-
if (response.status === 422 &&
|
|
90
|
-
errorData.error === 'INSUFFICIENT_LIQUIDITY') {
|
|
91
|
-
throw new error_1.InsufficientLiquidityError({
|
|
92
|
-
availableIntents: errorData.availableIntents.map(parseTokenAmountsRecord),
|
|
93
|
-
unfillable: parseTokenAmountsRecord(errorData.unfillable),
|
|
94
|
-
traceId: errorData.traceId,
|
|
95
|
-
statusCode: 422,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
this.parseError({
|
|
99
|
-
response: {
|
|
100
|
-
status: response.status,
|
|
101
|
-
data: errorData,
|
|
102
|
-
headers: {},
|
|
103
|
-
},
|
|
63
|
+
body: JSON.stringify(body),
|
|
104
64
|
});
|
|
105
|
-
|
|
65
|
+
return {
|
|
66
|
+
intents: json.intents.map(parseTokenAmountsRecord),
|
|
67
|
+
};
|
|
106
68
|
}
|
|
107
|
-
async
|
|
108
|
-
const
|
|
109
|
-
if (dryRun) {
|
|
110
|
-
signedIntentOp.options = {
|
|
111
|
-
dryRun: true,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
const body = { signedIntentOp };
|
|
69
|
+
async createIntent(request, policyContext) {
|
|
70
|
+
const body = convertBigIntFields(request);
|
|
115
71
|
const headers = policyContext
|
|
116
72
|
? await this.getSubmitHeaders(policyContext.intentInput, policyContext.isSponsored)
|
|
117
73
|
: await this.getHeaders();
|
|
118
|
-
return await this.fetch(`${this.serverUrl}/
|
|
74
|
+
return await this.fetch(`${this.serverUrl}/intents`, {
|
|
119
75
|
method: 'POST',
|
|
120
76
|
headers,
|
|
121
77
|
body: JSON.stringify(body),
|
|
122
78
|
});
|
|
123
79
|
}
|
|
124
|
-
async
|
|
125
|
-
|
|
80
|
+
async getIntent(intentId) {
|
|
81
|
+
const json = await this.fetch(`${this.serverUrl}/intents/${intentId}`, {
|
|
126
82
|
headers: await this.getHeaders(),
|
|
127
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
|
+
};
|
|
128
98
|
}
|
|
129
99
|
async getHeaders() {
|
|
130
100
|
const auth = await this.authProvider.getHeaders();
|
|
131
101
|
return {
|
|
132
102
|
'Content-Type': 'application/json',
|
|
133
|
-
'x-sdk-version':
|
|
134
|
-
'x-api-version':
|
|
103
|
+
'x-sdk-version': SDK_VERSION,
|
|
104
|
+
'x-api-version': API_VERSION,
|
|
135
105
|
...auth,
|
|
136
106
|
...this.extraHeaders,
|
|
137
107
|
};
|
|
@@ -140,7 +110,8 @@ class Orchestrator {
|
|
|
140
110
|
const auth = await this.authProvider.getSubmitHeaders(intentInput, isSponsored);
|
|
141
111
|
return {
|
|
142
112
|
'Content-Type': 'application/json',
|
|
143
|
-
'x-sdk-version':
|
|
113
|
+
'x-sdk-version': SDK_VERSION,
|
|
114
|
+
'x-api-version': API_VERSION,
|
|
144
115
|
...auth,
|
|
145
116
|
...this.extraHeaders,
|
|
146
117
|
};
|
|
@@ -148,229 +119,152 @@ class Orchestrator {
|
|
|
148
119
|
async fetch(url, options) {
|
|
149
120
|
const response = await fetch(url, options);
|
|
150
121
|
if (!response.ok) {
|
|
151
|
-
let
|
|
122
|
+
let body;
|
|
152
123
|
try {
|
|
153
|
-
|
|
124
|
+
body = await response.json();
|
|
154
125
|
}
|
|
155
126
|
catch {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
127
|
+
body = {
|
|
128
|
+
code: 'INTERNAL_ERROR',
|
|
129
|
+
message: `Request failed with status ${response.status}`,
|
|
130
|
+
traceId: '',
|
|
131
|
+
};
|
|
161
132
|
}
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
response: {
|
|
165
|
-
status: response.status,
|
|
166
|
-
data: errorData,
|
|
167
|
-
headers: {
|
|
168
|
-
retryAfter: retryAfterHeader,
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
});
|
|
133
|
+
const retryAfter = response.headers?.get?.('retry-after') ?? undefined;
|
|
134
|
+
throw parseErrorEnvelope(body, response.status, retryAfter ?? undefined);
|
|
172
135
|
}
|
|
173
136
|
return response.json();
|
|
174
137
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
errorType = 'Forbidden';
|
|
190
|
-
break;
|
|
191
|
-
case 404:
|
|
192
|
-
errorType = 'Not Found';
|
|
193
|
-
break;
|
|
194
|
-
case 409:
|
|
195
|
-
errorType = 'Conflict';
|
|
196
|
-
break;
|
|
197
|
-
case 422:
|
|
198
|
-
errorType = 'Unprocessable Entity';
|
|
199
|
-
break;
|
|
200
|
-
case 429:
|
|
201
|
-
errorType = 'Too Many Requests';
|
|
202
|
-
break;
|
|
203
|
-
case 500:
|
|
204
|
-
errorType = 'Internal Server Error';
|
|
205
|
-
break;
|
|
206
|
-
case 503:
|
|
207
|
-
errorType = 'Service Unavailable';
|
|
208
|
-
break;
|
|
209
|
-
default:
|
|
210
|
-
errorType = 'Unknown';
|
|
211
|
-
}
|
|
212
|
-
const baseParams = {
|
|
213
|
-
context: { traceId },
|
|
214
|
-
errorType,
|
|
215
|
-
traceId,
|
|
216
|
-
statusCode: status,
|
|
217
|
-
};
|
|
218
|
-
if (status === 429) {
|
|
219
|
-
const retryAfter = headers?.retryAfter;
|
|
220
|
-
const context = { traceId, retryAfter };
|
|
221
|
-
throw new error_1.RateLimitedError({
|
|
222
|
-
...baseParams,
|
|
223
|
-
context,
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
if (status === 503) {
|
|
227
|
-
throw new error_1.ServiceUnavailableError(baseParams);
|
|
228
|
-
}
|
|
229
|
-
if (message) {
|
|
230
|
-
this.parseErrorMessage(message, baseParams);
|
|
231
|
-
}
|
|
232
|
-
for (const err of errors) {
|
|
233
|
-
const mergedParams = {
|
|
234
|
-
...baseParams,
|
|
235
|
-
context: { ...err.context, traceId },
|
|
236
|
-
};
|
|
237
|
-
this.parseErrorMessage(err.message, mergedParams);
|
|
238
|
-
}
|
|
239
|
-
switch (status) {
|
|
240
|
-
case 400:
|
|
241
|
-
throw new error_1.BadRequestError({
|
|
242
|
-
...baseParams,
|
|
243
|
-
context: { traceId, errors },
|
|
244
|
-
message: message,
|
|
245
|
-
});
|
|
246
|
-
case 401:
|
|
247
|
-
if (message === 'Authentication is required') {
|
|
248
|
-
throw new error_1.AuthenticationRequiredError(baseParams);
|
|
249
|
-
}
|
|
250
|
-
throw new error_1.UnauthorizedError(baseParams);
|
|
251
|
-
case 403:
|
|
252
|
-
throw new error_1.ForbiddenError(baseParams);
|
|
253
|
-
case 404:
|
|
254
|
-
throw new error_1.ResourceNotFoundError(baseParams);
|
|
255
|
-
case 409:
|
|
256
|
-
throw new error_1.ConflictError(baseParams);
|
|
257
|
-
case 500:
|
|
258
|
-
if (errors && errors.length > 0) {
|
|
259
|
-
const mergedParams = {
|
|
260
|
-
...baseParams,
|
|
261
|
-
context: { ...errors[0].context, traceId },
|
|
262
|
-
};
|
|
263
|
-
throw new error_1.OrchestratorError({
|
|
264
|
-
...mergedParams,
|
|
265
|
-
message: errors[0].message || 'Internal Server Error',
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
throw new error_1.InternalServerError(baseParams);
|
|
269
|
-
default:
|
|
270
|
-
throw new error_1.OrchestratorError({
|
|
271
|
-
...baseParams,
|
|
272
|
-
message: message || errorType,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
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);
|
|
276
152
|
}
|
|
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
|
-
|
|
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,
|
|
313
242
|
}
|
|
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
|
-
throw new error_1.NoPathFoundError(errorParams);
|
|
339
|
-
}
|
|
340
|
-
else if (message === 'Emissary is not enabled' ||
|
|
341
|
-
message === 'Emissary is not the expected address') {
|
|
342
|
-
throw new error_1.ForbiddenError(errorParams);
|
|
343
|
-
}
|
|
344
|
-
else if (message.includes('No such intent with nonce') ||
|
|
345
|
-
message === 'Order bundle not found') {
|
|
346
|
-
throw new error_1.IntentNotFoundError(errorParams);
|
|
347
|
-
}
|
|
348
|
-
else if (message === 'Could not retrieve a valid quote from any aggregator') {
|
|
349
|
-
throw new error_1.NoPathFoundError(errorParams);
|
|
350
|
-
}
|
|
351
|
-
else if (message === 'No aggregators available for swap') {
|
|
352
|
-
throw new error_1.InternalServerError(errorParams);
|
|
353
|
-
}
|
|
354
|
-
else if (message === 'entity.parse.failed' ||
|
|
355
|
-
message === 'entity.too.large' ||
|
|
356
|
-
message === 'encoding.unsupported') {
|
|
357
|
-
throw new error_1.BodyParserError({ message, ...errorParams });
|
|
358
|
-
}
|
|
359
|
-
else if (message === 'Bundle simulation failed') {
|
|
360
|
-
const simulations = errorParams.context.error.simulations;
|
|
361
|
-
const { traceId, errorType, statusCode, context } = errorParams;
|
|
362
|
-
throw new error_1.SimulationFailedError({
|
|
363
|
-
message,
|
|
364
|
-
context,
|
|
365
|
-
errorType,
|
|
366
|
-
traceId,
|
|
367
|
-
statusCode,
|
|
368
|
-
simulations,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
throw new error_1.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
|
+
};
|
|
373
267
|
}
|
|
374
268
|
}
|
|
269
|
+
return out;
|
|
375
270
|
}
|
|
376
|
-
exports.Orchestrator = Orchestrator;
|
|
@@ -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 = "
|
|
4
|
-
declare const API_VERSION = "2026-
|
|
3
|
+
declare const SDK_VERSION = "2.0.0-beta.1";
|
|
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,iBAAiB,CAAA;AAClC,QAAA,MAAM,WAAW,kBAAkB,CAAA;AAEnC,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,WAAW,EACX,WAAW,GACZ,CAAA"}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.API_VERSION = exports.SDK_VERSION = exports.RHINESTONE_SPOKE_POOL_ADDRESS = exports.PROD_ORCHESTRATOR_URL = void 0;
|
|
4
1
|
const PROD_ORCHESTRATOR_URL = 'https://v1.orchestrator.rhinestone.dev';
|
|
5
|
-
exports.PROD_ORCHESTRATOR_URL = PROD_ORCHESTRATOR_URL;
|
|
6
2
|
const RHINESTONE_SPOKE_POOL_ADDRESS = '0x000000000060f6e853447881951574cdd0663530';
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const API_VERSION = '2026-01.alps';
|
|
11
|
-
exports.API_VERSION = API_VERSION;
|
|
3
|
+
const SDK_VERSION = '2.0.0-beta.1';
|
|
4
|
+
const API_VERSION = '2026-04.blanc';
|
|
5
|
+
export { PROD_ORCHESTRATOR_URL, RHINESTONE_SPOKE_POOL_ADDRESS, SDK_VERSION, API_VERSION, };
|