EIPs Explained

ERC-900 · Stagnant · ERC · 2018-02-22

ERC-900: Simple Staking Interface

A minimal interface for locking ERC-20 tokens as a stake, with stake, unstake and balance queries plus optional history; it is Stagnant and never became a widely used standard.

What problem does it solve?

Many token systems ask users to lock up tokens to take part: voting, curating lists, running services, or earning rewards. In 2018 each project designed its own staking contract, so wallets and other contracts had to learn a new interface every time.

ERC-900 proposes a small, common staking interface. Any app can then stake, unstake, and read stake totals the same way, whatever the stake is used for. The spec mentions token-curated registries as one target use case.

How it works

A staking contract is tied to one token, given by token(), and exposes:

Function Purpose
stake(amount, data) Lock amount tokens from the caller. Must emit Staked
stakeFor(user, amount, data) Lock tokens from the caller on behalf of user
unstake(amount, data) Return tokens. Must revert if unstaking is not possible right now. Must emit Unstaked
totalStakedFor(addr) Current stake of one address
totalStaked() Total stake in the contract
supportsHistory() true if the optional history functions exist

Optional history functions are lastStakedFor(addr), totalStakedForAt(addr, blockNumber) and totalStakedAt(blockNumber). They let governance tools read stakes at a past block.

The data argument is free-form. More complex systems can use it to signal intent, for example which list entry a stake supports.

Events: Staked(user, amount, total, data) and Unstaked(user, amount, total, data), where total is the user's new stake.

Sample code

A minimal implementation without history (illustration only):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract SimpleStaking {
    event Staked(address indexed user, uint256 amount, uint256 total, bytes data);
    event Unstaked(address indexed user, uint256 amount, uint256 total, bytes data);

    IERC20 public immutable stakingToken;
    mapping(address => uint256) public totalStakedFor;
    uint256 public totalStaked;

    constructor(IERC20 t) { stakingToken = t; }

    function token() external view returns (address) { return address(stakingToken); }
    function supportsHistory() external pure returns (bool) { return false; }

    function stake(uint256 amount, bytes calldata data) external { stakeFor(msg.sender, amount, data); }

    function stakeFor(address user, uint256 amount, bytes calldata data) public {
        require(stakingToken.transferFrom(msg.sender, address(this), amount), "transfer");
        totalStakedFor[user] += amount;
        totalStaked += amount;
        emit Staked(user, amount, totalStakedFor[user], data);
    }

    function unstake(uint256 amount, bytes calldata data) external {
        totalStakedFor[msg.sender] -= amount;     // reverts on underflow
        totalStaked -= amount;
        require(stakingToken.transfer(msg.sender, amount), "transfer");
        emit Unstaked(msg.sender, amount, totalStakedFor[msg.sender], data);
    }
}

Things to know

  • This proposal is Stagnant and was never finalized. It is not a widely used standard, and most staking systems define their own interfaces.
  • The interface in the spec uses old Solidity syntax (public functions in an interface, bytes without a data location). Adjust it to compile with modern compilers.
  • stakeFor pulls tokens from the caller but credits another address. Decide who may later unstake those tokens before using it.
  • For deposit-and-share accounting on tokens, ERC-4626 tokenized vaults are now the common standard, though they solve a different problem than lock-up staking.

#staking #token #interface #stagnant

Details

Authors
Dean Eigenmann <[email protected]>, Jorge Izquierdo <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2018-02-22

Machine-readable: Markdown · JSON