11#! /bin/bash
22# A sample Bash script, by Hakuna
3- # ToDo:
4- # 1) In case the below LND directory doesn't work for you, add a direct link in line 22
5- # 2) Secondly, alternate the path to your rebalance-lnd directory if it's not in ~/rebalance-lnd/ in line 18 (umbrel) or line 24 (!umbrel)
3+ # ToDo:
4+ # 1) In case the below LND directory doesn't work for you, add a direct link in line 18
5+ # 2) Secondly, alternate the path to your rebalance-lnd directory if it's not in ~/rebalance-lnd/ in line 13 (umbrel) or line 19 (!umbrel)
66
7- activate () {
8- . ../.venv/bin/activate
9- source ~ /venv/bin/activate
10- }
11- activate
127
138# Set LN-Path & Rebalance-LND
149if [ " ` uname -a | grep umbrel` " != " " ]
15- then
10+ then
1611 # LNPATH setting on umbrel
1712 LNPATH=" ~/umbrel/lnd/"
1813 RLND=" /home/umbrel/rebalance-lnd/rebalance.py"
14+ umbrel=1
1915else
2016 # Other installations
2117# Set your own Path to LND in case the below does not work for you
2218 LNPATH=" ~/.lnd/"
23- # Adjust this directory in case you installed Rebalance-LND somewhere different
19+ # Adjust this directory in case you installed Rebalance-LND somewhere different
2420 RLND=" /home/admin/apps/rebalance-lnd/rebalance.py"
21+ umbrel=0
2522fi
2623
24+ activate () {
25+ if [ $umbrel = 1 ]
26+ then
27+ source ~ /venv/bin/activate
28+ else
29+ . ../.venv/bin/activate
30+ fi
31+ }
32+ activate
33+
2734helpFunction ()
2835{
2936 echo " FUCK $1 - something went wrong"
5461 helpFunction
5562fi
5663
57- rebalance_something ()
64+ rebalance_something ()
5865{
5966
6067if [ $direction == ' 👉Push' ]
@@ -63,18 +70,27 @@ if [ $direction == '👉Push' ]
6370 else
6471 direction=' t'
6572fi
73+ if [ $amountoption == ' Defined' ]
74+ then
75+ let a=$amountvalue /5
76+ python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -a $a
77+ python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -a $a
78+ python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -a $a
79+ python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -a $a
80+ python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -a $a
81+ else
6682 python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -p $2
6783 python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -p $3
6884 python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -p $4
6985 python $RLND --lnddir $LNPATH --$feeoption $feevalue -$direction $1 -p $5
70- python $RLND --lnddir $LNPATH -- $feeoption $feevalue - $direction $1
86+ fi
7187}
7288
7389rebalance_start ()
7490{
7591# Channel 1
7692echo " Starting the rebalancing on Channel 1"
77- rebalance_something $parameterJ 10 30 50 70
93+ rebalance_something $parameterJ 10 30 50 70 # adjust string for function to pick up -a or -p
7894
7995if [ -z " $parameterK " ]
8096then
127143}
128144
129145# Direction-Selection Process
130- echo -e " ===================================================================================================================================="
131146 echo -e " "
132- echo -e " \t You have successfully added one or more channels to be rebalanced. Now define where the liquidity should move to."
147+ echo -e " [DIRECTION-SELECTION PROCESS]======================================================================================================="
148+ echo -e " You have successfully added one or more channels to be rebalanced. Now define where the liquidity should move to."
133149 echo -e " "
134150 echo -e " \t - 👉 Pushing liquidity indicates low inbound, high amount of local outbound sats"
135151 echo -e " \t - 👈 Pulling liquidity indicates high inbound, low amount of local outbound sats"
@@ -145,7 +161,9 @@ break
145161done
146162
147163# Fee-Selection Process
148- echo -e " ===================================================================================================================================="
164+ echo -e " "
165+ echo -e " [FEE-SELECTION PROCESS]============================================================================================================="
166+ echo -e " Rebalance-LND offers 3 ways to set the price-ceiling for your rebalance. Chose one of three different options below."
149167 echo -e " "
150168 echo -e " \tfee-factor: set b/w 0.1 and 1.0. Compare the costs against the expected income, scaled by this factor. fee-factor 1.5, routes that cost at most 150% of the expected earnings"
151169 echo -e " \tfee-limit: enter total amount of Satoshis willing to spend per rebalance. If set, only consider rebalance transactions that cost up to the given number of satoshis."
@@ -162,10 +180,12 @@ break
162180done
163181
164182# Fee-Value Process
165- echo -e " ===================================================================================================================================="
166183 echo -e " "
167- echo -e " \t Indicate the price-ranges you want to allow as ceiling for your rebalance across all channels indicated. This is not error prone, read carefully"
168- echo -e " \t - fee-factor:decimal set. Examples: 0.1 indicates rebalance for max 10% costs. 0.5 = 50%, 1.5 = 150%. Start low eg 0.5"
184+ echo -e " [FEE-VALUE]========================================================================================================================="
185+ echo -e " Economically viable pricing your rebalance-action is important!"
186+ echo -e " Indicate the price-ranges you want to allow as ceiling for your rebalance across all channels indicated. This is not error prone, read carefully"
187+ echo -e " "
188+ echo -e " \t - fee-factor: decimal set. Examples: 0.1 indicates rebalance for max 10% costs. 0.5 = 50%, 1.5 = 150%. Start low eg 0.5"
169189 echo -e " \t - fee-limit: total amount of satoshis per rebalance, eg. 30"
170190 echo -e " \t - fee-ppm-limit: fee-rate per million satoshis. Set to 200 will pay a max of 200 satoshis for every million satoshis rebalanced"
171191 echo -e " "
@@ -189,20 +209,52 @@ else
189209fi
190210echo " We'll go for $feevalue "
191211
212+ # Amount-Definition Process
213+ echo -e " "
214+ echo -e " [AMOUNT-SELECTION PROCESS]==========================================================================================================="
215+ echo -e " Now lastly, let's determine the girth: Do you want the Script to take over how much to rebalance, or want to specify the size?"
216+ echo -e " "
217+ echo -e " \tAutomated: The script will aim for 5 steps to get your channel to 50:50 balance, or 1M on either side for channels bigger > 2M satoshis"
218+ echo -e " \tDefined: You aim to rebalance a defined amount satoshis. It'll be divided into 5 chunks, since smaller sizes usually rebalance easier "
219+ echo -e " "
220+ echo -e " Please note: In case you called > more than one channel to rebalance, the second option " Defined" will be tried for ALL channels given"
221+ echo -e " "
222+
223+ amountoptions=' Automated Defined'
224+ PS3=' Select Amount Option: '
225+
226+ select amountoption in $amountoptions
227+ do
228+ echo " We'll go for $amountoption "
229+ break
230+ done
231+
232+ if [ $amountoption == ' Defined' ]
233+ then
234+ echo " How much do you want to $direction ? Enter the absolute amount in Satoshis, eg 1000000"
235+ read amountvalue
236+ else
237+ amountvalue=' '
238+ # break
239+ fi
240+
192241# Parse parameters from the command initiation
193242echo -e " "
194- echo -e " ===================================================================================================================================="
195- echo " Fee Attribute > $feeoption "
196- echo " Fee Value > $feevalue "
197- echo " Direction 👉Push or 👈Pull > $direction "
198- echo " "
199- echo " Channel ID 1 > $parameterJ "
200- echo " Channel ID 2 > $parameterK "
201- echo " Channel ID 3 > $parameterL "
202- echo " Channel ID 4 > $parameterM "
203- echo " Channel ID 5 > $parameterN "
204- echo " Channel ID 6 > $parameterO "
205- echo " Channel ID 7 > $parameterP "
243+ echo -e " [SUMMARY]==========================================================================================================================="
244+ echo -e " Fee Attribute > \t\t $feeoption "
245+ echo -e " Fee Value > \t\t\t $feevalue "
246+ echo -e " Direction 👉Push or 👈Pull > \t $direction "
247+ echo -e " Amount-Definition > \t\t $amountoption $amountvalue "
248+
249+
250+ echo -e " "
251+ echo -e " Channel ID 1 > \t\t\t $parameterJ "
252+ echo -e " Channel ID 2 > \t\t\t $parameterK "
253+ echo -e " Channel ID 3 > \t\t\t $parameterL "
254+ echo -e " Channel ID 4 > \t\t\t $parameterM "
255+ echo -e " Channel ID 5 > \t\t\t $parameterN "
256+ echo -e " Channel ID 6 > \t\t\t $parameterO "
257+ echo -e " Channel ID 7 > \t\t\t $parameterP "
206258echo -e " ===================================================================================================================================="
207259echo -e " "
208260
0 commit comments