nftstaking
nftstaking copied to clipboard
Allow Owner To Update Token Reward Value
As an admin of the staking system (aka owner of contracts), I want to update the token reward using the onlyOwner
function so that I can change incentive at any time and incentivize early users differently from later-stage users.
Im coding a struct to create vaults in the smartcontract. This will include a vault update feature that will allow the reward math to be updated. Stay tuned.
Proposed Solution
As it's been a while since @slavakurilyak asked this question, I thought I would add the code here in case anyone wishes to add this function themselves.
@net2devcrypto you may have a better way of implementing this however I thought this would be the simplest and easiest.
You will require a new global variable underneath the totalStaked
variable:
uint256 public tokenRewards = 100000;
Change the following within the _claim
and earningInfo
functions:
rewardmath = 100000 ether * (block.timestamp - stakedAt) / 86400;
to
rewardmath = (tokenRewards * 1e18) * (block.timestamp - stakedAt) / 86400;
Finally, add a new function underneath the tokensOfOwner
function:
function setTokenRewards(uint256 _tokenRewards) public onlyOwner {
tokenRewards = _tokenRewards;
}
The above will allow the owner of the contract to update the token rewards whenever they require.