I was getting thrown off by exactly what R was, so I made it simple for me. Pretend that up to 1000 reward tokens are going to be given out over 1000 seconds. So R is just 1, each second, 1 reward token is up for grabs. Provided some tokens are actually staked. If 0 tokens are staked in a 1 second period, no rewards are available for that second. Let me know if I have this wrong.
Am I getting this right.. So one person's cost to execute the function scales linearly against the number of operations executed by all users between entering and exiting? It seems horribly inefficient to have to calculate these values on chain, per each staking and unstaking action.. and you must create new storage for the total rewards as well as staked-total data each time they change which accumulates over time. Not to mention there's probably no storage cleanup due to inefficiencies of having to calculate who remains in pool.
It would be great if you build a smart-contract on the above logic described. I am not saying to spoon-feed us but at-least we people have some reference.
k is just the time the user stakes their tokens, and n is the time where they unstake. Maybe it would have been better to just have the time be from a to b? k and n are used a lot in mathematics though as a convention. Note that the letter k comes before the letter n in the alphabet, and in the example, k is before n in time in seconds.
0:00 - Overview
2:00 - Math
5:51 - Examples 1
10:50 - More Math
18:24 - Examples 2
37:42 - Algorithm
Code
solidity-by-example.org/defi/staking-rewards/
Notes
github.com/t4sk/notes
Take a course
www.smartcontract.engineer/
Such a clever way to efficiently calculate rewards. Very good explanation as usual thanks.
lowkey mvp
you're awesome
I was getting thrown off by exactly what R was, so I made it simple for me. Pretend that up to 1000 reward tokens are going to be given out over 1000 seconds. So R is just 1, each second, 1 reward token is up for grabs. Provided some tokens are actually staked. If 0 tokens are staked in a 1 second period, no rewards are available for that second. Let me know if I have this wrong.
Can you derive APR from the rewards per token?
what if carol stakes 100 at 6 sec and alice withdraw a100 at 6 sec how is total supply token is calculat,Ti is calculated?
Am I getting this right..
So one person's cost to execute the function scales linearly against the number of operations executed by all users between entering and exiting?
It seems horribly inefficient to have to calculate these values on chain, per each staking and unstaking action.. and you must create new storage for the total rewards as well as staked-total data each time they change which accumulates over time.
Not to mention there's probably no storage cleanup due to inefficiencies of having to calculate who remains in pool.
No. The algorithm is efficient. It's basically users shares * (current reward per token - user's last reward per token)
It would be great if you build a smart-contract on the above logic described. I am not saying to spoon-feed us but at-least we people have some reference.
Do you do any free lancing?
no
How to implement pause reward ?
What fields of knowledge and at what level do you have to have in mathematics to be able to develop defi?
Is there a place to learn it?
high school math
Again, I don't know why you just don't call totalSupply totalStaked. Naming variables in programming is actually a lot of the work :)
what is the k stands for here?
k is just the time the user stakes their tokens, and n is the time where they unstake. Maybe it would have been better to just have the time be from a to b? k and n are used a lot in mathematics though as a convention. Note that the letter k comes before the letter n in the alphabet, and in the example, k is before n in time in seconds.