{"eip":2917,"title":"Staking Reward Calculation","description":"ERC2917 is a new standardization for on-chain calculation of staking reward.","authors":["Tony Carson \u003ctony.carsonn@gmail.com\u003e","Mehmet Sabir Kiraz \u003cm.kiraz@gmail.com\u003e","Süleyman Kardaş \u003cskardas@gmail.com\u003e"],"status":"Stagnant","type":"Standards Track","category":"ERC","created":"2020-08-28","discussionsTo":"https://github.com/ethereum/EIPs/issues/2925","repo":"ERCs","label":"ERC-2917","officialUrl":"https://eips.ethereum.org/EIPS/eip-2917","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2917.md","url":"https://eips.huatuo.xyz/eip-2917/","tldr":{"en":"A proposed interface for calculating staking rewards fully on-chain, paying each user a share of per-block interest proportional to their 'productivity' (stake) over time.","ja":"ステーキング報酬を完全にオンチェーンで計算するためのインターフェースの提案。各ユーザーに、時間にわたる「生産性」（ステーク）に比例して、ブロックごとの利息の分け前を支払う。","ko":"스테이킹 보상을 완전히 온체인으로 계산하기 위한 인터페이스 제안. 각 사용자에게 시간에 따른 '생산성'(스테이크)에 비례해 블록당 이자의 몫을 지급한다.","zh":"提议的一个接口，用于完全在链上计算质押奖励，按每个用户随时间变化的\"生产力\"（质押量）的比例，向其支付每区块利息的份额。"},"tags":["staking","rewards","defi","erc-20","interface"],"explainers":{"en":{"lang":"en","tldr":"A proposed interface for calculating staking rewards fully on-chain, paying each user a share of per-block interest proportional to their 'productivity' (stake) over time.","tags":["staking","rewards","defi","erc-20","interface"],"related":[20,900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2917/","markdown":"## What problem does it solve?\n\nEarly DeFi reward schemes tended to fall into two camps, according to the spec: either rewards were only distributed once everyone exited the contract, or the project collected data on-chain, computed rewards off-chain, and pushed the results back. The first is slow and forces users to withdraw collateral; the second relies on trusting the operator's calculation.\n\nERC-2917 proposes a standard, fully on-chain way to compute rewards at any block, plus a common interface so wallets can show users how much they have earned, how it is calculated, and what share of the total they contribute.\n\n## How it works\n\nThe contract mints a fixed amount of interest per block (`interestsPerBlock`). Each user has a **productivity** value (typically their effective stake) and the contract tracks the **global productivity**. For every stretch of blocks in which nobody's productivity changes, a user earns:\n\n```text\nreward_i = interestsPerBlock × blocks_in_period × (user_productivity / global_productivity)\n```\n\nA user's total reward is the sum over all such periods. The calculation is updated whenever a user's productivity increases or decreases, and when they withdraw, so joining late or leaving early gives no advantage.\n\nThe interface (the reward token itself is an ERC-20):\n\n| Function / event | Purpose |\n| --- | --- |\n| `interestsPerBlock()` | Interest produced per block |\n| `changeInterestRatePerBlock(v)` | Change the rate (should be restricted) |\n| `getProductivity(user)` | User's and global productivity |\n| `increaseProductivity(user, v)` / `decreaseProductivity(user, v)` | Adjust a user's stake (should be restricted to the staking contract) |\n| `take()` / `takeWithBlock()` | Rewards claimable by the caller now (and at which block) |\n| `mint()` | Mint the caller's accrued rewards to them |\n| `InterestRatePerBlockChanged`, `ProductivityIncreased`, `ProductivityDecreased` | Events |\n\n## Sample code\n\nThe usual way to implement this formula efficiently is an \"accumulated reward per unit of productivity\" counter, so no loop over periods is needed:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract RewardAccounting {\n    uint256 public interestsPerBlock;\n    uint256 public totalProductivity;\n    uint256 public accPerShare;      // scaled by 1e18\n    uint256 public lastBlock;\n\n    mapping(address =\u003e uint256) public productivity;\n    mapping(address =\u003e uint256) public rewardDebt;\n    mapping(address =\u003e uint256) public pending;\n\n    function _update() internal {\n        if (block.number \u003e lastBlock \u0026\u0026 totalProductivity \u003e 0) {\n            uint256 reward = (block.number - lastBlock) * interestsPerBlock;\n            accPerShare += reward * 1e18 / totalProductivity;\n        }\n        lastBlock = block.number;\n    }\n\n    function _settle(address user) internal {\n        pending[user] += productivity[user] * accPerShare / 1e18 - rewardDebt[user];\n    }\n\n    function _increase(address user, uint256 value) internal {\n        _update();\n        _settle(user);\n        productivity[user] += value;\n        totalProductivity += value;\n        rewardDebt[user] = productivity[user] * accPerShare / 1e18;\n    }\n}\n```\n\n## Things to know\n\n- **Status: Stagnant.** The Rationale and Security Considerations sections were never written, and the standard was not finalized.\n- The spec's own wording calls these \"interests\", but the mechanism is a reward emission, not interest in a financial sense; the emitted token's value depends entirely on the project.\n- `increaseProductivity`, `decreaseProductivity` and `changeInterestRatePerBlock` must be access-controlled. If anyone can call them, anyone can mint rewards.\n- The same accumulator pattern is widely used in staking and liquidity-mining contracts that never referenced this ERC.\n"},"ja":{"lang":"ja","tldr":"ステーキング報酬を完全にオンチェーンで計算するためのインターフェースの提案。各ユーザーに、時間にわたる「生産性」（ステーク）に比例して、ブロックごとの利息の分け前を支払う。","tags":["staking","rewards","defi","erc-20","interface"],"related":[20,900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2917/","markdown":"## 何を解決するのか\n\n仕様によると、初期の DeFi の報酬の仕組みは 2 つの陣営に分かれがちでした。全員がコントラクトから退出して初めて報酬が分配されるか、プロジェクトがオンチェーンでデータを集め、オフチェーンで報酬を計算し、結果を書き戻すかです。前者は遅く、ユーザーに担保を引き出させることになります。後者はオペレーターの計算を信頼することに依存します。\n\nERC-2917 は、任意のブロックで報酬を計算する標準的で完全にオンチェーンな方法と、ウォレットがユーザーにどれだけ稼いだか、どう計算されるか、全体に対してどれだけの割合を占めるかを表示できる共通のインターフェースを提案します。\n\n## 仕組み\n\nコントラクトはブロックごとに固定量の利息（`interestsPerBlock`）をミントします。各ユーザーは**生産性**（productivity、通常は実効ステーク）の値を持ち、コントラクトは**全体の生産性**を追跡します。誰の生産性も変わらないブロックの区間ごとに、ユーザーは次の量を獲得します。\n\n```text\nreward_i = interestsPerBlock × blocks_in_period × (user_productivity / global_productivity)\n```\n\nユーザーの報酬総額は、こうした区間すべての合計です。計算は、ユーザーの生産性が増減するとき、および引き出すときに更新されるので、遅れて参加しても早く抜けても有利にはなりません。\n\nインターフェース（報酬トークン自体は ERC-20 です）：\n\n| 関数 / イベント | 役割 |\n| --- | --- |\n| `interestsPerBlock()` | ブロックごとに生み出される利息 |\n| `changeInterestRatePerBlock(v)` | レートを変更する（制限すべき） |\n| `getProductivity(user)` | ユーザーと全体の生産性 |\n| `increaseProductivity(user, v)` / `decreaseProductivity(user, v)` | ユーザーのステークを調整する（ステーキングコントラクトに限定すべき） |\n| `take()` / `takeWithBlock()` | 呼び出し元が今請求できる報酬（と、そのブロック） |\n| `mint()` | 呼び出し元の発生済み報酬を本人にミントする |\n| `InterestRatePerBlockChanged`、`ProductivityIncreased`、`ProductivityDecreased` | イベント |\n\n## サンプルコード\n\nこの式を効率的に実装する一般的な方法は、「生産性 1 単位あたりの累積報酬」カウンターを使うことで、区間ごとのループが不要になります。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract RewardAccounting {\n    uint256 public interestsPerBlock;\n    uint256 public totalProductivity;\n    uint256 public accPerShare;      // scaled by 1e18\n    uint256 public lastBlock;\n\n    mapping(address =\u003e uint256) public productivity;\n    mapping(address =\u003e uint256) public rewardDebt;\n    mapping(address =\u003e uint256) public pending;\n\n    function _update() internal {\n        if (block.number \u003e lastBlock \u0026\u0026 totalProductivity \u003e 0) {\n            uint256 reward = (block.number - lastBlock) * interestsPerBlock;\n            accPerShare += reward * 1e18 / totalProductivity;\n        }\n        lastBlock = block.number;\n    }\n\n    function _settle(address user) internal {\n        pending[user] += productivity[user] * accPerShare / 1e18 - rewardDebt[user];\n    }\n\n    function _increase(address user, uint256 value) internal {\n        _update();\n        _settle(user);\n        productivity[user] += value;\n        totalProductivity += value;\n        rewardDebt[user] = productivity[user] * accPerShare / 1e18;\n    }\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス：Stagnant。** Rationale と Security Considerations のセクションは書かれないままで、標準は確定しませんでした。\n- 仕様自身の表現では「interests（利息）」と呼んでいますが、仕組みは金融上の利息ではなく報酬の発行です。発行されるトークンの価値はすべてプロジェクト次第です。\n- `increaseProductivity`、`decreaseProductivity`、`changeInterestRatePerBlock` にはアクセス制御が必須です。誰でも呼べるなら、誰でも報酬をミントできてしまいます。\n- 同じ累積カウンターのパターンは、この ERC を参照していないステーキングやリクイディティマイニングのコントラクトでも広く使われています。\n"},"ko":{"lang":"ko","tldr":"스테이킹 보상을 완전히 온체인으로 계산하기 위한 인터페이스 제안. 각 사용자에게 시간에 따른 '생산성'(스테이크)에 비례해 블록당 이자의 몫을 지급한다.","tags":["staking","rewards","defi","erc-20","interface"],"related":[20,900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2917/","markdown":"## 어떤 문제를 해결하나요?\n\n명세에 따르면 초기 DeFi 보상 방식은 두 부류로 나뉘는 경향이 있었습니다. 모든 사람이 컨트랙트를 빠져나간 뒤에야 보상을 분배하거나, 프로젝트가 온체인에서 데이터를 모으고 오프체인에서 보상을 계산한 뒤 결과를 다시 밀어 넣는 방식입니다. 전자는 느리고 사용자가 담보를 인출하도록 강제하며, 후자는 운영자의 계산을 신뢰해야 합니다.\n\nERC-2917은 임의의 블록에서 보상을 계산하는 표준적이고 완전히 온체인인 방법과, 지갑이 사용자에게 얼마를 벌었는지, 어떻게 계산되는지, 전체에서 어느 정도 비중을 차지하는지 보여 줄 수 있는 공통 인터페이스를 제안합니다.\n\n## 어떻게 동작하나요?\n\n컨트랙트는 블록마다 고정된 양의 이자(`interestsPerBlock`)를 발행합니다. 각 사용자는 **생산성**(productivity, 보통 유효 스테이크) 값을 가지며, 컨트랙트는 **전체 생산성**을 추적합니다. 아무의 생산성도 바뀌지 않는 블록 구간마다 사용자는 다음을 얻습니다.\n\n```text\nreward_i = interestsPerBlock × blocks_in_period × (user_productivity / global_productivity)\n```\n\n사용자의 총 보상은 이러한 모든 구간의 합입니다. 계산은 사용자의 생산성이 늘거나 줄 때, 그리고 인출할 때마다 갱신되므로 늦게 참여하거나 일찍 떠나도 이득이 없습니다.\n\n인터페이스(보상 토큰 자체는 ERC-20입니다):\n\n| 함수 / 이벤트 | 역할 |\n| --- | --- |\n| `interestsPerBlock()` | 블록당 생산되는 이자 |\n| `changeInterestRatePerBlock(v)` | 이율 변경(제한되어야 함) |\n| `getProductivity(user)` | 사용자와 전체의 생산성 |\n| `increaseProductivity(user, v)` / `decreaseProductivity(user, v)` | 사용자의 스테이크 조정(스테이킹 컨트랙트로 제한되어야 함) |\n| `take()` / `takeWithBlock()` | 호출자가 지금 청구할 수 있는 보상(과 해당 블록) |\n| `mint()` | 호출자의 누적 보상을 호출자에게 발행 |\n| `InterestRatePerBlockChanged`, `ProductivityIncreased`, `ProductivityDecreased` | 이벤트 |\n\n## 샘플 코드\n\n이 공식을 효율적으로 구현하는 일반적인 방법은 \"생산성 단위당 누적 보상\" 카운터를 쓰는 것으로, 구간별 반복문이 필요 없습니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract RewardAccounting {\n    uint256 public interestsPerBlock;\n    uint256 public totalProductivity;\n    uint256 public accPerShare;      // scaled by 1e18\n    uint256 public lastBlock;\n\n    mapping(address =\u003e uint256) public productivity;\n    mapping(address =\u003e uint256) public rewardDebt;\n    mapping(address =\u003e uint256) public pending;\n\n    function _update() internal {\n        if (block.number \u003e lastBlock \u0026\u0026 totalProductivity \u003e 0) {\n            uint256 reward = (block.number - lastBlock) * interestsPerBlock;\n            accPerShare += reward * 1e18 / totalProductivity;\n        }\n        lastBlock = block.number;\n    }\n\n    function _settle(address user) internal {\n        pending[user] += productivity[user] * accPerShare / 1e18 - rewardDebt[user];\n    }\n\n    function _increase(address user, uint256 value) internal {\n        _update();\n        _settle(user);\n        productivity[user] += value;\n        totalProductivity += value;\n        rewardDebt[user] = productivity[user] * accPerShare / 1e18;\n    }\n}\n```\n\n## 알아둘 점\n\n- **상태: Stagnant.** Rationale과 Security Considerations 섹션은 작성되지 않았고, 표준은 확정되지 않았습니다.\n- 명세 자체의 표현은 이를 \"interests(이자)\"라고 부르지만, 이 메커니즘은 금융적 의미의 이자가 아니라 보상 발행입니다. 발행되는 토큰의 가치는 전적으로 프로젝트에 달려 있습니다.\n- `increaseProductivity`, `decreaseProductivity`, `changeInterestRatePerBlock`에는 반드시 접근 제어가 있어야 합니다. 누구나 호출할 수 있다면 누구나 보상을 발행할 수 있습니다.\n- 같은 누적기 패턴은 이 ERC를 참조한 적이 없는 스테이킹 및 유동성 마이닝 컨트랙트에서도 널리 쓰입니다.\n"},"zh":{"lang":"zh","tldr":"提议的一个接口，用于完全在链上计算质押奖励，按每个用户随时间变化的\"生产力\"（质押量）的比例，向其支付每区块利息的份额。","tags":["staking","rewards","defi","erc-20","interface"],"related":[20,900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2917/","markdown":"## 它解决什么问题？\n\n据规范所述，早期 DeFi 的奖励方案往往分为两类：要么只有在所有人都退出合约之后才分发奖励，要么项目在链上收集数据、在链下计算奖励，再把结果推回链上。前者很慢，还迫使用户提走抵押品；后者依赖对运营方计算结果的信任。\n\nERC-2917 提出一种标准的、完全在链上的方式来计算任意区块的奖励，并提供通用接口，让钱包可以向用户展示他们赚了多少、如何计算，以及他们占总量的份额。\n\n## 它如何运作\n\n合约每个区块铸造固定数量的利息（`interestsPerBlock`）。每个用户有一个**生产力**（productivity）值（通常是其有效质押量），合约跟踪**全局生产力**。在没有任何人的生产力发生变化的每一段区块内，用户获得：\n\n```text\nreward_i = interestsPerBlock × blocks_in_period × (user_productivity / global_productivity)\n```\n\n用户的总奖励是所有这些时间段之和。每当用户的生产力增加或减少，以及用户提取时，计算都会更新，因此晚加入或早退出都不会有优势。\n\n接口（奖励代币本身是 ERC-20）：\n\n| 函数 / 事件 | 用途 |\n| --- | --- |\n| `interestsPerBlock()` | 每个区块产生的利息 |\n| `changeInterestRatePerBlock(v)` | 修改利率（应受限制） |\n| `getProductivity(user)` | 用户和全局的生产力 |\n| `increaseProductivity(user, v)` / `decreaseProductivity(user, v)` | 调整用户的质押量（应仅限质押合约调用） |\n| `take()` / `takeWithBlock()` | 调用者当前可领取的奖励（以及对应的区块） |\n| `mint()` | 把调用者已累积的奖励铸造给他 |\n| `InterestRatePerBlockChanged`、`ProductivityIncreased`、`ProductivityDecreased` | 事件 |\n\n## 示例代码\n\n高效实现这个公式的常用方法是使用\"每单位生产力的累计奖励\"计数器，这样就不需要对各时间段做循环：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract RewardAccounting {\n    uint256 public interestsPerBlock;\n    uint256 public totalProductivity;\n    uint256 public accPerShare;      // scaled by 1e18\n    uint256 public lastBlock;\n\n    mapping(address =\u003e uint256) public productivity;\n    mapping(address =\u003e uint256) public rewardDebt;\n    mapping(address =\u003e uint256) public pending;\n\n    function _update() internal {\n        if (block.number \u003e lastBlock \u0026\u0026 totalProductivity \u003e 0) {\n            uint256 reward = (block.number - lastBlock) * interestsPerBlock;\n            accPerShare += reward * 1e18 / totalProductivity;\n        }\n        lastBlock = block.number;\n    }\n\n    function _settle(address user) internal {\n        pending[user] += productivity[user] * accPerShare / 1e18 - rewardDebt[user];\n    }\n\n    function _increase(address user, uint256 value) internal {\n        _update();\n        _settle(user);\n        productivity[user] += value;\n        totalProductivity += value;\n        rewardDebt[user] = productivity[user] * accPerShare / 1e18;\n    }\n}\n```\n\n## 需要注意\n\n- **状态：Stagnant。** Rationale 和 Security Considerations 两节从未撰写，该标准没有最终确定。\n- 规范自己的措辞把这些称为\"interests\"（利息），但这个机制是奖励发行，而不是金融意义上的利息；发行代币的价值完全取决于项目本身。\n- `increaseProductivity`、`decreaseProductivity` 和 `changeInterestRatePerBlock` 必须有访问控制。如果任何人都能调用，任何人都能铸造奖励。\n- 同样的累加器模式在许多从未引用过这个 ERC 的质押和流动性挖矿合约中被广泛使用。\n"}}}
