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

perf: optimize CallbackModule #5

Merged
merged 13 commits into from
Nov 11, 2023
5 changes: 2 additions & 3 deletions docs/src/content/modules/finality/callback_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The Callback Module is a finality module that allows users to call a function on

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `finalizeRequest(bytes32 _requestId, address)`: Executing the callback call on the target.
- `decodeRequestData`: Returns the decoded data for a request.
- `finalizeRequest`: Executing the callback call on the target.

### Request Parameters

Expand All @@ -25,4 +25,3 @@ As any finality module, the `CallbackModule` implements the `finalizeRequest` fu
## 4. Gotchas

- The success of the callback call in `finalizeRequest` is purposely not checked, specifying a function or parameters that lead to a revert will not stop the request from being finalized.
- The target must be a contract.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core-contracts": "0.0.0-d05a00d0",
"@defi-wonderland/prophet-core-contracts": "0.0.0-a1d2cc55",
"@defi-wonderland/solidity-utils": "0.0.0-3e9c8e8b",
"@openzeppelin/contracts": "^4.9.3",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
Expand Down
64 changes: 28 additions & 36 deletions solidity/contracts/modules/finality/CallbackModule.sol
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);
}
}
Loading