permissionless 0.2.3 → 0.2.5

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 (66) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +46 -18
  3. package/_cjs/actions/erc7579/installModule.js +9 -37
  4. package/_cjs/actions/erc7579/installModule.js.map +1 -1
  5. package/_cjs/actions/erc7579/installModules.js +11 -33
  6. package/_cjs/actions/erc7579/installModules.js.map +1 -1
  7. package/_cjs/actions/erc7579/isModuleInstalled.js +3 -3
  8. package/_cjs/actions/erc7579/isModuleInstalled.js.map +1 -1
  9. package/_cjs/actions/erc7579/uninstallModule.js +9 -37
  10. package/_cjs/actions/erc7579/uninstallModule.js.map +1 -1
  11. package/_cjs/actions/erc7579/uninstallModules.js +11 -33
  12. package/_cjs/actions/erc7579/uninstallModules.js.map +1 -1
  13. package/_cjs/clients/createSmartAccountClient.js +1 -0
  14. package/_cjs/clients/createSmartAccountClient.js.map +1 -1
  15. package/_cjs/utils/encodeInstallModule.js +53 -0
  16. package/_cjs/utils/encodeInstallModule.js.map +1 -0
  17. package/_cjs/utils/encodeUninstallModule.js +53 -0
  18. package/_cjs/utils/encodeUninstallModule.js.map +1 -0
  19. package/_cjs/utils/index.js +5 -1
  20. package/_cjs/utils/index.js.map +1 -1
  21. package/_esm/actions/erc7579/installModule.js +9 -37
  22. package/_esm/actions/erc7579/installModule.js.map +1 -1
  23. package/_esm/actions/erc7579/installModules.js +11 -33
  24. package/_esm/actions/erc7579/installModules.js.map +1 -1
  25. package/_esm/actions/erc7579/isModuleInstalled.js +3 -3
  26. package/_esm/actions/erc7579/isModuleInstalled.js.map +1 -1
  27. package/_esm/actions/erc7579/uninstallModule.js +9 -37
  28. package/_esm/actions/erc7579/uninstallModule.js.map +1 -1
  29. package/_esm/actions/erc7579/uninstallModules.js +11 -33
  30. package/_esm/actions/erc7579/uninstallModules.js.map +1 -1
  31. package/_esm/clients/createSmartAccountClient.js +1 -0
  32. package/_esm/clients/createSmartAccountClient.js.map +1 -1
  33. package/_esm/utils/encodeInstallModule.js +49 -0
  34. package/_esm/utils/encodeInstallModule.js.map +1 -0
  35. package/_esm/utils/encodeUninstallModule.js +49 -0
  36. package/_esm/utils/encodeUninstallModule.js.map +1 -0
  37. package/_esm/utils/index.js +3 -1
  38. package/_esm/utils/index.js.map +1 -1
  39. package/_types/actions/erc7579/installModule.d.ts +18 -6
  40. package/_types/actions/erc7579/installModule.d.ts.map +1 -1
  41. package/_types/actions/erc7579/installModules.d.ts +13 -9
  42. package/_types/actions/erc7579/installModules.d.ts.map +1 -1
  43. package/_types/actions/erc7579/isModuleInstalled.d.ts +5 -2
  44. package/_types/actions/erc7579/isModuleInstalled.d.ts.map +1 -1
  45. package/_types/actions/erc7579/uninstallModule.d.ts +18 -6
  46. package/_types/actions/erc7579/uninstallModule.d.ts.map +1 -1
  47. package/_types/actions/erc7579/uninstallModules.d.ts +13 -11
  48. package/_types/actions/erc7579/uninstallModules.d.ts.map +1 -1
  49. package/_types/utils/encodeInstallModule.d.ts +20 -0
  50. package/_types/utils/encodeInstallModule.d.ts.map +1 -0
  51. package/_types/utils/encodeUninstallModule.d.ts +20 -0
  52. package/_types/utils/encodeUninstallModule.d.ts.map +1 -0
  53. package/_types/utils/index.d.ts +3 -1
  54. package/_types/utils/index.d.ts.map +1 -1
  55. package/actions/erc7579/installModule.test.ts +1 -1
  56. package/actions/erc7579/installModule.ts +45 -46
  57. package/actions/erc7579/installModules.test.ts +7 -0
  58. package/actions/erc7579/installModules.ts +40 -49
  59. package/actions/erc7579/isModuleInstalled.ts +17 -5
  60. package/actions/erc7579/uninstallModule.ts +52 -47
  61. package/actions/erc7579/uninstallModules.ts +40 -51
  62. package/clients/createSmartAccountClient.ts +1 -0
  63. package/package.json +1 -1
  64. package/utils/encodeInstallModule.ts +85 -0
  65. package/utils/encodeUninstallModule.ts +85 -0
  66. package/utils/index.ts +11 -1
@@ -1,35 +1,42 @@
1
+ import type { Address, Chain, Client, Hex, Narrow, Transport } from "viem"
1
2
  import {
2
- type Address,
3
- type Chain,
4
- type Client,
5
- type Hex,
6
- type Transport,
7
- encodeFunctionData,
8
- getAddress
9
- } from "viem"
10
- import {
11
- type GetSmartAccountParameter,
3
+ type PaymasterActions,
12
4
  type SmartAccount,
5
+ type UserOperationCalls,
13
6
  sendUserOperation
14
7
  } from "viem/account-abstraction"
15
8
  import { getAction } from "viem/utils"
16
9
  import { parseAccount } from "viem/utils"
17
10
  import { AccountNotFoundError } from "../../errors"
18
- import { type ModuleType, parseModuleTypeId } from "./supportsModule"
11
+ import {
12
+ type EncodeUninstallModuleParameters,
13
+ encodeUninstallModule
14
+ } from "../../utils/encodeUninstallModule"
19
15
 
20
16
  export type UninstallModulesParameters<
21
- TSmartAccount extends SmartAccount | undefined
22
- > = GetSmartAccountParameter<TSmartAccount> & {
23
- modules: [
24
- {
25
- type: ModuleType
26
- address: Address
27
- context: Hex
28
- }
29
- ]
17
+ TSmartAccount extends SmartAccount | undefined,
18
+ calls extends readonly unknown[] = readonly unknown[]
19
+ > = EncodeUninstallModuleParameters<TSmartAccount> & {
30
20
  maxFeePerGas?: bigint
31
21
  maxPriorityFeePerGas?: bigint
32
22
  nonce?: bigint
23
+ calls?: UserOperationCalls<Narrow<calls>>
24
+ paymaster?:
25
+ | Address
26
+ | true
27
+ | {
28
+ /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */
29
+ getPaymasterData?:
30
+ | PaymasterActions["getPaymasterData"]
31
+ | undefined
32
+ /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */
33
+ getPaymasterStubData?:
34
+ | PaymasterActions["getPaymasterStubData"]
35
+ | undefined
36
+ }
37
+ | undefined
38
+ /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */
39
+ paymasterContext?: unknown | undefined
33
40
  }
34
41
 
35
42
  export async function uninstallModules<
@@ -43,7 +50,10 @@ export async function uninstallModules<
43
50
  maxFeePerGas,
44
51
  maxPriorityFeePerGas,
45
52
  nonce,
46
- modules
53
+ modules,
54
+ calls,
55
+ paymaster,
56
+ paymasterContext
47
57
  } = parameters
48
58
 
49
59
  if (!account_) {
@@ -59,36 +69,15 @@ export async function uninstallModules<
59
69
  sendUserOperation,
60
70
  "sendUserOperation"
61
71
  )({
62
- calls: modules.map(({ type, address, context }) => ({
63
- to: account.address,
64
- value: BigInt(0),
65
- data: encodeFunctionData({
66
- abi: [
67
- {
68
- name: "uninstallModule",
69
- type: "function",
70
- stateMutability: "nonpayable",
71
- inputs: [
72
- {
73
- type: "uint256",
74
- name: "moduleTypeId"
75
- },
76
- {
77
- type: "address",
78
- name: "module"
79
- },
80
- {
81
- type: "bytes",
82
- name: "deInitData"
83
- }
84
- ],
85
- outputs: []
86
- }
87
- ],
88
- functionName: "uninstallModule",
89
- args: [parseModuleTypeId(type), getAddress(address), context]
90
- })
91
- })),
72
+ calls: [
73
+ ...encodeUninstallModule({
74
+ account,
75
+ modules
76
+ }),
77
+ ...(calls ?? [])
78
+ ],
79
+ paymaster,
80
+ paymasterContext,
92
81
  maxFeePerGas,
93
82
  maxPriorityFeePerGas,
94
83
  nonce,
@@ -136,6 +136,7 @@ export function createSmartAccountClient(
136
136
 
137
137
  const client = createBundlerClient({
138
138
  ...parameters,
139
+ client: client_,
139
140
  chain: parameters.chain ?? client_?.chain,
140
141
  key,
141
142
  name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permissionless",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "author": "Pimlico",
5
5
  "homepage": "https://docs.pimlico.io/permissionless",
6
6
  "repository": "github:pimlicolabs/permissionless.js",
@@ -0,0 +1,85 @@
1
+ import {
2
+ type Address,
3
+ type Hex,
4
+ type OneOf,
5
+ encodeFunctionData,
6
+ getAddress
7
+ } from "viem"
8
+ import type {
9
+ GetSmartAccountParameter,
10
+ SmartAccount
11
+ } from "viem/account-abstraction"
12
+ import {
13
+ type ModuleType,
14
+ parseModuleTypeId
15
+ } from "../actions/erc7579/supportsModule"
16
+ import { AccountNotFoundError } from "../errors"
17
+
18
+ export type EncodeInstallModuleParameter = {
19
+ type: ModuleType
20
+ address: Address
21
+ } & OneOf<
22
+ | {
23
+ context: Hex
24
+ }
25
+ | {
26
+ initData: Hex
27
+ }
28
+ >
29
+
30
+ export type EncodeInstallModuleParameters<
31
+ TSmartAccount extends SmartAccount | undefined
32
+ > = GetSmartAccountParameter<TSmartAccount> & {
33
+ modules: EncodeInstallModuleParameter[] | EncodeInstallModuleParameter
34
+ }
35
+
36
+ export function encodeInstallModule<
37
+ TSmartAccount extends SmartAccount | undefined
38
+ >(parameters: EncodeInstallModuleParameters<TSmartAccount>) {
39
+ const account = parameters.account as SmartAccount
40
+
41
+ if (!account) {
42
+ throw new AccountNotFoundError({
43
+ docsPath: "/docs/actions/wallet/sendTransaction"
44
+ })
45
+ }
46
+
47
+ const modules = Array.isArray(parameters.modules)
48
+ ? parameters.modules
49
+ : [parameters.modules]
50
+
51
+ return modules.map(({ type, address, context, initData }) => ({
52
+ to: account.address,
53
+ value: BigInt(0),
54
+ data: encodeFunctionData({
55
+ abi: [
56
+ {
57
+ name: "installModule",
58
+ type: "function",
59
+ stateMutability: "nonpayable",
60
+ inputs: [
61
+ {
62
+ type: "uint256",
63
+ name: "moduleTypeId"
64
+ },
65
+ {
66
+ type: "address",
67
+ name: "module"
68
+ },
69
+ {
70
+ type: "bytes",
71
+ name: "initData"
72
+ }
73
+ ],
74
+ outputs: []
75
+ }
76
+ ],
77
+ functionName: "installModule",
78
+ args: [
79
+ parseModuleTypeId(type),
80
+ getAddress(address),
81
+ context ?? initData
82
+ ]
83
+ })
84
+ }))
85
+ }
@@ -0,0 +1,85 @@
1
+ import {
2
+ type Address,
3
+ type Hex,
4
+ type OneOf,
5
+ encodeFunctionData,
6
+ getAddress
7
+ } from "viem"
8
+ import type {
9
+ GetSmartAccountParameter,
10
+ SmartAccount
11
+ } from "viem/account-abstraction"
12
+ import {
13
+ type ModuleType,
14
+ parseModuleTypeId
15
+ } from "../actions/erc7579/supportsModule"
16
+ import { AccountNotFoundError } from "../errors"
17
+
18
+ export type EncodeUninstallModuleParameter = {
19
+ type: ModuleType
20
+ address: Address
21
+ } & OneOf<
22
+ | {
23
+ context: Hex
24
+ }
25
+ | {
26
+ deInitData: Hex
27
+ }
28
+ >
29
+
30
+ export type EncodeUninstallModuleParameters<
31
+ TSmartAccount extends SmartAccount | undefined
32
+ > = GetSmartAccountParameter<TSmartAccount> & {
33
+ modules: EncodeUninstallModuleParameter[] | EncodeUninstallModuleParameter
34
+ }
35
+
36
+ export function encodeUninstallModule<
37
+ TSmartAccount extends SmartAccount | undefined
38
+ >(parameters: EncodeUninstallModuleParameters<TSmartAccount>) {
39
+ const account = parameters.account as SmartAccount
40
+
41
+ if (!account) {
42
+ throw new AccountNotFoundError({
43
+ docsPath: "/docs/actions/wallet/sendTransaction"
44
+ })
45
+ }
46
+
47
+ const modules = Array.isArray(parameters.modules)
48
+ ? parameters.modules
49
+ : [parameters.modules]
50
+
51
+ return modules.map(({ type, address, context, deInitData }) => ({
52
+ to: account.address,
53
+ value: BigInt(0),
54
+ data: encodeFunctionData({
55
+ abi: [
56
+ {
57
+ name: "uninstallModule",
58
+ type: "function",
59
+ stateMutability: "nonpayable",
60
+ inputs: [
61
+ {
62
+ type: "uint256",
63
+ name: "moduleTypeId"
64
+ },
65
+ {
66
+ type: "address",
67
+ name: "module"
68
+ },
69
+ {
70
+ type: "bytes",
71
+ name: "deInitData"
72
+ }
73
+ ],
74
+ outputs: []
75
+ }
76
+ ],
77
+ functionName: "uninstallModule",
78
+ args: [
79
+ parseModuleTypeId(type),
80
+ getAddress(address),
81
+ context ?? deInitData
82
+ ]
83
+ })
84
+ }))
85
+ }
package/utils/index.ts CHANGED
@@ -10,8 +10,14 @@ import { toOwner } from "./toOwner"
10
10
  import { decodeNonce } from "./decodeNonce"
11
11
  import { encodeNonce } from "./encodeNonce"
12
12
 
13
+ import {
14
+ type EncodeInstallModuleParameters,
15
+ encodeInstallModule
16
+ } from "./encodeInstallModule"
13
17
  import { getPackedUserOperation } from "./getPackedUserOperation"
14
18
 
19
+ import { type EncodeCallDataParams, encode7579Calls } from "./encode7579Calls"
20
+
15
21
  export {
16
22
  transactionReceiptStatus,
17
23
  deepHexlify,
@@ -22,5 +28,9 @@ export {
22
28
  getAddressFromInitCodeOrPaymasterAndData,
23
29
  getPackedUserOperation,
24
30
  encodeNonce,
25
- decodeNonce
31
+ decodeNonce,
32
+ type EncodeInstallModuleParameters,
33
+ encodeInstallModule,
34
+ type EncodeCallDataParams,
35
+ encode7579Calls
26
36
  }