Skip to content

Commit

Permalink
Merge pull request #688 from lidofinance/fix/shapella-upgrade-beta3-t…
Browse files Browse the repository at this point in the history
…o-rc

Fix: shapella upgrade from beta3 to rc
  • Loading branch information
TheDZhon authored Mar 22, 2023
2 parents 2bce10d + 98ff5e7 commit 3fa9940
Show file tree
Hide file tree
Showing 56 changed files with 4,330 additions and 1,350 deletions.
18 changes: 9 additions & 9 deletions contracts/0.4.24/Lido.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,8 @@ contract Lido is Versioned, StETHPermit, AragonApp {
* 4. Pass the accounting values to sanity checker to smoothen positive token rebase
* (i.e., postpone the extra rewards to be applied during the next rounds)
* 5. Invoke finalization of the withdrawal requests
* 6. Distribute protocol fee (treasury & node operators)
* 7. Burn excess shares within the allowed limit (can postpone some shares to be burnt later)
* 6. Burn excess shares within the allowed limit (can postpone some shares to be burnt later)
* 7. Distribute protocol fee (treasury & node operators)
* 8. Complete token rebase by informing observers (emit an event and call the external receivers if any)
* 9. Sanity check for the provided simulated share rate
*/
Expand Down Expand Up @@ -1261,6 +1261,13 @@ contract Lido is Versioned, StETHPermit, AragonApp {
);

// Step 6.
// Burn the previously requested shares
if (reportContext.sharesToBurn > 0) {
IBurner(contracts.burner).commitSharesToBurn(reportContext.sharesToBurn);
_burnShares(contracts.burner, reportContext.sharesToBurn);
}

// Step 7.
// Distribute protocol fee (treasury & node operators)
reportContext.sharesMintedAsFees = _processRewards(
reportContext,
Expand All @@ -1269,13 +1276,6 @@ contract Lido is Versioned, StETHPermit, AragonApp {
elRewards
);

// Step 7.
// Burn the previously requested shares
if (reportContext.sharesToBurn > 0) {
IBurner(contracts.burner).commitSharesToBurn(reportContext.sharesToBurn);
_burnShares(contracts.burner, reportContext.sharesToBurn);
}

// Step 8.
// Complete token rebase by informing observers (emit an event and call the external receivers if any)
(
Expand Down
86 changes: 43 additions & 43 deletions contracts/0.4.24/nos/NodeOperatorsRegistry.sol

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion contracts/0.4.24/test_helpers/MockLegacyOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ contract MockLegacyOracle is ILegacyOracle, LegacyOracle {
}

function initializeAsV3() external {
CONTRACT_VERSION_POSITION_DEPRECATED.setStorageUint256(3);
CONTRACT_VERSION_POSITION_DEPRECATED.setStorageUint256(3);
}

function setLido(address lido) external {
LIDO_POSITION.setStorageAddress(lido);
}

}
28 changes: 14 additions & 14 deletions contracts/0.4.24/test_helpers/NodeOperatorsRegistryMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ contract NodeOperatorsRegistryMock is NodeOperatorsRegistry {

function increaseNodeOperatorDepositedSigningKeysCount(uint256 _nodeOperatorId, uint64 _keysCount) external {
Packed64x4.Packed memory signingKeysStats = _nodeOperators[_nodeOperatorId].signingKeysStats;
signingKeysStats.set(DEPOSITED_KEYS_COUNT_OFFSET, signingKeysStats.get(DEPOSITED_KEYS_COUNT_OFFSET) + _keysCount);
signingKeysStats.set(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET, signingKeysStats.get(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET) + _keysCount);
_nodeOperators[_nodeOperatorId].signingKeysStats = signingKeysStats;

Packed64x4.Packed memory totalSigningKeysStats = _loadSummarySigningKeysStats();
totalSigningKeysStats.set(
DEPOSITED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(DEPOSITED_KEYS_COUNT_OFFSET).add(_keysCount)
TOTAL_DEPOSITED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET).add(_keysCount)
);
_saveSummarySigningKeysStats(totalSigningKeysStats);

Expand All @@ -26,34 +26,34 @@ contract NodeOperatorsRegistryMock is NodeOperatorsRegistry {
Packed64x4.Packed memory signingKeysStats;
for (uint256 i; i < nodeOperatorsCount; ++i) {
signingKeysStats = _loadOperatorSigningKeysStats(i);
testing_setDepositedSigningKeysCount(i, signingKeysStats.get(VETTED_KEYS_COUNT_OFFSET));
testing_setDepositedSigningKeysCount(i, signingKeysStats.get(TOTAL_VETTED_KEYS_COUNT_OFFSET));
}
}

function testing_markAllKeysDeposited(uint256 _nodeOperatorId) external {
_onlyExistedNodeOperator(_nodeOperatorId);
Packed64x4.Packed memory signingKeysStats = _nodeOperators[_nodeOperatorId].signingKeysStats;
testing_setDepositedSigningKeysCount(_nodeOperatorId, signingKeysStats.get(VETTED_KEYS_COUNT_OFFSET));
testing_setDepositedSigningKeysCount(_nodeOperatorId, signingKeysStats.get(TOTAL_VETTED_KEYS_COUNT_OFFSET));
}

function testing_setDepositedSigningKeysCount(uint256 _nodeOperatorId, uint256 _depositedSigningKeysCount) public {
_onlyExistedNodeOperator(_nodeOperatorId);
// NodeOperator storage nodeOperator = _nodeOperators[_nodeOperatorId];
Packed64x4.Packed memory signingKeysStats = _loadOperatorSigningKeysStats(_nodeOperatorId);
uint64 depositedSigningKeysCountBefore = signingKeysStats.get(DEPOSITED_KEYS_COUNT_OFFSET);
uint64 depositedSigningKeysCountBefore = signingKeysStats.get(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET);
if (_depositedSigningKeysCount == depositedSigningKeysCountBefore) {
return;
}

require(
_depositedSigningKeysCount <= signingKeysStats.get(VETTED_KEYS_COUNT_OFFSET),
_depositedSigningKeysCount <= signingKeysStats.get(TOTAL_VETTED_KEYS_COUNT_OFFSET),
"DEPOSITED_SIGNING_KEYS_COUNT_TOO_HIGH"
);
require(
_depositedSigningKeysCount >= signingKeysStats.get(EXITED_KEYS_COUNT_OFFSET), "DEPOSITED_SIGNING_KEYS_COUNT_TOO_LOW"
_depositedSigningKeysCount >= signingKeysStats.get(TOTAL_EXITED_KEYS_COUNT_OFFSET), "DEPOSITED_SIGNING_KEYS_COUNT_TOO_LOW"
);

signingKeysStats.set(DEPOSITED_KEYS_COUNT_OFFSET, uint64(_depositedSigningKeysCount));
signingKeysStats.set(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET, uint64(_depositedSigningKeysCount));
_saveOperatorSigningKeysStats(_nodeOperatorId, signingKeysStats);

emit DepositedSigningKeysCountChanged(_nodeOperatorId, _depositedSigningKeysCount);
Expand Down Expand Up @@ -87,9 +87,9 @@ contract NodeOperatorsRegistryMock is NodeOperatorsRegistry {
operator.rewardAddress = _rewardAddress;

Packed64x4.Packed memory signingKeysStats;
signingKeysStats.set(DEPOSITED_KEYS_COUNT_OFFSET, depositedSigningKeysCount);
signingKeysStats.set(VETTED_KEYS_COUNT_OFFSET, vettedSigningKeysCount);
signingKeysStats.set(EXITED_KEYS_COUNT_OFFSET, exitedSigningKeysCount);
signingKeysStats.set(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET, depositedSigningKeysCount);
signingKeysStats.set(TOTAL_VETTED_KEYS_COUNT_OFFSET, vettedSigningKeysCount);
signingKeysStats.set(TOTAL_EXITED_KEYS_COUNT_OFFSET, exitedSigningKeysCount);
signingKeysStats.set(TOTAL_KEYS_COUNT_OFFSET, totalSigningKeysCount);

operator.signingKeysStats = signingKeysStats;
Expand All @@ -101,9 +101,9 @@ contract NodeOperatorsRegistryMock is NodeOperatorsRegistry {
emit NodeOperatorAdded(id, _name, _rewardAddress, 0);

Packed64x4.Packed memory totalSigningKeysStats = _loadSummarySigningKeysStats();
totalSigningKeysStats.set(VETTED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(VETTED_KEYS_COUNT_OFFSET).add(vettedSigningKeysCount));
totalSigningKeysStats.set(DEPOSITED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(DEPOSITED_KEYS_COUNT_OFFSET).add(depositedSigningKeysCount));
totalSigningKeysStats.set(EXITED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(EXITED_KEYS_COUNT_OFFSET).add(exitedSigningKeysCount));
totalSigningKeysStats.set(TOTAL_VETTED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(TOTAL_VETTED_KEYS_COUNT_OFFSET).add(vettedSigningKeysCount));
totalSigningKeysStats.set(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(TOTAL_DEPOSITED_KEYS_COUNT_OFFSET).add(depositedSigningKeysCount));
totalSigningKeysStats.set(TOTAL_EXITED_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(TOTAL_EXITED_KEYS_COUNT_OFFSET).add(exitedSigningKeysCount));
totalSigningKeysStats.set(TOTAL_KEYS_COUNT_OFFSET, totalSigningKeysStats.get(TOTAL_KEYS_COUNT_OFFSET).add(totalSigningKeysCount));
_saveSummarySigningKeysStats(totalSigningKeysStats);
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/0.8.9/DepositSecurityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface IStakingRouter {
function getStakingModuleIsActive(uint256 _stakingModuleId) external view returns (bool);
function getStakingModuleNonce(uint256 _stakingModuleId) external view returns (uint256);
function getStakingModuleLastDepositBlock(uint256 _stakingModuleId) external view returns (uint256);
function hasStakingModule(uint256 _stakingModuleId) external view returns (bool);
}


Expand Down Expand Up @@ -377,6 +378,8 @@ contract DepositSecurityModule {
* such attestations will be enough to reach quorum.
*/
function canDeposit(uint256 stakingModuleId) external view returns (bool) {
if (!STAKING_ROUTER.hasStakingModule(stakingModuleId)) return false;

bool isModuleActive = STAKING_ROUTER.getStakingModuleIsActive(stakingModuleId);
uint256 lastDepositBlock = STAKING_ROUTER.getStakingModuleLastDepositBlock(stakingModuleId);
bool isLidoCanDeposit = LIDO.canDeposit();
Expand Down
Loading

0 comments on commit 3fa9940

Please sign in to comment.