Skip to content

Commit

Permalink
Merge pull request #74 from Impa10r/v1.6.2
Browse files Browse the repository at this point in the history
v1.6.2
  • Loading branch information
Impa10r authored Jul 7, 2024
2 parents cb289fa + 2593813 commit 4040535
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Versions

## 1.6.2

- Fix 'invalid asset' bug
- AutoSwap: disallow spending LBTC gained in the same channel
- AutoSwap: only consider channels with routed out > routed in

## 1.6.1

- AutoFee: add Update All to set paramereter(s) to all custom rules
Expand Down
7 changes: 3 additions & 4 deletions cmd/psweb/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
sumLocal += ch.GetLocalBalance()
sumRemote += ch.GetRemoteBalance()

// should not be less than both Min HTLC setting
keysendSats = max(keysendSats, info.PeerMinHtlc)
// should not be less than our Min HTLC setting
keysendSats = max(keysendSats, info.OurMinHtlc)

// add AF info
Expand Down Expand Up @@ -2077,9 +2076,9 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {

switch direction {
case "in":
id, err = ps.SwapIn(client, swapAmount, channelId, r.FormValue("asset"), false)
id, err = ps.SwapIn(client, swapAmount, channelId, asset, false)
case "out":
id, err = ps.SwapOut(client, swapAmount, channelId, r.FormValue("asset"), false)
id, err = ps.SwapOut(client, swapAmount, channelId, asset, false)
}

if err != nil {
Expand Down
26 changes: 24 additions & 2 deletions cmd/psweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

const (
// App version tag
version = "v1.6.1"
version = "v1.6.2"
)

type SwapParams struct {
Expand Down Expand Up @@ -1179,10 +1179,16 @@ func findSwapInCandidate(candidate *SwapParams) error {

// find last swap timestamps per channel
swapTimestamps := make(map[uint64]int64)
// true if initiated swap out or received swap in
lastWasSwapOut := make(map[uint64]bool)

for _, swap := range swaps {
if simplifySwapState(swap.State) == "success" && swapTimestamps[swap.LndChanId] < swap.CreatedAt {
swapTimestamps[swap.LndChanId] = swap.CreatedAt
lastWasSwapOut[swap.LndChanId] = false
if swap.Asset == "lbtc" && (swap.Type+swap.Role == "swap-outsender" || swap.Type+swap.Role == "swap-inreceiver") {
lastWasSwapOut[swap.LndChanId] = true
}
}
}

Expand All @@ -1198,6 +1204,11 @@ func findSwapInCandidate(candidate *SwapParams) error {
continue
}
for _, channel := range peer.Channels {
// ignore if there was an opposite peerswap
if lastWasSwapOut[channel.ChannelId] {
continue
}

chanInfo := ln.GetChannelInfo(cl, channel.ChannelId, peer.NodeId)
// find the potential swap amount to bring balance to target
targetBalance := chanInfo.Capacity * config.Config.AutoSwapTargetPct / 100
Expand All @@ -1210,6 +1221,17 @@ func findSwapInCandidate(candidate *SwapParams) error {
continue
}

// only consider sink channels (net routing > 1k)
lastSwapTimestamp := time.Now().AddDate(0, -6, 0).Unix()
if swapTimestamps[channel.ChannelId] > lastSwapTimestamp {
lastSwapTimestamp = swapTimestamps[channel.ChannelId]
}

stats := ln.GetChannelStats(channel.ChannelId, uint64(lastSwapTimestamp))
if stats.RoutedOut-stats.RoutedIn <= 1000 {
continue
}

swapAmount := targetBalance - channel.LocalBalance

// limit to own and peer's max HTLC setting and remote balance less reserve for LN fee
Expand All @@ -1226,7 +1248,7 @@ func findSwapInCandidate(candidate *SwapParams) error {
stats := ln.GetChannelStats(channel.ChannelId, uint64(lastTimestamp))

ppm := uint64(0)
if stats.RoutedOut > 1_000_000 { // ignore small results
if stats.RoutedOut > 1_000 { // ignore small results
ppm = stats.FeeSat * 1_000_000 / stats.RoutedOut
}

Expand Down
13 changes: 8 additions & 5 deletions cmd/psweb/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func telegramStart() {
case "/pegin":
t := ""
if config.Config.PeginTxId == "" {
t = "No pending peg-in"
t = "No pending peg-in or BTC withdrawal"
} else {
cl, clean, er := ln.GetClient()
if er != nil {
Expand All @@ -96,7 +96,10 @@ func telegramStart() {
confs, _ := ln.GetTxConfirmations(cl, config.Config.PeginTxId)
duration := time.Duration(10*(102-confs)) * time.Minute
formattedDuration := time.Time{}.Add(duration).Format("15h 04m")
t = "⏰ Amount: " + formatWithThousandSeparators(uint64(config.Config.PeginAmount)) + " sats, Confs: " + strconv.Itoa(int(confs)) + "/102, Time left: " + formattedDuration
t = "⏰ Amount: " + formatWithThousandSeparators(uint64(config.Config.PeginAmount)) + " sats, Confs: " + strconv.Itoa(int(confs))
if config.Config.PeginClaimScript != "" {
t += "/102, Time left: " + formattedDuration
}
clean()
}
}
Expand Down Expand Up @@ -145,15 +148,15 @@ func telegramConnect() {
},
tgbotapi.BotCommand{
Command: "backup",
Description: "Get Liquid wallet backup",
Description: "Elements wallet backup",
},
tgbotapi.BotCommand{
Command: "pegin",
Description: "Get status of peg-in",
Description: "Status of peg-in or BTC withdrawal",
},
tgbotapi.BotCommand{
Command: "auto",
Description: "Get status of auto swap-ins",
Description: "Status of auto swap-ins",
},
tgbotapi.BotCommand{
Command: "version",
Expand Down

0 comments on commit 4040535

Please sign in to comment.