Staking Rewards - Math, Examples and Algorithm | DeFi

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

КОМЕНТАРІ • 18

  • @smartcontractprogrammer
    @smartcontractprogrammer  2 роки тому +1

    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/

  • @bradsandilands6087
    @bradsandilands6087 2 роки тому +3

    Such a clever way to efficiently calculate rewards. Very good explanation as usual thanks.

  • @bearwolffish
    @bearwolffish 2 роки тому +3

    lowkey mvp

  • @teewhy3828
    @teewhy3828 2 роки тому +2

    Can you derive APR from the rewards per token?

  • @vishalkulkarni3977
    @vishalkulkarni3977 2 роки тому +2

    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?

  • @MrCoreyTexas
    @MrCoreyTexas 7 місяців тому +1

    Again, I don't know why you just don't call totalSupply totalStaked. Naming variables in programming is actually a lot of the work :)

  • @rajatarora9269
    @rajatarora9269 2 роки тому +1

    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.

  • @kszarkiewicz
    @kszarkiewicz 5 місяців тому

    you're awesome

  • @juliomendez177
    @juliomendez177 2 роки тому +1

    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?

  • @exserentia
    @exserentia 2 роки тому +1

    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.

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 роки тому +1

      No. The algorithm is efficient. It's basically users shares * (current reward per token - user's last reward per token)

  • @MrCoreyTexas
    @MrCoreyTexas 7 місяців тому

    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.

  • @tieule363
    @tieule363 2 роки тому

    How to implement pause reward ?

  • @ProspersPlace
    @ProspersPlace 2 роки тому +2

    Do you do any free lancing?

  • @DeepakKumar-vn5qx
    @DeepakKumar-vn5qx 2 роки тому

    what is the k stands for here?

    • @MrCoreyTexas
      @MrCoreyTexas 7 місяців тому

      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.