diff --git a/contracts/APRCalculator/APRCalculator.sol b/contracts/APRCalculator/APRCalculator.sol index 5d47270f..e5d4b73a 100644 --- a/contracts/APRCalculator/APRCalculator.sol +++ b/contracts/APRCalculator/APRCalculator.sol @@ -6,9 +6,8 @@ import {RSIndex} from "./modules/RSI/RSIndex.sol"; import {IAPRCalculator} from "./IAPRCalculator.sol"; contract APRCalculator is IAPRCalculator, MacroFactor, RSIndex { - uint256 public constant INITIAL_BASE_APR = 500; + uint256 public constant BASE_APR = 500; - uint256 public base; uint256[52] public vestingBonus; // _______________ Initializer _______________ @@ -23,27 +22,16 @@ contract APRCalculator is IAPRCalculator, MacroFactor, RSIndex { __MacroFactor_init(); __RSIndex_init(); - base = INITIAL_BASE_APR; - initializeVestingBonus(); } - // _______________ External functions _______________ - - /** - * @inheritdoc IAPRCalculator - */ - function setBase(uint256 newBase) external onlyRole(MANAGER_ROLE) { - base = newBase; - } - // _______________ Public functions _______________ /** * @inheritdoc IAPRCalculator */ - function getBaseAPR() public view returns (uint256) { - return base; + function getBaseAPR() public pure returns (uint256) { + return BASE_APR; } /** @@ -66,7 +54,7 @@ contract APRCalculator is IAPRCalculator, MacroFactor, RSIndex { function getMaxAPR() public view returns (uint256 nominator, uint256 denominator) { uint256 vestBonus = getVestingBonus(52); - nominator = (base + vestBonus) * MAX_MACRO_FACTOR * MAX_RSI_BONUS; + nominator = (BASE_APR + vestBonus) * MAX_MACRO_FACTOR * MAX_RSI_BONUS; denominator = 10000 ** 3; } @@ -89,8 +77,8 @@ contract APRCalculator is IAPRCalculator, MacroFactor, RSIndex { /** * @inheritdoc IAPRCalculator */ - function applyBaseAPR(uint256 amount) public view returns (uint256) { - return (amount * base) / DENOMINATOR; + function applyBaseAPR(uint256 amount) public pure returns (uint256) { + return (amount * BASE_APR) / DENOMINATOR; } // _______________ Internal functions _______________ diff --git a/contracts/APRCalculator/IAPRCalculator.sol b/contracts/APRCalculator/IAPRCalculator.sol index 4aa11bab..a8785afa 100644 --- a/contracts/APRCalculator/IAPRCalculator.sol +++ b/contracts/APRCalculator/IAPRCalculator.sol @@ -8,13 +8,6 @@ import {IMacroFactor} from "./modules/MacroFactor/IMacroFactor.sol"; interface IAPRCalculator is IMacroFactor, IRSIndex, IPrice { error InvalidRSI(); - /** - * @notice Sets new base APR - * @dev only owner can call this function - * @param newBase new base APR - */ - function setBase(uint256 newBase) external; - // _______________ Public functions _______________ /** diff --git a/contracts/APRCalculator/modules/Price/Price.sol b/contracts/APRCalculator/modules/Price/Price.sol index 1126b0e7..97abfdc2 100644 --- a/contracts/APRCalculator/modules/Price/Price.sol +++ b/contracts/APRCalculator/modules/Price/Price.sol @@ -47,6 +47,9 @@ abstract contract Price is IPrice, Initializable, System, Governed, HydraChainCo * @inheritdoc IPrice */ function updatePrice(uint256 _price, uint256 _day) external onlyPriceOracle { + assert(_price != 0); + assert(pricePerDay[_day] == 0); + latestDailyPrice = _price; pricePerDay[_day] = _price; diff --git a/contracts/HydraChain/modules/Inspector/Inspector.sol b/contracts/HydraChain/modules/Inspector/Inspector.sol index c8f5b174..aff2d72e 100644 --- a/contracts/HydraChain/modules/Inspector/Inspector.sol +++ b/contracts/HydraChain/modules/Inspector/Inspector.sol @@ -128,6 +128,10 @@ abstract contract Inspector is IInspector, ValidatorManager { * @inheritdoc IInspector */ function isSubjectToFinishBan(address account) public view returns (bool) { + if (validators[account].status == ValidatorStatus.Banned) { + return false; + } + // check if the owner (governance) is calling if (msg.sender == owner()) { return true; diff --git a/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol b/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol index 6bfd9898..1b737bae 100644 --- a/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol +++ b/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol @@ -117,6 +117,7 @@ abstract contract ValidatorManager is * @inheritdoc IValidatorManager */ function deactivateValidator(address account) external onlyHydraStaking { + assert(validators[account].status == ValidatorStatus.Active); validators[account].status = ValidatorStatus.Registered; activeValidatorsCount--; } diff --git a/contracts/HydraChain/modules/ValidatorsData/IValidatorsData.sol b/contracts/HydraChain/modules/ValidatorsData/IValidatorsData.sol index 4356a5bd..72f624b7 100644 --- a/contracts/HydraChain/modules/ValidatorsData/IValidatorsData.sol +++ b/contracts/HydraChain/modules/ValidatorsData/IValidatorsData.sol @@ -7,6 +7,8 @@ struct ValidatorPower { } interface IValidatorsData { + event ValidatorsDataSynced(ValidatorPower[] validatorsPower); + /** * @notice Syncs the validators voting power with the provided data * @param validatorsPower Array of ValidatorPower struct diff --git a/contracts/HydraChain/modules/ValidatorsData/ValidatorsData.sol b/contracts/HydraChain/modules/ValidatorsData/ValidatorsData.sol index a7b81261..d42a9de8 100644 --- a/contracts/HydraChain/modules/ValidatorsData/ValidatorsData.sol +++ b/contracts/HydraChain/modules/ValidatorsData/ValidatorsData.sol @@ -22,6 +22,10 @@ abstract contract ValidatorsData is IValidatorsData, System, Initializable { */ function syncValidatorsData(ValidatorPower[] calldata validatorsPower) external onlySystemCall { uint256 arrLength = validatorsPower.length; + if (arrLength == 0) { + return; + } + uint256 totalNewPower = 0; uint256 totalOldPower = 0; for (uint256 i = 0; i < arrLength; i++) { @@ -35,6 +39,8 @@ abstract contract ValidatorsData is IValidatorsData, System, Initializable { } else { totalVotingPower -= totalOldPower - totalNewPower; } + + emit ValidatorsDataSynced(validatorsPower); } /** diff --git a/contracts/HydraDelegation/Delegation.sol b/contracts/HydraDelegation/Delegation.sol index 3fc5f162..bc4fc98a 100644 --- a/contracts/HydraDelegation/Delegation.sol +++ b/contracts/HydraDelegation/Delegation.sol @@ -52,7 +52,7 @@ contract Delegation is uint256 _initialCommission ) internal onlyInitializing { __Governed_init(_governance); - __Withdrawal_init(_governance); + __Withdrawal_init(); __RewardWalletConnector_init(_rewardWalletAddr); __Delegation_init_unchained(_initialStakers, _initialCommission); } diff --git a/contracts/HydraDelegation/modules/VestedDelegation/IVestedDelegation.sol b/contracts/HydraDelegation/modules/VestedDelegation/IVestedDelegation.sol index e393ea0e..96d41ab3 100644 --- a/contracts/HydraDelegation/modules/VestedDelegation/IVestedDelegation.sol +++ b/contracts/HydraDelegation/modules/VestedDelegation/IVestedDelegation.sol @@ -1,10 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; +import {IVesting} from "../../../common/Vesting/IVesting.sol"; import {IDelegation} from "../../IDelegation.sol"; import {RPS, DelegationPoolDelegatorParams} from "../DelegationPoolLib/IDelegationPoolLib.sol"; -interface IVestedDelegation is IDelegation { +interface IVestedDelegation is IVesting, IDelegation { event PositionOpened( address indexed manager, address indexed staker, diff --git a/contracts/HydraDelegation/modules/VestedDelegation/VestedDelegation.sol b/contracts/HydraDelegation/modules/VestedDelegation/VestedDelegation.sol index 2a0c416b..64e95b1c 100644 --- a/contracts/HydraDelegation/modules/VestedDelegation/VestedDelegation.sol +++ b/contracts/HydraDelegation/modules/VestedDelegation/VestedDelegation.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import {Governed} from "../../../common/Governed/Governed.sol"; -import {Withdrawal} from "../../../common/Withdrawal/Withdrawal.sol"; import {VestedPositionLib} from "../../../common/Vesting/VestedPositionLib.sol"; import {VestingPosition} from "../../../common/Vesting/IVesting.sol"; import {Vesting} from "../../../common/Vesting/Vesting.sol"; @@ -17,13 +15,11 @@ import {IVestedDelegation, RPS, DelegationPoolDelegatorParams} from "./IVestedDe abstract contract VestedDelegation is IVestedDelegation, - Governed, - Withdrawal, + Vesting, HydraChainConnector, RewardWalletConnector, Delegation, - VestingManagerFactoryConnector, - Vesting + VestingManagerFactoryConnector { using DelegationPoolLib for DelegationPool; using VestedPositionLib for VestingPosition; diff --git a/contracts/HydraStaking/IHydraStaking.sol b/contracts/HydraStaking/IHydraStaking.sol index e3224504..ff7f6463 100644 --- a/contracts/HydraStaking/IHydraStaking.sol +++ b/contracts/HydraStaking/IHydraStaking.sol @@ -5,6 +5,7 @@ import {Uptime} from "../HydraChain/modules/ValidatorManager/IValidatorManager.s import {ILiquidStaking} from "./modules/LiquidStaking/ILiquidStaking.sol"; import {IDelegatedStaking} from "./modules/DelegatedStaking/IDelegatedStaking.sol"; import {IPenalizeableStaking} from "./modules/PenalizeableStaking/IPenalizeableStaking.sol"; +import {IVestedStaking} from "./modules/VestedStaking/IVestedStaking.sol"; import {IStaking} from "./IStaking.sol"; struct StakerInit { @@ -12,7 +13,7 @@ struct StakerInit { uint256 stake; } -interface IHydraStaking is IDelegatedStaking, IStaking, ILiquidStaking, IPenalizeableStaking { +interface IHydraStaking is IDelegatedStaking, IStaking, ILiquidStaking, IPenalizeableStaking, IVestedStaking { error DistributeRewardFailed(string message); /** diff --git a/contracts/HydraStaking/Staking.sol b/contracts/HydraStaking/Staking.sol index 6e8b4e08..de3c0d42 100644 --- a/contracts/HydraStaking/Staking.sol +++ b/contracts/HydraStaking/Staking.sol @@ -31,7 +31,7 @@ contract Staking is IStaking, Governed, Withdrawal, HydraChainConnector, APRCalc address _governance ) internal onlyInitializing { __Governed_init(_governance); - __Withdrawal_init(_governance); + __Withdrawal_init(); __HydraChainConnector_init(_hydraChainAddr); __APRCalculatorConnector_init(_aprCalculatorAddr); __RewardWalletConnector_init(_rewardWalletAddr); @@ -78,7 +78,7 @@ contract Staking is IStaking, Governed, Withdrawal, HydraChainConnector, APRCalc /** * @inheritdoc IStaking */ - function changeMinStake(uint256 newMinStake) external onlyOwner { + function changeMinStake(uint256 newMinStake) external onlyRole(DEFAULT_ADMIN_ROLE) { _changeMinStake(newMinStake); } diff --git a/contracts/HydraStaking/modules/VestedStaking/IVestedStaking.sol b/contracts/HydraStaking/modules/VestedStaking/IVestedStaking.sol index 2be2f8a4..0ac88ff3 100644 --- a/contracts/HydraStaking/modules/VestedStaking/IVestedStaking.sol +++ b/contracts/HydraStaking/modules/VestedStaking/IVestedStaking.sol @@ -1,13 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; +import {IVesting} from "../../../common/Vesting/IVesting.sol"; +import {IStaking} from "../../Staking.sol"; + struct StakingRewardsHistory { uint256 totalReward; uint256 epoch; uint256 timestamp; } -interface IVestedStaking { +interface IVestedStaking is IVesting, IStaking { /** * @notice Stakes sent amount with vesting period. * @param durationWeeks Duration of the vesting in weeks. Must be between 1 and 52. diff --git a/contracts/HydraStaking/modules/VestedStaking/VestedStaking.sol b/contracts/HydraStaking/modules/VestedStaking/VestedStaking.sol index 7b621d81..9be61347 100644 --- a/contracts/HydraStaking/modules/VestedStaking/VestedStaking.sol +++ b/contracts/HydraStaking/modules/VestedStaking/VestedStaking.sol @@ -11,7 +11,7 @@ import {IVestedStaking, StakingRewardsHistory} from "./IVestedStaking.sol"; * @title VestedStaking * @notice An extension of the Staking contract that enables vesting the stake for a higher APY */ -abstract contract VestedStaking is IVestedStaking, Staking, Vesting { +abstract contract VestedStaking is IVestedStaking, Vesting, Staking { using VestedPositionLib for VestingPosition; /** diff --git a/contracts/PriceOracle/PriceOracle.sol b/contracts/PriceOracle/PriceOracle.sol index 33e53b44..175321bf 100644 --- a/contracts/PriceOracle/PriceOracle.sol +++ b/contracts/PriceOracle/PriceOracle.sol @@ -20,6 +20,7 @@ contract PriceOracle is IPriceOracle, System, Initializable, HydraChainConnector mapping(uint256 => uint256) public pricePerDay; mapping(uint256 => List) public priceVotesForDay; + uint256 public constant MAX_UINT224 = type(uint224).max; uint256 public constant VOTING_POWER_PERCENTAGE_NEEDED = 61; uint256 public constant DAILY_VOTING_START_TIME = 36 minutes; uint256 public constant DAILY_VOTING_END_TIME = DAILY_VOTING_START_TIME + 3 hours; @@ -37,7 +38,7 @@ contract PriceOracle is IPriceOracle, System, Initializable, HydraChainConnector * @inheritdoc IPriceOracle */ function vote(uint256 price) external { - if (price == 0) { + if (price == 0 || price > MAX_UINT224) { revert InvalidPrice(); } diff --git a/contracts/VestingManager/VestingManager.sol b/contracts/VestingManager/VestingManager.sol index 05467e9e..39751bc4 100644 --- a/contracts/VestingManager/VestingManager.sol +++ b/contracts/VestingManager/VestingManager.sol @@ -14,13 +14,15 @@ contract VestingManager is IVestingManager, Initializable, OwnableUpgradeable { /// @notice The hydra delegation contract IHydraDelegation public immutable HYDRA_DELEGATION; + IERC20 public immutable LIQUIDITY_TOKEN; // _______________ Constructor _______________ - constructor(address hydraDelegationAddr) { + constructor(address hydraDelegationAddr, address liquidityTokenAddr) { // Set the HydraDelegation contract as part of the code (because immutable) when implementation is deployed. // That way, we don't have to set it separately in every proxy we create later. HYDRA_DELEGATION = IHydraDelegation(hydraDelegationAddr); + LIQUIDITY_TOKEN = IERC20(liquidityTokenAddr); _disableInitializers(); } @@ -37,8 +39,7 @@ contract VestingManager is IVestingManager, Initializable, OwnableUpgradeable { */ function openVestedDelegatePosition(address staker, uint256 durationWeeks) external payable onlyOwner { HYDRA_DELEGATION.delegateWithVesting{value: msg.value}(staker, durationWeeks); - address liquidToken = HYDRA_DELEGATION.liquidToken(); - _sendLiquidTokens(msg.sender, IERC20(liquidToken).balanceOf(address(this))); + _sendLiquidTokens(msg.sender, LIQUIDITY_TOKEN.balanceOf(address(this))); } /** @@ -59,9 +60,8 @@ contract VestingManager is IVestingManager, Initializable, OwnableUpgradeable { bytes32 r, bytes32 s ) external payable onlyOwner { - address liquidToken = HYDRA_DELEGATION.liquidToken(); uint256 owedLiquidTokens = HYDRA_DELEGATION.calculateOwedLiquidTokens(address(this), amount); - IERC20Permit(liquidToken).permit(msg.sender, address(this), owedLiquidTokens, deadline, v, r, s); + IERC20Permit(address(LIQUIDITY_TOKEN)).permit(msg.sender, address(this), owedLiquidTokens, deadline, v, r, s); _cutVestedPosition(staker, amount, owedLiquidTokens); } @@ -111,8 +111,7 @@ contract VestingManager is IVestingManager, Initializable, OwnableUpgradeable { * @param amount staked amount */ function _sendLiquidTokens(address positionOwner, uint256 amount) private onlyOwner { - address liquidToken = HYDRA_DELEGATION.liquidToken(); - IERC20(liquidToken).safeTransfer(positionOwner, amount); + LIQUIDITY_TOKEN.safeTransfer(positionOwner, amount); } /** @@ -121,7 +120,9 @@ contract VestingManager is IVestingManager, Initializable, OwnableUpgradeable { * @param amount Amount to be unstaked */ function _fulfillLiquidTokens(address positionOwner, uint256 amount) private onlyOwner { - address liquidToken = HYDRA_DELEGATION.liquidToken(); - IERC20(liquidToken).safeTransferFrom(positionOwner, address(this), amount); + LIQUIDITY_TOKEN.safeTransferFrom(positionOwner, address(this), amount); } + + // slither-disable-next-line unused-state,naming-convention + uint256[50] private __gap; } diff --git a/contracts/VestingManager/VestingManagerFactory.sol b/contracts/VestingManager/VestingManagerFactory.sol index 418f25aa..f76cf38e 100644 --- a/contracts/VestingManager/VestingManagerFactory.sol +++ b/contracts/VestingManager/VestingManagerFactory.sol @@ -19,12 +19,12 @@ contract VestingManagerFactory is IVestingManagerFactory, System, Initializable // _______________ Initializer _______________ - function initialize(address hydraDelegationAddr) external initializer onlySystemCall { - _initialize(hydraDelegationAddr); + function initialize(address hydraDelegationAddr, address liquidityTokenAddr) external initializer onlySystemCall { + _initialize(hydraDelegationAddr, liquidityTokenAddr); } - function _initialize(address hydraDelegationAddr) internal onlyInitializing { - address implementation = address(new VestingManager(hydraDelegationAddr)); + function _initialize(address hydraDelegationAddr, address liquidityTokenAddr) internal onlyInitializing { + address implementation = address(new VestingManager(hydraDelegationAddr, liquidityTokenAddr)); beacon = new UpgradeableBeacon(implementation); } @@ -43,7 +43,7 @@ contract VestingManagerFactory is IVestingManagerFactory, System, Initializable abi.encodeWithSelector(VestingManager(address(0)).initialize.selector, msg.sender) ); - _storeVestManagerData(address(manager), msg.sender); + _storeVestingManagerData(address(manager), msg.sender); emit NewVestingManager(msg.sender, address(manager)); } @@ -66,12 +66,12 @@ contract VestingManagerFactory is IVestingManagerFactory, System, Initializable /** * @notice Stores the vesting manager data - * @param vestManager Address of the vesting manager + * @param vestingManager Address of the vesting manager * @param owner Address of the vest manager owner */ - function _storeVestManagerData(address vestManager, address owner) private { - vestingManagerOwner[vestManager] = owner; - userVestingManagers[owner].push(vestManager); + function _storeVestingManagerData(address vestingManager, address owner) private { + vestingManagerOwner[vestingManager] = owner; + userVestingManagers[owner].push(vestingManager); } // slither-disable-next-line unused-state,naming-convention diff --git a/contracts/common/Vesting/IVesting.sol b/contracts/common/Vesting/IVesting.sol index a4b770a3..efa6b7e9 100644 --- a/contracts/common/Vesting/IVesting.sol +++ b/contracts/common/Vesting/IVesting.sol @@ -10,3 +10,16 @@ struct VestingPosition { uint256 rsiBonus; uint256 commission; } + +interface IVesting { + error FailedToBurnAmount(); + error PenaltyRateOutOfRange(); + + /** + * @notice sets a new penalty rate + * @param newRate the new penalty rate + * @dev Only callable by the admin + * @dev the rate should be between 10 and 150 (0.1% and 1.5%) + */ + function setPenaltyDecreasePerWeek(uint256 newRate) external; +} diff --git a/contracts/common/Vesting/Vesting.sol b/contracts/common/Vesting/Vesting.sol index 4c736daf..9978ccb5 100644 --- a/contracts/common/Vesting/Vesting.sol +++ b/contracts/common/Vesting/Vesting.sol @@ -1,19 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; +import {Governed} from "../../common/Governed/Governed.sol"; import {APRCalculatorConnector} from "../../APRCalculator/APRCalculatorConnector.sol"; import {VestedPositionLib} from "./VestedPositionLib.sol"; -import {VestingPosition} from "./IVesting.sol"; +import {VestingPosition, IVesting} from "./IVesting.sol"; /** * @title VestedStaking * @notice An extension of the Staking contract that enables vesting the stake for a higher APY */ -abstract contract Vesting is APRCalculatorConnector { +abstract contract Vesting is IVesting, Governed, APRCalculatorConnector { using VestedPositionLib for VestingPosition; - error FailedToBurnAmount(); - uint256 public constant DENOMINATOR = 10000; /** * @notice A constant for the calculation of the weeks left of a vesting period @@ -24,6 +23,8 @@ abstract contract Vesting is APRCalculatorConnector { /// A fraction's numerator representing the rate /// at which the liquidity tokens' distribution is decreased on a weekly basis uint256 public vestingLiquidityDecreasePerWeek; + /// The penalty decrease per week + uint256 public penaltyDecreasePerWeek; // _______________ Initializer _______________ @@ -35,6 +36,17 @@ abstract contract Vesting is APRCalculatorConnector { // solhint-disable-next-line func-name-mixedcase function __Vesting_init_unchainded() internal onlyInitializing { vestingLiquidityDecreasePerWeek = 133; // 0.0133 + penaltyDecreasePerWeek = 50; // 0.5% + } + + // _______________ External functions _______________ + + /** + * @inheritdoc IVesting + */ + function setPenaltyDecreasePerWeek(uint256 newRate) external onlyRole(DEFAULT_ADMIN_ROLE) { + if (newRate < 10 || newRate > 150) revert PenaltyRateOutOfRange(); + penaltyDecreasePerWeek = newRate; } // _______________ Internal functions _______________ @@ -60,7 +72,7 @@ abstract contract Vesting is APRCalculatorConnector { function _calcPenalty(VestingPosition memory position, uint256 amount) internal view returns (uint256) { uint256 leftPeriod = position.end - block.timestamp; uint256 leftWeeks = (leftPeriod + WEEK_MINUS_SECOND) / 1 weeks; - uint256 bps = 100 * leftWeeks; // 1% * left weeks + uint256 bps = penaltyDecreasePerWeek * leftWeeks; // 0.5% per week after initilization return (amount * bps) / aprCalculatorContract.getDENOMINATOR(); } diff --git a/contracts/common/Withdrawal/Withdrawal.sol b/contracts/common/Withdrawal/Withdrawal.sol index 75ccc495..3bd59849 100644 --- a/contracts/common/Withdrawal/Withdrawal.sol +++ b/contracts/common/Withdrawal/Withdrawal.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.17; import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; -import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; +import {Governed} from "../Governed/Governed.sol"; import {WithdrawalQueueLib, WithdrawalQueue} from "./WithdrawalQueueLib.sol"; import {IWithdrawal} from "./IWithdrawal.sol"; -abstract contract Withdrawal is IWithdrawal, ReentrancyGuardUpgradeable, Ownable2StepUpgradeable { +abstract contract Withdrawal is IWithdrawal, ReentrancyGuardUpgradeable, Governed { using WithdrawalQueueLib for WithdrawalQueue; uint256 public withdrawWaitPeriod; @@ -17,9 +17,8 @@ abstract contract Withdrawal is IWithdrawal, ReentrancyGuardUpgradeable, Ownable // _______________ Initializer _______________ // solhint-disable-next-line func-name-mixedcase - function __Withdrawal_init(address _governance) internal { + function __Withdrawal_init() internal { __ReentrancyGuard_init(); - _transferOwnership(_governance); __Withdrawal_init_unchained(); } @@ -45,7 +44,7 @@ abstract contract Withdrawal is IWithdrawal, ReentrancyGuardUpgradeable, Ownable /** * @inheritdoc IWithdrawal */ - function changeWithdrawalWaitPeriod(uint256 newWaitPeriod) external onlyOwner { + function changeWithdrawalWaitPeriod(uint256 newWaitPeriod) external onlyRole(DEFAULT_ADMIN_ROLE) { _changeWithdrawalWaitPeriod(newWaitPeriod); } diff --git a/docs/APRCalculator/APRCalculator.md b/docs/APRCalculator/APRCalculator.md index 24076c19..2de530e4 100644 --- a/docs/APRCalculator/APRCalculator.md +++ b/docs/APRCalculator/APRCalculator.md @@ -10,10 +10,10 @@ ## Methods -### DEFAULT_ADMIN_ROLE +### BASE_APR ```solidity -function DEFAULT_ADMIN_ROLE() external view returns (bytes32) +function BASE_APR() external view returns (uint256) ``` @@ -25,12 +25,12 @@ function DEFAULT_ADMIN_ROLE() external view returns (bytes32) | Name | Type | Description | |---|---|---| -| _0 | bytes32 | undefined | +| _0 | uint256 | undefined | -### DENOMINATOR +### DEFAULT_ADMIN_ROLE ```solidity -function DENOMINATOR() external view returns (uint256) +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) ``` @@ -42,12 +42,12 @@ function DENOMINATOR() external view returns (uint256) | Name | Type | Description | |---|---|---| -| _0 | uint256 | undefined | +| _0 | bytes32 | undefined | -### FAST_SMA +### DENOMINATOR ```solidity -function FAST_SMA() external view returns (uint256) +function DENOMINATOR() external view returns (uint256) ``` @@ -61,10 +61,10 @@ function FAST_SMA() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### INITIAL_BASE_APR +### FAST_SMA ```solidity -function INITIAL_BASE_APR() external view returns (uint256) +function FAST_SMA() external view returns (uint256) ``` @@ -268,7 +268,7 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) ### applyBaseAPR ```solidity -function applyBaseAPR(uint256 amount) external view returns (uint256) +function applyBaseAPR(uint256 amount) external pure returns (uint256) ``` Applies the base APR for the given amount @@ -337,23 +337,6 @@ function averageLoss() external view returns (uint256) -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | uint256 | undefined | - -### base - -```solidity -function base() external view returns (uint256) -``` - - - - - - #### Returns | Name | Type | Description | @@ -424,7 +407,7 @@ function disabledBonusesUpdates() external view returns (bool) ### getBaseAPR ```solidity -function getBaseAPR() external view returns (uint256) +function getBaseAPR() external pure returns (uint256) ``` Returns base APR @@ -784,22 +767,6 @@ function rsi() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### setBase - -```solidity -function setBase(uint256 newBase) external nonpayable -``` - -Sets new base APR - -*only owner can call this function* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newBase | uint256 | new base APR | - ### smaFastSum ```solidity diff --git a/docs/APRCalculator/IAPRCalculator.md b/docs/APRCalculator/IAPRCalculator.md index 3762e579..9a22b68b 100644 --- a/docs/APRCalculator/IAPRCalculator.md +++ b/docs/APRCalculator/IAPRCalculator.md @@ -222,22 +222,6 @@ Protects RSI bonus and Macro factor updates and set them to default values *only governance can call this function* -### setBase - -```solidity -function setBase(uint256 newBase) external nonpayable -``` - -Sets new base APR - -*only owner can call this function* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newBase | uint256 | new base APR | - ### updatePrice ```solidity diff --git a/docs/HydraChain/HydraChain.md b/docs/HydraChain/HydraChain.md index 47b685bf..f158bcab 100644 --- a/docs/HydraChain/HydraChain.md +++ b/docs/HydraChain/HydraChain.md @@ -1441,6 +1441,22 @@ event ValidatorBanned(address indexed validator) |---|---|---| | validator `indexed` | address | undefined | +### ValidatorsDataSynced + +```solidity +event ValidatorsDataSynced(ValidatorPower[] validatorsPower) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validatorsPower | ValidatorPower[] | undefined | + ### VaultFunded ```solidity diff --git a/docs/HydraChain/IHydraChain.md b/docs/HydraChain/IHydraChain.md index 08ad5597..a1475a4a 100644 --- a/docs/HydraChain/IHydraChain.md +++ b/docs/HydraChain/IHydraChain.md @@ -584,6 +584,22 @@ event ValidatorBanned(address indexed validator) |---|---|---| | validator `indexed` | address | undefined | +### ValidatorsDataSynced + +```solidity +event ValidatorsDataSynced(ValidatorPower[] validatorsPower) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validatorsPower | ValidatorPower[] | undefined | + ### VaultFunded ```solidity diff --git a/docs/HydraChain/modules/ValidatorsData/IValidatorsData.md b/docs/HydraChain/modules/ValidatorsData/IValidatorsData.md index 3fa327cd..67159d0f 100644 --- a/docs/HydraChain/modules/ValidatorsData/IValidatorsData.md +++ b/docs/HydraChain/modules/ValidatorsData/IValidatorsData.md @@ -67,4 +67,23 @@ function syncValidatorsData(ValidatorPower[] validatorsPower) external nonpayabl +## Events + +### ValidatorsDataSynced + +```solidity +event ValidatorsDataSynced(ValidatorPower[] validatorsPower) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validatorsPower | ValidatorPower[] | undefined | + + diff --git a/docs/HydraChain/modules/ValidatorsData/ValidatorsData.md b/docs/HydraChain/modules/ValidatorsData/ValidatorsData.md index 3fa12a87..9e3a42df 100644 --- a/docs/HydraChain/modules/ValidatorsData/ValidatorsData.md +++ b/docs/HydraChain/modules/ValidatorsData/ValidatorsData.md @@ -226,6 +226,22 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | +### ValidatorsDataSynced + +```solidity +event ValidatorsDataSynced(ValidatorPower[] validatorsPower) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validatorsPower | ValidatorPower[] | undefined | + ## Errors diff --git a/docs/HydraDelegation/Delegation.md b/docs/HydraDelegation/Delegation.md index db2d71b2..fc27392b 100644 --- a/docs/HydraDelegation/Delegation.md +++ b/docs/HydraDelegation/Delegation.md @@ -61,17 +61,6 @@ A constant for the minimum delegation limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -441,40 +430,6 @@ The minimum delegation amount to be delegated |---|---|---| | _0 | uint256 | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### pendingWithdrawals ```solidity @@ -497,17 +452,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -658,22 +602,6 @@ Returns the total amount of delegation for a staker |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### undelegate ```solidity @@ -872,40 +800,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/HydraDelegation/HydraDelegation.md b/docs/HydraDelegation/HydraDelegation.md index 2564dd4d..4fd70f4c 100644 --- a/docs/HydraDelegation/HydraDelegation.md +++ b/docs/HydraDelegation/HydraDelegation.md @@ -180,17 +180,6 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -977,39 +966,22 @@ The minimum delegation amount to be delegated |---|---|---| | _0 | uint256 | undefined | -### owner +### penaltyDecreasePerWeek ```solidity -function owner() external view returns (address) +function penaltyDecreasePerWeek() external view returns (uint256) ``` +The penalty decrease per week -*Returns the address of the current owner.* #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | +| _0 | uint256 | undefined | ### pendingWithdrawals @@ -1033,17 +1005,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -1111,6 +1072,22 @@ Sets commission for staker. |---|---|---| | newCommission | uint256 | New commission (100 = 100%) | +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + ### stakerDelegationCommission ```solidity @@ -1211,22 +1188,6 @@ Returns the total amount of delegation for a staker |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### undelegate ```solidity @@ -1505,40 +1466,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### PositionCut ```solidity @@ -1829,6 +1756,17 @@ error NotVestingManager() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + ### Unauthorized ```solidity diff --git a/docs/HydraDelegation/IHydraDelegation.md b/docs/HydraDelegation/IHydraDelegation.md index c53735d5..323a9c21 100644 --- a/docs/HydraDelegation/IHydraDelegation.md +++ b/docs/HydraDelegation/IHydraDelegation.md @@ -551,6 +551,22 @@ Sets commission for staker. |---|---|---| | newCommission | uint256 | New commission (100 = 100%) | +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + ### stakerDelegationCommission ```solidity @@ -953,6 +969,17 @@ error CommissionUpdateNotAvailable() +### FailedToBurnAmount + +```solidity +error FailedToBurnAmount() +``` + + + + + + ### InvalidCommission ```solidity @@ -1019,6 +1046,17 @@ error NotVestingManager() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + ### WithdrawalFailed ```solidity diff --git a/docs/HydraDelegation/modules/LiquidDelegation/LiquidDelegation.md b/docs/HydraDelegation/modules/LiquidDelegation/LiquidDelegation.md index 697d4f16..c9ae5f77 100644 --- a/docs/HydraDelegation/modules/LiquidDelegation/LiquidDelegation.md +++ b/docs/HydraDelegation/modules/LiquidDelegation/LiquidDelegation.md @@ -61,17 +61,6 @@ A constant for the minimum delegation limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -503,40 +492,6 @@ The minimum delegation amount to be delegated |---|---|---| | _0 | uint256 | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### pendingWithdrawals ```solidity @@ -559,17 +514,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -720,22 +664,6 @@ Returns the total amount of delegation for a staker |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### undelegate ```solidity @@ -934,40 +862,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/HydraDelegation/modules/VestedDelegation/IVestedDelegation.md b/docs/HydraDelegation/modules/VestedDelegation/IVestedDelegation.md index fc15ca73..c4778c21 100644 --- a/docs/HydraDelegation/modules/VestedDelegation/IVestedDelegation.md +++ b/docs/HydraDelegation/modules/VestedDelegation/IVestedDelegation.md @@ -493,6 +493,22 @@ Sets commission for staker. |---|---|---| | newCommission | uint256 | New commission (100 = 100%) | +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + ### stakerDelegationCommission ```solidity @@ -895,6 +911,17 @@ error CommissionUpdateNotAvailable() +### FailedToBurnAmount + +```solidity +error FailedToBurnAmount() +``` + + + + + + ### InvalidCommission ```solidity @@ -961,6 +988,17 @@ error NotVestingManager() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + ### WithdrawalFailed ```solidity diff --git a/docs/HydraDelegation/modules/VestedDelegation/VestedDelegation.md b/docs/HydraDelegation/modules/VestedDelegation/VestedDelegation.md index a01d0a99..0e970e96 100644 --- a/docs/HydraDelegation/modules/VestedDelegation/VestedDelegation.md +++ b/docs/HydraDelegation/modules/VestedDelegation/VestedDelegation.md @@ -78,17 +78,6 @@ A constant for the minimum delegation limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -771,39 +760,22 @@ The minimum delegation amount to be delegated |---|---|---| | _0 | uint256 | undefined | -### owner +### penaltyDecreasePerWeek ```solidity -function owner() external view returns (address) +function penaltyDecreasePerWeek() external view returns (uint256) ``` +The penalty decrease per week -*Returns the address of the current owner.* #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | +| _0 | uint256 | undefined | ### pendingWithdrawals @@ -827,17 +799,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -905,6 +866,22 @@ Sets commission for staker. |---|---|---| | newCommission | uint256 | New commission (100 = 100%) | +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + ### stakerDelegationCommission ```solidity @@ -1005,22 +982,6 @@ Returns the total amount of delegation for a staker |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### undelegate ```solidity @@ -1299,40 +1260,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### PositionCut ```solidity @@ -1623,6 +1550,17 @@ error NotVestingManager() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + ### WithdrawalFailed ```solidity diff --git a/docs/HydraStaking/HydraStaking.md b/docs/HydraStaking/HydraStaking.md index de34dbe5..b41a5ec3 100644 --- a/docs/HydraStaking/HydraStaking.md +++ b/docs/HydraStaking/HydraStaking.md @@ -163,17 +163,6 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -649,23 +638,6 @@ Called by the delegation contract when a user undelegates from a staker |---|---|---| | staker | address | The address of the staker | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### penalizeStaker ```solidity @@ -683,22 +655,22 @@ function penalizeStaker(address staker, PenalizedStakeDistribution[] stakeDistri | staker | address | undefined | | stakeDistributions | PenalizedStakeDistribution[] | undefined | -### pendingOwner +### penaltyDecreasePerWeek ```solidity -function pendingOwner() external view returns (address) +function penaltyDecreasePerWeek() external view returns (uint256) ``` +The penalty decrease per week -*Returns the address of the pending owner.* #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | +| _0 | uint256 | undefined | ### pendingWithdrawals @@ -738,17 +710,6 @@ Return back a validator after temporary removal from the validator set by emitin |---|---|---| | account | address | address of the validator to be returned | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -800,6 +761,22 @@ function rewardWalletContract() external view returns (contract IRewardWallet) |---|---|---| | _0 | contract IRewardWallet | undefined | +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + ### stake ```solidity @@ -1013,22 +990,6 @@ function totalStake() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### unclaimedRewards ```solidity @@ -1215,40 +1176,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity @@ -1492,6 +1419,17 @@ error NoWithdrawalAvailable() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + ### StakeLeftLow ```solidity diff --git a/docs/HydraStaking/IHydraStaking.md b/docs/HydraStaking/IHydraStaking.md index e00b3fe4..1072714a 100644 --- a/docs/HydraStaking/IHydraStaking.md +++ b/docs/HydraStaking/IHydraStaking.md @@ -10,6 +10,30 @@ ## Methods +### calcVestedStakingPositionPenalty + +```solidity +function calcVestedStakingPositionPenalty(address staker, uint256 amount) external view returns (uint256 penalty, uint256 reward) +``` + +Returns the penalty and reward that will be burned, if vested stake position is active + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| staker | address | The address of the staker | +| amount | uint256 | The amount that is going to be unstaked | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| penalty | uint256 | for the staker | +| reward | uint256 | of the staker | + ### calculateOwedLiquidTokens ```solidity @@ -33,6 +57,51 @@ Returns the amount of liquid tokens the user owes to the protocol based on the g |---|---|---| | _0 | uint256 | The amount of liquid tokens the user owes to the protocol | +### calculatePositionClaimableReward + +```solidity +function calculatePositionClaimableReward(address staker, uint256 rewardHistoryIndex) external view returns (uint256) +``` + +Calculates the staker's vested position claimable (already matured) rewards. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| staker | address | The address of the staker | +| rewardHistoryIndex | uint256 | The index of the reward history at time that is already matured | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | claimable reward of the staker* | + +### calculatePositionTotalReward + +```solidity +function calculatePositionTotalReward(address staker) external view returns (uint256) +``` + +Calculates the staker's total (pending + claimable) rewards. Pending - such that are not matured so not claimable yet. Claimable - such that are matured and claimable. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| staker | address | The address of the staker | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | Pending rewards expected by the vested staker's position (in HYDRA wei) | + ### changeMinStake ```solidity @@ -76,6 +145,22 @@ Claims staking rewards for the sender. +### claimStakingRewards + +```solidity +function claimStakingRewards(uint256 rewardHistoryIndex) external nonpayable +``` + +Claims staking rewards for the sender. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| rewardHistoryIndex | uint256 | The index of the reward history to claim rewards from | + ### distributeRewardsFor ```solidity @@ -93,6 +178,28 @@ function distributeRewardsFor(uint256 epochId, Uptime[] uptime) external nonpaya | epochId | uint256 | undefined | | uptime | Uptime[] | undefined | +### getStakingRewardsHistoryValues + +```solidity +function getStakingRewardsHistoryValues(address staker) external view returns (struct StakingRewardsHistory[]) +``` + +Returns historical records of the staking rewards of the user + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| staker | address | The address of the staker | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | StakingRewardsHistory[] | stakingRewardsHistory array with the historical records of the staking rewards of the user | + ### liquidToken ```solidity @@ -197,6 +304,22 @@ Return back a validator after temporary removal from the validator set by emitin |---|---|---| | account | address | address of the validator to be returned | +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + ### stake ```solidity @@ -230,6 +353,22 @@ Returns staked amount for the given account. |---|---|---| | _0 | uint256 | undefined | +### stakeWithVesting + +```solidity +function stakeWithVesting(uint256 durationWeeks) external payable +``` + +Stakes sent amount with vesting period. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| durationWeeks | uint256 | Duration of the vesting in weeks. Must be between 1 and 52. | + ### temporaryEjectValidator ```solidity @@ -499,6 +638,17 @@ error DistributeRewardFailed(string message) |---|---|---| | message | string | undefined | +### FailedToBurnAmount + +```solidity +error FailedToBurnAmount() +``` + + + + + + ### InvalidMinStake ```solidity @@ -554,6 +704,17 @@ error NoWithdrawalAvailable() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + ### StakeLeftLow ```solidity diff --git a/docs/HydraStaking/Staking.md b/docs/HydraStaking/Staking.md index 99c19d83..1ecc53a9 100644 --- a/docs/HydraStaking/Staking.md +++ b/docs/HydraStaking/Staking.md @@ -44,17 +44,6 @@ A constant for the minimum stake limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -211,40 +200,6 @@ A state variable to keep the minimum amount of stake |---|---|---| | _0 | uint256 | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### pendingWithdrawals ```solidity @@ -267,17 +222,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -446,22 +390,6 @@ function totalStake() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### unclaimedRewards ```solidity @@ -575,40 +503,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/HydraStaking/modules/DelegatedStaking/DelegatedStaking.md b/docs/HydraStaking/modules/DelegatedStaking/DelegatedStaking.md index 6e7cedf3..3ae058b9 100644 --- a/docs/HydraStaking/modules/DelegatedStaking/DelegatedStaking.md +++ b/docs/HydraStaking/modules/DelegatedStaking/DelegatedStaking.md @@ -44,17 +44,6 @@ A constant for the minimum stake limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -260,40 +249,6 @@ Called by the delegation contract when a user undelegates from a staker |---|---|---| | staker | address | The address of the staker | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### pendingWithdrawals ```solidity @@ -316,17 +271,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -495,22 +439,6 @@ function totalStake() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### unclaimedRewards ```solidity @@ -624,40 +552,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/HydraStaking/modules/LiquidStaking/LiquidStaking.md b/docs/HydraStaking/modules/LiquidStaking/LiquidStaking.md index f1ee0442..74087007 100644 --- a/docs/HydraStaking/modules/LiquidStaking/LiquidStaking.md +++ b/docs/HydraStaking/modules/LiquidStaking/LiquidStaking.md @@ -44,17 +44,6 @@ A constant for the minimum stake limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -273,40 +262,6 @@ A state variable to keep the minimum amount of stake |---|---|---| | _0 | uint256 | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### pendingWithdrawals ```solidity @@ -329,17 +284,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -508,22 +452,6 @@ function totalStake() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### unclaimedRewards ```solidity @@ -637,40 +565,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/HydraStaking/modules/PenalizeableStaking/PenalizeableStaking.md b/docs/HydraStaking/modules/PenalizeableStaking/PenalizeableStaking.md index 456f0598..6ce2151f 100644 --- a/docs/HydraStaking/modules/PenalizeableStaking/PenalizeableStaking.md +++ b/docs/HydraStaking/modules/PenalizeableStaking/PenalizeableStaking.md @@ -44,17 +44,6 @@ A constant for the minimum stake limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -233,23 +222,6 @@ A state variable to keep the minimum amount of stake |---|---|---| | _0 | uint256 | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### penalizeStaker ```solidity @@ -267,23 +239,6 @@ function penalizeStaker(address staker, PenalizedStakeDistribution[] stakeDistri | staker | address | undefined | | stakeDistributions | PenalizedStakeDistribution[] | undefined | -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### pendingWithdrawals ```solidity @@ -306,17 +261,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -485,22 +429,6 @@ function totalStake() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### unclaimedRewards ```solidity @@ -625,40 +553,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/HydraStaking/modules/StateSyncStaking/StateSyncStaking.md b/docs/HydraStaking/modules/StateSyncStaking/StateSyncStaking.md index ca366f1e..86556365 100644 --- a/docs/HydraStaking/modules/StateSyncStaking/StateSyncStaking.md +++ b/docs/HydraStaking/modules/StateSyncStaking/StateSyncStaking.md @@ -44,17 +44,6 @@ A constant for the minimum stake limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -211,40 +200,6 @@ A state variable to keep the minimum amount of stake |---|---|---| | _0 | uint256 | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### pendingWithdrawals ```solidity @@ -267,17 +222,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -446,22 +390,6 @@ function totalStake() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### unclaimedRewards ```solidity @@ -592,40 +520,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity diff --git a/docs/HydraStaking/modules/VestedStaking/IVestedStaking.md b/docs/HydraStaking/modules/VestedStaking/IVestedStaking.md index 14a1b4af..6f1b3ad6 100644 --- a/docs/HydraStaking/modules/VestedStaking/IVestedStaking.md +++ b/docs/HydraStaking/modules/VestedStaking/IVestedStaking.md @@ -79,6 +79,49 @@ Calculates the staker's total (pending + claimable) rewards. Pending - such |---|---|---| | _0 | uint256 | Pending rewards expected by the vested staker's position (in HYDRA wei) | +### changeMinStake + +```solidity +function changeMinStake(uint256 newMinStake) external nonpayable +``` + +Changes minimum stake required for stakers. + +*Should be called by the Governance.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newMinStake | uint256 | New minimum stake | + +### changeWithdrawalWaitPeriod + +```solidity +function changeWithdrawalWaitPeriod(uint256 newWaitPeriod) external nonpayable +``` + +Changes the withdrawal wait period. + +*This function should be called only by the Governed contract.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newWaitPeriod | uint256 | The new withdrawal wait period. MUST be longer than a single epoch (in some realistic worst-case scenario) in case somebody's stake needs to be penalized. | + +### claimStakingRewards + +```solidity +function claimStakingRewards() external nonpayable +``` + +Claims staking rewards for the sender. + + + + ### claimStakingRewards ```solidity @@ -117,6 +160,77 @@ Returns historical records of the staking rewards of the user |---|---|---| | _0 | StakingRewardsHistory[] | stakingRewardsHistory array with the historical records of the staking rewards of the user | +### pendingWithdrawals + +```solidity +function pendingWithdrawals(address account) external view returns (uint256) +``` + +Calculates how much is yet to become withdrawable for account. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account | address | The account to calculate amount for | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | Amount not yet withdrawable (in wei) | + +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + +### stake + +```solidity +function stake() external payable +``` + +Stakes sent amount. + + + + +### stakeOf + +```solidity +function stakeOf(address account) external view returns (uint256) +``` + +Returns staked amount for the given account. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account | address | Staker address | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + ### stakeWithVesting ```solidity @@ -133,6 +247,285 @@ Stakes sent amount with vesting period. |---|---|---| | durationWeeks | uint256 | Duration of the vesting in weeks. Must be between 1 and 52. | +### unclaimedRewards + +```solidity +function unclaimedRewards(address account) external view returns (uint256) +``` + +Returns unclaimed rewards for the given account. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account | address | Staker address | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### unstake + +```solidity +function unstake(uint256 amount) external nonpayable +``` + +Unstakes amount for sender. Claims rewards beforehand. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| amount | uint256 | Amount to unstake | + +### withdraw + +```solidity +function withdraw(address to) external nonpayable +``` + +Withdraws sender's withdrawable amount to specified address. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | Address to withdraw to | + +### withdrawable + +```solidity +function withdrawable(address account) external view returns (uint256) +``` + +Calculates how much can be withdrawn for account at this time. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account | address | The account to calculate amount for | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | Amount withdrawable (in wei) | + + + +## Events + +### Staked + +```solidity +event Staked(address indexed account, uint256 amount) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account `indexed` | address | undefined | +| amount | uint256 | undefined | + +### StakingRewardDistributed + +```solidity +event StakingRewardDistributed(address indexed account, uint256 amount) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account `indexed` | address | undefined | +| amount | uint256 | undefined | + +### StakingRewardsClaimed + +```solidity +event StakingRewardsClaimed(address indexed account, uint256 amount) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account `indexed` | address | undefined | +| amount | uint256 | undefined | + +### Unstaked + +```solidity +event Unstaked(address indexed account, uint256 amount) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account `indexed` | address | undefined | +| amount | uint256 | undefined | + +### WithdrawalFinished + +```solidity +event WithdrawalFinished(address indexed account, address indexed to, uint256 amount) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account `indexed` | address | undefined | +| to `indexed` | address | undefined | +| amount | uint256 | undefined | + +### WithdrawalRegistered + +```solidity +event WithdrawalRegistered(address indexed account, uint256 amount) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| account `indexed` | address | undefined | +| amount | uint256 | undefined | + + + +## Errors + +### FailedToBurnAmount + +```solidity +error FailedToBurnAmount() +``` + + + + + + +### InvalidMinStake + +```solidity +error InvalidMinStake() +``` + + + + + + +### InvalidWaitPeriod + +```solidity +error InvalidWaitPeriod() +``` + + + + + + +### NoRewards + +```solidity +error NoRewards() +``` + + + + + + +### NoWithdrawalAvailable + +```solidity +error NoWithdrawalAvailable() +``` + + + + + + +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + +### StakeRequirement + +```solidity +error StakeRequirement(string src, string msg) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| src | string | undefined | +| msg | string | undefined | + +### WithdrawalFailed + +```solidity +error WithdrawalFailed() +``` + + + + diff --git a/docs/HydraStaking/modules/VestedStaking/VestedStaking.md b/docs/HydraStaking/modules/VestedStaking/VestedStaking.md index 4998f316..52b73ba1 100644 --- a/docs/HydraStaking/modules/VestedStaking/VestedStaking.md +++ b/docs/HydraStaking/modules/VestedStaking/VestedStaking.md @@ -61,17 +61,6 @@ A constant for the minimum stake limit |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### aprCalculatorContract ```solidity @@ -335,39 +324,22 @@ A state variable to keep the minimum amount of stake |---|---|---| | _0 | uint256 | undefined | -### owner +### penaltyDecreasePerWeek ```solidity -function owner() external view returns (address) +function penaltyDecreasePerWeek() external view returns (uint256) ``` +The penalty decrease per week -*Returns the address of the current owner.* #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | +| _0 | uint256 | undefined | ### pendingWithdrawals @@ -391,17 +363,6 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - ### renounceRole ```solidity @@ -453,6 +414,22 @@ function rewardWalletContract() external view returns (contract IRewardWallet) |---|---|---| | _0 | contract IRewardWallet | undefined | +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + ### stake ```solidity @@ -611,22 +588,6 @@ function totalStake() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### unclaimedRewards ```solidity @@ -785,40 +746,6 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - ### RoleAdminChanged ```solidity @@ -1035,6 +962,17 @@ error NoWithdrawalAvailable() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + ### StakeRequirement ```solidity diff --git a/docs/PriceOracle/PriceOracle.md b/docs/PriceOracle/PriceOracle.md index 2827e2db..b9bd6f47 100644 --- a/docs/PriceOracle/PriceOracle.md +++ b/docs/PriceOracle/PriceOracle.md @@ -38,6 +38,23 @@ function DAILY_VOTING_START_TIME() external view returns (uint256) +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### MAX_UINT224 + +```solidity +function MAX_UINT224() external view returns (uint256) +``` + + + + + + #### Returns | Name | Type | Description | diff --git a/docs/VestingManager/VestingManager.md b/docs/VestingManager/VestingManager.md index db709566..7c9234f0 100644 --- a/docs/VestingManager/VestingManager.md +++ b/docs/VestingManager/VestingManager.md @@ -27,6 +27,23 @@ The hydra delegation contract |---|---|---| | _0 | contract IHydraDelegation | undefined | +### LIQUIDITY_TOKEN + +```solidity +function LIQUIDITY_TOKEN() external view returns (contract IERC20) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | contract IERC20 | undefined | + ### claimVestedPositionReward ```solidity diff --git a/docs/VestingManager/VestingManagerFactory.md b/docs/VestingManager/VestingManagerFactory.md index 9fc274ae..b27fd1f1 100644 --- a/docs/VestingManager/VestingManagerFactory.md +++ b/docs/VestingManager/VestingManagerFactory.md @@ -154,7 +154,7 @@ Gets user vesting managers. ### initialize ```solidity -function initialize(address hydraDelegationAddr) external nonpayable +function initialize(address hydraDelegationAddr, address liquidityTokenAddr) external nonpayable ``` @@ -166,6 +166,7 @@ function initialize(address hydraDelegationAddr) external nonpayable | Name | Type | Description | |---|---|---| | hydraDelegationAddr | address | undefined | +| liquidityTokenAddr | address | undefined | ### isVestingManager diff --git a/docs/common/Vesting/IVesting.md b/docs/common/Vesting/IVesting.md new file mode 100644 index 00000000..a9ef052e --- /dev/null +++ b/docs/common/Vesting/IVesting.md @@ -0,0 +1,56 @@ +# IVesting + + + + + + + + + +## Methods + +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + + + + +## Errors + +### FailedToBurnAmount + +```solidity +error FailedToBurnAmount() +``` + + + + + + +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + + diff --git a/docs/common/Vesting/Vesting.md b/docs/common/Vesting/Vesting.md index fc9db50f..32a1c456 100644 --- a/docs/common/Vesting/Vesting.md +++ b/docs/common/Vesting/Vesting.md @@ -10,6 +10,23 @@ An extension of the Staking contract that enables vesting the stake for a higher ## Methods +### DEFAULT_ADMIN_ROLE + +```solidity +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### DENOMINATOR ```solidity @@ -44,6 +61,157 @@ function aprCalculatorContract() external view returns (contract IAPRCalculator) |---|---|---| | _0 | contract IAPRCalculator | undefined | +### getRoleAdmin + +```solidity +function getRoleAdmin(bytes32 role) external view returns (bytes32) +``` + + + +*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + +### grantRole + +```solidity +function grantRole(bytes32 role, address account) external nonpayable +``` + + + +*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### hasRole + +```solidity +function hasRole(bytes32 role, address account) external view returns (bool) +``` + + + +*Returns `true` if `account` has been granted `role`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### penaltyDecreasePerWeek + +```solidity +function penaltyDecreasePerWeek() external view returns (uint256) +``` + +The penalty decrease per week + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### renounceRole + +```solidity +function renounceRole(bytes32 role, address account) external nonpayable +``` + + + +*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### revokeRole + +```solidity +function revokeRole(bytes32 role, address account) external nonpayable +``` + + + +*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### setPenaltyDecreasePerWeek + +```solidity +function setPenaltyDecreasePerWeek(uint256 newRate) external nonpayable +``` + +sets a new penalty rate + +*Only callable by the adminthe rate should be between 10 and 150 (0.1% and 1.5%)* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newRate | uint256 | the new penalty rate | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*See {IERC165-supportsInterface}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + ### vestingLiquidityDecreasePerWeek ```solidity @@ -81,6 +249,60 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | +### RoleAdminChanged + +```solidity +event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| previousAdminRole `indexed` | bytes32 | undefined | +| newAdminRole `indexed` | bytes32 | undefined | + +### RoleGranted + +```solidity +event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | + +### RoleRevoked + +```solidity +event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | + ## Errors @@ -96,4 +318,15 @@ error FailedToBurnAmount() +### PenaltyRateOutOfRange + +```solidity +error PenaltyRateOutOfRange() +``` + + + + + + diff --git a/docs/common/Withdrawal/Withdrawal.md b/docs/common/Withdrawal/Withdrawal.md index adab84da..f269966d 100644 --- a/docs/common/Withdrawal/Withdrawal.md +++ b/docs/common/Withdrawal/Withdrawal.md @@ -10,17 +10,23 @@ ## Methods -### acceptOwnership +### DEFAULT_ADMIN_ROLE ```solidity -function acceptOwnership() external nonpayable +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) ``` -*The new owner accepts the ownership transfer.* + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### changeWithdrawalWaitPeriod ```solidity @@ -37,39 +43,67 @@ Changes the withdrawal wait period. |---|---|---| | newWaitPeriod | uint256 | The new withdrawal wait period. MUST be longer than a single epoch (in some realistic worst-case scenario) in case somebody's stake needs to be penalized. | -### owner +### getRoleAdmin ```solidity -function owner() external view returns (address) +function getRoleAdmin(bytes32 role) external view returns (bytes32) ``` -*Returns the address of the current owner.* +*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* + +#### Parameters +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | +| _0 | bytes32 | undefined | -### pendingOwner +### grantRole ```solidity -function pendingOwner() external view returns (address) +function grantRole(bytes32 role, address account) external nonpayable ``` -*Returns the address of the pending owner.* +*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | +### hasRole + +```solidity +function hasRole(bytes32 role, address account) external view returns (bool) +``` + + + +*Returns `true` if `account` has been granted `role`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | +| _0 | bool | undefined | ### pendingWithdrawals @@ -93,32 +127,61 @@ Calculates how much is yet to become withdrawable for account. |---|---|---| | _0 | uint256 | Amount not yet withdrawable (in wei) | -### renounceOwnership +### renounceRole + +```solidity +function renounceRole(bytes32 role, address account) external nonpayable +``` + + + +*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### revokeRole ```solidity -function renounceOwnership() external nonpayable +function revokeRole(bytes32 role, address account) external nonpayable ``` -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* +*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* + +#### Parameters +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | -### transferOwnership +### supportsInterface ```solidity -function transferOwnership(address newOwner) external nonpayable +function supportsInterface(bytes4 interfaceId) external view returns (bool) ``` -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* +*See {IERC165-supportsInterface}.* #### Parameters | Name | Type | Description | |---|---|---| -| newOwner | address | undefined | +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | ### withdraw @@ -195,10 +258,10 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferStarted +### RoleAdminChanged ```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) +event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) ``` @@ -209,13 +272,14 @@ event OwnershipTransferStarted(address indexed previousOwner, address indexed ne | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| previousAdminRole `indexed` | bytes32 | undefined | +| newAdminRole `indexed` | bytes32 | undefined | -### OwnershipTransferred +### RoleGranted ```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) ``` @@ -226,8 +290,27 @@ event OwnershipTransferred(address indexed previousOwner, address indexed newOwn | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | + +### RoleRevoked + +```solidity +event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | ### WithdrawalFinished diff --git a/test/APRCalculator/APRCalculator.test.ts b/test/APRCalculator/APRCalculator.test.ts index b2278050..e27e4ebf 100644 --- a/test/APRCalculator/APRCalculator.test.ts +++ b/test/APRCalculator/APRCalculator.test.ts @@ -6,7 +6,7 @@ import { DENOMINATOR, ERRORS, FAST_SMA, - INITIAL_BASE_APR, + BASE_APR, INITIAL_DEFAULT_MACRO_FACTOR, INITIAL_PRICE, MAX_MACRO_FACTOR, @@ -26,9 +26,8 @@ export function RunAPRCalculatorTests(): void { const { aprCalculator } = await loadFixture(this.fixtures.presetHydraChainStateFixture); expect(aprCalculator.deployTransaction.from).to.equal(this.signers.admin.address); - expect(await aprCalculator.base()).to.equal(0); - expect(await aprCalculator.INITIAL_BASE_APR()).to.equal(INITIAL_BASE_APR); expect(await aprCalculator.DENOMINATOR()).to.be.equal(DENOMINATOR); + expect(await aprCalculator.BASE_APR()).to.equal(BASE_APR); // RSIndex expect(await aprCalculator.MAX_RSI_BONUS()).to.be.equal(MAX_RSI_BONUS); @@ -77,7 +76,6 @@ export function RunAPRCalculatorTests(): void { expect(await aprCalculator.hasRole(managerRole, this.signers.governance.address)).to.be.true; expect(await aprCalculator.hasRole(adminRole, this.signers.governance.address)).to.be.true; - expect(await aprCalculator.base()).to.be.equal(INITIAL_BASE_APR); // Macro Factor expect(await aprCalculator.defaultMacroFactor()).to.equal(INITIAL_DEFAULT_MACRO_FACTOR); @@ -125,7 +123,7 @@ export function RunAPRCalculatorTests(): void { it("should get max APR", async function () { const { aprCalculator } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - const base = await aprCalculator.base(); + const base = await aprCalculator.BASE_APR(); const macroFactor = await aprCalculator.MAX_MACRO_FACTOR(); const vestingBonus = await aprCalculator.getVestingBonus(52); const rsiBonus = await aprCalculator.MAX_RSI_BONUS(); @@ -148,25 +146,6 @@ export function RunAPRCalculatorTests(): void { }); }); - describe("Set base", function () { - it("should revert when trying to set base without manager role", async function () { - const { aprCalculator } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - const managerRole = await aprCalculator.MANAGER_ROLE(); - - await expect(aprCalculator.setBase(1500)).to.be.revertedWith( - ERRORS.accessControl(this.signers.accounts[0].address.toLocaleLowerCase(), managerRole) - ); - }); - - it("should set base", async function () { - const { aprCalculator } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - - await aprCalculator.connect(this.signers.governance).setBase(1500); - - expect(await aprCalculator.base()).to.be.equal(1500); - }); - }); - describe("Price", function () { RunPriceTests(); }); diff --git a/test/APRCalculator/Price.test.ts b/test/APRCalculator/Price.test.ts index 975eaf22..a86db165 100644 --- a/test/APRCalculator/Price.test.ts +++ b/test/APRCalculator/Price.test.ts @@ -2,7 +2,7 @@ import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; import { expect } from "chai"; -import { ERRORS } from "../constants"; +import { ERRORS, INITIAL_PRICES_TO_REACH_BONUSES } from "../constants"; import { getCurrentDay } from "../helper"; export function RunPriceTests(): void { @@ -15,6 +15,38 @@ export function RunPriceTests(): void { .withArgs(ERRORS.unauthorized.priceOracleArg); }); + it("should revert if Price Oracle gives 0", async function () { + const { aprCalculator, hydraChain } = await loadFixture(this.fixtures.presetHydraChainStateFixture); + // Initialize APR Calculator and set governance as price oracle + await aprCalculator + .connect(this.signers.system) + .initialize( + this.signers.governance.address, + hydraChain.address, + this.signers.governance.address, + INITIAL_PRICES_TO_REACH_BONUSES + ); + + await expect(aprCalculator.connect(this.signers.governance).updatePrice(0, 1152)).to.be.reverted; + }); + + it("should revert if Price Oracle gives a day that already have a price", async function () { + const { aprCalculator, hydraChain } = await loadFixture(this.fixtures.presetHydraChainStateFixture); + // Initialize APR Calculator and set governance as price oracle + await aprCalculator + .connect(this.signers.system) + .initialize( + this.signers.governance.address, + hydraChain.address, + this.signers.governance.address, + INITIAL_PRICES_TO_REACH_BONUSES + ); + + await expect(aprCalculator.connect(this.signers.governance).updatePrice(4, 1)).to.not.be.reverted; + expect(await aprCalculator.pricePerDay(1)).to.not.equal(0); + await expect(aprCalculator.connect(this.signers.governance).updatePrice(4, 1)).to.be.reverted; + }); + it("should update price correctly", async function () { const { aprCalculator, priceOracle, priceToVote, validatorToVote } = await loadFixture( this.fixtures.votedValidatorsStateFixture diff --git a/test/HydraChain/Inspector.test.ts b/test/HydraChain/Inspector.test.ts index 1f83a08c..1e013618 100644 --- a/test/HydraChain/Inspector.test.ts +++ b/test/HydraChain/Inspector.test.ts @@ -471,6 +471,26 @@ export function RunInspectorTests(): void { .to.not.be.reverted; }); + it("should not ban validator if he is already banned", async function () { + const { systemHydraChain, hydraStaking } = await loadFixture(this.fixtures.stakedValidatorsStateFixture); + + // commit a couple of epochs in order to have a timestamp + await commitEpochs( + systemHydraChain, + hydraStaking, + [this.signers.validators[0], this.signers.validators[1]], + 5, // number of epochs to commit + this.epochSize + ); + + await expect(systemHydraChain.connect(this.signers.governance).banValidator(this.signers.validators[0].address)) + .to.not.be.reverted; + + await expect( + systemHydraChain.connect(this.signers.governance).banValidator(this.signers.validators[0].address) + ).to.be.revertedWithCustomError(systemHydraChain, "NoBanSubject"); + }); + it("should set bansInitiate to 0 on ban", async function () { const { hydraChain } = await loadFixture(this.fixtures.banInitiatedFixtureFunction); diff --git a/test/HydraChain/ValidatrosData.test.ts b/test/HydraChain/ValidatrosData.test.ts index e3177c5a..4f942daa 100644 --- a/test/HydraChain/ValidatrosData.test.ts +++ b/test/HydraChain/ValidatrosData.test.ts @@ -136,4 +136,32 @@ export function RunValidatorsDataTests(): void { expect(await hydraChain.getTotalVotingPower()).to.deep.equal(20); }); + + it("should emit event on syncValidatorsData", async function () { + const { hydraChain } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); + + const validatorsData = [{ validator: this.signers.validators[1].address, votingPower: 12 }]; + const tx = await hydraChain.connect(this.signers.system).syncValidatorsData(validatorsData); + + const receipt = await tx.wait(); + + // Find the specific ValidatorsDataSynced event + const event = receipt.events?.find((e) => e.event === "ValidatorsDataSynced"); + + // Check the event and its arguments + if (!event || !event.args) { + throw new Error("ValidatorsDataSynced event not found."); + } + expect(event.args[0][0].validator).to.be.equal(this.signers.validators[1].address); + expect(event.args[0][0].votingPower).to.be.equal(12); + }); + + it("should return if we pass empty validators data", async function () { + const { hydraChain } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); + + await expect(hydraChain.connect(this.signers.system).syncValidatorsData([])).to.not.emit( + hydraChain, + "ValidatorsDataSynced" + ); + }); } diff --git a/test/HydraDelegation/HydraDelegation.test.ts b/test/HydraDelegation/HydraDelegation.test.ts index 0d89b64c..5b0a533a 100644 --- a/test/HydraDelegation/HydraDelegation.test.ts +++ b/test/HydraDelegation/HydraDelegation.test.ts @@ -41,17 +41,21 @@ export function RunHydraDelegationTests(): void { const { hydraDelegation } = await loadFixture(this.fixtures.presetHydraChainStateFixture); expect(hydraDelegation.deployTransaction.from).to.equal(this.signers.admin.address); - expect(await hydraDelegation.owner()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraDelegation.minDelegation()).to.equal(0); expect(await hydraDelegation.totalDelegation()).to.equal(0); expect(await hydraDelegation.hydraChainContract()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraDelegation.hydraStakingContract()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraDelegation.aprCalculatorContract()).to.equal(hre.ethers.constants.AddressZero); + expect( + await hydraDelegation.hasRole(await hydraDelegation.DEFAULT_ADMIN_ROLE(), this.signers.governance.address), + "hasRole" + ).to.be.false; expect(await hydraDelegation.MAX_COMMISSION()).to.equal(MAX_COMMISSION); expect(await hydraDelegation.MIN_DELEGATION_LIMIT()).to.equal(this.minDelegation); // Vested Delegation + expect(await hydraDelegation.penaltyDecreasePerWeek()).to.equal(0); expect(await hydraDelegation.vestingLiquidityDecreasePerWeek()).to.equal(0); expect(await hydraDelegation.vestingManagerFactoryContract()).to.equal(hre.ethers.constants.AddressZero); @@ -137,7 +141,6 @@ export function RunHydraDelegationTests(): void { "delegationCommissionPerStaker" ).to.equal(INITIAL_COMMISSION); - expect(await hydraDelegation.owner(), "owner").to.equal(this.signers.governance.address); expect(await hydraDelegation.minDelegation(), "minDelegation").to.equal(this.minDelegation); expect(await hydraDelegation.hydraChainContract(), "hydraChainContract").to.equal(hydraChain.address); expect(await hydraDelegation.hydraStakingContract(), "hydraStakingContract").to.equal(hydraStaking.address); @@ -148,6 +151,7 @@ export function RunHydraDelegationTests(): void { ).to.be.true; // Vested Delegation + expect(await hydraDelegation.penaltyDecreasePerWeek()).to.equal(50); expect(await hydraDelegation.vestingLiquidityDecreasePerWeek()).to.equal(133); expect(await hydraDelegation.vestingManagerFactoryContract(), "vestingManagerFactoryContract").to.equal( vestingManagerFactory.address @@ -561,7 +565,7 @@ export function RunHydraDelegationTests(): void { ); const baseReward = await hydraDelegation.getRawReward(delegatedValidator.address, vestManager.address); const baseRewardAfterCommission = applyCommissionToReward(baseReward, positionData.commission); - const base = await aprCalculator.base(); + const base = await aprCalculator.BASE_APR(); // calculate position rewards const expectedReward = await calcExpectedPositionRewardForActivePosition( diff --git a/test/HydraDelegation/VestedDelegation.test.ts b/test/HydraDelegation/VestedDelegation.test.ts index 5d074909..30ed90e4 100644 --- a/test/HydraDelegation/VestedDelegation.test.ts +++ b/test/HydraDelegation/VestedDelegation.test.ts @@ -1708,5 +1708,36 @@ export function RunVestedDelegationTests(): void { expect(rewardAfterCommission).to.be.equal(rewardAfterCommitEpoch); }); }); + + describe("penaltyDecreasePerWeek()", async function () { + it("should revert setting penalty decrease per week if not governance", async function () { + const { hydraDelegation, delegatedValidator } = await loadFixture(this.fixtures.vestedDelegationFixture); + + const admin = await hydraDelegation.DEFAULT_ADMIN_ROLE(); + + await expect(hydraDelegation.connect(delegatedValidator).setPenaltyDecreasePerWeek(100)).to.be.revertedWith( + ERRORS.accessControl(delegatedValidator.address.toLocaleLowerCase(), admin) + ); + }); + + it("should revert setting penalty decrease per week if amount of of range", async function () { + const { hydraDelegation } = await loadFixture(this.fixtures.vestedDelegationFixture); + + await expect( + hydraDelegation.connect(this.signers.governance).setPenaltyDecreasePerWeek(9) + ).to.be.revertedWithCustomError(hydraDelegation, "PenaltyRateOutOfRange"); + + await expect( + hydraDelegation.connect(this.signers.governance).setPenaltyDecreasePerWeek(151) + ).to.be.revertedWithCustomError(hydraDelegation, "PenaltyRateOutOfRange"); + }); + + it("should set penalty decrease per week", async function () { + const { hydraDelegation } = await loadFixture(this.fixtures.vestedDelegationFixture); + + await hydraDelegation.connect(this.signers.governance).setPenaltyDecreasePerWeek(100); + expect(await hydraDelegation.penaltyDecreasePerWeek()).to.be.eq(100); + }); + }); }); } diff --git a/test/HydraStaking/HydraStaking.test.ts b/test/HydraStaking/HydraStaking.test.ts index 43d00b05..5616c3d8 100644 --- a/test/HydraStaking/HydraStaking.test.ts +++ b/test/HydraStaking/HydraStaking.test.ts @@ -18,18 +18,22 @@ export function RunHydraStakingTests(): void { const { hydraStaking } = await loadFixture(this.fixtures.presetHydraChainStateFixture); expect(hydraStaking.deployTransaction.from).to.equal(this.signers.admin.address); - expect(await hydraStaking.owner()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraStaking.minStake()).to.equal(0); expect(await hydraStaking.totalStake()).to.equal(0); expect(await hydraStaking.hydraChainContract()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraStaking.delegationContract()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraStaking.aprCalculatorContract()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraStaking.lastDistribution()).to.be.equal(0); + expect( + await hydraStaking.hasRole(await hydraStaking.DEFAULT_ADMIN_ROLE(), this.signers.governance.address), + "hasRole" + ).to.be.false; expect(await hydraStaking.MIN_STAKE_LIMIT()).to.equal(this.minStake); // Vested Staking expect(await hydraStaking.vestingLiquidityDecreasePerWeek()).to.equal(0); + expect(await hydraStaking.penaltyDecreasePerWeek()).to.equal(0); expect(await hydraStaking.DENOMINATOR()).to.equal(DENOMINATOR); // Liquid Delegation @@ -104,7 +108,6 @@ export function RunHydraStakingTests(): void { const { hydraChain, hydraDelegation, liquidToken, hydraStaking, aprCalculator, rewardWallet } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - expect(await hydraStaking.owner(), "owner").to.equal(this.signers.governance.address); expect(await hydraStaking.minStake(), "minStake").to.equal(this.minStake); expect(await hydraStaking.totalStake(), "totalStake").to.equal(this.minStake.mul(2)); expect(await hydraStaking.totalBalance(), "totalBalance").to.equal(this.minStake.mul(2)); @@ -114,13 +117,14 @@ export function RunHydraStakingTests(): void { expect(await hydraStaking.stakeOf(this.signers.admin.address), "stakeOf").to.equal(this.minStake.mul(2)); expect(await hydraStaking.totalBalanceOf(this.signers.admin.address), "stakeOf").to.equal(this.minStake.mul(2)); expect( - await hydraDelegation.hasRole(await hydraDelegation.DEFAULT_ADMIN_ROLE(), this.signers.governance.address), + await hydraStaking.hasRole(await hydraStaking.DEFAULT_ADMIN_ROLE(), this.signers.governance.address), "hasRole" ).to.be.true; expect(await hydraStaking.lastDistribution()).to.not.equal(0); // Vested Staking expect(await hydraStaking.vestingLiquidityDecreasePerWeek()).to.equal(133); + expect(await hydraStaking.penaltyDecreasePerWeek()).to.equal(50); // Liquid Delegation expect(await hydraStaking.liquidToken(), "liquidToken").to.equal(liquidToken.address); @@ -232,7 +236,7 @@ export function RunHydraStakingTests(): void { const { hydraStaking } = await loadFixture(this.fixtures.registeredValidatorsStateFixture); await expect(hydraStaking.connect(this.signers.validators[0]).changeMinStake(this.minStake)).to.be.revertedWith( - ERRORS.ownable + ERRORS.accessControl(this.signers.validators[0].address, await hydraStaking.DEFAULT_ADMIN_ROLE()) ); }); diff --git a/test/HydraStaking/VestedStaking.test.ts b/test/HydraStaking/VestedStaking.test.ts index b0d23540..f68607ae 100644 --- a/test/HydraStaking/VestedStaking.test.ts +++ b/test/HydraStaking/VestedStaking.test.ts @@ -12,7 +12,7 @@ import { getValidatorReward, registerValidator, } from "../helper"; -import { VESTING_DURATION_WEEKS, WEEK } from "../constants"; +import { ERRORS, VESTING_DURATION_WEEKS, WEEK } from "../constants"; export function RunVestedStakingTests(): void { describe("", function () { @@ -44,7 +44,7 @@ export function RunVestedStakingTests(): void { const start = await time.latest(); expect(vestingData.start, "start").to.be.equal(start); expect(vestingData.end, "end").to.be.equal(start + vestingDuration); - expect(vestingData.base, "base").to.be.equal(await aprCalculator.base()); + expect(vestingData.base, "base").to.be.equal(await aprCalculator.BASE_APR()); expect(vestingData.vestBonus, "vestBonus").to.be.equal(await aprCalculator.getVestingBonus(10)); expect(vestingData.rsiBonus, "rsiBonus").to.be.equal(await aprCalculator.rsi()); @@ -433,5 +433,36 @@ export function RunVestedStakingTests(): void { expect(totalRewards).to.be.eq(claimableRewards); }); }); + + describe("penaltyDecreasePerWeek()", async function () { + it("should revert setting penalty decrease per week if not admin", async function () { + const { hydraDelegation, delegatedValidator } = await loadFixture(this.fixtures.vestedDelegationFixture); + + const admin = await hydraDelegation.DEFAULT_ADMIN_ROLE(); + + await expect(hydraDelegation.connect(delegatedValidator).setPenaltyDecreasePerWeek(100)).to.be.revertedWith( + ERRORS.accessControl(delegatedValidator.address.toLocaleLowerCase(), admin) + ); + }); + + it("should revert setting penalty decrease per week if amount of of range", async function () { + const { hydraDelegation } = await loadFixture(this.fixtures.vestedDelegationFixture); + + await expect( + hydraDelegation.connect(this.signers.governance).setPenaltyDecreasePerWeek(9) + ).to.be.revertedWithCustomError(hydraDelegation, "PenaltyRateOutOfRange"); + + await expect( + hydraDelegation.connect(this.signers.governance).setPenaltyDecreasePerWeek(151) + ).to.be.revertedWithCustomError(hydraDelegation, "PenaltyRateOutOfRange"); + }); + + it("should set penalty decrease per week", async function () { + const { hydraDelegation } = await loadFixture(this.fixtures.vestedDelegationFixture); + + await hydraDelegation.connect(this.signers.governance).setPenaltyDecreasePerWeek(100); + expect(await hydraDelegation.penaltyDecreasePerWeek()).to.be.eq(100); + }); + }); }); } diff --git a/test/LiquidityToken/LiquidityToken.test.ts b/test/LiquidityToken/LiquidityToken.test.ts index 5a0c77bf..d3cc7a87 100644 --- a/test/LiquidityToken/LiquidityToken.test.ts +++ b/test/LiquidityToken/LiquidityToken.test.ts @@ -91,7 +91,7 @@ export function RunLiquidityTokenTests(): void { const { token } = await loadFixture(initializeFixture); await expect(token.mint(accounts[4].address, 100)).to.be.revertedWith( - "AccessControl: account " + accounts[0].address.toLowerCase() + " is missing role " + supplyControllerRole + ERRORS.accessControl(accounts[0].address.toLowerCase(), supplyControllerRole) ); }); }); @@ -101,7 +101,7 @@ export function RunLiquidityTokenTests(): void { const { token } = await loadFixture(initializeFixture); await expect(token.burn(accounts[4].address, 100)).to.be.revertedWith( - "AccessControl: account " + accounts[0].address.toLowerCase() + " is missing role " + supplyControllerRole + ERRORS.accessControl(accounts[0].address.toLowerCase(), supplyControllerRole) ); }); }); @@ -126,11 +126,11 @@ export function RunLiquidityTokenTests(): void { const { token } = await loadFixture(initializeFixture); await expect(token.revokeRole(supplyControllerRole, supplyController.address)).to.be.revertedWith( - "AccessControl: account " + accounts[0].address.toLowerCase() + " is missing role " + governorRole + ERRORS.accessControl(accounts[0].address.toLowerCase(), governorRole) ); await expect(token.grantRole(supplyControllerRole, accounts[5].address)).to.be.revertedWith( - "AccessControl: account " + accounts[0].address.toLowerCase() + " is missing role " + governorRole + ERRORS.accessControl(accounts[0].address.toLowerCase(), governorRole) ); }); diff --git a/test/PriceOracle/PriceOracle.test.ts b/test/PriceOracle/PriceOracle.test.ts index 927deda3..8fb5a32a 100644 --- a/test/PriceOracle/PriceOracle.test.ts +++ b/test/PriceOracle/PriceOracle.test.ts @@ -2,6 +2,7 @@ import { ethers, network } from "hardhat"; /* eslint-disable node/no-extraneous-import */ import { loadFixture, time } from "@nomicfoundation/hardhat-network-helpers"; import { expect } from "chai"; +import { BigNumber } from "ethers"; import * as mcl from "../../ts/mcl"; import { CHAIN_ID, DAY, DOMAIN, ERRORS, INITIAL_PRICE, MAX_ACTIVE_VALIDATORS } from "../constants"; @@ -57,6 +58,16 @@ export function RunPriceOracleTests(): void { ); }); + it("should revert vote with price bigger than max uint224", async function () { + const { priceOracle } = await loadFixture(this.fixtures.stakedValidatorsStateFixture); + + const maxUint224 = BigNumber.from(2).pow(224).sub(1); + + await expect( + priceOracle.connect(this.signers.validators[0]).vote(maxUint224.add(1)) + ).to.be.revertedWithCustomError(priceOracle, "InvalidPrice"); + }); + it("should revert when not in voting time", async function () { const { priceOracle } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); diff --git a/test/VestingManager/VestingManager.test.ts b/test/VestingManager/VestingManager.test.ts index aab2cd85..d07a590d 100644 --- a/test/VestingManager/VestingManager.test.ts +++ b/test/VestingManager/VestingManager.test.ts @@ -8,9 +8,12 @@ export function RunVestingManagerTests(): void { describe("", function () { describe("VestingManager initializations", function () { it("should validate values when VestingManager is cloned", async function () { - const { vestManager, hydraDelegation, vestManagerOwner } = await loadFixture(this.fixtures.vestManagerFixture); + const { vestManager, hydraDelegation, vestManagerOwner, liquidToken } = await loadFixture( + this.fixtures.vestManagerFixture + ); expect(await vestManager.HYDRA_DELEGATION()).to.equal(hydraDelegation.address); + expect(await vestManager.LIQUIDITY_TOKEN()).to.equal(liquidToken.address); expect(await vestManager.owner()).to.equal(vestManagerOwner.address); }); diff --git a/test/VestingManager/VestingManagerFactory.test.ts b/test/VestingManager/VestingManagerFactory.test.ts index 537df882..376bb47b 100644 --- a/test/VestingManager/VestingManagerFactory.test.ts +++ b/test/VestingManager/VestingManagerFactory.test.ts @@ -16,11 +16,11 @@ export function RunVestManagerFactoryTests(): void { }); it("should revert when initialized without system call", async function () { - const { vestingManagerFactory, hydraDelegation } = await loadFixture( + const { vestingManagerFactory, hydraDelegation, liquidToken } = await loadFixture( this.fixtures.presetHydraChainStateFixture ); - await expect(vestingManagerFactory.initialize(hydraDelegation.address)) + await expect(vestingManagerFactory.initialize(hydraDelegation.address, liquidToken.address)) .to.be.revertedWithCustomError(vestingManagerFactory, ERRORS.unauthorized.name) .withArgs(ERRORS.unauthorized.systemCallArg); }); @@ -32,12 +32,12 @@ export function RunVestManagerFactoryTests(): void { }); it("should revert on re-initialization attempt", async function () { - const { hydraDelegation, vestingManagerFactory } = await loadFixture( + const { hydraDelegation, vestingManagerFactory, liquidToken } = await loadFixture( this.fixtures.initializedHydraChainStateFixture ); await expect( - vestingManagerFactory.connect(this.signers.system).initialize(hydraDelegation.address) + vestingManagerFactory.connect(this.signers.system).initialize(hydraDelegation.address, liquidToken.address) ).to.be.revertedWith(ERRORS.initialized); }); }); diff --git a/test/common/Withdrawal.test.ts b/test/common/Withdrawal.test.ts index dc967eb7..e608cbff 100644 --- a/test/common/Withdrawal.test.ts +++ b/test/common/Withdrawal.test.ts @@ -73,10 +73,11 @@ export function RunWithdrawalTests(): void { it("should fail to update withdraw time if not governance", async function () { const { hydraStaking } = await loadFixture(this.fixtures.withdrawableFixture); + const adminRole = await hydraStaking.DEFAULT_ADMIN_ROLE(); await expect( hydraStaking.connect(this.signers.validators[0]).changeWithdrawalWaitPeriod(WEEK * 2) - ).to.be.revertedWith(ERRORS.ownable); + ).to.be.revertedWith(ERRORS.accessControl(this.signers.validators[0].address, adminRole)); }); it("should fail update withdraw time if we pass 0", async function () { diff --git a/test/constants.ts b/test/constants.ts index 17fedfea..7d186430 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -14,7 +14,7 @@ export const HOUR = 60 * 60; export const DAY = 60 * 60 * 24; export const WEEK = DAY * 7; export const VESTING_DURATION_WEEKS = 10; // in weeks -export const INITIAL_BASE_APR = ethers.BigNumber.from(500); +export const BASE_APR = ethers.BigNumber.from(500); export const INITIAL_DEFAULT_MACRO_FACTOR = ethers.BigNumber.from(7500); export const MIN_MACRO_FACTOR = ethers.BigNumber.from(1250); export const MAX_MACRO_FACTOR = ethers.BigNumber.from(17500); diff --git a/test/fixtures.ts b/test/fixtures.ts index 89116053..fbde9f9f 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -244,7 +244,7 @@ async function initializedHydraChainStateFixtureFunction(this: Mocha.Context) { rewardWallet.address ); - await vestingManagerFactory.connect(this.signers.system).initialize(hydraDelegation.address); + await vestingManagerFactory.connect(this.signers.system).initialize(hydraDelegation.address, liquidToken.address); await priceOracle.connect(this.signers.system).initialize(hydraChain.address, aprCalculator.address); @@ -353,7 +353,7 @@ async function initializedWithSpecificBonusesStateFixtureFunction(this: Mocha.Co rewardWallet.address ); - await vestingManagerFactory.connect(this.signers.system).initialize(hydraDelegation.address); + await vestingManagerFactory.connect(this.signers.system).initialize(hydraDelegation.address, liquidToken.address); await priceOracle.connect(this.signers.system).initialize(hydraChain.address, aprCalculator.address); diff --git a/test/forge/InitializedContracts.sol b/test/forge/InitializedContracts.sol index abfc03ef..cd99d6ca 100644 --- a/test/forge/InitializedContracts.sol +++ b/test/forge/InitializedContracts.sol @@ -67,7 +67,7 @@ abstract contract InitializedContracts is Test { aprCalculator.initialize(governance, address(hydraChain), address(priceOracle), prices); // ⭐️ Initialize VestingManagerFactory - vestingManagerFactory.initialize(address(hydraDelegation)); + vestingManagerFactory.initialize(address(hydraDelegation), address(liquidityToken)); // ⭐️ Initialize PriceOracle priceOracle.initialize(address(hydraChain), address(aprCalculator)); @@ -261,7 +261,8 @@ contract TestInitlizedContracts is InitializedContracts { // HydraStaking function test_getGovernanceFromHydraStaking() public view { - assert(hydraStaking.owner() == governance); + bytes32 role = hydraStaking.DEFAULT_ADMIN_ROLE(); + assert(hydraStaking.hasRole(role, governance) == true); } function test_getMinStakeFromHydraStaking() public view { @@ -299,7 +300,8 @@ contract TestInitlizedContracts is InitializedContracts { // HydraDelegation function test_getGovernanceFromHydraDelegation() public view { - assert(hydraDelegation.owner() == governance); + bytes32 role = hydraStaking.DEFAULT_ADMIN_ROLE(); + assert(hydraStaking.hasRole(role, governance) == true); } function test_getInitalCommissionFromHydraDelegation() public view { diff --git a/test/forge/PriceModule.t.sol b/test/forge/PriceModule.t.sol index cedd6eda..a41a9ae9 100644 --- a/test/forge/PriceModule.t.sol +++ b/test/forge/PriceModule.t.sol @@ -52,7 +52,7 @@ contract TestUpdatePrice is InitlizeAPR { function test_updateBonusesWithPricesGoingUp() public { vm.startPrank(governance); - for (uint256 i = 0; i < 115; i++) { + for (uint256 i = 1; i < 116; i++) { aprCalculator.updatePrice(600 * i, i); assertEq(aprCalculator.latestDailyPrice(), 600 * i); assertEq(aprCalculator.pricePerDay(i), 600 * i); @@ -76,6 +76,9 @@ contract TestUpdatePrice is InitlizeAPR { vm.startPrank(governance); for (uint256 i = 0; i < 500; i++) { uint256 price = generateRandomAmount(i); + if (price == 0) { + price = 1; + } aprCalculator.updatePrice(price, i); assertEq(aprCalculator.latestDailyPrice(), price); assertEq(aprCalculator.pricePerDay(i), price); diff --git a/test/helper.ts b/test/helper.ts index da6d904d..5057db49 100644 --- a/test/helper.ts +++ b/test/helper.ts @@ -323,14 +323,14 @@ export async function calculatePenalty(position: any, timestamp: BigNumber, amou } // basis points used for precise percentage calculations - const bps = leftWeeks.mul(100); + const bps = leftWeeks.mul(50); return amount.mul(bps).div(DENOMINATOR); } export async function calculatePenaltyByWeeks(weeksLeft: number, amount: BigNumber) { // 1% penalty for each week that is left const weeksInBigNumber = hre.ethers.BigNumber.from(weeksLeft); - const bps = weeksInBigNumber.mul(100); + const bps = weeksInBigNumber.mul(50); return amount.mul(bps).div(DENOMINATOR); } @@ -386,7 +386,7 @@ export async function attachAddressToVestingManager(address: string) { } export async function applyMaxReward(aprCalculator: APRCalculator, reward: BigNumber) { - const base = await aprCalculator.base(); + const base = await aprCalculator.BASE_APR(); const rsi = await aprCalculator.rsi(); const vestBonus = await aprCalculator.getVestingBonus(52);