-
Notifications
You must be signed in to change notification settings - Fork 7
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 zero-amount Receive Chain Swap #538
base: main
Are you sure you want to change the base?
Changes from all commits
89e20d4
bedc05d
92c403b
445418c
c1a556b
333c5c5
05483a5
322972f
35cb343
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,9 +407,12 @@ dictionary PrepareReceiveRequest { | |
}; | ||
|
||
dictionary PrepareReceiveResponse { | ||
u64? payer_amount_sat; | ||
PaymentMethod payment_method; | ||
u64 fees_sat; | ||
u64? payer_amount_sat; | ||
u64? zero_amount_min_payer_amount_sat; | ||
u64? zero_amount_max_payer_amount_sat; | ||
f64? zero_amount_service_feerate; | ||
Comment on lines
+412
to
+415
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The prefix zero_amount is a bit confusing IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only weird case is when Should I then set them to |
||
}; | ||
|
||
dictionary ReceivePaymentRequest { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,29 @@ impl ChainSwapHandler { | |
| ChainSwapStates::TransactionLockupFailed | ||
| ChainSwapStates::TransactionRefunded | ||
| ChainSwapStates::SwapExpired => { | ||
// Zero-amount Receive Chain Swaps also get to TransactionLockupFailed when user locks up funds | ||
let is_zero_amount = swap.payer_amount_sat == 0; | ||
if matches!(swap_state, ChainSwapStates::TransactionLockupFailed) && is_zero_amount | ||
{ | ||
if let Err(e) = self | ||
.swapper | ||
.get_zero_amount_chain_swap_quote(&swap.id) | ||
.map(|quote| quote.to_sat()) | ||
.and_then(|quote| { | ||
info!("Got quote of {quote} sat for swap {}", &swap.id); | ||
|
||
self.persister.update_swap_payer_amount(&swap.id, quote)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the quote here is the server lockup amount. If so, I think there needs to be some recalculations done. The receiver amount (quote - claim fees), fees (server fees + boltz fees + claim fees) and payer amount (receiver amount + claim fees + server fees + boltz fees) need calculating. |
||
self.swapper | ||
ok300 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.accept_zero_amount_chain_swap_quote(&swap.id, quote) | ||
}) | ||
{ | ||
warn!("Failed to accept the quote for swap {}: {e:?}", &swap.id); | ||
} | ||
|
||
// We successfully accepted the quote, the swap should continue as normal | ||
return Ok(()); // Break from TxLockupFailed branch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems the error case arrives here too, we should allow it to be set to Refundable |
||
} | ||
|
||
match swap.refund_tx_id.clone() { | ||
None => { | ||
warn!("Chain Swap {id} is in an unrecoverable state: {swap_state:?}"); | ||
|
@@ -384,7 +407,7 @@ impl ChainSwapHandler { | |
} | ||
} | ||
Some(refund_tx_id) => warn!( | ||
"Refund tx for Chain Swap {id} was already broadcast: txid {refund_tx_id}" | ||
"Refund for Chain Swap {id} was already broadcast: txid {refund_tx_id}" | ||
), | ||
}; | ||
Ok(()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,6 +263,43 @@ impl Persister { | |
Ok(()) | ||
} | ||
|
||
/// Used for Zero-amount Receive Chain swaps, when we fetched the quote and we know how much | ||
/// the sender locked up | ||
pub(crate) fn update_swap_payer_amount( | ||
&self, | ||
swap_id: &str, | ||
payer_amount_sat: u64, | ||
) -> Result<(), PaymentError> { | ||
let swap = self | ||
.fetch_chain_swap_by_id(swap_id)? | ||
.ok_or_else(|| PaymentError::Generic { | ||
err: format!("Cannot update non-existent chain swap with ID: {swap_id}"), | ||
})?; | ||
ensure_sdk!( | ||
matches!(swap.direction, Direction::Incoming), | ||
PaymentError::Generic { | ||
err: format!( | ||
"Can only update payer_amount_sat for incoming chain swaps. Swap ID: {swap_id}" | ||
) | ||
} | ||
); | ||
Comment on lines
+273
to
+285
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a part of the SQL where clause below |
||
|
||
log::info!("Updating chain swap {swap_id}: payer_amount_sat = {payer_amount_sat}"); | ||
let con: Connection = self.get_connection()?; | ||
con.execute( | ||
"UPDATE chain_swaps | ||
SET | ||
payer_amount_sat = :payer_amount_sat | ||
WHERE | ||
id = :id", | ||
named_params! { | ||
":id": swap_id, | ||
":payer_amount_sat": payer_amount_sat, | ||
}, | ||
)?; | ||
Ok(()) | ||
} | ||
|
||
// Only set the Chain Swap claim_tx_id if not set, otherwise return an error | ||
pub(crate) fn set_chain_swap_claim_tx_id( | ||
&self, | ||
|
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.
I think the service feerate is going to be a
0.1
type value