-
Notifications
You must be signed in to change notification settings - Fork 5
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
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8a061c4
feat: keep3rsponsor.sol
2b9c91f
fix: ashi comments addressed
0e3e712
fix: final fixes
e5017f2
fix: final fixes
3bf80dc
feat: keep3r sponsor
ashitakah 98f7f32
feat: few tests
ashitakah b2f21de
fix: conflicts
ashitakah 98891ac
feat: tests
ashitakah 1ac9fb4
Merge branch 'dev' of github.com:defi-wonderland/keep3r-framework-cor…
ashitakah de5bdbb
feat: keep3r as param
ashitakah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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 | ||
* @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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
_; | ||
} | ||
} |
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,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; | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complete the natspec