@rhinestone/sdk 0.2.0 → 0.3.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.
Files changed (101) hide show
  1. package/README.md +7 -19
  2. package/dist/accounts/index.d.ts +15535 -0
  3. package/dist/accounts/index.d.ts.map +1 -0
  4. package/dist/accounts/index.js +242 -0
  5. package/dist/accounts/nexus.d.ts +23281 -0
  6. package/dist/accounts/nexus.d.ts.map +1 -0
  7. package/dist/accounts/nexus.js +230 -0
  8. package/dist/accounts/safe.d.ts +15 -0
  9. package/dist/accounts/safe.d.ts.map +1 -0
  10. package/dist/{services/account → accounts}/safe.js +36 -37
  11. package/dist/accounts/utils.d.ts +27 -0
  12. package/dist/accounts/utils.d.ts.map +1 -0
  13. package/dist/accounts/utils.js +155 -0
  14. package/dist/examples/abi/weth.d.ts +214 -0
  15. package/dist/examples/abi/weth.d.ts.map +1 -0
  16. package/dist/examples/abi/weth.js +279 -0
  17. package/dist/examples/cross-chain-ss.d.ts +1 -0
  18. package/dist/examples/cross-chain-ss.d.ts.map +1 -0
  19. package/dist/{example.js → examples/cross-chain-ss.js} +70 -44
  20. package/dist/examples/omni-account.d.ts +1 -0
  21. package/dist/examples/omni-account.d.ts.map +1 -0
  22. package/dist/examples/omni-account.js +169 -0
  23. package/dist/examples/smart-sessions.d.ts +1 -0
  24. package/dist/examples/smart-sessions.d.ts.map +1 -0
  25. package/dist/examples/smart-sessions.js +216 -0
  26. package/dist/execution/index.d.ts +31 -0
  27. package/dist/execution/index.d.ts.map +1 -0
  28. package/dist/execution/index.js +222 -0
  29. package/dist/execution/smart-session.d.ts +14 -0
  30. package/dist/execution/smart-session.d.ts.map +1 -0
  31. package/dist/execution/smart-session.js +83 -0
  32. package/dist/index.d.ts +15 -4
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +11 -11
  35. package/dist/modules/abi/smart-sessions.d.ts +42 -0
  36. package/dist/modules/abi/smart-sessions.d.ts.map +1 -0
  37. package/dist/modules/abi/smart-sessions.js +128 -0
  38. package/dist/modules/common.d.ts +16 -0
  39. package/dist/modules/common.d.ts.map +1 -0
  40. package/dist/modules/common.js +5 -0
  41. package/dist/modules/index.d.ts +33 -0
  42. package/dist/modules/index.d.ts.map +1 -0
  43. package/dist/modules/index.js +129 -0
  44. package/dist/modules/omni-account.d.ts +9 -0
  45. package/dist/modules/omni-account.d.ts.map +1 -0
  46. package/dist/modules/omni-account.js +7 -0
  47. package/dist/modules/validators.d.ts +31 -0
  48. package/dist/modules/validators.d.ts.map +1 -0
  49. package/dist/modules/validators.js +518 -0
  50. package/dist/{services/orchestrator → orchestrator}/client.d.ts +2 -5
  51. package/dist/orchestrator/client.d.ts.map +1 -0
  52. package/dist/orchestrator/consts.d.ts +4 -0
  53. package/dist/orchestrator/consts.d.ts.map +1 -0
  54. package/dist/orchestrator/consts.js +3 -0
  55. package/dist/orchestrator/error.d.ts.map +1 -0
  56. package/dist/orchestrator/index.d.ts +9 -0
  57. package/dist/orchestrator/index.d.ts.map +1 -0
  58. package/dist/orchestrator/index.js +10 -0
  59. package/dist/orchestrator/registry.d.ts +5 -0
  60. package/dist/orchestrator/registry.d.ts.map +1 -0
  61. package/dist/orchestrator/registry.js +187 -0
  62. package/dist/{services/orchestrator → orchestrator}/types.d.ts +39 -23
  63. package/dist/orchestrator/types.d.ts.map +1 -0
  64. package/dist/orchestrator/types.js +7 -0
  65. package/dist/orchestrator/utils.d.ts +11 -0
  66. package/dist/orchestrator/utils.d.ts.map +1 -0
  67. package/dist/{services/orchestrator → orchestrator}/utils.js +20 -6
  68. package/dist/types.d.ts +70 -8
  69. package/dist/types.d.ts.map +1 -1
  70. package/package.json +3 -3
  71. package/dist/example.d.ts +0 -1
  72. package/dist/example.d.ts.map +0 -1
  73. package/dist/services/account/index.d.ts +0 -13
  74. package/dist/services/account/index.d.ts.map +0 -1
  75. package/dist/services/account/index.js +0 -54
  76. package/dist/services/account/nexus.d.ts +0 -9
  77. package/dist/services/account/nexus.d.ts.map +0 -1
  78. package/dist/services/account/nexus.js +0 -67
  79. package/dist/services/account/safe.d.ts +0 -9
  80. package/dist/services/account/safe.d.ts.map +0 -1
  81. package/dist/services/modules.d.ts +0 -32
  82. package/dist/services/modules.d.ts.map +0 -1
  83. package/dist/services/modules.js +0 -166
  84. package/dist/services/orchestrator/client.d.ts.map +0 -1
  85. package/dist/services/orchestrator/consts.d.ts +0 -6
  86. package/dist/services/orchestrator/consts.d.ts.map +0 -1
  87. package/dist/services/orchestrator/consts.js +0 -4
  88. package/dist/services/orchestrator/error.d.ts.map +0 -1
  89. package/dist/services/orchestrator/index.d.ts +0 -8
  90. package/dist/services/orchestrator/index.d.ts.map +0 -1
  91. package/dist/services/orchestrator/index.js +0 -9
  92. package/dist/services/orchestrator/types.d.ts.map +0 -1
  93. package/dist/services/orchestrator/types.js +0 -6
  94. package/dist/services/orchestrator/utils.d.ts +0 -7
  95. package/dist/services/orchestrator/utils.d.ts.map +0 -1
  96. package/dist/services/transaction.d.ts +0 -6
  97. package/dist/services/transaction.d.ts.map +0 -1
  98. package/dist/services/transaction.js +0 -93
  99. /package/dist/{services/orchestrator → orchestrator}/client.js +0 -0
  100. /package/dist/{services/orchestrator → orchestrator}/error.d.ts +0 -0
  101. /package/dist/{services/orchestrator → orchestrator}/error.js +0 -0
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ // import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
3
+ // import {
4
+ // baseSepolia,
5
+ // arbitrumSepolia,
6
+ // optimismSepolia,
7
+ // arbitrum,
8
+ // base,
9
+ // optimism,
10
+ // sepolia,
11
+ // } from 'viem/chains'
12
+ // import {
13
+ // Chain,
14
+ // createPublicClient,
15
+ // createWalletClient,
16
+ // encodeFunctionData,
17
+ // erc20Abi,
18
+ // Hex,
19
+ // http,
20
+ // parseEther,
21
+ // parseUnits,
22
+ // } from 'viem'
23
+ // import { createRhinestoneAccount } from '../index'
24
+ // const fundingPrivateKey = process.env.FUNDING_PRIVATE_KEY
25
+ // if (!fundingPrivateKey) {
26
+ // throw new Error('FUNDING_PRIVATE_KEY is not set')
27
+ // }
28
+ // const rhinestoneApiKey = process.env.RHINESTONE_API_KEY
29
+ // if (!rhinestoneApiKey) {
30
+ // throw new Error('RHINESTONE_API_KEY is not set')
31
+ // }
32
+ // const sourceChain = baseSepolia
33
+ // const targetChain = arbitrumSepolia
34
+ // const usdcSource = getTokenAddress(sourceChain)
35
+ // const usdcTarget = getTokenAddress(targetChain)
36
+ // const usdcAmount = 1n
37
+ // const fundingAccount = privateKeyToAccount(fundingPrivateKey as Hex)
38
+ // const publicClient = createPublicClient({
39
+ // chain: sourceChain,
40
+ // transport: getTransport(sourceChain),
41
+ // })
42
+ // const publicTargetClient = createPublicClient({
43
+ // chain: targetChain,
44
+ // transport: getTransport(targetChain),
45
+ // })
46
+ // const fundingClient = createWalletClient({
47
+ // account: fundingAccount,
48
+ // chain: sourceChain,
49
+ // transport: getTransport(sourceChain),
50
+ // })
51
+ // const fundingTargetClient = createWalletClient({
52
+ // account: fundingAccount,
53
+ // chain: targetChain,
54
+ // transport: getTransport(targetChain),
55
+ // })
56
+ // const useNewKeys = true
57
+ // if (!useNewKeys) {
58
+ // console.log('new pks', [
59
+ // generatePrivateKey(),
60
+ // generatePrivateKey(),
61
+ // generatePrivateKey(),
62
+ // ])
63
+ // }
64
+ // const privateKeyA = useNewKeys
65
+ // ? generatePrivateKey()
66
+ // : '0xe4b8f59fa0999924cf05c7c81fe436de905c43d8c2ba1cb50b8695d6e830cb7a'
67
+ // const accountA = privateKeyToAccount(privateKeyA)
68
+ // const privateKeyB = useNewKeys
69
+ // ? generatePrivateKey()
70
+ // : '0x0b6d1278f1dce8419f99c72a0354f10a52dfe5bc65008f72b59c2fdb2731fae5'
71
+ // const accountB = privateKeyToAccount(privateKeyB)
72
+ // const privateKeyC = useNewKeys
73
+ // ? generatePrivateKey()
74
+ // : '0xc1a32b6410d65a2faf779dd809c3b91c35436c89f51ff7b5335e57ebf4c50dc5'
75
+ // const accountC = privateKeyToAccount(privateKeyC)
76
+ // const rhinestoneAccount = await createRhinestoneAccount({
77
+ // account: {
78
+ // type: 'nexus',
79
+ // },
80
+ // owners: {
81
+ // type: 'ecdsa',
82
+ // accounts: [accountA, accountB, accountC],
83
+ // threshold: 2,
84
+ // },
85
+ // rhinestoneApiKey,
86
+ // deployerAccount: fundingAccount,
87
+ // })
88
+ // const address = await rhinestoneAccount.getAddress()
89
+ // console.log(address)
90
+ // // prefund
91
+ // const ethBalance = await publicClient.getBalance({
92
+ // address,
93
+ // })
94
+ // if (ethBalance < parseEther('0.001')) {
95
+ // const txHash = await fundingClient.sendTransaction({
96
+ // to: address,
97
+ // value: parseEther('0.001'),
98
+ // })
99
+ // await publicClient.waitForTransactionReceipt({ hash: txHash })
100
+ // // const txHash2 = await fundingTargetClient.sendTransaction({
101
+ // // to: usdcTarget,
102
+ // // data: encodeFunctionData({
103
+ // // abi: erc20Abi,
104
+ // // functionName: 'transfer',
105
+ // // args: [address, parseUnits('0.2', 6)],
106
+ // // }),
107
+ // // })
108
+ // // console.log('txHash2', txHash2)
109
+ // // await publicTargetClient.waitForTransactionReceipt({ hash: txHash2 })
110
+ // const txHash2 = await fundingClient.sendTransaction({
111
+ // to: usdcSource,
112
+ // data: encodeFunctionData({
113
+ // abi: erc20Abi,
114
+ // functionName: 'transfer',
115
+ // args: [address, parseUnits('0.5', 6)],
116
+ // }),
117
+ // })
118
+ // await publicClient.waitForTransactionReceipt({ hash: txHash2 })
119
+ // }
120
+ // const transactionResult = await rhinestoneAccount.sendTransactions({
121
+ // sourceChain,
122
+ // targetChain,
123
+ // calls: [
124
+ // {
125
+ // to: usdcTarget,
126
+ // value: 0n,
127
+ // data: encodeFunctionData({
128
+ // abi: erc20Abi,
129
+ // functionName: 'transfer',
130
+ // args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', usdcAmount],
131
+ // }),
132
+ // },
133
+ // ],
134
+ // tokenRequests: [
135
+ // {
136
+ // address: usdcTarget,
137
+ // amount: usdcAmount,
138
+ // },
139
+ // ],
140
+ // })
141
+ // console.log('result', transactionResult)
142
+ // const result = await rhinestoneAccount.waitForExecution(transactionResult)
143
+ // console.log('status', result)
144
+ // function getTokenAddress(chain: Chain) {
145
+ // switch (chain.id) {
146
+ // case sepolia.id:
147
+ // return '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238'
148
+ // case baseSepolia.id:
149
+ // return '0x036cbd53842c5426634e7929541ec2318f3dcf7e'
150
+ // case arbitrumSepolia.id:
151
+ // return '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d'
152
+ // case optimismSepolia.id:
153
+ // return '0x5fd84259d66Cd46123540766Be93DFE6D43130D7'
154
+ // case base.id:
155
+ // return '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
156
+ // case arbitrum.id:
157
+ // return '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
158
+ // case optimism.id:
159
+ // return '0x0b2c639c533813f4aa9d7837caf62653d097ff85'
160
+ // default:
161
+ // throw new Error('Unsupported chain')
162
+ // }
163
+ // }
164
+ // function getTransport(chain: Chain) {
165
+ // if (chain.id === sepolia.id) {
166
+ // return http('https://ethereum-sepolia-rpc.publicnode.com')
167
+ // }
168
+ // return http()
169
+ // }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=smart-sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-sessions.d.ts","sourceRoot":"","sources":["../../examples/smart-sessions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ // import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
3
+ // import {
4
+ // baseSepolia,
5
+ // arbitrumSepolia,
6
+ // optimismSepolia,
7
+ // sepolia,
8
+ // } from 'viem/chains'
9
+ // import {
10
+ // Chain,
11
+ // createPublicClient,
12
+ // createWalletClient,
13
+ // encodeFunctionData,
14
+ // getAbiItem,
15
+ // Hex,
16
+ // http,
17
+ // parseEther,
18
+ // toFunctionSelector,
19
+ // } from 'viem'
20
+ // import { createRhinestoneAccount } from '../index'
21
+ // import { abi as wethAbi } from './abi/weth'
22
+ // import { Session } from '../types'
23
+ // const fundingPrivateKey = process.env.FUNDING_PRIVATE_KEY
24
+ // if (!fundingPrivateKey) {
25
+ // throw new Error('FUNDING_PRIVATE_KEY is not set')
26
+ // }
27
+ // const rhinestoneApiKey = process.env.RHINESTONE_API_KEY
28
+ // if (!rhinestoneApiKey) {
29
+ // throw new Error('RHINESTONE_API_KEY is not set')
30
+ // }
31
+ // const pimlicoApiKey = process.env.PIMLICO_API_KEY
32
+ // if (!pimlicoApiKey) {
33
+ // throw new Error('PIMLICO_API_KEY is not set')
34
+ // }
35
+ // const chain = optimismSepolia
36
+ // // const targetChain = arbitrumSepolia
37
+ // const wethAddress = getWethAddress(chain)
38
+ // const wethAmount = 1n
39
+ // const fundingAccount = privateKeyToAccount(fundingPrivateKey as Hex)
40
+ // console.log('fundingAccount', fundingAccount.address)
41
+ // const publicClient = createPublicClient({
42
+ // chain,
43
+ // transport: getTransport(chain),
44
+ // })
45
+ // const fundingClient = createWalletClient({
46
+ // account: fundingAccount,
47
+ // chain,
48
+ // transport: getTransport(chain),
49
+ // })
50
+ // const useNewKeys = true
51
+ // if (!useNewKeys) {
52
+ // console.log('new pks', [
53
+ // generatePrivateKey(),
54
+ // generatePrivateKey(),
55
+ // generatePrivateKey(),
56
+ // ])
57
+ // }
58
+ // const privateKeyA = useNewKeys
59
+ // ? generatePrivateKey()
60
+ // : '0xe48befb91c9741788c829da2b9ff5b4d64dd77a170c284d7cf10e9acf9e11175'
61
+ // const accountA = privateKeyToAccount(privateKeyA)
62
+ // const privateKeyB = useNewKeys
63
+ // ? generatePrivateKey()
64
+ // : '0xe076077b3c53583d0eefcad6b30929cc0dfd58e9a2566cf6a059e327ec62fdbe'
65
+ // const accountB = privateKeyToAccount(privateKeyB)
66
+ // const privateKeyC = useNewKeys
67
+ // ? generatePrivateKey()
68
+ // : '0x34afca21087883dba533ecf1d9d705dd2ab8a1933e98db704bb7d9ff83edcaa8'
69
+ // const accountC = privateKeyToAccount(privateKeyC)
70
+ // const session: Session = {
71
+ // owners: {
72
+ // type: 'ecdsa',
73
+ // accounts: [accountA],
74
+ // },
75
+ // actions: [
76
+ // {
77
+ // target: wethAddress,
78
+ // selector: toFunctionSelector(
79
+ // getAbiItem({
80
+ // abi: wethAbi,
81
+ // name: 'deposit',
82
+ // }),
83
+ // ),
84
+ // },
85
+ // {
86
+ // target: wethAddress,
87
+ // selector: toFunctionSelector(
88
+ // getAbiItem({
89
+ // abi: wethAbi,
90
+ // name: 'transfer',
91
+ // }),
92
+ // ),
93
+ // },
94
+ // ],
95
+ // }
96
+ // const session2: Session = {
97
+ // owners: {
98
+ // type: 'ecdsa',
99
+ // accounts: [accountA],
100
+ // },
101
+ // actions: [
102
+ // {
103
+ // target: wethAddress,
104
+ // selector: toFunctionSelector(
105
+ // getAbiItem({
106
+ // abi: wethAbi,
107
+ // name: 'deposit',
108
+ // }),
109
+ // ),
110
+ // },
111
+ // {
112
+ // target: wethAddress,
113
+ // selector: toFunctionSelector(
114
+ // getAbiItem({
115
+ // abi: wethAbi,
116
+ // name: 'transfer',
117
+ // }),
118
+ // ),
119
+ // policies: [
120
+ // {
121
+ // type: 'universal-action',
122
+ // rules: [
123
+ // {
124
+ // condition: 'equal',
125
+ // calldataOffset: 0n,
126
+ // referenceValue: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
127
+ // },
128
+ // ],
129
+ // },
130
+ // ],
131
+ // },
132
+ // ],
133
+ // }
134
+ // const rhinestoneAccount = await createRhinestoneAccount({
135
+ // account: {
136
+ // type: 'nexus',
137
+ // },
138
+ // owners: {
139
+ // type: 'ecdsa',
140
+ // accounts: [accountA, accountB, accountC],
141
+ // threshold: 2,
142
+ // },
143
+ // sessions: [session],
144
+ // rhinestoneApiKey,
145
+ // deployerAccount: fundingAccount,
146
+ // bundler: {
147
+ // type: 'pimlico',
148
+ // apiKey: pimlicoApiKey,
149
+ // },
150
+ // })
151
+ // const address = await rhinestoneAccount.getAddress()
152
+ // console.log(address)
153
+ // // prefund
154
+ // const ethBalance = await publicClient.getBalance({
155
+ // address,
156
+ // })
157
+ // if (ethBalance < parseEther('0.001')) {
158
+ // const txHash = await fundingClient.sendTransaction({
159
+ // to: address,
160
+ // value: parseEther('0.001'),
161
+ // })
162
+ // await publicClient.waitForTransactionReceipt({ hash: txHash })
163
+ // }
164
+ // const transactionResult = await rhinestoneAccount.sendTransactions({
165
+ // chain,
166
+ // calls: [
167
+ // {
168
+ // to: wethAddress,
169
+ // value: 10n,
170
+ // data: encodeFunctionData({
171
+ // abi: wethAbi,
172
+ // functionName: 'deposit',
173
+ // }),
174
+ // },
175
+ // {
176
+ // to: wethAddress,
177
+ // data: encodeFunctionData({
178
+ // abi: wethAbi,
179
+ // functionName: 'transfer',
180
+ // args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 1n],
181
+ // }),
182
+ // },
183
+ // ],
184
+ // tokenRequests: [
185
+ // {
186
+ // address: wethAddress,
187
+ // amount: 1n,
188
+ // },
189
+ // ],
190
+ // signers: {
191
+ // type: 'session',
192
+ // session: session2,
193
+ // },
194
+ // })
195
+ // const result = await rhinestoneAccount.waitForExecution(transactionResult)
196
+ // console.log('status', result)
197
+ // function getWethAddress(chain: Chain) {
198
+ // switch (chain.id) {
199
+ // case sepolia.id:
200
+ // return '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14'
201
+ // case baseSepolia.id:
202
+ // return '0x4200000000000000000000000000000000000006'
203
+ // case arbitrumSepolia.id:
204
+ // return '0x980B62Da83eFf3D4576C647993b0c1D7faf17c73'
205
+ // case optimismSepolia.id:
206
+ // return '0x4200000000000000000000000000000000000006'
207
+ // default:
208
+ // throw new Error('Unsupported chain')
209
+ // }
210
+ // }
211
+ // function getTransport(chain: Chain) {
212
+ // if (chain.id === sepolia.id) {
213
+ // return http('https://ethereum-sepolia-rpc.publicnode.com')
214
+ // }
215
+ // return http()
216
+ // }
@@ -0,0 +1,31 @@
1
+ import { Address, Chain, Hex } from 'viem';
2
+ import { type BundleResult } from '../orchestrator';
3
+ import { RhinestoneAccountConfig, Transaction } from '../types';
4
+ type TransactionResult = {
5
+ type: 'userop';
6
+ hash: Hex;
7
+ sourceChain: Chain;
8
+ targetChain: Chain;
9
+ } | {
10
+ type: 'bundle';
11
+ id: bigint;
12
+ sourceChain: Chain;
13
+ targetChain: Chain;
14
+ };
15
+ declare function sendTransaction(config: RhinestoneAccountConfig, transaction: Transaction): Promise<TransactionResult>;
16
+ declare function waitForExecution(config: RhinestoneAccountConfig, result: TransactionResult): Promise<BundleResult | {
17
+ actualGasCost: bigint;
18
+ actualGasUsed: bigint;
19
+ entryPoint: Address;
20
+ logs: import("viem").Log<bigint, number, false>[];
21
+ nonce: bigint;
22
+ paymaster?: `0x${string}` | undefined;
23
+ reason?: string | undefined | undefined;
24
+ receipt: import("viem").TransactionReceipt<bigint, number, "success" | "reverted">;
25
+ sender: Address;
26
+ success: boolean;
27
+ userOpHash: import("viem").Hash;
28
+ }>;
29
+ export { sendTransaction, waitForExecution };
30
+ export type { TransactionResult };
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../execution/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,EAKL,GAAG,EAKJ,MAAM,MAAM,CAAA;AAMb,OAAO,EACL,KAAK,YAAY,EASlB,MAAM,iBAAiB,CAAA;AAYxB,OAAO,EACL,uBAAuB,EACvB,WAAW,EAKZ,MAAM,UAAU,CAAA;AAajB,KAAK,iBAAiB,GAClB;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,GAAG,CAAA;IACT,WAAW,EAAE,KAAK,CAAA;IAClB,WAAW,EAAE,KAAK,CAAA;CACnB,GACD;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,KAAK,CAAA;IAClB,WAAW,EAAE,KAAK,CAAA;CACnB,CAAA;AAEL,iBAAe,eAAe,CAC5B,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,WAAW,8BAuBzB;AA8QD,iBAAe,gBAAgB,CAC7B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,iBAAiB;;;;;;;;;;;;GAgC1B;AAED,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAA;AAC5C,YAAY,EAAE,iBAAiB,EAAE,CAAA"}
@@ -0,0 +1,222 @@
1
+ import { createPublicClient, createWalletClient, encodeAbiParameters, encodePacked, http, keccak256, pad, toHex, } from 'viem';
2
+ import { entryPoint07Address, getUserOperationHash, } from 'viem/account-abstraction';
3
+ import { BUNDLE_STATUS_PENDING, BUNDLE_STATUS_FAILED, getOrchestrator, getOrderBundleHash, BUNDLE_STATUS_PARTIALLY_COMPLETED, getEmptyUserOp, } from '../orchestrator';
4
+ import { getAddress, isDeployed, deploySource, deployTarget, getBundleInitCode, sign, getSmartSessionSmartAccount, getDeployArgs, } from '../accounts';
5
+ import { getOwnerValidator } from '../modules';
6
+ import { getBundlerClient } from '../accounts/utils';
7
+ import { getSmartSessionValidator } from '../modules/validators';
8
+ import { getTokenBalanceSlot } from '../orchestrator';
9
+ import { enableSmartSession, getSessionSignature, hashErc7739, } from './smart-session';
10
+ const POLLING_INTERVAL = 500;
11
+ async function sendTransaction(config, transaction) {
12
+ if ('chain' in transaction) {
13
+ // Same-chain transaction
14
+ return await sendTransactionInternal(config, transaction.chain, transaction.chain, transaction.calls, transaction.tokenRequests, transaction.signers);
15
+ }
16
+ else {
17
+ // Cross-chain transaction
18
+ return await sendTransactionInternal(config, transaction.sourceChain, transaction.targetChain, transaction.calls, transaction.tokenRequests, transaction.signers);
19
+ }
20
+ }
21
+ async function sendTransactionInternal(config, sourceChain, targetChain, calls, tokenRequests, signers) {
22
+ const isAccountDeployed = await isDeployed(sourceChain, config);
23
+ if (!isAccountDeployed) {
24
+ await deploySource(sourceChain, config);
25
+ }
26
+ const withSession = signers?.type === 'session' ? signers.session : null;
27
+ if (withSession) {
28
+ await enableSmartSession(sourceChain, config, withSession);
29
+ }
30
+ const accountAddress = await getAddress(config);
31
+ if (withSession) {
32
+ // Smart sessions require a UserOp flow
33
+ return await sendTransactionAsUserOp(config, sourceChain, targetChain, calls, tokenRequests, accountAddress, withSession);
34
+ }
35
+ else {
36
+ return await sendTransactionAsIntent(config, sourceChain, targetChain, calls, tokenRequests, accountAddress);
37
+ }
38
+ }
39
+ async function sendTransactionAsUserOp(config, sourceChain, targetChain, calls, tokenRequests, accountAddress, withSession) {
40
+ const publicClient = createPublicClient({
41
+ chain: sourceChain,
42
+ transport: http(),
43
+ });
44
+ const sessionAccount = await getSmartSessionSmartAccount(config, publicClient, sourceChain, withSession);
45
+ const bundlerClient = getBundlerClient(config, publicClient);
46
+ const targetPublicClient = createPublicClient({
47
+ chain: targetChain,
48
+ transport: http(),
49
+ });
50
+ const targetSessionAccount = await getSmartSessionSmartAccount(config, targetPublicClient, targetChain, withSession);
51
+ const targetBundlerClient = getBundlerClient(config, targetPublicClient);
52
+ if (sourceChain.id === targetChain.id) {
53
+ await enableSmartSession(targetChain, config, withSession);
54
+ const hash = await bundlerClient.sendUserOperation({
55
+ account: sessionAccount,
56
+ calls,
57
+ });
58
+ return {
59
+ type: 'userop',
60
+ hash,
61
+ sourceChain,
62
+ targetChain,
63
+ };
64
+ }
65
+ const metaIntent = {
66
+ targetChainId: targetChain.id,
67
+ tokenTransfers: tokenRequests.map((tokenRequest) => ({
68
+ tokenAddress: tokenRequest.address,
69
+ amount: tokenRequest.amount,
70
+ })),
71
+ targetAccount: accountAddress,
72
+ userOp: getEmptyUserOp(),
73
+ };
74
+ const orchestrator = getOrchestrator(config.rhinestoneApiKey);
75
+ const orderPath = await orchestrator.getOrderPath(metaIntent, accountAddress);
76
+ // Deploy the account on the target chain
77
+ const { factory, factoryData } = await getDeployArgs(config);
78
+ const deployerAccount = config.deployerAccount;
79
+ const targetWalletClient = createWalletClient({
80
+ chain: targetChain,
81
+ transport: http(),
82
+ });
83
+ const targetDeployTx = await targetWalletClient.sendTransaction({
84
+ account: deployerAccount,
85
+ to: factory,
86
+ data: factoryData,
87
+ });
88
+ await targetPublicClient.waitForTransactionReceipt({
89
+ hash: targetDeployTx,
90
+ });
91
+ await enableSmartSession(targetChain, config, withSession);
92
+ const userOp = await targetBundlerClient.prepareUserOperation({
93
+ account: targetSessionAccount,
94
+ calls: [...orderPath[0].injectedExecutions, ...calls],
95
+ stateOverride: [
96
+ ...tokenRequests.map((request) => {
97
+ const rootBalanceSlot = getTokenBalanceSlot(targetChain, request.address);
98
+ const balanceSlot = rootBalanceSlot
99
+ ? keccak256(encodeAbiParameters([{ type: 'address' }, { type: 'uint256' }], [accountAddress, rootBalanceSlot]))
100
+ : '0x';
101
+ return {
102
+ address: request.address,
103
+ stateDiff: [
104
+ {
105
+ slot: balanceSlot,
106
+ value: pad(toHex(request.amount)),
107
+ },
108
+ ],
109
+ };
110
+ }),
111
+ ],
112
+ });
113
+ userOp.signature = await targetSessionAccount.signUserOperation(userOp);
114
+ const userOpHash = getUserOperationHash({
115
+ userOperation: userOp,
116
+ chainId: targetChain.id,
117
+ entryPointAddress: entryPoint07Address,
118
+ entryPointVersion: '0.7',
119
+ });
120
+ orderPath[0].orderBundle.segments[0].witness.userOpHash = userOpHash;
121
+ const { hash, appDomainSeparator, contentsType, structHash, orderBundleHash, } = await hashErc7739(sourceChain, orderPath, accountAddress);
122
+ const signature = await sign(withSession.owners, targetChain, hash);
123
+ const sessionSignature = getSessionSignature(signature, appDomainSeparator, structHash, contentsType, withSession);
124
+ const smartSessionValidator = getSmartSessionValidator(config);
125
+ if (!smartSessionValidator) {
126
+ throw new Error('Smart session validator not available');
127
+ }
128
+ const packedSig = encodePacked(['address', 'bytes'], [smartSessionValidator.address, sessionSignature]);
129
+ const signedOrderBundle = {
130
+ ...orderPath[0].orderBundle,
131
+ originSignatures: Array(orderPath[0].orderBundle.segments.length).fill(packedSig),
132
+ targetSignature: packedSig,
133
+ };
134
+ await deployTarget(targetChain, config);
135
+ const bundleResults = await orchestrator.postSignedOrderBundle([
136
+ {
137
+ signedOrderBundle,
138
+ userOp,
139
+ },
140
+ ]);
141
+ return {
142
+ type: 'bundle',
143
+ id: bundleResults[0].bundleId,
144
+ sourceChain,
145
+ targetChain,
146
+ };
147
+ }
148
+ async function sendTransactionAsIntent(config, sourceChain, targetChain, calls, tokenRequests, accountAddress) {
149
+ const metaIntent = {
150
+ targetChainId: targetChain.id,
151
+ tokenTransfers: tokenRequests.map((tokenRequest) => ({
152
+ tokenAddress: tokenRequest.address,
153
+ amount: tokenRequest.amount,
154
+ })),
155
+ targetAccount: accountAddress,
156
+ targetExecutions: calls.map((call) => ({
157
+ value: call.value ?? 0n,
158
+ to: call.to,
159
+ data: call.data ?? '0x',
160
+ })),
161
+ };
162
+ const orchestrator = getOrchestrator(config.rhinestoneApiKey);
163
+ const orderPath = await orchestrator.getOrderPath(metaIntent, accountAddress);
164
+ orderPath[0].orderBundle.segments[0].witness.execs = [
165
+ ...orderPath[0].injectedExecutions,
166
+ ...metaIntent.targetExecutions,
167
+ ];
168
+ const orderBundleHash = getOrderBundleHash(orderPath[0].orderBundle);
169
+ const bundleSignature = await sign(config.owners, sourceChain, orderBundleHash);
170
+ const validatorModule = getOwnerValidator(config);
171
+ const packedSig = encodePacked(['address', 'bytes'], [validatorModule.address, bundleSignature]);
172
+ const signedOrderBundle = {
173
+ ...orderPath[0].orderBundle,
174
+ originSignatures: Array(orderPath[0].orderBundle.segments.length).fill(packedSig),
175
+ targetSignature: packedSig,
176
+ };
177
+ await deployTarget(targetChain, config);
178
+ const initCode = await getBundleInitCode(config);
179
+ const bundleResults = await orchestrator.postSignedOrderBundle([
180
+ {
181
+ signedOrderBundle,
182
+ initCode,
183
+ },
184
+ ]);
185
+ return {
186
+ type: 'bundle',
187
+ id: bundleResults[0].bundleId,
188
+ sourceChain,
189
+ targetChain,
190
+ };
191
+ }
192
+ async function waitForExecution(config, result) {
193
+ switch (result.type) {
194
+ case 'bundle': {
195
+ let bundleResult = null;
196
+ while (bundleResult === null ||
197
+ bundleResult.status === BUNDLE_STATUS_PENDING ||
198
+ bundleResult.status === BUNDLE_STATUS_PARTIALLY_COMPLETED) {
199
+ const orchestrator = getOrchestrator(config.rhinestoneApiKey);
200
+ bundleResult = await orchestrator.getBundleStatus(result.id);
201
+ await new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL));
202
+ }
203
+ if (bundleResult.status === BUNDLE_STATUS_FAILED) {
204
+ throw new Error('Bundle failed');
205
+ }
206
+ return bundleResult;
207
+ }
208
+ case 'userop': {
209
+ const publicClient = createPublicClient({
210
+ chain: result.sourceChain,
211
+ transport: http(),
212
+ });
213
+ // It's a UserOp hash
214
+ const bundlerClient = getBundlerClient(config, publicClient);
215
+ const receipt = await bundlerClient.waitForUserOperationReceipt({
216
+ hash: result.hash,
217
+ });
218
+ return receipt;
219
+ }
220
+ }
221
+ }
222
+ export { sendTransaction, waitForExecution };
@@ -0,0 +1,14 @@
1
+ import { Chain, Hex, Address } from 'viem';
2
+ import { RhinestoneAccountConfig, Session } from '../types';
3
+ import { OrderPath } from '../orchestrator';
4
+ declare function enableSmartSession(chain: Chain, config: RhinestoneAccountConfig, session: Session): Promise<void>;
5
+ declare function hashErc7739(sourceChain: Chain, orderPath: OrderPath, accountAddress: Address): Promise<{
6
+ hash: `0x${string}`;
7
+ appDomainSeparator: `0x${string}`;
8
+ contentsType: string;
9
+ structHash: `0x${string}`;
10
+ orderBundleHash: `0x${string}`;
11
+ }>;
12
+ declare function getSessionSignature(signature: Hex, appDomainSeparator: Hex, structHash: Hex, contentsType: string, withSession: Session): `0x${string}`;
13
+ export { enableSmartSession, hashErc7739, getSessionSignature };
14
+ //# sourceMappingURL=smart-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-session.d.ts","sourceRoot":"","sources":["../../execution/smart-session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAIL,GAAG,EAGH,OAAO,EACR,MAAM,MAAM,CAAA;AAWb,OAAO,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAM3C,iBAAe,kBAAkB,CAC/B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,uBAAuB,EAC/B,OAAO,EAAE,OAAO,iBAyBjB;AAED,iBAAe,WAAW,CACxB,WAAW,EAAE,KAAK,EAClB,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,OAAO;;;;;;GAmExB;AAED,iBAAS,mBAAmB,CAC1B,SAAS,EAAE,GAAG,EACd,kBAAkB,EAAE,GAAG,EACvB,UAAU,EAAE,GAAG,EACf,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,OAAO,iBAkBrB;AAED,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAA"}