@rhinestone/sdk 0.9.0 → 0.10.0

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.
@@ -6,22 +6,23 @@ declare function getDeployArgs(config: RhinestoneAccountConfig): {
6
6
  salt: `0x${string}`;
7
7
  hashedInitcode: `0x${string}`;
8
8
  implementation: `0x${string}`;
9
- initializationCallData: `0x${string}`;
9
+ initializationCallData: null;
10
10
  } | {
11
11
  factory: `0x${string}`;
12
12
  factoryData: `0x${string}`;
13
13
  salt: `0x${string}`;
14
14
  hashedInitcode: `0x${string}`;
15
15
  implementation: `0x${string}`;
16
- initializationCallData: null;
16
+ initializationCallData: `0x${string}`;
17
17
  };
18
18
  declare function getAddress(config: RhinestoneAccountConfig): `0x${string}`;
19
19
  declare function isDeployed(chain: Chain, config: RhinestoneAccountConfig): Promise<boolean>;
20
+ declare function deploy(config: RhinestoneAccountConfig, chain: Chain, session?: Session): Promise<void>;
20
21
  declare function deploySource(chain: Chain, config: RhinestoneAccountConfig): Promise<void>;
21
22
  declare function deployTarget(chain: Chain, config: RhinestoneAccountConfig, asUserOp: boolean): Promise<void>;
22
23
  declare function getBundleInitCode(config: RhinestoneAccountConfig): `0x${string}` | undefined;
23
24
  declare function getSmartAccount(config: RhinestoneAccountConfig, client: PublicClient, chain: Chain): Promise<import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>>;
24
25
  declare function getSmartSessionSmartAccount(config: RhinestoneAccountConfig, client: PublicClient, chain: Chain, session: Session): Promise<import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>>;
25
26
  declare function sign(validators: OwnerSet, chain: Chain, hash: Hex): Promise<`0x${string}`>;
26
- export { getDeployArgs, getBundleInitCode, getAddress, isDeployed, deploySource, deployTarget, getSmartAccount, getSmartSessionSmartAccount, sign, };
27
+ export { getDeployArgs, getBundleInitCode, getAddress, isDeployed, deploy, deploySource, deployTarget, getSmartAccount, getSmartSessionSmartAccount, sign, };
27
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../accounts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAKV,KAAK,GAAG,EAGR,KAAK,YAAY,EAIlB,MAAM,MAAM,CAAA;AAUb,OAAO,KAAK,EAEV,QAAQ,EACR,uBAAuB,EACvB,OAAO,EACR,MAAM,UAAU,CAAA;AAiBjB,iBAAS,aAAa,CAAC,MAAM,EAAE,uBAAuB;;;;;;;;;;;;;;EAUrD;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,uBAAuB,iBAgBlD;AAED,iBAAe,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,oBAiBtE;AAED,iBAAe,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,iBAMxE;AAED,iBAAe,YAAY,CACzB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,OAAO,iBASlB;AAUD,iBAAS,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,6BAUzD;AAgID,iBAAe,eAAe,CAC5B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,KAAK,sJA0Bb;AAED,iBAAe,2BAA2B,CACxC,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,sJA8BjB;AAED,iBAAe,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,0BAYhE;AAgED,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,2BAA2B,EAC3B,IAAI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ACZ,eAAe,EACf,2BAA2B,EAC3B,IAAI,GACL,CAAA"}
@@ -4,12 +4,14 @@ exports.getDeployArgs = getDeployArgs;
4
4
  exports.getBundleInitCode = getBundleInitCode;
5
5
  exports.getAddress = getAddress;
6
6
  exports.isDeployed = isDeployed;
7
+ exports.deploy = deploy;
7
8
  exports.deploySource = deploySource;
8
9
  exports.deployTarget = deployTarget;
9
10
  exports.getSmartAccount = getSmartAccount;
10
11
  exports.getSmartSessionSmartAccount = getSmartSessionSmartAccount;
11
12
  exports.sign = sign;
12
13
  const viem_1 = require("viem");
14
+ const smart_session_1 = require("../execution/smart-session");
13
15
  const modules_1 = require("../modules");
14
16
  const validators_1 = require("../modules/validators");
15
17
  const nexus_1 = require("./nexus");
@@ -56,6 +58,12 @@ async function isDeployed(chain, config) {
56
58
  }
57
59
  return (0, viem_1.size)(code) > 0;
58
60
  }
61
+ async function deploy(config, chain, session) {
62
+ await deploySource(chain, config);
63
+ if (session) {
64
+ await (0, smart_session_1.enableSmartSession)(chain, config, session);
65
+ }
66
+ }
59
67
  async function deploySource(chain, config) {
60
68
  if (is7702(config)) {
61
69
  return deploy7702Self(chain, config);
@@ -1,19 +1,9 @@
1
- import { type Address, type Chain, type Hex } from 'viem';
1
+ import { type Address, type Chain } from 'viem';
2
2
  import type { BundleResult } from '../orchestrator';
3
3
  import type { RhinestoneAccountConfig, Transaction } from '../types';
4
- type TransactionResult = {
5
- type: 'userop';
6
- hash: Hex;
7
- sourceChain: number;
8
- targetChain: number;
9
- } | {
10
- type: 'bundle';
11
- id: bigint;
12
- sourceChain?: number;
13
- targetChain: number;
14
- };
4
+ import type { BundleData, TransactionResult } from './utils';
15
5
  declare function sendTransaction(config: RhinestoneAccountConfig, transaction: Transaction): Promise<TransactionResult>;
16
- declare function waitForExecution(config: RhinestoneAccountConfig, result: TransactionResult, acceptsPreconfirmations: boolean): Promise<BundleResult | {
6
+ declare function waitForExecution(config: RhinestoneAccountConfig, result: TransactionResult, acceptsPreconfirmations: boolean): Promise<{
17
7
  actualGasCost: bigint;
18
8
  actualGasUsed: bigint;
19
9
  entryPoint: Address;
@@ -25,9 +15,9 @@ declare function waitForExecution(config: RhinestoneAccountConfig, result: Trans
25
15
  sender: Address;
26
16
  success: boolean;
27
17
  userOpHash: import("viem").Hash;
28
- }>;
18
+ } | BundleResult>;
29
19
  declare function getMaxSpendableAmount(config: RhinestoneAccountConfig, chain: Chain, tokenAddress: Address, gasUnits: bigint): Promise<bigint>;
30
20
  declare function getPortfolio(config: RhinestoneAccountConfig, onTestnets: boolean): Promise<import("../orchestrator").UserTokenBalance[]>;
31
21
  export { sendTransaction, waitForExecution, getMaxSpendableAmount, getPortfolio, };
32
- export type { TransactionResult };
22
+ export type { BundleData, TransactionResult };
33
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../execution/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,KAAK,EAIV,KAAK,GAAG,EAMT,MAAM,MAAM,CAAA;AAmBb,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,iBAAiB,CAAA;AAqBxB,OAAO,KAAK,EAEV,uBAAuB,EAIvB,WAAW,EACZ,MAAM,UAAU,CAAA;AASjB,KAAK,iBAAiB,GAClB;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,GAAG,CAAA;IACT,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;CACpB,GACD;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAEL,iBAAe,eAAe,CAC5B,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,WAAW,8BAyBzB;AAsSD,iBAAe,gBAAgB,CAC7B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,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qBAAqB,EACrB,YAAY,GACb,CAAA;AACD,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAA"}
@@ -5,16 +5,13 @@ exports.waitForExecution = waitForExecution;
5
5
  exports.getMaxSpendableAmount = getMaxSpendableAmount;
6
6
  exports.getPortfolio = getPortfolio;
7
7
  const viem_1 = require("viem");
8
- const account_abstraction_1 = require("viem/account-abstraction");
9
8
  const chains_1 = require("viem/chains");
10
9
  const accounts_1 = require("../accounts");
11
10
  const utils_1 = require("../accounts/utils");
12
- const modules_1 = require("../modules");
13
- const validators_1 = require("../modules/validators");
14
11
  const orchestrator_1 = require("../orchestrator");
15
- const consts_1 = require("../orchestrator/consts");
16
12
  const registry_1 = require("../orchestrator/registry");
17
13
  const smart_session_1 = require("./smart-session");
14
+ const utils_2 = require("./utils");
18
15
  const POLLING_INTERVAL = 500;
19
16
  async function sendTransaction(config, transaction) {
20
17
  if ('chain' in transaction) {
@@ -63,12 +60,6 @@ async function sendTransactionAsUserOp(config, sourceChain, targetChain, calls,
63
60
  });
64
61
  const sessionAccount = await (0, accounts_1.getSmartSessionSmartAccount)(config, publicClient, sourceChain, withSession);
65
62
  const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
66
- const targetPublicClient = (0, viem_1.createPublicClient)({
67
- chain: targetChain,
68
- transport: (0, viem_1.http)(),
69
- });
70
- const targetSessionAccount = await (0, accounts_1.getSmartSessionSmartAccount)(config, targetPublicClient, targetChain, withSession);
71
- const targetBundlerClient = (0, utils_1.getBundlerClient)(config, targetPublicClient);
72
63
  if (sourceChain.id === targetChain.id) {
73
64
  await (0, smart_session_1.enableSmartSession)(targetChain, config, withSession);
74
65
  const hash = await bundlerClient.sendUserOperation({
@@ -82,132 +73,18 @@ async function sendTransactionAsUserOp(config, sourceChain, targetChain, calls,
82
73
  targetChain: targetChain.id,
83
74
  };
84
75
  }
85
- const accountAccessList = sourceChain
86
- ? {
87
- chainIds: [sourceChain.id],
88
- }
89
- : (0, registry_1.getDefaultAccountAccessList)();
90
- const metaIntent = {
91
- targetChainId: targetChain.id,
92
- tokenTransfers: tokenRequests.map((tokenRequest) => ({
93
- tokenAddress: tokenRequest.address,
94
- amount: tokenRequest.amount,
95
- })),
96
- targetAccount: accountAddress,
97
- targetGasUnits: gasLimit,
98
- userOp: (0, orchestrator_1.getEmptyUserOp)(),
99
- accountAccessList,
100
- };
101
- const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
102
- const orderPath = await orchestrator.getOrderPath(metaIntent, accountAddress);
76
+ const orderPath = await (0, utils_2.getUserOpOrderPath)(sourceChain, targetChain, tokenRequests, accountAddress, gasLimit, config.rhinestoneApiKey);
103
77
  // Deploy the account on the target chain
104
78
  await (0, accounts_1.deployTarget)(targetChain, config, true);
105
79
  await (0, smart_session_1.enableSmartSession)(targetChain, config, withSession);
106
- const userOp = await targetBundlerClient.prepareUserOperation({
107
- account: targetSessionAccount,
108
- calls: [...orderPath[0].injectedExecutions, ...calls],
109
- stateOverride: [
110
- ...tokenRequests.map((request) => {
111
- const rootBalanceSlot = (0, orchestrator_1.getTokenRootBalanceSlot)(targetChain, request.address);
112
- const balanceSlot = rootBalanceSlot
113
- ? (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'uint256' }], [accountAddress, rootBalanceSlot]))
114
- : '0x';
115
- return {
116
- address: request.address,
117
- stateDiff: [
118
- {
119
- slot: balanceSlot,
120
- value: (0, viem_1.pad)((0, viem_1.toHex)(request.amount)),
121
- },
122
- ],
123
- };
124
- }),
125
- ],
126
- });
127
- userOp.signature = await targetSessionAccount.signUserOperation(userOp);
128
- const userOpHash = (0, account_abstraction_1.getUserOperationHash)({
129
- userOperation: userOp,
130
- chainId: targetChain.id,
131
- entryPointAddress: account_abstraction_1.entryPoint07Address,
132
- entryPointVersion: '0.7',
133
- });
134
- orderPath[0].orderBundle.segments[0].witness.userOpHash = userOpHash;
135
- const { hash, appDomainSeparator, contentsType, structHash } = await (0, smart_session_1.hashErc7739)(sourceChain, orderPath, accountAddress);
136
- const signature = await (0, accounts_1.sign)(withSession.owners, targetChain, hash);
137
- const sessionSignature = (0, smart_session_1.getSessionSignature)(signature, appDomainSeparator, structHash, contentsType, withSession);
138
- const smartSessionValidator = (0, validators_1.getSmartSessionValidator)(config);
139
- if (!smartSessionValidator) {
140
- throw new Error('Smart session validator not available');
141
- }
142
- const packedSig = (0, viem_1.encodePacked)(['address', 'bytes'], [smartSessionValidator.address, sessionSignature]);
143
- const signedOrderBundle = {
144
- ...orderPath[0].orderBundle,
145
- originSignatures: Array(orderPath[0].orderBundle.segments.length).fill(packedSig),
146
- targetSignature: packedSig,
147
- };
148
- const bundleResults = await orchestrator.postSignedOrderBundle([
149
- {
150
- signedOrderBundle,
151
- userOp,
152
- },
153
- ]);
154
- return {
155
- type: 'bundle',
156
- id: bundleResults[0].bundleId,
157
- sourceChain: sourceChain.id,
158
- targetChain: targetChain.id,
159
- };
80
+ const userOp = await (0, utils_2.getUserOp)(config, targetChain, withSession, orderPath, calls, tokenRequests, accountAddress);
81
+ const sessionSignature = await (0, utils_2.signUserOp)(config, sourceChain, targetChain, accountAddress, withSession, userOp, orderPath);
82
+ return await (0, utils_2.submitUserOp)(config, sourceChain, targetChain, userOp, orderPath, sessionSignature);
160
83
  }
161
84
  async function sendTransactionAsIntent(config, sourceChain, targetChain, calls, gasLimit, tokenRequests, accountAddress) {
162
- const accountAccessList = sourceChain
163
- ? {
164
- chainIds: [sourceChain.id],
165
- }
166
- : (0, registry_1.getDefaultAccountAccessList)();
167
- const metaIntent = {
168
- targetChainId: targetChain.id,
169
- tokenTransfers: tokenRequests.map((tokenRequest) => ({
170
- tokenAddress: tokenRequest.address,
171
- amount: tokenRequest.amount,
172
- })),
173
- targetAccount: accountAddress,
174
- targetExecutions: calls.map((call) => ({
175
- value: call.value ?? 0n,
176
- to: call.to,
177
- data: call.data ?? '0x',
178
- })),
179
- targetGasUnits: gasLimit,
180
- accountAccessList,
181
- };
182
- const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
183
- const orderPath = await orchestrator.getOrderPath(metaIntent, accountAddress);
184
- orderPath[0].orderBundle.segments[0].witness.execs = [
185
- ...orderPath[0].injectedExecutions,
186
- ...metaIntent.targetExecutions,
187
- ];
188
- const orderBundleHash = (0, orchestrator_1.getOrderBundleHash)(orderPath[0].orderBundle);
85
+ const { orderPath, hash: orderBundleHash } = await (0, utils_2.prepareTransactionAsIntent)(config, sourceChain, targetChain, calls, gasLimit, tokenRequests, accountAddress);
189
86
  const bundleSignature = await (0, accounts_1.sign)(config.owners, sourceChain || targetChain, orderBundleHash);
190
- const validatorModule = (0, modules_1.getOwnerValidator)(config);
191
- const packedSig = (0, viem_1.encodePacked)(['address', 'bytes'], [validatorModule.address, bundleSignature]);
192
- const signedOrderBundle = {
193
- ...orderPath[0].orderBundle,
194
- originSignatures: Array(orderPath[0].orderBundle.segments.length).fill(packedSig),
195
- targetSignature: packedSig,
196
- };
197
- await (0, accounts_1.deployTarget)(targetChain, config, false);
198
- const initCode = (0, accounts_1.getBundleInitCode)(config);
199
- const bundleResults = await orchestrator.postSignedOrderBundle([
200
- {
201
- signedOrderBundle,
202
- initCode,
203
- },
204
- ]);
205
- return {
206
- type: 'bundle',
207
- id: bundleResults[0].bundleId,
208
- sourceChain: sourceChain?.id,
209
- targetChain: targetChain.id,
210
- };
87
+ return await (0, utils_2.submitIntentInternal)(config, sourceChain, targetChain, orderPath, bundleSignature, true);
211
88
  }
212
89
  async function waitForExecution(config, result, acceptsPreconfirmations) {
213
90
  const validStatuses = new Set([
@@ -222,7 +99,7 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
222
99
  case 'bundle': {
223
100
  let bundleResult = null;
224
101
  while (bundleResult === null || !validStatuses.has(bundleResult.status)) {
225
- const orchestrator = getOrchestratorByChain(result.targetChain, config.rhinestoneApiKey);
102
+ const orchestrator = (0, utils_2.getOrchestratorByChain)(result.targetChain, config.rhinestoneApiKey);
226
103
  bundleResult = await orchestrator.getBundleStatus(result.id);
227
104
  await new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL));
228
105
  }
@@ -247,18 +124,12 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
247
124
  }
248
125
  async function getMaxSpendableAmount(config, chain, tokenAddress, gasUnits) {
249
126
  const address = (0, accounts_1.getAddress)(config);
250
- const orchestrator = getOrchestratorByChain(chain.id, config.rhinestoneApiKey);
127
+ const orchestrator = (0, utils_2.getOrchestratorByChain)(chain.id, config.rhinestoneApiKey);
251
128
  return orchestrator.getMaxTokenAmount(address, chain.id, tokenAddress, gasUnits);
252
129
  }
253
130
  async function getPortfolio(config, onTestnets) {
254
131
  const address = (0, accounts_1.getAddress)(config);
255
132
  const chainId = onTestnets ? chains_1.sepolia.id : chains_1.mainnet.id;
256
- const orchestrator = getOrchestratorByChain(chainId, config.rhinestoneApiKey);
133
+ const orchestrator = (0, utils_2.getOrchestratorByChain)(chainId, config.rhinestoneApiKey);
257
134
  return orchestrator.getPortfolio(address, (0, registry_1.getDefaultAccountAccessList)());
258
135
  }
259
- function getOrchestratorByChain(chainId, apiKey) {
260
- const orchestratorUrl = (0, registry_1.isTestnet)(chainId)
261
- ? consts_1.DEV_ORCHESTRATOR_URL
262
- : consts_1.PROD_ORCHESTRATOR_URL;
263
- return (0, orchestrator_1.getOrchestrator)(apiKey, orchestratorUrl);
264
- }
@@ -0,0 +1,66 @@
1
+ import { Address, Chain, Hex } from 'viem';
2
+ import { UserOperation } from 'viem/account-abstraction';
3
+ import { OrderPath } from '../orchestrator/types';
4
+ import { Call, RhinestoneAccountConfig, Session, TokenRequest, Transaction } from '../types';
5
+ type TransactionResult = {
6
+ type: 'userop';
7
+ hash: Hex;
8
+ sourceChain: number;
9
+ targetChain: number;
10
+ } | {
11
+ type: 'bundle';
12
+ id: bigint;
13
+ sourceChain?: number;
14
+ targetChain: number;
15
+ };
16
+ interface BundleData {
17
+ hash: Hex;
18
+ orderPath: OrderPath;
19
+ userOp?: UserOperation;
20
+ }
21
+ interface PreparedTransactionData {
22
+ bundleData: BundleData;
23
+ transaction: Transaction;
24
+ }
25
+ interface SignedTransactionData extends PreparedTransactionData {
26
+ signature: Hex;
27
+ }
28
+ declare function prepareTransaction(config: RhinestoneAccountConfig, transaction: Transaction): Promise<PreparedTransactionData>;
29
+ declare function signTransaction(config: RhinestoneAccountConfig, preparedTransaction: PreparedTransactionData): Promise<SignedTransactionData>;
30
+ declare function submitTransaction(config: RhinestoneAccountConfig, signedTransaction: SignedTransactionData): Promise<TransactionResult>;
31
+ declare function prepareTransactionAsIntent(config: RhinestoneAccountConfig, sourceChain: Chain | undefined, targetChain: Chain, calls: Call[], gasLimit: bigint | undefined, tokenRequests: TokenRequest[], accountAddress: Address): Promise<BundleData>;
32
+ declare function signUserOp(config: RhinestoneAccountConfig, sourceChain: Chain, targetChain: Chain, accountAddress: Address, withSession: Session, userOp: UserOperation, orderPath: OrderPath): Promise<`0x${string}`>;
33
+ declare function submitUserOp(config: RhinestoneAccountConfig, sourceChain: Chain, targetChain: Chain, userOp: UserOperation, orderPath: OrderPath, sessionSignature: Hex): Promise<TransactionResult>;
34
+ declare function getOrchestratorByChain(chainId: number, apiKey: string): import("../orchestrator").Orchestrator;
35
+ declare function getUserOpOrderPath(sourceChain: Chain, targetChain: Chain, tokenRequests: TokenRequest[], accountAddress: Address, gasLimit: bigint | undefined, rhinestoneApiKey: string): Promise<OrderPath>;
36
+ declare function getUserOp(config: RhinestoneAccountConfig, targetChain: Chain, withSession: Session, orderPath: OrderPath, calls: Call[], tokenRequests: TokenRequest[], accountAddress: Address): Promise<{
37
+ readonly account: import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>;
38
+ readonly stateOverride: {
39
+ address: `0x${string}`;
40
+ stateDiff: {
41
+ slot: `0x${string}`;
42
+ value: `0x${string}`;
43
+ }[];
44
+ }[];
45
+ callData: Hex;
46
+ paymasterAndData: undefined;
47
+ sender: UserOperation["sender"];
48
+ authorization: UserOperation["authorization"];
49
+ factory: UserOperation["factory"];
50
+ factoryData: UserOperation["factoryData"];
51
+ nonce: UserOperation["nonce"];
52
+ maxFeePerGas: UserOperation["maxFeePerGas"];
53
+ maxPriorityFeePerGas: UserOperation["maxPriorityFeePerGas"];
54
+ callGasLimit: UserOperation["callGasLimit"];
55
+ preVerificationGas: UserOperation["preVerificationGas"];
56
+ verificationGasLimit: UserOperation["verificationGasLimit"];
57
+ paymasterPostOpGasLimit: UserOperation["paymasterPostOpGasLimit"];
58
+ paymasterVerificationGasLimit: UserOperation["paymasterVerificationGasLimit"];
59
+ paymaster: UserOperation["paymaster"];
60
+ paymasterData: UserOperation["paymasterData"];
61
+ signature: UserOperation["signature"];
62
+ }>;
63
+ declare function submitIntentInternal(config: RhinestoneAccountConfig, sourceChain: Chain | undefined, targetChain: Chain, orderPath: OrderPath, bundleSignature: Hex, deploy: boolean): Promise<TransactionResult>;
64
+ export { prepareTransaction, signTransaction, submitTransaction, getOrchestratorByChain, getUserOpOrderPath, getUserOp, signUserOp, submitUserOp, prepareTransactionAsIntent, submitIntentInternal, };
65
+ export type { BundleData, TransactionResult, PreparedTransactionData, SignedTransactionData, };
66
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../execution/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,EAIL,GAAG,EAMJ,MAAM,MAAM,CAAA;AACb,OAAO,EAGL,aAAa,EACd,MAAM,0BAA0B,CAAA;AA2BjC,OAAO,EAEL,SAAS,EAGV,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,IAAI,EACJ,uBAAuB,EACvB,OAAO,EACP,YAAY,EACZ,WAAW,EACZ,MAAM,UAAU,CAAA;AAIjB,KAAK,iBAAiB,GAClB;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,GAAG,CAAA;I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
+ exports.prepareTransaction = prepareTransaction;
4
+ exports.signTransaction = signTransaction;
5
+ exports.submitTransaction = submitTransaction;
6
+ exports.getOrchestratorByChain = getOrchestratorByChain;
7
+ exports.getUserOpOrderPath = getUserOpOrderPath;
8
+ exports.getUserOp = getUserOp;
9
+ exports.signUserOp = signUserOp;
10
+ exports.submitUserOp = submitUserOp;
11
+ exports.prepareTransactionAsIntent = prepareTransactionAsIntent;
12
+ exports.submitIntentInternal = submitIntentInternal;
13
+ const viem_1 = require("viem");
14
+ const account_abstraction_1 = require("viem/account-abstraction");
15
+ const accounts_1 = require("../accounts");
16
+ const utils_1 = require("../accounts/utils");
17
+ const validators_1 = require("../modules/validators");
18
+ const orchestrator_1 = require("../orchestrator");
19
+ const consts_1 = require("../orchestrator/consts");
20
+ const registry_1 = require("../orchestrator/registry");
21
+ const smart_session_1 = require("./smart-session");
22
+ async function prepareTransaction(config, transaction) {
23
+ const { sourceChain, targetChain, tokenRequests, withSession } = getTransactionParams(transaction);
24
+ const accountAddress = (0, accounts_1.getAddress)(config);
25
+ let bundleData;
26
+ if (withSession) {
27
+ if (!sourceChain) {
28
+ throw new Error(`Specifying source chain is required when using smart sessions`);
29
+ }
30
+ // Smart sessions require a UserOp flow
31
+ bundleData = await prepareTransactionAsUserOp(config, sourceChain, targetChain, transaction.calls, transaction.gasLimit, tokenRequests, accountAddress, withSession);
32
+ }
33
+ else {
34
+ bundleData = await prepareTransactionAsIntent(config, sourceChain, targetChain, transaction.calls, transaction.gasLimit, tokenRequests, accountAddress);
35
+ }
36
+ return {
37
+ bundleData,
38
+ transaction,
39
+ };
40
+ }
41
+ async function signTransaction(config, preparedTransaction) {
42
+ const { sourceChain, targetChain, withSession } = getTransactionParams(preparedTransaction.transaction);
43
+ const bundleData = preparedTransaction.bundleData;
44
+ const accountAddress = (0, accounts_1.getAddress)(config);
45
+ let signature;
46
+ if (withSession) {
47
+ if (!sourceChain) {
48
+ throw new Error(`Specifying source chain is required when using smart sessions`);
49
+ }
50
+ const userOp = bundleData.userOp;
51
+ if (!userOp) {
52
+ throw new Error(`User operation is required when using smart sessions`);
53
+ }
54
+ // Smart sessions require a UserOp flow
55
+ signature = await signUserOp(config, sourceChain, targetChain, accountAddress, withSession, userOp, bundleData.orderPath);
56
+ }
57
+ else {
58
+ signature = await signIntent(config, sourceChain, targetChain, bundleData.hash);
59
+ }
60
+ return {
61
+ bundleData,
62
+ transaction: preparedTransaction.transaction,
63
+ signature,
64
+ };
65
+ }
66
+ async function submitTransaction(config, signedTransaction) {
67
+ const { bundleData, transaction, signature } = signedTransaction;
68
+ const { sourceChain, targetChain, withSession } = getTransactionParams(transaction);
69
+ if (withSession) {
70
+ if (!sourceChain) {
71
+ throw new Error(`Specifying source chain is required when using smart sessions`);
72
+ }
73
+ const userOp = bundleData.userOp;
74
+ if (!userOp) {
75
+ throw new Error(`User operation is required when using smart sessions`);
76
+ }
77
+ // Smart sessions require a UserOp flow
78
+ return await submitUserOp(config, sourceChain, targetChain, userOp, bundleData.orderPath, signature);
79
+ }
80
+ else {
81
+ return await submitIntent(config, sourceChain, targetChain, bundleData.orderPath, signature);
82
+ }
83
+ }
84
+ function getTransactionParams(transaction) {
85
+ const sourceChain = 'chain' in transaction ? transaction.chain : transaction.sourceChain;
86
+ const targetChain = 'chain' in transaction ? transaction.chain : transaction.targetChain;
87
+ const initialTokenRequests = transaction.tokenRequests;
88
+ const withSession = transaction.signers?.type === 'session' ? transaction.signers.session : null;
89
+ // Across requires passing some value to repay the solvers
90
+ const tokenRequests = initialTokenRequests.length === 0
91
+ ? [
92
+ {
93
+ address: viem_1.zeroAddress,
94
+ amount: 1n,
95
+ },
96
+ ]
97
+ : initialTokenRequests;
98
+ return {
99
+ sourceChain,
100
+ targetChain,
101
+ tokenRequests,
102
+ withSession,
103
+ };
104
+ }
105
+ async function prepareTransactionAsUserOp(config, sourceChain, targetChain, calls, gasLimit, tokenRequests, accountAddress, withSession) {
106
+ if (sourceChain.id === targetChain.id) {
107
+ throw new Error('Source and target chains cannot be the same when using user operations');
108
+ }
109
+ const orderPath = await getUserOpOrderPath(sourceChain, targetChain, tokenRequests, accountAddress, gasLimit, config.rhinestoneApiKey);
110
+ const userOp = await getUserOp(config, targetChain, withSession, orderPath, calls, tokenRequests, accountAddress);
111
+ const hash = (0, account_abstraction_1.getUserOperationHash)({
112
+ userOperation: userOp,
113
+ entryPointAddress: account_abstraction_1.entryPoint07Address,
114
+ entryPointVersion: '0.7',
115
+ chainId: targetChain.id,
116
+ });
117
+ return {
118
+ orderPath,
119
+ userOp,
120
+ hash,
121
+ };
122
+ }
123
+ async function prepareTransactionAsIntent(config, sourceChain, targetChain, calls, gasLimit, tokenRequests, accountAddress) {
124
+ const accountAccessList = sourceChain
125
+ ? {
126
+ chainIds: [sourceChain.id],
127
+ }
128
+ : (0, registry_1.getDefaultAccountAccessList)();
129
+ const metaIntent = {
130
+ targetChainId: targetChain.id,
131
+ tokenTransfers: tokenRequests.map((tokenRequest) => ({
132
+ tokenAddress: tokenRequest.address,
133
+ amount: tokenRequest.amount,
134
+ })),
135
+ targetAccount: accountAddress,
136
+ targetExecutions: calls.map((call) => ({
137
+ value: call.value ?? 0n,
138
+ to: call.to,
139
+ data: call.data ?? '0x',
140
+ })),
141
+ targetGasUnits: gasLimit,
142
+ accountAccessList,
143
+ };
144
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
145
+ const orderPath = await orchestrator.getOrderPath(metaIntent, accountAddress);
146
+ orderPath[0].orderBundle.segments[0].witness.execs = [
147
+ ...orderPath[0].injectedExecutions,
148
+ ...metaIntent.targetExecutions,
149
+ ];
150
+ const orderBundleHash = (0, orchestrator_1.getOrderBundleHash)(orderPath[0].orderBundle);
151
+ return {
152
+ orderPath,
153
+ hash: orderBundleHash,
154
+ };
155
+ }
156
+ async function signIntent(config, sourceChain, targetChain, bundleHash) {
157
+ const signature = await (0, accounts_1.sign)(config.owners, sourceChain || targetChain, bundleHash);
158
+ return signature;
159
+ }
160
+ async function signUserOp(config, sourceChain, targetChain, accountAddress, withSession, userOp, orderPath) {
161
+ const targetPublicClient = (0, viem_1.createPublicClient)({
162
+ chain: targetChain,
163
+ transport: (0, viem_1.http)(),
164
+ });
165
+ const targetSessionAccount = await (0, accounts_1.getSmartSessionSmartAccount)(config, targetPublicClient, targetChain, withSession);
166
+ userOp.signature = await targetSessionAccount.signUserOperation(userOp);
167
+ const userOpHash = (0, account_abstraction_1.getUserOperationHash)({
168
+ userOperation: userOp,
169
+ chainId: targetChain.id,
170
+ entryPointAddress: account_abstraction_1.entryPoint07Address,
171
+ entryPointVersion: '0.7',
172
+ });
173
+ orderPath[0].orderBundle.segments[0].witness.userOpHash = userOpHash;
174
+ const { hash, appDomainSeparator, contentsType, structHash } = await (0, smart_session_1.hashErc7739)(sourceChain, orderPath, accountAddress);
175
+ const signature = await (0, accounts_1.sign)(withSession.owners, targetChain, hash);
176
+ const sessionSignature = (0, smart_session_1.getSessionSignature)(signature, appDomainSeparator, structHash, contentsType, withSession);
177
+ return sessionSignature;
178
+ }
179
+ async function submitUserOp(config, sourceChain, targetChain, userOp, orderPath, sessionSignature) {
180
+ const smartSessionValidator = (0, validators_1.getSmartSessionValidator)(config);
181
+ if (!smartSessionValidator) {
182
+ throw new Error('Smart session validator not available');
183
+ }
184
+ const packedSig = (0, viem_1.encodePacked)(['address', 'bytes'], [smartSessionValidator.address, sessionSignature]);
185
+ const signedOrderBundle = {
186
+ ...orderPath[0].orderBundle,
187
+ originSignatures: Array(orderPath[0].orderBundle.segments.length).fill(packedSig),
188
+ targetSignature: packedSig,
189
+ };
190
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
191
+ const bundleResults = await orchestrator.postSignedOrderBundle([
192
+ {
193
+ signedOrderBundle,
194
+ userOp,
195
+ },
196
+ ]);
197
+ return {
198
+ type: 'bundle',
199
+ id: bundleResults[0].bundleId,
200
+ sourceChain: sourceChain.id,
201
+ targetChain: targetChain.id,
202
+ };
203
+ }
204
+ async function submitIntent(config, sourceChain, targetChain, orderPath, bundleSignature) {
205
+ const validatorModule = (0, validators_1.getOwnerValidator)(config);
206
+ const packedSig = (0, viem_1.encodePacked)(['address', 'bytes'], [validatorModule.address, bundleSignature]);
207
+ const signedOrderBundle = {
208
+ ...orderPath[0].orderBundle,
209
+ originSignatures: Array(orderPath[0].orderBundle.segments.length).fill(packedSig),
210
+ targetSignature: packedSig,
211
+ };
212
+ const initCode = (0, accounts_1.getBundleInitCode)(config);
213
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
214
+ const bundleResults = await orchestrator.postSignedOrderBundle([
215
+ {
216
+ signedOrderBundle,
217
+ initCode,
218
+ },
219
+ ]);
220
+ return {
221
+ type: 'bundle',
222
+ id: bundleResults[0].bundleId,
223
+ sourceChain: sourceChain?.id,
224
+ targetChain: targetChain.id,
225
+ };
226
+ }
227
+ function getOrchestratorByChain(chainId, apiKey) {
228
+ const orchestratorUrl = (0, registry_1.isTestnet)(chainId)
229
+ ? consts_1.DEV_ORCHESTRATOR_URL
230
+ : consts_1.PROD_ORCHESTRATOR_URL;
231
+ return (0, orchestrator_1.getOrchestrator)(apiKey, orchestratorUrl);
232
+ }
233
+ async function getUserOpOrderPath(sourceChain, targetChain, tokenRequests, accountAddress, gasLimit, rhinestoneApiKey) {
234
+ const accountAccessList = sourceChain
235
+ ? {
236
+ chainIds: [sourceChain.id],
237
+ }
238
+ : (0, registry_1.getDefaultAccountAccessList)();
239
+ const metaIntent = {
240
+ targetChainId: targetChain.id,
241
+ tokenTransfers: tokenRequests.map((tokenRequest) => ({
242
+ tokenAddress: tokenRequest.address,
243
+ amount: tokenRequest.amount,
244
+ })),
245
+ targetAccount: accountAddress,
246
+ targetGasUnits: gasLimit,
247
+ userOp: (0, orchestrator_1.getEmptyUserOp)(),
248
+ accountAccessList,
249
+ };
250
+ const orchestrator = getOrchestratorByChain(targetChain.id, rhinestoneApiKey);
251
+ const orderPath = await orchestrator.getOrderPath(metaIntent, accountAddress);
252
+ return orderPath;
253
+ }
254
+ async function getUserOp(config, targetChain, withSession, orderPath, calls, tokenRequests, accountAddress) {
255
+ const targetPublicClient = (0, viem_1.createPublicClient)({
256
+ chain: targetChain,
257
+ transport: (0, viem_1.http)(),
258
+ });
259
+ const targetSessionAccount = await (0, accounts_1.getSmartSessionSmartAccount)(config, targetPublicClient, targetChain, withSession);
260
+ const targetBundlerClient = (0, utils_1.getBundlerClient)(config, targetPublicClient);
261
+ return await targetBundlerClient.prepareUserOperation({
262
+ account: targetSessionAccount,
263
+ calls: [...orderPath[0].injectedExecutions, ...calls],
264
+ stateOverride: [
265
+ ...tokenRequests.map((request) => {
266
+ const rootBalanceSlot = (0, registry_1.getTokenRootBalanceSlot)(targetChain, request.address);
267
+ const balanceSlot = rootBalanceSlot
268
+ ? (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'uint256' }], [accountAddress, rootBalanceSlot]))
269
+ : '0x';
270
+ return {
271
+ address: request.address,
272
+ stateDiff: [
273
+ {
274
+ slot: balanceSlot,
275
+ value: (0, viem_1.pad)((0, viem_1.toHex)(request.amount)),
276
+ },
277
+ ],
278
+ };
279
+ }),
280
+ ],
281
+ });
282
+ }
283
+ async function submitIntentInternal(config, sourceChain, targetChain, orderPath, bundleSignature, deploy) {
284
+ const validatorModule = (0, validators_1.getOwnerValidator)(config);
285
+ const packedSig = (0, viem_1.encodePacked)(['address', 'bytes'], [validatorModule.address, bundleSignature]);
286
+ const signedOrderBundle = {
287
+ ...orderPath[0].orderBundle,
288
+ originSignatures: Array(orderPath[0].orderBundle.segments.length).fill(packedSig),
289
+ targetSignature: packedSig,
290
+ };
291
+ if (deploy) {
292
+ await (0, accounts_1.deployTarget)(targetChain, config, false);
293
+ }
294
+ const initCode = (0, accounts_1.getBundleInitCode)(config);
295
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
296
+ const bundleResults = await orchestrator.postSignedOrderBundle([
297
+ {
298
+ signedOrderBundle,
299
+ initCode,
300
+ },
301
+ ]);
302
+ return {
303
+ type: 'bundle',
304
+ id: bundleResults[0].bundleId,
305
+ sourceChain: sourceChain?.id,
306
+ targetChain: targetChain.id,
307
+ };
308
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Address, Chain } from 'viem';
2
2
  import type { TransactionResult } from './execution';
3
+ import { BundleData, PreparedTransactionData, SignedTransactionData } from './execution/utils';
3
4
  import type { BundleStatus, MetaIntent, MultiChainCompact, PostOrderBundleResult, SignedMultiChainCompact } from './orchestrator';
4
5
  import type { Call, Execution, RhinestoneAccountConfig, Session, Transaction } from './types';
5
6
  /**
@@ -10,8 +11,12 @@ import type { Call, Execution, RhinestoneAccountConfig, Session, Transaction } f
10
11
  */
11
12
  declare function createRhinestoneAccount(config: RhinestoneAccountConfig): Promise<{
12
13
  config: RhinestoneAccountConfig;
14
+ deploy: (chain: Chain, session?: Session) => Promise<void>;
15
+ prepareTransaction: (transaction: Transaction) => Promise<PreparedTransactionData>;
16
+ signTransaction: (preparedTransaction: PreparedTransactionData) => Promise<SignedTransactionData>;
17
+ submitTransaction: (signedTransaction: SignedTransactionData) => Promise<TransactionResult>;
13
18
  sendTransaction: (transaction: Transaction) => Promise<TransactionResult>;
14
- waitForExecution: (result: TransactionResult, acceptsPreconfirmations?: boolean) => Promise<import("./orchestrator").BundleResult | {
19
+ waitForExecution: (result: TransactionResult, acceptsPreconfirmations?: boolean) => Promise<{
15
20
  actualGasCost: bigint;
16
21
  actualGasUsed: bigint;
17
22
  entryPoint: Address;
@@ -23,11 +28,11 @@ declare function createRhinestoneAccount(config: RhinestoneAccountConfig): Promi
23
28
  sender: Address;
24
29
  success: boolean;
25
30
  userOpHash: import("viem").Hash;
26
- }>;
31
+ } | import("./orchestrator").BundleResult>;
27
32
  getAddress: () => `0x${string}`;
28
33
  getPortfolio: (onTestnets?: boolean) => Promise<import("./orchestrator").UserTokenBalance[]>;
29
34
  getMaxSpendableAmount: (chain: Chain, tokenAddress: Address, gasUnits: bigint) => Promise<bigint>;
30
35
  }>;
31
36
  export { createRhinestoneAccount };
32
- export type { BundleStatus, Session, Call, Execution, MetaIntent, MultiChainCompact, PostOrderBundleResult, SignedMultiChainCompact, };
37
+ export type { BundleStatus, Session, Call, Execution, MetaIntent, MultiChainCompact, PostOrderBundleResult, SignedMultiChainCompact, BundleData, PreparedTransactionData, SignedTransactionData, TransactionResult, };
33
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAOpD,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EACT,uBAAuB,EACvB,OAAO,EACP,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB;;;;;GAKG;AACH,iBAAe,uBAAuB,CAAC,MAAM,EAAE,uBAAuB;;mCAM9B,WAAW;+BAWvC,iBAAiB;;;;;;;;;;;;;;;mCA+BlB,KAAK,gBACE,OAAO,YACX,MAAM;GAanB;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAA;AAClC,YAAY,EACV,YAAY,EACZ,OAAO,EACP,IAAI,EACJ,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,GACxB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAK1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAOpD,OAAO,EACL,UAAU,EACV,uBAAuB,EAEvB,qBAAqB,EAGtB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EACT,uBAAuB,EACvB,OAAO,EACP,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB;;;;;GAKG;AACH,iBAAe,uBAAuB,CAAC,MAAM,EAAE,uBAAuB;;oBAC7C,KAAK,YAAY,OAAO;sCAIN,WAAW;2CAIN,uBAAuB;2CAIvB,qBAAqB;mCAS7B,WAAW;+BAWvC,iBAAiB;;;;;;;;;;;;;;;mCA+BlB,KAAK,gBACE,OAAO,YACX,MAAM;GAiBnB;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAA;AAClC,YAAY,EACV,YAAY,EACZ,OAAO,EACP,IAAI,EACJ,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,UAAU,EACV,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,GAClB,CAAA"}
package/dist/src/index.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRhinestoneAccount = createRhinestoneAccount;
4
4
  const accounts_1 = require("./accounts");
5
5
  const execution_1 = require("./execution");
6
+ const utils_1 = require("./execution/utils");
6
7
  /**
7
8
  * Initialize a Rhinestone account
8
9
  * Note: accounts are deployed onchain only when the first transaction is sent.
@@ -10,6 +11,18 @@ const execution_1 = require("./execution");
10
11
  * @returns account
11
12
  */
12
13
  async function createRhinestoneAccount(config) {
14
+ function deploy(chain, session) {
15
+ return (0, accounts_1.deploy)(config, chain, session);
16
+ }
17
+ function prepareTransaction(transaction) {
18
+ return (0, utils_1.prepareTransaction)(config, transaction);
19
+ }
20
+ function signTransaction(preparedTransaction) {
21
+ return (0, utils_1.signTransaction)(config, preparedTransaction);
22
+ }
23
+ function submitTransaction(signedTransaction) {
24
+ return (0, utils_1.submitTransaction)(config, signedTransaction);
25
+ }
13
26
  /**
14
27
  * Sign and send a transaction
15
28
  * @param transaction Transaction to send
@@ -54,6 +67,10 @@ async function createRhinestoneAccount(config) {
54
67
  }
55
68
  return {
56
69
  config,
70
+ deploy,
71
+ prepareTransaction,
72
+ signTransaction,
73
+ submitTransaction,
57
74
  sendTransaction,
58
75
  waitForExecution,
59
76
  getAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinestone/sdk",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "End-to-end chain abstraction and modularity toolkit",
5
5
  "author": {
6
6
  "name": "Rhinestone",