-
Notifications
You must be signed in to change notification settings - Fork 19
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
Optimize rewards #41
Comments
Here is the wynd link: https://github.com/cosmorama/wynddao/blob/main/contracts/wynd-stake/src/distribution.rs For some reason the other link doesn't work for me. |
The correct link is here https://github.com/cosmorama/wynddao/blob/main/contracts/wynd-stake/src/distribution.rs |
Hey guys, im redoing PR #40 to be more performant, its my first try at staking contracts so I would like to run the rewards calculation design by you to see if its correct and make sure I didn't miss anything. Same design will apply to both withdraw to consumer and withdraw to delegator, the general idea is to calculate the rewards per token per block we need to pay, we take the total rewards divide it by the total staked amount and then divide it by height from last calculation, this gives us This will allow us to remove all the bad loops I did, almost similar to DAO DAO Solution, you can see my current code which removes the loops without the calculation here: Art3miX#2 (might be easier to read the code then the PR) Details, in withdraw from validator (When we receive rewards from validator or from consumer):
Then we have
I think the calculation is correct, and should work, but there is 1 issue, I do not reset Little example:
|
I added the calculation to the PR, you can find the implementation of the calculation design in |
The above calculation was wrong, I changed to it be rewards per token, and remove the whole height factor. Validator calculation: https://github.com/CosmWasm/mesh-security/pull/40/files#diff-525d18d496dfc7f7589e3e5cc521ff82a04622c901787dc68054f9aa9da16352R174 Consumer/delegator calculation: https://github.com/CosmWasm/mesh-security/pull/40/files#diff-525d18d496dfc7f7589e3e5cc521ff82a04622c901787dc68054f9aa9da16352R63 In general we use decimal and only send full tokens, and keep the leftover in Also added a very basic unit test for the calculation: https://github.com/CosmWasm/mesh-security/pull/40/files#diff-57f78331e53081f97e605bebd7fde48e220851e35899836db3357047ce129ee5R210 |
PR #40 is adding the withdraw rewards flow (not merged at time of writing), however it is still at proof of concept stage and not optimized at all. It is also not very robust or well tested.
@ethanfrey's comments from the review:
The DAO DAO implementation is here: https://github.com/DA0-DA0/dao-contracts/tree/main/contracts/staking/cw20-stake-external-rewards
The text was updated successfully, but these errors were encountered: