0

I am trying to write a contract where a user can come and stake his platfrom tokens and earn rewards on them. The rewards are generated on the basis of the current APY. I am trying to base the APY on another token, thus constantly modifying current APY value. With this, the rewards for a particular user will always change.

Let's say I stake 100 TST tokens. Current DPY is 1%, thus I will receive 1 TST after 1 day. Let's say DPY increase to 2%, so the rewards next day will be 2 TST, totalling to 3 TST. According to my logic, the final answer is coming to be 4 TST. Any idea how can I achieve this?

1 Answer 1

2

The formula for APY is (1+APR/n)^n)-1, where n is the number of compounding periods per year.

If the DAO compounds rewards 3 times per day, there would be 3*365=1095 compounding periods.

If the reward is 0.5% every compound, the APR would be 0.5*1095=547.5%, which would be 5.475 as a decimal.

Our example DAO would have an APY of ((1+5.475/1095)^1095)-1, which is an increase of ~234.41 times, or 23441% APY.

There's a problem, though. You want to reward the user every compounding period. Not every year. You don't actually want to calculate APY in the contract. In fact, APY is just a display metric for DAOs. The actual values set in the DAO are the frequency and reward amount per rebase.

Your example is incorrect, but I'm glad you tried it out, because it goes to show that calculating rewards based off of APY is hard and doesn't make sense. Just for reference: On the second day you are earning 2% interest on 101 TST Tokens, which would leave you with a 2.02 TST reward, not just 2 TST.

Further reading: APR vs. APY: What’s the Difference?

TL;DR: Reward the user every rebase period by the reward amount. These will probably be public variables in the DAO contract. Only calculate and display the full APY on the frontend.

5
  • Hey, thanks for your insight. I really didn't know that. Although, the project I am working on doesn't need compounded APY. So, in that case the rewards will be 2 TST for the user. I am trying to use stake per share ratio to solve this problem. Not sure if it's gonna work though. Commented May 31, 2022 at 4:47
  • It was supposed to be APR. My bad. Commented May 31, 2022 at 4:55
  • Stake per share seems like it would work. When you deposit, you get would a certain share of the amount, and your share would fluctuate based on future deposits from everyone. When it is time to withdraw, you would redeem your share of the rewards. This way, you wouldn't have to calculate APR on-chain to reward users, it would just be a display metric on your frontend. Commented May 31, 2022 at 13:20
  • Yes. That's the plan. Although I do have another doubt. Do you have discord or reddit where I could find you? Commented Jun 1, 2022 at 11:03
  • Why wouldn't you calculate the APR directly on the contract? @ShubhamSharma
    – dNyrM
    Commented Feb 18 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.