A time-based ERC20 staking rewards contract, derived from the Synthetix
StakingRewards design. Users deposit a staking token and continuously
accrue a rewards token over a configurable distribution period.
StakingRewards.sol— core staking contract. Usersstake,withdraw,getReward, orexit. The owner can recover non-staking ERC20s and configure the rewards duration; the designated rewards distributor callsnotifyRewardAmountto start or top up a reward epoch.StakingRewardUpdater.sol— helper used by the deployer to roll multiple expiredStakingRewardsinstances into a new epoch in one transaction (accept ownership, set duration, fund, notify, hand ownership back).RewardsDistributionRecipient.sol,Owned.sol,Pausable.sol— access control and pause primitives used by the core contract.interfaces/IStakingRewards.sol— external interface.utils/ERC20Token.sol— minimal ERC20 used in tests/migrations.
- Node.js and npm
- Truffle (
npm install -g truffle) - Solidity
0.5.16(resolved automatically by Truffle)
npm installmake build
# or
truffle compileLaunches the Truffle development console with an in-memory chain:
make develop
# or
truffle developConfigure a network in truffle-config.js, then update the constructor
arguments in migrations/3_deploy_staking_rewards.js (owner, rewards
distributor, rewards token, staking token) and run:
truffle migrate --network <network-name>- Deploy
StakingRewardswith the owner, rewards distributor, rewards token, and staking token addresses. - Optionally call
setRewardsDuration(default is 7 days). - Transfer the reward budget to the contract.
- The rewards distributor calls
notifyRewardAmount(reward)to begin the epoch. - Users approve and
stake, then claim withgetRewardor unwind withexit.
Released under the MIT License.