Skip to content

feat(xKlerosLiquid): upgrade for V2 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion contracts/kleros/xKlerosLiquid.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { IRandomAuRa } from "../interfaces/IRandomAuRa.sol";

import { SortitionSumTreeFactory } from "@kleros/kleros/contracts/data-structures/SortitionSumTreeFactory.sol";

interface IForeignGateway {
function createDispute(uint _choices, bytes _extraData) external payable returns (uint disputeID);
}

/**
* @title xKlerosLiquid
* @dev This contract is an adaption of Mainnet's KlerosLiquid (https://github.com/kleros/kleros/blob/69cfbfb2128c29f1625b3a99a3183540772fda08/contracts/kleros/KlerosLiquid.sol)
Expand Down Expand Up @@ -179,6 +183,11 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
mapping(uint => Dispute) public disputes; // The disputes.
uint public totalDisputes;

IForeignGateway public foreignGateway; // The contract that will relay disputes to V2 arbitrator.

// TODO: implement fee conversion into WETH. The addresses of WETH and WXDAI tokens can be declared as constants.
//IUniswapRouter public uniswapRouter; // Router to convert xDai fees into WETH in order to transfer them to foreign gateway.

// Juror
mapping(address => Juror) public jurors; // The jurors.

Expand Down Expand Up @@ -213,6 +222,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
* @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the general court.
* @param _timesPerPeriod The `timesPerPeriod` property value of the general court.
* @param _sortitionSumTreeK The number of children per node of the general court's sortition sum tree.
* @param _foreignGateway Foreign gateway contract.
*/
function initialize(
address _governor,
Expand All @@ -226,7 +236,8 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
uint _feeForJuror,
uint _jurorsForCourtJump,
uint[4] _timesPerPeriod,
uint _sortitionSumTreeK
uint _sortitionSumTreeK,
IForeignGateway _foreignGateway
) public initializer {
// Initialize contract.
governor = _governor;
Expand All @@ -237,6 +248,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
lastPhaseChange = now;
lockInsolventTransfers = true;
nextDelayedSetStake = 1;
foreignGateway = _foreignGateway;

// Create the general court.
courts.push(Court({
Expand Down Expand Up @@ -301,6 +313,13 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
maxDrawingTime = _maxDrawingTime;
}

/** @dev Changes the `foreignGateway` storage variable.
* @param _foreignGateway The new value for the `foreignGateway` storage variable.
*/
function changeForeignGateway(IForeignGateway _foreignGateway) external onlyByGovernor {
foreignGateway = _foreignGateway;
}

/** @dev Creates a subcourt under a specified parent court.
* @param _parent The `parent` property value of the subcourt.
* @param _hiddenVotes The `hiddenVotes` property value of the subcourt.
Expand Down Expand Up @@ -694,6 +713,22 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
dispute.arbitrated.rule(_disputeID, winningChoice);
}

/** @dev Receive the ruling from foreign gateway which technically is an arbitrator of this contract.
* @param _disputeID ID of the dispute.
* @param _ruling Ruling given by V2 court and relayed by foreign gateway.
*/
function rule(uint _disputeID, uint _ruling) external {
require(_disputeID < totalDisputes, "Dispute ID does not exist.");
require(msg.sender == address(foreignGateway), "Can only be called by gateway");

Dispute storage dispute = disputes[_disputeID];
require(!dispute.ruled, "Ruling already executed.");
dispute.ruled = true;

// Send the relayed ruling to the arbitrable while fully bypassing the dispute flow.
dispute.arbitrated.rule(_disputeID, _ruling);
}

/* Public */

/** @dev Creates a dispute. Must be called by the arbitrable contract.
Expand Down Expand Up @@ -723,6 +758,10 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
dispute.penaltiesInEachRound.push(0);
disputesWithoutJurors++;

// TODO: convert msg.value into WETH and transfer it to foreign gateway instead of sending it directly.
// Keep in mind that foreign gateway also checks the arbitrator fee and it does so based on the fee in V2.
foreignGateway.createDispute.value(msg.value)(_numberOfChoices, _extraData);

emit DisputeCreation(disputeID, Arbitrable(msg.sender));
}

Expand Down