Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP-5827: Auto-renewable allowance extension #5827

Merged
merged 32 commits into from
Nov 16, 2022
Merged
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
df240f7
feat: add EIP-5824
zlace0x Oct 25, 2022
90f93c5
chore: update title
zlace0x Oct 25, 2022
12e94b2
chore: update links
zlace0x Oct 25, 2022
e1f76cf
fix: EIP number, relative links
zlace0x Oct 25, 2022
2416d98
fix: added renamed file
zlace0x Oct 25, 2022
4562bb0
fix: add EIP-20 reference
zlace0x Oct 25, 2022
324131c
Apply suggestions from code review
zlace0x Oct 25, 2022
ad0e6af
feat: keep interface optionally separated from EIP-20
zlace0x Oct 25, 2022
e34f13d
Apply suggestions from code review
zlace0x Oct 26, 2022
961610d
feat: add optional interfaces
zlace0x Oct 27, 2022
4a1cf7c
refactor: renamed event and approve functions
zlace0x Oct 27, 2022
f08a8ee
refactor: added more functions to ERC165 hash
zlace0x Oct 27, 2022
98ea468
refactor: comment styles
zlace0x Oct 27, 2022
bd06f37
fix: added expiration to query function
zlace0x Oct 28, 2022
bf4b6ed
feat: change recoveryRate to uint256
zlace0x Oct 28, 2022
0182646
feat: added ERC165 hashes
zlace0x Oct 28, 2022
31bf394
Merge pull request #3 from zlace0x/feat/uint256-recovery
zlace0x Oct 28, 2022
d66419f
Merge pull request #2 from zlace0x/feat/refactor-rename
zlace0x Oct 28, 2022
5e26de2
Merge remote-tracking branch 'upstream/master'
zlace0x Oct 28, 2022
d9ead5b
fix: trailing space, added requirement
zlace0x Oct 28, 2022
4ae57a1
feat: added insufficient allowance error, clarified transfer event
zlace0x Nov 1, 2022
a997a97
fix: linter
zlace0x Nov 1, 2022
dda0a39
fix: replace fancy double-quotes with u+22
zhongfu Nov 3, 2022
4ecfaae
fix: prose style
zhongfu Nov 3, 2022
7c2d6c3
fix: fix natspec docs in interfaces
zhongfu Nov 3, 2022
26f9138
feat: add new security consideration about non-EIP-5827-aware apps
zhongfu Nov 3, 2022
e9b7a7f
fix: specify that the extensions should extend IERC5827 too
zhongfu Nov 3, 2022
2f1990f
fix: clarify possibly awkward expression
zhongfu Nov 3, 2022
9d10067
Merge pull request #4 from zlace0x/fix/style-and-syntax
zlace0x Nov 3, 2022
fb87f37
fix: add Markdown link to first mention of EIP-5827
zhongfu Nov 3, 2022
3184a9d
Merge pull request #5 from zlace0x/fix/markdown-link-on-first-eip-men…
zlace0x Nov 3, 2022
e1f80fa
fix: "MUST not" -> "MUST NOT"
zhongfu Nov 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions EIPS/eip-5827.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
eip: 5827
title: Auto-renewable allowance extension
description: Extension to enable automatic renewals on allowance approvals
author: zlace (@zlace0x), zhongfu (@zhongfu), edison0xyz (@edison0xyz)
discussions-to: https://ethereum-magicians.org/t/eip-5827-auto-renewable-allowance-extension/10392
status: Draft
type: Standards Track
category: ERC
created: 2022-10-22
requires: 20, 165
---

## Abstract

This extension adds a renewable allowance mechanism to [EIP-20](./eip-20.md) allowances, in which a `recoveryRate` defines the amount of token per second that the allowance regains towards the initial maximum approval `amount`.

## Motivation

Currently, EIP-20 supports allowances, with which token owners can allow a spender to spend a certain amount of tokens on their behalf. However, this is not ideal in circumstances involving recurring payments (e.g. subscriptions, salaries, recurring DCA purchases).

Many existing DApps circumvent this limitation by requesting that users grant a large or unlimited allowance. This presents a security risk as malicious DApps can drain users' accounts up to the allowance granted, and users may not be aware of the implications of giving an allowances.
zlace0x marked this conversation as resolved.
Show resolved Hide resolved

An auto-renewable allowance enables many traditional financial concepts like credit and debit limits. An account owner can specify a spending limit, and limit the amount charged to the account based on an allowance that recovers over time.


## Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

```solidity
interface IERC5827 {
zlace0x marked this conversation as resolved.
Show resolved Hide resolved
zlace0x marked this conversation as resolved.
Show resolved Hide resolved
/// @notice Emitted when a new allowance is set
zlace0x marked this conversation as resolved.
Show resolved Hide resolved
/// @param _owner owner of token
/// @param _spender allowed spender of token
/// @param _value initial and maximum allowance given to spender
/// @param _recoveryRate recovery amount per second
event SetRenewableAllowance(
address indexed _owner,
address indexed _spender,
uint256 _value,
uint192 _recoveryRate
);

/// @notice grants an allowance of _value to _spender initially, which recovers over time based on _recoveryRate up to a limit of _value
zlace0x marked this conversation as resolved.
Show resolved Hide resolved
/// SHOULD throw when _recoveryRate is larger than _value
/// MUST emit SetRenewableAllowance event
zlace0x marked this conversation as resolved.
Show resolved Hide resolved
/// @param _spender allowed spender of token
/// @param _value initial and maximum allowance given to spender
/// @param _recoveryRate recovery amount per second
function approve(
address _spender,
uint256 _value,
uint192 _recoveryRate
) external returns (bool success);

/// @notice Moves `amount` tokens from `from` to `to` using the
/// allowance mechanism. `amount` is then deducted from the caller's
/// allowance factoring in recovery rate logic.
/// SHOULD throw when there is insufficient allowance
/// @param from token owner address
/// @param to token recipient
/// @param amount amount of token to transfer
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);

/// @notice fetch amounts spendable by _spender
zlace0x marked this conversation as resolved.
Show resolved Hide resolved
/// @return remaining allowance at the current point in time
function allowance(address _owner, address _spender)
external
view
returns (uint256 remaining);

/// @notice fetch approved max amount and recovery rate
zlace0x marked this conversation as resolved.
Show resolved Hide resolved
/// @return amount initial and maximum allowance given to spender
/// @return recoveryRate recovery amount per second
function renewableAllowance(address _owner, address _spender)
external
view
returns (uint256 amount, uint192 recoveryRate);
}
```

Base method `approve(address _spender, uint256 _value)` MAY emit `SetRenewableAllowance` with a `recoveryRate` of 0.

Both `allowance()` and `transferFrom()` MUST be updated to include allowance recovery logic.

## Rationale

Renewable allowances can be implemented with discrete resets per time cycle. However, a continuous `recoveryRate` allows for more flexible use cases not bound by reset cycles and can be implemented with simpler logic.

## Backwards Compatibility

Existing EIP-20 token contracts can delegate allowance enforcement to a proxy contract that implements this specification.

## Security Considerations

This EIP introduces a stricter set of constraints compared to EIP-20 with unlimited allowances. However, when `_recoveryRate` is set to a large value, large amounts can still be transferred over multiple transactions.

## Copyright

Copyright and related rights waived via [CC0](../LICENSE.md).