diff --git a/solidity/contracts/modules/ArbitratorModule.sol b/solidity/contracts/modules/ArbitratorModule.sol index 057a072d..bb4ba6c5 100644 --- a/solidity/contracts/modules/ArbitratorModule.sol +++ b/solidity/contracts/modules/ArbitratorModule.sol @@ -19,7 +19,7 @@ contract ArbitratorModule is Module, IArbitratorModule { } // get the arbitrator address for a dispute (the same arbitrator is fixed for a given request) - function decodeRequestData(bytes32 _requestId) external view returns (address _arbitrator) { + function decodeRequestData(bytes32 _requestId) public view returns (address _arbitrator) { // Get the arbitrator address associated with the request id _arbitrator = abi.decode(requestData[_requestId], (address)); } diff --git a/solidity/contracts/modules/BondEscalationModule.sol b/solidity/contracts/modules/BondEscalationModule.sol index bef53300..07e19fac 100644 --- a/solidity/contracts/modules/BondEscalationModule.sol +++ b/solidity/contracts/modules/BondEscalationModule.sol @@ -39,7 +39,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { if (_dispute.requestId == bytes32(0)) revert BondEscalationModule_DisputeDoesNotExist(); - (,,,, uint256 _bondEscalationDeadline, uint256 _tyingBuffer) = _decodeRequestData(requestData[_dispute.requestId]); + (,,,, uint256 _bondEscalationDeadline, uint256 _tyingBuffer) = decodeRequestData(_dispute.requestId); // If the bond escalation deadline is not over, no dispute can be escalated if (block.timestamp <= _bondEscalationDeadline) revert BondEscalationModule_BondEscalationNotOver(); @@ -93,7 +93,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { uint256 _bondSize, , uint256 _bondEscalationDeadline, - ) = _decodeRequestData(requestData[_requestId]); + ) = decodeRequestData(_requestId); // if the bond escalation is not over and there's an active dispute going through it, revert if (block.timestamp <= _bondEscalationDeadline && bondEscalationStatus[_requestId] == BondEscalationStatus.Active) { @@ -123,7 +123,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { function updateDisputeStatus(bytes32 _disputeId, IOracle.Dispute memory _dispute) external onlyOracle { (IBondEscalationAccounting _accountingExtension, IERC20 _bondToken, uint256 _bondSize,,,) = - _decodeRequestData(requestData[_dispute.requestId]); + decodeRequestData(_dispute.requestId); bool _won = _dispute.status == IOracle.DisputeStatus.Won; @@ -198,7 +198,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { uint256 _maxNumberOfEscalations, uint256 _bondEscalationDeadline, uint256 _tyingBuffer - ) = _decodeRequestData(requestData[_dispute.requestId]); + ) = decodeRequestData(_dispute.requestId); if (_maxNumberOfEscalations == 0 || _bondSize == 0) revert BondEscalationModule_ZeroValue(); @@ -262,7 +262,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { uint256 _maxNumberOfEscalations, uint256 _bondEscalationDeadline, uint256 _tyingBuffer - ) = _decodeRequestData(requestData[_dispute.requestId]); + ) = decodeRequestData(_dispute.requestId); if (_maxNumberOfEscalations == 0 || _bondSize == 0) revert BondEscalationModule_ZeroValue(); @@ -313,7 +313,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { , uint256 _bondEscalationDeadline, uint256 _tyingBuffer - ) = _decodeRequestData(requestData[_requestId]); + ) = decodeRequestData(_requestId); if (block.timestamp <= _bondEscalationDeadline + _tyingBuffer) { revert BondEscalationModule_BondEscalationNotOver(); @@ -370,7 +370,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { * party to tie if at the end of the initial deadline the pledgess weren't tied. */ function decodeRequestData(bytes32 _requestId) - external + public view returns ( IBondEscalationAccounting _accountingExtension, @@ -382,7 +382,7 @@ contract BondEscalationModule is Module, IBondEscalationModule { ) { (_accountingExtension, _bondToken, _bondSize, _maxNumberOfEscalations, _bondEscalationDeadline, _tyingBuffer) = - _decodeRequestData(requestData[_requestId]); + abi.decode(requestData[_requestId], (IBondEscalationAccounting, IERC20, uint256, uint256, uint256, uint256)); } /** @@ -430,24 +430,4 @@ contract BondEscalationModule is Module, IBondEscalationModule { } } } - - //////////////////////////////////////////////////////////////////// - // Pure Functions - //////////////////////////////////////////////////////////////////// - - function _decodeRequestData(bytes memory _data) - internal - pure - returns ( - IBondEscalationAccounting _accountingExtension, - IERC20 _bondToken, - uint256 _bondSize, - uint256 _maxNumberOfEscalations, - uint256 _bondEscalationDeadline, - uint256 _tyingBuffer - ) - { - (_accountingExtension, _bondToken, _bondSize, _maxNumberOfEscalations, _bondEscalationDeadline, _tyingBuffer) = - abi.decode(_data, (IBondEscalationAccounting, IERC20, uint256, uint256, uint256, uint256)); - } } diff --git a/solidity/contracts/modules/BondEscalationResolutionModule.sol b/solidity/contracts/modules/BondEscalationResolutionModule.sol index 956a11cd..6f8dff5a 100644 --- a/solidity/contracts/modules/BondEscalationResolutionModule.sol +++ b/solidity/contracts/modules/BondEscalationResolutionModule.sol @@ -40,23 +40,7 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu ) { (_accountingExtension, _token, _percentageDiff, _pledgeThreshold, _timeUntilDeadline, _timeToBreakInequality) = - _decodeRequestData(requestData[_requestId]); - } - - function _decodeRequestData(bytes memory _data) - internal - pure - returns ( - IBondEscalationAccounting _accountingExtension, - IERC20 _token, - uint256 _percentageDiff, - uint256 _pledgeThreshold, - uint256 _timeUntilDeadline, - uint256 _timeToBreakInequality - ) - { - (_accountingExtension, _token, _percentageDiff, _pledgeThreshold, _timeUntilDeadline, _timeToBreakInequality) = - abi.decode(_data, (IBondEscalationAccounting, IERC20, uint256, uint256, uint256, uint256)); + abi.decode(requestData[_requestId], (IBondEscalationAccounting, IERC20, uint256, uint256, uint256, uint256)); } function startResolution(bytes32 _disputeId) external onlyOracle { diff --git a/solidity/contracts/modules/BondedDisputeModule.sol b/solidity/contracts/modules/BondedDisputeModule.sol index 56c3c114..8f8825a0 100644 --- a/solidity/contracts/modules/BondedDisputeModule.sol +++ b/solidity/contracts/modules/BondedDisputeModule.sol @@ -17,11 +17,12 @@ contract BondedDisputeModule is Module, IBondedDisputeModule { } function decodeRequestData(bytes32 _requestId) - external + public view returns (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize) { - (_accountingExtension, _bondToken, _bondSize) = _decodeRequestData(requestData[_requestId]); + (_accountingExtension, _bondToken, _bondSize) = + abi.decode(requestData[_requestId], (IAccountingExtension, IERC20, uint256)); } function disputeEscalated(bytes32 _disputeId) external onlyOracle {} @@ -41,15 +42,14 @@ contract BondedDisputeModule is Module, IBondedDisputeModule { createdAt: block.timestamp }); - (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize) = - _decodeRequestData(requestData[_requestId]); + (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize) = decodeRequestData(_requestId); _accountingExtension.bond(_disputer, _requestId, _bondToken, _bondSize); } // TODO: This doesn't handle the cases of unconclusive statuses function updateDisputeStatus(bytes32, /* _disputeId */ IOracle.Dispute memory _dispute) external onlyOracle { (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize) = - _decodeRequestData(requestData[_dispute.requestId]); + decodeRequestData(_dispute.requestId); bool _won = _dispute.status == IOracle.DisputeStatus.Won; _accountingExtension.pay( @@ -64,12 +64,4 @@ contract BondedDisputeModule is Module, IBondedDisputeModule { _won ? _dispute.disputer : _dispute.proposer, _dispute.requestId, _bondToken, _bondSize ); } - - function _decodeRequestData(bytes memory _data) - internal - pure - returns (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize) - { - (_accountingExtension, _bondToken, _bondSize) = abi.decode(_data, (IAccountingExtension, IERC20, uint256)); - } } diff --git a/solidity/contracts/modules/BondedResponseModule.sol b/solidity/contracts/modules/BondedResponseModule.sol index ca743f29..e85e398f 100644 --- a/solidity/contracts/modules/BondedResponseModule.sol +++ b/solidity/contracts/modules/BondedResponseModule.sol @@ -13,20 +13,12 @@ contract BondedResponseModule is Module, IBondedResponseModule { constructor(IOracle _oracle) Module(_oracle) {} function decodeRequestData(bytes32 _requestId) - external + public view returns (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize, uint256 _deadline) - { - (_accountingExtension, _bondToken, _bondSize, _deadline) = _decodeRequestData(requestData[_requestId]); - } - - function _decodeRequestData(bytes memory _data) - internal - pure - returns (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize, uint256 _deadline) { (_accountingExtension, _bondToken, _bondSize, _deadline) = - abi.decode(_data, (IAccountingExtension, IERC20, uint256, uint256)); + abi.decode(requestData[_requestId], (IAccountingExtension, IERC20, uint256, uint256)); } function propose( @@ -35,7 +27,7 @@ contract BondedResponseModule is Module, IBondedResponseModule { bytes calldata _responseData ) external onlyOracle returns (IOracle.Response memory _response) { (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize, uint256 _deadline) = - _decodeRequestData(requestData[_requestId]); + decodeRequestData(_requestId); // Cannot propose after the deadline if (block.timestamp >= _deadline) revert BondedResponseModule_TooLateToPropose(); @@ -66,7 +58,7 @@ contract BondedResponseModule is Module, IBondedResponseModule { function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize, uint256 _deadline) = - _decodeRequestData(requestData[_requestId]); + decodeRequestData(_requestId); if (block.timestamp < _deadline) revert BondedResponseModule_TooEarlyToFinalize(); diff --git a/solidity/contracts/modules/CallbackModule.sol b/solidity/contracts/modules/CallbackModule.sol index 45ce020c..0d6fa6f8 100644 --- a/solidity/contracts/modules/CallbackModule.sol +++ b/solidity/contracts/modules/CallbackModule.sol @@ -9,7 +9,7 @@ import {IModule, Module} from '../Module.sol'; contract CallbackModule is Module, ICallbackModule { constructor(IOracle _oracle) Module(_oracle) {} - function decodeRequestData(bytes32 _requestId) external view returns (address _target, bytes memory _data) { + function decodeRequestData(bytes32 _requestId) public view returns (address _target, bytes memory _data) { (_target, _data) = abi.decode(requestData[_requestId], (address, bytes)); } diff --git a/solidity/contracts/modules/ContractCallRequestModule.sol b/solidity/contracts/modules/ContractCallRequestModule.sol index e7e9b5c6..1b666f29 100644 --- a/solidity/contracts/modules/ContractCallRequestModule.sol +++ b/solidity/contracts/modules/ContractCallRequestModule.sol @@ -12,7 +12,7 @@ contract ContractCallRequestModule is Module, IContractCallRequestModule { constructor(IOracle _oracle) Module(_oracle) {} function decodeRequestData(bytes32 _requestId) - external + public view returns ( address _target, @@ -24,28 +24,12 @@ contract ContractCallRequestModule is Module, IContractCallRequestModule { ) { (_target, _functionSelector, _data, _accountingExtension, _paymentToken, _paymentAmount) = - _decodeRequestData(requestData[_requestId]); - } - - function _decodeRequestData(bytes memory _encodedData) - internal - pure - returns ( - address _target, - bytes4 _functionSelector, - bytes memory _data, - IAccountingExtension _accountingExtension, - IERC20 _paymentToken, - uint256 _paymentAmount - ) - { - (_target, _functionSelector, _data, _accountingExtension, _paymentToken, _paymentAmount) = - abi.decode(_encodedData, (address, bytes4, bytes, IAccountingExtension, IERC20, uint256)); + abi.decode(requestData[_requestId], (address, bytes4, bytes, IAccountingExtension, IERC20, uint256)); } function _afterSetupRequest(bytes32 _requestId, bytes calldata _data) internal override { (,,, IAccountingExtension _accountingExtension, IERC20 _paymentToken, uint256 _paymentAmount) = - _decodeRequestData(_data); + decodeRequestData(_requestId); IOracle.Request memory _request = ORACLE.getRequest(_requestId); _accountingExtension.bond(_request.requester, _requestId, _paymentToken, _paymentAmount); } @@ -54,7 +38,7 @@ contract ContractCallRequestModule is Module, IContractCallRequestModule { IOracle.Request memory _request = ORACLE.getRequest(_requestId); IOracle.Response memory _response = ORACLE.getFinalizedResponse(_requestId); (,,, IAccountingExtension _accountingExtension, IERC20 _paymentToken, uint256 _paymentAmount) = - _decodeRequestData(requestData[_requestId]); + decodeRequestData(_requestId); if (_response.createdAt != 0) { _accountingExtension.pay(_requestId, _request.requester, _response.proposer, _paymentToken, _paymentAmount); } else { diff --git a/solidity/contracts/modules/HttpRequestModule.sol b/solidity/contracts/modules/HttpRequestModule.sol index 4fb173e2..81e71818 100644 --- a/solidity/contracts/modules/HttpRequestModule.sol +++ b/solidity/contracts/modules/HttpRequestModule.sol @@ -12,7 +12,7 @@ contract HttpRequestModule is Module, IHttpRequestModule { constructor(IOracle _oracle) Module(_oracle) {} function decodeRequestData(bytes32 _requestId) - external + public view returns ( string memory _url, @@ -24,37 +24,21 @@ contract HttpRequestModule is Module, IHttpRequestModule { ) { (_url, _method, _body, _accountingExtension, _paymentToken, _paymentAmount) = - _decodeRequestData(requestData[_requestId]); + abi.decode(requestData[_requestId], (string, HttpMethod, string, IAccountingExtension, IERC20, uint256)); } function _afterSetupRequest(bytes32 _requestId, bytes calldata _data) internal override { (,,, IAccountingExtension _accountingExtension, IERC20 _paymentToken, uint256 _paymentAmount) = - _decodeRequestData(_data); + decodeRequestData(_requestId); IOracle.Request memory _request = ORACLE.getRequest(_requestId); _accountingExtension.bond(_request.requester, _requestId, _paymentToken, _paymentAmount); } - function _decodeRequestData(bytes memory _data) - internal - pure - returns ( - string memory _url, - HttpMethod _method, - string memory _body, - IAccountingExtension _accountingExtension, - IERC20 _paymentToken, - uint256 _paymentAmount - ) - { - (_url, _method, _body, _accountingExtension, _paymentToken, _paymentAmount) = - abi.decode(_data, (string, HttpMethod, string, IAccountingExtension, IERC20, uint256)); - } - function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { IOracle.Request memory _request = ORACLE.getRequest(_requestId); IOracle.Response memory _response = ORACLE.getFinalizedResponse(_requestId); (,,, IAccountingExtension _accountingExtension, IERC20 _paymentToken, uint256 _paymentAmount) = - _decodeRequestData(requestData[_requestId]); + decodeRequestData(_requestId); if (_response.createdAt != 0) { _accountingExtension.pay(_requestId, _request.requester, _response.proposer, _paymentToken, _paymentAmount); } else { diff --git a/solidity/contracts/modules/MultipleCallbacksModule.sol b/solidity/contracts/modules/MultipleCallbacksModule.sol index a0646e5d..cfe8a748 100644 --- a/solidity/contracts/modules/MultipleCallbacksModule.sol +++ b/solidity/contracts/modules/MultipleCallbacksModule.sol @@ -9,11 +9,7 @@ import {IModule, Module} from '../Module.sol'; contract MultipleCallbacksModule is Module, ICallbackModule { constructor(IOracle _oracle) Module(_oracle) {} - function decodeRequestData(bytes32 _requestId) - external - view - returns (address[] memory _targets, bytes[] memory _datas) - { + function decodeRequestData(bytes32 _requestId) public view returns (address[] memory _targets, bytes[] memory _datas) { (_targets, _datas) = abi.decode(requestData[_requestId], (address[], bytes[])); }