Description:
Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"@kleros/dispute-resolver-interface-contract-0.8/contracts/IDisputeResolver.sol": {
"content": "// SPDX-License-Identifier: MIT
/**
* @authors: [@ferittuncer]
* @reviewers: [@mtsalenc*, @hbarcelos*, @unknownunknown1, @MerlinEgalite, @fnanni-0*, @shalzz]
* @auditors: []
* @bounties: []
* @deployments: []
*/
pragma solidity ^0.8.0;
import "@kleros/erc-792/contracts/IArbitrable.sol";
import "@kleros/erc-792/contracts/erc-1497/IEvidence.sol";
import "@kleros/erc-792/contracts/IArbitrator.sol";
/**
* @title This serves as a standard interface for crowdfunded appeals and evidence submission, which aren't a part of the arbitration (erc-792 and erc-1497) standard yet.
This interface is used in Dispute Resolver (resolve.kleros.io).
*/
abstract contract IDisputeResolver is IArbitrable, IEvidence {
string public constant VERSION = "2.0.0"; // Can be used to distinguish between multiple deployed versions, if necessary.
/** @dev Raised when a contribution is made, inside fundAppeal function.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _round The round number the contribution was made to.
* @param ruling Indicates the ruling option which got the contribution.
* @param _contributor Caller of fundAppeal function.
* @param _amount Contribution amount.
*/
event Contribution(uint256 indexed _localDisputeID, uint256 indexed _round, uint256 ruling, address indexed _contributor, uint256 _amount);
/** @dev Raised when a contributor withdraws non-zero value.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _round The round number the withdrawal was made from.
* @param _ruling Indicates the ruling option which contributor gets rewards from.
* @param _contributor The beneficiary of withdrawal.
* @param _reward Total amount of withdrawal, consists of reimbursed deposits plus rewards.
*/
event Withdrawal(uint256 indexed _localDisputeID, uint256 indexed _round, uint256 _ruling, address indexed _contributor, uint256 _reward);
/** @dev To be raised when a ruling option is fully funded for appeal.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _round Number of the round this ruling option was fully funded in.
* @param _ruling The ruling option which just got fully funded.
*/
event RulingFunded(uint256 indexed _localDisputeID, uint256 indexed _round, uint256 indexed _ruling);
/** @dev Maps external (arbitrator side) dispute id to local (arbitrable) dispute id.
* @param _externalDisputeID Dispute id as in arbitrator contract.
* @return localDisputeID Dispute id as in arbitrable contract.
*/
function externalIDtoLocalID(uint256 _externalDisputeID) external virtual returns (uint256 localDisputeID);
/** @dev Returns number of possible ruling options. Valid rulings are [0, return value].
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @return count The number of ruling options.
*/
function numberOfRulingOptions(uint256 _localDisputeID) external view virtual returns (uint256 count);
/** @dev Allows to submit evidence for a given dispute.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _evidenceURI IPFS path to evidence, example: '/ipfs/Qmarwkf7C9RuzDEJNnarT3WZ7kem5bk8DZAzx78acJjMFH/evidence.json'
*/
function submitEvidence(uint256 _localDisputeID, string calldata _evidenceURI) external virtual;
/** @dev Manages contributions and calls appeal function of the specified arbitrator to appeal a dispute. This function lets appeals be crowdfunded.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _ruling The ruling option to which the caller wants to contribute.
* @return fullyFunded True if the ruling option got fully funded as a result of this contribution.
*/
function fundAppeal(uint256 _localDisputeID, uint256 _ruling) external payable virtual returns (bool fullyFunded);
/** @dev Returns appeal multipliers.
* @return winnerStakeMultiplier Winners stake multiplier.
* @return loserStakeMultiplier Losers stake multiplier.
* @return loserAppealPeriodMultiplier Losers appeal period multiplier. The loser is given less time to fund its appeal to defend against last minute appeal funding attacks.
* @return denominator Multiplier denominator in basis points.
*/
function getMultipliers()
external
view
virtual
returns (
uint256 winnerStakeMultiplier,
uint256 loserStakeMultiplier,
uint256 loserAppealPeriodMultiplier,
uint256 denominator
);
/** @dev Allows to withdraw any reimbursable fees or rewards after the dispute gets resolved.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _contributor Beneficiary of withdraw operation.
* @param _round Number of the round that caller wants to execute withdraw on.
* @param _ruling A ruling option that caller wants to execute withdraw on.
* @return sum The amount that is going to be transferred to contributor as a result of this function call.
*/
function withdrawFeesAndRewards(
uint256 _localDisputeID,
address payable _contributor,
uint256 _round,
uint256 _ruling
) external virtual returns (uint256 sum);
/** @dev Allows to withdraw any rewards or reimbursable fees after the dispute gets resolved for all rounds at once.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _contributor Beneficiary of withdraw operation.
* @param _ruling Ruling option that caller wants to execute withdraw on.
*/
function withdrawFeesAndRewardsForAllRounds(
uint256 _localDisputeID,
address payable _contributor,
uint256 _ruling
) external virtual;
/** @dev Returns the sum of withdrawable amount.
* @param _localDisputeID Identifier of a dispute in scope of arbitrable contract. Arbitrator ids can be translated to local ids via externalIDtoLocalID.
* @param _contributor Beneficiary of withdraw operation.
* @param _ruling Ruling option that caller wants to get withdrawable amount from.
* @return sum The total amount available to withdraw.
*/
function getTotalWithdrawableAmount(
uint256 _localDisputeID,
address payable _contributor,
uint256 _ruling
) external view virtual returns (uint256 sum);
}
"
},
"@kleros/erc-792/contracts/erc-1497/IEvidence.sol": {
"content": "/**
* @authors: [@ferittuncer, @hbarcelos]
* @reviewers: []
* @auditors: []
* @bounties: []
* @deployments: []
* SPDX-License-Identifier: MIT
*/
pragma solidity >=0.7;
import "../IArbitrator.sol";
/** @title IEvidence
* ERC-1497: Evidence Standard
*/
interface IEvidence {
/**
* @dev To be emitted when meta-evidence is submitted.
* @param _metaEvidenceID Unique identifier of meta-evidence.
* @param _evidence A link to the meta-evidence JSON.
*/
event MetaEvidence(uint256 indexed _metaEvidenceID, string _evidence);
/**
* @dev To be raised when evidence is submitted. Should point to the resource (evidences are not to be stored on chain due to gas considerations).
* @param _arbitrator The arbitrator of the contract.
* @param _evidenceGroupID Unique identifier of the evidence group the evidence belongs to.
* @param _party The address of the party submiting the evidence. Note that 0x0 refers to evidence not submitted by any party.
* @param _evidence A URI to the evidence JSON file whose name should be its keccak256 hash followed by .json.
*/
event Evidence(
IArbitrator indexed _arbitrator,
uint256 indexed _evidenceGroupID,
address indexed _party,
string _evidence
);
/**
* @dev To be emitted when a dispute is created to link the correct meta-evidence to the disputeID.
* @param _arbitrator The arbitrator of the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _metaEvidenceID Unique identifier of meta-evidence.
* @param _evidenceGroupID Unique identifier of the evidence group that is linked to this dispute.
*/
event Dispute(
IArbitrator indexed _arbitrator,
uint256 indexed _disputeID,
uint256 _metaEvidenceID,
uint256 _evidenceGroupID
);
}
"
},
"@kleros/erc-792/contracts/IArbitrable.sol": {
"content": "/**
* @authors: [@ferittuncer, @hbarcelos]
* @reviewers: [@remedcu*]
* @auditors: []
* @bounties: []
* @deployments: []
* SPDX-License-Identifier: MIT
*/
pragma solidity >=0.7;
import "./IArbitrator.sol";
/**
* @title IArbitrable
* Arbitrable interface.
* When developing arbitrable contracts, we need to:
* - Define the action taken when a ruling is received by the contract.
* - Allow dispute creation. For this a function must call arbitrator.createDispute{value: _fee}(_choices,_extraData);
*/
interface IArbitrable {
/**
* @dev To be raised when a ruling is given.
* @param _arbitrator The arbitrator giving the ruling.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling The ruling which was given.
*/
event Ruling(IArbitrator indexed _arbitrator, uint256 indexed _disputeID, uint256 _ruling);
/**
* @dev Give a ruling for a dispute. Must be called by the arbitrator.
* The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
*/
function rule(uint256 _disputeID, uint256 _ruling) external;
}
"
},
"@kleros/erc-792/contracts/IArbitrator.sol": {
"content": "/**
* @authors: [@ferittuncer, @hbarcelos]
* @reviewers: [@remedcu*]
* @auditors: []
* @bounties: []
* @deployments: []
* SPDX-License-Identifier: MIT
*/
pragma solidity >=0.7;
import "./IArbitrable.sol";
/**
* @title Arbitrator
* Arbitrator abstract contract.
* When developing arbitrator contracts we need to:
* - Define the functions for dispute creation (createDispute) and appeal (appeal). Don't forget to store the arbitrated contract and the disputeID (which should be unique, may nbDisputes).
* - Define the functions for cost display (arbitrationCost and appealCost).
* - Allow giving rulings. For this a function must call arbitrable.rule(disputeID, ruling).
*/
interface IArbitrator {
enum DisputeStatus {Waiting, Appealable, Solved}
/**
* @dev To be emitted when a dispute is created.
* @param _disputeID ID of the dispute.
* @param _arbitrable The contract which created the dispute.
*/
event DisputeCreation(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
/**
* @dev To be emitted when a dispute can be appealed.
* @param _disputeID ID of the dispute.
* @param _arbitrable The contract which created the dispute.
*/
event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
/**
* @dev To be emitted when the current ruling is appealed.
* @param _disputeID ID of the dispute.
* @param _arbitrable The contract which created the dispute.
*/
event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
/**
* @dev Create a dispute. Must be called by the arbitrable contract.
* Must be paid at least arbitrationCost(_extraData).
* @param _choices Amount of choices the arbitrator can make in this dispute.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return disputeID ID of the dispute created.
*/
function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID);
/**
* @dev Compute the cost of arbitration. It is recommended not to increase it often, as it can be highly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return cost Amount to be paid.
*/
function arbitrationCost(bytes calldata _extraData) external view returns (uint256 cost);
/**
* @dev Appeal a ruling. Note that it has to be called before the arbitrator contract calls rule.
* @param _disputeID ID of the dispute to be appealed.
* @param _extraData Can be used to give extra info on the appeal.
*/
function appeal(uint256 _disputeID, bytes calldata _extraData) external payable;
/**
* @dev Compute the cost of appeal. It is recommended not to increase it often, as it can be higly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
* @param _disputeID ID of the dispute to be appealed.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return cost Amount to be paid.
*/
function appealCost(uint256 _disputeID, bytes calldata _extraData) external view returns (uint256 cost);
/**
* @dev Compute the start and end of the dispute's current or next appeal period, if possible. If not known or appeal is impossible: should return (0, 0).
* @param _disputeID ID of the dispute.
* @return start The start of the period.
* @return end The end of the period.
*/
function appealPeriod(uint256 _disputeID) external view returns (uint256 start, uint256 end);
/**
* @dev Return the status of a dispute.
* @param _disputeID ID of the dispute to rule.
* @return status The status of the dispute.
*/
function disputeStatus(uint256 _disputeID) external view returns (DisputeStatus status);
/**
* @dev Return the current ruling of a dispute. This is useful for parties to know if they should appeal.
* @param _disputeID ID of the dispute.
* @return ruling The ruling which has been given or the one which will be given if there is no appeal.
*/
function currentRuling(uint256 _disputeID) external view returns (uint256 ruling);
}
"
},
"src/0.8/interfaces/IArbitrationProxies.sol": {
"content": "// SPDX-License-Identifier: MIT\r
pragma solidity 0.8.25;\r
\r
import {IArbitrable} from "@kleros/erc-792/contracts/IArbitrable.sol";\r
import {IEvidence} from "@kleros/erc-792/contracts/erc-1497/IEvidence.sol";\r
import {IRealitio} from "./IRealitio.sol";\r
\r
interface IHomeArbitrationProxy {\r
/**\r
* @notice To be emitted when the Realitio contract has been notified of an arbitration request.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
* @param _maxPrevious The maximum value of the previous bond for the question.\r
*/\r
event RequestNotified(bytes32 indexed _questionID, address indexed _requester, uint256 _maxPrevious);\r
\r
/**\r
* @notice To be emitted when arbitration request is rejected.\r
* @dev This can happen if the current bond for the question is higher than maxPrevious\r
* or if the question is already finalized.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
* @param _maxPrevious The maximum value of the current bond for the question.\r
* @param _reason The reason why the request was rejected.\r
*/\r
event RequestRejected(\r
bytes32 indexed _questionID,\r
address indexed _requester,\r
uint256 _maxPrevious,\r
string _reason\r
);\r
\r
/**\r
* @notice To be emitted when the arbitration request acknowledgement is sent to the Foreign Chain.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
event RequestAcknowledged(bytes32 indexed _questionID, address indexed _requester);\r
\r
/**\r
* @notice To be emitted when the arbitration request is canceled.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
event RequestCanceled(bytes32 indexed _questionID, address indexed _requester);\r
\r
/**\r
* @notice To be emitted when the dispute could not be created on the Foreign Chain.\r
* @dev This will happen if the arbitration fee increases in between the arbitration request and acknowledgement.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
event ArbitrationFailed(bytes32 indexed _questionID, address indexed _requester);\r
\r
/**\r
* @notice To be emitted when receiving the answer from the arbitrator.\r
* @param _questionID The ID of the question.\r
* @param _answer The answer from the arbitrator.\r
*/\r
event ArbitratorAnswered(bytes32 indexed _questionID, bytes32 _answer);\r
\r
/**\r
* @notice To be emitted when reporting the arbitrator answer to Realitio.\r
* @param _questionID The ID of the question.\r
*/\r
event ArbitrationFinished(bytes32 indexed _questionID);\r
\r
/**\r
* @dev Receives the requested arbitration for a question. TRUSTED.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
* @param _maxPrevious The maximum value of the current bond for the question. The arbitration request will get rejected if the current bond is greater than _maxPrevious. If set to 0, _maxPrevious is ignored.\r
*/\r
function receiveArbitrationRequest(bytes32 _questionID, address _requester, uint256 _maxPrevious) external;\r
\r
/**\r
* @notice Handles arbitration request after it has been notified to Realitio for a given question.\r
* @dev This method exists because `receiveArbitrationRequest` is called by\r
* the bridge and cannot send messages back to it.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function handleNotifiedRequest(bytes32 _questionID, address _requester) external;\r
\r
/**\r
* @notice Handles arbitration request after it has been rejected.\r
* @dev This method exists because `receiveArbitrationRequest` is called by\r
* the bridge and cannot send messages back to it.\r
* Reasons why the request might be rejected:\r
* - The question does not exist\r
* - The question was not answered yet\r
* - The quesiton bond value changed while the arbitration was being requested\r
* - Another request was already accepted\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function handleRejectedRequest(bytes32 _questionID, address _requester) external;\r
\r
/**\r
* @notice Receives a failed attempt to request arbitration. TRUSTED.\r
* @dev Currently this can happen only if the arbitration cost increased.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function receiveArbitrationFailure(bytes32 _questionID, address _requester) external;\r
\r
/**\r
* @notice Receives the answer to a specified question. TRUSTED.\r
* @param _questionID The ID of the question.\r
* @param _answer The answer from the arbitrator.\r
*/\r
function receiveArbitrationAnswer(bytes32 _questionID, bytes32 _answer) external;\r
\r
/** @notice Provides a string of json-encoded metadata with the following properties:\r
- tos: A URI representing the location of a terms-of-service document for the arbitrator.\r
- template_hashes: An array of hashes of templates supported by the arbitrator. If you have a numerical ID for a template registered with Reality.eth, you can look up this hash by calling the Reality.eth template_hashes() function.\r
* @dev Template_hashes won't be used by this home proxy. \r
*/\r
function metadata() external view returns (string calldata);\r
\r
/**\r
* @notice Returns the address of Reality instance.\r
* @return Realitio address.\r
*/\r
function realitio() external view returns (IRealitio);\r
}\r
\r
interface IForeignArbitrationProxy {\r
/**\r
* @notice Should be emitted when the arbitration is requested.\r
* @param _questionID The ID of the question with the request for arbitration.\r
* @param _requester The address of the arbitration requester.\r
* @param _maxPrevious The maximum value of the current bond for the question. The arbitration request will get rejected if the current bond is greater than _maxPrevious. If set to 0, _maxPrevious is ignored.\r
*/\r
event ArbitrationRequested(bytes32 indexed _questionID, address indexed _requester, uint256 _maxPrevious);\r
\r
/**\r
* @notice Should be emitted when the dispute is created.\r
* @param _questionID The ID of the question with the request for arbitration.\r
* @param _requester The address of the arbitration requester.\r
* @param _disputeID The ID of the dispute.\r
*/\r
event ArbitrationCreated(bytes32 indexed _questionID, address indexed _requester, uint256 indexed _disputeID);\r
\r
/**\r
* @notice Should be emitted when the arbitration is canceled by the Home Chain.\r
* @param _questionID The ID of the question with the request for arbitration.\r
* @param _requester The address of the arbitration requester.\r
*/\r
event ArbitrationCanceled(bytes32 indexed _questionID, address indexed _requester);\r
\r
/**\r
* @notice Should be emitted when the dispute could not be created.\r
* @dev This will happen if there is an increase in the arbitration fees\r
* between the time the arbitration is made and the time it is acknowledged.\r
* @param _questionID The ID of the question with the request for arbitration.\r
* @param _requester The address of the arbitration requester.\r
*/\r
event ArbitrationFailed(bytes32 indexed _questionID, address indexed _requester);\r
\r
/**\r
* @notice Should be emitted when the ruling is relayed to home proxy manually. Some implementations may not emit this event.\r
* @param _questionID The ID of the question with the ruling to relay.\r
* @param _ruling Ruling converted into Realitio format.\r
*/\r
event RulingRelayed(bytes32 _questionID, bytes32 _ruling);\r
\r
/**\r
* @notice Requests arbitration for the given question and contested answer.\r
* @param _questionID The ID of the question.\r
* @param _maxPrevious The maximum value of the current bond for the question. The arbitration request will get rejected if the current bond is greater than _maxPrevious. If set to 0, _maxPrevious is ignored.\r
*/\r
function requestArbitration(bytes32 _questionID, uint256 _maxPrevious) external payable;\r
\r
/**\r
* @notice Receives the acknowledgement of the arbitration request for the given question and requester. TRUSTED.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function receiveArbitrationAcknowledgement(bytes32 _questionID, address _requester) external;\r
\r
/**\r
* @notice Receives the cancelation of the arbitration request for the given question and requester. TRUSTED.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function receiveArbitrationCancelation(bytes32 _questionID, address _requester) external;\r
\r
/**\r
* @notice Cancels the arbitration in case the dispute could not be created.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function handleFailedDisputeCreation(bytes32 _questionID, address _requester) external payable;\r
\r
/**\r
* @notice Gets the fee to create a dispute.\r
* @param _questionID the ID of the question.\r
* @return The fee to create a dispute.\r
*/\r
function getDisputeFee(bytes32 _questionID) external view returns (uint256);\r
\r
/**\r
* @notice Returns the address of the home proxy.\r
* @return Home proxy address.\r
*/\r
function homeProxy() external view returns (address);\r
\r
/**\r
* @notice Returns the creation block of the dispute.\r
* @param _disputeID the ID of the dispute.\r
* @return Block number of dispute creation.\r
*/\r
function arbitrationCreatedBlock(uint256 _disputeID) external view returns (uint256);\r
}\r
"
},
"src/0.8/interfaces/IRealitio.sol": {
"content": "/* solhint-disable var-name-mixedcase */\r
// SPDX-License-Identifier: MIT\r
\r
/**\r
* Interface of https://github.com/RealityETH/reality-eth-monorepo/blob/main/packages/contracts/flat/RealityETH-3.0.sol.\r
* @reviewers: [@hbarcelos, @fnanni-0, @nix1g, @unknownunknown1, @ferittuncer, @jaybuidl]\r
* @auditors: []\r
* @bounties: []\r
* @deployments: []\r
*/\r
\r
pragma solidity 0.8.25;\r
\r
interface IRealitio {\r
event LogNewAnswer(\r
bytes32 answer,\r
bytes32 indexed question_id,\r
bytes32 history_hash,\r
address indexed user,\r
uint256 bond,\r
uint256 ts,\r
bool is_commitment\r
);\r
\r
event LogNewTemplate(uint256 indexed template_id, address indexed user, string question_text);\r
\r
event LogNewQuestion(\r
bytes32 indexed question_id,\r
address indexed user,\r
uint256 template_id,\r
string question,\r
bytes32 indexed content_hash,\r
address arbitrator,\r
uint32 timeout,\r
uint32 opening_ts,\r
uint256 nonce,\r
uint256 created\r
);\r
\r
/**\r
* @dev The arbitrator contract is trusted to only call this if they've been paid, and tell us who paid them.\r
* @notice Notify the contract that the arbitrator has been paid for a question, freezing it pending their decision.\r
* @param question_id The ID of the question.\r
* @param requester The account that requested arbitration.\r
* @param max_previous If specified, reverts if a bond higher than this was submitted after you sent your transaction.\r
*/\r
function notifyOfArbitrationRequest(bytes32 question_id, address requester, uint256 max_previous) external;\r
\r
/**\r
* @notice Cancel a previously-requested arbitration and extend the timeout\r
* @dev Useful when doing arbitration across chains that can't be requested atomically\r
* @param question_id The ID of the question\r
*/\r
function cancelArbitration(bytes32 question_id) external;\r
\r
/**\r
* @notice Submit the answer for a question, for use by the arbitrator, working out the appropriate winner based on the last answer details.\r
* @dev Doesn't require (or allow) a bond.\r
* @param question_id The ID of the question\r
* @param answer The answer, encoded into bytes32\r
* @param payee_if_wrong The account to be credited as winner if the last answer given is wrong, usually the account that paid the arbitrator\r
* @param last_history_hash The history hash before the final one\r
* @param last_answer_or_commitment_id The last answer given, or the commitment ID if it was a commitment.\r
* @param last_answerer The address that supplied the last answer\r
*/\r
function assignWinnerAndSubmitAnswerByArbitrator(\r
bytes32 question_id,\r
bytes32 answer,\r
address payee_if_wrong,\r
bytes32 last_history_hash,\r
bytes32 last_answer_or_commitment_id,\r
address last_answerer\r
) external;\r
}\r
"
},
"src/0.8/interfaces/optimism/ICrossDomainMessenger.sol": {
"content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity 0.8.25;\r
// @dev https://github.com/ethereum-optimism/optimism/blob/v1.7.7/packages/contracts-bedrock/src/universal/CrossDomainMessenger.sol\r
interface ICrossDomainMessenger {\r
function sendMessage(address _target, bytes calldata _message, uint32 _gasLimit) external;\r
\r
function xDomainMessageSender() external view returns (address);\r
}\r
"
},
"src/0.8/libraries/SafeSend.sol": {
"content": "/**\r
* @authors: [@andreimvp]\r
* @reviewers: [@divyangchauhan, @wadader, @fcanela, @unknownunknown1]\r
* @auditors: []\r
* @bounties: []\r
* SPDX-License-Identifier: MIT\r
*/\r
\r
pragma solidity 0.8.25;\r
\r
interface WethLike {\r
function deposit() external payable;\r
\r
function transfer(address dst, uint256 wad) external;\r
}\r
\r
library SafeSend {\r
function safeSend(address payable _to, uint256 _value, address _wethLike) internal {\r
if (_to.send(_value)) return;\r
\r
WethLike(_wethLike).deposit{value: _value}();\r
WethLike(_wethLike).transfer(_to, _value);\r
}\r
}\r
"
},
"src/0.8/RealitioForeignProxyOptimism.sol": {
"content": "// SPDX-License-Identifier: MIT\r
\r
/**\r
* @authors: [@anmol-dhiman, @unknownunknown1]\r
* @reviewers: [@jaybuidl, @kokialgo]\r
* @auditors: []\r
* @bounties: []\r
* @deployments: []\r
*/\r
\r
pragma solidity 0.8.25;\r
\r
import {IDisputeResolver, IArbitrator} from "@kleros/dispute-resolver-interface-contract-0.8/contracts/IDisputeResolver.sol";\r
import {IForeignArbitrationProxy, IHomeArbitrationProxy} from "./interfaces/IArbitrationProxies.sol";\r
import {ICrossDomainMessenger} from "./interfaces/optimism/ICrossDomainMessenger.sol";\r
import {SafeSend} from "./libraries/SafeSend.sol";\r
\r
/**\r
* @title Arbitration proxy for Realitio on foreign chain (eg. mainnet).\r
* @dev https://docs.optimism.io/app-developers/bridging/messaging\r
*/\r
contract RealitioForeignProxyOptimism is IForeignArbitrationProxy, IDisputeResolver {\r
using SafeSend for address payable;\r
\r
/* Constants */\r
\r
// Gas limit of the transaction call on L2. Note that setting value too high results in high gas estimation fee (tested on Sepolia).\r
// Also note that chosen value is high enough to cover gas spendings.\r
uint32 public constant MIN_GAS_LIMIT = 200000;\r
\r
uint256 public constant NUMBER_OF_CHOICES_FOR_ARBITRATOR = type(uint256).max; // The number of choices for the arbitrator.\r
uint256 public constant REFUSE_TO_ARBITRATE_REALITIO = type(uint256).max; // Constant that represents "Refuse to rule" in realitio format.\r
uint256 public constant MULTIPLIER_DIVISOR = 10000; // Divisor parameter for multipliers.\r
uint256 public constant META_EVIDENCE_ID = 0; // The ID of the MetaEvidence for disputes.\r
\r
/* Storage */\r
\r
enum Status {\r
None,\r
Requested,\r
Created,\r
Ruled,\r
Relayed,\r
Failed\r
}\r
\r
struct ArbitrationRequest {\r
Status status; // Status of the arbitration.\r
uint248 deposit; // The deposit paid by the requester at the time of the arbitration.\r
uint256 disputeID; // The ID of the dispute in arbitrator contract.\r
uint256 answer; // The answer given by the arbitrator.\r
Round[] rounds; // Tracks each appeal round of a dispute.\r
}\r
\r
struct DisputeDetails {\r
uint256 arbitrationID; // The ID of the arbitration.\r
address requester; // The address of the requester who managed to go through with the arbitration request.\r
}\r
\r
// Round struct stores the contributions made to particular answers.\r
struct Round {\r
mapping(uint256 => uint256) paidFees; // Tracks the fees paid in this round in the form paidFees[answer].\r
mapping(uint256 => bool) hasPaid; // True if the fees for this particular answer have been fully paid in the form hasPaid[answer].\r
mapping(address => mapping(uint256 => uint256)) contributions; // Maps contributors to their contributions for each answer in the form contributions[address][answer].\r
uint256 feeRewards; // Sum of reimbursable appeal fees available to the parties that made contributions to the answer that ultimately wins a dispute.\r
uint256[] fundedAnswers; // Stores the answer choices that are fully funded.\r
}\r
\r
address public immutable wNative; // Address of wrapped version of the chain's native currency. WETH-like.\r
\r
// contract for L1 -> L2 communication\r
ICrossDomainMessenger public immutable messenger;\r
address public immutable homeProxy; // Proxy on L2.\r
\r
IArbitrator public immutable arbitrator; // The address of the arbitrator. TRUSTED.\r
bytes public arbitratorExtraData; // The extra data used to raise a dispute in the arbitrator.\r
\r
// Multipliers are in basis points.\r
uint256 public immutable winnerMultiplier; // Multiplier for calculating the appeal fee that must be paid for the answer that was chosen by the arbitrator in the previous round.\r
uint256 public immutable loserMultiplier; // Multiplier for calculating the appeal fee that must be paid for the answer that the arbitrator didn't rule for in the previous round.\r
uint256 public immutable loserAppealPeriodMultiplier; // Multiplier for calculating the duration of the appeal period for the loser, in basis points.\r
\r
mapping(uint256 => mapping(address => ArbitrationRequest)) public arbitrationRequests; // Maps arbitration ID to its data. arbitrationRequests[uint(questionID)][requester].\r
mapping(uint256 => DisputeDetails) public disputeIDToDisputeDetails; // Maps external dispute ids to local arbitration ID and requester who was able to complete the arbitration request.\r
mapping(uint256 => bool) public arbitrationIDToDisputeExists; // Whether a dispute has already been created for the given arbitration ID or not.\r
\r
mapping(uint256 => address) public arbitrationIDToRequester; // Maps arbitration ID to the requester who was able to complete the arbitration request.\r
mapping(uint256 => uint256) public arbitrationCreatedBlock; // Block of dispute creation.\r
\r
modifier onlyHomeProxy() {\r
require(msg.sender == address(messenger), "NOT_MESSENGER");\r
require(messenger.xDomainMessageSender() == homeProxy, "Can only be called by Home proxy");\r
_;\r
}\r
\r
/**\r
* @notice Creates an arbitration proxy on the foreign chain (L1).\r
* @param _wNative The address of the wrapped version of the native currency.\r
* @param _arbitrator Arbitrator contract address.\r
* @param _arbitratorExtraData The extra data used to raise a dispute in the arbitrator.\r
* @param _metaEvidence The URI of the meta evidence file.\r
* @param _winnerMultiplier Multiplier for calculating the appeal cost of the winning answer.\r
* @param _loserMultiplier Multiplier for calculating the appeal cost of the losing answer.\r
* @param _loserAppealPeriodMultiplier Multiplier for calculating the appeal period for the losing answer.\r
* @param _homeProxy Proxy on L2.\r
* @param _messenger contract for L1 -> L2 tx\r
*/\r
constructor(\r
address _wNative,\r
IArbitrator _arbitrator,\r
bytes memory _arbitratorExtraData,\r
string memory _metaEvidence,\r
uint256 _winnerMultiplier,\r
uint256 _loserMultiplier,\r
uint256 _loserAppealPeriodMultiplier,\r
address _homeProxy,\r
address _messenger\r
) {\r
wNative = _wNative;\r
arbitrator = _arbitrator;\r
arbitratorExtraData = _arbitratorExtraData;\r
winnerMultiplier = _winnerMultiplier;\r
loserMultiplier = _loserMultiplier;\r
loserAppealPeriodMultiplier = _loserAppealPeriodMultiplier;\r
homeProxy = _homeProxy;\r
messenger = ICrossDomainMessenger(_messenger);\r
\r
emit MetaEvidence(META_EVIDENCE_ID, _metaEvidence);\r
}\r
\r
/*//////////////////////////////////////////////////////////////\r
REALITIO LOGIC\r
//////////////////////////////////////////////////////////////*/\r
\r
/**\r
* @notice Requests arbitration for the given question and contested answer.\r
* This version of the function uses recommended bridging parameters.\r
* Note that the signature of this function can't be changed as it's required by Reality UI.\r
* @param _questionID The ID of the question.\r
* @param _maxPrevious The maximum value of the current bond for the question. The arbitration request will get rejected if the current bond is greater than _maxPrevious. If set to 0, _maxPrevious is ignored.\r
*/\r
function requestArbitration(bytes32 _questionID, uint256 _maxPrevious) external payable override {\r
_requestArbitration(_questionID, _maxPrevious, MIN_GAS_LIMIT);\r
}\r
\r
/**\r
* @notice Requests arbitration for the given question and contested answer.\r
* This function is to be used if the bridging with default parameters fail.\r
* @param _questionID The ID of the question.\r
* @param _maxPrevious The maximum value of the current bond for the question. The arbitration request will get rejected if the current bond is greater than _maxPrevious. If set to 0, _maxPrevious is ignored.\r
* @param _gasLimit Gas limit for the L2 transaction.\r
*/\r
function requestArbitrationCustomParameters(\r
bytes32 _questionID,\r
uint256 _maxPrevious,\r
uint32 _gasLimit\r
) external payable {\r
_requestArbitration(_questionID, _maxPrevious, _gasLimit);\r
}\r
\r
/**\r
* @notice Receives the acknowledgement of the arbitration request for the given question and requester. TRUSTED.\r
* @param _questionID The ID of the question.\r
* @param _requester The requester.\r
*/\r
function receiveArbitrationAcknowledgement(\r
bytes32 _questionID,\r
address _requester\r
) external override onlyHomeProxy {\r
uint256 arbitrationID = uint256(_questionID);\r
ArbitrationRequest storage arbitration = arbitrationRequests[arbitrationID][_requester];\r
require(arbitration.status == Status.Requested, "Invalid arbitration status");\r
\r
// Arbitration cost can possibly change between when the request has been made and received, so evaluate once more.\r
uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);\r
if (arbitration.deposit >= arbitrationCost) {\r
try\r
arbitrator.createDispute{value: arbitrationCost}(NUMBER_OF_CHOICES_FOR_ARBITRATOR, arbitratorExtraData)\r
returns (uint256 disputeID) {\r
DisputeDetails storage disputeDetails = disputeIDToDisputeDetails[disputeID];\r
disputeDetails.arbitrationID = arbitrationID;\r
disputeDetails.requester = _requester;\r
\r
arbitrationIDToDisputeExists[arbitrationID] = true;\r
arbitrationIDToRequester[arbitrationID] = _requester;\r
arbitrationCreatedBlock[disputeID] = block.number;\r
\r
// At this point, arbitration.deposit is guaranteed to be greater than or equal to the arbitration cost.\r
uint256 remainder = arbitration.deposit - arbitrationCost;\r
\r
arbitration.status = Status.Created;\r
arbitration.deposit = 0;\r
arbitration.disputeID = disputeID;\r
arbitration.rounds.push();\r
\r
if (remainder > 0) {\r
payable(_requester).safeSend(remainder, wNative);\r
}\r
\r
emit ArbitrationCreated(_questionID, _requester, disputeID);\r
emit Dispute(arbitrator, disputeID, META_EVIDENCE_ID, arbitrationID);\r
} catch {\r
arbitration.status = Status.Failed;\r
emit ArbitrationFailed(_questionID, _requester);\r
}\r
} else {\r
arbitration.status = Status.Failed;\r
emit ArbitrationFailed(_questionID, _requester);\r
}\r
}\r
\r
/**\r
* @notice Receives the cancelation of the arbitration request for the given question and requester. TRUSTED.\r
* @param _questionID The ID of the question.\r
* @param _requester The requester.\r
*/\r
function receiveArbitrationCancelation(bytes32 _questionID, address _requester) external override onlyHomeProxy {\r
uint256 arbitrationID = uint256(_questionID);\r
ArbitrationRequest storage arbitration = arbitrationRequests[arbitrationID][_requester];\r
require(arbitration.status == Status.Requested, "Invalid arbitration status");\r
uint256 deposit = arbitration.deposit;\r
\r
delete arbitrationRequests[arbitrationID][_requester];\r
payable(_requester).safeSend(deposit, wNative);\r
\r
emit ArbitrationCanceled(_questionID, _requester);\r
}\r
\r
/**\r
* @notice Cancels the arbitration in case the dispute could not be created.\r
* This version of the function uses recommended bridging parameters.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function handleFailedDisputeCreation(bytes32 _questionID, address _requester) external payable override {\r
_handleFailedDisputeCreation(_questionID, _requester, MIN_GAS_LIMIT);\r
}\r
\r
/**\r
* @notice Cancels the arbitration in case the dispute could not be created.\r
* This function is to be used if the bridging with default parameters fail.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
* @param _gasLimit Gas limit for the L2 transaction.\r
*/\r
function handleFailedDisputeCreationCustomParameters(\r
bytes32 _questionID,\r
address _requester,\r
uint32 _gasLimit\r
) external payable {\r
_handleFailedDisputeCreation(_questionID, _requester, _gasLimit);\r
}\r
\r
// ********************************* //\r
// * Appeals and arbitration * //\r
// ********************************* //\r
\r
/**\r
* @notice Takes up to the total amount required to fund an answer. Reimburses the rest. Creates an appeal if at least two answers are funded.\r
* @param _arbitrationID The ID of the arbitration, which is questionID cast into uint256.\r
* @param _answer One of the possible rulings the arbitrator can give that the funder considers to be the correct answer to the question.\r
* Note that the answer has Kleros denomination, meaning that it has '+1' offset compared to Realitio format.\r
* Also note that '0' answer can be funded.\r
* @return Whether the answer was fully funded or not.\r
*/\r
function fundAppeal(uint256 _arbitrationID, uint256 _answer) external payable override returns (bool) {\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][\r
arbitrationIDToRequester[_arbitrationID]\r
];\r
require(arbitration.status == Status.Created, "No dispute to appeal.");\r
\r
uint256 disputeID = arbitration.disputeID;\r
(uint256 appealPeriodStart, uint256 appealPeriodEnd) = arbitrator.appealPeriod(disputeID);\r
require(block.timestamp >= appealPeriodStart && block.timestamp < appealPeriodEnd, "Appeal period is over.");\r
\r
uint256 multiplier;\r
{\r
uint256 winner = arbitrator.currentRuling(disputeID);\r
if (winner == _answer) {\r
multiplier = winnerMultiplier;\r
} else {\r
require(\r
block.timestamp - appealPeriodStart <\r
((appealPeriodEnd - appealPeriodStart) * (loserAppealPeriodMultiplier)) / MULTIPLIER_DIVISOR,\r
"Appeal period is over for loser"\r
);\r
multiplier = loserMultiplier;\r
}\r
}\r
\r
uint256 lastRoundID = arbitration.rounds.length - 1;\r
Round storage round = arbitration.rounds[lastRoundID];\r
require(!round.hasPaid[_answer], "Appeal fee is already paid.");\r
uint256 appealCost = arbitrator.appealCost(disputeID, arbitratorExtraData);\r
uint256 totalCost = appealCost + ((appealCost * multiplier) / MULTIPLIER_DIVISOR);\r
\r
// Take up to the amount necessary to fund the current round at the current costs.\r
uint256 contribution;\r
if (totalCost <= round.paidFees[_answer]) {\r
contribution = 0;\r
} else {\r
contribution = totalCost - (round.paidFees[_answer]) > msg.value\r
? msg.value\r
: totalCost - (round.paidFees[_answer]);\r
emit Contribution(_arbitrationID, lastRoundID, _answer, msg.sender, contribution);\r
}\r
\r
round.contributions[msg.sender][_answer] += contribution;\r
round.paidFees[_answer] += contribution;\r
if (round.paidFees[_answer] >= totalCost) {\r
round.feeRewards += round.paidFees[_answer];\r
round.fundedAnswers.push(_answer);\r
round.hasPaid[_answer] = true;\r
emit RulingFunded(_arbitrationID, lastRoundID, _answer);\r
}\r
\r
if (round.fundedAnswers.length > 1) {\r
// At least two sides are fully funded.\r
arbitration.rounds.push();\r
\r
round.feeRewards = round.feeRewards - appealCost;\r
arbitrator.appeal{value: appealCost}(disputeID, arbitratorExtraData);\r
}\r
\r
if (msg.value - contribution > 0) payable(msg.sender).safeSend(msg.value - contribution, wNative); // Sending extra value back to contributor.\r
return round.hasPaid[_answer];\r
}\r
\r
/**\r
* @notice Sends the fee stake rewards and reimbursements proportional to the contributions made to the winner of a dispute. Reimburses contributions if there is no winner.\r
* @param _arbitrationID The ID of the arbitration.\r
* @param _beneficiary The address to send reward to.\r
* @param _round The round from which to withdraw.\r
* @param _answer The answer to query the reward from.\r
* Note that the `_answer` has Kleros denomination, meaning that it has '+1' offset compared to Realitio format.\r
* @return reward The withdrawn amount.\r
*/\r
function withdrawFeesAndRewards(\r
uint256 _arbitrationID,\r
address payable _beneficiary,\r
uint256 _round,\r
uint256 _answer\r
) public override returns (uint256 reward) {\r
address requester = arbitrationIDToRequester[_arbitrationID];\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][requester];\r
Round storage round = arbitration.rounds[_round];\r
require(arbitration.status == Status.Ruled || arbitration.status == Status.Relayed, "Dispute not resolved");\r
// Allow to reimburse if funding of the round was unsuccessful.\r
if (!round.hasPaid[_answer]) {\r
reward = round.contributions[_beneficiary][_answer];\r
} else if (!round.hasPaid[arbitration.answer]) {\r
// Reimburse unspent fees proportionally if the ultimate winner didn't pay appeal fees fully.\r
// Note that if only one side is funded it will become a winner and this part of the condition won't be reached.\r
reward = round.fundedAnswers.length > 1\r
? (round.contributions[_beneficiary][_answer] * round.feeRewards) /\r
(round.paidFees[round.fundedAnswers[0]] + round.paidFees[round.fundedAnswers[1]])\r
: 0;\r
} else if (arbitration.answer == _answer) {\r
uint256 paidFees = round.paidFees[_answer];\r
// Reward the winner.\r
reward = paidFees > 0 ? (round.contributions[_beneficiary][_answer] * round.feeRewards) / paidFees : 0;\r
}\r
\r
if (reward != 0) {\r
round.contributions[_beneficiary][_answer] = 0;\r
_beneficiary.safeSend(reward, wNative);\r
emit Withdrawal(_arbitrationID, _round, _answer, _beneficiary, reward);\r
}\r
}\r
\r
/**\r
* @notice Allows to withdraw any rewards or reimbursable fees for all rounds at once.\r
* @dev This function is O(n) where n is the total number of rounds. Arbitration cost of subsequent rounds is `A(n) = 2A(n-1) + 1`.\r
* So because of this exponential growth of costs, you can assume n is less than 10 at all times.\r
* @param _arbitrationID The ID of the arbitration.\r
* @param _beneficiary The address that made contributions.\r
* @param _contributedTo Answer that received contributions from contributor.\r
* Note that the `_contributedTo` answer has Kleros denomination, meaning that it has '+1' offset compared to Realitio format.\r
*/\r
function withdrawFeesAndRewardsForAllRounds(\r
uint256 _arbitrationID,\r
address payable _beneficiary,\r
uint256 _contributedTo\r
) external override {\r
address requester = arbitrationIDToRequester[_arbitrationID];\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][requester];\r
\r
uint256 numberOfRounds = arbitration.rounds.length;\r
for (uint256 roundNumber = 0; roundNumber < numberOfRounds; roundNumber++) {\r
withdrawFeesAndRewards(_arbitrationID, _beneficiary, roundNumber, _contributedTo);\r
}\r
}\r
\r
/**\r
* @notice Allows to submit evidence for a particular question.\r
* @param _arbitrationID The ID of the arbitration related to the question.\r
* @param _evidenceURI Link to evidence.\r
*/\r
function submitEvidence(uint256 _arbitrationID, string calldata _evidenceURI) external override {\r
emit Evidence(arbitrator, _arbitrationID, msg.sender, _evidenceURI);\r
}\r
\r
/**\r
* @notice Rules a specified dispute. Can only be called by the arbitrator.\r
* @dev Accounts for the situation where the winner loses a case due to paying less appeal fees than expected.\r
* @param _disputeID The ID of the dispute in the ERC792 arbitrator.\r
* @param _ruling The ruling given by the arbitrator.\r
*/\r
function rule(uint256 _disputeID, uint256 _ruling) external override {\r
DisputeDetails storage disputeDetails = disputeIDToDisputeDetails[_disputeID];\r
uint256 arbitrationID = disputeDetails.arbitrationID;\r
address requester = disputeDetails.requester;\r
\r
ArbitrationRequest storage arbitration = arbitrationRequests[arbitrationID][requester];\r
require(msg.sender == address(arbitrator), "Only arbitrator allowed");\r
require(arbitration.status == Status.Created, "Invalid arbitration status");\r
uint256 finalRuling = _ruling;\r
\r
// If one side paid its fees, the ruling is in its favor. Note that if the other side had also paid, an appeal would have been created.\r
Round storage round = arbitration.rounds[arbitration.rounds.length - 1];\r
if (round.fundedAnswers.length == 1) finalRuling = round.fundedAnswers[0];\r
\r
arbitration.answer = finalRuling;\r
arbitration.status = Status.Ruled;\r
\r
emit Ruling(arbitrator, _disputeID, finalRuling);\r
}\r
\r
/**\r
* @notice Relays the ruling to home proxy.\r
* This version of the function uses recommended bridging parameters.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
*/\r
function relayRule(bytes32 _questionID, address _requester) external {\r
_relayRule(_questionID, _requester, MIN_GAS_LIMIT);\r
}\r
\r
/**\r
* @notice Relays the ruling to home proxy.\r
* This function is to be used if the bridging with default parameters fail.\r
* @param _questionID The ID of the question.\r
* @param _requester The address of the arbitration requester.\r
* @param _gasLimit Gas limit for the L2 transaction.\r
*/\r
function relayRuleCustomParameters(bytes32 _questionID, address _requester, uint32 _gasLimit) external {\r
_relayRule(_questionID, _requester, _gasLimit);\r
}\r
\r
// ********************************* //\r
// * External View Functions * //\r
// ********************************* //\r
\r
/**\r
* @notice Returns stake multipliers.\r
* @return winner Winners stake multiplier.\r
* @return loser Losers stake multiplier.\r
* @return loserAppealPeriod Multiplier for calculating an appeal period duration for the losing side.\r
* @return divisor Multiplier divisor.\r
*/\r
function getMultipliers()\r
external\r
view\r
override\r
returns (uint256 winner, uint256 loser, uint256 loserAppealPeriod, uint256 divisor)\r
{\r
return (winnerMultiplier, loserMultiplier, loserAppealPeriodMultiplier, MULTIPLIER_DIVISOR);\r
}\r
\r
/**\r
* @notice Returns number of possible ruling options. Valid rulings are [0, return value].\r
* @return count The number of ruling options.\r
*/\r
function numberOfRulingOptions(uint256 /* _arbitrationID */) external pure override returns (uint256) {\r
return NUMBER_OF_CHOICES_FOR_ARBITRATOR;\r
}\r
\r
/**\r
* @notice Gets the fee to create a dispute.\r
* @return The fee to create a dispute.\r
*/\r
function getDisputeFee(bytes32 /* _questionID */) external view override returns (uint256) {\r
return arbitrator.arbitrationCost(arbitratorExtraData);\r
}\r
\r
/**\r
* @notice Gets the number of rounds of the specific question.\r
* @param _arbitrationID The ID of the arbitration related to the question.\r
* @return The number of rounds.\r
*/\r
function getNumberOfRounds(uint256 _arbitrationID) external view returns (uint256) {\r
address requester = arbitrationIDToRequester[_arbitrationID];\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][requester];\r
return arbitration.rounds.length;\r
}\r
\r
/**\r
* @notice Gets the information of a round of a question.\r
* @param _arbitrationID The ID of the arbitration.\r
* @param _round The round to query.\r
* @return paidFees The amount of fees paid for each fully funded answer.\r
* @return feeRewards The amount of fees that will be used as rewards.\r
* @return fundedAnswers IDs of fully funded answers.\r
* Note that the `fundedAnswers` have Kleros denomination, meaning that it has '+1' offset compared to Realitio format.\r
*/\r
function getRoundInfo(\r
uint256 _arbitrationID,\r
uint256 _round\r
) external view returns (uint256[] memory paidFees, uint256 feeRewards, uint256[] memory fundedAnswers) {\r
address requester = arbitrationIDToRequester[_arbitrationID];\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][requester];\r
Round storage round = arbitration.rounds[_round];\r
fundedAnswers = round.fundedAnswers;\r
\r
paidFees = new uint256[](round.fundedAnswers.length);\r
\r
for (uint256 i = 0; i < round.fundedAnswers.length; i++) {\r
paidFees[i] = round.paidFees[round.fundedAnswers[i]];\r
}\r
\r
feeRewards = round.feeRewards;\r
}\r
\r
/**\r
* @notice Gets the information of a round of a question for a specific answer choice.\r
* @param _arbitrationID The ID of the arbitration.\r
* @param _round The round to query.\r
* @param _answer The answer choice to get funding status for.\r
* Note that the `_answer` has Kleros denomination, meaning that it has '+1' offset compared to Realitio format.\r
* @return raised The amount paid for this answer.\r
* @return fullyFunded Whether the answer is fully funded or not.\r
*/\r
function getFundingStatus(\r
uint256 _arbitrationID,\r
uint256 _round,\r
uint256 _answer\r
) external view returns (uint256 raised, bool fullyFunded) {\r
address requester = arbitrationIDToRequester[_arbitrationID];\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][requester];\r
Round storage round = arbitration.rounds[_round];\r
\r
raised = round.paidFees[_answer];\r
fullyFunded = round.hasPaid[_answer];\r
}\r
\r
/**\r
* @notice Gets contributions to the answers that are fully funded.\r
* @param _arbitrationID The ID of the arbitration.\r
* @param _round The round to query.\r
* @param _contributor The address whose contributions to query.\r
* @return fundedAnswers IDs of the answers that are fully funded.\r
* Note that the `fundedAnswers` have Kleros denomination, meaning that it has '+1' offset compared to Realitio format.\r
* @return contributions The amount contributed to each funded answer by the contributor.\r
*/\r
function getContributionsToSuccessfulFundings(\r
uint256 _arbitrationID,\r
uint256 _round,\r
address _contributor\r
) external view returns (uint256[] memory fundedAnswers, uint256[] memory contributions) {\r
address requester = arbitrationIDToRequester[_arbitrationID];\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][requester];\r
Round storage round = arbitration.rounds[_round];\r
\r
fundedAnswers = round.fundedAnswers;\r
contributions = new uint256[](round.fundedAnswers.length);\r
\r
for (uint256 i = 0; i < contributions.length; i++) {\r
contributions[i] = round.contributions[_contributor][fundedAnswers[i]];\r
}\r
}\r
\r
/**\r
* @notice Returns the sum of withdrawable amount.\r
* @dev This function is O(n) where n is the total number of rounds.\r
* @dev This could exceed the gas limit, therefore this function should be used only as a utility and not be relied upon by other contracts.\r
* @param _arbitrationID The ID of the arbitration.\r
* @param _beneficiary The contributor for which to query.\r
* @param _contributedTo Answer that received contributions from contributor.\r
* Note that the `_contributedTo` answer has Kleros denomination, meaning that it has '+1' offset compared to Realitio format.\r
* @return sum The total amount available to withdraw.\r
*/\r
function getTotalWithdrawableAmount(\r
uint256 _arbitrationID,\r
address payable _beneficiary,\r
uint256 _contributedTo\r
) external view override returns (uint256 sum) {\r
address requester = arbitrationIDToRequester[_arbitrationID];\r
ArbitrationRequest storage arbitration = arbitrationRequests[_arbitrationID][requester];\r
if (!(arbitration.status == Status.Ruled || arbitration.status == Status.Relayed)) return sum;\r
\r
uint256 finalAnswer = arbitration.answer;\r
uint256 noOfRounds = arbitration.rounds.length;\r
for (uint256 roundNumber = 0; roundNumber < noOfRounds; roundNumber++) {\r
Round storage round = arbitration.rounds[roundNumber];\r
\r
if (!round.hasPaid[_contributedTo]) {\r
// Allow to reimburse if funding was unsuccessful for this answer option.\r
sum += round.contributions[_beneficiary][_contributedTo];\r
} else if (!round.hasPaid[finalAnswer]) {\r
// Reimburse unspent fees proportionally if the ultimate winner didn't pay appeal fees fully.\r
// Note that if only one side is funded it will become a winner and this part of the condition won't be reached.\r
sum += round.fundedAnswers.length > 1\r
? (round.contributions[_beneficiary][_contributedTo] * round.feeRewards) /\r
(round.paidFees[round.fundedAnswers[0]] + round.paidFees[round.fundedAnswers[1]])\r
: 0;\r
} else if (finalAnswer == _contributedTo) {\r
uint256 paidFees = round.paidFees[_contributedTo];\r
// Reward the winner.\r
sum += paidFees > 0\r
? (round.contributions[_beneficiary][_contributedTo] * round.feeRewards) / paidFees\r
: 0;\r
}\r
}\r
}\r
\r
/**\r
* @notice Casts question ID into uint256 thus returning the related arbitration ID.\r
* @param _questionID The ID of the question.\r
* @return The ID of the arbitration.\r
*/\r
function questionIDToArbitrationID(bytes32 _questionID) external pure returns (uint256) {\r
return uint256(_questionID);\r
}\r
\r
/**\r
* @notice Maps external (arbitrator side) dispute id to local (arbitrable) dispute id.\r
* @param _externalDisputeID Dispute id as in arbitrator side.\r
* @return localDisputeID Dispute id as in arbitrable contract.\r
*/\r
function externalIDtoLocalID(uint256 _externalDisputeID) external view override returns (uint256) {\r
return disputeIDToDisputeDetails[_externalDisputeID].arbitrationID;\r
}\r
\r
// **************************** //\r
// * Internal * //\r
// **************************** //\r
\r
function _requestArbitration(bytes32 _questionID, uint256 _maxPrevious, uint32 _gasLimit) internal {\r
require(!arbitrationIDToDisputeExists[uint256(_questionID)], "Dispute already created");\r
\r
ArbitrationRequest storage arbitration = arbitrationRequests[uint256(_questionID)][msg.sender];\r
require(arbitration.status == Status.None, "Arbitration already requested");\r
\r
uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);\r
\r
require(msg.value >= arbitrationCost, "Deposit value too low");\r
\r
arbitration.status = Status.Requested;\r
arbitration.deposit = uint248(msg.value);\r
\r
bytes4 methodSelector = IHomeArbitrationProxy.receiveArbitrationRequest.selector;\r
bytes memory data = abi.encodeWithSelector(methodSelector, _questionID, msg.sender, _maxPrevious);\r
\r
messenger.sendMessage(homeProxy, data, _gasLimit);\r
emit ArbitrationRequested(_questionID, msg.sender, _maxPrevious);\r
}\r
\r
function _handleFailedDisputeCreation(bytes32 _questionID, address _requester, uint32 _gasLimit) internal {\r
uint256 ar
Submitted on: 2025-10-15 20:50:14
Comments
Log in to comment.
No comments yet.