Skip to content

Commit

Permalink
feat: stakeroot cleanup (#766)
Browse files Browse the repository at this point in the history
* chore: forge fmt src/contracts

* nit: organize imports

* fix: bump pragma -> ^0.8.27

* refactor(optimization): significantly reduce sloads/sstores

* refactor: custom errors

* refactor(optimization): significantly reduce sloads/sstores

missed some stuff

* refactor: rename compendium -> manager

* refactor: more storage optmizations

* feat: safe eth transfer helper

* refactor: manager -> compendium

* refactor: variable renaming

* refactor: rename compendium -> manager

* feat: add `proofIntervalSeconds` getter

* feat: fixed accounting bug and refactoring (#767)

* refactor: review reconciliations

* refactor: review reconciliations

* fix: rename colluding param

* fix: types and naming

* fix: revert stakeroot calculation changes

* fix: revert stakeRoot calc views

---------

Co-authored-by: shotaro <10378902+shotaronowhere@users.noreply.github.com>
  • Loading branch information
2 people authored and ypatil12 committed Sep 24, 2024
1 parent 40e762d commit 4b56b8c
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 261 deletions.
28 changes: 15 additions & 13 deletions script/deploy/devnet/operatorSets/PopulateSRC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ contract PopulateSRC is Script, Test, ExistingDeploymentParser {
StakeRootCompendium.initialize.selector,
msg.sender,
msg.sender,
1 minutes,
100 ether,
0,
0
uint32(1 minutes),
IStakeRootCompendium.ChargeParams({
chargePerOperatorSet: uint96(100 ether),
chargePerStrategy: uint96(0),
maxChargePerProof: uint96(0)
})
)
)));
vm.stopBroadcast();
emit log_named_address("allocationManager", address(allocationManager));
emit log_named_address("stakeRootCompendium", address(stakeRootCompendium));
emit log_named_address("StakeRootCompendium", address(stakeRootCompendium));

address[] memory allStrategies = _parseDeployedStrategies(strategyFile);

Expand Down Expand Up @@ -113,7 +115,7 @@ contract PopulateSRC is Script, Test, ExistingDeploymentParser {
}

string memory parent_object = "success";
vm.serializeAddress(parent_object, "stakeRootCompendium", address(stakeRootCompendium));
vm.serializeAddress(parent_object, "StakeRootCompendium", address(stakeRootCompendium));
vm.serializeAddress(parent_object, "avs", address(avs));
vm.serializeAddress(parent_object, "operators", operators[i]);
vm.serializeAddress(parent_object, "strategies", strategyAddresses);
Expand All @@ -125,12 +127,12 @@ contract PopulateSRC is Script, Test, ExistingDeploymentParser {

contract AVS {
IAVSDirectory avsDirectory;
IStakeRootCompendium stakeRootCompendium;
IStakeRootCompendium StakeRootCompendium;

// creates an operator set for each list of strategies
constructor(IAVSDirectory _avsDirectory, IStakeRootCompendium _stakeRootCompendium) {
constructor(IAVSDirectory _avsDirectory, IStakeRootCompendium _StakeRootCompendium) {
avsDirectory = _avsDirectory;
stakeRootCompendium = _stakeRootCompendium;
StakeRootCompendium = _StakeRootCompendium;
avsDirectory.becomeOperatorSetAVS();
}

Expand All @@ -141,7 +143,7 @@ contract AVS {
if(!avsDirectory.isOperatorSet(address(this), operatorSetId)) {
avsDirectory.createOperatorSets(operatorSetIdsToCreate);

stakeRootCompendium.deposit{value: 2 * stakeRootCompendium.MIN_BALANCE_THRESHOLD()}(OperatorSet({
StakeRootCompendium.deposit{value: 2 * StakeRootCompendium.MIN_BALANCE_THRESHOLD()}(OperatorSet({
avs: address(this),
operatorSetId: operatorSetId
}));
Expand All @@ -168,10 +170,10 @@ contract AVS {
multiplier: 1 ether
});
}
stakeRootCompendium.addOrModifyStrategiesAndMultipliers(operatorSetId, strategiesAndMultipliers);
stakeRootCompendium.setOperatorSetExtraData(operatorSetId, keccak256(abi.encodePacked(operatorSetId)));
StakeRootCompendium.addOrModifyStrategiesAndMultipliers(operatorSetId, strategiesAndMultipliers);
StakeRootCompendium.setOperatorSetExtraData(operatorSetId, keccak256(abi.encodePacked(operatorSetId)));
for (uint256 i = 0; i < operators.length; ++i) {
stakeRootCompendium.setOperatorExtraData(operatorSetId, operators[i], keccak256(abi.encodePacked(operators[i])));
StakeRootCompendium.setOperatorExtraData(operatorSetId, operators[i], keccak256(abi.encodePacked(operators[i])));
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ contract AllocationManager is
return uint64(totalMagnitude);
}

/// @dev gets the latest total magnitude
/// @dev gets the latest total magnitude
function _getLatestTotalMagnitudeView(address operator, IStrategy strategy) internal view returns (uint64) {
(bool exists,, uint224 totalMagnitude) = _totalMagnitudeUpdate[operator][strategy].latestSnapshot();
if (!exists) {
Expand All @@ -441,11 +441,8 @@ contract AllocationManager is
uint64 totalMagnitude = _getLatestTotalMagnitudeView(operator, strategy);

bytes32 operatorSetKey = _encodeOperatorSet(operatorSet);
uint64 currentMagnitude = uint64(
_magnitudeUpdate[operator][strategy][operatorSetKey].upperLookupLinear(
uint32(block.timestamp)
)
);
uint64 currentMagnitude =
uint64(_magnitudeUpdate[operator][strategy][operatorSetKey].upperLookupLinear(uint32(block.timestamp)));

return (totalMagnitude, currentMagnitude);
}
Expand Down Expand Up @@ -652,7 +649,8 @@ contract AllocationManager is
uint64[] memory totalMagnitude = new uint64[](strategies.length);
uint64[] memory allocatedMagnitude = new uint64[](strategies.length);
for (uint256 i = 0; i < strategies.length; ++i) {
(totalMagnitude[i], allocatedMagnitude[i]) = _getTotalAndAllocatedMagnitude(operator, operatorSet, strategies[i]);
(totalMagnitude[i], allocatedMagnitude[i]) =
_getTotalAndAllocatedMagnitude(operator, operatorSet, strategies[i]);
}
return (totalMagnitude, allocatedMagnitude);
}
Expand Down
Loading

0 comments on commit 4b56b8c

Please sign in to comment.