@rhinestone/sdk 1.0.41-alpha.0 → 1.0.41
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/dist/src/accounts/error.d.ts +114 -0
- package/dist/src/accounts/error.d.ts.map +1 -0
- package/dist/src/accounts/error.js +174 -0
- package/dist/src/accounts/index.d.ts +50 -0
- package/dist/src/accounts/index.d.ts.map +1 -0
- package/dist/src/accounts/index.js +669 -0
- package/dist/src/accounts/index.test.d.ts +2 -0
- package/dist/src/accounts/index.test.d.ts.map +1 -0
- package/dist/src/accounts/index.test.js +33 -0
- package/dist/src/accounts/json-rpc/index.d.ts +5 -0
- package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/index.js +20 -0
- package/dist/src/accounts/json-rpc/index.test.d.ts +2 -0
- package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/index.test.js +33 -0
- package/dist/src/accounts/json-rpc/providers.d.ts +5 -0
- package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/providers.js +22 -0
- package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
- package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/providers.test.js +43 -0
- package/dist/src/accounts/kernel.d.ts +29 -0
- package/dist/src/accounts/kernel.d.ts.map +1 -0
- package/dist/src/accounts/kernel.js +297 -0
- package/dist/src/accounts/kernel.test.d.ts +2 -0
- package/dist/src/accounts/kernel.test.d.ts.map +1 -0
- package/dist/src/accounts/kernel.test.js +132 -0
- package/dist/src/accounts/nexus.d.ts +35 -0
- package/dist/src/accounts/nexus.d.ts.map +1 -0
- package/dist/src/accounts/nexus.js +471 -0
- package/dist/src/accounts/nexus.test.d.ts +2 -0
- package/dist/src/accounts/nexus.test.d.ts.map +1 -0
- package/dist/src/accounts/nexus.test.js +118 -0
- package/dist/src/accounts/passport.d.ts +12 -0
- package/dist/src/accounts/passport.d.ts.map +1 -0
- package/dist/src/accounts/passport.js +173 -0
- package/dist/src/accounts/safe.d.ts +35 -0
- package/dist/src/accounts/safe.d.ts.map +1 -0
- package/dist/src/accounts/safe.js +365 -0
- package/dist/src/accounts/safe.test.d.ts +2 -0
- package/dist/src/accounts/safe.test.d.ts.map +1 -0
- package/dist/src/accounts/safe.test.js +118 -0
- package/dist/src/accounts/signing/common.d.ts +27 -0
- package/dist/src/accounts/signing/common.d.ts.map +1 -0
- package/dist/src/accounts/signing/common.js +183 -0
- package/dist/src/accounts/signing/message.d.ts +5 -0
- package/dist/src/accounts/signing/message.d.ts.map +1 -0
- package/dist/src/accounts/signing/message.js +47 -0
- package/dist/src/accounts/signing/passkeys.d.ts +36 -0
- package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
- package/dist/src/accounts/signing/passkeys.js +125 -0
- package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
- package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
- package/dist/src/accounts/signing/passkeys.test.js +88 -0
- package/dist/src/accounts/signing/typedData.d.ts +5 -0
- package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
- package/dist/src/accounts/signing/typedData.js +35 -0
- package/dist/src/accounts/startale.d.ts +27 -0
- package/dist/src/accounts/startale.d.ts.map +1 -0
- package/dist/src/accounts/startale.js +116 -0
- package/dist/src/accounts/startale.test.d.ts +2 -0
- package/dist/src/accounts/startale.test.d.ts.map +1 -0
- package/dist/src/accounts/startale.test.js +92 -0
- package/dist/src/accounts/utils.d.ts +33 -0
- package/dist/src/accounts/utils.d.ts.map +1 -0
- package/dist/src/accounts/utils.js +208 -0
- package/dist/src/accounts/utils.test.d.ts +2 -0
- package/dist/src/accounts/utils.test.d.ts.map +1 -0
- package/dist/src/accounts/utils.test.js +49 -0
- package/dist/src/accounts/walletClient.d.ts +34 -0
- package/dist/src/accounts/walletClient.d.ts.map +1 -0
- package/dist/src/accounts/walletClient.js +121 -0
- package/dist/src/actions/compact.d.ts +13 -0
- package/dist/src/actions/compact.d.ts.map +1 -0
- package/dist/src/actions/compact.js +210 -0
- package/dist/src/actions/deployment.d.ts +19 -0
- package/dist/src/actions/deployment.d.ts.map +1 -0
- package/dist/src/actions/deployment.js +78 -0
- package/dist/src/actions/ecdsa.d.ts +35 -0
- package/dist/src/actions/ecdsa.d.ts.map +1 -0
- package/dist/src/actions/ecdsa.js +114 -0
- package/dist/src/actions/ecdsa.test.d.ts +2 -0
- package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
- package/dist/src/actions/ecdsa.test.js +99 -0
- package/dist/src/actions/index.d.ts +17 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/index.js +53 -0
- package/dist/src/actions/mfa.d.ts +37 -0
- package/dist/src/actions/mfa.d.ts.map +1 -0
- package/dist/src/actions/mfa.js +133 -0
- package/dist/src/actions/passkeys.d.ts +37 -0
- package/dist/src/actions/passkeys.d.ts.map +1 -0
- package/dist/src/actions/passkeys.js +129 -0
- package/dist/src/actions/passkeys.test.d.ts +2 -0
- package/dist/src/actions/passkeys.test.d.ts.map +1 -0
- package/dist/src/actions/passkeys.test.js +54 -0
- package/dist/src/actions/recovery.d.ts +33 -0
- package/dist/src/actions/recovery.d.ts.map +1 -0
- package/dist/src/actions/recovery.js +193 -0
- package/dist/src/actions/recovery.test.d.ts +2 -0
- package/dist/src/actions/recovery.test.d.ts.map +1 -0
- package/dist/src/actions/recovery.test.js +168 -0
- package/dist/src/actions/smart-sessions.d.ts +14 -0
- package/dist/src/actions/smart-sessions.d.ts.map +1 -0
- package/dist/src/actions/smart-sessions.js +16 -0
- package/dist/src/errors/index.d.ts +5 -0
- package/dist/src/errors/index.d.ts.map +1 -0
- package/dist/src/errors/index.js +53 -0
- package/dist/src/execution/compact.d.ts +151 -0
- package/dist/src/execution/compact.d.ts.map +1 -0
- package/dist/src/execution/compact.js +122 -0
- package/dist/src/execution/error.d.ts +61 -0
- package/dist/src/execution/error.d.ts.map +1 -0
- package/dist/src/execution/error.js +87 -0
- package/dist/src/execution/index.d.ts +41 -0
- package/dist/src/execution/index.d.ts.map +1 -0
- package/dist/src/execution/index.js +233 -0
- package/dist/src/execution/permit2.d.ts +148 -0
- package/dist/src/execution/permit2.d.ts.map +1 -0
- package/dist/src/execution/permit2.js +291 -0
- package/dist/src/execution/singleChainOps.d.ts +28 -0
- package/dist/src/execution/singleChainOps.d.ts.map +1 -0
- package/dist/src/execution/singleChainOps.js +32 -0
- package/dist/src/execution/smart-session.d.ts +13 -0
- package/dist/src/execution/smart-session.d.ts.map +1 -0
- package/dist/src/execution/smart-session.js +178 -0
- package/dist/src/execution/types.d.ts +36 -0
- package/dist/src/execution/types.d.ts.map +1 -0
- package/dist/src/execution/types.js +2 -0
- package/dist/src/execution/utils.d.ts +83 -0
- package/dist/src/execution/utils.d.ts.map +1 -0
- package/dist/src/execution/utils.js +705 -0
- package/dist/src/index.d.ts +74 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +317 -0
- package/dist/src/modules/abi/smart-sessions.d.ts +104 -0
- package/dist/src/modules/abi/smart-sessions.d.ts.map +1 -0
- package/dist/src/modules/abi/smart-sessions.js +131 -0
- package/dist/src/modules/chain-abstraction.d.ts +5 -0
- package/dist/src/modules/chain-abstraction.d.ts.map +1 -0
- package/dist/src/modules/chain-abstraction.js +7 -0
- package/dist/src/modules/common.d.ts +30 -0
- package/dist/src/modules/common.d.ts.map +1 -0
- package/dist/src/modules/common.js +42 -0
- package/dist/src/modules/index.d.ts +10 -0
- package/dist/src/modules/index.d.ts.map +1 -0
- package/dist/src/modules/index.js +94 -0
- package/dist/src/modules/index.test.d.ts +2 -0
- package/dist/src/modules/index.test.d.ts.map +1 -0
- package/dist/src/modules/index.test.js +81 -0
- package/dist/src/modules/legacy.d.ts +10 -0
- package/dist/src/modules/legacy.d.ts.map +1 -0
- package/dist/src/modules/legacy.js +65 -0
- package/dist/src/modules/read.d.ts +9 -0
- package/dist/src/modules/read.d.ts.map +1 -0
- package/dist/src/modules/read.js +125 -0
- package/dist/src/modules/validators/core.d.ts +29 -0
- package/dist/src/modules/validators/core.d.ts.map +1 -0
- package/dist/src/modules/validators/core.js +278 -0
- package/dist/src/modules/validators/core.test.d.ts +2 -0
- package/dist/src/modules/validators/core.test.d.ts.map +1 -0
- package/dist/src/modules/validators/core.test.js +101 -0
- package/dist/src/modules/validators/index.d.ts +4 -0
- package/dist/src/modules/validators/index.d.ts.map +1 -0
- package/dist/src/modules/validators/index.js +15 -0
- package/dist/src/modules/validators/smart-sessions.d.ts +96 -0
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -0
- package/dist/src/modules/validators/smart-sessions.js +497 -0
- package/dist/src/modules/validators/smart-sessions.test.d.ts +2 -0
- package/dist/src/modules/validators/smart-sessions.test.d.ts.map +1 -0
- package/dist/src/modules/validators/smart-sessions.test.js +219 -0
- package/dist/src/orchestrator/client.d.ts +27 -0
- package/dist/src/orchestrator/client.d.ts.map +1 -0
- package/dist/src/orchestrator/client.js +354 -0
- package/dist/src/orchestrator/consts.d.ts +5 -0
- package/dist/src/orchestrator/consts.d.ts.map +1 -0
- package/dist/src/orchestrator/consts.js +9 -0
- package/dist/src/orchestrator/error.d.ts +232 -0
- package/dist/src/orchestrator/error.d.ts.map +1 -0
- package/dist/src/orchestrator/error.js +268 -0
- package/dist/src/orchestrator/index.d.ts +10 -0
- package/dist/src/orchestrator/index.d.ts.map +1 -0
- package/dist/src/orchestrator/index.js +57 -0
- package/dist/src/orchestrator/registry.d.ts +22 -0
- package/dist/src/orchestrator/registry.d.ts.map +1 -0
- package/dist/src/orchestrator/registry.js +121 -0
- package/dist/src/orchestrator/registry.test.d.ts +2 -0
- package/dist/src/orchestrator/registry.test.d.ts.map +1 -0
- package/dist/src/orchestrator/registry.test.js +150 -0
- package/dist/src/orchestrator/types.d.ts +295 -0
- package/dist/src/orchestrator/types.d.ts.map +1 -0
- package/dist/src/orchestrator/types.js +17 -0
- package/dist/src/orchestrator/utils.d.ts +3 -0
- package/dist/src/orchestrator/utils.d.ts.map +1 -0
- package/dist/src/orchestrator/utils.js +24 -0
- package/dist/src/types.d.ts +284 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/utils/index.d.ts +26 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +63 -0
- package/dist/test/consts.d.ts +10 -0
- package/dist/test/consts.d.ts.map +1 -0
- package/dist/test/consts.js +22 -0
- package/dist/test/utils/utils.d.ts +5 -0
- package/dist/test/utils/utils.d.ts.map +1 -0
- package/dist/test/utils/utils.js +20 -0
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMPACT_ADDRESS = void 0;
|
|
4
|
+
exports.getCompactTypedData = getCompactTypedData;
|
|
5
|
+
exports.getCompactDigest = getCompactDigest;
|
|
6
|
+
exports.getPermit2Digest = getPermit2Digest;
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const permit2_1 = require("./permit2");
|
|
9
|
+
const COMPACT_ADDRESS = '0x00000000000000171ede64904551eeDF3C6C9788';
|
|
10
|
+
exports.COMPACT_ADDRESS = COMPACT_ADDRESS;
|
|
11
|
+
// Define the typed data structure as const to preserve type safety
|
|
12
|
+
const COMPACT_TYPED_DATA_TYPES = {
|
|
13
|
+
MultichainCompact: [
|
|
14
|
+
{ name: 'sponsor', type: 'address' },
|
|
15
|
+
{ name: 'nonce', type: 'uint256' },
|
|
16
|
+
{ name: 'expires', type: 'uint256' },
|
|
17
|
+
{ name: 'elements', type: 'Element[]' },
|
|
18
|
+
],
|
|
19
|
+
Element: [
|
|
20
|
+
{ name: 'arbiter', type: 'address' },
|
|
21
|
+
{ name: 'chainId', type: 'uint256' },
|
|
22
|
+
{ name: 'commitments', type: 'Lock[]' },
|
|
23
|
+
{ name: 'mandate', type: 'Mandate' },
|
|
24
|
+
],
|
|
25
|
+
Lock: [
|
|
26
|
+
{ name: 'lockTag', type: 'bytes12' },
|
|
27
|
+
{ name: 'token', type: 'address' },
|
|
28
|
+
{ name: 'amount', type: 'uint256' },
|
|
29
|
+
],
|
|
30
|
+
Mandate: [
|
|
31
|
+
{ name: 'target', type: 'Target' },
|
|
32
|
+
{ name: 'v', type: 'uint8' },
|
|
33
|
+
{ name: 'minGas', type: 'uint128' },
|
|
34
|
+
{ name: 'originOps', type: 'Op[]' },
|
|
35
|
+
{ name: 'destOps', type: 'Op[]' },
|
|
36
|
+
{ name: 'q', type: 'bytes32' },
|
|
37
|
+
],
|
|
38
|
+
Target: [
|
|
39
|
+
{ name: 'recipient', type: 'address' },
|
|
40
|
+
{ name: 'tokenOut', type: 'Token[]' },
|
|
41
|
+
{ name: 'targetChain', type: 'uint256' },
|
|
42
|
+
{ name: 'fillExpiry', type: 'uint256' },
|
|
43
|
+
],
|
|
44
|
+
Token: [
|
|
45
|
+
{ name: 'token', type: 'address' },
|
|
46
|
+
{ name: 'amount', type: 'uint256' },
|
|
47
|
+
],
|
|
48
|
+
Op: [
|
|
49
|
+
{ name: 'to', type: 'address' },
|
|
50
|
+
{ name: 'value', type: 'uint256' },
|
|
51
|
+
{ name: 'data', type: 'bytes' },
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
function getCompactTypedData(intentOp) {
|
|
55
|
+
const typedData = {
|
|
56
|
+
domain: {
|
|
57
|
+
name: 'The Compact',
|
|
58
|
+
version: '1',
|
|
59
|
+
chainId: Number(intentOp.elements[0].chainId),
|
|
60
|
+
verifyingContract: '0x73d2dc0c21fca4ec1601895d50df7f5624f07d3f',
|
|
61
|
+
},
|
|
62
|
+
types: COMPACT_TYPED_DATA_TYPES,
|
|
63
|
+
primaryType: 'MultichainCompact',
|
|
64
|
+
message: {
|
|
65
|
+
sponsor: intentOp.sponsor,
|
|
66
|
+
nonce: BigInt(intentOp.nonce),
|
|
67
|
+
expires: BigInt(intentOp.expires),
|
|
68
|
+
elements: intentOp.elements.map((element) => ({
|
|
69
|
+
arbiter: element.arbiter,
|
|
70
|
+
chainId: BigInt(element.chainId),
|
|
71
|
+
commitments: element.idsAndAmounts.map((token) => ({
|
|
72
|
+
lockTag: (0, viem_1.slice)((0, viem_1.toHex)(BigInt(token[0])), 0, 12),
|
|
73
|
+
token: (0, viem_1.slice)((0, viem_1.toHex)(BigInt(token[0])), 12, 32),
|
|
74
|
+
amount: BigInt(token[1]),
|
|
75
|
+
})),
|
|
76
|
+
mandate: {
|
|
77
|
+
target: {
|
|
78
|
+
recipient: element.mandate.recipient,
|
|
79
|
+
tokenOut: element.mandate.tokenOut.map((token) => ({
|
|
80
|
+
token: (0, viem_1.slice)((0, viem_1.toHex)(BigInt(token[0])), 12, 32),
|
|
81
|
+
amount: BigInt(token[1]),
|
|
82
|
+
})),
|
|
83
|
+
targetChain: BigInt(element.mandate.destinationChainId),
|
|
84
|
+
fillExpiry: BigInt(element.mandate.fillDeadline),
|
|
85
|
+
},
|
|
86
|
+
v: element.mandate.v,
|
|
87
|
+
minGas: BigInt(element.mandate.minGas),
|
|
88
|
+
originOps: element.mandate.preClaimOps.map((op) => ({
|
|
89
|
+
to: op.to,
|
|
90
|
+
value: BigInt(op.value),
|
|
91
|
+
data: op.data,
|
|
92
|
+
})),
|
|
93
|
+
destOps: element.mandate.destinationOps.map((op) => ({
|
|
94
|
+
to: op.to,
|
|
95
|
+
value: BigInt(op.value),
|
|
96
|
+
data: op.data,
|
|
97
|
+
})),
|
|
98
|
+
q: (0, viem_1.keccak256)(element.mandate.qualifier.encodedVal),
|
|
99
|
+
},
|
|
100
|
+
})),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
return typedData;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the compact digest for signing
|
|
107
|
+
* @param intentOp The intent operation
|
|
108
|
+
* @returns The digest hash
|
|
109
|
+
*/
|
|
110
|
+
function getCompactDigest(intentOp) {
|
|
111
|
+
const typedData = getCompactTypedData(intentOp);
|
|
112
|
+
return (0, viem_1.hashTypedData)(typedData);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the Permit2 digest for signing
|
|
116
|
+
* @param intentOp The intent operation
|
|
117
|
+
* @returns The digest hash
|
|
118
|
+
*/
|
|
119
|
+
function getPermit2Digest(element, nonce, expires) {
|
|
120
|
+
const typedData = (0, permit2_1.getTypedData)(element, nonce, expires);
|
|
121
|
+
return (0, viem_1.hashTypedData)(typedData);
|
|
122
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
declare class ExecutionError extends Error {
|
|
2
|
+
private readonly _message;
|
|
3
|
+
private readonly _context;
|
|
4
|
+
private readonly _errorType;
|
|
5
|
+
private readonly _traceId;
|
|
6
|
+
constructor(params?: {
|
|
7
|
+
message?: string;
|
|
8
|
+
context?: any;
|
|
9
|
+
errorType?: string;
|
|
10
|
+
traceId?: string;
|
|
11
|
+
});
|
|
12
|
+
get message(): string;
|
|
13
|
+
get context(): any;
|
|
14
|
+
get errorType(): string;
|
|
15
|
+
get traceId(): string;
|
|
16
|
+
}
|
|
17
|
+
declare class SignerNotSupportedError extends ExecutionError {
|
|
18
|
+
constructor(params?: {
|
|
19
|
+
context?: any;
|
|
20
|
+
errorType?: string;
|
|
21
|
+
traceId?: string;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
declare class CallsNotSupportedError extends ExecutionError {
|
|
25
|
+
constructor(params?: {
|
|
26
|
+
context?: any;
|
|
27
|
+
errorType?: string;
|
|
28
|
+
traceId?: string;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
declare class OrderPathRequiredForIntentsError extends ExecutionError {
|
|
32
|
+
constructor(params?: {
|
|
33
|
+
context?: any;
|
|
34
|
+
errorType?: string;
|
|
35
|
+
traceId?: string;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
declare class SessionChainRequiredError extends ExecutionError {
|
|
39
|
+
constructor(params?: {
|
|
40
|
+
context?: any;
|
|
41
|
+
errorType?: string;
|
|
42
|
+
traceId?: string;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
declare class IntentFailedError extends ExecutionError {
|
|
46
|
+
constructor(params?: {
|
|
47
|
+
context?: any;
|
|
48
|
+
errorType?: string;
|
|
49
|
+
traceId?: string;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
declare class IntentStatusTimeoutError extends ExecutionError {
|
|
53
|
+
constructor(params?: {
|
|
54
|
+
context?: any;
|
|
55
|
+
errorType?: string;
|
|
56
|
+
traceId?: string;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
declare function isExecutionError(error: Error): error is ExecutionError;
|
|
60
|
+
export { isExecutionError, ExecutionError, OrderPathRequiredForIntentsError, CallsNotSupportedError, SessionChainRequiredError, IntentFailedError, IntentStatusTimeoutError, SignerNotSupportedError, };
|
|
61
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +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,cAAM,uBAAwB,SAAQ,cAAc;gBACtC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAOF;AAED,cAAM,sBAAuB,SAAQ,cAAc;gBACrC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,cAAM,gCAAiC,SAAQ,cAAc;gBAC/C,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,cAAM,yBAA0B,SAAQ,cAAc;gBACxC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAOF;AAED,cAAM,iBAAkB,SAAQ,cAAc;gBAChC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,cAAM,wBAAyB,SAAQ,cAAc;gBACvC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;CAMF;AAED,iBAAS,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,cAAc,CAE/D;AAED,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gCAAgC,EAChC,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,GACxB,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerNotSupportedError = exports.IntentStatusTimeoutError = exports.IntentFailedError = exports.SessionChainRequiredError = exports.CallsNotSupportedError = exports.OrderPathRequiredForIntentsError = exports.ExecutionError = void 0;
|
|
4
|
+
exports.isExecutionError = isExecutionError;
|
|
5
|
+
class ExecutionError extends Error {
|
|
6
|
+
_message;
|
|
7
|
+
_context;
|
|
8
|
+
_errorType;
|
|
9
|
+
_traceId;
|
|
10
|
+
constructor(params) {
|
|
11
|
+
super();
|
|
12
|
+
this._message = params?.message || 'ExecutionError';
|
|
13
|
+
this._context = params?.context || {};
|
|
14
|
+
this._errorType = params?.errorType || 'Unknown';
|
|
15
|
+
this._traceId = params?.traceId || '';
|
|
16
|
+
}
|
|
17
|
+
get message() {
|
|
18
|
+
return this._message;
|
|
19
|
+
}
|
|
20
|
+
get context() {
|
|
21
|
+
return this._context;
|
|
22
|
+
}
|
|
23
|
+
get errorType() {
|
|
24
|
+
return this._errorType;
|
|
25
|
+
}
|
|
26
|
+
get traceId() {
|
|
27
|
+
return this._traceId;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ExecutionError = ExecutionError;
|
|
31
|
+
class SignerNotSupportedError extends ExecutionError {
|
|
32
|
+
constructor(params) {
|
|
33
|
+
super({
|
|
34
|
+
message: 'Sending a transaction is not supported for this type of signers. Use user operations instead.',
|
|
35
|
+
...params,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.SignerNotSupportedError = SignerNotSupportedError;
|
|
40
|
+
class CallsNotSupportedError extends ExecutionError {
|
|
41
|
+
constructor(params) {
|
|
42
|
+
super({
|
|
43
|
+
message: 'Target chain calls are not supported for this account type',
|
|
44
|
+
...params,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.CallsNotSupportedError = CallsNotSupportedError;
|
|
49
|
+
class OrderPathRequiredForIntentsError extends ExecutionError {
|
|
50
|
+
constructor(params) {
|
|
51
|
+
super({
|
|
52
|
+
message: 'Order path is required when using intents',
|
|
53
|
+
...params,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.OrderPathRequiredForIntentsError = OrderPathRequiredForIntentsError;
|
|
58
|
+
class SessionChainRequiredError extends ExecutionError {
|
|
59
|
+
constructor(params) {
|
|
60
|
+
super({
|
|
61
|
+
message: 'Specifying a chain is required when using multi-chain smart sessions',
|
|
62
|
+
...params,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.SessionChainRequiredError = SessionChainRequiredError;
|
|
67
|
+
class IntentFailedError extends ExecutionError {
|
|
68
|
+
constructor(params) {
|
|
69
|
+
super({
|
|
70
|
+
message: 'Intent failed',
|
|
71
|
+
...params,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.IntentFailedError = IntentFailedError;
|
|
76
|
+
class IntentStatusTimeoutError extends ExecutionError {
|
|
77
|
+
constructor(params) {
|
|
78
|
+
super({
|
|
79
|
+
message: 'Intent status polling timed out',
|
|
80
|
+
...params,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.IntentStatusTimeoutError = IntentStatusTimeoutError;
|
|
85
|
+
function isExecutionError(error) {
|
|
86
|
+
return error instanceof ExecutionError;
|
|
87
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Address, type Chain, type Hex } from 'viem';
|
|
2
|
+
import type { UserOperationReceipt } from 'viem/_types/account-abstraction';
|
|
3
|
+
import type { IntentOpStatus } from '../orchestrator';
|
|
4
|
+
import type { SettlementLayer } from '../orchestrator/types';
|
|
5
|
+
import type { CalldataInput, CallInput, RhinestoneAccountConfig, RhinestoneConfig, SignerSet, SourceAssetInput, Sponsorship, TokenRequest, TokenSymbol, Transaction, UserOperationTransaction } from '../types';
|
|
6
|
+
import { ExecutionError, IntentFailedError, IntentStatusTimeoutError, isExecutionError, OrderPathRequiredForIntentsError, SessionChainRequiredError, SignerNotSupportedError } from './error';
|
|
7
|
+
import type { TransactionResult, UserOperationResult } from './utils';
|
|
8
|
+
interface TransactionStatus {
|
|
9
|
+
fill: {
|
|
10
|
+
hash: Hex | undefined;
|
|
11
|
+
chainId: number;
|
|
12
|
+
};
|
|
13
|
+
claims: {
|
|
14
|
+
hash: Hex | undefined;
|
|
15
|
+
chainId: number;
|
|
16
|
+
}[];
|
|
17
|
+
}
|
|
18
|
+
declare function sendTransaction(config: RhinestoneAccountConfig, transaction: Transaction): Promise<TransactionResult>;
|
|
19
|
+
declare function sendUserOperation(config: RhinestoneAccountConfig, transaction: UserOperationTransaction): Promise<UserOperationResult>;
|
|
20
|
+
declare function sendTransactionInternal(config: RhinestoneConfig, sourceChains: Chain[] | undefined, targetChain: Chain, options: {
|
|
21
|
+
callInputs?: CallInput[];
|
|
22
|
+
gasLimit?: bigint;
|
|
23
|
+
initialTokenRequests?: TokenRequest[];
|
|
24
|
+
recipient?: RhinestoneAccountConfig | Address;
|
|
25
|
+
signers?: SignerSet;
|
|
26
|
+
sponsored?: Sponsorship;
|
|
27
|
+
settlementLayers?: SettlementLayer[];
|
|
28
|
+
sourceAssets?: SourceAssetInput;
|
|
29
|
+
lockFunds?: boolean;
|
|
30
|
+
feeAsset?: Address | TokenSymbol;
|
|
31
|
+
}): Promise<TransactionResult>;
|
|
32
|
+
declare function sendUserOperationInternal(config: RhinestoneConfig, chain: Chain, callInputs: CalldataInput[], signers?: SignerSet): Promise<UserOperationResult>;
|
|
33
|
+
declare function waitForExecution(config: RhinestoneConfig, result: TransactionResult | UserOperationResult, acceptsPreconfirmations: boolean): Promise<TransactionStatus | UserOperationReceipt>;
|
|
34
|
+
declare function getMaxSpendableAmount(config: RhinestoneConfig, chain: Chain, token: Address | TokenSymbol, gasUnits: bigint, sponsored?: boolean): Promise<bigint>;
|
|
35
|
+
declare function getPortfolio(config: RhinestoneConfig, onTestnets: boolean): Promise<import("../orchestrator").Portfolio>;
|
|
36
|
+
declare function getIntentStatus(apiKey: string | undefined, endpointUrl: string | undefined, intentId: bigint): Promise<TransactionStatus & {
|
|
37
|
+
status: IntentOpStatus['status'];
|
|
38
|
+
}>;
|
|
39
|
+
export { sendTransaction, sendTransactionInternal, sendUserOperation, sendUserOperationInternal, waitForExecution, getMaxSpendableAmount, getPortfolio, getIntentStatus, isExecutionError, ExecutionError, IntentFailedError, IntentStatusTimeoutError, OrderPathRequiredForIntentsError, SessionChainRequiredError, SignerNotSupportedError, };
|
|
40
|
+
export type { TransactionStatus, TransactionResult, UserOperationResult };
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAI3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAUrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,wBAAwB,EACzB,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,wBAAwB,EACxB,gBAAgB,EAChB,gCAAgC,EAChC,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAqBrE,UAAU,iBAAiB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,GAAG,GAAG,SAAS,CAAA;QACrB,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,MAAM,EAAE;QACN,IAAI,EAAE,GAAG,GAAG,SAAS,CAAA;QACrB,OAAO,EAAE,MAAM,CAAA;KAChB,EAAE,CAAA;CACJ;AAED,iBAAe,eAAe,CAC5B,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,WAAW,8BAiCzB;AAED,iBAAe,iBAAiB,CAC9B,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,wBAAwB,gCAqBtC;AAED,iBAAe,uBAAuB,CACpC,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,KAAK,EAAE,GAAG,SAAS,EACjC,WAAW,EAAE,KAAK,EAClB,OAAO,EAAE;IACP,UAAU,CAAC,EAAE,SAAS,EAAE,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oBAAoB,CAAC,EAAE,YAAY,EAAE,CAAA;IACrC,SAAS,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAA;IAC7C,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAA;IACpC,YAAY,CAAC,EAAE,gBAAgB,CAAA;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;CACjC,8BAqCF;AAED,iBAAe,yBAAyB,CACtC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,aAAa,EAAE,EAC3B,OAAO,CAAC,EAAE,SAAS,gCAgCpB;AAwDD,iBAAe,gBAAgB,CAC7B,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,iBAAiB,GAAG,mBAAmB,EAC/C,uBAAuB,EAAE,OAAO,GAC/B,OAAO,CAAC,iBAAiB,GAAG,oBAAoB,CAAC,CAiGnD;AAED,iBAAe,qBAAqB,CAClC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,OAAO,GAAG,WAAW,EAC5B,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,OAAe,GACzB,OAAO,CAAC,MAAM,CAAC,CAejB;AAED,iBAAe,YAAY,CAAC,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,gDASxE;AAED,iBAAe,eAAe,CAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,QAAQ,EAAE,MAAM,GACf,OAAO,CACR,iBAAiB,GAAG;IAClB,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;CACjC,CACF,CAgBA;AAED,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EAEf,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAChC,yBAAyB,EACzB,uBAAuB,GACxB,CAAA;AACD,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerNotSupportedError = exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.IntentStatusTimeoutError = exports.IntentFailedError = exports.ExecutionError = exports.isExecutionError = void 0;
|
|
4
|
+
exports.sendTransaction = sendTransaction;
|
|
5
|
+
exports.sendTransactionInternal = sendTransactionInternal;
|
|
6
|
+
exports.sendUserOperation = sendUserOperation;
|
|
7
|
+
exports.sendUserOperationInternal = sendUserOperationInternal;
|
|
8
|
+
exports.waitForExecution = waitForExecution;
|
|
9
|
+
exports.getMaxSpendableAmount = getMaxSpendableAmount;
|
|
10
|
+
exports.getPortfolio = getPortfolio;
|
|
11
|
+
exports.getIntentStatus = getIntentStatus;
|
|
12
|
+
const viem_1 = require("viem");
|
|
13
|
+
const chains_1 = require("viem/chains");
|
|
14
|
+
const accounts_1 = require("../accounts");
|
|
15
|
+
const utils_1 = require("../accounts/utils");
|
|
16
|
+
const orchestrator_1 = require("../orchestrator");
|
|
17
|
+
const registry_1 = require("../orchestrator/registry");
|
|
18
|
+
const error_1 = require("./error");
|
|
19
|
+
Object.defineProperty(exports, "ExecutionError", { enumerable: true, get: function () { return error_1.ExecutionError; } });
|
|
20
|
+
Object.defineProperty(exports, "IntentFailedError", { enumerable: true, get: function () { return error_1.IntentFailedError; } });
|
|
21
|
+
Object.defineProperty(exports, "IntentStatusTimeoutError", { enumerable: true, get: function () { return error_1.IntentStatusTimeoutError; } });
|
|
22
|
+
Object.defineProperty(exports, "isExecutionError", { enumerable: true, get: function () { return error_1.isExecutionError; } });
|
|
23
|
+
Object.defineProperty(exports, "OrderPathRequiredForIntentsError", { enumerable: true, get: function () { return error_1.OrderPathRequiredForIntentsError; } });
|
|
24
|
+
Object.defineProperty(exports, "SessionChainRequiredError", { enumerable: true, get: function () { return error_1.SessionChainRequiredError; } });
|
|
25
|
+
Object.defineProperty(exports, "SignerNotSupportedError", { enumerable: true, get: function () { return error_1.SignerNotSupportedError; } });
|
|
26
|
+
const smart_session_1 = require("./smart-session");
|
|
27
|
+
const utils_2 = require("./utils");
|
|
28
|
+
const POLL_INITIAL_MS = 500;
|
|
29
|
+
const POLL_SLOW_AFTER_MS = 15000;
|
|
30
|
+
const POLL_SLOW_MS = 2000;
|
|
31
|
+
const POLL_MAX_WAIT_MS = 180000;
|
|
32
|
+
const POLL_ERROR_BACKOFF_MS = 1000;
|
|
33
|
+
const POLL_ERROR_BACKOFF_MAX_MS = 10000;
|
|
34
|
+
async function sendTransaction(config, transaction) {
|
|
35
|
+
const sourceChains = 'chain' in transaction ? [transaction.chain] : transaction.sourceChains;
|
|
36
|
+
const targetChain = 'chain' in transaction ? transaction.chain : transaction.targetChain;
|
|
37
|
+
const { calls, gasLimit, tokenRequests, recipient, signers, sponsored, settlementLayers, sourceAssets, feeAsset, } = transaction;
|
|
38
|
+
const isUserOpSigner = signers?.type === 'guardians' || signers?.type === 'session';
|
|
39
|
+
if (isUserOpSigner) {
|
|
40
|
+
throw new error_1.SignerNotSupportedError();
|
|
41
|
+
}
|
|
42
|
+
return await sendTransactionInternal(config, sourceChains, targetChain, {
|
|
43
|
+
callInputs: calls,
|
|
44
|
+
gasLimit,
|
|
45
|
+
initialTokenRequests: tokenRequests,
|
|
46
|
+
recipient,
|
|
47
|
+
signers,
|
|
48
|
+
sponsored,
|
|
49
|
+
settlementLayers,
|
|
50
|
+
sourceAssets,
|
|
51
|
+
feeAsset,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function sendUserOperation(config, transaction) {
|
|
55
|
+
const accountAddress = (0, accounts_1.getAddress)(config);
|
|
56
|
+
const resolvedCalls = await (0, utils_2.resolveCallInputs)(transaction.calls, config, transaction.chain, accountAddress);
|
|
57
|
+
const userOpSigner = transaction.signers?.type === 'session' ? transaction.signers.session : null;
|
|
58
|
+
if (userOpSigner) {
|
|
59
|
+
await (0, smart_session_1.enableSmartSession)(transaction.chain, config, userOpSigner);
|
|
60
|
+
}
|
|
61
|
+
// Smart sessions require a UserOp flow
|
|
62
|
+
return await sendUserOperationInternal(config, transaction.chain, resolvedCalls, transaction.signers);
|
|
63
|
+
}
|
|
64
|
+
async function sendTransactionInternal(config, sourceChains, targetChain, options) {
|
|
65
|
+
const accountAddress = (0, accounts_1.getAddress)(config);
|
|
66
|
+
const resolvedCalls = await (0, utils_2.resolveCallInputs)(options.callInputs, config, targetChain, accountAddress);
|
|
67
|
+
const tokenRequests = (0, utils_2.getTokenRequests)(sourceChains, targetChain, options.initialTokenRequests, options.settlementLayers);
|
|
68
|
+
const sendAsUserOp = options.signers?.type === 'guardians' || options.signers?.type === 'session';
|
|
69
|
+
if (sendAsUserOp) {
|
|
70
|
+
throw new error_1.SignerNotSupportedError();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return await sendTransactionAsIntent(config, sourceChains, targetChain, resolvedCalls, options.gasLimit, tokenRequests, options.recipient, options.signers, options.sponsored, options.settlementLayers, options.sourceAssets, options.feeAsset, options.lockFunds);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function sendUserOperationInternal(config, chain, callInputs, signers) {
|
|
77
|
+
// Make sure the account is deployed
|
|
78
|
+
await (0, accounts_1.deploy)(config, chain);
|
|
79
|
+
const withSession = signers?.type === 'session' ? signers.session : null;
|
|
80
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
81
|
+
chain,
|
|
82
|
+
transport: (0, utils_1.createTransport)(chain, config.provider),
|
|
83
|
+
});
|
|
84
|
+
const validatorAccount = await (0, utils_2.getValidatorAccount)(config, signers, publicClient, chain);
|
|
85
|
+
if (!validatorAccount) {
|
|
86
|
+
throw new Error('No validator account found');
|
|
87
|
+
}
|
|
88
|
+
const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
|
|
89
|
+
if (withSession) {
|
|
90
|
+
await (0, smart_session_1.enableSmartSession)(chain, config, withSession);
|
|
91
|
+
}
|
|
92
|
+
const calls = (0, utils_2.parseCalls)(callInputs, chain.id);
|
|
93
|
+
const hash = await bundlerClient.sendUserOperation({
|
|
94
|
+
account: validatorAccount,
|
|
95
|
+
calls,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
type: 'userop',
|
|
99
|
+
hash,
|
|
100
|
+
chain: chain.id,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async function sendTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipient, signers, sponsored, settlementLayers, sourceAssets, feeAsset, lockFunds) {
|
|
104
|
+
const intentRoute = await (0, utils_2.prepareTransactionAsIntent)(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipient, sponsored ?? false, undefined, settlementLayers, sourceAssets, feeAsset, lockFunds, undefined);
|
|
105
|
+
if (!intentRoute) {
|
|
106
|
+
throw new error_1.OrderPathRequiredForIntentsError();
|
|
107
|
+
}
|
|
108
|
+
const { originSignatures, destinationSignature } = await (0, utils_2.signIntent)(config, intentRoute.intentOp, signers);
|
|
109
|
+
const authorizations = config.eoa
|
|
110
|
+
? await (0, utils_2.signAuthorizationsInternal)(config, intentRoute)
|
|
111
|
+
: [];
|
|
112
|
+
return await (0, utils_2.submitIntentInternal)(config, sourceChains, targetChain, intentRoute.intentOp, originSignatures, destinationSignature, authorizations, false);
|
|
113
|
+
}
|
|
114
|
+
async function waitForExecution(config, result, acceptsPreconfirmations) {
|
|
115
|
+
const validStatuses = new Set([
|
|
116
|
+
orchestrator_1.INTENT_STATUS_FAILED,
|
|
117
|
+
orchestrator_1.INTENT_STATUS_COMPLETED,
|
|
118
|
+
orchestrator_1.INTENT_STATUS_FILLED,
|
|
119
|
+
]);
|
|
120
|
+
if (acceptsPreconfirmations) {
|
|
121
|
+
validStatuses.add(orchestrator_1.INTENT_STATUS_PRECONFIRMED);
|
|
122
|
+
}
|
|
123
|
+
switch (result.type) {
|
|
124
|
+
case 'intent': {
|
|
125
|
+
let intentStatus = null;
|
|
126
|
+
const startTs = Date.now();
|
|
127
|
+
let nextDelayMs = POLL_INITIAL_MS;
|
|
128
|
+
let errorBackoffMs = POLL_ERROR_BACKOFF_MS;
|
|
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
|
+
}
|
|
136
|
+
const orchestrator = (0, utils_2.getOrchestratorByChain)(result.targetChain, config.apiKey, config.endpointUrl);
|
|
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
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (intentStatus.status === orchestrator_1.INTENT_STATUS_FAILED) {
|
|
178
|
+
throw new error_1.IntentFailedError();
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
fill: {
|
|
182
|
+
hash: intentStatus.fillTransactionHash,
|
|
183
|
+
chainId: result.targetChain,
|
|
184
|
+
},
|
|
185
|
+
claims: intentStatus.claims.map((claim) => ({
|
|
186
|
+
hash: claim.claimTransactionHash,
|
|
187
|
+
chainId: claim.chainId,
|
|
188
|
+
})),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
case 'userop': {
|
|
192
|
+
const targetChain = (0, registry_1.getChainById)(result.chain);
|
|
193
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
194
|
+
chain: targetChain,
|
|
195
|
+
transport: (0, utils_1.createTransport)(targetChain, config.provider),
|
|
196
|
+
});
|
|
197
|
+
const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
|
|
198
|
+
const receipt = await bundlerClient.waitForUserOperationReceipt({
|
|
199
|
+
hash: result.hash,
|
|
200
|
+
});
|
|
201
|
+
return receipt;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async function getMaxSpendableAmount(config, chain, token, gasUnits, sponsored = false) {
|
|
206
|
+
const orchestrator = (0, utils_2.getOrchestratorByChain)(chain.id, config.apiKey, config.endpointUrl);
|
|
207
|
+
const tokenAddress = (0, registry_1.resolveTokenAddress)(token, chain.id);
|
|
208
|
+
const account = (0, utils_2.getIntentAccount)(config, undefined, undefined);
|
|
209
|
+
return orchestrator.getMaxTokenAmount(account, chain.id, tokenAddress, gasUnits, sponsored);
|
|
210
|
+
}
|
|
211
|
+
async function getPortfolio(config, onTestnets) {
|
|
212
|
+
const address = (0, accounts_1.getAddress)(config);
|
|
213
|
+
const chainId = onTestnets ? chains_1.baseSepolia.id : chains_1.base.id;
|
|
214
|
+
const orchestrator = (0, utils_2.getOrchestratorByChain)(chainId, config.apiKey, config.endpointUrl);
|
|
215
|
+
return orchestrator.getPortfolio(address);
|
|
216
|
+
}
|
|
217
|
+
async function getIntentStatus(apiKey, endpointUrl, intentId) {
|
|
218
|
+
const environment = BigInt(intentId.toString().slice(0, 1));
|
|
219
|
+
const chainId = environment === 4n ? chains_1.base.id : chains_1.baseSepolia.id;
|
|
220
|
+
const orchestrator = (0, utils_2.getOrchestratorByChain)(chainId, apiKey, endpointUrl);
|
|
221
|
+
const internalStatus = await orchestrator.getIntentOpStatus(intentId);
|
|
222
|
+
return {
|
|
223
|
+
status: internalStatus.status,
|
|
224
|
+
fill: {
|
|
225
|
+
hash: internalStatus.fillTransactionHash,
|
|
226
|
+
chainId: chainId,
|
|
227
|
+
},
|
|
228
|
+
claims: internalStatus.claims.map((claim) => ({
|
|
229
|
+
hash: claim.claimTransactionHash,
|
|
230
|
+
chainId: claim.chainId,
|
|
231
|
+
})),
|
|
232
|
+
};
|
|
233
|
+
}
|