Skip to content
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

feat: keep3rSponsor #24

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
137 changes: 137 additions & 0 deletions solidity/contracts/periphery/Keep3rSponsor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.19;

import {IKeep3rSponsor, IKeep3rV2} from '../../interfaces/periphery/IKeep3rSponsor.sol';
import {IAutomationVault, IOpenRelay} from '../../interfaces/relays/IOpenRelay.sol';
import {EnumerableSet} from 'openzeppelin/utils/structs/EnumerableSet.sol';

/**
* @title Keep3rSponsor
* @notice This contract managed by Keep3r Network will sponsor some execution in determined jobs
*/

contract Keep3rSponsor is IKeep3rSponsor {
using EnumerableSet for EnumerableSet.AddressSet;

/// @inheritdoc IKeep3rSponsor
IKeep3rV2 public immutable KEEP3R_V2;

/// @inheritdoc IKeep3rSponsor
IOpenRelay public openRelay;

/// @inheritdoc IKeep3rSponsor
address public owner;

/// @inheritdoc IKeep3rSponsor
address public pendingOwner;

/// @inheritdoc IKeep3rSponsor
address public feeRecipient;

/**
* @notice List of sponsored jobs
*/
EnumerableSet.AddressSet internal _sponsoredJobs;

/**
* @param _owner The address of the owner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete the natspec

* @param _feeRecipient The address of the fee recipient
* @param _openRelay The address of the open relay
*/
constructor(address _owner, address _feeRecipient, IOpenRelay _openRelay, IKeep3rV2 _keep3rV2) {
openRelay = _openRelay;
owner = _owner;
feeRecipient = _feeRecipient;
KEEP3R_V2 = _keep3rV2;
}

/// @inheritdoc IKeep3rSponsor
function getSponsoredJobs() external view returns (address[] memory _sponsoredJobsList) {
_sponsoredJobsList = _sponsoredJobs.values();
}

/// @inheritdoc IKeep3rSponsor
function changeOwner(address _pendingOwner) external onlyOwner {
pendingOwner = _pendingOwner;
emit ChangeOwner(_pendingOwner);
}

/// @inheritdoc IKeep3rSponsor
function acceptOwner() external onlyPendingOwner {
pendingOwner = address(0);
owner = msg.sender;
emit AcceptOwner(msg.sender);
}

/// @inheritdoc IKeep3rSponsor
function setFeeRecipient(address _feeRecipient) external onlyOwner {
feeRecipient = _feeRecipient;
emit FeeRecipientSetted(_feeRecipient);
}

/// @inheritdoc IKeep3rSponsor
function setOpenRelay(IOpenRelay _openRelay) external onlyOwner {
openRelay = _openRelay;
emit OpenRelaySetted(_openRelay);
}

/// @inheritdoc IKeep3rSponsor
function addSponsoredJobs(address[] calldata _jobs) public onlyOwner {
for (uint256 _i; _i < _jobs.length;) {
_sponsoredJobs.add(_jobs[_i]);
emit ApproveSponsoredJob(_jobs[_i]);

unchecked {
++_i;
}
}
}

/// @inheritdoc IKeep3rSponsor
function deleteSponsoredJobs(address[] calldata _jobs) public onlyOwner {
for (uint256 _i; _i < _jobs.length;) {
_sponsoredJobs.remove(_jobs[_i]);

emit DeleteSponsoredJob(_jobs[_i]);
unchecked {
++_i;
}
}
}

function exec(IAutomationVault _automationVault, IAutomationVault.ExecData[] calldata _execData) external {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add inheritdoc

for (uint256 _i; _i < _execData.length;) {
if (!_sponsoredJobs.contains(_execData[_i].job)) revert Keep3rSponsor_JobNotSponsored();

unchecked {
++_i;
}
}

// The first call to `isKeeper` ensures the caller is a valid keeper
bool _isKeeper = KEEP3R_V2.isKeeper(msg.sender);
if (!_isKeeper) revert Keep3rSponsor_NotKeeper();

openRelay.exec(_automationVault, _execData, feeRecipient);

KEEP3R_V2.worked(msg.sender);
}

/**
* @notice Checks that the caller is the owner
*/
modifier onlyOwner() {
address _owner = owner;
if (msg.sender != _owner) revert Keep3rSponsor_OnlyOwner();
_;
}

/**
* @notice Checks that the caller is the pending owner
*/
modifier onlyPendingOwner() {
address _pendingOwner = pendingOwner;
if (msg.sender != _pendingOwner) revert Keep3rSponsor_OnlyPendingOwner();
_;
}
}
164 changes: 164 additions & 0 deletions solidity/interfaces/periphery/IKeep3rSponsor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.19;

import {IAutomationVault, IOpenRelay} from '../../interfaces/relays/IOpenRelay.sol';
import {IKeep3rV2} from '../../interfaces/external/IKeep3rV2.sol';

interface IKeep3rSponsor {
/*///////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/**
* @notice Emitted when a job is executed
* @param _job The address of the job
*/
event JobExecuted(address _job);

/**
* @notice Emitted when the owner is proposed to change
* @param _pendingOwner The address that is being proposed
*/
event ChangeOwner(address indexed _pendingOwner);

/**
* @notice Emitted when the owner is accepted
* @param _owner The address of the new owner
*/
event AcceptOwner(address indexed _owner);

/**
* @notice Emitted when the fee recipient is setted
* @param _feeRecipient The address of the new fee recipient
*/
event FeeRecipientSetted(address indexed _feeRecipient);

/**
* @notice Emitted when the open relay is setted
* @param _openRelay The address of the new open relay
*/
event OpenRelaySetted(IOpenRelay indexed _openRelay);

/**
* @notice Emitted when a sponsored job is approved
* @param _job The address of the sponsored job
*/
event ApproveSponsoredJob(address indexed _job);

/**
* @notice Emitted when a sponsored job is deleted
* @param _job job The address of the sponsored job
*/
event DeleteSponsoredJob(address indexed _job);

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

/**
* @notice Thrown when the job executed is not in the list of sponsored jobs
*/
error Keep3rSponsor_JobNotSponsored();

/**
* @notice Thrown when the caller is not the owner
*/
error Keep3rSponsor_OnlyOwner();

/**
* @notice Thrown when the caller is not the pending owner
*/
error Keep3rSponsor_OnlyPendingOwner();

/**
* @notice Thrown when the caller is not a keeper
*/
error Keep3rSponsor_NotKeeper();

/*///////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice Returns the keep3rV2 contract
* @return _keep3rV2 The address of the keep3rV2 contract
*/
function KEEP3R_V2() external view returns (IKeep3rV2 _keep3rV2);

/**
* @notice Returns the open relay
* @return _openRelay The address of the open relay
*/
function openRelay() external view returns (IOpenRelay _openRelay);

/**
* @notice Returns the owner address
* @return _owner The address of the owner
*/
function owner() external view returns (address _owner);

/**
* @notice Returns the pending owner address
* @return _pendingOwner The address of the pending owner
*/
function pendingOwner() external view returns (address _pendingOwner);

/**
* @notice Returns the fee recipient address
* @return _feeRecipient The address of the fee recipient
*/
function feeRecipient() external view returns (address _feeRecipient);

/**
* @notice Returns the list of the sponsored jobs
* @return _sponsoredJobsList The list of the sponsored jobs
*/
function getSponsoredJobs() external returns (address[] memory _sponsoredJobsList);

/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice Propose a new owner for the contract
* @dev The new owner will need to accept the ownership before it is transferred
* @param _pendingOwner The address of the new owner
*/
function changeOwner(address _pendingOwner) external;

/**
* @notice Accepts the ownership of the contract
*/
function acceptOwner() external;

/**
* @notice Sets the fee recipient who will receive the payment of the open relay
* @param _feeRecipient The address of the fee recipient
*/
function setFeeRecipient(address _feeRecipient) external;

/**
* @notice Sets the open relay
* @param _openRelay The address of the open relay
*/
function setOpenRelay(IOpenRelay _openRelay) external;

/**
* @notice Adds a job to the sponsored list
* @param _jobs List of jobs to add
*/
function addSponsoredJobs(address[] calldata _jobs) external;

/**
* @notice Removes a job from the sponsored list
* @param _jobs List of jobs to remove
*/
function deleteSponsoredJobs(address[] calldata _jobs) external;

/**
* @notice Execute an open relay which will execute the jobs and will manage the payment to the fee data receivers
* @param _automationVault The automation vault that will be executed
* @param _execData The array of exec data
*/
function exec(IAutomationVault _automationVault, IAutomationVault.ExecData[] calldata _execData) external;
}
2 changes: 1 addition & 1 deletion solidity/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract contract Deploy is Script {
IKeep3rRelay public keep3rRelay;
IKeep3rBondedRelay public keep3rBondedRelay;

// Metadata
// Periphery contracts
IXKeeperMetadata public xKeeperMetadata;

// External contracts
Expand Down
Loading
Loading