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

feat: changing burnableShares to EnumerableMap #1028

Merged
merged 13 commits into from
Jan 21, 2025
4 changes: 2 additions & 2 deletions docs/storage-report/StrategyManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
|----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+--------------------------------------------------------|
| __deprecated_thirdPartyTransfersForbidden | mapping(contract IStrategy => bool) | 211 | 0 | 32 | src/contracts/core/StrategyManager.sol:StrategyManager |
|----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+--------------------------------------------------------|
| burnableShares | mapping(contract IStrategy => uint256) | 212 | 0 | 32 | src/contracts/core/StrategyManager.sol:StrategyManager |
| burnableShares | struct EnumerableMap.AddressToUintMap | 212 | 0 | 96 | src/contracts/core/StrategyManager.sol:StrategyManager |
eigenmikem marked this conversation as resolved.
Show resolved Hide resolved
|----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+--------------------------------------------------------|
| __gap | uint256[38] | 213 | 0 | 1216 | src/contracts/core/StrategyManager.sol:StrategyManager |
| __gap | uint256[38] | 215 | 0 | 1216 | src/contracts/core/StrategyManager.sol:StrategyManager |
╰----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+--------------------------------------------------------╯

4 changes: 2 additions & 2 deletions docs/storage-report/StrategyManagerStorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
|----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+----------------------------------------------------------------------|
| __deprecated_thirdPartyTransfersForbidden | mapping(contract IStrategy => bool) | 10 | 0 | 32 | src/contracts/core/StrategyManagerStorage.sol:StrategyManagerStorage |
|----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+----------------------------------------------------------------------|
| burnableShares | mapping(contract IStrategy => uint256) | 11 | 0 | 32 | src/contracts/core/StrategyManagerStorage.sol:StrategyManagerStorage |
| burnableShares | struct EnumerableMap.AddressToUintMap | 11 | 0 | 96 | src/contracts/core/StrategyManagerStorage.sol:StrategyManagerStorage |
|----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+----------------------------------------------------------------------|
| __gap | uint256[38] | 12 | 0 | 1216 | src/contracts/core/StrategyManagerStorage.sol:StrategyManagerStorage |
| __gap | uint256[38] | 14 | 0 | 1216 | src/contracts/core/StrategyManagerStorage.sol:StrategyManagerStorage |
╰----------------------------------------------------------+------------------------------------------------------------+------+--------+-------+----------------------------------------------------------------------╯

7 changes: 4 additions & 3 deletions src/contracts/core/StrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ contract StrategyManager is

/// @inheritdoc IShareManager
function increaseBurnableShares(IStrategy strategy, uint256 addedSharesToBurn) external onlyDelegationManager {
burnableShares[strategy] += addedSharesToBurn;
(, uint256 currentShares) = EnumerableMap.tryGet(burnableShares, address(strategy));
EnumerableMap.set(burnableShares, address(strategy), currentShares + addedSharesToBurn);
emit BurnableSharesIncreased(strategy, addedSharesToBurn);
}

/// @inheritdoc IStrategyManager
function burnShares(
IStrategy strategy
) external nonReentrant {
uint256 sharesToBurn = burnableShares[strategy];
burnableShares[strategy] = 0;
(, uint256 sharesToBurn) = EnumerableMap.tryGet(burnableShares, address(strategy));
EnumerableMap.set(burnableShares, address(strategy), 0);
0xClandestine marked this conversation as resolved.
Show resolved Hide resolved
emit BurnableSharesDecreased(strategy, sharesToBurn);
// burning shares is functionally the same as withdrawing but with different destination address
strategy.withdraw(DEFAULT_BURN_ADDRESS, strategy.underlyingToken(), sharesToBurn);
Expand Down
11 changes: 10 additions & 1 deletion src/contracts/core/StrategyManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "../interfaces/IStrategy.sol";
import "../interfaces/IEigenPodManager.sol";
import "../interfaces/IDelegationManager.sol";
import "../interfaces/IAVSDirectory.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
eigenmikem marked this conversation as resolved.
Show resolved Hide resolved

/**
* @title Storage variables for the `StrategyManager` contract.
Expand Down Expand Up @@ -70,7 +71,7 @@ abstract contract StrategyManagerStorage is IStrategyManager {
mapping(IStrategy strategy => bool) private __deprecated_thirdPartyTransfersForbidden;

/// @notice Returns the amount of `shares` that have been slashed on EigenLayer but not burned yet.
eigenmikem marked this conversation as resolved.
Show resolved Hide resolved
mapping(IStrategy strategy => uint256) public burnableShares;
EnumerableMap.AddressToUintMap internal burnableShares;

// Construction

Expand All @@ -83,6 +84,14 @@ abstract contract StrategyManagerStorage is IStrategyManager {
delegation = _delegation;
}

//Access for burnableShares
eigenmikem marked this conversation as resolved.
Show resolved Hide resolved
function getBurnableShares(
IStrategy strategy
) public view returns (uint256) {
(, uint256 shares) = EnumerableMap.tryGet(burnableShares, address(strategy));
return shares;
}

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
Expand Down
8 changes: 4 additions & 4 deletions src/test/unit/StrategyManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ contract StrategyManagerUnitTests_increaseBurnableShares is StrategyManagerUnitT
cheats.prank(address(delegationManagerMock));
strategyManager.increaseBurnableShares(strategy, addedSharesToBurn);
assertEq(
strategyManager.burnableShares(strategy),
strategyManager.getBurnableShares(strategy),
addedSharesToBurn,
"strategyManager.burnableShares(strategy) != addedSharesToBurn"
);
Expand All @@ -1487,7 +1487,7 @@ contract StrategyManagerUnitTests_increaseBurnableShares is StrategyManagerUnitT
emit BurnableSharesIncreased(strategy, existingBurnableShares);
strategyManager.increaseBurnableShares(strategy, existingBurnableShares);
assertEq(
strategyManager.burnableShares(strategy),
strategyManager.getBurnableShares(strategy),
existingBurnableShares,
"strategyManager.burnableShares(strategy) != existingBurnableShares"
);
Expand All @@ -1498,7 +1498,7 @@ contract StrategyManagerUnitTests_increaseBurnableShares is StrategyManagerUnitT
strategyManager.increaseBurnableShares(strategy, addedSharesToBurn);

assertEq(
strategyManager.burnableShares(strategy),
strategyManager.getBurnableShares(strategy),
existingBurnableShares + addedSharesToBurn,
"strategyManager.burnableShares(strategy) != existingBurnableShares + addedSharesToBurn"
);
Expand Down Expand Up @@ -1572,7 +1572,7 @@ contract StrategyManagerUnitTests_burnShares is StrategyManagerUnitTests {
strategyManager.burnShares(strategy);

assertEq(
strategyManager.burnableShares(strategy),
strategyManager.getBurnableShares(strategy),
sharesToBurn,
"burnable shares should be unchanged"
);
Expand Down
Loading