Skip to content
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: EBOFinalityModule #2

Merged
merged 16 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core-contracts": "0.0.0-438de1c5",
"@defi-wonderland/prophet-modules-contracts": "0.0.0-1197c328"
"@defi-wonderland/prophet-core": "0.0.0-2e39539b",
"@defi-wonderland/prophet-modules": "0.0.0-e52f8cce"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
Expand Down
4 changes: 2 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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-modules-contracts/=node_modules/@defi-wonderland/prophet-modules-contracts
@defi-wonderland/prophet-core/=node_modules/@defi-wonderland/prophet-core
@defi-wonderland/prophet-modules/=node_modules/@defi-wonderland/prophet-modules

contracts/=src/contracts
interfaces/=src/interfaces
86 changes: 86 additions & 0 deletions src/contracts/EBOFinalityModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

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

import {Arbitrable} from 'contracts/Arbitrable.sol';
import {IEBOFinalityModule} from 'interfaces/IEBOFinalityModule.sol';

/**
* @title EBOFinalityModule
* @notice Module allowing users to index data into the subgraph
* as a result of a request being finalized
*/
contract EBOFinalityModule is Module, Arbitrable, IEBOFinalityModule {
/// @inheritdoc IEBOFinalityModule
address public eboRequestCreator;

/**
* @notice Constructor
* @param _oracle The address of the Oracle
* @param _eboRequestCreator The address of the EBORequestCreator
* @param _arbitrator The address of The Graph's Arbitrator
* @param _council The address of The Graph's Council
*/
constructor(
IOracle _oracle,

Check warning on line 28 in src/contracts/EBOFinalityModule.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_oracle" is unused
address _eboRequestCreator,
address _arbitrator,

Check warning on line 30 in src/contracts/EBOFinalityModule.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_arbitrator" is unused
address _council

Check warning on line 31 in src/contracts/EBOFinalityModule.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_council" is unused
) Module(_oracle) Arbitrable(_arbitrator, _council) {
_setEBORequestCreator(_eboRequestCreator);
}

/// @inheritdoc IEBOFinalityModule
function finalizeRequest(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
0xShaito marked this conversation as resolved.
Show resolved Hide resolved
address _finalizer
) external override(Module, IEBOFinalityModule) onlyOracle {
if (_request.requester != eboRequestCreator) revert EBOFinalityModule_InvalidRequester();

if (_response.requestId != 0) {
_validateResponse(_request, _response);

// TODO: Redeclare the `Response` struct
// emit NewEpoch(_response.epoch, _response.chainId, _response.block);
}

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IEBOFinalityModule
function amendEpoch(
uint256 _epoch,
uint256[] calldata _chainIds,
uint256[] calldata _blockNumbers
) external onlyArbitrator {
uint256 _length = _chainIds.length;
if (_length != _blockNumbers.length) revert EBOFinalityModule_LengthMismatch();

for (uint256 _i; _i < _length; ++_i) {
emit AmendEpoch(_epoch, _chainIds[_i], _blockNumbers[_i]);
}
}

/// @inheritdoc IEBOFinalityModule
function setEBORequestCreator(address _eboRequestCreator) external onlyArbitrator {
_setEBORequestCreator(_eboRequestCreator);
}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
_moduleName = 'EBOFinalityModule';
}

/**
* @notice Sets the address of the EBORequestCreator
* @param _eboRequestCreator The address of the EBORequestCreator
*/
function _setEBORequestCreator(address _eboRequestCreator) private {
ashitakah marked this conversation as resolved.
Show resolved Hide resolved
eboRequestCreator = _eboRequestCreator;
emit SetEBORequestCreator(_eboRequestCreator);
}
}
97 changes: 97 additions & 0 deletions src/interfaces/IEBOFinalityModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

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

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

/**
* @title EBOFinalityModule
* @notice Module allowing users to index data into the subgraph
* as a result of a request being finalized
*/
interface IEBOFinalityModule is IFinalityModule, IArbitrable {
/*///////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/**
* @notice Emitted when the block number has been resolved for a particular epoch-chainId pair
* @param _epoch The new epoch
* @param _chainId The chain ID
* @param _blockNumber The block number for the epoch-chainId pair
*/
event NewEpoch(uint256 _epoch, uint256 indexed _chainId, uint256 _blockNumber);

/**
* @notice Emitted when a block number is amended
* @param _epoch The epoch to amend
* @param _chainId The chain ID to amend
* @param _blockNumber The amended block number
*/
event AmendEpoch(uint256 _epoch, uint256 indexed _chainId, uint256 _blockNumber);

/**
* @notice Emitted when the EBORequestCreator is set
* @param _eboRequestCreator The address of the EBORequestCreator
*/
event SetEBORequestCreator(address _eboRequestCreator);

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

/**
* @notice Thrown when the requester is not the EBORequestCreator
*/
error EBOFinalityModule_InvalidRequester();

/**
* @notice Thrown when the lengths of chain IDs and block numbers do not match
*/
error EBOFinalityModule_LengthMismatch();

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice Returns the address of the EBORequestCreator
* @return _eboRequestCreator The address of the EBORequestCreator
*/
function eboRequestCreator() external view returns (address _eboRequestCreator);

/*///////////////////////////////////////////////////////////////
LOGIC
//////////////////////////////////////////////////////////////*/

/**
* @notice Finalizes the request by publishing the response
* @dev Callable only by the Oracle
* @param _request The request being finalized
* @param _response The final response
* @param _finalizer The address that initiated the finalization
*/
function finalizeRequest(

Check warning on line 76 in src/interfaces/IEBOFinalityModule.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 63)
0xShaito marked this conversation as resolved.
Show resolved Hide resolved
IOracle.Request calldata _request,
IOracle.Response calldata _response,
address _finalizer
) external;

/**
* @notice Allows to amend data in case of an error or an emergency
* @dev Callable only by The Graph's Arbitrator
* @param _epoch The epoch to amend
* @param _chainIds The chain IDs to amend
* @param _blockNumbers The amended block numbers
*/
function amendEpoch(uint256 _epoch, uint256[] calldata _chainIds, uint256[] calldata _blockNumbers) external;

/**
* @notice Sets the address of the EBORequestCreator
* @dev Callable only by The Graph's Arbitrator
* @param _eboRequestCreator The address of the EBORequestCreator
*/
function setEBORequestCreator(address _eboRequestCreator) external;
}
Loading
Loading