Openpeer Docs
Search
K

Escrows

This contract implements an escrow system for ETH and ERC20 tokens. It is designed to be used in peer-to-peer transactions where a trusted third party (an arbitrator) is needed to resolve disputes.
The OpenPeerEscrow contract is an Ethereum smart contract that implements an escrow mechanism for trading goods or services between a buyer and a seller. It is designed to hold funds or tokens in escrow until both parties agree that the conditions of the trade have been met.
State variables
  • arbitrator: The address of the arbitrator, who resolves any disputes that may arise during the trade.
  • feeRecipient: The address of the recipient of the fee collected by the escrow service.
  • seller: The address of the seller.
  • buyer: The address of the buyer.
  • token: The address of the token used in the trade.
  • amount: The amount of the token to be transferred from the buyer to the seller.
  • feeBps: The fee charged by the escrow service, expressed in basis points (i.e. 10000 basis points = 100%).
  • sellerWaitingTime: The number of seconds the seller has to cancel the order if the buyer does not pay.
  • sellerCanCancelAfter: The timestamp after which the seller can cancel the order.
  • dispute: A boolean flag indicating whether a dispute has been opened.
  • disputeFee: The fee charged by the escrow service for resolving a dispute.
Events
  • Released(): Triggered when the funds or tokens are released from escrow to the buyer.
  • CancelledByBuyer(): Triggered when the buyer cancels the trade.
  • SellerCancelDisabled(): Triggered when the seller is no longer able to cancel the trade.
  • CancelledBySeller(): Triggered when the seller cancels the trade.
  • DisputeOpened(address _sender): Triggered when a dispute is opened by either the buyer or the seller.
  • DisputeResolved(): Triggered when a dispute is resolved by the arbitrator.
Functions
  • initialize(address payable _seller, address payable _buyer, address _token, uint256 _amount, uint256 _fee, address _arbitrator, address payable _feeRecipient, uint32 _sellerWaitingTime, address trustedForwarder) external virtual initializer: Initializes the contract with the given parameters. It is called by the deployer after deploying the contract.
  • createNativeEscrow(bytes32 _orderID, address payable _buyer, uint256 _amount, address payable _partner): Creates an escrow for the native token of the chain.
  • createERC20Escrow(bytes32 _orderID, address payable _buyer, address _token, uint256 _amount, address payable _partner): Creates an escrow for a ERC20 token.
  • release(bytes32 _orderID, address payable _buyer, address _token, uint256 _amount) external onlySeller returns (bool): Releases the funds or tokens from escrow to the buyer. It can only be called by the seller.
  • buyerCancel(bytes32 _orderID, address payable _buyer, address _token, uint256 _amount) external returns (bool): Cancels the trade and refunds the funds or tokens to the seller. It can only be called by the buyer.
  • sellerCancel(bytes32 _orderID, address payable _buyer, address _token, uint256 _amount) external onlySeller returns (bool): Cancels the trade and refunds the funds or tokens to the buyer. It can only be called by the seller, but only after the sellerCanCancelAfter timestamp has passed. It can only be called by the seller.
  • openDispute(bytes32 _orderID, address payable _buyer, address _token, uint256 _amount) external payable returns (bool): Opens a dispute for the current trade. It can be called by either the buyer or the seller, but only once.
  • resolveDispute(bytes32 _orderID, address payable _buyer, address _token, uint256 _amount, address payable _winner): Resolves a dispute between a buyer and a seller by determining the outcome of the dispute. The _buyerWins parameter specifies whether the buyer wins the dispute (true) or the seller wins the dispute (false).
    This function can only be called by the designated arbitrator, as specified by the onlyArbitrator modifier. Once called, the function will update the state of the contract to reflect the outcome of the dispute. If the buyer wins the dispute, the contract will transfer the escrowed funds to the buyer. If the seller wins the dispute, the contract will transfer the escrowed funds to the seller.