Good morning everyone. I have a problem, I'm thinking about it but the only solution I found at the moment is very expensive.
Imagine that we have a token, we know all the holders of this token. And now just for having this token, we want to give you even more tokens. For example if your balance today was higher than 0, at the end of the day you have your balance + "X" that the system gives you as a reward for logging the token. On the other hand "X" is not the same for all holders, sistema earns "Y" every day, then every 24 hours this "Y" has to be distributed among all holders depending on their amount of tokens in the balance, the more tokens you have, the bigger your daily reward will be.
For example:
- User 1 has 10 tokens.
- User 2 has 90 tokens.
- 24 hours pass, system has earned 10 tokens.
System distributes these 10 tokens between 2 holders:
- User 1 receives 1 token. His balance will be 11 tokens.
- User 2 receives 9 tokens. His balance will be 99 tokens.
The only way I see now as a solution is to create a for to go through all the holders, but if we have a lot of holders, the cost of this operation will be huge and it has to be in sections, because if we have 20000 holders we can't go through them in the same for, we will run out of gas.
So what I have thought is to create a function to which we pass the index range of the holders and how many tokens we have to distribute among them. And so call it several times, until everything is distributed. As far as I understand it is the worst solution to the problem. Any other ideas?