-
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.
perf: optimize
ContractCallRequestModule
- Loading branch information
Showing
4 changed files
with
311 additions
and
409 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
112 changes: 55 additions & 57 deletions
112
solidity/contracts/modules/request/ContractCallRequestModule.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,64 +1,62 @@ | ||
// // 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 {IContractCallRequestModule} from '../../../interfaces/modules/request/IContractCallRequestModule.sol'; | ||
import {IContractCallRequestModule} from '../../../interfaces/modules/request/IContractCallRequestModule.sol'; | ||
|
||
// contract ContractCallRequestModule is Module, IContractCallRequestModule { | ||
// constructor(IOracle _oracle) Module(_oracle) {} | ||
contract ContractCallRequestModule is Module, IContractCallRequestModule { | ||
constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
// /// @inheritdoc IModule | ||
// function moduleName() public pure returns (string memory _moduleName) { | ||
// _moduleName = 'ContractCallRequestModule'; | ||
// } | ||
/// @inheritdoc IModule | ||
function moduleName() public pure returns (string memory _moduleName) { | ||
_moduleName = 'ContractCallRequestModule'; | ||
} | ||
|
||
// /// @inheritdoc IContractCallRequestModule | ||
// function decodeRequestData(bytes32 _requestId) public view returns (RequestParameters memory _params) { | ||
// _params = abi.decode(requestData[_requestId], (RequestParameters)); | ||
// } | ||
/// @inheritdoc IContractCallRequestModule | ||
function decodeRequestData(bytes calldata _data) public pure returns (RequestParameters memory _params) { | ||
_params = abi.decode(_data, (RequestParameters)); | ||
} | ||
|
||
// /** | ||
// * @notice Bonds the requester's funds through the accounting extension | ||
// * @param _requestId The id of the request being set up | ||
// */ | ||
// function _afterSetupRequest(bytes32 _requestId, bytes calldata) internal override { | ||
// RequestParameters memory _params = decodeRequestData(_requestId); | ||
// IOracle.Request memory _request = ORACLE.getRequest(_requestId); | ||
// _params.accountingExtension.bond({ | ||
// _bonder: _request.requester, | ||
// _requestId: _requestId, | ||
// _token: _params.paymentToken, | ||
// _amount: _params.paymentAmount | ||
// }); | ||
// } | ||
/// @inheritdoc IContractCallRequestModule | ||
function createRequest(bytes32 _requestId, bytes calldata _data, address _requester) external { | ||
RequestParameters memory _params = decodeRequestData(_data); | ||
|
||
// /// @inheritdoc IContractCallRequestModule | ||
// function finalizeRequest( | ||
// bytes32 _requestId, | ||
// address _finalizer | ||
// ) external override(IContractCallRequestModule, Module) onlyOracle { | ||
// IOracle.Request memory _request = ORACLE.getRequest(_requestId); | ||
// IOracle.Response memory _response = ORACLE.getFinalizedResponse(_requestId); | ||
// RequestParameters memory _params = decodeRequestData(_requestId); | ||
// if (_response.createdAt != 0) { | ||
// _params.accountingExtension.pay({ | ||
// _requestId: _requestId, | ||
// _payer: _request.requester, | ||
// _receiver: _response.proposer, | ||
// _token: _params.paymentToken, | ||
// _amount: _params.paymentAmount | ||
// }); | ||
// } else { | ||
// _params.accountingExtension.release({ | ||
// _bonder: _request.requester, | ||
// _requestId: _requestId, | ||
// _token: _params.paymentToken, | ||
// _amount: _params.paymentAmount | ||
// }); | ||
// } | ||
// emit RequestFinalized(_requestId, _finalizer); | ||
// } | ||
// } | ||
_params.accountingExtension.bond({ | ||
_bonder: _requester, | ||
_requestId: _requestId, | ||
_token: _params.paymentToken, | ||
_amount: _params.paymentAmount | ||
}); | ||
} | ||
|
||
/// @inheritdoc IContractCallRequestModule | ||
function finalizeRequest( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
address _finalizer | ||
) external override(IContractCallRequestModule, Module) onlyOracle { | ||
RequestParameters memory _params = decodeRequestData(_request.requestModuleData); | ||
|
||
if (ORACLE.createdAt(_getId(_response)) != 0) { | ||
_params.accountingExtension.pay({ | ||
_requestId: _response.requestId, | ||
_payer: _request.requester, | ||
_receiver: _response.proposer, | ||
_token: _params.paymentToken, | ||
_amount: _params.paymentAmount | ||
}); | ||
} else { | ||
_params.accountingExtension.release({ | ||
_bonder: _request.requester, | ||
_requestId: _response.requestId, | ||
_token: _params.paymentToken, | ||
_amount: _params.paymentAmount | ||
}); | ||
} | ||
|
||
emit RequestFinalized(_response.requestId, _response, _finalizer); | ||
} | ||
} |
91 changes: 51 additions & 40 deletions
91
solidity/interfaces/modules/request/IContractCallRequestModule.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,45 +1,56 @@ | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity ^0.8.19; | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
// import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
// import {IRequestModule} from | ||
// '@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/request/IRequestModule.sol'; | ||
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
import {IRequestModule} from | ||
'@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/request/IRequestModule.sol'; | ||
|
||
// import {IAccountingExtension} from '../../../interfaces/extensions/IAccountingExtension.sol'; | ||
import {IAccountingExtension} from '../../../interfaces/extensions/IAccountingExtension.sol'; | ||
|
||
// /** | ||
// * @title ContractCallRequestModule | ||
// * @notice Request module for making contract calls | ||
// */ | ||
// interface IContractCallRequestModule is IRequestModule { | ||
// /** | ||
// * @notice Parameters of the request as stored in the module | ||
// * @param target The address of the contract to do the call on | ||
// * @param functionSelector The selector of the function to call | ||
// * @param data The encoded arguments of the function to call (optional) | ||
// * @param accountingExtension The accounting extension to bond and release funds | ||
// * @param paymentToken The token in which the response proposer will be paid | ||
// * @param paymentAmount The amount of `paymentToken` to pay to the response proposer | ||
// */ | ||
// struct RequestParameters { | ||
// address target; | ||
// bytes4 functionSelector; | ||
// bytes data; | ||
// IAccountingExtension accountingExtension; | ||
// IERC20 paymentToken; | ||
// uint256 paymentAmount; | ||
// } | ||
/** | ||
* @title ContractCallRequestModule | ||
* @notice Request module for making contract calls | ||
*/ | ||
interface IContractCallRequestModule is IRequestModule { | ||
/** | ||
* @notice Parameters of the request as stored in the module | ||
* @param target The address of the contract to do the call on | ||
* @param functionSelector The selector of the function to call | ||
* @param data The encoded arguments of the function to call (optional) | ||
* @param accountingExtension The accounting extension to bond and release funds | ||
* @param paymentToken The token in which the response proposer will be paid | ||
* @param paymentAmount The amount of `paymentToken` to pay to the response proposer | ||
*/ | ||
struct RequestParameters { | ||
address target; | ||
bytes4 functionSelector; | ||
bytes data; | ||
IAccountingExtension accountingExtension; | ||
IERC20 paymentToken; | ||
uint256 paymentAmount; | ||
} | ||
|
||
// /** | ||
// * @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 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 a request by paying the response proposer | ||
// * @param _requestId The id of the request | ||
// */ | ||
// function finalizeRequest(bytes32 _requestId, address) external; | ||
// } | ||
/// @inheritdoc IRequestModule | ||
function createRequest(bytes32 _requestId, bytes calldata _data, address _requester) external; | ||
|
||
/** | ||
* @notice Finalizes the request by paying the proposer for the response or releasing the requester's bond if no response was submitted | ||
* | ||
* @param _request The request that is being finalized | ||
* @param _response The final response | ||
* @param _finalizer The user who triggered the finalization | ||
*/ | ||
function finalizeRequest( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
address _finalizer | ||
) external; | ||
} |
Oops, something went wrong.