-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
2,795 additions
and
3,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/DelegatedStaking/DelegationPoolLib.sol → ...cts/HydraDelegation/DelegationPoolLib.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import {Delegation} from "./Delegation.sol"; | ||
import {LiquidDelegation} from "./modules/LiquidDelegation/LiquidDelegation.sol"; | ||
import {VestedDelegation} from "./modules/VestedDelegation/VestedDelegation.sol"; | ||
import {APRCalculatorConnector} from "./../APRCalculator/APRCalculatorConnector.sol"; | ||
import {IHydraDelegation} from "./IHydraDelegation.sol"; | ||
import {StakerInit} from "./../HydraStaking/IHydraStaking.sol"; | ||
import {HydraStakingConnector} from "./../HydraStakingV2/HydraStakingConnector.sol"; | ||
|
||
contract HydraDelegation is | ||
IHydraDelegation, | ||
APRCalculatorConnector, | ||
HydraStakingConnector, | ||
Delegation, | ||
LiquidDelegation, | ||
VestedDelegation | ||
{ | ||
/// @notice A constant for the maximum comission a validator can receive from the delegator's rewards | ||
uint256 public constant MAX_COMMISSION = 100; | ||
|
||
mapping(address => uint256) public delegationCommissionPerStaker; | ||
|
||
// _______________ Initializer _______________ | ||
|
||
// TODO: Move commision to Delegation module | ||
function __DelegatedStaking_init( | ||
StakerInit[] calldata initialStakers, | ||
uint256 initialCommission | ||
) internal onlyInitializing { | ||
__DelegatedStaking_init_unchained(initialStakers, initialCommission); | ||
} | ||
|
||
function __DelegatedStaking_init_unchained( | ||
StakerInit[] calldata initialStakers, | ||
uint256 initialCommission | ||
) internal onlyInitializing { | ||
for (uint256 i = 0; i < initialStakers.length; i++) { | ||
_setCommission(initialStakers[i].addr, initialCommission); | ||
} | ||
} | ||
|
||
function stakerDelegationCommission(address staker) external view returns (uint256) { | ||
return delegationCommissionPerStaker[staker]; | ||
} | ||
|
||
function distributeDelegationRewards(address staker, uint256 reward, uint256 epochId) external onlyHydraStaking { | ||
_distributeDelegationRewards(staker, reward, epochId); | ||
} | ||
|
||
/** | ||
* @inheritdoc IHydraDelegation | ||
*/ | ||
function setCommission(uint256 newCommission) external { | ||
_setCommission(msg.sender, newCommission); | ||
} | ||
|
||
function _delegate( | ||
address staker, | ||
address delegator, | ||
uint256 amount | ||
) internal virtual override(Delegation, LiquidDelegation, VestedDelegation) { | ||
super._delegate(staker, delegator, amount); | ||
} | ||
|
||
function _undelegate( | ||
address validator, | ||
address delegator, | ||
uint256 amount | ||
) internal virtual override(Delegation, LiquidDelegation, VestedDelegation) { | ||
super._undelegate(validator, delegator, amount); | ||
} | ||
|
||
function _setCommission(address staker, uint256 newCommission) private { | ||
if (newCommission > MAX_COMMISSION) revert InvalidCommission(newCommission); | ||
|
||
delegationCommissionPerStaker[staker] = newCommission; | ||
|
||
emit CommissionUpdated(staker, newCommission); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import {ILiquid} from "./../common/Liquid/ILiquid.sol"; | ||
import {IDelegation} from "./IDelegation.sol"; | ||
import {IVestedDelegation} from "./modules/VestedDelegation/IVestedDelegation.sol"; | ||
|
||
interface IHydraDelegation is IDelegation, IVestedDelegation, ILiquid { | ||
event CommissionUpdated(address indexed validator, uint256 newCommission); | ||
|
||
error InvalidCommission(uint256 commission); | ||
|
||
function stakerDelegationCommission(address staker) external view returns (uint256); | ||
|
||
/** | ||
* @notice Sets commission for validator. | ||
* @param newCommission New commission (100 = 100%) | ||
*/ | ||
function setCommission(uint256 newCommission) external; | ||
|
||
function distributeDelegationRewards(address staker, uint256 reward, uint256 epochId) external; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.