The worker
One background process that reads the escrow, buys bills, asks providers again, settles on chain, pays rewards and sends notices, each job safe to run twice.
On start it runs the database migrations, starts pg-boss, registers the jobs, starts the escrow indexer and the Telegram bot (when configured), and writes a heartbeat every 30 seconds that /api/health reads.
Jobs
| Job | What it does | Runs |
|---|---|---|
delivery.vend | Buys the bill from the provider. Never retried by the queue | On OrderPaid; 4 at a time |
delivery.requery | Asks the provider again | On the ladder, on a webhook; 4 at a time |
chain.operator | release, refund, claimFromPot, reclaimPot | One at a time (one signer) |
orders.expire | Marks unpaid prices expired | Every minute |
orders.sweep | Re-sends anything stuck (a purchase, a settlement, a requery) | Every minute and at start |
rates.refresh | The naira rate from Paycrest, a QIE price sample | Every minute |
float.refresh | Provider balances; opens or closes the float breaker | Every minute |
escrow.solvency | Compares the escrow's balance with what it owes | Every minute |
feed.publish | A new naira round when needed | Every 5 minutes |
rewards.payout | Cashback, invite and shop rewards, gas drips, in QIE | Every minute and after each release |
drops.tend | Clears failed claims, sends ended pots home | Every minute |
telegram.notify, telegram.reminders, telegram.ops | Notices, reminders, operator alerts | On events; reminders every minute |
oauth.purge | Old sign-in requests, dead tokens, unused app registrations | Daily |
Jobs that touch one order use a singleton key per order, so the same work can't run twice at once.
The indexer
It reads the escrow's logs every 4 seconds in windows of up to 9,000 blocks, from one RPC node per pass (rotating through the five), and writes the events and its cursor (block number and hash) in one database transaction. If a stored block's hash changes, it rewinds 100 blocks. One advisory lock keeps it to one runner. Events are processed once, in chain order. The app's "I paid" call and the operator lane's own receipts feed the same handler.
Signing lanes
| Key | Signs | Can it move money? |
|---|---|---|
| Quote key (web) | EIP-712 prices only | No |
| Operator (worker) | release, refund, claimFromPot, reclaimPot | Only along the contract's three paths |
| Feed key (worker) | Rate feed rounds | No |
| Rewards (worker) | QIE transfers for rewards and gas drips, under daily caps | From its own small wallet |
| Admin | Roles, limits, unpause | Never on the server |
Each lane takes a database lock for its address, simulates the call, estimates gas (limit × 1.2), picks the nonce, signs, stores the signed transaction, then broadcasts and waits for the receipt. After a crash, stored transactions are re-sent first, oldest nonce first. A (purpose, ref) pair can only ever have one transaction, and before a release or refund the lane reads the order on chain to make sure it is still Held.