Skip to content

Commit d9ee8a8

Browse files
committed
refactor: better separation between v2, v1 ethereum and v1 xdai interfaces and libraries
1 parent 4df5ae8 commit d9ee8a8

20 files changed

+242
-193
lines changed

contracts/deploy/00-home-chain-arbitration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
7676
log: true,
7777
});
7878

79-
const sortitionSumTreeLibrary = await deploy("SortitionSumTreeFactory", {
79+
const sortitionSumTreeLibrary = await deploy("SortitionSumTreeFactoryV2", {
8080
from: deployer,
8181
log: true,
8282
});
@@ -88,7 +88,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
8888
const klerosCore = await deploy("KlerosCore", {
8989
from: deployer,
9090
libraries: {
91-
SortitionSumTreeFactory: sortitionSumTreeLibrary.address,
91+
SortitionSumTreeFactoryV2: sortitionSumTreeLibrary.address,
9292
},
9393
args: [
9494
deployer,

contracts/src/arbitration/KlerosCore.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ pragma solidity ^0.8;
1313
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1414
import "./IArbitrator.sol";
1515
import "./IDisputeKit.sol";
16-
import {SortitionSumTreeFactory} from "../data-structures/SortitionSumTreeFactory.sol";
16+
import {SortitionSumTreeFactoryV2} from "../libraries/SortitionSumTreeFactoryV2.sol";
1717

1818
/**
1919
* @title KlerosCore
2020
* Core arbitrator contract for Kleros v2.
2121
* Note that this contract trusts the token and the dispute kit contracts.
2222
*/
2323
contract KlerosCore is IArbitrator {
24-
using SortitionSumTreeFactory for SortitionSumTreeFactory.SortitionSumTrees; // Use library functions for sortition sum trees.
24+
using SortitionSumTreeFactoryV2 for SortitionSumTreeFactoryV2.SortitionSumTrees; // Use library functions for sortition sum trees.
2525

2626
// ************************************* //
2727
// * Enums / Structs * //
@@ -120,7 +120,7 @@ contract KlerosCore is IArbitrator {
120120
uint256[] public disputesKitIDsThatNeedFreezing; // The disputeKitIDs that need switching to Freezing phase.
121121
Dispute[] public disputes; // The disputes.
122122
mapping(address => Juror) internal jurors; // The jurors.
123-
SortitionSumTreeFactory.SortitionSumTrees internal sortitionSumTrees; // The sortition sum trees.
123+
SortitionSumTreeFactoryV2.SortitionSumTrees internal sortitionSumTrees; // The sortition sum trees.
124124
mapping(uint256 => DelayedStake) public delayedStakes; // Stores the stakes that were changed during Freezing phase, to update them when the phase is switched to Staking.
125125

126126
uint256 public delayedStakeWriteIndex; // The index of the last `delayedStake` item that was written to the array. 0 index is skipped.
@@ -1003,7 +1003,7 @@ contract KlerosCore is IArbitrator {
10031003
bytes32 _key,
10041004
uint256 _nodeIndex
10051005
) public view returns (uint256 K, uint256 length, bytes32 ID) {
1006-
SortitionSumTreeFactory.SortitionSumTree storage tree = sortitionSumTrees.sortitionSumTrees[_key];
1006+
SortitionSumTreeFactoryV2.SortitionSumTree storage tree = sortitionSumTrees.sortitionSumTrees[_key];
10071007
K = tree.K;
10081008
length = tree.nodes.length;
10091009
ID = tree.nodeIndexesToIDs[_nodeIndex];

contracts/src/kleros-v1/ITokenController.sol

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
/**
4+
* @authors: [@ferittuncer, @hbarcelos, @clesaege]
5+
* @reviewers: [@remedcu]
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
pragma solidity ^0.8;
11+
12+
import "./IArbitratorV1.sol";
13+
14+
/**
15+
* @title IArbitrable
16+
* Arbitrable interface compliant with ERC-792.
17+
* When developing arbitrable contracts, we need to:
18+
* - Define the action taken when a ruling is received by the contract.
19+
* - Allow dispute creation. For this a function must call arbitrator.createDispute{value: _fee}(_choices,_extraData);
20+
*/
21+
interface IArbitrableV1 {
22+
/**
23+
* @dev To be raised when a ruling is given.
24+
* @param _arbitrator The arbitrator giving the ruling.
25+
* @param _disputeID ID of the dispute in the Arbitrator contract.
26+
* @param _ruling The ruling which was given.
27+
*/
28+
event Ruling(IArbitratorV1 indexed _arbitrator, uint256 indexed _disputeID, uint256 _ruling);
29+
30+
/**
31+
* @dev Give a ruling for a dispute. Must be called by the arbitrator.
32+
* The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
33+
* @param _disputeID ID of the dispute in the Arbitrator contract.
34+
* @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
35+
*/
36+
function rule(uint256 _disputeID, uint256 _ruling) external;
37+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
/**
4+
* @authors: [@ferittuncer, @hbarcelos, @clesaege]
5+
* @reviewers: [@remedcu]
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
11+
pragma solidity ^0.8.0;
12+
13+
import "./IArbitrableV1.sol";
14+
15+
/**
16+
* @title Arbitrator
17+
* Arbitrator abstract contract compliant with ERC-792.
18+
* When developing arbitrator contracts we need to:
19+
* - 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).
20+
* - Define the functions for cost display (arbitrationCost and appealCost).
21+
* - Allow giving rulings. For this a function must call arbitrable.rule(disputeID, ruling).
22+
*/
23+
interface IArbitratorV1 {
24+
enum DisputeStatus {
25+
Waiting,
26+
Appealable,
27+
Solved
28+
}
29+
30+
/**
31+
* @dev To be emitted when a dispute is created.
32+
* @param _disputeID ID of the dispute.
33+
* @param _arbitrable The contract which created the dispute.
34+
*/
35+
event DisputeCreation(uint256 indexed _disputeID, IArbitrableV1 indexed _arbitrable);
36+
37+
/**
38+
* @dev To be emitted when a dispute can be appealed.
39+
* @param _disputeID ID of the dispute.
40+
* @param _arbitrable The contract which created the dispute.
41+
*/
42+
event AppealPossible(uint256 indexed _disputeID, IArbitrableV1 indexed _arbitrable);
43+
44+
/**
45+
* @dev To be emitted when the current ruling is appealed.
46+
* @param _disputeID ID of the dispute.
47+
* @param _arbitrable The contract which created the dispute.
48+
*/
49+
event AppealDecision(uint256 indexed _disputeID, IArbitrableV1 indexed _arbitrable);
50+
51+
/**
52+
* @dev Create a dispute. Must be called by the arbitrable contract.
53+
* Must be paid at least arbitrationCost(_extraData).
54+
* @param _choices Amount of choices the arbitrator can make in this dispute.
55+
* @param _extraData Can be used to give additional info on the dispute to be created.
56+
* @return disputeID ID of the dispute created.
57+
*/
58+
function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID);
59+
60+
/**
61+
* @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.
62+
* @param _extraData Can be used to give additional info on the dispute to be created.
63+
* @return cost Amount to be paid.
64+
*/
65+
function arbitrationCost(bytes calldata _extraData) external view returns (uint256 cost);
66+
67+
/**
68+
* @dev Appeal a ruling. Note that it has to be called before the arbitrator contract calls rule.
69+
* @param _disputeID ID of the dispute to be appealed.
70+
* @param _extraData Can be used to give extra info on the appeal.
71+
*/
72+
function appeal(uint256 _disputeID, bytes calldata _extraData) external payable;
73+
74+
/**
75+
* @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.
76+
* @param _disputeID ID of the dispute to be appealed.
77+
* @param _extraData Can be used to give additional info on the dispute to be created.
78+
* @return cost Amount to be paid.
79+
*/
80+
function appealCost(uint256 _disputeID, bytes calldata _extraData) external view returns (uint256 cost);
81+
82+
/**
83+
* @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).
84+
* @param _disputeID ID of the dispute.
85+
* @return start The start of the period.
86+
* @return end The end of the period.
87+
*/
88+
function appealPeriod(uint256 _disputeID) external view returns (uint256 start, uint256 end);
89+
90+
/**
91+
* @dev Return the status of a dispute.
92+
* @param _disputeID ID of the dispute to rule.
93+
* @return status The status of the dispute.
94+
*/
95+
function disputeStatus(uint256 _disputeID) external view returns (DisputeStatus status);
96+
97+
/**
98+
* @dev Return the current ruling of a dispute. This is useful for parties to know if they should appeal.
99+
* @param _disputeID ID of the dispute.
100+
* @return ruling The ruling which has been given or the one which will be given if there is no appeal.
101+
*/
102+
function currentRuling(uint256 _disputeID) external view returns (uint256 ruling);
103+
}

contracts/src/kleros-v1/IKlerosLiquid.sol renamed to contracts/src/kleros-v1/interfaces/IKlerosLiquid.sol

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
pragma solidity ^0.8;
44

5-
import "../arbitration/IArbitrator.sol";
5+
import "./IArbitratorV1.sol";
66

7-
interface IKlerosLiquid is IArbitrator {
7+
interface IKlerosLiquid is IArbitratorV1 {
88
enum Period {
99
evidence, // Evidence can be submitted. This is also when drawing has to take place.
1010
commit, // Jurors commit a hashed vote. This is skipped for courts without hidden votes.
@@ -49,7 +49,9 @@ interface IKlerosLiquid is IArbitrator {
4949
uint256 lockedTokens; // The juror's total amount of tokens locked in disputes.
5050
}
5151

52-
function courts(uint256 _index)
52+
function courts(
53+
uint256 _index
54+
)
5355
external
5456
view
5557
returns (
@@ -75,28 +77,18 @@ interface IKlerosLiquid is IArbitrator {
7577

7678
function changeSubcourtTimesPerPeriod(uint96 _subcourtID, uint256[4] calldata _timesPerPeriod) external;
7779

78-
function executeGovernorProposal(
79-
address _destination,
80-
uint256 _amount,
81-
bytes calldata _data
82-
) external;
80+
function executeGovernorProposal(address _destination, uint256 _amount, bytes calldata _data) external;
8381

8482
// Getters
8583
function getVote(
8684
uint256 _disputeID,
8785
uint256 _appeal,
8886
uint256 _voteID
89-
)
90-
external
91-
view
92-
returns (
93-
address account,
94-
bytes32 commit,
95-
uint256 choice,
96-
bool voted
97-
);
87+
) external view returns (address account, bytes32 commit, uint256 choice, bool voted);
9888

99-
function getDispute(uint256 _disputeID)
89+
function getDispute(
90+
uint256 _disputeID
91+
)
10092
external
10193
view
10294
returns (
@@ -108,8 +100,7 @@ interface IKlerosLiquid is IArbitrator {
108100
uint256[] memory penaltiesInEachRound
109101
);
110102

111-
function getSubcourt(uint96 _subcourtID)
112-
external
113-
view
114-
returns (uint256[] memory children, uint256[4] memory timesPerPeriod);
103+
function getSubcourt(
104+
uint96 _subcourtID
105+
) external view returns (uint256[] memory children, uint256[4] memory timesPerPeriod);
115106
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8;
4+
5+
/**
6+
* @dev The token controller contract must implement these functions. See https://github.com/Giveth/minime/blob/master/contracts/TokenController.sol
7+
*/
8+
interface ITokenController {
9+
/**
10+
* @notice Called when `_owner` sends ether to the MiniMe Token contract
11+
* @param _owner The address that sent the ether to create tokens
12+
* @return True if the ether is accepted, false if it throws
13+
*/
14+
function proxyPayment(address _owner) external payable returns (bool);
15+
16+
/**
17+
* @notice Notifies the controller about a token transfer allowing the controller to react if desired
18+
* @param _from The origin of the transfer
19+
* @param _to The destination of the transfer
20+
* @param _amount The amount of the transfer
21+
* @return False if the controller does not authorize the transfer
22+
*/
23+
function onTransfer(address _from, address _to, uint256 _amount) external returns (bool);
24+
25+
/**
26+
* @notice Notifies the controller about an approval allowing the controller to react if desired
27+
* @param _owner The address that calls `approve()`
28+
* @param _spender The spender in the `approve()` call
29+
* @param _amount The amount in the `approve()` call
30+
* @return False if the controller does not authorize the approval
31+
*/
32+
function onApprove(address _owner, address _spender, uint256 _amount) external returns (bool);
33+
}

0 commit comments

Comments
 (0)