Skip to content

Commit

Permalink
feat: owner
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Jul 31, 2024
1 parent 302e1d6 commit 3e795ce
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 419 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ multiline_func_header = 'params_first'
sort_imports = true

[profile.default]
solc_version = '0.8.23'
solc_version = '0.8.26'
libs = ['node_modules', 'lib']
optimizer_runs = 10_000

Expand Down
33 changes: 0 additions & 33 deletions script/Deploy.sol

This file was deleted.

116 changes: 116 additions & 0 deletions src/contracts/EBORequestCreator.sol
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() {

Check warning on line 103 in src/contracts/EBORequestCreator.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, modifier definition can not go after internal pure function (line 99)
if (msg.sender != owner) {
revert EBORequestCreator_OnlyOwner();
}
_;
}

modifier onlyPendingOwner() {
if (msg.sender != pendingOwner) {
revert EBORequestCreator_OnlyPendingOwner();
}
_;
}
}
59 changes: 0 additions & 59 deletions src/contracts/Greeter.sol

This file was deleted.

153 changes: 153 additions & 0 deletions src/interfaces/IEBORequestCreator.sol
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;

Check warning on line 106 in src/interfaces/IEBORequestCreator.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, external function can not go after external view function (line 96)

/**
* @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);
}
Loading

0 comments on commit 3e795ce

Please sign in to comment.