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

refacto: clean indentation of the smart contracts #9

Merged
merged 6 commits into from
Mar 24, 2022
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
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"singleQuote": true,
"trailingComma": "all",
"overrides": [
{
"files": "*.sol",
"options": {
"singleQuote": false,
"printWidth": 120,
"explicitTypes": "always",
"tabWidth": 4
}
}
]
}
115 changes: 74 additions & 41 deletions contracts/CentralizedAppealableArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,47 @@ interface IArbitrable {
* @param _metaEvidenceID Unique identifier of meta-evidence.
* @param _evidence A link to the meta-evidence JSON.
*/
event MetaEvidence(uint indexed _metaEvidenceID, string _evidence);
event MetaEvidence(uint256 indexed _metaEvidenceID, string _evidence);

/** @dev To be emmited when a dispute is created to link the correct meta-evidence to the disputeID
* @param _arbitrator The arbitrator of the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _metaEvidenceID Unique identifier of meta-evidence.
* @param _evidenceGroupID Unique identifier of the evidence group that is linked to this dispute.
*/
event Dispute(Arbitrator indexed _arbitrator, uint indexed _disputeID, uint _metaEvidenceID, uint _evidenceGroupID);
event Dispute(
Arbitrator indexed _arbitrator,
uint256 indexed _disputeID,
uint256 _metaEvidenceID,
uint256 _evidenceGroupID
);

/** @dev To be raised when evidence are submitted. Should point to the ressource (evidences are not to be stored on chain due to gas considerations).
* @param _arbitrator The arbitrator of the contract.
* @param _evidenceGroupID Unique identifier of the evidence group the evidence belongs to.
* @param _party The address of the party submiting the evidence. Note that 0x0 refers to evidence not submitted by any party.
* @param _evidence A URI to the evidence JSON file whose name should be its keccak256 hash followed by .json.
*/
event Evidence(Arbitrator indexed _arbitrator, uint indexed _evidenceGroupID, address indexed _party, string _evidence);
event Evidence(
Arbitrator indexed _arbitrator,
uint256 indexed _evidenceGroupID,
address indexed _party,
string _evidence
);

/** @dev To be raised when a ruling is given.
* @param _arbitrator The arbitrator giving the ruling.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling The ruling which was given.
*/
event Ruling(Arbitrator indexed _arbitrator, uint indexed _disputeID, uint _ruling);
event Ruling(Arbitrator indexed _arbitrator, uint256 indexed _disputeID, uint256 _ruling);

/** @dev Give a ruling for a dispute. Must be called by the arbitrator.
* The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
*/
function rule(uint _disputeID, uint _ruling) external;
function rule(uint256 _disputeID, uint256 _ruling) external;
}

/** @title Arbitrator
Expand All @@ -64,15 +74,18 @@ interface IArbitrable {
* -Allow giving rulings. For this a function must call arbitrable.rule(disputeID, ruling).
*/
abstract contract Arbitrator {

enum DisputeStatus {Waiting, Appealable, Solved}
enum DisputeStatus {
Waiting,
Appealable,
Solved
}

modifier requireArbitrationFee(bytes calldata _extraData) {
require(msg.value >= this.arbitrationCost(_extraData), "Not enough ETH to cover arbitration costs.");
_;
}

modifier requireAppealFee(uint _disputeID, bytes calldata _extraData) {
modifier requireAppealFee(uint256 _disputeID, bytes calldata _extraData) {
require(msg.value >= this.appealCost(_disputeID, _extraData), "Not enough ETH to cover appeal costs.");
_;
}
Expand All @@ -81,38 +94,49 @@ abstract contract Arbitrator {
* @param _disputeID ID of the dispute.
* @param _arbitrable The contract which created the dispute.
*/
event DisputeCreation(uint indexed _disputeID, IArbitrable indexed _arbitrable);
event DisputeCreation(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);

/** @dev To be raised when a dispute can be appealed.
* @param _disputeID ID of the dispute.
*/
event AppealPossible(uint indexed _disputeID, IArbitrable indexed _arbitrable);
event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);

/** @dev To be raised when the current ruling is appealed.
* @param _disputeID ID of the dispute.
* @param _arbitrable The contract which created the dispute.
*/
event AppealDecision(uint indexed _disputeID, IArbitrable indexed _arbitrable);
event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);

/** @dev Create a dispute. Must be called by the arbitrable contract.
* Must be paid at least arbitrationCost(_extraData).
* @param _choices Amount of choices the arbitrator can make in this dispute.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return disputeID ID of the dispute created.
*/
function createDispute(uint _choices, bytes calldata _extraData) virtual public requireArbitrationFee(_extraData) payable returns(uint disputeID) {}
function createDispute(uint256 _choices, bytes calldata _extraData)
public
payable
virtual
requireArbitrationFee(_extraData)
returns (uint256 disputeID)
{}

/** @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.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return fee Amount to be paid.
*/
function arbitrationCost(bytes calldata _extraData) public view virtual returns(uint fee);
function arbitrationCost(bytes calldata _extraData) public view virtual returns (uint256 fee);

/** @dev Appeal a ruling. Note that it has to be called before the arbitrator contract calls rule.
* @param _disputeID ID of the dispute to be appealed.
* @param _extraData Can be used to give extra info on the appeal.
*/
function appeal(uint _disputeID, bytes calldata _extraData) public virtual requireAppealFee(_disputeID,_extraData) payable {
function appeal(uint256 _disputeID, bytes calldata _extraData)
public
payable
virtual
requireAppealFee(_disputeID, _extraData)
{
emit AppealDecision(_disputeID, IArbitrable(msg.sender));
}

Expand All @@ -121,34 +145,33 @@ abstract contract Arbitrator {
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return fee Amount to be paid.
*/
function appealCost(uint _disputeID, bytes calldata _extraData) public view virtual returns(uint fee);
function appealCost(uint256 _disputeID, bytes calldata _extraData) public view virtual returns (uint256 fee);

/** @dev Compute the start and end of the dispute's current or next appeal period, if possible.
* @param _disputeID ID of the dispute.
* @return start The start of the period.
* @return end The end of the period.
*/
function appealPeriod(uint _disputeID) public view virtual returns(uint start, uint end) {}
function appealPeriod(uint256 _disputeID) public view virtual returns (uint256 start, uint256 end) {}

/** @dev Return the status of a dispute.
* @param _disputeID ID of the dispute to rule.
* @return status The status of the dispute.
*/
function disputeStatus(uint _disputeID) public view virtual returns(DisputeStatus status);
function disputeStatus(uint256 _disputeID) public view virtual returns (DisputeStatus status);

/** @dev Return the current ruling of a dispute. This is useful for parties to know if they should appeal.
* @param _disputeID ID of the dispute.
* @return ruling The ruling which has been given or the one which will be given if there is no appeal.
*/
function currentRuling(uint _disputeID) public view virtual returns(uint ruling);
function currentRuling(uint256 _disputeID) public view virtual returns (uint256 ruling);
}

/** @title Centralized Arbitrator
* @dev Note: It's a naive implementation to manage court appeals where arbitration fees are not systematically refunded to the winning party.
* @dev This is a centralized arbitrator deciding alone on the result of disputes. No appeals are possible.
*/
contract CentralizedAppealableArbitrator is Arbitrator {

address public owner = msg.sender;
uint256 arbitrationPrice; // Not public because arbitrationCost already acts as an accessor.
uint256 public rulingTime;
Expand All @@ -163,7 +186,10 @@ contract CentralizedAppealableArbitrator is Arbitrator {
DisputeStatus status;
}

modifier onlyOwner {require(msg.sender == owner, "Can only be called by the owner."); _;}
modifier onlyOwner() {
require(msg.sender == owner, "Can only be called by the owner.");
_;
}

DisputeStruct[] public disputes;

Expand All @@ -186,7 +212,7 @@ contract CentralizedAppealableArbitrator is Arbitrator {
* @param _extraData Not used by this contract.
* @return fee Amount to be paid.
*/
function arbitrationCost(bytes memory _extraData) override public view returns(uint fee) {
function arbitrationCost(bytes memory _extraData) public view override returns (uint256 fee) {
return arbitrationPrice;
}

Expand All @@ -195,10 +221,7 @@ contract CentralizedAppealableArbitrator is Arbitrator {
* @param _extraData Not used by this contract.
* @return fee Amount to be paid.
*/
function appealCost(
uint256 _disputeID,
bytes memory _extraData
) override public view returns(uint256 fee) {
function appealCost(uint256 _disputeID, bytes memory _extraData) public view override returns (uint256 fee) {
return arbitrationPrice;
}

Expand All @@ -208,18 +231,25 @@ contract CentralizedAppealableArbitrator is Arbitrator {
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return disputeID ID of the dispute created.
*/
function createDispute(uint256 _choices, bytes calldata _extraData) public override payable returns(uint256 disputeID) {
function createDispute(uint256 _choices, bytes calldata _extraData)
public
payable
override
returns (uint256 disputeID)
{
super.createDispute(_choices, _extraData);

disputes.push(DisputeStruct({
arbitrated: IArbitrable(msg.sender),
choices: _choices,
fee: msg.value,
isAppealed: false,
rulingAppealTimeOut: 0,
ruling: 0,
status: DisputeStatus.Waiting
})); // Create the dispute and return its number.
disputes.push(
DisputeStruct({
arbitrated: IArbitrable(msg.sender),
choices: _choices,
fee: msg.value,
isAppealed: false,
rulingAppealTimeOut: 0,
ruling: 0,
status: DisputeStatus.Waiting
})
); // Create the dispute and return its number.

emit DisputeCreation(disputeID, IArbitrable(msg.sender));

Expand All @@ -230,12 +260,16 @@ contract CentralizedAppealableArbitrator is Arbitrator {
* @param _disputeID The ID of the dispute.
* @param _extraData Additional info about the appeal.
*/
function appeal(uint256 _disputeID, bytes calldata _extraData) override public payable requireAppealFee(_disputeID, _extraData) {
function appeal(uint256 _disputeID, bytes calldata _extraData)
public
payable
override
requireAppealFee(_disputeID, _extraData)
{
super.appeal(_disputeID, _extraData);

DisputeStruct storage dispute = disputes[_disputeID];


dispute.isAppealed = true;
}

Expand All @@ -256,7 +290,7 @@ contract CentralizedAppealableArbitrator is Arbitrator {
dispute.status = DisputeStatus.Appealable;

emit AppealPossible(_disputeID, disputes[_disputeID].arbitrated);
} else if(dispute.rulingAppealTimeOut <= block.timestamp) {
} else if (dispute.rulingAppealTimeOut <= block.timestamp) {
dispute.status = DisputeStatus.Solved;

payable(msg.sender).send(dispute.fee); // Avoid blocking.
Expand All @@ -270,16 +304,15 @@ contract CentralizedAppealableArbitrator is Arbitrator {
* @param _disputeID ID of the dispute to rule.
* @return status The status of the dispute.
*/
function disputeStatus(uint256 _disputeID) override public view returns(DisputeStatus status) {
function disputeStatus(uint256 _disputeID) public view override returns (DisputeStatus status) {
return disputes[_disputeID].status;
}

/** @dev Return the ruling of a dispute.
* @param _disputeID ID of the dispute to rule.
* @return ruling The ruling which would or has been given.
*/
function currentRuling(uint256 _disputeID) override public view returns(uint256 ruling) {
function currentRuling(uint256 _disputeID) public view override returns (uint256 ruling) {
return disputes[_disputeID].ruling;
}
}

2 changes: 1 addition & 1 deletion contracts/ERC20Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ contract ERC20Mock is ERC20 {
constructor() ERC20("ERC20Mock", "ERC20M") {
_mint(msg.sender, 10000000000000000000000); // 10000 ERC20M
}
}
}
Loading