Overview
ThePostIntentHookRegistry is a registry contract that manages a whitelist of authorized post-intent hook contracts. These hooks are executed after an intent is successfully fulfilled, enabling custom logic such as automated bridging, token swaps, or other post-payment actions.
Contract Location: contracts/registries/PostIntentHookRegistry.sol
Purpose
The PostIntentHookRegistry serves several important functions:- Hook Whitelisting: Maintain a list of trusted post-intent hook contracts
- Security Control: Prevent unauthorized or malicious hooks from being executed
- Extensibility: Enable protocol extensions through approved custom logic
- Governance: Allow protocol owners to control which hooks are available
State Variables
whitelistedHooks: Maps hook addresses to their whitelist statushooks: Array of all whitelisted hook addresses
Core Functions
Adding Hooks
_hook: Address of the hook contract to whitelist
- Hook address cannot be zero address
- Hook must not already be whitelisted
- Only callable by owner
PostIntentHookAdded(address indexed hook)
Reference: contracts/registries/PostIntentHookRegistry.sol:32
Removing Hooks
_hook: Address of the hook contract to remove
- Hook must be currently whitelisted
- Only callable by owner
PostIntentHookRemoved(address indexed hook)
Reference: contracts/registries/PostIntentHookRegistry.sol:47
View Functions
Check Hook Status
_hook: Address of the hook contract to check
true if the hook is whitelisted, false otherwise
Reference: contracts/registries/PostIntentHookRegistry.sol:58
Get All Hooks
contracts/registries/PostIntentHookRegistry.sol:62
Integration with Core Contracts
Orchestrator
The Orchestrator contract uses the PostIntentHookRegistry to validate and execute post-intent hooks:contracts/Orchestrator.sol:84
Hook Execution Flow
- User signals intent with an optional post-intent hook address
- Orchestrator validates hook is whitelisted via registry
- After intent fulfillment, orchestrator calls the whitelisted hook
- Hook executes custom logic (e.g., bridge tokens, swap, etc.)
Configuration Updates
Orchestrator can update its registry reference:contracts/Orchestrator.sol:327
Example Post-Intent Hooks
AcrossBridgeHookV2
Automatically bridges tokens to another chain after payment is received:- Whitelisted in the registry
- Called after successful intent fulfillment
- Bridges funds using Across Protocol
contracts/hooks/AcrossBridgeHookV2.sol
Custom Hook Pattern
Post-intent hooks must implement the expected interface:Access Control
Owner-Only Functions
All state-modifying functions require owner privileges:addPostIntentHook(): Add hook to whitelistremovePostIntentHook(): Remove hook from whitelist
Ownable with onlyOwner modifier
View Functions
All query functions are publicly accessible:isWhitelistedHook()getWhitelistedHooks()whitelistedHooks[address](public mapping)
Events
- Monitoring hook whitelist changes
- Off-chain indexing of available hooks
- Audit trails for governance decisions
Usage Patterns
Adding a New Hook
Using Hooks in Intents
Removing Deprecated Hooks
Security Considerations
Hook Validation
- Whitelist Only: Only explicitly approved hooks can be used
- Owner Control: Centralized governance over hook approval
- No Automatic Approval: Hooks must be manually reviewed and added
Hook Security Requirements
Before whitelisting a hook, verify:- Code Audit: Hook contract should be audited for security
- Correct Interface: Implements expected function signatures
- Re-entrancy Protection: Doesn’t create re-entrancy vulnerabilities
- Gas Limits: Doesn’t consume excessive gas
- Fund Safety: Cannot steal or lock user funds
Integration Security
- Validation First: Always check
isWhitelistedHook()before execution - Error Handling: Handle hook failures gracefully
- Event Logging: Track hook executions for monitoring
User Protection
- Users should understand what hooks do before using them
- Hook execution failures should not prevent intent fulfillment
- Hooks cannot access more funds than specified in the intent
Hook Development Guidelines
When developing post-intent hooks:- Stateless Execution: Hooks should be stateless when possible
- Clear Purpose: Each hook should have a specific, well-defined purpose
- Gas Efficiency: Optimize for gas to keep user costs low
- Error Recovery: Handle errors gracefully without reverting the entire transaction
- Documentation: Clearly document hook behavior and parameters
Deployment Strategy
- Initial Deployment: Deploy registry with no hooks
- Add Trusted Hooks: Whitelist audited hook contracts
- Configure Orchestrator: Set registry address in Orchestrator
- Monitor Usage: Track hook usage via events
- Iterate: Add new hooks as protocol evolves
Related Contracts
- Orchestrator - Executes whitelisted hooks after intent fulfillment
- AcrossBridgeHookV2 - Example post-intent hook for cross-chain bridging
- OrchestratorRegistry - Related registry for orchestrator authorization