Skip to content

Commit

Permalink
feat: pass finalizer address to finalizeRequest (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShaito authored Aug 10, 2023
1 parent 58cf529 commit eaf8b67
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 49 deletions.
2 changes: 1 addition & 1 deletion solidity/contracts/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
10 changes: 5 additions & 5 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/modules/BondedResponseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/modules/CallbackModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/modules/ContractCallRequestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/modules/HttpRequestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/modules/MultipleCallbacksModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions solidity/contracts/modules/SequentialResolutionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
3 changes: 2 additions & 1 deletion solidity/interfaces/IModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions solidity/test/integration/Payments.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions solidity/test/unit/BondedResponseModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions solidity/test/unit/CallbackModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ contract CallbackModule_UnitTest is Test {
emit Callback(_target, _requestId, _data);

vm.prank(address(oracle));
callbackModule.finalizeRequest(_requestId);
callbackModule.finalizeRequest(_requestId, address(oracle));
}

/**
* @notice Test that the finalizeRequest reverts if caller is not the oracle
*/
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));
}

/**
Expand Down
7 changes: 4 additions & 3 deletions solidity/test/unit/ContractCallRequestModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand All @@ -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));
}
}
7 changes: 4 additions & 3 deletions solidity/test/unit/HttpRequestModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions solidity/test/unit/Module.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
7 changes: 4 additions & 3 deletions solidity/test/unit/MultipleCallbacksModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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(
Expand All @@ -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));
}
}
20 changes: 10 additions & 10 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
7 changes: 4 additions & 3 deletions solidity/test/unit/SequentialResolutionModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions solidity/test/unit/SparseMerkleTreeRequestModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down

0 comments on commit eaf8b67

Please sign in to comment.