[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-80253":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":14,"stars30d":15,"stars90d":13,"forks30d":13,"starsTrendScore":13,"compositeScore":16,"rankGlobal":8,"rankLanguage":8,"license":17,"archived":18,"fork":18,"defaultBranch":19,"hasWiki":20,"hasPages":18,"topics":21,"createdAt":8,"pushedAt":8,"updatedAt":22,"readmeContent":23,"aiSummary":24,"trendingCount":13,"starSnapshotCount":13,"syncStatus":25,"lastSyncTime":26,"discoverSource":27},80253,"MimicPolymarket","ChiryanOY\u002FMimicPolymarket","ChiryanOY",null,"TypeScript",174,16,6,0,7,64,50.59,"ISC License",false,"main",true,[],"2026-06-12 04:01:27","\u003Cdiv align=\"center\">\n  \u003Ch1>Polymarket Mimic Trading Bot\u003C\u002Fh1>\n  \u003Cp>\u003Ccode>[ CONCURRENCY: MULTI-WALLET ]\u003C\u002Fcode> \u003Ccode>[ ENGINE: ORDER-AGGREGATION ]\u003C\u002Fcode>\u003C\u002Fp>\n  \u003Cp>\u003Cstrong>Industrial-Grade Quantitative Execution Node\u003C\u002Fstrong>\u003C\u002Fp>\n  \u003Cp>\u003Cem>Engineered for Account Abstraction (AA) proxy routing, multi-wallet concurrency, and dynamic order aggregation.\u003C\u002Fem>\u003C\u002Fp>\n  \u003Cp>\u003Cem>\u003Ca href=\"README.md\">English\u003C\u002Fa> | \u003Ca href=\"README.zh-CN.md\">中文\u003C\u002Fa> | \u003Ca href=\"README.ja.md\">日本語\u003C\u002Fa> | \u003Ca href=\"README.ko.md\">한국어\u003C\u002Fa> | \u003Ca href=\"README.es.md\">Español\u003C\u002Fa> | \u003Ca href=\"README.ru.md\">Русский\u003C\u002Fa>\u003C\u002Fem>\u003C\u002Fp>\n  \u003Cp>\n    \u003Ca href=\"LICENSE\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-ISC-blue.svg\" alt=\"License: ISC\" \u002F>\u003C\u002Fa>\n    \u003Ca href=\"https:\u002F\u002Fnodejs.org\u002F\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fnode-%3E%3D18.0.0-brightgreen.svg\" alt=\"Node.js Version\" \u002F>\u003C\u002Fa>\n    \u003Ca href=\"https:\u002F\u002Fpolymarket.com\u002F\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMarket-Polymarket-6b5cff.svg\" alt=\"Polymarket\" \u002F>\u003C\u002Fa>\n    \u003Ca href=\"https:\u002F\u002Fwww.mongodb.com\u002F\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FStorage-MongoDB-47A248.svg\" alt=\"MongoDB\" \u002F>\u003C\u002Fa>\n  \u003C\u002Fp>\n\u003C\u002Fdiv>\n\n## Why Build This System?\n\nIn the high-frequency battlefield of Polymarket, top traders (\"Smart Money\") often execute via numerous micro-trades (snipes). Blind 1:1 mimicking leads to massive gas attrition and extreme slippage. Furthermore, Polymarket's updated API enforces an Account Abstraction-based Deposit Wallet flow, causing traditional EOA calls to be blocked with a `maker address not allowed` error.\n\n**Polymarket Mimic Trading Bot** is not just a simple API wrapper. It is a fully-fledged automated execution node featuring state persistence, an order aggregator, a dynamic risk control engine, and full compatibility with Polymarket's new Relayer routing mechanism.\n\n### Core Architectural Features\n\n- **Trade Aggregation Engine**: Establishes an in-memory time-window (e.g., 5 seconds) to aggregate fragmented snipes on the same market\u002Foutcome within a price threshold into clean batch orders, avoiding rate limits and boosting execution efficiency.\n- **Dynamic Risk & Precision Scaling**: A fine-grained JSON strategy matrix that dynamically calculates execution size based on your capital ratio, automatically handles exchange-specific Tick Size requirements, and enforces strict slippage caps.\n- **AA Proxy Routing (Deposit Wallet Flow)**: Natively implements the `POLY_1271` signature protocol and Relayer interaction logic. Strict validation mechanisms ensure the runtime mode, on-chain contract state, and environment variables are perfectly aligned to prevent asset loss.\n- **State Machine & Resilience**: The entire lifecycle (positions, order metadata, execution history) is persisted in real-time to MongoDB. Built-in network retry mechanisms utilize Exponential Backoff algorithms to handle RPC jitters.\n\n## Architecture Overview\n\n\u003Cimg alt=\"screenshot\" src=\".\u002Fassets\u002Fimage.png\" \u002F>\n\n1. **Continuous Monitoring**: Polls the target addresses' activity stream via the Polymarket Data API.\n2. **Aggregation & Cleansing**: Merges high-frequency noise within a time window into executable batch orders.\n3. **Risk Control & Scaling**: Calculates the true order size dynamically based on account balance and the strategy matrix.\n4. **Routing & Validation**: Switches underlying signature logic automatically based on `WALLET_MODE`, broadcasting orders via Relayer or native RPC.\n5. **Persistence**: Logs the full state lifecycle to MongoDB for seamless recovery.\n\n## Quick Start\n\n### Prerequisites\n\n- Node.js v18+\n- MongoDB database ([MongoDB Atlas](https:\u002F\u002Fwww.mongodb.com\u002Fcloud\u002Fatlas\u002Fregister) recommended)\n- Polygon wallet funded with USDC and POL\u002FMATIC for Gas\n- Polygon RPC endpoint (e.g., Infura, Alchemy)\n\n### Rapid Deployment\n\n```bash\n# Clone the repository\ngit clone https:\u002F\u002Fgithub.com\u002FChiryanOY\u002FMimicPolymarket.git\ncd MimicPolymarket\n\n# Install dependencies\nnpm install\n\n# Initialize configuration\ncp .env.docker.example .env\n\n# (Recommended) Run the interactive setup wizard\n# npm run setup\n\n# If your account requires the Deposit Wallet flow, run:\n# npm run setup-deposit-wallet\n\n# Build and run health checks\nnpm run build\nnpm run health-check\n\n# Spin up the execution engine\nnpm start\n```\n\n## Core Configuration Guide\n\nThe runtime environment relies on the `.env` file (see [`\u002F.env.docker.example`](.\u002F.env.docker.example)).\n\n### Required Environment Variables\n\n- `USER_ADDRESSES`: Target wallets to monitor (comma-separated).\n- `TRADING_WALLET`: The execution address (EOA\u002FSafe for `LEGACY`; derived Deposit Wallet for `DEPOSIT`).\n- `WALLET_MODE`: Routing mode (`LEGACY` or `DEPOSIT`).\n- `PRIVATE_KEY`: Private key of the Owner or Signer.\n- `CLOB_HTTP_URL` \u002F `CLOB_WS_URL`: Polymarket API endpoints.\n- `MONGO_URI`: MongoDB state machine connection string.\n- `RPC_URL` \u002F `USDC_CONTRACT_ADDRESS`: Polygon network configuration.\n\n### Deep Dive: Wallet Routing Modes\n\n#### `LEGACY` Mode\nDesigned for early EOA or Safe multi-sig direct signature calls. The engine strictly validates whether the `TRADING_WALLET` matches the Signer derived from the `PRIVATE_KEY`.\n\n#### `DEPOSIT` Mode (Mandatory for New API)\nRequired when Polymarket intercepts calls with `maker address not allowed, please use the deposit wallet flow`.\n1. Configure Relayer credentials like `POLY_BUILDER_API_KEY`.\n2. Run `npm run setup-deposit-wallet` to dynamically derive the Deposit Wallet, and set it as `TRADING_WALLET`.\n3. The engine strictly verifies the on-chain contract deployment status of this address upon startup.\n\n> ⚠️ **Safety Interception**: If the `WALLET_MODE` mismatches the on-chain reality, the engine throws a Fatal Error during initialization and halts to protect your funds.\n\n### Deep Dive: Strategy Matrix Configuration\n\nFine-grained control is achieved via `TRADER_STRATEGIES`, which must be a valid JSON string:\n\n```json\n[\n  {\n    \"address\": \"0xabc...\",\n    \"mimicSize\": 1.0,\n    \"maxOrderSizeUSD\": 500,\n    \"maxPositionSizeUSD\": 2000,\n    \"tradeAggregationEnabled\": true,\n    \"tradeAggregationWindowSeconds\": 5\n  }\n]\n```\nThe default strategy utilizes a `PERCENTAGE` based proportional scaling algorithm.\n\n### 📖 Deep Dive: Trading & Execution Mechanics\n\nTo ensure the quantitative execution is both efficient and highly secure, the bot employs two distinctly different risk-control pipelines for buying and selling. Here is a breakdown of the core mechanics:\n\n#### 🟢 Buy Order Mechanics\nWhen the engine detects a \"Smart Money\" buy operation, it triggers a rigorous sequence of conditional checks:\n1. **Base Size Calculation**: Computes the target token amount based on your configured `mimicSize` percentage: `Trader Tokens * (mimicSize \u002F 100)`.\n2. **Multi-Threshold Scaling**:\n   - **Max Order Size**: If the calculated token value exceeds `maxOrderSizeUSD`, it is strictly capped at this limit.\n   - **Max Position Size**: The engine evaluates your current position cost plus the incoming order cost. If this exceeds `maxPositionSizeUSD`, the order is trimmed to fit the remaining allowance. If the allowance translates to less than 5 tokens, the order is rejected.\n   - **Balance Protection**: Checks your current USDC balance and caps the order at `99%` of your available funds to prevent `INSUFFICIENT_BALANCE` errors due to minor price fluctuations or fees.\n3. **Slippage & Limit Order Execution**: It takes the trader's execution price and adds the configured `buySlippageThreshold`. A strict **Limit Order** is then generated. This ensures that even during extreme market volatility, your entry cost will never exceed your safety threshold.\n\n#### 🔴 Sell Order Mechanics\nSelling usually indicates that \"Smart Money\" is taking profits or cutting losses. Therefore, execution priority and liquidity capturing are paramount. The engine adopts a \"Clear & Market Snipe\" strategy:\n1. **Clear Pending Buy Orders**: Before executing a sell, the engine actively cancels all your pending BUY orders for that specific asset to free up capital and avoid conflicting trades.\n2. **Dynamic Proportional Selling**:\n   - The system compares the trader's sell size against their historical position size to calculate the true **Sell Percentage**.\n   - It then multiplies your *real CLOB token balance* by this percentage to determine your sell amount. If the trader dumps their entire position (or if their historical position cannot be tracked), the engine will trigger a **100% full liquidation** of your holdings.\n3. **FOK (Fill-or-Kill) Execution**:\n   - The engine fetches the real-time Order Book to locate the highest buyer (Best Bid).\n   - It subtracts your configured `sellSlippageThreshold` to establish a safety floor price.\n   - The order is then broadcasted using the **FOK (Fill-or-Kill)** order type. FOK ensures the order is either fully filled immediately or entirely canceled, preventing fragmented partial fills from hanging on the order book.\n   - In case of liquidity shifts causing FOK rejections or network issues, the engine triggers an exponential backoff retry mechanism (up to `RETRY_LIMIT`), aggressively chasing liquidity until the position is cleared.\n\n## Docker Containerization\n\nWe provide an out-of-the-box `docker-compose.yml` to spin up both the Bot and a MongoDB instance with a single command, achieving a pure Local Daemon execution.\n\n```bash\n# Initialize environment\ncp .env.docker.example .env\n# We recommend setting this in .env: MONGO_URI='mongodb:\u002F\u002Fmongodb:27017\u002Fpolymarket_mimictrading'\n\n# Start services\ndocker-compose up -d\n\n# Tail engine logs\ndocker-compose logs -f bot\n```\n\n## Hunting for Alpha (Smart Money)\n\n1. Analyze the [Polymarket Leaderboard](https:\u002F\u002Fpolymarket.com\u002Fleaderboard).\n2. Filter for traders with positive P&L, >55% win rate, and recent activity.\n3. Cross-validate deep stats using [Predictfolio](https:\u002F\u002Fpredictfolio.com).\n4. Inject the selected addresses into `USER_ADDRESSES` and let the engine take over.\n\n## Star History\n\n\u003Ca href=\"https:\u002F\u002Fstar-history.com\u002F#ChiryanOY\u002FMimicPolymarket&Date\">\n  \u003Cpicture>\n    \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\"https:\u002F\u002Fapi.star-history.com\u002Fsvg?repos=ChiryanOY\u002FMimicPolymarket&type=Date&theme=dark\" \u002F>\n    \u003Csource media=\"(prefers-color-scheme: light)\" srcset=\"https:\u002F\u002Fapi.star-history.com\u002Fsvg?repos=ChiryanOY\u002FMimicPolymarket&type=Date\" \u002F>\n    \u003Cimg alt=\"Star History Chart\" src=\"https:\u002F\u002Fapi.star-history.com\u002Fsvg?repos=ChiryanOY\u002FMimicPolymarket&type=Date\" \u002F>\n  \u003C\u002Fpicture>\n\u003C\u002Fa>\n\n## License\nISC License - See [LICENSE](LICENSE) for details.\n\n## Acknowledgments\n- Core dependencies built on [Polymarket CLOB Client V2](https:\u002F\u002Fgithub.com\u002FPolymarket\u002Fclob-client-v2).\n- Data analytics powered by [Predictfolio](https:\u002F\u002Fpredictfolio.com).\n\n---\n**Disclaimer:** This software is provided strictly for technical research, code study, and educational purposes. It does not constitute financial or investment advice. Prediction markets carry extreme risks, and automated execution can result in the total loss of capital. The developers bear no responsibility for any financial losses. Deploy this system at your own risk only after fully understanding the source code logic.\n","Polymarket Mimic Trading Bot 是一个专为 Polymarket 设计的量化执行节点，旨在通过账户抽象（AA）代理路由、多钱包并发处理和动态订单聚合来提高交易效率。项目采用 TypeScript 编写，核心功能包括基于内存时间窗口的交易聚合引擎，用于减少小额交易带来的手续费损耗；动态风险与精度调整策略矩阵，根据用户资金比例自动调整执行规模并遵守交易所特定的要求；以及完全兼容 Polymarket 新 Relayer 路由机制的 AA 代理路由实现。此外，它还具备强大的状态管理和容错能力，所有交易信息实时保存至 MongoDB，并使用指数退避算法处理网络不稳定问题。该工具适用于希望在 Polymarket 上进行高效自动化交易的用户或团队。",2,"2026-06-11 03:59:51","CREATED_QUERY"]