## How Uniswap v4 Subscribers Revolutionize Liquidity Mining Security Uniswap v4 introduces a foundational architectural change called "Subscribers," a feature that fundamentally enhances the security of liquidity incentive programs. To fully grasp its significance, we must first understand how these programs, often called liquidity mining, functioned in Uniswap v3 and the inherent risks they carried. This lesson will compare the old custodial model with the new, non-custodial Subscriber system, illustrating a major leap forward in user asset security. ### The Old Way: Custodial Reward Contracts in Uniswap v3 In decentralized finance, liquidity mining is a common practice where protocols offer additional token rewards to users who provide liquidity to specific trading pools. In Uniswap v3, each liquidity position is a unique Non-Fungible Token (NFT) that represents ownership and control over the underlying assets. To implement a reward program in v3, a protocol would deploy a "Reward Contract." Let's consider an example where a protocol wants to incentivize liquidity for an ABC/XYZ token pair. **The v3 Process and its Critical Flaw:** 1. **User Deposit:** A user wanting to participate would send their ABC and XYZ tokens not to Uniswap, but directly to the third-party Reward Contract. 2. **Contract Adds Liquidity:** The Reward Contract would then take these tokens and interact with Uniswap's `NonfungiblePositionManager` to create a liquidity position. 3. **Custodial NFT Minting:** This is the crucial step. The NFT representing the liquidity position would be minted to and owned by the **Reward Contract**, not the user. The contract took full custody of the user's assets. 4. **Reward Calculation:** The Reward Contract, now holding the NFT, could track the position's performance and calculate the rewards owed to the original depositor. 5. **User Claims Rewards:** The user would periodically interact with the Reward Contract to claim their earned rewards. The primary drawback of this model is the immense security risk. The Reward Contract becomes a single point of failure. Because it owns the NFTs for every single participant, a bug or exploit in this one contract could allow an attacker to drain the underlying liquidity of all its users. Participants were forced to trust the security of a third-party contract with their entire principal investment. ### The New Way: Non-Custodial Rewards with Uniswap v4 Subscribers Uniswap v4's Subscribers feature provides an elegant solution to this security problem by shifting from a custodial model to a non-custodial, notification-based system. It allows reward programs to function without ever taking ownership of a user's assets. Using the same ABC/XYZ Reward Contract example, the process in v4 is fundamentally safer. **The v4 Process with Subscribers:** 1. **User Adds Liquidity:** The user interacts directly with Uniswap v4's `PositionManager` to create their liquidity position. 2. **Non-Custodial NFT Minting:** The `PositionManager` mints the position NFT **directly to the user's wallet.** At every stage, the user retains full ownership and control of their NFT and the underlying liquidity. 3. **User Subscribes:** To participate in the reward program, the user calls a `subscribe` function on the `PositionManager`, specifying their position NFT and the address of the Reward Contract. This action does not transfer ownership; it simply registers the contract as an observer. 4. **Contract Notified:** The `PositionManager` sends a notification to the Reward Contract, informing it that the user's position is now subscribed. The contract receives data, not assets. 5. **Reward Calculation:** The Reward Contract can now track the subscribed position's status based on notifications and accurately calculate rewards. 6. **User Receives Rewards:** The Reward Contract sends earned rewards directly to the user's wallet. The `PositionManager` automatically notifies the subscribed Reward Contract whenever a key event occurs, ensuring the reward calculations remain accurate. These notification triggers include: * When a position is initially subscribed. * When a position's liquidity is increased or decreased. * When the position NFT is transferred to a new owner. * When the position is unsubscribed. ### The Key Advantage: Eliminating the Single Point of Failure The security improvement is profound. The user never relinquishes custody of their liquidity position NFT. The Reward Contract is only granted permission to receive data about the position, not to control it. In this new model, even if the Reward Contract were hacked, the attacker would have no access to the users' underlying funds. The user's principal liquidity remains secure in their own wallet, controlled by their own private key. The worst-case scenario is a disruption in reward distribution, not a catastrophic loss of all deposited assets. The single point of failure is eliminated. By replacing the high-risk custodial model of v3 with a secure, non-custodial notification system, the Subscribers feature marks a significant evolution. It empowers developers to build safer and more sophisticated applications on top of Uniswap, fostering a more robust ecosystem while ensuring users always remain in control of their assets.
Uniswap v4 introduces a foundational architectural change called "Subscribers," a feature that fundamentally enhances the security of liquidity incentive programs. To fully grasp its significance, we must first understand how these programs, often called liquidity mining, functioned in Uniswap v3 and the inherent risks they carried. This lesson will compare the old custodial model with the new, non-custodial Subscriber system, illustrating a major leap forward in user asset security.
In decentralized finance, liquidity mining is a common practice where protocols offer additional token rewards to users who provide liquidity to specific trading pools. In Uniswap v3, each liquidity position is a unique Non-Fungible Token (NFT) that represents ownership and control over the underlying assets.
To implement a reward program in v3, a protocol would deploy a "Reward Contract." Let's consider an example where a protocol wants to incentivize liquidity for an ABC/XYZ token pair.
The v3 Process and its Critical Flaw:
User Deposit: A user wanting to participate would send their ABC and XYZ tokens not to Uniswap, but directly to the third-party Reward Contract.
Contract Adds Liquidity: The Reward Contract would then take these tokens and interact with Uniswap's NonfungiblePositionManager to create a liquidity position.
Custodial NFT Minting: This is the crucial step. The NFT representing the liquidity position would be minted to and owned by the Reward Contract, not the user. The contract took full custody of the user's assets.
Reward Calculation: The Reward Contract, now holding the NFT, could track the position's performance and calculate the rewards owed to the original depositor.
User Claims Rewards: The user would periodically interact with the Reward Contract to claim their earned rewards.
The primary drawback of this model is the immense security risk. The Reward Contract becomes a single point of failure. Because it owns the NFTs for every single participant, a bug or exploit in this one contract could allow an attacker to drain the underlying liquidity of all its users. Participants were forced to trust the security of a third-party contract with their entire principal investment.
Uniswap v4's Subscribers feature provides an elegant solution to this security problem by shifting from a custodial model to a non-custodial, notification-based system. It allows reward programs to function without ever taking ownership of a user's assets.
Using the same ABC/XYZ Reward Contract example, the process in v4 is fundamentally safer.
The v4 Process with Subscribers:
User Adds Liquidity: The user interacts directly with Uniswap v4's PositionManager to create their liquidity position.
Non-Custodial NFT Minting: The PositionManager mints the position NFT directly to the user's wallet. At every stage, the user retains full ownership and control of their NFT and the underlying liquidity.
User Subscribes: To participate in the reward program, the user calls a subscribe function on the PositionManager, specifying their position NFT and the address of the Reward Contract. This action does not transfer ownership; it simply registers the contract as an observer.
Contract Notified: The PositionManager sends a notification to the Reward Contract, informing it that the user's position is now subscribed. The contract receives data, not assets.
Reward Calculation: The Reward Contract can now track the subscribed position's status based on notifications and accurately calculate rewards.
User Receives Rewards: The Reward Contract sends earned rewards directly to the user's wallet.
The PositionManager automatically notifies the subscribed Reward Contract whenever a key event occurs, ensuring the reward calculations remain accurate. These notification triggers include:
When a position is initially subscribed.
When a position's liquidity is increased or decreased.
When the position NFT is transferred to a new owner.
When the position is unsubscribed.
The security improvement is profound. The user never relinquishes custody of their liquidity position NFT. The Reward Contract is only granted permission to receive data about the position, not to control it.
In this new model, even if the Reward Contract were hacked, the attacker would have no access to the users' underlying funds. The user's principal liquidity remains secure in their own wallet, controlled by their own private key. The worst-case scenario is a disruption in reward distribution, not a catastrophic loss of all deposited assets. The single point of failure is eliminated.
By replacing the high-risk custodial model of v3 with a secure, non-custodial notification system, the Subscribers feature marks a significant evolution. It empowers developers to build safer and more sophisticated applications on top of Uniswap, fostering a more robust ecosystem while ensuring users always remain in control of their assets.
A security-focused breakdown to Uniswap v4 Subscribers - Explore the architectural shift from risky custodial reward contracts in v3 to the secure, non-custodial notification system introduced in v4.
Previous lesson
Previous
Next lesson
Next
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 PositionManager
Uniswap v4 Universal Router
Uniswap v4 Singleton architecture and flash accounting
Uniswap v4 operations and lifecycle
Uniswap v4 multihopping and quoting
How to build a Uniswap v4 swap router
How to build a smart contract a liquidation bot executes
Last updated on November 6, 2025
Duration: 6min
Duration: 8min
Duration: 39min
Duration: 35min
Duration: 34min
Duration: 31min
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 PositionManager
Uniswap v4 Universal Router
Uniswap v4 Singleton architecture and flash accounting
Uniswap v4 operations and lifecycle
Uniswap v4 multihopping and quoting
How to build a Uniswap v4 swap router
How to build a smart contract a liquidation bot executes
Last updated on November 6, 2025