Liquidity Reward

Contract in charge of handling CTX rewards for liquidity providers.

Code

LiquidityReward.sol

Address

Mainnet

ContractAddress
ETH Liquidty Reward0xc8bb1cd417d20116387a5e0603e195ca4f3cf59a

Rinkeby

ContractAddress
ETH Liquidty Reward0x7Cc49304b0Ef50f1e3F808D1E494149Ca177DFf7
DAI Liquidty Reward0x2E0a511DD1d4aB8EB3F9c0441CfCcde19C9544F0
CTX Liquidty RewardTBD

Public Variables

IERC20 public immutable rewardsToken;

Address of the reward.

IERC20 public immutable stakingToken;

Address of the staking token.

uint256 public periodFinish = 0;

Tracks the period where users stop earning rewards.

uint256 public rewardRate = 0;

Tracks the current reward rate.

uint256 public rewardsDuration = 186 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.

uint256 public immutable vestingEnd;

Time were vesting ends.

uint256 public immutable vestingRatio;

Vesting ratio.

mapping(address => uint256) public vestingAmounts;

tracks vesting amount per user.

Private Variables

uint256 private _totalSupply;

Tracks the total supply of staked tokens.

mapping(address => uint256) private _balances;

Tracks the amount of staked tokens 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 tokens are staked to earn rewards

event Withdrawn(address indexed user, uint256 amount);

An event emitted when staked tokens are withdrawn.

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.

Read-Only Functions

totalSupply

function totalSupply() external view returns (uint256);

Returns the total amount of staked tokens.

balanceOf

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

Returns the amount of staked tokens 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 _stakingToken,
uint256 _vestingEnd,
uint256 _vestingRatio
);

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

stake

function stake(uint256 _amount)
external
nonReentrant
whenNotPaused
updateReward(msg.sender);

Transfer staking token to contract. Updates reward on call.

exit

function exit() external;

Removes all stake and transfers all rewards to the staker.

claimVest

function claimVest() external nonReentrant;

Claims all vesting amount.

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(uint256 _amount)
public
nonReentrant
updateReward(msg.sender);

Remove staking token and transfer back to staker. 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. Only 70% of reward is inmediate transfered the rest is locked into vesting