feat: add economically optimized Loop Out CLI tool with real route probing and SOT accounting - #52
Merged
Merged
Conversation
…ounting - Refactor Other/swap_out-loop.py to identify high-local-liquidity, low-fee channels via LNDg API. - Implement hybrid sizing: explicit --amt or dynamic per-channel equilibrium sizing. - Add two-stage route validation: lncli queryroutes fee calculation followed by live prepay probing via lncli sendpayment with fake hashes. - Calculate full economic cost: Loop service fee, on-chain sweep fee, LN routing fee, and local opportunity cost (foregone PPM). - Provide interactive arrow-key terminal menu navigation (termios/tty) with graceful non-interactive fallback. - Enforce economical sweep settings with minimum 6-block conf_target (default 9) and batched publication. - Stream litloop monitor in foreground with instructions for safe background detachment. - Persist operations in SQLite database (data/loop_out_history.db) with auto-synced CSV export. - Add comprehensive documentation in Other/swap_out-loop.md. - Add test suite in tests/Other/test_swap_out_loop.py (11 tests, 81/81 total passing).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Economic Loop Out CLI Optimizer (
Other/swap_out-loop.py):--amt <sats>.lncli queryroutesDijkstra pathfinding to Loop node (021c97a9...).lncli sendpaymentto detect ghost liquidity and verify real downstream routing paths.lncli buildrouteand probing vialncli sendtorouteto accurately determine real routing fees.29383\text{Total Cost} = \text{Loop Service Fee} + \text{On-chain Sweep Fee} + \text{LN Routing Fee} + \text{Opportunity Cost (PPM)}29383
↑/↓/Enter/q) using nativetermios/tty, with clean PrettyTable fallback for non-TTY pipelines and--auto-approve.--workers <N>(usingThreadPoolExecutorwith thread-safe output) while preserving 15s probe timeout.--fastfor fee-saving swap batching.Native Source of Truth (SOT) Accounting via Loop's
loop.db:~/.loop/mainnet/loop_sqlite.db), eliminating redundant custom databases and state divergence.loop_db_pathinconfig.ini, with seamless RPC fallback tolitloop listswaps.--label "Loop-Out: <alias> (<chan_id>)"to preserve channel metadata natively inloop.db.python Other/swap_out-loop.py --history [--limit N]displaying actual settled costs and realized PPM.--history --csv [path].Documentation & Config:
Other/swap_out-loop.md.[loop]section inconfig.ini.exampleand live Debian NUCconfig.ini.README.mdtool index.Testing & Live Verification:
tests/Other/test_swap_out_loop.pycovering candidate filtering, dynamic sizing, quote parsing, economic scoring, route probing, direct route fallback, SOT SQLite querying, and CSV export.debian-nuc.lanwith live--dry-run,--workers 2,--history, and real on-chain execution.Verification
pytestpassed 91/91 tests in 15.6s.debian-nuc.lanwith dry-run, workers, history, and real swap execution.