From 7c6219e8ce9b273cb50f65f6d4f00833b1f6b375 Mon Sep 17 00:00:00 2001 From: Sewmina Date: Sun, 11 Jan 2026 12:38:39 +0530 Subject: [PATCH] init --- .env.example | 9 + .gitignore | 9 + README.md | 126 +++ database/schema.sql | 56 ++ package-lock.json | 1973 +++++++++++++++++++++++++++++++++++++++++++ package.json | 30 + src/database.ts | 379 +++++++++ src/index.ts | 606 +++++++++++++ tsconfig.json | 18 + 9 files changed, 3206 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 README.md create mode 100644 database/schema.sql create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/database.ts create mode 100644 src/index.ts create mode 100644 tsconfig.json diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..88b8a64 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# Database Configuration +DB_HOST=vps.playpoolstudios.com +DB_PORT=3306 +DB_USER=root +DB_PASSWORD=3kcu087vIDyx)0gg +DB_NAME=hyperliquid_tracker + +# Server Configuration +PORT=3000 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32a7e47 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +node_modules/ +dist/ +*.log +.env +.env.local +.DS_Store +wallets.json +wallets.json.backup + diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f483cd --- /dev/null +++ b/README.md @@ -0,0 +1,126 @@ +# Hyperliquid Wallet PnL Tracker + +Automatically track wallet addresses from Hyperliquid trades and sort them by highest PnL. + +## Features + +- 🔄 **Automatic Trade Tracking**: Real-time monitoring of trades on Hyperliquid +- 💾 **MySQL Database Storage**: Persistent storage of tracked wallets +- 📊 **PnL Sorting**: Automatically sorts wallets by highest profit/loss +- 🚀 **REST API**: Query tracked wallets and their PnL data +- 📈 **Historical Tracking**: Optional PnL snapshot history + +## Prerequisites + +- Node.js >= 20.16.0 +- MySQL 5.7+ or MariaDB 10.3+ +- npm or yarn + +## Installation + +1. Clone the repository and install dependencies: +```bash +npm install +``` + +2. Set up MySQL database: +```bash +# Create database +mysql -u root -p < database/schema.sql + +# Or manually: +# CREATE DATABASE hyperliquid_tracker; +# USE hyperliquid_tracker; +# source database/schema.sql; +``` + +3. Configure environment variables: +```bash +cp .env.example .env +# Edit .env with your database credentials +``` + +## Environment Variables + +Create a `.env` file in the root directory: + +```env +DB_HOST=localhost +DB_PORT=3306 +DB_USER=root +DB_PASSWORD=your_password +DB_NAME=hyperliquid_tracker +PORT=3000 +``` + +## Usage + +### Development +```bash +npm run dev +``` + +### Production +```bash +npm run build +npm start +``` + +## API Endpoints + +### Get Tracked Wallets Sorted by PnL +```bash +GET /api/wallets/tracked +``` + +Returns all automatically tracked wallets sorted by PnL (highest first). + +### Get List of Tracked Wallets +```bash +GET /api/wallets/list +``` + +Returns list of all tracked wallet addresses. + +### Manually Add Wallets +```bash +POST /api/wallets/track +Content-Type: application/json + +{ + "wallets": ["0x123...", "0x456..."] +} +``` + +### Query Specific Wallets PnL +```bash +GET /api/wallets/pnl?wallets=0x123...,0x456... +``` + +Or POST: +```bash +POST /api/wallets/pnl +Content-Type: application/json + +{ + "wallets": ["0x123...", "0x456..."] +} +``` + +## Database Schema + +The application creates two main tables: + +- **wallets**: Stores tracked wallet addresses with metadata +- **wallet_pnl_snapshots**: Optional historical PnL snapshots + +See `database/schema.sql` for full schema details. + +## Migration from JSON + +If you have an existing `wallets.json` file, the application will automatically migrate wallets to the database on first run. The original file will be backed up to `wallets.json.backup`. + +## License + +ISC + diff --git a/database/schema.sql b/database/schema.sql new file mode 100644 index 0000000..64e0a8e --- /dev/null +++ b/database/schema.sql @@ -0,0 +1,56 @@ +-- Hyperliquid Wallet Tracker Database Schema + +-- Create database (uncomment if needed) +CREATE DATABASE IF NOT EXISTS hyperliquid_tracker CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +USE hyperliquid_tracker; + +-- Wallets table to store tracked wallet addresses +CREATE TABLE IF NOT EXISTS wallets ( + id INT AUTO_INCREMENT PRIMARY KEY, + address VARCHAR(66) NOT NULL UNIQUE COMMENT 'Wallet address (normalized to lowercase)', + first_seen_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'When this wallet was first tracked', + last_seen_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last time this wallet was seen in trades', + trade_count INT DEFAULT 1 COMMENT 'Number of times this wallet has been seen in trades', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + INDEX idx_address (address), + INDEX idx_last_seen (last_seen_at), + INDEX idx_trade_count (trade_count) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Tracked wallet addresses from Hyperliquid trades'; + +-- Wallet PnL snapshots table (optional - for historical tracking) +CREATE TABLE IF NOT EXISTS wallet_pnl_snapshots ( + id INT AUTO_INCREMENT PRIMARY KEY, + wallet_id INT NOT NULL, + wallet_address VARCHAR(66) NOT NULL, + pnl DECIMAL(30, 8) COMMENT 'Profit and Loss value', + account_value DECIMAL(30, 8) COMMENT 'Total account value', + unrealized_pnl DECIMAL(30, 8) COMMENT 'Unrealized PnL', + snapshot_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (wallet_id) REFERENCES wallets(id) ON DELETE CASCADE, + INDEX idx_wallet_id (wallet_id), + INDEX idx_wallet_address (wallet_address), + INDEX idx_snapshot_at (snapshot_at) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Historical PnL snapshots for tracked wallets'; + +-- View for wallets with latest PnL +CREATE OR REPLACE VIEW wallets_with_latest_pnl AS +SELECT + w.id, + w.address, + w.first_seen_at, + w.last_seen_at, + w.trade_count, + wps.pnl, + wps.account_value, + wps.unrealized_pnl, + wps.snapshot_at as last_pnl_snapshot +FROM wallets w +LEFT JOIN wallet_pnl_snapshots wps ON w.id = wps.wallet_id +LEFT JOIN ( + SELECT wallet_id, MAX(snapshot_at) as max_snapshot + FROM wallet_pnl_snapshots + GROUP BY wallet_id +) latest ON w.id = latest.wallet_id AND wps.snapshot_at = latest.max_snapshot; + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..daead35 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1973 @@ +{ + "name": "hypr_tracker", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "hypr_tracker", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@nktkas/hyperliquid": "^0.30.2", + "dotenv": "^17.2.3", + "express": "^4.18.2", + "mysql2": "^3.16.0", + "ws": "^8.19.0" + }, + "devDependencies": { + "@types/express": "^4.17.21", + "@types/node": "^20.10.0", + "@types/ws": "^8.18.1", + "ts-node": "^10.9.2", + "tsx": "^4.21.0", + "typescript": "^5.3.3" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.2.tgz", + "integrity": "sha512-GZMB+a0mOMZs4MpDbj8RJp4cw+w1WV5NYD6xzgvzUJ5Ek2jerwfO2eADyI6ExDSUED+1X8aMbegahsJi+8mgpw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.2.tgz", + "integrity": "sha512-DVNI8jlPa7Ujbr1yjU2PfUSRtAUZPG9I1RwW4F4xFB1Imiu2on0ADiI/c3td+KmDtVKNbi+nffGDQMfcIMkwIA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.2.tgz", + "integrity": "sha512-pvz8ZZ7ot/RBphf8fv60ljmaoydPU12VuXHImtAs0XhLLw+EXBi2BLe3OYSBslR4rryHvweW5gmkKFwTiFy6KA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.2.tgz", + "integrity": "sha512-z8Ank4Byh4TJJOh4wpz8g2vDy75zFL0TlZlkUkEwYXuPSgX8yzep596n6mT7905kA9uHZsf/o2OJZubl2l3M7A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.2.tgz", + "integrity": "sha512-davCD2Zc80nzDVRwXTcQP/28fiJbcOwvdolL0sOiOsbwBa72kegmVU0Wrh1MYrbuCL98Omp5dVhQFWRKR2ZAlg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.2.tgz", + "integrity": "sha512-ZxtijOmlQCBWGwbVmwOF/UCzuGIbUkqB1faQRf5akQmxRJ1ujusWsb3CVfk/9iZKr2L5SMU5wPBi1UWbvL+VQA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.2.tgz", + "integrity": "sha512-lS/9CN+rgqQ9czogxlMcBMGd+l8Q3Nj1MFQwBZJyoEKI50XGxwuzznYdwcav6lpOGv5BqaZXqvBSiB/kJ5op+g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.2.tgz", + "integrity": "sha512-tAfqtNYb4YgPnJlEFu4c212HYjQWSO/w/h/lQaBK7RbwGIkBOuNKQI9tqWzx7Wtp7bTPaGC6MJvWI608P3wXYA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.2.tgz", + "integrity": "sha512-vWfq4GaIMP9AIe4yj1ZUW18RDhx6EPQKjwe7n8BbIecFtCQG4CfHGaHuh7fdfq+y3LIA2vGS/o9ZBGVxIDi9hw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.2.tgz", + "integrity": "sha512-hYxN8pr66NsCCiRFkHUAsxylNOcAQaxSSkHMMjcpx0si13t1LHFphxJZUiGwojB1a/Hd5OiPIqDdXONia6bhTw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.2.tgz", + "integrity": "sha512-MJt5BRRSScPDwG2hLelYhAAKh9imjHK5+NE/tvnRLbIqUWa+0E9N4WNMjmp/kXXPHZGqPLxggwVhz7QP8CTR8w==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.2.tgz", + "integrity": "sha512-lugyF1atnAT463aO6KPshVCJK5NgRnU4yb3FUumyVz+cGvZbontBgzeGFO1nF+dPueHD367a2ZXe1NtUkAjOtg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.2.tgz", + "integrity": "sha512-nlP2I6ArEBewvJ2gjrrkESEZkB5mIoaTswuqNFRv/WYd+ATtUpe9Y09RnJvgvdag7he0OWgEZWhviS1OTOKixw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.2.tgz", + "integrity": "sha512-C92gnpey7tUQONqg1n6dKVbx3vphKtTHJaNG2Ok9lGwbZil6DrfyecMsp9CrmXGQJmZ7iiVXvvZH6Ml5hL6XdQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.2.tgz", + "integrity": "sha512-B5BOmojNtUyN8AXlK0QJyvjEZkWwy/FKvakkTDCziX95AowLZKR6aCDhG7LeF7uMCXEJqwa8Bejz5LTPYm8AvA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.2.tgz", + "integrity": "sha512-p4bm9+wsPwup5Z8f4EpfN63qNagQ47Ua2znaqGH6bqLlmJ4bx97Y9JdqxgGZ6Y8xVTixUnEkoKSHcpRlDnNr5w==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.2.tgz", + "integrity": "sha512-uwp2Tip5aPmH+NRUwTcfLb+W32WXjpFejTIOWZFw/v7/KnpCDKG66u4DLcurQpiYTiYwQ9B7KOeMJvLCu/OvbA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.2.tgz", + "integrity": "sha512-Kj6DiBlwXrPsCRDeRvGAUb/LNrBASrfqAIok+xB0LxK8CHqxZ037viF13ugfsIpePH93mX7xfJp97cyDuTZ3cw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.2.tgz", + "integrity": "sha512-HwGDZ0VLVBY3Y+Nw0JexZy9o/nUAWq9MlV7cahpaXKW6TOzfVno3y3/M8Ga8u8Yr7GldLOov27xiCnqRZf0tCA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.2.tgz", + "integrity": "sha512-DNIHH2BPQ5551A7oSHD0CKbwIA/Ox7+78/AWkbS5QoRzaqlev2uFayfSxq68EkonB+IKjiuxBFoV8ESJy8bOHA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.2.tgz", + "integrity": "sha512-/it7w9Nb7+0KFIzjalNJVR5bOzA9Vay+yIPLVHfIQYG/j+j9VTH84aNB8ExGKPU4AzfaEvN9/V4HV+F+vo8OEg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.2.tgz", + "integrity": "sha512-LRBbCmiU51IXfeXk59csuX/aSaToeG7w48nMwA6049Y4J4+VbWALAuXcs+qcD04rHDuSCSRKdmY63sruDS5qag==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.2.tgz", + "integrity": "sha512-kMtx1yqJHTmqaqHPAzKCAkDaKsffmXkPHThSfRwZGyuqyIeBvf08KSsYXl+abf5HDAPMJIPnbBfXvP2ZC2TfHg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.2.tgz", + "integrity": "sha512-Yaf78O/B3Kkh+nKABUF++bvJv5Ijoy9AN1ww904rOXZFLWVc5OLOfL56W+C8F9xn5JQZa3UX6m+IktJnIb1Jjg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.2.tgz", + "integrity": "sha512-Iuws0kxo4yusk7sw70Xa2E2imZU5HoixzxfGCdxwBdhiDgt9vX9VUCBhqcwY7/uh//78A1hMkkROMJq9l27oLQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.2.tgz", + "integrity": "sha512-sRdU18mcKf7F+YgheI/zGf5alZatMUTKj/jNS6l744f9u3WFu4v7twcUI9vu4mknF4Y9aDlblIie0IM+5xxaqQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@nktkas/hyperliquid": { + "version": "0.30.2", + "resolved": "https://registry.npmjs.org/@nktkas/hyperliquid/-/hyperliquid-0.30.2.tgz", + "integrity": "sha512-xz1/oGRunLxY1z1FOsCsXUFOWx8ADL3vL87pQkpl68gIxHT6Duf5z18uxFQWxlPPyB5PHYmpudlziJ6xVPB4Vw==", + "license": "MIT", + "dependencies": { + "@nktkas/rews": "^1.2.3", + "@noble/hashes": "^2.0.1", + "micro-eth-signer": "^0.18.1", + "valibot": "1.2.0" + }, + "bin": { + "hyperliquid": "esm/bin/cli.js" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/@nktkas/rews": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@nktkas/rews/-/rews-1.2.3.tgz", + "integrity": "sha512-cpfcIlkUpYlbAI1cvfCTBCajWZfUM6gWyuCJXszECKxdetsU3vURKC8Sz//MDR6RWoULk9T48eJ+0agxT7yB1w==", + "license": "MIT", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/@noble/curves": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-2.0.1.tgz", + "integrity": "sha512-vs1Az2OOTBiP4q0pwjW5aF0xp9n4MxVrmkFBxc6EKZc6ddYx5gaZiAsZoq0uRRXWbi3AT/sBqn05eRPtn1JCPw==", + "license": "MIT", + "dependencies": { + "@noble/hashes": "2.0.1" + }, + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.0.1.tgz", + "integrity": "sha512-XlOlEbQcE9fmuXxrVTXCTlG2nlRXa9Rj3rr5Ue/+tX+nmkgbX720YHh0VR3hBF9xDvwnb8D2shVGOwNx+ulArw==", + "license": "MIT", + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/base": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-2.0.0.tgz", + "integrity": "sha512-3E1kpuZginKkek01ovG8krQ0Z44E3DHPjc5S2rjJw9lZn3KSQOs8S7wqikF/AH7iRanHypj85uGyxk0XAyC37w==", + "license": "MIT", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.12.tgz", + "integrity": "sha512-UCYBaeFvM11aU2y3YPZ//O5Rhj+xKyzy7mvcIoAjASbigy8mHMryP5cK7dgjlz2hWxh1g5pLw084E0a/wlUSFQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/body-parser": { + "version": "1.19.6", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", + "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "node_modules/@types/connect": { + "version": "3.4.38", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", + "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/express": { + "version": "4.17.25", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.25.tgz", + "integrity": "sha512-dVd04UKsfpINUnK0yBoYHDF3xu7xVH4BuDotC/xGuycx4CgbP48X/KF/586bcObxT0HENHXEU8Nqtu6NR+eKhw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.33", + "@types/qs": "*", + "@types/serve-static": "^1" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "4.19.8", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.8.tgz", + "integrity": "sha512-02S5fmqeoKzVZCHPZid4b8JH2eM5HzQLZWN2FohQEy/0eXTq8VXZfSN6Pcr3F6N9R/vNrj7cpgbhjie6m/1tCA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*", + "@types/send": "*" + } + }, + "node_modules/@types/http-errors": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", + "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/mime": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", + "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "20.19.28", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.28.tgz", + "integrity": "sha512-VyKBr25BuFDzBFCK5sUM6ZXiWfqgCTwTAOK8qzGV/m9FCirXYDlmczJ+d5dXBAQALGCdRRdbteKYfJ84NGEusw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/@types/qs": { + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-eOunJqu0K1923aExK6y8p6fsihYEn/BYuQ4g0CxAAgFc4b/ZLN4CrsRZ55srTdqoiLzU2B2evC+apEIxprEzkQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/range-parser": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", + "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/serve-static": { + "version": "1.15.10", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.10.tgz", + "integrity": "sha512-tRs1dB+g8Itk72rlSI2ZrW6vZg0YrLI81iQSTkMmOqnqCaNr/8Ek4VwWcN5vZgCYWbg/JJSGBlUaYGAOP73qBw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/http-errors": "*", + "@types/node": "*", + "@types/send": "<1" + } + }, + "node_modules/@types/serve-static/node_modules/@types/send": { + "version": "0.17.6", + "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.6.tgz", + "integrity": "sha512-Uqt8rPBE8SY0RK8JB1EzVOIZ32uqy8HwdxCnoCOsYrvnswqmFZ/k+9Ikidlk/ImhsdvBsloHbAlewb2IEBV/Og==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/mime": "^1", + "@types/node": "*" + } + }, + "node_modules/@types/ws": { + "version": "8.18.1", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz", + "integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/acorn": { + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", + "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", + "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "license": "MIT" + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/body-parser": { + "version": "1.20.4", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz", + "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.14.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/dotenv": { + "version": "17.2.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", + "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/esbuild": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.2.tgz", + "integrity": "sha512-HyNQImnsOC7X9PMNaCIeAm4ISCQXs5a5YasTXVliKv4uuBo1dKrG0A+uQS8M5eXjVMnLg3WgXaKvprHlFJQffw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.2", + "@esbuild/android-arm": "0.27.2", + "@esbuild/android-arm64": "0.27.2", + "@esbuild/android-x64": "0.27.2", + "@esbuild/darwin-arm64": "0.27.2", + "@esbuild/darwin-x64": "0.27.2", + "@esbuild/freebsd-arm64": "0.27.2", + "@esbuild/freebsd-x64": "0.27.2", + "@esbuild/linux-arm": "0.27.2", + "@esbuild/linux-arm64": "0.27.2", + "@esbuild/linux-ia32": "0.27.2", + "@esbuild/linux-loong64": "0.27.2", + "@esbuild/linux-mips64el": "0.27.2", + "@esbuild/linux-ppc64": "0.27.2", + "@esbuild/linux-riscv64": "0.27.2", + "@esbuild/linux-s390x": "0.27.2", + "@esbuild/linux-x64": "0.27.2", + "@esbuild/netbsd-arm64": "0.27.2", + "@esbuild/netbsd-x64": "0.27.2", + "@esbuild/openbsd-arm64": "0.27.2", + "@esbuild/openbsd-x64": "0.27.2", + "@esbuild/openharmony-arm64": "0.27.2", + "@esbuild/sunos-x64": "0.27.2", + "@esbuild/win32-arm64": "0.27.2", + "@esbuild/win32-ia32": "0.27.2", + "@esbuild/win32-x64": "0.27.2" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.22.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz", + "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.3", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.12", + "proxy-addr": "~2.0.7", + "qs": "~6.14.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "license": "MIT", + "dependencies": { + "is-property": "^1.0.2" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/get-tsconfig": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz", + "integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", + "license": "MIT" + }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, + "node_modules/lru.min": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.3.tgz", + "integrity": "sha512-Lkk/vx6ak3rYkRR0Nhu4lFUT2VDnQSxBe8Hbl7f36358p6ow8Bnvr8lrLt98H8J1aGxfhbX4Fs5tYg2+FTwr5Q==", + "license": "MIT", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, + "license": "ISC" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/micro-eth-signer": { + "version": "0.18.1", + "resolved": "https://registry.npmjs.org/micro-eth-signer/-/micro-eth-signer-0.18.1.tgz", + "integrity": "sha512-vXKhCZxrytpl+dXR9JeaE41ZVFndi7wCKc1Jd22smOMAeDErvRcXaTxhYUf1yQxis4n2kIdv/pH7iuf+5/cj+Q==", + "license": "MIT", + "dependencies": { + "@noble/curves": "^2.0.0", + "@noble/hashes": "^2.0.0", + "micro-packed": "^0.8.0" + }, + "engines": { + "node": ">= 20.19.0" + } + }, + "node_modules/micro-packed": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/micro-packed/-/micro-packed-0.8.0.tgz", + "integrity": "sha512-AKb8znIvg9sooythbXzyFeChEY0SkW0C6iXECpy/ls0e5BtwXO45J9wD9SLzBztnS4XmF/5kwZknsq+jyynd/A==", + "license": "MIT", + "dependencies": { + "@scure/base": "2.0.0" + }, + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/mysql2": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.16.0.tgz", + "integrity": "sha512-AEGW7QLLSuSnjCS4pk3EIqOmogegmze9h8EyrndavUQnIUcfkVal/sK7QznE+a3bc6rzPbAiui9Jcb+96tPwYA==", + "license": "MIT", + "dependencies": { + "aws-ssl-profiles": "^1.1.1", + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.7.0", + "long": "^5.2.1", + "lru.min": "^1.0.0", + "named-placeholders": "^1.1.3", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.2" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/named-placeholders": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.6.tgz", + "integrity": "sha512-Tz09sEL2EEuv5fFowm419c1+a/jSMiBjI9gHxVLrVdbUkkNUUfjsVYs9pVZu5oCon/kmRh9TfLEObFtkVxmY0w==", + "license": "MIT", + "dependencies": { + "lru.min": "^1.1.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.14.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz", + "integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/seq-queue": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", + "integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/tsx": { + "version": "4.21.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", + "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.27.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "devOptional": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true, + "license": "MIT" + }, + "node_modules/valibot": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/valibot/-/valibot-1.2.0.tgz", + "integrity": "sha512-mm1rxUsmOxzrwnX5arGS+U4T25RdvpPjPN4yR0u9pUBov9+zGVtO84tif1eY4r6zWxVxu3KzIyknJy3rxfRZZg==", + "license": "MIT", + "peerDependencies": { + "typescript": ">=5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/ws": { + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.19.0.tgz", + "integrity": "sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..d5e62ec --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "hypr_tracker", + "version": "1.0.0", + "description": "TypeScript Express Hello World", + "main": "dist/index.js", + "scripts": { + "build": "tsc", + "start": "node dist/index.js", + "dev": "tsx src/index.ts", + "watch": "tsx watch src/index.ts" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@nktkas/hyperliquid": "^0.30.2", + "dotenv": "^17.2.3", + "express": "^4.18.2", + "mysql2": "^3.16.0", + "ws": "^8.19.0" + }, + "devDependencies": { + "@types/express": "^4.17.21", + "@types/node": "^20.10.0", + "@types/ws": "^8.18.1", + "ts-node": "^10.9.2", + "tsx": "^4.21.0", + "typescript": "^5.3.3" + } +} diff --git a/src/database.ts b/src/database.ts new file mode 100644 index 0000000..9ecc374 --- /dev/null +++ b/src/database.ts @@ -0,0 +1,379 @@ +// Load environment variables first +import * as dotenv from 'dotenv'; +import * as path from 'path'; + +// Load .env.local first (higher priority), then .env +const envLocalPath = path.join(process.cwd(), '.env.local'); +const envPath = path.join(process.cwd(), '.env'); + +dotenv.config({ path: envLocalPath }); +dotenv.config({ path: envPath }); // .env.local values will override .env + +import mysql from 'mysql2/promise'; + +// Database configuration +const dbConfig: mysql.PoolOptions = { + host: process.env.DB_HOST || 'localhost', + port: parseInt(process.env.DB_PORT || '3306'), + user: process.env.DB_USER || 'root', + password: process.env.DB_PASSWORD || '', + database: process.env.DB_NAME || 'hyperliquid_tracker', + waitForConnections: true, + connectionLimit: 10, + queueLimit: 0, + // Connection timeout settings + connectTimeout: 60000, // 60 seconds + // Enable keep-alive to prevent connection from being closed + enableKeepAlive: true, + keepAliveInitialDelay: 0, + // For remote connections, often need SSL or allow insecure connections + ...(process.env.DB_SSL === 'true' ? { + ssl: { + rejectUnauthorized: process.env.DB_SSL_REJECT_UNAUTHORIZED !== 'false' + } + } : {}), + // Additional connection options + timezone: 'Z', // Use UTC + charset: 'utf8mb4', + // Multiple statements can help with some connection issues + multipleStatements: false, + // Flags for better compatibility + flags: [ + '-FOUND_ROWS', + '-IGNORE_SPACE', + '-LONG_PASSWORD', + '-LONG_FLAG', + '-TRANSACTIONS', + '-PROTOCOL_41', + '-SECURE_CONNECTION', + ], +}; + +console.log('[DB] Database config loaded:', { + host: dbConfig.host, + port: dbConfig.port, + database: dbConfig.database, + user: dbConfig.user, + passwordSet: !!dbConfig.password, + ssl: dbConfig.ssl ? 'enabled' : 'disabled', +}); + +// Create connection pool +let pool: mysql.Pool | null = null; + +/** + * Initialize database connection pool + */ +export function initDatabase(): mysql.Pool { + if (!pool) { + pool = mysql.createPool(dbConfig); + console.log('[DB] ✅ Database connection pool created'); + console.log('[DB] Config:', { + host: dbConfig.host, + port: dbConfig.port, + database: dbConfig.database, + user: dbConfig.user, + }); + + // Handle connection events + pool.on('connection', (connection: any) => { + console.log('[DB] 🔌 New connection established'); + + connection.on('error', (err: any) => { + console.error('[DB] ❌ Connection error:', err); + if (err.code === 'PROTOCOL_CONNECTION_LOST') { + console.log('[DB] ⚠️ Connection lost, pool will attempt to reconnect'); + } + }); + }); + } + return pool; +} + +/** + * Get database connection pool + */ +export function getPool(): mysql.Pool { + if (!pool) { + return initDatabase(); + } + return pool; +} + +/** + * Test database connection with retry logic + */ +export async function testConnection(maxRetries: number = 3): Promise { + // First, try a direct connection (not pool) to diagnose issues + console.log('[DB] 🔍 Testing direct connection first...'); + + try { + // Create a direct connection for testing (not using pool) + const directConnection = await mysql.createConnection({ + ...dbConfig, + // Reduce timeout for faster failure detection + connectTimeout: 10000, + }); + + console.log('[DB] 🔌 Direct connection established'); + + // Immediately test the connection + const [rows] = await directConnection.query('SELECT 1 as test, DATABASE() as current_db, USER() as current_user, VERSION() as version'); + console.log('[DB] ✅ Test query successful:', rows); + + await directConnection.ping(); + console.log('[DB] ✅ Ping successful'); + + await directConnection.end(); + console.log('[DB] ✅ Direct connection test successful - pool should work now'); + + // If direct connection works, test pool connection + for (let attempt = 1; attempt <= maxRetries; attempt++) { + try { + console.log(`[DB] 🔄 Testing pool connection (${attempt}/${maxRetries})...`); + const connectionPool = getPool(); + + // Try to get a connection from pool + const connection = await connectionPool.getConnection(); + console.log('[DB] 🔌 Connection obtained from pool'); + + // Test with a simple query immediately + const [poolRows] = await connection.query('SELECT 1 as test'); + console.log('[DB] ✅ Pool query successful:', poolRows); + + await connection.ping(); + console.log('[DB] ✅ Pool ping successful'); + + connection.release(); + console.log('[DB] ✅ Connection released back to pool'); + console.log('[DB] ✅ Database connection test successful'); + + return true; + } catch (poolError: any) { + console.error(`[DB] ❌ Pool connection failed (attempt ${attempt}/${maxRetries}):`, poolError.message); + + if (attempt < maxRetries) { + const delay = attempt * 2000; + console.log(`[DB] ⏳ Retrying pool connection in ${delay}ms...`); + await new Promise(resolve => setTimeout(resolve, delay)); + } + } + } + + return false; + } catch (error: any) { + const errorDetails = { + message: error.message, + code: error.code, + errno: error.errno, + sqlState: error.sqlState, + sqlMessage: error.sqlMessage, + fatal: error.fatal, + }; + + console.error('[DB] ❌ Direct connection failed'); + console.error('[DB] Error details:', JSON.stringify(errorDetails, null, 2)); + + // Try to connect without database first to check if it's a database/user issue + if (error.code === 'PROTOCOL_CONNECTION_LOST' || error.code === 'ECONNREFUSED') { + try { + console.log('[DB] 🔍 Attempting connection without database to diagnose issue...'); + const testConfig: any = { + host: dbConfig.host, + port: dbConfig.port, + user: dbConfig.user, + password: dbConfig.password, + connectTimeout: 10000, + }; + + const testConnection = await mysql.createConnection(testConfig); + const [testRows] = await testConnection.query('SELECT 1 as test, USER() as current_user'); + console.log('[DB] ✅ Connection without database works:', testRows); + console.log('[DB] 💡 Issue may be with database name or permissions on that database'); + + // Try to create database if it doesn't exist + try { + await testConnection.query('CREATE DATABASE IF NOT EXISTS ??', [dbConfig.database]); + console.log(`[DB] ✅ Verified/created database: ${dbConfig.database}`); + } catch (dbError: any) { + console.error(`[DB] ❌ Could not create database:`, dbError.message); + } + + await testConnection.end(); + } catch (testError: any) { + console.error('[DB] ❌ Connection without database also failed:', testError.message); + console.error('[DB] 💡 This suggests a fundamental connection/auth issue'); + console.error('[DB] 💡 Troubleshooting steps:'); + console.error(' 1. Verify MySQL user and password are correct'); + console.error(' 2. Check if user can connect from your IP:'); + console.error(' SELECT user, host FROM mysql.user WHERE user = ?;', [dbConfig.user]); + console.error(' 3. Grant permissions:'); + console.error(` GRANT ALL ON ${dbConfig.database}.* TO '${dbConfig.user}'@'%';`); + console.error(' FLUSH PRIVILEGES;'); + console.error(' 4. Check MySQL bind-address in my.cnf (should be 0.0.0.0 or your server IP)'); + } + } + + return false; + } +} + +/** + * Load all tracked wallets from database + */ +export async function loadWalletsFromDB(): Promise { + try { + const connectionPool = getPool(); + const [rows] = await connectionPool.execute( + 'SELECT address FROM wallets ORDER BY last_seen_at DESC' + ); + return rows.map(row => row.address); + } catch (error) { + console.error('[DB] Error loading wallets:', error); + return []; + } +} + +/** + * Add or update wallet in database + */ +export async function addWalletToDB(wallet: string): Promise { + try { + const normalizedWallet = wallet.toLowerCase(); + const connectionPool = getPool(); + + // Use INSERT ... ON DUPLICATE KEY UPDATE to handle existing wallets + await connectionPool.execute( + `INSERT INTO wallets (address, last_seen_at, trade_count) + VALUES (?, NOW(), 1) + ON DUPLICATE KEY UPDATE + last_seen_at = NOW(), + trade_count = trade_count + 1` + , [normalizedWallet]); + + return true; + } catch (error) { + console.error('[DB] Error adding wallet:', error); + return false; + } +} + +/** + * Get wallet by address + */ +export async function getWalletFromDB(wallet: string): Promise { + try { + const normalizedWallet = wallet.toLowerCase(); + const connectionPool = getPool(); + const [rows] = await connectionPool.execute( + 'SELECT * FROM wallets WHERE address = ?', + [normalizedWallet] + ); + return rows.length > 0 ? rows[0] : null; + } catch (error) { + console.error('[DB] Error getting wallet:', error); + return null; + } +} + +/** + * Get all wallets with optional limit + */ +export async function getAllWalletsFromDB(limit?: number): Promise { + try { + const connectionPool = getPool(); + const query = limit + ? 'SELECT * FROM wallets ORDER BY last_seen_at DESC LIMIT ?' + : 'SELECT * FROM wallets ORDER BY last_seen_at DESC'; + + const [rows] = limit + ? await connectionPool.execute(query, [limit]) + : await connectionPool.execute(query); + + return rows as any[]; + } catch (error) { + console.error('[DB] Error getting all wallets:', error); + return []; + } +} + +/** + * Save PnL snapshot for a wallet + */ +export async function savePnLSnapshot( + walletAddress: string, + pnl: string, + accountValue: string, + unrealizedPnl: string +): Promise { + try { + const normalizedWallet = walletAddress.toLowerCase(); + const connectionPool = getPool(); + + // Get wallet ID + const wallet = await getWalletFromDB(normalizedWallet); + if (!wallet) { + console.error(`[DB] Wallet not found for PnL snapshot: ${normalizedWallet}`); + return false; + } + + await connectionPool.execute( + `INSERT INTO wallet_pnl_snapshots (wallet_id, wallet_address, pnl, account_value, unrealized_pnl) + VALUES (?, ?, ?, ?, ?)`, + [wallet.id, normalizedWallet, pnl, accountValue, unrealizedPnl] + ); + + return true; + } catch (error) { + console.error('[DB] Error saving PnL snapshot:', error); + return false; + } +} + +/** + * Get wallets with latest PnL (using the view) + */ +export async function getWalletsWithLatestPnL(): Promise { + try { + const connectionPool = getPool(); + const [rows] = await connectionPool.execute( + 'SELECT * FROM wallets_with_latest_pnl ORDER BY COALESCE(pnl, 0) DESC' + ); + return rows as any[]; + } catch (error) { + console.error('[DB] Error getting wallets with PnL:', error); + return []; + } +} + +/** + * Migrate wallets from JSON file to database + */ +export async function migrateWalletsFromJSON(wallets: string[]): Promise { + let migrated = 0; + try { + const connectionPool = getPool(); + + for (const wallet of wallets) { + const normalizedWallet = wallet.toLowerCase(); + try { + await connectionPool.execute( + `INSERT INTO wallets (address, first_seen_at, last_seen_at) + VALUES (?, NOW(), NOW()) + ON DUPLICATE KEY UPDATE last_seen_at = NOW()`, + [normalizedWallet] + ); + migrated++; + } catch (error) { + console.error(`[DB] Error migrating wallet ${normalizedWallet}:`, error); + } + } + + console.log(`[DB] ✅ Migrated ${migrated} wallets to database`); + return migrated; + } catch (error) { + console.error('[DB] Error during migration:', error); + return migrated; + } +} + diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..0023721 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,606 @@ +// Load environment variables first (before any other imports) +import * as dotenv from 'dotenv'; +import * as path from 'path'; + +// Load .env.local first (higher priority), then .env +const envLocalPath = path.join(process.cwd(), '.env.local'); +const envPath = path.join(process.cwd(), '.env'); + +dotenv.config({ path: envLocalPath }); +dotenv.config({ path: envPath }); // .env.local values will override .env + +console.log('[ENV] Environment variables loaded'); +console.log('[ENV] DB_HOST:', process.env.DB_HOST || 'not set'); +console.log('[ENV] DB_PORT:', process.env.DB_PORT || 'not set'); +console.log('[ENV] DB_NAME:', process.env.DB_NAME || 'not set'); + +import express, { Request, Response } from 'express'; +import { HttpTransport, InfoClient, SubscriptionClient, WebSocketTransport } from '@nktkas/hyperliquid'; +import * as fs from 'fs'; +import WebSocket from 'ws'; +import { + initDatabase, + testConnection, + loadWalletsFromDB, + addWalletToDB, + getAllWalletsFromDB, + savePnLSnapshot, + migrateWalletsFromJSON, +} from './database'; + +// Set WebSocket as global for @nktkas/rews to use in Node.js environment +(global as any).WebSocket = WebSocket; + +const app = express(); +const PORT = process.env.PORT || 3000; + +// Enable JSON parsing +app.use(express.json()); + +const client = new InfoClient({ transport: new HttpTransport() }); + +// Create WebSocket transport with logging +const wsTransport = new WebSocketTransport(); + +// Log WebSocket connection events +const socket = (wsTransport as any).socket; +if (socket) { + socket.addEventListener('open', () => { + console.log('[WEBSOCKET] ✅ Connection opened'); + }); + + socket.addEventListener('close', (event: any) => { + console.log('[WEBSOCKET] ❌ Connection closed:', event.code, event.reason); + }); + + socket.addEventListener('error', (error: any) => { + console.error('[WEBSOCKET] ❌ Connection error:', error); + }); + + socket.addEventListener('message', (event: any) => { + try { + const data = JSON.parse(event.data); + // console.log('[WEBSOCKET] 📨 Received message:', JSON.stringify(data, null, 2)); + } catch (e) { + console.log('[WEBSOCKET] 📨 Received raw message:', event.data); + } + }); +} else { + console.log('[WEBSOCKET] ⚠️ Socket not yet available'); +} + +const subscriptionClient = new SubscriptionClient({ + transport: wsTransport +}); + +console.log('[INIT] Subscription client created:', { + hasTransport: !!wsTransport, + transportType: wsTransport.constructor?.name, +}); + +// Storage for tracked wallet addresses (in-memory cache) +const trackedWallets = new Set(); + +// Initialize database and load wallets +async function initializeDatabase(): Promise { + try { + console.log('[INIT] Initializing database...'); + initDatabase(); + + // Test connection + const connected = await testConnection(); + if (!connected) { + console.error('[INIT] ⚠️ Database connection failed, but continuing...'); + return; + } + + // Load wallets from database + console.log('[INIT] Loading wallets from database...'); + const wallets = await loadWalletsFromDB(); + wallets.forEach(wallet => trackedWallets.add(wallet.toLowerCase())); + console.log(`[INIT] ✅ Loaded ${trackedWallets.size} wallets from database`); + + // Migrate from JSON file if it exists (one-time migration) + const WALLETS_FILE = path.join(process.cwd(), 'wallets.json'); + if (fs.existsSync(WALLETS_FILE)) { + console.log('[INIT] Found wallets.json, attempting migration...'); + try { + const data = fs.readFileSync(WALLETS_FILE, 'utf-8'); + const jsonWallets = JSON.parse(data) as string[]; + const migrated = await migrateWalletsFromJSON(jsonWallets); + console.log(`[INIT] ✅ Migrated ${migrated} wallets from JSON to database`); + + // Reload from database after migration + const updatedWallets = await loadWalletsFromDB(); + trackedWallets.clear(); + updatedWallets.forEach(wallet => trackedWallets.add(wallet.toLowerCase())); + console.log(`[INIT] ✅ Total wallets after migration: ${trackedWallets.size}`); + + // Optionally backup the old file + const backupFile = `${WALLETS_FILE}.backup`; + fs.copyFileSync(WALLETS_FILE, backupFile); + console.log(`[INIT] ✅ Backed up wallets.json to ${backupFile}`); + } catch (error) { + console.error('[INIT] Error during migration:', error); + } + } + } catch (error) { + console.error('[INIT] Error initializing database:', error); + } +} + +// Add wallet to tracking (both in-memory and database) +async function addWallet(wallet: string): Promise { + if (!wallet || typeof wallet !== 'string' || !wallet.startsWith('0x')) { + console.log(`[WALLET] ⚠️ Invalid wallet format, skipping:`, wallet); + return; + } + + const normalizedWallet = wallet.toLowerCase(); + + // Add to in-memory cache + if (!trackedWallets.has(normalizedWallet)) { + trackedWallets.add(normalizedWallet); + } + + // Save to database + try { + const success = await addWalletToDB(normalizedWallet); + if (success) { + console.log(`[WALLET] ✅ Added/updated wallet in database: ${normalizedWallet}`); + console.log(`[WALLET] 📊 Total tracked wallets: ${trackedWallets.size}`); + } else { + console.error(`[WALLET] ❌ Failed to save wallet to database: ${normalizedWallet}`); + } + } catch (error) { + console.error(`[WALLET] ❌ Error saving wallet to database:`, error); + } +} + +interface WalletPnL { + wallet: string; + pnl: string; + accountValue?: string; + unrealizedPnl?: string; + realizedPnl?: string; +} + +/** + * Get PnL for a single wallet + */ +async function getWalletPnL(wallet: string): Promise { + try { + const state = await client.clearinghouseState({ user: wallet }); + + // Extract data from marginSummary + const marginSummary = state.marginSummary; + const accountValue = marginSummary?.accountValue || '0'; + + // Calculate unrealized PnL from assetPositions + // PnL is typically the difference between current value and entry value + let totalUnrealizedPnl = '0'; + + if (state.assetPositions && Array.isArray(state.assetPositions)) { + totalUnrealizedPnl = state.assetPositions.reduce((sum, position: any) => { + // Access unrealizedPnl from position structure + // The structure may vary, so we check multiple possible paths + const positionPnl = + position.position?.unrealizedPnl || + position.unrealizedPnl || + (position.position?.unrealizedPnl || '0'); + const pnlValue = parseFloat(positionPnl) || 0; + return (parseFloat(sum) + pnlValue).toString(); + }, '0'); + } + + // Use totalRawUsd from marginSummary as alternative PnL indicator + // totalRawUsd represents total account value including unrealized PnL + // We can use it to derive PnL if needed + const totalRawUsd = marginSummary?.totalRawUsd || '0'; + + // Primary PnL metric: use unrealized PnL from positions, fallback to calculated value + const pnl = totalUnrealizedPnl !== '0' ? totalUnrealizedPnl : totalRawUsd; + + return { + wallet, + pnl, + accountValue, + unrealizedPnl: totalUnrealizedPnl, + }; + } catch (error) { + console.error(`Error fetching PnL for wallet ${wallet}:`, error); + return null; + } +} + +/** + * Start tracking trades to automatically collect wallet addresses + */ +async function startTradeTracking(): Promise { + try { + console.log('[TRACKING] Starting trade tracking...'); + console.log('[TRACKING] WebSocket transport:', wsTransport); + + // Wait for WebSocket connection to be ready + try { + console.log('[TRACKING] Waiting for WebSocket connection to be ready...'); + await wsTransport.ready(); + console.log('[TRACKING] ✅ WebSocket connection ready!'); + console.log('[TRACKING] WebSocket state:', (wsTransport as any).socket?.readyState); + console.log('[TRACKING] Socket info:', { + readyState: (wsTransport as any).socket?.readyState, + url: (wsTransport as any).socket?.url, + }); + } catch (error) { + console.error('[TRACKING] ❌ Error waiting for WebSocket connection:', error); + throw error; + } + + // Common trading pairs to track + const coinsToTrack = ['ETH', 'BTC', 'SOL', 'ARB', 'AVAX']; + console.log(`[TRACKING] Will subscribe to trades for: ${coinsToTrack.join(', ')}`); + + // Subscribe to trades for multiple coins + for (const coin of coinsToTrack) { + try { + console.log(`[TRACKING] Attempting to subscribe to ${coin} trades...`); + + const subscription = await subscriptionClient.trades({ coin }, (trade: any) => { + console.log(`[TRADE] Received trade data for ${coin}:`, JSON.stringify(trade, null, 2)); + + try { + // Extract wallet addresses from trade data + // Trade structure may vary + console.log(`[TRADE] Processing trade data for ${coin}, structure:`, Object.keys(trade)); + + // Check if trade has a 'trades' array or is a single trade + const trades = trade.trades || (Array.isArray(trade) ? trade : [trade]); + console.log(`[TRADE] Found ${trades.length} trade(s) to process`); + + trades.forEach((t: any, index: number) => { + console.log(`[TRADE] Processing trade ${index + 1}/${trades.length}`); + console.log(`[TRADE] Trade ${index + 1} keys:`, Object.keys(t)); + + // Collect all potential wallet addresses found + const foundWallets: string[] = []; + + // Check various possible fields for wallet address + const wallet = t.user || t.userAddress || t.account || t.side?.user || t.oid?.user || t.closedPnl?.user; + console.log(`[TRADE] Extracted wallet from primary fields:`, wallet); + + // Scan all fields for potential wallet addresses + const scanForWallets = (obj: any, prefix = ''): void => { + if (!obj || typeof obj !== 'object') return; + + Object.keys(obj).forEach(key => { + const value = obj[key]; + const fullPath = prefix ? `${prefix}.${key}` : key; + + if (typeof value === 'string' && value.startsWith('0x') && value.length >= 42) { + console.log(`[TRADE] 🔍 Found potential wallet at '${fullPath}': ${value}`); + foundWallets.push(value); + } else if (typeof value === 'object' && value !== null && !Array.isArray(value)) { + scanForWallets(value, fullPath); + } else if (Array.isArray(value)) { + value.forEach((item, idx) => { + if (typeof item === 'object' && item !== null) { + scanForWallets(item, `${fullPath}[${idx}]`); + } else if (typeof item === 'string' && item.startsWith('0x') && item.length >= 42) { + console.log(`[TRADE] 🔍 Found potential wallet at '${fullPath}[${idx}]': ${item}`); + foundWallets.push(item); + } + }); + } + }); + }; + + // Scan the entire trade object + scanForWallets(t); + + // Add all found wallets (remove duplicates) + const uniqueWallets = [...new Set(foundWallets)]; + console.log(`[TRADE] 📋 Found ${uniqueWallets.length} unique wallet(s):`, uniqueWallets); + + uniqueWallets.forEach(w => { + addWallet(w).catch(err => { + console.error(`[WALLET] Error adding wallet ${w}:`, err); + }); + }); + + // Also check for maker/taker if available + if (t.maker && typeof t.maker === 'string' && t.maker.startsWith('0x')) { + console.log(`[WALLET] Adding wallet from maker field: ${t.maker}`); + addWallet(t.maker).catch(err => { + console.error(`[WALLET] Error adding maker wallet:`, err); + }); + } + if (t.taker && typeof t.taker === 'string' && t.taker.startsWith('0x')) { + console.log(`[WALLET] Adding wallet from taker field: ${t.taker}`); + addWallet(t.taker).catch(err => { + console.error(`[WALLET] Error adding taker wallet:`, err); + }); + } + + if (uniqueWallets.length === 0) { + console.log(`[TRADE] ⚠️ No wallet addresses found in this trade`); + console.log(`[TRADE] Full trade data:`, JSON.stringify(t, null, 2)); + } + }); + } catch (error) { + console.error('[TRADE] Error processing trade:', error); + console.error('[TRADE] Error stack:', (error as Error).stack); + } + }); + + console.log(`[TRACKING] Successfully subscribed to ${coin} trades, subscription:`, subscription); + } catch (error) { + console.error(`[TRACKING] Error subscribing to ${coin} trades:`, error); + console.error(`[TRACKING] Error details:`, (error as Error).stack); + } + } + + console.log('[TRACKING] Trade tracking initialization complete'); + console.log(`[TRACKING] Currently tracking ${trackedWallets.size} wallets`); + } catch (error) { + console.error('[TRACKING] Fatal error starting trade tracking:', error); + console.error('[TRACKING] Error stack:', (error as Error).stack); + } +} + +/** + * API endpoint to get tracked wallets sorted by PnL + * No input required - uses automatically tracked wallets + */ +app.get('/api/wallets/tracked', async (req: Request, res: Response) => { + try { + console.log(`[API] GET /api/wallets/tracked called`); + + // Get wallets from database + const wallets = await loadWalletsFromDB(); + console.log(`[API] Loaded ${wallets.length} wallets from database`); + + if (wallets.length === 0) { + console.log(`[API] ⚠️ No wallets found in database`); + return res.json({ + success: true, + count: 0, + message: 'No wallets tracked yet. Wallets will be added automatically as trades are detected.', + wallets: [], + }); + } + + console.log(`[API] Processing ${wallets.length} wallets for PnL calculation`); + + // Fetch PnL for all tracked wallets in parallel + const walletPnLs = await Promise.all( + wallets.map(async (wallet) => { + const pnlData = await getWalletPnL(wallet); + if (pnlData) { + // Save PnL snapshot to database + await savePnLSnapshot( + wallet, + pnlData.pnl, + pnlData.accountValue || '0', + pnlData.unrealizedPnl || '0' + ).catch(err => { + console.error(`[DB] Error saving PnL snapshot for ${wallet}:`, err); + }); + } + return pnlData; + }) + ); + + // Filter out null results (failed requests) + const validWalletPnLs = walletPnLs.filter((w): w is WalletPnL => w !== null); + + // Sort by PnL (highest first) - convert string to number for sorting + validWalletPnLs.sort((a, b) => { + const pnlA = parseFloat(a.pnl) || 0; + const pnlB = parseFloat(b.pnl) || 0; + return pnlB - pnlA; + }); + + res.json({ + success: true, + count: validWalletPnLs.length, + totalTracked: wallets.length, + wallets: validWalletPnLs, + }); + } catch (error) { + console.error('Error in /api/wallets/tracked:', error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +/** + * API endpoint to manually add wallets to tracking + */ +app.post('/api/wallets/track', async (req: Request, res: Response) => { + try { + const { wallets } = req.body; + + if (!wallets || !Array.isArray(wallets)) { + return res.status(400).json({ + error: 'Missing or invalid wallets array in request body.' + }); + } + + const added: string[] = []; + const existing: string[] = []; + + for (const wallet of wallets) { + if (typeof wallet === 'string' && wallet.startsWith('0x')) { + const normalizedWallet = wallet.toLowerCase(); + const dbWallet = await getAllWalletsFromDB(1000); + const exists = dbWallet.some(w => w.address === normalizedWallet); + + if (exists) { + existing.push(normalizedWallet); + } else { + await addWallet(normalizedWallet); + added.push(normalizedWallet); + } + } + } + + // Reload count from database + const allWallets = await loadWalletsFromDB(); + + res.json({ + success: true, + added, + existing, + totalTracked: allWallets.length, + }); + } catch (error) { + console.error('Error in POST /api/wallets/track:', error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +/** + * API endpoint to get list of tracked wallet addresses (without PnL) + */ +app.get('/api/wallets/list', async (req: Request, res: Response) => { + try { + const wallets = await loadWalletsFromDB(); + res.json({ + success: true, + count: wallets.length, + wallets: wallets, + }); + } catch (error) { + console.error('Error in GET /api/wallets/list:', error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +/** + * API endpoint to get wallets sorted by PnL + * Accepts wallet addresses via query parameter or request body + * + * GET /api/wallets/pnl?wallets=0x123,0x456 + * or + * POST /api/wallets/pnl + * Body: { wallets: ["0x123", "0x456"] } + */ +app.get('/api/wallets/pnl', async (req: Request, res: Response) => { + try { + const walletsParam = req.query.wallets as string; + + if (!walletsParam) { + return res.status(400).json({ + error: 'Missing wallets parameter. Provide comma-separated wallet addresses.' + }); + } + + const wallets = walletsParam.split(',').map(w => w.trim()).filter(w => w.length > 0); + + if (wallets.length === 0) { + return res.status(400).json({ error: 'No valid wallet addresses provided.' }); + } + + // Fetch PnL for all wallets in parallel + const walletPnLs = await Promise.all( + wallets.map(wallet => getWalletPnL(wallet)) + ); + + // Filter out null results (failed requests) + const validWalletPnLs = walletPnLs.filter((w): w is WalletPnL => w !== null); + + // Sort by PnL (highest first) - convert string to number for sorting + validWalletPnLs.sort((a, b) => { + const pnlA = parseFloat(a.pnl) || 0; + const pnlB = parseFloat(b.pnl) || 0; + return pnlB - pnlA; + }); + + res.json({ + success: true, + count: validWalletPnLs.length, + wallets: validWalletPnLs, + }); + } catch (error) { + console.error('Error in /api/wallets/pnl:', error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +/** + * POST endpoint for wallet PnL (alternative to GET) + */ +app.post('/api/wallets/pnl', async (req: Request, res: Response) => { + try { + const { wallets } = req.body; + + if (!wallets || !Array.isArray(wallets) || wallets.length === 0) { + return res.status(400).json({ + error: 'Missing or invalid wallets array in request body.' + }); + } + + // Fetch PnL for all wallets in parallel + const walletPnLs = await Promise.all( + wallets.map((wallet: string) => getWalletPnL(wallet)) + ); + + // Filter out null results (failed requests) + const validWalletPnLs = walletPnLs.filter((w): w is WalletPnL => w !== null); + + // Sort by PnL (highest first) - convert string to number for sorting + validWalletPnLs.sort((a, b) => { + const pnlA = parseFloat(a.pnl) || 0; + const pnlB = parseFloat(b.pnl) || 0; + return pnlB - pnlA; + }); + + res.json({ + success: true, + count: validWalletPnLs.length, + wallets: validWalletPnLs, + }); + } catch (error) { + console.error('Error in POST /api/wallets/pnl:', error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +app.get('/', (req: Request, res: Response) => { + res.json({ + message: 'Hyperliquid Wallet PnL Tracker API', + endpoints: { + 'GET /api/wallets/tracked': 'Get automatically tracked wallets sorted by PnL (no input needed)', + 'GET /api/wallets/list': 'Get list of tracked wallet addresses', + 'POST /api/wallets/track': 'Manually add wallets to tracking', + 'GET /api/wallets/pnl?wallets=0x...': 'Get specific wallets sorted by PnL (query param)', + 'POST /api/wallets/pnl': 'Get specific wallets sorted by PnL (request body)', + }, + stats: { + trackedWallets: trackedWallets.size, + isTracking: true, + }, + example: { + tracked: '/api/wallets/tracked', + manual: '/api/wallets/pnl?wallets=0x123,0x456,0x789' + } + }); +}); + +// Start the server +app.listen(PORT, async () => { + console.log('='.repeat(60)); + console.log(`🚀 Server is running on http://localhost:${PORT}`); + console.log(`📊 API endpoint: http://localhost:${PORT}/api/wallets/tracked`); + console.log('='.repeat(60)); + + // Initialize database first + await initializeDatabase(); + + console.log(`👛 Currently tracking ${trackedWallets.size} wallets`); + + // Start trade tracking after server starts + // Add a small delay to ensure server is fully initialized + setTimeout(async () => { + await startTradeTracking(); + }, 1000); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b432dc9 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "commonjs", + "lib": ["ES2020"], + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "moduleResolution": "node" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} +