@charterlabs/rhinestone-sdk 0.3.1 → 0.3.3
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 +31 -200
- package/dist/src/accounts/index.d.ts +3 -2
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +14 -6
- package/dist/src/accounts/signing/common.d.ts.map +1 -1
- package/dist/src/accounts/signing/common.js +9 -18
- package/dist/src/actions/compact.d.ts +2 -1
- package/dist/src/actions/compact.d.ts.map +1 -1
- package/dist/src/actions/compact.js +3 -1
- package/dist/src/actions/smart-sessions.d.ts +11 -1
- package/dist/src/actions/smart-sessions.d.ts.map +1 -1
- package/dist/src/actions/smart-sessions.js +35 -2
- package/dist/src/errors/index.d.ts +2 -2
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +2 -1
- package/dist/src/execution/compact.d.ts +3 -1
- package/dist/src/execution/compact.d.ts.map +1 -1
- package/dist/src/execution/compact.js +5 -1
- package/dist/src/execution/error.d.ts +1 -0
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/index.d.ts +3 -3
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +18 -12
- package/dist/src/execution/utils.d.ts +12 -8
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +116 -26
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -12
- package/dist/src/modules/index.d.ts +4 -4
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js +2 -1
- package/dist/src/modules/validators/core.d.ts +3 -1
- package/dist/src/modules/validators/core.d.ts.map +1 -1
- package/dist/src/modules/validators/core.js +7 -3
- package/dist/src/modules/validators/smart-sessions.d.ts +12 -8
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +396 -29
- package/dist/src/orchestrator/client.d.ts +2 -7
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +49 -43
- package/dist/src/orchestrator/error.d.ts +11 -1
- package/dist/src/orchestrator/error.d.ts.map +1 -1
- package/dist/src/orchestrator/error.js +16 -1
- package/dist/src/orchestrator/index.d.ts +4 -4
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +2 -1
- package/dist/src/orchestrator/registry.d.ts +1 -1
- package/dist/src/orchestrator/registry.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.js +3 -14
- package/dist/src/orchestrator/registry.test.js +5 -1
- package/dist/src/orchestrator/types.d.ts +28 -4
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/orchestrator/types.js +15 -1
- package/dist/src/types.d.ts +30 -11
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -3,17 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = exports.SMART_SESSION_EMISSARY_ADDRESS = void 0;
|
|
6
|
+
exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = exports.SMART_SESSION_EMISSARY_ADDRESS_DEV = exports.SMART_SESSION_EMISSARY_ADDRESS = void 0;
|
|
7
|
+
exports.packSignature = packSignature;
|
|
7
8
|
exports.getSessionData = getSessionData;
|
|
8
9
|
exports.getEnableSessionCall = getEnableSessionCall;
|
|
9
10
|
exports.getPermissionId = getPermissionId;
|
|
10
11
|
exports.getSmartSessionValidator = getSmartSessionValidator;
|
|
11
12
|
exports.getSessionDetails = getSessionDetails;
|
|
13
|
+
exports.isSessionEnabled = isSessionEnabled;
|
|
14
|
+
exports.signEnableSession = signEnableSession;
|
|
15
|
+
const solady_1 = require("solady");
|
|
12
16
|
const viem_1 = require("viem");
|
|
13
|
-
const
|
|
17
|
+
const chains_1 = require("viem/chains");
|
|
18
|
+
const utils_1 = require("../../accounts/utils");
|
|
19
|
+
const compact_1 = require("../../execution/compact");
|
|
20
|
+
const utils_2 = require("../../execution/utils");
|
|
14
21
|
const smart_session_emissary_1 = __importDefault(require("../abi/smart-session-emissary"));
|
|
15
22
|
const common_1 = require("../common");
|
|
16
23
|
const core_1 = require("./core");
|
|
24
|
+
Object.defineProperty(exports, "SMART_SESSION_EMISSARY_ADDRESS", { enumerable: true, get: function () { return core_1.SMART_SESSION_EMISSARY_ADDRESS; } });
|
|
25
|
+
Object.defineProperty(exports, "SMART_SESSION_EMISSARY_ADDRESS_DEV", { enumerable: true, get: function () { return core_1.SMART_SESSION_EMISSARY_ADDRESS_DEV; } });
|
|
17
26
|
const types = {
|
|
18
27
|
PolicyData: [
|
|
19
28
|
{ name: 'policy', type: 'address' },
|
|
@@ -58,42 +67,190 @@ const types = {
|
|
|
58
67
|
],
|
|
59
68
|
MultiChainSession: [{ name: 'sessionsAndChainIds', type: 'ChainSession[]' }],
|
|
60
69
|
};
|
|
61
|
-
const SMART_SESSION_EMISSARY_ADDRESS = '0x4411abbbede0215626284d0385dd55b4303012b7';
|
|
62
|
-
exports.SMART_SESSION_EMISSARY_ADDRESS = SMART_SESSION_EMISSARY_ADDRESS;
|
|
63
70
|
const SMART_SESSION_MODE_USE = '0x00';
|
|
64
71
|
const SMART_SESSION_MODE_ENABLE = '0x01';
|
|
65
|
-
const SMART_SESSION_MODE_UNSAFE_ENABLE = '0x02';
|
|
66
|
-
const SUDO_POLICY_ADDRESS = '0x0000003111cD8e92337C100F22B7A9dbf8DEE301';
|
|
67
72
|
const SMART_SESSIONS_FALLBACK_TARGET_FLAG = '0x0000000000000000000000000000000000000001';
|
|
68
73
|
exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = SMART_SESSIONS_FALLBACK_TARGET_FLAG;
|
|
69
74
|
const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = '0x00000001';
|
|
70
75
|
exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG;
|
|
71
76
|
const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = '0x00000002';
|
|
72
77
|
exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION;
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
const SPENDING_LIMITS_POLICY_ADDRESS = '0x00000088d48cf102a8cdb0137a9b173f957c6343';
|
|
79
|
+
const TIME_FRAME_POLICY_ADDRESS = '0x8177451511de0577b911c254e9551d981c26dc72';
|
|
80
|
+
const SUDO_POLICY_ADDRESS = '0x0000003111cd8e92337c100f22b7a9dbf8dee301';
|
|
81
|
+
const UNIVERSAL_ACTION_POLICY_ADDRESS = '0x0000006dda6c463511c4e9b05cfc34c1247fcf1f';
|
|
82
|
+
const USAGE_LIMIT_POLICY_ADDRESS = '0x1f34ef8311345a3a4a4566af321b313052f51493';
|
|
83
|
+
const VALUE_LIMIT_POLICY_ADDRESS = '0x730da93267e7e513e932301b47f2ac7d062abc83';
|
|
84
|
+
const ACTION_CONDITION_EQUAL = 0;
|
|
85
|
+
const ACTION_CONDITION_GREATER_THAN = 1;
|
|
86
|
+
const ACTION_CONDITION_LESS_THAN = 2;
|
|
87
|
+
const ACTION_CONDITION_GREATER_THAN_OR_EQUAL = 3;
|
|
88
|
+
const ACTION_CONDITION_LESS_THAN_OR_EQUAL = 4;
|
|
89
|
+
const ACTION_CONDITION_NOT_EQUAL = 5;
|
|
90
|
+
const ACTION_CONDITION_IN_RANGE = 6;
|
|
91
|
+
function packSignature(signers, validatorSignature) {
|
|
92
|
+
const session = signers.session;
|
|
93
|
+
const permissionId = getPermissionId(session);
|
|
94
|
+
if (signers.verifyExecutions) {
|
|
95
|
+
const smartSessionMode = signers.enableData
|
|
96
|
+
? SMART_SESSION_MODE_ENABLE
|
|
97
|
+
: SMART_SESSION_MODE_USE;
|
|
98
|
+
const sessionData = getSessionData(signers.session);
|
|
99
|
+
const packedSignature = signers.enableData
|
|
100
|
+
? solady_1.LibZip.flzCompress((0, viem_1.encodeAbiParameters)([
|
|
101
|
+
{
|
|
102
|
+
type: 'tuple',
|
|
103
|
+
name: 'enableData',
|
|
104
|
+
components: [
|
|
105
|
+
{ type: 'bytes', name: 'allocatorSig' },
|
|
106
|
+
{ type: 'bytes', name: 'userSig' },
|
|
107
|
+
{ type: 'uint256', name: 'expires' },
|
|
108
|
+
{
|
|
109
|
+
type: 'tuple',
|
|
110
|
+
name: 'enableSession',
|
|
111
|
+
components: [
|
|
112
|
+
{
|
|
113
|
+
type: 'uint8',
|
|
114
|
+
name: 'chainDigestIndex',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: 'tuple[]',
|
|
118
|
+
name: 'hashesAndChainIds',
|
|
119
|
+
components: [
|
|
120
|
+
{ type: 'uint64', name: 'chainId' },
|
|
121
|
+
{ type: 'bytes32', name: 'sessionDigest' },
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: 'tuple',
|
|
126
|
+
name: 'session',
|
|
127
|
+
components: [
|
|
128
|
+
{ type: 'address', name: 'sessionValidator' },
|
|
129
|
+
{ type: 'bytes', name: 'sessionValidatorInitData' },
|
|
130
|
+
{ type: 'bytes32', name: 'salt' },
|
|
131
|
+
{
|
|
132
|
+
type: 'tuple[]',
|
|
133
|
+
name: 'actions',
|
|
134
|
+
components: [
|
|
135
|
+
{ type: 'bytes4', name: 'actionTargetSelector' },
|
|
136
|
+
{ type: 'address', name: 'actionTarget' },
|
|
137
|
+
{
|
|
138
|
+
type: 'tuple[]',
|
|
139
|
+
name: 'actionPolicies',
|
|
140
|
+
components: [
|
|
141
|
+
{ type: 'address', name: 'policy' },
|
|
142
|
+
{ type: 'bytes', name: 'initData' },
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
type: 'tuple[]',
|
|
149
|
+
name: 'claimPolicies',
|
|
150
|
+
components: [
|
|
151
|
+
{ type: 'address', name: 'policy' },
|
|
152
|
+
{ type: 'bytes', name: 'initData' },
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
type: 'tuple',
|
|
157
|
+
name: 'erc7739Policies',
|
|
158
|
+
components: [
|
|
159
|
+
{
|
|
160
|
+
type: 'tuple[]',
|
|
161
|
+
name: 'allowedERC7739Content',
|
|
162
|
+
components: [
|
|
163
|
+
{
|
|
164
|
+
type: 'bytes32',
|
|
165
|
+
name: 'appDomainSeparator',
|
|
166
|
+
},
|
|
167
|
+
{ type: 'string[]', name: 'contentNames' },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
type: 'tuple[]',
|
|
172
|
+
name: 'erc1271Policies',
|
|
173
|
+
components: [
|
|
174
|
+
{ type: 'address', name: 'policy' },
|
|
175
|
+
{ type: 'bytes', name: 'initData' },
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
type: 'tuple',
|
|
188
|
+
name: 'config',
|
|
189
|
+
components: [
|
|
190
|
+
{ type: 'uint8', name: 'scope' },
|
|
191
|
+
{ type: 'uint8', name: 'resetPeriod' },
|
|
192
|
+
{ type: 'address', name: 'allocator' },
|
|
193
|
+
{ type: 'bytes32', name: 'permissionId' },
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
{ type: 'bytes' },
|
|
197
|
+
], [
|
|
198
|
+
{
|
|
199
|
+
allocatorSig: viem_1.zeroHash,
|
|
200
|
+
userSig: signers.enableData.userSignature,
|
|
201
|
+
expires: viem_1.maxUint256,
|
|
202
|
+
enableSession: {
|
|
203
|
+
chainDigestIndex: signers.enableData.sessionToEnableIndex,
|
|
204
|
+
hashesAndChainIds: signers.enableData.hashesAndChainIds,
|
|
205
|
+
session: sessionData,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
scope: compact_1.SCOPE_MULTICHAIN,
|
|
210
|
+
resetPeriod: compact_1.RESET_PERIOD_ONE_WEEK,
|
|
211
|
+
allocator: viem_1.zeroAddress,
|
|
212
|
+
permissionId: getPermissionId(signers.session),
|
|
213
|
+
},
|
|
214
|
+
validatorSignature,
|
|
215
|
+
]))
|
|
216
|
+
: validatorSignature;
|
|
217
|
+
return signers.enableData
|
|
218
|
+
? (0, viem_1.encodePacked)(['bytes1', 'bytes'], [smartSessionMode, packedSignature])
|
|
219
|
+
: (0, viem_1.encodePacked)(['bytes1', 'bytes32', 'bytes'], [smartSessionMode, permissionId, packedSignature]);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
const SIGNATURE_IS_VALID_SIG_1271 = '0x00';
|
|
223
|
+
const policyDataOffset = BigInt(64 + (0, viem_1.size)(validatorSignature));
|
|
224
|
+
const mode = SIGNATURE_IS_VALID_SIG_1271;
|
|
225
|
+
const policySpecificData = '0x';
|
|
226
|
+
const signature = (0, viem_1.encodePacked)(['bytes1', 'bytes32', 'uint256', 'bytes', 'bytes'], [
|
|
227
|
+
mode,
|
|
228
|
+
permissionId,
|
|
229
|
+
policyDataOffset,
|
|
230
|
+
validatorSignature,
|
|
231
|
+
policySpecificData,
|
|
232
|
+
]);
|
|
233
|
+
return signature;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function getSessionDetails(account, sessions, useDevContracts) {
|
|
237
|
+
const lockTag = '0x000000000000000000000000';
|
|
238
|
+
const sessionNonces = await Promise.all(sessions.map((session) => getSessionNonce(account, session, lockTag, useDevContracts)));
|
|
78
239
|
const sessionDatas = sessions.map((session) => getSessionData(session));
|
|
79
|
-
const signedSessions = sessionDatas.map((session, index) => getSignedSession(account, lockTag, session, sessionNonces[index]));
|
|
240
|
+
const signedSessions = sessionDatas.map((session, index) => getSignedSession(account, lockTag, session, sessionNonces[index], useDevContracts));
|
|
80
241
|
const chains = sessions.map((session) => session.chain);
|
|
81
|
-
const
|
|
242
|
+
const hashesAndChainIds = signedSessions.map((session, index) => ({
|
|
82
243
|
chainId: BigInt(chains[index].id),
|
|
83
244
|
sessionDigest: (0, viem_1.hashStruct)({
|
|
84
|
-
types
|
|
245
|
+
types,
|
|
85
246
|
primaryType: 'SignedSession',
|
|
86
247
|
data: session,
|
|
87
248
|
}),
|
|
88
249
|
}));
|
|
89
|
-
const hashesAndChainIds = chainDigests.map((chainDigest) => ({
|
|
90
|
-
chainId: BigInt(chainDigest.chainId),
|
|
91
|
-
sessionDigest: chainDigest.sessionDigest,
|
|
92
|
-
}));
|
|
93
250
|
const data = {
|
|
94
251
|
domain: {
|
|
95
252
|
name: 'SmartSessionEmissary',
|
|
96
|
-
version: '1
|
|
253
|
+
version: '1',
|
|
97
254
|
},
|
|
98
255
|
types: types,
|
|
99
256
|
primaryType: 'MultiChainSession',
|
|
@@ -110,13 +267,42 @@ async function getSessionDetails(account, sessions) {
|
|
|
110
267
|
data,
|
|
111
268
|
};
|
|
112
269
|
}
|
|
113
|
-
async function
|
|
270
|
+
async function isSessionEnabled(account, provider, session, useDevContracts) {
|
|
271
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
272
|
+
chain: session.chain,
|
|
273
|
+
transport: (0, utils_1.createTransport)(session.chain, provider),
|
|
274
|
+
});
|
|
275
|
+
const isEnabled = await publicClient.readContract({
|
|
276
|
+
address: getSmartSessionEmissaryAddress(useDevContracts),
|
|
277
|
+
abi: [
|
|
278
|
+
{
|
|
279
|
+
type: 'function',
|
|
280
|
+
name: 'isPermissionEnabled',
|
|
281
|
+
inputs: [
|
|
282
|
+
{ name: 'account', type: 'address' },
|
|
283
|
+
{ name: 'permissionId', type: 'bytes32' },
|
|
284
|
+
],
|
|
285
|
+
outputs: [{ name: 'isEnabled', type: 'bool' }],
|
|
286
|
+
stateMutability: 'view',
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
functionName: 'isPermissionEnabled',
|
|
290
|
+
args: [account, getPermissionId(session)],
|
|
291
|
+
});
|
|
292
|
+
return isEnabled;
|
|
293
|
+
}
|
|
294
|
+
async function signEnableSession(config, details) {
|
|
295
|
+
return (0, utils_2.signTypedData)(config, details.data, chains_1.mainnet, undefined, {
|
|
296
|
+
skipErc6492: true,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
async function getSessionNonce(account, session, lockTag, useDevContracts) {
|
|
114
300
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
115
301
|
chain: session.chain,
|
|
116
302
|
transport: (0, viem_1.http)(),
|
|
117
303
|
});
|
|
118
304
|
const nonce = await publicClient.readContract({
|
|
119
|
-
address:
|
|
305
|
+
address: getSmartSessionEmissaryAddress(useDevContracts),
|
|
120
306
|
abi: [
|
|
121
307
|
{
|
|
122
308
|
type: 'function',
|
|
@@ -134,7 +320,7 @@ async function getSessionNonce(account, session, lockTag) {
|
|
|
134
320
|
});
|
|
135
321
|
return nonce;
|
|
136
322
|
}
|
|
137
|
-
function getSignedSession(account, lockTag, session, nonce) {
|
|
323
|
+
function getSignedSession(account, lockTag, session, nonce, useDevContracts) {
|
|
138
324
|
return {
|
|
139
325
|
account,
|
|
140
326
|
permissions: {
|
|
@@ -157,24 +343,24 @@ function getSignedSession(account, lockTag, session, nonce) {
|
|
|
157
343
|
sessionValidator: session.sessionValidator,
|
|
158
344
|
sessionValidatorInitData: session.sessionValidatorInitData,
|
|
159
345
|
salt: session.salt,
|
|
160
|
-
smartSessionEmissary:
|
|
346
|
+
smartSessionEmissary: getSmartSessionEmissaryAddress(useDevContracts),
|
|
161
347
|
expires: viem_1.maxUint256,
|
|
162
348
|
nonce,
|
|
163
349
|
};
|
|
164
350
|
}
|
|
165
|
-
async function getEnableSessionCall(account, session, enableSessionSignature, hashesAndChainIds, sessionToEnableIndex) {
|
|
351
|
+
async function getEnableSessionCall(account, session, enableSessionSignature, hashesAndChainIds, sessionToEnableIndex, useDevContracts) {
|
|
166
352
|
const sessionData = getSessionData(session);
|
|
167
353
|
const permissionId = getPermissionId(session);
|
|
168
354
|
return {
|
|
169
|
-
to:
|
|
355
|
+
to: getSmartSessionEmissaryAddress(useDevContracts),
|
|
170
356
|
data: (0, viem_1.encodeFunctionData)({
|
|
171
357
|
abi: smart_session_emissary_1.default,
|
|
172
358
|
functionName: 'setConfig',
|
|
173
359
|
args: [
|
|
174
360
|
account,
|
|
175
361
|
{
|
|
176
|
-
scope: SCOPE_MULTICHAIN,
|
|
177
|
-
resetPeriod: RESET_PERIOD_ONE_WEEK,
|
|
362
|
+
scope: compact_1.SCOPE_MULTICHAIN,
|
|
363
|
+
resetPeriod: compact_1.RESET_PERIOD_ONE_WEEK,
|
|
178
364
|
allocator: viem_1.zeroAddress,
|
|
179
365
|
permissionId,
|
|
180
366
|
},
|
|
@@ -209,12 +395,34 @@ function getSessionData(session) {
|
|
|
209
395
|
},
|
|
210
396
|
],
|
|
211
397
|
};
|
|
398
|
+
const sudoAction = {
|
|
399
|
+
actionTargetSelector: SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
|
|
400
|
+
actionTarget: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
|
|
401
|
+
actionPolicies: [
|
|
402
|
+
{
|
|
403
|
+
policy: SUDO_POLICY_ADDRESS,
|
|
404
|
+
initData: '0x',
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
};
|
|
408
|
+
const actions = session.actions
|
|
409
|
+
? session.actions.map((action) => ({
|
|
410
|
+
actionTargetSelector: action.selector ?? SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
|
|
411
|
+
actionTarget: action.target ?? SMART_SESSIONS_FALLBACK_TARGET_FLAG,
|
|
412
|
+
actionPolicies: action.policies?.map((policy) => getPolicyData(policy)) ?? [
|
|
413
|
+
{
|
|
414
|
+
policy: SUDO_POLICY_ADDRESS,
|
|
415
|
+
initData: '0x',
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
}))
|
|
419
|
+
: [sudoAction];
|
|
212
420
|
return {
|
|
213
421
|
sessionValidator: validator.address,
|
|
214
422
|
salt: viem_1.zeroHash,
|
|
215
423
|
sessionValidatorInitData: validator.initData,
|
|
216
424
|
erc7739Policies: erc7739Data,
|
|
217
|
-
actions
|
|
425
|
+
actions,
|
|
218
426
|
claimPolicies: [],
|
|
219
427
|
};
|
|
220
428
|
}
|
|
@@ -239,6 +447,157 @@ function getPermissionId(session) {
|
|
|
239
447
|
sessionData.salt,
|
|
240
448
|
]));
|
|
241
449
|
}
|
|
450
|
+
function getPolicyData(policy) {
|
|
451
|
+
switch (policy.type) {
|
|
452
|
+
case 'sudo':
|
|
453
|
+
return {
|
|
454
|
+
policy: SUDO_POLICY_ADDRESS,
|
|
455
|
+
initData: '0x',
|
|
456
|
+
};
|
|
457
|
+
case 'universal-action': {
|
|
458
|
+
function getCondition(condition) {
|
|
459
|
+
switch (condition) {
|
|
460
|
+
case 'equal':
|
|
461
|
+
return ACTION_CONDITION_EQUAL;
|
|
462
|
+
case 'greaterThan':
|
|
463
|
+
return ACTION_CONDITION_GREATER_THAN;
|
|
464
|
+
case 'lessThan':
|
|
465
|
+
return ACTION_CONDITION_LESS_THAN;
|
|
466
|
+
case 'greaterThanOrEqual':
|
|
467
|
+
return ACTION_CONDITION_GREATER_THAN_OR_EQUAL;
|
|
468
|
+
case 'lessThanOrEqual':
|
|
469
|
+
return ACTION_CONDITION_LESS_THAN_OR_EQUAL;
|
|
470
|
+
case 'notEqual':
|
|
471
|
+
return ACTION_CONDITION_NOT_EQUAL;
|
|
472
|
+
case 'inRange':
|
|
473
|
+
return ACTION_CONDITION_IN_RANGE;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
const MAX_RULES = 16;
|
|
477
|
+
const rules = createFixedArray(MAX_RULES, () => ({
|
|
478
|
+
condition: ACTION_CONDITION_EQUAL,
|
|
479
|
+
offset: 0n,
|
|
480
|
+
isLimited: false,
|
|
481
|
+
ref: viem_1.zeroHash,
|
|
482
|
+
usage: { limit: 0n, used: 0n },
|
|
483
|
+
}));
|
|
484
|
+
for (let i = 0; i < policy.rules.length; i++) {
|
|
485
|
+
const rule = policy.rules[i];
|
|
486
|
+
const ref = (0, viem_1.isHex)(rule.referenceValue)
|
|
487
|
+
? (0, viem_1.padHex)(rule.referenceValue)
|
|
488
|
+
: (0, viem_1.toHex)(rule.referenceValue, { size: 32 });
|
|
489
|
+
rules[i] = {
|
|
490
|
+
condition: getCondition(rule.condition),
|
|
491
|
+
offset: rule.calldataOffset,
|
|
492
|
+
isLimited: rule.usageLimit !== undefined,
|
|
493
|
+
ref,
|
|
494
|
+
usage: {
|
|
495
|
+
limit: rule.usageLimit ? rule.usageLimit : 0n,
|
|
496
|
+
used: 0n,
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
policy: UNIVERSAL_ACTION_POLICY_ADDRESS,
|
|
502
|
+
initData: (0, viem_1.encodeAbiParameters)([
|
|
503
|
+
{
|
|
504
|
+
components: [
|
|
505
|
+
{
|
|
506
|
+
name: 'valueLimitPerUse',
|
|
507
|
+
type: 'uint256',
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
components: [
|
|
511
|
+
{
|
|
512
|
+
name: 'length',
|
|
513
|
+
type: 'uint256',
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
components: [
|
|
517
|
+
{
|
|
518
|
+
name: 'condition',
|
|
519
|
+
type: 'uint8',
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
name: 'offset',
|
|
523
|
+
type: 'uint64',
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: 'isLimited',
|
|
527
|
+
type: 'bool',
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
name: 'ref',
|
|
531
|
+
type: 'bytes32',
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
components: [
|
|
535
|
+
{
|
|
536
|
+
name: 'limit',
|
|
537
|
+
type: 'uint256',
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
name: 'used',
|
|
541
|
+
type: 'uint256',
|
|
542
|
+
},
|
|
543
|
+
],
|
|
544
|
+
name: 'usage',
|
|
545
|
+
type: 'tuple',
|
|
546
|
+
},
|
|
547
|
+
],
|
|
548
|
+
name: 'rules',
|
|
549
|
+
type: 'tuple[16]',
|
|
550
|
+
},
|
|
551
|
+
],
|
|
552
|
+
name: 'paramRules',
|
|
553
|
+
type: 'tuple',
|
|
554
|
+
},
|
|
555
|
+
],
|
|
556
|
+
name: 'ActionConfig',
|
|
557
|
+
type: 'tuple',
|
|
558
|
+
},
|
|
559
|
+
], [
|
|
560
|
+
{
|
|
561
|
+
valueLimitPerUse: policy.valueLimitPerUse ?? 0n,
|
|
562
|
+
paramRules: {
|
|
563
|
+
length: BigInt(policy.rules.length),
|
|
564
|
+
rules: rules,
|
|
565
|
+
},
|
|
566
|
+
},
|
|
567
|
+
]),
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
case 'spending-limits': {
|
|
571
|
+
const tokens = policy.limits.map(({ token }) => token);
|
|
572
|
+
const limits = policy.limits.map(({ amount }) => amount);
|
|
573
|
+
return {
|
|
574
|
+
policy: SPENDING_LIMITS_POLICY_ADDRESS,
|
|
575
|
+
initData: (0, viem_1.encodeAbiParameters)([{ type: 'address[]' }, { type: 'uint256[]' }], [tokens, limits]),
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
case 'time-frame': {
|
|
579
|
+
return {
|
|
580
|
+
policy: TIME_FRAME_POLICY_ADDRESS,
|
|
581
|
+
initData: (0, viem_1.encodePacked)(['uint48', 'uint48'], [
|
|
582
|
+
Math.floor(policy.validUntil / 1000),
|
|
583
|
+
Math.floor(policy.validAfter / 1000),
|
|
584
|
+
]),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
case 'usage-limit': {
|
|
588
|
+
return {
|
|
589
|
+
policy: USAGE_LIMIT_POLICY_ADDRESS,
|
|
590
|
+
initData: (0, viem_1.encodePacked)(['uint128'], [policy.limit]),
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
case 'value-limit': {
|
|
594
|
+
return {
|
|
595
|
+
policy: VALUE_LIMIT_POLICY_ADDRESS,
|
|
596
|
+
initData: (0, viem_1.encodeAbiParameters)([{ type: 'uint256' }], [policy.limit]),
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
242
601
|
function getSmartSessionValidator(config) {
|
|
243
602
|
if (!config.experimental_sessions) {
|
|
244
603
|
return null;
|
|
@@ -248,10 +607,18 @@ function getSmartSessionValidator(config) {
|
|
|
248
607
|
return null;
|
|
249
608
|
}
|
|
250
609
|
return {
|
|
251
|
-
address: module ??
|
|
610
|
+
address: module ?? getSmartSessionEmissaryAddress(config.useDevContracts),
|
|
252
611
|
initData: '0x',
|
|
253
612
|
deInitData: '0x',
|
|
254
613
|
additionalContext: '0x',
|
|
255
614
|
type: common_1.MODULE_TYPE_ID_VALIDATOR,
|
|
256
615
|
};
|
|
257
616
|
}
|
|
617
|
+
function getSmartSessionEmissaryAddress(useDevContracts) {
|
|
618
|
+
return useDevContracts === true
|
|
619
|
+
? core_1.SMART_SESSION_EMISSARY_ADDRESS_DEV
|
|
620
|
+
: core_1.SMART_SESSION_EMISSARY_ADDRESS;
|
|
621
|
+
}
|
|
622
|
+
function createFixedArray(length, getValue) {
|
|
623
|
+
return Array.from({ length }, (_, i) => getValue(i));
|
|
624
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address } from 'viem';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IntentInput, IntentOpStatus, IntentResult, IntentRoute, Portfolio, SignedIntentOp, SplitIntentsInput, SplitIntentsResult } from './types';
|
|
3
3
|
export declare class Orchestrator {
|
|
4
4
|
private serverUrl;
|
|
5
5
|
private apiKey?;
|
|
@@ -10,13 +10,8 @@ export declare class Orchestrator {
|
|
|
10
10
|
[chainId: number]: Address[];
|
|
11
11
|
};
|
|
12
12
|
}): Promise<Portfolio>;
|
|
13
|
-
getMaxTokenAmount(account: {
|
|
14
|
-
address: Address;
|
|
15
|
-
accountType: AccountType;
|
|
16
|
-
setupOps: Pick<Execution, 'to' | 'data'>[];
|
|
17
|
-
}, destinationChainId: number, destinationTokenAddress: Address, destinationGasUnits: bigint, sponsored: boolean): Promise<bigint>;
|
|
18
|
-
getIntentCost(input: IntentInput): Promise<IntentCost>;
|
|
19
13
|
getIntentRoute(input: IntentInput): Promise<IntentRoute>;
|
|
14
|
+
splitIntents(input: SplitIntentsInput): Promise<SplitIntentsResult>;
|
|
20
15
|
submitIntent(signedIntentOpUnformatted: SignedIntentOp, dryRun: boolean): Promise<IntentResult>;
|
|
21
16
|
getIntentOpStatus(intentId: bigint): Promise<IntentOpStatus>;
|
|
22
17
|
private getHeaders;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../orchestrator/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../orchestrator/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AA0BnC,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,WAAW,EACX,SAAS,EAET,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAchB,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,MAAM,CAAC,CAAQ;gBAEX,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAKxC,YAAY,CAChB,WAAW,EAAE,OAAO,EACpB,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;QACnB,MAAM,CAAC,EAAE;YACP,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,CAAA;SAC7B,CAAA;KACF,GACA,OAAO,CAAC,SAAS,CAAC;IA+Cf,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAQxD,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAwDnE,YAAY,CAChB,yBAAyB,EAAE,cAAc,EACzC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,YAAY,CAAC;IAgBlB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IASlE,OAAO,CAAC,UAAU;YAUJ,KAAK;IA4BnB,OAAO,CAAC,UAAU;IA6GlB,OAAO,CAAC,iBAAiB;CAmG1B"}
|
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Orchestrator = void 0;
|
|
4
4
|
const error_1 = require("./error");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
+
function parseTokenAmountsRecord(record) {
|
|
7
|
+
return Object.fromEntries(Object.entries(record).map(([addr, amount]) => [
|
|
8
|
+
addr,
|
|
9
|
+
BigInt(amount),
|
|
10
|
+
]));
|
|
11
|
+
}
|
|
6
12
|
class Orchestrator {
|
|
7
13
|
serverUrl;
|
|
8
14
|
apiKey;
|
|
@@ -42,57 +48,57 @@ class Orchestrator {
|
|
|
42
48
|
}));
|
|
43
49
|
return portfolio;
|
|
44
50
|
}
|
|
45
|
-
async
|
|
46
|
-
|
|
47
|
-
account,
|
|
48
|
-
destinationExecutions: [],
|
|
49
|
-
destinationChainId,
|
|
50
|
-
destinationGasUnits,
|
|
51
|
-
tokenRequests: [
|
|
52
|
-
{
|
|
53
|
-
tokenAddress: destinationTokenAddress,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
options: {
|
|
57
|
-
topupCompact: false,
|
|
58
|
-
sponsorSettings: {
|
|
59
|
-
gasSponsored: sponsored,
|
|
60
|
-
bridgeFeesSponsored: sponsored,
|
|
61
|
-
swapFeesSponsored: sponsored,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
if (!intentCost.hasFulfilledAll) {
|
|
66
|
-
return 0n;
|
|
67
|
-
}
|
|
68
|
-
const tokenReceived = intentCost.tokensReceived.find((token) => token.tokenAddress.toLowerCase() ===
|
|
69
|
-
destinationTokenAddress.toLowerCase());
|
|
70
|
-
if (!tokenReceived) {
|
|
71
|
-
return 0n;
|
|
72
|
-
}
|
|
73
|
-
const tokenAmount = tokenReceived.destinationAmount;
|
|
74
|
-
if (BigInt(tokenAmount) < 0n) {
|
|
75
|
-
return 0n;
|
|
76
|
-
}
|
|
77
|
-
// `sponsorSettings` is not taken into account in the API response for now
|
|
78
|
-
// As a workaround, we use the `amountSpent` if the transaction is sponsored
|
|
79
|
-
return sponsored
|
|
80
|
-
? BigInt(tokenReceived.amountSpent)
|
|
81
|
-
: BigInt(tokenReceived.destinationAmount);
|
|
82
|
-
}
|
|
83
|
-
async getIntentCost(input) {
|
|
84
|
-
return await this.fetch(`${this.serverUrl}/intents/cost`, {
|
|
51
|
+
async getIntentRoute(input) {
|
|
52
|
+
return await this.fetch(`${this.serverUrl}/intents/route`, {
|
|
85
53
|
method: 'POST',
|
|
86
54
|
headers: this.getHeaders(),
|
|
87
55
|
body: JSON.stringify((0, utils_1.convertBigIntFields)(input)),
|
|
88
56
|
});
|
|
89
57
|
}
|
|
90
|
-
async
|
|
91
|
-
|
|
58
|
+
async splitIntents(input) {
|
|
59
|
+
const response = await fetch(`${this.serverUrl}/intents/split`, {
|
|
92
60
|
method: 'POST',
|
|
93
61
|
headers: this.getHeaders(),
|
|
94
|
-
body: JSON.stringify((0, utils_1.convertBigIntFields)(
|
|
62
|
+
body: JSON.stringify((0, utils_1.convertBigIntFields)({
|
|
63
|
+
chainId: input.chain.id,
|
|
64
|
+
tokens: input.tokens,
|
|
65
|
+
settlementLayers: input.settlementLayers,
|
|
66
|
+
})),
|
|
67
|
+
});
|
|
68
|
+
if (response.ok) {
|
|
69
|
+
const json = await response.json();
|
|
70
|
+
return {
|
|
71
|
+
intents: json.intents.map(parseTokenAmountsRecord),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
let errorData = {};
|
|
75
|
+
try {
|
|
76
|
+
errorData = await response.json();
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
try {
|
|
80
|
+
const text = await response.text();
|
|
81
|
+
errorData = { message: text };
|
|
82
|
+
}
|
|
83
|
+
catch { }
|
|
84
|
+
}
|
|
85
|
+
if (response.status === 422 &&
|
|
86
|
+
errorData.error === 'INSUFFICIENT_LIQUIDITY') {
|
|
87
|
+
throw new error_1.InsufficientLiquidityError({
|
|
88
|
+
availableIntents: errorData.availableIntents.map(parseTokenAmountsRecord),
|
|
89
|
+
unfillable: parseTokenAmountsRecord(errorData.unfillable),
|
|
90
|
+
traceId: errorData.traceId,
|
|
91
|
+
statusCode: 422,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
this.parseError({
|
|
95
|
+
response: {
|
|
96
|
+
status: response.status,
|
|
97
|
+
data: errorData,
|
|
98
|
+
headers: {},
|
|
99
|
+
},
|
|
95
100
|
});
|
|
101
|
+
throw new error_1.OrchestratorError({ message: 'Unexpected error' });
|
|
96
102
|
}
|
|
97
103
|
async submitIntent(signedIntentOpUnformatted, dryRun) {
|
|
98
104
|
const signedIntentOp = (0, utils_1.convertBigIntFields)(signedIntentOpUnformatted);
|