Skip to content

feat: reward initiator for ECDSAServiceManagerBase #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions src/unaudited/ECDSAServiceManagerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
pragma solidity ^0.8.12;

import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";

import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";

import {IServiceManager} from "../interfaces/IServiceManager.sol";
import {IServiceManagerUI} from "../interfaces/IServiceManagerUI.sol";
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
Expand All @@ -15,10 +13,7 @@ import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces
import {Quorum} from "../interfaces/IECDSAStakeRegistryEventsAndErrors.sol";
import {ECDSAStakeRegistry} from "../unaudited/ECDSAStakeRegistry.sol";

abstract contract ECDSAServiceManagerBase is
IServiceManager,
OwnableUpgradeable
{
abstract contract ECDSAServiceManagerBase is IServiceManager, OwnableUpgradeable {
/// @notice Address of the stake registry contract, which manages registration and stake recording.
address public immutable stakeRegistry;

Expand All @@ -30,6 +25,10 @@ abstract contract ECDSAServiceManagerBase is

/// @notice Address of the delegation manager contract, which manages staker delegations to operators.
address internal immutable delegationManager;

/// @notice Address of the rewards initiator, which is allowed to create AVS rewards submissions.
address public rewardsInitiator;

/**
* @dev Ensures that the function is only callable by the `stakeRegistry` contract.
* This is used to restrict certain registration and deregistration functionality to the `stakeRegistry`
Expand All @@ -42,6 +41,17 @@ abstract contract ECDSAServiceManagerBase is
_;
}

/**
* @dev Ensures that the function is only callable by the `rewardsInitiator`.
*/
modifier onlyRewardsInitiator() {
require(
msg.sender == rewardsInitiator,
"ECDSAServiceManagerBase.onlyRewardsInitiator: caller is not the rewards initiator"
);
_;
}

/**
* @dev Constructor for ECDSAServiceManagerBase, initializing immutable contract addresses and disabling initializers.
* @param _avsDirectory The address of the AVS directory contract, managing AVS-related data for registered operators.
Expand All @@ -65,11 +75,14 @@ abstract contract ECDSAServiceManagerBase is
/**
* @dev Initializes the base service manager by transferring ownership to the initial owner.
* @param initialOwner The address to which the ownership of the contract will be transferred.
* @param _rewardsInitiator The address which is allowed to create AVS rewards submissions.
*/
function __ServiceManagerBase_init(
address initialOwner
address initialOwner,
address _rewardsInitiator
) internal virtual onlyInitializing {
_transferOwnership(initialOwner);
_setRewardsInitiator(_rewardsInitiator);
}

/// @inheritdoc IServiceManagerUI
Expand All @@ -82,7 +95,7 @@ abstract contract ECDSAServiceManagerBase is
/// @inheritdoc IServiceManager
function createAVSRewardsSubmission(
IRewardsCoordinator.RewardsSubmission[] calldata rewardsSubmissions
) external virtual onlyOwner {
) external virtual onlyRewardsInitiator {
_createAVSRewardsSubmission(rewardsSubmissions);
}

Expand Down Expand Up @@ -168,9 +181,11 @@ abstract contract ECDSAServiceManagerBase is
address(this),
rewardsSubmissions[i].amount
);
uint256 allowance =
rewardsSubmissions[i].token.allowance(address(this), rewardsCoordinator);
rewardsSubmissions[i].token.approve(
rewardsCoordinator,
rewardsSubmissions[i].amount
rewardsSubmissions[i].amount + allowance
);
}

Expand Down Expand Up @@ -234,6 +249,20 @@ abstract contract ECDSAServiceManagerBase is
return restakedStrategies;
}

/**
* @notice Sets the rewards initiator address.
* @param newRewardsInitiator The new rewards initiator address.
* @dev Only callable by the owner.
*/
function setRewardsInitiator(address newRewardsInitiator) external onlyOwner {
_setRewardsInitiator(newRewardsInitiator);
}

function _setRewardsInitiator(address newRewardsInitiator) internal {
emit RewardsInitiatorUpdated(rewardsInitiator, newRewardsInitiator);
rewardsInitiator = newRewardsInitiator;
}

// storage gap for upgradeability
// slither-disable-next-line shadowing-state
uint256[50] private __GAP;
Expand Down