Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into gates-contracts
Browse files Browse the repository at this point in the history
# Conflicts:
#	script/DeployBase.s.sol
#	script/fork-helpers/SimulateVote.s.sol
  • Loading branch information
skhomuti committed Jan 14, 2025
2 parents bc5d50a + 9f812b3 commit c471b8e
Show file tree
Hide file tree
Showing 24 changed files with 1,218 additions and 30 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lib/
!src/lib
GAS.md
artifacts/
docs/
13 changes: 11 additions & 2 deletions script/DeployBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ abstract contract DeployBase is Script {
),
pivotSlot: Slot.wrap(
uint64(config.verifierSupportedEpoch * config.slotsPerEpoch)
)
),
admin: deployer
});

accounting.initialize({
Expand Down Expand Up @@ -261,15 +262,17 @@ abstract contract DeployBase is Script {
_avgPerfLeewayBP: config.avgPerfLeewayBP
});

address[] memory sealables = new address[](3);
address[] memory sealables = new address[](4);
sealables[0] = address(csm);
sealables[1] = address(accounting);
sealables[2] = address(oracle);
sealables[3] = address(verifier);
address gateSeal = _deployGateSeal(sealables);

csm.grantRole(csm.PAUSE_ROLE(), gateSeal);
oracle.grantRole(oracle.PAUSE_ROLE(), gateSeal);
accounting.grantRole(accounting.PAUSE_ROLE(), gateSeal);
verifier.grantRole(verifier.PAUSE_ROLE(), gateSeal);
accounting.grantRole(
accounting.RESET_BOND_CURVE_ROLE(),
config.setResetBondCurveAddress
Expand Down Expand Up @@ -299,6 +302,12 @@ abstract contract DeployBase is Script {
csm.grantRole(csm.DEFAULT_ADMIN_ROLE(), config.aragonAgent);
csm.revokeRole(csm.DEFAULT_ADMIN_ROLE(), deployer);

verifier.grantRole(
verifier.DEFAULT_ADMIN_ROLE(),
config.aragonAgent
);
verifier.revokeRole(verifier.DEFAULT_ADMIN_ROLE(), deployer);

accounting.grantRole(
accounting.DEFAULT_ADMIN_ROLE(),
config.aragonAgent
Expand Down
10 changes: 7 additions & 3 deletions script/DeployCSVerifierElectra.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Config {
Slot firstSupportedSlot;
Slot pivotSlot;
uint64 slotsPerEpoch;
address admin;
}

// Check the constants below via `yarn run gindex`.
Expand Down Expand Up @@ -63,7 +64,8 @@ abstract contract DeployCSVerifier is Script {
gIHistoricalSummariesPrev: config.gIHistoricalSummariesPrev,
gIHistoricalSummariesCurr: config.gIHistoricalSummariesCurr,
firstSupportedSlot: config.firstSupportedSlot,
pivotSlot: config.pivotSlot
pivotSlot: config.pivotSlot,
admin: config.admin
});
console.log("CSVerifier deployed at:", address(verifier));
}
Expand All @@ -82,7 +84,8 @@ contract DeployCSVerifierHolesky is DeployCSVerifier {
gIHistoricalSummariesPrev: HISTORICAL_SUMMARIES_DENEB,
gIHistoricalSummariesCurr: HISTORICAL_SUMMARIES_ELECTRA,
firstSupportedSlot: Slot.wrap(950272), // 269_568 * 32, @see https://github.com/eth-clients/mainnet/blob/main/metadata/config.yaml#L52
pivotSlot: Slot.wrap(0) // TODO: Update with Electra slot.
pivotSlot: Slot.wrap(0), // TODO: Update with Electra slot.
admin: 0xE92329EC7ddB11D25e25b3c21eeBf11f15eB325d // Aragon Agent
});
}
}
Expand All @@ -100,7 +103,8 @@ contract DeployCSVerifierMainnet is DeployCSVerifier {
gIHistoricalSummariesPrev: HISTORICAL_SUMMARIES_DENEB,
gIHistoricalSummariesCurr: HISTORICAL_SUMMARIES_ELECTRA,
firstSupportedSlot: Slot.wrap(8626176), // 29_696 * 32, @see https://github.com/eth-clients/holesky/blob/main/metadata/config.yaml#L38
pivotSlot: Slot.wrap(0) // TODO: Update with Electra slot.
pivotSlot: Slot.wrap(0), // TODO: Update with Electra slot.
admin: 0x3e40D73EB977Dc6a537aF587D48316feE66E9C8c // Aragon Agent
});
}
}
19 changes: 18 additions & 1 deletion script/DeployImplementationsBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Slot } from "../src/lib/Types.sol";
import { DeployBase } from "./DeployBase.s.sol";

abstract contract DeployImplementationsBase is DeployBase {
address gateSeal;
address earlyAdoption;

function _deploy() internal {
Expand Down Expand Up @@ -90,9 +91,24 @@ abstract contract DeployImplementationsBase is DeployBase {
),
pivotSlot: Slot.wrap(
uint64(config.verifierSupportedEpoch * config.slotsPerEpoch)
)
),
admin: deployer
});

address[] memory sealables = new address[](4);
sealables[0] = address(csm);
sealables[1] = address(accounting);
sealables[2] = address(oracle);
sealables[3] = address(verifier);
gateSeal = _deployGateSeal(sealables);

verifier.grantRole(verifier.PAUSE_ROLE(), address(gateSeal));
verifier.grantRole(
verifier.DEFAULT_ADMIN_ROLE(),
config.aragonAgent
);
verifier.revokeRole(verifier.DEFAULT_ADMIN_ROLE(), deployer);

JsonObj memory deployJson = Json.newObj();
deployJson.set("PermissionlessGate", address(permissionlessGate));
deployJson.set("VettedGate", address(vettedGate));
Expand All @@ -102,6 +118,7 @@ abstract contract DeployImplementationsBase is DeployBase {
deployJson.set("CSFeeDistributorImpl", address(feeDistributorImpl));
deployJson.set("CSVerifier", address(verifier));
deployJson.set("HashConsensus", address(hashConsensus));
deployJson.set("GateSeal", address(gateSeal));
deployJson.set("git-ref", gitRef);
vm.writeJson(
deployJson.str,
Expand Down
20 changes: 20 additions & 0 deletions script/fork-helpers/SimulateVote.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { DeploymentFixtures } from "test/helpers/Fixtures.sol";
import { IStakingRouter } from "../../src/interfaces/IStakingRouter.sol";
import { OssifiableProxy } from "../../src/lib/proxy/OssifiableProxy.sol";
import { CSModule } from "../../src/CSModule.sol";
import { CSAccounting } from "../../src/CSAccounting.sol";
import { CSFeeOracle } from "../../src/CSFeeOracle.sol";
import { IBurner } from "../../src/interfaces/IBurner.sol";
import { ForkHelpersCommon } from "./Common.sol";

Expand Down Expand Up @@ -100,6 +102,8 @@ contract SimulateVote is Script, DeploymentFixtures, ForkHelpersCommon {

address admin = _prepareAdmin(deploymentConfig.csm);
csm = CSModule(deploymentConfig.csm);
accounting = CSAccounting(deploymentConfig.accounting);
oracle = CSFeeOracle(deploymentConfig.oracle);

vm.startBroadcast(admin);

Expand All @@ -121,6 +125,22 @@ contract SimulateVote is Script, DeploymentFixtures, ForkHelpersCommon {
csm.revokeRole(csm.VERIFIER_ROLE(), address(deploymentConfig.verifier));
csm.grantRole(csm.VERIFIER_ROLE(), address(upgradeConfig.verifier));

csm.revokeRole(csm.PAUSE_ROLE(), address(deploymentConfig.gateSeal));
accounting.revokeRole(
accounting.PAUSE_ROLE(),
address(deploymentConfig.gateSeal)
);
oracle.revokeRole(
oracle.PAUSE_ROLE(),
address(deploymentConfig.gateSeal)
);

csm.grantRole(csm.PAUSE_ROLE(), address(upgradeConfig.gateSeal));
accounting.grantRole(
accounting.PAUSE_ROLE(),
address(upgradeConfig.gateSeal)
);
oracle.grantRole(oracle.PAUSE_ROLE(), address(upgradeConfig.gateSeal));
vm.stopBroadcast();
}
}
7 changes: 7 additions & 0 deletions src/CSAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ contract CSAccounting is
);
}

/// @inheritdoc ICSAccounting
function getClaimableBondShares(
uint256 nodeOperatorId
) public view returns (uint256) {
return _getClaimableBondShares(nodeOperatorId);
}

function _pullFeeRewards(
uint256 nodeOperatorId,
uint256 cumulativeFeeShares,
Expand Down
4 changes: 3 additions & 1 deletion src/CSFeeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract CSFeeDistributor is
}

STETH.transferShares(ACCOUNTING, sharesToDistribute);
emit FeeDistributed(nodeOperatorId, sharesToDistribute);
emit OperatorFeeDistributed(nodeOperatorId, sharesToDistribute);
}

/// @inheritdoc ICSFeeDistributor
Expand Down Expand Up @@ -121,6 +121,8 @@ contract CSFeeDistributor is
);
}

emit ModuleFeeDistributed(distributed);

// NOTE: Make sure off-chain tooling provides a distinct CID of a log even for empty reports, e.g. by mixing
// in a frame identifier such as reference slot to a file.
if (bytes(_logCid).length == 0) revert InvalidLogCID();
Expand Down
135 changes: 135 additions & 0 deletions src/CSPerksRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// SPDX-FileCopyrightText: 2024 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.24;

import { ICSPerksRegistry } from "./interfaces/ICSPerksRegistry.sol";
import { AccessControlEnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/extensions/AccessControlEnumerableUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract CSPerksRegistry is
ICSPerksRegistry,
Initializable,
AccessControlEnumerableUpgradeable
{
uint256 internal constant MAX_BP = 10000;

mapping(uint256 => uint256) internal _priorityQueueLimits;

mapping(uint256 => uint256[]) internal _rewardSharePivotsData;
mapping(uint256 => uint256[]) internal _rewardShareValuesData;

mapping(uint256 => uint256[]) internal _performanceLeewayPivotsData;
mapping(uint256 => uint256[]) internal _performanceLeewayValuesData;

constructor() {
_disableInitializers();
}

/// @notice initialize contract
function initialize(address admin) external initializer {
if (admin == address(0)) revert ZeroAdminAddress();
__AccessControlEnumerable_init();
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}

/// @inheritdoc ICSPerksRegistry
function setRewardShareData(
uint256 curveId,
uint256[] calldata keyPivots,
uint256[] calldata rewardShares
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (keyPivots.length + 1 != rewardShares.length)
revert InvalidRewardShareData();
if (keyPivots.length > 0 && keyPivots[0] == 0)
revert InvalidRewardShareData();
if (keyPivots.length > 1) {
for (uint256 i = 0; i < keyPivots.length - 1; ++i) {
if (keyPivots[i] >= keyPivots[i + 1])
revert InvalidRewardShareData();
}
}
for (uint256 i = 0; i < rewardShares.length; ++i) {
if (rewardShares[i] > MAX_BP) revert InvalidRewardShareData();
}
_rewardSharePivotsData[curveId] = keyPivots;
_rewardShareValuesData[curveId] = rewardShares;

emit RewardShareDataSet(curveId);
}

/// @inheritdoc ICSPerksRegistry
function getRewardShareData(
uint256 curveId
)
external
view
returns (uint256[] memory keyPivots, uint256[] memory rewardShares)
{
if (_rewardShareValuesData[curveId].length == 0) revert NoData();
return (
_rewardSharePivotsData[curveId],
_rewardShareValuesData[curveId]
);
}

/// @inheritdoc ICSPerksRegistry
function setPerformanceLeewayData(

Check warning on line 77 in src/CSPerksRegistry.sol

View workflow job for this annotation

GitHub Actions / Linters

Function order is incorrect, external function can not go after external view function (line 62)
uint256 curveId,
uint256[] calldata keyPivots,
uint256[] calldata performanceLeeways
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (keyPivots.length + 1 != performanceLeeways.length)
revert InvalidPerformanceLeewayData();
if (keyPivots.length > 0 && keyPivots[0] == 0)
revert InvalidPerformanceLeewayData();
if (keyPivots.length > 1) {
for (uint256 i = 0; i < keyPivots.length - 1; ++i) {
if (keyPivots[i] >= keyPivots[i + 1])
revert InvalidPerformanceLeewayData();
}
}
for (uint256 i = 0; i < performanceLeeways.length; ++i) {
if (performanceLeeways[i] > MAX_BP)
revert InvalidPerformanceLeewayData();
}
_performanceLeewayPivotsData[curveId] = keyPivots;
_performanceLeewayValuesData[curveId] = performanceLeeways;

emit PerformanceLeewayDataSet(curveId);
}

/// @inheritdoc ICSPerksRegistry
function getPerformanceLeewayData(
uint256 curveId
)
external
view
returns (
uint256[] memory keyPivots,
uint256[] memory performanceLeeways
)
{
if (_performanceLeewayValuesData[curveId].length == 0) revert NoData();
return (
_performanceLeewayPivotsData[curveId],
_performanceLeewayValuesData[curveId]
);
}

/// @inheritdoc ICSPerksRegistry
function setPriorityQueueLimit(
uint256 curveId,
uint256 limit
) external onlyRole(DEFAULT_ADMIN_ROLE) {
_priorityQueueLimits[curveId] = limit;
emit PriorityQueueLimitSet(curveId, limit);
}

/// @inheritdoc ICSPerksRegistry
function getPriorityQueueLimit(
uint256 curveId
) external view returns (uint256 limit) {
return _priorityQueueLimits[curveId];
}
}
Loading

0 comments on commit c471b8e

Please sign in to comment.