Skip to content

Commit

Permalink
Merge pull request rhinestonewtf#97 from rhinestonewtf/feat/kernel-hook
Browse files Browse the repository at this point in the history
feat: make kernel hook optional
  • Loading branch information
kopy-kat authored Oct 30, 2024
2 parents 3cb6308 + 3de44ea commit d6cb333
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/account/kernel/api/encodeModuleInstallationData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Account } from '../../types'
import { Hex, encodePacked, encodeAbiParameters } from 'viem'
import { Hex, encodePacked, encodeAbiParameters, zeroAddress } from 'viem'
import { KernelModule } from '../types'

export const encodeModuleInstallationData = ({
Expand All @@ -15,7 +15,7 @@ export const encodeModuleInstallationData = ({
return encodePacked(
['address', 'bytes'],
[
module.hook!,
module.hook ?? zeroAddress,
encodeAbiParameters(
[{ type: 'bytes' }, { type: 'bytes' }],
[module.initData, '0x'],
Expand All @@ -29,7 +29,7 @@ export const encodeModuleInstallationData = ({
['bytes4', 'address', 'bytes'],
[
module.selector!,
module.hook!,
module.hook ?? zeroAddress,
encodeAbiParameters(
[{ type: 'bytes' }, { type: 'bytes' }],
[
Expand Down
11 changes: 4 additions & 7 deletions src/account/kernel/api/installModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
encodeFunctionData,
encodePacked,
parseAbi,
zeroAddress,
} from 'viem'
import { isModuleInstalled } from './isModuleInstalled'
import { accountAbi } from '../constants/abis'
Expand Down Expand Up @@ -48,10 +49,6 @@ const _installModule = async ({
const executions: Execution[] = []
const isInstalled = await isModuleInstalled({ client, account, module })

if (withHook && !module.hook) {
throw new Error(`Hook is required for module type ${module.type}`)
}

if (!isInstalled) {
const data = encodeFunctionData({
functionName: 'installModule',
Expand All @@ -63,7 +60,7 @@ const _installModule = async ({
? encodePacked(
['address', 'bytes'],
[
module.hook!,
module.hook ?? zeroAddress,
encodeAbiParameters(
[{ type: 'bytes' }, { type: 'bytes' }],
[module.initData || '0x', '0x'],
Expand Down Expand Up @@ -94,7 +91,7 @@ async function installFallback({
account: Account
module: KernelModule
}): Promise<Execution[]> {
if (!module.hook || !module.selector || !module.callType) {
if (!module.selector || !module.callType) {
throw new Error(
`Hook, selector and callType are required for module type ${module.type}`,
)
Expand All @@ -119,7 +116,7 @@ async function installFallback({
['bytes4', 'address', 'bytes'],
[
module.selector,
module.hook,
module.hook ?? zeroAddress,
encodeAbiParameters(
[{ type: 'bytes' }, { type: 'bytes' }],
[
Expand Down

0 comments on commit d6cb333

Please sign in to comment.