How can I distribute funds to present stakers efficiently?

Ethereum Asked by Fariha Abbasi on January 3, 2022

I am building a smart contract which keep the token holder’s eths for a while and give them rewards when they withdraw. The reward is given from the ethers collected by early withdraw of people. If someone made withdraw before the time period expires then he has to pay penalty fee and that penalty fee will be distributed to the token holders who have their deposits in contract currently at the moment when penalty fee was paid.

My question is that, how shall I do it efficiently to distribute penalty fee? The reason to ask this question is:

if penalty fee is so small then dividing it at that moment among all token holders will make each share even more smaller and i am afraid if the solidity doesn’t write 0 instead of 0.9 weis (may be)

The second point i am thinking of is that how to efficiently allocate the rewards to stakers currently present in contract? If the people who have their deposit in contract (stakers) is above hundred or thousands, then alloting the reward to each one of them will need me to iterate over the complete array or something, this will require more gas and I am not sure if it will always be successful even for million stakers?

I need to keep a record that which penalty fee is deserved by which stakers.

I am looking towards the best efficient and low gas consumption implementation.

One Answer

There are a couple cases similar to this one:

While they are dealing with ERC20 tokens, not Ether, they are essentially dealing with the same problem of how to cost-efficiently distribute funds to a large number of recipients.

If those cases are anything to go by, there is no cost-efficient way to do what you want to do. It would have to be a for loop with all the associated costs, and as the number of participants increases, the cost will continue to grow. That is to say – the idea itself will not scale.

Answered by Vasily on January 3, 2022

Add your own answers!

Related Questions

Avoiding double spending in Plasma Cash

1  Asked on December 25, 2021


Filter past events with condition

0  Asked on December 25, 2021 by simon-bachmann


fatal error when try to serve geth in ipc

1  Asked on December 23, 2021


How long did a transaction spend in the mempool?

1  Asked on December 22, 2021 by jespern


Migrate contract from testnet to mainnet

2  Asked on December 20, 2021


Is there some possibility to listen MakerDAO’s LogNote events?

1  Asked on December 20, 2021 by svitlana-moiseyenko


Call a smart contract function when condition met

1  Asked on December 18, 2021 by yohjinakamoto


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP