@rhinestone/sdk 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -42,6 +42,13 @@ declare class IntentFailedError extends ExecutionError {
|
|
|
42
42
|
traceId?: string;
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
declare class IntentStatusTimeoutError extends ExecutionError {
|
|
46
|
+
constructor(params?: {
|
|
47
|
+
context?: any;
|
|
48
|
+
errorType?: string;
|
|
49
|
+
traceId?: string;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
45
52
|
declare function isExecutionError(error: Error): error is ExecutionError;
|
|
46
|
-
export { isExecutionError, ExecutionError, OrderPathRequiredForIntentsError, SessionChainRequiredError, IntentFailedError, SignerNotSupportedError, };
|
|
53
|
+
export { isExecutionError, ExecutionError, OrderPathRequiredForIntentsError, SessionChainRequiredError, IntentFailedError, IntentStatusTimeoutError, SignerNotSupportedError, };
|
|
47
54
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../execution/error.ts"],"names":[],"mappings":"AAAA,cAAM,cAAe,SAAQ,KAAK;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAK;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAErB,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;IAQD,IAAI,OAAO,WAEV;IAED,IAAI,OAAO,QAEV;IAED,IAAI,SAAS,WAEZ;IAED,IAAI,OAAO,WAEV;CACF;AAED,cAA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AAyB,EACzB,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,GACxB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SignerNotSupportedError = exports.IntentFailedError = exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.ExecutionError = void 0;
|
|
3
|
+
exports.SignerNotSupportedError = exports.IntentStatusTimeoutError = exports.IntentFailedError = exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.ExecutionError = void 0;
|
|
4
4
|
exports.isExecutionError = isExecutionError;
|
|
5
5
|
class ExecutionError extends Error {
|
|
6
6
|
_message;
|
|
@@ -64,6 +64,15 @@ class IntentFailedError extends ExecutionError {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
exports.IntentFailedError = IntentFailedError;
|
|
67
|
+
class IntentStatusTimeoutError extends ExecutionError {
|
|
68
|
+
constructor(params) {
|
|
69
|
+
super({
|
|
70
|
+
message: 'Intent status polling timed out',
|
|
71
|
+
...params,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.IntentStatusTimeoutError = IntentStatusTimeoutError;
|
|
67
76
|
function isExecutionError(error) {
|
|
68
77
|
return error instanceof ExecutionError;
|
|
69
78
|
}
|
|
@@ -2,7 +2,7 @@ import { type Address, type Chain, type Hex } from 'viem';
|
|
|
2
2
|
import type { UserOperationReceipt } from 'viem/_types/account-abstraction';
|
|
3
3
|
import type { SettlementLayer } from '../orchestrator/types';
|
|
4
4
|
import type { CalldataInput, CallInput, RhinestoneAccountConfig, RhinestoneConfig, SignerSet, SourceAssetInput, TokenRequest, TokenSymbol, Transaction, UserOperationTransaction } from '../types';
|
|
5
|
-
import { ExecutionError, IntentFailedError, isExecutionError, OrderPathRequiredForIntentsError, SessionChainRequiredError, SignerNotSupportedError } from './error';
|
|
5
|
+
import { ExecutionError, IntentFailedError, IntentStatusTimeoutError, isExecutionError, OrderPathRequiredForIntentsError, SessionChainRequiredError, SignerNotSupportedError } from './error';
|
|
6
6
|
import type { TransactionResult, UserOperationResult } from './utils';
|
|
7
7
|
interface TransactionStatus {
|
|
8
8
|
fill: {
|
|
@@ -31,6 +31,6 @@ declare function sendUserOperationInternal(config: RhinestoneConfig, chain: Chai
|
|
|
31
31
|
declare function waitForExecution(config: RhinestoneConfig, result: TransactionResult | UserOperationResult, acceptsPreconfirmations: boolean): Promise<TransactionStatus | UserOperationReceipt>;
|
|
32
32
|
declare function getMaxSpendableAmount(config: RhinestoneConfig, chain: Chain, tokenAddress: Address, gasUnits: bigint, sponsored?: boolean): Promise<bigint>;
|
|
33
33
|
declare function getPortfolio(config: RhinestoneConfig, onTestnets: boolean): Promise<import("../orchestrator").Portfolio>;
|
|
34
|
-
export { sendTransaction, sendTransactionInternal, sendUserOperation, sendUserOperationInternal, waitForExecution, getMaxSpendableAmount, getPortfolio, isExecutionError, ExecutionError, IntentFailedError, OrderPathRequiredForIntentsError, SessionChainRequiredError, SignerNotSupportedError, };
|
|
34
|
+
export { sendTransaction, sendTransactionInternal, sendUserOperation, sendUserOperationInternal, waitForExecution, getMaxSpendableAmount, getPortfolio, isExecutionError, ExecutionError, IntentFailedError, IntentStatusTimeoutError, OrderPathRequiredForIntentsError, SessionChainRequiredError, SignerNotSupportedError, };
|
|
35
35
|
export type { TransactionStatus, TransactionResult, UserOperationResult };
|
|
36
36
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../execution/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAsB,KAAK,GAAG,EAAE,MAAM,MAAM,CAAA;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["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"__esModule", { value: true });
|
|
3
|
-
exports.SignerNotSupportedError = exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.IntentFailedError = exports.ExecutionError = exports.isExecutionError = void 0;
|
|
3
|
+
exports.SignerNotSupportedError = exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.IntentStatusTimeoutError = exports.IntentFailedError = exports.ExecutionError = exports.isExecutionError = void 0;
|
|
4
4
|
exports.sendTransaction = sendTransaction;
|
|
5
5
|
exports.sendTransactionInternal = sendTransactionInternal;
|
|
6
6
|
exports.sendUserOperation = sendUserOperation;
|
|
@@ -17,13 +17,19 @@ const registry_1 = require("../orchestrator/registry");
|
|
|
17
17
|
const error_1 = require("./error");
|
|
18
18
|
Object.defineProperty(exports, "ExecutionError", { enumerable: true, get: function () { return error_1.ExecutionError; } });
|
|
19
19
|
Object.defineProperty(exports, "IntentFailedError", { enumerable: true, get: function () { return error_1.IntentFailedError; } });
|
|
20
|
+
Object.defineProperty(exports, "IntentStatusTimeoutError", { enumerable: true, get: function () { return error_1.IntentStatusTimeoutError; } });
|
|
20
21
|
Object.defineProperty(exports, "isExecutionError", { enumerable: true, get: function () { return error_1.isExecutionError; } });
|
|
21
22
|
Object.defineProperty(exports, "OrderPathRequiredForIntentsError", { enumerable: true, get: function () { return error_1.OrderPathRequiredForIntentsError; } });
|
|
22
23
|
Object.defineProperty(exports, "SessionChainRequiredError", { enumerable: true, get: function () { return error_1.SessionChainRequiredError; } });
|
|
23
24
|
Object.defineProperty(exports, "SignerNotSupportedError", { enumerable: true, get: function () { return error_1.SignerNotSupportedError; } });
|
|
24
25
|
const smart_session_1 = require("./smart-session");
|
|
25
26
|
const utils_2 = require("./utils");
|
|
26
|
-
const
|
|
27
|
+
const POLL_INITIAL_MS = 500;
|
|
28
|
+
const POLL_SLOW_AFTER_MS = 5000;
|
|
29
|
+
const POLL_SLOW_MS = 2000;
|
|
30
|
+
const POLL_MAX_WAIT_MS = 180000;
|
|
31
|
+
const POLL_ERROR_BACKOFF_MS = 1000;
|
|
32
|
+
const POLL_ERROR_BACKOFF_MAX_MS = 10000;
|
|
27
33
|
async function sendTransaction(config, transaction) {
|
|
28
34
|
const sourceChains = 'chain' in transaction
|
|
29
35
|
? [transaction.chain]
|
|
@@ -117,10 +123,56 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
|
|
|
117
123
|
switch (result.type) {
|
|
118
124
|
case 'intent': {
|
|
119
125
|
let intentStatus = null;
|
|
126
|
+
const startTs = Date.now();
|
|
127
|
+
let nextDelayMs = POLL_INITIAL_MS;
|
|
128
|
+
let errorBackoffMs = POLL_ERROR_BACKOFF_MS;
|
|
120
129
|
while (intentStatus === null || !validStatuses.has(intentStatus.status)) {
|
|
130
|
+
const now = Date.now();
|
|
131
|
+
if (now - startTs >= POLL_MAX_WAIT_MS) {
|
|
132
|
+
throw new error_1.IntentStatusTimeoutError({
|
|
133
|
+
context: { waitedMs: now - startTs },
|
|
134
|
+
});
|
|
135
|
+
}
|
|
121
136
|
const orchestrator = (0, utils_2.getOrchestratorByChain)(result.targetChain, config.apiKey, config.endpointUrl);
|
|
122
|
-
|
|
123
|
-
|
|
137
|
+
try {
|
|
138
|
+
intentStatus = await orchestrator.getIntentOpStatus(result.id);
|
|
139
|
+
// reset error backoff on success
|
|
140
|
+
errorBackoffMs = POLL_ERROR_BACKOFF_MS;
|
|
141
|
+
const elapsed = Date.now() - startTs;
|
|
142
|
+
nextDelayMs =
|
|
143
|
+
elapsed >= POLL_SLOW_AFTER_MS ? POLL_SLOW_MS : POLL_INITIAL_MS;
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, nextDelayMs));
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
if ((0, orchestrator_1.isRateLimited)(err)) {
|
|
148
|
+
const retryAfter = err?.context?.retryAfter;
|
|
149
|
+
let retryMs = nextDelayMs;
|
|
150
|
+
if (retryAfter) {
|
|
151
|
+
const parsed = Number(retryAfter);
|
|
152
|
+
if (!Number.isNaN(parsed)) {
|
|
153
|
+
retryMs = Math.max(parsed * 1000, nextDelayMs);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const asDate = Date.parse(retryAfter);
|
|
157
|
+
if (!Number.isNaN(asDate)) {
|
|
158
|
+
retryMs = Math.max(asDate - Date.now(), nextDelayMs);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
retryMs = Math.max(POLL_SLOW_MS, nextDelayMs);
|
|
164
|
+
}
|
|
165
|
+
await new Promise((resolve) => setTimeout(resolve, retryMs));
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if ((0, orchestrator_1.isRetryable)(err)) {
|
|
169
|
+
const backoff = Math.min(errorBackoffMs, POLL_ERROR_BACKOFF_MAX_MS);
|
|
170
|
+
errorBackoffMs = Math.min(errorBackoffMs * 2, POLL_ERROR_BACKOFF_MAX_MS);
|
|
171
|
+
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
throw err;
|
|
175
|
+
}
|
|
124
176
|
}
|
|
125
177
|
if (intentStatus.status === orchestrator_1.INTENT_STATUS_FAILED) {
|
|
126
178
|
throw new error_1.IntentFailedError();
|