src/Ambi.sol. Inherits ReentrancyGuard and Ownable2Step.
Constants and state
States:
Missing, Listed, Matched, Filled, Refunded, Canceled.
Listing
Escrows
amount of token (address(0) for ETH, sent as msg.value) and lists the order.Reverts with InvalidTerms if amounts are zero, any of chain, asset, recipient is empty, the token has no code, msg.value is wrong, or the verifier’s accepts returns false. PaymentWindowTooShort if payBy is under MIN_WINDOW away. VerifierUnavailable (from the registry) if the verifier isn’t approved or its code changed. TransferFailed if the market’s balance didn’t rise by exactly amount.Emits Listed(id, maker, token, amount, bond, request).Lists exactly as
list does, and records an integrator that earns bps of the escrow at release. InvalidTerms if bps is 0 or above MAX_INTEGRATOR_BPS, or integrator is zero or the market. Emits Listed and IntegratorSet(id, integrator, bps).Requests
Posts the bond (
msg.value must equal bond) and joins the order’s requests. Unavailable if not listed, past payBy, called by the maker, or already requested. InvalidBond if the value is wrong. InterestLimit at 64 requests. Emits Interested(id, filler, bond).Same as
requestFill, with the escrow credited to payout if this filler is matched. The filler still pays from their own address, and the bond still returns to the filler. InvalidTerms if payout is zero or the market. Emits Interested and PayoutRequested(id, filler, payout).Leaves the requests while the order is listed. The bond is credited back. Emits
InterestWithdrawn(id, filler, bond).Matching
Selects one requester.
Unauthorized if not the maker. Unavailable if not listed or filler didn’t request. PaymentWindowTooShort if under MIN_WINDOW remains. VerifierCodeChanged if the verifier’s code no longer matches. Every other bond is credited back. Emits Matched(id, filler, statement).Settlement
Settles a Paid order. Requires
Matched, unchanged verifier code, and verify(statement, proof) true (InvalidProof otherwise). Credits amount − fee − integrator fee to the filler (or payoutOf(id)), the bond to the filler, feeRecipient the fee and the integrator its fee, where fee = amount × 30 / 10,000 and the integrator fee is amount × bps / 10,000, both rounded down. Emits FeeTaken(id, token, fee), IntegratorFeeTaken when there is one, and Filled(id, filler).Settles an ExpiredUnpaid order. Requires
Matched, unchanged verifier code, and verifyExpired(statement, proof) true. Credits the maker the escrow and the filler’s bond. Emits Refunded(id).Closes a listed order. Before
payBy only the maker can call it. Credits the maker the escrow and every requester their bond. Emits Refunded(id).Cancellation
Opens a cancel proposal on a matched order. Emits
CancelProposed(id, proposer).Accepts the open proposal. Reverts with
Unavailable if the verifier already reports Paid for the statement. Credits the maker the escrow and the filler the bond; the order becomes Canceled. Emits CancelAccepted(id, accepter).Withdrawals
Sends the caller’s whole credit for
token to to. Reverts with InvalidTerms for a zero credit, a zero to or the market itself, and TransferFailed unless both balances moved by exactly the amount. Emits Withdrawn(owner, asset, to, amount).Administration
The owner has no other power over the market. It can’t move escrow or credits, change the fee rate, changeMIN_WINDOW, pause the market or upgrade it.
Payload functions
matchWithPayload and publishPayload let the matched parties pin an off-chain ciphertext digest. They play no part in normal settlement.