Skip to content

Commit

Permalink
Print settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson committed Mar 26, 2023
1 parent 966e7cc commit c684a25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/raiju/raiju.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ func parseFees(thresholds string, fees string) (raiju.LiquidityFees, error) {
ffs[i] = lightning.FeePPM(ff)
}

return raiju.NewLiquidityFees(tfs, ffs)
lf, err := raiju.NewLiquidityFees(tfs, ffs)
if err != nil {
return raiju.LiquidityFees{}, err
}

lf.PrintSettings()

return lf, nil
}

func main() {
Expand Down
16 changes: 16 additions & 0 deletions fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package raiju

import (
"errors"
"fmt"
"os"

"github.com/nyonson/raiju/lightning"
)
Expand Down Expand Up @@ -60,10 +62,24 @@ func (lf LiquidityFees) RebalanceChannels(channels lightning.Channels) (high lig
return high, low
}

// RebalanceFee is the max fee to use in a circular rebalance to ensure its not wasted.
func (lf LiquidityFees) RebalanceFee() lightning.FeePPM {
return lf.fees[len(lf.fees)-1]
}

// PrintSettings to output.
func (lf LiquidityFees) PrintSettings() {
for i := 0; i < len(lf.fees); i++ {
if i == len(lf.fees)-1 {
fmt.Fprintf(os.Stderr, "channels under %g%% local liquidity to %g ppm\n", lf.thresholds[i-1], lf.fees[i])
} else if i == 0 {
fmt.Fprintf(os.Stderr, "channels over %g%% local liquidity to %g ppm, ", lf.thresholds[i], lf.fees[i])
} else {
fmt.Fprintf(os.Stderr, "channels between %g%% and %g%% local liquidity to %g ppm, ", lf.thresholds[i-1], lf.thresholds[i], lf.fees[i])
}
}
}

// NewLiquidityFees with threshold and fee validation.
func NewLiquidityFees(thresholds []float64, fees []lightning.FeePPM) (LiquidityFees, error) {
// ensure every bucket has a fee
Expand Down

0 comments on commit c684a25

Please sign in to comment.