Exercise Counter Hook

A stateful exercise to Counter Hooks Exercises - Learn how to write a custom hook contract by setting permissions and implementing logic to count various pool actions like swaps and liquidity changes.

1. Hooks Intro
An architectural deep dive into Uniswap v4 Hooks - Learn how external contracts can inject custom logic before and after core pool actions like swaps and liquidity modifications. Discover how the `PoolKey` struct makes the hook's address a fundamental, immutable part of a pool's on-chain identity. Duration: 6min
2. Encode Hook Flags
A technical breakdown of Uniswap v4's Address-Based Permissions - Explore how Uniswap v4 embeds permissions directly into a hook's address using a 14-bit flag system. Learn how to use the `CREATE2` opcode and the `HookMiner` utility to find a valid `salt` for deterministic deployment. Duration: 6min
3. Access msg.sender
A practical guide to accessing msg.sender in Uniswap v4 Hooks - Learn why the `msg.sender` global variable is unreliable for identifying the end-user inside a hook. Discover the secure, two-part pattern using the `sender` parameter to query a trusted router for the originator's address. Duration: 4min
4. Exercise Counter Hook
A stateful exercise to Counter Hooks Exercises - Learn how to write a custom hook contract by setting permissions and implementing logic to count various pool actions like swaps and liquidity changes. Reading Time: 0min
6. Limit Order
A strategic guide to crypto limit orders - Distinguish between price-guaranteed limit orders and execution-guaranteed market swaps. Learn how to set orders to automatically buy low or sell high when your target price is met. Duration: 2min
7. Review Of Liquidity And Ticks
A mechanistic explanation of automated limit orders with Uniswap v4 Hooks - Learn how single-tick concentrated liquidity can function as an on-chain limit order. Discover how the `afterSwap` hook automates liquidity withdrawal for a truly decentralized experience. Duration: 3min
8. Limit Order Algorithm
An algorithmic guide to implementing gas-efficient limit orders with Uniswap v4 hooks - Discover the "slots of buckets" data structure for aggregating and processing thousands of orders with a single, low-cost state change. Learn how this hook-based design avoids expensive loops to create a scalable on-chain order book. Duration: 14min
9. Application Limit Order
A programmatic exercise to Limit Order Exercises - Learn to implement a full-featured limit order hook by managing liquidity in specific tick ranges and using the afterSwap hook to process filled orders. Reading Time: 0min

Course Overview

About the course

What you'll learn

Difference between Uniswap v3 and v4

Uniswap v4 PoolManager

Uniswap v4 Hooks

Uniswap v4 Singleton architecture

Uniswap v4 flash accounting

Uniswap v4 operations

Uniswap v4 lifecycle

How to build a Uniswap v4 swap router

Course Description

Meet your instructors

Tasuku Nakamura

Tasuku Nakamura

Founder at smartcontract.engineer

Smart contract engineer and educator.

Last updated on September 29, 2025