Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 57 additions & 57 deletions .agents/agents.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .github/SECURITY.md

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ENV/

# Configuration and Secrets
config.ini
Magma/magma_config.ini
feeConfig.json
wallets.json
.env
Expand Down
42 changes: 33 additions & 9 deletions LNBits/pocketmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
from telebot import TeleBot
import argparse

def normalize_lnbits_base_url(raw_url):
"""Normalize LNbits base URL so /api/v1/... endpoints are never doubled."""
url = (raw_url or "").strip().rstrip("/")
if url.endswith("/api/v1"):
url = url[: -len("/api/v1")].rstrip("/")
return url


# Get the path to the parent directory
parent_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -19,15 +27,15 @@
config.read(config_file_path)

# Parse scheduling preferences
recurrence_raw = config["Schedule"]["recurrence"]
recurrence_raw = config.get("Schedule", "recurrence", fallback="weekly")
RECURRENCE = recurrence_raw.split("#")[0].strip().lower()

# Verify RECURRENCE
if RECURRENCE not in ["daily", "weekly"]:
raise ValueError("Invalid recurrence setting. Choose from 'daily' or 'weekly'.")

TIME = config["Schedule"]["time"].strip()
DAY_OF_WEEK = config["Schedule"].get("day_of_week", "friday").strip()
TIME = config.get("Schedule", "time", fallback="09:00").strip()
DAY_OF_WEEK = config.get("Schedule", "day_of_week", fallback="friday").strip().lower()

# Check if TIME is valid
try:
Expand All @@ -36,17 +44,18 @@
raise ValueError("Invalid time format. Use HH:MM (e.g., 09:00).")

# Other configuration variables
ADMIN_KEY = config["LNBits"]["admin_key"]
LNBITS_URL = config["LNBits"]["base_url"]
TOKEN = config["telegram"]["lnbits_bot_token"]
CHAT_ID = config["telegram"]["telegram_user_id"]
ADMIN_KEY = config.get("LNBits", "admin_key", fallback="").strip()
LNBITS_URL = normalize_lnbits_base_url(config.get("LNBits", "base_url", fallback=""))
TOKEN = config.get("telegram", "lnbits_bot_token", fallback="").strip()
CHAT_ID = config.get("telegram", "telegram_user_id", fallback="").strip()
THRESHOLD_BALANCE = 1000000

# Initialize Telegram bot
bot = TeleBot(TOKEN)
# Initialize Telegram bot (safe placeholder when imported without config.ini in tests)
bot = TeleBot(TOKEN if (TOKEN and ":" in TOKEN) else "123456:fake_token_for_testing")

# Set up logging
log_file_path = os.path.join(os.path.dirname(__file__), "..", "logs", "pocketmoney.log")
os.makedirs(os.path.dirname(log_file_path), exist_ok=True)
handler = RotatingFileHandler(log_file_path, maxBytes=10 * 1024 * 1024, backupCount=5)
logging.basicConfig(
level=logging.DEBUG,
Expand Down Expand Up @@ -233,6 +242,20 @@ def schedule_transfers():
raise ValueError("Invalid recurrence setting. Choose from 'daily' or 'weekly'.")


def validate_runtime_config():
missing = []
if not LNBITS_URL:
missing.append("[LNBits] base_url")
if not ADMIN_KEY:
missing.append("[LNBits] admin_key")
if not TOKEN or ":" not in TOKEN:
missing.append("[telegram] lnbits_bot_token")
if not CHAT_ID:
missing.append("[telegram] telegram_user_id")
if missing:
raise ValueError(f"Missing or invalid config.ini settings: {', '.join(missing)}")


def main():
parser = argparse.ArgumentParser(description="Pocket Money Scheduler")
parser.add_argument(
Expand All @@ -241,6 +264,7 @@ def main():
help="Run the transfer once and exit, best for cronjobs",
)
args = parser.parse_args()
validate_runtime_config()

if args.run_once:
scheduled_transfer()
Expand Down
4 changes: 3 additions & 1 deletion LNDg/amboss_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
LNDG_BASE_URL = config.get("lndg", "lndg_api_url", fallback="http://localhost:8889")

# Output Paths
CHARGE_LND_PATH = config.get("paths", "charge_lnd_path", fallback="/tmp/charge-lnd")
CHARGE_LND_PATH = os.path.expanduser(
config.get("paths", "charge_lnd_path", fallback="/tmp/charge-lnd")
)
FINISHED_FILE_NAME = "magma-finished.txt"
FEE_CAP_FILE_PATTERN = re.compile(r"^magma-channels_(\d+)\.txt$")
LOG_FILE_PATH = os.path.join(parent_dir, "..", "logs", "amboss-LNDg_changes.log")
Expand Down
1 change: 1 addition & 0 deletions LNDg/channel_base-fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def modify_channels(channels):

if response.status_code == 200:
# Log the changes
os.makedirs(os.path.dirname(log_file_path), exist_ok=True)
with open(log_file_path, "a") as log_file:
log_file.write(
f"{timestamp}: Changed 'local_base_fee' to 0 for channel {chan_id}\n"
Expand Down
1 change: 1 addition & 0 deletions LNDg/channel_fee-pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get_chan_ids_to_write():
chan_ids = get_chan_ids_to_write()
print(f"Channel-IDs: {chan_ids}")

os.makedirs(os.path.dirname(file_path), exist_ok=True)
if chan_ids:
with open(file_path, "w") as file:
for chan_id in chan_ids:
Expand Down
1 change: 1 addition & 0 deletions LNDg/disabled_fee-accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

# File path for the log file
log_file_path = os.path.join(parent_dir, "..", "logs", "lndg-fee-accelerator.log")
os.makedirs(os.path.dirname(log_file_path), exist_ok=True)

# Logfile definition
logging.basicConfig(filename=log_file_path, level=logging.DEBUG)
Expand Down
1 change: 1 addition & 0 deletions LNDg/mempool_rebalancer_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def get_current_timestamp():

# Logfile definition
log_file_path = os.path.join(parent_dir, "..", "logs", "mempool_rebalancer_trigger.log")
os.makedirs(os.path.dirname(log_file_path), exist_ok=True)
logging.basicConfig(filename=log_file_path, level=logging.DEBUG)


Expand Down
2 changes: 2 additions & 0 deletions LNDg/swap_out-candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def write_bos_tags():
]
}

os.makedirs(os.path.dirname(file_path_to_bos), exist_ok=True)
with open(file_path_to_bos, "w") as file:
json.dump(tags_data, file, indent=2)

Expand All @@ -262,6 +263,7 @@ def main():
if args.file_export:
chan_ids = get_chan_ids_to_write()
if chan_ids:
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, "w") as file:
file.write(",".join(chan_ids) + "\n")
print(f"Channel-ID data written to {file_path}")
Expand Down
6 changes: 3 additions & 3 deletions Magma/magma_config.ini → Magma/magma_config.ini.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Magma/magma_config.ini
# This file contains Magma-specific settings for the magma_market_fee.py script.
# Magma/magma_config.ini.example
# Copy to Magma/magma_config.ini and customize settings for Magma/magma_market_fee.py.

[magma_autoprice]
# Enable/disable the magma auto-pricing script
Expand Down Expand Up @@ -48,4 +48,4 @@ target_apr_min = 7.0
target_apr_max = 18.0
capital_allocation_share = 0.6

# ... add more [magma_offer_TEMPLATENAME] sections as needed ...
# ... add more [magma_offer_TEMPLATENAME] sections as needed ...
9 changes: 5 additions & 4 deletions Magma/magma_market_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
# - Includes a --dry-run mode to simulate actions without making live API changes.
#
# How to Run:
# 1. Ensure Python 3 is installed.
# 2. Install required Python packages: `pip install requests telebot configparser`
# 1. Ensure Python 3.11+ is installed.
# 2. Install required Python packages: `pip install -r requirements.txt`
# 3. Ensure `../config.ini` exists and is configured (see config.ini.example).
# 4. Create `Magma/magma_config.ini` for Magma-specific settings.
# 4. Copy `Magma/magma_config.ini.example` to `Magma/magma_config.ini` and customize offer settings.
# 5. Make the script executable: `chmod +x magma_market_fee.py`
# 6. Run the script: `python /path/to/Magma/magma_market_fee.py`
# For dry run: `python /path/to/Magma/magma_market_fee.py --dry-run`
Expand Down Expand Up @@ -1338,7 +1338,8 @@ def main():

if not os.path.exists(MAGMA_CONFIG_FILE_PATH):
logging.critical(
f"CRITICAL: Magma-specific configuration file {MAGMA_CONFIG_FILE_PATH} not found. Exiting."
f"CRITICAL: Magma-specific configuration file {MAGMA_CONFIG_FILE_PATH} not found "
"(copy Magma/magma_config.ini.example to Magma/magma_config.ini). Exiting."
)
return
magma_specific_config.read(MAGMA_CONFIG_FILE_PATH)
Expand Down
Loading
Loading