Skip to content

Commit

Permalink
Merge branch 'dev' into perf/opo-605-private-erc20-resolution-module
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Nov 21, 2023
2 parents 575f1b4 + 9eda7b0 commit 28286f9
Show file tree
Hide file tree
Showing 31 changed files with 2,822 additions and 3,319 deletions.
2 changes: 1 addition & 1 deletion docs/src/content/modules/dispute/bonded_dispute_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Bonded Dispute Module is a contract that allows users to dispute a proposed

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `decodeRequestData(bytes calldata _data)`: Returns the decoded data for a request.
- `disputeResponse(bytes32 _requestId, bytes32 _responseId, address _disputer, address _proposer)`: Starts a dispute.
- `onDisputeStatusChange(bytes32 _disputeId, IOracle.Dispute memory _dispute)`: Is a hook called by the oracle when a dispute status has been updated.
- `disputeEscalated(bytes32 _disputeId)`: Called by the oracle when a dispute has been escalated. Not implemented in this module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `MultipleCallbacksModule` is a finality module that allows users to make mul

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request. The returned data includes the target addresses for the callback and the calldata forwarded to the targets.
- `finalizeRequest(bytes32 _requestId, address)`: Finalizes the request by executing the callback calls on the targets.
- `decodeRequestData`: Returns the decoded data for a request. The returned data includes the target addresses for the callback and the calldata forwarded to the targets.
- `finalizeRequest`: Finalizes the request by executing the callback calls on the targets.

### Request Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `ContractCallRequestModule` is a module for requesting on-chain information.

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: This method decodes the request data for a given request ID. It returns the target contract address, the function selector, the encoded arguments of the function to call, the accounting extension to bond and release funds, the payment token, and the payment amount.
- `finalizeRequest(bytes32 _requestId, address)`: This method finalizes a request by paying the response proposer. It is only callable by the oracle.
- `decodeRequestData`: This method decodes the request data for a given request ID. It returns the target contract address, the function selector, the encoded arguments of the function to call, the accounting extension to bond and release funds, the payment token, and the payment amount.
- `finalizeRequest`: This method finalizes a request by paying the response proposer. It is only callable by the oracle.

### Request Parameters

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/modules/request/http_request_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `HttpRequestModule` is a contract that allows users to request HTTP calls.

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: This method decodes the data for a request given its ID. It returns the URL, HTTP method, body, accounting extension, payment token, and payment amount associated with the request.
- `finalizeRequest(bytes32 _requestId, address)`: This method finalizes a request by paying the proposer if there is a valid response, or releases the requester bond if no valid response was provided.
- `decodeRequestData`: This method decodes request parameters. It returns the URL, HTTP method, body, accounting extension, payment token, and payment amount from the given data.
- `finalizeRequest`: This method finalizes a request by paying the proposer if there is a valid response, or releases the requester bond if no valid response was provided.

### Request Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `SparseMerkleTreeRequestModule` is a contract that allows a user to request

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: This function decodes the request data for a given request ID. It returns a RequestParameters struct that contains the parameters for the request.
- `finalizeRequest(bytes32 _requestId, address _finalizer)`: This function is called by the Oracle to finalize the request. It either pays the proposer for the response or releases the requester's bond if no response was submitted.
- `decodeRequestData`: This function decodes the request data for a given request ID. It returns a RequestParameters struct that contains the parameters for the request.
- `finalizeRequest`: This function is called by the Oracle to finalize the request. It either pays the proposer for the response or releases the requester's bond if no response was submitted.

### Request Parameters

Expand All @@ -28,5 +28,5 @@ The `SparseMerkleTreeRequestModule` uses a Merkle tree to calculate the root fro

## 4. Gotchas

- The module is supposed to be paired with the root verification module.
- The module is supposed to be paired with [`RootVerificationModule`](../dispute/root_verification_module.md).
- The verifier contract must follow the `ITreeVerifier` interface, otherwise the proposers won't be able to calculate the correct response.
10 changes: 5 additions & 5 deletions docs/src/content/modules/resolution/arbitrator_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ The Arbitrator Module is a part of the dispute resolution system. It allows an e

### Key Methods

- `getStatus(bytes32 _disputeId)`: Returns the arbitration status of a dispute.
- `isValid(bytes32 _disputeId)`: Indicates whether the dispute has been arbitrated.
- `startResolution(bytes32 _disputeId)`: Starts the arbitration process by calling `resolve` on the arbitrator and flags the dispute as `Active`.
- `resolveDispute(bytes32 _disputeId)`: Resolves the dispute by getting the answer from the arbitrator and notifying the oracle.
- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `getStatus`: Returns the arbitration status of a dispute.
- `isValid`: Indicates whether the dispute has been arbitrated.
- `startResolution`: Starts the arbitration process by calling `resolve` on the arbitrator and flags the dispute as `Active`.
- `resolveDispute`: Resolves the dispute by getting the answer from the arbitrator and notifying the oracle.
- `decodeRequestData`: Returns the decoded data for a request.

### Request Parameters

Expand Down
10 changes: 5 additions & 5 deletions docs/src/content/modules/resolution/erc20_resolution_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ The `ERC20ResolutionModule` is a dispute resolution module that decides on the o

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Decodes the request data associated with a given request ID.
- `startResolution(bytes32 _disputeId)`: Starts the resolution process for a given dispute.
- `castVote(bytes32 _requestId, bytes32 _disputeId, uint256 _numberOfVotes)`: Allows a user to cast votes for a dispute.
- `resolveDispute(bytes32 _disputeId)`: Resolves a dispute based on the votes cast.
- `getVoters(bytes32 _disputeId)`: Returns the addresses of the voters for a given dispute.
- `decodeRequestData`: Decodes the request data associated with a given request ID.
- `startResolution`: Starts the resolution process for a given dispute.
- `castVote`: Allows a user to cast votes for a dispute.
- `resolveDispute`: Resolves a dispute based on the votes cast.
- `getVoters`: Returns the addresses of the voters for a given dispute.

### Request Parameters

Expand Down
197 changes: 94 additions & 103 deletions solidity/contracts/modules/dispute/BondedDisputeModule.sol
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});
}
}
Loading

0 comments on commit 28286f9

Please sign in to comment.