-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
209 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,34 @@ | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity ^0.8.19; | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
// // solhint-disable-next-line no-unused-import | ||
// import {Module, IModule} from '@defi-wonderland/prophet-core-contracts/solidity/contracts/Module.sol'; | ||
// import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
// solhint-disable-next-line no-unused-import | ||
import {Module, IModule} from '@defi-wonderland/prophet-core-contracts/solidity/contracts/Module.sol'; | ||
import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
|
||
// import {ICallbackModule} from '../../../interfaces/modules/finality/ICallbackModule.sol'; | ||
import {ICallbackModule} from '../../../interfaces/modules/finality/ICallbackModule.sol'; | ||
|
||
// contract CallbackModule is Module, ICallbackModule { | ||
// constructor(IOracle _oracle) Module(_oracle) {} | ||
contract CallbackModule is Module, ICallbackModule { | ||
constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
// /// @inheritdoc IModule | ||
// function moduleName() public pure returns (string memory _moduleName) { | ||
// _moduleName = 'CallbackModule'; | ||
// } | ||
/// @inheritdoc IModule | ||
function moduleName() public pure returns (string memory _moduleName) { | ||
_moduleName = 'CallbackModule'; | ||
} | ||
|
||
// /// @inheritdoc ICallbackModule | ||
// function decodeRequestData(bytes32 _requestId) public view returns (RequestParameters memory _params) { | ||
// _params = abi.decode(requestData[_requestId], (RequestParameters)); | ||
// } | ||
/// @inheritdoc ICallbackModule | ||
function decodeRequestData(bytes calldata _data) public pure returns (RequestParameters memory _params) { | ||
_params = abi.decode(_data, (RequestParameters)); | ||
} | ||
|
||
// /** | ||
// * @notice Checks if the target address has code (i.e. is a contract) | ||
// * @param _data The encoded data for the request | ||
// */ | ||
// function _afterSetupRequest(bytes32, bytes calldata _data) internal view override { | ||
// RequestParameters memory _params = abi.decode(_data, (RequestParameters)); | ||
// if (_params.target.code.length == 0) revert CallbackModule_TargetHasNoCode(); | ||
// } | ||
|
||
// /// @inheritdoc ICallbackModule | ||
// function finalizeRequest( | ||
// bytes32 _requestId, | ||
// address _finalizer | ||
// ) external override(Module, ICallbackModule) onlyOracle { | ||
// RequestParameters memory _params = decodeRequestData(_requestId); | ||
// _params.target.call(_params.data); | ||
// emit Callback(_requestId, _params.target, _params.data); | ||
// emit RequestFinalized(_requestId, _finalizer); | ||
// } | ||
// } | ||
/// @inheritdoc ICallbackModule | ||
function finalizeRequest( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
address _finalizer | ||
) external override(Module, ICallbackModule) 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); | ||
} | ||
} |
128 changes: 63 additions & 65 deletions
128
solidity/interfaces/modules/finality/ICallbackModule.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,63 @@ | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity ^0.8.19; | ||
|
||
// import {IFinalityModule} from | ||
// '@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/finality/IFinalityModule.sol'; | ||
|
||
// /** | ||
// * @title CallbackModule | ||
// * @notice Module allowing users to call a function on a contract | ||
// * as a result of a request being finalized. | ||
// */ | ||
// interface ICallbackModule 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); | ||
|
||
// /*/////////////////////////////////////////////////////////////// | ||
// ERRORS | ||
// //////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @notice Thrown when the target address has no code (i.e. is not a contract) | ||
// */ | ||
// error CallbackModule_TargetHasNoCode(); | ||
|
||
// /*/////////////////////////////////////////////////////////////// | ||
// 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 | ||
// //////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @notice Returns the decoded data for a request | ||
// * @param _requestId The ID of the request | ||
// * @return _params The struct containing the parameters for the request | ||
// */ | ||
// function decodeRequestData(bytes32 _requestId) 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 | ||
// * @param _requestId The id of the request | ||
// */ | ||
// function finalizeRequest(bytes32 _requestId, address) external; | ||
// } | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
import {IFinalityModule} from | ||
'@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/finality/IFinalityModule.sol'; | ||
|
||
/** | ||
* @title CallbackModule | ||
* @notice Module allowing users to call a function on a contract | ||
* as a result of a request being finalized. | ||
*/ | ||
interface ICallbackModule 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); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
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 | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @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 | ||
* @param _request The request being finalized | ||
* @param _response The final response | ||
* @param _finalizer The address that initiated the finalization | ||
*/ | ||
function finalizeRequest( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
address _finalizer | ||
) external; | ||
} |
Oops, something went wrong.