Skip to content

Conversation

@Forte11Cuba
Copy link

Adds LN Markets as a new Lightning Network backend, enabling mints to operate using LN Markets accounts with full Bitcoin Lightning capabilities.

Lightning Operations:

  • Mint: Deposit sats via Lightning invoices
  • Melt: Withdraw sats by paying Lightning invoices
  • LNURL payments supported
  • Lightning Address payments supported
  • Real-time balance checking and payment status verification

Authentication:

  • HMAC-SHA256 signature (LN Markets API v3)
  • Requires API key, secret, and passphrase

Configuration
Add to .env:
MINT_BACKEND_BOLT11_SAT=LNMarketsWallet
MINT_LNMARKETS_KEY=your_api_key
MINT_LNMARKETS_SECRET=your_api_secret
MINT_LNMARKETS_PASSPHRASE=your_passphrase
MINT_LNMARKETS_ENDPOINT=https://api.lnmarkets.com/v3

Payments from this mint to another LN Markets account do not work due to LN Markets platform limitations that prevent circular payments within the same service. Payments to external Lightning nodes, LNURL, and Lightning addresses work correctly.

- Implements LNMarketsWallet backend for Bitcoin Lightning operations (mint/melt)
- Supports Lightning invoice payments, LNURL, and Lightning Address
- Uses HMAC-SHA256 authentication with LN Markets API v3
Copy link
Collaborator

@a1denvalu3 a1denvalu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! I did this a while back but now the API v3 is much better.

.env.example Outdated
Comment on lines 119 to 122
# LN Markets API endpoint
# - Production: https://api.lnmarkets.com/v3
# - Testnet: https://api.testnet4.lnmarkets.com/v3
MINT_LNMARKETS_ENDPOINT=https://api.lnmarkets.com/v3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be in the .env.example IMO, but it's fine to leave it as a config param for development.

Copy link
Collaborator

@callebtc callebtc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! What's the state of this PR? Do fees work correctly? Would it be possible to add tests for the backend with mocked responses like we do for the blink backend? (see cashu/tests/mint/test_mint_lightning_blink.py)

The blink tests are not the best but they demonstrate how to use the mock library.

Any updates from LNMarkets if this could be used as a fiat mint too?

@Forte11Cuba
Copy link
Author

Hi, thank you very much for the comments I hadn’t seen this review.
I’ll start working on it and add tests similar to the ones in the Blink backend using mocked responses.

Regarding fiat support, it would be amazing, but LNMarkets hasn’t enabled the required endpoint yet. You can open a short or do a swap after receiving the sats, but I think this is problematic for mints because of volatility: the value of the tokens at the moment of the request could differ from the value at the moment the sats are actually received.

In API v2 there was an endpoint that allowed receiving sats and automatically converting them to sUSD while freezing the price for a few minutes, effectively absorbing volatility but this endpoint is not available in v3. I’ve contacted them about it, but it doesn’t seem to be a priority for them right now. Hopefully they reconsider.

  - Fix import sorting in lnmarkets.py and __init__.py
  - Remove unused imports (secrets, Dict, Union)
  - Replace bare except clauses with specific Exception type
  - Fix paid_invoices_stream return type (remove async)
  - Remove MINT_LNMARKETS_ENDPOINT from .env.example (uses default from
  settings)
  withdrawals

  - Handle new API response format with 'data' field
  - Fix deposits and withdrawals to use response['data']
  - Add debug logging for better troubleshooting
  - Fix linting errors (bare except clauses)
  - Fix mypy error (remove async from paid_invoices_stream)
@codecov
Copy link

codecov bot commented Nov 30, 2025

Codecov Report

❌ Patch coverage is 28.50242% with 148 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.52%. Comparing base (4a4b7f7) to head (f279193).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
cashu/lightning/lnmarkets.py 26.73% 148 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #824       +/-   ##
===========================================
+ Coverage   47.84%   62.52%   +14.68%     
===========================================
  Files          90       92        +2     
  Lines       10592    11107      +515     
===========================================
+ Hits         5068     6945     +1877     
+ Misses       5524     4162     -1362     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants