ERC-900 Simple Staking Interface
Stagnant · Vaults & DeFi · created 2018-02-22
Defines the process of depositing (staking) tokens into a contract, and querying and releasing them, with common functions and events, so that different staking systems can be handled the same way.
Why it is needed
Applications that use staking, such as token curated registries, are increasing, but when each contract defines its own function names and event formats, wallets and other services have to redo integration work every time. Without a standard way to query how much a given address has staked, or how much was staked at a given past point in time, each service has to implement it separately, making it hard to reuse and forcing users to learn different usage for each service.
What to implement
event Staked(address indexed user, uint256 amount, uint256 total, bytes data);: An event emitted when a user stakes tokens.event Unstaked(address indexed user, uint256 amount, uint256 total, bytes data);: An event emitted when a user receives back tokens they had staked.function stake(uint256 amount, bytes data) public;: The caller stakes a certain amount of tokens on their own behalf.function stakeFor(address user, uint256 amount, bytes data) public;: The caller stakes tokens on behalf of another address they specify.function unstake(uint256 amount, bytes data) public;: Releases a certain amount of staked tokens and returns them.function totalStakedFor(address addr) public view returns (uint256);: Returns the total amount currently staked by a specific address.function totalStaked() public view returns (uint256);: Returns the current total amount staked across the entire contract.function token() public view returns (address);: Returns the address of the token contract that this interface handles.function supportsHistory() public pure returns (bool);: Returns whether the optional history query functions below are implemented.function lastStakedFor(address addr) public view returns (uint256);: Returns the block number at which the given address last staked. This is an optional implementation.function totalStakedForAt(address addr, uint256 blockNumber) public view returns (uint256);: Returns the total amount staked by the given address at a specific block. This is an optional implementation.function totalStakedAt(uint256 blockNumber) public view returns (uint256);: Returns the total amount staked across all addresses at a specific block. This is an optional implementation.
In depth
Difference between stake and stakeFor
stake transfers and stakes the caller's own tokens. stakeFor stakes on behalf of another address (user) specified by the caller, but the tokens transferred come from the caller. Both functions accept a data field, which the source text explains can be used to add signalling information for more complex staking applications. Both functions must emit a Staked event when called.
Conditions for unstake's return
unstake releases the specified amount from staking. The source text states that tokens should be returned to the user, but if unstaking is currently not possible, the transaction must revert. The data field can be used to remove signalling information that was added at stake time. An Unstaked event must be emitted when called.
Query functions: totalStakedFor, totalStaked, token
totalStakedFor(addr) returns the total amount currently staked by a specific address, and totalStaked() returns the current total amount staked across the entire contract. token() returns the address of the token contract that this staking interface handles.
supportsHistory and the optional history functions
On the premise that not every staking system needs a complete historical record, the three functions lastStakedFor, totalStakedForAt, and totalStakedAt are OPTIONAL. supportsHistory() must accurately report true or false as to whether these three functions are implemented. lastStakedFor returns the block number at which the given address last staked, totalStakedForAt returns the total amount staked by a specific address at a specific block, and totalStakedAt returns the total amount staked across all addresses at a specific block.
Proposal status: Stagnant
This proposal was written in February 2018 and is currently in Stagnant status. In other words, it is a proposal where discussion has stopped progressing, and it may never be revised or formally adopted.