nftstaking icon indicating copy to clipboard operation
nftstaking copied to clipboard

Allow Owner To Update Token Reward Value

Open slavakurilyak opened this issue 2 years ago • 2 comments

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.

slavakurilyak avatar Mar 29 '22 22:03 slavakurilyak

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.

net2devcrypto avatar Mar 30 '22 00:03 net2devcrypto

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.

WiseBigDan721 avatar May 24 '22 14:05 WiseBigDan721