rmi-backend/scripts/setup_x402_rotation.py
opencode c762564d40 style(rmi-backend): complete lint cleanup — 1175→0 ruff errors
- Fix 71 invalid-syntax files (class-body newline-broken assignments)
- Add from/None chain to 307 B904 raise-without-from sites
- Add B008 ignore to ruff.toml (already in pyproject.toml)
- Noqa F401 on __init__.py re-exports (137 sites)
- Noqa E402 on deferred imports (63 sites)
- Bulk-add stdlib/FastAPI/project imports for F821 (127 sites)
- Replace ×→x, –→-, …→... in docstrings (4093 chars)
- Manual refactor of 5 SIM103/SIM116 patterns

Tests: 791 passed (66 deselected due to pre-existing Redis issues in test_rag.py)
Co-authored-by: opencode <opencode@rugmunch.io>
2026-07-06 15:43:20 +02:00

74 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""
Setup x402 Payment Address Rotation Schedules
Sets 90-day auto-rotation on all x402 receiving wallets.
Run with: python3 setup_x402_rotation.py
Requires WALLET_VAULT_PASSWORD env var.
"""
import os
import sys
sys.path.insert(0, "/root/backend")
os.chdir("/root/backend")
from app.wallet_manager_v2 import get_wallet_manager_v2 # noqa: E402
# Target addresses from fact_store (id=74)
EVM_RECEIVING = "0x5761E0337a49819A8Cd4D35D76E882255Cb113b9".lower()
SOL_RECEIVING = "9JNVRRttW9Mbev78tKinvmgPtZvgNwjs9fCTQs17Ur3k"
def main():
password = os.getenv("WALLET_VAULT_PASSWORD", "")
if not password:
print("ERROR: WALLET_VAULT_PASSWORD not set")
sys.exit(1)
mgr = get_wallet_manager_v2(password)
# Find all x402-enabled wallets
x402_wallets = []
for w in mgr._wallets.values():
if getattr(w, "x402_enabled", False):
x402_wallets.append(w)
print(f"Found {len(x402_wallets)} x402-enabled wallets")
# Also try address matching for the known receiving wallets
for w in mgr._wallets.values():
addr = str(getattr(w, "address", "") or "").lower()
if EVM_RECEIVING in addr or SOL_RECEIVING.lower() in addr:
if w not in x402_wallets:
x402_wallets.append(w)
print(f"Added by address match: {w.wallet_id} ({w.chain})")
if not x402_wallets:
print("No x402 wallets found. Setting rotation on ALL wallets instead.")
x402_wallets = list(mgr._wallets.values())
schedules = []
for w in x402_wallets:
try:
schedule = mgr.schedule_rotation(w.wallet_id, days=90, auto=True)
schedules.append(
{
"wallet_id": w.wallet_id,
"chain": w.chain,
"rotation_days": 90,
"auto_rotate": True,
"next_rotation": schedule.next_rotation if schedule else None,
}
)
print(f"Rotation scheduled: {w.wallet_id} ({w.chain}) → every 90 days, auto=True")
except Exception as e:
print(f"Failed to schedule rotation for {w.wallet_id}: {e}")
print(f"\nRotation schedules set: {len(schedules)}/{len(x402_wallets)}")
return schedules
if __name__ == "__main__":
main()