Technical details
Below is a technical workflow that illustrates how escrow works.

Overview
The main features of the contract include:
Creating escrow
Making payments
Reimbursements
Raising disputes
Ruling
Functions
createTransaction
Allows the client to create a new transaction by providing the ERC20 token, the freelancer's address, and the transaction amount. The client must have approved the amount of the ERC20 token transfer.
pay
Allows the client to pay the freelancer for the provided goods or services. The function checks whether the caller is the transaction client, whether the transaction has a valid status, and whether the amount is within the valid range before proceeding.
reimburse
Allows the freelancer to reimburse the client if the goods or services cannot be fully provided. The function checks whether the caller is the transaction freelancer, whether the transaction has a valid status, and whether the amount to be reimbursed is within the valid range before proceeding.
Allows the client or the freelancer to pay the arbitration fee to raise a dispute. The function verifies whether the caller is the transaction client or freelancer, whether the transaction has a valid status, and whether the correct arbitration fee has been paid before proceeding.
timeOut
Allows the client or the freelancer to request a ruling in their favor if the other party fails to pay the arbitration fee within the specified timeout. The function checks whether the transaction has a valid status and whether the timeout has been reached before proceeding.
acceptRuling
Accept ruling for a dispute.
_executeRuling
Internal function to execute a ruling of a dispute. It reimburses the arbitration fee to the winning party and updates the transaction status accordingly.
getTransaction
External function helper for frontend calls returns the transaction or raises an error if the transaction does not exist.
getArbitrationCost
Ask the arbitrator for the arbitration cost.
fetchRuling
Get the ruling for the dispute of the given transaction.
Events
Payment
Emitted when a payment is made. It provides the transaction ID, the ERC20 token address, the amount paid, and the address of the client.
HasToPayFee
Emitted when a party has to pay an arbitration fee. It provides the transaction ID and the party that has to pay the fee.
DisputeCreated
Emitted when a dispute is created. It provides the transaction ID, the dispute ID, and the first party opened the dispute.
TransactionCreated
Emitted when a new transaction is created (the Escrow). It provides all the needed information.
FeeRecipientPayment
Emitted when a fee payment is made to the fee recipient. It provides the transaction ID, the ERC20 token address, and the fee amount.
FeeRecipientChanged
Emitted when fee recipient is changed (admin function). It provides the old and new fee recipients.
WhitelistChanged
Emitted when a token whitelist is changed (admin function).
SendFailed (SafeTransfer)
Emitted when sending funds fails. If the address of the ERC20 is 0 it refers to the native token (used for arbitration).
Custom Errors
NullAddress
Emitted when a required address is instead null.
NoTimeout
Emitted when a timeOut operation is attempted before the feeTimeout period has elapsed.
InvalidCaller
Emitted when the function caller is not the expected one.
InvalidStatus
Emitted when the status of a transaction does not allow a certain operation to be performed.
InvalidAmount
Emitted when the function is called with an invalid amount.
InvalidTransaction
Emitted when the requested transactionID does not refer to a valid transaction.
InvalidToken
InvalidFeeBasisPoint
NotRuled
Emitted when a ruling is queried or attempted to be executed for a dispute that has not yet been ruled.
Enumerations
Status
Represents the current status of a transaction:
NoDispute: The transaction has no dispute.WaitingClient: The transaction is waiting for the client to pay the arbitration fee.WaitingFreelancer: The transaction is waiting for the freelancer to pay the arbitration fee.DisputeCreated: A dispute has been created for the transaction.Resolved: The transaction has been resolved, either by a ruling or by the parties coming to an agreement.
Parties
The parties involved in a transaction are:
client: The party sending the payment.freelancer: The party receiving the payment.
This contract allows two parties, a client and a freelancer, to engage in transactions with the possibility of raising disputes and having them resolved by an arbitrator. The contract handles payments, fee calculations, dispute creation, and evidence submission. In the case of a dispute, the arbitrator is responsible for providing a ruling, which will result in either the client being reimbursed or the freelancer being paid. The contract also enforces timeouts for various actions, such as paying arbitration fees and executing transactions.
Last updated