Skip to content

Commit

Permalink
fix(loop_provider.go): handle error when parsing LIMITFEES environmen…
Browse files Browse the repository at this point in the history
…t variable to prevent potential panic (#62)

refactor(loop_provider.go): introduce maximumFeesAllowed variable for better code readability
feat(loop_provider.go): enhance error message when swap fees exceed maximum limit fees to provide more detailed information
  • Loading branch information
Jossec101 authored Nov 18, 2023
1 parent cad882e commit c83672c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions provider/loop_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ func (l *LoopProvider) RequestSubmarineSwap(ctx context.Context, request Submari

limitFeesStr := os.Getenv("LIMITFEES")
limitFees, err := strconv.ParseFloat(limitFeesStr, 64)
if err != nil {
return SubmarineSwapResponse{}, err
}

sumFees := quote.SwapFeeSat + quote.HtlcPublishFeeSat

if sumFees > int64(float64(request.SatsAmount)*limitFees) {
err := fmt.Errorf("swap fees are greater than max limit fees")
maximumFeesAllowed := int64(float64(request.SatsAmount) * limitFees)
if sumFees > maximumFeesAllowed {
err := fmt.Errorf("swap fees are greater than max limit fees, quote fees: %d, maximum fees alowed: %d", sumFees, maximumFeesAllowed)
log.Error(err)
return SubmarineSwapResponse{}, err
}
Expand Down Expand Up @@ -237,10 +242,15 @@ func (l *LoopProvider) RequestReverseSubmarineSwap(ctx context.Context, request

limitFeesStr := os.Getenv("LIMITFEES")
limitFees, err := strconv.ParseFloat(limitFeesStr, 64)
sumFees := quote.SwapFeeSat + quote.HtlcSweepFeeSat + quote.PrepayAmtSat
if err != nil {
return ReverseSubmarineSwapResponse{}, err
}

if sumFees > int64(float64(request.SatsAmount)*limitFees) {
err := fmt.Errorf("swap fees are greater than max limit fees")
sumFees := quote.SwapFeeSat + quote.HtlcSweepFeeSat + quote.PrepayAmtSat
maximumFeesAllowed := int64(float64(request.SatsAmount) * limitFees)

if sumFees > maximumFeesAllowed {
err := fmt.Errorf("swap fees are greater than max limit fees, quote fees: %d, maximum fees alowed: %d", sumFees, maximumFeesAllowed)
log.Error(err)
return ReverseSubmarineSwapResponse{}, err
}
Expand Down

0 comments on commit c83672c

Please sign in to comment.