owned this note
owned this note
Published
Linked with GitHub
ERC-2212 v2
===
```
eip: 2212
title: ERC-2212 Interest Earning Stakes
author: Paul Razvan Berg (@PaulRBerg) <hello@paulrberg.com>
discussions-to: https://github.com/ethereum/EIPs/issues/2212
status: Draft
type: Standards Track
category: ERC
created: 2019-07-30
requires: 20
```
<!--You can leave these HTML comments in your merged EIP and delete the visible duplicate text guides, they will not appear and may be helpful to refer to if you edit it again. This is the suggested template for new EIPs. Note that an EIP number will be assigned by an editor. When opening a pull request to submit your EIP, please use an abbreviated title in the filename, `eip-draft_title_abbrev.md`. The title should be 44 characters or less.-->
## Simple Summary
<!--"If you can't explain it simply, you don't understand it well enough." Provide a simplified and layman-accessible explanation of the EIP.-->
We propose a new way to monetise decentralised apps that involves users staking tokens in exchange for a product or a service and creators earning interest on the pooled stakes through a continuous lending protocol such as [Compound](https://compound.finance).
## Abstract
<!--A short (~200 word) description of the technical issue being addressed.-->
The advent of decentralised lending brought to the web3 ecosystem a new primitive for designing business models. We herein describe a smart contract interface that accepts deposits ("stakes") in ERC20 tokens. These deposits are immediately lent on the market to earn interest either for just the owner of the contract, or for both them and the user. We assume that users get access to a product or a service for as long as they keep staking tokens.
## Motivation
<!--The motivation is critical for EIPs that want to change the Ethereum protocol. It should clearly explain why the existing protocol specification is inadequate to address the problem that the EIP solves. EIP submissions without sufficient motivation may be rejected outright.-->
While most web3 business models rely on paying a percentage fee on transfers, or commiting to a monthly subscription, we aim to flip the model on its head. Users are their own banks now, so, instead of charging them, we make them stake tokens that can be claimed back, in full, at any point in time. We view this as a win-win-win scenario for users, dapp creators and lending protocols.
It is worth it to mention PoolTogether, a "no-loss lottery" that launched recently. It works by having participants deposit money in their contracts, locking it up for a while and earning interest through Compound. Ultimately, they choose a lucky winner and return the deposits back to all other players. PoolTogether takes a 10% commission on the prize.
We wrote this specification because interest earning stakes are a powerful financial instrument and a community-vetted standard and implementation will reduce the cost of replication.
### Use Cases
- Software products and services
- Charity pools
- Games
- Gym memberships
## Specification
<!--The technical specification should describe the syntax and semantics of any new feature. The specification should be detailed enough to allow competing, interoperable implementations for any of the current Ethereum platforms (go-ethereum, parity, cpp-ethereum, ethereumj, ethereumjs, and [others](https://github.com/ethereum/wiki/wiki/Clients)).-->
Having an owner is mandatory for this spec to make sense, thus we assume that a proper implementation would use a well-known contract such as OpenZeppelin's [Ownable](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/ownership/Ownable.sol). For brevity, we haven't included any method for assigning or transferring ownership.
### Methods
#### owner
Returns the owner of the contract.
```solidity
function owner() external view returns (address);
```
#### fee
Returns the fee as a percentage value scaled by 1e18.
```solidity
function fee() external view returns (uint256);
```
#### balanceOf
Returns the stake that consists of the initial deposit plus the interest accrued over time.
SHOULD revert if `staker` doesn't have an active stake.
```solidity
function balanceOf(address staker) external view returns (uint256);
```
#### depositOf
Returns the initial deposit.
SHOULD revert if `staker` doesn't have an active stake.
```solidity
function depositOf(address staker) external view returns (uint256);
```
#### stake
Creates a new stake object for `msg.sender`. Automatically converts an underlying to its lending form so that the contract can earn interest.
MUST revert if `msg.sender` already has an active stake.
**Triggers Event**: [Stake](#stake)
```solidity
function stake(address tokenAddress, uint256 amount) external;
```
#### redeem
Returns the deposit plus any accrued interest to the staker and levies the fee for the `owner`.
MUST revert if `msg.sender` is not the staker or the owner.
**Triggers Event**: [Redeem](#redeem)
```solidity
function redeem(address staker) external;
```
#### takeEarnings
Withdraws the earnings accrued over time.
MUST revert if `msg.sender` is not the owner.
**Triggers Event**: [TakeEarnings](#take-earnings)
```solidity
function takeEarnings(address tokenAddress, uint256 amount) external;
```
#### updateFee
Updates the fee practiced by the contract. Has to be a percentage value scaled by 1e18. Can be anything between 0% and 100%.
MUST revert if `msg.sender` is not the owner.
**Triggers Event**: [UpdateFee](#update-fee)
```solidity
function updateFee(uint256 newFee) external;
```
---
### Events
#### Stake
MUST be triggered when `stake` is successfully called.
```solidity
event Stake(address indexed staker, address indexed underlyingAddress, bool converted, uint256 deposit, uint256 exchangeRate);
```
#### Redeem
MUST be triggered when `redeem` is successfully called.
```solidity
event Redeem(address indexed staker, address indexed underlyingAddress, uint256 fee, uint256 withdrawal);
```
#### TakeEarnings
MUST be triggered when `takeEarnings` is successfully called.
```solidity
event TakeEarnings(address indexed tokenAddress, uint256 indexed amount);
```
#### UpdateFee
MUST be triggered when `updateFee` is successfully called.
```solidity
event UpdateFee(uint256 indexed fee);
```
## Rationale
<!--The rationale fleshes out the specification by describing what motivated the design and why particular design decisions were made. It should describe alternate designs that were considered and related work, e.g. how the feature is supported in other languages. The rationale may also provide evidence of consensus within the community, and should discuss important objections or concerns raised during discussion.-->
In the v1 of this spec, there were a few methods highly specific to Compound:
- whitelistCToken(address, address)
- discardCToken(address, address)
- resetAllowance(address, address)
We removed them to make the spec protocol agnostic. It is up to the implementor if they choose Compound, Maker or they roll out their own lending market.
Finally, we designed these interest earning stakes with simplicity in mind, while acknowledging that there are some missing features and obvious concerns which we shall discuss below.
---
### Missing Features
#### Update
By and large, this is the most prominent missing feature. Dapp creators might want to update their staking requirements and the only way to achieve that would be to ask users to redeem their previous stake and put in the new amount.
We assume that most apps don't need this and the spec as it is now is sufficient for running the very first experiments. Yet, time will tell best. We are looking forward to making updates if need be.
#### Parallel Staking
Large enterprises have multiple sources of revenue, hence swiching to a business model based on staking would require a smart contract that accepts multiple stakes per user.
However, the goal is to avoid writing an over-optimised standard. Parallel staking would require dapp creators to keep track of multiple stake ids, instead of only the user's account. Also, the user's interface would become more complex, as they would have to be aware of multiple stakes.
---
### Concerns
#### Loan Defaults
Lending never comes without risks, so interest earning stakes are not a good fit for the ultra-sensitive business applications. That said, dapp creators have an incentive to monitor the market for borrowers that go under the collateral requirements and liquidate them. By doing so, they secure the network for their own users and also earn a fee in the process.
#### Fluctuating Rates
The market rates for lending stablecoins hovered around 10% in early 2019, but this is not a given. Dapp creators can accommodate this issue by asking for a stake that generates interest reasonably above what they deem as an acceptable revenue stream.
#### Rent-Seeking
Interest earning stakes work best for products or services that are priced on time instead of quantity (imagine subscription-based SaaS). If a dapp is quota-based, its creators would be better off charging a fee on every transfer.
## Implementation
<!--The implementations must be completed before any EIP is given status "Final", but it need not be completed before the EIP is accepted. While there is merit to the approach of reaching consensus on the specification and rationale before writing code, the principle of "rough consensus and running code" is still useful when it comes to resolving many discussions of API details.-->
[Head to the Sablier organisation on GitHub](https://github.com/SablierApp/ies) for a WIP implementation.
## Additional References
- [Thread on cTokens](https://twitter.com/PaulRBerg/status/1147980107740524544)
- [Compound Presidio](https://compound.finance/developers)
- [PoolTogether](https://pooltogether.us)
- [Pooled cDAI](https://github.com/ZeframLou/pooled-cdai)
- [Lending Proxy by Luciano Bertenasco](https://github.com/lbertenasco/lending-proxy)
- [Web3 Revenue Primitives](https://github.com/FEMBusinessModelsRing/web3_revenue_primitives)
## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
@PaulRBerg and @SablierHQ ✌️