Skip to content
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

First draft of mostro fee #79

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

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

missing =

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix asap

# 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.03) / 2.0;
grunch marked this conversation as resolved.
Show resolved Hide resolved
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.03) / 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