loop: clean up server cost calculation for slightly better UX

Previously we'd calculate the server costs (swap fees) by accounting for
both the on-chain HTLC and the off-chain payment which was confusing as
server cost fluctuated by the amount of the swap itself. Now we'll only
add the actual cost when the swap happened, so the server cost will go
form zero to the actual fee value paid.
This commit is contained in:
Andras Banki-Horvath 2024-02-06 17:04:41 +01:00
parent e1ddb50dfe
commit 5294b4ff07
No known key found for this signature in database
GPG key ID: 80E5375C094198D8
2 changed files with 6 additions and 14 deletions

View file

@ -452,7 +452,8 @@ func (s *loopOutSwap) handlePaymentResult(result paymentResult) error {
return nil
case result.status.State == lnrpc.Payment_SUCCEEDED:
s.cost.Server += result.status.Value.ToSatoshis()
s.cost.Server += result.status.Value.ToSatoshis() -
s.AmountRequested
s.cost.Offchain += result.status.Fee.ToSatoshis()
return nil
@ -539,9 +540,7 @@ func (s *loopOutSwap) executeSwap(globalCtx context.Context) error {
sweepSuccessful := s.htlc.IsSuccessWitness(htlcInput.Witness)
if sweepSuccessful {
s.cost.Server -= htlcValue
s.cost.Onchain = spend.OnChainFeePortion
s.state = loopdb.StateSuccess
} else {
s.state = loopdb.StateFailSweepTimeout