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 1 commit
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
35 changes: 1 addition & 34 deletions src/contracts/EBOFinalityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {IEBOFinalityModule} from 'interfaces/IEBOFinalityModule.sol';

/**
* @title EBOFinalityModule
* @notice Module allowing users to call a function on a contract
* @notice Module allowing users to index data into the subgraph
* as a result of a request being finalized
*/
contract EBOFinalityModule is Module, IEBOFinalityModule {
Expand Down Expand Up @@ -39,21 +39,12 @@ contract EBOFinalityModule is Module, IEBOFinalityModule {
_moduleName = 'EBOFinalityModule';
}

/// @inheritdoc IEBOFinalityModule
function decodeRequestData(bytes calldata _data) public pure returns (RequestParameters memory _params) {
_params = abi.decode(_data, (RequestParameters));
}

/// @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 {
RequestParameters memory _params = decodeRequestData(_request.finalityModuleData);

_params.target.call(_params.data);
emit Callback(_response.requestId, _params.target, _params.data);
emit RequestFinalized(_response.requestId, _response, _finalizer);
// emit NewEpoch(_response.epoch, _response.chainId, _response.block);
}
Expand All @@ -71,28 +62,4 @@ contract EBOFinalityModule is Module, IEBOFinalityModule {
emit AmendEpoch(_epoch, _chainIds[i], _blockNumbers[i]);
}
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
view
override(Module, IModule)
returns (bool _valid)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will EBOFinalityModule override validateParameters()?

{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = _targetHasBytecode(_params.target) && _params.data.length != 0;
}

/**
* @notice Checks if a target address has bytecode
* @param _target The address to check
* @return _hasBytecode Whether the target has bytecode or not
*/
function _targetHasBytecode(address _target) private view returns (bool _hasBytecode) {
uint256 _size;
assembly {
_size := extcodesize(_target)
}
_hasBytecode = _size > 0;
}
}
34 changes: 2 additions & 32 deletions src/interfaces/IEBOFinalityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ import {IFinalityModule} from

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

/**
* @notice A callback has been executed
* @param _requestId The id of the request being finalized
* @param _target The target address for the callback
* @param _data The calldata forwarded to the target
*/
event Callback(bytes32 indexed _requestId, address indexed _target, bytes _data);

/**
* @notice Emitted when the block number has been resolved for a particular epoch-chainId pair
* @param _epoch The new epoch
Expand Down Expand Up @@ -53,20 +45,6 @@ interface IEBOFinalityModule is IFinalityModule {
*/
error EBOFinalityModule_LengthMismatch();

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

/**
* @notice Parameters of the request as stored in the module
* @param target The target address for the callback
* @param data The calldata forwarded to the target
*/
struct RequestParameters {
address target;
bytes data;
}

/*///////////////////////////////////////////////////////////////
LOGIC
//////////////////////////////////////////////////////////////*/
Expand All @@ -78,15 +56,7 @@ interface IEBOFinalityModule is IFinalityModule {
function ARBITRATOR() external view returns (address _arbitrator);

/**
* @notice Returns the decoded data for a request
* @param _data The encoded request parameters
* @return _params The struct containing the parameters for the request
*/
function decodeRequestData(bytes calldata _data) external view returns (RequestParameters memory _params);

/**
* @notice Finalizes the request by executing the callback call on the target
* @dev The success of the callback call is purposely not checked
* @notice Finalizes the request by publishing the response
* @param _request The request being finalized
* @param _response The final response
* @param _finalizer The address that initiated the finalization
Expand Down