-
Notifications
You must be signed in to change notification settings - Fork 24
stETH and wstETH addresses can be saved on implementation to save gas #77
Description
The LidoSplitFactory contract holds two immutable values for the addresses of the stETH and wstETH tokens.
When new clones are deployed, these values are encoded as immutable args. This adds the values to the contract code of the clone, so that each time a call is made, they are passed as calldata along to the implementation, which reads the values from the calldata for use.
Since these values will be consistent across all clones on the same chain, it would be more gas efficient to store them in the implementation directly, which can be done with immutable storage values, set in the constructor.
This would save 40 bytes of calldata on each call to the clone, which leads to a savings of approximately 640 gas on each call.
Recommendation
- Add the following to
LidoSplit.sol:
address immutable public stETH;
address immutable public wstETH;-
Add a constructor to
LidoSplit.solwhich sets these immutable values. Solidity treats immutable values as constants and stores them directly in the contract bytecode, so they will be accessible from the clones. -
Remove
stETHandwstETHfromLidoSplitFactory.sol, both as storage values, arguments to the constructor, and arguments toclone(). -
Adjust the
distribute()function inLidoSplit.solto read the storage values for these two addresses, and remove the helper functions to read the clone's immutable arguments for these two values.