20,000 USDC
View results
Submission Details
Severity: gas
Valid

[G-03] - Convert multiple `mappings` to single mapping using `struct`.

Details

In the Stacking contract we are using 3 differnt mappings to store supplyIndex, balances and claimable rewards. These all 3 mappings connected with user address. We can convert all these 3 mappings to single mapping using struct like this;

struct User {
uint256 supplyIndex;
uint256 balance;
uint256 claimable;
}
mapping(address => User) public users;

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Staking.sol#L19-L24

Just need to update places like this;

- balances[msg.sender] += _amount;
+ users[msg.sender].balance += _amount;
- claimable[msg.sender] = 0;
+ users[msg.sender].claimable = 0;
- supplyIndex[recipient] = index_;
+ users[recipient].supplyIndex = index_;

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.