Skip to content

Commit

Permalink
multi: enable per-peer premium configuration
Browse files Browse the repository at this point in the history
Allow setting different premium values for BTC and LBTC.

This change also enables users to configure individual premiums for
each peer, providing more granular control over pricing and
liquidity.

- Added separate premium fields for BTC and LBTC.
- Implemented logic to apply peer-specific premiums.
  • Loading branch information
YusukeShimizu committed Jan 6, 2025
1 parent abc40d9 commit ff38dc8
Show file tree
Hide file tree
Showing 29 changed files with 1,683 additions and 1,121 deletions.
28 changes: 16 additions & 12 deletions clightning/clightning_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,11 @@ func (l *ListPeers) Call() (jrpc2.Result, error) {
SatsOut: ReceiverSatsOut,
SatsIn: ReceiverSatsIn,
},
PaidFee: paidFees,
SwapInPremiumRatePpm: p.SwapInPremiumRatePPM,
SwapOutPremiumRatePpm: p.SwapOutPremiumRatePPM,
PaidFee: paidFees,
BTCSwapInPremiumRatePPM: p.BTCSwapInPremiumRatePPM,
BTCSwapOutPremiumRatePPM: p.BTCSwapOutPremiumRatePPM,
LBTCSwapInPremiumRatePPM: p.LBTCSwapInPremiumRatePPM,
LBTCSwapOutPremiumRatePPM: p.LBTCSwapOutPremiumRatePPM,
}
channels, err := l.cl.glightning.ListChannelsBySource(peer.Id)
if err != nil {
Expand Down Expand Up @@ -1115,15 +1117,17 @@ type SwapStats struct {
}

type PeerSwapPeer struct {
NodeId string `json:"nodeid"`
SwapsAllowed bool `json:"swaps_allowed"`
SupportedAssets []string `json:"supported_assets"`
Channels []*PeerSwapPeerChannel `json:"channels"`
AsSender *SwapStats `json:"sent,omitempty"`
AsReceiver *SwapStats `json:"received,omitempty"`
PaidFee uint64 `json:"total_fee_paid,omitempty"`
SwapInPremiumRatePpm int64
SwapOutPremiumRatePpm int64
NodeId string `json:"nodeid"`
SwapsAllowed bool `json:"swaps_allowed"`
SupportedAssets []string `json:"supported_assets"`
Channels []*PeerSwapPeerChannel `json:"channels"`
AsSender *SwapStats `json:"sent,omitempty"`
AsReceiver *SwapStats `json:"received,omitempty"`
PaidFee uint64 `json:"total_fee_paid,omitempty"`
BTCSwapInPremiumRatePPM int64 `json:"btc_swap_in_premium_rate_ppm"`
BTCSwapOutPremiumRatePPM int64 `json:"btc_swap_out_premium_rate_ppm"`
LBTCSwapInPremiumRatePPM int64 `json:"lbtc_swap_in_premium_rate_ppm"`
LBTCSwapOutPremiumRatePPM int64 `json:"lbtc_swap_out_premium_rate_ppm"`
}

// checkFeatures checks if a node runs the peerswap Plugin
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ require (
github.com/lightningnetwork/lnd/ticker v1.1.0 // indirect
github.com/lightningnetwork/lnd/tlv v1.0.3 // indirect
github.com/samber/lo v1.47.0
gopkg.in/ini.v1 v1.67.0
)

// This fork contains some options we need to reconnect to lnd.
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6 h1:sE4tvxWw01v7K3MAHwKF2UF3xQbgy23PRURntuV1CkU=
github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/elementsproject/glightning v0.0.0-20241218050901-3885803d9ee1 h1:E6+AMjkLPqdmd26ORsJa/glxiiiNAluosVsNY/sLJPw=
github.com/elementsproject/glightning v0.0.0-20241218050901-3885803d9ee1/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo=
github.com/elementsproject/glightning v0.0.0-20241218232330-5d69c660a74c h1:R4SOjU755MzmyedUIHlDIVc0uGZHnKVULKD0dkfJf88=
github.com/elementsproject/glightning v0.0.0-20241218232330-5d69c660a74c/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -1169,6 +1167,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
gopkg.in/httprequest.v1 v1.2.0/go.mod h1:T61ZUaJLpMnzvoJDO03ZD8yRXD4nZzBeDoW5e9sffjg=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/juju/environschema.v1 v1.0.0/go.mod h1:WTgU3KXKCVoO9bMmG/4KHzoaRvLeoxfjArpgd1MGWFA=
gopkg.in/macaroon-bakery.v2 v2.3.0 h1:b40knPgPTke1QLTE8BSYeH7+R/hiIozB1A8CTLYN0Ic=
gopkg.in/macaroon-bakery.v2 v2.3.0/go.mod h1:/8YhtPARXeRzbpEPLmRB66+gQE8/pzBBkWwg7Vz/guc=
Expand Down
20 changes: 12 additions & 8 deletions peerswaprpc/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import (

func GetPolicyMessage(p policy.Policy) *Policy {
return &Policy{
ReserveOnchainMsat: p.ReserveOnchainMsat,
MinSwapAmountMsat: p.MinSwapAmountMsat,
AcceptAllPeers: p.AcceptAllPeers,
AllowNewSwaps: p.AllowNewSwaps,
AllowlistedPeers: p.PeerAllowlist,
SuspiciousPeerList: p.SuspiciousPeerList,
SwapInPremiumRatePpm: p.SwapInPremiumRatePPM,
SwapOutPremiumRatePpm: p.SwapOutPremiumRatePPM,
ReserveOnchainMsat: p.ReserveOnchainMsat,
MinSwapAmountMsat: p.MinSwapAmountMsat,
AcceptAllPeers: p.AcceptAllPeers,
AllowNewSwaps: p.AllowNewSwaps,
AllowlistedPeers: p.PeerAllowlist,
SuspiciousPeerList: p.SuspiciousPeerList,
DefaultPremium: &Premium{
BtcSwapInPremiumRatePpm: p.GetPremiumRate("", policy.BtcSwapIn),
BtcSwapOutPremiumRatePpm: p.GetPremiumRate("", policy.BtcSwapOut),
LbtcSwapInPremiumRatePpm: p.GetPremiumRate("", policy.LbtcSwapIn),
LbtcSwapOutPremiumRatePpm: p.GetPremiumRate("", policy.LbtcSwapOut),
},
}
}

Expand Down
Loading

0 comments on commit ff38dc8

Please sign in to comment.