Skip to content

Commit

Permalink
Merge pull request #18 from NethermindEth/anshu/eigenlayer-mvp
Browse files Browse the repository at this point in the history
Add Eigenlayer MVP
  • Loading branch information
AnshuJalan authored Jun 15, 2024
2 parents 9c186c7 + c6aed95 commit 1d3d0b6
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
12 changes: 12 additions & 0 deletions SmartContracts/src/eigenlayer-mvp/AVSDirectory.sol
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 {}
}
42 changes: 42 additions & 0 deletions SmartContracts/src/eigenlayer-mvp/DelegationManager.sol
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;
}
}
28 changes: 28 additions & 0 deletions SmartContracts/src/eigenlayer-mvp/Slasher.sol
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];
}
}
32 changes: 32 additions & 0 deletions SmartContracts/src/eigenlayer-mvp/StrategyManager.sol
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);
}
}

0 comments on commit 1d3d0b6

Please sign in to comment.