diff --git a/solidity/contracts/Module.sol b/solidity/contracts/Module.sol index fd02fbff..d89c91ee 100644 --- a/solidity/contracts/Module.sol +++ b/solidity/contracts/Module.sol @@ -24,6 +24,6 @@ abstract contract Module is IModule { _afterSetupRequest(_requestId, _data); } - function finalizeRequest(bytes32 _requestId) external virtual onlyOracle {} + function finalizeRequest(bytes32 _requestId, address _finalizer) external virtual onlyOracle {} function _afterSetupRequest(bytes32 _requestId, bytes calldata _data) internal virtual {} } diff --git a/solidity/contracts/Oracle.sol b/solidity/contracts/Oracle.sol index 01eccaf7..3ad56ab7 100644 --- a/solidity/contracts/Oracle.sol +++ b/solidity/contracts/Oracle.sol @@ -236,16 +236,16 @@ contract Oracle is IOracle { _finalizedResponses[_requestId] = _response; if (address(_request.finalityModule) != address(0)) { - _request.finalityModule.finalizeRequest(_requestId); + _request.finalityModule.finalizeRequest(_requestId, msg.sender); } if (address(_request.resolutionModule) != address(0)) { - _request.resolutionModule.finalizeRequest(_requestId); + _request.resolutionModule.finalizeRequest(_requestId, msg.sender); } - _request.disputeModule.finalizeRequest(_requestId); - _request.responseModule.finalizeRequest(_requestId); - _request.requestModule.finalizeRequest(_requestId); + _request.disputeModule.finalizeRequest(_requestId, msg.sender); + _request.responseModule.finalizeRequest(_requestId, msg.sender); + _request.requestModule.finalizeRequest(_requestId, msg.sender); emit Oracle_RequestFinalized(msg.sender, _requestId); } diff --git a/solidity/contracts/modules/BondedResponseModule.sol b/solidity/contracts/modules/BondedResponseModule.sol index e85e398f..c0e7ef15 100644 --- a/solidity/contracts/modules/BondedResponseModule.sol +++ b/solidity/contracts/modules/BondedResponseModule.sol @@ -56,7 +56,7 @@ contract BondedResponseModule is Module, IBondedResponseModule { _accountingExtension.bond(_response.proposer, _requestId, _bondToken, _bondSize); } - function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { + function finalizeRequest(bytes32 _requestId, address) external override(IModule, Module) onlyOracle { (IAccountingExtension _accountingExtension, IERC20 _bondToken, uint256 _bondSize, uint256 _deadline) = decodeRequestData(_requestId); diff --git a/solidity/contracts/modules/CallbackModule.sol b/solidity/contracts/modules/CallbackModule.sol index 0d6fa6f8..215d2585 100644 --- a/solidity/contracts/modules/CallbackModule.sol +++ b/solidity/contracts/modules/CallbackModule.sol @@ -19,7 +19,7 @@ contract CallbackModule is Module, ICallbackModule { // callback to _target (which should implement ICallback), passing _data and _request // the callback will be executed by a keeper job - function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { + function finalizeRequest(bytes32 _requestId, address) external override(IModule, Module) onlyOracle { (address _target, bytes memory _data) = abi.decode(requestData[_requestId], (address, bytes)); ICallback(_target).callback(_requestId, _data); emit Callback(_target, _requestId, _data); diff --git a/solidity/contracts/modules/ContractCallRequestModule.sol b/solidity/contracts/modules/ContractCallRequestModule.sol index 1b666f29..79df88b1 100644 --- a/solidity/contracts/modules/ContractCallRequestModule.sol +++ b/solidity/contracts/modules/ContractCallRequestModule.sol @@ -34,7 +34,7 @@ contract ContractCallRequestModule is Module, IContractCallRequestModule { _accountingExtension.bond(_request.requester, _requestId, _paymentToken, _paymentAmount); } - function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { + function finalizeRequest(bytes32 _requestId, address) 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) = diff --git a/solidity/contracts/modules/HttpRequestModule.sol b/solidity/contracts/modules/HttpRequestModule.sol index 81e71818..f99b0b28 100644 --- a/solidity/contracts/modules/HttpRequestModule.sol +++ b/solidity/contracts/modules/HttpRequestModule.sol @@ -34,7 +34,7 @@ contract HttpRequestModule is Module, IHttpRequestModule { _accountingExtension.bond(_request.requester, _requestId, _paymentToken, _paymentAmount); } - function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { + function finalizeRequest(bytes32 _requestId, address) 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) = diff --git a/solidity/contracts/modules/MultipleCallbacksModule.sol b/solidity/contracts/modules/MultipleCallbacksModule.sol index 14559d19..b67462ef 100644 --- a/solidity/contracts/modules/MultipleCallbacksModule.sol +++ b/solidity/contracts/modules/MultipleCallbacksModule.sol @@ -17,7 +17,7 @@ contract MultipleCallbacksModule is Module, ICallbackModule { _moduleName = 'MultipleCallbacksModule'; } - function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { + function finalizeRequest(bytes32 _requestId, address) external override(IModule, Module) onlyOracle { (address[] memory _targets, bytes[] memory _data) = abi.decode(requestData[_requestId], (address[], bytes[])); if (_targets.length != _data.length) revert CallbackModule_InvalidParameters(); diff --git a/solidity/contracts/modules/SequentialResolutionModule.sol b/solidity/contracts/modules/SequentialResolutionModule.sol index 3730de34..7eb506bb 100644 --- a/solidity/contracts/modules/SequentialResolutionModule.sol +++ b/solidity/contracts/modules/SequentialResolutionModule.sol @@ -51,9 +51,9 @@ contract SequentialResolutionModule is Module, ISequentialResolutionModule { } // TODO: finalizeRequest function. None of the resolution modules use it. How should we implement it? - function finalizeRequest(bytes32 _requestId) external virtual override onlyOracle { + function finalizeRequest(bytes32 _requestId, address _finalizer) external virtual override onlyOracle { for (uint256 i; i < resolutionModules.length; ++i) { - resolutionModules[i].finalizeRequest(_requestId); + resolutionModules[i].finalizeRequest(_requestId, _finalizer); } } diff --git a/solidity/contracts/modules/SparseMerkleTreeRequestModule.sol b/solidity/contracts/modules/SparseMerkleTreeRequestModule.sol index c3bdc39e..26dcdd2e 100644 --- a/solidity/contracts/modules/SparseMerkleTreeRequestModule.sol +++ b/solidity/contracts/modules/SparseMerkleTreeRequestModule.sol @@ -45,7 +45,7 @@ contract SparseMerkleTreeRequestModule is Module, ISparseMerkleTreeRequestModule _accountingExtension.bond(_request.requester, _requestId, _paymentToken, _paymentAmount); } - function finalizeRequest(bytes32 _requestId) external override(IModule, Module) onlyOracle { + function finalizeRequest(bytes32 _requestId, address) 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) = diff --git a/solidity/interfaces/IModule.sol b/solidity/interfaces/IModule.sol index 09f0d372..62e4c8ac 100644 --- a/solidity/interfaces/IModule.sol +++ b/solidity/interfaces/IModule.sol @@ -8,5 +8,6 @@ interface IModule is IModuleData { error Module_InvalidCaller(); function setupRequest(bytes32 _requestId, bytes calldata _data) external; - function finalizeRequest(bytes32 _requestId) external; + function finalizeRequest(bytes32 _requestId, address _finalizer) external; + function moduleName() external view returns (string memory _moduleName); } diff --git a/solidity/test/integration/Payments.t.sol b/solidity/test/integration/Payments.t.sol index 4723974a..b78126db 100644 --- a/solidity/test/integration/Payments.t.sol +++ b/solidity/test/integration/Payments.t.sol @@ -125,7 +125,7 @@ contract Integration_Payments is IntegrationBase { vm.prank(address(oracle)); _disputeModule.updateDisputeStatus(bytes32(0), _dispute); vm.prank(address(oracle)); - _requestModule.finalizeRequest(_requestId); + _requestModule.finalizeRequest(_requestId, address(oracle)); uint256 _requesterBalanceAfter = _accountingExtension.balanceOf(requester, usdc); uint256 _proposerBalanceAfter = _accountingExtension.balanceOf(proposer, usdc); @@ -176,7 +176,7 @@ contract Integration_Payments is IntegrationBase { vm.prank(address(oracle)); _disputeModule.updateDisputeStatus(bytes32(0), _dispute); vm.prank(address(oracle)); - _requestModule.finalizeRequest(_requestId); + _requestModule.finalizeRequest(_requestId, address(oracle)); uint256 _requesterBalanceAfter = _accountingExtension.balanceOf(requester, weth); uint256 _proposerBalanceAfter = _accountingExtension.balanceOf(proposer, weth); diff --git a/solidity/test/unit/BondedResponseModule.t.sol b/solidity/test/unit/BondedResponseModule.t.sol index acf0c75e..430431c9 100644 --- a/solidity/test/unit/BondedResponseModule.t.sol +++ b/solidity/test/unit/BondedResponseModule.t.sol @@ -148,7 +148,7 @@ contract BondedResponseModule_UnitTest is Test { bondedResponseModule.forTest_setRequestData(_requestId, _data); vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector); - bondedResponseModule.finalizeRequest(_requestId); + bondedResponseModule.finalizeRequest(_requestId, address(this)); // Check correct calls are made if deadline has passed _deadline = block.timestamp; @@ -176,7 +176,7 @@ contract BondedResponseModule_UnitTest is Test { address(accounting), abi.encodeCall(IAccountingExtension.release, (proposer, _requestId, token, _bondSize)) ); - bondedResponseModule.finalizeRequest(_requestId); + bondedResponseModule.finalizeRequest(_requestId, address(this)); } /** diff --git a/solidity/test/unit/CallbackModule.t.sol b/solidity/test/unit/CallbackModule.t.sol index 120f2594..53205bff 100644 --- a/solidity/test/unit/CallbackModule.t.sol +++ b/solidity/test/unit/CallbackModule.t.sol @@ -76,7 +76,7 @@ contract CallbackModule_UnitTest is Test { emit Callback(_target, _requestId, _data); vm.prank(address(oracle)); - callbackModule.finalizeRequest(_requestId); + callbackModule.finalizeRequest(_requestId, address(oracle)); } /** @@ -84,9 +84,9 @@ contract CallbackModule_UnitTest is Test { */ function test_finalizeOnlyCalledByOracle(bytes32 _requestId, address _caller) public { vm.assume(_caller != address(oracle)); - vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector)); - callbackModule.finalizeRequest(_requestId); + vm.prank(_caller); + callbackModule.finalizeRequest(_requestId, address(_caller)); } /** diff --git a/solidity/test/unit/ContractCallRequestModule.t.sol b/solidity/test/unit/ContractCallRequestModule.t.sol index 887bdfc8..556698d0 100644 --- a/solidity/test/unit/ContractCallRequestModule.t.sol +++ b/solidity/test/unit/ContractCallRequestModule.t.sol @@ -199,7 +199,7 @@ contract ContractCallRequestModule_UnitTest is Test { ); vm.startPrank(address(oracle)); - contractCallRequestModule.finalizeRequest(_requestId); + contractCallRequestModule.finalizeRequest(_requestId, address(oracle)); // Test the release flow _fullResponse.createdAt = 0; @@ -219,7 +219,7 @@ contract ContractCallRequestModule_UnitTest is Test { abi.encodeCall(IAccountingExtension.release, (_requester, _requestId, _paymentToken, _paymentAmount)) ); - contractCallRequestModule.finalizeRequest(_requestId); + contractCallRequestModule.finalizeRequest(_requestId, address(this)); } /** @@ -229,6 +229,7 @@ contract ContractCallRequestModule_UnitTest is Test { vm.assume(_caller != address(oracle)); vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector)); - contractCallRequestModule.finalizeRequest(_requestId); + vm.prank(_caller); + contractCallRequestModule.finalizeRequest(_requestId, address(_caller)); } } diff --git a/solidity/test/unit/HttpRequestModule.t.sol b/solidity/test/unit/HttpRequestModule.t.sol index e710af40..31afa7c4 100644 --- a/solidity/test/unit/HttpRequestModule.t.sol +++ b/solidity/test/unit/HttpRequestModule.t.sol @@ -166,7 +166,7 @@ contract HttpRequestModule_UnitTest is Test { ); vm.startPrank(address(oracle)); - httpRequestModule.finalizeRequest(_requestId); + httpRequestModule.finalizeRequest(_requestId, address(oracle)); // Test the release flow _fullResponse.createdAt = 0; @@ -185,7 +185,7 @@ contract HttpRequestModule_UnitTest is Test { address(accounting), abi.encodeCall(IAccountingExtension.release, (_requester, _requestId, TOKEN, _amount)) ); - httpRequestModule.finalizeRequest(_requestId); + httpRequestModule.finalizeRequest(_requestId, address(this)); } /** @@ -195,7 +195,8 @@ contract HttpRequestModule_UnitTest is Test { vm.assume(_caller != address(oracle)); vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector)); - httpRequestModule.finalizeRequest(_requestId); + vm.prank(_caller); + httpRequestModule.finalizeRequest(_requestId, address(_caller)); } /** diff --git a/solidity/test/unit/Module.t.sol b/solidity/test/unit/Module.t.sol index 89631b34..afe36656 100644 --- a/solidity/test/unit/Module.t.sol +++ b/solidity/test/unit/Module.t.sol @@ -67,11 +67,11 @@ contract Module_UnitTest is Test { // Check: reverts if not called by oracle? vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector)); vm.prank(_caller); - module.finalizeRequest(_requestId); + module.finalizeRequest(_requestId, address(_caller)); // Check: does not revert if called by oracle vm.prank(address(oracle)); - module.finalizeRequest(_requestId); + module.finalizeRequest(_requestId, address(oracle)); } /** diff --git a/solidity/test/unit/MultipleCallbacksModule.t.sol b/solidity/test/unit/MultipleCallbacksModule.t.sol index 9fc85af2..2acf125f 100644 --- a/solidity/test/unit/MultipleCallbacksModule.t.sol +++ b/solidity/test/unit/MultipleCallbacksModule.t.sol @@ -81,7 +81,7 @@ contract Unit_MultipleCallbacksModule_FinalizeRequests is Base { emit Callback(_target, _requestId, _data); vm.prank(address(oracle)); - multipleCallbackModule.finalizeRequest(_requestId); + multipleCallbackModule.finalizeRequest(_requestId, address(oracle)); } /** @@ -91,7 +91,8 @@ contract Unit_MultipleCallbacksModule_FinalizeRequests is Base { vm.assume(_caller != address(oracle)); vm.expectRevert(IModule.Module_OnlyOracle.selector); - multipleCallbackModule.finalizeRequest(_requestId); + vm.prank(_caller); + multipleCallbackModule.finalizeRequest(_requestId, address(_caller)); } function test_Revert_InvalidParameters( @@ -105,6 +106,6 @@ contract Unit_MultipleCallbacksModule_FinalizeRequests is Base { vm.expectRevert(ICallbackModule.CallbackModule_InvalidParameters.selector); vm.prank(address(oracle)); - multipleCallbackModule.finalizeRequest(_requestId); + multipleCallbackModule.finalizeRequest(_requestId, address(oracle)); } } diff --git a/solidity/test/unit/Oracle.t.sol b/solidity/test/unit/Oracle.t.sol index 0bddc5b3..bc215126 100644 --- a/solidity/test/unit/Oracle.t.sol +++ b/solidity/test/unit/Oracle.t.sol @@ -851,25 +851,25 @@ contract Oracle_UnitTest is Test { } // mock and expect the finalize request in requestModule - vm.mockCall(address(requestModule), abi.encodeCall(IModule.finalizeRequest, (_requestId)), abi.encode()); - vm.expectCall(address(requestModule), abi.encodeCall(IModule.finalizeRequest, (_requestId))); + vm.mockCall(address(requestModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller)), abi.encode()); + vm.expectCall(address(requestModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller))); // mock and expect the finalize request in responseModule - vm.mockCall(address(responseModule), abi.encodeCall(IModule.finalizeRequest, (_requestId)), abi.encode()); - vm.expectCall(address(responseModule), abi.encodeCall(IModule.finalizeRequest, (_requestId))); + vm.mockCall(address(responseModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller)), abi.encode()); + vm.expectCall(address(responseModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller))); // mock and expect the finalize request in resolutionModule - vm.mockCall(address(resolutionModule), abi.encodeCall(IModule.finalizeRequest, (_requestId)), abi.encode()); - vm.expectCall(address(resolutionModule), abi.encodeCall(IModule.finalizeRequest, (_requestId))); + vm.mockCall(address(resolutionModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller)), abi.encode()); + vm.expectCall(address(resolutionModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller))); if (_useResolutionAndFinality) { // mock and expect the call to disputeModule - vm.mockCall(address(disputeModule), abi.encodeCall(IModule.finalizeRequest, (_requestId)), abi.encode()); - vm.expectCall(address(disputeModule), abi.encodeCall(IModule.finalizeRequest, (_requestId))); + vm.mockCall(address(disputeModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller)), abi.encode()); + vm.expectCall(address(disputeModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller))); // mock and expect the call to finalityModule - vm.mockCall(address(finalityModule), abi.encodeCall(IModule.finalizeRequest, (_requestId)), abi.encode()); - vm.expectCall(address(finalityModule), abi.encodeCall(IModule.finalizeRequest, (_requestId))); + vm.mockCall(address(finalityModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller)), abi.encode()); + vm.expectCall(address(finalityModule), abi.encodeCall(IModule.finalizeRequest, (_requestId, _caller))); } // Check: emits RequestFinalized event? diff --git a/solidity/test/unit/SequentialResolutionModule.t.sol b/solidity/test/unit/SequentialResolutionModule.t.sol index 7cbafa3c..394a1e75 100644 --- a/solidity/test/unit/SequentialResolutionModule.t.sol +++ b/solidity/test/unit/SequentialResolutionModule.t.sol @@ -251,13 +251,14 @@ contract SequentialResolutionModule_UnitTest is Base { vm.expectCall(address(submodule2), abi.encodeWithSelector(IModule.finalizeRequest.selector, requestId)); vm.expectCall(address(submodule3), abi.encodeWithSelector(IModule.finalizeRequest.selector, requestId)); vm.prank(address(oracle)); - module.finalizeRequest(requestId); + module.finalizeRequest(requestId, address(oracle)); } function testReverts_finalizeRequestCalledByNonOracle() public { - vm.prank(makeAddr('other_sender')); + address _caller = makeAddr('other_sender'); + vm.prank(_caller); vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector)); - module.finalizeRequest(requestId); + module.finalizeRequest(requestId, _caller); } function test_listSubmodulesFullList() public { diff --git a/solidity/test/unit/SparseMerkleTreeRequestModule.t.sol b/solidity/test/unit/SparseMerkleTreeRequestModule.t.sol index 2c81f487..ccd8b113 100644 --- a/solidity/test/unit/SparseMerkleTreeRequestModule.t.sol +++ b/solidity/test/unit/SparseMerkleTreeRequestModule.t.sol @@ -231,7 +231,7 @@ contract SparseMerkleTreeRequestModule_UnitTest is Test { ); vm.startPrank(address(oracle)); - sparseMerkleTreeRequestModule.finalizeRequest(_requestId); + sparseMerkleTreeRequestModule.finalizeRequest(_requestId, address(oracle)); // Test the release flow _fullResponse.createdAt = 0; @@ -251,7 +251,7 @@ contract SparseMerkleTreeRequestModule_UnitTest is Test { abi.encodeCall(IAccountingExtension.release, (_requester, _requestId, _paymentToken, _paymentAmount)) ); - sparseMerkleTreeRequestModule.finalizeRequest(_requestId); + sparseMerkleTreeRequestModule.finalizeRequest(_requestId, address(this)); } /** @@ -261,7 +261,8 @@ contract SparseMerkleTreeRequestModule_UnitTest is Test { vm.assume(_caller != address(oracle)); vm.expectRevert(abi.encodeWithSelector(IModule.Module_OnlyOracle.selector)); - sparseMerkleTreeRequestModule.finalizeRequest(_requestId); + vm.prank(_caller); + sparseMerkleTreeRequestModule.finalizeRequest(_requestId, address(_caller)); } /**