Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge StETH and Lido into the one contract #225

Merged
merged 39 commits into from
Dec 8, 2020
Merged

Conversation

ujenjt
Copy link
Member

@ujenjt ujenjt commented Dec 4, 2020

The changes are aimed to remove a lot of cross calls between the Lido and the StETH smart contracts and simplify the protocol's code.

The protocol code in the Lido contract is closely coupled with StETH token. Basic operations like deposits and reward distribution require multiple reads and writes between the Lido and the StETH contracts. This makes then costly, and doubly so because of the Aragon tax.

The pull request makes StETH a base contract for Lido, eliminating the need to the numerous cross calls. StETH is an abstract contract implementing ERC20 spec. It encapsulates the logic of share-based balances and methods like _transferShares, _mintShares and _burnShares. Note that the only virtual function is _getTotalPooledEther, and the Lido as a subclass contract implements it.

burnShares is moved to the Lido code and is wrapped with ACL role checker. Public mintShares method was deleted since only the Lido protocol is authorized to mint tokens. It does it through the internal _mintShares method.

While the current result is bigger than what we have started from, it's still bellow the maximum ethereum contract size (24576 bytes) and the total amount of the code we're deploying to the blockchain is 7644 bytes less.

Lido contract before merge: 18973 bytes
StETH contract before merge: 9993 bytes
Lido contract after merge: 21322 bytes

The updated submit method is almost twice cheaper than the current one. As every protocol user bears the gas costs of calling it, optimizing the method is quite important for the Lido.

First submit call from the address: current 158494 gas, pull version 86335 gas
Next submit calls from the address: current 146494 gas, pull version 74335 gas

@ujenjt ujenjt requested a review from skozin December 4, 2020 22:06
@ujenjt
Copy link
Member Author

ujenjt commented Dec 4, 2020

This pull is still WIP since tests related to the burnShares logic was commented out. Will update it soon.

@ujenjt ujenjt added the WIP label Dec 4, 2020
@ujenjt ujenjt force-pushed the token-refactoring branch from f38b4c3 to f3812cc Compare December 7, 2020 11:14
@ujenjt ujenjt removed the WIP label Dec 7, 2020
@ujenjt ujenjt linked an issue Dec 7, 2020 that may be closed by this pull request
@skozin skozin changed the base branch from master to develop December 8, 2020 13:52
@skozin skozin merged commit 4eabbfe into develop Dec 8, 2020
tamtamchik added a commit that referenced this pull request Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move _shares, mintShares, burnShares to Lido
4 participants