Building and Updating a Decentralized Payment Streaming System (DPSS) – ERC20 Token Support and More

In the world of decentralized finance (DeFi), payment streams are becoming an increasingly popular way to facilitate ongoing, automatic payments. But how do we ensure that users can send and receive payments over time without losing control? That’s where the Decentralized Payment Streaming System (DPSS) comes into play. In this post, I’ll walk you through an update to my DPSS contract, transforming it from a simple ETH-only stream to a more versatile, secure, and feature-rich version that supports both ETH and ERC20 tokens. What's Changed in DPSS2? After building the initial DPSS1 contract, I realized that there were a few key features that could enhance its functionality, especially for tokenized payments in the DeFi space. Here’s what’s new in DPSS2: ERC20 Token Support The most important update is the support for ERC20 tokens. Initially, the system was limited to ETH. Now, it supports both ETH and any ERC20 token, giving users more flexibility in how they fund and receive payment streams. This update uses OpenZeppelin’s SafeERC20 library to ensure that token transfers are safe and efficient. Pause and Resume Streams Users can now pause and resume payment streams. This is useful in scenarios where the payer or recipient may need to temporarily halt payments but plan to resume later. This gives more control and flexibility over payment schedules, which is vital for long-term DeFi projects. Extend Stream Duration Another important update is the ability to extend the duration of an existing stream. If the payer wants to continue the stream beyond the initial duration, they can fund the stream again, which will extend its duration based on the additional funds sent. More Detailed Error Handling Error messages have been improved, making it easier to understand why a stream might have failed or what needs to be done to resolve the issue. How Does DPSS2 Work? The contract creates a payment stream that allows a payer to send funds to a recipient over a specified duration. Payments are released gradually based on a calculated rate. Here’s a simplified version of the logic: The payer sends a certain amount of tokens (ETH or ERC20) to the contract, specifying the recipient and the duration of the stream. The contract calculates the rate at which funds will be released (amount / duration). The recipient can withdraw funds periodically based on the rate, and they can even pause the stream when needed. Security Considerations When working with DeFi contracts, security is a top priority. Some of the security features in DPSS2 include: Reentrancy Guard: To prevent reentrancy attacks, the contract uses OpenZeppelin’s ReentrancyGuard to ensure that functions like withdraw() can’t be exploited. SafeERC20: By using SafeERC20, token transfers are made safe by handling potential pitfalls in ERC20 implementations. Why DPSS2 Matters The new DPSS2 contract brings enhanced flexibility and security to DeFi payments, enabling projects to build more complex payment structures with ERC20 tokens, stream extensions, and pause/resume functionality. I believe this update provides the necessary tools for decentralized payment systems to handle more sophisticated use cases, especially in the world of long-term subscriptions, payments, and investments. Check Out the Full Code If you want to dive deeper into the code, I’ve uploaded the full DPSS2 contract on GitHub. You can fork, modify, and improve it for your own projects.

Apr 29, 2025 - 17:35
 0
Building and Updating a Decentralized Payment Streaming System (DPSS) – ERC20 Token Support and More

In the world of decentralized finance (DeFi), payment streams are becoming an increasingly popular way to facilitate ongoing, automatic payments. But how do we ensure that users can send and receive payments over time without losing control? That’s where the Decentralized Payment Streaming System (DPSS) comes into play.

In this post, I’ll walk you through an update to my DPSS contract, transforming it from a simple ETH-only stream to a more versatile, secure, and feature-rich version that supports both ETH and ERC20 tokens.

What's Changed in DPSS2?
After building the initial DPSS1 contract, I realized that there were a few key features that could enhance its functionality, especially for tokenized payments in the DeFi space. Here’s what’s new in DPSS2:

ERC20 Token Support

The most important update is the support for ERC20 tokens. Initially, the system was limited to ETH. Now, it supports both ETH and any ERC20 token, giving users more flexibility in how they fund and receive payment streams.

This update uses OpenZeppelin’s SafeERC20 library to ensure that token transfers are safe and efficient.

Pause and Resume Streams

Users can now pause and resume payment streams. This is useful in scenarios where the payer or recipient may need to temporarily halt payments but plan to resume later.

This gives more control and flexibility over payment schedules, which is vital for long-term DeFi projects.

Extend Stream Duration

Another important update is the ability to extend the duration of an existing stream. If the payer wants to continue the stream beyond the initial duration, they can fund the stream again, which will extend its duration based on the additional funds sent.

More Detailed Error Handling

Error messages have been improved, making it easier to understand why a stream might have failed or what needs to be done to resolve the issue.

How Does DPSS2 Work?
The contract creates a payment stream that allows a payer to send funds to a recipient over a specified duration. Payments are released gradually based on a calculated rate.

Here’s a simplified version of the logic:

The payer sends a certain amount of tokens (ETH or ERC20) to the contract, specifying the recipient and the duration of the stream.

The contract calculates the rate at which funds will be released (amount / duration).

The recipient can withdraw funds periodically based on the rate, and they can even pause the stream when needed.

Security Considerations
When working with DeFi contracts, security is a top priority. Some of the security features in DPSS2 include:

Reentrancy Guard: To prevent reentrancy attacks, the contract uses OpenZeppelin’s ReentrancyGuard to ensure that functions like withdraw() can’t be exploited.

SafeERC20: By using SafeERC20, token transfers are made safe by handling potential pitfalls in ERC20 implementations.

Why DPSS2 Matters
The new DPSS2 contract brings enhanced flexibility and security to DeFi payments, enabling projects to build more complex payment structures with ERC20 tokens, stream extensions, and pause/resume functionality.

I believe this update provides the necessary tools for decentralized payment systems to handle more sophisticated use cases, especially in the world of long-term subscriptions, payments, and investments.

Check Out the Full Code
If you want to dive deeper into the code, I’ve uploaded the full DPSS2 contract on GitHub. You can fork, modify, and improve it for your own projects.