CentralizedArbitrator

Git Source

Inherits: IArbitratorV2

This is a centralized arbitrator deciding alone on the result of disputes. It illustrates how IArbitratorV2 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

NameTypeDescription
_arbitrationFeeuint256Amount to be paid for arbitration.
_appealDurationuint256Duration of the appeal period.
_appealFeeuint256Amount 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

NameTypeDescription
_arbitrationFeeuint256Amount 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

NameTypeDescription
_appealDurationuint256New duration of the appeal period.

setAppealFee

Set the appeal fee. Only callable by the owner.

function setAppealFee(uint256 _appealFee) external onlyOwner;

Parameters

NameTypeDescription
_appealFeeuint256Amount to be paid for appeal.

createDispute

Create a dispute and pay for the fees in the native currency, typically ETH. Must be called by the arbitrable contract. Must pay at least arbitrationCost(_extraData).

function createDispute(uint256 _choices, bytes calldata _extraData)
    external
    payable
    override
    returns (uint256 disputeID);

Parameters

NameTypeDescription
_choicesuint256
_extraDatabytesAdditional info about the dispute. We use it to pass the ID of the dispute's court (first 32 bytes), the minimum number of jurors required (next 32 bytes) and the ID of the specific dispute kit (last 32 bytes).

Returns

NameTypeDescription
disputeIDuint256The identifier of the dispute created.

createDispute

Create a dispute and pay for the fees in the native currency, typically ETH. Must be called by the arbitrable contract. Must pay at least arbitrationCost(_extraData).

function createDispute(uint256, bytes calldata, IERC20, uint256) external pure override returns (uint256);

Parameters

NameTypeDescription
<none>uint256
<none>bytes
<none>IERC20
<none>uint256

Returns

NameTypeDescription
<none>uint256disputeID The identifier 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

NameTypeDescription
_disputeIDuint256Index of the dispute to appeal.
_choiceuint256A 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

NameTypeDescription
_disputeIDuint256ID of the dispute to rule.
_rulinguint256Ruling 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

NameTypeDescription
_disputeIDuint256Index of the dispute in disputes array.
_beneficiaryaddress payableThe address which rewards to withdraw.
_rounduint256The round the caller wants to withdraw from.
_choiceuint256The ruling option that the caller wants to withdraw from.

Returns

NameTypeDescription
amountuint256The withdrawn amount.

arbitrationCost

Compute the cost of arbitration denominated in the native currency, typically ETH. 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.

function arbitrationCost(bytes calldata) public view override returns (uint256 fee);

Parameters

NameTypeDescription
<none>bytes

Returns

NameTypeDescription
feeuint256cost The arbitration cost in ETH.

arbitrationCost

Compute the cost of arbitration denominated in the native currency, typically ETH. 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.

function arbitrationCost(bytes calldata, IERC20) public pure override returns (uint256);

Parameters

NameTypeDescription
<none>bytes
<none>IERC20

Returns

NameTypeDescription
<none>uint256cost The arbitration cost in ETH.

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

NameTypeDescription
_disputeIDuint256The ID of the dispute to appeal.
_choiceuint256The choice to check the funding status of.

Returns

NameTypeDescription
fundeduint256The amount funded so far for this choice in wei.
goaluint256The 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

NameTypeDescription
_disputeIDuint256ID of the dispute.

Returns

NameTypeDescription
startuint256The start of the period.
enduint256The end of the period.

currentRuling

function currentRuling(uint256) public pure returns (uint256, bool, bool);

Events

AppealPossible

To be emitted when a dispute can be appealed.

event AppealPossible(uint256 indexed _disputeID, IArbitrableV2 indexed _arbitrable);

AppealDecision

To be emitted when the current ruling is appealed.

event AppealDecision(uint256 indexed _disputeID, IArbitrableV2 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 {
    IArbitrableV2 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
}