1
1
// SPDX-License-Identifier: MIT
2
2
3
- /// @authors: [@unknownunknown1, @fnanni-0, @shalzz]
3
+ /// @authors: [@unknownunknown1, @fnanni-0, @shalzz, @jaybuidl ]
4
4
/// @reviewers: []
5
5
/// @auditors: []
6
6
/// @bounties: []
@@ -29,7 +29,7 @@ contract Escrow is IArbitrableV2 {
29
29
WaitingSender,
30
30
WaitingReceiver,
31
31
DisputeCreated,
32
- Resolved
32
+ TransactionResolved
33
33
}
34
34
35
35
enum Resolution {
@@ -105,7 +105,7 @@ contract Escrow is IArbitrableV2 {
105
105
// ************************************* //
106
106
107
107
modifier onlyByGovernor () {
108
- require ( address ( this ) == msg .sender , " Only the governor allowed. " );
108
+ if (governor != msg .sender ) revert GovernorOnly ( );
109
109
_;
110
110
}
111
111
@@ -194,9 +194,9 @@ contract Escrow is IArbitrableV2 {
194
194
/// @param _amount Amount to pay in wei.
195
195
function pay (uint256 _transactionID , uint256 _amount ) external {
196
196
Transaction storage transaction = transactions[_transactionID];
197
- require (transaction.sender == msg .sender , " The caller must be the sender. " );
198
- require (transaction.status == Status.NoDispute, " The transaction must not be disputed. " );
199
- require (_amount <= transaction.amount, " Maximum amount available for payment exceeded. " );
197
+ if (transaction.sender != msg .sender ) revert SenderOnly ( );
198
+ if (transaction.status != Status.NoDispute) revert TransactionDisputed ( );
199
+ if (_amount > transaction.amount) revert MaximumPaymentAmountExceeded ( );
200
200
201
201
transaction.receiver.send (_amount); // It is the user responsibility to accept ETH.
202
202
transaction.amount -= _amount;
@@ -209,9 +209,9 @@ contract Escrow is IArbitrableV2 {
209
209
/// @param _amountReimbursed Amount to reimburse in wei.
210
210
function reimburse (uint256 _transactionID , uint256 _amountReimbursed ) external {
211
211
Transaction storage transaction = transactions[_transactionID];
212
- require (transaction.receiver == msg .sender , " The caller must be the receiver. " );
213
- require (transaction.status == Status.NoDispute, " The transaction must not be disputed. " );
214
- require (_amountReimbursed <= transaction.amount, " Maximum reimbursement available exceeded. " );
212
+ if (transaction.receiver != msg .sender ) revert ReceiverOnly ( );
213
+ if (transaction.status != Status.NoDispute) revert TransactionDisputed ( );
214
+ if (_amountReimbursed > transaction.amount) revert MaximumPaymentAmountExceeded ( );
215
215
216
216
transaction.sender.send (_amountReimbursed); // It is the user responsibility to accept ETH.
217
217
transaction.amount -= _amountReimbursed;
@@ -223,13 +223,12 @@ contract Escrow is IArbitrableV2 {
223
223
/// @param _transactionID The index of the transaction.
224
224
function executeTransaction (uint256 _transactionID ) external {
225
225
Transaction storage transaction = transactions[_transactionID];
226
- require (block .timestamp >= transaction.deadline, " Deadline not passed. " );
227
- require (transaction.status == Status.NoDispute, " The transaction must not be disputed. " );
226
+ if (block .timestamp < transaction.deadline) revert DeadlineNotPassed ( );
227
+ if (transaction.status != Status.NoDispute) revert TransactionDisputed ( );
228
228
229
229
transaction.receiver.send (transaction.amount); // It is the user responsibility to accept ETH.
230
230
transaction.amount = 0 ;
231
-
232
- transaction.status = Status.Resolved;
231
+ transaction.status = Status.TransactionResolved;
233
232
234
233
emit TransactionResolved (_transactionID, Resolution.TransactionExecuted);
235
234
}
@@ -241,20 +240,17 @@ contract Escrow is IArbitrableV2 {
241
240
/// @param _transactionID The index of the transaction.
242
241
function payArbitrationFeeBySender (uint256 _transactionID ) external payable {
243
242
Transaction storage transaction = transactions[_transactionID];
244
- require (
245
- transaction.status < Status.DisputeCreated,
246
- "Dispute has already been created or because the transaction has been executed. "
247
- );
248
- require (msg .sender == transaction.sender, "The caller must be the sender. " );
243
+ if (transaction.status >= Status.DisputeCreated) revert DisputeAlreadyCreatedOrTransactionAlreadyExecuted ();
244
+ if (msg .sender != transaction.sender) revert SenderOnly ();
249
245
250
246
transaction.senderFee += msg .value ;
251
247
uint256 arbitrationCost = arbitrator.arbitrationCost (arbitratorExtraData);
252
- require (transaction.senderFee >= arbitrationCost, " The sender fee must cover arbitration costs. " );
248
+ if (transaction.senderFee < arbitrationCost) revert SenderFeeNotCoverArbitrationCosts ( );
253
249
254
250
transaction.lastInteraction = block .timestamp ;
255
251
256
- // The receiver still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
257
252
if (transaction.receiverFee < arbitrationCost) {
253
+ // The receiver still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
258
254
transaction.status = Status.WaitingReceiver;
259
255
emit HasToPayFee (_transactionID, Party.Receiver);
260
256
} else {
@@ -268,20 +264,17 @@ contract Escrow is IArbitrableV2 {
268
264
/// @param _transactionID The index of the transaction.
269
265
function payArbitrationFeeByReceiver (uint256 _transactionID ) external payable {
270
266
Transaction storage transaction = transactions[_transactionID];
271
- require (
272
- transaction.status < Status.DisputeCreated,
273
- "Dispute has already been created or because the transaction has been executed. "
274
- );
275
- require (msg .sender == transaction.receiver, "The caller must be the receiver. " );
267
+ if (transaction.status >= Status.DisputeCreated) revert DisputeAlreadyCreatedOrTransactionAlreadyExecuted ();
268
+ if (msg .sender != transaction.receiver) revert ReceiverOnly ();
276
269
277
270
transaction.receiverFee += msg .value ;
278
271
uint256 arbitrationCost = arbitrator.arbitrationCost (arbitratorExtraData);
279
- require (transaction.receiverFee >= arbitrationCost, " The receiver fee must cover arbitration costs. " );
272
+ if (transaction.receiverFee < arbitrationCost) revert ReceiverFeeNotCoverArbitrationCosts ( );
280
273
281
274
transaction.lastInteraction = block .timestamp ;
282
- // The sender still has to pay. This can also happen if he has paid,
283
- // but arbitrationCost has increased.
275
+
284
276
if (transaction.senderFee < arbitrationCost) {
277
+ // The sender still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
285
278
transaction.status = Status.WaitingSender;
286
279
emit HasToPayFee (_transactionID, Party.Sender);
287
280
} else {
@@ -294,8 +287,8 @@ contract Escrow is IArbitrableV2 {
294
287
/// @param _transactionID The index of the transaction.
295
288
function timeOutBySender (uint256 _transactionID ) external {
296
289
Transaction storage transaction = transactions[_transactionID];
297
- require (transaction.status == Status.WaitingReceiver, " The transaction is not waiting on the receiver. " );
298
- require (block .timestamp - transaction.lastInteraction >= feeTimeout, " Timeout time has not passed yet. " );
290
+ if (transaction.status != Status.WaitingReceiver) revert NotWaitingForReceiverFees ( );
291
+ if (block .timestamp - transaction.lastInteraction < feeTimeout) revert TimeoutNotPassed ( );
299
292
300
293
if (transaction.receiverFee != 0 ) {
301
294
transaction.receiver.send (transaction.receiverFee); // It is the user responsibility to accept ETH.
@@ -309,8 +302,8 @@ contract Escrow is IArbitrableV2 {
309
302
/// @param _transactionID The index of the transaction.
310
303
function timeOutByReceiver (uint256 _transactionID ) external {
311
304
Transaction storage transaction = transactions[_transactionID];
312
- require (transaction.status == Status.WaitingSender, " The transaction is not waiting on the sender. " );
313
- require (block .timestamp - transaction.lastInteraction >= feeTimeout, " Timeout time has not passed yet. " );
305
+ if (transaction.status != Status.WaitingSender) revert NotWaitingForSenderFees ( );
306
+ if (block .timestamp - transaction.lastInteraction < feeTimeout) revert TimeoutNotPassed ( );
314
307
315
308
if (transaction.senderFee != 0 ) {
316
309
transaction.sender.send (transaction.senderFee); // It is the user responsibility to accept ETH.
@@ -327,12 +320,12 @@ contract Escrow is IArbitrableV2 {
327
320
/// @param _ruling Ruling given by the arbitrator. Note that 0 is reserved
328
321
/// for "Refuse to arbitrate".
329
322
function rule (uint256 _disputeID , uint256 _ruling ) external override {
330
- require (msg .sender == address (arbitrator), "The caller must be the arbitrator. " );
331
- require (_ruling <= AMOUNT_OF_CHOICES, "Invalid ruling. " );
323
+ if (msg .sender != address (arbitrator)) revert ArbitratorOnly ();
324
+ if (_ruling > AMOUNT_OF_CHOICES) revert InvalidRuling ();
325
+
332
326
uint256 transactionID = disputeIDtoTransactionID[_disputeID];
333
327
Transaction storage transaction = transactions[transactionID];
334
-
335
- require (transaction.status == Status.DisputeCreated, "The dispute has already been resolved. " );
328
+ if (transaction.status != Status.DisputeCreated) revert DisputeAlreadyResolved ();
336
329
337
330
emit Ruling (arbitrator, _disputeID, _ruling);
338
331
executeRuling (transactionID, _ruling);
@@ -390,7 +383,7 @@ contract Escrow is IArbitrableV2 {
390
383
transaction.amount = 0 ;
391
384
transaction.senderFee = 0 ;
392
385
transaction.receiverFee = 0 ;
393
- transaction.status = Status.Resolved ;
386
+ transaction.status = Status.TransactionResolved ;
394
387
395
388
emit TransactionResolved (_transactionID, Resolution.RulingEnforced);
396
389
}
@@ -404,4 +397,24 @@ contract Escrow is IArbitrableV2 {
404
397
function getCountTransactions () external view returns (uint256 ) {
405
398
return transactions.length ;
406
399
}
400
+
401
+ // ************************************* //
402
+ // * Errors * //
403
+ // ************************************* //
404
+
405
+ error GovernorOnly ();
406
+ error SenderOnly ();
407
+ error ReceiverOnly ();
408
+ error ArbitratorOnly ();
409
+ error TransactionDisputed ();
410
+ error MaximumPaymentAmountExceeded ();
411
+ error DisputeAlreadyCreatedOrTransactionAlreadyExecuted ();
412
+ error DeadlineNotPassed ();
413
+ error SenderFeeNotCoverArbitrationCosts ();
414
+ error ReceiverFeeNotCoverArbitrationCosts ();
415
+ error NotWaitingForReceiverFees ();
416
+ error NotWaitingForSenderFees ();
417
+ error TimeoutNotPassed ();
418
+ error InvalidRuling ();
419
+ error DisputeAlreadyResolved ();
407
420
}
0 commit comments