InfraredVault

Git Source

Inherits: MultiRewards, IInfraredVault

This contract is the vault for staking tokens, and receiving rewards from the Proof of Liquidity protocol.

This contract uses the MultiRewards contract to distribute rewards to vault stakers, this is taken from curve.fi. (inspired by Synthetix).

Does not support staking tokens with non-standard ERC20 transfer tax behavior.

State Variables

MAX_NUM_REWARD_TOKENS

Maximum number of reward tokens that can be supported

Limited to prevent gas issues with reward calculations

uint256 public constant MAX_NUM_REWARD_TOKENS = 10;

infrared

The infrared contract address acts a vault factory and coordinator

address public immutable infrared;

rewardsVault

IBerachainRewardsVault public immutable rewardsVault;

Functions

onlyInfrared

Modifier to check that the caller is infrared contract

modifier onlyInfrared();

constructor

constructor(address _stakingToken, uint256 _rewardsDuration)
    MultiRewards(_stakingToken);

_createRewardsVaultIfNecessary

Gets or creates the berachain rewards vault for given staking token

function _createRewardsVaultIfNecessary(
    address _infrared,
    address _stakingToken
) private returns (IBerachainRewardsVault);

Parameters

NameTypeDescription
_infraredaddressThe address of Infrared
_stakingTokenaddressThe address of the staking token for this vault

Returns

NameTypeDescription
<none>IBerachainRewardsVaultThe address of the berachain rewards vault

onStake

Transfers to berachain low level module on staking of LP tokens with the vault after transferring tokens in

function onStake(uint256 amount) internal override;

Parameters

NameTypeDescription
amountuint256The amount of staking token transferred in to the contract

onWithdraw

Redeems from berachain low level module on withdraw of LP tokens from the vault before transferring tokens out

function onWithdraw(uint256 amount) internal override;

Parameters

NameTypeDescription
amountuint256The amount of staking token transferred out of the contract

onReward

hook called after the reward is claimed to harvest the rewards from the berachain rewards vault

function onReward() internal override;

updateRewardsDuration

Updates reward duration for a specific reward token

Only callable by Infrared contract

Note: access-control: Requires INFRARED_ROLE

function updateRewardsDuration(address _rewardsToken, uint256 _rewardsDuration)
    external
    onlyInfrared;

Parameters

NameTypeDescription
_rewardsTokenaddressThe address of the reward token
_rewardsDurationuint256The new duration in seconds

togglePause

Toggles pause state of the vault

Affects all vault operations when paused

Note: access-control: Requires INFRARED_ROLE

function togglePause() external onlyInfrared;

addReward

Adds a new reward token to the vault

Cannot exceed maximum number of reward tokens

Note: access-control: Requires INFRARED_ROLE

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

Parameters

NameTypeDescription
_rewardsTokenaddressThe reward token to add
_rewardsDurationuint256The reward period duration

notifyRewardAmount

Notifies the vault of newly added rewards

Updates internal reward rate calculations

function notifyRewardAmount(address _rewardToken, uint256 _reward)
    external
    onlyInfrared;

Parameters

NameTypeDescription
_rewardTokenaddressThe reward token address
_rewarduint256The amount of new rewards

recoverERC20

Recovers accidentally sent tokens

Cannot recover staking token or active reward tokens

function recoverERC20(address _to, address _token, uint256 _amount)
    external
    onlyInfrared;

Parameters

NameTypeDescription
_toaddressThe address to receive the recovered tokens
_tokenaddressThe token to recover
_amountuint256The amount to recover

getAllRewardTokens

Returns all reward tokens

function getAllRewardTokens() external view returns (address[] memory);

Returns

NameTypeDescription
<none>address[]An array of reward token addresses

getAllRewardsForUser

Returns all rewards for a user

function getAllRewardsForUser(address _user)
    external
    view
    returns (UserReward[] memory);

Parameters

NameTypeDescription
_useraddressThe address of the user

Returns

NameTypeDescription
<none>UserReward[]An array of UserReward structs