Thank you for your videos and your outstanding work! In your video explaining the maths, you say that the amount of rewards changes every second, this is not the case in this contract. Can you please explain the similarities and differences between the two videos?
@@smartcontractprogrammer So I'm not sure I understand the purpose of this contract. The aim is to share a sum of reward equally between all the stakers at a given time? What I understand in this example, When the owner (or the reward issuer) uses the updateRewardIndex function, the rewardIndex is calculated, which is then used to share the total reward among the stakers. I don't see when the rewardIndex is automatically updated every second. Moreover Alice can arrive afterwards, stake the same amount as Bob (the staker in the example) and steal his reward (if he hasn't claimed before her). In short, I don't think I understood anything about the functioning, the purpose and the use case of such a contract. Could you explain it to me? Sorry for the inconvenience.
Hi @smartcontractprogrammer, I have a few questions : 1. Nowhere in the contract we see the rewardIndex being set or changed. Why is that ? 2. Also, don't you think the reward Index should change during stake, unstake or claim ? Let's say, during stake the deposits increase and reward token per person should decrease , shouldn't the rewardIndex be changes as well ? Any reason to skip it
1. 4:15 2. reward index must be update only when the reward is transferred into the contract. Reward index of user must be updated on deposit, withdraw and claim
But how does the rewardIndex is different for Alice and Bob, according to theroy section the rewardIndex for Alice is r4 and Bob is r7, but according to code in function _calculateRewards in return statement "return (shares * (rewardIndex - rewardIndexOf[account])) / MULTIPLIER;" here rewardIndex will be same for Alice and Bob, i mean to say rewardIndex seems independent of user which contradicts the theory section of the video.
Thanks for this video. High quality stuff as usual. One question: Synthetix staking implies a fixed reward (like block based) and a variable staking amount, this new discrete staking contract seems to imply the opposite: variable reward and a fixed staking amount. The discrete staking contract can handle a dynamic user staking amount? In your algo explanation you show Alice staking 2000 tokens from t0 to t6. What happens if Alice stakes 1000 tokens more at t5? Thanks a lot
Good evening, your videos are highly informative and easy to understand. Can you possibly tell me how can I make the rewards token BNB? Its been a few months since I've started learning Solidity so I'm kind of a beginner. Thank you once again for your videos.
@@smartcontractprogrammer Thank you for answering me, what about sending Ether? I've heard that both are technically the same because of their similar 18 decimals and when deployed Ether is automatically replaced with BNB.
Video explaining the math here
ua-cam.com/video/mo6rHnDU8us/v-deo.html
0:00 - Intro
0:22 - Constructor
1:16 - State variables
3:14 - updateRewardIndex
4:40 - calculateRewards
6:30 - updateRewards
8:07 - stake
8:45 - unstake
9:07 - claim
10:27 - Demo
Code
solidity-by-example.org/defi/discrete-staking-rewards/
Take a course
www.smartcontract.engineer/
Thanks for the video 👍
Thank you for your videos and your outstanding work!
In your video explaining the maths, you say that the amount of rewards changes every second, this is not the case in this contract.
Can you please explain the similarities and differences between the two videos?
They are the same. Reward is 0 for most seconds. When reward is given out (updateRewardIndex is called), reward is > 0
@@smartcontractprogrammer So I'm not sure I understand the purpose of this contract.
The aim is to share a sum of reward equally between all the stakers at a given time?
What I understand in this example,
When the owner (or the reward issuer) uses the updateRewardIndex function, the rewardIndex is calculated, which is then used to share the total reward among the stakers. I don't see when the rewardIndex is automatically updated every second. Moreover Alice can arrive afterwards, stake the same amount as Bob (the staker in the example) and steal his reward (if he hasn't claimed before her).
In short, I don't think I understood anything about the functioning, the purpose and the use case of such a contract. Could you explain it to me?
Sorry for the inconvenience.
Man, you are just the best!
After FTX: WE NEED A VIDEO ON REMOVING MY MONEY FROM LOCKED SMART CONTACTS!
You are the superman!
Hi @smartcontractprogrammer, I have a few questions :
1. Nowhere in the contract we see the rewardIndex being set or changed. Why is that ?
2. Also, don't you think the reward Index should change during stake, unstake or claim ? Let's say, during stake the deposits increase and reward token per person should decrease , shouldn't the rewardIndex be changes as well ? Any reason to skip it
1. 4:15
2. reward index must be update only when the reward is transferred into the contract. Reward index of user must be updated on deposit, withdraw and claim
But how does the rewardIndex is different for Alice and Bob, according to theroy section the rewardIndex for Alice is r4 and Bob is r7, but according to code in function _calculateRewards in return statement "return (shares * (rewardIndex - rewardIndexOf[account])) / MULTIPLIER;" here rewardIndex will be same for Alice and Bob, i mean to say rewardIndex seems independent of user which contradicts the theory section of the video.
Thanks for this video. High quality stuff as usual.
One question: Synthetix staking implies a fixed reward (like block based) and a variable staking amount, this new discrete staking contract seems to imply the opposite: variable reward and a fixed staking amount.
The discrete staking contract can handle a dynamic user staking amount? In your algo explanation you show Alice staking 2000 tokens from t0 to t6. What happens if Alice stakes 1000 tokens more at t5?
Thanks a lot
Sythetix reward contract pays reward every second
This contract may or may not pay reward every second
Rest of the algorithm are the same
Good evening, your videos are highly informative and easy to understand. Can you possibly tell me how can I make the rewards token BNB? Its been a few months since I've started learning Solidity so I'm kind of a beginner. Thank you once again for your videos.
I don't know BNB
@@smartcontractprogrammer Thank you for answering me, what about sending Ether? I've heard that both are technically the same because of their similar 18 decimals and when deployed Ether is automatically replaced with BNB.
What about the IERC20 token where is the code
You don't need it if you declare an interface
nonreentrant is missed XD lol
you might not need it if you know that the staking and reward token are not gonna do reentrancy
Yeah ERC20 by default doesn't do reenterancy since it doesn't have a fallback. ERC777 for example does.