ZivoeRewards.sol

Staking for Native Protocol Token(s)

Introduction

This contract facilitates staking and yield distribution.

This contract has the following responsibilities:

  • Allows staking and unstaking of modular "stakingToken".

  • Allows claiming yield distributed / "deposited" to this contract.

  • Allows multiple assets to be added as "rewardToken" for distributions.

  • Vests rewardTokens linearly overtime to stakers.

State Variables

TypeNameDescription

address

GBL

The ZivoeGlobals contract.

address[]

rewardTokens

Array of ERC20 tokens distributed as rewards (if present).

uint256

_totalSupply

Total supply of (non-transferrable) LP tokens for reards contract.

rewardData

Contains rewards information for each rewardToken.

mapping(address => mapping(address => (uint256))

accountRewardPerTokenPaid

The order is account -> rewardAsset -> amount.

mapping(address => mapping(address => (uint256))

rewards

The order is account -> rewardAsset -> amount.

mapping(address => uint256)

_balances

Contains LP token balance of each account (is 1:1 ratio with amount deposited).

IERC20

stakingToken

IERC20 wrapper for the stakingToken (deposited to receive LP tokens).

Reward

This struct stores information for reward tokens.

TypeNameDescription

uint256

rewardsDuration

How long rewards take to vest, e.g. 30 days.

uint256

periodFinish

When current rewards will finish vesting.

uint256

rewardRate

Rewards emitted per second.

uint256

lastUpdateTime

Last time this data struct was updated.

uint256

rewardPerTokenStored

Last snapshot of rewardPerToken taken.

Sections

Read Functions

  • balanceOf() - Returns the amount of tokens owned by "account", received when depositing via stake().

  • getRewardForDuration() - Returns the total amount of rewards being distributed to everyone for current rewardsDuration.

  • totalSupply() - Returns the amount of tokens in existence; these are minted and burned when depositing or withdrawing.

  • viewAccountRewardPerTokenPaid() - Returns the last snapshot of rewardPerTokenStored taken for a reward asset.

  • viewRewards() - Returns the rewards earned of a specific rewardToken for an address.

  • earned() - Provides information on the rewards available for claim.

  • lastTimeRewardApplicable() - Helper function for assessing distribution timelines.

  • rewardPerToken() - Cumulative amount of rewards distributed per LP token.

Write Functions

  • addReward() - Adds a new asset as a reward to this contract.

  • depositReward() - Deposits a reward to this contract for distribution.

  • fullWithdraw() - Simultaneously calls withdraw() and getRewards() for convenience.

  • stake() - Stakes the specified amount of stakingToken to this contract.

  • stakeFor() - Stakes the specified amount of stakingToken to this contract, awarded to someone else.

  • getRewards() - Claim rewards for all possible _rewardTokens.

  • withdraw() - Withdraws the specified amount of stakingToken from this contract.

Events

Read Functions

balanceOf()

Returns the amount of tokens owned by "account", received when depositing via stake().

function balanceOf(
    address account
) external view returns (uint256 amount);
TypeNameDescription

address

account

The account to view information of.

Returns

TypeNameDescription

uint256

amount

The amount of tokens owned by "account".

getRewardForDuration()

Returns the total amount of rewards being distributed to everyone for current rewardsDuration.

function getRewardForDuration(
    address _rewardsToken
) external view returns (uint256 amount);
TypeNameDescription

address

_rewardsToken

The asset that's being distributed.

Returns

TypeNameDescription

uint256

amount

The amount of rewards being distributed.

totalSupply()

Returns the amount of tokens in existence; these are minted and burned when depositing or withdrawing.

function totalSupply() external view returns (uint256 amount);

Returns

TypeNameDescription

uint256

amount

The amount of tokens in existence.

viewAccountRewardPerTokenPaid()

Returns the last snapshot of rewardPerTokenStored taken for a reward asset.

function viewAccountRewardPerTokenPaid(
    address account, 
    address rewardAsset
) external view returns (uint256 amount);
TypeNameDescription

address

account

The account to view information of.

address

rewardAsset

The reward token for which we want to return the rewardPerTokenstored.

Returns

TypeNameDescription

uint256

amount

The latest up-to-date value of rewardPerTokenStored.

viewRewards()

Returns the rewards earned of a specific rewardToken for an address.

function viewRewards(
    address account,
    address rewardAsset
) external view returns (uint256 amount);
TypeNameDescription

address

account

The account to view information of.

address

rewardAsset

The asset earned as a reward.

Returns

TypeNameDescription

uint256

amount

The amount of rewards earned.

earned()

Provides information on the rewards available for claim.

function earned(
    address account, 
    address _rewardsToken
) public view returns (uint256 amount);
TypeNameDescription

address

account

The account to view information of.

address

_rewardsToken

The asset that's being distributed.

Returns

TypeNameDescription

uint256

amount

The amount of rewards earned.

lastTimeRewardApplicable()

Helper function for assessing distribution timelines.

function lastTimeRewardApplicable(
    address _rewardsToken
) public view returns (uint256 timestamp); 
TypeNameDescription

address

_rewardsToken

The asset that's being distributed.

Returns

TypeNameDescription

uint256

timestamp

The most recent time (in UNIX format) at which rewards are available for distribution.

rewardPerToken()

Cumulative amount of rewards distributed per LP token.

function rewardPerToken(
    address _rewardsToken
) public view returns (uint256 amount);
TypeNameDescription

address

_rewardsToken

The asset that's being distributed.

Returns

TypeNameDescription

uint256

amount

The cumulative amount of rewards distributed per LP token.

Write Functions

addReward()

Adds a new asset as a reward to this contract.

function addReward(
    address _rewardsToken, 
    uint256 _rewardsDuration
) external;
TypeNameDescription

address

_rewardsToken

The asset that's being distributed

uint256

_rewardsDuration

How long rewards take to vest, e.g. 30 days (denoted in seconds).

Emits the RewardAdded() event

depositReward()

Deposits a reward to this contract for distribution.

function depositReward(
    address _rewardsToken, 
    uint256 reward
) external updateReward(address(0)) nonReentrant;
TypeNameDescription

address

_rewardsToken

The asset that's being distributed.

uint256

reward

The amount of the _rewardsToken to deposit.

Emits the RewardDeposited() event

fullWithdraw()

Simultaneously calls withdraw() and getRewards() for convenience.

function fullWithdraw() external;

Emits the Withdrawn() and RewardDistributed() event(s)

stake()

Stakes the specified amount of stakingToken to this contract.

function stake(uint256 amount) external nonReentrant updateReward(_msgSender());
TypeNameDescription

uint256

amount

The amount of the _rewardTokens to deposit.

Emits the Staked() event

stakeFor()

Stakes the specified amount of stakingToken to this contract, awarded to someone else.

function stakeFor(
    uint256 amount, 
    address account
) external nonReentrant updateReward(account);
TypeNameDescription

uint256

amount

The amount of the _rewardsToken to deposit.

address

account

The account to stake for (that ultimately receives the stake).

Emits the StakedFor() event

getRewards()

Claim rewards for all possible _rewardTokens.

function getRewards() public updateReward(_msgSender());

Emits the RewardDistributed() event

withdraw()

Withdraws the specified amount of stakingToken from this contract.

function withdraw(uint256 amount) public nonReentrant updateReward(_msgSender());
TypeNameDescription

uint256

amount

The amount of the _rewardsToken to withdraw.

Emits the Withdrawn() event

Events

RewardAdded()

Emitted during addReward()

event RewardAdded(address indexed reward);
TypeIndexedNameDescription

address

True

reward

The asset that's being distributed.

RewardDeposited()

Emitted during depositReward()

event RewardDeposited(
    address indexed reward, 
    uint256 amount, 
    address indexed depositor
);
TypeIndexedNameDescription

address

True

reward

The asset that's being deposited.

uint256

False

amount

The amount deposited.

address

True

depositor

The _msgSender() who deposited said reward.

RewardDistributed()

Emitted during #getrewardat

event RewardDistributed(
    address indexed account, 
    address indexed rewardsToken, 
    uint256 reward
);
TypeIndexedNameDescription

address

True

account

The account receiving a reward.

address

True

rewardsToken

The ERC20 asset distributed as a reward.

uint256

False

reward

The amount of "rewardsToken" distributed.

Staked()

Emitted during stake()

event Staked(address indexed account, uint256 amount);
TypeIndexedNameDescription

address

True

account

The account staking "stakingToken".

uint256

False

amount

The amount of "stakingToken" staked.

StakedFor()

Emitted during stakeFor()

event StakedFor(
    address indexed account, 
    uint256 amount, 
    address indexed by
);
TypeIndexedNameDescription

address

True

account

The account receiveing the staked position of "stakingToken".

uint256

False

amount

The amount of "stakingToken" staked.

address

True

by

The account facilitating the staking.

Withdrawn()

Emitted during withdraw()

event Withdrawn(address indexed account, uint256 amount);
TypeIndexedNameDescription

address

True

account

The account withdrawing "stakingToken".

uint256

False

amount

The amount of "stakingToken" to withdraw.

Last updated

Zivoe Finance - Official Documentation