Skip to content

Commit

Permalink
feat(contracts): indicate minimum collateral requirements in manager …
Browse files Browse the repository at this point in the history
…view methods
  • Loading branch information
mempirate committed Oct 16, 2024
1 parent 1f779d4 commit ff311eb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
17 changes: 15 additions & 2 deletions bolt-contracts/src/contracts/BoltManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ contract BoltManager is IBoltManager, OwnableUpgradeable, UUPSUpgradeable {
/// @notice Get the status of multiple proposers, given their pubkey hashes.
/// @param pubkeyHashes The pubkey hashes of the proposers to get the status for.
/// @return statuses The statuses of the proposers, including their operator and active stake.
function getProposersStatus(
function getProposerStatuses(
bytes32[] calldata pubkeyHashes
) public view returns (IBoltValidators.ProposerStatus[] memory statuses) {
statuses = new IBoltValidators.ProposerStatus[](pubkeyHashes.length);
Expand All @@ -150,12 +150,12 @@ contract BoltManager is IBoltManager, OwnableUpgradeable, UUPSUpgradeable {
}

uint48 epochStartTs = getEpochStartTs(getEpochAtTs(Time.timestamp()));
// NOTE: this will revert when the proposer does not exist.
IBoltValidators.Validator memory validator = validators.getValidatorByPubkeyHash(pubkeyHash);

Operator memory operator = operators.get(validator.authorizedOperator);

status.pubkeyHash = pubkeyHash;
status.active = validator.exists;
status.operator = validator.authorizedOperator;
status.operatorRPC = operator.rpc;

Expand All @@ -167,6 +167,19 @@ contract BoltManager is IBoltManager, OwnableUpgradeable, UUPSUpgradeable {
(status.collaterals, status.amounts) =
IBoltMiddleware(operator.middleware).getOperatorCollaterals(validator.authorizedOperator);

// NOTE: check if the sum of the collaterals covers the minimum operator stake required.

uint256 totalOperatorStake = 0;
for (uint256 i = 0; i < status.amounts.length; ++i) {
totalOperatorStake += status.amounts[i];
}

if (totalOperatorStake < parameters.MINIMUM_OPERATOR_STAKE()) {
status.active = false;
} else {
status.active = true;
}

return status;
}

Expand Down
9 changes: 9 additions & 0 deletions bolt-contracts/src/interfaces/IBoltManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IBoltManager {
error OperatorAlreadyRegistered();
error OperatorNotRegistered();
error UnauthorizedMiddleware();
error InactiveOperator();

struct Operator {
string rpc;
Expand Down Expand Up @@ -35,6 +36,14 @@ interface IBoltManager {

function validators() external view returns (IBoltValidators);

function getProposerStatus(
bytes32 pubkeyHash
) external view returns (IBoltValidators.ProposerStatus memory status);

function getProposerStatuses(
bytes32[] calldata pubkeyHashes
) external view returns (IBoltValidators.ProposerStatus[] memory statuses);

function isOperatorAuthorizedForValidator(address operator, bytes32 pubkeyHash) external view returns (bool);

function getSupportedRestakingProtocols() external view returns (address[] memory middlewares);
Expand Down
7 changes: 7 additions & 0 deletions bolt-contracts/src/interfaces/IBoltValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ interface IBoltValidators {
address controller;
}

/// @notice Proposer status info.
struct ProposerStatus {
// The pubkey hash of the validator.
bytes32 pubkeyHash;
// Whether the corresponding operator is active based on collateral requirements.
bool active;
// The operator address that is authorized to make & sign commitments on behalf of the validator.
address operator;
// The operator RPC endpoint.
string operatorRPC;
// The addresses of the collateral tokens.
address[] collaterals;
// The corresponding amounts of the collateral tokens.
uint256[] amounts;
}

Expand Down
2 changes: 1 addition & 1 deletion bolt-contracts/test/BoltManager.EigenLayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ contract BoltManagerEigenLayerTest is Test {
validators.registerValidatorUnsafe(pubkey, PRECONF_MAX_GAS_LIMIT, operator);
}

IBoltValidators.ProposerStatus[] memory statuses = manager.getProposersStatus(pubkeyHashes);
IBoltValidators.ProposerStatus[] memory statuses = manager.getProposerStatuses(pubkeyHashes);
assertEq(statuses.length, 10);
}

Expand Down
2 changes: 1 addition & 1 deletion bolt-contracts/test/BoltManager.Symbiotic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ contract BoltManagerSymbioticTest is Test {
vm.warp(block.timestamp + EPOCH_DURATION * 2 + 1);
assertEq(vault.currentEpoch(), 2);

IBoltValidators.ProposerStatus[] memory statuses = manager.getProposersStatus(pubkeyHashes);
IBoltValidators.ProposerStatus[] memory statuses = manager.getProposerStatuses(pubkeyHashes);
assertEq(statuses.length, 10);
}

Expand Down

0 comments on commit ff311eb

Please sign in to comment.