CentralizedArbitrator
Inherits: IArbitrator
This is a centralized arbitrator deciding alone on the result of disputes. It illustrates how IArbitrator interface can be implemented. Note that this contract supports appeals. The ruling given by the arbitrator can be appealed by crowdfunding a desired choice.
State Variables
WINNER_STAKE_MULTIPLIER
uint256 public constant WINNER_STAKE_MULTIPLIER = 10000;
LOSER_STAKE_MULTIPLIER
uint256 public constant LOSER_STAKE_MULTIPLIER = 20000;
LOSER_APPEAL_PERIOD_MULTIPLIER
uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000;
MULTIPLIER_DIVISOR
uint256 public constant MULTIPLIER_DIVISOR = 10000;
owner
address public owner = msg.sender;
appealDuration
uint256 public appealDuration;
arbitrationFee
uint256 private arbitrationFee;
appealFee
uint256 public appealFee;
disputes
DisputeStruct[] public disputes;
disputeIDtoRoundArray
mapping(uint256 => Round[]) public disputeIDtoRoundArray;
Functions
onlyOwner
modifier onlyOwner();
constructor
Constructor.
constructor(uint256 _arbitrationFee, uint256 _appealDuration, uint256 _appealFee);
Parameters
Name | Type | Description |
---|---|---|
_arbitrationFee | uint256 | Amount to be paid for arbitration. |
_appealDuration | uint256 | Duration of the appeal period. |
_appealFee | uint256 | Amount to be paid to fund one of the appeal choices, not counting the additional fee stake amount. |
setArbitrationFee
Set the arbitration fee. Only callable by the owner.
function setArbitrationFee(uint256 _arbitrationFee) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_arbitrationFee | uint256 | Amount to be paid for arbitration. |
setAppealDuration
Set the duration of the appeal period. Only callable by the owner.
function setAppealDuration(uint256 _appealDuration) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_appealDuration | uint256 | New duration of the appeal period. |
setAppealFee
Set the appeal fee. Only callable by the owner.
function setAppealFee(uint256 _appealFee) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_appealFee | uint256 | Amount to be paid for appeal. |
createDispute
Create a dispute. Must be called by the arbitrable contract. Must be paid at least arbitrationCost().
function createDispute(uint256 _choices, bytes calldata _extraData)
external
payable
override
returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_choices | uint256 | Amount of choices the arbitrator can make in this dispute. |
_extraData | bytes | Can be used to give additional info on the dispute to be created. |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | ID of the dispute created. |
fundAppeal
Manages contributions, and appeals a dispute if at least two choices are fully funded. This function allows the appeals to be crowdfunded. Note that the surplus deposit will be reimbursed.
function fundAppeal(uint256 _disputeID, uint256 _choice) external payable;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | Index of the dispute to appeal. |
_choice | uint256 | A choice that receives funding. |
giveRuling
Give a ruling to a dispute. Once it's given the dispute can be appealed, and after the appeal period has passed this function should be called again to finalize the ruling. Accounts for the situation where the winner loses a case due to paying less appeal fees than expected.
function giveRuling(uint256 _disputeID, uint256 _ruling) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute to rule. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 means that arbitrator chose "Refused to rule". |
withdrawFeesAndRewards
Allows to withdraw any reimbursable fees or rewards after the dispute gets resolved.
function withdrawFeesAndRewards(uint256 _disputeID, address payable _beneficiary, uint256 _round, uint256 _choice)
external
returns (uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | Index of the dispute in disputes array. |
_beneficiary | address payable | The address which rewards to withdraw. |
_round | uint256 | The round the caller wants to withdraw from. |
_choice | uint256 | The ruling option that the caller wants to withdraw from. |
Returns
Name | Type | Description |
---|---|---|
amount | uint256 | The withdrawn amount. |
arbitrationCost
Cost of arbitration.
function arbitrationCost(bytes calldata) public view override returns (uint256 fee);
Returns
Name | Type | Description |
---|---|---|
fee | uint256 | The required amount. |
fundingStatus
Return the funded amount and funding goal for one of the choices.
function fundingStatus(uint256 _disputeID, uint256 _choice) external view returns (uint256 funded, uint256 goal);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute to appeal. |
_choice | uint256 | The choice to check the funding status of. |
Returns
Name | Type | Description |
---|---|---|
funded | uint256 | The amount funded so far for this choice in wei. |
goal | uint256 | The amount to fully fund this choice in wei. |
appealPeriod
Compute the start and end of the dispute's appeal period, if possible. If the dispute is not appealble return (0, 0).
function appealPeriod(uint256 _disputeID) public view returns (uint256 start, uint256 end);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
start | uint256 | The start of the period. |
end | uint256 | The end of the period. |
Events
AppealPossible
To be emitted when a dispute can be appealed.
event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
AppealDecision
To be emitted when the current ruling is appealed.
event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
Contribution
Raised when a contribution is made, inside fundAppeal function.
event Contribution(
uint256 indexed _disputeID, uint256 indexed _round, uint256 _choice, address indexed _contributor, uint256 _amount
);
Withdrawal
Raised when a contributor withdraws a non-zero value.
event Withdrawal(
uint256 indexed _disputeID, uint256 indexed _round, uint256 _choice, address indexed _contributor, uint256 _amount
);
ChoiceFunded
To be raised when a choice is fully funded for appeal.
event ChoiceFunded(uint256 indexed _disputeID, uint256 indexed _round, uint256 indexed _choice);
Structs
DisputeStruct
struct DisputeStruct {
IArbitrable arbitrated;
bytes arbitratorExtraData;
uint256 choices;
uint256 appealPeriodStart;
uint256 arbitrationFee;
uint256 ruling;
DisputeStatus status;
}
Round
struct Round {
mapping(uint256 => uint256) paidFees;
mapping(uint256 => bool) hasPaid;
mapping(address => mapping(uint256 => uint256)) contributions;
uint256 feeRewards;
uint256[] fundedChoices;
}
Enums
DisputeStatus
enum DisputeStatus {
Waiting,
Appealable,
Solved
}