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

front run protection changes #2076

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,15 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
validatorRegistrator = _address;
}

/// @notice Set the address of the staking monitor that is allowed to modify
/// stakeETHThreshold and reset stakeETHTally
/// @notice Set the address of the staking monitor that is allowed to reset stakeETHTally
function setStakingMonitor(address _address) external onlyGovernor {
emit StakingMonitorChanged(_address);
stakingMonitor = _address;
}

/// @notice Set the amount of ETH that can be staked before governor needs to a approve
/// further staking.
function setStakeETHThreshold(uint256 _amount) external onlyStakingMonitor {
/// @notice Set the amount of ETH that can be staked before staking monitor
// needs to a approve further staking by resetting the stake ETH tally
function setStakeETHThreshold(uint256 _amount) external onlyGovernor {
emit StakeETHThresholdChanged(_amount);
stakeETHThreshold = _amount;
}
Expand Down Expand Up @@ -149,7 +148,7 @@ abstract contract ValidatorRegistrator is Governable, Pausable {

require(
stakeETHTally + requiredETH <= stakeETHThreshold,
"Staking ETH over approved threshold"
"Staking ETH over threshold"
);
stakeETHTally += requiredETH;

Expand Down
59 changes: 59 additions & 0 deletions contracts/deploy/holesky/010_upgrade_strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { upgradeNativeStakingSSVStrategy } = require("../deployActions");
const { isFork } = require("../../test/helpers");
const { withConfirmation } = require("../../utils/deploy");
const { resolveContract } = require("../../utils/resolvers");
const addresses = require("../../utils/addresses");
const { parseEther } = require("ethers/lib/utils");
// const { impersonateAndFund } = require("../../utils/signers.js");

const mainExport = async () => {
console.log("Running 010 deployment on Holesky...");

console.log("Upgrading native staking strategy");
await upgradeNativeStakingSSVStrategy();

const cNativeStakingStrategy = await resolveContract(
"NativeStakingSSVStrategyProxy",
"NativeStakingSSVStrategy"
);

if (isFork) {
const { governorAddr } = await getNamedAccounts();
const sGovernor = await ethers.provider.getSigner(governorAddr);

await withConfirmation(
cNativeStakingStrategy
.connect(sGovernor)
// Holesky defender relayer
.setStakingMonitor(addresses.holesky.Guardian)
);

await withConfirmation(
cNativeStakingStrategy
.connect(sGovernor)
.setStakeETHThreshold(parseEther("64"))
);

console.log(
`Set the staking monitor to ${addresses.holesky.Guardian} and stake ETH threshold to 32 ETH`
);
} else {
console.log(
`Set the staking monitor to ${addresses.holesky.Guardian} using Hardhat task`
);
}

console.log(
`Staking monitor set to ${await cNativeStakingStrategy.stakingMonitor()}`
);

console.log("Running 010 deployment done");
return true;
};

mainExport.id = "010_upgrade_strategy";
mainExport.tags = [];
mainExport.dependencies = [];
mainExport.skip = () => false;

module.exports = mainExport;
5 changes: 3 additions & 2 deletions contracts/deploy/mainnet/097_native_ssv_staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ module.exports = deploymentWithGovernanceProposal(
contract: cStrategy,
signature: "setStakeETHThreshold(uint256)",
// TODO: confirm this number makes sense
args: [ethers.utils.parseEther("32")], // 32ETH * 32
args: [ethers.utils.parseEther("1024")], // 32ETH * 32
},
// 7. set staking monitor
{
contract: cStrategy,
signature: "setStakingMonitor(address)",
args: [addresses.mainnet.Guardian], // 32ETH * 32
// The 5/8 multisig
args: [addresses.mainnet.Guardian],
},
// 8. Upgrade the OETH Harvester
{
Expand Down
260 changes: 135 additions & 125 deletions contracts/docs/NativeStakingSSVStrategySquashed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 68 additions & 54 deletions contracts/docs/NativeStakingSSVStrategyStorage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion contracts/test/behaviour/ssvStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const shouldBehaveLikeAnSsvStrategy = (context) => {
);
await expect(await nativeStakingSSVStrategy.stakingMonitor()).to.equal(
addresses.Guardian,
"Incorrect validator registrator"
"Incorrect staking monitor"
);
});
});
Expand Down
8 changes: 3 additions & 5 deletions contracts/test/strategies/nativeSSVStaking.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ describe("Unit test: Native SSV Staking Strategy", function () {
.setStakingMonitor(anna.address);

await nativeStakingSSVStrategy
.connect(anna)
.connect(governor)
.setStakeETHThreshold(stakeThreshold);
});

Expand Down Expand Up @@ -1094,9 +1094,7 @@ describe("Unit test: Native SSV Staking Strategy", function () {
]);

if (stakeTresholdErrorTriggered && i == validators - 1) {
await expect(tx).to.be.revertedWith(
"Staking ETH over approved threshold"
);
await expect(tx).to.be.revertedWith("Staking ETH over threshold");
} else {
await tx;
}
Expand Down Expand Up @@ -1145,7 +1143,7 @@ describe("Unit test: Native SSV Staking Strategy", function () {
nativeStakingSSVStrategy
.connect(josh)
.setStakeETHThreshold(ethUnits("32"))
).to.be.revertedWith("Caller is not the Monitor");
).to.be.revertedWith("Caller is not the Governor");
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("ForkTest: Convex 3pool/OUSD Meta Strategy - Balanced Metapool", functi
const currentBalance = await ousd.connect(anna).balanceOf(anna.address);

// Now try to redeem the amount
const redeemAmount = ousdUnits("29990");
const redeemAmount = ousdUnits("29900");
await vault.connect(anna).redeem(redeemAmount, 0);

// User balance should be down by 30k
Expand Down
Loading
Loading