Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(StakeManager): allow users to customize and change reward address #138

Open
3esmit opened this issue Sep 27, 2024 · 4 comments
Open

Comments

@3esmit
Copy link
Collaborator

3esmit commented Sep 27, 2024

Currently it automatically uses StakeVault.owner() which might not be desirable for all cases.

@Pranay-Bhilare
Copy link

I would like to contribute on this issue, here's how I would think implementing this:

  1. We would make a setRewardAddress function, in StakeVault contract, from which the users will interact.

  2. This function call will internally call, setRewardAddress function, which would be implemented in StakeManager contract

  3. In StakeManager::setRewardAddress() function, we would set the Account struct's rewardAddress parameter, i.e accounts[msg.sender].rewardAddress as the address being passed as parameter while calling the function.

  4. Now while staking , in VaultManager::stake(), first we will check whether the accounts[msg.sender].rewardAddress is containing a ZERO address or not.
    If yes, then , already exisiting implementation , i.e rewardAddress being set to the vault's owner would work.
    If not, it means the user has already set the rewardAddress.

  5. Then an event can be added in StakeVault contract, after setting reward address is being completed.

And of course using the setRewardAddress function, users can anytime set/change their Reward Address

Would this work ?
If yes, would like to work on PR for it for sure.

@3esmit
Copy link
Collaborator Author

3esmit commented Sep 30, 2024

I'm not sure yet , I Think would be better to just send back the reward to StakeVault and StakeVault be changed to be able to deal with this

@Pranay-Bhilare
Copy link

If this is the required way of implementation, here's how I think it can be implemented :

  1. A storage variable can be added in StakeVault as rewardAddress, which can be set/changed by the user by using setRewardAddress function.

  2. While StakeManager::_processAccount, after reward calculation , i.e. in the if ( userReward > 0 ) block, after transferring the amount to the vault, an internal function call should be made, which would be implemented in StakeVault contract.

  3. Lets say that internal function is named as _processReward, now in this function , the funds that were transferred into the StakeVault , would be transferred further to the rewardAddress.

So the flow would be something like this :

StakeManager::_processAccount() ---> if userReward > 0 ---> stakedToken.transfer(account.rewardAddress / stakeVaultAddress, userReward) & StakeVault::_processReward(userReward) ---> transfer userReward to rewardAddress set by user.

NOTE : The account.rewardAddress in this case will always be set to the following user's StakeVault only, i.e the msg.sender while StakeManager::stake() function call.
So accordingly the account.rewardAddress should be set to msg.sender instead of StakeVault(msg.sender).owner()

Also, the rewardAddress parameter will be set to msg.sender by default while StakeVault::stake() function call done by user, if there's no address already being set to rewardAddress.

@Pranay-Bhilare
Copy link

I Think would be better to just send back the reward to StakeVault and StakeVault be changed to be able to deal with this

Is this being thought with the consideration of issue #137 ?? That user then would be able to use StakeVault for getting the reward.
If yes, then instead of directly sending reward to the user, implementing a claiming reward function in StakeVault, by which users will claim their reward sent from StakeManager to StakeVault, will easily handle both issue.

And since this would be a PULL method , instead of PUSH , security wise also it would be a better option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants