Skip to content
Skip to Content
QIE

The escrow contract

TodokuEscrow holds every payment in QUSDC. What it owes can go only to Todoku's treasury after delivery, the payer, or a drop's funder, and it can't be upgraded.

TodokuEscrow (Solidity 0.8.28, OpenZeppelin 5.6.1) is the promise in code. It is not upgradeable: no proxy, no admin who can swap the logic. Money it owes can leave to three places only: Todoku's treasury, the wallet that paid, or a drop's funder; the admin can sweep only the surplus above what it owes.

ContractWhat it doesAddress
TodokuEscrowHolds every payment until delivery, refund or reclaimReading this deployment…
FiatRateFeed (NGN / USD)Todoku's naira rate, published on QIEReading this deployment…

What each function does

FunctionWho may call itWorks while paused?What it does
payWithQIE(quote, sig)The payer named in the quoteNoOpens the orders as Held, swaps the QIE sent for the exact QUSDC on QIEDEX, returns leftover QIE
payWithQUSDC(quote, sig)The payerNoOpens the orders and pulls the exact QUSDC (approve first)
release(orderId)Todoku's operatorNoHeld → Released: the QUSDC goes to the treasury
refund(orderId, reason)Todoku's operatorYesHeld → Refunded: back to the payer, or into the drop's pot while it runs
reclaim(orderId)Only the payerYesAfter RECLAIM_DELAY: Held → Reclaimed, back to the payer
fundPotWithQIE / fundPotWithQUSDCThe funder in the pot quoteNoFunds or tops up a drop's pot
claimFromPot(potId, orderId)Todoku's operatorNoTurns one claim into a Held order paid from the pot
reclaimPot(potId)AnyoneYesAfter the drop ends: what's left goes to the funder
pause / unpausePauser / adminStops new payments and releases; refunds and reclaims keep working
sweepExcess(to)AdminMoves only what the contract holds beyond what it owes

The checks on every payment

Todoku signs each price with EIP-712 (Quote(payer, orderIds[], amounts[], expiry), domain "TodokuEscrow", version 1). The contract refuses a payment when:

  • the caller isn't the payer in the quote, or the quote expired;
  • the signature isn't Todoku's quote key;
  • an order id was used before;
  • one order is over 100 QUSDC, a payment over 2,000 QUSDC or 20 lines;
  • the QUSDC that arrived isn't exactly the total.

Every order sits in one storage slot: payer, amount, paid time and status (None, Held, Released, Refunded, Reclaimed). Each one moves from Held to exactly one ending.

Reclaim

RECLAIM_DELAY is fixed when the contract is deployed: never under 10 minutes; planned at 24 hours for production, and 10 minutes on the test build. The app reads it from the contract, so the order page always shows the real time.

Tested

39 Foundry tests: 25 unit tests, 4 invariants (the balance always covers what is owed; what is owed equals held orders plus pot balances; money in equals money out plus the balance; no QIE left in the contract), 4 for the rate feed, 2 on a QIE mainnet fork (pay in QIE, release; pay in QUSDC, refund on the real router, WQIE and QUSDC), and 4 for the test-chain stand-ins.

Events and the full ABI: Escrow events.

On this page