Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Aug 9, 2024
1 parent 5f8fc37 commit d6982d9
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 287 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core-contracts": "0.0.0-438de1c5",
"@defi-wonderland/prophet-core": "0.0.0-172a7bcf",
"@defi-wonderland/prophet-modules-contracts": "0.0.0-1197c328"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
forge-std/=node_modules/forge-std/src
halmos-cheatcodes=node_modules/halmos-cheatcodes
@defi-wonderland/prophet-core-contracts/=node_modules/@defi-wonderland/prophet-core-contracts
@defi-wonderland/prophet-core/=node_modules/@defi-wonderland/prophet-core
@defi-wonderland/prophet-modules-contracts/=node_modules/@defi-wonderland/prophet-modules-contracts

contracts/=src/contracts
Expand Down
102 changes: 43 additions & 59 deletions src/contracts/EBORequestCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@
pragma solidity 0.8.26;

import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {Arbitrable} from 'contracts/Arbitrable.sol';
import {IEBORequestCreator, IOracle} from 'interfaces/IEBORequestCreator.sol';

contract EBORequestCreator is IEBORequestCreator {
contract EBORequestCreator is IEBORequestCreator, Arbitrable {
using EnumerableSet for EnumerableSet.Bytes32Set;

/// @inheritdoc IEBORequestCreator
IOracle public oracle;

/// @inheritdoc IEBORequestCreator
RequestData public requestData;

/// @inheritdoc IEBORequestCreator
address public arbitrator;

/// @inheritdoc IEBORequestCreator
address public pendingArbitrator;

/// @inheritdoc IEBORequestCreator
uint256 public reward;
IOracle.Request public requestData;

/// @inheritdoc IEBORequestCreator
mapping(string _chainId => mapping(uint256 _epoch => bytes32 _requestId)) public requestIdPerChainAndEpoch;
Expand All @@ -30,33 +23,15 @@ contract EBORequestCreator is IEBORequestCreator {
*/
EnumerableSet.Bytes32Set internal _chainIdsAllowed;

constructor(IOracle _oracle, address _arbitrator) {
constructor(IOracle _oracle, address _arbitrator, address _council) Arbitrable(_arbitrator, _council) {

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

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_arbitrator" is unused

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

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_council" is unused
oracle = _oracle;
arbitrator = _arbitrator;
reward = 0;
}

/// @inheritdoc IEBORequestCreator
function setPendingArbitrator(address _pendingArbitrator) external onlyArbitrator {
pendingArbitrator = _pendingArbitrator;

emit PendingArbitratorSetted(_pendingArbitrator);
}

/// @inheritdoc IEBORequestCreator
function acceptPendingArbitrator() external onlyPendingArbitrator {
address _oldArbitrator = arbitrator;
arbitrator = pendingArbitrator;
pendingArbitrator = address(0);

emit ArbitratorSetted(_oldArbitrator, arbitrator);
}

/// @inheritdoc IEBORequestCreator
function createRequests(uint256 _epoch, string[] calldata _chainIds) external {
bytes32 _encodedChainId;

RequestData memory _requestData = requestData;
IOracle.Request memory _requestData = requestData;

for (uint256 _i; _i < _chainIds.length; _i++) {
_encodedChainId = _encodeChainId(_chainIds[_i]);
Expand Down Expand Up @@ -111,45 +86,54 @@ contract EBORequestCreator is IEBORequestCreator {
}

/// @inheritdoc IEBORequestCreator
function setReward(uint256 _reward) external onlyArbitrator {
uint256 _oldReward = reward;
reward = _reward;
emit RewardSet(_oldReward, _reward);
function setRequestModuleData(address _requestModule, bytes calldata _requestModuleData) external onlyArbitrator {
requestData.requestModule = _requestModule;
requestData.requestModuleData = _requestModuleData;

emit RequestModuleDataSet(_requestModule, _requestModuleData);
}

/// @inheritdoc IEBORequestCreator
function setRequestData(RequestData calldata _requestData) external onlyArbitrator {
requestData = _requestData;
function setResponseModuleData(address _responseModule, bytes calldata _responseModuleData) external onlyArbitrator {
requestData.responseModule = _responseModule;
requestData.responseModuleData = _responseModuleData;

emit RequestDataSet(_requestData);
emit ResponseModuleDataSet(_responseModule, _responseModuleData);
}

/**
* @notice Encodes the chain id
* @dev The chain id is hashed to have a enumerable set to avoid duplicates
*/
function _encodeChainId(string calldata _chainId) internal pure returns (bytes32 _encodedChainId) {
_encodedChainId = keccak256(abi.encodePacked(_chainId));
/// TODO: Change module data to the specific interface when we have
/// @inheritdoc IEBORequestCreator
function setDisputeModuleData(address _disputeModule, bytes calldata _disputeModuleData) external onlyArbitrator {
requestData.disputeModule = _disputeModule;
requestData.disputeModuleData = _disputeModuleData;

emit DisputeModuleDataSet(_disputeModule, _disputeModuleData);
}

/**
* @notice Checks if the sender is the arbitrator
*/
modifier onlyArbitrator() {
if (msg.sender != arbitrator) {
revert EBORequestCreator_OnlyArbitrator();
}
_;
/// @inheritdoc IEBORequestCreator
function setResolutionModuleData(
address _resolutionModule,
bytes calldata _resolutionModuleData
) external onlyArbitrator {
requestData.resolutionModule = _resolutionModule;
requestData.resolutionModuleData = _resolutionModuleData;

emit ResolutionModuleDataSet(_resolutionModule, _resolutionModuleData);
}

/// @inheritdoc IEBORequestCreator
function setFinalityModuleData(address _finalityModule, bytes calldata _finalityModuleData) external onlyArbitrator {
requestData.finalityModule = _finalityModule;
requestData.finalityModuleData = _finalityModuleData;

emit FinalityModuleDataSet(_finalityModule, _finalityModuleData);
}

/**
* @notice Checks if the sender is the pending arbitrator
* @notice Encodes the chain id
* @dev The chain id is hashed to have a enumerable set to avoid duplicates
*/
modifier onlyPendingArbitrator() {
if (msg.sender != pendingArbitrator) {
revert EBORequestCreator_OnlyPendingArbitrator();
}

_;
function _encodeChainId(string calldata _chainId) internal pure returns (bytes32 _encodedChainId) {
_encodedChainId = keccak256(abi.encodePacked(_chainId));
}
}
138 changes: 58 additions & 80 deletions src/interfaces/IEBORequestCreator.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol';
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';

interface IEBORequestCreator {
/*///////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/**
* @notice Emitted when the pending arbitrator is set
* @param _pendingArbitrator The address of the pending arbitrator
*/
event PendingArbitratorSetted(address _pendingArbitrator);

/**
* @notice Emitted when the abitrator is set
* @param _oldArbitrator The old abitrator address
* @param _newArbitrator The new abitrator address
*/
event ArbitratorSetted(address _oldArbitrator, address _newArbitrator);

/**
* @notice Emitted when a request is created
* @param _requestId The id of the request
Expand All @@ -42,31 +29,43 @@ interface IEBORequestCreator {
event ChainRemoved(string indexed _chainId);

/**
* @notice Emitted when the reward is set
* @param _oldReward The old reward value
* @param _newReward The new reward value
* @notice Emitted when the request data module is set
* @param _requestModule The request module
* @param _requestModuleData The request module data
*/
event RewardSet(uint256 _oldReward, uint256 _newReward);
event RequestModuleDataSet(address indexed _requestModule, bytes _requestModuleData);

/**
* @notice Emitted when a request data is set
* @param _requestData The request data
* @notice Emitted when the response data module is set
* @param _responseModule The response module
* @param _responseModuleData The response module data
*/
event RequestDataSet(RequestData _requestData);
event ResponseModuleDataSet(address indexed _responseModule, bytes _responseModuleData);

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/**
* @notice Emitted when the dispute data module is set
* @param _disputeModule The dispute module
* @param _disputeModuleData The dispute module data
*/
event DisputeModuleDataSet(address indexed _disputeModule, bytes _disputeModuleData);

/**
* @notice Thrown when the caller is not the arbitrator
* @notice Emitted when the resolution data module is set
* @param _resolutionModule The resolution module
* @param _resolutionModuleData The resolution module data
*/
error EBORequestCreator_OnlyArbitrator();
event ResolutionModuleDataSet(address indexed _resolutionModule, bytes _resolutionModuleData);

/**
* @notice Thrown when the caller is not the pending arbitrator
* @notice Emitted when the finality data module is set
* @param _finalityModule The finality module
* @param _finalityModuleData The finality module data
*/
error EBORequestCreator_OnlyPendingArbitrator();
event FinalityModuleDataSet(address indexed _finalityModule, bytes _finalityModuleData);

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

/**
* @notice hrown when the chain is already added
Expand All @@ -78,23 +77,6 @@ interface IEBORequestCreator {
*/
error EBORequestCreator_ChainNotAdded();

/*///////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////*/

struct RequestData {
address requestModule;
address responseModule;
address disputeModule;
address resolutionModule;
address finalityModule;
bytes requestModuleData;
bytes responseModuleData;
bytes disputeModuleData;
bytes resolutionModuleData;
bytes finalityModuleData;
}

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/
Expand All @@ -111,6 +93,8 @@ interface IEBORequestCreator {
external
view
returns (
uint96 _nonce,
address _requester,
address _requestModule,
address _responseModule,
address _disputeModule,
Expand All @@ -123,24 +107,6 @@ interface IEBORequestCreator {
bytes memory _finalityModuleData
);

/**
* @notice The arbitrator of the contract
* @return _arbitrator The arbitrator
*/
function arbitrator() external view returns (address _arbitrator);

/**
* @notice The pending arbitrator of the contract
* @return _pendingArbitrator The pending owner
*/
function pendingArbitrator() external view returns (address _pendingArbitrator);

/**
* @notice The reward paid for each chain updated
* @return _reward The reward
*/
function reward() external view returns (uint256 _reward);

/**
* @notice The request id per chain and epoch
* @param _chainId The chain id
Expand All @@ -156,17 +122,6 @@ interface IEBORequestCreator {
LOGIC
//////////////////////////////////////////////////////////////*/

/**
* @notice Set the pending arbitrator
* @param _pendingArbitrator The address of the pending arbitrator
*/
function setPendingArbitrator(address _pendingArbitrator) external;

/**
* @notice Accept the pending arbitrator
*/
function acceptPendingArbitrator() external;

/**
* @notice Create requests
* @param _epoch The epoch of the request
Expand All @@ -187,14 +142,37 @@ interface IEBORequestCreator {
function removeChain(string calldata _chainId) external;

/**
* @notice Set the reward paid for each chain updated
* @param _reward The reward to set
* @notice Set the request data module
* @param _requestModule The request module
* @param _requestModuleData The request module data
*/
function setRequestModuleData(address _requestModule, bytes calldata _requestModuleData) external;

/**
* @notice Set the response data module
* @param _responseModule The response module
* @param _responseModuleData The response module data
*/
function setResponseModuleData(address _responseModule, bytes calldata _responseModuleData) external;

/**
* @notice Set the dispute data module
* @param _disputeModule The dispute module
* @param _disputeModuleData The dispute module data
*/
function setDisputeModuleData(address _disputeModule, bytes calldata _disputeModuleData) external;

/**
* @notice Set the resolution data module
* @param _resolutionModule The resolution module
* @param _resolutionModuleData The resolution module data
*/
function setReward(uint256 _reward) external;
function setResolutionModuleData(address _resolutionModule, bytes calldata _resolutionModuleData) external;

/**
* @notice Set the request data
* @param _requestData The request data to set
* @notice Set the finality data module
* @param _finalityModule The finality module
* @param _finalityModuleData The finality module data
*/
function setRequestData(RequestData calldata _requestData) external;
function setFinalityModuleData(address _finalityModule, bytes calldata _finalityModuleData) external;
}
7 changes: 5 additions & 2 deletions test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ pragma solidity 0.8.26;
import {Test} from 'forge-std/Test.sol';
import {IERC20} from 'forge-std/interfaces/IERC20.sol';

Check warning on line 5 in test/integration/IntegrationBase.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IERC20" is unused

import {Oracle} from '@defi-wonderland/prophet-core-contracts/solidity/contracts/Oracle.sol';
import {Oracle} from '@defi-wonderland/prophet-core/solidity/contracts/Oracle.sol';
import {EBORequestCreator, IEBORequestCreator, IOracle} from 'contracts/EBORequestCreator.sol';

contract IntegrationBase is Test {
uint256 internal constant _FORK_BLOCK = 18_920_905;

address internal _arbitrator = makeAddr('arbitrator');
address internal _council = makeAddr('council');
address internal _owner = makeAddr('owner');
address internal _user = makeAddr('user');

Expand All @@ -22,7 +23,9 @@ contract IntegrationBase is Test {
vm.startPrank(_owner);

_oracle = new Oracle();
_eboRequestCreator = new EBORequestCreator(_oracle, _arbitrator);

// TODO: Replace with the implementation
_eboRequestCreator = new EBORequestCreator(_oracle, _arbitrator, _council);

vm.stopPrank();
}
Expand Down
Loading

0 comments on commit d6982d9

Please sign in to comment.