-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from NethermindEth/anshu/eigenlayer-mvp
Add Eigenlayer MVP
- Loading branch information
Showing
4 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.25; | ||
|
||
import {IAVSDirectory} from "../interfaces/eigenlayer-mvp/IAVSDirectory.sol"; | ||
|
||
contract AVSDirectory is IAVSDirectory { | ||
function registerOperatorToAVS(address operator, IAVSDirectory.SignatureWithSaltAndExpiry memory operatorSignature) | ||
external | ||
{} | ||
|
||
function deregisterOperatorFromAVS(address operator) external {} | ||
} |
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,42 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.25; | ||
|
||
import {IDelegationManager} from "../interfaces/eigenlayer-mvp/IDelegationManager.sol"; | ||
import {IStrategyManager} from "../interfaces/eigenlayer-mvp/IStrategyManager.sol"; | ||
|
||
contract DelegationManager is IDelegationManager { | ||
IStrategyManager internal immutable strategyManager; | ||
|
||
mapping(address operator => uint256 shares) internal operatorShares; | ||
|
||
constructor(IStrategyManager _strategyManager) { | ||
strategyManager = _strategyManager; | ||
} | ||
|
||
modifier onlyStrategyManager() { | ||
require(msg.sender == address(strategyManager), "DelegationManager: Only Strategy Manager allowed"); | ||
_; | ||
} | ||
|
||
/// @dev In this MVP, operator and staker are used interchangeably | ||
function increaseDelegatedShares(address operator, address strategy, uint256 shares) external onlyStrategyManager { | ||
require(strategy == address(0), "DelegationManager: Only ETH strategy supported"); | ||
operatorShares[operator] += shares; | ||
emit OperatorSharesIncreased(operator, operator, strategy, shares); | ||
} | ||
|
||
/// @dev This has been modified from the original EL implementation to accomodate for slashing | ||
function getOperatorShares(address operator, address[] memory strategies) | ||
external | ||
view | ||
returns (uint256[] memory) | ||
{ | ||
uint256[] memory shares = new uint256[](strategies.length); | ||
|
||
for (uint256 i; i < strategies.length; ++i) { | ||
require(strategies[i] == address(0), "DelegationManager: Only ETH strategy supported"); | ||
shares[i] = operatorShares[operator]; | ||
} | ||
return shares; | ||
} | ||
} |
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,28 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.25; | ||
|
||
import {ISlasher} from "../interfaces/eigenlayer-mvp/ISlasher.sol"; | ||
|
||
contract Slasher is ISlasher { | ||
mapping(address operator => mapping(address avs => bool canSlash)) internal slashingAllowed; | ||
mapping(address operator => bool slashed) internal isSlashed; | ||
|
||
modifier onlyIfSlashingAllowed(address operator, address caller) { | ||
require(slashingAllowed[operator][caller], "Slasher: Caller is not allowed to slash the operator"); | ||
_; | ||
} | ||
|
||
function optIntoSlashing(address avs) external { | ||
slashingAllowed[msg.sender][avs] = true; | ||
emit OptedIntoSlashing(msg.sender, avs); | ||
} | ||
|
||
function slashOperator(address operator) external onlyIfSlashingAllowed(operator, msg.sender) { | ||
isSlashed[operator] = true; | ||
emit OperatorSlashed(operator, msg.sender); | ||
} | ||
|
||
function isOperatorSlashed(address operator) external view returns (bool) { | ||
return isSlashed[operator]; | ||
} | ||
} |
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,32 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.25; | ||
|
||
import {IStrategyManager} from "../interfaces/eigenlayer-mvp/IStrategyManager.sol"; | ||
import {IDelegationManager} from "../interfaces/eigenlayer-mvp/IDelegationManager.sol"; | ||
|
||
contract StrategyManager is IStrategyManager { | ||
IDelegationManager internal immutable delegation; | ||
|
||
uint256 internal constant ETH_DEPOSIT = 1 ether; | ||
|
||
constructor(IDelegationManager _delegation) { | ||
delegation = _delegation; | ||
} | ||
|
||
function depositIntoStrategy(address strategy, address token, uint256 amount) | ||
external | ||
payable | ||
returns (uint256 shares) | ||
{ | ||
require(strategy == address(0), "StrategyManager: Only ETH strategy supported"); | ||
require(token == address(0), "StrategyManager: Only ETH deposits supported"); | ||
require(msg.value == ETH_DEPOSIT && amount == ETH_DEPOSIT, "StrategyManager: Invalid ETH deposit"); | ||
|
||
// In the MVP, the shares equal the sent amount as we do not have any form of reward accrual | ||
shares = amount; | ||
|
||
delegation.increaseDelegatedShares(msg.sender, strategy, shares); | ||
|
||
emit Deposit(msg.sender, token, strategy, shares); | ||
} | ||
} |