-
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.
Merge pull request #11 from defi-wonderland/perf/opo-602-arbitrator-m…
…odule perf: optimize `ArbitratorModule`
- Loading branch information
Showing
4 changed files
with
455 additions
and
466 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
131 changes: 69 additions & 62 deletions
131
solidity/contracts/modules/resolution/ArbitratorModule.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,62 +1,69 @@ | ||
// // 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'; | ||
|
||
// import {IArbitratorModule} from '../../../interfaces/modules/resolution/IArbitratorModule.sol'; | ||
// import {IArbitrator} from '../../../interfaces/IArbitrator.sol'; | ||
|
||
// contract ArbitratorModule is Module, IArbitratorModule { | ||
// /** | ||
// * @notice The status of all disputes | ||
// */ | ||
// mapping(bytes32 _disputeId => ArbitrationStatus _status) internal _disputeData; | ||
|
||
// constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
// /// @inheritdoc IModule | ||
// function moduleName() external pure returns (string memory _moduleName) { | ||
// return 'ArbitratorModule'; | ||
// } | ||
|
||
// /// @inheritdoc IArbitratorModule | ||
// function decodeRequestData(bytes32 _requestId) public view returns (address _arbitrator) { | ||
// _arbitrator = abi.decode(requestData[_requestId], (address)); | ||
// } | ||
|
||
// /// @inheritdoc IArbitratorModule | ||
// function getStatus(bytes32 _disputeId) external view returns (ArbitrationStatus _disputeStatus) { | ||
// _disputeStatus = _disputeData[_disputeId]; | ||
// } | ||
|
||
// /// @inheritdoc IArbitratorModule | ||
// function startResolution(bytes32 _disputeId) external onlyOracle { | ||
// IOracle.Dispute memory _dispute = ORACLE.getDispute(_disputeId); | ||
|
||
// address _arbitrator = abi.decode(requestData[_dispute.requestId], (address)); | ||
// if (_arbitrator == address(0)) revert ArbitratorModule_InvalidArbitrator(); | ||
|
||
// _disputeData[_disputeId] = ArbitrationStatus.Active; | ||
// IArbitrator(_arbitrator).resolve(_disputeId); | ||
|
||
// emit ResolutionStarted(_dispute.requestId, _disputeId); | ||
// } | ||
|
||
// /// @inheritdoc IArbitratorModule | ||
// function resolveDispute(bytes32 _disputeId) external onlyOracle { | ||
// IOracle.Dispute memory _dispute = ORACLE.getDispute(_disputeId); | ||
// if (_dispute.status != IOracle.DisputeStatus.Escalated) revert ArbitratorModule_InvalidDisputeId(); | ||
|
||
// address _arbitrator = abi.decode(requestData[_dispute.requestId], (address)); | ||
// IOracle.DisputeStatus _status = IArbitrator(_arbitrator).getAnswer(_disputeId); | ||
|
||
// if (_status <= IOracle.DisputeStatus.Escalated) revert ArbitratorModule_InvalidResolutionStatus(); | ||
// _disputeData[_disputeId] = ArbitrationStatus.Resolved; | ||
|
||
// ORACLE.updateDisputeStatus(_disputeId, _status); | ||
|
||
// emit DisputeResolved(_dispute.requestId, _disputeId, _status); | ||
// } | ||
// } | ||
// 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'; | ||
|
||
import {IArbitratorModule} from '../../../interfaces/modules/resolution/IArbitratorModule.sol'; | ||
import {IArbitrator} from '../../../interfaces/IArbitrator.sol'; | ||
|
||
contract ArbitratorModule is Module, IArbitratorModule { | ||
/** | ||
* @notice The status of all disputes | ||
*/ | ||
mapping(bytes32 _disputeId => ArbitrationStatus _status) internal _disputeData; | ||
|
||
constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
/// @inheritdoc IModule | ||
function moduleName() external pure returns (string memory _moduleName) { | ||
return 'ArbitratorModule'; | ||
} | ||
|
||
/// @inheritdoc IArbitratorModule | ||
function decodeRequestData(bytes calldata _data) public pure returns (RequestParameters memory _params) { | ||
_params = abi.decode(_data, (RequestParameters)); | ||
} | ||
|
||
/// @inheritdoc IArbitratorModule | ||
function getStatus(bytes32 _disputeId) external view returns (ArbitrationStatus _disputeStatus) { | ||
_disputeStatus = _disputeData[_disputeId]; | ||
} | ||
|
||
/// @inheritdoc IArbitratorModule | ||
function startResolution( | ||
bytes32 _disputeId, | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
Check warning on line 38 in solidity/contracts/modules/resolution/ArbitratorModule.sol GitHub Actions / Run Linters (16.x)
|
||
IOracle.Dispute calldata _dispute | ||
) external onlyOracle { | ||
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData); | ||
if (_params.arbitrator == address(0)) revert ArbitratorModule_InvalidArbitrator(); | ||
|
||
_disputeData[_disputeId] = ArbitrationStatus.Active; | ||
IArbitrator(_params.arbitrator).resolve(_disputeId); | ||
|
||
emit ResolutionStarted(_dispute.requestId, _disputeId); | ||
} | ||
|
||
/// @inheritdoc IArbitratorModule | ||
function resolveDispute( | ||
bytes32 _disputeId, | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external onlyOracle { | ||
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) revert ArbitratorModule_InvalidDisputeId(); | ||
|
||
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData); | ||
IOracle.DisputeStatus _status = IArbitrator(_params.arbitrator).getAnswer(_disputeId); | ||
|
||
if (_status <= IOracle.DisputeStatus.Escalated) revert ArbitratorModule_InvalidResolutionStatus(); | ||
_disputeData[_disputeId] = ArbitrationStatus.Resolved; | ||
|
||
ORACLE.updateDisputeStatus(_request, _response, _dispute, _status); | ||
|
||
emit DisputeResolved(_dispute.requestId, _disputeId, _status); | ||
} | ||
} |
166 changes: 95 additions & 71 deletions
166
solidity/interfaces/modules/resolution/IArbitratorModule.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,84 +1,108 @@ | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity ^0.8.19; | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
// import {IResolutionModule} from | ||
// '@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/resolution/IResolutionModule.sol'; | ||
import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
import {IResolutionModule} from | ||
'@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/resolution/IResolutionModule.sol'; | ||
|
||
// /* | ||
// * @title ArbitratorModule | ||
// * @notice Module allowing an external arbitrator contract | ||
// * to resolve a dispute. | ||
// */ | ||
// interface IArbitratorModule is IResolutionModule { | ||
// /*/////////////////////////////////////////////////////////////// | ||
// ERRORS | ||
// //////////////////////////////////////////////////////////////*/ | ||
/* | ||
* @title ArbitratorModule | ||
* @notice Module allowing an external arbitrator contract to resolve a dispute. | ||
*/ | ||
interface IArbitratorModule is IResolutionModule { | ||
Check warning on line 12 in solidity/interfaces/modules/resolution/IArbitratorModule.sol GitHub Actions / Run Linters (16.x)
|
||
/*/////////////////////////////////////////////////////////////// | ||
ERRORS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @notice Thrown when an unauthorized caller calls a function only the arbitrator can call | ||
// */ | ||
// error ArbitratorModule_OnlyArbitrator(); | ||
/** | ||
* @notice Thrown when trying to resolve a dispute that is not escalated | ||
*/ | ||
error ArbitratorModule_InvalidDisputeId(); | ||
|
||
// /** | ||
// * @notice Thrown when trying to resolve a dispute that is not escalated | ||
// */ | ||
// error ArbitratorModule_InvalidDisputeId(); | ||
/** | ||
* @notice Thrown when the arbitrator address is the address zero | ||
*/ | ||
error ArbitratorModule_InvalidArbitrator(); | ||
|
||
// /** | ||
// * @notice Thrown when the arbitrator address is the address zero | ||
// */ | ||
// error ArbitratorModule_InvalidArbitrator(); | ||
/** | ||
* @notice Thrown when the arbitrator returns an invalid resolution status | ||
*/ | ||
error ArbitratorModule_InvalidResolutionStatus(); | ||
|
||
// /** | ||
// * @notice Thrown when the arbitrator returns an invalid resolution status | ||
// */ | ||
// error ArbitratorModule_InvalidResolutionStatus(); | ||
/*/////////////////////////////////////////////////////////////// | ||
STRUCTS | ||
//////////////////////////////////////////////////////////////*/ | ||
/** | ||
* @notice Parameters of the request as stored in the module | ||
* @param arbitrator The address of the arbitrator | ||
*/ | ||
struct RequestParameters { | ||
address arbitrator; | ||
} | ||
|
||
// /*/////////////////////////////////////////////////////////////// | ||
// ENUMS | ||
// //////////////////////////////////////////////////////////////*/ | ||
/*/////////////////////////////////////////////////////////////// | ||
ENUMS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @notice Available status of the arbitration process | ||
// */ | ||
// enum ArbitrationStatus { | ||
// Unknown, // The arbitration process has not started (default) | ||
// Active, // The arbitration process is active | ||
// Resolved // The arbitration process is resolved | ||
// } | ||
/** | ||
* @notice Available status of the arbitration process | ||
*/ | ||
enum ArbitrationStatus { | ||
Unknown, // The arbitration process has not started (default) | ||
Active, // The arbitration process is active | ||
Resolved // The arbitration process is resolved | ||
} | ||
|
||
// /*/////////////////////////////////////////////////////////////// | ||
// LOGIC | ||
// //////////////////////////////////////////////////////////////*/ | ||
/*/////////////////////////////////////////////////////////////// | ||
LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @notice Returns the current arbitration status of a dispute | ||
// * @param _disputeId The ID of the dispute | ||
// * @return _disputeStatus The `ArbitrationStatus` of the dispute | ||
// */ | ||
// function getStatus(bytes32 _disputeId) external view returns (ArbitrationStatus _disputeStatus); | ||
/** | ||
* @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 Starts the arbitration process by calling `resolve` on the | ||
// * arbitrator and flags the dispute as Active | ||
// * @dev Only callable by the Oracle | ||
// * @dev Will revert if the arbitrator address is the address zero | ||
// * @param _disputeId The ID of the dispute | ||
// */ | ||
// function startResolution(bytes32 _disputeId) external; | ||
/** | ||
* @notice Returns the current arbitration status of a dispute | ||
* | ||
* @param _disputeId The ID of the dispute | ||
* @return _disputeStatus The `ArbitrationStatus` of the dispute | ||
*/ | ||
function getStatus(bytes32 _disputeId) external view returns (ArbitrationStatus _disputeStatus); | ||
|
||
// /** | ||
// * @notice Resolves the dispute by getting the answer from the arbitrator | ||
// * and updating the dispute status | ||
// * @dev Only callable by the Oracle | ||
// * @param _disputeId The ID of the dispute | ||
// */ | ||
// function resolveDispute(bytes32 _disputeId) external; | ||
/** | ||
* @notice Starts the arbitration process by calling `resolve` on the arbitrator and flags the dispute as Active | ||
* | ||
* @dev Only callable by the Oracle | ||
* @dev Will revert if the arbitrator address is the address zero | ||
* @param _disputeId The ID of the dispute | ||
* @param _request The request | ||
* @param _response The disputed response | ||
* @param _dispute The dispute being sent to the resolution | ||
*/ | ||
function startResolution( | ||
bytes32 _disputeId, | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external; | ||
|
||
// /** | ||
// * @notice Returns the decoded data for a request | ||
// * @param _requestId The ID of the request | ||
// * @return _arbitrator The address of the arbitrator | ||
// */ | ||
// function decodeRequestData(bytes32 _requestId) external view returns (address _arbitrator); | ||
// } | ||
/** | ||
* @notice Resolves the dispute by getting the answer from the arbitrator and updating the dispute status | ||
* | ||
* @dev Only callable by the Oracle | ||
* @param _disputeId The ID of the dispute | ||
* @param _request The request | ||
* @param _response The disputed response | ||
* @param _dispute The dispute that is being resolved | ||
*/ | ||
function resolveDispute( | ||
bytes32 _disputeId, | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external; | ||
} |
Oops, something went wrong.