From 4609b9b638cf219c3e24c7114794e877af568c46 Mon Sep 17 00:00:00 2001 From: Nicholas Addison Date: Fri, 9 Jul 2021 17:21:36 +1000 Subject: [PATCH] chore: Updated Boosted Vault Natspec --- .../boosted-staking/BoostedDualVault.sol | 31 ++++++++++---- .../boosted-staking/BoostedTokenWrapper.sol | 5 +++ .../rewards/boosted-staking/BoostedVault.sol | 41 +++++++++++++------ 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/contracts/rewards/boosted-staking/BoostedDualVault.sol b/contracts/rewards/boosted-staking/BoostedDualVault.sol index bb8cc534..9d47cc3e 100644 --- a/contracts/rewards/boosted-staking/BoostedDualVault.sol +++ b/contracts/rewards/boosted-staking/BoostedDualVault.sol @@ -15,7 +15,7 @@ import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { StableMath } from "../../shared/StableMath.sol"; /** - * @title BoostedVault + * @title BoostedDualVault * @author mStable * @notice Accrues rewards second by second, based on a users boosted balance * @dev Forked from rewards/staking/StakingRewards.sol @@ -24,6 +24,7 @@ import { StableMath } from "../../shared/StableMath.sol"; * - `updateBoost` hook called after every external action to reset a users boost * - Struct packing of common data * - Searching for and claiming of unlocked rewards + * - Add a second rewards token in the platform rewards */ contract BoostedDualVault is IBoostedDualVaultWithLockup, @@ -51,6 +52,7 @@ contract BoostedDualVault is /// @notice total raw balance uint256 public totalRaw; + /// @notice length of each staking period in seconds. 7 days = 604,800; 3 months = 7,862,400 uint64 public constant DURATION = 7 days; /// @notice Length of token lockup, after rewards are earned uint256 public constant LOCKUP = 26 weeks; @@ -59,7 +61,7 @@ contract BoostedDualVault is /// @notice Timestamp for current period finish uint256 public periodFinish; - /// @notice RewardRate for the rest of the PERIOD + /// @notice Reward rate for the rest of the period uint256 public rewardRate; /// @notice Platform reward rate for the rest of the period uint256 public platformRewardRate; @@ -90,32 +92,45 @@ contract BoostedDualVault is uint128 rate; } + /** + * @param _nexus mStable system Nexus address + * @param _stakingToken token that is beinf rewarded for being staked. eg MTA, imUSD or fPmUSD/GUSD + * @param _boostDirector vMTA boost director + * @param _priceCoeff Rough price of a given LP token, to be used in boost calculations, where $1 = 1e18 + * @param _boostCoeff Boost coefficent using the the boost formula + * @param _rewardsToken first token that is being distributed as a reward. eg MTA + * @param _platformToken second token that is being distributed as a reward. eg FXS for FRAX + */ constructor( address _nexus, address _stakingToken, address _boostDirector, uint256 _priceCoeff, - uint256 _coeff, + uint256 _boostCoeff, address _rewardsToken, address _platformToken ) InitializableRewardsDistributionRecipient(_nexus) - BoostedTokenWrapper(_stakingToken, _boostDirector, _priceCoeff, _coeff) + BoostedTokenWrapper(_stakingToken, _boostDirector, _priceCoeff, _boostCoeff) { rewardsToken = IERC20(_rewardsToken); platformToken = IERC20(_platformToken); } /** - * @dev StakingRewards is a TokenWrapper and RewardRecipient - * Constants added to bytecode at deployTime to reduce SLOAD cost + * @dev Initialization function for upgradable proxy contract. + * This function should be called via Proxy just after contract deployment. + * To avoid variable shadowing appended `Arg` after arguments name. + * @param _rewardsDistributorArg mStable Reward Distributor contract address + * @param _nameArg token name. eg imUSD Vault or GUSD Feeder Pool Vault + * @param _symbolArg token symbol. eg v-imUSD or v-fPmUSD/GUSD */ function initialize( - address _rewardsDistributor, + address _rewardsDistributorArg, string calldata _nameArg, string calldata _symbolArg ) external initializer { - InitializableRewardsDistributionRecipient._initialize(_rewardsDistributor); + InitializableRewardsDistributionRecipient._initialize(_rewardsDistributorArg); BoostedTokenWrapper._initialize(_nameArg, _symbolArg); platformTokenVendor = new PlatformTokenVendor(platformToken); } diff --git a/contracts/rewards/boosted-staking/BoostedTokenWrapper.sol b/contracts/rewards/boosted-staking/BoostedTokenWrapper.sol index bfa358f0..3ccbbb41 100644 --- a/contracts/rewards/boosted-staking/BoostedTokenWrapper.sol +++ b/contracts/rewards/boosted-staking/BoostedTokenWrapper.sol @@ -49,6 +49,7 @@ contract BoostedTokenWrapper is InitializableReentrancyGuard { * @param _stakingToken Wrapped token to be staked * @param _boostDirector vMTA boost director * @param _priceCoeff Rough price of a given LP token, to be used in boost calculations, where $1 = 1e18 + * @param _boostCoeff Boost coefficent using the the boost formula */ constructor( address _stakingToken, @@ -62,6 +63,10 @@ contract BoostedTokenWrapper is InitializableReentrancyGuard { boostCoeff = _boostCoeff; } + /** + * @param _nameArg token name. eg imUSD Vault or GUSD Feeder Pool Vault + * @param _symbolArg token symbol. eg v-imUSD or v-fPmUSD/GUSD + */ function _initialize(string memory _nameArg, string memory _symbolArg) internal { _initializeReentrancyGuard(); _name = _nameArg; diff --git a/contracts/rewards/boosted-staking/BoostedVault.sol b/contracts/rewards/boosted-staking/BoostedVault.sol index 0c80c52c..cc8ee6b7 100644 --- a/contracts/rewards/boosted-staking/BoostedVault.sol +++ b/contracts/rewards/boosted-staking/BoostedVault.sol @@ -39,24 +39,27 @@ contract BoostedVault is event Poked(address indexed user); event RewardPaid(address indexed user, uint256 reward); + /// @notice token the rewards are distributed in. eg MTA IERC20 public immutable rewardsToken; + /// @notice length of each staking period in seconds. 7 days = 604,800; 3 months = 7,862,400 uint64 public constant DURATION = 7 days; - // Length of token lockup, after rewards are earned + /// @notice Length of token lockup, after rewards are earned uint256 public constant LOCKUP = 26 weeks; - // Percentage of earned tokens unlocked immediately + /// @notice Percentage of earned tokens unlocked immediately uint64 public constant UNLOCK = 33e16; - // Timestamp for current period finish + /// @notice Timestamp for current period finish uint256 public periodFinish; - // RewardRate for the rest of the PERIOD + /// @notice RewardRate for the rest of the period uint256 public rewardRate; - // Last time any user took action + /// @notice Last time any user took action uint256 public lastUpdateTime; - // Ever increasing rewardPerToken rate, based on % of total supply + /// @notice Ever increasing rewardPerToken rate, based on % of total supply uint256 public rewardPerTokenStored; + mapping(address => UserData) public userData; - // Locked reward tracking + /// @notice Locked reward tracking mapping(address => Reward[]) public userRewards; mapping(address => uint64) public userClaim; @@ -73,30 +76,42 @@ contract BoostedVault is uint128 rate; } + /** + * @param _nexus mStable system Nexus address + * @param _stakingToken token that is beinf rewarded for being staked. eg MTA, imUSD or fPmUSD/GUSD + * @param _boostDirector vMTA boost director + * @param _priceCoeff Rough price of a given LP token, to be used in boost calculations, where $1 = 1e18 + * @param _boostCoeff Boost coefficent using the the boost formula + * @param _rewardsToken first token that is being distributed as a reward. eg MTA + */ constructor( address _nexus, address _stakingToken, address _boostDirector, uint256 _priceCoeff, - uint256 _coeff, + uint256 _boostCoeff, address _rewardsToken ) InitializableRewardsDistributionRecipient(_nexus) - BoostedTokenWrapper(_stakingToken, _boostDirector, _priceCoeff, _coeff) + BoostedTokenWrapper(_stakingToken, _boostDirector, _priceCoeff, _boostCoeff) { rewardsToken = IERC20(_rewardsToken); } /** - * @dev StakingRewards is a TokenWrapper and RewardRecipient - * Constants added to bytecode at deployTime to reduce SLOAD cost + * @dev Initialization function for upgradable proxy contract. + * This function should be called via Proxy just after contract deployment. + * To avoid variable shadowing appended `Arg` after arguments name. + * @param _rewardsDistributorArg mStable Reward Distributor contract address + * @param _nameArg token name. eg imUSD Vault or GUSD Feeder Pool Vault + * @param _symbolArg token symbol. eg v-imUSD or v-fPmUSD/GUSD */ function initialize( - address _rewardsDistributor, + address _rewardsDistributorArg, string calldata _nameArg, string calldata _symbolArg ) external initializer { - InitializableRewardsDistributionRecipient._initialize(_rewardsDistributor); + InitializableRewardsDistributionRecipient._initialize(_rewardsDistributorArg); BoostedTokenWrapper._initialize(_nameArg, _symbolArg); }