Skip to content

Commit 0185f07

Browse files
committed
Restricted snapBalances when consolidation is in progress
1 parent 0692950 commit 0185f07

File tree

5 files changed

+54
-20
lines changed

5 files changed

+54
-20
lines changed

contracts/contracts/strategies/NativeStaking/CompoundingValidatorManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ abstract contract CompoundingValidatorManager is Governable, Pausable {
957957
/// This behaviour is correct.
958958
///
959959
/// The validator balances on the beacon chain can then be proved with `verifyBalances`.
960-
function snapBalances() external {
960+
function snapBalances() external onlyRegistrator {
961961
uint64 currentTimestamp = SafeCast.toUint64(block.timestamp);
962962
require(
963963
snappedBalance.timestamp + SNAP_BALANCES_DELAY < currentTimestamp,

contracts/contracts/strategies/NativeStaking/ConsolidationController.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ contract ConsolidationController is Ownable {
287287
*
288288
*/
289289

290+
/// @notice Forwards to the new Compounding Staking Strategy.
291+
/// Is only callable by the validator registrator when a consolidation is in progress.
292+
/// Anyone can call when there are no consolidations in progress.
293+
function snapBalances() external {
294+
if (consolidationCount > 0 && msg.sender != validatorRegistrator) {
295+
revert("Consolidation in progress");
296+
}
297+
298+
targetStrategy.snapBalances();
299+
}
300+
290301
/**
291302
* @notice Anyone can verify balances on the new Compounding Staking Strategy
292303
* as long as there are no consolidations in progress.

contracts/tasks/tasks.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,10 +2448,14 @@ task("stakeValidator").setAction(async (_, __, runSuper) => {
24482448
return runSuper();
24492449
});
24502450

2451-
subtask(
2452-
"snapBalances",
2453-
"Takes a snapshot of the staking strategy's balance"
2454-
).setAction(snapBalances);
2451+
subtask("snapBalances", "Takes a snapshot of the staking strategy's balance")
2452+
.addOptionalParam(
2453+
"consol",
2454+
"Call the consolidation controller instead of the strategy",
2455+
false,
2456+
types.boolean
2457+
)
2458+
.setAction(snapBalances);
24552459
task("snapBalances").setAction(async (_, __, runSuper) => {
24562460
return runSuper();
24572461
});

contracts/tasks/validatorCompound.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ const {
3333

3434
const log = require("../utils/logger")("task:validator:compounding");
3535

36-
async function snapBalances() {
36+
async function snapBalances({ consol = false }) {
3737
const signer = await getSigner();
3838

3939
// TODO check the slot of the first pending deposit is not zero
4040

41-
const strategy = await resolveContract(
42-
"CompoundingStakingSSVStrategyProxy",
43-
"CompoundingStakingSSVStrategy"
44-
);
41+
const contract = consol
42+
? await resolveContract("ConsolidationController")
43+
: await resolveContract(
44+
"CompoundingStakingSSVStrategyProxy",
45+
"CompoundingStakingSSVStrategy"
46+
);
4547

46-
log(`About to snap balances for strategy ${strategy.address}`);
47-
const tx = await strategy.connect(signer).snapBalances();
48+
log(`About to snap balances on ${contract.address}`);
49+
const tx = await contract.connect(signer).snapBalances();
4850
await logTxDetails(tx, "snapBalances");
4951

5052
const receipt = await tx.wait();

contracts/test/strategies/stakingConsolidation.mainnet.fork-test.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe("ForkTest: Consolidation of Staking Strategies", function () {
201201
"0x67d077e55a1f4af124a8df1e1ac720d1e1e557a5305d774c5ebf98be3479cf8d"
202202
);
203203

204-
await compoundingStakingStrategy.connect(registratorSigner).snapBalances();
204+
await consolidationController.connect(registratorSigner).snapBalances();
205205

206206
await consolidationController
207207
.connect(registratorSigner)
@@ -606,9 +606,17 @@ describe("ForkTest: Consolidation of Staking Strategies", function () {
606606

607607
await expect(tx).to.be.revertedWith("No consolidation in progress");
608608
});
609+
it("Should call snapBalance on the Consolidation Controller by anyone when no consolidation in progress", async () => {
610+
const { josh } = fixture;
611+
await advanceTime(12 * 40);
612+
613+
const tx = await consolidationController.connect(josh).snapBalances();
614+
615+
await expect(tx).to.emit(compoundingStakingStrategy, "BalancesSnapped");
616+
});
609617
it("Fail to directly call verifyBalance on the Compounding Staking Strategy", async () => {
610618
await advanceTime(12 * 40);
611-
await compoundingStakingStrategy.snapBalances();
619+
await consolidationController.snapBalances();
612620

613621
const tx = compoundingStakingStrategy
614622
.connect(registratorSigner)
@@ -795,17 +803,26 @@ describe("ForkTest: Consolidation of Staking Strategies", function () {
795803
await expect(tx).to.emit(compoundingStakingStrategy, "BalancesVerified");
796804
});
797805
// Balance proofs after the deposit to validator 13498458 has been verified.
798-
it("Should call snapBalance on the Compounding Staking Strategy", async () => {
799-
const { josh } = fixture;
806+
it("Should call snapBalance on the Consolidation Controller by the Registrator after the consolidation has started", async () => {
800807
await advanceTime(12 * 40);
801808

802-
const tx = await compoundingStakingStrategy.connect(josh).snapBalances();
809+
const tx = await consolidationController
810+
.connect(registratorSigner)
811+
.snapBalances();
803812

804813
await expect(tx).to.emit(compoundingStakingStrategy, "BalancesSnapped");
805814
});
806-
it("Fail to verifyBalance of a snapshot after the consolidation was started", async () => {
815+
it("Fail snapBalance on the new compounding staking strategy when called by non-registrator after the consolidation has started", async () => {
816+
const { josh } = fixture;
817+
await advanceTime(12 * 40);
818+
819+
const tx = compoundingStakingStrategy.connect(josh).snapBalances();
820+
821+
await expect(tx).to.be.revertedWith("Not Registrator");
822+
});
823+
it("Fail to verifyBalance of a snapshot after the consolidation has started", async () => {
807824
await advanceTime(12 * 40);
808-
await compoundingStakingStrategy.snapBalances();
825+
await consolidationController.connect(registratorSigner).snapBalances();
809826

810827
const tx = consolidationController
811828
.connect(registratorSigner)
@@ -1040,7 +1057,7 @@ describe("ForkTest: Consolidation of Staking Strategies", function () {
10401057
beaconBlockRoot
10411058
);
10421059

1043-
await compoundingStakingStrategy.connect(fixture.josh).snapBalances();
1060+
await consolidationController.connect(registratorSigner).snapBalances();
10441061
});
10451062

10461063
it("Should confirm consolidation", async () => {

0 commit comments

Comments
 (0)