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

Ensure fees are calculated without overflow #671

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
2 changes: 1 addition & 1 deletion cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,9 @@ impl Payment {
unblinding_data: None,
timestamp: swap.created_at,
amount_sat,
fees_sat: swap.payer_amount_sat - swap.receiver_amount_sat,
fees_sat: swap
.payer_amount_sat
.saturating_sub(swap.receiver_amount_sat),
swapper_fees_sat: Some(swap.swapper_fees_sat),
payment_type,
status: swap.status,
Expand Down Expand Up @@ -1607,8 +1609,8 @@ impl Payment {
// For receive swaps, to avoid some edge case issues related to potential past
// overpayments, we use the actual claim value as the final received amount
// for fee calculation.
PaymentType::Receive => s.payer_amount_sat - tx.amount_sat,
PaymentType::Send => s.payer_amount_sat - s.receiver_amount_sat,
PaymentType::Receive => s.payer_amount_sat.saturating_sub(tx.amount_sat),
PaymentType::Send => s.payer_amount_sat.saturating_sub(s.receiver_amount_sat),
},
None => match tx.payment_type {
PaymentType::Receive => 0,
Expand Down
Loading