Hooks modules

Overview

Hook modules in the Veive protocol provide additional functionality that can be executed before or after an operation. These modules are not strictly about validation or execution but offer supplementary actions like logging, monitoring, or enforcing additional policies. They add an extra layer of customization to the smart account, allowing users to implement specific behaviors that go beyond basic operations.

Flow

Hook modules are invoked in two main stages:

  1. Pre-Operation Hook: Before the main operation is executed, the pre-operation hook can perform checks or setup tasks. This includes verifying additional conditions, preparing data, or enforcing preliminary policies.

  2. Post-Operation Hook: After the main operation is completed, the post-operation hook can log the operation details, update states, notify external systems, or perform cleanup tasks. This ensures that all relevant information is recorded and any necessary follow-up actions are taken.

These hooks provide a flexible way to manage cross-cutting concerns and ensure comprehensive handling of operations.

Scope

Hook modules can be defined across various scopes, similar to other module types, allowing them to be triggered in specific situations:

  1. Entry Point + Contract ID: Specific hooks for certain methods in particular contracts. For example, a pre-operation hook might enforce a spending limit on a specific token contract.

  2. Entry Point: General hooks for operations involving a specific method, applicable across different contracts. This can include actions like auditing all transfers or ensuring compliance with certain policies.

  3. Any: The broadest scope, where hooks apply to all operations. This is useful for universal actions like logging or applying global security policies.

Multiple hook modules can operate in parallel, providing comprehensive monitoring and additional actions across various stages of an operation.

Examples

  • Spending Limit Hook: A pre-operation hook that checks if a transaction exceeds a predefined spending limit. If the limit is exceeded, the operation is blocked, helping manage budgets and prevent unauthorized expenditures.

  • Notification Hook: A post-operation hook that sends notifications or alerts when certain operations occur. For example, it could notify a user whenever a significant transfer happens from their account.

  • Event Logging Hook: Records all

Last updated