How nfttoolz/blurbiddingbot works
Project Type & Purpose
• This is a Node.js CLI tool written in TypeScript that automates bidding on NFT collections on the Blur marketplace.
• Its primary function is to fetch collection data, evaluate pool sizes and bidding criteria, place or cancel bids via Blur’s API, and persist state/configuration locally.
File‐Structure Analysis
Top‐level
• package.json, tsconfig.json – Node/TypeScript config
• sample.env – environment variables template
• src/index.ts – CLI entrypoint
• src/commands/ – command definitions (run, cancel, collections, generateCollectionConfigs)
• src/actions/ – business logic “actions” invoked by each command
• src/blur/ – API client wrappers for Blur REST endpoints and (missing) WS socket
• src/os/ – “operating‐system” helpers mapping higher‐level operations (login, collectionBid, user)
• src/storage/ – file‐based persistence (CSV generation, configs, bids, wallets)
• src/store/ – in‐memory state slices (Redux‐style) for collections and wallets
• src/utils/ – HTTP (axios), blockchain provider, Discord notifications, rate-limiting, logging, feature flags
Core Components
A. CLI Interface
• index.ts invokes a command parser that reads process.argv and dispatches to the appropriate command module.
B. Command Layer (src/commands)
• Thin adapters that call a named “action” (e.g. run → portfolioCheck + bid loops).
C. Action Layer (src/actions)
• Encapsulates bidding logic, failsafe checks, state recovery, health checks, etc.
• Coordinates multiple services: Blur client, OS helpers, storage, store.
D. Blur API Client (src/blur)
• REST calls: bids, collections, healthCheck. (Plus private WS client in premium version.)
E. OS Helpers (src/os)
• High‐level operations like login(), fetch user data, place collection bids.
F. State Management (src/store)
• Redux‐style slices manage runtime state of collections and wallets.
G. Persistence (src/storage)
• Reads/writes JSON/CSV to disk (TMP_DIR) for configs, bids, wallet balances.
H. Utilities (src/utils)
• HTTP wrapper (axios), provider factory (ethers.js), Discord webhook notifier, rate limiter, logger.
I. External Systems
• Blur REST API & (private) WebSocket
• Ethereum RPC node (via provider)
• Discord API
• Local filesystem
Relationships & Data Flows
1. User runs node dist/index.js [action] → CLI Interface
2. CLI calls Command Layer → invokes corresponding Action
3. Action layer:
• Loads config from environment (sample.env → .env)
• Initializes store, storage, utils (provider, logger, rateLimit)
• Calls OS helpers & Blur client to retrieve pool data, user balance
• Applies bidding logic (consts + flags)
• Places/cancels bids via Blur client or OS helper
• Persists results to storage and updates in‐memory store
• Optionally sends Discord notifications
4. Underlying HTTP/RPC calls happen through utils/axios and utils/provider
Architectural Patterns & Design Principles
• Layered architecture: CLI → Command → Action → Service → Data
• Separation of concerns:
• Commands only route to actions
• Actions contain business logic
• API wrappers isolated in src/blur & src/os
• State vs. persistence decoupled (store vs. storage)
• Reusable utilities for cross‐cutting concerns
• Environment‐driven configuration (.env)
• Redux‐style in‐memory store for predictable state updates