permissionless 0.0.30 → 0.0.32

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 (118) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/actions/bundler/estimateUserOperationGas.js +21 -15
  3. package/_cjs/actions/bundler/estimateUserOperationGas.js.map +1 -1
  4. package/_cjs/actions/bundler/sendUserOperation.js +14 -7
  5. package/_cjs/actions/bundler/sendUserOperation.js.map +1 -1
  6. package/_cjs/actions/index.js.map +1 -1
  7. package/_cjs/errors/account.js +311 -0
  8. package/_cjs/errors/account.js.map +1 -0
  9. package/_cjs/errors/bundler.js +61 -0
  10. package/_cjs/errors/bundler.js.map +1 -0
  11. package/_cjs/errors/estimateUserOperationGas.js +47 -0
  12. package/_cjs/errors/estimateUserOperationGas.js.map +1 -0
  13. package/_cjs/errors/gas.js +113 -0
  14. package/_cjs/errors/gas.js.map +1 -0
  15. package/_cjs/errors/index.js +35 -0
  16. package/_cjs/errors/index.js.map +1 -0
  17. package/_cjs/errors/paymaster.js +228 -0
  18. package/_cjs/errors/paymaster.js.map +1 -0
  19. package/_cjs/errors/sendUserOperation.js +47 -0
  20. package/_cjs/errors/sendUserOperation.js.map +1 -0
  21. package/_cjs/errors/utils.js +18 -0
  22. package/_cjs/errors/utils.js.map +1 -0
  23. package/_cjs/index.js +1 -0
  24. package/_cjs/index.js.map +1 -1
  25. package/_cjs/utils/errors/getBundlerError.js +124 -0
  26. package/_cjs/utils/errors/getBundlerError.js.map +1 -0
  27. package/_cjs/utils/errors/getEstimateUserOperationGasError.js +19 -0
  28. package/_cjs/utils/errors/getEstimateUserOperationGasError.js.map +1 -0
  29. package/_cjs/utils/errors/getSendUserOperationError.js +19 -0
  30. package/_cjs/utils/errors/getSendUserOperationError.js.map +1 -0
  31. package/_cjs/utils/getAddressFromInitCodeOrPaymasterAndData.js +15 -0
  32. package/_cjs/utils/getAddressFromInitCodeOrPaymasterAndData.js.map +1 -0
  33. package/_cjs/utils/index.js +5 -3
  34. package/_cjs/utils/index.js.map +1 -1
  35. package/_esm/actions/bundler/estimateUserOperationGas.js +22 -15
  36. package/_esm/actions/bundler/estimateUserOperationGas.js.map +1 -1
  37. package/_esm/actions/bundler/sendUserOperation.js +14 -7
  38. package/_esm/actions/bundler/sendUserOperation.js.map +1 -1
  39. package/_esm/actions/index.js.map +1 -1
  40. package/_esm/errors/account.js +298 -0
  41. package/_esm/errors/account.js.map +1 -0
  42. package/_esm/errors/bundler.js +56 -0
  43. package/_esm/errors/bundler.js.map +1 -0
  44. package/_esm/errors/estimateUserOperationGas.js +43 -0
  45. package/_esm/errors/estimateUserOperationGas.js.map +1 -0
  46. package/_esm/errors/gas.js +106 -0
  47. package/_esm/errors/gas.js.map +1 -0
  48. package/_esm/errors/index.js +8 -0
  49. package/_esm/errors/index.js.map +1 -0
  50. package/_esm/errors/paymaster.js +218 -0
  51. package/_esm/errors/paymaster.js.map +1 -0
  52. package/_esm/errors/sendUserOperation.js +44 -0
  53. package/_esm/errors/sendUserOperation.js.map +1 -0
  54. package/_esm/errors/utils.js +14 -0
  55. package/_esm/errors/utils.js.map +1 -0
  56. package/_esm/index.js +1 -0
  57. package/_esm/index.js.map +1 -1
  58. package/_esm/utils/errors/getBundlerError.js +121 -0
  59. package/_esm/utils/errors/getBundlerError.js.map +1 -0
  60. package/_esm/utils/errors/getEstimateUserOperationGasError.js +19 -0
  61. package/_esm/utils/errors/getEstimateUserOperationGasError.js.map +1 -0
  62. package/_esm/utils/errors/getSendUserOperationError.js +15 -0
  63. package/_esm/utils/errors/getSendUserOperationError.js.map +1 -0
  64. package/_esm/utils/getAddressFromInitCodeOrPaymasterAndData.js +11 -0
  65. package/_esm/utils/getAddressFromInitCodeOrPaymasterAndData.js.map +1 -0
  66. package/_esm/utils/index.js +3 -2
  67. package/_esm/utils/index.js.map +1 -1
  68. package/_types/actions/bundler/estimateUserOperationGas.d.ts +3 -1
  69. package/_types/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
  70. package/_types/actions/bundler/sendUserOperation.d.ts.map +1 -1
  71. package/_types/actions/index.d.ts +2 -2
  72. package/_types/actions/index.d.ts.map +1 -1
  73. package/_types/errors/account.d.ts +121 -0
  74. package/_types/errors/account.d.ts.map +1 -0
  75. package/_types/errors/bundler.d.ts +24 -0
  76. package/_types/errors/bundler.d.ts.map +1 -0
  77. package/_types/errors/estimateUserOperationGas.d.ts +13 -0
  78. package/_types/errors/estimateUserOperationGas.d.ts.map +1 -0
  79. package/_types/errors/gas.d.ts +47 -0
  80. package/_types/errors/gas.d.ts.map +1 -0
  81. package/_types/errors/index.d.ts +8 -0
  82. package/_types/errors/index.d.ts.map +1 -0
  83. package/_types/errors/paymaster.d.ts +85 -0
  84. package/_types/errors/paymaster.d.ts.map +1 -0
  85. package/_types/errors/sendUserOperation.d.ts +13 -0
  86. package/_types/errors/sendUserOperation.d.ts.map +1 -0
  87. package/_types/errors/utils.d.ts +5 -0
  88. package/_types/errors/utils.d.ts.map +1 -0
  89. package/_types/index.d.ts +1 -0
  90. package/_types/index.d.ts.map +1 -1
  91. package/_types/utils/errors/getBundlerError.d.ts +11 -0
  92. package/_types/utils/errors/getBundlerError.d.ts.map +1 -0
  93. package/_types/utils/errors/getEstimateUserOperationGasError.d.ts +9 -0
  94. package/_types/utils/errors/getEstimateUserOperationGasError.d.ts.map +1 -0
  95. package/_types/utils/errors/getSendUserOperationError.d.ts +4 -0
  96. package/_types/utils/errors/getSendUserOperationError.d.ts.map +1 -0
  97. package/_types/utils/getAddressFromInitCodeOrPaymasterAndData.d.ts +3 -0
  98. package/_types/utils/getAddressFromInitCodeOrPaymasterAndData.d.ts.map +1 -0
  99. package/_types/utils/index.d.ts +3 -2
  100. package/_types/utils/index.d.ts.map +1 -1
  101. package/actions/bundler/estimateUserOperationGas.ts +33 -15
  102. package/actions/bundler/sendUserOperation.ts +26 -8
  103. package/actions/index.ts +3 -1
  104. package/errors/account.ts +345 -0
  105. package/errors/bundler.ts +62 -0
  106. package/errors/estimateUserOperationGas.ts +50 -0
  107. package/errors/gas.ts +120 -0
  108. package/errors/index.ts +118 -0
  109. package/errors/paymaster.ts +257 -0
  110. package/errors/sendUserOperation.ts +49 -0
  111. package/errors/utils.ts +19 -0
  112. package/index.ts +1 -0
  113. package/package.json +6 -1
  114. package/utils/errors/getBundlerError.ts +220 -0
  115. package/utils/errors/getEstimateUserOperationGasError.ts +37 -0
  116. package/utils/errors/getSendUserOperationError.ts +25 -0
  117. package/utils/getAddressFromInitCodeOrPaymasterAndData.ts +13 -0
  118. package/utils/index.ts +4 -2
@@ -0,0 +1,220 @@
1
+ import {
2
+ type Address,
3
+ BaseError,
4
+ ExecutionRevertedError,
5
+ type ExecutionRevertedErrorType,
6
+ UnknownNodeError,
7
+ type UnknownNodeErrorType
8
+ } from "viem"
9
+ import { SenderAlreadyDeployedError } from "../../errors"
10
+ import {
11
+ InitCodeDidNotDeploySenderError,
12
+ type InitCodeDidNotDeploySenderErrorType,
13
+ InitCodeRevertedError,
14
+ type InitCodeRevertedErrorType,
15
+ InvalidSmartAccountNonceError,
16
+ type InvalidSmartAccountNonceErrorType,
17
+ SenderAddressMismatchError,
18
+ type SenderAddressMismatchErrorType,
19
+ type SenderAlreadyDeployedErrorType,
20
+ SenderNotDeployedError,
21
+ type SenderNotDeployedErrorType,
22
+ SmartAccountInsufficientFundsError,
23
+ type SmartAccountInsufficientFundsErrorType,
24
+ SmartAccountSignatureValidityPeriodError,
25
+ type SmartAccountSignatureValidityPeriodErrorType,
26
+ SmartAccountValidationRevertedError,
27
+ type SmartAccountValidationRevertedErrorType
28
+ } from "../../errors/account"
29
+ import {
30
+ PaymasterDataRejectedError,
31
+ type PaymasterDataRejectedErrorType,
32
+ PaymasterDepositTooLowError,
33
+ type PaymasterDepositTooLowErrorType,
34
+ PaymasterNotDeployedError,
35
+ type PaymasterNotDeployedErrorType,
36
+ PaymasterValidationRevertedError,
37
+ type PaymasterValidationRevertedErrorType,
38
+ PaymasterValidityPeriodError,
39
+ type PaymasterValidityPeriodErrorType
40
+ } from "../../errors/paymaster"
41
+ import type { UserOperation } from "../../types"
42
+
43
+ export type GetBundlerErrorParameters = {
44
+ userOperation: Partial<UserOperation>
45
+ entryPoint: Address
46
+ }
47
+
48
+ export type GetBundlerErrorReturnType =
49
+ | ExecutionRevertedErrorType
50
+ | UnknownNodeErrorType
51
+ | SenderAlreadyDeployedErrorType
52
+ | InitCodeRevertedErrorType
53
+ | SenderAddressMismatchErrorType
54
+ | InitCodeDidNotDeploySenderErrorType
55
+ | SenderNotDeployedErrorType
56
+ | SmartAccountInsufficientFundsErrorType
57
+ | SmartAccountSignatureValidityPeriodErrorType
58
+ | SmartAccountValidationRevertedErrorType
59
+ | InvalidSmartAccountNonceErrorType
60
+ | PaymasterNotDeployedErrorType
61
+ | PaymasterDepositTooLowErrorType
62
+ | PaymasterValidityPeriodErrorType
63
+ | PaymasterValidationRevertedErrorType
64
+ | PaymasterDataRejectedErrorType
65
+
66
+ export function getBundlerError(
67
+ err: BaseError,
68
+ args: GetBundlerErrorParameters
69
+ ) {
70
+ const message = (err.details || "").toLowerCase()
71
+
72
+ const executionRevertedError =
73
+ err instanceof BaseError
74
+ ? err.walk(
75
+ (e) =>
76
+ (e as { code: number }).code ===
77
+ ExecutionRevertedError.code
78
+ )
79
+ : err
80
+
81
+ if (executionRevertedError instanceof BaseError) {
82
+ return new ExecutionRevertedError({
83
+ cause: err,
84
+ message: executionRevertedError.details
85
+ }) as any
86
+ }
87
+
88
+ // TODO: Add validation Errors
89
+ if (args.userOperation.sender === undefined)
90
+ return new UnknownNodeError({ cause: err })
91
+ if (args.userOperation.nonce === undefined)
92
+ return new UnknownNodeError({ cause: err })
93
+
94
+ if (SenderAlreadyDeployedError.message.test(message)) {
95
+ return new SenderAlreadyDeployedError({
96
+ cause: err,
97
+ sender: args.userOperation.sender,
98
+ docsPath:
99
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa10"
100
+ }) as any
101
+ }
102
+
103
+ if (InitCodeRevertedError.message.test(message)) {
104
+ return new InitCodeRevertedError({
105
+ cause: err,
106
+ docsPath:
107
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa13"
108
+ }) as any
109
+ }
110
+
111
+ if (SenderAddressMismatchError.message.test(message)) {
112
+ return new SenderAddressMismatchError({
113
+ cause: err,
114
+ sender: args.userOperation.sender,
115
+ docsPath:
116
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa14"
117
+ }) as any
118
+ }
119
+
120
+ if (InitCodeDidNotDeploySenderError.message.test(message)) {
121
+ return new InitCodeDidNotDeploySenderError({
122
+ cause: err,
123
+ sender: args.userOperation.sender,
124
+ docsPath:
125
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa15"
126
+ }) as any
127
+ }
128
+
129
+ if (SenderNotDeployedError.message.test(message)) {
130
+ return new SenderNotDeployedError({
131
+ cause: err,
132
+ sender: args.userOperation.sender,
133
+ docsPath:
134
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa20"
135
+ }) as any
136
+ }
137
+
138
+ if (SmartAccountInsufficientFundsError.message.test(message)) {
139
+ return new SmartAccountInsufficientFundsError({
140
+ cause: err,
141
+ sender: args.userOperation.sender,
142
+ docsPath:
143
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa21"
144
+ }) as any
145
+ }
146
+
147
+ if (SmartAccountSignatureValidityPeriodError.message.test(message)) {
148
+ return new SmartAccountSignatureValidityPeriodError({
149
+ cause: err,
150
+ docsPath:
151
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa22"
152
+ }) as any
153
+ }
154
+
155
+ if (SmartAccountValidationRevertedError.message.test(message)) {
156
+ return new SmartAccountValidationRevertedError({
157
+ cause: err,
158
+ sender: args.userOperation.sender,
159
+ docsPath:
160
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa23"
161
+ }) as any
162
+ }
163
+
164
+ if (InvalidSmartAccountNonceError.message.test(message)) {
165
+ return new InvalidSmartAccountNonceError({
166
+ cause: err,
167
+ sender: args.userOperation.sender,
168
+ nonce: args.userOperation.nonce,
169
+ docsPath:
170
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa25"
171
+ }) as any
172
+ }
173
+
174
+ if (PaymasterNotDeployedError.message.test(message)) {
175
+ return new PaymasterNotDeployedError({
176
+ cause: err,
177
+ paymasterAndData: args.userOperation.paymasterAndData,
178
+ docsPath:
179
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa30"
180
+ }) as any
181
+ }
182
+
183
+ if (PaymasterDepositTooLowError.message.test(message)) {
184
+ return new PaymasterDepositTooLowError({
185
+ cause: err,
186
+ paymasterAndData: args.userOperation.paymasterAndData,
187
+ docsPath:
188
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa31"
189
+ }) as any
190
+ }
191
+
192
+ if (PaymasterValidityPeriodError.message.test(message)) {
193
+ return new PaymasterValidityPeriodError({
194
+ cause: err,
195
+ paymasterAndData: args.userOperation.paymasterAndData,
196
+ docsPath:
197
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa32"
198
+ }) as any
199
+ }
200
+
201
+ if (PaymasterValidationRevertedError.message.test(message)) {
202
+ return new PaymasterValidationRevertedError({
203
+ cause: err,
204
+ paymasterAndData: args.userOperation.paymasterAndData,
205
+ docsPath:
206
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa33"
207
+ }) as any
208
+ }
209
+
210
+ if (PaymasterDataRejectedError.message.test(message)) {
211
+ return new PaymasterDataRejectedError({
212
+ cause: err,
213
+ paymasterAndData: args.userOperation.paymasterAndData,
214
+ docsPath:
215
+ "https://docs.pimlico.io/bundler/reference/entrypoint-errors/aa34"
216
+ }) as any
217
+ }
218
+
219
+ return new UnknownNodeError({ cause: err }) as any
220
+ }
@@ -0,0 +1,37 @@
1
+ import { BaseError, UnknownNodeError } from "viem"
2
+ import type { EstimateUserOperationGasParameters } from "../../actions/bundler/estimateUserOperationGas"
3
+ import {
4
+ EstimateUserOperationGasError,
5
+ type EstimateUserOperationGasErrorType
6
+ } from "../../errors/estimateUserOperationGas"
7
+ import { type ErrorType } from "../../errors/utils"
8
+ import {
9
+ type GetBundlerErrorParameters,
10
+ type GetBundlerErrorReturnType,
11
+ getBundlerError
12
+ } from "./getBundlerError"
13
+
14
+ export type GetEstimateUserOperationGasErrorReturnType<cause = ErrorType> =
15
+ Omit<EstimateUserOperationGasErrorType, "cause"> & {
16
+ cause: cause | GetBundlerErrorReturnType
17
+ }
18
+
19
+ export function getEstimateUserOperationGasError<err extends ErrorType<string>>(
20
+ error: err,
21
+ args: EstimateUserOperationGasParameters
22
+ ) {
23
+ const cause = (() => {
24
+ const cause = getBundlerError(
25
+ // biome-ignore lint/complexity/noBannedTypes: <explanation>
26
+ error as {} as BaseError,
27
+ args as GetBundlerErrorParameters
28
+ )
29
+ // biome-ignore lint/complexity/noBannedTypes: <explanation>
30
+ if (cause instanceof UnknownNodeError) return error as {} as BaseError
31
+ return cause
32
+ })()
33
+
34
+ throw new EstimateUserOperationGasError(cause, {
35
+ ...args
36
+ }) as GetEstimateUserOperationGasErrorReturnType<err>
37
+ }
@@ -0,0 +1,25 @@
1
+ import { BaseError, UnknownNodeError } from "viem"
2
+ import type { SendUserOperationParameters } from "../../actions/bundler/sendUserOperation"
3
+ import { SendUserOperationError } from "../../errors"
4
+ import {
5
+ type GetBundlerErrorParameters,
6
+ getBundlerError
7
+ } from "./getBundlerError"
8
+
9
+ export function getSendUserOperationError(
10
+ err: BaseError,
11
+ args: SendUserOperationParameters
12
+ ) {
13
+ const cause = (() => {
14
+ const cause = getBundlerError(
15
+ err as BaseError,
16
+ args as GetBundlerErrorParameters
17
+ )
18
+ if (cause instanceof UnknownNodeError) return err as BaseError
19
+ return cause
20
+ })()
21
+
22
+ throw new SendUserOperationError(cause, {
23
+ ...args
24
+ })
25
+ }
@@ -0,0 +1,13 @@
1
+ import { type Address, type Hex, getAddress } from "viem"
2
+
3
+ export function getAddressFromInitCodeOrPaymasterAndData(
4
+ data: Hex
5
+ ): Address | undefined {
6
+ if (!data) {
7
+ return undefined
8
+ }
9
+ if (data.length >= 42) {
10
+ return getAddress(data.slice(0, 42))
11
+ }
12
+ return undefined
13
+ }
package/utils/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Account, Address } from "viem"
2
2
  import { deepHexlify, transactionReceiptStatus } from "./deepHexlify.js"
3
3
  import { getAction } from "./getAction.js"
4
+ import { getAddressFromInitCodeOrPaymasterAndData } from "./getAddressFromInitCodeOrPaymasterAndData.js"
4
5
  import {
5
6
  type GetRequiredPrefundReturnType,
6
7
  getRequiredPrefund
@@ -9,7 +10,7 @@ import {
9
10
  type GetUserOperationHashParams,
10
11
  getUserOperationHash
11
12
  } from "./getUserOperationHash.js"
12
- import { isSmartAccountDeployed } from "./isSmartAccountDeployed"
13
+ import { isSmartAccountDeployed } from "./isSmartAccountDeployed.js"
13
14
  import {
14
15
  AccountOrClientNotFoundError,
15
16
  type SignUserOperationHashWithECDSAParams,
@@ -35,5 +36,6 @@ export {
35
36
  signUserOperationHashWithECDSA,
36
37
  type SignUserOperationHashWithECDSAParams,
37
38
  AccountOrClientNotFoundError,
38
- isSmartAccountDeployed
39
+ isSmartAccountDeployed,
40
+ getAddressFromInitCodeOrPaymasterAndData
39
41
  }