Smart contracts
Assay’s contracts hold customer funds and provider stake on Robinhood Chain. They enforce who can spend, collect, refund or penalize those funds. Result checking happens off chain; the contracts enforce the signed payment and penalty instructions they accept.
Addresses: see the Assay app. Payments and stake use USDG. Read the deployed contracts’ current settings before preparing a transaction.
The contracts
Section titled “The contracts”| Contract | Responsibility | Useful reads |
|---|---|---|
AssayEscrow |
Customer deposits, account caps, payment-key permissions, signed payments, payment holds and withdrawals. | escrowOf, held, delegationOf, delegatesOf, effectiveCapsOf, DOMAIN_SEPARATOR |
AssayStake |
Provider deposits, unstaking, reserved penalties, disputes and penalty execution. | stakeOf, bondedOf, withdrawableOf, slashRecordOf, DOMAIN_SEPARATOR |
AssayConfig |
Shared parameters, pause state, blocked accounts, verifier registry and role assignments. Holds no tokens. | params, owner, admin, arbiter, paused, blocked, verifierKey, canSign, slashDelaySeconds, minSlashDelaySeconds, collectHoldSeconds |
All three use upgradeable UUPS proxies. The config owner authorizes upgrades and appoints the admin. Upgrades are a separate power from the day-to-day admin role.
Main functions and events
Section titled “Main functions and events”Customer funds and payment keys
Section titled “Customer funds and payment keys”A delegate is a payment key your wallet authorizes to sign payments within caps and an expiry. It cannot withdraw funds or change account permissions.
| Function | Who uses it and what it does | Main events |
|---|---|---|
deposit(amount), depositFor(...) |
A funder transfers approved tokens into their own or another customer’s escrow. | Deposited |
setLimits(maxVoucherAmount, maxPerWindow) |
The customer sets account ceilings. Zero caps refuse payments. | EscrowLimitsSet, CapsHeld when prior caps are retained |
setLimitsBySig(...) |
Anyone may relay the customer’s signed ceiling change. | Same as setLimits |
authorizeDelegate(...), authorizeDelegateBySig(...) |
The customer grants or updates a key; anyone may relay the signed form. | DelegateAuthorized, DelegateUpdated, possibly CapsHeld |
revokeDelegate(delegate), revokeDelegateBySig(...) |
The customer revokes a key directly or through a signed message anyone may relay. Prior authority has a tightening delay. | DelegateRevoked, CapsHeld |
requestWithdraw(amount), requestWithdrawBySig(...) |
The customer starts the withdrawal wait, directly or through a signed message anyone may relay. | WithdrawRequested with availableAt |
withdraw() |
The customer claims a matured withdrawal to their own wallet, up to the remaining balance. | EscrowWithdrawn |
Payments held for collection
Section titled “Payments held for collection”The Solidity payment instruction is named Voucher. It binds payer, provider, amount, resource hash, request hash, sequence and issue/expiry times. Its EIP-712 domain binds the chain and escrow contract. You normally let assay-mcp construct and sign it.
| Function | Authority and effect | Main events |
|---|---|---|
redeemVoucher(v, sig) |
Redeemer only. Checks the signature, sequence, time window, account and key caps, the provider’s free stake and customer balance. Creates a held payment. | VoucherRedeemed, PaymentHeld, and DelegateVoucherRedeemed for a key-signed payment |
redeemVoucherBatch(vs, sigs) |
Same checks, applied atomically to a batch. | Same events per payment |
collectHeld(payer, seq) |
Redeemer after collectableAt; anyone after the additional timeout. Pays the provider share and treasury fee. |
HeldCollected |
refundHeld(payer, seq) |
Redeemer only, before the refund cutoff. Restores the whole amount to customer escrow. | HeldRefunded |
collectHeldBatch(payers, seqs), refundHeldBatch(payers, seqs) |
Atomic batch forms with the same authority and timing rules. | Same events per payment |
VoucherRedeemed records redemption into a hold. Use HeldCollected to establish provider payment and HeldRefunded to establish a return to customer escrow. A refund does not replenish the on-chain spending-window counter.
Channel payments
Section titled “Channel payments”A payment key can also sign a ChannelVoucher: a running total for one channel instead of one payment per call. Its fields are payer, provider, channelId, cumulative, calls, issuedAt and expiresAt, signed under the same EIP-712 domain. A channel’s key is keccak256(abi.encode(payer, signer, provider, channelId)), where signer is the payer itself when the payer signed.
| Function | Authority and effect | Main events |
|---|---|---|
settleChannels(vs, sigs, fromSettled, charges) |
Redeemer only. Charges at most cumulative minus what the channel already settled into a hold bucket; the rest of the step is waived. An item whose outcome depends on state or time is skipped, not reverted. |
ChannelOpened on a key’s first settlement, ChannelSettled, ChannelBucketDeferred, ChannelSettleSkipped |
collectChannels(refs, keepHeld) |
Redeemer from maturity (it may keep an amount held for an open report); anyone from maturity plus 7 days, keeping nothing. Pays matured buckets to the provider and the fee to the treasury, oldest first. A failed transfer is set aside in unpaid for that recipient alone. |
ChannelCollected, ChannelCollectSkipped, TransferDeferred |
refundChannels(refs, buckets, amounts, refundIds) |
Redeemer only, while the bucket is inside its refund window (until maturityHour × 3,600 + 7 days). Not pause-gated: it moves no token. A bucket is named maturityHour << 16 | takeRateBps. Returns money to the payer’s balance. Each item carries a bytes32 refundId: an id applied once on a channel is never applied again there, in a later call or later in the same batch. An item skipped for any other reason leaves its id unused, so it can be retried. |
ChannelRefunded, ChannelRefundSkipped |
claimUnpaid(to) |
Anyone may call; pays an amount set aside for to, to to only. |
UnpaidClaimed |
channelBooks(key, to) |
Read: the channel’s packed state (the settled total is its low 56 bits), unpaid[to], totalUnpaid and the total channel money held. |
— |
A settle item is skipped, not reverted, when its outcome depends on state or time. ChannelSettleSkipped carries the reason as a uint8 (append-only):
| Value | Reason | Value | Reason |
|---|---|---|---|
| 0 | Expired |
7 | EscrowWindow |
| 1 | NotYetValid |
8 | DelegateWindow |
| 2 | BaseMismatch (fromSettled is not the channel’s settled total) |
9 | Stake (provider below minimum free stake) |
| 3 | Authority (signer not authorized) |
10 | Balance |
| 4 | Calls |
11 | NoBucket (no bucket can take the charge) |
| 5 | Blocked |
12 | BadSignature (the signature does not recover to a valid signer; key is then zero) |
| 6 | PerCallCap |
A refund item is skipped, not reverted, when it cannot apply. ChannelRefundSkipped carries the reason as a uint8:
| Value | Reason | Meaning |
|---|---|---|
| 0 | NoSuchBucket |
The channel holds no bucket with that name (it was collected, or folded into a later maturity). |
| 1 | Insufficient |
The named bucket holds less than amount. |
| 2 | WindowClosed |
The bucket’s refund window has closed. |
| 3 | AlreadyRefunded |
This refundId was already applied on this channel. |
Assay’s redeemer derives one refundId per refunded call. When a collect has left a disputed call’s money split across both buckets of its channel, an upheld refund is sent as up to two pieces, one per bucket, each with its own id keccak256(intentId ‖ k), where k is the piece number. Sum the ChannelRefunded amounts of all pieces to get the call’s refund.
A channel bucket matures at a whole hour: maturityHour is redemption time plus the collection hold, rounded up to the next full hour, in hours since the Unix epoch. A later settlement can fold into a bucket that has not matured and move its maturity later (ChannelBucketDeferred), which extends the refund window of the money in it.
Event changelog
Section titled “Event changelog”| Event | Change |
|---|---|
ChannelOpened(bytes32 indexed key, address signer, bytes32 channelId) |
New. Emitted once per key, just before its first ChannelSettled, in the same item. |
ChannelSettled(bytes32 indexed key, address indexed payer, address indexed provider, uint64 cumulative, uint32 calls, uint64 charge, uint24 maturityHour, uint16 takeRateBps) |
Slimmed: signer, channelId and waived are no longer in it. |
ChannelBucketDeferred(bytes32 indexed key, uint24 fromHour, uint24 toHour, uint16 takeRateBps) |
New. A settlement moved a bucket’s maturity later. |
ChannelSettleSkipped(uint256 indexed index, address indexed payer, bytes32 key, uint64 cumulative, uint8 reason) |
New. A settle item changed nothing; key is zero when the signer was not recovered. Reasons 0–12: Expired, NotYetValid, BaseMismatch, Authority, Calls, Blocked, PerCallCap, EscrowWindow, DelegateWindow, Stake, Balance, NoBucket, BadSignature. |
ChannelCollected(bytes32 indexed key, address indexed provider, uint24 maturityHour, uint64 gross, uint64 fee) |
New. One per bucket paid out. |
ChannelCollectSkipped(bytes32 indexed key, uint8 reason) |
New. Reason 0 = Blocked. |
ChannelRefunded(bytes32 indexed key, address indexed payer, uint40 bucket, uint64 amount, bytes32 refundId) |
New. One per refunded bucket piece; refundId is the item’s id. |
ChannelRefundSkipped(bytes32 indexed key, uint40 bucket, uint64 amount, uint8 reason) |
New. Reasons 0–3 as listed above, including AlreadyRefunded. |
TransferDeferred(address indexed to, uint128 amount), UnpaidClaimed(address indexed to, uint128 amount) |
New. A refused payout set aside in unpaid, and its later claim. |
PaymentHeld, HeldCollected, HeldRefunded |
Unchanged. |
To rebuild what the old event carried:
- Read
signerandchannelIdfor a key from itsChannelOpened. - Derive
waivedper settlement:cumulative − previous cumulative − charge, where the previous cumulative is thecumulativeof the key’s priorChannelSettled(0 for its first). - Read the full history from the escrow’s deploy block. A partial scan gives a wrong previous cumulative.
Provider stake and penalties
Section titled “Provider stake and penalties”A slash is a penalty deducted from provider stake. Proposing one reserves stake; executing it moves money. A signature from a registered verifier is required for a proposal.
A provider’s free stake is its bonded stake minus the reservations of pending and disputed penalties. Redemption pays a provider only while its free stake is at least minimumStake; otherwise it reverts ProviderBelowMinimumStake. Stake reserved by penalties, including penalties the provider disputes, does not back new paid calls. A proposal reserves stake at once, so a single proposal can pause payments to a provider staked at or near the minimum until the record is resolved or the provider adds stake. revokeVerifier does not itself release reservations; expireSlash does, record by record.
| Function | Authority and effect | Main events |
|---|---|---|
depositStake(amount), depositStakeFor(provider, amount) |
Fund your own or another provider’s stake. | StakeDeposited |
requestUnstake(amount) |
Provider moves bonded stake into the waiting pool and restarts its unbonding clock. | UnstakeRequested |
withdrawStake(amount) |
Provider claims matured, unreserved stake to their own wallet. | StakeWithdrawn |
proposeSlash(attestation, sig) |
Anyone may submit a valid verifier-signed data-failure attestation. Checks the penalty ceiling, limits the reservation to the provider’s penalty cap and reserves it from free at-risk stake. If that stake cannot cover the whole reservation, the call reverts and writes nothing; the attestation is not used up and can be submitted again while it is valid. | SlashProposed |
executeSlash(requestId) |
Anyone after the stored delay, while pending and within the execution window. Rechecks the verifier and applies the provider’s rolling penalty cap. No per-verifier-key cap applies. | SlashExecuted |
disputeSlash(requestId) |
Named provider, once, before executableAt. Freezes execution. |
SlashDisputed |
upholdSlash(requestId) |
Arbiter returns a disputed record to pending. Execution still requires its own call. | SlashUpheld |
cancelSlash(requestId) |
Admin or arbiter releases the reservation. | SlashCancelled |
expireSlash(requestId) |
Anyone releases an expired record, an unresolved timed-out dispute, or, at once, a pending or disputed record whose verifier can no longer sign (revoked or expired key). | SlashCancelled with a reason |
disputeSlashBatch, upholdSlashBatch, cancelSlashBatch |
Atomic forms of those actions with the same caller rules. | Same events per record |
For calculation and wallet steps, use Staking and penalties on chain and Dispute a stake penalty on chain.
Configuration and roles
Section titled “Configuration and roles”| Role or function | Power | Main events |
|---|---|---|
Owner: setAdmin, proxy upgrades |
Appoint the admin and authorize upgrades. | AdminSet, proxy Upgraded |
Admin: updateConfig |
Set treasury, redeemer, fee, stake and penalty parameters, within contract bounds. | ConfigUpdated |
Admin: setPaused |
Pause or resume guarded actions. | PauseToggled |
Admin: registerVerifier, revokeVerifier |
Manage the keys whose penalty attestations are accepted. | VerifierRegistered, VerifierRevokedEvent |
Admin: setArbiter, setSlashDelay, setCollectHold |
Choose the dispute arbiter and timing for new records. | ArbiterSet, SlashDelaySet, CollectHoldSet |
setBlocked |
Admin can block or unblock; arbiter can only block. | BlockedSet |
The admin cannot be a non-revoked verifier. The arbiter cannot be the admin, redeemer or a non-revoked verifier. A verifier signs penalty evidence; the redeemer submits payments and held refunds; the arbiter rules on stake disputes.
Pause and blocked accounts
Section titled “Pause and blocked accounts”Pause stops escrow deposits, cap changes, withdrawal requests and claims, new key grants, payment redemption and collection. Stake deposits, unstaking, withdrawals, penalty proposals and execution also stop. Guarded escrow and stake fund actions check the relevant blocked accounts too.
Key revocation, held refunds, stake disputes, rulings, cancellation and expiry remain available during pause. These actions reduce authority or change a reservation without paying funds out. Pause and blocking do not themselves move money.
Limits and clocks
Section titled “Limits and clocks”These are contract bounds and defaults, not a statement of the deployment’s chosen fee or stake requirement. A basis point (bps) is one hundredth of a percentage point.
| Setting | Bound or default |
|---|---|
| Collection hold | Default 3,600 seconds; configurable 60–86,400 seconds; frozen per payment. |
| Public collection and refund cutoff | collectableAt plus 7 days. Refund closes at that instant. |
| Customer withdrawal wait | 10,800 seconds. |
| Tightening delay for lower caps or revocation | 10,800 seconds; key authority never extends beyond its prior expiry. |
| Payment instruction lifetime | At most 300 seconds; up to 120 seconds future clock tolerance; redemption grace 7,200 seconds after expiry. |
| Sequence | Nonzero. Each (payer, seq) pair can be redeemed at most once, in any order. A seq above the highest redeemed one may jump by at most 1,000,000 (MAX_SEQ_GAP). Gaps are allowed. |
| Escrow and key caps | Both per-call and window caps apply. A window counter drains over 24 hours; it is not a fixed midnight reset or an exact trailing sum. |
| Key permission | At most 365 days; up to 16 listed keys per payer. |
| Redemption, held-payment and stake-action batches | 1–64 items; matching arrays where required. One bad item reverts the batch. |
| Channel bucket maturity | Redemption plus the collection hold, rounded up to the next full hour. Each channel keeps at most two buckets. |
| Platform take rate | At most 3,000 bps (30%). Read params() for the actual rate. |
| Unbonding period | Configurable 11–30 days. |
| Penalty proposal delay | Default 72 hours; configurable 48 hours–22 days (10 minutes on testnet); frozen per record. |
| Penalty execution grace | 7 days from executableAt. |
| Unresolved stake dispute timeout | 30 days from disputedAt. |
| Penalty attestation lifetime | At most 7 days. |
| Verifier key lifetime | At most 365 days. |
| Provider penalty cap | Configurable, nonzero and at most 5,000 bps (50%) of the at-risk stake basis, metered over a rolling 24 hours at execution. There is no per-verifier-key cap: verifierDailyCap is still in params() but is not enforced. |
Optional: signing and counter details
The EIP-712 domain name is Assay Settlement, version 2. Escrow and stake have different verifying contracts. Read DOMAIN_SEPARATOR from the relevant proxy. Relayed customer permission changes share an authorization nonce and carry a deadline; these are separate from payment sequences.
The on-chain window counter decays linearly with rounding up. It can permit up to twice the nominal window cap across an arbitrary 24-hour interval. The local MCP’s rolling spending record is a separate guard. effectiveCapsOf includes temporary prior-cap authority; new-call admission must use current permissions and revocation state instead.
Errors
Section titled “Errors”| Contract error | Meaning | Next action |
|---|---|---|
ProgramPaused, AddressBlocked |
A guarded action is frozen. | Read current config and account state. |
NotRedeemer |
The caller cannot submit that payment action. | Use the designated redeemer flow. |
VoucherSeqUsed, VoucherExpired |
That payment sequence number was already used, or the payment’s clock is no longer acceptable. | Reconcile the existing call before signing a replacement. |
VoucherExceedsPerCallLimit, EscrowWindowLimitExceeded |
Account caps refuse redemption. | Read current and retained caps and spending counters. |
DelegateVoucherExceedsPerCallLimit, DelegateWindowLimitExceeded |
Key caps refuse redemption. | Check the authorized key’s caps. |
ProviderBelowMinimumStake, EscrowInsufficient |
The provider’s free stake (bonded minus pending penalty reservations) or the customer balance is too low. | Restore the required stake or customer balance, or wait for pending penalties to be resolved. |
NothingToSlash |
The provider has no at-risk stake, or its free stake cannot cover the whole reservation. Nothing was written. | Submit the attestation again, while it is valid, once other reservations are released. |
HeldNotYetCollectable, HeldRefundWindowClosed, HeldPaymentNotHeld |
Timing or held-payment state does not fit the action. | Read held(payer, seq) before retrying. |
SlashNotYetExecutable, DisputeWindowClosed, SlashNotPending |
Penalty timing or state does not fit. | Read slashRecordOf. |
SlashWindowNotDrained |
The whole reserved penalty does not yet fit its execution caps. | Wait for capacity; do not split the record. |
EmptyBatch, BatchTooLarge, BatchLengthMismatch |
Invalid batch size or array pairing. | Fix the batch before resubmitting. |
