Smart contracts for creating custom pricing strategies and onchain actions for Slice products.
Hooks enable dynamic pricing, purchase restrictions, rewards, integration with external protocols and other custom behaviors when products are bought.
src/
├── hooks/ # Reusable hooks with registry support
│ ├── actions/ # Onchain actions (gating, rewards, etc.)
│ ├── pricing/ # Pricing strategies (NFT discounts, VRGDA, etc.)
│ └── pricingActions/ # Combined pricing + action hooks
├── examples/ # Product-specific reference implementations
├── interfaces/ # Core hook interfaces
└── utils/ # Base contracts and utilities
Hooks are built around three main interfaces:
IOnchainAction
: Execute custom logic during purchases (eligibility checks, rewards, etc.)IPricingStrategy
: Calculate dynamic prices for productsIHookRegistry
: Enable reusable hooks across multiple products with frontend integration
Hooks can be:
- Product-specific: Custom smart contracts tailored for individual products. These are integrated using the
custom
onchain action or pricing strategy in Slice. - Registry hooks: Reusable contracts designed to support multiple products. Registries enable automatic integration with Slice clients.
See Hook types for more details.
Here's how hooks integrate into the product purchase flow:
Checkout
│
▼
┌─────────────────────┐
│ Price Fetching │ ← `productPrice` called here
│ (before purchase) │ (IPricingStrategy)
└─────────────────────┘
│
▼
┌─────────────────────┐
│ Purchase Execution │ ← `onProductPurchase` called here
│ (during purchase) │ (IOnchainAction)
└─────────────────────┘
│
▼
┌─────────────────────┐
│ Purchase Complete │
└─────────────────────┘
Pricing Strategies are called during the price fetching phase to calculate price based on buyer and custom logic
Onchain Actions are executed during the purchase transaction to:
- Validate purchase eligibility
- Execute custom logic (gating, minting, rewards, etc.)
Deploy once, use across multiple products with frontend integration:
- Actions: See available onchain actions and implementation guide
- Pricing: See available pricing strategies and implementation guide
- Pricing Actions: See combined pricing + action hooks
Tailored implementations for individual products:
- Examples: See real-world implementations and creation guide
The base contracts in src/utils
are designed to be inherited, providing essential building blocks for developing custom Slice hooks efficiently.
RegistryOnchainAction
: Base for reusable onchain actionsRegistryPricingStrategy
: Base for reusable pricing strategiesRegistryPricingStrategyAction
: Base for reusable pricing + action hooks
OnchainAction
: Base for product-specific onchain actionsPricingStrategy
: Base for product-specific pricing strategiesPricingStrategyAction
: Base for product-specific pricing + action hooks
- For reusable actions: See detailed guides in
/src/hooks/actions
- For reusable pricing strategies: See detailed guides in
/src/hooks/pricing
- For reusable pricing strategy actions: See detailed guides in
/src/hooks/pricingActions
- For product-specific hooks: See implementation examples in
/src/examples/
forge soldeer install # Install dependencies
forge test # Run tests
forge build # Build
Requires Foundry.
To deploy hooks, use the deployment script:
./script/deploy.sh
The script will present you with a list of available contracts to deploy. Select the contract you want to deploy and follow the prompts.
When writing tests for your hooks, inherit from the appropriate base test contract:
RegistryOnchainActionTest
: For testingRegistryOnchainAction
contractsRegistryPricingStrategyTest
: For testingRegistryPricingStrategy
contractsRegistryPricingStrategyActionTest
: For testingRegistryPricingStrategyAction
contractsOnchainActionTest
: For testingOnchainAction
contractsPricingStrategyTest
: For testingPricingStrategy
contractsPricingStrategyActionTest
: For testingPricingStrategyAction
contracts
Inheriting the appropriate test contract for your hook allows you to focus your tests solely on your custom hook logic.
To contribute a new hook to this repository:
- Choose the appropriate hook type based on your needs (registry vs product-specific)
- Implement your hook following the existing patterns in the codebase
- Write comprehensive tests using the appropriate test base contract
- Add documentation explaining your hook's purpose and usage
- Submit a pull request against this repository
Make sure your contribution follows the existing code style and includes proper documentation.