Hey guys,
I am writing a staking and locker contract but the apy is placed to be constant
Now the issue is how to store the new stake locks without creating a list of them and looping through them
Rn i am using a struct named stake that is:
struct Stake {
uint256 amount;
uint256 timein;
uint256 timelock;
uint256 reward_multiplier_index;
}
mapping(address=>Stake[]) stake;
now a normal stake ive placed timelock as the same timestamp as timein so it is withdrawable but when user unstakes i will have to loop through a list of stake structs to modify and do changes what is a more efficient way to do it.
the reward multiplier is a list with reward multiplier numbers ive used index cuz ill change the rewardmultipliers later so wont have to them all in stake's
I'd really appriciate a way cuz i think this way gas costly
Nov 3, 2022, 2:30 PM
I recommend researching stuff like Synthetix staking or MasterChef staking. Writing a gas-efficient staking contract is often not trivial
Nov 3, 2022, 2:32 PM
You dont learn much this way, If he is trying something to learn, id say take a stab at it.
Otherwise if something prod, then maybe look into forking existing contracts
Nov 3, 2022, 2:39 PM
I guess it depends on the person. I've learned a lot by studying existing contracts.
Nov 3, 2022, 2:46 PM
For sure
I learn more hands on vs reading I guess but your right; Depends on the person.
But I have used the chef contracts, and just using them hands on you can learn quite a bit too
Iv done NFT Generation if your images are layered
Nov 3, 2022, 4:05 PM