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 Oct 11, 2024
1 parent 638736d commit 5f32ed3
Show file tree
Hide file tree
Showing 27 changed files with 1,037 additions and 594 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 @@ -154,6 +154,7 @@ require (
github.com/lightningnetwork/lnd/queue v1.1.0 // indirect
github.com/lightningnetwork/lnd/ticker v1.1.0 // indirect
github.com/lightningnetwork/lnd/tlv v1.0.3 // indirect
gopkg.in/ini.v1 v1.67.0
)

// This fork contains some options we need to reconnect to lnd.
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,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 5f32ed3

Please sign in to comment.