Overview
Hooks are smart contracts that extend your Gotchipus’s behavior. This guide walks you through building, deploying, and attaching a custom Hook.Prerequisites
- Solidity development experience
- Foundry installed (
forge,cast) - Familiarity with the Hooks concept
Step 1: Choose Your Hook Type
TheBaseHook contract provides three specialized base contracts:
| Base Contract | Supports |
|---|---|
BeforeExecuteHook | Only beforeExecute events |
AfterExecuteHook | Only afterExecute events |
FullHook | Both beforeExecute and afterExecute |
Step 2: Write Your Hook
Hook Parameters
Every Hook receives aHookParams struct:
| Field | Type | Description |
|---|---|---|
tokenId | uint256 | The Gotchipus NFT token ID |
account | address | The Gotchipus’s TBA address |
caller | address | Who initiated the execution |
target | address | Target contract being called |
value | uint256 | Native token value being sent |
selector | bytes4 | Function selector being called |
hookAddress | address | This Hook’s own address |
Return Value
Hooks must returnHOOK_SUCCESS (bytes4) to indicate successful execution. Returning any other value or reverting will cause the execution to fail.
Step 3: Deploy
Step 4: Attach to a Gotchipus
Once deployed, attach your Hook via theHooksFacet:
Step 5: Test
Write Foundry tests to verify your Hook behaves correctly:Constraints
- Maximum 10 Hooks per event per Gotchipus
- Hooks must be valid contracts implementing the correct interface
- The
onlyGotchipusmodifier ensures Hooks can only be called by the Diamond - Hooks should be gas-efficient — excessive gas usage impacts execution cost
Example Hooks
The codebase includes two reference implementations:| Hook | File | Behavior |
|---|---|---|
| RewardHook | src/hooks/examples/RewardHook.sol | Distributes rewards after successful executions |
| WhitelistHook | src/hooks/examples/WhitelistHook.sol | Restricts execution to whitelisted target addresses |