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,17 +1,19 @@
1
- import { type Address, type Chain, type Client, type Hex, type Transport } from "viem";
2
- import { type GetSmartAccountParameter, type SmartAccount } from "viem/account-abstraction";
3
- import { type ModuleType } from "./supportsModule";
4
- export type UninstallModulesParameters<TSmartAccount extends SmartAccount | undefined> = GetSmartAccountParameter<TSmartAccount> & {
5
- modules: [
6
- {
7
- type: ModuleType;
8
- address: Address;
9
- context: Hex;
10
- }
11
- ];
1
+ import type { Address, Chain, Client, Hex, Narrow, Transport } from "viem";
2
+ import { type PaymasterActions, type SmartAccount, type UserOperationCalls } from "viem/account-abstraction";
3
+ import { type EncodeUninstallModuleParameters } from "../../utils/encodeUninstallModule";
4
+ export type UninstallModulesParameters<TSmartAccount extends SmartAccount | undefined, calls extends readonly unknown[] = readonly unknown[]> = EncodeUninstallModuleParameters<TSmartAccount> & {
12
5
  maxFeePerGas?: bigint;
13
6
  maxPriorityFeePerGas?: bigint;
14
7
  nonce?: bigint;
8
+ calls?: UserOperationCalls<Narrow<calls>>;
9
+ paymaster?: Address | true | {
10
+ /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */
11
+ getPaymasterData?: PaymasterActions["getPaymasterData"] | undefined;
12
+ /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */
13
+ getPaymasterStubData?: PaymasterActions["getPaymasterStubData"] | undefined;
14
+ } | undefined;
15
+ /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */
16
+ paymasterContext?: unknown | undefined;
15
17
  };
16
18
  export declare function uninstallModules<TSmartAccount extends SmartAccount | undefined>(client: Client<Transport, Chain | undefined, TSmartAccount>, parameters: UninstallModulesParameters<TSmartAccount>): Promise<Hex>;
17
19
  //# sourceMappingURL=uninstallModules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uninstallModules.d.ts","sourceRoot":"","sources":["../../../actions/erc7579/uninstallModules.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,SAAS,EAGjB,MAAM,MAAM,CAAA;AACb,OAAO,EACH,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAEpB,MAAM,0BAA0B,CAAA;AAIjC,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AAErE,MAAM,MAAM,0BAA0B,CAClC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,OAAO,EAAE;QACL;YACI,IAAI,EAAE,UAAU,CAAA;YAChB,OAAO,EAAE,OAAO,CAAA;YAChB,OAAO,EAAE,GAAG,CAAA;SACf;KACJ,CAAA;IACD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAsB,gBAAgB,CAClC,aAAa,SAAS,YAAY,GAAG,SAAS,EAE9C,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,aAAa,CAAC,EAC3D,UAAU,EAAE,0BAA0B,CAAC,aAAa,CAAC,GACtD,OAAO,CAAC,GAAG,CAAC,CAyDd"}
1
+ {"version":3,"file":"uninstallModules.d.ts","sourceRoot":"","sources":["../../../actions/erc7579/uninstallModules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAC1E,OAAO,EACH,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EAE1B,MAAM,0BAA0B,CAAA;AAIjC,OAAO,EACH,KAAK,+BAA+B,EAEvC,MAAM,mCAAmC,CAAA;AAE1C,MAAM,MAAM,0BAA0B,CAClC,aAAa,SAAS,YAAY,GAAG,SAAS,EAC9C,KAAK,SAAS,SAAS,OAAO,EAAE,GAAG,SAAS,OAAO,EAAE,IACrD,+BAA+B,CAAC,aAAa,CAAC,GAAG;IACjD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACzC,SAAS,CAAC,EACJ,OAAO,GACP,IAAI,GACJ;QACI,uGAAuG;QACvG,gBAAgB,CAAC,EACX,gBAAgB,CAAC,kBAAkB,CAAC,GACpC,SAAS,CAAA;QACf,2FAA2F;QAC3F,oBAAoB,CAAC,EACf,gBAAgB,CAAC,sBAAsB,CAAC,GACxC,SAAS,CAAA;KAClB,GACD,SAAS,CAAA;IACf,wFAAwF;IACxF,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACzC,CAAA;AAED,wBAAsB,gBAAgB,CAClC,aAAa,SAAS,YAAY,GAAG,SAAS,EAE9C,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,aAAa,CAAC,EAC3D,UAAU,EAAE,0BAA0B,CAAC,aAAa,CAAC,GACtD,OAAO,CAAC,GAAG,CAAC,CAuCd"}
@@ -0,0 +1,20 @@
1
+ import { type Address, type Hex, type OneOf } from "viem";
2
+ import type { GetSmartAccountParameter, SmartAccount } from "viem/account-abstraction";
3
+ import { type ModuleType } from "../actions/erc7579/supportsModule";
4
+ export type EncodeInstallModuleParameter = {
5
+ type: ModuleType;
6
+ address: Address;
7
+ } & OneOf<{
8
+ context: Hex;
9
+ } | {
10
+ initData: Hex;
11
+ }>;
12
+ export type EncodeInstallModuleParameters<TSmartAccount extends SmartAccount | undefined> = GetSmartAccountParameter<TSmartAccount> & {
13
+ modules: EncodeInstallModuleParameter[] | EncodeInstallModuleParameter;
14
+ };
15
+ export declare function encodeInstallModule<TSmartAccount extends SmartAccount | undefined>(parameters: EncodeInstallModuleParameters<TSmartAccount>): {
16
+ to: `0x${string}`;
17
+ value: bigint;
18
+ data: `0x${string}`;
19
+ }[];
20
+ //# sourceMappingURL=encodeInstallModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encodeInstallModule.d.ts","sourceRoot":"","sources":["../../utils/encodeInstallModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,KAAK,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACH,KAAK,UAAU,EAElB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,MAAM,4BAA4B,GAAG;IACvC,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACH;IACI,OAAO,EAAE,GAAG,CAAA;CACf,GACD;IACI,QAAQ,EAAE,GAAG,CAAA;CAChB,CACN,CAAA;AAED,MAAM,MAAM,6BAA6B,CACrC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,OAAO,EAAE,4BAA4B,EAAE,GAAG,4BAA4B,CAAA;CACzE,CAAA;AAED,wBAAgB,mBAAmB,CAC/B,aAAa,SAAS,YAAY,GAAG,SAAS,EAChD,UAAU,EAAE,6BAA6B,CAAC,aAAa,CAAC;;;;IA+CzD"}
@@ -0,0 +1,20 @@
1
+ import { type Address, type Hex, type OneOf } from "viem";
2
+ import type { GetSmartAccountParameter, SmartAccount } from "viem/account-abstraction";
3
+ import { type ModuleType } from "../actions/erc7579/supportsModule";
4
+ export type EncodeUninstallModuleParameter = {
5
+ type: ModuleType;
6
+ address: Address;
7
+ } & OneOf<{
8
+ context: Hex;
9
+ } | {
10
+ deInitData: Hex;
11
+ }>;
12
+ export type EncodeUninstallModuleParameters<TSmartAccount extends SmartAccount | undefined> = GetSmartAccountParameter<TSmartAccount> & {
13
+ modules: EncodeUninstallModuleParameter[] | EncodeUninstallModuleParameter;
14
+ };
15
+ export declare function encodeUninstallModule<TSmartAccount extends SmartAccount | undefined>(parameters: EncodeUninstallModuleParameters<TSmartAccount>): {
16
+ to: `0x${string}`;
17
+ value: bigint;
18
+ data: `0x${string}`;
19
+ }[];
20
+ //# sourceMappingURL=encodeUninstallModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encodeUninstallModule.d.ts","sourceRoot":"","sources":["../../utils/encodeUninstallModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,KAAK,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACH,KAAK,UAAU,EAElB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,MAAM,8BAA8B,GAAG;IACzC,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACH;IACI,OAAO,EAAE,GAAG,CAAA;CACf,GACD;IACI,UAAU,EAAE,GAAG,CAAA;CAClB,CACN,CAAA;AAED,MAAM,MAAM,+BAA+B,CACvC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,OAAO,EAAE,8BAA8B,EAAE,GAAG,8BAA8B,CAAA;CAC7E,CAAA;AAED,wBAAgB,qBAAqB,CACjC,aAAa,SAAS,YAAY,GAAG,SAAS,EAChD,UAAU,EAAE,+BAA+B,CAAC,aAAa,CAAC;;;;IA+C3D"}
@@ -5,6 +5,8 @@ import { isSmartAccountDeployed } from "./isSmartAccountDeployed";
5
5
  import { toOwner } from "./toOwner";
6
6
  import { decodeNonce } from "./decodeNonce";
7
7
  import { encodeNonce } from "./encodeNonce";
8
+ import { type EncodeInstallModuleParameters, encodeInstallModule } from "./encodeInstallModule";
8
9
  import { getPackedUserOperation } from "./getPackedUserOperation";
9
- export { transactionReceiptStatus, deepHexlify, getRequiredPrefund, toOwner, type GetRequiredPrefundReturnType, isSmartAccountDeployed, getAddressFromInitCodeOrPaymasterAndData, getPackedUserOperation, encodeNonce, decodeNonce };
10
+ import { type EncodeCallDataParams, encode7579Calls } from "./encode7579Calls";
11
+ export { transactionReceiptStatus, deepHexlify, getRequiredPrefund, toOwner, type GetRequiredPrefundReturnType, isSmartAccountDeployed, getAddressFromInitCodeOrPaymasterAndData, getPackedUserOperation, encodeNonce, decodeNonce, type EncodeInstallModuleParameters, encodeInstallModule, type EncodeCallDataParams, encode7579Calls };
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAA;AACrG,OAAO,EACH,KAAK,4BAA4B,EACjC,kBAAkB,EACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,EACH,wBAAwB,EACxB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,KAAK,4BAA4B,EACjC,sBAAsB,EACtB,wCAAwC,EACxC,sBAAsB,EACtB,WAAW,EACX,WAAW,EACd,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAA;AACrG,OAAO,EACH,KAAK,4BAA4B,EACjC,kBAAkB,EACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EACH,KAAK,6BAA6B,EAClC,mBAAmB,EACtB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,EAAE,KAAK,oBAAoB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,EACH,wBAAwB,EACxB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,KAAK,4BAA4B,EACjC,sBAAsB,EACtB,wCAAwC,EACxC,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,KAAK,6BAA6B,EAClC,mBAAmB,EACnB,KAAK,oBAAoB,EACzB,eAAe,EAClB,CAAA"}
@@ -36,7 +36,7 @@ describe.each(getCoreSmartAccounts())(
36
36
  account: smartClient.account,
37
37
  type: "executor",
38
38
  address: "0xc98B026383885F41d9a995f85FC480E9bb8bB891",
39
- context: name.startsWith("Kernel 7579")
39
+ initData: name.startsWith("Kernel 7579")
40
40
  ? encodePacked(
41
41
  ["address", "bytes"],
42
42
  [
@@ -1,29 +1,50 @@
1
- import {
2
- type Address,
3
- type Client,
4
- type Hex,
5
- encodeFunctionData,
6
- getAddress
7
- } from "viem"
1
+ import type { Address, Client, Hex, Narrow, OneOf } from "viem"
8
2
  import {
9
3
  type GetSmartAccountParameter,
4
+ type PaymasterActions,
10
5
  type SmartAccount,
6
+ type UserOperationCalls,
11
7
  sendUserOperation
12
8
  } from "viem/account-abstraction"
13
9
  import { getAction, parseAccount } from "viem/utils"
14
10
  import { AccountNotFoundError } from "../../errors"
15
- import { type ModuleType, parseModuleTypeId } from "./supportsModule"
11
+ import { encodeInstallModule } from "../../utils"
12
+ import type { ModuleType } from "./supportsModule"
16
13
 
17
14
  export type InstallModuleParameters<
18
- TSmartAccount extends SmartAccount | undefined
15
+ TSmartAccount extends SmartAccount | undefined,
16
+ calls extends readonly unknown[] = readonly unknown[]
19
17
  > = GetSmartAccountParameter<TSmartAccount> & {
20
18
  type: ModuleType
21
19
  address: Address
22
- context: Hex
23
20
  maxFeePerGas?: bigint
24
21
  maxPriorityFeePerGas?: bigint
25
22
  nonce?: bigint
26
- }
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
40
+ } & OneOf<
41
+ | {
42
+ context: Hex
43
+ }
44
+ | {
45
+ initData: Hex
46
+ }
47
+ >
27
48
 
28
49
  export async function installModule<
29
50
  TSmartAccount extends SmartAccount | undefined
@@ -37,7 +58,12 @@ export async function installModule<
37
58
  maxPriorityFeePerGas,
38
59
  nonce,
39
60
  address,
40
- context
61
+ context,
62
+ initData,
63
+ type,
64
+ calls,
65
+ paymaster,
66
+ paymasterContext
41
67
  } = parameters
42
68
 
43
69
  if (!account_) {
@@ -54,41 +80,14 @@ export async function installModule<
54
80
  "sendUserOperation"
55
81
  )({
56
82
  calls: [
57
- {
58
- to: account.address,
59
- value: BigInt(0),
60
- data: encodeFunctionData({
61
- abi: [
62
- {
63
- name: "installModule",
64
- type: "function",
65
- stateMutability: "nonpayable",
66
- inputs: [
67
- {
68
- type: "uint256",
69
- name: "moduleTypeId"
70
- },
71
- {
72
- type: "address",
73
- name: "module"
74
- },
75
- {
76
- type: "bytes",
77
- name: "initData"
78
- }
79
- ],
80
- outputs: []
81
- }
82
- ],
83
- functionName: "installModule",
84
- args: [
85
- parseModuleTypeId(parameters.type),
86
- getAddress(address),
87
- context
88
- ]
89
- })
90
- }
83
+ ...encodeInstallModule({
84
+ account,
85
+ modules: [{ address, context: context ?? initData, type }]
86
+ }),
87
+ ...(calls ?? [])
91
88
  ],
89
+ paymaster,
90
+ paymasterContext,
92
91
  maxFeePerGas,
93
92
  maxPriorityFeePerGas,
94
93
  nonce,
@@ -34,6 +34,13 @@ describe.each(getCoreSmartAccounts())(
34
34
 
35
35
  const opHash = await installModules(smartClient, {
36
36
  account: smartClient.account,
37
+ calls: [
38
+ {
39
+ to: smartClient.account.address,
40
+ value: 0n,
41
+ data: "0x"
42
+ }
43
+ ],
37
44
  modules: [
38
45
  {
39
46
  type: "executor",
@@ -1,32 +1,41 @@
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, parseAccount } from "viem/utils"
16
9
  import { AccountNotFoundError } from "../../errors"
17
- import { type ModuleType, parseModuleTypeId } from "./supportsModule"
10
+ import {
11
+ type EncodeInstallModuleParameters,
12
+ encodeInstallModule
13
+ } from "../../utils/encodeInstallModule"
18
14
 
19
15
  export type InstallModulesParameters<
20
- TSmartAccount extends SmartAccount | undefined
21
- > = GetSmartAccountParameter<TSmartAccount> & {
22
- modules: {
23
- type: ModuleType
24
- address: Address
25
- context: Hex
26
- }[]
16
+ TSmartAccount extends SmartAccount | undefined,
17
+ calls extends readonly unknown[] = readonly unknown[]
18
+ > = EncodeInstallModuleParameters<TSmartAccount> & {
27
19
  maxFeePerGas?: bigint
28
20
  maxPriorityFeePerGas?: bigint
29
21
  nonce?: bigint
22
+ calls?: UserOperationCalls<Narrow<calls>>
23
+ paymaster?:
24
+ | Address
25
+ | true
26
+ | {
27
+ /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */
28
+ getPaymasterData?:
29
+ | PaymasterActions["getPaymasterData"]
30
+ | undefined
31
+ /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */
32
+ getPaymasterStubData?:
33
+ | PaymasterActions["getPaymasterStubData"]
34
+ | undefined
35
+ }
36
+ | undefined
37
+ /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */
38
+ paymasterContext?: unknown | undefined
30
39
  }
31
40
 
32
41
  export async function installModules<
@@ -40,7 +49,10 @@ export async function installModules<
40
49
  maxFeePerGas,
41
50
  maxPriorityFeePerGas,
42
51
  nonce,
43
- modules
52
+ modules,
53
+ paymaster,
54
+ paymasterContext,
55
+ calls
44
56
  } = parameters
45
57
 
46
58
  if (!account_) {
@@ -55,36 +67,15 @@ export async function installModules<
55
67
  sendUserOperation,
56
68
  "sendUserOperation"
57
69
  )({
58
- calls: modules.map(({ type, address, context }) => ({
59
- to: account.address,
60
- value: BigInt(0),
61
- data: encodeFunctionData({
62
- abi: [
63
- {
64
- name: "installModule",
65
- type: "function",
66
- stateMutability: "nonpayable",
67
- inputs: [
68
- {
69
- type: "uint256",
70
- name: "moduleTypeId"
71
- },
72
- {
73
- type: "address",
74
- name: "module"
75
- },
76
- {
77
- type: "bytes",
78
- name: "initData"
79
- }
80
- ],
81
- outputs: []
82
- }
83
- ],
84
- functionName: "installModule",
85
- args: [parseModuleTypeId(type), getAddress(address), context]
86
- })
87
- })),
70
+ calls: [
71
+ ...encodeInstallModule({
72
+ account,
73
+ modules
74
+ }),
75
+ ...(calls ?? [])
76
+ ],
77
+ paymaster,
78
+ paymasterContext,
88
79
  maxFeePerGas,
89
80
  maxPriorityFeePerGas,
90
81
  nonce,
@@ -4,6 +4,7 @@ import {
4
4
  type Client,
5
5
  ContractFunctionExecutionError,
6
6
  type Hex,
7
+ type OneOf,
7
8
  type Transport,
8
9
  decodeFunctionResult,
9
10
  encodeFunctionData,
@@ -23,8 +24,14 @@ export type IsModuleInstalledParameters<
23
24
  > = GetSmartAccountParameter<TSmartAccount> & {
24
25
  type: ModuleType
25
26
  address: Address
26
- context: Hex
27
- }
27
+ } & OneOf<
28
+ | {
29
+ additionalContext: Hex
30
+ }
31
+ | {
32
+ context: Hex
33
+ }
34
+ >
28
35
 
29
36
  export async function isModuleInstalled<
30
37
  TSmartAccount extends SmartAccount | undefined
@@ -32,7 +39,12 @@ export async function isModuleInstalled<
32
39
  client: Client<Transport, Chain | undefined, TSmartAccount>,
33
40
  parameters: IsModuleInstalledParameters<TSmartAccount>
34
41
  ): Promise<boolean> {
35
- const { account: account_ = client.account, address, context } = parameters
42
+ const {
43
+ account: account_ = client.account,
44
+ address,
45
+ context,
46
+ additionalContext
47
+ } = parameters
36
48
 
37
49
  if (!account_) {
38
50
  throw new AccountNotFoundError({
@@ -82,7 +94,7 @@ export async function isModuleInstalled<
82
94
  args: [
83
95
  parseModuleTypeId(parameters.type),
84
96
  getAddress(address),
85
- context
97
+ context ?? additionalContext
86
98
  ],
87
99
  address: account.address
88
100
  })
@@ -104,7 +116,7 @@ export async function isModuleInstalled<
104
116
  args: [
105
117
  parseModuleTypeId(parameters.type),
106
118
  getAddress(address),
107
- context
119
+ context ?? additionalContext
108
120
  ]
109
121
  })
110
122
  })
@@ -1,32 +1,59 @@
1
- import {
2
- type Address,
3
- type Chain,
4
- type Client,
5
- type Hex,
6
- type Transport,
7
- encodeFunctionData,
8
- getAddress
1
+ import type {
2
+ Address,
3
+ Chain,
4
+ Client,
5
+ Hex,
6
+ Narrow,
7
+ OneOf,
8
+ Transport
9
9
  } from "viem"
10
10
  import {
11
11
  type GetSmartAccountParameter,
12
+ type PaymasterActions,
12
13
  type SmartAccount,
14
+ type UserOperationCalls,
13
15
  sendUserOperation
14
16
  } from "viem/account-abstraction"
15
17
  import { getAction } from "viem/utils"
16
18
  import { parseAccount } from "viem/utils"
17
19
  import { AccountNotFoundError } from "../../errors"
18
- import { type ModuleType, parseModuleTypeId } from "./supportsModule"
20
+ import { encodeUninstallModule } from "../../utils/encodeUninstallModule"
21
+ import type { ModuleType } from "./supportsModule"
19
22
 
20
23
  export type UninstallModuleParameters<
21
- TSmartAccount extends SmartAccount | undefined
24
+ TSmartAccount extends SmartAccount | undefined,
25
+ calls extends readonly unknown[] = readonly unknown[]
22
26
  > = GetSmartAccountParameter<TSmartAccount> & {
23
27
  type: ModuleType
24
28
  address: Address
25
- context: Hex
26
29
  maxFeePerGas?: bigint
27
30
  maxPriorityFeePerGas?: bigint
28
31
  nonce?: bigint
29
- }
32
+ calls?: UserOperationCalls<Narrow<calls>>
33
+ paymaster?:
34
+ | Address
35
+ | true
36
+ | {
37
+ /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */
38
+ getPaymasterData?:
39
+ | PaymasterActions["getPaymasterData"]
40
+ | undefined
41
+ /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */
42
+ getPaymasterStubData?:
43
+ | PaymasterActions["getPaymasterStubData"]
44
+ | undefined
45
+ }
46
+ | undefined
47
+ /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */
48
+ paymasterContext?: unknown | undefined
49
+ } & OneOf<
50
+ | {
51
+ deInitData: Hex
52
+ }
53
+ | {
54
+ context: Hex
55
+ }
56
+ >
30
57
 
31
58
  export async function uninstallModule<
32
59
  TSmartAccount extends SmartAccount | undefined
@@ -40,7 +67,12 @@ export async function uninstallModule<
40
67
  maxPriorityFeePerGas,
41
68
  nonce,
42
69
  address,
43
- context
70
+ context,
71
+ deInitData,
72
+ type,
73
+ calls,
74
+ paymaster,
75
+ paymasterContext
44
76
  } = parameters
45
77
 
46
78
  if (!account_) {
@@ -57,41 +89,14 @@ export async function uninstallModule<
57
89
  "sendUserOperation"
58
90
  )({
59
91
  calls: [
60
- {
61
- to: account.address,
62
- value: BigInt(0),
63
- data: encodeFunctionData({
64
- abi: [
65
- {
66
- name: "uninstallModule",
67
- type: "function",
68
- stateMutability: "nonpayable",
69
- inputs: [
70
- {
71
- type: "uint256",
72
- name: "moduleTypeId"
73
- },
74
- {
75
- type: "address",
76
- name: "module"
77
- },
78
- {
79
- type: "bytes",
80
- name: "deInitData"
81
- }
82
- ],
83
- outputs: []
84
- }
85
- ],
86
- functionName: "uninstallModule",
87
- args: [
88
- parseModuleTypeId(parameters.type),
89
- getAddress(address),
90
- context
91
- ]
92
- })
93
- }
92
+ ...encodeUninstallModule({
93
+ account,
94
+ modules: [{ type, address, context: context ?? deInitData }]
95
+ }),
96
+ ...(calls ?? [])
94
97
  ],
98
+ paymaster,
99
+ paymasterContext,
95
100
  maxFeePerGas,
96
101
  maxPriorityFeePerGas,
97
102
  nonce,