Reward Handler

Contract in charge of handling the initial bootstrap of CTX for the users that minted the TCAP Token.

Code

RewardHandler.sol

Address

Mainnet

ContractAddress
ETH RewardHandler0x5b577578565c2404bb84e734f583cf8523236ef1
DAI RewardHandler0xe0c99c503c4ae5ec50ac63c59c7ef4725c355fdd

Rinkeby

ContractAddress
ETH RewardHandler0x9e6ad39935AA04f3e1801205D4a8Ee1d9bEeFF11
DAI RewardHandler0x2E0a511DD1d4aB8EB3F9c0441CfCcde19C9544F0

Public Variables

IERC20 public immutable rewardsToken;

Address of the reward.

address public immutable vault;

Address of the vault.

uint256 public periodFinish = 0;

Tracks the period where users stop earning rewards.

uint256 public rewardRate = 0;

Tracks the current reward rate.

uint256 public rewardsDuration = 14 days;

How long the rewards lasts, it updates when more rewards are added.

uint256 public lastUpdateTime;

Last time rewards were updated.

uint256 public rewardPerTokenStored;

Amount of reward calculated per token stored.

mapping(address => uint256) public userRewardPerTokenPaid;

Track the rewards paid to users.

mapping(address => uint256) public rewards;

Tracks the user rewards.

Private Variables

uint256 private _totalSupply;

Tracks the total supply of the minted TCAPs.

mapping(address => uint256) private _balances;

Tracks the amount of TCAP minted per user.

Events

Events are called each time the state changes on the contract.

event RewardAdded(uint256 reward);

An event emitted when a reward is added.

event Staked(address indexed user, uint256 amount);

An event emitted when TCAP is minted and staked to earn rewards

event Withdrawn(address indexed user, uint256 amount);

An event emitted when TCAP is burned and removed of stake.

event RewardPaid(address indexed user, uint256 reward);

An event emitted when reward is paid to a user.

event RewardsDurationUpdated(uint256 newDuration);

An event emitted when the rewards duration is updated.

event Recovered(address token, uint256 amount);

An event emitted when a erc20 token is recovered.

Modifiers

updateReward

modifier updateReward(address _account);

Updates the reward and time on call.

onlyVault

modifier onlyVault();

Reverts if the caller is not a vault.

Read-Only Functions

totalSupply

function totalSupply() external view returns (uint256);

Returns the total amount of TCAP tokens minted and getting reward on this vault.

balanceOf

function balanceOf(address _account) external view returns (uint256);

Returns the amount of TCAP tokens minted and getting reward from specific user.

getRewardForDuration

function getRewardForDuration() external view returns (uint256);

Returns the Reward rate multiplied by the rewards duration time.

lastTimeRewardApplicable

function lastTimeRewardApplicable() public view returns (uint256);

Returns the minimun between current block timestamp or the finish period of rewards.

rewardPerToken

function rewardPerToken() public view returns (uint256);

Returns the calculated reward per token deposited.

earned

function earned(address _account) public view returns (uint256);

Returns the amount of reward tokens a _account has earned.

min

function min(uint256 _a, uint256 _b) public pure returns (uint256);

Returns the minimun between two variables.

State-Changing Functions

constructor

constructor(
address _owner,
address _rewardsToken,
address _vault
);

Called once the contract it's deployed, sets the orchestrator as owner.

stake

function stake(address _staker, uint256 _amount)
external
onlyVault
nonReentrant
whenNotPaused
updateReward(_staker);

Called when TCAP is minted, adds the minted value as stake. Only vault can call it. Updates reward on call.

exit

function exit(address _staker) external onlyVault;

Removes all stake and transfers all rewards to the staker. Only vault can call it.

notifyRewardAmount

function notifyRewardAmount(uint256 _reward)
external
onlyOwner
updateReward(address(0));

Notifies the contract that reward has been added to be given. Only owner can call it. Increases duration of rewards.

recoverERC20

function recoverERC20(address _tokenAddress, uint256 _tokenAmount)
external
onlyOwner;

Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders.

setRewardsDuration

function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner;

Updates the reward duration. Only owner can call it. Previous rewards must be complete.

withdraw

function withdraw(address _staker, uint256 _amount)
public
onlyVault
nonReentrant
updateReward(_staker);

Called when TCAP is burned or liquidated, removes the burned value as stake. Only vault can call it. Updates rewards on call.

getRewardFromVault

function getRewardFromVault(address _staker)
public
onlyVault
nonReentrant
updateReward(_staker);

Called when TCAP is burned or liquidated, transfers to the staker the current amount of rewards tokens earned. Only vault can call it. Updates rewards on call.

getReward

function getReward() public nonReentrant updateReward(msg.sender);

Transfers to the caller the current amount of rewards tokens earned. Updates rewards on call.