Skip to content

Phase 5: worker and buy scheduler - #113

Merged
MFrancis-dev merged 1 commit into
mainfrom
feat/worker
Nov 4, 2026
Merged

MFrancis-dev merged 1 commit into
mainfrom
feat/worker

Conversation

@MFrancis-dev

Copy link
Copy Markdown
Owner

Implements the background worker (ARCHITECTURE §4.4).

What changed

  • scheduleBuys (K5.3): per vault — skip when paused, not due, a buy is in flight, inside a 15-minute backoff after a skip/failure, or the vault is empty. Buys min(amount_per_run, balance). Real quote (fails closed on signature) → cost check → plan match → row inserted before execute_buy → deposit tx submitted (best effort). Skips, refusals and failures are recorded with a note; refusals and failures raise an alert.
  • pollFunding (K5.2): 1Click status → credited / underpaid (alert) / refunded / failed; pending past the deadline → expired; one bad attempt never stops the rest.
  • pollBuys (K5.4): final status with the actual amount out and destination tx; refunds noted with 1Click's reason (refunds return to the vault).
  • expireQuotes + alerts (K5.5): DB-only expiry of unpaid quotes; keeper NEAR balance alert below 1 NEAR.
  • Runner (K5.1): loops never overlap, errors are logged and the loop continues, SIGINT/SIGTERM wait for running ticks. JSON-line logs without secrets.
  • buys.note column (migration 0001_buy_note).

Smoke run: pnpm worker with no env starts on PGlite, warns that the keeper isn't configured, and stops cleanly on SIGTERM.

Closes #50
Closes #51
Closes #52
Closes #53
Closes #54

Roadmap

  • ROADMAP.md updated: K5.1–K5.5 done, Phase 5 at 100%

Checks

  • 100 tests (16 worker tests covering every scheduler branch), pnpm typecheck, pnpm lint

NEAR HACKATHON rules

  • No secrets; no funds moved; nothing signed with real keys

- scheduleBuys: due / in-flight / 15-min backoff / empty checks, amount =
  min(per-run, balance), real quote, cost check, plan match, row inserted
  before execute_buy, deposit tx submitted; skips, refusals and failures
  recorded with a note and alerted
- pollFunding and pollBuys map 1Click statuses, expire stale quotes,
  record actual amount out, destination tx and refund reasons
- expireQuotes (DB only) and a keeper gas alert
- runner: loops never overlap, survive errors, stop cleanly on signals
- buys.note column (migration 0001); 100 TS tests
@MFrancis-dev
MFrancis-dev merged commit 67c6b13 into main Nov 4, 2026
3 checks passed
@MFrancis-dev
MFrancis-dev deleted the feat/worker branch November 4, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants