From c684a254996ffbad92a165e5f16c0a6ebc8ce80f Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Sun, 26 Mar 2023 07:09:13 -0700 Subject: [PATCH] Print settings --- cmd/raiju/raiju.go | 9 ++++++++- fees.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/raiju/raiju.go b/cmd/raiju/raiju.go index 4014586..1560e83 100644 --- a/cmd/raiju/raiju.go +++ b/cmd/raiju/raiju.go @@ -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() { diff --git a/fees.go b/fees.go index 8c9b199..6132b93 100644 --- a/fees.go +++ b/fees.go @@ -2,6 +2,8 @@ package raiju import ( "errors" + "fmt" + "os" "github.com/nyonson/raiju/lightning" ) @@ -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