permissionless 0.0.2 → 0.0.4

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 (82) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/_cjs/actions/bundler.js +6 -5
  3. package/_cjs/actions/bundler.js.map +1 -1
  4. package/_cjs/actions/index.js +3 -2
  5. package/_cjs/actions/index.js.map +1 -1
  6. package/_cjs/actions/pimlico.js +55 -0
  7. package/_cjs/actions/pimlico.js.map +1 -0
  8. package/_cjs/actions/utils.js +5 -1
  9. package/_cjs/actions/utils.js.map +1 -1
  10. package/_cjs/clients/bundler.js +17 -0
  11. package/_cjs/clients/bundler.js.map +1 -0
  12. package/_cjs/clients/index.js +6 -0
  13. package/_cjs/clients/index.js.map +1 -0
  14. package/_cjs/clients/pimlico.js +29 -0
  15. package/_cjs/clients/pimlico.js.map +1 -0
  16. package/_cjs/index.js +2 -0
  17. package/_cjs/index.js.map +1 -1
  18. package/_cjs/types/pimlico.js +3 -0
  19. package/_cjs/types/pimlico.js.map +1 -0
  20. package/_cjs/utils/index.js +38 -0
  21. package/_cjs/utils/index.js.map +1 -0
  22. package/_esm/actions/bundler.js +14 -147
  23. package/_esm/actions/bundler.js.map +1 -1
  24. package/_esm/actions/index.js +2 -2
  25. package/_esm/actions/index.js.map +1 -1
  26. package/_esm/actions/pimlico.js +124 -0
  27. package/_esm/actions/pimlico.js.map +1 -0
  28. package/_esm/actions/utils.js +4 -0
  29. package/_esm/actions/utils.js.map +1 -1
  30. package/_esm/clients/bundler.js +32 -0
  31. package/_esm/clients/bundler.js.map +1 -0
  32. package/_esm/clients/index.js +3 -0
  33. package/_esm/clients/index.js.map +1 -0
  34. package/_esm/clients/pimlico.js +62 -0
  35. package/_esm/clients/pimlico.js.map +1 -0
  36. package/_esm/index.js +2 -0
  37. package/_esm/index.js.map +1 -1
  38. package/_esm/types/pimlico.js +2 -0
  39. package/_esm/types/pimlico.js.map +1 -0
  40. package/_esm/utils/index.js +56 -0
  41. package/_esm/utils/index.js.map +1 -0
  42. package/_types/actions/bundler.d.ts +116 -27
  43. package/_types/actions/bundler.d.ts.map +1 -1
  44. package/_types/actions/index.d.ts +4 -2
  45. package/_types/actions/index.d.ts.map +1 -1
  46. package/_types/actions/pimlico.d.ts +178 -0
  47. package/_types/actions/pimlico.d.ts.map +1 -0
  48. package/_types/actions/utils.d.ts +4 -0
  49. package/_types/actions/utils.d.ts.map +1 -1
  50. package/_types/clients/bundler.d.ts +38 -0
  51. package/_types/clients/bundler.d.ts.map +1 -0
  52. package/_types/clients/index.d.ts +3 -0
  53. package/_types/clients/index.d.ts.map +1 -0
  54. package/_types/clients/pimlico.d.ts +73 -0
  55. package/_types/clients/pimlico.d.ts.map +1 -0
  56. package/_types/index.d.ts +2 -0
  57. package/_types/index.d.ts.map +1 -1
  58. package/_types/types/bundler.d.ts +4 -37
  59. package/_types/types/bundler.d.ts.map +1 -1
  60. package/_types/types/index.d.ts +1 -2
  61. package/_types/types/index.d.ts.map +1 -1
  62. package/_types/types/pimlico.d.ts +50 -0
  63. package/_types/types/pimlico.d.ts.map +1 -0
  64. package/_types/types/userOperation.d.ts +1 -0
  65. package/_types/types/userOperation.d.ts.map +1 -1
  66. package/_types/utils/index.d.ts +31 -0
  67. package/_types/utils/index.d.ts.map +1 -0
  68. package/actions/bundler.ts +87 -35
  69. package/actions/index.ts +25 -8
  70. package/actions/pimlico.ts +252 -0
  71. package/actions/utils.ts +5 -0
  72. package/clients/bundler.ts +38 -0
  73. package/clients/index.ts +3 -0
  74. package/clients/pimlico.ts +91 -0
  75. package/index.ts +2 -0
  76. package/package.json +23 -3
  77. package/tsconfig.build.tsbuildinfo +1 -1
  78. package/types/bundler.ts +4 -39
  79. package/types/index.ts +1 -2
  80. package/types/pimlico.ts +55 -0
  81. package/types/userOperation.ts +2 -0
  82. package/utils/index.ts +70 -0
package/types/bundler.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { Account, Address, Chain, Client, Hash, Hex, Transport } from "viem"
1
+ import type { Address, Hash, Hex } from "viem"
2
2
  import type { PartialBy } from "viem/types/utils"
3
3
  import type { UserOperationWithBigIntAsHex } from "./userOperation"
4
4
 
5
- export type BundlerClient = Client<Transport, Chain | undefined, Account | undefined, BundlerRpcSchema>
6
-
7
- type BundlerRpcSchema = [
5
+ export type BundlerRpcSchema = [
8
6
  {
9
7
  Method: "eth_sendUserOperation"
10
8
  Parameters: [userOperation: UserOperationWithBigIntAsHex, entryPoint: Address]
@@ -53,39 +51,6 @@ type BundlerRpcSchema = [
53
51
  }
54
52
  ]
55
53
 
56
- export type UserOperationReceipt = {
57
- userOpHash: Hash
58
- sender: Address
59
- nonce: bigint
60
- actualGasUsed: bigint
61
- actualGasCost: bigint
62
- success: boolean
63
- receipt: {
64
- transactionHash: Hex
65
- transactionIndex: bigint
66
- blockHash: Hash
67
- blockNumber: bigint
68
- from: Address
69
- to: Address | null
70
- cumulativeGasUsed: bigint
71
- status: bigint | null
72
- gasUsed: bigint
73
- contractAddress: Address | null
74
- logsBloom: string
75
- effectiveGasPrice: bigint
76
- }
77
- logs: {
78
- data: Hex
79
- blockNumber: bigint
80
- blockHash: Hash
81
- transactionHash: Hash
82
- logIndex: bigint
83
- transactionIndex: bigint
84
- address: Address
85
- topics: Hex[]
86
- }[]
87
- }
88
-
89
54
  type UserOperationReceiptWithBigIntAsHex = {
90
55
  userOpHash: Hash
91
56
  sender: Address
@@ -101,10 +66,10 @@ type UserOperationReceiptWithBigIntAsHex = {
101
66
  from: Address
102
67
  to: Address | null
103
68
  cumulativeGasUsed: Hex
104
- status: Hex | null
69
+ status: "0x0" | "0x1"
105
70
  gasUsed: Hex
106
71
  contractAddress: Address | null
107
- logsBloom: string
72
+ logsBloom: Hex
108
73
  effectiveGasPrice: Hex
109
74
  }
110
75
  logs: {
package/types/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { UserOperationReceipt } from "./bundler"
2
1
  import type { UserOperation } from "./userOperation"
3
2
 
4
- export type { UserOperationReceipt, UserOperation }
3
+ export type { UserOperation }
@@ -0,0 +1,55 @@
1
+ import type { Address, Hash, Hex } from "viem"
2
+ import type { PartialBy } from "viem/types/utils"
3
+ import type { UserOperationWithBigIntAsHex } from "./userOperation"
4
+
5
+ type PimlicoUserOperationGasPriceWithBigIntAsHex = {
6
+ slow: {
7
+ maxFeePerGas: Hex
8
+ maxPriorityFeePerGas: Hex
9
+ }
10
+ standard: {
11
+ maxFeePerGas: Hex
12
+ maxPriorityFeePerGas: Hex
13
+ }
14
+ fast: {
15
+ maxFeePerGas: Hex
16
+ maxPriorityFeePerGas: Hex
17
+ }
18
+ }
19
+
20
+ export type PimlicoUserOperationStatus = {
21
+ status: "not_found" | "not_submitted" | "submitted" | "rejected" | "reverted" | "included" | "failed"
22
+ transactionHash: Hash | null
23
+ }
24
+
25
+ export type PimlicoBundlerRpcSchema = [
26
+ {
27
+ Method: "pimlico_getUserOperationGasPrice"
28
+ Parameters: []
29
+ ReturnType: PimlicoUserOperationGasPriceWithBigIntAsHex
30
+ },
31
+ {
32
+ Method: "pimlico_getUserOperationStatus"
33
+ Parameters: [hash: Hash]
34
+ ReturnType: PimlicoUserOperationStatus
35
+ }
36
+ ]
37
+
38
+ export type PimlicoPaymasterRpcSchema = [
39
+ {
40
+ Method: "pm_sponsorUserOperation"
41
+ Parameters: [
42
+ userOperation: PartialBy<
43
+ UserOperationWithBigIntAsHex,
44
+ "callGasLimit" | "preVerificationGas" | "verificationGasLimit" | "paymasterAndData"
45
+ >,
46
+ entryPoint: Address
47
+ ]
48
+ ReturnType: {
49
+ paymasterAndData: Hex
50
+ preVerificationGas: Hex
51
+ verificationGasLimit: Hex
52
+ callGasLimit: Hex
53
+ }
54
+ }
55
+ ]
@@ -1,6 +1,8 @@
1
1
  import type { Address } from "abitype"
2
2
  import type { Hex } from "viem"
3
3
 
4
+ export type TStatus = "success" | "reverted"
5
+
4
6
  export type UserOperationWithBigIntAsHex = {
5
7
  sender: Address
6
8
  nonce: Hex
package/utils/index.ts ADDED
@@ -0,0 +1,70 @@
1
+ import type { Address, Hash, Hex } from "viem"
2
+ import { encodeAbiParameters, keccak256 } from "viem"
3
+ import type { UserOperation } from "../types"
4
+
5
+ function packUserOp({ userOperation }: { userOperation: UserOperation }): Hex {
6
+ const hashedInitCode = keccak256(userOperation.initCode)
7
+ const hashedCallData = keccak256(userOperation.callData)
8
+ const hashedPaymasterAndData = keccak256(userOperation.paymasterAndData)
9
+
10
+ return encodeAbiParameters(
11
+ [
12
+ { type: "address" },
13
+ { type: "uint256" },
14
+ { type: "bytes32" },
15
+ { type: "bytes32" },
16
+ { type: "uint256" },
17
+ { type: "uint256" },
18
+ { type: "uint256" },
19
+ { type: "uint256" },
20
+ { type: "uint256" },
21
+ { type: "bytes32" }
22
+ ],
23
+ [
24
+ userOperation.sender as Address,
25
+ userOperation.nonce,
26
+ hashedInitCode,
27
+ hashedCallData,
28
+ userOperation.callGasLimit,
29
+ userOperation.verificationGasLimit,
30
+ userOperation.preVerificationGas,
31
+ userOperation.maxFeePerGas,
32
+ userOperation.maxPriorityFeePerGas,
33
+ hashedPaymasterAndData
34
+ ]
35
+ )
36
+ }
37
+
38
+ export type GetUserOperationHashParams = { userOperation: UserOperation; entryPoint: Address; chainId: number }
39
+
40
+ /**
41
+ *
42
+ * Returns user operation hash that is a unique identifier of the user operation.
43
+ *
44
+ * - Docs: https://docs.pimlico.io/permissionless/reference/utils/getUserOperationHash
45
+ *
46
+ * @param args: userOperation, entryPoint, chainId as {@link GetUserOperationHashParams}
47
+ * @returns userOperationHash as {@link Hash}
48
+ *
49
+ * @example
50
+ * import { getUserOperationHash } from "permissionless/utils"
51
+ *
52
+ * const userOperationHash = getUserOperationHash({
53
+ * userOperation,
54
+ * entryPoint,
55
+ * chainId
56
+ * })
57
+ *
58
+ * // Returns "0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34"
59
+ *
60
+ */
61
+ const getUserOperationHash = ({ userOperation, entryPoint, chainId }: GetUserOperationHashParams): Hash => {
62
+ const encoded = encodeAbiParameters(
63
+ [{ type: "bytes32" }, { type: "address" }, { type: "uint256" }],
64
+ [keccak256(packUserOp({ userOperation })), entryPoint, BigInt(chainId)]
65
+ ) as `0x${string}`
66
+
67
+ return keccak256(encoded)
68
+ }
69
+
70
+ export { getUserOperationHash }