This double division by BASE can be eliminated to improve precision and reduce gas costs:
uint256 tokensNeeded = basketAsERC20.totalSupply() pendingWeights[i] newRatio / BASE / BASE;
Recommended Mitigation Steps
if you introduce a constant variable, e.g.:
uint256 private constant BASE_2X = BASE 2;
uint256 tokensNeeded = basketAsERC20.totalSupply() pendingWeights[i] * newRatio / BASE_2X;
Agree with the gas cost reduction as the value of BASE_2X will be inlined in the bytecode
Can't confirm on the precision as you're still dividing by the same value
Handle
pauliax
Vulnerability details
Impact
This double division by BASE can be eliminated to improve precision and reduce gas costs: uint256 tokensNeeded = basketAsERC20.totalSupply() pendingWeights[i] newRatio / BASE / BASE;
Recommended Mitigation Steps
if you introduce a constant variable, e.g.: uint256 private constant BASE_2X = BASE 2; uint256 tokensNeeded = basketAsERC20.totalSupply() pendingWeights[i] * newRatio / BASE_2X;