-
-
Notifications
You must be signed in to change notification settings - Fork 137
Add LN Markets Lightning backend integration #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
lollerfirst
left a comment
There was a problem hiding this 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
| # 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 |
There was a problem hiding this comment.
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.
callebtc
left a comment
There was a problem hiding this 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?
|
Hi, thank you very much for the comments I hadn’t seen this review. 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)
Adds LN Markets as a new Lightning Network backend, enabling mints to operate using LN Markets accounts with full Bitcoin Lightning capabilities.
Lightning Operations:
Authentication:
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.