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

Add support for getting and accepting quotes #81

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion src/swaps/boltz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
//! output_amount - base_fees - claim_fee
//! );

use bitcoin::key;
use bitcoin::{
hashes::sha256, hex::DisplayHex, taproot::TapLeaf, PublicKey, ScriptBuf, Transaction,
};
use bitcoin::{key, Amount};
use lightning_invoice::Bolt11Invoice;
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -564,6 +564,28 @@ impl BoltzApiClientV2 {
let end_point = format!("chain/{}/transaction", chain);
Ok(serde_json::from_str(&self.post(&end_point, data)?)?)
}

/// Looks up the quote for a Zero-Amount Receive Chain Swap.
///
/// If the user locked up a valid amount, it will return the server lockup amount. In all other
/// cases, it will return an error.
pub fn get_quote(&self, swap_id: &str) -> Result<GetQuoteResponse, Error> {
let end_point = format!("swap/chain/{swap_id}/quote");
Ok(serde_json::from_str(&self.get(&end_point)?)?)
}

/// Accepts a specific quote for a Zero-Amount Receive Chain Swap.
pub fn accept_quote(&self, swap_id: &str, amount_sat: u64) -> Result<(), Error> {
let data = json!(
{
"amount": amount_sat
}
);

let end_point = format!("swap/chain/{swap_id}/quote");
self.post(&end_point, data)?;
Ok(())
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -1284,6 +1306,13 @@ pub struct GetFeeEstimationResponse {
pub lbtc: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetQuoteResponse {
/// Server lockup amount, in sat
pub amount: u64,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading