0

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.

0

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.

| improve this answer | |

Your Answer

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

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