Subscriptions in web3 have been a tricky problem to solve. Existing solutions like streaming ERC20 tokens have their flaws. For instance, they require upfront token approval, which opens the door for potential abuse. Imagine a streaming protocol withdrawing all approved ERC20 tokens! One workaround is to approve small amounts, but that means users have to keep approving multiple times to maintain their subscriptions.
We can solve this issue by upgrading ERC20 tokens with timebound approvals.
Concept
The lack of time-bound restrictions in ERC20 token approvals allows dApps to withdraw all approved tokens in one go, posing security risks. Instead of enabling dApp to withdraw all approved tokens at a single time, dApps will be able to withdraw only certain amount of token between certain intervals. So now, that user will approve 1 token at interval of every 30 days for 6 months, dApp can withdraw that 1 token anytime in those 30 days, if they fail to withdraw those tokens, it will be carried forward in the next interval. This way, users can be certain that they are paying only for what they are using and that dApps can’t defraud them
Interface
interface IERC20 {
struct Recurring {
uint256 allowedAmount;
uint256 timePeriod;
uint256 timeLimit;
uint256 nextInterval;
}
mapping(address => mapping(address => Recurring)) public recurringAllowance;
function recurringApprove(
address spender,
uint256 amount,
uint256 timePeriod,
uint256 timeLimit
) public virtual returns (bool);
function transferFromRecurring(
address from,
address to,
uint256 amount
) public virtual returns (bool);
}
Would love to get opinions from Ethereum Magicians community
Reference Implementation - Github