Smart contract APIs

InfraredVault.sol

Git source coming soon

The purpose of InfraredVault.sol is to create a simple and general API that can host all tokenized liquidity positions and reflect them on proof-of-liquidity. It is built in a familiar and robust APIs for staking, and streaming rewards on a per second basis. This Smart contract will be used for all staking, including LP tokens, and iBGT. It allows multi rewards to be accrued (1 stake token, many reward tokens).

Inherits: ReentrancyGuard, Pausable, IMultiRewards

Fork of MultiRewards with hooks on stake/withdraw of LP tokens

State variables

stakingToken

IERC20 public stakingToken;

rewardTokens

address[] public rewardTokens;

userRewardPerTokenPaid

mapping(address => mapping(address => uint256)) public userRewardPerTokenPaid;

rewards

mapping(address => mapping(address => uint256)) public rewards;

rewardsVault

IBerachainRewardsVault public rewardsVault;

Functions

totalSupply

Returns the number of staked tokens.

function totalSupply() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256uint256 The number of staked tokens.

balanceOf

Returns the balance of staked tokens for the given account.

function balanceOf(address account) external view returns (uint256 _balance);

Parameters

NameTypeDescription
accountaddressaddress The account to get the balance for.

Returns

NameTypeDescription
_balanceuint256uint256 The balance of staked tokens.

lastTimeRewardApplicable

Calculates the last time reward is applicable for a given rewards token.

This function returns the minimum between the current block timestamp and the period finish time of the rewards token.

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

Parameters

NameTypeDescription
_rewardsTokenaddressaddress The address of the rewards token.

Returns

NameTypeDescription
<none>uint256uint256 value representing the last time reward is applicable.

rewardPerToken

Calculates the reward per token for a given rewards token.

This function returns the stored reward per token if the total supply is 0. Otherwise, it calculates the reward per token by adding the stored reward per token to the product of the reward rate and the time difference between the last applicable time for rewards and the last update time, multiplied by 1e18 and divided by the total supply.

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

Parameters

NameTypeDescription
_rewardsTokenaddressaddress The address of the rewards token.

Returns

NameTypeDescription
<none>uint256A uint256 value representing the reward per token.

earned

Calculates the earned rewards for a given account and rewards token.

This function calculates the earned rewards by multiplying the account balance by the difference between the reward per token and the paid reward per token for the account, dividing by 1e18, and adding the rewards for the account.

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

Parameters

NameTypeDescription
accountaddressaddress The address of the account.
_rewardsTokenaddressaddress The address of the rewards token.

Returns

NameTypeDescription
<none>uint256uint256 value representing the earned rewards.

getRewardForDuration

Calculates the total reward for the duration of a given rewards token.

This function calculates the total reward by multiplying the reward rate by the rewards duration for the given rewards token.

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

Parameters

NameTypeDescription
_rewardsTokenaddressaddress The address of the rewards token.

Returns

NameTypeDescription
<none>uint256uint256 value representing the total reward for the duration.

stake

Stakes the given amount of tokens for the user (msg.sender).

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

Parameters

NameTypeDescription
amountuint256uint256 The amount of tokens to stake.

onStake

Hook called in the stake function after transfering staking token in

function onStake(uint256 amount) internal virtual;

Parameters

NameTypeDescription
amountuint256The amount of staking token transferred in to the contract

withdraw

Withdraws the staked tokens for the user (msg.sender).

function withdraw(uint256 amount)
    public
    nonReentrant
    updateReward(msg.sender);

Parameters

NameTypeDescription
amountuint256uint256 The amount of staked tokens to withdraw.

onWithdraw

Hook called in withdraw function before transferring staking token out

function onWithdraw(uint256 amount) internal virtual;

Parameters

NameTypeDescription
amountuint256The amount of staking token to be transferred out of the contract

getRewardForUser

Claims the rewards for the given user.

function getRewardForUser(address _user)
    public
    nonReentrant
    updateReward(_user);

Parameters

NameTypeDescription
_useraddressaddress The address of the user to claim the rewards for.

onReward

Hook called in getRewardForUser function after updating rewards

function onReward() internal virtual;

getReward

Claims all pending rewards for msg sender.

Change from forked MultiRewards.sol to allow for claim of reward for any user to their address

function getReward() public;

exit

Withdraws the staked tokens and all rewards for the user.

function exit() external;

On this page