x402EscrowSolidity:
v0.8.22+License: MIT
Inheritance: Initializable, UUPSUpgradeable, Ownable2StepUpgradeable, AccessControlUpgradeable, ReentrancyGuard
Constants
State Variables
Types
Escrow (Internal Storage)
Packed into a single 32-byte storage slot.EscrowView (Returned by getEscrow)
Full-width types for off-chain consumption.Functions
initialize
Reverts
ZeroAddress()— if any parameter isaddress(0).NotContract()— if_usdchas no code.
settle
Returns
Reverts
InvalidAmount()— ifmaxAmountis zero or exceedstype(uint56).max.NotYetValid()— ifblock.timestamp < validAfter.TimeoutExpired()— ifblock.timestamp >= validBefore.EscrowAlreadyExists()— if an active escrow with this ID already exists.TransferMismatch()— if the actual USDC received differs frommaxAmount.
Deposited(escrowId, client, maxAmount)
release
Behavior
- Payment goes to
msg.sender(the calling facilitator), not a stored address. - If
facilitatorAmount == 0, the full amount returns to the client. - If
facilitatorAmount == escrow.amount, nothing returns to the client. - Escrow storage is cleared before transfers.
EscrowNotFound()— if the escrow does not exist or was already settled/refunded.InvalidAmount()— iffacilitatorAmount > escrow.amount.
Released(escrowId, msg.sender, facilitatorAmount, clientRefund)
refundAfterTimeout
Behavior
- The full amount transfers to the stored
clientaddress regardless of who calls this function. - Escrow storage is cleared before the transfer.
EscrowNotFound()— if the escrow does not exist.TimeoutNotReached()— ifblock.timestamp < escrow.refundAt.
Refunded(escrowId, client, amount)
setTimeout
Reverts
InvalidTimeout()— if outside the valid range.
TimeoutUpdated(_timeoutSecs)
getEscrow
Returns:
EscrowView with:
client— depositor address (zero if the escrow doesn’t exist).amount— USDC locked.refundAt— timestamp when refund becomes available.canRefund—trueifrefundAfterTimeout()can be called now.timeUntilRefund— seconds remaining until refund is available (0 if eligible).
Events
Deposited
settle().
Released
release().
Refunded
refundAfterTimeout().
TimeoutUpdated
setTimeout().