EIPs Explained

ERC-5827 · Stagnant · ERC · 2022-10-22

ERC-5827: Auto-renewable allowance extension

An ERC-20 extension where an allowance refills itself at a fixed rate per second up to a cap, enabling subscriptions and spending limits without unlimited approvals.

What problem does it solve?

ERC-20 allowances are a fixed number. For recurring payments (subscriptions, salaries, regular dollar-cost-averaging buys) that is awkward: either the user re-approves every period, or the dapp asks for a huge or unlimited allowance. Unlimited approvals are a common way users lose funds when a contract is malicious or gets exploited.

ERC-5827 adds renewable allowances: the user approves a maximum amount and a recovery rate. After the spender uses some of it, the allowance climbs back toward the maximum at that rate. This works like a credit or debit limit, such as "at most 100 USDC, regaining 100 USDC every 30 days".

How it works

  • approveRenewable(spender, value, recoveryRate) sets both the initial allowance and the cap to value; recoveryRate is tokens per second. It should revert if recoveryRate > value and must emit RenewableApproval(owner, spender, value, recoveryRate).
  • renewableAllowance(owner, spender) returns the cap and the recovery rate.
  • allowance(owner, spender) is overridden to return what is spendable right now: the remaining amount plus whatever has recovered since the last spend, never above the cap.
  • transferFrom deducts from that recovered amount and should revert with InsufficientRenewableAllowance(available) if it is too small.
  • A plain approve still works and sets the recovery rate to 0 (a normal, non-renewing allowance).
  • supportsInterface(0x93cd7af6) must return true.

Optional add-ons: IERC5827Proxy lets an existing ERC-20 delegate allowance enforcement to a proxy contract, and IERC5827Expirable adds an expiry timestamp to a renewable approval.

Sample code

Core recovery logic and a client call (ethers v6):

struct Renewable { uint256 maxAmount; uint256 recoveryRate; uint256 remaining; uint64 lastUpdated; }
mapping(address => mapping(address => Renewable)) internal _rAllowance;

function allowance(address owner, address spender) public view returns (uint256) {
    Renewable memory a = _rAllowance[owner][spender];
    uint256 recovered = a.recoveryRate * (block.timestamp - a.lastUpdated);
    uint256 total = a.remaining + recovered;
    return total > a.maxAmount ? a.maxAmount : total;
}

function _spendAllowance(address owner, address spender, uint256 amount) internal {
    uint256 available = allowance(owner, spender);
    if (available < amount) revert InsufficientRenewableAllowance(available);
    Renewable storage a = _rAllowance[owner][spender];
    a.remaining = available - amount;
    a.lastUpdated = uint64(block.timestamp);
}
import { parseUnits } from "ethers";

// Allow a subscription contract to pull up to 100 tokens, refilling over 30 days
const cap = parseUnits("100", 18);
const perSecond = cap / BigInt(30 * 24 * 60 * 60);
await token.approveRenewable(subscriptionContract, cap, perSecond);

Things to know

  • Status: Stagnant. Few tokens implement it natively; the proxy variant is the practical route for existing tokens.
  • Recovery is continuous, not in discrete cycles. If the per-second rate is high, a spender can still drain a lot over many transactions.
  • Tools that don't know about ERC-5827 may read allowance() or Approval events as the most the spender can ever take. With a renewable allowance the spender can take more over time.
  • Related ideas: ERC-2612 (signed approvals) and ERC-7674 (temporary, single-transaction approvals).

#erc20 #allowance #subscription #payments #extension

Details

Authors
zlace (@zlace0x), zhongfu (@zhongfu), edison0xyz (@edison0xyz)
Status
Stagnant
Type
Standards Track / ERC
Created
2022-10-22
Requires

Machine-readable: Markdown · JSON