-
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 #14 from defi-wonderland/perf/opo-593-bonded-dispu…
…te-module perf: optimize `BondedDisputeModule`
- Loading branch information
Showing
5 changed files
with
425 additions
and
584 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
197 changes: 94 additions & 103 deletions
197
solidity/contracts/modules/dispute/BondedDisputeModule.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,115 +1,106 @@ | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity ^0.8.19; | ||
// 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'; | ||
// 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 {IBondedDisputeModule} from '../../../interfaces/modules/dispute/IBondedDisputeModule.sol'; | ||
import {IBondedDisputeModule} from '../../../interfaces/modules/dispute/IBondedDisputeModule.sol'; | ||
|
||
// contract BondedDisputeModule is Module, IBondedDisputeModule { | ||
// constructor(IOracle _oracle) Module(_oracle) {} | ||
contract BondedDisputeModule is Module, IBondedDisputeModule { | ||
constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
// /// @inheritdoc IModule | ||
// function moduleName() external pure returns (string memory _moduleName) { | ||
// return 'BondedDisputeModule'; | ||
// } | ||
/// @inheritdoc IModule | ||
function moduleName() external pure returns (string memory _moduleName) { | ||
return 'BondedDisputeModule'; | ||
} | ||
|
||
// /// @inheritdoc IBondedDisputeModule | ||
// function decodeRequestData(bytes32 _requestId) public view returns (RequestParameters memory _params) { | ||
// _params = abi.decode(requestData[_requestId], (RequestParameters)); | ||
// } | ||
/// @inheritdoc IBondedDisputeModule | ||
function decodeRequestData(bytes calldata _data) public view returns (RequestParameters memory _params) { | ||
_params = abi.decode(_data, (RequestParameters)); | ||
} | ||
|
||
// /// @inheritdoc IBondedDisputeModule | ||
// function disputeEscalated(bytes32 _disputeId) external onlyOracle {} | ||
/// @inheritdoc IBondedDisputeModule | ||
function disputeResponse( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external onlyOracle { | ||
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData); | ||
|
||
// /// @inheritdoc IBondedDisputeModule | ||
// function disputeResponse( | ||
// bytes32 _requestId, | ||
// bytes32 _responseId, | ||
// address _disputer, | ||
// address _proposer | ||
// ) external onlyOracle returns (IOracle.Dispute memory _dispute) { | ||
// _dispute = IOracle.Dispute({ | ||
// disputer: _disputer, | ||
// responseId: _responseId, | ||
// proposer: _proposer, | ||
// requestId: _requestId, | ||
// status: IOracle.DisputeStatus.Active, | ||
// createdAt: block.timestamp | ||
// }); | ||
_params.accountingExtension.bond({ | ||
_bonder: _dispute.disputer, | ||
_requestId: _dispute.requestId, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
|
||
// RequestParameters memory _params = decodeRequestData(_requestId); | ||
// _params.accountingExtension.bond({ | ||
// _bonder: _disputer, | ||
// _requestId: _requestId, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
emit ResponseDisputed({ | ||
_requestId: _dispute.requestId, | ||
_responseId: _dispute.responseId, | ||
_disputeId: _getId(_dispute), | ||
_dispute: _dispute, | ||
_blockNumber: block.number | ||
}); | ||
} | ||
|
||
// emit ResponseDisputed(_requestId, _responseId, _disputer, _proposer); | ||
// } | ||
/// @inheritdoc IBondedDisputeModule | ||
function onDisputeStatusChange( | ||
bytes32 _disputeId, | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external onlyOracle { | ||
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData); | ||
IOracle.DisputeStatus _status = ORACLE.disputeStatus(_disputeId); | ||
|
||
// /// @inheritdoc IBondedDisputeModule | ||
// function onDisputeStatusChange(bytes32, /* _disputeId */ IOracle.Dispute memory _dispute) external onlyOracle { | ||
// RequestParameters memory _params = decodeRequestData(_dispute.requestId); | ||
// IOracle.DisputeStatus _status = _dispute.status; | ||
// address _proposer = _dispute.proposer; | ||
// address _disputer = _dispute.disputer; | ||
if (_status == IOracle.DisputeStatus.NoResolution) { | ||
// No resolution, we release both bonds | ||
_params.accountingExtension.release({ | ||
_bonder: _dispute.disputer, | ||
_requestId: _dispute.requestId, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
|
||
// if (_status == IOracle.DisputeStatus.NoResolution) { | ||
// // No resolution, we release both bonds | ||
// _params.accountingExtension.release({ | ||
// _bonder: _disputer, | ||
// _requestId: _dispute.requestId, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
_params.accountingExtension.release({ | ||
_bonder: _dispute.proposer, | ||
_requestId: _dispute.requestId, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
} else if (_status == IOracle.DisputeStatus.Won) { | ||
// Disputer won, we pay the disputer and release their bond | ||
_params.accountingExtension.pay({ | ||
_requestId: _dispute.requestId, | ||
_payer: _dispute.proposer, | ||
_receiver: _dispute.disputer, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
_params.accountingExtension.release({ | ||
_bonder: _dispute.disputer, | ||
_requestId: _dispute.requestId, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
} else if (_status == IOracle.DisputeStatus.Lost) { | ||
// Disputer lost, we pay the proposer and release their bond | ||
_params.accountingExtension.pay({ | ||
_requestId: _dispute.requestId, | ||
_payer: _dispute.disputer, | ||
_receiver: _dispute.proposer, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
_params.accountingExtension.release({ | ||
_bonder: _dispute.proposer, | ||
_requestId: _dispute.requestId, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
} | ||
|
||
// _params.accountingExtension.release({ | ||
// _bonder: _proposer, | ||
// _requestId: _dispute.requestId, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
// } else if (_status == IOracle.DisputeStatus.Won) { | ||
// // Disputer won, we pay the disputer and release their bond | ||
// _params.accountingExtension.pay({ | ||
// _requestId: _dispute.requestId, | ||
// _payer: _proposer, | ||
// _receiver: _disputer, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
// _params.accountingExtension.release({ | ||
// _bonder: _disputer, | ||
// _requestId: _dispute.requestId, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
// } else if (_status == IOracle.DisputeStatus.Lost) { | ||
// // Disputer lost, we pay the proposer and release their bond | ||
// _params.accountingExtension.pay({ | ||
// _requestId: _dispute.requestId, | ||
// _payer: _disputer, | ||
// _receiver: _proposer, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
// _params.accountingExtension.release({ | ||
// _bonder: _proposer, | ||
// _requestId: _dispute.requestId, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
// } | ||
|
||
// emit DisputeStatusChanged({ | ||
// _requestId: _dispute.requestId, | ||
// _responseId: _dispute.responseId, | ||
// _disputer: _disputer, | ||
// _proposer: _proposer, | ||
// _status: _status | ||
// }); | ||
// } | ||
// } | ||
emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: _status}); | ||
} | ||
} |
131 changes: 64 additions & 67 deletions
131
solidity/interfaces/modules/dispute/IBondedDisputeModule.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,75 +1,72 @@ | ||
// // SPDX-License-Identifier: MIT | ||
// pragma solidity ^0.8.19; | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
// import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
// import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
// import {IDisputeModule} from | ||
// '@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/dispute/IDisputeModule.sol'; | ||
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; | ||
import {IDisputeModule} from | ||
'@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/dispute/IDisputeModule.sol'; | ||
|
||
// import {IAccountingExtension} from '../../extensions/IAccountingExtension.sol'; | ||
import {IAccountingExtension} from '../../extensions/IAccountingExtension.sol'; | ||
|
||
// /* | ||
// * @title BondedDisputeModule | ||
// * @notice Module allowing users to dispute a proposed response | ||
// * by bonding tokens. According to the result of the dispute, | ||
// * the tokens are either returned to the disputer or to the proposer. | ||
// */ | ||
// interface IBondedDisputeModule is IDisputeModule { | ||
// /*/////////////////////////////////////////////////////////////// | ||
// STRUCTS | ||
// //////////////////////////////////////////////////////////////*/ | ||
/* | ||
* @title BondedDisputeModule | ||
* @notice Module allowing users to dispute a proposed response | ||
* by bonding tokens. According to the result of the dispute, | ||
* the tokens are either returned to the disputer or to the proposer. | ||
*/ | ||
interface IBondedDisputeModule is IDisputeModule { | ||
/*/////////////////////////////////////////////////////////////// | ||
STRUCTS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @notice Parameters of the request as stored in the module | ||
// * @param ipfsHash The hash of the CID from IPFS | ||
// * @param requestModule The address of the request module | ||
// * @param responseModule The address of the response module | ||
// */ | ||
// struct RequestParameters { | ||
// IAccountingExtension accountingExtension; | ||
// IERC20 bondToken; | ||
// uint256 bondSize; | ||
// } | ||
/** | ||
* @notice Parameters of the request as stored in the module | ||
* @param ipfsHash The hash of the CID from IPFS | ||
* @param requestModule The address of the request module | ||
* @param responseModule The address of the response module | ||
*/ | ||
struct RequestParameters { | ||
IAccountingExtension accountingExtension; | ||
IERC20 bondToken; | ||
uint256 bondSize; | ||
} | ||
|
||
// /*/////////////////////////////////////////////////////////////// | ||
// LOGIC | ||
// //////////////////////////////////////////////////////////////*/ | ||
/*/////////////////////////////////////////////////////////////// | ||
LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
// /** | ||
// * @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); | ||
/** | ||
* @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 Called by the oracle when a dispute has been made on a response. | ||
// * Bonds the tokens of the disputer. | ||
// * @param _requestId The ID of the request whose response is disputed | ||
// * @param _responseId The ID of the response being disputed | ||
// * @param _disputer The address of the user who disputed the response | ||
// * @param _proposer The address of the user who proposed the disputed response | ||
// * @return _dispute The dispute on the proposed response | ||
// */ | ||
// function disputeResponse( | ||
// bytes32 _requestId, | ||
// bytes32 _responseId, | ||
// address _disputer, | ||
// address _proposer | ||
// ) external returns (IOracle.Dispute memory _dispute); | ||
/** | ||
* @notice Called by the oracle when a dispute has been made on a response | ||
* | ||
* @dev Bonds the tokens of the disputer | ||
* @param _request The request a dispute has been submitted for | ||
* @param _response The response that is being disputed | ||
* @param _dispute The dispute that is being submitted | ||
*/ | ||
function disputeResponse( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external; | ||
|
||
// /** | ||
// * @notice Called by the oracle when a dispute status has been updated. | ||
// * According to the result of the dispute, bonds are released to the proposer or | ||
// * paid to the disputer. | ||
// * @param _disputeId The ID of the dispute being updated | ||
// * @param _dispute The dispute object | ||
// */ | ||
// function onDisputeStatusChange(bytes32 _disputeId, IOracle.Dispute memory _dispute) external; | ||
|
||
// /** | ||
// * @notice Called by the oracle when a dispute has been escalated. Not implemented in this module | ||
// * @param _disputeId The ID of the dispute being escalated | ||
// */ | ||
// function disputeEscalated(bytes32 _disputeId) external; | ||
// } | ||
/** | ||
* @notice Called by the oracle when a dispute status has been updated | ||
* | ||
* @dev According to the result of the dispute, bonds are released to the proposer or paid to the disputer | ||
* @param _disputeId The ID of the dispute being updated | ||
* @param _dispute The dispute object | ||
*/ | ||
function onDisputeStatusChange( | ||
bytes32 _disputeId, | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external; | ||
} |
Oops, something went wrong.