Skip to content
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

feat(Arbitration): standard update #1

Merged
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## 0.1.0 (2021-11-11)
## 0.1.0 (2021-11-30)

- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))
- fix(IArbitrator): appeals removed from the standard ([02c20ce](https://github.com/kleros/kleros-v2/commit/02c20ce))
- fix(IArbitrator): interface simplification ([e81fb8b](https://github.com/kleros/kleros-v2/commit/e81fb8b))
- fix(IArbitrator): replaced appealCost with fundingStatus ([f189dd9](https://github.com/kleros/kleros-v2/commit/f189dd9))
- feat: modern toolchain setup and simple RNG smart contracts ([17f6a76](https://github.com/kleros/kleros-v2/commit/17f6a76))
- feat(Arbitration): standard update ([ed930de](https://github.com/kleros/kleros-v2/commit/ed930de))
- chore: added GitHub code scanning ([4a70475](https://github.com/kleros/kleros-v2/commit/4a70475))
- chore: added the hardhat config for layer 2 networks, added hardhat-deploy and mocha ([a12ea0e](https://github.com/kleros/kleros-v2/commit/a12ea0e))
- test: added a test for IncrementalNG ([65a996b](https://github.com/kleros/kleros-v2/commit/65a996b))
- docs: initial commit ([23356e7](https://github.com/kleros/kleros-v2/commit/23356e7))
- docs: license file added ([cb62d2c](https://github.com/kleros/kleros-v2/commit/cb62d2c))
- docs: readme and spdx headers ([8a5b397](https://github.com/kleros/kleros-v2/commit/8a5b397))
- docs: updated ([5b9a8f1](https://github.com/kleros/kleros-v2/commit/5b9a8f1))
- feat: modern toolchain setup and simple RNG smart contracts ([17f6a76](https://github.com/kleros/kleros-v2/commit/17f6a76))
68 changes: 68 additions & 0 deletions contracts/src/arbitration/ArbitrableExample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

import "./IArbitrable.sol";

/**
* @title ArbitrableExample
* An example of the arbitrable contract which connects to the arbitator that implements IArbitrator interface.
*/
contract ArbitrableExample is IArbitrable {
struct DisputeStruct {
bool isRuled; // Whether the dispute has been ruled or not.
uint256 ruling; // Ruling given by the arbitrator.
uint256 numberOfRulingOptions; // The number of choices the arbitrator can give.
}

IArbitrator public immutable arbitrator; // Arbitrator is set in constructor and never changed.

mapping(uint256 => uint256) public externalIDtoLocalID; // Maps external (arbitrator side) dispute IDs to local dispute IDs.

DisputeStruct[] public disputes; // Stores the disputes' info. disputes[disputeID].

/** @dev Constructor
* @param _arbitrator The arbitrator to rule on created disputes.
*/
constructor(IArbitrator _arbitrator) {
arbitrator = _arbitrator;
}

/** @dev TRUSTED. Calls createDispute function of the specified arbitrator to create a dispute.
Note that we don’t need to check that msg.value is enough to pay arbitration fees as it’s the responsibility of the arbitrator contract.
* @param _numberOfRulingOptions Number of ruling options. Must be greater than 1, otherwise there is nothing to choose from.
* @param _arbitratorExtraData Extra data for the arbitrator.
* @return disputeID Dispute id (on arbitrator side) of the dispute created.
*/
function createDispute(uint256 _numberOfRulingOptions, bytes calldata _arbitratorExtraData)
external
payable
returns (uint256 disputeID)
{
require(_numberOfRulingOptions > 1, "Incorrect number of choices");

uint256 localDisputeID = disputes.length;
disputes.push(DisputeStruct({isRuled: false, ruling: 0, numberOfRulingOptions: _numberOfRulingOptions}));

disputeID = arbitrator.createDispute{value: msg.value}(_numberOfRulingOptions, _arbitratorExtraData);

externalIDtoLocalID[disputeID] = localDisputeID;
}

/** @dev To be called by the arbitrator of the dispute, to declare the winning ruling.
* @param _externalDisputeID ID of the dispute in arbitrator contract.
* @param _ruling The ruling choice of the arbitration.
*/
function rule(uint256 _externalDisputeID, uint256 _ruling) external override {
uint256 localDisputeID = externalIDtoLocalID[_externalDisputeID];
DisputeStruct storage dispute = disputes[localDisputeID];
require(msg.sender == address(arbitrator), "Only the arbitrator can execute this.");
require(_ruling <= dispute.numberOfRulingOptions, "Invalid ruling.");
require(dispute.isRuled == false, "This dispute has been ruled already.");

dispute.isRuled = true;
dispute.ruling = _ruling;

emit Ruling(IArbitrator(msg.sender), _externalDisputeID, dispute.ruling);
}
}
Loading