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

Sparrow dom/validator simulator #2098

Open
wants to merge 147 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
063d8b2
initial commit of the native staking strategy
sparrowDom Apr 4, 2024
6e8332b
fix text
sparrowDom Apr 4, 2024
b933f22
add some more functionality
sparrowDom Apr 10, 2024
0a43d14
finish up the fuse interval test, update deploy script
sparrowDom Apr 11, 2024
d31fe30
some natspec and refactoring
sparrowDom Apr 11, 2024
03c544c
add some more accounting logic
sparrowDom Apr 11, 2024
9aa0d73
finish up accounting and add tests for it
sparrowDom Apr 12, 2024
e99f86c
add some comments
sparrowDom Apr 15, 2024
52ba11e
add tests for manually fixing accounting
sparrowDom Apr 15, 2024
e656ecb
lint and prettier
sparrowDom Apr 15, 2024
fe113a5
undo file delete
sparrowDom Apr 15, 2024
71ad71f
implement the collect rewards function and add tests for it
sparrowDom Apr 16, 2024
2c448bb
implement and test checkBalance
sparrowDom Apr 16, 2024
5d5e9cb
add functions to register and exit/remove the ssv validator
sparrowDom Apr 18, 2024
121c7f7
Native staking updates (#2023)
naddison36 Apr 22, 2024
8a64dc8
Native staking changes (#2024)
naddison36 Apr 23, 2024
8419fc7
Native staking changes and unit tests (#2029)
naddison36 Apr 25, 2024
87c5254
allow for WETH to send ETH to the contract
sparrowDom Apr 26, 2024
1d66508
shorten error message
sparrowDom Apr 26, 2024
00ec878
fix depositing bug
sparrowDom Apr 27, 2024
ec4933b
Holesky deploy (#2026)
sparrowDom Apr 29, 2024
6179cb1
manuallyFixAccounting changes (#2034)
naddison36 Apr 29, 2024
da6a7b5
fix fork tests
sparrowDom Apr 29, 2024
fd17ec9
Merge branch 'master' into sparrowDom/nativeStaking
sparrowDom May 6, 2024
8f7d3d5
prettier
sparrowDom May 6, 2024
967fe49
fix unit test
sparrowDom May 6, 2024
1af324d
mainnet native staking fork tests (#2037)
naddison36 May 7, 2024
ce2ec63
fix unit tests
sparrowDom May 6, 2024
fe12d23
fix global hooks filter
sparrowDom May 7, 2024
c61c9bb
add github workflow
sparrowDom May 7, 2024
7e2e640
another workflow fix
sparrowDom May 7, 2024
af8ea03
another workflow fix
sparrowDom May 7, 2024
32480dd
fix holesky tests
sparrowDom May 7, 2024
0fb09ea
remove the .only
sparrowDom May 7, 2024
c7175bb
prettier
sparrowDom May 7, 2024
69abd8f
Sparrow dom/native staking defender action (#2051)
sparrowDom May 9, 2024
2f7a9cd
Fix fork tests (#2050)
naddison36 May 9, 2024
0623a47
add payable to fee accumulator (#2053)
sparrowDom May 9, 2024
f268742
fix linter
naddison36 May 9, 2024
20d29a1
Fix balancer fork test
naddison36 May 10, 2024
2a93df2
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 10, 2024
b898801
Fixed resolveContract for none proxied contracts
naddison36 May 10, 2024
25170aa
simplified woethCcipZapperFixture
naddison36 May 10, 2024
e1ff728
Regenerated latest contract diagrams
naddison36 May 10, 2024
c09cd46
Resolved Slither divide-before-multiply warning
naddison36 May 10, 2024
9d83e97
Native staking deployment to reduceQueueTime
naddison36 May 10, 2024
7eb135b
Fixed fork test harvesting CRV rewards
naddison36 May 10, 2024
579a93c
gas optimisation
sparrowDom May 10, 2024
4c864ca
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 10, 2024
e7b96e9
make verification automatic
sparrowDom May 10, 2024
8a53f3e
removed wethToVault from manuallyFixAccounting
naddison36 May 10, 2024
98a193a
Merge remote-tracking branch 'origin/sparrowDom/nativeStaking' into s…
naddison36 May 10, 2024
905abf9
native staking strategy redeployed
sparrowDom May 10, 2024
fc48427
adjust the comment
sparrowDom May 10, 2024
4b51655
add rate limit to calling manually fix accounting (#2057)
sparrowDom May 13, 2024
657b064
Correct deployName in Native Staking deploy script
naddison36 May 13, 2024
769018a
Fix linter
naddison36 May 13, 2024
b98e9de
Remove approveAssets on Swapper contract in 095_ogn_buyback script as…
naddison36 May 13, 2024
622a3b4
Fix Holesky fork tests
naddison36 May 13, 2024
c25745d
Fix mainnet fork tests
naddison36 May 13, 2024
4ca3136
skip deploy 095_ogn_buyback for now
naddison36 May 13, 2024
37c9d0a
fix some Slither errors
naddison36 May 13, 2024
193af2f
Fix Slither warnings
naddison36 May 13, 2024
6d5034a
Upgrade the CI to use node.js 20.x
naddison36 May 13, 2024
848d578
Fix CI
naddison36 May 13, 2024
79d5058
Fix CI
naddison36 May 13, 2024
7b7ac39
Upgrade to node.js 20
naddison36 May 13, 2024
6b2be67
Still upgrade the buyback contracts but not approveAssets on the swapper
naddison36 May 13, 2024
5f2f8f6
Upgrade actions so they don't use node.js 16
naddison36 May 13, 2024
6baed9b
attempt to fix holesky fork run
sparrowDom May 13, 2024
9ce05e1
Generated latest contract diagram
naddison36 May 13, 2024
8c052d8
fix codecov upload
naddison36 May 13, 2024
3687fbe
Fix OETH process diagram for native staking
naddison36 May 13, 2024
6df4f5f
add a withdrawal event when withdrawing WETH to vault (#2059)
sparrowDom May 13, 2024
614b11e
Regenerated latest native staking diagram
naddison36 May 13, 2024
21d5569
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 13, 2024
cfe6a81
add a util contract that is able to recalculate a valid deposit data …
sparrowDom May 16, 2024
c491131
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 22, 2024
e8c15b5
Prettier native staking test
naddison36 May 22, 2024
acad4b9
Renamed native staking deploy script
naddison36 May 22, 2024
638bf30
Fix event values (#2060)
sparrowDom May 22, 2024
b4e9c3f
Deploy latest Native Staking Strategy to Holesky (#2073)
naddison36 May 22, 2024
77d7b07
Deploy native staking Proxy via Relayer (#2066)
sparrowDom May 22, 2024
4c25093
Setup basic defender action (#2072)
sparrowDom May 22, 2024
c4456b9
Output more contract details in 097 deploy script
naddison36 May 23, 2024
4e9e24f
Fix Native Staking fork tests
naddison36 May 24, 2024
8cf9a25
Changed ssv util getClusterInfo to use the SSV API instead of the ssv…
naddison36 May 24, 2024
fc09bed
Prettier
naddison36 May 24, 2024
bb3b7e6
ValidatorRegistrator.stakeEth gas improvement when multiple validators
naddison36 May 24, 2024
e163cff
Corrected stakeEth call in OETH processes diagram
naddison36 May 24, 2024
e853081
Added fork test for registering a validator twice
naddison36 May 27, 2024
12bba64
Stake funds with confirmations for front-running protection of Beacon…
sparrowDom May 28, 2024
0a0e9da
Updated Buyback value flow for OETH
naddison36 May 28, 2024
93b3cdf
Updated Native staking process diagram
naddison36 May 29, 2024
003fcdb
Updated OETH Vault diagrams
naddison36 May 29, 2024
9295fe7
Add process for pausing the Native Staking Strategy
naddison36 May 29, 2024
8748170
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 29, 2024
270a3f6
Removed the redundant condition in the fuse interval check (#2082)
naddison36 Jun 2, 2024
706da2e
OZ - Native Staking - M-01 All Addresses Are Registered Validators by…
naddison36 Jun 2, 2024
71adea7
OZ - Native Staking - N-07 Lack of Indexed Event Parameters (#2083)
naddison36 Jun 2, 2024
8f8118d
Deployed new Native Staking Strategy
naddison36 Jun 2, 2024
d398042
generated latest NativeStakingSSVStrategy docs
naddison36 Jun 2, 2024
b6c2219
P2P API changes (#2084)
naddison36 Jun 2, 2024
49439ec
Hardhat tasks for Native Staking (#2085)
naddison36 Jun 3, 2024
6ecf222
Cap the validators a Native Staking Strategy can hold (#2087)
naddison36 Jun 3, 2024
c807e8d
don't format Defender Action code in dist folder
naddison36 Jun 4, 2024
7f54c94
Deployed latest NativeStakingSSVStrategy contract to Holesky
naddison36 Jun 4, 2024
8b7c866
Capitalised error messages in Native Staking Strategy
naddison36 Jun 5, 2024
7e19fbb
Fix hot deploy of Native Staking Strategy
naddison36 Jun 5, 2024
37a1d10
moved when event it emitted
naddison36 Jun 5, 2024
57f78b8
remove unchecked when calculating fullyWithdrawnValidators
naddison36 Jun 5, 2024
4c3ba23
Renamed MAX_STAKE to FULL_STAKE
naddison36 Jun 5, 2024
e4db674
Renamed withdrawal_credentials to withdrawalCredentials
naddison36 Jun 5, 2024
02fe259
Renamed WETH_TOKEN_ADDRESS to WETH
naddison36 Jun 5, 2024
f4fb309
renamed SSV_TOKEN_ADDRESS to SSV_TOKEN
naddison36 Jun 5, 2024
0231bb8
replaced 32 ether with FULL_STAKE
naddison36 Jun 5, 2024
7db25d2
Fix fork tests
naddison36 Jun 5, 2024
b685925
moved the internal function to the bottom of NativeStakingSSVStrategy
naddison36 Jun 5, 2024
1d9fa16
fixed formatting of if statements
naddison36 Jun 5, 2024
6dc40ab
Moved emits to after state changes
naddison36 Jun 5, 2024
f8879bd
Removed validatorsLength variable as we aren't dealing with a storage…
naddison36 Jun 5, 2024
670064e
removed unchecked iteration in for loop
naddison36 Jun 5, 2024
9ac93f5
consistent check of currentState
naddison36 Jun 5, 2024
e6af23a
Added new Holesky deploy script
naddison36 Jun 5, 2024
2457b37
Removed Governable from FeeAccumulator
naddison36 Jun 5, 2024
9ff8c5a
Decryption of validator key from P2P API (#2088)
naddison36 Jun 5, 2024
4b8a315
Added asset check to withdraw
naddison36 Jun 6, 2024
b581b9e
Merge remote-tracking branch 'origin/sparrowDom/nativeStaking' into s…
naddison36 Jun 6, 2024
275527a
bumped down the events in Native Staking Strategy
naddison36 Jun 6, 2024
125cad8
Replaced 32 ether with FULL_STAKE
naddison36 Jun 6, 2024
66a6f63
Using FULL_STAKE instead of 32 ether to make it easier for EIP-7251, …
naddison36 Jun 6, 2024
56d3331
Removed withdrawalCredentials from ETHStaked event
naddison36 Jun 6, 2024
563003d
fix updating depositedWethAccountedFor on withdrawal (#2091)
naddison36 Jun 6, 2024
370d70e
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 Jun 6, 2024
9acd4a7
Changed max validators to 500
naddison36 Jun 7, 2024
dfbf709
remove extra await from fork tests
naddison36 Jun 7, 2024
c29887b
Reduced the stakeETHThreshold to 512 which is 16 validators
naddison36 Jun 7, 2024
630d8d4
Natspec update to ValidatorRegistrator
naddison36 Jun 7, 2024
ccfa636
New Holesky deployment
naddison36 Jun 7, 2024
aed063a
initial contract changes
sparrowDom Jun 7, 2024
ecbab50
Merge remote-tracking branch 'origin/master' into sparrowDom/validato…
sparrowDom Jun 7, 2024
b7cf329
more progress on validator simulator
sparrowDom Jun 11, 2024
239fb70
messy commit
sparrowDom Jun 11, 2024
7f1351a
...
sparrowDom Jun 12, 2024
ec6bf35
add fuzz testing for validator beacon chain rewards and withdrawals
sparrowDom Jun 14, 2024
12d1b45
remove creep file
sparrowDom Jun 14, 2024
0ef6640
Merge remote-tracking branch 'origin/master' into sparrowDom/validato…
sparrowDom Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion contracts/contracts/mocks/MockDepositContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import { IDepositContract } from "./../interfaces/IDepositContract.sol";

contract MockDepositContract is IDepositContract {
uint256 deposit_count;
uint256 public deposit_count;

function deposit(
bytes calldata pubkey,
Expand Down Expand Up @@ -47,6 +47,8 @@ contract MockDepositContract is IDepositContract {
deposit_data_root != 0,
"DepositContract: invalid deposit_data_root"
);

deposit_count += 1;
}

function get_deposit_root() external view override returns (bytes32) {
Expand Down
22 changes: 18 additions & 4 deletions contracts/contracts/mocks/MockSSVNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,51 @@ pragma solidity ^0.8.0;
import { Cluster } from "./../interfaces/ISSVNetwork.sol";

contract MockSSVNetwork {
uint256 public registeredValidators;
uint256 public exitedValidators;
uint256 public removedValidators;

/* solhint-disable no-unused-vars */
function registerValidator(
bytes calldata publicKey,
uint64[] calldata operatorIds,
bytes calldata sharesData,
uint256 amount,
Cluster memory cluster
) external {}
) external {
registeredValidators += 1;
}

function bulkRegisterValidator(
bytes[] calldata publicKeys,
uint64[] calldata operatorIds,
bytes[] calldata sharesData,
uint256 amount,
Cluster memory cluster
) external {}
) external {
registeredValidators += publicKeys.length;
}

function exitValidator(
bytes calldata publicKey,
uint64[] calldata operatorIds
) external {}
) external {
exitedValidators += 1;
}

function removeValidator(
bytes calldata publicKey,
uint64[] calldata operatorIds,
Cluster memory cluster
) external {}
) external {
removedValidators += 1;
}

function deposit(
address clusterOwner,
uint64[] calldata operatorIds,
uint256 amount,
Cluster memory cluster
) external {}
/* solhint-enable no-unused-vars */
}
4 changes: 2 additions & 2 deletions contracts/deploy/deployActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
getOracleAddresses,
isMainnet,
isHolesky,
} = require("../test/helpers.js");
} = require("../test/helpers");
const { deployWithConfirmation, withConfirmation } = require("../utils/deploy");
const {
metapoolLPCRVPid,
Expand Down Expand Up @@ -904,7 +904,7 @@ const deployNativeStakingSSVStrategy = async () => {
assetAddresses.WETH, // wethAddress
assetAddresses.SSV, // ssvToken
assetAddresses.SSVNetwork, // ssvNetwork
500, // maxValidators
600, // maxValidators
dFeeAccumulatorProxy.address, // feeAccumulator
assetAddresses.beaconChainDepositContract, // depositContractMock
]
Expand Down
Binary file added contracts/docs/plantuml/oethProcesses-pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 98 additions & 4 deletions contracts/test/_fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
getOracleAddresses,
oethUnits,
ousdUnits,
ethUnits,
units,
isFork,
isHolesky,
Expand Down Expand Up @@ -153,7 +154,7 @@ const simpleOETHFixture = deployments.createFixture(async () => {
}
} else {
// Fund WETH contract
await hardhatSetBalance(weth.address, "999999999999999");
await hardhatSetBalance(weth.address, "99999999999999999");

// Fund all with mockTokens
await fundAccountsForOETHUnitTests();
Expand Down Expand Up @@ -300,7 +301,7 @@ const defaultFixture = deployments.createFixture(async () => {
const nativeStakingFeeAccumulatorProxy = await ethers.getContract(
"NativeStakingFeeAccumulatorProxy"
);
const nativeStakingFeeAccumulator = await ethers.getContractAt(
let nativeStakingFeeAccumulator = await ethers.getContractAt(
"FeeAccumulator",
nativeStakingFeeAccumulatorProxy.address
);
Expand Down Expand Up @@ -369,6 +370,7 @@ const defaultFixture = deployments.createFixture(async () => {
cvxBooster,
cvxRewardPool,
depositContractUtils,
depositContract,
LUSDMetaStrategy,
oethDripper,
oethZapper,
Expand Down Expand Up @@ -522,6 +524,14 @@ const defaultFixture = deployments.createFixture(async () => {
fluxStrategyProxy.address
);

const nativeStakingFeeAccumulatorProxy = await ethers.getContract(
"NativeStakingFeeAccumulatorProxy"
);
nativeStakingFeeAccumulator = await ethers.getContractAt(
"FeeAccumulator",
nativeStakingFeeAccumulatorProxy.address
);

vaultValueChecker = await ethers.getContract("VaultValueChecker");
oethVaultValueChecker = await ethers.getContract("OETHVaultValueChecker");
} else {
Expand Down Expand Up @@ -559,6 +569,7 @@ const defaultFixture = deployments.createFixture(async () => {
cvxBooster = await ethers.getContract("MockBooster");
cvxRewardPool = await ethers.getContract("MockRewardPool");
depositContractUtils = await ethers.getContract("DepositContractUtils");
depositContract = await ethers.getContract("MockDepositContract");

adai = await ethers.getContract("MockADAI");
aaveToken = await ethers.getContract("MockAAVEToken");
Expand Down Expand Up @@ -744,7 +755,7 @@ const defaultFixture = deployments.createFixture(async () => {
cvxBooster,
cvxRewardPool,
depositContractUtils,

depositContract,
aaveStrategy,
aaveToken,
aaveAddressProvider,
Expand Down Expand Up @@ -1650,6 +1661,88 @@ async function nativeStakingSSVStrategyFixture() {
return fixture;
}

/**
* NativeStakingSSVStrategy fixture with 600 validators deposited
*/
async function nativeStakingValidatorDepositsFixture() {
const fixture = await nativeStakingSSVStrategyFixture();

const {
nativeStakingSSVStrategy,
validatorRegistrator,
governor,
weth,
josh,
} = fixture;

const testValidator = {
publicKey:
"0xaba6acd335d524a89fb89b9977584afdb23f34a6742547fa9ec1c656fbd2bfc0e7a234460328c2731828c9a43be06e25",
operatorIds: [348, 352, 361, 377],
sharesData:
"0x859f01c8f609cb5cb91f0c98e9b39b077775f10302d0db0edc4ea65e692c97920d5169f6281845a956404c0ba90b88060b74aa3755347441a5729b90bf30a449fa568e21915d11733c7135602b2a3d1a4dce41218ecb0fdb1788ee7e48a9ebd4b4b34f62deea20e9212ce78040dcad2e6382c2f4d4c8b3515a840e1693574068e26c0d58f17dc47d30efe4393f2660dc988aba6166b67732e8df7d9a69d316f330779b2fa4d14712d3bb60436d912bab4464c7c31ae8d2a966d7829063821fc899cc3ec4a8c7098b042323eb9d9cc4d5e945c6d5e6d4eb1b2484163d4b8cd83eea4cc195a68320f023b4d2405cda5110a2eea2c12b70abd9b6bfb567a7850a95fe073a0485c787744efc8658789b0faaff0d942b3c7b89540f594d007936f23c3e7c79fabfe1e2c49199a3f374198e231ca391909ca05ee3c89a7292207131653f6f2f5f5d638d4789a8029001b93827f6f45ef062c9a9d1360a3aedae00fbb8c34495056bacc98c6cecfc1171c84a1e47f3bc328539dbbcd6c79c2aebf7833c684bd807cc8c4dfd6b660e64aece6adf659a969851cf976dead050e9d14aa9c358326c0c0f0cb747041830e124ec872fcf6f82e7f05024da9e6bad10319ca085a0d1519b04c60738043babc1f5a144655e6a28922c2734701c5c93b845996589b8fd246e1bcd97570951cdbed032eeb9c2ac49ac8aeb2e988b6a5513ddcef9ca9bd592c0bce7d38041b52e69e85cda5fd0b84f905c7212b299cf265ee603add20d6459e0841dd05524e96574eebb46473151ec10a08873f7075e15342852f9f16aeb8305211706632475c39ccd8da33969390d035f8a68324e7adced66a726f80532b425cc82dd52a2edc10989db0167317b472a0016215dae35b4c26b28c0ebcf56e115eb32231449812e9ce866a8c0b3128878d3878f5be0670051a8bf94807123c54e6ea2f51607e32c2fe1b132c905c81965dd6d2a7474aa40b65f18d34084a74ba9a21fbdfba3bfaf6b11175d85f03181d655fda086d8dbe2f03dfa2e1b7140b1d9dc68fc9e22f184ed278599d29f6660af128e4c548de6926912d920e35575db90338a1a840f8d8842685f5b459fda573eaf5c5180e3369fc50faa681941dbe7dec83ee9649f30c1a0eac1f8a42fb3083d9274f4c622e2aa1e74b70fa6c027b4f23e1f80bfc4f69248b4d0b3e0eee9372869f97eb89d8d155e469191c48834ad58dd831f1b73409d71fccb958b6582a4ac3f98bcffff2abd393cbe64d7397ada699ecc75301e3be9e9b4ee92a990202c6a5e5112de5ea9cd666f41cdac4611575c8efe2137d6132cd4d4eea0de159eab44588a88f887e4263f673fb365415df537c77a4aaaee12dceff022eafcb8e6973eec7e18eb65cfeefa845b79754ec52a9270f0a7e570b1dd2171e629d498f34e6371726fa8cfe6863f9263c5222a953a44612944183789ad1020de8da527bf850429558dda7896059476e497284512c946d7a57acda3c3ee722d280c0d0daf758d6be88db48e96e14124832c38aa6d0dd38baeb4f246b01d7b0beb55c3983fb182cbf630b778384cc13ab6216611bc1eab94ffe17bb1e829700c99ec28fae1a87eaefd9c8edc4cdf3b6f2b07d85e0d8090ddfb2df4280dacd13a1f30cf946f5606940dc3f75622159b1c6f84bfdbd4ba9fa0f1d522f52bc2049da53f0d06931d650ef1274eb0247844c36349617095f9734e89be683fd7bd5001b416d800c53ec8e8eb533c418a83e803daf6fdfd552ca745bb2b24d8abe899ea89572524343386a035b675e9d5eeae81aefb3a24397f36fe501c66b27d1c0e453fcc975c888d9d6d5a4ca0a4b32b41deebed70",
signature:
"0x90157a1c1b26384f0b4d41bec867d1a000f75e7b634ac7c4c6d8dfc0b0eaeb73bcc99586333d42df98c6b0a8c5ef0d8d071c68991afcd8fbbaa8b423e3632ee4fe0782bc03178a30a8bc6261f64f84a6c833fb96a0f29de1c34ede42c4a859b0",
depositDataRoot:
"0xdbe778a625c68446f3cc8b2009753a5e7dd7c37b8721ee98a796bb9179dfe8ac",
};

const emptyCluster = [
0, // validatorCount
0, // networkFeeIndex
0, // index
true, // active
0, // balance
];

await nativeStakingSSVStrategy
.connect(governor)
.setStakeETHThreshold(parseEther("19200")); // 32 * 600 = 19200

await weth
.connect(josh)
.transfer(nativeStakingSSVStrategy.address, parseEther("19200")); // 32 * 600 = 19200

const pubKeys = [];
const sharesData = [];
const stakeData = [];

for (let i = 0; i < 600; i++) {
// this just creates incrementally bigger validator pubKeys that are of sufficient length
const pubkey = "0x" + (i + 1).toString(16).padStart(96, "0");

pubKeys[i] = pubkey;
sharesData[i] = testValidator.sharesData;
stakeData[i] = {
pubkey,
signature: testValidator.signature,
depositDataRoot: testValidator.depositDataRoot,
};
}

const ssvAmount = ethUnits("10");

for (let i = 0; i < 3; i++) {
// Register a new validator with the SSV Network
await nativeStakingSSVStrategy
.connect(validatorRegistrator)
.registerSsvValidators(
pubKeys.slice(i * 200, (i + 1) * 200),
testValidator.operatorIds,
sharesData.slice(i * 200, (i + 1) * 200),
ssvAmount,
emptyCluster
);

// Stake ETH to the new validator
nativeStakingSSVStrategy
.connect(validatorRegistrator)
.stakeEth(stakeData.slice(i * 200, (i + 1) * 200));
}

return fixture;
}

/**
* Generalized strategy fixture that works only in forked environment
*
Expand Down Expand Up @@ -2483,8 +2576,9 @@ module.exports = {
untiltBalancerMetaStableWETHPool,
fraxETHStrategyFixture,
frxEthRedeemStrategyFixture,
lidoWithdrawalStrategyFixture,
nativeStakingSSVStrategyFixture,
nativeStakingValidatorDepositsFixture,
lidoWithdrawalStrategyFixture,
oethMorphoAaveFixture,
oeth1InchSwapperFixture,
oethCollateralSwapFixture,
Expand Down
50 changes: 50 additions & 0 deletions contracts/test/strategies/nativeSSVStakingValidatorSim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { isCI } = require("../helpers");
const ValidatorSimulator = require("../../utils/ValidatorSimulator");
const {
createFixtureLoader,
nativeStakingValidatorDepositsFixture,
} = require("./../_fixture");
const loadFixture = createFixtureLoader(nativeStakingValidatorDepositsFixture);

let validatorSimulator;
describe("Unit test: Native SSV Staking Strategy", function () {
this.timeout(0);

// Retry up to 3 times on CI
this.retries(isCI ? 3 : 0);

let fixture;
beforeEach(async () => {
fixture = await loadFixture();
const {
nativeStakingSSVStrategy,
depositContract,
ssvNetwork,
validatorRegistrator,
} = fixture;

validatorSimulator = new ValidatorSimulator(
nativeStakingSSVStrategy,
depositContract,
ssvNetwork,
validatorRegistrator
);
});

describe("Native SSV Staking validator simulations", function () {
const maxSlashedValidators = 5;
const maxWithdrawnValidators = 50;

// loop through possible combinations of slashed and withdrawn validators
for (let i = 0; i < maxSlashedValidators + 1; i++) {
for (let j = 0; j < maxWithdrawnValidators + 1; j++) {
it(`Should correctly do accounting when ${i} validators are slashed and ${j} validators are fully withdrawn`, async () => {
await validatorSimulator.executeSimulation({
validatorSlashes: i,
validatorFullWithdrawals: j,
});
});
}
}
});
});
Loading
Loading