Skip to content
This repository was archived by the owner on Apr 27, 2025. It is now read-only.
Draft
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
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ LND_TLS_CERT_PATH="/../tls.cert"
LND_GRPC_HOST="https://localhost:10004"


STABLESATS_AUTH_BEARER=YOUR_AUTH_BEARER
STABLESATS_GALOY_URL=YOUR_GALOY_URL
STABLESATS_USD_WALLET_ID=YOUR_USD_WALLET_ID




### environment variables for the fedimint-cli
CLI_FEDIMINT_CONNECTION="fed...."
5 changes: 5 additions & 0 deletions moksha-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ pub struct CashuErrorResponse {
pub error: String,
}

#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct InvoiceQuoteResult {
pub amount_in_cent: u64,
}

#[cfg(test)]
mod tests {
use crate::{
Expand Down
10 changes: 8 additions & 2 deletions moksha-mint/src/bin/moksha-mint.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use mokshamint::{
info::MintInfoSettings,
lightning::{
AlbyLightningSettings, LightningType, LnbitsLightningSettings, LndLightningSettings,
StrikeLightningSettings,
stablesats::StablesatsSettings, AlbyLightningSettings, LightningType,
LnbitsLightningSettings, LndLightningSettings, StrikeLightningSettings,
},
MintBuilder,
};
Expand Down Expand Up @@ -58,6 +58,12 @@ pub async fn main() -> anyhow::Result<()> {
.from_env::<StrikeLightningSettings>()
.expect("Please provide strike info");
LightningType::Strike(strike_settings)
},
"Stablesats" => {
let settings = envy::prefixed("STABLESATS_")
.from_env::<StablesatsSettings>()
.expect("Please provide stablesats info");
LightningType::Stablesats(settings)
}
_ => panic!(
"env MINT_LIGHTNING_BACKEND not found or invalid values. Valid values are Lnbits, Lnd, Alby, and Strike"
Expand Down
6 changes: 6 additions & 0 deletions moksha-mint/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub enum MokshaMintError {
#[error("Failed to pay invoice {0} - Error {1}")]
PayInvoice(String, LightningError),

#[error("Failed to pay invoice {0} - Error {1}")]
PayInvoiceStablesats(String, String), // FIXME

#[error("DB Error {0}")]
Db(#[from] rocksdb::Error),

Expand Down Expand Up @@ -59,6 +62,9 @@ pub enum MokshaMintError {

#[error("Lightning Error {0}")]
Lightning(#[from] LightningError),

#[error("Deserialize Error {0}")]
DeserializeResponse(String),
}

impl IntoResponse for MokshaMintError {
Expand Down
34 changes: 31 additions & 3 deletions moksha-mint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::Arc;

use axum::extract::{Query, State};
use axum::extract::{Path, Query, State};
use axum::routing::{get_service, post};
use axum::Router;
use axum::{routing::get, Json};
Expand All @@ -13,12 +13,14 @@ use error::MokshaMintError;
use hyper::http::{HeaderName, HeaderValue};
use hyper::Method;
use info::{MintInfoResponse, MintInfoSettings, Parameter};
use lightning::stablesats::StablesatsLightning;
use lightning::{AlbyLightning, Lightning, LightningType, LnbitsLightning, StrikeLightning};
use mint::{LightningFeeConfig, Mint};
use model::{GetMintQuery, PostMintQuery};
use moksha_core::model::{
CheckFeesRequest, CheckFeesResponse, Keysets, PaymentRequest, PostMeltRequest,
PostMeltResponse, PostMintRequest, PostMintResponse, PostSplitRequest, PostSplitResponse,
CheckFeesRequest, CheckFeesResponse, InvoiceQuoteResult, Keysets, PaymentRequest,
PostMeltRequest, PostMeltResponse, PostMintRequest, PostMintResponse, PostSplitRequest,
PostSplitResponse,
};
use secp256k1::PublicKey;

Expand Down Expand Up @@ -93,6 +95,21 @@ impl MintBuilder {
Some(LightningType::Strike(strike_settings)) => Arc::new(StrikeLightning::new(
strike_settings.api_key.expect("STRIKE_API_KEY not set"),
)),
Some(LightningType::Stablesats(settings)) => Arc::new(StablesatsLightning::new(
settings
.auth_bearer
.expect("STABLESATS_AUTH_BEARER not set")
.as_str(),
settings
.galoy_url
.expect("STABLESATS_GALOY_URL not set")
.as_str(),
settings
.usd_wallet_id
.expect("STABLESATS_USD_WALLET_ID not set")
.as_str(),
)),

Some(LightningType::Lnd(lnd_settings)) => Arc::new(
lightning::LndLightning::new(
lnd_settings.grpc_host.expect("LND_GRPC_HOST not set"),
Expand Down Expand Up @@ -171,6 +188,7 @@ fn app(mint: Mint, serve_wallet_path: Option<PathBuf>, prefix: Option<String>) -
.route("/keysets", get(get_keysets))
.route("/mint", get(get_mint).post(post_mint))
.route("/checkfees", post(post_check_fees))
.route("/melt/:invoice", get(get_melt))
.route("/melt", post(post_melt))
.route("/split", post(post_split))
.route("/info", get(get_info));
Expand Down Expand Up @@ -242,6 +260,16 @@ async fn post_check_fees(
}))
}

async fn get_melt(
Path(invoice): Path<String>,
State(mint): State<Mint>,
) -> Result<Json<InvoiceQuoteResult>, MokshaMintError> {
let quote = mint.lightning.get_quote(invoice.to_owned()).await?;
Ok(Json(InvoiceQuoteResult {
amount_in_cent: quote.amount_in_cent,
}))
}

async fn get_info(State(mint): State<Mint>) -> Result<Json<MintInfoResponse>, MokshaMintError> {
let mint_info = MintInfoResponse {
name: mint.mint_info.name,
Expand Down
13 changes: 12 additions & 1 deletion moksha-mint/src/lightning/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_trait::async_trait;
use moksha_core::model::InvoiceQuoteResult;
use std::fmt::{self, Formatter};
use tokio::sync::{MappedMutexGuard, Mutex, MutexGuard};
use tonic_lnd::Client;
Expand All @@ -17,20 +18,25 @@ use lightning_invoice::{Bolt11Invoice as LNInvoice, SignedRawBolt11Invoice};
mod alby;
pub mod error;
mod lnbits;
pub mod stablesats;
mod strike;

#[cfg(test)]
use mockall::automock;
use std::{path::PathBuf, str::FromStr, sync::Arc};

use self::{alby::AlbyClient, error::LightningError, lnbits::LNBitsClient, strike::StrikeClient};
use self::{
alby::AlbyClient, error::LightningError, lnbits::LNBitsClient, stablesats::StablesatsSettings,
strike::StrikeClient,
};

#[derive(Debug, Clone)]
pub enum LightningType {
Lnbits(LnbitsLightningSettings),
Alby(AlbyLightningSettings),
Strike(StrikeLightningSettings),
Lnd(LndLightningSettings),
Stablesats(StablesatsSettings),
}

impl fmt::Display for LightningType {
Expand All @@ -40,6 +46,7 @@ impl fmt::Display for LightningType {
LightningType::Alby(settings) => write!(f, "Alby: {}", settings),
LightningType::Strike(settings) => write!(f, "Strike: {}", settings),
LightningType::Lnd(settings) => write!(f, "Lnd: {}", settings),
LightningType::Stablesats(settings) => write!(f, "Stablesats: {}", settings),
}
}
}
Expand All @@ -58,6 +65,10 @@ pub trait Lightning: Send + Sync {
LNInvoice::from_str(&payment_request)
.map_err(|err| MokshaMintError::DecodeInvoice(payment_request, err))
}

async fn get_quote(&self, _invoice: String) -> Result<InvoiceQuoteResult, MokshaMintError> {
Ok(Default::default())
}
}

#[derive(Deserialize, Serialize, Debug, Clone, Default)]
Expand Down
Loading