Official SDK for building Gotchipus Hooks - interfaces, base contracts, and utilities.
# npm
npm install @gotchipus/sdk
# yarn
yarn add @gotchipus/sdk
# pnpm
pnpm add @gotchipus/sdk
# Foundry
forge install gotchipus/sdk// SPDX-License-Identifier: MIT
pragma solidity ^0.8.29;
import { IHook } from "@gotchipus/sdk/contracts/interfaces/IHook.sol";
contract MyHook is IHook {
bytes4 private constant HOOK_SUCCESS = 0x378e142e;
function getHookPermissions() external pure override returns (Permissions memory) {
return Permissions({ beforeExecute: true, afterExecute: false });
}
function beforeExecute(HookParams calldata params) external override returns (bytes4) {
// Your custom logic here
require(params.value < 1 ether, "Value too high");
return HOOK_SUCCESS;
}
function afterExecute(HookParams calldata) external pure override returns (bytes4) {
revert("Not implemented");
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.29;
import { BeforeExecuteHook } from "@gotchipus/sdk/contracts/base/BaseHook.sol";
import { IHook } from "@gotchipus/sdk/contracts/interfaces/IHook.sol";
contract MyHook is BeforeExecuteHook {
constructor(address _gotchipus) BeforeExecuteHook(_gotchipus) {}
function _beforeExecute(IHook.HookParams calldata params) internal view override {
// Your custom logic here
require(params.value < 1 ether, "Value too high");
// No need to return - BaseHook handles it
}
}| Contract | Description |
|---|---|
IHook |
Core interface that all hooks must implement |
| Contract | Description |
|---|---|
BaseHook |
Abstract base with safety checks |
BeforeExecuteHook |
For hooks that only run before execution |
AfterExecuteHook |
For hooks that only run after execution |
FullHook |
For hooks that run before and after execution |
| Contract | Description |
|---|---|
HookConstants |
Common constants (HOOK_SUCCESS, etc.) |
HookErrors |
Custom error definitions |
Runs before the account executes a transaction. Use cases:
- Access control / whitelisting
- Spending limits
- Transaction validation
- Rate limiting
contract WhitelistHook is BeforeExecuteHook {
mapping(address => bool) public whitelist;
constructor(address _gotchipus) BeforeExecuteHook(_gotchipus) {}
function _beforeExecute(IHook.HookParams calldata params) internal view override {
require(whitelist[params.to], "Target not whitelisted");
}
}Runs after the account executes a transaction. Use cases:
- Reward distribution
- Event logging
- State updates based on results
contract RewardHook is AfterExecuteHook {
constructor(address _gotchipus) AfterExecuteHook(_gotchipus) {}
function _afterExecute(IHook.HookParams calldata params) internal override {
if (params.success) {
// Distribute rewards
}
}
}Runs both before and after execution. Use cases:
- Comprehensive logging
- Complex state management
- Gas metering
contract LoggerHook is FullHook {
constructor(address _gotchipus) FullHook(_gotchipus) {}
function _beforeExecute(IHook.HookParams calldata params) internal override {
emit ExecutionStarted(params.tokenId, params.to);
}
function _afterExecute(IHook.HookParams calldata params) internal override {
emit ExecutionCompleted(params.tokenId, params.success);
}
}struct HookParams {
uint256 tokenId; // Gotchipus NFT token ID
address account; // ERC6551 token-bound account
address caller; // Transaction initiator
address to; // Target contract/address
uint256 value; // ETH value
bytes4 selector; // Function selector
bytes hookData; // Full calldata
bool success; // Execution result (afterExecute only)
bytes returnData; // Return data (afterExecute only)
}Add to remappings.txt:
@gotchipus/sdk/=node_modules/@gotchipus/sdk/
Or install via forge:
forge install gotchipus/sdkThen add remapping:
@gotchipus/sdk/=lib/sdk/
Works out of the box with npm imports:
import "@gotchipus/sdk/contracts/interfaces/IHook.sol";- Always validate permissions - Ensure your hook's
getHookPermissions()matches implemented functions - Use onlyGotchipus modifier - BaseHook includes this; implement it if using IHook directly
- Handle failures gracefully - Consider what happens if your hook reverts
- Gas limits - Be mindful of gas consumption in hooks
See the examples directory for complete hook implementations:
WhitelistHook- Address whitelistingSpendingLimitHook- Daily spending limitsRewardDistributorHook- Post-execution rewardsExecutionLoggerHook- Comprehensive logging
Contributions are welcome! Please read our Contributing Guide first.
MIT License - see LICENSE for details.