Hello. Do someone know tools to calculate gas cost?
I have a function that possibly can out of gas limit, and I want to calculate the count of data when it gonna happen
Sep 26, 2022, 7:56 AM
This is staking contract, and after each new transaction (stake, unstake, harvest) I call updatePool. Update pool include loop that set new data for each staker
Is is possible to calculate gas cost, for example, when my contract will have 1000 stakers?
Sep 26, 2022, 7:58 AM
I would just write a script or unit test and check the gas usage
but in general you should not use an open-ended loop. ever.
Sep 26, 2022, 8:00 AM
but how can I avoid that?
In my case, after each new stake/unstake it will change totalWeight variable.
totalWeight included in formula to calculate rewards
that's why I save already calculated rewards in mapping in my updatePool function
In my case, after each new stake/unstake it will change totalWeight variable.
totalWeight included in formula to calculate rewards
that's why I save already calculated rewards in mapping in my updatePool function
Sep 26, 2022, 8:08 AM
it's a form of art. I suggest you get to to know Synthetix staking and MasterChef staking - they scale up perfectly without loops.
Sep 26, 2022, 8:11 AM
Ser do gasless yield
Let users pay for the gas
Sep 26, 2022, 8:16 AM
They already pay for the gas
but I want to know the limit of users for my contract
MasterChef and Synthetix looks good but we have a bit different formula.
Sep 26, 2022, 8:18 AM
they have a way different formula. mostly because they are efficient.
I don't know your exact business case, but your contract simply doesn't scale. Say the maximum user limit for the loop is 500. When you get your 501st user the whole function becomes useless and the whole staking contract fails.
I don't know your exact business case, but your contract simply doesn't scale. Say the maximum user limit for the loop is 500. When you get your 501st user the whole function becomes useless and the whole staking contract fails.
Sep 26, 2022, 8:50 AM
My case is next, I can't use the latest totalWeight value,
so i need to have something like totalWeight history
for example: user staked tokens when totalWeight was 1000,
after few days totalWeight become 5000,
and I want to calculate rewards using each increasing step
In contracts that I seen they just use the latest totalWeight value,
that mean when new user will stake tokens and change totalWeight it will affect other stakers rewards
so i need to have something like totalWeight history
for example: user staked tokens when totalWeight was 1000,
after few days totalWeight become 5000,
and I want to calculate rewards using each increasing step
In contracts that I seen they just use the latest totalWeight value,
that mean when new user will stake tokens and change totalWeight it will affect other stakers rewards
my ideas is to have totalWeight history with start block and end block
and when I want to calculate rewards - I will iterate totalWeight history and calculate rewards for each period
but I think its complicated
and when I want to calculate rewards - I will iterate totalWeight history and calculate rewards for each period
but I think its complicated
Sep 26, 2022, 9:04 AM
sorry, would require quite some work to get acquainted with the business case and code.
Sep 26, 2022, 10:27 AM
https://hackernoon.com/how-much-can-i-do-in-a-block-163q3xp2
Sep 29, 2022, 11:51 AM