11// SPDX-License-Identifier: MIT
22
3- /**
4- * @authors: [@unknownunknown1, @fnanni-0, @shalzz]
5- * @reviewers: []
6- * @auditors: []
7- * @bounties: []
8- */
3+ /// @authors: [@unknownunknown1, @fnanni-0, @shalzz]
4+ /// @reviewers: []
5+ /// @auditors: []
6+ /// @bounties: []
97
108pragma solidity 0.8.18 ;
119
1210import {IArbitrableV2, IArbitratorV2} from "../interfaces/IArbitrableV2.sol " ;
1311import "../interfaces/IDisputeTemplateRegistry.sol " ;
1412
15- /**
16- * @title Escrow
17- * @dev MultipleArbitrableTransaction contract that is compatible with V2.
18- * https://github.com/kleros/kleros-interaction/blob/master/contracts/standard/arbitration/MultipleArbitrableTransaction.sol
19- */
13+ /// @title Escrow
14+ /// @dev MultipleArbitrableTransaction contract that is compatible with V2.
15+ /// Adapted from https://github.com/kleros/kleros-interaction/blob/master/contracts/standard/arbitration/MultipleArbitrableTransaction.sol
2016contract Escrow is IArbitrableV2 {
21- // **************************** //
22- // * Contract variables * //
23- // **************************** //
24-
25- uint256 public constant AMOUNT_OF_CHOICES = 2 ;
17+ // ************************************* //
18+ // * Enums / Structs * //
19+ // ************************************* //
2620
2721 enum Party {
2822 None,
@@ -59,65 +53,70 @@ contract Escrow is IArbitrableV2 {
5953 Status status;
6054 }
6155
56+ // ************************************* //
57+ // * Storage * //
58+ // ************************************* //
59+
60+ uint256 public constant AMOUNT_OF_CHOICES = 2 ;
6261 address public immutable governor;
63- IArbitratorV2 public arbitrator; // Address of the arbitrator contract. TRUSTED.
62+ IArbitratorV2 public arbitrator; // Address of the arbitrator contract.
6463 bytes public arbitratorExtraData; // Extra data to set up the arbitration.
6564 IDisputeTemplateRegistry public templateRegistry; // The dispute template registry.
66-
6765 uint256 public immutable feeTimeout; // Time in seconds a party can take to pay arbitration fees before being considered unresponsive and lose the dispute.
68- /// @dev List of all created transactions.
69- Transaction[] public transactions;
70-
66+ Transaction[] public transactions; // List of all created transactions.
7167 mapping (uint256 => uint256 ) public disputeIDtoTransactionID; // Naps dispute ID to tx ID.
7268
73- // **************************** //
74- // * Events * //
75- // **************************** //
69+ // ************************************* //
70+ // * Events * //
71+ // ************************************* //
7672
77- /** @dev To be emitted when a party pays or reimburses the other.
78- * @param _transactionID The index of the transaction.
79- * @param _amount The amount paid.
80- * @param _party The party that paid.
81- */
73+ /// @dev To be emitted when a party pays or reimburses the other.
74+ /// @param _transactionID The index of the transaction.
75+ /// @param _amount The amount paid.
76+ /// @param _party The party that paid.
8277 event Payment (uint256 indexed _transactionID , uint256 _amount , address _party );
8378
84- /** @dev Indicate that a party has to pay a fee or would otherwise be considered as losing.
85- * @param _transactionID The index of the transaction.
86- * @param _party The party who has to pay.
87- */
79+ /// @dev Indicate that a party has to pay a fee or would otherwise be considered as losing.
80+ /// @param _transactionID The index of the transaction.
81+ /// @param _party The party who has to pay.
8882 event HasToPayFee (uint256 indexed _transactionID , Party _party );
8983
90- /** @dev Emitted when a transaction is created.
91- * @param _transactionID The index of the transaction.
92- * @param _sender The address of the sender.
93- * @param _receiver The address of the receiver.
94- * @param _amount The initial amount in the transaction.
95- */
84+ /// @dev Emitted when a transaction is created.
85+ /// @param _transactionID The index of the transaction.
86+ /// @param _sender The address of the sender.
87+ /// @param _receiver The address of the receiver.
88+ /// @param _amount The initial amount in the transaction.
9689 event TransactionCreated (
9790 uint256 indexed _transactionID ,
9891 address indexed _sender ,
9992 address indexed _receiver ,
10093 uint256 _amount
10194 );
10295
103- /** @dev To be emitted when a transaction is resolved, either by its
104- * execution, a timeout or because a ruling was enforced.
105- * @param _transactionID The ID of the respective transaction.
106- * @param _resolution Short description of what caused the transaction to be solved.
107- */
96+ /// @dev To be emitted when a transaction is resolved, either by its
97+ /// execution, a timeout or because a ruling was enforced.
98+ /// @param _transactionID The ID of the respective transaction.
99+ /// @param _resolution Short description of what caused the transaction to be solved.
108100 event TransactionResolved (uint256 indexed _transactionID , Resolution indexed _resolution );
109101
102+ // ************************************* //
103+ // * Function Modifiers * //
104+ // ************************************* //
105+
110106 modifier onlyByGovernor () {
111107 require (address (this ) == msg .sender , "Only the governor allowed. " );
112108 _;
113109 }
114110
115- /** @dev Constructor.
116- * @param _arbitrator The arbitrator of the contract.
117- * @param _arbitratorExtraData Extra data for the arbitrator.
118- * @param _templateRegistry The dispute template registry.
119- * @param _feeTimeout Arbitration fee timeout for the parties.
120- */
111+ // ************************************* //
112+ // * Constructor * //
113+ // ************************************* //
114+
115+ /// @dev Constructor.
116+ /// @param _arbitrator The arbitrator of the contract.
117+ /// @param _arbitratorExtraData Extra data for the arbitrator.
118+ /// @param _templateRegistry The dispute template registry.
119+ /// @param _feeTimeout Arbitration fee timeout for the parties.
121120 constructor (
122121 IArbitratorV2 _arbitrator ,
123122 bytes memory _arbitratorExtraData ,
@@ -147,13 +146,16 @@ contract Escrow is IArbitrableV2 {
147146 templateRegistry = _templateRegistry;
148147 }
149148
150- /** @dev Create a transaction.
151- * @param _timeoutPayment Time after which a party can automatically execute the arbitrable transaction.
152- * @param _receiver The recipient of the transaction.
153- * @param _templateData The dispute template data.
154- * @param _templateDataMappings The dispute template data mappings.
155- * @return transactionID The index of the transaction.
156- */
149+ // ************************************* //
150+ // * State Modifiers * //
151+ // ************************************* //
152+
153+ /// @dev Create a transaction.
154+ /// @param _timeoutPayment Time after which a party can automatically execute the arbitrable transaction.
155+ /// @param _receiver The recipient of the transaction.
156+ /// @param _templateData The dispute template data.
157+ /// @param _templateDataMappings The dispute template data mappings.
158+ /// @return transactionID The index of the transaction.
157159 function createTransaction (
158160 uint256 _timeoutPayment ,
159161 address payable _receiver ,
@@ -173,10 +175,9 @@ contract Escrow is IArbitrableV2 {
173175 emit TransactionCreated (transactionID, msg .sender , _receiver, msg .value );
174176 }
175177
176- /** @dev Pay receiver. To be called if the good or service is provided.
177- * @param _transactionID The index of the transaction.
178- * @param _amount Amount to pay in wei.
179- */
178+ /// @dev Pay receiver. To be called if the good or service is provided.
179+ /// @param _transactionID The index of the transaction.
180+ /// @param _amount Amount to pay in wei.
180181 function pay (uint256 _transactionID , uint256 _amount ) external {
181182 Transaction storage transaction = transactions[_transactionID];
182183 require (transaction.sender == msg .sender , "The caller must be the sender. " );
@@ -189,10 +190,9 @@ contract Escrow is IArbitrableV2 {
189190 emit Payment (_transactionID, _amount, msg .sender );
190191 }
191192
192- /** @dev Reimburse sender. To be called if the good or service can't be fully provided.
193- * @param _transactionID The index of the transaction.
194- * @param _amountReimbursed Amount to reimburse in wei.
195- */
193+ /// @dev Reimburse sender. To be called if the good or service can't be fully provided.
194+ /// @param _transactionID The index of the transaction.
195+ /// @param _amountReimbursed Amount to reimburse in wei.
196196 function reimburse (uint256 _transactionID , uint256 _amountReimbursed ) external {
197197 Transaction storage transaction = transactions[_transactionID];
198198 require (transaction.receiver == msg .sender , "The caller must be the receiver. " );
@@ -205,9 +205,8 @@ contract Escrow is IArbitrableV2 {
205205 emit Payment (_transactionID, _amountReimbursed, msg .sender );
206206 }
207207
208- /** @dev Transfer the transaction's amount to the receiver if the timeout has passed.
209- * @param _transactionID The index of the transaction.
210- */
208+ /// @dev Transfer the transaction's amount to the receiver if the timeout has passed.
209+ /// @param _transactionID The index of the transaction.
211210 function executeTransaction (uint256 _transactionID ) external {
212211 Transaction storage transaction = transactions[_transactionID];
213212 require (block .timestamp >= transaction.deadline, "Deadline not passed. " );
@@ -221,12 +220,11 @@ contract Escrow is IArbitrableV2 {
221220 emit TransactionResolved (_transactionID, Resolution.TransactionExecuted);
222221 }
223222
224- /** @dev Pay the arbitration fee to raise a dispute. To be called by the sender. UNTRUSTED.
225- * Note that the arbitrator can have createDispute throw, which will make
226- * this function throw and therefore lead to a party being timed-out.
227- * This is not a vulnerability as the arbitrator can rule in favor of one party anyway.
228- * @param _transactionID The index of the transaction.
229- */
223+ /// @dev Pay the arbitration fee to raise a dispute. To be called by the sender.
224+ /// Note that the arbitrator can have createDispute throw, which will make
225+ /// this function throw and therefore lead to a party being timed-out.
226+ /// This is not a vulnerability as the arbitrator can rule in favor of one party anyway.
227+ /// @param _transactionID The index of the transaction.
230228 function payArbitrationFeeBySender (uint256 _transactionID ) external payable {
231229 Transaction storage transaction = transactions[_transactionID];
232230 require (
@@ -253,10 +251,9 @@ contract Escrow is IArbitrableV2 {
253251 }
254252 }
255253
256- /** @dev Pay the arbitration fee to raise a dispute. To be called by the receiver. UNTRUSTED.
257- * Note that this function mirrors payArbitrationFeeBySender.
258- * @param _transactionID The index of the transaction.
259- */
254+ /// @dev Pay the arbitration fee to raise a dispute. To be called by the receiver.
255+ /// Note that this function mirrors payArbitrationFeeBySender.
256+ /// @param _transactionID The index of the transaction.
260257 function payArbitrationFeeByReceiver (uint256 _transactionID ) external payable {
261258 Transaction storage transaction = transactions[_transactionID];
262259 require (
@@ -282,9 +279,8 @@ contract Escrow is IArbitrableV2 {
282279 }
283280 }
284281
285- /** @dev Reimburse sender if receiver fails to pay the fee.
286- * @param _transactionID The index of the transaction.
287- */
282+ /// @dev Reimburse sender if receiver fails to pay the fee.
283+ /// @param _transactionID The index of the transaction.
288284 function timeOutBySender (uint256 _transactionID ) external {
289285 Transaction storage transaction = transactions[_transactionID];
290286 require (transaction.status == Status.WaitingReceiver, "The transaction is not waiting on the receiver. " );
@@ -298,9 +294,8 @@ contract Escrow is IArbitrableV2 {
298294 emit TransactionResolved (_transactionID, Resolution.TimeoutBySender);
299295 }
300296
301- /** @dev Pay receiver if sender fails to pay the fee.
302- * @param _transactionID The index of the transaction.
303- */
297+ /// @dev Pay receiver if sender fails to pay the fee.
298+ /// @param _transactionID The index of the transaction.
304299 function timeOutByReceiver (uint256 _transactionID ) external {
305300 Transaction storage transaction = transactions[_transactionID];
306301 require (transaction.status == Status.WaitingSender, "The transaction is not waiting on the sender. " );
@@ -315,10 +310,9 @@ contract Escrow is IArbitrableV2 {
315310 emit TransactionResolved (_transactionID, Resolution.TimeoutByReceiver);
316311 }
317312
318- /** @dev Create a dispute. UNTRUSTED.
319- * @param _transactionID The index of the transaction.
320- * @param _arbitrationCost Amount to pay the arbitrator.
321- */
313+ /// @dev Create a dispute.
314+ /// @param _transactionID The index of the transaction.
315+ /// @param _arbitrationCost Amount to pay the arbitrator.
322316 function raiseDispute (uint256 _transactionID , uint256 _arbitrationCost ) internal {
323317 Transaction storage transaction = transactions[_transactionID];
324318 transaction.status = Status.DisputeCreated;
@@ -349,13 +343,11 @@ contract Escrow is IArbitrableV2 {
349343 }
350344 }
351345
352- /** @dev Give a ruling for a dispute. Must be called by the arbitrator to
353- * enforce the final ruling. The purpose of this function is to ensure that
354- * the address calling it has the right to rule on the contract.
355- * @param _disputeID ID of the dispute in the Arbitrator contract.
356- * @param _ruling Ruling given by the arbitrator. Note that 0 is reserved
357- * for "Refuse to arbitrate".
358- */
346+ /// @dev Give a ruling for a dispute. Must be called by the arbitrator to enforce the final ruling.
347+ /// The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
348+ /// @param _disputeID ID of the dispute in the Arbitrator contract.
349+ /// @param _ruling Ruling given by the arbitrator. Note that 0 is reserved
350+ /// for "Refuse to arbitrate".
359351 function rule (uint256 _disputeID , uint256 _ruling ) external override {
360352 require (msg .sender == address (arbitrator), "The caller must be the arbitrator. " );
361353 require (_ruling <= AMOUNT_OF_CHOICES, "Invalid ruling. " );
@@ -368,10 +360,9 @@ contract Escrow is IArbitrableV2 {
368360 executeRuling (transactionID, _ruling);
369361 }
370362
371- /** @dev Execute a ruling of a dispute. It reimburses the fee to the winning party.
372- * @param _transactionID The index of the transaction.
373- * @param _ruling Ruling given by the arbitrator. 1 : Reimburse the receiver. 2 : Pay the sender.
374- */
363+ /// @dev Execute a ruling of a dispute. It reimburses the fee to the winning party.
364+ /// @param _transactionID The index of the transaction.
365+ /// @param _ruling Ruling given by the arbitrator. 1 : Reimburse the receiver. 2 : Pay the sender.
375366 function executeRuling (uint256 _transactionID , uint256 _ruling ) internal {
376367 Transaction storage transaction = transactions[_transactionID];
377368 // Give the arbitration fee back.
@@ -394,13 +385,12 @@ contract Escrow is IArbitrableV2 {
394385 emit TransactionResolved (_transactionID, Resolution.RulingEnforced);
395386 }
396387
397- // **************************** //
398- // * Constant getters * //
399- // **************************** //
388+ // ************************************* //
389+ // * Public Views * //
390+ // ************************************* //
400391
401- /** @dev Getter to know the count of transactions.
402- * @return The count of transactions.
403- */
392+ /// @dev Getter to know the count of transactions.
393+ /// @return The count of transactions.
404394 function getCountTransactions () external view returns (uint256 ) {
405395 return transactions.length ;
406396 }
0 commit comments