Skip to content

Commit

Permalink
fix: parameter defauls for safe module encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Oct 9, 2024
1 parent f089bd2 commit e7631ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/account/safe/api/encodeModuleInstallationData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Account } from '../../types'
import { Hex, encodeAbiParameters, parseAbiParameters } from 'viem'
import { Module } from '../../../module/types'
import { CallType, Module } from '../../../module/types'
import { SafeHookType } from '../types'

export const encodeModuleInstallationData = ({
account,
Expand All @@ -18,14 +19,22 @@ export const encodeModuleInstallationData = ({
parseAbiParameters(
'uint8 hookType, bytes4 selector, bytes memory initData',
),
[module.hookType!, module.selector!, module.initData || '0x'],
[
module.hookType ?? SafeHookType.GLOBAL,
module.hookType == SafeHookType.SIG ? module.selector! : '0x00000000',
module.initData,
],
)
case 'fallback':
return encodeAbiParameters(
parseAbiParameters(
'bytes4 functionSig, bytes1 calltype, bytes memory initData',
),
[module.functionSig!, module.callType!, module.initData || '0x'],
[
module.functionSig!,
module.callType ?? CallType.CALLTYPE_SINGLE,
module.initData,
],
)
default:
throw new Error(`Unknown module type ${module.type}`)
Expand Down
7 changes: 6 additions & 1 deletion src/account/safe/api/encodeModuleUninstallationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from 'viem'
import { Module } from '../../../module/types'
import { getPreviousModule } from '../../../common'
import { SafeHookType } from '../types'

export const encodeModuleUninstallationData = async ({
client,
Expand All @@ -33,7 +34,11 @@ export const encodeModuleUninstallationData = async ({
parseAbiParameters(
'uint8 hookType, bytes4 selector, bytes memory deInitData',
),
[module.hookType!, module.selector!, module.deInitData],
[
module.hookType ?? SafeHookType.GLOBAL,
module.hookType == SafeHookType.SIG ? module.selector! : '0x00000000',
module.deInitData,
],
)

case 'fallback':
Expand Down

0 comments on commit e7631ab

Please sign in to comment.