Core Components: - uniswap_manager.py: V3 concentrated liquidity position manager - clp_hedger.py: Hyperliquid perpetuals hedging bot - requirements.txt: Python dependencies - .gitignore: Security exclusions for sensitive data - doc/: Project documentation - tools/: Utility scripts and Git agent Features: - Automated liquidity provision on Uniswap V3 (WETH/USDC) - Delta-neutral hedging using Hyperliquid perpetuals - Position lifecycle management (open/close/rebalance) - Automated backup and version control system Security: - Private keys and tokens excluded from version control - Environment variables properly handled - Automated security validation for backups Git Agent: - Hourly automated backups to separate branches - Keep last 100 backups (~4 days coverage) - Detailed change tracking and parameter monitoring - Push to Gitea server automatically - Manual main branch control preserved - No performance tracking for privacy - No notifications for simplicity Files Added: - git_agent.py: Main automation script - agent_config.json: Configuration with Gitea settings - git_utils.py: Git operations wrapper - backup_manager.py: Backup branch management - change_detector.py: File change analysis - cleanup_manager.py: 100-backup rotation - commit_formatter.py: Detailed commit messages - README_GIT_AGENT.md: Complete usage documentation
3.8 KiB
3.8 KiB
Uniswap Manager Workflow Documentation
This document describes the operational logic of the uniswap_manager_refactored.py script, specifically focusing on how it handles position lifecycle events.
1. Out of Range Workflow (Position Closing)
When the script detects that an active Concentrated Liquidity Position (CLP) has moved out of its defined tick range, the following sequence occurs:
-
Detection (Monitoring Loop):
- The
mainloop runs everyMONITOR_INTERVAL_SECONDS(default: 60s). - It retrieves the active position's
tickLowerandtickUpperfrom on-chain data. - It fetches the current pool
tick. - It determines if the position is out of range (
current_tick < tickLowerorcurrent_tick >= tickUpper).
- The
-
Logging:
- A warning is logged to both console and file:
🛑 Closing Position {token_id} (Out of Range).
- A warning is logged to both console and file:
-
Status Update -> "CLOSING":
- The
hedge_status.jsonfile is updated to mark the position status as"CLOSING". - Purpose: This signals external Hedger bots (watching this file) to halt hedging operations or close their hedges immediately.
- The
-
Liquidity Removal:
- The script executes a
decreaseLiquiditytransaction on theNonfungiblePositionManagercontract. - It removes 100% of the liquidity, converting the position back into the underlying tokens (WETH and USDC) in the wallet.
- The script executes a
-
Fee Collection:
- Immediately following liquidity removal, a
collecttransaction is sent to claim all accrued trading fees.
- Immediately following liquidity removal, a
-
Status Update -> "CLOSED":
- Upon successful confirmation of the transactions,
hedge_status.jsonis updated to status"CLOSED". - A
timestamp_closeis recorded.
- Upon successful confirmation of the transactions,
-
Rebalancing (Optional/Configuration Dependent):
- The script checks the
REBALANCE_ON_CLOSE_BELOW_RANGEflag. - Scenario: If the price fell BELOW the range, the position is 100% WETH.
- Action: If implemented, the script may perform a swap (e.g., selling 50% of the WETH for USDC) to rebalance the portfolio before opening a new position.
- Current State: The logic identifies this condition but requires the specific swap logic implementation (currently a
passplaceholder in the refactored script).
- The script checks the
-
Cycle Reset:
- The script returns to the monitoring loop.
- In the next cycle, detecting no "OPEN" position, it will evaluate
OPEN_POSITION_ENABLEDto potentially calculate and mint a new position centered on the current market price.
2. New Position Creation (Opening)
When no active position exists and OPEN_POSITION_ENABLED is True:
-
Market Analysis:
- Fetches current pool price and tick.
- Calculates a new range (default: +/- 2.5%) centered on the current tick.
-
Investment Calculation:
- Uses
TARGET_INVESTMENT_VALUE_USDC(default: $200). - If set to
"MAX", it calculates the maximum affordable position based on wallet balances minus a safety buffer. - Calculates the precise amount of Token0 and Token1 required for the target value at the current price and range.
- Uses
-
Preparation (Swap & Approve):
- Checks wallet balances.
- Auto-Wrap: Wraps ETH to WETH if necessary.
- Auto-Swap: Swaps surplus tokens (e.g., excess USDC for WETH) to match the required ratio for the new position.
- Approvals: Checks and sends
approvetransactions for the Position Manager if allowances are insufficient.
-
Minting:
- Sends the
minttransaction to create the new NFT position. - Applies a slippage tolerance (default: 0.5%) to
amountMinparameters.
- Sends the
-
Status Recording:
- On success, updates
hedge_status.jsonwith the new position details (Token ID, Range, Entry Price, Initial Amounts). - Sets status to
"OPEN".
- On success, updates
Last Updated: December 19, 2025