In a naive implementation, the staking contract would push fractional payments to all the participants each time a reward gets distributed. However, in such an implementation the distribute function would take O(N) time to compute, where N is the number of participants.

Is there a better solution?

I've been working on the fractional approach pegged on block number instead of time

Distribution of rewards among stakeholders iterating over an array of stakeholders is inefficient in terms of gas spending. Therefore to calculate the reward since the last reward calculation requires keeping the sum of rewards at block #X and total staked at block #X. Hence, on each reward addition, we need to keep an array of the sum of stakes at a specific block number. And the second array is for the sum of rewards at a specific block number. It's becoming quite complicated. To keep it non-reentrant along with an ever-growing 2 array of sums.

Need some input on how to implement this on-chain

  • can you do total fund available divided by total number of stake holders? that way, its easy to give fund according to their share perfectage. Jan 24 at 4:44
  • @Yogesh-EtherAuthority.io If user1 owns 90% and user2 owns 10% that would be unfair Jan 24 at 6:36
  • А можешь изложить проблему по-русски? А то, боюсь, я не понимаю сути в дебрях обратного перевода.
    – Mad Jackal
    Jan 24 at 10:30
  • @MadJackal Участники стейкинга делают депозит разными суммами в разный период времени, то есть в разный период времени общий % юзера отличается. Потом в контракт приходит reward, который надо распределить среди участников стейкинга согласно их % участия и длительности стейкинга Jan 24 at 13:10
  • @MadJackal Есть push распределение, которое даже не рассматривается из-за больших расходов на газ, а есть pull, при котором каждый стейкер снимает сам свою долю, но тогда эту долю надо рассчитать в каждый период времени, когда участник делает депозит или снятие Jan 24 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.