---
eip: 2917
label: ERC-2917
title: Staking Reward Calculation
status: Stagnant
type: Standards Track
category: ERC
created: 2020-08-28
official: https://eips.ethereum.org/EIPS/eip-2917
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2917.md
canonical: https://eips.huatuo.xyz/ja/eip-2917/
lang: ja
tldr: ステーキング報酬を完全にオンチェーンで計算するためのインターフェースの提案。各ユーザーに、時間にわたる「生産性」（ステーク）に比例して、ブロックごとの利息の分け前を支払う。
tags: [staking, rewards, defi, erc-20, interface]
---

# ERC-2917: Staking Reward Calculation

> ERC2917 is a new standardization for on-chain calculation of staking reward.

**TL;DR:** ステーキング報酬を完全にオンチェーンで計算するためのインターフェースの提案。各ユーザーに、時間にわたる「生産性」（ステーク）に比例して、ブロックごとの利息の分け前を支払う。

## 何を解決するのか

仕様によると、初期の DeFi の報酬の仕組みは 2 つの陣営に分かれがちでした。全員がコントラクトから退出して初めて報酬が分配されるか、プロジェクトがオンチェーンでデータを集め、オフチェーンで報酬を計算し、結果を書き戻すかです。前者は遅く、ユーザーに担保を引き出させることになります。後者はオペレーターの計算を信頼することに依存します。

ERC-2917 は、任意のブロックで報酬を計算する標準的で完全にオンチェーンな方法と、ウォレットがユーザーにどれだけ稼いだか、どう計算されるか、全体に対してどれだけの割合を占めるかを表示できる共通のインターフェースを提案します。

## 仕組み

コントラクトはブロックごとに固定量の利息（`interestsPerBlock`）をミントします。各ユーザーは**生産性**（productivity、通常は実効ステーク）の値を持ち、コントラクトは**全体の生産性**を追跡します。誰の生産性も変わらないブロックの区間ごとに、ユーザーは次の量を獲得します。

```text
reward_i = interestsPerBlock × blocks_in_period × (user_productivity / global_productivity)
```

ユーザーの報酬総額は、こうした区間すべての合計です。計算は、ユーザーの生産性が増減するとき、および引き出すときに更新されるので、遅れて参加しても早く抜けても有利にはなりません。

インターフェース（報酬トークン自体は ERC-20 です）：

| 関数 / イベント | 役割 |
| --- | --- |
| `interestsPerBlock()` | ブロックごとに生み出される利息 |
| `changeInterestRatePerBlock(v)` | レートを変更する（制限すべき） |
| `getProductivity(user)` | ユーザーと全体の生産性 |
| `increaseProductivity(user, v)` / `decreaseProductivity(user, v)` | ユーザーのステークを調整する（ステーキングコントラクトに限定すべき） |
| `take()` / `takeWithBlock()` | 呼び出し元が今請求できる報酬（と、そのブロック） |
| `mint()` | 呼び出し元の発生済み報酬を本人にミントする |
| `InterestRatePerBlockChanged`、`ProductivityIncreased`、`ProductivityDecreased` | イベント |

## サンプルコード

この式を効率的に実装する一般的な方法は、「生産性 1 単位あたりの累積報酬」カウンターを使うことで、区間ごとのループが不要になります。

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

contract RewardAccounting {
    uint256 public interestsPerBlock;
    uint256 public totalProductivity;
    uint256 public accPerShare;      // scaled by 1e18
    uint256 public lastBlock;

    mapping(address => uint256) public productivity;
    mapping(address => uint256) public rewardDebt;
    mapping(address => uint256) public pending;

    function _update() internal {
        if (block.number > lastBlock && totalProductivity > 0) {
            uint256 reward = (block.number - lastBlock) * interestsPerBlock;
            accPerShare += reward * 1e18 / totalProductivity;
        }
        lastBlock = block.number;
    }

    function _settle(address user) internal {
        pending[user] += productivity[user] * accPerShare / 1e18 - rewardDebt[user];
    }

    function _increase(address user, uint256 value) internal {
        _update();
        _settle(user);
        productivity[user] += value;
        totalProductivity += value;
        rewardDebt[user] = productivity[user] * accPerShare / 1e18;
    }
}
```

## 知っておくべきこと

- **ステータス：Stagnant。** Rationale と Security Considerations のセクションは書かれないままで、標準は確定しませんでした。
- 仕様自身の表現では「interests（利息）」と呼んでいますが、仕組みは金融上の利息ではなく報酬の発行です。発行されるトークンの価値はすべてプロジェクト次第です。
- `increaseProductivity`、`decreaseProductivity`、`changeInterestRatePerBlock` にはアクセス制御が必須です。誰でも呼べるなら、誰でも報酬をミントできてしまいます。
- 同じ累積カウンターのパターンは、この ERC を参照していないステーキングやリクイディティマイニングのコントラクトでも広く使われています。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2917
