Skip to content

Conversation

@naddison36
Copy link
Collaborator

Changes

  • Added a MAX_VALIDATORS immutable to ValidatorRegistrator that caps the number of validators in the strategy

Code Change Checklist

To be completed before internal review begins:

  • The contract code is complete
  • Executable deployment file
  • Fork tests that test after the deployment file runs
  • Unit tests *if needed
  • The owner has done a full checklist review of the code + tests

Internal review:

  • Two approvals by internal reviewers

@github-actions
Copy link

github-actions bot commented Jun 3, 2024

Warnings
⚠️ 👀 This PR needs at least 2 reviewers

Generated by 🚫 dangerJS against aed1661

@naddison36 naddison36 mentioned this pull request Jun 3, 2024
@codecov
Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.06%. Comparing base (49439ec) to head (aed1661).

Additional details and impacted files
@@                     Coverage Diff                      @@
##           sparrowDom/nativeStaking    #2087      +/-   ##
============================================================
+ Coverage                     62.55%   63.06%   +0.51%     
============================================================
  Files                            65       65              
  Lines                          3247     3249       +2     
  Branches                        632      841     +209     
============================================================
+ Hits                           2031     2049      +18     
+ Misses                         1213     1197      -16     
  Partials                          3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@openzeppelin-code
Copy link

openzeppelin-code bot commented Jun 3, 2024

Cap the validators a Native Staking Strategy can hold

Generated at commit: aed1661a5c8bf4551faf56477b2016d481ab2bf5

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
3
3
0
18
42
66
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@naddison36 naddison36 merged commit 6ecf222 into sparrowDom/nativeStaking Jun 3, 2024
@naddison36 naddison36 deleted the nicka/cap-validators branch June 3, 2024 22:34
naddison36 added a commit that referenced this pull request Jun 8, 2024
* add fuse interval logic and deploy script

* add accounting logic

* add manually fixing accounting

* implement the collect rewards function and add tests for it

* implement and test checkBalance

* add functions to register and exit/remove the ssv validator

* Implemented depositSSV

* Moved MAX_STAKE on ValidatorAccountant to a constant

* Removed strategist from strategy as its already maintained in the Vault

* Native staking changes (#2024)

* Added OETH process diagram with functions calls for native staking

* Native Staking Strategy now hold consensus rewards at ETH
FeeAccumulator now holds execution rewards as ETH
Removed WETH immutable from FeeAccumulator
Converted custom errors back to require with string
collect rewards now converts ETH to WETH at harvest
checkBalance is now validators * 32 plus WETH balance from deposits
Renamed beaconChainRewardsWETH to consensusRewards
Fixed bug in stakeETH that was converting all WETH to ETH

* Native staking changes and unit tests (#2029)

* Fixed native staking deployment since the strategist is got from the vault

* Refactor of some Native Staking events
* Refactor of Native Staking unit tests

* Renamed AccountingBeaconChainRewards to AccountingConsensusRewards
* Accounting updated to handle zero ETH from the beacon chain

* fixed bug not accounting for previous consensus rewards
* Blow fuse if ETH balance < previous consensus rewards

* Pause collectRewardTokens and doAccounting on accounting failure.

Validated asset on deposit to Native Staking Strategy.

Moved depositSSV from NativeStakingSSVStrategy to ValidatorRegistrator

moved onlyStrategist modified and VAULT_ADDRESS immutable from ValidatorAccountant to ValidatorRegistrator

manuallyFixAccounting changed to use whenPaused modifier

made fuseIntervalEnd inclusive

* allow for WETH to send ETH to the contract

* Holesky deploy (#2026)

* add basic steps to deploy OETH to holesky

* add holesky deployment files

* make the fork tests run on Holesky

* testing SSV staking on Holesky

* add deposit to validator deployment files

* SSV cluster info (#2036)

* add ability to fetch SSV cluster information

* manuallyFixAccounting changes (#2034)

* manuallyFixAccounting now uses delta values and only callable by the strategist
manuallyFixAccounting calls doAccounting to check the fuse is still not blown
Removed accountingGovernor

* Added pauseOnFail param to internal _doAccounting
Increased the allowed delta values of manuallyFixAccounting

* mainnet native staking fork tests (#2037)

* manuallyFixAccounting now uses delta values and only callable by the strategist
manuallyFixAccounting calls doAccounting to check the fuse is still not blown
Removed accountingGovernor

* Added pauseOnFail param to internal _doAccounting
Increased the allowed delta values of manuallyFixAccounting

* ran prettier

* Added Defender Relayer for validator registrator
Added ssv utils to get cluster data
Added native staking fork tests

* Removed now redundant IWETH9 import

* moved more logic into native staking fixture

* Removed unused imports

* fix native staking unit tests

* Fail accounting if activeDepositedValidators < fullyWithdrawnValidators
Changed Harvester to transfer WETH to dripper
Added more mainnet fork tests for native staking

* Updated the OETH value flows

* Added governable Hardhat tasks
Created a resolveContract util

* deconstruct params for Hardhat tasks

* WIP Hardhat tasks for validator registration

* Added depositSSV HH task

* Updated OETH contract dependency diagram

* Update to diagrams

* mini fixes

* fix bug and minor test improvement

* update yarn fulie

* unify the holesky and the mainnet fork tests

* re-deploy holesky native staking strategy (#2046)

* also re-deploy the harvester

* upgrade harvester as well

* fix upgrade script and correct the bug in deploy actions

* Deployed new Native Staking strategy including the proxy

* Added Hardhat tasks for generic strategy functions

* remove nativeStakingSSVStrategyProxy from js addresses file

---------

Co-authored-by: Domen Grabec <[email protected]>

* fix unit tests

* fix global hooks filter

* add github workflow

* another workflow fix

* another workflow fix

* fix holesky tests

* remove the .only

* prettier

* Sparrow dom/native staking defender action (#2051)

* adding defender action task

* fix unit tests setup

* update the registrator address of the native staking contract

* fix up the operate validators script so that it works for native staking on holesky

* also add the gitignore

* add ability to exit if staking contract is paused

* Fix fork tests (#2050)

* Fixed resolveAsset

* Fixed validator fork tests
Added error func sigs to ISSVNetwork

* Fixed harvester behaviour tests

* Fix global hooks

* Fix tooling

---------

Co-authored-by: Shahul Hameed <[email protected]>

* add payable to fee accumulator (#2053)

* add payable to fee accumulator

* remove zero initializers

* some gas savings

* fix linter

* Fix balancer fork test

* Fixed resolveContract for none proxied contracts

* simplified woethCcipZapperFixture

* Regenerated latest contract diagrams

* Resolved Slither divide-before-multiply warning

* Native staking deployment to reduceQueueTime

* Fixed fork test harvesting CRV rewards

* gas optimisation

* make verification automatic

* removed wethToVault from manuallyFixAccounting

* native staking strategy redeployed

* adjust the comment

* add rate limit to calling manually fix accounting (#2057)

* add rate limit to calling manually fix accounting

* fix comment

* Correct deployName in Native Staking deploy script

* Fix linter

* Remove approveAssets on Swapper contract in 095_ogn_buyback script as it has already been done

* Fix Holesky fork tests

* Fix mainnet fork tests

* skip deploy 095_ogn_buyback for now

* fix some Slither errors

* Fix Slither warnings

* Upgrade the CI to use node.js 20.x

* Fix CI

* Fix CI

* Upgrade to node.js 20

* Still upgrade the buyback contracts but not approveAssets on the swapper

* Upgrade actions so they don't use node.js 16

* attempt to fix holesky fork run

* Generated latest contract diagram

* fix codecov upload

* Fix OETH process diagram for native staking

* add a withdrawal event when withdrawing WETH to vault (#2059)

* Regenerated latest native staking diagram

* add a util contract that is able to recalculate a valid deposit data root with an invalid signature

* Prettier native staking test

* Renamed native staking deploy script

* Fix event values (#2060)

* add withdrawal events to the tests

* add WETH accounting

* add better documentation

* add sending WETH to the Vault back to fix manual accounting function

* actually wrap the ETH to WETH before sending it to the Vault when manually fixing accounting

* add withdrawal event to manually fix accounting

* fix bugs and add tests with WETH accounting

* add test to verify correct deposits

* Gas changes to Native Staking's depositAll

---------

Co-authored-by: Nicholas Addison <[email protected]>

* Deploy latest Native Staking Strategy to Holesky (#2073)

* Deployed new NativeStakingSSVStrategy

* Generated latest Native Staking Strategy diagrams

* Deploy native staking Proxy via Relayer (#2066)

* deploy native staking proxy and add auxiliary functions to transfer its governance

* Shortened error message in InitializeGovernedUpgradeabilityProxy.initialize

---------

Co-authored-by: Nicholas Addison <[email protected]>

* Setup basic defender action (#2072)

* deploy native staking proxy and add auxiliary functions to transfer its governance

* Setup basic defender action

* update defender-sdk version

* add defender client as an external export

* configuration update

---------

Co-authored-by: Nicholas Addison <[email protected]>

* Output more contract details in 097 deploy script

* Fix Native Staking fork tests

* Changed ssv util getClusterInfo to use the SSV API instead of the ssv-scanner
Moved duplicate getClusterInfo in tasks to utils

* Prettier

* ValidatorRegistrator.stakeEth gas improvement when multiple validators

* Corrected stakeEth call in OETH processes diagram

* Added fork test for registering a validator twice

* Stake funds with confirmations for front-running protection of Beacon Deposits (#2074)

* contract changes and tests for gated protection against front running

* Update off-chain validator registration process to also consider stake threshold

* front run protection changes (#2076)

* Added Holesky deploy script

* Fixed OUSD metapool fork test

* Generated latest NativeStakingSSVStrategy contract diagrams

* Deployed new NativeStakingSSVStrategy to Holesky

---------

Co-authored-by: Nicholas Addison <[email protected]>

* Updated Buyback value flow for OETH

* Updated Native staking process diagram

* Updated OETH Vault diagrams

* Add process for pausing the Native Staking Strategy

* Removed the redundant condition in the fuse interval check (#2082)

* OZ - Native Staking - M-01 All Addresses Are Registered Validators by Default (#2081)

* Added default NON_REGISTERED to VALIDATOR_STATE

* Added explicit check that a validator has not already been registered

* Added new Holesky deploy script

* OZ - Native Staking - N-07 Lack of Indexed Event Parameters (#2083)

* Indexed the RegistratorChanged and StakingMonitorChanged events

* Added indexed pubKeyHash to validator events

* Deployed new Native Staking Strategy

* generated latest NativeStakingSSVStrategy docs

* P2P API changes (#2084)

* Updated Natspec

* Updated native staking process diagrams

* Fixed signer for Holesky

* split operateValidators into registerValidators and stakeValidators

* Fix vault mint HH task. It now waits for the approve tx to be mined

* resolveAsset to handle local Holesky fork

* upgrade signer to use new defender-relay-client package

* added approve option to vault mint HH task

* Added stakeValidators HH task

* update git ignore file

* Added depositWETH and withdrawWETH HH tasks
* Added resetStakeETHTally and setStakeETHThreshold HH tasks

* generated latest Native Staking Strategy docs

* Hardhat tasks for Native Staking (#2085)

* Fixed depositSSV HH tasks

* Added exitValidator and removeValidator HH tasks

* Added doAccounting Defender Action

* Added harvest HH task

* Added fixAccounting and pauseStaking HH tasks

* Fixed stakeValidators when run without uuid option

* Cap the validators a Native Staking Strategy can hold (#2087)

* Added max validators check to Native Staking Strategy

* don't format Defender Action code in dist folder

* Deployed latest NativeStakingSSVStrategy contract to Holesky

* Capitalised error messages in Native Staking Strategy

* Fix hot deploy of Native Staking Strategy

* moved when event it emitted

* remove unchecked when  calculating fullyWithdrawnValidators

* Renamed MAX_STAKE to FULL_STAKE

* Renamed withdrawal_credentials to withdrawalCredentials

* Renamed WETH_TOKEN_ADDRESS to WETH

* renamed SSV_TOKEN_ADDRESS to SSV_TOKEN
renamed SSV_NETWORK_ADDRESS to SSV_NETWORK

* replaced 32 ether with FULL_STAKE

* moved the internal function to the bottom of NativeStakingSSVStrategy

* fixed formatting of if statements

* Moved emits to after state changes

* Removed validatorsLength variable as we aren't dealing with a storage array

* removed unchecked iteration in for loop

* consistent check of currentState

* Added new Holesky deploy script

* Removed Governable from FeeAccumulator

---------

Co-authored-by: Nick Addison <[email protected]>
Co-authored-by: Shahul Hameed <[email protected]>
sparrowDom added a commit that referenced this pull request Jan 22, 2025
* bumped the deploy script number

* Cap the validators a Native Staking Strategy can hold (#2087)

* Added max validators check to Native Staking Strategy

* don't format Defender Action code in dist folder

* Deployed latest NativeStakingSSVStrategy contract to Holesky

* Fix deployment file

* updated deploy number for OETH withdrawal queue

* Fixed unit tests

* Remove stETH from Vault in OETH Withdrawal Queue deployment is not already done
Skip Lido Withdrawal Strategy tests

* Skipping OETH Vault collateral swaps

* Skipping OETH whale redeem in fork tests
Added OETH whale request withdrawal to fork tests

* Fixed spelling in comments of VaultStorage

* Fail CI if any mainnet fork tests fail

* Continue with fork tests if any fail but still fail the CI job

* increment deploy script number

* restore Github Actions config

* Updated OETHVaultCore comments

* Upgraded OETH Vault on Holesky to include the withdrawal queue

* Added Vault requestWithdrawal andclaimWithdrawal Hardhat tasks
Added Dripper collect and setDripDuration Hardhat tasks

* OETHVaultCore Natspec updates
OETHVaultCore params with an underscore

* Add 30 minute time delay between request and claim from the OETH Withdrawal Queue. (#2127)

* feat: add delay between request and claim.

* test: update test with delay.

* fix: move `CLAIM_DELAY` from `VaultStorage.sol` to `OETHVaultCore.sol`.

* style: require error message start with capital letter.

---------

Co-authored-by: Nicholas Addison <[email protected]>

* fix: test expectRevert with new error message

* Fixed unit tests

* Remove stETH and rETH asset from OETH Vault
Remove legacy strategies from the Vault

* Skip legacy strategy tests

* Skiped legacy Oracle prices

* Skipped Aura price tests

* Remove rETH as an asset from the Vault

* Added call to cacheWETHAssetIndex after stETH is removed from  the Vault

* Updated vault storage diagrams

* Added second native staking strategy as the default for WETH

* Add solvency check. (#2131)

* feat: add solvency check.

* test: add test for solvency check.

* docs: add comments

* test: add more assertions.

* style: run prettier

* test: redeem with fees.

* test: increase coverage.

* test: increase coverage again.

* fix: failing test.

* Fixed claim Natspec now the delay is in place

* Changed console debug in assertUpgradeIsSafe to use logger

* Updated Natspec

* Assert totalValue in withdrawal queue unit tests

* Fixed prettier

* Asset vault checkBalance of WETH to OETH Vault unit tests

* _checkBalance and _totalValue on OETH Vault to protect against insolvency with most users requesting a withdrawal

* Override _totalValueInVault in OETH Vault

* Removed super._totalValue call

* Fix AMO fork tests

* Generated latest OETH Vault diagrams

* Don't account for WETH reserved for withdrawal during allocation (#2138)

* Override allocate method

* Add test

* WIP more unit tests

* Added more unit tests

* Added more withdrawal unit tests

* Fix skipped test

* Add extra test to OETH ARM. (#2139)

* test: add extra fork test for claiming withdraw.

* fix: div by zero on `_postRedeem()`.

* test: add test when vault is insolvent.

* test: when enough WETH in vault to cover exactly withdraw.

* test: when more than enough WETH in vault to cover withdraw.

* fix: reduce delay period between request and claim to 10min. (#2140)

* Refactor OETH Vault's `_allocate()` (#2141)

* Refactor of OETH Vault's _allocate

* Updated allocate test

* Add extra test for OETH Withdraw Queue  (#2142)

* test: add tests for `_allocate()`.

* Override allocate on OETH Vault so _addWithdrawalQueueLiquidity is not called twice on large mints (#2144)

OEH Vault _allocate exits early if no default WETH strategy

* Skip waiting for confirmation on Tenderly testnets

* Fix unit tests

* Add snapVault hardhat task

* Updated insolvency unit tests

* Added more insolvency unit tests

* Fix _totalValue so it handles when vault value is less than the outstanding withdrawal requests

* Added SafeCast to unit128

* Reject redeems and withdrawals if no available assets due to insolvency

* Redeem to no longer try and get liquidity from the default strategy if not enough available WETH in the vault

* Simplify _wethAvailable

* refactor of _claimWithdrawal

* Generated latest OETHVaultCore diagram

* Fix Slither

* Updated the other _wethAvailable function

* Set Vault buffer to 0.2%

* Swapped order in deploy script

* Simplify _totalValue logic

* Moved the burn of OETH lower in the request withdrawal

* Added reentrant protection to addWithdrawalQueueLiquidity

* Refactor _addWithdrawalQueueLiquidity
Removed nonReentrant on addWithdrawalQueueLiquidity for now

* Added vault buffer to snapVault Hardhat task

* M-01 _checkBalance Returns an Incorrect Value During Insolvency (#2166)

* Fix checkBalance bug in new OETHVaultCore (#2162)

* Added unit test for checkBalance when balance is less than the outstanding requests

* Fix _checkBalance so it returns 0 when the amount of WETH in the vault and strategies is less than the outstanding withdrawal requests

* Moved asset check to top of _checkBalance

* simplified _totalValue by calling _checkBalance (#2163)

* Fix vault storage slots (#2167)

* L-03 Missing Docstrings (#2169)

* Added Natspec to VaultStorage

* Added Natspec to VaultCore

* Fixed Natspec on requestWithdrawal (#2170)

* Changed _requestIds param in claimWithdrawals be of type calldata (#2171)

* Remove unnecessary address cast (#2172)

* Updated Natpsec of _checkBalance and _checkBalance (#2173)

* made constant CLAIM_DELAY public (#2174)

* Removed unused MAX_UINT constant (#2175)

* N-08 Variables Are Initialized to Their Default Values (#2176)

* Removed unused MAX_UINT constant

* Removed variables being initialized to their default values

* Generated latest Vault contract diagrams

* initial commit

* WIP Sonic Vault

* Changed Sonic Vault to use OETH Base Vault

* WIP sonic

* WIP sonic

* WIP sonic

* Got unit tests working

* Added sonic to node script

* WIP Sonic deploy script

* Added sonic to storageSlots

* Fix getHardhatNetworkProperties

* Added sonic deployment files

* Added WETH address on Sonic

* Fix Sonic deployment

* Upgraded Hardhat

* More Sonic deployment changes

* More Sonic fixes

* Sonic VaultAdmin override supportAsset as it doesn't have a price provider

* Solidity prettier

* Skipping reborn attack tests now self-destruct has been removed

* fix reborn tests

* re-enable fixed reborn tests

* Added SPC

* fix reborn tests

* Fix Solidity compile

* WIP Sonic Staking Strategy

* Add supported validators to Sonic Staking Strategy

* Added Sonic Staking Strategy to deploy script

* checkBalance now gets stake and pending rewards

* add basic fork tests for Sonic staking

* add correct validator ids

* Added Defender Relayer for Sonic

* Fixed Sonic unit tests
Prettier and linter

* More admin unit tests

* More unit tests

* Update dependencies

* bumped solidity-coverage version

* Added Sonic tests to CI

* Fix deprecation notices
Renamed actions

* Formatting of fork-test.sh script

* Slither fixes

* Removed unit tests to get gas numbers from CI

* Removed redeem from OSonicVault

* Removed unused code from SonicValidatorDelegator

* clean up fork test structure

* improve fork test checks

* add basic withdrawal tests

* prettier

* Fix OSonic unit test deploy after merge with yield delegation

* Added Fixed Rate Dripper for Sonic

* Fixed base unit tests after
Fix upgrade script of OETHBase

* Added Sonic Zapper

* Added Sonic contract dependency diagram

* add withdrawal fork tests

* add restaking test

* add withdrawal timestamp to the withdrawal struct

* Updated Sonic token metadata

* prettier

* Update Natspec
Added governor transfer unit tests

* Added VaultValueChecker to Sonic deploy script

* Added phase 2 contracts to Sonic contract dependencies

* Generated Sonic contract diagrams
Updated existing OToken diagrams after Yield Delegation

* Added Sonic fork tests for Zapper

* Reduced depositedWSAccountedFor when delegating or withdrawing from the Sonic Staking Strategy

* Generated latest SonicStakingStrategy

* Added Sonic Vault config to deploy script

* Added TODO in Sonic addresses

* Added Sonic Vault fork tests
Added missing Vault config to Sonic deploy script
Sonic Staking Strategy governor fixed in deploy script

* remove the depositedWSAccountedFor

* automatically delegate on deposit transaction & add strategist allowance to undelegate

* add donation attack comment and pick up any S tokens in the withdrawAll

* Prettier

* Cleaned up imports
Updated __gap after adding defaultValidatorId

* Fix Slither

* Updated Natspec

* Removed Deposit event from restakeRewards

* Fix Natspec

* Fix fork tests after removing Deposit event from restakeRewards
More Natspec updated

* Added deposit and withdraw fork tests for sonic staking strategy

* Added more Sonic fork tests

* Generated latest Sonic Strategy diagrams

* update the solc version to re-enable harhdat tracer

* Added Sonic Admin and Guardian wallets

* Added logger to Sonic staking fork tests

* update the compiler version to 0.8.28

* Prettier

(cherry picked from commit fe45bce)

* Added Timelock to Sonic deploy script

(cherry picked from commit 2c3e2e4)

* deployOnSonic now handles Timelock governance
Split Sonic deploy up into vault/tokens and sonic staking strategy

(cherry picked from commit d57fd0c)

* cleaner max int

* remove unused variable

* simplify casting

* remove secondary 0 amount check

* gas optimisation

* fix incorrect type

* Sonic Deploy 001 - Token and Vault  (#2352)

* fix incorrect type

* update hardhat-verify to support sonic chain verifications

* add descriptors of sonic 001 deploy

* remove trustee address and feeBps setting

* Prettier

---------

Co-authored-by: Domen Grabec <[email protected]>

* add oracle router deployment (#2353)

* add oracle router deployment

* Renamed Router to be consistent with other Sonic contracts

* Added oracle router to Sonic contract diagram

---------

Co-authored-by: Nicholas Addison <[email protected]>

* Revert change to MAX_INT in VaultCore

* Changed withConfirmation it ignore confirmations to Sonic and Base Tenderly Testnets

* change max int notation

* Correct chainId when generating Gnosis file

(cherry picked from commit 27b4e82)

* create a separate contract for OSonicOracleRouter

* Hardhat tasks working with Sonic (#2357)

* Made depositWETH work with Sonic

* HH tasks allocate, capital, rebase, mint, requestWithdrawal, claimWithdrawal and  and snapVault working with Sonic

* correct comment

* correct comment

* allow restaking only of the supported validators

* add SonicOracleRouter deployment files (#2355)

* add the ability to claim rewards without restaking them

* emit Withdrawal event when funds withdrawn from the strategy

* simplify ACL

* Store contract state before executing external calls

* automatically undelegate when unsupporting a validator

* remove comment

* remove slither disables

* add test for confirming rewards being restaked

* emit withdrawal event when collecting rewards

* Sonic 003 deploy script changed to config vault and upgrade Wrapped OS token

* remove the non required is validator supported check

* add test for depositAll

* add some missing tests

* add test for not receiving sonic

* add comment

* add trustee address to the deploy script

* correct local variable names

* Sonic Deploy 003 - Sonic Staking Strategy (#2359)

* Added setAssetDefaultStrategy to Sonic deploy 003 script

* Added setDefaultValidator Hardhat task

* Fixed Sonic fork tests now mints are auto allocating to the Sonic Staking Strategy

* Sonic deploy 003 contracts

---------

Co-authored-by: Shahul Hameed <[email protected]>
Co-authored-by: Clément <[email protected]>
Co-authored-by: clement-ux <[email protected]>
Co-authored-by: Domen Grabec <[email protected]>
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.

3 participants