Skip to content

Commit

Permalink
feat: epoch manager and epoch control
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Aug 9, 2024
1 parent 5f8fc37 commit dd52cec
Show file tree
Hide file tree
Showing 11 changed files with 593 additions and 504 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
4 changes: 2 additions & 2 deletions src/contracts/Arbitrable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IArbitrable} from 'interfaces/IArbitrable.sol';

Expand Down
117 changes: 62 additions & 55 deletions src/contracts/EBORequestCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
pragma solidity 0.8.26;

import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';
import {IEBORequestCreator, IOracle} from 'interfaces/IEBORequestCreator.sol';

contract EBORequestCreator is IEBORequestCreator {
import {Arbitrable} from 'contracts/Arbitrable.sol';
import {IEBORequestCreator, IEpochManager, IOracle} from 'interfaces/IEBORequestCreator.sol';

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;
IEpochManager public epochManager;

/// @inheritdoc IEBORequestCreator
address public pendingArbitrator;
IOracle.Request public requestData;

/// @inheritdoc IEBORequestCreator
uint256 public reward;
uint256 public startEpoch;

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

constructor(IOracle _oracle, address _arbitrator) {
constructor(
IOracle _oracle,
IEpochManager _epochManager,
address _arbitrator,

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

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_arbitrator" is unused
address _council

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

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_council" is unused
) Arbitrable(_arbitrator, _council) {
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);
epochManager = _epochManager;

emit ArbitratorSetted(_oldArbitrator, arbitrator);
startEpoch = epochManager.currentEpoch();
}

/// @inheritdoc IEBORequestCreator
function createRequests(uint256 _epoch, string[] calldata _chainIds) external {
if (_epoch > epochManager.currentEpoch() || startEpoch > _epoch) revert EBORequestCreator_EpochNotValid();

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 +102,61 @@ 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);
}

/// @inheritdoc IEBORequestCreator
function setEpochManager(IEpochManager _epochManager) external onlyArbitrator {
epochManager = _epochManager;

emit EpochManagerSet(_epochManager);
}

/**
* @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));
}
}
6 changes: 3 additions & 3 deletions src/interfaces/IArbitrable.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;
/**
* @title Arbitrable
* @notice Makes a contract subject to arbitration by The Graph
*/

interface IArbitrable {
/*///////////////////////////////////////////////////////////////
EVENTS
Expand Down
Loading

0 comments on commit dd52cec

Please sign in to comment.