Discrete Staking Rewards | Solidity 0.8

Поділитися
Вставка
  • Опубліковано 5 жов 2024

КОМЕНТАРІ • 21

  • @smartcontractprogrammer
    @smartcontractprogrammer  Рік тому +3

    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/

  • @yyyd6559
    @yyyd6559 Рік тому +1

    Thanks for the video 👍

  • @carlitod2624
    @carlitod2624 Рік тому +1

    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
      @smartcontractprogrammer  Рік тому

      They are the same. Reward is 0 for most seconds. When reward is given out (updateRewardIndex is called), reward is > 0

    • @carlitod2624
      @carlitod2624 Рік тому +1

      @@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.

  • @tomandreii
    @tomandreii Рік тому

    Man, you are just the best!

  • @TjSpoonManJacques
    @TjSpoonManJacques Рік тому

    After FTX: WE NEED A VIDEO ON REMOVING MY MONEY FROM LOCKED SMART CONTACTS!

  • @meka4996
    @meka4996 Рік тому

    You are the superman!

  • @pulkitagarwal3228
    @pulkitagarwal3228 Рік тому

    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

    • @smartcontractprogrammer
      @smartcontractprogrammer  Рік тому

      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

    • @kkkkkkjjj
      @kkkkkkjjj 9 місяців тому

      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.

  • @marcopiccioli8691
    @marcopiccioli8691 Рік тому

    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

    • @smartcontractprogrammer
      @smartcontractprogrammer  Рік тому

      Sythetix reward contract pays reward every second
      This contract may or may not pay reward every second
      Rest of the algorithm are the same

  • @invalortone
    @invalortone Рік тому

    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
      @smartcontractprogrammer  Рік тому

      I don't know BNB

    • @invalortone
      @invalortone Рік тому

      @@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.

  • @Namids
    @Namids Рік тому

    What about the IERC20 token where is the code

  • @madisopabul
    @madisopabul Рік тому +3

    nonreentrant is missed XD lol

    • @smartcontractprogrammer
      @smartcontractprogrammer  Рік тому +1

      you might not need it if you know that the staking and reward token are not gonna do reentrancy

    • @gabkov
      @gabkov Рік тому

      Yeah ERC20 by default doesn't do reenterancy since it doesn't have a fallback. ERC777 for example does.