Skip to content

Commit 3a8bbd3

Browse files
authored
Merge pull request #5 from TrezorHannes/myfeature
Myfeature
2 parents 3574f57 + 0c93d10 commit 3a8bbd3

File tree

2 files changed

+90
-36
lines changed

2 files changed

+90
-36
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# bash-rebalancer
22
With bash-rebalancer as a wrapper, you can use Carsten Otto's rebalance-lnd with > more than one channel in a batch system.
3+
It'll allow to add a bunch of channels when calling the script, and then a menu will guide you through the next steps.
34

45
The prerequisits are
56
- Installed Python Environment
67
- Rebalance-lnd https://github.com/C-Otto/rebalance-lnd
78
- LNDManage https://github.com/bitromortac/lndmanage
89

9-
It'll allow you to
10+
### Key Feature Set
1011
- Add **more than one channel** to rebalance
11-
- Incrementally start the ratio to rebalance with **10%, 30%, 50%, 70%** and remainder ratio to rebalance*
12+
- Incrementally start the ratio to rebalance with **10%, 30%, 50%, 70%** and remainder ratio to rebalance
1213
- For < 2M sats channels, the script will strive to achieve a 50:50 ratio. For > 2M Channel size, it'll aim to get 1M at either side
14+
- Alternatively, it allows to set a fixed amount of satoshis, and tries that _amount_ divided into 5 attempts for every selected channel
1315

1416
### Installation
1517
```
1618
$ git clone https://github.com/TrezorHannes/bash-rebalancer
1719
$ nano bash-rebalancer/my_rebalancer.sh
1820
```
19-
1) In case the LND directory doesn't work for you, add a direct link in line 22
20-
2) Secondly, alternate the path to your rebalance-lnd directory if it's not in ~/rebalance-lnd/ in line 18 (umbrel) or line 24 (not umbrel)
21-
21+
1) In case not successfully identifying your LND directory, add a direct link in the header
22+
2) If your rebalance-lnd directory isn't stored in $HOME (~/rebalance-lnd/), add a direct link in the header, too
2223

2324
#### Syntax for one channel
2425
`$ ./bash-rebalancer/my_rebalancer.sh -j cidxxxxxxxxxxxxxxx`
@@ -36,6 +37,7 @@ This command will try to rebalance _for 6 different channels_ (j-o).
3637
- Direction push (👉) outbound or pull (👈) inbound liquidity
3738
- -j Single channel ID of first and required channel
3839
- -k to -p arguments allow for passing additional optional channels to rebalance
40+
- Specify Automated or Defined Amount to be rebalanced
3941
```
4042

4143
### Hints

my_rebalancer.sh

Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
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
149
if [ "`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
1915
else
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
2522
fi
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+
2734
helpFunction()
2835
{
2936
echo "FUCK $1 - something went wrong"
@@ -54,7 +61,7 @@ then
5461
helpFunction
5562
fi
5663

57-
rebalance_something ()
64+
rebalance_something ()
5865
{
5966

6067
if [ $direction == '👉Push' ]
@@ -63,18 +70,27 @@ if [ $direction == '👉Push' ]
6370
else
6471
direction='t'
6572
fi
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

7389
rebalance_start()
7490
{
7591
#Channel 1
7692
echo "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

7995
if [ -z "$parameterK" ]
8096
then
@@ -127,9 +143,9 @@ fi
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
145161
done
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
162180
done
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
189209
fi
190210
echo "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
193242
echo -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"
206258
echo -e "===================================================================================================================================="
207259
echo -e ""
208260

0 commit comments

Comments
 (0)