Skip to content

ASP for monitoring blockchain activity and producing auditable risk decisions

License

Notifications You must be signed in to change notification settings

vickyshaw29/chainwatch-asp

Repository files navigation

ChainWatch ASP

ChainWatch ASP is a production-style, off-chain evaluation backend that models how an Association Set Provider (ASP) processes on-chain events and produces compliance decisions.

It demonstrates how smart contract events can be ingested, evaluated against risk rules, and converted into enforceable eligibility decisions:

Smart Contract → Watcher → ASP Backend → Rule Engine → Decision Store → Eligibility Guard


🔎 What This Project Shows

This project simulates the compliance and risk layer of a privacy-aware protocol.

It implements:

  • On-chain event ingestion via watcher
  • Asynchronous evaluation pipeline
  • Deterministic rule engine (deny > flag > allow)
  • Persistent decision storage
  • Admin-managed policy layer
  • Eligibility enforcement API

This is not just CRUD — it is an event-driven compliance backend.


🏗 Architecture

1️⃣ Watcher (Worker Process)

  • Listens to smart contract events via ethers.js
  • Automatically forwards structured events to POST /events
  • Runs independently from API server

2️⃣ Event Ingestion

POST /events

  • Stores event in Postgres
  • Enforces idempotency using (tx_hash, log_index)
  • Dispatches asynchronous evaluation

3️⃣ Rule Engine

Each event is evaluated against modular rules:

  • sanctionsRule → deny blocked senders
  • amountRule → flag high-value deposits
  • velocityRule → flag abnormal frequency

Priority resolution:

deny > flag > allow

All rules run; final decision is deterministic and auditable.

4️⃣ Decision Storage

Events and decisions are persisted:

  • events
  • decisions
  • blocked_addresses

Schema managed via node-pg-migrate.

5️⃣ Eligibility Guard

GET /eligibility/:eventId

Used by relayers, frontends, or middleware before allowing sensitive actions.

Example response:

{
  "eligible": false,
  "status": "deny",
  "reason": "sender is blocked"
}

This simulates how compliance decisions are enforced off-chain.

6️⃣ Admin Policy Layer

POST /admin/block-address

Allows operators to manage blocked addresses.
Policy updates directly affect evaluation outcomes.


🚀 How To Run

Start API server:

npm run dev

Start watcher worker:

npm run watcher

🧠 Design Highlights

  • Clean separation: controllers → services → repositories → rules
  • Async evaluation via dispatcher
  • Idempotent event ingestion
  • Modular, extensible rule engine
  • Clear enforcement boundary (eligibility API)
  • Worker + API process separation
  • Audit-ready decision storage

🎯 Why This Matters

This project models real-world off-chain compliance systems used in:

  • Privacy infrastructure
  • Risk evaluation pipelines
  • Relayer-based architectures
  • Policy-driven transaction filtering

About

ASP for monitoring blockchain activity and producing auditable risk decisions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published