Overview
A post-intent hook is a smart contract that executes custom logic when an intent is fulfilled. Common use cases:- Cross-chain bridging: Automatically bridge USDC to another chain
- Token swapping: Convert USDC to another token
- Protocol deposits: Deposit into yield protocols
- Multi-step workflows: Chain multiple actions together
How Hooks Work
Using the Across Bridge Hook
TheAcrossBridgeHook automatically bridges USDC to another chain after fulfillment.
Setting Up Bridge Intent
1
Prepare commitment data
Define destination chain parameters at signaling time:
2
Signal intent with hook
Include the hook address and commitment in your intent:
3
Fulfill with bridge data
At fulfillment, provide just-in-time bridge parameters:
Fallback Behavior
The Across hook gracefully handles failures:Creating Custom Hooks
Hook Interface
Implement theIPostIntentHook interface:
Example: Yield Deposit Hook
Automatically deposit USDC into a yield protocol:Example: Token Swap Hook
Swap USDC to another token via a DEX:Hook Registration
Before use, hooks must be whitelisted in thePostIntentHookRegistry:
Testing Hooks
Best Practices
Exact Consumption
Always consume exactly
_amountNetFees. Orchestrator enforces this.Authorization
Only allow orchestrator to call
execute(). Revert for other callers.Graceful Failures
Handle errors gracefully - consider fallback transfers like AcrossBridge.
Gas Efficiency
Optimize gas usage - takers pay for hook execution.
Security Considerations
Reentrancy Protection
Reentrancy Protection
Hooks are called during
fulfillIntent which has reentrancy guards. Additional protection in hooks is optional but recommended.Allowance Management
Allowance Management
Reset token allowances to 0 after operations to prevent residual allowance exploits.
Balance Checks
Balance Checks
Verify exact token consumption with before/after balance snapshots.
Input Validation
Input Validation
Validate all decoded parameters from
_intent.data and _fulfillIntentData.Next Steps
Testing Guide
Learn how to test your custom hooks
Hook Registry
View the PostIntentHookRegistry contract