Skip to content

Commit c020f15

Browse files
authored
chore: style updates (#1416)
**Motivation:** We want consistent style across the repo **Modifications:** 1. Use modifier to gate access control 2. Don't use burn solo anywhere 3. Don't use virtual functions if not needed **Result:** Cleaner code
1 parent bd2663f commit c020f15

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed

src/contracts/core/DelegationManager.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ contract DelegationManager is
288288
IStrategy strategy,
289289
uint64 prevMaxMagnitude,
290290
uint64 newMaxMagnitude
291-
) external onlyAllocationManager nonReentrant returns (uint256 totalDepositSharesToBurn) {
291+
) external onlyAllocationManager nonReentrant returns (uint256 totalDepositSharesToSlash) {
292292
uint256 operatorSharesSlashed = SlashingLib.calcSlashedAmount({
293293
operatorShares: operatorShares[operator][strategy],
294294
prevMaxMagnitude: prevMaxMagnitude,
@@ -304,7 +304,7 @@ contract DelegationManager is
304304

305305
// Calculate the total deposit shares to burn - slashed operator shares plus still-slashable
306306
// shares sitting in the withdrawal queue.
307-
totalDepositSharesToBurn = operatorSharesSlashed + scaledSharesSlashedFromQueue;
307+
totalDepositSharesToSlash = operatorSharesSlashed + scaledSharesSlashedFromQueue;
308308

309309
// Remove shares from operator
310310
_decreaseDelegation({
@@ -315,13 +315,13 @@ contract DelegationManager is
315315
});
316316

317317
// Emit event for operator shares being slashed
318-
emit OperatorSharesSlashed(operator, strategy, totalDepositSharesToBurn);
318+
emit OperatorSharesSlashed(operator, strategy, totalDepositSharesToSlash);
319319

320320
_getShareManager(strategy).increaseBurnOrRedistributableShares(
321-
operatorSet, slashId, strategy, totalDepositSharesToBurn
321+
operatorSet, slashId, strategy, totalDepositSharesToSlash
322322
);
323323

324-
return totalDepositSharesToBurn;
324+
return totalDepositSharesToSlash;
325325
}
326326

327327
/**

src/contracts/core/SlashEscrow.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contract SlashEscrow is ISlashEscrow {
1818
uint256 slashId,
1919
address recipient,
2020
IStrategy strategy
21-
) external virtual {
21+
) external {
2222
// Assert that the deployment parameters are valid by validating against the address of this proxy.
2323
require(
2424
verifyDeploymentParameters(slashEscrowFactory, slashEscrowImplementation, operatorSet, slashId),
@@ -39,7 +39,7 @@ contract SlashEscrow is ISlashEscrow {
3939
ISlashEscrow slashEscrowImplementation,
4040
OperatorSet calldata operatorSet,
4141
uint256 slashId
42-
) public view virtual returns (bool) {
42+
) public view returns (bool) {
4343
return ClonesUpgradeable.predictDeterministicAddress(
4444
address(slashEscrowImplementation),
4545
keccak256(abi.encodePacked(operatorSet.key(), slashId)),

src/contracts/core/SlashEscrowFactory.sol

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ contract SlashEscrowFactory is Initializable, SlashEscrowFactoryStorage, Ownable
1414
using OperatorSetLib for *;
1515
using EnumerableSet for *;
1616
using ClonesUpgradeable for address;
17+
18+
modifier onlyStrategyManager() {
19+
require(msg.sender == address(strategyManager), OnlyStrategyManager());
20+
_;
21+
}
22+
1723
/**
1824
*
1925
* INITIALIZATION
2026
*
2127
*/
22-
2328
constructor(
2429
IAllocationManager _allocationManager,
2530
IStrategyManager _strategyManager,
@@ -52,9 +57,11 @@ contract SlashEscrowFactory is Initializable, SlashEscrowFactoryStorage, Ownable
5257
*/
5358

5459
/// @inheritdoc ISlashEscrowFactory
55-
function initiateSlashEscrow(OperatorSet calldata operatorSet, uint256 slashId, IStrategy strategy) external {
56-
require(msg.sender == address(strategyManager), OnlyStrategyManager());
57-
60+
function initiateSlashEscrow(
61+
OperatorSet calldata operatorSet,
62+
uint256 slashId,
63+
IStrategy strategy
64+
) external onlyStrategyManager {
5865
// Create storage pointers for readability.
5966
EnumerableSet.UintSet storage pendingSlashIds = _pendingSlashIds[operatorSet.key()];
6067
EnumerableSet.AddressSet storage pendingStrategiesForSlashId =

src/contracts/core/SlashEscrowFactoryStorage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract contract SlashEscrowFactoryStorage is ISlashEscrowFactory {
5151
/// @dev Returns the global escrow delay for all strategies.
5252
uint32 internal _globalEscrowDelayBlocks;
5353

54-
/// @dev Returns the operator set delay for a given strategy.
54+
/// @dev Returns the escrow delay for a given strategy.
5555
mapping(address strategy => uint32 delay) internal _strategyEscrowDelayBlocks;
5656

5757
// Constructor

src/contracts/core/StrategyManager.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,18 @@ contract StrategyManager is
171171
function clearBurnOrRedistributableShares(
172172
OperatorSet calldata operatorSet,
173173
uint256 slashId
174-
) external nonReentrant {
174+
) external nonReentrant returns (uint256[] memory) {
175175
// Get the strategies to clear.
176176
address[] memory strategies = _burnOrRedistributableShares[operatorSet.key()][slashId].keys();
177177
uint256 length = strategies.length;
178+
uint256[] memory amounts = new uint256[](length);
178179

179180
// Note: We don't need to iterate backwards since we're indexing into the `EnumerableMap` directly.
180181
for (uint256 i = 0; i < length; ++i) {
181-
clearBurnOrRedistributableSharesByStrategy(operatorSet, slashId, IStrategy(strategies[i]));
182+
amounts[i] = clearBurnOrRedistributableSharesByStrategy(operatorSet, slashId, IStrategy(strategies[i]));
182183
}
184+
185+
return amounts;
183186
}
184187

185188
/// @inheritdoc IStrategyManager
@@ -194,9 +197,10 @@ contract StrategyManager is
194197
(, uint256 sharesToRemove) = burnOrRedistributableShares.tryGet(address(strategy));
195198
burnOrRedistributableShares.remove(address(strategy));
196199

200+
uint256 amountOut;
197201
if (sharesToRemove != 0) {
198202
// Withdraw the shares to the slash escrow.
199-
IStrategy(strategy).withdraw({
203+
amountOut = IStrategy(strategy).withdraw({
200204
recipient: address(slashEscrowFactory.getSlashEscrow(operatorSet, slashId)),
201205
token: IStrategy(strategy).underlyingToken(),
202206
amountShares: sharesToRemove
@@ -206,7 +210,7 @@ contract StrategyManager is
206210
emit BurnOrRedistributableSharesDecreased(operatorSet, slashId, strategy, sharesToRemove);
207211
}
208212

209-
return sharesToRemove;
213+
return amountOut;
210214
}
211215

212216
/// @inheritdoc IStrategyManager

src/contracts/interfaces/IDelegationManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ interface IDelegationManager is ISignatureUtilsMixin, IDelegationManagerErrors,
365365
* @dev Callable only by the AllocationManager.
366366
* @dev Note: Assumes `prevMaxMagnitude <= newMaxMagnitude`. This invariant is maintained in
367367
* the AllocationManager.
368-
* @return totalDepositSharesToBurn The total deposit shares to burn.
368+
* @return totalDepositSharesToSlash The total deposit shares to burn or redistribute.
369369
*/
370370
function slashOperatorShares(
371371
address operator,
@@ -374,7 +374,7 @@ interface IDelegationManager is ISignatureUtilsMixin, IDelegationManagerErrors,
374374
IStrategy strategy,
375375
uint64 prevMaxMagnitude,
376376
uint64 newMaxMagnitude
377-
) external returns (uint256 totalDepositSharesToBurn);
377+
) external returns (uint256 totalDepositSharesToSlash);
378378

379379
/**
380380
*

src/contracts/interfaces/IStrategyManager.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,19 @@ interface IStrategyManager is IStrategyManagerErrors, IStrategyManagerEvents, IS
139139
* @notice Removes burned shares from storage and transfers the underlying tokens for the slashId to the slash escrow.
140140
* @param operatorSet The operator set to burn shares in.
141141
* @param slashId The slash ID to burn shares in.
142+
* @return The amounts of tokens transferred to the slash escrow for each strategy
142143
*/
143-
function clearBurnOrRedistributableShares(OperatorSet calldata operatorSet, uint256 slashId) external;
144+
function clearBurnOrRedistributableShares(
145+
OperatorSet calldata operatorSet,
146+
uint256 slashId
147+
) external returns (uint256[] memory);
144148

145149
/**
146150
* @notice Removes a single strategy's shares from storage and transfers the underlying tokens for the slashId to the slash escrow.
147151
* @param operatorSet The operator set to burn shares in.
148152
* @param slashId The slash ID to burn shares in.
149153
* @param strategy The strategy to burn shares in.
150-
* @return The amount of shares that were burned.
154+
* @return The amount of tokens transferred to the slash escrow for the strategy.
151155
*/
152156
function clearBurnOrRedistributableSharesByStrategy(
153157
OperatorSet calldata operatorSet,

src/test/mocks/StrategyManagerMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ contract StrategyManagerMock is Test {
110110
return (existingShares, addedShares);
111111
}
112112

113-
function clearBurnOrRedistributableShares(OperatorSet calldata operatorSet, uint slashId) external {}
113+
function clearBurnOrRedistributableShares(OperatorSet calldata operatorSet, uint slashId) external returns (address[] memory) {}
114114

115115
function clearBurnOrRedistributableSharesByStrategy(OperatorSet calldata operatorSet, uint slashId, IStrategy strategy)
116116
external

0 commit comments

Comments
 (0)