Skip to content

Commit

Permalink
fix: finalizeRequest in BondedDisputeModule
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Oct 30, 2023
1 parent 9d15e84 commit e87f864
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
52 changes: 24 additions & 28 deletions solidity/contracts/modules/response/BondedResponseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ contract BondedResponseModule is Module, IBondedResponseModule {
_moduleName = 'BondedResponseModule';
}

/// @inheritdoc IBondedResponseModule
function decodeRequestData(bytes32 _requestId) public view returns (RequestParameters memory _params) {}

function decodeRequestData(bytes calldata _data) public view returns (RequestParameters memory _params) {
function decodeRequestData(bytes calldata _data) public pure returns (RequestParameters memory _params) {
_params = abi.decode(_data, (RequestParameters));
}

Expand All @@ -28,7 +25,6 @@ contract BondedResponseModule is Module, IBondedResponseModule {
IOracle.Response calldata _response,
address _sender
) external onlyOracle {
// bytes32 _requestId = _getId(_request);
RequestParameters memory _params = decodeRequestData(_request.responseModuleData);

// Cannot propose after the deadline
Expand All @@ -39,12 +35,10 @@ contract BondedResponseModule is Module, IBondedResponseModule {
uint256 _responsesLength = _responseIds.length;

if (_responsesLength != 0) {
// bytes32 _disputeId = ORACLE.getResponse(_responseIds[_responsesLength - 1]).disputeId;
bytes32 _disputeId = ORACLE.disputeOf(_responseIds[_responsesLength - 1]);

// Allowing one undisputed response at a time
if (_disputeId == bytes32(0)) revert BondedResponseModule_AlreadyResponded();
// IOracle.Dispute memory _dispute = ORACLE.getDispute(_disputeId);
IOracle.DisputeStatus _status = ORACLE.disputeStatus(_disputeId);
// TODO: leaving a note here to re-check this check if a new status is added
// If the dispute was lost, we assume the proposed answer was correct. DisputeStatus.None should not be reachable due to the previous check.
Expand Down Expand Up @@ -82,28 +76,30 @@ contract BondedResponseModule is Module, IBondedResponseModule {
IOracle.Response calldata _response,
address _finalizer
) external override(IBondedResponseModule, Module) onlyOracle {
// RequestParameters memory _params = decodeRequestData(_requestId);
bytes32 _requestId = _getId(_request);

RequestParameters memory _params = decodeRequestData(_request.responseModuleData);

bool _isModule = ORACLE.allowedModule(_requestId, _finalizer);

if (!_isModule && block.timestamp < _params.deadline) {
revert BondedResponseModule_TooEarlyToFinalize();
}

if (_response.createdAt != 0) {
if (!_isModule && block.timestamp < _response.createdAt + _params.disputeWindow) {
revert BondedResponseModule_TooEarlyToFinalize();
}

_params.accountingExtension.release({
_bonder: _response.proposer,
_requestId: _requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});
}

// bool _isModule = ORACLE.allowedModule(_requestId, _finalizer);

// if (!_isModule && block.timestamp < _params.deadline) {
// revert BondedResponseModule_TooEarlyToFinalize();
// }

// IOracle.Response memory _response = ORACLE.getFinalizedResponse(_requestId);
// if (_response.createdAt != 0) {
// if (!_isModule && block.timestamp < _response.createdAt + _params.disputeWindow) {
// revert BondedResponseModule_TooEarlyToFinalize();
// }

// _params.accountingExtension.release({
// _bonder: _response.proposer,
// _requestId: _requestId,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
// }
// emit RequestFinalized(_requestId, _finalizer);
emit RequestFinalized(_requestId, _finalizer);
}

/// @inheritdoc Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ interface IBondedResponseModule is IResponseModule {

/**
* @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);
function decodeRequestData(bytes calldata _data) external view returns (RequestParameters memory _params);

/**
Expand Down

0 comments on commit e87f864

Please sign in to comment.