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.
- package/CHANGELOG.md +14 -0
- package/README.md +46 -18
- package/_cjs/actions/erc7579/installModule.js +9 -37
- package/_cjs/actions/erc7579/installModule.js.map +1 -1
- package/_cjs/actions/erc7579/installModules.js +11 -33
- package/_cjs/actions/erc7579/installModules.js.map +1 -1
- package/_cjs/actions/erc7579/isModuleInstalled.js +3 -3
- package/_cjs/actions/erc7579/isModuleInstalled.js.map +1 -1
- package/_cjs/actions/erc7579/uninstallModule.js +9 -37
- package/_cjs/actions/erc7579/uninstallModule.js.map +1 -1
- package/_cjs/actions/erc7579/uninstallModules.js +11 -33
- package/_cjs/actions/erc7579/uninstallModules.js.map +1 -1
- package/_cjs/clients/createSmartAccountClient.js +1 -0
- package/_cjs/clients/createSmartAccountClient.js.map +1 -1
- package/_cjs/utils/encodeInstallModule.js +53 -0
- package/_cjs/utils/encodeInstallModule.js.map +1 -0
- package/_cjs/utils/encodeUninstallModule.js +53 -0
- package/_cjs/utils/encodeUninstallModule.js.map +1 -0
- package/_cjs/utils/index.js +5 -1
- package/_cjs/utils/index.js.map +1 -1
- package/_esm/actions/erc7579/installModule.js +9 -37
- package/_esm/actions/erc7579/installModule.js.map +1 -1
- package/_esm/actions/erc7579/installModules.js +11 -33
- package/_esm/actions/erc7579/installModules.js.map +1 -1
- package/_esm/actions/erc7579/isModuleInstalled.js +3 -3
- package/_esm/actions/erc7579/isModuleInstalled.js.map +1 -1
- package/_esm/actions/erc7579/uninstallModule.js +9 -37
- package/_esm/actions/erc7579/uninstallModule.js.map +1 -1
- package/_esm/actions/erc7579/uninstallModules.js +11 -33
- package/_esm/actions/erc7579/uninstallModules.js.map +1 -1
- package/_esm/clients/createSmartAccountClient.js +1 -0
- package/_esm/clients/createSmartAccountClient.js.map +1 -1
- package/_esm/utils/encodeInstallModule.js +49 -0
- package/_esm/utils/encodeInstallModule.js.map +1 -0
- package/_esm/utils/encodeUninstallModule.js +49 -0
- package/_esm/utils/encodeUninstallModule.js.map +1 -0
- package/_esm/utils/index.js +3 -1
- package/_esm/utils/index.js.map +1 -1
- package/_types/actions/erc7579/installModule.d.ts +18 -6
- package/_types/actions/erc7579/installModule.d.ts.map +1 -1
- package/_types/actions/erc7579/installModules.d.ts +13 -9
- package/_types/actions/erc7579/installModules.d.ts.map +1 -1
- package/_types/actions/erc7579/isModuleInstalled.d.ts +5 -2
- package/_types/actions/erc7579/isModuleInstalled.d.ts.map +1 -1
- package/_types/actions/erc7579/uninstallModule.d.ts +18 -6
- package/_types/actions/erc7579/uninstallModule.d.ts.map +1 -1
- package/_types/actions/erc7579/uninstallModules.d.ts +13 -11
- package/_types/actions/erc7579/uninstallModules.d.ts.map +1 -1
- package/_types/utils/encodeInstallModule.d.ts +20 -0
- package/_types/utils/encodeInstallModule.d.ts.map +1 -0
- package/_types/utils/encodeUninstallModule.d.ts +20 -0
- package/_types/utils/encodeUninstallModule.d.ts.map +1 -0
- package/_types/utils/index.d.ts +3 -1
- package/_types/utils/index.d.ts.map +1 -1
- package/actions/erc7579/installModule.test.ts +1 -1
- package/actions/erc7579/installModule.ts +45 -46
- package/actions/erc7579/installModules.test.ts +7 -0
- package/actions/erc7579/installModules.ts +40 -49
- package/actions/erc7579/isModuleInstalled.ts +17 -5
- package/actions/erc7579/uninstallModule.ts +52 -47
- package/actions/erc7579/uninstallModules.ts +40 -51
- package/clients/createSmartAccountClient.ts +1 -0
- package/package.json +1 -1
- package/utils/encodeInstallModule.ts +85 -0
- package/utils/encodeUninstallModule.ts +85 -0
- 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
|
|
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 {
|
|
11
|
+
import {
|
|
12
|
+
type EncodeUninstallModuleParameters,
|
|
13
|
+
encodeUninstallModule
|
|
14
|
+
} from "../../utils/encodeUninstallModule"
|
|
19
15
|
|
|
20
16
|
export type UninstallModulesParameters<
|
|
21
|
-
TSmartAccount extends SmartAccount | undefined
|
|
22
|
-
|
|
23
|
-
|
|
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:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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,
|
package/package.json
CHANGED
|
@@ -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
|
}
|