Skip to content

Docs

How a deal works

Lifecycle, states, and who can call what.

Lifecycle

  1. Lock. The payer calls createDeal on the DealFactory with the payee, asset, amount, mode, deadline and one or more tranches. The factory deploys a new Deal clone and moves the earnest into it in the same transaction.
  2. Accept. The payee calls accept. If a payee bond is set, it is posted now. Before acceptance the payer may cancel for a full refund.
  3. Condition. In Metric mode, the Terms are read live. In Handshake mode, the payee calls markDelivered and the payer reviews.
  4. Settle. Anyone calls settle(trancheIndex). The contract releases to the payee, minus the 1 % fee, or refunds the payer, according to the rules below.

Each Deal is its own contract. Its parameters cannot change after creation. The factory holds no funds.

States

StateMeaning
OpenCreated, earnest locked, payee has not accepted. The payer may cancel.
ActiveAccepted by the payee, or a bounty. Terms are live.
DeliveredHandshake only. The payee marked the work delivered. The 72 h review window is running.
SettledFinished, and at least one amount was released to the payee.
RefundedFinished, and nothing was released except a possible kill fee. Includes cancelled and rejected deals.
ExpiredThe payee never accepted and the deadline passed. The earnest was returned.

Bounties have no payee to accept, so they start in Active. See Open bounties.

Who can call what

FunctionCallerWhenEffect
acceptPayeeOpen, before the deadlinePosts the bond if set. State becomes Active.
cancelPayerOpen, named payee onlyFull refund. State becomes Refunded.
markDeliveredPayeeHandshake, Active, before the deadlineState becomes Delivered. Review window starts.
acceptDeliveryPayerDeliveredReleases to the payee. State becomes Settled.
rejectPayerDelivered, inside 72 hKill fee to the payee, rest refunded. State becomes Refunded.
settle(trancheIndex)AnyoneSee belowReleases or refunds.
claim(trancheIndex)AnyoneBounty, Active, Term truePays the caller.
observe(trancheIndex)AnyoneAny timeRecords an observation for Terms that measure over time.

What settle does

settle reads the deal at the moment it is called.

  • Open, past the deadline. Full refund to the payer. State becomes Expired.
  • Metric, Term true. The tranche is released to the payee, minus the fee. This also works after the deadline, as long as nobody has refunded the tranche first.
  • Metric, Term false, past the deadline. The tranche is refunded to the payer.
  • Metric, Term false, before the deadline. Reverts with ConditionNotMet.
  • Handshake, Delivered, 72 h passed. Released to the payee. Silence means release.
  • Handshake, Active, past the deadline. Refunded to the payer. The payee bond, if any, goes to the payer.

"Past the deadline" means the block timestamp is strictly greater than the deadline. At the deadline second itself, the deal is still running.

Payees should call settle as soon as their Term is true. Once the deadline has passed, anyone, including the payer, can call settle the moment the Term reads false, and that refund is final.

Final accounting

A Deal finishes when every tranche is closed. If anything was released, the final state is Settled. If nothing was, it is Refunded. A posted payee bond is returned or forfeited at this point. See Payee bond.

History

Every Deal stores its own history on-chain: creation, acceptance, delivery, each release and refund, bond movements. The deal page reads it directly, so no indexer is needed.