From 2b776da18374bfb34484b226e4c18b09b4a1a67e Mon Sep 17 00:00:00 2001 From: bruwbird Date: Sat, 12 Oct 2024 23:53:05 +0000 Subject: [PATCH] multi: enable per-peer premium configuration 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. --- clightning/clightning_commands.go | 28 +- go.mod | 1 + go.sum | 2 + peerswaprpc/format.go | 20 +- peerswaprpc/peerswaprpc.pb.go | 586 ++++++++++++----------- peerswaprpc/peerswaprpc.proto | 24 +- peerswaprpc/peerswaprpc.swagger.json | 41 +- peerswaprpc/server.go | 16 +- policy/policy.go | 73 ++- policy/policy_test.go | 75 ++- policy/premium.go | 165 +++++++ policy/premium_test.go | 182 ++++++++ poll/messages.go | 24 +- poll/service.go | 70 +-- poll/service_test.go | 7 +- sample_policy.conf | 16 +- swap/actions.go | 17 +- swap/service.go | 34 +- swap/service_test.go | 4 +- swap/services.go | 5 +- swap/swap_out_sender_test.go | 8 +- test/bitcoin_cln_test.go | 72 +-- test/bitcoin_lnd_test.go | 60 +-- test/liquid_cln_test.go | 48 +- test/liquid_lnd_test.go | 48 +- test/lwk_cln_test.go | 666 +++++++++++++++------------ test/lwk_lnd_test.go | 481 ++++++++++--------- test/recovery_test.go | 12 +- test/testcases.go | 5 +- 29 files changed, 1671 insertions(+), 1119 deletions(-) create mode 100644 policy/premium.go create mode 100644 policy/premium_test.go diff --git a/clightning/clightning_commands.go b/clightning/clightning_commands.go index 52e93f44..777f8448 100644 --- a/clightning/clightning_commands.go +++ b/clightning/clightning_commands.go @@ -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 { @@ -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 diff --git a/go.mod b/go.mod index 90540f96..fba2db10 100644 --- a/go.mod +++ b/go.mod @@ -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. diff --git a/go.sum b/go.sum index f8289c28..2629bc34 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/peerswaprpc/format.go b/peerswaprpc/format.go index a80c8d21..72ffad76 100644 --- a/peerswaprpc/format.go +++ b/peerswaprpc/format.go @@ -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), + }, } } diff --git a/peerswaprpc/peerswaprpc.pb.go b/peerswaprpc/peerswaprpc.pb.go index de3d2ddf..64d89416 100644 --- a/peerswaprpc/peerswaprpc.pb.go +++ b/peerswaprpc/peerswaprpc.pb.go @@ -1301,26 +1301,101 @@ func (x *PrettyPrintSwap) GetPremiumAmount() int64 { return 0 } +// Premium message represents the premium rates. +type Premium struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Premium rate for BTC swap-in (in PPM) + BtcSwapInPremiumRatePpm int64 `protobuf:"varint,1,opt,name=btc_swap_in_premium_rate_ppm,json=btcSwapInPremiumRatePpm,proto3" json:"btc_swap_in_premium_rate_ppm,omitempty"` + // Premium rate for BTC swap-out (in PPM) + BtcSwapOutPremiumRatePpm int64 `protobuf:"varint,2,opt,name=btc_swap_out_premium_rate_ppm,json=btcSwapOutPremiumRatePpm,proto3" json:"btc_swap_out_premium_rate_ppm,omitempty"` + // Premium rate for LBTC swap-in (in PPM) + LbtcSwapInPremiumRatePpm int64 `protobuf:"varint,3,opt,name=lbtc_swap_in_premium_rate_ppm,json=lbtcSwapInPremiumRatePpm,proto3" json:"lbtc_swap_in_premium_rate_ppm,omitempty"` + // Premium rate for LBTC swap-out (in PPM) + LbtcSwapOutPremiumRatePpm int64 `protobuf:"varint,4,opt,name=lbtc_swap_out_premium_rate_ppm,json=lbtcSwapOutPremiumRatePpm,proto3" json:"lbtc_swap_out_premium_rate_ppm,omitempty"` +} + +func (x *Premium) Reset() { + *x = Premium{} + if protoimpl.UnsafeEnabled { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[23] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Premium) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Premium) ProtoMessage() {} + +func (x *Premium) ProtoReflect() protoreflect.Message { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[23] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Premium.ProtoReflect.Descriptor instead. +func (*Premium) Descriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{23} +} + +func (x *Premium) GetBtcSwapInPremiumRatePpm() int64 { + if x != nil { + return x.BtcSwapInPremiumRatePpm + } + return 0 +} + +func (x *Premium) GetBtcSwapOutPremiumRatePpm() int64 { + if x != nil { + return x.BtcSwapOutPremiumRatePpm + } + return 0 +} + +func (x *Premium) GetLbtcSwapInPremiumRatePpm() int64 { + if x != nil { + return x.LbtcSwapInPremiumRatePpm + } + return 0 +} + +func (x *Premium) GetLbtcSwapOutPremiumRatePpm() int64 { + if x != nil { + return x.LbtcSwapOutPremiumRatePpm + } + return 0 +} + type PeerSwapPeer struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - NodeId string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` - SwapsAllowed bool `protobuf:"varint,2,opt,name=swaps_allowed,json=swapsAllowed,proto3" json:"swaps_allowed,omitempty"` - SupportedAssets []string `protobuf:"bytes,3,rep,name=supported_assets,json=supportedAssets,proto3" json:"supported_assets,omitempty"` - Channels []*PeerSwapPeerChannel `protobuf:"bytes,4,rep,name=channels,proto3" json:"channels,omitempty"` - AsSender *SwapStats `protobuf:"bytes,5,opt,name=as_sender,json=asSender,proto3" json:"as_sender,omitempty"` - AsReceiver *SwapStats `protobuf:"bytes,6,opt,name=as_receiver,json=asReceiver,proto3" json:"as_receiver,omitempty"` - PaidFee uint64 `protobuf:"varint,7,opt,name=paid_fee,json=paidFee,proto3" json:"paid_fee,omitempty"` - SwapInPremiumRatePpm int64 `protobuf:"varint,8,opt,name=swap_in_premium_rate_ppm,json=swapInPremiumRatePpm,proto3" json:"swap_in_premium_rate_ppm,omitempty"` - SwapOutPremiumRatePpm int64 `protobuf:"varint,9,opt,name=swap_out_premium_rate_ppm,json=swapOutPremiumRatePpm,proto3" json:"swap_out_premium_rate_ppm,omitempty"` + NodeId string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` + SwapsAllowed bool `protobuf:"varint,2,opt,name=swaps_allowed,json=swapsAllowed,proto3" json:"swaps_allowed,omitempty"` + SupportedAssets []string `protobuf:"bytes,3,rep,name=supported_assets,json=supportedAssets,proto3" json:"supported_assets,omitempty"` + Channels []*PeerSwapPeerChannel `protobuf:"bytes,4,rep,name=channels,proto3" json:"channels,omitempty"` + AsSender *SwapStats `protobuf:"bytes,5,opt,name=as_sender,json=asSender,proto3" json:"as_sender,omitempty"` + AsReceiver *SwapStats `protobuf:"bytes,6,opt,name=as_receiver,json=asReceiver,proto3" json:"as_receiver,omitempty"` + PaidFee uint64 `protobuf:"varint,7,opt,name=paid_fee,json=paidFee,proto3" json:"paid_fee,omitempty"` + Premium *Premium `protobuf:"bytes,8,opt,name=premium,proto3" json:"premium,omitempty"` } func (x *PeerSwapPeer) Reset() { *x = PeerSwapPeer{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[23] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1333,7 +1408,7 @@ func (x *PeerSwapPeer) String() string { func (*PeerSwapPeer) ProtoMessage() {} func (x *PeerSwapPeer) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[23] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1346,7 +1421,7 @@ func (x *PeerSwapPeer) ProtoReflect() protoreflect.Message { // Deprecated: Use PeerSwapPeer.ProtoReflect.Descriptor instead. func (*PeerSwapPeer) Descriptor() ([]byte, []int) { - return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{23} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{24} } func (x *PeerSwapPeer) GetNodeId() string { @@ -1398,18 +1473,11 @@ func (x *PeerSwapPeer) GetPaidFee() uint64 { return 0 } -func (x *PeerSwapPeer) GetSwapInPremiumRatePpm() int64 { - if x != nil { - return x.SwapInPremiumRatePpm - } - return 0 -} - -func (x *PeerSwapPeer) GetSwapOutPremiumRatePpm() int64 { +func (x *PeerSwapPeer) GetPremium() *Premium { if x != nil { - return x.SwapOutPremiumRatePpm + return x.Premium } - return 0 + return nil } type PeerSwapPeerChannel struct { @@ -1426,7 +1494,7 @@ type PeerSwapPeerChannel struct { func (x *PeerSwapPeerChannel) Reset() { *x = PeerSwapPeerChannel{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1439,7 +1507,7 @@ func (x *PeerSwapPeerChannel) String() string { func (*PeerSwapPeerChannel) ProtoMessage() {} func (x *PeerSwapPeerChannel) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1452,7 +1520,7 @@ func (x *PeerSwapPeerChannel) ProtoReflect() protoreflect.Message { // Deprecated: Use PeerSwapPeerChannel.ProtoReflect.Descriptor instead. func (*PeerSwapPeerChannel) Descriptor() ([]byte, []int) { - return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{24} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{25} } func (x *PeerSwapPeerChannel) GetChannelId() uint64 { @@ -1497,7 +1565,7 @@ type SwapStats struct { func (x *SwapStats) Reset() { *x = SwapStats{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1510,7 +1578,7 @@ func (x *SwapStats) String() string { func (*SwapStats) ProtoMessage() {} func (x *SwapStats) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1523,7 +1591,7 @@ func (x *SwapStats) ProtoReflect() protoreflect.Message { // Deprecated: Use SwapStats.ProtoReflect.Descriptor instead. func (*SwapStats) Descriptor() ([]byte, []int) { - return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{25} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{26} } func (x *SwapStats) GetSwapsOut() uint64 { @@ -1554,66 +1622,20 @@ func (x *SwapStats) GetSatsIn() uint64 { return 0 } -type PeerSwapNodes struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - NodeId string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` -} - -func (x *PeerSwapNodes) Reset() { - *x = PeerSwapNodes{} - if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *PeerSwapNodes) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*PeerSwapNodes) ProtoMessage() {} - -func (x *PeerSwapNodes) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use PeerSwapNodes.ProtoReflect.Descriptor instead. -func (*PeerSwapNodes) Descriptor() ([]byte, []int) { - return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{26} -} - -func (x *PeerSwapNodes) GetNodeId() string { - if x != nil { - return x.NodeId - } - return "" -} - type Policy struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ReserveOnchainMsat uint64 `protobuf:"varint,1,opt,name=reserve_onchain_msat,json=reserveOnchainMsat,proto3" json:"reserve_onchain_msat,omitempty"` - MinSwapAmountMsat uint64 `protobuf:"varint,2,opt,name=min_swap_amount_msat,json=minSwapAmountMsat,proto3" json:"min_swap_amount_msat,omitempty"` - AcceptAllPeers bool `protobuf:"varint,3,opt,name=accept_all_peers,json=acceptAllPeers,proto3" json:"accept_all_peers,omitempty"` - AllowNewSwaps bool `protobuf:"varint,4,opt,name=allow_new_swaps,json=allowNewSwaps,proto3" json:"allow_new_swaps,omitempty"` - AllowlistedPeers []string `protobuf:"bytes,5,rep,name=allowlisted_peers,json=allowlistedPeers,proto3" json:"allowlisted_peers,omitempty"` - SuspiciousPeerList []string `protobuf:"bytes,6,rep,name=suspicious_peer_list,json=suspiciousPeerList,proto3" json:"suspicious_peer_list,omitempty"` - SwapInPremiumRatePpm int64 `protobuf:"varint,7,opt,name=swap_in_premium_rate_ppm,json=swapInPremiumRatePpm,proto3" json:"swap_in_premium_rate_ppm,omitempty"` - SwapOutPremiumRatePpm int64 `protobuf:"varint,8,opt,name=swap_out_premium_rate_ppm,json=swapOutPremiumRatePpm,proto3" json:"swap_out_premium_rate_ppm,omitempty"` + ReserveOnchainMsat uint64 `protobuf:"varint,1,opt,name=reserve_onchain_msat,json=reserveOnchainMsat,proto3" json:"reserve_onchain_msat,omitempty"` + MinSwapAmountMsat uint64 `protobuf:"varint,2,opt,name=min_swap_amount_msat,json=minSwapAmountMsat,proto3" json:"min_swap_amount_msat,omitempty"` + AcceptAllPeers bool `protobuf:"varint,3,opt,name=accept_all_peers,json=acceptAllPeers,proto3" json:"accept_all_peers,omitempty"` + AllowNewSwaps bool `protobuf:"varint,4,opt,name=allow_new_swaps,json=allowNewSwaps,proto3" json:"allow_new_swaps,omitempty"` + AllowlistedPeers []string `protobuf:"bytes,5,rep,name=allowlisted_peers,json=allowlistedPeers,proto3" json:"allowlisted_peers,omitempty"` + SuspiciousPeerList []string `protobuf:"bytes,6,rep,name=suspicious_peer_list,json=suspiciousPeerList,proto3" json:"suspicious_peer_list,omitempty"` + // Displays the default premium rates. + // The premium rates for each peer are included in PeerSwapPeer. + DefaultPremium *Premium `protobuf:"bytes,7,opt,name=default_premium,json=defaultPremium,proto3" json:"default_premium,omitempty"` } func (x *Policy) Reset() { @@ -1690,18 +1712,11 @@ func (x *Policy) GetSuspiciousPeerList() []string { return nil } -func (x *Policy) GetSwapInPremiumRatePpm() int64 { - if x != nil { - return x.SwapInPremiumRatePpm - } - return 0 -} - -func (x *Policy) GetSwapOutPremiumRatePpm() int64 { +func (x *Policy) GetDefaultPremium() *Premium { if x != nil { - return x.SwapOutPremiumRatePpm + return x.DefaultPremium } - return 0 + return nil } type AllowSwapRequestsRequest struct { @@ -1972,7 +1987,24 @@ var file_peerswaprpc_peerswaprpc_proto_rawDesc = []byte{ 0x0e, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6c, 0x6e, 0x64, 0x43, 0x68, 0x61, 0x6e, 0x49, 0x64, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, - 0x6d, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xa7, 0x03, 0x0a, 0x0c, 0x50, 0x65, 0x65, 0x72, + 0x6d, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x8d, 0x02, 0x0a, 0x07, 0x50, 0x72, 0x65, 0x6d, + 0x69, 0x75, 0x6d, 0x12, 0x3d, 0x0a, 0x1c, 0x62, 0x74, 0x63, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x5f, + 0x69, 0x6e, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x5f, + 0x70, 0x70, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x17, 0x62, 0x74, 0x63, 0x53, 0x77, + 0x61, 0x70, 0x49, 0x6e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x50, + 0x70, 0x6d, 0x12, 0x3f, 0x0a, 0x1d, 0x62, 0x74, 0x63, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x6f, + 0x75, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x5f, + 0x70, 0x70, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x18, 0x62, 0x74, 0x63, 0x53, 0x77, + 0x61, 0x70, 0x4f, 0x75, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, + 0x50, 0x70, 0x6d, 0x12, 0x3f, 0x0a, 0x1d, 0x6c, 0x62, 0x74, 0x63, 0x5f, 0x73, 0x77, 0x61, 0x70, + 0x5f, 0x69, 0x6e, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, + 0x5f, 0x70, 0x70, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x18, 0x6c, 0x62, 0x74, 0x63, + 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, + 0x65, 0x50, 0x70, 0x6d, 0x12, 0x41, 0x0a, 0x1e, 0x6c, 0x62, 0x74, 0x63, 0x5f, 0x73, 0x77, 0x61, + 0x70, 0x5f, 0x6f, 0x75, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x72, 0x61, + 0x74, 0x65, 0x5f, 0x70, 0x70, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x19, 0x6c, 0x62, + 0x74, 0x63, 0x53, 0x77, 0x61, 0x70, 0x4f, 0x75, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, + 0x52, 0x61, 0x74, 0x65, 0x50, 0x70, 0x6d, 0x22, 0xe2, 0x02, 0x0a, 0x0c, 0x50, 0x65, 0x65, 0x72, 0x53, 0x77, 0x61, 0x70, 0x50, 0x65, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x77, 0x61, 0x70, 0x73, 0x5f, 0x61, 0x6c, 0x6c, 0x6f, 0x77, @@ -1992,143 +2024,133 @@ var file_peerswaprpc_peerswaprpc_proto_rawDesc = []byte{ 0x77, 0x61, 0x70, 0x53, 0x74, 0x61, 0x74, 0x73, 0x52, 0x0a, 0x61, 0x73, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x61, 0x69, 0x64, 0x5f, 0x66, 0x65, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x70, 0x61, 0x69, 0x64, 0x46, 0x65, 0x65, 0x12, - 0x36, 0x0a, 0x18, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x69, 0x6e, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, - 0x75, 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x70, 0x70, 0x6d, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x14, 0x73, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, - 0x52, 0x61, 0x74, 0x65, 0x50, 0x70, 0x6d, 0x12, 0x38, 0x0a, 0x19, 0x73, 0x77, 0x61, 0x70, 0x5f, - 0x6f, 0x75, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, - 0x5f, 0x70, 0x70, 0x6d, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x15, 0x73, 0x77, 0x61, 0x70, - 0x4f, 0x75, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x50, 0x70, - 0x6d, 0x22, 0x98, 0x01, 0x0a, 0x13, 0x50, 0x65, 0x65, 0x72, 0x53, 0x77, 0x61, 0x70, 0x50, 0x65, - 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, - 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x63, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x0c, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x25, 0x0a, - 0x0e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x42, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x22, 0x77, 0x0a, 0x09, - 0x53, 0x77, 0x61, 0x70, 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x77, 0x61, - 0x70, 0x73, 0x5f, 0x6f, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x73, 0x77, - 0x61, 0x70, 0x73, 0x4f, 0x75, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x77, 0x61, 0x70, 0x73, 0x5f, - 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x73, 0x77, 0x61, 0x70, 0x73, 0x49, - 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x61, 0x74, 0x73, 0x5f, 0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x07, 0x73, 0x61, 0x74, 0x73, 0x4f, 0x75, 0x74, 0x12, 0x17, 0x0a, 0x07, - 0x73, 0x61, 0x74, 0x73, 0x5f, 0x69, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x73, - 0x61, 0x74, 0x73, 0x49, 0x6e, 0x22, 0x28, 0x0a, 0x0d, 0x50, 0x65, 0x65, 0x72, 0x53, 0x77, 0x61, - 0x70, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x22, - 0x8e, 0x03, 0x0a, 0x06, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x30, 0x0a, 0x14, 0x72, 0x65, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x5f, 0x6f, 0x6e, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x6d, 0x73, - 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x12, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, - 0x65, 0x4f, 0x6e, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x4d, 0x73, 0x61, 0x74, 0x12, 0x2f, 0x0a, 0x14, - 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, - 0x6d, 0x73, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x6d, 0x69, 0x6e, 0x53, - 0x77, 0x61, 0x70, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x4d, 0x73, 0x61, 0x74, 0x12, 0x28, 0x0a, - 0x10, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x65, 0x65, 0x72, - 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x41, - 0x6c, 0x6c, 0x50, 0x65, 0x65, 0x72, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x61, 0x6c, 0x6c, 0x6f, 0x77, - 0x5f, 0x6e, 0x65, 0x77, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x0d, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x4e, 0x65, 0x77, 0x53, 0x77, 0x61, 0x70, 0x73, 0x12, - 0x2b, 0x0a, 0x11, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x70, - 0x65, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x10, 0x61, 0x6c, 0x6c, 0x6f, - 0x77, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x64, 0x50, 0x65, 0x65, 0x72, 0x73, 0x12, 0x30, 0x0a, 0x14, - 0x73, 0x75, 0x73, 0x70, 0x69, 0x63, 0x69, 0x6f, 0x75, 0x73, 0x5f, 0x70, 0x65, 0x65, 0x72, 0x5f, - 0x6c, 0x69, 0x73, 0x74, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x12, 0x73, 0x75, 0x73, 0x70, - 0x69, 0x63, 0x69, 0x6f, 0x75, 0x73, 0x50, 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x36, - 0x0a, 0x18, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x69, 0x6e, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, - 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x70, 0x70, 0x6d, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x14, 0x73, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, - 0x61, 0x74, 0x65, 0x50, 0x70, 0x6d, 0x12, 0x38, 0x0a, 0x19, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x6f, - 0x75, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x5f, - 0x70, 0x70, 0x6d, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x15, 0x73, 0x77, 0x61, 0x70, 0x4f, - 0x75, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x50, 0x70, 0x6d, - 0x22, 0x30, 0x0a, 0x18, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, - 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x61, 0x6c, 0x6c, - 0x6f, 0x77, 0x22, 0x31, 0x0a, 0x19, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x77, 0x61, 0x70, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x14, 0x0a, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, - 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x32, 0x9a, - 0x09, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x53, 0x77, 0x61, 0x70, 0x12, 0x3b, 0x0a, 0x07, 0x53, - 0x77, 0x61, 0x70, 0x4f, 0x75, 0x74, 0x12, 0x18, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, - 0x70, 0x2e, 0x53, 0x77, 0x61, 0x70, 0x4f, 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x16, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x77, 0x61, 0x70, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x06, 0x53, 0x77, 0x61, 0x70, - 0x49, 0x6e, 0x12, 0x17, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x77, - 0x61, 0x70, 0x49, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x65, + 0x2b, 0x0a, 0x07, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x11, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x72, 0x65, 0x6d, + 0x69, 0x75, 0x6d, 0x52, 0x07, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x22, 0x98, 0x01, 0x0a, + 0x13, 0x50, 0x65, 0x65, 0x72, 0x53, 0x77, 0x61, 0x70, 0x50, 0x65, 0x65, 0x72, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x62, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x72, 0x65, 0x6d, 0x6f, + 0x74, 0x65, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x0d, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x06, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x22, 0x77, 0x0a, 0x09, 0x53, 0x77, 0x61, 0x70, 0x53, + 0x74, 0x61, 0x74, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x77, 0x61, 0x70, 0x73, 0x5f, 0x6f, 0x75, + 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x73, 0x77, 0x61, 0x70, 0x73, 0x4f, 0x75, + 0x74, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x77, 0x61, 0x70, 0x73, 0x5f, 0x69, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x07, 0x73, 0x77, 0x61, 0x70, 0x73, 0x49, 0x6e, 0x12, 0x19, 0x0a, 0x08, + 0x73, 0x61, 0x74, 0x73, 0x5f, 0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, + 0x73, 0x61, 0x74, 0x73, 0x4f, 0x75, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x73, 0x61, 0x74, 0x73, 0x5f, + 0x69, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x73, 0x61, 0x74, 0x73, 0x49, 0x6e, + 0x22, 0xd8, 0x02, 0x0a, 0x06, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x30, 0x0a, 0x14, 0x72, + 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x5f, 0x6f, 0x6e, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x6d, + 0x73, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x12, 0x72, 0x65, 0x73, 0x65, 0x72, + 0x76, 0x65, 0x4f, 0x6e, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x4d, 0x73, 0x61, 0x74, 0x12, 0x2f, 0x0a, + 0x14, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x5f, 0x6d, 0x73, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x6d, 0x69, 0x6e, + 0x53, 0x77, 0x61, 0x70, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x4d, 0x73, 0x61, 0x74, 0x12, 0x28, + 0x0a, 0x10, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, + 0x41, 0x6c, 0x6c, 0x50, 0x65, 0x65, 0x72, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x61, 0x6c, 0x6c, 0x6f, + 0x77, 0x5f, 0x6e, 0x65, 0x77, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x0d, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x4e, 0x65, 0x77, 0x53, 0x77, 0x61, 0x70, 0x73, + 0x12, 0x2b, 0x0a, 0x11, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x64, 0x5f, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x10, 0x61, 0x6c, 0x6c, + 0x6f, 0x77, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x64, 0x50, 0x65, 0x65, 0x72, 0x73, 0x12, 0x30, 0x0a, + 0x14, 0x73, 0x75, 0x73, 0x70, 0x69, 0x63, 0x69, 0x6f, 0x75, 0x73, 0x5f, 0x70, 0x65, 0x65, 0x72, + 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x12, 0x73, 0x75, 0x73, + 0x70, 0x69, 0x63, 0x69, 0x6f, 0x75, 0x73, 0x50, 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, + 0x3a, 0x0a, 0x0f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, + 0x75, 0x6d, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, + 0x77, 0x61, 0x70, 0x2e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x0e, 0x64, 0x65, 0x66, + 0x61, 0x75, 0x6c, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x22, 0x30, 0x0a, 0x18, 0x41, + 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x22, 0x31, 0x0a, + 0x19, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x6c, + 0x6c, 0x6f, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, + 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x32, 0x9a, 0x09, 0x0a, 0x08, 0x50, 0x65, + 0x65, 0x72, 0x53, 0x77, 0x61, 0x70, 0x12, 0x3b, 0x0a, 0x07, 0x53, 0x77, 0x61, 0x70, 0x4f, 0x75, + 0x74, 0x12, 0x18, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x77, 0x61, + 0x70, 0x4f, 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x12, 0x18, - 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, - 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, - 0x77, 0x61, 0x70, 0x2e, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x44, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, 0x73, 0x12, 0x1a, 0x2e, - 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, - 0x70, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, - 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x65, - 0x65, 0x72, 0x73, 0x12, 0x1a, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, - 0x69, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, - 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x12, - 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x77, 0x61, - 0x70, 0x73, 0x12, 0x23, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, + 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x06, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x12, 0x17, 0x2e, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, + 0x70, 0x2e, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, + 0x0a, 0x07, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x12, 0x18, 0x2e, 0x70, 0x65, 0x65, 0x72, + 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, + 0x77, 0x61, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x09, 0x4c, + 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, 0x73, 0x12, 0x1a, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, + 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x44, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x73, 0x12, 0x1a, + 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x65, + 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x77, 0x61, 0x70, 0x73, 0x12, 0x23, 0x2e, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x77, 0x61, 0x70, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x77, 0x61, 0x70, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, - 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, - 0x53, 0x77, 0x61, 0x70, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4a, 0x0a, - 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x53, 0x77, 0x61, 0x70, 0x73, - 0x12, 0x1a, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x53, 0x77, 0x61, 0x70, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, - 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x11, 0x41, 0x6c, 0x6c, - 0x6f, 0x77, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x12, 0x22, - 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x53, - 0x77, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, - 0x6c, 0x69, 0x63, 0x79, 0x12, 0x47, 0x0a, 0x10, 0x52, 0x65, 0x6c, 0x6f, 0x61, 0x64, 0x50, 0x6f, - 0x6c, 0x69, 0x63, 0x79, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, - 0x77, 0x61, 0x70, 0x2e, 0x52, 0x65, 0x6c, 0x6f, 0x61, 0x64, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, - 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, - 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x35, 0x0a, - 0x07, 0x41, 0x64, 0x64, 0x50, 0x65, 0x65, 0x72, 0x12, 0x18, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, - 0x77, 0x61, 0x70, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, - 0x6c, 0x69, 0x63, 0x79, 0x12, 0x3b, 0x0a, 0x0a, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x50, 0x65, - 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x52, 0x65, - 0x6d, 0x6f, 0x76, 0x65, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, - 0x79, 0x12, 0x38, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x53, 0x75, 0x73, 0x50, 0x65, 0x65, 0x72, 0x12, - 0x18, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x65, - 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, - 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x3e, 0x0a, 0x0d, 0x52, - 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x75, 0x73, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x70, - 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x50, 0x65, - 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, - 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x4d, 0x0a, 0x10, 0x4c, - 0x69, 0x71, 0x75, 0x69, 0x64, 0x47, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, - 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x64, - 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, - 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x10, 0x4c, 0x69, - 0x71, 0x75, 0x69, 0x64, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1b, - 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x65, - 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x13, 0x4c, 0x69, 0x71, - 0x75, 0x69, 0x64, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x6f, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x12, 0x1e, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x65, 0x6e, 0x64, - 0x54, 0x6f, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1f, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x65, 0x6e, 0x64, - 0x54, 0x6f, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x28, 0x0a, 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x0f, 0x2e, 0x70, 0x65, 0x65, 0x72, - 0x73, 0x77, 0x61, 0x70, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0f, 0x2e, 0x70, 0x65, 0x65, - 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x31, 0x5a, 0x2f, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, - 0x74, 0x73, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, - 0x61, 0x70, 0x2f, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x72, 0x70, 0x63, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4a, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, + 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x53, 0x77, 0x61, 0x70, 0x73, 0x12, 0x1a, 0x2e, 0x70, 0x65, + 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, + 0x61, 0x70, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x77, 0x61, 0x70, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x11, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x77, 0x61, + 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x12, 0x22, 0x2e, 0x70, 0x65, 0x65, 0x72, + 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x77, 0x61, 0x70, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, + 0x47, 0x0a, 0x10, 0x52, 0x65, 0x6c, 0x6f, 0x61, 0x64, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x46, + 0x69, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x52, + 0x65, 0x6c, 0x6f, 0x61, 0x64, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x46, 0x69, 0x6c, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, + 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x35, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x50, + 0x65, 0x65, 0x72, 0x12, 0x18, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, + 0x64, 0x64, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, + 0x3b, 0x0a, 0x0a, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1b, 0x2e, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x50, + 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x38, 0x0a, 0x0a, + 0x41, 0x64, 0x64, 0x53, 0x75, 0x73, 0x50, 0x65, 0x65, 0x72, 0x12, 0x18, 0x2e, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, + 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x3e, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, + 0x53, 0x75, 0x73, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, + 0x61, 0x70, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, + 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x4d, 0x0a, 0x10, 0x4c, 0x69, 0x71, 0x75, 0x69, 0x64, + 0x47, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1b, 0x2e, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, + 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x10, 0x4c, 0x69, 0x71, 0x75, 0x69, 0x64, 0x47, + 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x2e, 0x70, 0x65, 0x65, 0x72, + 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, + 0x70, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x13, 0x4c, 0x69, 0x71, 0x75, 0x69, 0x64, 0x53, 0x65, + 0x6e, 0x64, 0x54, 0x6f, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1e, 0x2e, 0x70, 0x65, + 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x6f, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x65, + 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x6f, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x04, + 0x53, 0x74, 0x6f, 0x70, 0x12, 0x0f, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0f, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x70, 0x72, 0x6f, + 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2f, 0x70, 0x65, + 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -2170,10 +2192,10 @@ var file_peerswaprpc_peerswaprpc_proto_goTypes = []interface{}{ (*RequestSwapList)(nil), // 21: peerswap.RequestSwapList (*RequestedSwap)(nil), // 22: peerswap.RequestedSwap (*PrettyPrintSwap)(nil), // 23: peerswap.PrettyPrintSwap - (*PeerSwapPeer)(nil), // 24: peerswap.PeerSwapPeer - (*PeerSwapPeerChannel)(nil), // 25: peerswap.PeerSwapPeerChannel - (*SwapStats)(nil), // 26: peerswap.SwapStats - (*PeerSwapNodes)(nil), // 27: peerswap.PeerSwapNodes + (*Premium)(nil), // 24: peerswap.Premium + (*PeerSwapPeer)(nil), // 25: peerswap.PeerSwapPeer + (*PeerSwapPeerChannel)(nil), // 26: peerswap.PeerSwapPeerChannel + (*SwapStats)(nil), // 27: peerswap.SwapStats (*Policy)(nil), // 28: peerswap.Policy (*AllowSwapRequestsRequest)(nil), // 29: peerswap.AllowSwapRequestsRequest (*AllowSwapRequestsResponse)(nil), // 30: peerswap.AllowSwapRequestsResponse @@ -2184,53 +2206,55 @@ var file_peerswaprpc_peerswaprpc_proto_depIdxs = []int32{ 23, // 0: peerswap.SwapOutResponse.swap:type_name -> peerswap.PrettyPrintSwap 23, // 1: peerswap.SwapResponse.swap:type_name -> peerswap.PrettyPrintSwap 23, // 2: peerswap.ListSwapsResponse.swaps:type_name -> peerswap.PrettyPrintSwap - 24, // 3: peerswap.ListPeersResponse.peers:type_name -> peerswap.PeerSwapPeer + 25, // 3: peerswap.ListPeersResponse.peers:type_name -> peerswap.PeerSwapPeer 32, // 4: peerswap.ListRequestedSwapsResponse.requested_swaps:type_name -> peerswap.ListRequestedSwapsResponse.RequestedSwapsEntry 22, // 5: peerswap.RequestSwapList.requested_swaps:type_name -> peerswap.RequestedSwap 0, // 6: peerswap.RequestedSwap.swap_type:type_name -> peerswap.RequestedSwap.SwapType - 25, // 7: peerswap.PeerSwapPeer.channels:type_name -> peerswap.PeerSwapPeerChannel - 26, // 8: peerswap.PeerSwapPeer.as_sender:type_name -> peerswap.SwapStats - 26, // 9: peerswap.PeerSwapPeer.as_receiver:type_name -> peerswap.SwapStats - 21, // 10: peerswap.ListRequestedSwapsResponse.RequestedSwapsEntry.value:type_name -> peerswap.RequestSwapList - 7, // 11: peerswap.PeerSwap.SwapOut:input_type -> peerswap.SwapOutRequest - 9, // 12: peerswap.PeerSwap.SwapIn:input_type -> peerswap.SwapInRequest - 11, // 13: peerswap.PeerSwap.GetSwap:input_type -> peerswap.GetSwapRequest - 12, // 14: peerswap.PeerSwap.ListSwaps:input_type -> peerswap.ListSwapsRequest - 14, // 15: peerswap.PeerSwap.ListPeers:input_type -> peerswap.ListPeersRequest - 19, // 16: peerswap.PeerSwap.ListRequestedSwaps:input_type -> peerswap.ListRequestedSwapsRequest - 12, // 17: peerswap.PeerSwap.ListActiveSwaps:input_type -> peerswap.ListSwapsRequest - 29, // 18: peerswap.PeerSwap.AllowSwapRequests:input_type -> peerswap.AllowSwapRequestsRequest - 16, // 19: peerswap.PeerSwap.ReloadPolicyFile:input_type -> peerswap.ReloadPolicyFileRequest - 17, // 20: peerswap.PeerSwap.AddPeer:input_type -> peerswap.AddPeerRequest - 18, // 21: peerswap.PeerSwap.RemovePeer:input_type -> peerswap.RemovePeerRequest - 17, // 22: peerswap.PeerSwap.AddSusPeer:input_type -> peerswap.AddPeerRequest - 18, // 23: peerswap.PeerSwap.RemoveSusPeer:input_type -> peerswap.RemovePeerRequest - 1, // 24: peerswap.PeerSwap.LiquidGetAddress:input_type -> peerswap.GetAddressRequest - 3, // 25: peerswap.PeerSwap.LiquidGetBalance:input_type -> peerswap.GetBalanceRequest - 5, // 26: peerswap.PeerSwap.LiquidSendToAddress:input_type -> peerswap.SendToAddressRequest - 31, // 27: peerswap.PeerSwap.Stop:input_type -> peerswap.Empty - 10, // 28: peerswap.PeerSwap.SwapOut:output_type -> peerswap.SwapResponse - 10, // 29: peerswap.PeerSwap.SwapIn:output_type -> peerswap.SwapResponse - 10, // 30: peerswap.PeerSwap.GetSwap:output_type -> peerswap.SwapResponse - 13, // 31: peerswap.PeerSwap.ListSwaps:output_type -> peerswap.ListSwapsResponse - 15, // 32: peerswap.PeerSwap.ListPeers:output_type -> peerswap.ListPeersResponse - 20, // 33: peerswap.PeerSwap.ListRequestedSwaps:output_type -> peerswap.ListRequestedSwapsResponse - 13, // 34: peerswap.PeerSwap.ListActiveSwaps:output_type -> peerswap.ListSwapsResponse - 28, // 35: peerswap.PeerSwap.AllowSwapRequests:output_type -> peerswap.Policy - 28, // 36: peerswap.PeerSwap.ReloadPolicyFile:output_type -> peerswap.Policy - 28, // 37: peerswap.PeerSwap.AddPeer:output_type -> peerswap.Policy - 28, // 38: peerswap.PeerSwap.RemovePeer:output_type -> peerswap.Policy - 28, // 39: peerswap.PeerSwap.AddSusPeer:output_type -> peerswap.Policy - 28, // 40: peerswap.PeerSwap.RemoveSusPeer:output_type -> peerswap.Policy - 2, // 41: peerswap.PeerSwap.LiquidGetAddress:output_type -> peerswap.GetAddressResponse - 4, // 42: peerswap.PeerSwap.LiquidGetBalance:output_type -> peerswap.GetBalanceResponse - 6, // 43: peerswap.PeerSwap.LiquidSendToAddress:output_type -> peerswap.SendToAddressResponse - 31, // 44: peerswap.PeerSwap.Stop:output_type -> peerswap.Empty - 28, // [28:45] is the sub-list for method output_type - 11, // [11:28] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name + 26, // 7: peerswap.PeerSwapPeer.channels:type_name -> peerswap.PeerSwapPeerChannel + 27, // 8: peerswap.PeerSwapPeer.as_sender:type_name -> peerswap.SwapStats + 27, // 9: peerswap.PeerSwapPeer.as_receiver:type_name -> peerswap.SwapStats + 24, // 10: peerswap.PeerSwapPeer.premium:type_name -> peerswap.Premium + 24, // 11: peerswap.Policy.default_premium:type_name -> peerswap.Premium + 21, // 12: peerswap.ListRequestedSwapsResponse.RequestedSwapsEntry.value:type_name -> peerswap.RequestSwapList + 7, // 13: peerswap.PeerSwap.SwapOut:input_type -> peerswap.SwapOutRequest + 9, // 14: peerswap.PeerSwap.SwapIn:input_type -> peerswap.SwapInRequest + 11, // 15: peerswap.PeerSwap.GetSwap:input_type -> peerswap.GetSwapRequest + 12, // 16: peerswap.PeerSwap.ListSwaps:input_type -> peerswap.ListSwapsRequest + 14, // 17: peerswap.PeerSwap.ListPeers:input_type -> peerswap.ListPeersRequest + 19, // 18: peerswap.PeerSwap.ListRequestedSwaps:input_type -> peerswap.ListRequestedSwapsRequest + 12, // 19: peerswap.PeerSwap.ListActiveSwaps:input_type -> peerswap.ListSwapsRequest + 29, // 20: peerswap.PeerSwap.AllowSwapRequests:input_type -> peerswap.AllowSwapRequestsRequest + 16, // 21: peerswap.PeerSwap.ReloadPolicyFile:input_type -> peerswap.ReloadPolicyFileRequest + 17, // 22: peerswap.PeerSwap.AddPeer:input_type -> peerswap.AddPeerRequest + 18, // 23: peerswap.PeerSwap.RemovePeer:input_type -> peerswap.RemovePeerRequest + 17, // 24: peerswap.PeerSwap.AddSusPeer:input_type -> peerswap.AddPeerRequest + 18, // 25: peerswap.PeerSwap.RemoveSusPeer:input_type -> peerswap.RemovePeerRequest + 1, // 26: peerswap.PeerSwap.LiquidGetAddress:input_type -> peerswap.GetAddressRequest + 3, // 27: peerswap.PeerSwap.LiquidGetBalance:input_type -> peerswap.GetBalanceRequest + 5, // 28: peerswap.PeerSwap.LiquidSendToAddress:input_type -> peerswap.SendToAddressRequest + 31, // 29: peerswap.PeerSwap.Stop:input_type -> peerswap.Empty + 10, // 30: peerswap.PeerSwap.SwapOut:output_type -> peerswap.SwapResponse + 10, // 31: peerswap.PeerSwap.SwapIn:output_type -> peerswap.SwapResponse + 10, // 32: peerswap.PeerSwap.GetSwap:output_type -> peerswap.SwapResponse + 13, // 33: peerswap.PeerSwap.ListSwaps:output_type -> peerswap.ListSwapsResponse + 15, // 34: peerswap.PeerSwap.ListPeers:output_type -> peerswap.ListPeersResponse + 20, // 35: peerswap.PeerSwap.ListRequestedSwaps:output_type -> peerswap.ListRequestedSwapsResponse + 13, // 36: peerswap.PeerSwap.ListActiveSwaps:output_type -> peerswap.ListSwapsResponse + 28, // 37: peerswap.PeerSwap.AllowSwapRequests:output_type -> peerswap.Policy + 28, // 38: peerswap.PeerSwap.ReloadPolicyFile:output_type -> peerswap.Policy + 28, // 39: peerswap.PeerSwap.AddPeer:output_type -> peerswap.Policy + 28, // 40: peerswap.PeerSwap.RemovePeer:output_type -> peerswap.Policy + 28, // 41: peerswap.PeerSwap.AddSusPeer:output_type -> peerswap.Policy + 28, // 42: peerswap.PeerSwap.RemoveSusPeer:output_type -> peerswap.Policy + 2, // 43: peerswap.PeerSwap.LiquidGetAddress:output_type -> peerswap.GetAddressResponse + 4, // 44: peerswap.PeerSwap.LiquidGetBalance:output_type -> peerswap.GetBalanceResponse + 6, // 45: peerswap.PeerSwap.LiquidSendToAddress:output_type -> peerswap.SendToAddressResponse + 31, // 46: peerswap.PeerSwap.Stop:output_type -> peerswap.Empty + 30, // [30:47] is the sub-list for method output_type + 13, // [13:30] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_peerswaprpc_peerswaprpc_proto_init() } @@ -2516,7 +2540,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeerSwapPeer); i { + switch v := v.(*Premium); i { case 0: return &v.state case 1: @@ -2528,7 +2552,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeerSwapPeerChannel); i { + switch v := v.(*PeerSwapPeer); i { case 0: return &v.state case 1: @@ -2540,7 +2564,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SwapStats); i { + switch v := v.(*PeerSwapPeerChannel); i { case 0: return &v.state case 1: @@ -2552,7 +2576,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeerSwapNodes); i { + switch v := v.(*SwapStats); i { case 0: return &v.state case 1: diff --git a/peerswaprpc/peerswaprpc.proto b/peerswaprpc/peerswaprpc.proto index 3e072e41..e666f8b8 100644 --- a/peerswaprpc/peerswaprpc.proto +++ b/peerswaprpc/peerswaprpc.proto @@ -142,6 +142,18 @@ message PrettyPrintSwap { int64 premium_amount = 15; } +// Premium message represents the premium rates. +message Premium { + // Premium rate for BTC swap-in (in PPM) + int64 btc_swap_in_premium_rate_ppm = 1; + // Premium rate for BTC swap-out (in PPM) + int64 btc_swap_out_premium_rate_ppm = 2; + // Premium rate for LBTC swap-in (in PPM) + int64 lbtc_swap_in_premium_rate_ppm = 3; + // Premium rate for LBTC swap-out (in PPM) + int64 lbtc_swap_out_premium_rate_ppm = 4; +} + message PeerSwapPeer { string node_id = 1; bool swaps_allowed = 2; @@ -150,8 +162,7 @@ message PeerSwapPeer { SwapStats as_sender = 5; SwapStats as_receiver = 6; uint64 paid_fee = 7; - int64 swap_in_premium_rate_ppm = 8; - int64 swap_out_premium_rate_ppm = 9; + Premium premium = 8; } message PeerSwapPeerChannel { @@ -168,9 +179,7 @@ message SwapStats { uint64 sats_in = 4; } -message PeerSwapNodes { - string node_id = 1; -} + message Policy { uint64 reserve_onchain_msat = 1; @@ -179,8 +188,9 @@ message Policy { bool allow_new_swaps = 4; repeated string allowlisted_peers = 5; repeated string suspicious_peer_list = 6; - int64 swap_in_premium_rate_ppm = 7; - int64 swap_out_premium_rate_ppm = 8; + // Displays the default premium rates. + // The premium rates for each peer are included in PeerSwapPeer. + Premium default_premium = 7; } message AllowSwapRequestsRequest { diff --git a/peerswaprpc/peerswaprpc.swagger.json b/peerswaprpc/peerswaprpc.swagger.json index 6b537b4e..f65ed2e0 100644 --- a/peerswaprpc/peerswaprpc.swagger.json +++ b/peerswaprpc/peerswaprpc.swagger.json @@ -600,13 +600,8 @@ "type": "string", "format": "uint64" }, - "swapInPremiumRatePpm": { - "type": "string", - "format": "int64" - }, - "swapOutPremiumRatePpm": { - "type": "string", - "format": "int64" + "premium": { + "$ref": "#/definitions/peerswapPremium" } } }, @@ -659,15 +654,37 @@ "type": "string" } }, - "swapInPremiumRatePpm": { + "defaultPremium": { + "$ref": "#/definitions/peerswapPremium", + "description": "Displays the default premium rates.\r\nThe premium rates for each peer are included in PeerSwapPeer." + } + } + }, + "peerswapPremium": { + "type": "object", + "properties": { + "btcSwapInPremiumRatePpm": { + "type": "string", + "format": "int64", + "title": "Premium rate for BTC swap-in (in PPM)" + }, + "btcSwapOutPremiumRatePpm": { "type": "string", - "format": "int64" + "format": "int64", + "title": "Premium rate for BTC swap-out (in PPM)" }, - "swapOutPremiumRatePpm": { + "lbtcSwapInPremiumRatePpm": { "type": "string", - "format": "int64" + "format": "int64", + "title": "Premium rate for LBTC swap-in (in PPM)" + }, + "lbtcSwapOutPremiumRatePpm": { + "type": "string", + "format": "int64", + "title": "Premium rate for LBTC swap-out (in PPM)" } - } + }, + "description": "Premium message represents the premium rates." }, "peerswapPrettyPrintSwap": { "type": "object", diff --git a/peerswaprpc/server.go b/peerswaprpc/server.go index acd0ec8c..3ca50b91 100644 --- a/peerswaprpc/server.go +++ b/peerswaprpc/server.go @@ -358,12 +358,10 @@ func (p *PeerswapServer) ListPeers(ctx context.Context, request *ListPeersReques } peerSwapPeers = append(peerSwapPeers, &PeerSwapPeer{ - NodeId: v.PubKey, - SwapsAllowed: poll.PeerAllowed, - SwapInPremiumRatePpm: poll.SwapInPremiumRatePPM, - SwapOutPremiumRatePpm: poll.SwapOutPremiumRatePPM, - SupportedAssets: poll.Assets, - Channels: getPeerSwapChannels(v.PubKey, channelRes.Channels), + NodeId: v.PubKey, + SwapsAllowed: poll.PeerAllowed, + SupportedAssets: poll.Assets, + Channels: getPeerSwapChannels(v.PubKey, channelRes.Channels), AsSender: &SwapStats{ SwapsOut: SenderSwapsOut, SwapsIn: SenderSwapsIn, @@ -377,6 +375,12 @@ func (p *PeerswapServer) ListPeers(ctx context.Context, request *ListPeersReques SatsIn: ReceiverSatsIn, }, PaidFee: paidFees, + Premium: &Premium{ + BtcSwapInPremiumRatePpm: poll.BTCSwapInPremiumRatePPM, + BtcSwapOutPremiumRatePpm: poll.BTCSwapOutPremiumRatePPM, + LbtcSwapInPremiumRatePpm: poll.LBTCSwapInPremiumRatePPM, + LbtcSwapOutPremiumRatePpm: poll.LBTCSwapOutPremiumRatePPM, + }, }) } diff --git a/policy/policy.go b/policy/policy.go index f480ddbb..8cf59e35 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -25,10 +25,6 @@ const ( // to perform a swap. We need this lower boundary as it is uneconomical to // swap small amounts. defaultMinSwapAmountMsat uint64 = 100000000 - // defaultSwapInPremiumRatePPM is the default of the swap in premium rate in ppm. - defaultSwapInPremiumRatePPM int64 = 10000 - // defaultSwapOutPremiumRatePPM is the default of the swap out premium rate in ppm. - defaultSwapOutPremiumRatePPM int64 = 10000 ) // Global Mutex @@ -87,9 +83,8 @@ type Policy struct { // AllowNewSwaps can be used to disallow any new swaps. This can be useful // when we want to upgrade the node and do not want to allow for any new // swap request from the peer or the node operator. - AllowNewSwaps bool `json:"allow_new_swaps" long:"allow_new_swaps" description:"If set to false, disables all swap requests, defaults to true."` - SwapInPremiumRatePPM int64 `json:"swap_in_premium_rate_ppm" long:"swap_in_premium_rate_ppm" description:"The premium rate for swaps in."` - SwapOutPremiumRatePPM int64 `json:"swap_out_premium_rate_ppm" long:"swap_out_premium_rate_ppm" description:"The premium rate for swaps out."` + AllowNewSwaps bool `json:"allow_new_swaps" long:"allow_new_swaps" description:"If set to false, disables all swap requests, defaults to true."` + premium *premium } func (p *Policy) String() string { @@ -115,14 +110,13 @@ func (p *Policy) Get() Policy { defer mu.Unlock() return Policy{ - ReserveOnchainMsat: p.ReserveOnchainMsat, - PeerAllowlist: p.PeerAllowlist, - SuspiciousPeerList: p.SuspiciousPeerList, - AcceptAllPeers: p.AcceptAllPeers, - MinSwapAmountMsat: p.MinSwapAmountMsat, - AllowNewSwaps: p.AllowNewSwaps, - SwapInPremiumRatePPM: p.SwapInPremiumRatePPM, - SwapOutPremiumRatePPM: p.SwapOutPremiumRatePPM, + ReserveOnchainMsat: p.ReserveOnchainMsat, + PeerAllowlist: p.PeerAllowlist, + SuspiciousPeerList: p.SuspiciousPeerList, + AcceptAllPeers: p.AcceptAllPeers, + MinSwapAmountMsat: p.MinSwapAmountMsat, + AllowNewSwaps: p.AllowNewSwaps, + premium: p.premium, } } @@ -143,22 +137,6 @@ func (p *Policy) GetMinSwapAmountMsat() uint64 { return p.MinSwapAmountMsat } -// GetSwapInPremiumRatePPM returns the minimum swap amount in msat that is needed -// to perform a swap. -func (p *Policy) GetSwapInPremiumRatePPM() int64 { - mu.Lock() - defer mu.Unlock() - return p.SwapInPremiumRatePPM -} - -// GetSwapInPremiumRatePPM returns the minimum swap amount in msat that is needed -// to perform a swap. -func (p *Policy) GetSwapOutPremiumRatePPM() int64 { - mu.Lock() - defer mu.Unlock() - return p.SwapOutPremiumRatePPM -} - // NewSwapsAllowed returns the boolean value of AllowNewSwaps. func (p *Policy) NewSwapsAllowed() bool { return p.AllowNewSwaps @@ -315,6 +293,18 @@ func (p *Policy) AddToSuspiciousPeerList(pubkey string) error { return p.ReloadFile() } +func (p *Policy) GetPremiumRate(peerID string, k PremiumRateKind) int64 { + mu.Lock() + defer mu.Unlock() + return p.premium.GetRate(peerID, k).Value() +} + +func (p *Policy) ComputePremium(peerID string, k PremiumRateKind, amtSat uint64) int64 { + mu.Lock() + defer mu.Unlock() + return p.premium.GetRate(peerID, k).Compute(amtSat) +} + func addLineToFile(filePath, line string) error { file, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0660) if err != nil { @@ -440,14 +430,13 @@ func (p *Policy) reload(r io.Reader) error { // the default values. func DefaultPolicy() *Policy { return &Policy{ - ReserveOnchainMsat: defaultReserveOnchainMsat, - PeerAllowlist: defaultPeerAllowlist, - SuspiciousPeerList: defaultSuspiciousPeerList, - AcceptAllPeers: defaultAcceptAllPeers, - MinSwapAmountMsat: defaultMinSwapAmountMsat, - AllowNewSwaps: defaultAllowNewSwaps, - SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM, - SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM, + ReserveOnchainMsat: defaultReserveOnchainMsat, + PeerAllowlist: defaultPeerAllowlist, + SuspiciousPeerList: defaultSuspiciousPeerList, + AcceptAllPeers: defaultAcceptAllPeers, + MinSwapAmountMsat: defaultMinSwapAmountMsat, + AllowNewSwaps: defaultAllowNewSwaps, + premium: defaultPreium(), } } @@ -480,7 +469,11 @@ func CreateFromFile(path string) (*Policy, error) { if err != nil { return nil, err } - + p, err := newPremiumConfig(file) + if err != nil { + return nil, fmt.Errorf("could not create premium config: %v", err) + } + policy.premium = p policy.path = policyPath return policy, nil } diff --git a/policy/policy_test.go b/policy/policy_test.go index 727494c7..61649694 100644 --- a/policy/policy_test.go +++ b/policy/policy_test.go @@ -25,14 +25,13 @@ func Test_Create(t *testing.T) { policy, err := create(strings.NewReader("")) assert.NoError(t, err) assert.EqualValues(t, &Policy{ - ReserveOnchainMsat: defaultReserveOnchainMsat, - PeerAllowlist: defaultPeerAllowlist, - SuspiciousPeerList: defaultSuspiciousPeerList, - AcceptAllPeers: defaultAcceptAllPeers, - MinSwapAmountMsat: defaultMinSwapAmountMsat, - AllowNewSwaps: defaultAllowNewSwaps, - SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM, - SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM, + ReserveOnchainMsat: defaultReserveOnchainMsat, + PeerAllowlist: defaultPeerAllowlist, + SuspiciousPeerList: defaultSuspiciousPeerList, + AcceptAllPeers: defaultAcceptAllPeers, + MinSwapAmountMsat: defaultMinSwapAmountMsat, + AllowNewSwaps: defaultAllowNewSwaps, + premium: defaultPreium(), }, policy) peer1 := "123" @@ -59,14 +58,13 @@ func Test_Create(t *testing.T) { policy2, err := create(strings.NewReader(conf)) assert.NoError(t, err) assert.EqualValues(t, &Policy{ - ReserveOnchainMsat: defaultReserveOnchainMsat, - PeerAllowlist: []string{peer1, peer2}, - SuspiciousPeerList: []string{peer1, peer2}, - AcceptAllPeers: accept, - MinSwapAmountMsat: defaultMinSwapAmountMsat, - AllowNewSwaps: defaultAllowNewSwaps, - SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM, - SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM, + ReserveOnchainMsat: defaultReserveOnchainMsat, + PeerAllowlist: []string{peer1, peer2}, + SuspiciousPeerList: []string{peer1, peer2}, + AcceptAllPeers: accept, + MinSwapAmountMsat: defaultMinSwapAmountMsat, + AllowNewSwaps: defaultAllowNewSwaps, + premium: defaultPreium(), }, policy2) } @@ -84,14 +82,13 @@ func Test_Reload(t *testing.T) { policy, err := create(strings.NewReader(conf)) assert.NoError(t, err) assert.EqualValues(t, &Policy{ - ReserveOnchainMsat: defaultReserveOnchainMsat, - PeerAllowlist: []string{peer1, peer2}, - SuspiciousPeerList: defaultSuspiciousPeerList, - AcceptAllPeers: accept, - MinSwapAmountMsat: defaultMinSwapAmountMsat, - AllowNewSwaps: defaultAllowNewSwaps, - SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM, - SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM, + ReserveOnchainMsat: defaultReserveOnchainMsat, + PeerAllowlist: []string{peer1, peer2}, + SuspiciousPeerList: defaultSuspiciousPeerList, + AcceptAllPeers: accept, + MinSwapAmountMsat: defaultMinSwapAmountMsat, + AllowNewSwaps: defaultAllowNewSwaps, + premium: defaultPreium(), }, policy) newPeer := "new_peer" @@ -100,14 +97,13 @@ func Test_Reload(t *testing.T) { err = policy.reload(strings.NewReader(newConf)) assert.NoError(t, err) assert.EqualValues(t, &Policy{ - ReserveOnchainMsat: defaultReserveOnchainMsat, - PeerAllowlist: []string{newPeer}, - SuspiciousPeerList: []string{newPeer}, - AcceptAllPeers: defaultAcceptAllPeers, - MinSwapAmountMsat: defaultMinSwapAmountMsat, - AllowNewSwaps: defaultAllowNewSwaps, - SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM, - SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM, + ReserveOnchainMsat: defaultReserveOnchainMsat, + PeerAllowlist: []string{newPeer}, + SuspiciousPeerList: []string{newPeer}, + AcceptAllPeers: defaultAcceptAllPeers, + MinSwapAmountMsat: defaultMinSwapAmountMsat, + AllowNewSwaps: defaultAllowNewSwaps, + premium: defaultPreium(), }, policy) } @@ -125,14 +121,13 @@ func Test_Reload_NoOverrideOnError(t *testing.T) { policy, err := create(strings.NewReader(conf)) assert.NoError(t, err) assert.EqualValues(t, &Policy{ - ReserveOnchainMsat: defaultReserveOnchainMsat, - PeerAllowlist: []string{peer1, peer2}, - SuspiciousPeerList: defaultSuspiciousPeerList, - AcceptAllPeers: accept, - MinSwapAmountMsat: defaultMinSwapAmountMsat, - AllowNewSwaps: defaultAllowNewSwaps, - SwapInPremiumRatePPM: defaultSwapInPremiumRatePPM, - SwapOutPremiumRatePPM: defaultSwapOutPremiumRatePPM, + ReserveOnchainMsat: defaultReserveOnchainMsat, + PeerAllowlist: []string{peer1, peer2}, + SuspiciousPeerList: defaultSuspiciousPeerList, + AcceptAllPeers: accept, + MinSwapAmountMsat: defaultMinSwapAmountMsat, + AllowNewSwaps: defaultAllowNewSwaps, + premium: defaultPreium(), }, policy) // copy policy diff --git a/policy/premium.go b/policy/premium.go new file mode 100644 index 00000000..f9bdbc51 --- /dev/null +++ b/policy/premium.go @@ -0,0 +1,165 @@ +package policy + +import ( + "fmt" + "io" + "strings" + + "gopkg.in/ini.v1" +) + +const ( + // premiumRateParts is the total number of parts used to express fee rates. + premiumRateParts = 1e6 + // defaultSwapInPremiumRatePPM is the default of the swap in premium rate in ppm. + defaultSwapInPremiumRatePPM int64 = 10000 + // defaultSwapOutPremiumRatePPM is the default of the swap out premium rate in ppm. + defaultSwapOutPremiumRatePPM int64 = 10000 + basePremiumSectionKey = "base_premium_rate" + peersPremiumSectionKey = "peers_premium_rate" + premiumRatePPMKey = "premium_rate_ppm" + swapInPremiumRatePPMKey = "swap_in_" + premiumRatePPMKey + SwapOutPremiumRatePPMKey = "swap_out_" + premiumRatePPMKey + btcSwapInPremiumRatePPMKey = "btc_" + swapInPremiumRatePPMKey + btcSwapOutPremiumRatePPMKey = "btc_" + SwapOutPremiumRatePPMKey + lbtcSwapInPremiumRatePPMKey = "lbtc_" + swapInPremiumRatePPMKey + lbtcSwapOutPremiumRatePPMKey = "lbtc_" + SwapOutPremiumRatePPMKey +) + +type PremiumRateKind string + +const ( + BtcSwapIn PremiumRateKind = "btcSwapInPremiumRatePPM" + BtcSwapOut PremiumRateKind = "btcSwapOutPremiumRatePPM" + LbtcSwapIn PremiumRateKind = "lbtcSwapInPremiumRatePPM" + LbtcSwapOut PremiumRateKind = "lbtcSwapOutPremiumRatePPM" +) + +// PPM は百万分率を表す構造体です。 +type ppm struct { + ppmValue int64 // ppm値 + +} + +// NewPPM は新しいPPMを作成します。 +func NewPPM(value int64) *ppm { + return &ppm{ppmValue: value} +} + +// Value はppm値を返します。 +func (p *ppm) Value() int64 { + if p == nil { + return 0 + } + return p.ppmValue +} + +func (p *ppm) Compute(amtSat uint64) (sat int64) { + return int64(amtSat) * p.ppmValue / premiumRateParts +} + +type premiumRates struct { + // btcSwapInPremiumRatePPM はBTCのスワップインのプレミアムレートを表します。 + btcSwapInPremiumRatePPM *ppm + // btcSwapOutPremiumRatePPM はBTCのスワップアウトのプレミアムレートを表します。 + btcSwapOutPremiumRatePPM *ppm + // lbtcSwapInPremiumRatePPM はLBTCのスワップインのプレミアムレートを表します。 + lbtcSwapInPremiumRatePPM *ppm + // lbtcSwapOutPremiumRatePPM はLBTCのスワップアウトのプレミアムレートを表します。 + lbtcSwapOutPremiumRatePPM *ppm +} + +func (p *premiumRates) GetPremiumRate(k PremiumRateKind) *ppm { + switch k { + case BtcSwapIn: + return p.btcSwapInPremiumRatePPM + case BtcSwapOut: + return p.btcSwapOutPremiumRatePPM + case LbtcSwapIn: + return p.lbtcSwapInPremiumRatePPM + case LbtcSwapOut: + return p.lbtcSwapOutPremiumRatePPM + default: + return nil + } +} + +type premium struct { + baseRates *premiumRates + premiumByPeerIds map[string]*premiumRates +} + +func newPremiumConfig(r io.Reader) (*premium, error) { + f, err := ini.Load(r) + if err != nil { + return nil, fmt.Errorf("failed to load config: %w", err) + } + + premiumByPeerIds := map[string]*premiumRates{} + + for _, key := range f.Section(peersPremiumSectionKey).Keys() { + parts := strings.Split(key.Name(), ".") + if len(parts) != 2 { + return nil, fmt.Errorf("invalid value to set premium of peer: %s", key.Name()) + } + peerID := parts[0] + fieldName := parts[1] + if _, ok := premiumByPeerIds[peerID]; !ok { + premiumByPeerIds[peerID] = &premiumRates{} + } + switch fieldName { + case btcSwapInPremiumRatePPMKey: + premiumByPeerIds[peerID].btcSwapInPremiumRatePPM = NewPPM(key.MustInt64()) + case btcSwapOutPremiumRatePPMKey: + premiumByPeerIds[peerID].btcSwapOutPremiumRatePPM = NewPPM(key.MustInt64()) + case lbtcSwapInPremiumRatePPMKey: + premiumByPeerIds[peerID].lbtcSwapInPremiumRatePPM = NewPPM(key.MustInt64()) + case lbtcSwapOutPremiumRatePPMKey: + premiumByPeerIds[peerID].lbtcSwapOutPremiumRatePPM = NewPPM(key.MustInt64()) + default: + return nil, fmt.Errorf("invalid field name to set premium of peer: %s", fieldName) + } + } + return &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM( + f.Section(basePremiumSectionKey).Key(btcSwapInPremiumRatePPMKey).MustInt64(defaultSwapInPremiumRatePPM), // デフォルト値を0に設定 + ), + btcSwapOutPremiumRatePPM: NewPPM( + f.Section(basePremiumSectionKey).Key(btcSwapOutPremiumRatePPMKey).MustInt64(defaultSwapOutPremiumRatePPM), // デフォルト値を0に設定 + ), + lbtcSwapInPremiumRatePPM: NewPPM( + f.Section(basePremiumSectionKey).Key(lbtcSwapInPremiumRatePPMKey).MustInt64(defaultSwapInPremiumRatePPM), // デフォルト値を0に設定 + ), + lbtcSwapOutPremiumRatePPM: NewPPM( + f.Section(basePremiumSectionKey).Key(lbtcSwapOutPremiumRatePPMKey).MustInt64(defaultSwapOutPremiumRatePPM), // デフォルト値を0に設定 + ), + }, + premiumByPeerIds: premiumByPeerIds, + }, nil +} + +func (p *premium) GetRate(peerID string, k PremiumRateKind) *ppm { + if rates, ok := p.premiumByPeerIds[peerID]; ok { + if ppm := rates.GetPremiumRate(k); ppm != nil { + return ppm + } + } + return p.baseRates.GetPremiumRate(k) +} + +func (p *premium) compute(peerID string, k PremiumRateKind, amtSat uint64) int64 { + return p.GetRate(peerID, k).Compute(amtSat) +} + +func defaultPreium() *premium { + return &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM(defaultSwapInPremiumRatePPM), + btcSwapOutPremiumRatePPM: NewPPM(defaultSwapOutPremiumRatePPM), + lbtcSwapInPremiumRatePPM: NewPPM(defaultSwapInPremiumRatePPM), + lbtcSwapOutPremiumRatePPM: NewPPM(defaultSwapOutPremiumRatePPM), + }, + premiumByPeerIds: map[string]*premiumRates{}, + } +} diff --git a/policy/premium_test.go b/policy/premium_test.go new file mode 100644 index 00000000..aff0374c --- /dev/null +++ b/policy/premium_test.go @@ -0,0 +1,182 @@ +package policy + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_newPremiumConfig(t *testing.T) { + t.Parallel() + tests := map[string]struct { + iniFile string + want *premium + wantErr bool + }{ + + "ValidConfig": { + iniFile: ` +[base_premium_rate] +btc_swap_in_premium_rate_ppm=100 +[peers_premium_rate] +peer1.btc_swap_in_premium_rate_ppm=1000 +peer2.btc_swap_out_premium_rate_ppm=2000`, + want: &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM(100), + btcSwapOutPremiumRatePPM: NewPPM(10000), + lbtcSwapInPremiumRatePPM: NewPPM(10000), + lbtcSwapOutPremiumRatePPM: NewPPM(10000), + }, + premiumByPeerIds: map[string]*premiumRates{ + "peer1": { + btcSwapInPremiumRatePPM: NewPPM(1000), + }, + "peer2": { + btcSwapOutPremiumRatePPM: NewPPM(2000), + }, + }, + }, + wantErr: false, + }, + "InvalidFieldName": { + iniFile: ` +[peers_premium_rate] +peer1.InvalidField=1000 +`, + want: nil, + wantErr: true, + }, + "InvalidKeyFormat": { + iniFile: ` +[peers_premium_rate] +peer1BTCSwapInPremiumRatePPM=1000`, + + want: nil, + wantErr: true, + }, + "EmptyConfig": { + iniFile: ``, + want: &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM(10000), + btcSwapOutPremiumRatePPM: NewPPM(10000), + lbtcSwapInPremiumRatePPM: NewPPM(10000), + lbtcSwapOutPremiumRatePPM: NewPPM(10000), + }, + premiumByPeerIds: map[string]*premiumRates{}, + }, + wantErr: false, + }, + } + + for name, tt := range tests { + tt := tt + t.Run(name, func(t *testing.T) { + t.Parallel() + r := strings.NewReader(tt.iniFile) + got, err := newPremiumConfig(r) + if (err != nil) != tt.wantErr { + t.Errorf("newPremiumConfig() error = %v, wantErr %v", err, tt.wantErr) + return + } + assert.Equal(t, tt.want, got) + }) + } +} +func Test_premium_GetRate(t *testing.T) { + t.Parallel() + type args struct { + peerID string + k PremiumRateKind + } + tests := map[string]struct { + p *premium + args args + want *ppm + }{ + "GetRateForExistingPeer": { + p: &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM(100), + btcSwapOutPremiumRatePPM: NewPPM(200), + lbtcSwapInPremiumRatePPM: NewPPM(300), + lbtcSwapOutPremiumRatePPM: NewPPM(400), + }, + premiumByPeerIds: map[string]*premiumRates{ + "peer1": { + btcSwapInPremiumRatePPM: NewPPM(1000), + }, + }, + }, + args: args{ + peerID: "peer1", + k: BtcSwapIn, + }, + want: NewPPM(1000), + }, + "GetRateForNonExistingPeer": { + p: &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM(100), + btcSwapOutPremiumRatePPM: NewPPM(200), + lbtcSwapInPremiumRatePPM: NewPPM(300), + lbtcSwapOutPremiumRatePPM: NewPPM(400), + }, + premiumByPeerIds: map[string]*premiumRates{}, + }, + args: args{ + peerID: "peer2", + k: BtcSwapIn, + }, + want: NewPPM(100), + }, + "GetRateForExistingPeerWithDifferentKind": { + p: &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM(100), + btcSwapOutPremiumRatePPM: NewPPM(200), + lbtcSwapInPremiumRatePPM: NewPPM(300), + lbtcSwapOutPremiumRatePPM: NewPPM(400), + }, + premiumByPeerIds: map[string]*premiumRates{ + "peer1": { + btcSwapInPremiumRatePPM: NewPPM(1000), + }, + }, + }, + args: args{ + peerID: "peer1", + k: BtcSwapOut, + }, + want: NewPPM(200), + }, + "GetRateForNonExistingPeerWithDifferentKind": { + p: &premium{ + baseRates: &premiumRates{ + btcSwapInPremiumRatePPM: NewPPM(100), + btcSwapOutPremiumRatePPM: NewPPM(200), + lbtcSwapInPremiumRatePPM: NewPPM(300), + lbtcSwapOutPremiumRatePPM: NewPPM(400), + }, + premiumByPeerIds: map[string]*premiumRates{}, + }, + args: args{ + peerID: "peer2", + k: LbtcSwapIn, + }, + want: NewPPM(300), + }, + } + + for name, tt := range tests { + tt := tt + t.Run(name, func(t *testing.T) { + t.Parallel() + if got := tt.p.GetRate(tt.args.peerID, tt.args.k); !assert.Equal(t, tt.want, got) { + t.Errorf("premium.GetRate() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/poll/messages.go b/poll/messages.go index cd7949a5..91ef5f36 100644 --- a/poll/messages.go +++ b/poll/messages.go @@ -3,11 +3,13 @@ package poll import "github.com/elementsproject/peerswap/messages" type PollMessage struct { - Version uint64 `json:"version"` - Assets []string `json:"assets"` - PeerAllowed bool `json:"peer_allowed"` - SwapInPremiumRatePPM int64 `json:"swap_in_premium_rate_ppm"` - SwapOutPremiumRatePPM int64 `json:"swap_out_premium_rate_ppm"` + Version uint64 `json:"version"` + Assets []string `json:"assets"` + PeerAllowed bool `json:"peer_allowed"` + 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"` } func (PollMessage) MessageType() messages.MessageType { @@ -15,11 +17,13 @@ func (PollMessage) MessageType() messages.MessageType { } type RequestPollMessage struct { - Version uint64 `json:"version"` - Assets []string `json:"assets"` - PeerAllowed bool `json:"peer_allowed"` - SwapInPremiumRatePPM int64 `json:"swap_in_premium_rate_ppm"` - SwapOutPremiumRatePPM int64 `json:"swap_out_premium_rate_ppm"` + Version uint64 `json:"version"` + Assets []string `json:"assets"` + PeerAllowed bool `json:"peer_allowed"` + 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"` } func (RequestPollMessage) MessageType() messages.MessageType { diff --git a/poll/service.go b/poll/service.go index 269fdf00..ac777548 100644 --- a/poll/service.go +++ b/poll/service.go @@ -9,6 +9,7 @@ import ( "time" "github.com/elementsproject/peerswap/log" + policy "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/messages" @@ -39,8 +40,7 @@ type PeerGetter interface { type Policy interface { IsPeerAllowed(peerId string) bool - GetSwapInPremiumRatePPM() int64 - GetSwapOutPremiumRatePPM() int64 + GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 } type Store interface { @@ -50,12 +50,14 @@ type Store interface { } type PollInfo struct { - ProtocolVersion uint64 `json:"version"` - Assets []string `json:"assets"` - SwapInPremiumRatePPM int64 `json:"swap_in_premium_rate_ppm"` - SwapOutPremiumRatePPM int64 `json:"swap_out_premium_rate_ppm"` - PeerAllowed bool - LastSeen time.Time + ProtocolVersion uint64 `json:"version"` + Assets []string `json:"assets"` + 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"` + PeerAllowed bool + LastSeen time.Time } type Service struct { sync.RWMutex @@ -123,11 +125,13 @@ func (s *Service) Stop() { // Poll sends the POLL message to a single peer. func (s *Service) Poll(peer string) { poll := PollMessage{ - Version: swap.PEERSWAP_PROTOCOL_VERSION, - Assets: s.assets, - PeerAllowed: s.policy.IsPeerAllowed(peer), - SwapInPremiumRatePPM: s.policy.GetSwapInPremiumRatePPM(), - SwapOutPremiumRatePPM: s.policy.GetSwapOutPremiumRatePPM(), + Version: swap.PEERSWAP_PROTOCOL_VERSION, + Assets: s.assets, + PeerAllowed: s.policy.IsPeerAllowed(peer), + BTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.BtcSwapIn), + BTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.BtcSwapOut), + LBTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.LbtcSwapIn), + LBTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.LbtcSwapOut), } msg, err := json.Marshal(poll) @@ -152,11 +156,13 @@ func (s *Service) PollAllPeers() { // single peer. func (s *Service) RequestPoll(peer string) { request := RequestPollMessage{ - Version: swap.PEERSWAP_PROTOCOL_VERSION, - Assets: s.assets, - PeerAllowed: s.policy.IsPeerAllowed(peer), - SwapInPremiumRatePPM: s.policy.GetSwapInPremiumRatePPM(), - SwapOutPremiumRatePPM: s.policy.GetSwapOutPremiumRatePPM(), + Version: swap.PEERSWAP_PROTOCOL_VERSION, + Assets: s.assets, + PeerAllowed: s.policy.IsPeerAllowed(peer), + BTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.BtcSwapIn), + BTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.BtcSwapOut), + LBTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.LbtcSwapIn), + LBTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peer, policy.LbtcSwapOut), } msg, err := json.Marshal(request) @@ -202,12 +208,14 @@ func (s *Service) MessageHandler(peerID, msgType string, payload []byte) error { return jerr } if serr := s.store.Update(peerID, PollInfo{ - ProtocolVersion: msg.Version, - Assets: msg.Assets, - PeerAllowed: msg.PeerAllowed, - SwapInPremiumRatePPM: msg.SwapInPremiumRatePPM, - SwapOutPremiumRatePPM: msg.SwapOutPremiumRatePPM, - LastSeen: time.Now(), + ProtocolVersion: msg.Version, + Assets: msg.Assets, + PeerAllowed: msg.PeerAllowed, + BTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.BtcSwapIn), + BTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.BtcSwapOut), + LBTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.LbtcSwapIn), + LBTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.LbtcSwapOut), + LastSeen: time.Now(), }); serr != nil { return serr } @@ -229,12 +237,14 @@ func (s *Service) MessageHandler(peerID, msgType string, payload []byte) error { return jerr } if serr := s.store.Update(peerID, PollInfo{ - ProtocolVersion: msg.Version, - Assets: msg.Assets, - PeerAllowed: msg.PeerAllowed, - SwapInPremiumRatePPM: msg.SwapInPremiumRatePPM, - SwapOutPremiumRatePPM: msg.SwapOutPremiumRatePPM, - LastSeen: time.Now(), + ProtocolVersion: msg.Version, + Assets: msg.Assets, + PeerAllowed: msg.PeerAllowed, + BTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.BtcSwapIn), + BTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.BtcSwapOut), + LBTCSwapInPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.LbtcSwapIn), + LBTCSwapOutPremiumRatePPM: s.policy.GetPremiumRate(peerID, policy.LbtcSwapOut), + LastSeen: time.Now(), }); serr != nil { return serr } diff --git a/poll/service_test.go b/poll/service_test.go index 34716690..d8f8a8c0 100644 --- a/poll/service_test.go +++ b/poll/service_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/elementsproject/peerswap/messages" + policy "github.com/elementsproject/peerswap/policy" "github.com/stretchr/testify/assert" "go.etcd.io/bbolt" ) @@ -50,11 +51,7 @@ func (m *PolicyMock) IsPeerAllowed(peerId string) bool { return m.allowList[m.called-1] } -func (m *PolicyMock) GetSwapInPremiumRatePPM() int64 { - return 1000000 -} - -func (m *PolicyMock) GetSwapOutPremiumRatePPM() int64 { +func (m *PolicyMock) GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 { return 1000000 } diff --git a/sample_policy.conf b/sample_policy.conf index 9893dbc7..f6d5f2ac 100644 --- a/sample_policy.conf +++ b/sample_policy.conf @@ -5,5 +5,17 @@ allowlisted_peers=peer3 accept_all_peers=0 # swap_amount * premium_rate_ppm / 1000000 is the premium # Negative values can also be set to give a discount -swap_in_premium_rate_ppm=10000 -swap_out_premium_rate_ppm=20000 +# * The value specified by `btc_swap_in_premium_rate_ppm` is the premium rate for BTC swap in +# * The value specified by `btc_swap_out_premium_rate_ppm` is the premium rate for BTC swap out +# * The value specified by `lbtc_swap_in_premium_rate_ppm` is the premium rate for LBTC swap in +# * The value specified by `lbtc_swap_out_premium_rate_ppm` is the premium rate for LBTC swap out +[base_premium_rate] +btc_swap_in_premium_rate_ppm=100 +# Set the premium rate for each peer +# * The value specified by `peer1.btc_swap_in_premium_rate_ppm` is the premium rate for BTC swap in for peer1 +# * The value specified by `peer1.btc_swap_out_premium_rate_ppm` is the premium rate for BTC swap out for peer1 +# * The value specified by `peer1.lbtc_swap_in_premium_rate_ppm` is the premium rate for LBTC swap in for peer1 +# * The value specified by `peer1.lbtc_swap_out_premium_rate_ppm` is the premium rate for LBTC swap out for peer1 +[peers_premium_rate] +peer1.btc_swap_in_premium_rate_ppm=1000 +peer2.btc_swap_out_premium_rate_ppm=2000 \ No newline at end of file diff --git a/swap/actions.go b/swap/actions.go index 9bc84205..c4c68358 100644 --- a/swap/actions.go +++ b/swap/actions.go @@ -10,6 +10,7 @@ import ( "time" "github.com/elementsproject/peerswap/log" + "github.com/elementsproject/peerswap/policy" "github.com/btcsuite/btcd/btcec/v2" "github.com/elementsproject/peerswap/isdev" @@ -144,11 +145,17 @@ func (a CheckRequestWrapperAction) Execute(services *SwapServices, swap *SwapDat type SwapInReceiverInitAction struct{} func (s *SwapInReceiverInitAction) Execute(services *SwapServices, swap *SwapData) EventType { + var premium int64 + if swap.GetChain() == l_btc_chain { + premium = services.policy.ComputePremium(swap.PeerNodeId, policy.LbtcSwapIn, swap.GetAmount()) + } else { + premium = services.policy.ComputePremium(swap.PeerNodeId, policy.BtcSwapIn, swap.GetAmount()) + } agreementMessage := &SwapInAgreementMessage{ ProtocolVersion: PEERSWAP_PROTOCOL_VERSION, SwapId: swap.GetId(), Pubkey: hex.EncodeToString(swap.GetPrivkey().PubKey().SerializeCompressed()), - Premium: ComputePremium(swap.GetAmount(), services.policy.GetSwapInPremiumRatePPM()), + Premium: premium, } swap.SwapInAgreement = agreementMessage @@ -419,13 +426,19 @@ func (c *CreateSwapOutFromRequestAction) Execute(services *SwapServices, swap *S if err != nil { return swap.HandleError(err) } + var premium int64 + if swap.GetChain() == l_btc_chain { + premium = services.policy.ComputePremium(swap.PeerNodeId, policy.LbtcSwapOut, swap.GetAmount()) + } else { + premium = services.policy.ComputePremium(swap.PeerNodeId, policy.BtcSwapOut, swap.GetAmount()) + } message := &SwapOutAgreementMessage{ ProtocolVersion: PEERSWAP_PROTOCOL_VERSION, SwapId: swap.GetId(), Pubkey: hex.EncodeToString(swap.GetPrivkey().PubKey().SerializeCompressed()), Payreq: feeInvoice, - Premium: ComputePremium(swap.GetAmount(), services.policy.GetSwapOutPremiumRatePPM()), + Premium: premium, } swap.SwapOutAgreement = message diff --git a/swap/service.go b/swap/service.go index d55fda63..9a13d0e1 100644 --- a/swap/service.go +++ b/swap/service.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/elementsproject/peerswap/log" + "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/messages" ) @@ -541,21 +542,18 @@ func (s *SwapService) estimateMaximumSwapAmountSat(chain string) (uint64, error) return 0, errors.New("invalid chain") } -const ( - // premiumRateParts is the total number of parts used to express fee rates. - premiumRateParts = 1e6 -) - -// ComputePremium computes the premium. -// The premium rate charged per sat will be: (amount * premiumRate/1,000,000). -func ComputePremium( - amtSat uint64, premiumRate int64) int64 { - return int64(amtSat) * premiumRate / premiumRateParts -} - // OnSwapInRequestReceived creates a new swap-in process and sends the event to the swap statemachine func (s *SwapService) OnSwapInRequestReceived(swapId *SwapId, peerId string, message *SwapInRequestMessage) error { - premium := ComputePremium(message.Amount, s.swapServices.policy.GetSwapInPremiumRatePPM()) + var premium int64 + // Network is the desired on-chain network to use. This can be: + // Bitcoin: mainnet, testnet, signet, regtest + // Liquid: The field is left blank as the asset id also defines the bitcoinNetwork. + if message.Network == "" { + premium = s.swapServices.policy.ComputePremium(peerId, policy.LbtcSwapIn, message.Amount) + } else { + premium = s.swapServices.policy.ComputePremium(peerId, policy.BtcSwapIn, message.Amount) + } + if premium > message.PremiumLimit { err := fmt.Errorf("unacceptable premium: %d, limit: %d", premium, message.PremiumLimit) msg := fmt.Sprintf("from the %s peer: %s", s.swapServices.lightning.Implementation(), err.Error()) @@ -648,7 +646,15 @@ func (s *SwapService) OnSwapInRequestReceived(swapId *SwapId, peerId string, mes // OnSwapInRequestReceived creates a new swap-out process and sends the event to the swap statemachine func (s *SwapService) OnSwapOutRequestReceived(swapId *SwapId, peerId string, message *SwapOutRequestMessage) error { - premium := ComputePremium(message.Amount, s.swapServices.policy.GetSwapOutPremiumRatePPM()) + var premium int64 + // Network is the desired on-chain network to use. This can be: + // Bitcoin: mainnet, testnet, signet, regtest + // Liquid: The field is left blank as the asset id also defines the bitcoinNetwork. + if message.Network == "" { + premium = s.swapServices.policy.ComputePremium(peerId, policy.LbtcSwapOut, message.Amount) + } else { + premium = s.swapServices.policy.ComputePremium(peerId, policy.BtcSwapOut, message.Amount) + } if premium > message.PremiumLimit { err := fmt.Errorf("unacceptable premium: %d, limit: %d", premium, message.PremiumLimit) msg := fmt.Sprintf("from the %s peer: %s", s.swapServices.lightning.Implementation(), err.Error()) diff --git a/swap/service_test.go b/swap/service_test.go index 4dc6b63b..d32ab19a 100644 --- a/swap/service_test.go +++ b/swap/service_test.go @@ -403,8 +403,8 @@ func getTestSetup(name string) *SwapService { policy := &dummyPolicy{ getMinSwapAmountMsatReturn: policy.DefaultPolicy().MinSwapAmountMsat, newSwapsAllowedReturn: policy.DefaultPolicy().AllowNewSwaps, - getSwapInPremiumRatePPM: policy.DefaultPolicy().SwapInPremiumRatePPM, - getSwapOutPremiumRatePPM: policy.DefaultPolicy().SwapOutPremiumRatePPM, + getSwapInPremiumRatePPM: policy.DefaultPolicy().GetPremiumRate(name, policy.BtcSwapIn), + getSwapOutPremiumRatePPM: policy.DefaultPolicy().GetPremiumRate(name, policy.BtcSwapOut), } chain := &dummyChain{returnGetCSVHeight: 1008} chain.SetBalance(10000000) diff --git a/swap/services.go b/swap/services.go index 02a5d4b4..4c18e516 100644 --- a/swap/services.go +++ b/swap/services.go @@ -7,6 +7,7 @@ import ( "time" "github.com/elementsproject/peerswap/messages" + policy "github.com/elementsproject/peerswap/policy" "github.com/btcsuite/btcd/btcec/v2" btecdsa "github.com/btcsuite/btcd/btcec/v2/ecdsa" @@ -36,8 +37,8 @@ type Policy interface { AddToSuspiciousPeerList(pubkey string) error GetReserveOnchainMsat() uint64 GetMinSwapAmountMsat() uint64 - GetSwapInPremiumRatePPM() int64 - GetSwapOutPremiumRatePPM() int64 + GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 + ComputePremium(peerID string, k policy.PremiumRateKind, amtSat uint64) int64 NewSwapsAllowed() bool } diff --git a/swap/swap_out_sender_test.go b/swap/swap_out_sender_test.go index b519f3a5..282d43bb 100644 --- a/swap/swap_out_sender_test.go +++ b/swap/swap_out_sender_test.go @@ -8,6 +8,7 @@ import ( "github.com/elementsproject/peerswap/lightning" "github.com/elementsproject/peerswap/messages" + "github.com/elementsproject/peerswap/policy" "github.com/stretchr/testify/assert" ) @@ -390,12 +391,11 @@ func (d *dummyPolicy) GetMinSwapAmountMsat() uint64 { return d.getMinSwapAmountMsatReturn } -func (d *dummyPolicy) GetSwapInPremiumRatePPM() int64 { +func (d *dummyPolicy) GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 { return d.getSwapInPremiumRatePPM } - -func (d *dummyPolicy) GetSwapOutPremiumRatePPM() int64 { - return d.getSwapOutPremiumRatePPM +func (d *dummyPolicy) ComputePremium(peerID string, k policy.PremiumRateKind, amtSat uint64) int64 { + return policy.NewPPM(d.getSwapInPremiumRatePPM).Compute(amtSat) } func (d *dummyPolicy) IsPeerAllowed(peer string) bool { diff --git a/test/bitcoin_cln_test.go b/test/bitcoin_cln_test.go index 68c16f1b..1e43b703 100644 --- a/test/bitcoin_cln_test.go +++ b/test/bitcoin_cln_test.go @@ -76,8 +76,8 @@ func Test_OnlyOneActiveSwapPerChannelCln(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -172,8 +172,8 @@ func Test_ClnCln_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -244,8 +244,8 @@ func Test_ClnCln_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -318,8 +318,8 @@ func Test_ClnCln_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -397,8 +397,8 @@ func Test_ClnCln_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -470,8 +470,8 @@ func Test_ClnCln_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -543,8 +543,8 @@ func Test_ClnCln_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -625,8 +625,8 @@ func Test_ClnLnd_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -701,8 +701,8 @@ func Test_ClnLnd_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -777,8 +777,8 @@ func Test_ClnLnd_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -859,8 +859,8 @@ func Test_ClnLnd_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -935,8 +935,8 @@ func Test_ClnLnd_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1011,8 +1011,8 @@ func Test_ClnLnd_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1089,8 +1089,8 @@ func Test_ClnCln_ExcessiveAmount(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1168,8 +1168,8 @@ func Test_Cln_HtlcMaximum(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1240,8 +1240,8 @@ func Test_Cln_HtlcMaximum(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1324,7 +1324,7 @@ func Test_Cln_Premium(t *testing.T) { swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), swapInPremiumRate: -10000, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1400,7 +1400,7 @@ func Test_Cln_Premium(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), swapOutPremiumRate: -10000, } asset := "btc" @@ -1471,8 +1471,8 @@ func Test_Cln_Premium(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: 1, - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" diff --git a/test/bitcoin_lnd_test.go b/test/bitcoin_lnd_test.go index 047d6f32..47335a0f 100644 --- a/test/bitcoin_lnd_test.go +++ b/test/bitcoin_lnd_test.go @@ -85,8 +85,8 @@ func Test_OnlyOneActiveSwapPerChannelLnd(t *testing.T) { confirms: BitcoinConfirms, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -201,8 +201,8 @@ func Test_LndLnd_Bitcoin_SwapIn(t *testing.T) { confirms: BitcoinConfirms, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -284,8 +284,8 @@ func Test_LndLnd_Bitcoin_SwapIn(t *testing.T) { confirms: BitcoinConfirms, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -368,8 +368,8 @@ func Test_LndLnd_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -458,8 +458,8 @@ func Test_LndLnd_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -543,8 +543,8 @@ func Test_LndLnd_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -628,8 +628,8 @@ func Test_LndLnd_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -716,8 +716,8 @@ func Test_LndCln_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -798,8 +798,8 @@ func Test_LndCln_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -881,8 +881,8 @@ func Test_LndCln_Bitcoin_SwapIn(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -969,8 +969,8 @@ func Test_LndCln_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1051,8 +1051,8 @@ func Test_LndCln_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1133,8 +1133,8 @@ func Test_LndCln_Bitcoin_SwapOut(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1222,8 +1222,8 @@ func Test_LndLnd_ExcessiveAmount(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -1306,8 +1306,8 @@ func Test_LndLnd_ExcessiveAmount(t *testing.T) { confirms: BitcoinConfirms, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" _, err = lightningds[0].SetHtlcMaximumMilliSatoshis(scid, channelBalances[0]*1000/2-1) diff --git a/test/liquid_cln_test.go b/test/liquid_cln_test.go index 8f01176f..0f10f757 100644 --- a/test/liquid_cln_test.go +++ b/test/liquid_cln_test.go @@ -75,8 +75,8 @@ func Test_ClnCln_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -154,8 +154,8 @@ func Test_ClnCln_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -231,8 +231,8 @@ func Test_ClnCln_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -314,8 +314,8 @@ func Test_ClnCln_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -391,8 +391,8 @@ func Test_ClnCln_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -468,8 +468,8 @@ func Test_ClnCln_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -555,8 +555,8 @@ func Test_ClnLnd_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -636,8 +636,8 @@ func Test_ClnLnd_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -717,8 +717,8 @@ func Test_ClnLnd_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -805,8 +805,8 @@ func Test_ClnLnd_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -885,8 +885,8 @@ func Test_ClnLnd_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -965,8 +965,8 @@ func Test_ClnLnd_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" diff --git a/test/liquid_lnd_test.go b/test/liquid_lnd_test.go index 538979da..c5f30270 100644 --- a/test/liquid_lnd_test.go +++ b/test/liquid_lnd_test.go @@ -86,8 +86,8 @@ func Test_LndLnd_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -174,8 +174,8 @@ func Test_LndLnd_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -262,8 +262,8 @@ func Test_LndLnd_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -356,8 +356,8 @@ func Test_LndLnd_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -445,8 +445,8 @@ func Test_LndLnd_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -534,8 +534,8 @@ func Test_LndLnd_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -627,8 +627,8 @@ func Test_LndCln_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -713,8 +713,8 @@ func Test_LndCln_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -799,8 +799,8 @@ func Test_LndCln_Liquid_SwapIn(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_IN, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -891,8 +891,8 @@ func Test_LndCln_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -977,8 +977,8 @@ func Test_LndCln_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" @@ -1063,8 +1063,8 @@ func Test_LndCln_Liquid_SwapOut(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" diff --git a/test/lwk_cln_test.go b/test/lwk_cln_test.go index a2dbf877..90f74ed3 100644 --- a/test/lwk_cln_test.go +++ b/test/lwk_cln_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/elementsproject/peerswap/clightning" + "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/stretchr/testify/require" ) @@ -65,28 +66,31 @@ func Test_ClnCln_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -144,28 +148,31 @@ func Test_ClnCln_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -224,28 +231,31 @@ func Test_ClnCln_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -308,28 +318,31 @@ func Test_ClnCln_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -387,28 +400,31 @@ func Test_ClnCln_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -467,28 +483,31 @@ func Test_ClnCln_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -555,21 +574,24 @@ func Test_ClnLnd_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapd.DaemonProcess, - makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapd.DaemonProcess, + makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -577,7 +599,7 @@ func Test_ClnLnd_LWK_SwapIn(t *testing.T) { go func() { // We need to run this in a go routine as the Request call is blocking and sometimes does not return. var response map[string]interface{} - err := lightningds[1].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() preimageClaimTest(t, params) @@ -637,21 +659,24 @@ func Test_ClnLnd_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapd.DaemonProcess, - makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapd.DaemonProcess, + makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -659,7 +684,7 @@ func Test_ClnLnd_LWK_SwapIn(t *testing.T) { go func() { // We need to run this in a go routine as the Request call is blocking and sometimes does not return. var response map[string]interface{} - lightningds[1].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + lightningds[1].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) }() coopClaimTest(t, params) }) @@ -718,21 +743,24 @@ func Test_ClnLnd_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapd.DaemonProcess, - makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapd.DaemonProcess, + makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -740,7 +768,7 @@ func Test_ClnLnd_LWK_SwapIn(t *testing.T) { go func() { // We need to run this in a go routine as the Request call is blocking and sometimes does not return. var response map[string]interface{} - lightningds[1].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + lightningds[1].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) }() csvClaimTest(t, params) }) @@ -805,21 +833,24 @@ func Test_ClnLnd_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -827,7 +858,7 @@ func Test_ClnLnd_LWK_SwapOut(t *testing.T) { go func() { // We need to run this in a go routine as the Request call is blocking and sometimes does not return. var response map[string]interface{} - lightningds[0].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + lightningds[0].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) }() preimageClaimTest(t, params) }) @@ -886,21 +917,24 @@ func Test_ClnLnd_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -908,7 +942,7 @@ func Test_ClnLnd_LWK_SwapOut(t *testing.T) { go func() { // We need to run this in a go routine as the Request call is blocking and sometimes does not return. var response map[string]interface{} - lightningds[0].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + lightningds[0].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) }() coopClaimTest(t, params) }) @@ -967,21 +1001,24 @@ func Test_ClnLnd_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -989,7 +1026,7 @@ func Test_ClnLnd_LWK_SwapOut(t *testing.T) { go func() { // We need to run this in a go routine as the Request call is blocking and sometimes does not return. var response map[string]interface{} - lightningds[0].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + lightningds[0].(*CLightningNodeWithLiquid).Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) }() csvClaimTest(t, params) }) @@ -1050,28 +1087,31 @@ func Test_ClnCln_LWKElements_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -1129,28 +1169,31 @@ func Test_ClnCln_LWKElements_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -1209,28 +1252,31 @@ func Test_ClnCln_LWKElements_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].Rpc.Request(&clightning.SwapIn{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -1293,28 +1339,31 @@ func Test_ClnCln_LWKLiquid_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -1372,28 +1421,31 @@ func Test_ClnCln_LWKLiquid_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -1452,28 +1504,31 @@ func Test_ClnCln_LWKLiquid_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" // Do swap. go func() { var response map[string]interface{} - err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[0].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.NoError(err) }() @@ -1536,21 +1591,24 @@ func Test_ClnCln_LWKLiquid_BackendDown(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].DaemonProcess, - makerPeerswap: lightningds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].DaemonProcess, + makerPeerswap: lightningds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -1558,7 +1616,7 @@ func Test_ClnCln_LWKLiquid_BackendDown(t *testing.T) { // Do swap. var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset}, &response) + err := lightningds[1].Rpc.Request(&clightning.SwapOut{SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) require.Error(err) }) t.Run("electrsdown", func(t *testing.T) { diff --git a/test/lwk_lnd_test.go b/test/lwk_lnd_test.go index 1c992ab0..e53dae69 100644 --- a/test/lwk_lnd_test.go +++ b/test/lwk_lnd_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/elementsproject/peerswap/peerswaprpc" + "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/stretchr/testify/require" ) @@ -77,21 +78,24 @@ func Test_LndLnd_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapds[0].DaemonProcess, - makerPeerswap: peerswapds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapds[0].DaemonProcess, + makerPeerswap: peerswapds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -100,9 +104,10 @@ func Test_LndLnd_LWK_SwapIn(t *testing.T) { defer cancel() go func() { peerswapds[1].PeerswapClient.SwapIn(ctx, &peerswaprpc.SwapInRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() preimageClaimTest(t, params) @@ -169,21 +174,24 @@ func Test_LndLnd_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapds[0].DaemonProcess, - makerPeerswap: peerswapds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapds[0].DaemonProcess, + makerPeerswap: peerswapds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -192,9 +200,10 @@ func Test_LndLnd_LWK_SwapIn(t *testing.T) { defer cancel() go func() { peerswapds[1].PeerswapClient.SwapIn(ctx, &peerswaprpc.SwapInRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() coopClaimTest(t, params) @@ -261,21 +270,24 @@ func Test_LndLnd_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapds[0].DaemonProcess, - makerPeerswap: peerswapds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapds[0].DaemonProcess, + makerPeerswap: peerswapds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -284,9 +296,10 @@ func Test_LndLnd_LWK_SwapIn(t *testing.T) { defer cancel() go func() { peerswapds[1].PeerswapClient.SwapIn(ctx, &peerswaprpc.SwapInRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() csvClaimTest(t, params) @@ -359,21 +372,24 @@ func Test_LndLnd_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapds[0].DaemonProcess, - makerPeerswap: peerswapds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapds[0].DaemonProcess, + makerPeerswap: peerswapds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -382,9 +398,10 @@ func Test_LndLnd_LWK_SwapOut(t *testing.T) { defer cancel() go func() { peerswapds[0].PeerswapClient.SwapOut(ctx, &peerswaprpc.SwapOutRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() preimageClaimTest(t, params) @@ -451,21 +468,24 @@ func Test_LndLnd_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapds[0].DaemonProcess, - makerPeerswap: peerswapds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapds[0].DaemonProcess, + makerPeerswap: peerswapds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -474,9 +494,10 @@ func Test_LndLnd_LWK_SwapOut(t *testing.T) { defer cancel() go func() { peerswapds[0].PeerswapClient.SwapOut(ctx, &peerswaprpc.SwapOutRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() coopClaimTest(t, params) @@ -543,21 +564,24 @@ func Test_LndLnd_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapds[0].DaemonProcess, - makerPeerswap: peerswapds[1].DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapds[0].DaemonProcess, + makerPeerswap: peerswapds[1].DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -566,9 +590,10 @@ func Test_LndLnd_LWK_SwapOut(t *testing.T) { defer cancel() go func() { peerswapds[1].PeerswapClient.SwapOut(ctx, &peerswaprpc.SwapOutRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() csvClaimTest(t, params) @@ -639,21 +664,24 @@ func Test_LndCln_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -662,9 +690,10 @@ func Test_LndCln_LWK_SwapIn(t *testing.T) { defer cancel() go func() { peerswapd.PeerswapClient.SwapIn(ctx, &peerswaprpc.SwapInRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() preimageClaimTest(t, params) @@ -729,21 +758,24 @@ func Test_LndCln_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -752,9 +784,10 @@ func Test_LndCln_LWK_SwapIn(t *testing.T) { defer cancel() go func() { peerswapd.PeerswapClient.SwapIn(ctx, &peerswaprpc.SwapInRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() coopClaimTest(t, params) @@ -819,21 +852,24 @@ func Test_LndCln_LWK_SwapIn(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_IN, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: lightningds[0].(*CLightningNodeWithLiquid).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -842,9 +878,10 @@ func Test_LndCln_LWK_SwapIn(t *testing.T) { defer cancel() go func() { peerswapd.PeerswapClient.SwapIn(ctx, &peerswaprpc.SwapInRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() csvClaimTest(t, params) @@ -915,21 +952,24 @@ func Test_LndCln_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapd.DaemonProcess, - makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapd.DaemonProcess, + makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -938,9 +978,10 @@ func Test_LndCln_LWK_SwapOut(t *testing.T) { defer cancel() go func() { peerswapd.PeerswapClient.SwapOut(ctx, &peerswaprpc.SwapOutRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() preimageClaimTest(t, params) @@ -1005,21 +1046,24 @@ func Test_LndCln_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapd.DaemonProcess, - makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapd.DaemonProcess, + makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -1028,9 +1072,10 @@ func Test_LndCln_LWK_SwapOut(t *testing.T) { defer cancel() go func() { peerswapd.PeerswapClient.SwapOut(ctx, &peerswaprpc.SwapOutRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() coopClaimTest(t, params) @@ -1095,21 +1140,24 @@ func Test_LndCln_LWK_SwapOut(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 2, - scid: scid, - origTakerWallet: walletBalances[0], - origMakerWallet: walletBalances[1], - origTakerBalance: channelBalances[0], - origMakerBalance: channelBalances[1], - takerNode: lightningds[0], - makerNode: lightningds[1], - takerPeerswap: peerswapd.DaemonProcess, - makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, - chainRpc: liquidd.RpcProxy, - chaind: liquidd, - confirms: LiquidConfirms, - csv: LiquidCsv, - swapType: swap.SWAPTYPE_OUT, + swapAmt: channelBalances[0] / 2, + scid: scid, + origTakerWallet: walletBalances[0], + origMakerWallet: walletBalances[1], + origTakerBalance: channelBalances[0], + origMakerBalance: channelBalances[1], + takerNode: lightningds[0], + makerNode: lightningds[1], + takerPeerswap: peerswapd.DaemonProcess, + makerPeerswap: lightningds[1].(*CLightningNodeWithLiquid).DaemonProcess, + chainRpc: liquidd.RpcProxy, + chaind: liquidd, + confirms: LiquidConfirms, + csv: LiquidCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "lbtc" @@ -1118,9 +1166,10 @@ func Test_LndCln_LWK_SwapOut(t *testing.T) { defer cancel() go func() { peerswapd.PeerswapClient.SwapOut(ctx, &peerswaprpc.SwapOutRequest{ - ChannelId: lcid, - SwapAmount: params.swapAmt, - Asset: asset, + ChannelId: lcid, + SwapAmount: params.swapAmt, + Asset: asset, + PremiumLimit: params.premiumLimit, }) }() csvClaimTest(t, params) diff --git a/test/recovery_test.go b/test/recovery_test.go index da6662a6..ad94b68a 100644 --- a/test/recovery_test.go +++ b/test/recovery_test.go @@ -75,8 +75,8 @@ func Test_RestoreFromPassedCSV(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "btc" @@ -209,8 +209,8 @@ func Test_Recover_PassedSwap_BTC(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), } asset := "btc" @@ -321,8 +321,8 @@ func Test_Recover_PassedSwap_LBTC(t *testing.T) { csv: LiquidCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().SwapInPremiumRatePPM, - swapOutPremiumRate: policy.DefaultPolicy().SwapOutPremiumRatePPM, + swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), + swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), } asset := "lbtc" diff --git a/test/testcases.go b/test/testcases.go index 2fa2ed5e..5e54c0e8 100644 --- a/test/testcases.go +++ b/test/testcases.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/testframework" "github.com/stretchr/testify/require" @@ -35,9 +36,9 @@ type testParams struct { func (p *testParams) premium() int64 { switch p.swapType { case swap.SWAPTYPE_IN: - return swap.ComputePremium(p.swapAmt, p.swapInPremiumRate) + return policy.NewPPM(p.swapInPremiumRate).Compute(p.swapAmt) case swap.SWAPTYPE_OUT: - return swap.ComputePremium(p.swapAmt, p.swapOutPremiumRate) + return policy.NewPPM(p.swapOutPremiumRate).Compute(p.swapAmt) default: return 0 }