Skip to content

Commit

Permalink
First draft of mostro fee (#79)
Browse files Browse the repository at this point in the history
* First draft of mostro fee

* add env-sample

* Fixes on some typos
  • Loading branch information
arkanoider committed May 12, 2023
1 parent 9da7a17 commit d4f3f7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ HOLD_INVOICE_CLTV_DELTA=144
MIN_PAYMENT_AMT=100

# Expiration order hours
EXP_HOURS = 24
EXP_HOURS=24
# Expiration of pending orders
EXP_SECONDS = 900
EXP_SECONDS=900
# Max routing fee that we want to pay to the network, 0.001 = 0.1%
MAX_ROUTING_FEE=0.001
# Mostro Fee
FEE=0.006
15 changes: 12 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ pub async fn show_hold_invoice(
order: &Order,
) -> anyhow::Result<()> {
let mut ln_client = lightning::LndConnector::new().await;
// Add fee of seller to hold invoice
let seller_fee = var("FEE").unwrap().parse::<f64>().unwrap_or(0.003) / 2.0;
let seller_total_amout = (seller_fee * order.amount as f64) + order.amount as f64;

// Now we generate the hold invoice that seller should pay
let (invoice_response, preimage, hash) = ln_client
.create_hold_invoice(
Expand All @@ -231,7 +235,7 @@ pub async fn show_hold_invoice(
&order.fiat_code,
&order.fiat_amount.to_string(),
)?,
order.amount,
seller_total_amout as i64,
)
.await?;
if let Some(invoice) = payment_request {
Expand Down Expand Up @@ -317,10 +321,15 @@ pub async fn set_market_order_sats_amount(
// Update amount order
let new_sats_amout =
get_market_quote(&order.fiat_amount, &order.fiat_code, &order.premium).await?;

// Add fee of seller to hold invoice
let buyer_fee = var("FEE").unwrap().parse::<f64>().unwrap_or(0.003) / 2.0;
let buyer_total_amout = new_sats_amout as f64 - (buyer_fee * new_sats_amout as f64);

// We send this data related to the order to the parties
let order_data = SmallOrder::new(
order.id,
new_sats_amout,
buyer_total_amout as i64,
order.fiat_code.clone(),
order.fiat_amount,
order.payment_method.clone(),
Expand All @@ -341,7 +350,7 @@ pub async fn set_market_order_sats_amount(
send_dm(client, my_keys, &buyer_pubkey, message).await?;

// Update order with new sats value
order.amount = new_sats_amout;
order.amount = buyer_total_amout as i64;
update_order_event(
pool,
client,
Expand Down

0 comments on commit d4f3f7a

Please sign in to comment.