permissionless 0.3.6 → 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.
Files changed (229) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/_cjs/accounts/biconomy/toBiconomySmartAccount.js +9 -5
  3. package/_cjs/accounts/biconomy/toBiconomySmartAccount.js.map +1 -1
  4. package/_cjs/accounts/kernel/toKernelSmartAccount.js +4 -0
  5. package/_cjs/accounts/kernel/toKernelSmartAccount.js.map +1 -1
  6. package/_cjs/accounts/light/toLightSmartAccount.js +9 -5
  7. package/_cjs/accounts/light/toLightSmartAccount.js.map +1 -1
  8. package/_cjs/accounts/nexus/toNexusSmartAccount.js +3 -2
  9. package/_cjs/accounts/nexus/toNexusSmartAccount.js.map +1 -1
  10. package/_cjs/accounts/safe/signUserOperation.js +14 -1
  11. package/_cjs/accounts/safe/signUserOperation.js.map +1 -1
  12. package/_cjs/accounts/safe/toSafeSmartAccount.js +6 -4
  13. package/_cjs/accounts/safe/toSafeSmartAccount.js.map +1 -1
  14. package/_cjs/accounts/simple/toSimpleSmartAccount.js +15 -10
  15. package/_cjs/accounts/simple/toSimpleSmartAccount.js.map +1 -1
  16. package/_cjs/accounts/thirdweb/utils/decodeCallData.js +7 -5
  17. package/_cjs/accounts/thirdweb/utils/decodeCallData.js.map +1 -1
  18. package/_cjs/accounts/trust/utils/decodeCallData.js +7 -5
  19. package/_cjs/accounts/trust/utils/decodeCallData.js.map +1 -1
  20. package/_cjs/actions/{erc7579.js → erc7579/index.js} +9 -9
  21. package/_cjs/actions/erc7579/index.js.map +1 -0
  22. package/_cjs/actions/{etherspot.js → etherspot/index.js} +2 -2
  23. package/_cjs/actions/etherspot/index.js.map +1 -0
  24. package/_cjs/actions/{passkeyServer.js → passkeyServer/index.js} +4 -4
  25. package/_cjs/actions/passkeyServer/index.js.map +1 -0
  26. package/_cjs/actions/pimlico/estimateErc20PaymasterCost.js +7 -3
  27. package/_cjs/actions/pimlico/estimateErc20PaymasterCost.js.map +1 -1
  28. package/_cjs/actions/{pimlico.js → pimlico/index.js} +8 -8
  29. package/_cjs/actions/pimlico/index.js.map +1 -0
  30. package/_cjs/actions/{smartAccount.js → smartAccount/index.js} +5 -5
  31. package/_cjs/actions/smartAccount/index.js.map +1 -0
  32. package/_cjs/clients/createSmartAccountClient.js.map +1 -1
  33. package/_cjs/clients/decorators/pimlico.js +4 -4
  34. package/_cjs/clients/decorators/pimlico.js.map +1 -1
  35. package/_cjs/clients/{passkeyServer.js → passkeyServer/index.js} +2 -2
  36. package/_cjs/clients/passkeyServer/index.js.map +1 -0
  37. package/_cjs/clients/{pimlico.js → pimlico/index.js} +2 -2
  38. package/_cjs/clients/pimlico/index.js.map +1 -0
  39. package/_cjs/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.js +6 -5
  40. package/_cjs/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.js.map +1 -1
  41. package/_cjs/utils/index.js +3 -1
  42. package/_cjs/utils/index.js.map +1 -1
  43. package/_cjs/utils/sortAddresses.js +16 -0
  44. package/_cjs/utils/sortAddresses.js.map +1 -0
  45. package/_esm/accounts/biconomy/toBiconomySmartAccount.js +9 -5
  46. package/_esm/accounts/biconomy/toBiconomySmartAccount.js.map +1 -1
  47. package/_esm/accounts/kernel/toKernelSmartAccount.js +4 -0
  48. package/_esm/accounts/kernel/toKernelSmartAccount.js.map +1 -1
  49. package/_esm/accounts/light/toLightSmartAccount.js +9 -5
  50. package/_esm/accounts/light/toLightSmartAccount.js.map +1 -1
  51. package/_esm/accounts/nexus/toNexusSmartAccount.js +3 -2
  52. package/_esm/accounts/nexus/toNexusSmartAccount.js.map +1 -1
  53. package/_esm/accounts/safe/signUserOperation.js +14 -1
  54. package/_esm/accounts/safe/signUserOperation.js.map +1 -1
  55. package/_esm/accounts/safe/toSafeSmartAccount.js +6 -4
  56. package/_esm/accounts/safe/toSafeSmartAccount.js.map +1 -1
  57. package/_esm/accounts/simple/toSimpleSmartAccount.js +15 -10
  58. package/_esm/accounts/simple/toSimpleSmartAccount.js.map +1 -1
  59. package/_esm/accounts/thirdweb/utils/decodeCallData.js +7 -5
  60. package/_esm/accounts/thirdweb/utils/decodeCallData.js.map +1 -1
  61. package/_esm/accounts/trust/utils/decodeCallData.js +7 -5
  62. package/_esm/accounts/trust/utils/decodeCallData.js.map +1 -1
  63. package/_esm/actions/{erc7579.js → erc7579/index.js} +9 -9
  64. package/_esm/actions/erc7579/index.js.map +1 -0
  65. package/_esm/actions/etherspot/index.js +2 -0
  66. package/_esm/actions/etherspot/index.js.map +1 -0
  67. package/_esm/actions/passkeyServer/index.js +4 -0
  68. package/_esm/actions/passkeyServer/index.js.map +1 -0
  69. package/_esm/actions/pimlico/estimateErc20PaymasterCost.js +7 -3
  70. package/_esm/actions/pimlico/estimateErc20PaymasterCost.js.map +1 -1
  71. package/_esm/actions/pimlico/index.js +8 -0
  72. package/_esm/actions/pimlico/index.js.map +1 -0
  73. package/_esm/actions/smartAccount/index.js +5 -0
  74. package/_esm/actions/smartAccount/index.js.map +1 -0
  75. package/_esm/clients/createSmartAccountClient.js.map +1 -1
  76. package/_esm/clients/decorators/pimlico.js +1 -1
  77. package/_esm/clients/decorators/pimlico.js.map +1 -1
  78. package/_esm/clients/{passkeyServer.js → passkeyServer/index.js} +2 -2
  79. package/_esm/clients/passkeyServer/index.js.map +1 -0
  80. package/_esm/clients/{pimlico.js → pimlico/index.js} +2 -2
  81. package/_esm/clients/pimlico/index.js.map +1 -0
  82. package/_esm/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.js +5 -4
  83. package/_esm/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.js.map +1 -1
  84. package/_esm/utils/index.js +1 -0
  85. package/_esm/utils/index.js.map +1 -1
  86. package/_esm/utils/sortAddresses.js +19 -0
  87. package/_esm/utils/sortAddresses.js.map +1 -0
  88. package/_types/accounts/biconomy/toBiconomySmartAccount.d.ts.map +1 -1
  89. package/_types/accounts/kernel/toKernelSmartAccount.d.ts.map +1 -1
  90. package/_types/accounts/light/toLightSmartAccount.d.ts.map +1 -1
  91. package/_types/accounts/nexus/toNexusSmartAccount.d.ts.map +1 -1
  92. package/_types/accounts/safe/signUserOperation.d.ts.map +1 -1
  93. package/_types/accounts/safe/toSafeSmartAccount.d.ts.map +1 -1
  94. package/_types/accounts/simple/toSimpleSmartAccount.d.ts.map +1 -1
  95. package/_types/accounts/thirdweb/utils/decodeCallData.d.ts.map +1 -1
  96. package/_types/accounts/trust/utils/decodeCallData.d.ts.map +1 -1
  97. package/_types/actions/{erc7579.d.ts → erc7579/index.d.ts} +11 -11
  98. package/_types/actions/erc7579/index.d.ts.map +1 -0
  99. package/_types/actions/etherspot/index.d.ts +2 -0
  100. package/_types/actions/etherspot/index.d.ts.map +1 -0
  101. package/_types/actions/passkeyServer/index.d.ts +4 -0
  102. package/_types/actions/passkeyServer/index.d.ts.map +1 -0
  103. package/_types/actions/pimlico/estimateErc20PaymasterCost.d.ts.map +1 -1
  104. package/_types/actions/pimlico/index.d.ts +8 -0
  105. package/_types/actions/pimlico/index.d.ts.map +1 -0
  106. package/_types/actions/smartAccount/index.d.ts +5 -0
  107. package/_types/actions/smartAccount/index.d.ts.map +1 -0
  108. package/_types/clients/createSmartAccountClient.d.ts +9 -1
  109. package/_types/clients/createSmartAccountClient.d.ts.map +1 -1
  110. package/_types/clients/decorators/pimlico.d.ts +1 -1
  111. package/_types/clients/decorators/pimlico.d.ts.map +1 -1
  112. package/_types/clients/{passkeyServer.d.ts → passkeyServer/index.d.ts} +8 -4
  113. package/_types/clients/passkeyServer/index.d.ts.map +1 -0
  114. package/_types/clients/pimlico/index.d.ts +21 -0
  115. package/_types/clients/pimlico/index.d.ts.map +1 -0
  116. package/_types/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.d.ts.map +1 -1
  117. package/_types/utils/index.d.ts +1 -0
  118. package/_types/utils/index.d.ts.map +1 -1
  119. package/_types/utils/sortAddresses.d.ts +9 -0
  120. package/_types/utils/sortAddresses.d.ts.map +1 -0
  121. package/accounts/biconomy/package.json +6 -0
  122. package/accounts/biconomy/toBiconomySmartAccount.ts +13 -5
  123. package/accounts/etherspot/package.json +6 -0
  124. package/accounts/kernel/package.json +6 -0
  125. package/accounts/kernel/toKernelSmartAccount.ts +7 -0
  126. package/accounts/light/package.json +6 -0
  127. package/accounts/light/toLightSmartAccount.ts +13 -5
  128. package/accounts/nexus/package.json +6 -0
  129. package/accounts/nexus/toNexusSmartAccount.ts +3 -6
  130. package/accounts/package.json +6 -0
  131. package/accounts/safe/package.json +6 -0
  132. package/accounts/safe/signUserOperation.ts +15 -3
  133. package/accounts/safe/toSafeSmartAccount.ts +7 -6
  134. package/accounts/simple/package.json +6 -0
  135. package/accounts/simple/toSimpleSmartAccount.ts +21 -10
  136. package/accounts/thirdweb/package.json +6 -0
  137. package/accounts/thirdweb/utils/decodeCallData.ts +9 -5
  138. package/accounts/trust/package.json +6 -0
  139. package/accounts/trust/utils/decodeCallData.ts +9 -5
  140. package/actions/{erc7579.ts → erc7579/index.ts} +10 -16
  141. package/actions/erc7579/package.json +6 -0
  142. package/actions/{etherspot.ts → etherspot/index.ts} +1 -1
  143. package/actions/etherspot/package.json +6 -0
  144. package/actions/{passkeyServer.ts → passkeyServer/index.ts} +3 -3
  145. package/actions/passkeyServer/package.json +6 -0
  146. package/actions/pimlico/estimateErc20PaymasterCost.ts +9 -3
  147. package/actions/{pimlico.ts → pimlico/index.ts} +7 -7
  148. package/actions/pimlico/package.json +6 -0
  149. package/actions/smartAccount/index.ts +7 -0
  150. package/actions/smartAccount/package.json +6 -0
  151. package/clients/createSmartAccountClient.ts +45 -20
  152. package/clients/decorators/pimlico.ts +10 -10
  153. package/clients/package.json +6 -0
  154. package/clients/{passkeyServer.ts → passkeyServer/index.ts} +15 -13
  155. package/clients/passkeyServer/package.json +6 -0
  156. package/clients/{pimlico.ts → pimlico/index.ts} +50 -23
  157. package/clients/pimlico/package.json +6 -0
  158. package/errors/package.json +6 -0
  159. package/experimental/pimlico/package.json +6 -0
  160. package/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.ts +6 -4
  161. package/package.json +34 -29
  162. package/utils/index.ts +1 -0
  163. package/utils/package.json +6 -0
  164. package/utils/sortAddresses.ts +21 -0
  165. package/_cjs/actions/erc7579.js.map +0 -1
  166. package/_cjs/actions/etherspot.js.map +0 -1
  167. package/_cjs/actions/passkeyServer.js.map +0 -1
  168. package/_cjs/actions/pimlico.js.map +0 -1
  169. package/_cjs/actions/smartAccount.js.map +0 -1
  170. package/_cjs/clients/passkeyServer.js.map +0 -1
  171. package/_cjs/clients/pimlico.js.map +0 -1
  172. package/_esm/actions/erc7579.js.map +0 -1
  173. package/_esm/actions/etherspot.js +0 -2
  174. package/_esm/actions/etherspot.js.map +0 -1
  175. package/_esm/actions/passkeyServer.js +0 -4
  176. package/_esm/actions/passkeyServer.js.map +0 -1
  177. package/_esm/actions/pimlico.js +0 -8
  178. package/_esm/actions/pimlico.js.map +0 -1
  179. package/_esm/actions/smartAccount.js +0 -5
  180. package/_esm/actions/smartAccount.js.map +0 -1
  181. package/_esm/clients/passkeyServer.js.map +0 -1
  182. package/_esm/clients/pimlico.js.map +0 -1
  183. package/_types/actions/erc7579.d.ts.map +0 -1
  184. package/_types/actions/etherspot.d.ts +0 -2
  185. package/_types/actions/etherspot.d.ts.map +0 -1
  186. package/_types/actions/passkeyServer.d.ts +0 -4
  187. package/_types/actions/passkeyServer.d.ts.map +0 -1
  188. package/_types/actions/pimlico.d.ts +0 -8
  189. package/_types/actions/pimlico.d.ts.map +0 -1
  190. package/_types/actions/smartAccount.d.ts +0 -5
  191. package/_types/actions/smartAccount.d.ts.map +0 -1
  192. package/_types/clients/passkeyServer.d.ts.map +0 -1
  193. package/_types/clients/pimlico.d.ts +0 -13
  194. package/_types/clients/pimlico.d.ts.map +0 -1
  195. package/accounts/decodeCalls.test.ts +0 -505
  196. package/accounts/safe/signUserOperation.test.ts +0 -275
  197. package/actions/erc7579/accountId.test.ts +0 -39
  198. package/actions/erc7579/installModule.test.ts +0 -214
  199. package/actions/erc7579/installModules.test.ts +0 -235
  200. package/actions/erc7579/isModuleInstalled.test.ts +0 -72
  201. package/actions/erc7579/supportsExecutionMode.test.ts +0 -108
  202. package/actions/erc7579/supportsModule.test.ts +0 -35
  203. package/actions/erc7579/uninstallModule.test.ts +0 -128
  204. package/actions/erc7579/uninstallModules.test.ts +0 -117
  205. package/actions/pimlico/getTokenQuotes.test.ts +0 -90
  206. package/actions/pimlico/getUserOperationGasPrice.test.ts +0 -82
  207. package/actions/pimlico/getUserOperationStatus.test.ts +0 -223
  208. package/actions/pimlico/sponsorUserOperation.test.ts +0 -236
  209. package/actions/pimlico/validateSponsorshipPolicies.test.ts +0 -153
  210. package/actions/public/getAccountNonce.test.ts +0 -96
  211. package/actions/public/getSenderAddress.test.ts +0 -154
  212. package/actions/smartAccount/getCallsStatus.test.ts +0 -253
  213. package/actions/smartAccount/sendCalls.test.ts +0 -569
  214. package/actions/smartAccount/sendTransaction.test.ts +0 -414
  215. package/actions/smartAccount/signMessage.test.ts +0 -217
  216. package/actions/smartAccount/signTypedData.test.ts +0 -226
  217. package/actions/smartAccount.ts +0 -7
  218. package/experimental/pimlico/utils/prepareUserOperationForErc20Paymaster.test.ts +0 -574
  219. package/types/package.json +0 -6
  220. package/utils/decodeNonce.test.ts +0 -40
  221. package/utils/deepHexlify.test.ts +0 -57
  222. package/utils/encode7579Calls.test.ts +0 -69
  223. package/utils/encodeNonce.test.ts +0 -38
  224. package/utils/erc20AllowanceOverride.test.ts +0 -59
  225. package/utils/erc20BalanceOverride.test.ts +0 -57
  226. package/utils/getAddressFromInitCodeOrPaymasterAndData.test.ts +0 -31
  227. package/utils/getPackedUserOperation.test.ts +0 -204
  228. package/utils/getRequiredPrefund.test.ts +0 -90
  229. package/vitest.config.ts +0 -41
@@ -1,574 +0,0 @@
1
- import { http, parseEther, zeroAddress } from "viem"
2
- import {
3
- entryPoint06Address,
4
- entryPoint07Address,
5
- entryPoint08Address
6
- } from "viem/account-abstraction"
7
- import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"
8
- import { foundry } from "viem/chains"
9
- import { describe, expect } from "vitest"
10
- import {
11
- erc20Address,
12
- sudoMintTokens,
13
- tokenBalanceOf
14
- } from "../../../../mock-paymaster/helpers/erc20-utils"
15
- import {
16
- createAutoBundleTransport,
17
- testWithRpc
18
- } from "../../../../permissionless-test/src/testWithRpc"
19
- import {
20
- getCoreSmartAccounts,
21
- getPublicClient
22
- } from "../../../../permissionless-test/src/utils"
23
- import { createSmartAccountClient } from "../../../clients/createSmartAccountClient"
24
- import { createPimlicoClient } from "../../../clients/pimlico"
25
- import { prepareUserOperationForErc20Paymaster } from "./prepareUserOperationForErc20Paymaster"
26
-
27
- describe.each(getCoreSmartAccounts())(
28
- "prepareUserOperationForErc20Paymaster $name",
29
- ({
30
- getSmartAccountClient,
31
- supportsEntryPointV06,
32
- supportsEntryPointV07,
33
- supportsEntryPointV08,
34
- isEip7702Compliant,
35
- name
36
- }) => {
37
- const privateKey = generatePrivateKey()
38
- testWithRpc.skipIf(!supportsEntryPointV06 || name === "Kernel 0.2.1")(
39
- "prepareUserOperationForErc20Paymaster_v06",
40
- async ({ rpc }) => {
41
- const { anvilRpc } = rpc
42
-
43
- const account = (
44
- await getSmartAccountClient({
45
- entryPoint: {
46
- version: "0.6"
47
- },
48
- privateKey,
49
- ...rpc
50
- })
51
- ).account
52
-
53
- const pimlicoClient = createPimlicoClient({
54
- transport: http(rpc.paymasterRpc),
55
- entryPoint: {
56
- address: entryPoint06Address,
57
- version: "0.6"
58
- }
59
- })
60
-
61
- const publicClient = getPublicClient(anvilRpc)
62
-
63
- const smartAccountClient = createSmartAccountClient({
64
- // @ts-ignore
65
- client: getPublicClient(anvilRpc),
66
- account,
67
- paymaster: pimlicoClient,
68
- chain: foundry,
69
- userOperation: {
70
- prepareUserOperation:
71
- prepareUserOperationForErc20Paymaster(pimlicoClient)
72
- },
73
- bundlerTransport: createAutoBundleTransport(
74
- rpc.altoRpc,
75
- rpc.anvilRpc
76
- )
77
- })
78
-
79
- const INTIAL_ETH_BALANCE = await publicClient.getBalance({
80
- address: smartAccountClient.account.address
81
- })
82
-
83
- const PRE_MINT_TOKEN_BALANCE = await tokenBalanceOf(
84
- smartAccountClient.account.address,
85
- rpc.anvilRpc
86
- )
87
-
88
- await sudoMintTokens({
89
- amount: parseEther("100"),
90
- to: smartAccountClient.account.address,
91
- anvilRpc
92
- })
93
-
94
- const INITIAL_TOKEN_BALANCE =
95
- PRE_MINT_TOKEN_BALANCE + parseEther("100")
96
-
97
- const opHash = await smartAccountClient.sendUserOperation({
98
- calls: [
99
- {
100
- to: zeroAddress,
101
- data: "0x",
102
- value: 0n
103
- }
104
- ],
105
- paymasterContext: {
106
- token: erc20Address
107
- }
108
- })
109
-
110
- const receipt =
111
- await smartAccountClient.waitForUserOperationReceipt({
112
- hash: opHash
113
- })
114
-
115
- expect(receipt).toBeTruthy()
116
- expect(receipt).toBeTruthy()
117
-
118
- expect(receipt.success).toBeTruthy()
119
- const FINAL_TOKEN_BALANCE = await tokenBalanceOf(
120
- smartAccountClient.account.address,
121
- rpc.anvilRpc
122
- )
123
- const FINAL_ETH_BALANCE = await publicClient.getBalance({
124
- address: smartAccountClient.account.address
125
- })
126
-
127
- expect(FINAL_TOKEN_BALANCE).toBeLessThan(INITIAL_TOKEN_BALANCE) // Token balance should be deducted
128
- expect(FINAL_ETH_BALANCE).toEqual(INTIAL_ETH_BALANCE) // There should be no ETH balance change
129
- }
130
- )
131
-
132
- testWithRpc.skipIf(!supportsEntryPointV07)(
133
- "prepareUserOperationForErc20Paymaster_v07",
134
- async ({ rpc }) => {
135
- const { anvilRpc } = rpc
136
-
137
- const privateKeyAccount = privateKeyToAccount(privateKey)
138
-
139
- const account = (
140
- await getSmartAccountClient({
141
- entryPoint: {
142
- version: "0.7"
143
- },
144
- privateKey,
145
- ...rpc
146
- })
147
- ).account
148
-
149
- const publicClient = getPublicClient(anvilRpc)
150
-
151
- const pimlicoClient = createPimlicoClient({
152
- transport: http(rpc.paymasterRpc),
153
- entryPoint: {
154
- address: entryPoint07Address,
155
- version: "0.7"
156
- }
157
- })
158
-
159
- const smartAccountClient = createSmartAccountClient({
160
- // @ts-ignore
161
- client: getPublicClient(anvilRpc),
162
- account,
163
- paymaster: pimlicoClient,
164
- chain: foundry,
165
- userOperation: {
166
- prepareUserOperation:
167
- prepareUserOperationForErc20Paymaster(pimlicoClient)
168
- },
169
- bundlerTransport: createAutoBundleTransport(
170
- rpc.altoRpc,
171
- rpc.anvilRpc
172
- )
173
- })
174
-
175
- const INTIAL_ETH_BALANCE = await publicClient.getBalance({
176
- address: smartAccountClient.account.address
177
- })
178
-
179
- const PRE_MINT_TOKEN_BALANCE = await tokenBalanceOf(
180
- smartAccountClient.account.address,
181
- rpc.anvilRpc
182
- )
183
-
184
- await sudoMintTokens({
185
- amount: parseEther("100"),
186
- to: smartAccountClient.account.address,
187
- anvilRpc
188
- })
189
-
190
- const INITIAL_TOKEN_BALANCE =
191
- PRE_MINT_TOKEN_BALANCE + parseEther("100")
192
-
193
- const authorization = isEip7702Compliant
194
- ? await privateKeyAccount.signAuthorization({
195
- address: (smartAccountClient.account as any)
196
- .implementation,
197
- chainId: smartAccountClient.chain.id,
198
- nonce: await publicClient.getTransactionCount({
199
- address: smartAccountClient.account.address
200
- })
201
- })
202
- : undefined
203
-
204
- const opHash = await smartAccountClient.sendUserOperation({
205
- calls: [
206
- {
207
- to: zeroAddress,
208
- data: "0x",
209
- value: 0n
210
- }
211
- ],
212
- paymasterContext: {
213
- token: erc20Address
214
- },
215
- authorization
216
- })
217
-
218
- const receipt =
219
- await smartAccountClient.waitForUserOperationReceipt({
220
- hash: opHash
221
- })
222
-
223
- expect(receipt).toBeTruthy()
224
- expect(receipt).toBeTruthy()
225
- expect(receipt.success).toBeTruthy()
226
-
227
- const FINAL_TOKEN_BALANCE = await tokenBalanceOf(
228
- smartAccountClient.account.address,
229
- rpc.anvilRpc
230
- )
231
- const FINAL_ETH_BALANCE = await publicClient.getBalance({
232
- address: smartAccountClient.account.address
233
- })
234
-
235
- expect(FINAL_TOKEN_BALANCE).toBeLessThan(INITIAL_TOKEN_BALANCE) // Token balance should be deducted
236
- expect(FINAL_ETH_BALANCE).toEqual(INTIAL_ETH_BALANCE) // There should be no ETH balance change
237
- }
238
- )
239
-
240
- testWithRpc.skipIf(!supportsEntryPointV08)(
241
- "prepareUserOperationForErc20Paymaster_v08",
242
- async ({ rpc }) => {
243
- const { anvilRpc } = rpc
244
-
245
- const privateKeyAccount = privateKeyToAccount(privateKey)
246
-
247
- const account = (
248
- await getSmartAccountClient({
249
- entryPoint: {
250
- version: "0.8"
251
- },
252
- privateKey,
253
- ...rpc
254
- })
255
- ).account
256
-
257
- const publicClient = getPublicClient(anvilRpc)
258
-
259
- const pimlicoClient = createPimlicoClient({
260
- transport: http(rpc.paymasterRpc),
261
- entryPoint: {
262
- address: entryPoint08Address,
263
- version: "0.8"
264
- }
265
- })
266
-
267
- const smartAccountClient = createSmartAccountClient({
268
- // @ts-ignore
269
- client: getPublicClient(anvilRpc),
270
- account,
271
- paymaster: pimlicoClient,
272
- chain: foundry,
273
- userOperation: {
274
- prepareUserOperation:
275
- prepareUserOperationForErc20Paymaster(pimlicoClient)
276
- },
277
- bundlerTransport: createAutoBundleTransport(
278
- rpc.altoRpc,
279
- rpc.anvilRpc
280
- )
281
- })
282
-
283
- const INTIAL_ETH_BALANCE = await publicClient.getBalance({
284
- address: smartAccountClient.account.address
285
- })
286
-
287
- const PRE_MINT_TOKEN_BALANCE = await tokenBalanceOf(
288
- smartAccountClient.account.address,
289
- rpc.anvilRpc
290
- )
291
-
292
- await sudoMintTokens({
293
- amount: parseEther("100"),
294
- to: smartAccountClient.account.address,
295
- anvilRpc
296
- })
297
-
298
- const INITIAL_TOKEN_BALANCE =
299
- PRE_MINT_TOKEN_BALANCE + parseEther("100")
300
-
301
- const authorization = isEip7702Compliant
302
- ? await privateKeyAccount.signAuthorization({
303
- address: (smartAccountClient.account as any)
304
- .implementation,
305
- chainId: smartAccountClient.chain.id,
306
- nonce: await publicClient.getTransactionCount({
307
- address: smartAccountClient.account.address
308
- })
309
- })
310
- : undefined
311
-
312
- const opHash = await smartAccountClient.sendUserOperation({
313
- calls: [
314
- {
315
- to: zeroAddress,
316
- data: "0x",
317
- value: 0n
318
- }
319
- ],
320
- paymasterContext: {
321
- token: erc20Address
322
- },
323
- authorization
324
- })
325
-
326
- const receipt =
327
- await smartAccountClient.waitForUserOperationReceipt({
328
- hash: opHash
329
- })
330
-
331
- expect(receipt).toBeTruthy()
332
- expect(receipt).toBeTruthy()
333
- expect(receipt.success).toBeTruthy()
334
-
335
- const FINAL_TOKEN_BALANCE = await tokenBalanceOf(
336
- smartAccountClient.account.address,
337
- rpc.anvilRpc
338
- )
339
- const FINAL_ETH_BALANCE = await publicClient.getBalance({
340
- address: smartAccountClient.account.address
341
- })
342
-
343
- expect(FINAL_TOKEN_BALANCE).toBeLessThan(INITIAL_TOKEN_BALANCE) // Token balance should be deducted
344
- expect(FINAL_ETH_BALANCE).toEqual(INTIAL_ETH_BALANCE) // There should be no ETH balance change
345
- }
346
- )
347
-
348
- testWithRpc.skipIf(!supportsEntryPointV07)(
349
- "prepareUserOperationForErc20Paymaster_v07 (balanceOverride enabled)",
350
- async ({ rpc }) => {
351
- const { anvilRpc } = rpc
352
-
353
- const privateKeyAccount = privateKeyToAccount(privateKey)
354
-
355
- const account = (
356
- await getSmartAccountClient({
357
- entryPoint: {
358
- version: "0.7"
359
- },
360
- privateKey,
361
- ...rpc
362
- })
363
- ).account
364
-
365
- const publicClient = getPublicClient(anvilRpc)
366
-
367
- const pimlicoClient = createPimlicoClient({
368
- transport: http(rpc.paymasterRpc),
369
- entryPoint: {
370
- address: entryPoint07Address,
371
- version: "0.7"
372
- }
373
- })
374
-
375
- const smartAccountClient = createSmartAccountClient({
376
- // @ts-ignore
377
- client: getPublicClient(anvilRpc),
378
- account,
379
- paymaster: pimlicoClient,
380
- chain: foundry,
381
- userOperation: {
382
- prepareUserOperation:
383
- prepareUserOperationForErc20Paymaster(
384
- pimlicoClient,
385
- {
386
- balanceOverride: true
387
- }
388
- )
389
- },
390
- bundlerTransport: createAutoBundleTransport(
391
- rpc.altoRpc,
392
- rpc.anvilRpc
393
- )
394
- })
395
-
396
- const INTIAL_ETH_BALANCE = await publicClient.getBalance({
397
- address: smartAccountClient.account.address
398
- })
399
-
400
- const PRE_MINT_TOKEN_BALANCE = await tokenBalanceOf(
401
- smartAccountClient.account.address,
402
- rpc.anvilRpc
403
- )
404
-
405
- await sudoMintTokens({
406
- amount: parseEther("100"),
407
- to: smartAccountClient.account.address,
408
- anvilRpc
409
- })
410
-
411
- const INITIAL_TOKEN_BALANCE =
412
- PRE_MINT_TOKEN_BALANCE + parseEther("100")
413
-
414
- const authorization = isEip7702Compliant
415
- ? await privateKeyAccount.signAuthorization({
416
- address: (smartAccountClient.account as any)
417
- .implementation,
418
- chainId: smartAccountClient.chain.id,
419
- nonce: await publicClient.getTransactionCount({
420
- address: smartAccountClient.account.address
421
- })
422
- })
423
- : undefined
424
-
425
- const opHash = await smartAccountClient.sendUserOperation({
426
- calls: [
427
- {
428
- to: zeroAddress,
429
- data: "0x",
430
- value: 0n
431
- }
432
- ],
433
- paymasterContext: {
434
- token: erc20Address
435
- },
436
- authorization
437
- })
438
-
439
- const receipt =
440
- await smartAccountClient.waitForUserOperationReceipt({
441
- hash: opHash
442
- })
443
-
444
- expect(receipt).toBeTruthy()
445
- expect(receipt).toBeTruthy()
446
- expect(receipt.success).toBeTruthy()
447
-
448
- const FINAL_TOKEN_BALANCE = await tokenBalanceOf(
449
- smartAccountClient.account.address,
450
- rpc.anvilRpc
451
- )
452
- const FINAL_ETH_BALANCE = await publicClient.getBalance({
453
- address: smartAccountClient.account.address
454
- })
455
-
456
- expect(FINAL_TOKEN_BALANCE).toBeLessThan(INITIAL_TOKEN_BALANCE) // Token balance should be deducted
457
- expect(FINAL_ETH_BALANCE).toEqual(INTIAL_ETH_BALANCE) // There should be no ETH balance change
458
- }
459
- )
460
-
461
- testWithRpc.skipIf(!supportsEntryPointV08)(
462
- "prepareUserOperationForErc20Paymaster_v08 (balanceOverride enabled)",
463
- async ({ rpc }) => {
464
- const { anvilRpc } = rpc
465
-
466
- const privateKeyAccount = privateKeyToAccount(privateKey)
467
-
468
- const account = (
469
- await getSmartAccountClient({
470
- entryPoint: {
471
- version: "0.8"
472
- },
473
- privateKey,
474
- ...rpc
475
- })
476
- ).account
477
-
478
- const publicClient = getPublicClient(anvilRpc)
479
-
480
- const pimlicoClient = createPimlicoClient({
481
- transport: http(rpc.paymasterRpc),
482
- entryPoint: {
483
- address: entryPoint08Address,
484
- version: "0.8"
485
- }
486
- })
487
-
488
- const smartAccountClient = createSmartAccountClient({
489
- // @ts-ignore
490
- client: getPublicClient(anvilRpc),
491
- account,
492
- paymaster: pimlicoClient,
493
- chain: foundry,
494
- userOperation: {
495
- prepareUserOperation:
496
- prepareUserOperationForErc20Paymaster(
497
- pimlicoClient,
498
- {
499
- balanceOverride: true
500
- }
501
- )
502
- },
503
- bundlerTransport: createAutoBundleTransport(
504
- rpc.altoRpc,
505
- rpc.anvilRpc
506
- )
507
- })
508
-
509
- const INTIAL_ETH_BALANCE = await publicClient.getBalance({
510
- address: smartAccountClient.account.address
511
- })
512
-
513
- const PRE_MINT_TOKEN_BALANCE = await tokenBalanceOf(
514
- smartAccountClient.account.address,
515
- rpc.anvilRpc
516
- )
517
-
518
- await sudoMintTokens({
519
- amount: parseEther("100"),
520
- to: smartAccountClient.account.address,
521
- anvilRpc
522
- })
523
-
524
- const INITIAL_TOKEN_BALANCE =
525
- PRE_MINT_TOKEN_BALANCE + parseEther("100")
526
-
527
- const authorization = isEip7702Compliant
528
- ? await privateKeyAccount.signAuthorization({
529
- address: (smartAccountClient.account as any)
530
- .implementation,
531
- chainId: smartAccountClient.chain.id,
532
- nonce: await publicClient.getTransactionCount({
533
- address: smartAccountClient.account.address
534
- })
535
- })
536
- : undefined
537
-
538
- const opHash = await smartAccountClient.sendUserOperation({
539
- calls: [
540
- {
541
- to: zeroAddress,
542
- data: "0x",
543
- value: 0n
544
- }
545
- ],
546
- paymasterContext: {
547
- token: erc20Address
548
- },
549
- authorization
550
- })
551
-
552
- const receipt =
553
- await smartAccountClient.waitForUserOperationReceipt({
554
- hash: opHash
555
- })
556
-
557
- expect(receipt).toBeTruthy()
558
- expect(receipt).toBeTruthy()
559
- expect(receipt.success).toBeTruthy()
560
-
561
- const FINAL_TOKEN_BALANCE = await tokenBalanceOf(
562
- smartAccountClient.account.address,
563
- rpc.anvilRpc
564
- )
565
- const FINAL_ETH_BALANCE = await publicClient.getBalance({
566
- address: smartAccountClient.account.address
567
- })
568
-
569
- expect(FINAL_TOKEN_BALANCE).toBeLessThan(INITIAL_TOKEN_BALANCE) // Token balance should be deducted
570
- expect(FINAL_ETH_BALANCE).toEqual(INTIAL_ETH_BALANCE) // There should be no ETH balance change
571
- }
572
- )
573
- }
574
- )
@@ -1,6 +0,0 @@
1
- {
2
- "type": "module",
3
- "types": "../_types/types/index.d.ts",
4
- "module": "../_esm/types/index.js",
5
- "main": "../_cjs/types/index.js"
6
- }
@@ -1,40 +0,0 @@
1
- import { describe, expect, test } from "vitest"
2
- import { decodeNonce, encodeNonce } from "./index"
3
-
4
- describe("decodeNonce", () => {
5
- test("should encode key and sequence correctly", async () => {
6
- const key = 123456789012345678901234n
7
- const sequence = 9876543210n
8
-
9
- const result = encodeNonce({ key, sequence })
10
-
11
- const decodedNonce = decodeNonce(result)
12
-
13
- expect(decodedNonce.key).toBe(key)
14
- expect(decodedNonce.sequence).toBe(sequence)
15
- })
16
-
17
- test("should handle zero values correctly", () => {
18
- const key = BigInt(0)
19
- const sequence = BigInt(0)
20
-
21
- const result = encodeNonce({ key, sequence })
22
-
23
- const decodedNonce = decodeNonce(result)
24
-
25
- expect(decodedNonce.key).toBe(key)
26
- expect(decodedNonce.sequence).toBe(sequence)
27
- })
28
-
29
- test("should handle large values correctly", () => {
30
- const key = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFF")
31
- const sequence = BigInt("0xFFFFFFFF")
32
-
33
- const result = encodeNonce({ key, sequence })
34
-
35
- const decodedNonce = decodeNonce(result)
36
-
37
- expect(decodedNonce.key).toBe(key)
38
- expect(decodedNonce.sequence).toBe(sequence)
39
- })
40
- })
@@ -1,57 +0,0 @@
1
- import { toHex } from "viem"
2
- import { describe, expect, test } from "vitest"
3
- import { deepHexlify } from "../utils"
4
-
5
- describe("deepHexlify", () => {
6
- test("should return undefined for function input", async () => {
7
- const func = () => {}
8
- expect(deepHexlify(func)).toBeUndefined()
9
- })
10
-
11
- test("should return null for null input", () => {
12
- expect(deepHexlify(null)).toBeNull()
13
- })
14
-
15
- test("should return the same string for string input", () => {
16
- const str = "test"
17
- expect(deepHexlify(str)).toBe(str)
18
- })
19
-
20
- test("should return the same boolean for boolean input", () => {
21
- const bool = true
22
- expect(deepHexlify(bool)).toBe(bool)
23
- })
24
-
25
- test("should return hex string for bigint input", () => {
26
- const bigint = BigInt(12345)
27
- expect(deepHexlify(bigint)).toBe(toHex(bigint))
28
- })
29
-
30
- test("should return hex string for number input", () => {
31
- const number = 12345
32
- expect(deepHexlify(number)).toBe(toHex(number).replace(/^0x0/, "0x"))
33
- })
34
-
35
- test("should return array with hex values for array input", () => {
36
- const array = [12345, BigInt(67890)]
37
- expect(deepHexlify(array)).toEqual([
38
- toHex(12345).replace(/^0x0/, "0x"),
39
- toHex(BigInt(67890))
40
- ])
41
- })
42
-
43
- test("should return object with hex values for object input", () => {
44
- const obj = {
45
- a: 12345,
46
- b: BigInt(67890),
47
- c: "string",
48
- d: true
49
- }
50
- expect(deepHexlify(obj)).toEqual({
51
- a: toHex(12345).replace(/^0x0/, "0x"),
52
- b: toHex(BigInt(67890)),
53
- c: "string",
54
- d: true
55
- })
56
- })
57
- })