-
Notifications
You must be signed in to change notification settings - Fork 93
Native staking updates #2023
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
Merged
Merged
Native staking updates #2023
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8753083
Update Natspec
naddison36 d9ac43a
Generated docs for native eth strategy
naddison36 2020f8b
Prettier and linter
naddison36 97c0f54
Updated Natspec
naddison36 21294e7
Removed strategist from strategy as its already maintained in the Vault
naddison36 dde1375
Fix compilation error
naddison36 8560573
Fix unit tests
naddison36 e94858b
fix linter
naddison36 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Diagrams | ||
|
|
||
| ## Native Staking SSV Strategy | ||
|
|
||
| ### Hierarchy | ||
|
|
||
|  | ||
|
|
||
| ### Squashed | ||
|
|
||
|  | ||
|
|
||
| ### Storage | ||
|
|
||
|  | ||
|
|
||
| ## Fee Accumulator | ||
|
|
||
| ### Squashed | ||
|
|
||
|  |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,18 @@ pragma solidity ^0.8.0; | |
|
|
||
| import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol"; | ||
| import { ValidatorRegistrator } from "./ValidatorRegistrator.sol"; | ||
| import { IVault } from "../../interfaces/IVault.sol"; | ||
| import { IWETH9 } from "../../interfaces/IWETH9.sol"; | ||
|
|
||
| /// @title Accountant of the rewards Beacon Chain ETH | ||
| /// @notice This contract contains the logic to attribute the Beacon Chain swept ETH either to full | ||
| /// or partial withdrawals | ||
| /// @author Origin Protocol Inc | ||
| abstract contract ValidatorAccountant is ValidatorRegistrator { | ||
| /// @notice The maximum amount of ETH that can be staked by a validator | ||
| /// @dev this can change in the future with EIP-7251, Increase the MAX_EFFECTIVE_BALANCE | ||
| uint256 public constant MAX_STAKE = 32 ether; | ||
| /// @notice Address of the OETH Vault proxy contract | ||
| address public immutable VAULT_ADDRESS; | ||
|
|
||
| /// @dev The WETH present on this contract will come from 2 sources: | ||
|
|
@@ -23,14 +28,12 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| /// present as a result of a deposit. | ||
| uint256 public beaconChainRewardWETH = 0; | ||
|
|
||
| /// @dev start of fuse interval | ||
| /// @notice start of fuse interval | ||
| uint256 public fuseIntervalStart = 0; | ||
| /// @dev end of fuse interval | ||
| /// @notice end of fuse interval | ||
| uint256 public fuseIntervalEnd = 0; | ||
| /// @dev Governor that can manually correct the accounting | ||
| /// @notice Governor that can manually correct the accounting | ||
| address public accountingGovernor; | ||
| /// @dev Strategist that can pause the accounting | ||
| address public strategist; | ||
|
|
||
| uint256[50] private __gap; | ||
|
|
||
|
|
@@ -40,12 +43,12 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| uint256 start, | ||
| uint256 end | ||
| ); | ||
| event AccuntingFullyWithdrawnValidator( | ||
| event AccountingFullyWithdrawnValidator( | ||
| uint256 noOfValidators, | ||
| uint256 remainingValidators, | ||
| uint256 wethSentToVault | ||
| ); | ||
| event AccuntingValidatorSlashed( | ||
| event AccountingValidatorSlashed( | ||
| uint256 remainingValidators, | ||
| uint256 wethSentToVault | ||
| ); | ||
|
|
@@ -54,10 +57,6 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| address newAddress | ||
| ); | ||
| event AccountingBeaconChainRewards(uint256 amount); | ||
| event StrategistAddressChanged( | ||
| address oldStrategist, | ||
| address newStrategist | ||
| ); | ||
|
|
||
| event AccountingManuallyFixed( | ||
| uint256 oldActiveDepositedValidators, | ||
|
|
@@ -85,16 +84,29 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
|
|
||
| /// @dev Throws if called by any account other than the Strategist | ||
| modifier onlyStrategist() { | ||
| require(msg.sender == strategist, "Caller is not the Strategist"); | ||
| require( | ||
| msg.sender == IVault(VAULT_ADDRESS).strategistAddr(), | ||
| "Caller is not the Strategist" | ||
| ); | ||
| _; | ||
| } | ||
|
|
||
| /// @param _wethAddress Address of the Erc20 WETH Token contract | ||
| /// @param _vaultAddress Address of the Vault | ||
| /// @param _beaconChainDepositContract Address of the beacon chain deposit contract | ||
| /// @param _ssvNetwork Address of the SSV Network contract | ||
| constructor(address _wethAddress, address _vaultAddress, address _beaconChainDepositContract, address _ssvNetwork) | ||
| ValidatorRegistrator(_wethAddress, _beaconChainDepositContract, _ssvNetwork) { | ||
| constructor( | ||
| address _wethAddress, | ||
| address _vaultAddress, | ||
| address _beaconChainDepositContract, | ||
| address _ssvNetwork | ||
| ) | ||
| ValidatorRegistrator( | ||
| _wethAddress, | ||
| _beaconChainDepositContract, | ||
| _ssvNetwork | ||
| ) | ||
| { | ||
| VAULT_ADDRESS = _vaultAddress; | ||
| } | ||
|
|
||
|
|
@@ -103,11 +115,6 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| accountingGovernor = _address; | ||
| } | ||
|
|
||
| function setStrategist(address _address) external onlyGovernor { | ||
| emit StrategistAddressChanged(strategist, _address); | ||
| strategist = _address; | ||
| } | ||
|
|
||
| /// @notice set fuse interval values | ||
| function setFuseInterval( | ||
| uint256 _fuseIntervalStart, | ||
|
|
@@ -133,19 +140,24 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| fuseIntervalEnd = _fuseIntervalEnd; | ||
| } | ||
|
|
||
| /* solhint-disable max-line-length */ | ||
| /// This notion page offers a good explanation of how the accounting functions | ||
| /// https://www.notion.so/originprotocol/Limited-simplified-native-staking-accounting-67a217c8420d40678eb943b9da0ee77d | ||
| /// In short after dividing by 32 if the ETH remaining on the contract falls between 0 and fuseIntervalStart the accounting | ||
| /// In short, after dividing by 32 if the ETH remaining on the contract falls between 0 and fuseIntervalStart the accounting | ||
| /// function will treat that ETH as a Beacon Chain Reward ETH. | ||
| /// On the contrary if after dividing by 32 the ETH remaining on the contract falls between fuseIntervalEnd and 32 the | ||
| /// accounting function will treat that as a validator slashing. | ||
| /// @notice Perform the accounting attributing beacon chain ETH to either full or partial withdrawals. Returns true when | ||
| /// accounting is valid and fuse isn't "blown". Returns false when fuse is blown | ||
| /// accounting is valid and fuse isn't "blown". Returns false when fuse is blown. | ||
| /// @dev This function could in theory be permission-less but lets allow only the Registrator (Defender Action) to call it | ||
| /// for now | ||
| function doAccounting() external onlyRegistrator returns (bool accountingValid) { | ||
| /// for now. | ||
| /* solhint-enable max-line-length */ | ||
| function doAccounting() | ||
| external | ||
| onlyRegistrator | ||
| returns (bool accountingValid) | ||
| { | ||
| uint256 ethBalance = address(this).balance; | ||
| uint256 MAX_STAKE = 32 ether; | ||
| accountingValid = true; | ||
|
|
||
| // send the WETH that is from fully withdrawn validators to the Vault | ||
|
|
@@ -157,7 +169,7 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| IWETH9(WETH_TOKEN_ADDRESS).deposit{ value: wethToVault }(); | ||
| IWETH9(WETH_TOKEN_ADDRESS).transfer(VAULT_ADDRESS, wethToVault); | ||
|
|
||
| emit AccuntingFullyWithdrawnValidator( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha that is a bad typo :D |
||
| emit AccountingFullyWithdrawnValidator( | ||
| fullyWithdrawnValidators, | ||
| activeDepositedValidators, | ||
| wethToVault | ||
|
|
@@ -173,6 +185,7 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| // Beacon chain rewards swept (partial validator withdrawals) | ||
| if (ethRemaining <= fuseIntervalStart) { | ||
| IWETH9(WETH_TOKEN_ADDRESS).deposit{ value: ethRemaining }(); | ||
| // solhint-disable-next-line reentrancy | ||
| beaconChainRewardWETH += ethRemaining; | ||
| emit AccountingBeaconChainRewards(ethRemaining); | ||
| } | ||
|
|
@@ -182,7 +195,7 @@ abstract contract ValidatorAccountant is ValidatorRegistrator { | |
| IWETH9(WETH_TOKEN_ADDRESS).transfer(VAULT_ADDRESS, ethRemaining); | ||
| activeDepositedValidators -= 1; | ||
|
|
||
| emit AccuntingValidatorSlashed( | ||
| emit AccountingValidatorSlashed( | ||
| activeDepositedValidators, | ||
| ethRemaining | ||
| ); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is better yes thanks!