Skip to content

Commit

Permalink
Merge pull request #36 from rhinestonewtf/feedback-fixes
Browse files Browse the repository at this point in the history
Feedback fixes
  • Loading branch information
kopy-kat authored Jul 5, 2024
2 parents b0695ca + 28df5b4 commit 2932724
Show file tree
Hide file tree
Showing 63 changed files with 340 additions and 226 deletions.
18 changes: 9 additions & 9 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ The Module SDK allows you to:
- **Interact with** and **use** modules using a simple and consistent API
- Can be used **alongside existing account SDKs** such as [permissionless.js](https://www.npmjs.com/package/permissionless), [Biconomy](https://www.npmjs.com/package/@biconomy/account), [Zerodev](https://www.npmjs.com/package/@zerodevapp/sdk) and many more
- **Use core modules**, such as:
- AutoSavings Executor: Automatically save a percentage of incoming funds
- ColdStorage Hook: Prevent funds from being withdrawn without a timelock
- Deadman Switch Validator: Prevent funds from being locked forever
- Auto Savings: Automatically allocate a set percentage of any incoming token to a target vault
- ColdStorage Hook: Restrict all transactions with a timelock and only allow funds to be sent to a single address
- Deadman Switch: Recover an account after a specified inactive period
- Hook Multiplexer: Combine multiple hooks into one with fine-grained control over when they are called
- MultiFactor Validator: Use multiple validators in combination as a multi-factor authentication system
- Multi Factor: Use multiple validators in combination as a multi-factor authentication system
- Ownable Executor: Allow an account to control a subaccount and pay for its transaction fees
- Ownable Validator: Authenticate on your account with multiple ECDSA keys
- Registry Hook: Query the Module Registry before installing and using modules
- Scheduled Orders Executor: Execute swaps on a specified schedule
- Scheduled Transfers Executor: Transfer funds on a specified schedule
- Social Recovery Validator: Recover your account using a set of guardians
- Scheduled Orders: Execute swaps on a specified schedule
- Scheduled Transfers: Transfer funds on a specified schedule
- Social Recovery: Recover your account using a set of guardians

In-depth documentation is available at [docs.rhinestone.wtf](https://docs.rhinestone.wtf/module-sdk/).

Expand Down Expand Up @@ -56,7 +56,7 @@ import {
getModule,
getAccount,
getClient,
getInstallMultiFactorValidator,
getMultiFactorValidator,
} from '@rhinestone/module-sdk'

// Create a client for the current network
Expand All @@ -72,7 +72,7 @@ const moduleToInstall = getModule({
})

// Or use one of the existing modules
moduleToInstall = getInstallMultiFactorValidator({
moduleToInstall = getMultiFactorValidator({
threshold: 2,
validators: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/account/erc7579-implementation/api/installModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const _installModule = async ({
args: [
BigInt(moduleTypeIds[module.type]),
module.module,
module.data || '0x',
module.initData || '0x',
],
}),
})
Expand Down Expand Up @@ -89,7 +89,7 @@ async function installFallback({
module.module,
encodePacked(
['bytes4', 'bytes1', 'bytes'],
[module.selector!, module.callType!, module.data ?? '0x'],
[module.selector!, module.callType!, module.initData ?? '0x'],
),
],
}),
Expand Down
4 changes: 2 additions & 2 deletions src/account/erc7579-implementation/api/uninstallModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const _uninstallModule = async ({
const isInstalled = await isModuleInstalled({ client, account, module })

if (isInstalled) {
let moduleData = module.data || '0x'
let moduleData = module.initData || '0x'
if (module.type === 'validator' || module.type === 'executor') {
const prev = await getPreviousModule({ client, account, module })
moduleData = encodeAbiParameters(
Expand Down Expand Up @@ -109,7 +109,7 @@ const _uninstallFallback = async ({
module.module,
encodePacked(
['bytes4', 'bytes'],
[module.selector!, module.data ?? '0x'],
[module.selector!, module.initData ?? '0x'],
),
],
}),
Expand Down
6 changes: 3 additions & 3 deletions src/account/kernel/api/installModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ const _installModule = async ({
module.hook!,
encodeAbiParameters(
[{ type: 'bytes' }, { type: 'bytes' }],
[module.data || '0x', '0x'],
[module.initData || '0x', '0x'],
),
],
)
: module.data || '0x',
: module.initData || '0x',
],
}),
})
Expand Down Expand Up @@ -124,7 +124,7 @@ async function installFallback({
[
encodePacked(
['bytes1', 'bytes'],
[module.callType, module.data || '0x'],
[module.callType, module.initData || '0x'],
),
'0x',
],
Expand Down
2 changes: 1 addition & 1 deletion src/account/kernel/api/isModuleInstalled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const _isModuleInstalled = async ({
address: account.address,
abi: parseAbi(accountAbi),
functionName: 'isModuleInstalled',
args: [kernelModuleTypeIds[module.type], module.module, module.data],
args: [kernelModuleTypeIds[module.type], module.module, module.initData],
})) as boolean
}

Expand Down
6 changes: 3 additions & 3 deletions src/account/kernel/api/uninstallModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const _uninstallModule = async ({
args: [
BigInt(kernelModuleTypeIds[module.type]),
module.module,
module.data || '0x',
module.initData || '0x',
],
}),
})
Expand All @@ -79,7 +79,7 @@ const _uninstallFallback = async ({
account,
module: {
...module,
data:
initData:
encodeAbiParameters(
[{ name: 'functionSignature', type: 'bytes4' }],
[module.selector!],
Expand All @@ -99,7 +99,7 @@ const _uninstallFallback = async ({
module.module,
encodePacked(
['bytes4', 'bytes'],
[module.selector!, module.data || '0x'],
[module.selector!, module.initData || '0x'],
),
],
}),
Expand Down
2 changes: 1 addition & 1 deletion src/account/kernel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address, Hex } from 'viem'

export type KernelModule = {
module: Address
data?: Hex
initData?: Hex
additionalContext?: Hex
type: KernelModuleType
hook?: Address
Expand Down
6 changes: 3 additions & 3 deletions src/account/safe/api/installModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ const getModuleCalldata = (module: Module): Hex => {
switch (module.type) {
case 'validator':
case 'executor':
return module.data || '0x'
return module.initData || '0x'
case 'hook':
return encodeAbiParameters(
parseAbiParameters(
'uint8 hookType, bytes4 selector, bytes memory initData',
),
[module.hookType!, module.selector!, module.data || '0x'],
[module.hookType!, module.selector!, module.initData || '0x'],
)
case 'fallback':
return encodeAbiParameters(
parseAbiParameters(
'bytes4 functionSig, bytes1 calltype, bytes memory initData',
),
[module.functionSig!, module.callType!, module.data || '0x'],
[module.functionSig!, module.callType!, module.initData || '0x'],
)
default:
throw new Error(`Unknown module type ${module.type}`)
Expand Down
6 changes: 3 additions & 3 deletions src/account/safe/api/uninstallModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ const getModuleCalldata = (module: Module): Hex => {
switch (module.type) {
case 'validator':
case 'executor':
return module.data || '0x'
return module.initData || '0x'
case 'hook':
return encodeAbiParameters(
parseAbiParameters(
'uint8 hookType, bytes4 selector, bytes memory initData',
),
[module.hookType!, module.selector!, module.data || '0x'],
[module.hookType!, module.selector!, module.initData || '0x'],
)
case 'fallback':
return encodeAbiParameters(
parseAbiParameters('bytes4 functionSig, bytes memory moduleDeInitData'),
[module.functionSig!, module.data || '0x'],
[module.functionSig!, module.initData || '0x'],
)
default:
throw new Error(`Unknown module type ${module.type}`)
Expand Down
4 changes: 3 additions & 1 deletion src/common/queries/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const getInstalledModules = async ({
return responseBody.data.moduleQueries.map((module: any) => module.module)
} else {
throw new Error(
`Error: ${responseBody.errors.map((error: any) => error.message).join(', ')}`,
`Error: ${responseBody.errors
.map((error: any) => error.message)
.join(', ')}`,
)
}
}
4 changes: 3 additions & 1 deletion src/common/queries/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const getRegistryModules = async (): Promise<any> => {
return responseBody.data.moduleRegistrations
} else {
throw new Error(
`Error: ${responseBody.errors.map((error: any) => error.message).join(', ')}`,
`Error: ${responseBody.errors
.map((error: any) => error.message)
.join(', ')}`,
)
}
}
29 changes: 15 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,70 @@ export type { Account, AccountType, Execution, InitialModules } from './account'
export {
getModule,
MULTI_FACTOR_VALIDATOR_ADDRESS,
getInstallMultiFactorValidator,
getMultiFactorValidator,
getSetMFAThresholdAction,
getSetMFAValidatorAction,
getRemoveMFAValidatorAction,
isMFASubValidator,
getMFAValidatorMockSignature,
OWNABLE_VALIDATOR_ADDRESS,
getInstallOwnableValidator,
getOwnableValidator,
getAddOwnableValidatorOwnerAction,
getRemoveOwnableValidatorOwnerAction,
getSetOwnableValidatorThresholdAction,
getOwnableValidatorOwners,
getOwnableValidatorThreshold,
getOwnableValidatorMockSignature,
SCHEDULED_ORDERS_EXECUTER_ADDRESS,
getInstallScheduledOrdersExecutor,
getScheduledOrdersExecutor,
getCreateScheduledOrderAction,
getSwapOrderData,
SCHEDULED_TRANSFERS_EXECUTER_ADDRESS,
getInstallScheduledTransfersExecutor,
getScheduledTransfersExecutor,
getCreateScheduledTransferAction,
getScheduledTransactionData,
getScheduledTransferData,
WEBAUTHN_VALIDATOR_ADDRESS,
getInstallWebAuthnValidator,
getWebAuthnValidator,
getWebauthnValidatorSignature,
getWebauthnValidatorMockSignature,
SOCIAL_RECOVERY_ADDRESS,
getInstallSocialRecoveryValidator,
getSocialRecoveryValidator,
getAddSocialRecoveryGuardianAction,
getSocialRecoveryGuardians,
getRemoveSocialRecoveryGuardianAction,
getSetSocialRecoveryThresholdAction,
getSocialRecoveryMockSignature,
DEADMAN_SWITCH_ADDRESS,
getInstallDeadmanSwitch,
getDeadmanSwitch,
getDeadmanSwitchConfig,
getDeadmanSwitchValidatorMockSignature,
OWNABLE_EXECUTER_ADDRESS,
getInstallOwnableExecuter,
getOwnableExecuter,
getAddOwnableExecutorOwnerAction,
getRemoveOwnableExecutorOwnerAction,
getOwnableExecutorOwners,
getExecuteOnOwnedAccountAction,
getExecuteBatchOnOwnedAccountAction,
AUTO_SAVINGS_ADDRESS,
getInstallAutoSavingsExecutor,
getAutoSavingsExecutor,
getSetAutoSavingConfigAction,
getAutoSavingAccountTokenConfig,
getDeleteAutoSavingConfigAction,
getAutoSaveAction,
getAutoSavingTokens,
REGISTRY_HOOK_ADDRESS,
getInstallRegistryHook,
getRegistryHook,
getSetRegistryAction,
HOOK_MULTI_PLEXER_ADDRESS,
getInstallHookMultiPlexer,
getHookMultiPlexer,
getAddHookAction,
getRemoveHookAction,
getHooks,
HookType,
COLD_STORAGE_HOOK_ADDRESS,
COLD_STORAGE_FLASHLOAN_ADDRESS,
getInstallColdStorageHook,
getInstallAllowedCallbackSenders,
getColdStorageHook,
getAllowedCallbackSenders,
getColdStorageSetWaitPeriodAction,
getRequestTimelockedExecution,
getRequestTimelockedModuleConfigExecution,
Expand Down
9 changes: 6 additions & 3 deletions src/module/api/getModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { SafeHookType } from '../../account/safe/types'

export const getModule = ({
module,
data = '0x',
initData = '0x',
deInitData = '0x',
type,
additionalContext,
hook,
Expand All @@ -14,7 +15,8 @@ export const getModule = ({
hookType,
}: {
module: Address
data?: Hex
initData?: Hex
deInitData?: Hex
type: ModuleType
additionalContext?: Hex

Expand All @@ -32,7 +34,8 @@ export const getModule = ({
}): Module => {
return {
module,
data,
initData,
deInitData,
type,
additionalContext: additionalContext || '0x',
hook,
Expand Down
2 changes: 1 addition & 1 deletion src/module/auto-savings/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { AUTO_SAVINGS_ADDRESS } from './constants'
export { getInstallAutoSavingsExecutor } from './installation'
export { getAutoSavingsExecutor } from './installation'
export {
getSetAutoSavingConfigAction,
getAutoSavingAccountTokenConfig,
Expand Down
5 changes: 3 additions & 2 deletions src/module/auto-savings/installation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type Params = {
hook?: Address
}

export const getInstallAutoSavingsExecutor = ({
export const getAutoSavingsExecutor = ({
tokens,
configs,
hook,
}: Params): Module => {
return {
module: AUTO_SAVINGS_ADDRESS,
data: encodeAbiParameters(
initData: encodeAbiParameters(
[
{ internalType: 'address[]', name: '_tokens', type: 'address[]' },
{
Expand All @@ -39,6 +39,7 @@ export const getInstallAutoSavingsExecutor = ({
],
[tokens, configs],
),
deInitData: '0x',
additionalContext: '0x',
type: 'executor',
hook,
Expand Down
5 changes: 1 addition & 4 deletions src/module/cold-storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ export {
COLD_STORAGE_HOOK_ADDRESS,
COLD_STORAGE_FLASHLOAN_ADDRESS,
} from './constants'
export {
getInstallColdStorageHook,
getInstallAllowedCallbackSenders,
} from './installation'
export { getColdStorageHook, getAllowedCallbackSenders } from './installation'
export {
getColdStorageSetWaitPeriodAction,
getRequestTimelockedExecution,
Expand Down
Loading

0 comments on commit 2932724

Please sign in to comment.