@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,283 +1,173 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimulationFailedError = exports.BodyParserError = exports.InternalServerError = exports.UnprocessableEntityError = exports.BadRequestError = exports.ConflictError = exports.ResourceNotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.ServiceUnavailableError = exports.RateLimitedError = exports.SchemaValidationError = exports.IntentNotFoundError = exports.NoPathFoundError = exports.OnlyOneTargetTokenAmountCanBeUnsetError = exports.InvalidIntentSignatureError = exports.InvalidApiKeyError = exports.AuthenticationRequiredError = exports.TokenNotSupportedError = exports.UnsupportedTokenError = exports.UnsupportedChainError = exports.UnsupportedChainIdError = exports.InsufficientBalanceError = exports.InsufficientLiquidityError = exports.OrchestratorError = void 0;
|
|
4
|
-
exports.isOrchestratorError = isOrchestratorError;
|
|
5
|
-
exports.isRetryable = isRetryable;
|
|
6
|
-
exports.isAuthError = isAuthError;
|
|
7
|
-
exports.isValidationError = isValidationError;
|
|
8
|
-
exports.isRateLimited = isRateLimited;
|
|
9
1
|
class OrchestratorError extends Error {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
_traceId;
|
|
14
|
-
_statusCode;
|
|
2
|
+
code;
|
|
3
|
+
traceId;
|
|
4
|
+
statusCode;
|
|
15
5
|
constructor(params) {
|
|
16
|
-
super();
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this._traceId = params?.traceId || '';
|
|
21
|
-
this._statusCode = params?.statusCode;
|
|
22
|
-
}
|
|
23
|
-
get message() {
|
|
24
|
-
return this._message;
|
|
25
|
-
}
|
|
26
|
-
get context() {
|
|
27
|
-
return this._context;
|
|
28
|
-
}
|
|
29
|
-
get errorType() {
|
|
30
|
-
return this._errorType;
|
|
31
|
-
}
|
|
32
|
-
get traceId() {
|
|
33
|
-
return this._traceId;
|
|
34
|
-
}
|
|
35
|
-
get statusCode() {
|
|
36
|
-
return this._statusCode;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.OrchestratorError = OrchestratorError;
|
|
40
|
-
class InsufficientBalanceError extends OrchestratorError {
|
|
41
|
-
constructor(params) {
|
|
42
|
-
super({
|
|
43
|
-
message: 'Insufficient balance',
|
|
44
|
-
...params,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.InsufficientBalanceError = InsufficientBalanceError;
|
|
49
|
-
class UnsupportedChainIdError extends OrchestratorError {
|
|
50
|
-
constructor(params) {
|
|
51
|
-
super({
|
|
52
|
-
message: 'Unsupported chain id',
|
|
53
|
-
...params,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.UnsupportedChainIdError = UnsupportedChainIdError;
|
|
58
|
-
class UnsupportedChainError extends OrchestratorError {
|
|
59
|
-
constructor(chainId, params) {
|
|
60
|
-
super({
|
|
61
|
-
message: `Unsupported chain ${chainId}`,
|
|
62
|
-
...params,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.UnsupportedChainError = UnsupportedChainError;
|
|
67
|
-
class UnsupportedTokenError extends OrchestratorError {
|
|
68
|
-
constructor(tokenSymbol, chainId, params) {
|
|
69
|
-
super({
|
|
70
|
-
message: `Unsupported token ${tokenSymbol} for chain ${chainId}`,
|
|
71
|
-
...params,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.UnsupportedTokenError = UnsupportedTokenError;
|
|
76
|
-
class TokenNotSupportedError extends OrchestratorError {
|
|
77
|
-
constructor(tokenAddress, chainId, params) {
|
|
78
|
-
super({
|
|
79
|
-
message: `Token ${tokenAddress} not supported on chain ${chainId}`,
|
|
80
|
-
...params,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.TokenNotSupportedError = TokenNotSupportedError;
|
|
85
|
-
class AuthenticationRequiredError extends OrchestratorError {
|
|
86
|
-
constructor(params) {
|
|
87
|
-
super({
|
|
88
|
-
message: 'Authentication is required',
|
|
89
|
-
...params,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.AuthenticationRequiredError = AuthenticationRequiredError;
|
|
94
|
-
class InvalidApiKeyError extends OrchestratorError {
|
|
95
|
-
constructor(params) {
|
|
96
|
-
super({
|
|
97
|
-
message: 'Invalid API key',
|
|
98
|
-
...params,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.InvalidApiKeyError = InvalidApiKeyError;
|
|
103
|
-
class InvalidIntentSignatureError extends OrchestratorError {
|
|
104
|
-
constructor(params) {
|
|
105
|
-
super({
|
|
106
|
-
message: 'Invalid intent signature',
|
|
107
|
-
...params,
|
|
108
|
-
});
|
|
6
|
+
super(params.message);
|
|
7
|
+
this.code = params.code ?? 'UNKNOWN';
|
|
8
|
+
this.traceId = params.traceId ?? '';
|
|
9
|
+
this.statusCode = params.statusCode;
|
|
109
10
|
}
|
|
110
11
|
}
|
|
111
|
-
|
|
112
|
-
|
|
12
|
+
class ValidationError extends OrchestratorError {
|
|
13
|
+
issues;
|
|
113
14
|
constructor(params) {
|
|
114
|
-
super({
|
|
115
|
-
|
|
116
|
-
...params,
|
|
117
|
-
});
|
|
15
|
+
super({ ...params, code: 'VALIDATION_ERROR' });
|
|
16
|
+
this.issues = params.issues ?? [];
|
|
118
17
|
}
|
|
119
18
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
super({
|
|
124
|
-
message: 'No Path Found',
|
|
125
|
-
...params,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.NoPathFoundError = NoPathFoundError;
|
|
130
|
-
class IntentNotFoundError extends OrchestratorError {
|
|
131
|
-
constructor(params) {
|
|
132
|
-
super({
|
|
133
|
-
message: 'Intent not found',
|
|
134
|
-
...params,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.IntentNotFoundError = IntentNotFoundError;
|
|
139
|
-
class SchemaValidationError extends OrchestratorError {
|
|
140
|
-
constructor(params) {
|
|
141
|
-
super({
|
|
142
|
-
message: params?.message || 'Schema validation error',
|
|
143
|
-
...params,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
exports.SchemaValidationError = SchemaValidationError;
|
|
148
|
-
class RateLimitedError extends OrchestratorError {
|
|
19
|
+
class InsufficientLiquidityError extends OrchestratorError {
|
|
20
|
+
availableIntents;
|
|
21
|
+
unfillable;
|
|
149
22
|
constructor(params) {
|
|
150
|
-
super({
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
23
|
+
super({ ...params, code: 'INSUFFICIENT_LIQUIDITY' });
|
|
24
|
+
this.availableIntents = params.availableIntents;
|
|
25
|
+
this.unfillable = params.unfillable;
|
|
154
26
|
}
|
|
155
27
|
}
|
|
156
|
-
|
|
157
|
-
class ServiceUnavailableError extends OrchestratorError {
|
|
28
|
+
class NotFoundError extends OrchestratorError {
|
|
158
29
|
constructor(params) {
|
|
159
|
-
super({
|
|
160
|
-
message: 'Service Unavailable',
|
|
161
|
-
...params,
|
|
162
|
-
});
|
|
30
|
+
super({ ...params, code: 'NOT_FOUND' });
|
|
163
31
|
}
|
|
164
32
|
}
|
|
165
|
-
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
166
33
|
class UnauthorizedError extends OrchestratorError {
|
|
167
34
|
constructor(params) {
|
|
168
|
-
super({
|
|
169
|
-
message: 'Unauthorized',
|
|
170
|
-
...params,
|
|
171
|
-
});
|
|
35
|
+
super({ ...params, code: 'UNAUTHORIZED' });
|
|
172
36
|
}
|
|
173
37
|
}
|
|
174
|
-
exports.UnauthorizedError = UnauthorizedError;
|
|
175
38
|
class ForbiddenError extends OrchestratorError {
|
|
176
39
|
constructor(params) {
|
|
177
|
-
super({
|
|
178
|
-
message: 'Forbidden',
|
|
179
|
-
...params,
|
|
180
|
-
});
|
|
40
|
+
super({ ...params, code: 'FORBIDDEN' });
|
|
181
41
|
}
|
|
182
42
|
}
|
|
183
|
-
|
|
184
|
-
class ResourceNotFoundError extends OrchestratorError {
|
|
43
|
+
class ConflictError extends OrchestratorError {
|
|
185
44
|
constructor(params) {
|
|
186
|
-
super({
|
|
187
|
-
message: 'Not Found',
|
|
188
|
-
...params,
|
|
189
|
-
});
|
|
45
|
+
super({ ...params, code: 'CONFLICT' });
|
|
190
46
|
}
|
|
191
47
|
}
|
|
192
|
-
|
|
193
|
-
class ConflictError extends OrchestratorError {
|
|
48
|
+
class UnprocessableContentError extends OrchestratorError {
|
|
194
49
|
constructor(params) {
|
|
195
|
-
super({
|
|
196
|
-
message: 'Conflict',
|
|
197
|
-
...params,
|
|
198
|
-
});
|
|
50
|
+
super({ ...params, code: 'UNPROCESSABLE_CONTENT' });
|
|
199
51
|
}
|
|
200
52
|
}
|
|
201
|
-
|
|
202
|
-
|
|
53
|
+
class RateLimitedError extends OrchestratorError {
|
|
54
|
+
retryAfter;
|
|
203
55
|
constructor(params) {
|
|
204
|
-
super({
|
|
205
|
-
|
|
206
|
-
...params,
|
|
207
|
-
});
|
|
56
|
+
super({ ...params, code: 'TOO_MANY_REQUESTS' });
|
|
57
|
+
this.retryAfter = params.retryAfter;
|
|
208
58
|
}
|
|
209
59
|
}
|
|
210
|
-
|
|
211
|
-
class UnprocessableEntityError extends OrchestratorError {
|
|
60
|
+
class SettlementQuoteError extends OrchestratorError {
|
|
212
61
|
constructor(params) {
|
|
213
|
-
super({
|
|
214
|
-
message: params?.message || 'Unprocessable Entity',
|
|
215
|
-
...params,
|
|
216
|
-
});
|
|
62
|
+
super({ ...params, code: 'SETTLEMENT_QUOTE_ERROR' });
|
|
217
63
|
}
|
|
218
64
|
}
|
|
219
|
-
|
|
220
|
-
class InternalServerError extends OrchestratorError {
|
|
65
|
+
class SettlementExecutionError extends OrchestratorError {
|
|
221
66
|
constructor(params) {
|
|
222
|
-
super({
|
|
223
|
-
message: 'Internal Server Error',
|
|
224
|
-
...params,
|
|
225
|
-
});
|
|
67
|
+
super({ ...params, code: 'SETTLEMENT_EXECUTION_ERROR' });
|
|
226
68
|
}
|
|
227
69
|
}
|
|
228
|
-
|
|
229
|
-
class BodyParserError extends OrchestratorError {
|
|
70
|
+
class ExternalServiceTimeoutError extends OrchestratorError {
|
|
230
71
|
constructor(params) {
|
|
231
|
-
super({
|
|
232
|
-
message: params?.message || 'Body parser error',
|
|
233
|
-
...params,
|
|
234
|
-
});
|
|
72
|
+
super({ ...params, code: 'EXTERNAL_SERVICE_TIMEOUT' });
|
|
235
73
|
}
|
|
236
74
|
}
|
|
237
|
-
|
|
238
|
-
class SimulationFailedError extends OrchestratorError {
|
|
75
|
+
class RelayerMarketUnavailableError extends OrchestratorError {
|
|
239
76
|
constructor(params) {
|
|
240
|
-
super({
|
|
241
|
-
message: params?.message || 'Simulation failed',
|
|
242
|
-
...params,
|
|
243
|
-
});
|
|
77
|
+
super({ ...params, code: 'RELAYER_MARKET_UNAVAILABLE' });
|
|
244
78
|
}
|
|
245
79
|
}
|
|
246
|
-
|
|
247
|
-
class InsufficientLiquidityError extends OrchestratorError {
|
|
248
|
-
availableIntents;
|
|
249
|
-
unfillable;
|
|
80
|
+
class InternalServerError extends OrchestratorError {
|
|
250
81
|
constructor(params) {
|
|
251
|
-
super({
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
82
|
+
super({ ...params, code: 'INTERNAL_ERROR' });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Thrown by the SDK's local token/chain registry — not an orchestrator API
|
|
87
|
+
* error. Distinct from `OrchestratorError` so consumers can catch them
|
|
88
|
+
* separately from server-side failures.
|
|
89
|
+
*/
|
|
90
|
+
class UnsupportedChainError extends Error {
|
|
91
|
+
chainId;
|
|
92
|
+
constructor(chainId) {
|
|
93
|
+
super(`Unsupported chain ${chainId}`);
|
|
94
|
+
this.chainId = chainId;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
class UnsupportedTokenError extends Error {
|
|
98
|
+
tokenSymbol;
|
|
99
|
+
chainId;
|
|
100
|
+
constructor(tokenSymbol, chainId) {
|
|
101
|
+
super(`Unsupported token ${tokenSymbol} for chain ${chainId}`);
|
|
102
|
+
this.tokenSymbol = tokenSymbol;
|
|
103
|
+
this.chainId = chainId;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function parseTokenAmounts(record) {
|
|
107
|
+
return Object.fromEntries(Object.entries(record).map(([addr, amount]) => [addr, BigInt(amount)]));
|
|
108
|
+
}
|
|
109
|
+
function parseErrorEnvelope(envelope, statusCode, retryAfter) {
|
|
110
|
+
const base = {
|
|
111
|
+
message: envelope.message,
|
|
112
|
+
traceId: envelope.traceId,
|
|
113
|
+
statusCode,
|
|
114
|
+
};
|
|
115
|
+
switch (envelope.code) {
|
|
116
|
+
case 'VALIDATION_ERROR': {
|
|
117
|
+
const issues = Array.isArray(envelope.details)
|
|
118
|
+
? envelope.details
|
|
119
|
+
: [];
|
|
120
|
+
return new ValidationError({ ...base, issues });
|
|
121
|
+
}
|
|
122
|
+
case 'INSUFFICIENT_LIQUIDITY': {
|
|
123
|
+
const details = (envelope.details ?? {});
|
|
124
|
+
return new InsufficientLiquidityError({
|
|
125
|
+
...base,
|
|
126
|
+
availableIntents: (details.availableIntents ?? []).map(parseTokenAmounts),
|
|
127
|
+
unfillable: parseTokenAmounts(details.unfillable ?? {}),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
case 'NOT_FOUND':
|
|
131
|
+
return new NotFoundError(base);
|
|
132
|
+
case 'UNAUTHORIZED':
|
|
133
|
+
return new UnauthorizedError(base);
|
|
134
|
+
case 'FORBIDDEN':
|
|
135
|
+
return new ForbiddenError(base);
|
|
136
|
+
case 'CONFLICT':
|
|
137
|
+
return new ConflictError(base);
|
|
138
|
+
case 'UNPROCESSABLE_CONTENT':
|
|
139
|
+
return new UnprocessableContentError(base);
|
|
140
|
+
case 'TOO_MANY_REQUESTS':
|
|
141
|
+
return new RateLimitedError({ ...base, retryAfter });
|
|
142
|
+
case 'SETTLEMENT_QUOTE_ERROR':
|
|
143
|
+
return new SettlementQuoteError(base);
|
|
144
|
+
case 'SETTLEMENT_EXECUTION_ERROR':
|
|
145
|
+
return new SettlementExecutionError(base);
|
|
146
|
+
case 'EXTERNAL_SERVICE_TIMEOUT':
|
|
147
|
+
return new ExternalServiceTimeoutError(base);
|
|
148
|
+
case 'RELAYER_MARKET_UNAVAILABLE':
|
|
149
|
+
return new RelayerMarketUnavailableError(base);
|
|
150
|
+
case 'INTERNAL_ERROR':
|
|
151
|
+
return new InternalServerError(base);
|
|
152
|
+
default:
|
|
153
|
+
return new OrchestratorError({ ...base, code: 'UNKNOWN' });
|
|
259
154
|
}
|
|
260
155
|
}
|
|
261
|
-
exports.InsufficientLiquidityError = InsufficientLiquidityError;
|
|
262
156
|
function isOrchestratorError(error) {
|
|
263
157
|
return error instanceof OrchestratorError;
|
|
264
158
|
}
|
|
265
159
|
function isRateLimited(error) {
|
|
266
|
-
return
|
|
267
|
-
(error instanceof OrchestratorError && error.statusCode === 429));
|
|
160
|
+
return error instanceof RateLimitedError;
|
|
268
161
|
}
|
|
269
162
|
function isValidationError(error) {
|
|
270
|
-
|
|
271
|
-
return false;
|
|
272
|
-
return error.statusCode === 400 || error.statusCode === 422;
|
|
163
|
+
return error instanceof ValidationError;
|
|
273
164
|
}
|
|
274
165
|
function isAuthError(error) {
|
|
275
|
-
|
|
276
|
-
return false;
|
|
277
|
-
return (error.statusCode === 401 || error instanceof AuthenticationRequiredError);
|
|
166
|
+
return error instanceof UnauthorizedError || error instanceof ForbiddenError;
|
|
278
167
|
}
|
|
279
168
|
function isRetryable(error) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
169
|
+
return (error instanceof InternalServerError ||
|
|
170
|
+
error instanceof ExternalServiceTimeoutError ||
|
|
171
|
+
error instanceof RelayerMarketUnavailableError);
|
|
283
172
|
}
|
|
173
|
+
export { parseErrorEnvelope, isOrchestratorError, isRetryable, isAuthError, isValidationError, isRateLimited, OrchestratorError, ValidationError, InsufficientLiquidityError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError, UnprocessableContentError, RateLimitedError, SettlementQuoteError, SettlementExecutionError, ExternalServiceTimeoutError, RelayerMarketUnavailableError, InternalServerError, UnsupportedChainError, UnsupportedTokenError, };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AuthProvider } from '../auth/provider';
|
|
2
|
-
import { Orchestrator } from './client';
|
|
3
|
-
import { RHINESTONE_SPOKE_POOL_ADDRESS } from './consts';
|
|
4
|
-
import {
|
|
5
|
-
import { getAllSupportedChainsAndTokens, getSupportedTokens, getTokenAddress, getTokenDecimals, getTokenSymbol, getWethAddress, isTokenAddressSupported } from './registry';
|
|
6
|
-
import type { ApprovalRequired, AuxiliaryFunds, Execution,
|
|
7
|
-
import { INTENT_STATUS_CLAIMED, INTENT_STATUS_COMPLETED, INTENT_STATUS_EXPIRED, INTENT_STATUS_FAILED, INTENT_STATUS_FILLED, INTENT_STATUS_PENDING, INTENT_STATUS_PRECONFIRMED } from './types';
|
|
1
|
+
import type { AuthProvider } from '../auth/provider.js';
|
|
2
|
+
import { Orchestrator } from './client.js';
|
|
3
|
+
import { RHINESTONE_SPOKE_POOL_ADDRESS } from './consts.js';
|
|
4
|
+
import { ConflictError, ExternalServiceTimeoutError, ForbiddenError, InsufficientLiquidityError, InternalServerError, isAuthError, isOrchestratorError, isRateLimited, isRetryable, isValidationError, NotFoundError, OrchestratorError, RateLimitedError, RelayerMarketUnavailableError, SettlementExecutionError, SettlementQuoteError, UnauthorizedError, UnprocessableContentError, UnsupportedChainError, UnsupportedTokenError, ValidationError } from './error.js';
|
|
5
|
+
import { getAllSupportedChainsAndTokens, getSupportedTokens, getTokenAddress, getTokenDecimals, getTokenSymbol, getWethAddress, isTokenAddressSupported } from './registry.js';
|
|
6
|
+
import type { ApprovalRequired, AuxiliaryFunds, Cost, CostTokenEntry, EstimatedFillTime, Execution, FeeBreakdown, Fees, FeeToken, IntentInput, IntentOpStatus, IntentOptions, IntentSubmitRequest, IntentSubmitResponse, Portfolio, Price, Quote, QuoteResponse, SettlementLayer, SignatureMode, SignData, SignedAuthorization, SplitIntentsInput, SplitIntentsResult, SponsorSettings, SupportedChain, TokenConfig, TokenRequirements, TypedDataDefinition, UsdAmount, WrapRequired } from './types.js';
|
|
7
|
+
import { INTENT_STATUS_CLAIMED, INTENT_STATUS_COMPLETED, INTENT_STATUS_EXPIRED, INTENT_STATUS_FAILED, INTENT_STATUS_FILLED, INTENT_STATUS_PENDING, INTENT_STATUS_PRECONFIRMED } from './types.js';
|
|
8
8
|
declare function getOrchestrator(authProvider: AuthProvider, orchestratorUrl?: string, headers?: Record<string, string>): Orchestrator;
|
|
9
|
-
export type { AuxiliaryFunds, Execution,
|
|
10
|
-
export { INTENT_STATUS_PENDING, INTENT_STATUS_EXPIRED, INTENT_STATUS_COMPLETED, INTENT_STATUS_FILLED, INTENT_STATUS_FAILED, INTENT_STATUS_PRECONFIRMED, INTENT_STATUS_CLAIMED, RHINESTONE_SPOKE_POOL_ADDRESS, Orchestrator,
|
|
9
|
+
export type { ApprovalRequired, AuxiliaryFunds, Cost, CostTokenEntry, EstimatedFillTime, Execution, FeeBreakdown, Fees, FeeToken, IntentInput, IntentOpStatus, IntentOptions, IntentSubmitRequest, IntentSubmitResponse, Portfolio, Price, Quote, QuoteResponse, SettlementLayer, SignatureMode, SignData, SignedAuthorization, SplitIntentsInput, SplitIntentsResult, SponsorSettings, SupportedChain, TokenConfig, TokenRequirements, TypedDataDefinition, UsdAmount, WrapRequired, };
|
|
10
|
+
export { INTENT_STATUS_PENDING, INTENT_STATUS_EXPIRED, INTENT_STATUS_COMPLETED, INTENT_STATUS_FILLED, INTENT_STATUS_FAILED, INTENT_STATUS_PRECONFIRMED, INTENT_STATUS_CLAIMED, RHINESTONE_SPOKE_POOL_ADDRESS, Orchestrator, ConflictError, ExternalServiceTimeoutError, ForbiddenError, InsufficientLiquidityError, InternalServerError, NotFoundError, OrchestratorError, RateLimitedError, RelayerMarketUnavailableError, SettlementExecutionError, SettlementQuoteError, UnauthorizedError, UnprocessableContentError, UnsupportedChainError, UnsupportedTokenError, ValidationError, getOrchestrator, getWethAddress, getTokenSymbol, getTokenAddress, getTokenDecimals, getSupportedTokens, getAllSupportedChainsAndTokens, isOrchestratorError, isRetryable, isAuthError, isValidationError, isRateLimited, isTokenAddressSupported, };
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../orchestrator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAyB,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAC/E,OAAO,EACL,2BAA2B,EAC3B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../orchestrator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAyB,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAC/E,OAAO,EACL,aAAa,EACb,2BAA2B,EAC3B,cAAc,EACd,0BAA0B,EAC1B,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,6BAA6B,EAC7B,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EAChB,MAAM,SAAS,CAAA;AAChB,OAAO,EACL,8BAA8B,EAC9B,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,uBAAuB,EACxB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,IAAI,EACJ,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,SAAS,EACT,KAAK,EACL,KAAK,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,SAAS,CAAA;AAEhB,iBAAS,eAAe,CACtB,YAAY,EAAE,YAAY,EAC1B,eAAe,CAAC,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,YAAY,CAMd;AAED,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,IAAI,EACJ,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,SAAS,EACT,KAAK,EACL,KAAK,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,GACb,CAAA;AACD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,qBAAqB,EACrB,6BAA6B,EAC7B,YAAY,EACZ,aAAa,EACb,2BAA2B,EAC3B,cAAc,EACd,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,6BAA6B,EAC7B,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,8BAA8B,EAC9B,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,uBAAuB,GACxB,CAAA"}
|
|
@@ -1,58 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "Orchestrator", { enumerable: true, get: function () { return client_1.Orchestrator; } });
|
|
7
|
-
const consts_1 = require("./consts");
|
|
8
|
-
Object.defineProperty(exports, "RHINESTONE_SPOKE_POOL_ADDRESS", { enumerable: true, get: function () { return consts_1.RHINESTONE_SPOKE_POOL_ADDRESS; } });
|
|
9
|
-
const error_1 = require("./error");
|
|
10
|
-
Object.defineProperty(exports, "AuthenticationRequiredError", { enumerable: true, get: function () { return error_1.AuthenticationRequiredError; } });
|
|
11
|
-
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return error_1.BadRequestError; } });
|
|
12
|
-
Object.defineProperty(exports, "BodyParserError", { enumerable: true, get: function () { return error_1.BodyParserError; } });
|
|
13
|
-
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return error_1.ConflictError; } });
|
|
14
|
-
Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return error_1.ForbiddenError; } });
|
|
15
|
-
Object.defineProperty(exports, "InsufficientBalanceError", { enumerable: true, get: function () { return error_1.InsufficientBalanceError; } });
|
|
16
|
-
Object.defineProperty(exports, "InsufficientLiquidityError", { enumerable: true, get: function () { return error_1.InsufficientLiquidityError; } });
|
|
17
|
-
Object.defineProperty(exports, "IntentNotFoundError", { enumerable: true, get: function () { return error_1.IntentNotFoundError; } });
|
|
18
|
-
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_1.InternalServerError; } });
|
|
19
|
-
Object.defineProperty(exports, "InvalidApiKeyError", { enumerable: true, get: function () { return error_1.InvalidApiKeyError; } });
|
|
20
|
-
Object.defineProperty(exports, "InvalidIntentSignatureError", { enumerable: true, get: function () { return error_1.InvalidIntentSignatureError; } });
|
|
21
|
-
Object.defineProperty(exports, "isAuthError", { enumerable: true, get: function () { return error_1.isAuthError; } });
|
|
22
|
-
Object.defineProperty(exports, "isOrchestratorError", { enumerable: true, get: function () { return error_1.isOrchestratorError; } });
|
|
23
|
-
Object.defineProperty(exports, "isRateLimited", { enumerable: true, get: function () { return error_1.isRateLimited; } });
|
|
24
|
-
Object.defineProperty(exports, "isRetryable", { enumerable: true, get: function () { return error_1.isRetryable; } });
|
|
25
|
-
Object.defineProperty(exports, "isValidationError", { enumerable: true, get: function () { return error_1.isValidationError; } });
|
|
26
|
-
Object.defineProperty(exports, "NoPathFoundError", { enumerable: true, get: function () { return error_1.NoPathFoundError; } });
|
|
27
|
-
Object.defineProperty(exports, "OnlyOneTargetTokenAmountCanBeUnsetError", { enumerable: true, get: function () { return error_1.OnlyOneTargetTokenAmountCanBeUnsetError; } });
|
|
28
|
-
Object.defineProperty(exports, "OrchestratorError", { enumerable: true, get: function () { return error_1.OrchestratorError; } });
|
|
29
|
-
Object.defineProperty(exports, "RateLimitedError", { enumerable: true, get: function () { return error_1.RateLimitedError; } });
|
|
30
|
-
Object.defineProperty(exports, "ResourceNotFoundError", { enumerable: true, get: function () { return error_1.ResourceNotFoundError; } });
|
|
31
|
-
Object.defineProperty(exports, "SchemaValidationError", { enumerable: true, get: function () { return error_1.SchemaValidationError; } });
|
|
32
|
-
Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return error_1.ServiceUnavailableError; } });
|
|
33
|
-
Object.defineProperty(exports, "SimulationFailedError", { enumerable: true, get: function () { return error_1.SimulationFailedError; } });
|
|
34
|
-
Object.defineProperty(exports, "TokenNotSupportedError", { enumerable: true, get: function () { return error_1.TokenNotSupportedError; } });
|
|
35
|
-
Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return error_1.UnauthorizedError; } });
|
|
36
|
-
Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return error_1.UnprocessableEntityError; } });
|
|
37
|
-
Object.defineProperty(exports, "UnsupportedChainError", { enumerable: true, get: function () { return error_1.UnsupportedChainError; } });
|
|
38
|
-
Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, get: function () { return error_1.UnsupportedChainIdError; } });
|
|
39
|
-
Object.defineProperty(exports, "UnsupportedTokenError", { enumerable: true, get: function () { return error_1.UnsupportedTokenError; } });
|
|
40
|
-
const registry_1 = require("./registry");
|
|
41
|
-
Object.defineProperty(exports, "getAllSupportedChainsAndTokens", { enumerable: true, get: function () { return registry_1.getAllSupportedChainsAndTokens; } });
|
|
42
|
-
Object.defineProperty(exports, "getSupportedTokens", { enumerable: true, get: function () { return registry_1.getSupportedTokens; } });
|
|
43
|
-
Object.defineProperty(exports, "getTokenAddress", { enumerable: true, get: function () { return registry_1.getTokenAddress; } });
|
|
44
|
-
Object.defineProperty(exports, "getTokenDecimals", { enumerable: true, get: function () { return registry_1.getTokenDecimals; } });
|
|
45
|
-
Object.defineProperty(exports, "getTokenSymbol", { enumerable: true, get: function () { return registry_1.getTokenSymbol; } });
|
|
46
|
-
Object.defineProperty(exports, "getWethAddress", { enumerable: true, get: function () { return registry_1.getWethAddress; } });
|
|
47
|
-
Object.defineProperty(exports, "isTokenAddressSupported", { enumerable: true, get: function () { return registry_1.isTokenAddressSupported; } });
|
|
48
|
-
const types_1 = require("./types");
|
|
49
|
-
Object.defineProperty(exports, "INTENT_STATUS_CLAIMED", { enumerable: true, get: function () { return types_1.INTENT_STATUS_CLAIMED; } });
|
|
50
|
-
Object.defineProperty(exports, "INTENT_STATUS_COMPLETED", { enumerable: true, get: function () { return types_1.INTENT_STATUS_COMPLETED; } });
|
|
51
|
-
Object.defineProperty(exports, "INTENT_STATUS_EXPIRED", { enumerable: true, get: function () { return types_1.INTENT_STATUS_EXPIRED; } });
|
|
52
|
-
Object.defineProperty(exports, "INTENT_STATUS_FAILED", { enumerable: true, get: function () { return types_1.INTENT_STATUS_FAILED; } });
|
|
53
|
-
Object.defineProperty(exports, "INTENT_STATUS_FILLED", { enumerable: true, get: function () { return types_1.INTENT_STATUS_FILLED; } });
|
|
54
|
-
Object.defineProperty(exports, "INTENT_STATUS_PENDING", { enumerable: true, get: function () { return types_1.INTENT_STATUS_PENDING; } });
|
|
55
|
-
Object.defineProperty(exports, "INTENT_STATUS_PRECONFIRMED", { enumerable: true, get: function () { return types_1.INTENT_STATUS_PRECONFIRMED; } });
|
|
1
|
+
import { Orchestrator } from './client.js';
|
|
2
|
+
import { PROD_ORCHESTRATOR_URL, RHINESTONE_SPOKE_POOL_ADDRESS } from './consts.js';
|
|
3
|
+
import { ConflictError, ExternalServiceTimeoutError, ForbiddenError, InsufficientLiquidityError, InternalServerError, isAuthError, isOrchestratorError, isRateLimited, isRetryable, isValidationError, NotFoundError, OrchestratorError, RateLimitedError, RelayerMarketUnavailableError, SettlementExecutionError, SettlementQuoteError, UnauthorizedError, UnprocessableContentError, UnsupportedChainError, UnsupportedTokenError, ValidationError, } from './error.js';
|
|
4
|
+
import { getAllSupportedChainsAndTokens, getSupportedTokens, getTokenAddress, getTokenDecimals, getTokenSymbol, getWethAddress, isTokenAddressSupported, } from './registry.js';
|
|
5
|
+
import { INTENT_STATUS_CLAIMED, INTENT_STATUS_COMPLETED, INTENT_STATUS_EXPIRED, INTENT_STATUS_FAILED, INTENT_STATUS_FILLED, INTENT_STATUS_PENDING, INTENT_STATUS_PRECONFIRMED, } from './types.js';
|
|
56
6
|
function getOrchestrator(authProvider, orchestratorUrl, headers) {
|
|
57
|
-
return new
|
|
7
|
+
return new Orchestrator(orchestratorUrl ?? PROD_ORCHESTRATOR_URL, authProvider, headers);
|
|
58
8
|
}
|
|
9
|
+
export { INTENT_STATUS_PENDING, INTENT_STATUS_EXPIRED, INTENT_STATUS_COMPLETED, INTENT_STATUS_FILLED, INTENT_STATUS_FAILED, INTENT_STATUS_PRECONFIRMED, INTENT_STATUS_CLAIMED, RHINESTONE_SPOKE_POOL_ADDRESS, Orchestrator, ConflictError, ExternalServiceTimeoutError, ForbiddenError, InsufficientLiquidityError, InternalServerError, NotFoundError, OrchestratorError, RateLimitedError, RelayerMarketUnavailableError, SettlementExecutionError, SettlementQuoteError, UnauthorizedError, UnprocessableContentError, UnsupportedChainError, UnsupportedTokenError, ValidationError, getOrchestrator, getWethAddress, getTokenSymbol, getTokenAddress, getTokenDecimals, getSupportedTokens, getAllSupportedChainsAndTokens, isOrchestratorError, isRetryable, isAuthError, isValidationError, isRateLimited, isTokenAddressSupported, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Address, type Chain } from 'viem';
|
|
2
|
-
import type { TokenSymbol } from '../types';
|
|
3
|
-
import type { TokenConfig } from './types';
|
|
2
|
+
import type { TokenSymbol } from '../types.js';
|
|
3
|
+
import type { TokenConfig } from './types.js';
|
|
4
4
|
declare function getSupportedChainIds(): number[];
|
|
5
5
|
declare function getWethAddress(chain: Chain): Address;
|
|
6
6
|
declare function getWrappedTokenAddress(chain: Chain): Address;
|
|
@@ -1,54 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getTokenAddress = getTokenAddress;
|
|
5
|
-
exports.getTokenDecimals = getTokenDecimals;
|
|
6
|
-
exports.getWethAddress = getWethAddress;
|
|
7
|
-
exports.getWrappedTokenAddress = getWrappedTokenAddress;
|
|
8
|
-
exports.getChainById = getChainById;
|
|
9
|
-
exports.getSupportedTokens = getSupportedTokens;
|
|
10
|
-
exports.getSupportedChainIds = getSupportedChainIds;
|
|
11
|
-
exports.isTestnet = isTestnet;
|
|
12
|
-
exports.isTokenAddressSupported = isTokenAddressSupported;
|
|
13
|
-
exports.getDefaultAccountAccessList = getDefaultAccountAccessList;
|
|
14
|
-
exports.resolveTokenAddress = resolveTokenAddress;
|
|
15
|
-
exports.getAllSupportedChainsAndTokens = getAllSupportedChainsAndTokens;
|
|
16
|
-
const shared_configs_1 = require("@rhinestone/shared-configs");
|
|
17
|
-
const viem_1 = require("viem");
|
|
18
|
-
const error_1 = require("./error");
|
|
1
|
+
import { chainRegistry, chains, } from '@rhinestone/shared-configs';
|
|
2
|
+
import { isAddress } from 'viem';
|
|
3
|
+
import { UnsupportedChainError, UnsupportedTokenError } from './error.js';
|
|
19
4
|
function getSupportedChainIds() {
|
|
20
|
-
return
|
|
5
|
+
return chains.map((chain) => chain.id);
|
|
21
6
|
}
|
|
22
7
|
function getChainEntry(chainId) {
|
|
23
|
-
return
|
|
8
|
+
return chainRegistry[chainId.toString()];
|
|
24
9
|
}
|
|
25
10
|
function getWethAddress(chain) {
|
|
26
11
|
const chainEntry = getChainEntry(chain.id);
|
|
27
12
|
if (!chainEntry) {
|
|
28
|
-
throw new
|
|
13
|
+
throw new UnsupportedChainError(chain.id);
|
|
29
14
|
}
|
|
30
15
|
const wethToken = chainEntry.tokens.find((token) => token.symbol === 'WETH');
|
|
31
16
|
if (!wethToken) {
|
|
32
|
-
throw new
|
|
17
|
+
throw new UnsupportedTokenError('WETH', chain.id);
|
|
33
18
|
}
|
|
34
19
|
return wethToken.address;
|
|
35
20
|
}
|
|
36
21
|
function getWrappedTokenAddress(chain) {
|
|
37
22
|
const chainEntry = getChainEntry(chain.id);
|
|
38
23
|
if (!chainEntry) {
|
|
39
|
-
throw new
|
|
24
|
+
throw new UnsupportedChainError(chain.id);
|
|
40
25
|
}
|
|
41
26
|
const token = chainEntry.wrappedNativeToken ??
|
|
42
27
|
chainEntry.tokens.find((t) => t.symbol === 'WETH');
|
|
43
28
|
if (!token) {
|
|
44
|
-
throw new
|
|
29
|
+
throw new UnsupportedTokenError('WETH', chain.id);
|
|
45
30
|
}
|
|
46
31
|
return token.address;
|
|
47
32
|
}
|
|
48
33
|
function getTokenSymbol(tokenAddress, chainId) {
|
|
49
34
|
const chainEntry = getChainEntry(chainId);
|
|
50
35
|
if (!chainEntry) {
|
|
51
|
-
throw new
|
|
36
|
+
throw new UnsupportedChainError(chainId);
|
|
52
37
|
}
|
|
53
38
|
const token = chainEntry.tokens.find((t) => t.address.toLowerCase() === tokenAddress.toLowerCase());
|
|
54
39
|
return token?.symbol;
|
|
@@ -56,29 +41,29 @@ function getTokenSymbol(tokenAddress, chainId) {
|
|
|
56
41
|
function getTokenAddress(tokenSymbol, chainId) {
|
|
57
42
|
const chainEntry = getChainEntry(chainId);
|
|
58
43
|
if (!chainEntry) {
|
|
59
|
-
throw new
|
|
44
|
+
throw new UnsupportedChainError(chainId);
|
|
60
45
|
}
|
|
61
46
|
const token = chainEntry.tokens.find((t) => t.symbol === tokenSymbol);
|
|
62
47
|
if (!token) {
|
|
63
|
-
throw new
|
|
48
|
+
throw new UnsupportedTokenError(tokenSymbol, chainId);
|
|
64
49
|
}
|
|
65
50
|
return token.address;
|
|
66
51
|
}
|
|
67
52
|
function getTokenDecimals(tokenSymbol, chainId) {
|
|
68
53
|
const chainEntry = getChainEntry(chainId);
|
|
69
54
|
if (!chainEntry) {
|
|
70
|
-
throw new
|
|
55
|
+
throw new UnsupportedChainError(chainId);
|
|
71
56
|
}
|
|
72
57
|
const token = chainEntry.tokens.find((t) => t.symbol === tokenSymbol);
|
|
73
58
|
if (!token) {
|
|
74
|
-
throw new
|
|
59
|
+
throw new UnsupportedTokenError(tokenSymbol, chainId);
|
|
75
60
|
}
|
|
76
61
|
return token.decimals;
|
|
77
62
|
}
|
|
78
63
|
function getChainById(chainId) {
|
|
79
|
-
const chain =
|
|
64
|
+
const chain = chains.find((chain) => chain.id === chainId);
|
|
80
65
|
if (!chain) {
|
|
81
|
-
throw new
|
|
66
|
+
throw new UnsupportedChainError(chainId);
|
|
82
67
|
}
|
|
83
68
|
return chain;
|
|
84
69
|
}
|
|
@@ -96,7 +81,7 @@ function isTokenAddressSupported(address, chainId) {
|
|
|
96
81
|
function getSupportedTokens(chainId) {
|
|
97
82
|
const chainEntry = getChainEntry(chainId);
|
|
98
83
|
if (!chainEntry) {
|
|
99
|
-
throw new
|
|
84
|
+
throw new UnsupportedChainError(chainId);
|
|
100
85
|
}
|
|
101
86
|
return chainEntry.tokens;
|
|
102
87
|
}
|
|
@@ -115,7 +100,7 @@ function getDefaultAccountAccessList(onTestnets) {
|
|
|
115
100
|
};
|
|
116
101
|
}
|
|
117
102
|
function resolveTokenAddress(token, chainId) {
|
|
118
|
-
if (
|
|
103
|
+
if (isAddress(token)) {
|
|
119
104
|
return token;
|
|
120
105
|
}
|
|
121
106
|
return getTokenAddress(token, chainId);
|
|
@@ -127,3 +112,4 @@ function getAllSupportedChainsAndTokens() {
|
|
|
127
112
|
tokens: getSupportedTokens(chainId),
|
|
128
113
|
}));
|
|
129
114
|
}
|
|
115
|
+
export { getTokenSymbol, getTokenAddress, getTokenDecimals, getWethAddress, getWrappedTokenAddress, getChainById, getSupportedTokens, getSupportedChainIds, isTestnet, isTokenAddressSupported, getDefaultAccountAccessList, resolveTokenAddress, getAllSupportedChainsAndTokens, };
|