Skip to content

Commit

Permalink
Add getters for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Nov 27, 2024
1 parent 790ccce commit 2ef6484
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 11 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions contracts/validator-manager/PoSValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract contract PoSValidatorManager is
* Note: Setting this value to 1 would disable delegations to validators, since
* the maximum stake would be equal to the initial stake.
*/
uint64 _maximumStakeMultiplier;
uint8 _maximumStakeMultiplier;
/// @notice The factor used to convert between weight and value.
uint256 _weightToValueFactor;
/// @notice The reward calculator for this validator manager.
Expand Down Expand Up @@ -154,7 +154,7 @@ abstract contract PoSValidatorManager is
revert InvalidStakeMultiplier(maximumStakeMultiplier);
}
// Minimum stake duration should be at least one churn period in order to prevent churn tracker abuse.
if (minimumStakeDuration < _getChurnPeriodSeconds()) {
if (minimumStakeDuration < _getSettings().churnPeriodSeconds) {
revert InvalidMinStakeDuration(minimumStakeDuration);
}
if (weightToValueFactor == 0) {
Expand Down Expand Up @@ -309,6 +309,25 @@ abstract contract PoSValidatorManager is
$._delegatorRewardRecipients[delegationID] = rewardRecipient;
}

/**
* @notice Returns the settings for the validator manager contract
*/
function getSettings() external view returns (PoSValidatorManagerSettings memory) {
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage();

return PoSValidatorManagerSettings({
baseSettings: _getSettings(),
minimumStakeAmount: $._minimumStakeAmount,
maximumStakeAmount: $._maximumStakeAmount,
minimumStakeDuration: $._minimumStakeDuration,
minimumDelegationFeeBips: $._minimumDelegationFeeBips,
maximumStakeMultiplier: $._maximumStakeMultiplier,
weightToValueFactor: $._weightToValueFactor,
rewardCalculator: $._rewardCalculator,
uptimeBlockchainID: $._uptimeBlockchainID
});
}

/**
* @dev Helper function that initializes the end of a PoS validation period.
* Returns false if it is possible for the validator to claim rewards, but it is not eligible.
Expand Down Expand Up @@ -882,7 +901,7 @@ abstract contract PoSValidatorManager is

// To prevent churn tracker abuse, check that one full churn period has passed,
// so a delegator may not stake twice in the same churn period.
if (block.timestamp < delegator.startedAt + _getChurnPeriodSeconds()) {
if (block.timestamp < delegator.startedAt + _getSettings().churnPeriodSeconds) {
revert MinStakeDurationNotPassed(uint64(block.timestamp));
}

Expand Down
16 changes: 14 additions & 2 deletions contracts/validator-manager/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
$._initializedValidatorSet = true;
}

/**
* @notice Returns the validator churn period information for this contract.
*/
function getValidatorChurnPeriod() external view returns (ValidatorChurnPeriod memory) {
return _getValidatorManagerStorage()._churnTracker;
}

function _validatePChainOwner(PChainOwner calldata pChainOwner) internal pure {
// If threshold is 0, addresses must be empty.
if (pChainOwner.threshold == 0 && pChainOwner.addresses.length != 0) {
Expand Down Expand Up @@ -532,8 +539,13 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
return (nonce, messageID);
}

function _getChurnPeriodSeconds() internal view returns (uint64) {
return _getValidatorManagerStorage()._churnPeriodSeconds;
function _getSettings() internal view returns (ValidatorManagerSettings memory) {
ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
return ValidatorManagerSettings({
subnetID: $._subnetID,
churnPeriodSeconds: $._churnPeriodSeconds,
maximumChurnPercentage: $._maximumChurnPercentage
});
}

/**
Expand Down

0 comments on commit 2ef6484

Please sign in to comment.