@rhinestone/sdk 0.2.1 → 0.4.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.
- package/README.md +4 -4
- package/dist/accounts/index.d.ts +15515 -4
- package/dist/accounts/index.d.ts.map +1 -1
- package/dist/accounts/index.js +69 -10
- package/dist/accounts/nexus.d.ts +15542 -32
- package/dist/accounts/nexus.d.ts.map +1 -1
- package/dist/accounts/nexus.js +86 -65
- package/dist/accounts/safe.d.ts +3 -1
- package/dist/accounts/safe.d.ts.map +1 -1
- package/dist/accounts/safe.js +8 -2
- package/dist/examples/abi/weth.d.ts +214 -0
- package/dist/examples/abi/weth.d.ts.map +1 -0
- package/dist/examples/abi/weth.js +279 -0
- package/dist/examples/cross-chain-ss.d.ts +1 -0
- package/dist/examples/cross-chain-ss.d.ts.map +1 -0
- package/dist/{example.js → examples/cross-chain-ss.js} +59 -22
- package/dist/examples/giza.d.ts +1 -0
- package/dist/examples/giza.d.ts.map +1 -0
- package/dist/examples/giza.js +124 -0
- package/dist/examples/omni-account.d.ts +1 -0
- package/dist/examples/omni-account.d.ts.map +1 -0
- package/dist/examples/omni-account.js +169 -0
- package/dist/examples/smart-sessions.d.ts +1 -0
- package/dist/examples/smart-sessions.d.ts.map +1 -0
- package/dist/examples/smart-sessions.js +216 -0
- package/dist/execution/index.d.ts +28 -3
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +177 -47
- package/dist/execution/smart-session.d.ts +14 -0
- package/dist/execution/smart-session.d.ts.map +1 -0
- package/dist/execution/smart-session.js +83 -0
- package/dist/index.d.ts +17 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- package/dist/modules/abi/smart-sessions.d.ts +42 -0
- package/dist/modules/abi/smart-sessions.d.ts.map +1 -0
- package/dist/modules/abi/smart-sessions.js +128 -0
- package/dist/modules/common.d.ts +16 -0
- package/dist/modules/common.d.ts.map +1 -0
- package/dist/modules/common.js +5 -0
- package/dist/modules/index.d.ts +7 -18
- package/dist/modules/index.d.ts.map +1 -1
- package/dist/modules/index.js +14 -119
- package/dist/modules/omni-account.d.ts +9 -0
- package/dist/modules/omni-account.d.ts.map +1 -0
- package/dist/modules/omni-account.js +7 -0
- package/dist/modules/validators.d.ts +31 -0
- package/dist/modules/validators.d.ts.map +1 -0
- package/dist/modules/validators.js +521 -0
- package/dist/orchestrator/client.d.ts +2 -5
- package/dist/orchestrator/client.d.ts.map +1 -1
- package/dist/orchestrator/consts.d.ts +3 -1
- package/dist/orchestrator/consts.d.ts.map +1 -1
- package/dist/orchestrator/consts.js +3 -1
- package/dist/orchestrator/index.d.ts +5 -3
- package/dist/orchestrator/index.d.ts.map +1 -1
- package/dist/orchestrator/index.js +5 -4
- package/dist/orchestrator/registry.d.ts +5 -0
- package/dist/orchestrator/registry.d.ts.map +1 -0
- package/dist/orchestrator/registry.js +187 -0
- package/dist/orchestrator/types.d.ts +39 -23
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/orchestrator/types.js +7 -6
- package/dist/orchestrator/utils.d.ts +8 -4
- package/dist/orchestrator/utils.d.ts.map +1 -1
- package/dist/orchestrator/utils.js +19 -5
- package/dist/types.d.ts +64 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/example.d.ts +0 -1
- package/dist/example.d.ts.map +0 -1
|
@@ -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
|
+
// }
|
|
@@ -1,6 +1,31 @@
|
|
|
1
|
+
import { Address, Chain, Hex } from 'viem';
|
|
1
2
|
import { type BundleResult } from '../orchestrator';
|
|
2
3
|
import { RhinestoneAccountConfig, Transaction } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 };
|
|
6
31
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../execution/index.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/execution/index.js
CHANGED
|
@@ -1,15 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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';
|
|
5
10
|
const POLLING_INTERVAL = 500;
|
|
6
|
-
async function
|
|
7
|
-
|
|
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) {
|
|
8
22
|
const isAccountDeployed = await isDeployed(sourceChain, config);
|
|
9
23
|
if (!isAccountDeployed) {
|
|
10
|
-
await deploySource(
|
|
24
|
+
await deploySource(sourceChain, config);
|
|
25
|
+
}
|
|
26
|
+
const withSession = signers?.type === 'session' ? signers.session : null;
|
|
27
|
+
if (withSession) {
|
|
28
|
+
await enableSmartSession(sourceChain, config, withSession);
|
|
11
29
|
}
|
|
12
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) {
|
|
13
149
|
const metaIntent = {
|
|
14
150
|
targetChainId: targetChain.id,
|
|
15
151
|
tokenTransfers: tokenRequests.map((tokenRequest) => ({
|
|
@@ -31,7 +167,7 @@ async function sendTransactions(config, transaction) {
|
|
|
31
167
|
];
|
|
32
168
|
const orderBundleHash = getOrderBundleHash(orderPath[0].orderBundle);
|
|
33
169
|
const bundleSignature = await sign(config.owners, sourceChain, orderBundleHash);
|
|
34
|
-
const validatorModule =
|
|
170
|
+
const validatorModule = getOwnerValidator(config);
|
|
35
171
|
const packedSig = encodePacked(['address', 'bytes'], [validatorModule.address, bundleSignature]);
|
|
36
172
|
const signedOrderBundle = {
|
|
37
173
|
...orderPath[0].orderBundle,
|
|
@@ -46,47 +182,41 @@ async function sendTransactions(config, transaction) {
|
|
|
46
182
|
initCode,
|
|
47
183
|
},
|
|
48
184
|
]);
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
bundleResult.status === BUNDLE_STATUS_PARTIALLY_COMPLETED) {
|
|
56
|
-
const orchestrator = getOrchestrator(config.rhinestoneApiKey);
|
|
57
|
-
bundleResult = await orchestrator.getBundleStatus(id);
|
|
58
|
-
await new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL));
|
|
59
|
-
}
|
|
60
|
-
if (bundleResult.status === BUNDLE_STATUS_FAILED) {
|
|
61
|
-
throw new Error('Bundle failed');
|
|
62
|
-
}
|
|
63
|
-
return bundleResult;
|
|
185
|
+
return {
|
|
186
|
+
type: 'bundle',
|
|
187
|
+
id: bundleResults[0].bundleId,
|
|
188
|
+
sourceChain,
|
|
189
|
+
targetChain,
|
|
190
|
+
};
|
|
64
191
|
}
|
|
65
|
-
async function
|
|
66
|
-
switch (
|
|
67
|
-
case '
|
|
68
|
-
|
|
69
|
-
|
|
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;
|
|
70
207
|
}
|
|
71
|
-
case '
|
|
72
|
-
|
|
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;
|
|
73
219
|
}
|
|
74
220
|
}
|
|
75
221
|
}
|
|
76
|
-
|
|
77
|
-
if (!account.signMessage) {
|
|
78
|
-
throw new Error('Signing not supported for the account');
|
|
79
|
-
}
|
|
80
|
-
return await account.signMessage({ message: { raw: hash } });
|
|
81
|
-
}
|
|
82
|
-
async function signPasskey(account, chain, hash) {
|
|
83
|
-
const { webauthn, signature } = await account.sign({ hash });
|
|
84
|
-
const usePrecompiled = isRip7212SupportedNetwork(chain);
|
|
85
|
-
const encodedSignature = getWebauthnValidatorSignature({
|
|
86
|
-
webauthn,
|
|
87
|
-
signature,
|
|
88
|
-
usePrecompiled,
|
|
89
|
-
});
|
|
90
|
-
return encodedSignature;
|
|
91
|
-
}
|
|
92
|
-
export { sendTransactions, waitForExecution };
|
|
222
|
+
export { sendTransaction, waitForExecution };
|