generated from defi-wonderland/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
443 additions
and
419 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
This file was deleted.
Oops, something went wrong.
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,116 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.26; | ||
|
||
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol'; | ||
import {IEBORequestCreator} from 'interfaces/IEBORequestCreator.sol'; | ||
|
||
contract EBORequestCreator is IEBORequestCreator { | ||
using EnumerableSet for EnumerableSet.Bytes32Set; | ||
|
||
// /// @inheritdoc IEBORequestCreator | ||
// IOracle public oracle; | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
address public owner; | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
address public pendingOwner; | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
uint256 public reward; | ||
|
||
/** | ||
* @notice The list of chain ids | ||
*/ | ||
EnumerableSet.Bytes32Set internal _chainIds; | ||
|
||
constructor(address _owner) { | ||
// oracle = _oracle; | ||
|
||
owner = _owner; | ||
reward = 0; | ||
} | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
function setPendingOwner(address _pendingOwner) external onlyOwner { | ||
pendingOwner = _pendingOwner; | ||
|
||
emit PendingOwnerSetted(_pendingOwner); | ||
} | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
function acceptPendingOwner() external onlyPendingOwner { | ||
address _oldOwner = owner; | ||
owner = pendingOwner; | ||
pendingOwner = address(0); | ||
|
||
emit OwnerSetted(_oldOwner, owner); | ||
} | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
function createRequest( | ||
address _requester, | ||
address _target, | ||
bytes calldata _data, | ||
uint256 _value, | ||
uint256 _nonce | ||
) external returns (bytes32 _requestId) { | ||
// emit RequestCreated(_requestId, _requester, _target, _data, _value, _nonce); | ||
} | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
function addChain(string calldata _chainId) external onlyOwner { | ||
if (!_chainIds.add(_chaindIdToBytes32(_chainId))) { | ||
revert EBORequestCreator_ChainAlreadyAdded(); | ||
} | ||
emit ChainAdded(_chainId); | ||
} | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
function removeChain(string calldata _chainId) external onlyOwner { | ||
if (!_chainIds.remove(_chaindIdToBytes32(_chainId))) { | ||
revert EBORequestCreator_ChainNotAdded(); | ||
} | ||
emit ChainRemoved(_chainId); | ||
} | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
function setReward(uint256 _reward) external onlyOwner { | ||
uint256 _oldReward = reward; | ||
reward = _reward; | ||
emit RewardSet(_oldReward, _reward); | ||
} | ||
|
||
/// @inheritdoc IEBORequestCreator | ||
function getChainIds() external view returns (string[] memory _chainIdsValues) { | ||
bytes32[] memory _chainIdsBytes = _chainIds.values(); | ||
|
||
for (uint256 _i; _i < _chainIdsBytes.length; _i++) { | ||
_chainIdsValues[_i] = _chaindIdToString(_chainIdsBytes[_i]); | ||
} | ||
} | ||
|
||
function _chaindIdToBytes32(string memory _chainId) internal pure returns (bytes32 _convertedChainId) { | ||
assembly { | ||
_convertedChainId := mload(add(_chainId, 32)) | ||
} | ||
} | ||
|
||
function _chaindIdToString(bytes32 _chainId) internal pure returns (string memory _convertedChainId) { | ||
_convertedChainId = string(abi.encodePacked(_chainId)); | ||
} | ||
|
||
modifier onlyOwner() { | ||
if (msg.sender != owner) { | ||
revert EBORequestCreator_OnlyOwner(); | ||
} | ||
_; | ||
} | ||
|
||
modifier onlyPendingOwner() { | ||
if (msg.sender != pendingOwner) { | ||
revert EBORequestCreator_OnlyPendingOwner(); | ||
} | ||
_; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,153 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.26; | ||
|
||
// import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
|
||
interface IEBORequestCreator { | ||
/*/////////////////////////////////////////////////////////////// | ||
EVENTS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice Emitted when the pending owner is set | ||
* @param _pendingOwner The address of the pending owner | ||
*/ | ||
event PendingOwnerSetted(address _pendingOwner); | ||
|
||
/** | ||
* @notice Emitted when the owner is set | ||
* @param _oldOwner The old owner address | ||
* @param _newOwner The new owner address | ||
*/ | ||
event OwnerSetted(address _oldOwner, address _newOwner); | ||
|
||
/** | ||
* @notice Emitted when a request is created | ||
* @param _epoch The epoch of the request | ||
* @param _chainId The chain id of the request | ||
*/ | ||
event RequestCreated(uint256 _epoch, uint256 _chainId); | ||
|
||
/** | ||
* @notice Emitted when a chain is added | ||
* @param _chainId The chain id added | ||
*/ | ||
event ChainAdded(string _chainId); | ||
|
||
/** | ||
* @notice Emitted when a chain is removed | ||
* @param _chainId The chain id removed | ||
*/ | ||
event ChainRemoved(string _chainId); | ||
|
||
/** | ||
* @notice Emitted when the reward is set | ||
* @param _oldReward The old reward value | ||
* @param _newReward The new reward value | ||
*/ | ||
event RewardSet(uint256 _oldReward, uint256 _newReward); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
ERRORS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice Thrown when the caller is not the owner | ||
*/ | ||
error EBORequestCreator_OnlyOwner(); | ||
|
||
/** | ||
* @notice Thrown when the caller is not the pending owner | ||
*/ | ||
error EBORequestCreator_OnlyPendingOwner(); | ||
|
||
/** | ||
* @notice hrown when the chain is already added | ||
*/ | ||
error EBORequestCreator_ChainAlreadyAdded(); | ||
|
||
/** | ||
* @notice Thrown when the chain is not added | ||
*/ | ||
error EBORequestCreator_ChainNotAdded(); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
VARIABLES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @notice The oracle contract | ||
// */ | ||
// function oracle() external view returns (IOracle _oracle); | ||
|
||
/** | ||
* @notice The owner of the contract | ||
*/ | ||
function owner() external view returns (address _owner); | ||
|
||
/** | ||
* @notice The pending owner of the contract | ||
*/ | ||
function pendingOwner() external view returns (address _pendingOwner); | ||
|
||
/** | ||
* @notice The reward paid for each chain updated | ||
*/ | ||
function reward() external view returns (uint256 _reward); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice Set the pending owner | ||
* @param _pendingOwner The address of the pending owner | ||
*/ | ||
function setPendingOwner(address _pendingOwner) external; | ||
|
||
/** | ||
* @notice Accept the pending owner | ||
*/ | ||
function acceptPendingOwner() external; | ||
|
||
/** | ||
* @notice Create a request | ||
* @param _requester The address of the requester | ||
* @param _target The address of the target | ||
* @param _data The data of the request | ||
* @param _value The value of the request | ||
* @param _nonce The nonce of the request | ||
* @return _requestId The id of the request | ||
*/ | ||
function createRequest( | ||
address _requester, | ||
address _target, | ||
bytes calldata _data, | ||
uint256 _value, | ||
uint256 _nonce | ||
) external returns (bytes32 _requestId); | ||
|
||
/** | ||
* @notice Add a chain to the allowed chains which can be updated | ||
* @param _chainId The chain id to add | ||
*/ | ||
function addChain(string calldata _chainId) external; | ||
|
||
/** | ||
* @notice Remove a chain from the allowed chains which can be updated | ||
* @param _chainId The chain id to remove | ||
*/ | ||
function removeChain(string calldata _chainId) external; | ||
|
||
/** | ||
* @notice Set the reward paid for each chain updated | ||
* @param _reward The reward to set | ||
*/ | ||
function setReward(uint256 _reward) external; | ||
|
||
/** | ||
* @notice Get the chain ids | ||
* @return _chainIdsValues The chain ids | ||
*/ | ||
function getChainIds() external view returns (string[] memory _chainIdsValues); | ||
} |
Oops, something went wrong.