88 lines
3.2 KiB
Python
88 lines
3.2 KiB
Python
import os
|
|
import sys
|
|
import json
|
|
from web3 import Web3
|
|
from dotenv import load_dotenv
|
|
|
|
# Add project root to path
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
project_root = os.path.dirname(os.path.dirname(current_dir)) # K:\Projects\uniswap_auto_clp
|
|
sys.path.append(project_root)
|
|
|
|
# Load env from florida/.env or root .env
|
|
load_dotenv(os.path.join(os.path.dirname(current_dir), '.env'))
|
|
|
|
RPC_URL = os.environ.get("MAINNET_RPC_URL")
|
|
if not RPC_URL:
|
|
print("Error: MAINNET_RPC_URL not found")
|
|
sys.exit(1)
|
|
|
|
w3 = Web3(Web3.HTTPProvider(RPC_URL))
|
|
if not w3.is_connected():
|
|
print("Error: Could not connect to RPC")
|
|
sys.exit(1)
|
|
|
|
NPM_ADDRESS = "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
NPM_ABI = [
|
|
{
|
|
"inputs": [{"internalType": "uint256", "name": "tokenId", "type": "uint256"}],
|
|
"name": "positions",
|
|
"outputs": [
|
|
{"internalType": "uint96", "name": "nonce", "type": "uint96"},
|
|
{"internalType": "address", "name": "operator", "type": "address"},
|
|
{"internalType": "address", "name": "token0", "type": "address"},
|
|
{"internalType": "address", "name": "token1", "type": "address"},
|
|
{"internalType": "uint24", "name": "fee", "type": "uint24"},
|
|
{"internalType": "int24", "name": "tickLower", "type": "int24"},
|
|
{"internalType": "int24", "name": "tickUpper", "type": "int24"},
|
|
{"internalType": "uint128", "name": "liquidity", "type": "uint128"},
|
|
{"internalType": "uint256", "name": "feeGrowthInside0LastX128", "type": "uint256"},
|
|
{"internalType": "uint256", "name": "feeGrowthInside1LastX128", "type": "uint256"},
|
|
{"internalType": "uint128", "name": "tokensOwed0", "type": "uint128"},
|
|
{"internalType": "uint128", "name": "tokensOwed1", "type": "uint128"}
|
|
],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}
|
|
]
|
|
|
|
npm = w3.eth.contract(address=NPM_ADDRESS, abi=NPM_ABI)
|
|
|
|
STATUS_FILE = os.path.join(os.path.dirname(current_dir), 'hedge_status.json')
|
|
|
|
def fix_liquidity():
|
|
if not os.path.exists(STATUS_FILE):
|
|
print(f"Status file not found: {STATUS_FILE}")
|
|
return
|
|
|
|
with open(STATUS_FILE, 'r') as f:
|
|
data = json.load(f)
|
|
|
|
updated = False
|
|
for entry in data:
|
|
if entry.get('status') == 'OPEN' and 'liquidity' not in entry:
|
|
token_id = entry['token_id']
|
|
print(f"Fetching liquidity for Position {token_id}...")
|
|
|
|
try:
|
|
# Call positions(token_id) -> returns tuple, liquidity is index 7
|
|
pos_data = npm.functions.positions(token_id).call()
|
|
liquidity = pos_data[7]
|
|
|
|
print(f" -> Liquidity: {liquidity}")
|
|
|
|
entry['liquidity'] = str(liquidity) # Store as string to match update logic
|
|
updated = True
|
|
except Exception as e:
|
|
print(f" -> Error: {e}")
|
|
|
|
if updated:
|
|
with open(STATUS_FILE, 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
print("Updated hedge_status.json")
|
|
else:
|
|
print("No OPEN positions needing liquidity update.")
|
|
|
|
if __name__ == "__main__":
|
|
fix_liquidity()
|