From 5711fb6329d77cfcd5b4b007452c3d3cbf9f1c1a Mon Sep 17 00:00:00 2001 From: bruwbird Date: Tue, 31 Dec 2024 17:29:18 +0900 Subject: [PATCH] premium: enable flexible settings with bbolt db Remove policy.conf management and switch to bbolt db for managing premium settings. Provide APIs for cln and lnd to interact with premium. - Implement Observer for premium updates - Poller detects updates and performs polling --- .envrc | 1 + clightning/clightning.go | 10 +- clightning/clightning_commands.go | 241 ++++- cmd/peerswap-plugin/main.go | 10 +- cmd/peerswaplnd/peerswapd/main.go | 10 +- cmd/peerswaplnd/pscli/main.go | 140 ++- docs/usage.md | 59 ++ flake.lock | 7 +- go.mod | 1 - go.sum | 2 - peerswaprpc/format.go | 6 - peerswaprpc/peerswaprpc.pb.go | 1207 ++++++++++++++++++-------- peerswaprpc/peerswaprpc.proto | 95 +- peerswaprpc/peerswaprpc.swagger.json | 69 +- peerswaprpc/peerswaprpc_grpc.pb.go | 152 ++++ peerswaprpc/server.go | 151 +++- policy/policy.go | 25 - policy/policy_test.go | 5 - policy/premium.go | 164 ---- policy/premium_test.go | 182 ---- poll/service.go | 59 +- poll/service_test.go | 13 +- premium/premium.go | 196 +++++ premium/premium_test.go | 119 +++ premium/store.go | 83 ++ sample_policy.conf | 16 - swap/actions.go | 33 +- swap/service.go | 42 +- swap/service_test.go | 53 +- swap/services.go | 10 +- swap/swap_in_receiver_test.go | 8 +- swap/swap_in_sender_test.go | 20 +- swap/swap_out_receiver_test.go | 12 +- swap/swap_out_sender_test.go | 22 +- test/bitcoin_cln_test.go | 656 +++++++------- test/bitcoin_lnd_test.go | 503 +++++------ test/liquid_cln_test.go | 409 ++++----- test/liquid_lnd_test.go | 409 ++++----- test/lwk_cln_test.go | 647 +++++++------- test/lwk_lnd_test.go | 409 ++++----- test/recovery_test.go | 103 +-- test/setup.go | 14 +- test/testcases.go | 6 +- 43 files changed, 3800 insertions(+), 2579 deletions(-) create mode 100644 .envrc delete mode 100644 policy/premium.go delete mode 100644 policy/premium_test.go create mode 100644 premium/premium.go create mode 100644 premium/premium_test.go create mode 100644 premium/store.go diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/clightning/clightning.go b/clightning/clightning.go index 1e9b8580..65bddba5 100644 --- a/clightning/clightning.go +++ b/clightning/clightning.go @@ -11,6 +11,7 @@ import ( "time" "github.com/elementsproject/peerswap/log" + "github.com/elementsproject/peerswap/premium" "github.com/btcsuite/btcd/chaincfg" "github.com/elementsproject/glightning/gbitcoin" @@ -46,6 +47,10 @@ var methods = []peerswaprpcMethod{ &ReloadPolicyFile{}, &GetRequestedSwaps{}, &ListConfig{}, + &GetPremiumRateRequest{}, + &SetPremiumRateRequest{}, + &GetDefaultPremiumRateRequest{}, + &SetDefaultPremiumRateRequest{}, } var devmethods = []peerswaprpcMethod{} @@ -70,6 +75,7 @@ type ClightningClient struct { requestedSwaps *swap.RequestedSwapsPrinter policy PolicyReloader pollService *poll.Service + ps *premium.Setting gbitcoin *gbitcoin.Bitcoin bitcoinChain *onchain.BitcoinOnChain @@ -326,7 +332,8 @@ func (cl *ClightningClient) GetPreimage() (lightning.Preimage, error) { func (cl *ClightningClient) SetupClients(liquidWallet wallet.Wallet, swaps *swap.SwapService, policy PolicyReloader, requestedSwaps *swap.RequestedSwapsPrinter, - bitcoin *gbitcoin.Bitcoin, bitcoinChain *onchain.BitcoinOnChain, pollService *poll.Service) { + bitcoin *gbitcoin.Bitcoin, bitcoinChain *onchain.BitcoinOnChain, pollService *poll.Service, + ps *premium.Setting) { cl.liquidWallet = liquidWallet cl.requestedSwaps = requestedSwaps cl.swaps = swaps @@ -334,6 +341,7 @@ func (cl *ClightningClient) SetupClients(liquidWallet wallet.Wallet, cl.gbitcoin = bitcoin cl.pollService = pollService cl.bitcoinChain = bitcoinChain + cl.ps = ps if cl.bitcoinChain != nil { cl.bitcoinNetwork = bitcoinChain.GetChain() } diff --git a/clightning/clightning_commands.go b/clightning/clightning_commands.go index 777f8448..16cb9217 100644 --- a/clightning/clightning_commands.go +++ b/clightning/clightning_commands.go @@ -12,6 +12,7 @@ import ( "github.com/elementsproject/peerswap/log" "github.com/elementsproject/peerswap/peerswaprpc" + "github.com/elementsproject/peerswap/premium" "github.com/elementsproject/glightning/glightning" "github.com/elementsproject/glightning/jrpc2" @@ -628,11 +629,13 @@ func (l *ListPeers) Call() (jrpc2.Result, error) { SatsOut: ReceiverSatsOut, SatsIn: ReceiverSatsIn, }, - PaidFee: paidFees, - BTCSwapInPremiumRatePPM: p.BTCSwapInPremiumRatePPM, - BTCSwapOutPremiumRatePPM: p.BTCSwapOutPremiumRatePPM, - LBTCSwapInPremiumRatePPM: p.LBTCSwapInPremiumRatePPM, - LBTCSwapOutPremiumRatePPM: p.LBTCSwapOutPremiumRatePPM, + PaidFee: paidFees, + PeerPremium: &Premium{ + BTCSwapInPremiumRatePPM: p.BTCSwapInPremiumRatePPM, + BTCSwapOutPremiumRatePPM: p.BTCSwapOutPremiumRatePPM, + LBTCSwapInPremiumRatePPM: p.LBTCSwapInPremiumRatePPM, + LBTCSwapOutPremiumRatePPM: p.LBTCSwapOutPremiumRatePPM, + }, } channels, err := l.cl.glightning.ListChannelsBySource(peer.Id) if err != nil { @@ -1102,6 +1105,208 @@ func (c ListConfig) LongDescription() string { return c.Description() } +func toPremiumAssetType(asset string) premium.AssetType { + switch strings.ToUpper(asset) { + case "BTC": + return premium.BTC + case "LBTC": + return premium.LBTC + default: + return premium.AsserUnspecified + } +} + +func toPremiumOperationType(operation string) premium.OperationType { + switch strings.ToUpper(operation) { + case "SWAP_IN": + return premium.SwapIn + case "SWAP_OUT": + return premium.SwapOut + default: + return premium.OperationUnspecified + } +} + +type GetPremiumRateRequest struct { + cl *ClightningClient + PeerID string `json:"peer_id"` + Asset string `json:"asset"` + OperationType string `json:"operation"` +} + +func (c *GetPremiumRateRequest) Name() string { + return "peerswap-getpremiumrate" +} + +func (c *GetPremiumRateRequest) New() interface{} { + return &GetPremiumRateRequest{ + cl: c.cl, + } +} + +func (c *GetPremiumRateRequest) Call() (jrpc2.Result, error) { + if !c.cl.isReady { + return nil, ErrWaitingForReady + } + e, err := c.cl.ps.GetRate(c.PeerID, toPremiumAssetType(c.Asset), + toPremiumOperationType(c.OperationType)) + if err != nil { + return nil, fmt.Errorf("error getting premium rate: %v", err) + } + return e.PremiumRatePPM().Value(), nil +} + +func (c *GetPremiumRateRequest) Get(client *ClightningClient) jrpc2.ServerMethod { + return &GetPremiumRateRequest{ + cl: client, + } +} + +func (c GetPremiumRateRequest) Description() string { + return "Get the premium rate for a peer" +} + +func (c GetPremiumRateRequest) LongDescription() string { + return c.Description() +} + +type SetPremiumRateRequest struct { + cl *ClightningClient + PeerID string `json:"peer_id"` + Asset string `json:"asset"` + OperationType string `json:"operation"` + PremiumRatePPM int64 `json:"premium_rate_ppm"` +} + +func (c *SetPremiumRateRequest) Name() string { + return "peerswap-setpremiumrate" +} + +func (c *SetPremiumRateRequest) New() interface{} { + return &SetPremiumRateRequest{ + cl: c.cl, + } +} + +func (c *SetPremiumRateRequest) Call() (jrpc2.Result, error) { + if !c.cl.isReady { + return nil, ErrWaitingForReady + } + rate, err := premium.NewPremiumRate(toPremiumAssetType(c.Asset), + toPremiumOperationType(c.OperationType), premium.NewPPM(c.PremiumRatePPM)) + if err != nil { + return nil, fmt.Errorf("error creating premium rate: %v", err) + } + err = c.cl.ps.SetRate(c.PeerID, rate) + if err != nil { + return nil, fmt.Errorf("error setting premium rate: %v", err) + } + return rate, nil +} + +func (c *SetPremiumRateRequest) Get(client *ClightningClient) jrpc2.ServerMethod { + return &SetPremiumRateRequest{ + cl: client, + } +} + +func (c SetPremiumRateRequest) Description() string { + return "Set the premium rate for a peer" +} + +func (c SetPremiumRateRequest) LongDescription() string { + return c.Description() +} + +type SetDefaultPremiumRateRequest struct { + cl *ClightningClient + Asset string `json:"asset"` + OperationType string `json:"operation"` + PremiumRatePPM int64 `json:"premium_rate_ppm"` +} + +func (c *SetDefaultPremiumRateRequest) Name() string { + return "peerswap-setdefaultpremiumrate" +} + +func (c *SetDefaultPremiumRateRequest) New() interface{} { + return &SetDefaultPremiumRateRequest{ + cl: c.cl, + } +} + +func (c *SetDefaultPremiumRateRequest) Call() (jrpc2.Result, error) { + if !c.cl.isReady { + return nil, ErrWaitingForReady + } + rate, err := premium.NewPremiumRate(toPremiumAssetType(c.Asset), + toPremiumOperationType(c.OperationType), premium.NewPPM(c.PremiumRatePPM)) + if err != nil { + return nil, fmt.Errorf("error creating premium rate: %v", err) + } + err = c.cl.ps.SetDefaultRate(rate) + if err != nil { + return nil, fmt.Errorf("error setting default premium rate: %v", err) + } + return rate, nil +} + +func (c *SetDefaultPremiumRateRequest) Get(client *ClightningClient) jrpc2.ServerMethod { + return &SetDefaultPremiumRateRequest{ + cl: client, + } +} + +func (c SetDefaultPremiumRateRequest) Description() string { + return "Set the default premium rate" +} + +func (c SetDefaultPremiumRateRequest) LongDescription() string { + return c.Description() +} + +type GetDefaultPremiumRateRequest struct { + cl *ClightningClient + Asset string `json:"asset"` + OperationType string `json:"operation"` +} + +func (c *GetDefaultPremiumRateRequest) Name() string { + return "peerswap-getdefaultpremiumrate" +} + +func (c *GetDefaultPremiumRateRequest) New() interface{} { + return &GetDefaultPremiumRateRequest{ + cl: c.cl, + } +} + +func (c *GetDefaultPremiumRateRequest) Call() (jrpc2.Result, error) { + if !c.cl.isReady { + return nil, ErrWaitingForReady + } + rate, err := c.cl.ps.GetDefaultRate(toPremiumAssetType(c.Asset), + toPremiumOperationType(c.OperationType)) + if err != nil { + return nil, fmt.Errorf("error getting default premium rate: %v", err) + } + return rate.PremiumRatePPM().Value(), nil +} + +func (c *GetDefaultPremiumRateRequest) Get(client *ClightningClient) jrpc2.ServerMethod { + return &GetDefaultPremiumRateRequest{ + cl: client, + } +} + +func (c GetDefaultPremiumRateRequest) Description() string { + return "Get the default premium rate" +} + +func (c GetDefaultPremiumRateRequest) LongDescription() string { + return c.Description() +} + type PeerSwapPeerChannel struct { ChannelId string `json:"short_channel_id"` LocalBalance uint64 `json:"local_balance"` @@ -1116,18 +1321,22 @@ type SwapStats struct { SatsIn uint64 `json:"total_sats_swapped_in"` } +type Premium struct { + 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"` +} + 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"` - 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"` + 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"` + PeerPremium *Premium `json:"premium,omitempty"` } // checkFeatures checks if a node runs the peerswap Plugin diff --git a/cmd/peerswap-plugin/main.go b/cmd/peerswap-plugin/main.go index 31da8fd2..9856c032 100644 --- a/cmd/peerswap-plugin/main.go +++ b/cmd/peerswap-plugin/main.go @@ -28,6 +28,7 @@ import ( "github.com/elementsproject/peerswap/onchain" "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/poll" + "github.com/elementsproject/peerswap/premium" "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/txwatcher" "github.com/elementsproject/peerswap/wallet" @@ -327,6 +328,10 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro // Manager for send message retry. mesmgr := messages.NewManager() + ps, err := premium.NewSetting(swapDb) + if err != nil { + return err + } swapServices := swap.NewSwapServices(swapStore, requestedSwapStore, @@ -342,6 +347,7 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro liquidOnChainService, liquidOnChainService, liquidTxWatcher, + ps, ) swapService := swap.NewSwapService(swapServices) @@ -370,12 +376,12 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro if err != nil { return err } - pollService := poll.NewService(1*time.Hour, 2*time.Hour, pollStore, lightningPlugin, pol, lightningPlugin, supportedAssets) + pollService := poll.NewService(1*time.Hour, 2*time.Hour, pollStore, lightningPlugin, pol, lightningPlugin, supportedAssets, ps) pollService.Start() defer pollService.Stop() sp := swap.NewRequestedSwapsPrinter(requestedSwapStore) - lightningPlugin.SetupClients(liquidRpcWallet, swapService, pol, sp, bitcoinCli, bitcoinOnChainService, pollService) + lightningPlugin.SetupClients(liquidRpcWallet, swapService, pol, sp, bitcoinCli, bitcoinOnChainService, pollService, ps) // We are ready to accept and handle requests. // FIXME: Once we reworked the recovery service (non-blocking) we want to diff --git a/cmd/peerswaplnd/peerswapd/main.go b/cmd/peerswaplnd/peerswapd/main.go index 04554373..c4377c5f 100644 --- a/cmd/peerswaplnd/peerswapd/main.go +++ b/cmd/peerswaplnd/peerswapd/main.go @@ -21,6 +21,7 @@ import ( "github.com/elementsproject/peerswap/lnd" "github.com/elementsproject/peerswap/log" "github.com/elementsproject/peerswap/lwk" + "github.com/elementsproject/peerswap/premium" "github.com/elementsproject/peerswap/version" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" @@ -316,6 +317,11 @@ func run() error { // Manager for send message retry. mesmgr := messages.NewManager() + ps, err := premium.NewSetting(swapDb) + if err != nil { + return err + } + swapServices := swap.NewSwapServices(swapStore, requestedSwapStore, lnd, @@ -330,6 +336,7 @@ func run() error { liquidOnChainService, liquidOnChainService, liquidTxWatcher, + ps, ) swapService := swap.NewSwapService(swapServices) @@ -365,7 +372,7 @@ func run() error { if err != nil { return err } - pollService := poll.NewService(1*time.Hour, 2*time.Hour, pollStore, lnd, pol, lnd, supportedAssets) + pollService := poll.NewService(1*time.Hour, 2*time.Hour, pollStore, lnd, pol, lnd, supportedAssets, ps) pollService.Start() defer pollService.Stop() @@ -388,6 +395,7 @@ func run() error { pol, liquidCli, lnrpc.NewLightningClient(cc), + ps, sigChan, ) diff --git a/cmd/peerswaplnd/pscli/main.go b/cmd/peerswaplnd/pscli/main.go index 3c644bc8..cf139f70 100644 --- a/cmd/peerswaplnd/pscli/main.go +++ b/cmd/peerswaplnd/pscli/main.go @@ -31,7 +31,8 @@ func main() { listPeersCommand, reloadPolicyFileCommand, listRequestedSwapsCommand, liquidGetBalanceCommand, liquidGetAddressCommand, liquidSendToAddressCommand, stopCommand, listActiveSwapsCommand, allowSwapRequestsCommand, addPeerCommand, removePeerCommand, - addSusPeerCommand, removeSusPeerCommand, + addSusPeerCommand, removeSusPeerCommand, getDefaultPremiumRateCommand, updateDefaultPremiumRateCommand, + getPeerPremiumRateCommand, updatePremiumRateCommand, } app.Version = fmt.Sprintf("commit: %s", GitCommit) err := app.Run(os.Args) @@ -54,7 +55,7 @@ var ( } assetFlag = cli.StringFlag{ Name: "asset", - Usage: "asset to swap with: 'btc' | 'lbtc'", + Usage: "asset to swap with: 'BTC' | 'LBTC'", Required: true, } swapIdFlag = cli.StringFlag{ @@ -78,6 +79,21 @@ var ( Usage: "premium limit for a swap", Required: false, } + operationFlag = cli.StringFlag{ + Name: "operation", + Usage: "operation type: 'SWAP_IN' | 'SWAP_OUT'", + Required: true, + } + rateFlag = cli.Int64Flag{ + Name: "rate", + Usage: "premium rate in ppm", + Required: true, + } + nodeIdFlag = cli.StringFlag{ + Name: "node_id", + Usage: "node ID of the peer", + Required: true, + } swapOutCommand = cli.Command{ Name: "swapout", @@ -209,6 +225,46 @@ var ( Flags: []cli.Flag{}, Action: stopPeerswap, } + getDefaultPremiumRateCommand = cli.Command{ + Name: "getdefaultpremiumrate", + Usage: "Get the default premium rate for a specific asset and operation", + Flags: []cli.Flag{ + assetFlag, + operationFlag, + }, + Action: getDefaultPremiumRate, + } + updateDefaultPremiumRateCommand = cli.Command{ + Name: "updatedefaultpremiumrate", + Usage: "Update the default premium rate for a specific asset and operation", + Flags: []cli.Flag{ + assetFlag, + operationFlag, + rateFlag, + }, + Action: updateDefaultPremiumRate, + } + getPeerPremiumRateCommand = cli.Command{ + Name: "getpeerpremiumrate", + Usage: "Get the premium rate for a specific peer, asset, and operation", + Flags: []cli.Flag{ + nodeIdFlag, + assetFlag, + operationFlag, + }, + Action: getPeerPremiumRate, + } + updatePremiumRateCommand = cli.Command{ + Name: "updatepremiumrate", + Usage: "Update the premium rate for a specific peer, asset, and operation", + Flags: []cli.Flag{ + nodeIdFlag, + assetFlag, + operationFlag, + rateFlag, + }, + Action: updatePremiumRate, + } ) func swapIn(ctx *cli.Context) error { @@ -490,6 +546,86 @@ func stopPeerswap(ctx *cli.Context) error { return nil } +func getDefaultPremiumRate(ctx *cli.Context) error { + client, cleanup, err := getClient(ctx) + if err != nil { + return err + } + defer cleanup() + + res, err := client.GetDefaultPremiumRate(context.Background(), &peerswaprpc.GetDefaultPremiumRateRequest{ + Asset: peerswaprpc.AssetType(peerswaprpc.AssetType_value[ctx.String(assetFlag.Name)]), + Operation: peerswaprpc.OperationType(peerswaprpc.OperationType_value[ctx.String(operationFlag.Name)]), + }) + if err != nil { + return err + } + printRespJSON(res) + return nil +} + +func updateDefaultPremiumRate(ctx *cli.Context) error { + client, cleanup, err := getClient(ctx) + if err != nil { + return err + } + defer cleanup() + + res, err := client.UpdateDefaultPremiumRate(context.Background(), &peerswaprpc.UpdateDefaultPremiumRateRequest{ + Rate: &peerswaprpc.PremiumRate{ + Asset: peerswaprpc.AssetType(peerswaprpc.AssetType_value[ctx.String(assetFlag.Name)]), + Operation: peerswaprpc.OperationType(peerswaprpc.OperationType_value[ctx.String(operationFlag.Name)]), + PremiumRatePpm: ctx.Int64(rateFlag.Name), + }, + }) + if err != nil { + return err + } + printRespJSON(res) + return nil +} + +func getPeerPremiumRate(ctx *cli.Context) error { + client, cleanup, err := getClient(ctx) + if err != nil { + return err + } + defer cleanup() + + res, err := client.GetPremiumRate(context.Background(), &peerswaprpc.GetPremiumRateRequest{ + NodeId: ctx.String(nodeIdFlag.Name), + Asset: peerswaprpc.AssetType(peerswaprpc.AssetType_value[ctx.String(assetFlag.Name)]), + Operation: peerswaprpc.OperationType(peerswaprpc.OperationType_value[ctx.String(operationFlag.Name)]), + }) + if err != nil { + return err + } + printRespJSON(res) + return nil +} + +func updatePremiumRate(ctx *cli.Context) error { + client, cleanup, err := getClient(ctx) + if err != nil { + return err + } + defer cleanup() + + res, err := client.UpdatePremiumRate(context.Background(), &peerswaprpc.UpdatePremiumRateRequest{ + NodeId: ctx.String(nodeIdFlag.Name), + Rate: &peerswaprpc.PremiumRate{ + Asset: peerswaprpc.AssetType(peerswaprpc.AssetType_value[ctx.String(assetFlag.Name)]), + Operation: peerswaprpc.OperationType(peerswaprpc.OperationType_value[ctx.String(operationFlag.Name)]), + PremiumRatePpm: ctx.Int64(rateFlag.Name), + }, + }) + if err != nil { + return err + } + printRespJSON(res) + return nil +} + func getClient(ctx *cli.Context) (peerswaprpc.PeerSwapClient, func(), error) { rpcServer := ctx.GlobalString("rpchost") diff --git a/docs/usage.md b/docs/usage.md index a6b76e99..836005d1 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -95,6 +95,65 @@ For LND: pscli swapin --channel_id [chan_id] --sat_amt [amount in sats] --asset [btc or lbtc] --premium_limit [premium limit in sats] ``` +## Premium + +The premium rate is the rate applied during a swap. There are default premium rates and peer-specific premium rates. + +### Get Default Premium Rate + +To get the default premium rate, use the following command: + +For CLN: +```bash +lightning-cli peerswap-getdefaultpremiumrate --asset [btc|lbtc] --operation [swap_in|swap_out] +``` + +For LND: +```bash +pscli getdefaultpremiumrate --asset [btc|lbtc] --operation [swap_in|swap_out] +``` + +### Set Default Premium Rate + +To set the default premium rate, use the following command: + +For CLN: +```bash +lightning-cli peerswap-setdefaultpremiumrate --asset [btc|lbtc] --operation [swap_in|swap_out] --rate [premium_rate_ppm] +``` + +For LND: +```bash +pscli updatedefaultpremiumrate --asset [btc|lbtc] --operation [swap_in|swap_out] --rate [premium_rate_ppm] +``` + +### Get Peer-Specific Premium Rate + +To get the premium rate for a specific peer, use the following command: + +For CLN: +```bash +lightning-cli peerswap-getpremiumrate --node_id [peer_id] --asset [BTC|LBTC] --operation [SWAP_IN|SWAP_OUT] +``` + +For LND: +```bash +pscli getpeerpremiumrate --node_id [node_id] --asset [BTC|LBTC] --operation [SWAP_IN|SWAP_OUT] +``` + +### Set Peer-Specific Premium Rate + +To set the premium rate for a specific peer, use the following command: + +For CLN: +```bash +lightning-cli peerswap-setpremiumrate --node_id [peer_id] --asset [BTC|LBTC] --operation [SWAP_IN|SWAP_OUT] --rate [premium_rate_ppm] +``` + +For LND: +```bash +pscli updatepremiumrate --node_id [node_id] --asset [BTC|LBTC] --operation [SWAP_IN|SWAP_OUT] --rate [premium_rate_ppm] +``` ## Misc diff --git a/flake.lock b/flake.lock index e2547de4..23ea66d5 100644 --- a/flake.lock +++ b/flake.lock @@ -102,17 +102,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1733858793, - "narHash": "sha256-jQNGd1Kmey15jq5U36m8pG+lVsxSJlDj1bJ167BjHQ4=", + "lastModified": 1735421166, + "narHash": "sha256-osjPRtm1MrspsIhrqQ0ZpZZg9wNlX3/bcxMdtCmIycQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4f0dadbf38ee4cf4cc38cbc232b7708fddf965bc", + "rev": "8fb763e05c822cb5b180cbe072ff7971da8097e7", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "4f0dadbf38ee4cf4cc38cbc232b7708fddf965bc", "type": "github" } }, diff --git a/go.mod b/go.mod index b684bb34..b864b697 100644 --- a/go.mod +++ b/go.mod @@ -157,7 +157,6 @@ require ( github.com/lightningnetwork/lnd/ticker v1.1.0 // indirect github.com/lightningnetwork/lnd/tlv v1.0.3 // indirect github.com/samber/lo v1.47.0 - gopkg.in/ini.v1 v1.67.0 ) // This fork contains some options we need to reconnect to lnd. diff --git a/go.sum b/go.sum index 5f9ac7ba..bbaeaa50 100644 --- a/go.sum +++ b/go.sum @@ -1167,8 +1167,6 @@ 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 72ffad76..4251e126 100644 --- a/peerswaprpc/format.go +++ b/peerswaprpc/format.go @@ -13,12 +13,6 @@ func GetPolicyMessage(p policy.Policy) *Policy { 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 64d89416..242658a0 100644 --- a/peerswaprpc/peerswaprpc.pb.go +++ b/peerswaprpc/peerswaprpc.pb.go @@ -20,6 +20,106 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +// Enum for supported asset types. +type AssetType int32 + +const ( + AssetType_ASSET_UNSPECIFIED AssetType = 0 // Unspecified asset type. + AssetType_BTC AssetType = 1 // Bitcoin asset type. + AssetType_LBTC AssetType = 2 // Liquid Bitcoin asset type. +) + +// Enum value maps for AssetType. +var ( + AssetType_name = map[int32]string{ + 0: "ASSET_UNSPECIFIED", + 1: "BTC", + 2: "LBTC", + } + AssetType_value = map[string]int32{ + "ASSET_UNSPECIFIED": 0, + "BTC": 1, + "LBTC": 2, + } +) + +func (x AssetType) Enum() *AssetType { + p := new(AssetType) + *p = x + return p +} + +func (x AssetType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (AssetType) Descriptor() protoreflect.EnumDescriptor { + return file_peerswaprpc_peerswaprpc_proto_enumTypes[0].Descriptor() +} + +func (AssetType) Type() protoreflect.EnumType { + return &file_peerswaprpc_peerswaprpc_proto_enumTypes[0] +} + +func (x AssetType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use AssetType.Descriptor instead. +func (AssetType) EnumDescriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{0} +} + +// Enum for supported operation types. +type OperationType int32 + +const ( + OperationType_OPERATION_UNSPECIFIED OperationType = 0 // Unspecified operation type. + OperationType_SWAP_IN OperationType = 1 // Swap in operation type. + OperationType_SWAP_OUT OperationType = 2 // Swap out operation type. +) + +// Enum value maps for OperationType. +var ( + OperationType_name = map[int32]string{ + 0: "OPERATION_UNSPECIFIED", + 1: "SWAP_IN", + 2: "SWAP_OUT", + } + OperationType_value = map[string]int32{ + "OPERATION_UNSPECIFIED": 0, + "SWAP_IN": 1, + "SWAP_OUT": 2, + } +) + +func (x OperationType) Enum() *OperationType { + p := new(OperationType) + *p = x + return p +} + +func (x OperationType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (OperationType) Descriptor() protoreflect.EnumDescriptor { + return file_peerswaprpc_peerswaprpc_proto_enumTypes[1].Descriptor() +} + +func (OperationType) Type() protoreflect.EnumType { + return &file_peerswaprpc_peerswaprpc_proto_enumTypes[1] +} + +func (x OperationType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use OperationType.Descriptor instead. +func (OperationType) EnumDescriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{1} +} + type RequestedSwap_SwapType int32 const ( @@ -50,11 +150,11 @@ func (x RequestedSwap_SwapType) String() string { } func (RequestedSwap_SwapType) Descriptor() protoreflect.EnumDescriptor { - return file_peerswaprpc_peerswaprpc_proto_enumTypes[0].Descriptor() + return file_peerswaprpc_peerswaprpc_proto_enumTypes[2].Descriptor() } func (RequestedSwap_SwapType) Type() protoreflect.EnumType { - return &file_peerswaprpc_peerswaprpc_proto_enumTypes[0] + return &file_peerswaprpc_peerswaprpc_proto_enumTypes[2] } func (x RequestedSwap_SwapType) Number() protoreflect.EnumNumber { @@ -1301,82 +1401,6 @@ 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 @@ -1389,13 +1413,13 @@ type PeerSwapPeer struct { 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"` + PeerPremium *PeerPremium `protobuf:"bytes,8,opt,name=peer_premium,json=peerPremium,proto3" json:"peer_premium,omitempty"` } func (x *PeerSwapPeer) Reset() { *x = PeerSwapPeer{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1408,7 +1432,7 @@ func (x *PeerSwapPeer) String() string { func (*PeerSwapPeer) ProtoMessage() {} func (x *PeerSwapPeer) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[23] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1421,7 +1445,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{24} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{23} } func (x *PeerSwapPeer) GetNodeId() string { @@ -1473,9 +1497,9 @@ func (x *PeerSwapPeer) GetPaidFee() uint64 { return 0 } -func (x *PeerSwapPeer) GetPremium() *Premium { +func (x *PeerSwapPeer) GetPeerPremium() *PeerPremium { if x != nil { - return x.Premium + return x.PeerPremium } return nil } @@ -1494,7 +1518,7 @@ type PeerSwapPeerChannel struct { func (x *PeerSwapPeerChannel) Reset() { *x = PeerSwapPeerChannel{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1507,7 +1531,7 @@ func (x *PeerSwapPeerChannel) String() string { func (*PeerSwapPeerChannel) ProtoMessage() {} func (x *PeerSwapPeerChannel) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[24] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1520,7 +1544,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{25} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{24} } func (x *PeerSwapPeerChannel) GetChannelId() uint64 { @@ -1565,7 +1589,7 @@ type SwapStats struct { func (x *SwapStats) Reset() { *x = SwapStats{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1578,7 +1602,7 @@ func (x *SwapStats) String() string { func (*SwapStats) ProtoMessage() {} func (x *SwapStats) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[25] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1591,7 +1615,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{26} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{25} } func (x *SwapStats) GetSwapsOut() uint64 { @@ -1633,15 +1657,12 @@ type Policy struct { 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() { *x = Policy{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[27] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1654,7 +1675,7 @@ func (x *Policy) String() string { func (*Policy) ProtoMessage() {} func (x *Policy) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[27] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[26] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1667,7 +1688,7 @@ func (x *Policy) ProtoReflect() protoreflect.Message { // Deprecated: Use Policy.ProtoReflect.Descriptor instead. func (*Policy) Descriptor() ([]byte, []int) { - return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{27} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{26} } func (x *Policy) GetReserveOnchainMsat() uint64 { @@ -1712,13 +1733,6 @@ func (x *Policy) GetSuspiciousPeerList() []string { return nil } -func (x *Policy) GetDefaultPremium() *Premium { - if x != nil { - return x.DefaultPremium - } - return nil -} - type AllowSwapRequestsRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1730,7 +1744,7 @@ type AllowSwapRequestsRequest struct { func (x *AllowSwapRequestsRequest) Reset() { *x = AllowSwapRequestsRequest{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[28] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1743,7 +1757,7 @@ func (x *AllowSwapRequestsRequest) String() string { func (*AllowSwapRequestsRequest) ProtoMessage() {} func (x *AllowSwapRequestsRequest) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[28] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[27] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1756,7 +1770,7 @@ func (x *AllowSwapRequestsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use AllowSwapRequestsRequest.ProtoReflect.Descriptor instead. func (*AllowSwapRequestsRequest) Descriptor() ([]byte, []int) { - return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{28} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{27} } func (x *AllowSwapRequestsRequest) GetAllow() bool { @@ -1777,7 +1791,7 @@ type AllowSwapRequestsResponse struct { func (x *AllowSwapRequestsResponse) Reset() { *x = AllowSwapRequestsResponse{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[29] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1790,7 +1804,7 @@ func (x *AllowSwapRequestsResponse) String() string { func (*AllowSwapRequestsResponse) ProtoMessage() {} func (x *AllowSwapRequestsResponse) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[29] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[28] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1803,7 +1817,7 @@ func (x *AllowSwapRequestsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use AllowSwapRequestsResponse.ProtoReflect.Descriptor instead. func (*AllowSwapRequestsResponse) Descriptor() ([]byte, []int) { - return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{29} + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{28} } func (x *AllowSwapRequestsResponse) GetAllow() bool { @@ -1822,7 +1836,7 @@ type Empty struct { func (x *Empty) Reset() { *x = Empty{} if protoimpl.UnsafeEnabled { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[30] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1835,7 +1849,7 @@ func (x *Empty) String() string { func (*Empty) ProtoMessage() {} func (x *Empty) ProtoReflect() protoreflect.Message { - mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[30] + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[29] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1848,9 +1862,365 @@ func (x *Empty) ProtoReflect() protoreflect.Message { // Deprecated: Use Empty.ProtoReflect.Descriptor instead. func (*Empty) Descriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{29} +} + +// PremiumRate defines the premium rate for a specific asset and operation. +type PremiumRate struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Asset AssetType `protobuf:"varint,1,opt,name=asset,proto3,enum=peerswap.AssetType" json:"asset,omitempty"` // Asset type (e.g., BTC, LBTC). + Operation OperationType `protobuf:"varint,2,opt,name=operation,proto3,enum=peerswap.OperationType" json:"operation,omitempty"` // Operation type (e.g., SWAP_IN, SWAP_OUT). + PremiumRatePpm int64 `protobuf:"varint,3,opt,name=premium_rate_ppm,json=premiumRatePpm,proto3" json:"premium_rate_ppm,omitempty"` // Premium rate in parts per million (PPM). +} + +func (x *PremiumRate) Reset() { + *x = PremiumRate{} + if protoimpl.UnsafeEnabled { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[30] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PremiumRate) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PremiumRate) ProtoMessage() {} + +func (x *PremiumRate) ProtoReflect() protoreflect.Message { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[30] + 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 PremiumRate.ProtoReflect.Descriptor instead. +func (*PremiumRate) Descriptor() ([]byte, []int) { return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{30} } +func (x *PremiumRate) GetAsset() AssetType { + if x != nil { + return x.Asset + } + return AssetType_ASSET_UNSPECIFIED +} + +func (x *PremiumRate) GetOperation() OperationType { + if x != nil { + return x.Operation + } + return OperationType_OPERATION_UNSPECIFIED +} + +func (x *PremiumRate) GetPremiumRatePpm() int64 { + if x != nil { + return x.PremiumRatePpm + } + return 0 +} + +// Premium configuration per peer. +// If no configuration exists, the default configuration is used. +// Unique by AssetType and OperationType. No explicit constraints on +// this data structure; consistency depends on peerswap implementation. +type PeerPremium 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"` // Node ID of the peer. + Rates []*PremiumRate `protobuf:"bytes,2,rep,name=rates,proto3" json:"rates,omitempty"` // List of premium rates for this peer. +} + +func (x *PeerPremium) Reset() { + *x = PeerPremium{} + if protoimpl.UnsafeEnabled { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[31] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PeerPremium) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PeerPremium) ProtoMessage() {} + +func (x *PeerPremium) ProtoReflect() protoreflect.Message { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[31] + 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 PeerPremium.ProtoReflect.Descriptor instead. +func (*PeerPremium) Descriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{31} +} + +func (x *PeerPremium) GetNodeId() string { + if x != nil { + return x.NodeId + } + return "" +} + +func (x *PeerPremium) GetRates() []*PremiumRate { + if x != nil { + return x.Rates + } + return nil +} + +// Request for GetPremiumRate. +// Errors: +// NOT_FOUND: No premium rate is configured for the specified peer, asset, and operation. +// INVALID_ARGUMENT: Invalid peer ID, asset, or operation specified. +type GetPremiumRateRequest 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"` // Node ID of the peer. + Asset AssetType `protobuf:"varint,2,opt,name=asset,proto3,enum=peerswap.AssetType" json:"asset,omitempty"` // Asset type (e.g., BTC, LBTC). + Operation OperationType `protobuf:"varint,3,opt,name=operation,proto3,enum=peerswap.OperationType" json:"operation,omitempty"` // Operation type (e.g., SWAP_IN, SWAP_OUT). +} + +func (x *GetPremiumRateRequest) Reset() { + *x = GetPremiumRateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[32] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetPremiumRateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetPremiumRateRequest) ProtoMessage() {} + +func (x *GetPremiumRateRequest) ProtoReflect() protoreflect.Message { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[32] + 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 GetPremiumRateRequest.ProtoReflect.Descriptor instead. +func (*GetPremiumRateRequest) Descriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{32} +} + +func (x *GetPremiumRateRequest) GetNodeId() string { + if x != nil { + return x.NodeId + } + return "" +} + +func (x *GetPremiumRateRequest) GetAsset() AssetType { + if x != nil { + return x.Asset + } + return AssetType_ASSET_UNSPECIFIED +} + +func (x *GetPremiumRateRequest) GetOperation() OperationType { + if x != nil { + return x.Operation + } + return OperationType_OPERATION_UNSPECIFIED +} + +// Request for UpdatePremiumRate. +// Errors: +// INVALID_ARGUMENT: Invalid peer ID, asset, operation, or rate specified. +type UpdatePremiumRateRequest 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"` // Node ID of the peer. + Rate *PremiumRate `protobuf:"bytes,2,opt,name=rate,proto3" json:"rate,omitempty"` // The new premium rate to be updated. +} + +func (x *UpdatePremiumRateRequest) Reset() { + *x = UpdatePremiumRateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[33] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdatePremiumRateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdatePremiumRateRequest) ProtoMessage() {} + +func (x *UpdatePremiumRateRequest) ProtoReflect() protoreflect.Message { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[33] + 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 UpdatePremiumRateRequest.ProtoReflect.Descriptor instead. +func (*UpdatePremiumRateRequest) Descriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{33} +} + +func (x *UpdatePremiumRateRequest) GetNodeId() string { + if x != nil { + return x.NodeId + } + return "" +} + +func (x *UpdatePremiumRateRequest) GetRate() *PremiumRate { + if x != nil { + return x.Rate + } + return nil +} + +// Request for GetDefaultPremiumRate. +// Errors: +// INVALID_ARGUMENT: Invalid asset or operation specified. +type GetDefaultPremiumRateRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Asset AssetType `protobuf:"varint,2,opt,name=asset,proto3,enum=peerswap.AssetType" json:"asset,omitempty"` // Asset type (e.g., BTC, LBTC). + Operation OperationType `protobuf:"varint,3,opt,name=operation,proto3,enum=peerswap.OperationType" json:"operation,omitempty"` // Operation type (e.g., SWAP_IN, SWAP_OUT). +} + +func (x *GetDefaultPremiumRateRequest) Reset() { + *x = GetDefaultPremiumRateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[34] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetDefaultPremiumRateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetDefaultPremiumRateRequest) ProtoMessage() {} + +func (x *GetDefaultPremiumRateRequest) ProtoReflect() protoreflect.Message { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[34] + 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 GetDefaultPremiumRateRequest.ProtoReflect.Descriptor instead. +func (*GetDefaultPremiumRateRequest) Descriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{34} +} + +func (x *GetDefaultPremiumRateRequest) GetAsset() AssetType { + if x != nil { + return x.Asset + } + return AssetType_ASSET_UNSPECIFIED +} + +func (x *GetDefaultPremiumRateRequest) GetOperation() OperationType { + if x != nil { + return x.Operation + } + return OperationType_OPERATION_UNSPECIFIED +} + +// Request for UpdateDefaultPremiumRate. +// Errors: +// INVALID_ARGUMENT: Invalid asset, operation, or rate specified. +type UpdateDefaultPremiumRateRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Rate *PremiumRate `protobuf:"bytes,2,opt,name=rate,proto3" json:"rate,omitempty"` // The new premium rate to be updated. +} + +func (x *UpdateDefaultPremiumRateRequest) Reset() { + *x = UpdateDefaultPremiumRateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[35] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateDefaultPremiumRateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateDefaultPremiumRateRequest) ProtoMessage() {} + +func (x *UpdateDefaultPremiumRateRequest) ProtoReflect() protoreflect.Message { + mi := &file_peerswaprpc_peerswaprpc_proto_msgTypes[35] + 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 UpdateDefaultPremiumRateRequest.ProtoReflect.Descriptor instead. +func (*UpdateDefaultPremiumRateRequest) Descriptor() ([]byte, []int) { + return file_peerswaprpc_peerswaprpc_proto_rawDescGZIP(), []int{35} +} + +func (x *UpdateDefaultPremiumRateRequest) GetRate() *PremiumRate { + if x != nil { + return x.Rate + } + return nil +} + var File_peerswaprpc_peerswaprpc_proto protoreflect.FileDescriptor var file_peerswaprpc_peerswaprpc_proto_rawDesc = []byte{ @@ -1987,24 +2357,7 @@ 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, 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, + 0x6d, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xef, 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, @@ -2024,133 +2377,202 @@ 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, - 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, 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, 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, + 0x38, 0x0a, 0x0c, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x18, + 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, + 0x2e, 0x50, 0x65, 0x65, 0x72, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x0b, 0x70, 0x65, + 0x65, 0x72, 0x50, 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, 0x9c, 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, 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, 0x22, 0x99, 0x01, 0x0a, 0x0b, 0x50, + 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x12, 0x29, 0x0a, 0x05, 0x61, 0x73, + 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x65, 0x72, + 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, 0x73, 0x73, 0x65, 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05, + 0x61, 0x73, 0x73, 0x65, 0x74, 0x12, 0x35, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, + 0x77, 0x61, 0x70, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, + 0x65, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x28, 0x0a, 0x10, + 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x70, 0x70, 0x6d, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, + 0x61, 0x74, 0x65, 0x50, 0x70, 0x6d, 0x22, 0x53, 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x50, 0x72, + 0x65, 0x6d, 0x69, 0x75, 0x6d, 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, 0x2b, + 0x0a, 0x05, 0x72, 0x61, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, + 0x52, 0x61, 0x74, 0x65, 0x52, 0x05, 0x72, 0x61, 0x74, 0x65, 0x73, 0x22, 0x92, 0x01, 0x0a, 0x15, + 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 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, 0x29, + 0x0a, 0x05, 0x61, 0x73, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, 0x73, 0x73, 0x65, 0x74, 0x54, 0x79, + 0x70, 0x65, 0x52, 0x05, 0x61, 0x73, 0x73, 0x65, 0x74, 0x12, 0x35, 0x0a, 0x09, 0x6f, 0x70, 0x65, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x70, + 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x22, 0x5e, 0x0a, 0x18, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, + 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 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, 0x29, 0x0a, 0x04, 0x72, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, + 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, 0x04, 0x72, 0x61, 0x74, 0x65, + 0x22, 0x80, 0x01, 0x0a, 0x1c, 0x47, 0x65, 0x74, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x50, + 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x29, 0x0a, 0x05, 0x61, 0x73, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x13, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x41, 0x73, 0x73, 0x65, + 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05, 0x61, 0x73, 0x73, 0x65, 0x74, 0x12, 0x35, 0x0a, 0x09, + 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, + 0x17, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x22, 0x4c, 0x0a, 0x1f, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x65, 0x66, + 0x61, 0x75, 0x6c, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x29, 0x0a, 0x04, 0x72, 0x61, 0x74, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, + 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, 0x04, 0x72, 0x61, 0x74, + 0x65, 0x2a, 0x35, 0x0a, 0x09, 0x41, 0x73, 0x73, 0x65, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x15, + 0x0a, 0x11, 0x41, 0x53, 0x53, 0x45, 0x54, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, + 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x42, 0x54, 0x43, 0x10, 0x01, 0x12, 0x08, + 0x0a, 0x04, 0x4c, 0x42, 0x54, 0x43, 0x10, 0x02, 0x2a, 0x45, 0x0a, 0x0d, 0x4f, 0x70, 0x65, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x19, 0x0a, 0x15, 0x4f, 0x50, 0x45, + 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, + 0x45, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x57, 0x41, 0x50, 0x5f, 0x49, 0x4e, 0x10, + 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x53, 0x57, 0x41, 0x50, 0x5f, 0x4f, 0x55, 0x54, 0x10, 0x02, 0x32, + 0xea, 0x0b, 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, 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, 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, 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, + 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, 0x56, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x12, 0x26, 0x2e, 0x70, 0x65, + 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, + 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x12, 0x5c, 0x0a, 0x18, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, + 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x12, 0x29, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, + 0x70, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x50, + 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x72, 0x65, + 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x12, 0x48, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x12, 0x1f, 0x2e, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, + 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x65, + 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, + 0x74, 0x65, 0x12, 0x4e, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x72, 0x65, 0x6d, + 0x69, 0x75, 0x6d, 0x52, 0x61, 0x74, 0x65, 0x12, 0x22, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x73, 0x77, + 0x61, 0x70, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, + 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x65, + 0x65, 0x72, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x52, 0x61, + 0x74, 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 ( @@ -2165,96 +2587,119 @@ func file_peerswaprpc_peerswaprpc_proto_rawDescGZIP() []byte { return file_peerswaprpc_peerswaprpc_proto_rawDescData } -var file_peerswaprpc_peerswaprpc_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_peerswaprpc_peerswaprpc_proto_msgTypes = make([]protoimpl.MessageInfo, 32) +var file_peerswaprpc_peerswaprpc_proto_enumTypes = make([]protoimpl.EnumInfo, 3) +var file_peerswaprpc_peerswaprpc_proto_msgTypes = make([]protoimpl.MessageInfo, 37) var file_peerswaprpc_peerswaprpc_proto_goTypes = []interface{}{ - (RequestedSwap_SwapType)(0), // 0: peerswap.RequestedSwap.SwapType - (*GetAddressRequest)(nil), // 1: peerswap.GetAddressRequest - (*GetAddressResponse)(nil), // 2: peerswap.GetAddressResponse - (*GetBalanceRequest)(nil), // 3: peerswap.GetBalanceRequest - (*GetBalanceResponse)(nil), // 4: peerswap.GetBalanceResponse - (*SendToAddressRequest)(nil), // 5: peerswap.SendToAddressRequest - (*SendToAddressResponse)(nil), // 6: peerswap.SendToAddressResponse - (*SwapOutRequest)(nil), // 7: peerswap.SwapOutRequest - (*SwapOutResponse)(nil), // 8: peerswap.SwapOutResponse - (*SwapInRequest)(nil), // 9: peerswap.SwapInRequest - (*SwapResponse)(nil), // 10: peerswap.SwapResponse - (*GetSwapRequest)(nil), // 11: peerswap.GetSwapRequest - (*ListSwapsRequest)(nil), // 12: peerswap.ListSwapsRequest - (*ListSwapsResponse)(nil), // 13: peerswap.ListSwapsResponse - (*ListPeersRequest)(nil), // 14: peerswap.ListPeersRequest - (*ListPeersResponse)(nil), // 15: peerswap.ListPeersResponse - (*ReloadPolicyFileRequest)(nil), // 16: peerswap.ReloadPolicyFileRequest - (*AddPeerRequest)(nil), // 17: peerswap.AddPeerRequest - (*RemovePeerRequest)(nil), // 18: peerswap.RemovePeerRequest - (*ListRequestedSwapsRequest)(nil), // 19: peerswap.ListRequestedSwapsRequest - (*ListRequestedSwapsResponse)(nil), // 20: peerswap.ListRequestedSwapsResponse - (*RequestSwapList)(nil), // 21: peerswap.RequestSwapList - (*RequestedSwap)(nil), // 22: peerswap.RequestedSwap - (*PrettyPrintSwap)(nil), // 23: peerswap.PrettyPrintSwap - (*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 - (*Empty)(nil), // 31: peerswap.Empty - nil, // 32: peerswap.ListRequestedSwapsResponse.RequestedSwapsEntry + (AssetType)(0), // 0: peerswap.AssetType + (OperationType)(0), // 1: peerswap.OperationType + (RequestedSwap_SwapType)(0), // 2: peerswap.RequestedSwap.SwapType + (*GetAddressRequest)(nil), // 3: peerswap.GetAddressRequest + (*GetAddressResponse)(nil), // 4: peerswap.GetAddressResponse + (*GetBalanceRequest)(nil), // 5: peerswap.GetBalanceRequest + (*GetBalanceResponse)(nil), // 6: peerswap.GetBalanceResponse + (*SendToAddressRequest)(nil), // 7: peerswap.SendToAddressRequest + (*SendToAddressResponse)(nil), // 8: peerswap.SendToAddressResponse + (*SwapOutRequest)(nil), // 9: peerswap.SwapOutRequest + (*SwapOutResponse)(nil), // 10: peerswap.SwapOutResponse + (*SwapInRequest)(nil), // 11: peerswap.SwapInRequest + (*SwapResponse)(nil), // 12: peerswap.SwapResponse + (*GetSwapRequest)(nil), // 13: peerswap.GetSwapRequest + (*ListSwapsRequest)(nil), // 14: peerswap.ListSwapsRequest + (*ListSwapsResponse)(nil), // 15: peerswap.ListSwapsResponse + (*ListPeersRequest)(nil), // 16: peerswap.ListPeersRequest + (*ListPeersResponse)(nil), // 17: peerswap.ListPeersResponse + (*ReloadPolicyFileRequest)(nil), // 18: peerswap.ReloadPolicyFileRequest + (*AddPeerRequest)(nil), // 19: peerswap.AddPeerRequest + (*RemovePeerRequest)(nil), // 20: peerswap.RemovePeerRequest + (*ListRequestedSwapsRequest)(nil), // 21: peerswap.ListRequestedSwapsRequest + (*ListRequestedSwapsResponse)(nil), // 22: peerswap.ListRequestedSwapsResponse + (*RequestSwapList)(nil), // 23: peerswap.RequestSwapList + (*RequestedSwap)(nil), // 24: peerswap.RequestedSwap + (*PrettyPrintSwap)(nil), // 25: peerswap.PrettyPrintSwap + (*PeerSwapPeer)(nil), // 26: peerswap.PeerSwapPeer + (*PeerSwapPeerChannel)(nil), // 27: peerswap.PeerSwapPeerChannel + (*SwapStats)(nil), // 28: peerswap.SwapStats + (*Policy)(nil), // 29: peerswap.Policy + (*AllowSwapRequestsRequest)(nil), // 30: peerswap.AllowSwapRequestsRequest + (*AllowSwapRequestsResponse)(nil), // 31: peerswap.AllowSwapRequestsResponse + (*Empty)(nil), // 32: peerswap.Empty + (*PremiumRate)(nil), // 33: peerswap.PremiumRate + (*PeerPremium)(nil), // 34: peerswap.PeerPremium + (*GetPremiumRateRequest)(nil), // 35: peerswap.GetPremiumRateRequest + (*UpdatePremiumRateRequest)(nil), // 36: peerswap.UpdatePremiumRateRequest + (*GetDefaultPremiumRateRequest)(nil), // 37: peerswap.GetDefaultPremiumRateRequest + (*UpdateDefaultPremiumRateRequest)(nil), // 38: peerswap.UpdateDefaultPremiumRateRequest + nil, // 39: peerswap.ListRequestedSwapsResponse.RequestedSwapsEntry } 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 - 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 - 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 + 25, // 0: peerswap.SwapOutResponse.swap:type_name -> peerswap.PrettyPrintSwap + 25, // 1: peerswap.SwapResponse.swap:type_name -> peerswap.PrettyPrintSwap + 25, // 2: peerswap.ListSwapsResponse.swaps:type_name -> peerswap.PrettyPrintSwap + 26, // 3: peerswap.ListPeersResponse.peers:type_name -> peerswap.PeerSwapPeer + 39, // 4: peerswap.ListRequestedSwapsResponse.requested_swaps:type_name -> peerswap.ListRequestedSwapsResponse.RequestedSwapsEntry + 24, // 5: peerswap.RequestSwapList.requested_swaps:type_name -> peerswap.RequestedSwap + 2, // 6: peerswap.RequestedSwap.swap_type:type_name -> peerswap.RequestedSwap.SwapType + 27, // 7: peerswap.PeerSwapPeer.channels:type_name -> peerswap.PeerSwapPeerChannel + 28, // 8: peerswap.PeerSwapPeer.as_sender:type_name -> peerswap.SwapStats + 28, // 9: peerswap.PeerSwapPeer.as_receiver:type_name -> peerswap.SwapStats + 34, // 10: peerswap.PeerSwapPeer.peer_premium:type_name -> peerswap.PeerPremium + 0, // 11: peerswap.PremiumRate.asset:type_name -> peerswap.AssetType + 1, // 12: peerswap.PremiumRate.operation:type_name -> peerswap.OperationType + 33, // 13: peerswap.PeerPremium.rates:type_name -> peerswap.PremiumRate + 0, // 14: peerswap.GetPremiumRateRequest.asset:type_name -> peerswap.AssetType + 1, // 15: peerswap.GetPremiumRateRequest.operation:type_name -> peerswap.OperationType + 33, // 16: peerswap.UpdatePremiumRateRequest.rate:type_name -> peerswap.PremiumRate + 0, // 17: peerswap.GetDefaultPremiumRateRequest.asset:type_name -> peerswap.AssetType + 1, // 18: peerswap.GetDefaultPremiumRateRequest.operation:type_name -> peerswap.OperationType + 33, // 19: peerswap.UpdateDefaultPremiumRateRequest.rate:type_name -> peerswap.PremiumRate + 23, // 20: peerswap.ListRequestedSwapsResponse.RequestedSwapsEntry.value:type_name -> peerswap.RequestSwapList + 9, // 21: peerswap.PeerSwap.SwapOut:input_type -> peerswap.SwapOutRequest + 11, // 22: peerswap.PeerSwap.SwapIn:input_type -> peerswap.SwapInRequest + 13, // 23: peerswap.PeerSwap.GetSwap:input_type -> peerswap.GetSwapRequest + 14, // 24: peerswap.PeerSwap.ListSwaps:input_type -> peerswap.ListSwapsRequest + 16, // 25: peerswap.PeerSwap.ListPeers:input_type -> peerswap.ListPeersRequest + 21, // 26: peerswap.PeerSwap.ListRequestedSwaps:input_type -> peerswap.ListRequestedSwapsRequest + 14, // 27: peerswap.PeerSwap.ListActiveSwaps:input_type -> peerswap.ListSwapsRequest + 30, // 28: peerswap.PeerSwap.AllowSwapRequests:input_type -> peerswap.AllowSwapRequestsRequest + 18, // 29: peerswap.PeerSwap.ReloadPolicyFile:input_type -> peerswap.ReloadPolicyFileRequest + 19, // 30: peerswap.PeerSwap.AddPeer:input_type -> peerswap.AddPeerRequest + 20, // 31: peerswap.PeerSwap.RemovePeer:input_type -> peerswap.RemovePeerRequest + 19, // 32: peerswap.PeerSwap.AddSusPeer:input_type -> peerswap.AddPeerRequest + 20, // 33: peerswap.PeerSwap.RemoveSusPeer:input_type -> peerswap.RemovePeerRequest + 3, // 34: peerswap.PeerSwap.LiquidGetAddress:input_type -> peerswap.GetAddressRequest + 5, // 35: peerswap.PeerSwap.LiquidGetBalance:input_type -> peerswap.GetBalanceRequest + 7, // 36: peerswap.PeerSwap.LiquidSendToAddress:input_type -> peerswap.SendToAddressRequest + 37, // 37: peerswap.PeerSwap.GetDefaultPremiumRate:input_type -> peerswap.GetDefaultPremiumRateRequest + 38, // 38: peerswap.PeerSwap.UpdateDefaultPremiumRate:input_type -> peerswap.UpdateDefaultPremiumRateRequest + 35, // 39: peerswap.PeerSwap.GetPremiumRate:input_type -> peerswap.GetPremiumRateRequest + 36, // 40: peerswap.PeerSwap.UpdatePremiumRate:input_type -> peerswap.UpdatePremiumRateRequest + 32, // 41: peerswap.PeerSwap.Stop:input_type -> peerswap.Empty + 12, // 42: peerswap.PeerSwap.SwapOut:output_type -> peerswap.SwapResponse + 12, // 43: peerswap.PeerSwap.SwapIn:output_type -> peerswap.SwapResponse + 12, // 44: peerswap.PeerSwap.GetSwap:output_type -> peerswap.SwapResponse + 15, // 45: peerswap.PeerSwap.ListSwaps:output_type -> peerswap.ListSwapsResponse + 17, // 46: peerswap.PeerSwap.ListPeers:output_type -> peerswap.ListPeersResponse + 22, // 47: peerswap.PeerSwap.ListRequestedSwaps:output_type -> peerswap.ListRequestedSwapsResponse + 15, // 48: peerswap.PeerSwap.ListActiveSwaps:output_type -> peerswap.ListSwapsResponse + 29, // 49: peerswap.PeerSwap.AllowSwapRequests:output_type -> peerswap.Policy + 29, // 50: peerswap.PeerSwap.ReloadPolicyFile:output_type -> peerswap.Policy + 29, // 51: peerswap.PeerSwap.AddPeer:output_type -> peerswap.Policy + 29, // 52: peerswap.PeerSwap.RemovePeer:output_type -> peerswap.Policy + 29, // 53: peerswap.PeerSwap.AddSusPeer:output_type -> peerswap.Policy + 29, // 54: peerswap.PeerSwap.RemoveSusPeer:output_type -> peerswap.Policy + 4, // 55: peerswap.PeerSwap.LiquidGetAddress:output_type -> peerswap.GetAddressResponse + 6, // 56: peerswap.PeerSwap.LiquidGetBalance:output_type -> peerswap.GetBalanceResponse + 8, // 57: peerswap.PeerSwap.LiquidSendToAddress:output_type -> peerswap.SendToAddressResponse + 33, // 58: peerswap.PeerSwap.GetDefaultPremiumRate:output_type -> peerswap.PremiumRate + 33, // 59: peerswap.PeerSwap.UpdateDefaultPremiumRate:output_type -> peerswap.PremiumRate + 33, // 60: peerswap.PeerSwap.GetPremiumRate:output_type -> peerswap.PremiumRate + 33, // 61: peerswap.PeerSwap.UpdatePremiumRate:output_type -> peerswap.PremiumRate + 32, // 62: peerswap.PeerSwap.Stop:output_type -> peerswap.Empty + 42, // [42:63] is the sub-list for method output_type + 21, // [21:42] is the sub-list for method input_type + 21, // [21:21] is the sub-list for extension type_name + 21, // [21:21] is the sub-list for extension extendee + 0, // [0:21] is the sub-list for field type_name } func init() { file_peerswaprpc_peerswaprpc_proto_init() } @@ -2540,7 +2985,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Premium); i { + switch v := v.(*PeerSwapPeer); i { case 0: return &v.state case 1: @@ -2552,7 +2997,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeerSwapPeer); i { + switch v := v.(*PeerSwapPeerChannel); i { case 0: return &v.state case 1: @@ -2564,7 +3009,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeerSwapPeerChannel); i { + switch v := v.(*SwapStats); i { case 0: return &v.state case 1: @@ -2576,7 +3021,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SwapStats); i { + switch v := v.(*Policy); i { case 0: return &v.state case 1: @@ -2588,7 +3033,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Policy); i { + switch v := v.(*AllowSwapRequestsRequest); i { case 0: return &v.state case 1: @@ -2600,7 +3045,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AllowSwapRequestsRequest); i { + switch v := v.(*AllowSwapRequestsResponse); i { case 0: return &v.state case 1: @@ -2612,7 +3057,7 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AllowSwapRequestsResponse); i { + switch v := v.(*Empty); i { case 0: return &v.state case 1: @@ -2624,7 +3069,67 @@ func file_peerswaprpc_peerswaprpc_proto_init() { } } file_peerswaprpc_peerswaprpc_proto_msgTypes[30].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Empty); i { + switch v := v.(*PremiumRate); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_peerswaprpc_peerswaprpc_proto_msgTypes[31].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PeerPremium); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_peerswaprpc_peerswaprpc_proto_msgTypes[32].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetPremiumRateRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_peerswaprpc_peerswaprpc_proto_msgTypes[33].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdatePremiumRateRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_peerswaprpc_peerswaprpc_proto_msgTypes[34].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetDefaultPremiumRateRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_peerswaprpc_peerswaprpc_proto_msgTypes[35].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateDefaultPremiumRateRequest); i { case 0: return &v.state case 1: @@ -2641,8 +3146,8 @@ func file_peerswaprpc_peerswaprpc_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_peerswaprpc_peerswaprpc_proto_rawDesc, - NumEnums: 1, - NumMessages: 32, + NumEnums: 3, + NumMessages: 37, NumExtensions: 0, NumServices: 1, }, diff --git a/peerswaprpc/peerswaprpc.proto b/peerswaprpc/peerswaprpc.proto index e666f8b8..8ffa880f 100644 --- a/peerswaprpc/peerswaprpc.proto +++ b/peerswaprpc/peerswaprpc.proto @@ -28,6 +28,19 @@ service PeerSwap { rpc LiquidSendToAddress(SendToAddressRequest) returns (SendToAddressResponse); + // Premium Stuff + // Premium rates can be configured globally (default) or specifically for peers. + // If no specific configuration exists for a peer, the default configuration is used. + + // Get a premium rate for a asset, and operation. + rpc GetDefaultPremiumRate(GetDefaultPremiumRateRequest) returns (PremiumRate); + // Update a premium rate for a asset, and operation. + rpc UpdateDefaultPremiumRate(UpdateDefaultPremiumRateRequest) returns (PremiumRate); + // Get a premium rate for a specific peer, asset, and operation. + rpc GetPremiumRate(GetPremiumRateRequest) returns (PremiumRate); + // Update a premium rate for a specific peer, asset, and operation. + rpc UpdatePremiumRate(UpdatePremiumRateRequest) returns (PremiumRate); + rpc Stop(Empty) returns (Empty); } @@ -142,18 +155,6 @@ 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; @@ -162,7 +163,7 @@ message PeerSwapPeer { SwapStats as_sender = 5; SwapStats as_receiver = 6; uint64 paid_fee = 7; - Premium premium = 8; + PeerPremium peer_premium = 8; } message PeerSwapPeerChannel { @@ -179,8 +180,6 @@ message SwapStats { uint64 sats_in = 4; } - - message Policy { uint64 reserve_onchain_msat = 1; uint64 min_swap_amount_msat = 2; @@ -188,9 +187,6 @@ message Policy { bool allow_new_swaps = 4; repeated string allowlisted_peers = 5; repeated string suspicious_peer_list = 6; - // Displays the default premium rates. - // The premium rates for each peer are included in PeerSwapPeer. - Premium default_premium = 7; } message AllowSwapRequestsRequest { @@ -202,3 +198,66 @@ message AllowSwapRequestsResponse { } message Empty {} + +// Enum for supported asset types. +enum AssetType { + ASSET_UNSPECIFIED = 0; // Unspecified asset type. + BTC = 1; // Bitcoin asset type. + LBTC = 2; // Liquid Bitcoin asset type. +} + +// Enum for supported operation types. +enum OperationType { + OPERATION_UNSPECIFIED = 0; // Unspecified operation type. + SWAP_IN = 1; // Swap in operation type. + SWAP_OUT = 2; // Swap out operation type. +} + +// PremiumRate defines the premium rate for a specific asset and operation. +message PremiumRate { + AssetType asset = 1; // Asset type (e.g., BTC, LBTC). + OperationType operation = 2; // Operation type (e.g., SWAP_IN, SWAP_OUT). + int64 premium_rate_ppm = 3; // Premium rate in parts per million (PPM). +} + +// Premium configuration per peer. +// If no configuration exists, the default configuration is used. +// Unique by AssetType and OperationType. No explicit constraints on +// this data structure; consistency depends on peerswap implementation. +message PeerPremium { + string node_id = 1; // Node ID of the peer. + repeated PremiumRate rates = 2; // List of premium rates for this peer. +} + +// Request for GetPremiumRate. +// Errors: +// NOT_FOUND: No premium rate is configured for the specified peer, asset, and operation. +// INVALID_ARGUMENT: Invalid peer ID, asset, or operation specified. +message GetPremiumRateRequest { + string node_id = 1; // Node ID of the peer. + AssetType asset = 2; // Asset type (e.g., BTC, LBTC). + OperationType operation = 3; // Operation type (e.g., SWAP_IN, SWAP_OUT). +} + +// Request for UpdatePremiumRate. +// Errors: +// INVALID_ARGUMENT: Invalid peer ID, asset, operation, or rate specified. +message UpdatePremiumRateRequest { + string node_id = 1; // Node ID of the peer. + PremiumRate rate = 2; // The new premium rate to be updated. +} + +// Request for GetDefaultPremiumRate. +// Errors: +// INVALID_ARGUMENT: Invalid asset or operation specified. +message GetDefaultPremiumRateRequest { + AssetType asset = 2; // Asset type (e.g., BTC, LBTC). + OperationType operation = 3; // Operation type (e.g., SWAP_IN, SWAP_OUT). +} + +// Request for UpdateDefaultPremiumRate. +// Errors: +// INVALID_ARGUMENT: Invalid asset, operation, or rate specified. +message UpdateDefaultPremiumRateRequest { + PremiumRate rate = 2; // The new premium rate to be updated. +} \ No newline at end of file diff --git a/peerswaprpc/peerswaprpc.swagger.json b/peerswaprpc/peerswaprpc.swagger.json index f65ed2e0..dbc588b3 100644 --- a/peerswaprpc/peerswaprpc.swagger.json +++ b/peerswaprpc/peerswaprpc.swagger.json @@ -516,6 +516,16 @@ } } }, + "peerswapAssetType": { + "type": "string", + "enum": [ + "ASSET_UNSPECIFIED", + "BTC", + "LBTC" + ], + "default": "ASSET_UNSPECIFIED", + "description": "Enum for supported asset types." + }, "peerswapEmpty": { "type": "object" }, @@ -569,6 +579,31 @@ } } }, + "peerswapOperationType": { + "type": "string", + "enum": [ + "OPERATION_UNSPECIFIED", + "SWAP_IN", + "SWAP_OUT" + ], + "default": "OPERATION_UNSPECIFIED", + "description": "Enum for supported operation types." + }, + "peerswapPeerPremium": { + "type": "object", + "properties": { + "nodeId": { + "type": "string" + }, + "rates": { + "type": "array", + "items": { + "$ref": "#/definitions/peerswapPremiumRate" + } + } + }, + "description": "Premium configuration per peer.\r\nIf no configuration exists, the default configuration is used.\r\nUnique by AssetType and OperationType. No explicit constraints on\r\nthis data structure; consistency depends on peerswap implementation." + }, "peerswapPeerSwapPeer": { "type": "object", "properties": { @@ -600,8 +635,8 @@ "type": "string", "format": "uint64" }, - "premium": { - "$ref": "#/definitions/peerswapPremium" + "peerPremium": { + "$ref": "#/definitions/peerswapPeerPremium" } } }, @@ -653,38 +688,24 @@ "items": { "type": "string" } - }, - "defaultPremium": { - "$ref": "#/definitions/peerswapPremium", - "description": "Displays the default premium rates.\r\nThe premium rates for each peer are included in PeerSwapPeer." } } }, - "peerswapPremium": { + "peerswapPremiumRate": { "type": "object", "properties": { - "btcSwapInPremiumRatePpm": { - "type": "string", - "format": "int64", - "title": "Premium rate for BTC swap-in (in PPM)" - }, - "btcSwapOutPremiumRatePpm": { - "type": "string", - "format": "int64", - "title": "Premium rate for BTC swap-out (in PPM)" + "asset": { + "$ref": "#/definitions/peerswapAssetType" }, - "lbtcSwapInPremiumRatePpm": { - "type": "string", - "format": "int64", - "title": "Premium rate for LBTC swap-in (in PPM)" + "operation": { + "$ref": "#/definitions/peerswapOperationType" }, - "lbtcSwapOutPremiumRatePpm": { + "premiumRatePpm": { "type": "string", - "format": "int64", - "title": "Premium rate for LBTC swap-out (in PPM)" + "format": "int64" } }, - "description": "Premium message represents the premium rates." + "description": "PremiumRate defines the premium rate for a specific asset and operation." }, "peerswapPrettyPrintSwap": { "type": "object", diff --git a/peerswaprpc/peerswaprpc_grpc.pb.go b/peerswaprpc/peerswaprpc_grpc.pb.go index e55393a5..b8fb10c7 100644 --- a/peerswaprpc/peerswaprpc_grpc.pb.go +++ b/peerswaprpc/peerswaprpc_grpc.pb.go @@ -36,6 +36,14 @@ type PeerSwapClient interface { LiquidGetAddress(ctx context.Context, in *GetAddressRequest, opts ...grpc.CallOption) (*GetAddressResponse, error) LiquidGetBalance(ctx context.Context, in *GetBalanceRequest, opts ...grpc.CallOption) (*GetBalanceResponse, error) LiquidSendToAddress(ctx context.Context, in *SendToAddressRequest, opts ...grpc.CallOption) (*SendToAddressResponse, error) + // Get a premium rate for a asset, and operation. + GetDefaultPremiumRate(ctx context.Context, in *GetDefaultPremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) + // Update a premium rate for a asset, and operation. + UpdateDefaultPremiumRate(ctx context.Context, in *UpdateDefaultPremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) + // Get a premium rate for a specific peer, asset, and operation. + GetPremiumRate(ctx context.Context, in *GetPremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) + // Update a premium rate for a specific peer, asset, and operation. + UpdatePremiumRate(ctx context.Context, in *UpdatePremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) Stop(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) } @@ -191,6 +199,42 @@ func (c *peerSwapClient) LiquidSendToAddress(ctx context.Context, in *SendToAddr return out, nil } +func (c *peerSwapClient) GetDefaultPremiumRate(ctx context.Context, in *GetDefaultPremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) { + out := new(PremiumRate) + err := c.cc.Invoke(ctx, "/peerswap.PeerSwap/GetDefaultPremiumRate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *peerSwapClient) UpdateDefaultPremiumRate(ctx context.Context, in *UpdateDefaultPremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) { + out := new(PremiumRate) + err := c.cc.Invoke(ctx, "/peerswap.PeerSwap/UpdateDefaultPremiumRate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *peerSwapClient) GetPremiumRate(ctx context.Context, in *GetPremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) { + out := new(PremiumRate) + err := c.cc.Invoke(ctx, "/peerswap.PeerSwap/GetPremiumRate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *peerSwapClient) UpdatePremiumRate(ctx context.Context, in *UpdatePremiumRateRequest, opts ...grpc.CallOption) (*PremiumRate, error) { + out := new(PremiumRate) + err := c.cc.Invoke(ctx, "/peerswap.PeerSwap/UpdatePremiumRate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *peerSwapClient) Stop(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) { out := new(Empty) err := c.cc.Invoke(ctx, "/peerswap.PeerSwap/Stop", in, out, opts...) @@ -222,6 +266,14 @@ type PeerSwapServer interface { LiquidGetAddress(context.Context, *GetAddressRequest) (*GetAddressResponse, error) LiquidGetBalance(context.Context, *GetBalanceRequest) (*GetBalanceResponse, error) LiquidSendToAddress(context.Context, *SendToAddressRequest) (*SendToAddressResponse, error) + // Get a premium rate for a asset, and operation. + GetDefaultPremiumRate(context.Context, *GetDefaultPremiumRateRequest) (*PremiumRate, error) + // Update a premium rate for a asset, and operation. + UpdateDefaultPremiumRate(context.Context, *UpdateDefaultPremiumRateRequest) (*PremiumRate, error) + // Get a premium rate for a specific peer, asset, and operation. + GetPremiumRate(context.Context, *GetPremiumRateRequest) (*PremiumRate, error) + // Update a premium rate for a specific peer, asset, and operation. + UpdatePremiumRate(context.Context, *UpdatePremiumRateRequest) (*PremiumRate, error) Stop(context.Context, *Empty) (*Empty, error) mustEmbedUnimplementedPeerSwapServer() } @@ -278,6 +330,18 @@ func (UnimplementedPeerSwapServer) LiquidGetBalance(context.Context, *GetBalance func (UnimplementedPeerSwapServer) LiquidSendToAddress(context.Context, *SendToAddressRequest) (*SendToAddressResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method LiquidSendToAddress not implemented") } +func (UnimplementedPeerSwapServer) GetDefaultPremiumRate(context.Context, *GetDefaultPremiumRateRequest) (*PremiumRate, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetDefaultPremiumRate not implemented") +} +func (UnimplementedPeerSwapServer) UpdateDefaultPremiumRate(context.Context, *UpdateDefaultPremiumRateRequest) (*PremiumRate, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateDefaultPremiumRate not implemented") +} +func (UnimplementedPeerSwapServer) GetPremiumRate(context.Context, *GetPremiumRateRequest) (*PremiumRate, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetPremiumRate not implemented") +} +func (UnimplementedPeerSwapServer) UpdatePremiumRate(context.Context, *UpdatePremiumRateRequest) (*PremiumRate, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdatePremiumRate not implemented") +} func (UnimplementedPeerSwapServer) Stop(context.Context, *Empty) (*Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method Stop not implemented") } @@ -582,6 +646,78 @@ func _PeerSwap_LiquidSendToAddress_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +func _PeerSwap_GetDefaultPremiumRate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetDefaultPremiumRateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PeerSwapServer).GetDefaultPremiumRate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/peerswap.PeerSwap/GetDefaultPremiumRate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PeerSwapServer).GetDefaultPremiumRate(ctx, req.(*GetDefaultPremiumRateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PeerSwap_UpdateDefaultPremiumRate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateDefaultPremiumRateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PeerSwapServer).UpdateDefaultPremiumRate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/peerswap.PeerSwap/UpdateDefaultPremiumRate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PeerSwapServer).UpdateDefaultPremiumRate(ctx, req.(*UpdateDefaultPremiumRateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PeerSwap_GetPremiumRate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetPremiumRateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PeerSwapServer).GetPremiumRate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/peerswap.PeerSwap/GetPremiumRate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PeerSwapServer).GetPremiumRate(ctx, req.(*GetPremiumRateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PeerSwap_UpdatePremiumRate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdatePremiumRateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PeerSwapServer).UpdatePremiumRate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/peerswap.PeerSwap/UpdatePremiumRate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PeerSwapServer).UpdatePremiumRate(ctx, req.(*UpdatePremiumRateRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _PeerSwap_Stop_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(Empty) if err := dec(in); err != nil { @@ -671,6 +807,22 @@ var PeerSwap_ServiceDesc = grpc.ServiceDesc{ MethodName: "LiquidSendToAddress", Handler: _PeerSwap_LiquidSendToAddress_Handler, }, + { + MethodName: "GetDefaultPremiumRate", + Handler: _PeerSwap_GetDefaultPremiumRate_Handler, + }, + { + MethodName: "UpdateDefaultPremiumRate", + Handler: _PeerSwap_UpdateDefaultPremiumRate_Handler, + }, + { + MethodName: "GetPremiumRate", + Handler: _PeerSwap_GetPremiumRate_Handler, + }, + { + MethodName: "UpdatePremiumRate", + Handler: _PeerSwap_UpdatePremiumRate_Handler, + }, { MethodName: "Stop", Handler: _PeerSwap_Stop_Handler, diff --git a/peerswaprpc/server.go b/peerswaprpc/server.go index 3ca50b91..e102e865 100644 --- a/peerswaprpc/server.go +++ b/peerswaprpc/server.go @@ -14,6 +14,8 @@ import ( "github.com/elementsproject/peerswap/log" "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/poll" + "github.com/elementsproject/peerswap/premium" + "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/wallet" "github.com/lightningnetwork/lnd/lnrpc" @@ -26,6 +28,7 @@ type PeerswapServer struct { requestedSwaps *swap.RequestedSwapsPrinter pollService *poll.Service policy *policy.Policy + ps *premium.Setting lnd lnrpc.LightningClient @@ -77,8 +80,8 @@ func (p *PeerswapServer) Stop(ctx context.Context, empty *Empty) (*Empty, error) return &Empty{}, nil } -func NewPeerswapServer(liquidWallet wallet.Wallet, swaps *swap.SwapService, requestedSwaps *swap.RequestedSwapsPrinter, pollService *poll.Service, policy *policy.Policy, gelements *gelements.Elements, lnd lnrpc.LightningClient, sigchan chan os.Signal) *PeerswapServer { - return &PeerswapServer{liquidWallet: liquidWallet, swaps: swaps, requestedSwaps: requestedSwaps, pollService: pollService, policy: policy, lnd: lnd, sigchan: sigchan} +func NewPeerswapServer(liquidWallet wallet.Wallet, swaps *swap.SwapService, requestedSwaps *swap.RequestedSwapsPrinter, pollService *poll.Service, policy *policy.Policy, gelements *gelements.Elements, lnd lnrpc.LightningClient, ps *premium.Setting, sigchan chan os.Signal) *PeerswapServer { + return &PeerswapServer{liquidWallet: liquidWallet, swaps: swaps, requestedSwaps: requestedSwaps, pollService: pollService, policy: policy, lnd: lnd, ps: ps, sigchan: sigchan} } func (p *PeerswapServer) SwapOut(ctx context.Context, request *SwapOutRequest) (*SwapResponse, error) { @@ -375,11 +378,30 @@ 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, + PeerPremium: &PeerPremium{ + NodeId: v.PubKey, + Rates: []*PremiumRate{ + { + Asset: AssetType_BTC, + Operation: OperationType_SWAP_IN, + PremiumRatePpm: poll.BTCSwapInPremiumRatePPM, + }, + { + Asset: AssetType_BTC, + Operation: OperationType_SWAP_OUT, + PremiumRatePpm: poll.BTCSwapOutPremiumRatePPM, + }, + { + Asset: AssetType_LBTC, + Operation: OperationType_SWAP_IN, + PremiumRatePpm: poll.LBTCSwapInPremiumRatePPM, + }, + { + Asset: AssetType_LBTC, + Operation: OperationType_SWAP_OUT, + PremiumRatePpm: poll.LBTCSwapOutPremiumRatePPM, + }, + }, }, }) } @@ -527,6 +549,121 @@ func (p *PeerswapServer) AllowSwapRequests(ctx context.Context, request *AllowSw return GetPolicyMessage(pol), nil } +func toPremiumAssetType(assetType AssetType) premium.AssetType { + switch assetType { + case AssetType_BTC: + return premium.BTC + case AssetType_LBTC: + return premium.LBTC + default: + return premium.AsserUnspecified + } +} + +func toPremiumOperationType(operationType OperationType) premium.OperationType { + switch operationType { + case OperationType_SWAP_IN: + return premium.SwapIn + case OperationType_SWAP_OUT: + return premium.SwapOut + default: + return premium.OperationUnspecified + } +} + +func toAssetType(assetType premium.AssetType) AssetType { + switch assetType { + case premium.BTC: + return AssetType_BTC + case premium.LBTC: + return AssetType_LBTC + default: + return AssetType_ASSET_UNSPECIFIED + } +} + +func toOperationType(operationType premium.OperationType) OperationType { + switch operationType { + case premium.SwapIn: + return OperationType_SWAP_IN + case premium.SwapOut: + return OperationType_SWAP_OUT + default: + return OperationType_OPERATION_UNSPECIFIED + } +} + +func (p *PeerswapServer) GetDefaultPremiumRate(ctx context.Context, + request *GetDefaultPremiumRateRequest) (*PremiumRate, error) { + if request.GetAsset() != AssetType_BTC && request.GetAsset() != AssetType_LBTC { + return nil, fmt.Errorf("invalid asset type: %s", request.Asset) + } + if request.GetOperation() != OperationType_SWAP_IN && + request.GetOperation() != OperationType_SWAP_OUT { + return nil, fmt.Errorf("invalid operation type: %s", request.Operation) + } + r, err := p.ps.GetDefaultRate(toPremiumAssetType(request.GetAsset()), + toPremiumOperationType(request.GetOperation())) + if err != nil { + return nil, err + } + return &PremiumRate{ + Asset: toAssetType(r.Asset()), + Operation: toOperationType(r.Operation()), + PremiumRatePpm: r.PremiumRatePPM().Value(), + }, nil +} + +func (p *PeerswapServer) UpdateDefaultPremiumRate(ctx context.Context, + request *UpdateDefaultPremiumRateRequest) (*PremiumRate, error) { + rate, err := premium.NewPremiumRate( + toPremiumAssetType(request.GetRate().GetAsset()), + toPremiumOperationType(request.GetRate().GetOperation()), + premium.NewPPM(request.GetRate().GetPremiumRatePpm()), + ) + err = p.ps.SetDefaultRate(rate) + if err != nil { + return nil, fmt.Errorf("could not set default rate: %v", err) + } + return request.GetRate(), nil +} + +func (p *PeerswapServer) GetPremiumRate(ctx context.Context, + request *GetPremiumRateRequest) (*PremiumRate, error) { + if request.GetAsset() != AssetType_BTC && request.GetAsset() != AssetType_LBTC { + return nil, fmt.Errorf("invalid asset type: %s", request.Asset) + } + if request.GetOperation() != OperationType_SWAP_IN && + request.GetOperation() != OperationType_SWAP_OUT { + return nil, fmt.Errorf("invalid operation type: %s", request.Operation) + } + r, err := p.ps.GetRate(request.GetNodeId(), + toPremiumAssetType(request.GetAsset()), + toPremiumOperationType(request.GetOperation())) + if err != nil { + return nil, err + } + return &PremiumRate{ + Asset: toAssetType(r.Asset()), + Operation: toOperationType(r.Operation()), + PremiumRatePpm: r.PremiumRatePPM().Value(), + }, nil +} + +func (p *PeerswapServer) UpdatePremiumRate(ctx context.Context, + request *UpdatePremiumRateRequest) (*PremiumRate, error) { + rate, err := premium.NewPremiumRate( + toPremiumAssetType(request.GetRate().GetAsset()), + toPremiumOperationType(request.GetRate().GetOperation()), + premium.NewPPM(request.GetRate().GetPremiumRatePpm()), + ) + err = p.ps.SetRate(request.GetNodeId(), rate) + if err != nil { + return nil, fmt.Errorf("could not set rate: %v", err) + } + return request.GetRate(), nil +} + func PrettyprintFromServiceSwap(swap *swap.SwapStateMachine) *PrettyPrintSwap { scid, err := newScidFromString(swap.Data.GetScid()) if err != nil { diff --git a/policy/policy.go b/policy/policy.go index 01e87a89..3ae3910d 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -84,7 +84,6 @@ type Policy struct { // 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."` - premium *premium } func (p *Policy) String() string { @@ -116,7 +115,6 @@ func (p *Policy) Get() Policy { AcceptAllPeers: p.AcceptAllPeers, MinSwapAmountMsat: p.MinSwapAmountMsat, AllowNewSwaps: p.AllowNewSwaps, - premium: p.premium, } } @@ -194,13 +192,8 @@ func (p *Policy) ReloadFile() error { if err != nil { return ErrCreatePolicy(err.Error()) } - premium, err := newPremiumConfig(file) - if err != nil { - return fmt.Errorf("could not create premium config: %v", err) - } p.path = path - p.premium = premium return nil } @@ -302,18 +295,6 @@ 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 { @@ -445,7 +426,6 @@ func DefaultPolicy() *Policy { AcceptAllPeers: defaultAcceptAllPeers, MinSwapAmountMsat: defaultMinSwapAmountMsat, AllowNewSwaps: defaultAllowNewSwaps, - premium: defaultPreium(), } } @@ -482,11 +462,6 @@ func CreateFromFile(path string) (*Policy, error) { if err != nil { return nil, ErrCreatePolicy(err.Error()) } - 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 61649694..2fc2854a 100644 --- a/policy/policy_test.go +++ b/policy/policy_test.go @@ -31,7 +31,6 @@ func Test_Create(t *testing.T) { AcceptAllPeers: defaultAcceptAllPeers, MinSwapAmountMsat: defaultMinSwapAmountMsat, AllowNewSwaps: defaultAllowNewSwaps, - premium: defaultPreium(), }, policy) peer1 := "123" @@ -64,7 +63,6 @@ func Test_Create(t *testing.T) { AcceptAllPeers: accept, MinSwapAmountMsat: defaultMinSwapAmountMsat, AllowNewSwaps: defaultAllowNewSwaps, - premium: defaultPreium(), }, policy2) } @@ -88,7 +86,6 @@ func Test_Reload(t *testing.T) { AcceptAllPeers: accept, MinSwapAmountMsat: defaultMinSwapAmountMsat, AllowNewSwaps: defaultAllowNewSwaps, - premium: defaultPreium(), }, policy) newPeer := "new_peer" @@ -103,7 +100,6 @@ func Test_Reload(t *testing.T) { AcceptAllPeers: defaultAcceptAllPeers, MinSwapAmountMsat: defaultMinSwapAmountMsat, AllowNewSwaps: defaultAllowNewSwaps, - premium: defaultPreium(), }, policy) } @@ -127,7 +123,6 @@ func Test_Reload_NoOverrideOnError(t *testing.T) { AcceptAllPeers: accept, MinSwapAmountMsat: defaultMinSwapAmountMsat, AllowNewSwaps: defaultAllowNewSwaps, - premium: defaultPreium(), }, policy) // copy policy diff --git a/policy/premium.go b/policy/premium.go deleted file mode 100644 index 0219855d..00000000 --- a/policy/premium.go +++ /dev/null @@ -1,164 +0,0 @@ -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 = 0 - // defaultSwapOutPremiumRatePPM is the default of the swap out premium rate in ppm. - defaultSwapOutPremiumRatePPM int64 = 0 - 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 represents a parts-per-million structure. -type ppm struct { - ppmValue int64 // ppm value -} - -// NewPPM creates a new ppm instance. -func NewPPM(value int64) *ppm { - return &ppm{ppmValue: value} -} - -// Value returns the ppm value. -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 represents the premium rate for BTC swap-in. - btcSwapInPremiumRatePPM *ppm - // btcSwapOutPremiumRatePPM represents the premium rate for BTC swap-out. - btcSwapOutPremiumRatePPM *ppm - // lbtcSwapInPremiumRatePPM represents the premium rate for LBTC swap-in. - lbtcSwapInPremiumRatePPM *ppm - // lbtcSwapOutPremiumRatePPM represents the premium rate for LBTC swap-out. - 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), - ), - btcSwapOutPremiumRatePPM: NewPPM( - f.Section(basePremiumSectionKey).Key(btcSwapOutPremiumRatePPMKey).MustInt64(defaultSwapOutPremiumRatePPM), - ), - lbtcSwapInPremiumRatePPM: NewPPM( - f.Section(basePremiumSectionKey).Key(lbtcSwapInPremiumRatePPMKey).MustInt64(defaultSwapInPremiumRatePPM), - ), - lbtcSwapOutPremiumRatePPM: NewPPM( - f.Section(basePremiumSectionKey).Key(lbtcSwapOutPremiumRatePPMKey).MustInt64(defaultSwapOutPremiumRatePPM), - ), - }, - 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 deleted file mode 100644 index cda2a2ca..00000000 --- a/policy/premium_test.go +++ /dev/null @@ -1,182 +0,0 @@ -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(defaultSwapInPremiumRatePPM), - lbtcSwapInPremiumRatePPM: NewPPM(defaultSwapInPremiumRatePPM), - lbtcSwapOutPremiumRatePPM: NewPPM(defaultSwapInPremiumRatePPM), - }, - 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(defaultSwapInPremiumRatePPM), - btcSwapOutPremiumRatePPM: NewPPM(defaultSwapInPremiumRatePPM), - lbtcSwapInPremiumRatePPM: NewPPM(defaultSwapInPremiumRatePPM), - lbtcSwapOutPremiumRatePPM: NewPPM(defaultSwapInPremiumRatePPM), - }, - 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/service.go b/poll/service.go index ac777548..2a55291a 100644 --- a/poll/service.go +++ b/poll/service.go @@ -9,7 +9,8 @@ import ( "time" "github.com/elementsproject/peerswap/log" - policy "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" + "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/messages" @@ -40,7 +41,6 @@ type PeerGetter interface { type Policy interface { IsPeerAllowed(peerId string) bool - GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 } type Store interface { @@ -68,6 +68,7 @@ type Service struct { assets []string messenger Messenger policy Policy + ps *premium.Setting peers PeerGetter store Store tmpStore map[string]string @@ -75,7 +76,7 @@ type Service struct { loggedDisconnect map[string]struct{} } -func NewService(tickDuration time.Duration, removeDuration time.Duration, store Store, messenger Messenger, policy Policy, peers PeerGetter, allowedAssets []string) *Service { +func NewService(tickDuration time.Duration, removeDuration time.Duration, store Store, messenger Messenger, policy Policy, peers PeerGetter, allowedAssets []string, ps *premium.Setting) *Service { clock := time.NewTicker(tickDuration) ctx, done := context.WithCancel(context.Background()) s := &Service{ @@ -90,12 +91,24 @@ func NewService(tickDuration time.Duration, removeDuration time.Duration, store tmpStore: make(map[string]string), removeDuration: removeDuration, loggedDisconnect: make(map[string]struct{}), + ps: ps, } s.messenger.AddMessageHandler(s.MessageHandler) + // Register as an observer of premium rate changes + // This ensures PollAllPeers is called whenever premium rates are updated + ps.AddObserver(s) return s } +// OnPremiumUpdate implements premium.Observer interface +// Called automatically when premium rates are changed +// via Setting.SetRate or Setting.SetDefaultRate +func (s *Service) OnPremiumUpdate() { + // Broadcast updated premium rates to all peers + s.PollAllPeers() +} + // Start the poll message loop and send the poll // messages on every tick. func (s *Service) Start() { @@ -122,16 +135,24 @@ func (s *Service) Stop() { s.done() } +func (s *Service) premiumRatePPM(peerID string, asset premium.AssetType, operation premium.OperationType) int64 { + rate, err := s.ps.GetRate(peerID, asset, operation) + if err != nil { + return 0 + } + return rate.PremiumRatePPM().Value() +} + // 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), - 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), + BTCSwapInPremiumRatePPM: s.premiumRatePPM(peer, premium.BTC, premium.SwapIn), + BTCSwapOutPremiumRatePPM: s.premiumRatePPM(peer, premium.BTC, premium.SwapOut), + LBTCSwapInPremiumRatePPM: s.premiumRatePPM(peer, premium.LBTC, premium.SwapIn), + LBTCSwapOutPremiumRatePPM: s.premiumRatePPM(peer, premium.LBTC, premium.SwapOut), } msg, err := json.Marshal(poll) @@ -159,10 +180,10 @@ func (s *Service) RequestPoll(peer string) { 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), + BTCSwapInPremiumRatePPM: s.premiumRatePPM(peer, premium.BTC, premium.SwapIn), + BTCSwapOutPremiumRatePPM: s.premiumRatePPM(peer, premium.BTC, premium.SwapOut), + LBTCSwapInPremiumRatePPM: s.premiumRatePPM(peer, premium.LBTC, premium.SwapIn), + LBTCSwapOutPremiumRatePPM: s.premiumRatePPM(peer, premium.LBTC, premium.SwapOut), } msg, err := json.Marshal(request) @@ -211,10 +232,10 @@ func (s *Service) MessageHandler(peerID, msgType string, payload []byte) error { 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), + BTCSwapInPremiumRatePPM: msg.BTCSwapInPremiumRatePPM, + BTCSwapOutPremiumRatePPM: msg.BTCSwapOutPremiumRatePPM, + LBTCSwapInPremiumRatePPM: msg.LBTCSwapInPremiumRatePPM, + LBTCSwapOutPremiumRatePPM: msg.LBTCSwapOutPremiumRatePPM, LastSeen: time.Now(), }); serr != nil { return serr @@ -240,10 +261,10 @@ func (s *Service) MessageHandler(peerID, msgType string, payload []byte) error { 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), + BTCSwapInPremiumRatePPM: msg.BTCSwapInPremiumRatePPM, + BTCSwapOutPremiumRatePPM: msg.BTCSwapOutPremiumRatePPM, + LBTCSwapInPremiumRatePPM: msg.LBTCSwapInPremiumRatePPM, + LBTCSwapOutPremiumRatePPM: msg.LBTCSwapOutPremiumRatePPM, LastSeen: time.Now(), }); serr != nil { return serr diff --git a/poll/service_test.go b/poll/service_test.go index d8f8a8c0..f35ea50c 100644 --- a/poll/service_test.go +++ b/poll/service_test.go @@ -8,7 +8,8 @@ import ( "time" "github.com/elementsproject/peerswap/messages" - policy "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" + "github.com/samber/lo" "github.com/stretchr/testify/assert" "go.etcd.io/bbolt" ) @@ -51,10 +52,6 @@ func (m *PolicyMock) IsPeerAllowed(peerId string) bool { return m.allowList[m.called-1] } -func (m *PolicyMock) GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 { - return 1000000 -} - func TestSendMessage(t *testing.T) { dir := t.TempDir() db, err := bbolt.Open(path.Join(dir, "poll-db"), os.ModePerm, nil) @@ -72,7 +69,8 @@ func TestSendMessage(t *testing.T) { peers: []string{"peer1", "peer2"}, } assets := []string{"asset1", "asset2", "asset3"} - ps := NewService(500*time.Millisecond, 1*time.Second, store, messenger, policy, peerGetter, assets) + premium := lo.Must(premium.NewSetting(db)) + ps := NewService(500*time.Millisecond, 1*time.Second, store, messenger, policy, peerGetter, assets, premium) for _, peer := range peerGetter.peers { ps.Poll(peer) } @@ -110,7 +108,8 @@ func TestRecievePollAndPollRequest(t *testing.T) { peers: []string{"peer1", "peer2"}, } assets := []string{"asset1", "asset2", "asset3"} - ps := NewService(500*time.Millisecond, 1*time.Second, store, messenger, policy, peerGetter, assets) + premium := lo.Must(premium.NewSetting(db)) + ps := NewService(500*time.Millisecond, 1*time.Second, store, messenger, policy, peerGetter, assets, premium) pmt := messages.MessageTypeToHexString(messages.MESSAGETYPE_POLL) rpmt := messages.MessageTypeToHexString(messages.MESSAGETYPE_REQUEST_POLL) diff --git a/premium/premium.go b/premium/premium.go new file mode 100644 index 00000000..af284696 --- /dev/null +++ b/premium/premium.go @@ -0,0 +1,196 @@ +package premium + +import ( + "errors" + "fmt" + + "go.etcd.io/bbolt" +) + +const ( + // premiumRateParts is the total number of parts used to express fee rates. + premiumRateParts = 1e6 + // defaultPremiumRatePPM is the default premium rate in ppm. + defaultPremiumRatePPM int64 = 0 + + premiumRatePPMKey = "premium_rate_ppm" +) + +// Enum for supported asset types. +type AssetType int32 + +const ( + AsserUnspecified AssetType = iota + BTC + LBTC +) + +func (a AssetType) String() string { + return [...]string{"Unspecified", "BTC", "LBTC"}[a] +} + +// Enum for supported operation types. +type OperationType int32 + +const ( + OperationUnspecified OperationType = iota + SwapIn + SwapOut +) + +func (o OperationType) String() string { + return [...]string{"Unspecified", "SwapIn", "SwapOut"}[o] +} + +// PremiumRate defines the premium rate for a specific asset and operation. +type PremiumRate struct { + asset AssetType + operation OperationType + premiumRate *PPM +} + +// NewPremiumRate creates a new PremiumRate instance with validation. +func NewPremiumRate(asset AssetType, operation OperationType, premiumRate *PPM) (*PremiumRate, error) { + if asset == AsserUnspecified { + return nil, fmt.Errorf("invalid asset type") + } + if operation == OperationUnspecified { + return nil, fmt.Errorf("invalid operation type") + } + return &PremiumRate{ + asset: asset, + operation: operation, + premiumRate: premiumRate, + }, nil +} + +// Asset returns the asset type. +func (p *PremiumRate) Asset() AssetType { + return p.asset +} + +// Operation returns the operation type. +func (p *PremiumRate) Operation() OperationType { + return p.operation +} + +// PremiumRatePPM returns the premium rate in ppm. +func (p *PremiumRate) PremiumRatePPM() *PPM { + return p.premiumRate +} + +// PPM represents a parts-per-million structure. +type PPM struct { + ppmValue int64 // ppm value +} + +// NewPPM creates a new ppm instance. +func NewPPM(value int64) *PPM { + return &PPM{ppmValue: value} +} + +// Value returns the ppm value. +func (p *PPM) Value() int64 { + if p == nil { + return 0 + } + return p.ppmValue +} + +// Compute calculates the premium in satoshis for a given amount in satoshis. +func (p *PPM) Compute(amtSat uint64) (sat int64) { + return int64(amtSat) * p.ppmValue / premiumRateParts +} + +// Observer pattern implementation +// ----------------------------- + +// Observer defines the interface for objects that should be notified of premium rate changes +type Observer interface { + // OnPremiumUpdate is called when premium rates are updated + OnPremiumUpdate() +} + +type Setting struct { + store *BBoltPremiumStore + observer []Observer // List of observers to be notified of premium rate changes +} + +func NewSetting(bbolt *bbolt.DB) (*Setting, error) { + store, err := NewBBoltPremiumStore(bbolt) + if err != nil { + return nil, err + } + return &Setting{ + store: store, + }, nil +} + +// AddObserver registers a new observer to be notified of premium rate changes +func (p *Setting) AddObserver(observer Observer) { + p.observer = append(p.observer, observer) +} + +// notifyObservers notifies all registered observers when premium rates change +func (p *Setting) notifyObservers() { + for _, observer := range p.observer { + observer.OnPremiumUpdate() + } +} + +// Premium rate operations +// --------------------- + +// GetRate retrieves the premium rate for a given peer, asset, and operation. +// If the rate is not found, it retrieves the default rate. +func (p *Setting) GetRate(peerID string, asset AssetType, operation OperationType) (*PremiumRate, error) { + rate, err := p.store.GetRate(peerID, asset, operation) + if err != nil { + if errors.Is(err, ErrRateNotFound) { + return p.GetDefaultRate(asset, operation) + } + return nil, err + } + return rate, nil +} + +// SetRate sets the premium rate for a given peer and notifies observers if successful. +func (p *Setting) SetRate(peerID string, rate *PremiumRate) error { + err := p.store.SetRate(peerID, rate) + if err == nil { + // Notify observers only if the update was successful + p.notifyObservers() + } + return err +} + +// GetDefaultRate retrieves the default premium rate for a given asset and operation. +func (p *Setting) GetDefaultRate(asset AssetType, operation OperationType) (*PremiumRate, error) { + rate, err := p.store.GetDefaultRate(asset, operation) + if err != nil { + if errors.Is(err, ErrRateNotFound) { + return NewPremiumRate(asset, operation, NewPPM(defaultPremiumRatePPM)) + } + return nil, err + } + return rate, nil +} + +// SetDefaultRate sets the default premium rate and notifies observers if successful. +func (p *Setting) SetDefaultRate(rate *PremiumRate) error { + err := p.store.SetDefaultRate(rate) + if err == nil { + // Notify observers only if the update was successful + p.notifyObservers() + } + return err +} + +// Compute calculates the premium in satoshis for a given amount in satoshis. +func (p *Setting) Compute(peerID string, asset AssetType, operation OperationType, amtSat uint64) (int64, error) { + rate, err := p.GetRate(peerID, asset, operation) + if err != nil { + return 0, err + } + return rate.PremiumRatePPM().Compute(amtSat), nil +} diff --git a/premium/premium_test.go b/premium/premium_test.go new file mode 100644 index 00000000..d10a7ee9 --- /dev/null +++ b/premium/premium_test.go @@ -0,0 +1,119 @@ +package premium_test + +import ( + "os" + "path" + "testing" + + "github.com/elementsproject/peerswap/premium" + "github.com/stretchr/testify/assert" + "go.etcd.io/bbolt" + + "github.com/samber/lo" +) + +const ( + testPeer = "test-peer" + testPPM1 = 1000 + testPPM2 = 2000 + testPPM3 = 1500 + testPPM4 = 2500 +) + +func setupPremium(t *testing.T) *premium.Setting { + dir := t.TempDir() + db, err := bbolt.Open(path.Join(dir, "premium-db"), os.ModePerm, nil) + p, err := premium.NewSetting(db) + if err != nil { + t.Fatalf("failed to create premium setting: %v", err) + } + return p +} + +func Test_Setting_GetRate(t *testing.T) { + t.Parallel() + tests := map[string]struct { + peerID string + asset premium.AssetType + operation premium.OperationType + ppm int64 + }{ + "BTC SwapIn": {testPeer, premium.BTC, premium.SwapIn, testPPM1}, + "BTC SwapOut": {testPeer, premium.BTC, premium.SwapOut, testPPM2}, + "LBTC SwapIn": {testPeer, premium.LBTC, premium.SwapIn, testPPM3}, + "LBTC SwapOut": {testPeer, premium.LBTC, premium.SwapOut, testPPM4}, + } + + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + t.Parallel() + setting := setupPremium(t) + rate := lo.Must(premium.NewPremiumRate(tt.asset, tt.operation, premium.NewPPM(tt.ppm))) + // Add test data to the store + err := setting.SetRate(tt.peerID, rate) + if err != nil { + t.Fatalf("failed to set rate: %v", err) + } + // Retrieve the rate + got, err := setting.GetRate(tt.peerID, rate.Asset(), rate.Operation()) + if err != nil { + t.Fatalf("failed to get rate: %v", err) + } + assert.Equal(t, rate, got) + }) + } +} + +func Test_Setting_GetRate_Default(t *testing.T) { + t.Parallel() + setting := setupPremium(t) + rate := lo.Must(premium.NewPremiumRate(premium.BTC, premium.SwapIn, premium.NewPPM(testPPM1))) + err := setting.SetRate("peer", rate) + if err != nil { + t.Fatalf("failed to set rate: %v", err) + } + // Retrieve the rate + got, err := setting.GetRate("test", rate.Asset(), rate.Operation()) + if err != nil { + t.Fatalf("failed to get rate: %v", err) + } + assert.Equal(t, rate.Asset(), got.Asset()) + assert.Equal(t, rate.Operation(), got.Operation()) + assert.Equal(t, int64(0), got.PremiumRatePPM().Value()) +} + +func Test_Setting_Compute(t *testing.T) { + t.Parallel() + tests := map[string]struct { + peerID string + asset premium.AssetType + operation premium.OperationType + ppm int64 + amtSat uint64 + expected int64 + }{ + "BTC SwapIn": {testPeer, premium.BTC, premium.SwapIn, testPPM1, 1000000, 1000}, + "BTC SwapOut": {testPeer, premium.BTC, premium.SwapOut, testPPM2, 1000000, 2000}, + "LBTC SwapIn": {testPeer, premium.LBTC, premium.SwapIn, testPPM3, 1000000, 1500}, + "LBTC SwapOut": {testPeer, premium.LBTC, premium.SwapOut, testPPM4, 1000000, 2500}, + } + + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + t.Parallel() + setting := setupPremium(t) + rate := lo.Must(premium.NewPremiumRate(tt.asset, tt.operation, premium.NewPPM(tt.ppm))) + // Add test data to the store + err := setting.SetRate(tt.peerID, rate) + if err != nil { + t.Fatalf("failed to set rate: %v", err) + } + // Compute the premium + got, err := setting.Compute(tt.peerID, tt.asset, tt.operation, tt.amtSat) + if err != nil { + t.Fatalf("failed to compute premium: %v", err) + } + assert.Equal(t, tt.expected, got) + }) + } +} diff --git a/premium/store.go b/premium/store.go new file mode 100644 index 00000000..7f5ed671 --- /dev/null +++ b/premium/store.go @@ -0,0 +1,83 @@ +package premium + +import ( + "errors" + "fmt" + + "go.etcd.io/bbolt" + bolt "go.etcd.io/bbolt" +) + +const ( + bucketName = "premium" + defaultPeerID = "default" +) + +// ErrRateNotFound is returned when a rate is not found in the database. +var ErrRateNotFound = errors.New("Rate not found") + +type BBoltPremiumStore struct { + db *bolt.DB +} + +func NewBBoltPremiumStore(db *bbolt.DB) (*BBoltPremiumStore, error) { + tx, err := db.Begin(true) + if err != nil { + return nil, err + } + defer tx.Rollback() + _, err = tx.CreateBucketIfNotExists([]byte(bucketName)) + if err != nil { + return nil, err + } + if err := tx.Commit(); err != nil { + return nil, err + } + return &BBoltPremiumStore{db: db}, err +} + +// SetRate sets the premium rate for a given peer, asset, and operation. +func (p *BBoltPremiumStore) SetRate(peer string, rate *PremiumRate) error { + return p.db.Update(func(tx *bolt.Tx) error { + bucket := tx.Bucket([]byte(bucketName)) + if bucket == nil { + return fmt.Errorf("Bucket not found") + } + key := fmt.Sprintf("%s.%d.%d", peer, rate.Asset(), rate.Operation()) + value := []byte(fmt.Sprintf("%d", rate.PremiumRatePPM().Value())) + return bucket.Put([]byte(key), value) + }) +} + +// GetRate retrieves the premium rate for a given peer, asset, and operation. +// If the rate is not found, it tries to retrieve the default rate. +func (p *BBoltPremiumStore) GetRate(peer string, asset AssetType, operation OperationType) (*PremiumRate, error) { + var rate int64 + err := p.db.View(func(tx *bolt.Tx) error { + bucket := tx.Bucket([]byte(bucketName)) + if bucket == nil { + return fmt.Errorf("Bucket not found") + } + key := fmt.Sprintf("%s.%d.%d", peer, asset, operation) + value := bucket.Get([]byte(key)) + if value == nil { + return ErrRateNotFound + } + _, err := fmt.Sscanf(string(value), "%d", &rate) + return err + }) + if err != nil { + return nil, err + } + return NewPremiumRate(asset, operation, NewPPM(rate)) +} + +// SetDefaultRate sets the default premium rate for a given asset and operation. +func (p *BBoltPremiumStore) SetDefaultRate(rate *PremiumRate) error { + return p.SetRate(defaultPeerID, rate) +} + +// GetDefaultRate retrieves the default premium rate for a given asset and operation. +func (p *BBoltPremiumStore) GetDefaultRate(asset AssetType, operation OperationType) (*PremiumRate, error) { + return p.GetRate(defaultPeerID, asset, operation) +} diff --git a/sample_policy.conf b/sample_policy.conf index f6d5f2ac..60d1140a 100644 --- a/sample_policy.conf +++ b/sample_policy.conf @@ -3,19 +3,3 @@ allowlisted_peers=peer1 allowlisted_peers=peer2 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 -# * 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 c4c68358..820ce247 100644 --- a/swap/actions.go +++ b/swap/actions.go @@ -10,7 +10,7 @@ import ( "time" "github.com/elementsproject/peerswap/log" - "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" "github.com/btcsuite/btcd/btcec/v2" "github.com/elementsproject/peerswap/isdev" @@ -145,17 +145,26 @@ func (a CheckRequestWrapperAction) Execute(services *SwapServices, swap *SwapDat type SwapInReceiverInitAction struct{} func (s *SwapInReceiverInitAction) Execute(services *SwapServices, swap *SwapData) EventType { - var premium int64 + var ( + premiumValue int64 + err error + ) if swap.GetChain() == l_btc_chain { - premium = services.policy.ComputePremium(swap.PeerNodeId, policy.LbtcSwapIn, swap.GetAmount()) + premiumValue, err = services.ps.Compute(swap.PeerNodeId, premium.LBTC, premium.SwapIn, swap.GetAmount()) + if err != nil { + return swap.HandleError(err) + } } else { - premium = services.policy.ComputePremium(swap.PeerNodeId, policy.BtcSwapIn, swap.GetAmount()) + premiumValue, err = services.ps.Compute(swap.PeerNodeId, premium.BTC, premium.SwapIn, swap.GetAmount()) + if err != nil { + return swap.HandleError(err) + } } agreementMessage := &SwapInAgreementMessage{ ProtocolVersion: PEERSWAP_PROTOCOL_VERSION, SwapId: swap.GetId(), Pubkey: hex.EncodeToString(swap.GetPrivkey().PubKey().SerializeCompressed()), - Premium: premium, + Premium: premiumValue, } swap.SwapInAgreement = agreementMessage @@ -426,11 +435,17 @@ func (c *CreateSwapOutFromRequestAction) Execute(services *SwapServices, swap *S if err != nil { return swap.HandleError(err) } - var premium int64 + var premiumValue int64 if swap.GetChain() == l_btc_chain { - premium = services.policy.ComputePremium(swap.PeerNodeId, policy.LbtcSwapOut, swap.GetAmount()) + premiumValue, err = services.ps.Compute(swap.PeerNodeId, premium.LBTC, premium.SwapOut, swap.GetAmount()) + if err != nil { + return swap.HandleError(err) + } } else { - premium = services.policy.ComputePremium(swap.PeerNodeId, policy.BtcSwapOut, swap.GetAmount()) + premiumValue, err = services.ps.Compute(swap.PeerNodeId, premium.BTC, premium.SwapOut, swap.GetAmount()) + if err != nil { + return swap.HandleError(err) + } } message := &SwapOutAgreementMessage{ @@ -438,7 +453,7 @@ func (c *CreateSwapOutFromRequestAction) Execute(services *SwapServices, swap *S SwapId: swap.GetId(), Pubkey: hex.EncodeToString(swap.GetPrivkey().PubKey().SerializeCompressed()), Payreq: feeInvoice, - Premium: premium, + Premium: premiumValue, } swap.SwapOutAgreement = message diff --git a/swap/service.go b/swap/service.go index 9a13d0e1..8d41701f 100644 --- a/swap/service.go +++ b/swap/service.go @@ -9,7 +9,7 @@ import ( "sync" "github.com/elementsproject/peerswap/log" - "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" "github.com/elementsproject/peerswap/messages" ) @@ -544,18 +544,27 @@ func (s *SwapService) estimateMaximumSwapAmountSat(chain string) (uint64, error) // 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 { - var premium int64 + var ( + premiumValue int64 + err error + ) // 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) + premiumValue, err = s.swapServices.ps.Compute(peerId, premium.LBTC, premium.SwapIn, message.Amount) + if err != nil { + return err + } } else { - premium = s.swapServices.policy.ComputePremium(peerId, policy.BtcSwapIn, message.Amount) + premiumValue, err = s.swapServices.ps.Compute(peerId, premium.BTC, premium.SwapIn, message.Amount) + if err != nil { + return err + } } - if premium > message.PremiumLimit { - err := fmt.Errorf("unacceptable premium: %d, limit: %d", premium, message.PremiumLimit) + if premiumValue > message.PremiumLimit { + err := fmt.Errorf("unacceptable premium: %d, limit: %d", premiumValue, message.PremiumLimit) msg := fmt.Sprintf("from the %s peer: %s", s.swapServices.lightning.Implementation(), err.Error()) // We want to tell our peer why we can not do this swap. msgBytes, msgType, err := MarshalPeerswapMessage(&CancelMessage{ @@ -566,7 +575,7 @@ func (s *SwapService) OnSwapInRequestReceived(swapId *SwapId, peerId string, mes return err } - err := s.swapServices.lightning.CanSpend(message.Amount * 1000) + err = s.swapServices.lightning.CanSpend(message.Amount * 1000) if err != nil { msg := fmt.Sprintf("from the %s peer: %s", s.swapServices.lightning.Implementation(), err.Error()) // We want to tell our peer why we can not do this swap. @@ -646,17 +655,26 @@ 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 { - var premium int64 + var ( + premiumValue int64 + err error + ) // 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) + premiumValue, err = s.swapServices.ps.Compute(peerId, premium.LBTC, premium.SwapOut, message.Amount) + if err != nil { + return err + } } else { - premium = s.swapServices.policy.ComputePremium(peerId, policy.BtcSwapOut, message.Amount) + premiumValue, err = s.swapServices.ps.Compute(peerId, premium.BTC, premium.SwapOut, message.Amount) + if err != nil { + return err + } } - if premium > message.PremiumLimit { - err := fmt.Errorf("unacceptable premium: %d, limit: %d", premium, message.PremiumLimit) + if premiumValue > message.PremiumLimit { + err := fmt.Errorf("unacceptable premium: %d, limit: %d", premiumValue, message.PremiumLimit) msg := fmt.Sprintf("from the %s peer: %s", s.swapServices.lightning.Implementation(), err.Error()) // We want to tell our peer why we can not do this swap. msgBytes, msgType, err := MarshalPeerswapMessage(&CancelMessage{ diff --git a/swap/service_test.go b/swap/service_test.go index abba5572..f917d283 100644 --- a/swap/service_test.go +++ b/swap/service_test.go @@ -4,14 +4,19 @@ import ( "context" "encoding/hex" "log" + "os" + "path" "sync" "testing" "time" "github.com/btcsuite/btcd/btcec/v2" + "github.com/samber/lo" + "go.etcd.io/bbolt" "github.com/elementsproject/peerswap/messages" "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -20,8 +25,8 @@ func Test_GoodCase(t *testing.T) { amount := uint64(100000) initiator, peer, _, _, channelId := getTestParams() - aliceSwapService := getTestSetup(initiator) - bobSwapService := getTestSetup(peer) + aliceSwapService := getTestSetup(t, initiator) + bobSwapService := getTestSetup(t, peer) aliceSwapService.swapServices.messenger.(*ConnectedMessenger).other = bobSwapService.swapServices.messenger.(*ConnectedMessenger) bobSwapService.swapServices.messenger.(*ConnectedMessenger).other = aliceSwapService.swapServices.messenger.(*ConnectedMessenger) @@ -74,8 +79,8 @@ func Test_FeePaymentFailed(t *testing.T) { amount := uint64(100000) initiator, peer, _, _, channelId := getTestParams() - aliceSwapService := getTestSetup(initiator) - bobSwapService := getTestSetup(peer) + aliceSwapService := getTestSetup(t, initiator) + bobSwapService := getTestSetup(t, peer) // set lightning to fail aliceSwapService.swapServices.lightning.(*dummyLightningClient).failpayment = true @@ -119,8 +124,8 @@ func Test_ClaimPaymentFailedCoopClose(t *testing.T) { amount := uint64(100000) initiator, peer, _, _, channelId := getTestParams() - aliceSwapService := getTestSetup(initiator) - bobSwapService := getTestSetup(peer) + aliceSwapService := getTestSetup(t, initiator) + bobSwapService := getTestSetup(t, peer) aliceSwapService.swapServices.messenger.(*ConnectedMessenger).other = bobSwapService.swapServices.messenger.(*ConnectedMessenger) bobSwapService.swapServices.messenger.(*ConnectedMessenger).other = aliceSwapService.swapServices.messenger.(*ConnectedMessenger) @@ -177,7 +182,7 @@ func Test_ClaimPaymentFailedCoopClose(t *testing.T) { } func Test_OnlyOneActiveSwapPerChannel(t *testing.T) { - service := getTestSetup("alice") + service := getTestSetup(t, "alice") swapId := NewSwapId() service.lockSwap(swapId.String(), "channelID", &SwapStateMachine{ SwapId: swapId, @@ -238,8 +243,8 @@ func TestMessageFromUnexpectedPeer(t *testing.T) { amount := uint64(100000) initiator, peer, _, _, channelId := getTestParams() - aliceSwapService := getTestSetup(initiator) - bobSwapService := getTestSetup(peer) + aliceSwapService := getTestSetup(t, initiator) + bobSwapService := getTestSetup(t, peer) aliceSwapService.swapServices.messenger.(*ConnectedMessenger).other = bobSwapService.swapServices.messenger.(*ConnectedMessenger) bobSwapService.swapServices.messenger.(*ConnectedMessenger).other = aliceSwapService.swapServices.messenger.(*ConnectedMessenger) @@ -326,7 +331,7 @@ func TestMessageFromUnexpectedPeer(t *testing.T) { func TestTimeout(t *testing.T) { t.Parallel() - sws := getTestSetup("alice") + sws := getTestSetup(t, "alice") sws.swapServices.messenger = &noopMessenger{} sws.Start() @@ -361,7 +366,7 @@ func Test_SwapIn_PeerIsSuspicious(t *testing.T) { const node = "alice" const peer = "bob" - swapService := getTestSetup(node) + swapService := getTestSetup(t, node) // Setup peer to be suspicious swapService.swapServices.policy = &dummyPolicy{ isPeerSuspiciousReturn: true, @@ -379,7 +384,7 @@ func Test_SwapOut_PeerIsSuspicious(t *testing.T) { const node = "alice" const peer = "bob" - swapService := getTestSetup(node) + swapService := getTestSetup(t, node) // Setup peer to be suspicious swapService.swapServices.policy = &dummyPolicy{ isPeerSuspiciousReturn: true, @@ -392,7 +397,7 @@ func Test_SwapOut_PeerIsSuspicious(t *testing.T) { assert.ErrorIs(t, err, PeerIsSuspiciousError(peer)) } -func getTestSetup(name string) *SwapService { +func getTestSetup(t *testing.T, name string) *SwapService { store := &dummyStore{dataMap: map[string]*SwapStateMachine{}} reqSwapsStore := &requestedSwapsStoreMock{data: map[string][]RequestedSwap{}} messenger := &ConnectedMessenger{ @@ -403,12 +408,28 @@ func getTestSetup(name string) *SwapService { policy := &dummyPolicy{ getMinSwapAmountMsatReturn: policy.DefaultPolicy().MinSwapAmountMsat, newSwapsAllowedReturn: policy.DefaultPolicy().AllowNewSwaps, - getSwapInPremiumRatePPM: 10000, - getSwapOutPremiumRatePPM: 10000, } chain := &dummyChain{returnGetCSVHeight: 1008} chain.SetBalance(10000000) - swapServices := NewSwapServices(store, reqSwapsStore, lc, messenger, mmgr, policy, true, chain, chain, chain, true, chain, chain, chain) + dir := t.TempDir() + db, err := bbolt.Open(path.Join(dir, "premium-db"), os.ModePerm, nil) + require.NoError(t, err) + premiumSetting, err := premium.NewSetting(db) + require.NoError(t, err) + require.NoError(t, + premiumSetting.SetDefaultRate( + lo.Must(premium.NewPremiumRate(premium.BTC, premium.SwapIn, premium.NewPPM(10000))))) + require.NoError(t, + premiumSetting.SetDefaultRate( + lo.Must(premium.NewPremiumRate(premium.BTC, premium.SwapOut, premium.NewPPM(10000))))) + require.NoError(t, + premiumSetting.SetDefaultRate( + lo.Must(premium.NewPremiumRate(premium.LBTC, premium.SwapIn, premium.NewPPM(10000))))) + require.NoError(t, + premiumSetting.SetDefaultRate( + lo.Must(premium.NewPremiumRate(premium.LBTC, premium.SwapOut, premium.NewPPM(10000))))) + + swapServices := NewSwapServices(store, reqSwapsStore, lc, messenger, mmgr, policy, true, chain, chain, chain, true, chain, chain, chain, premiumSetting) swapService := NewSwapService(swapServices) return swapService } diff --git a/swap/services.go b/swap/services.go index 4c18e516..236a9733 100644 --- a/swap/services.go +++ b/swap/services.go @@ -7,7 +7,7 @@ import ( "time" "github.com/elementsproject/peerswap/messages" - policy "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" "github.com/btcsuite/btcd/btcec/v2" btecdsa "github.com/btcsuite/btcd/btcec/v2/ecdsa" @@ -37,8 +37,6 @@ type Policy interface { AddToSuspiciousPeerList(pubkey string) error GetReserveOnchainMsat() uint64 GetMinSwapAmountMsat() uint64 - GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 - ComputePremium(peerID string, k policy.PremiumRateKind, amtSat uint64) int64 NewSwapsAllowed() bool } @@ -143,6 +141,7 @@ type SwapServices struct { liquidWallet Wallet liquidEnabled bool toService TimeOutService + ps *premium.Setting } func NewSwapServices( @@ -159,7 +158,9 @@ func NewSwapServices( liquidEnabled bool, liquidWallet Wallet, liquidValidator Validator, - liquidTxWatcher TxWatcher) *SwapServices { + liquidTxWatcher TxWatcher, + ps *premium.Setting, +) *SwapServices { return &SwapServices{ swapStore: swapStore, requestedSwapsStore: requestedSwapsStore, @@ -175,6 +176,7 @@ func NewSwapServices( liquidWallet: liquidWallet, liquidValidator: liquidValidator, liquidTxWatcher: liquidTxWatcher, + ps: ps, } } diff --git a/swap/swap_in_receiver_test.go b/swap/swap_in_receiver_test.go index 068ff49d..87de1b4a 100644 --- a/swap/swap_in_receiver_test.go +++ b/swap/swap_in_receiver_test.go @@ -16,7 +16,7 @@ func Test_SwapInReceiverValid(t *testing.T) { initiator, peer, _, _, chanId := getTestParams() msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swap := newSwapInReceiverFSM(swapId, swapServices, peer) _, err := swap.SendEvent(Event_SwapInReceiver_OnRequestReceived, &SwapInRequestMessage{ Amount: swapAmount, @@ -63,7 +63,7 @@ func Test_SwapInReceiverCancel1(t *testing.T) { initiator, peer, _, _, chanId := getTestParams() msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swap := newSwapInReceiverFSM(swapId, swapServices, peer) _, err := swap.SendEvent(Event_SwapInReceiver_OnRequestReceived, &SwapInRequestMessage{ @@ -96,7 +96,7 @@ func Test_SwapInReceiverCancel2(t *testing.T) { initiator, peer, _, _, chanId := getTestParams() msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swap := newSwapInReceiverFSM(swapId, swapServices, peer) _, err := swap.SendEvent(Event_SwapInReceiver_OnRequestReceived, &SwapInRequestMessage{ @@ -143,7 +143,7 @@ func Test_SwapInReceiver_PeerIsSuspicious(t *testing.T) { msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) // Setup the peer to be suspicious. swapServices.policy = &dummyPolicy{ isPeerSuspiciousReturn: true, diff --git a/swap/swap_in_sender_test.go b/swap/swap_in_sender_test.go index 5fd2b12a..a4c17556 100644 --- a/swap/swap_in_sender_test.go +++ b/swap/swap_in_sender_test.go @@ -1,11 +1,16 @@ package swap import ( + "os" + "path" "testing" "github.com/elementsproject/peerswap/messages" "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.etcd.io/bbolt" ) func Test_SwapInSenderValidSwap(t *testing.T) { @@ -16,7 +21,7 @@ func Test_SwapInSenderValidSwap(t *testing.T) { timeOutD := &timeOutDummy{} - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapServices.toService = timeOutD swap := newSwapInSenderFSM(swapServices, initiator, peer) @@ -59,7 +64,7 @@ func Test_SwapInSenderCancel1(t *testing.T) { initiator, peer, _, _, chanId := getTestParams() msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swap := newSwapInSenderFSM(swapServices, initiator, peer) _, err := swap.SendEvent(Event_SwapInSender_OnSwapInRequested, &SwapInRequestMessage{ @@ -89,7 +94,7 @@ func Test_SwapInSenderCoopClose(t *testing.T) { initiator, peer, takerPubkeyHash, _, chanId := getTestParams() msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swap := newSwapInSenderFSM(swapServices, initiator, peer) _, err := swap.SendEvent(Event_SwapInSender_OnSwapInRequested, &SwapInRequestMessage{ @@ -126,7 +131,7 @@ func Test_SwapInSenderCoopClose(t *testing.T) { assert.Equal(t, State_ClaimedCoop, swap.Current) } -func getSwapServices(msgChan chan PeerMessage) *SwapServices { +func getSwapServices(t *testing.T, msgChan chan PeerMessage) *SwapServices { store := &dummyStore{dataMap: map[string]*SwapStateMachine{}} reqSwapsStore := &requestedSwapsStoreMock{data: map[string][]RequestedSwap{}} messenger := &dummyMessenger{msgChan: msgChan} @@ -139,7 +144,12 @@ func getSwapServices(msgChan chan PeerMessage) *SwapServices { chain.SetBalance(1000000) mmgr := &MessengerManagerStub{} - swapServices := NewSwapServices(store, reqSwapsStore, lc, messenger, mmgr, policy, true, chain, chain, chain, true, chain, chain, chain) + dir := t.TempDir() + db, err := bbolt.Open(path.Join(dir, "premium-db"), os.ModePerm, nil) + require.NoError(t, err) + premium, err := premium.NewSetting(db) + require.NoError(t, err) + swapServices := NewSwapServices(store, reqSwapsStore, lc, messenger, mmgr, policy, true, chain, chain, chain, true, chain, chain, chain, premium) swapServices.toService = &timeOutDummy{} return swapServices } diff --git a/swap/swap_out_receiver_test.go b/swap/swap_out_receiver_test.go index 588b8d2f..5ab7040f 100644 --- a/swap/swap_out_receiver_test.go +++ b/swap/swap_out_receiver_test.go @@ -16,7 +16,7 @@ func Test_SwapOutReceiverValidSwap(t *testing.T) { msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapFSM := newSwapOutReceiverFSM(swapId, swapServices, peer) _, err := swapFSM.SendEvent(Event_OnSwapOutRequestReceived, &SwapOutRequestMessage{ @@ -54,7 +54,7 @@ func Test_SwapOutReceiverClaimCoop(t *testing.T) { msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapFSM := newSwapOutReceiverFSM(swapId, swapServices, peer) @@ -93,7 +93,7 @@ func Test_SwapOutReceiverCancelReceived(t *testing.T) { msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapFSM := newSwapOutReceiverFSM(swapId, swapServices, peer) @@ -127,7 +127,7 @@ func Test_SwapOutReceiverCancelInternal(t *testing.T) { msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapServices.lightning.(*dummyLightningClient).preimage = FeePreimage swapFSM := newSwapOutReceiverFSM(swapId, swapServices, peer) @@ -157,7 +157,7 @@ func Test_SwapOutReceiverInsufficientBalance(t *testing.T) { msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapServices.bitcoinWallet.(*dummyChain).SetBalance(0) swapServices.lightning.(*dummyLightningClient).preimage = FeePreimage @@ -193,7 +193,7 @@ func Test_SwapOutReceiver_PeerIsSuspicious(t *testing.T) { msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) // Setup the peer to be suspicious. swapServices.policy = &dummyPolicy{ diff --git a/swap/swap_out_sender_test.go b/swap/swap_out_sender_test.go index 282d43bb..710414eb 100644 --- a/swap/swap_out_sender_test.go +++ b/swap/swap_out_sender_test.go @@ -8,7 +8,6 @@ import ( "github.com/elementsproject/peerswap/lightning" "github.com/elementsproject/peerswap/messages" - "github.com/elementsproject/peerswap/policy" "github.com/stretchr/testify/assert" ) @@ -42,7 +41,7 @@ func Test_ValidSwap(t *testing.T) { timeOutD := &timeOutDummy{} - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapServices.toService = timeOutD swapFSM := newSwapOutSenderFSM(swapServices, initiator, peer) @@ -98,7 +97,7 @@ func Test_Cancel2(t *testing.T) { initiator, peer, takerpubkeyhash, _, chanId := getTestParams() msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapFSM := newSwapOutSenderFSM(swapServices, initiator, peer) _, err := swapFSM.SendEvent(Event_OnSwapOutStarted, &SwapOutRequestMessage{ @@ -127,7 +126,7 @@ func Test_Cancel1(t *testing.T) { FeeInvoice := "err" msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapFSM := newSwapOutSenderFSM(swapServices, initiator, peer) _, err := swapFSM.SendEvent(Event_OnSwapOutStarted, &SwapOutRequestMessage{ @@ -158,7 +157,7 @@ func Test_AbortCsvClaim(t *testing.T) { FeeInvoice := "fee" msgChan := make(chan PeerMessage) - swapServices := getSwapServices(msgChan) + swapServices := getSwapServices(t, msgChan) swapFSM := newSwapOutSenderFSM(swapServices, initiator, peer) @@ -371,10 +370,8 @@ type dummyPolicy struct { getMinSwapAmountMsatCalled int getMinSwapAmountMsatReturn uint64 - newSwapsAllowedCalled int - newSwapsAllowedReturn bool - getSwapInPremiumRatePPM int64 - getSwapOutPremiumRatePPM int64 + newSwapsAllowedCalled int + newSwapsAllowedReturn bool } func (d *dummyPolicy) NewSwapsAllowed() bool { @@ -391,13 +388,6 @@ func (d *dummyPolicy) GetMinSwapAmountMsat() uint64 { return d.getMinSwapAmountMsatReturn } -func (d *dummyPolicy) GetPremiumRate(peerID string, k policy.PremiumRateKind) int64 { - return d.getSwapInPremiumRatePPM -} -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 { return true } diff --git a/test/bitcoin_cln_test.go b/test/bitcoin_cln_test.go index 70a7dd66..f8aaa279 100644 --- a/test/bitcoin_cln_test.go +++ b/test/bitcoin_cln_test.go @@ -10,7 +10,7 @@ import ( "github.com/elementsproject/peerswap/clightning" "github.com/elementsproject/peerswap/peerswaprpc" - "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/testframework" "github.com/stretchr/testify/assert" @@ -61,24 +61,22 @@ func Test_OnlyOneActiveSwapPerChannelCln(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 5, - 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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + swapAmt: channelBalances[0] / 5, + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -133,12 +131,12 @@ func Test_ClnCln_Bitcoin_SwapIn(t *testing.T) { tailableProcess{ p: lightningds[0].DaemonProcess, filter: filter, - lines: defaultLines, + lines: 1000, }, tailableProcess{ p: lightningds[1].DaemonProcess, filter: filter, - lines: defaultLines, + lines: 1000, }, ) } @@ -157,24 +155,22 @@ func Test_ClnCln_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -229,24 +225,22 @@ func Test_ClnCln_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -303,24 +297,22 @@ func Test_ClnCln_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -382,24 +374,22 @@ func Test_ClnCln_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -455,24 +445,22 @@ func Test_ClnCln_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -528,24 +516,22 @@ func Test_ClnCln_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -610,24 +596,22 @@ func Test_ClnLnd_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -686,24 +670,22 @@ func Test_ClnLnd_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -762,24 +744,22 @@ func Test_ClnLnd_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -844,24 +824,22 @@ func Test_ClnLnd_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -920,24 +898,22 @@ func Test_ClnLnd_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -996,24 +972,22 @@ func Test_ClnLnd_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1074,24 +1048,22 @@ func Test_ClnCln_ExcessiveAmount(t *testing.T) { } params := &testParams{ - swapAmt: 2 * channelBalances[0], - 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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + swapAmt: 2 * channelBalances[0], + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1153,24 +1125,22 @@ func Test_Cln_HtlcMaximum(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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1225,24 +1195,22 @@ func Test_Cln_HtlcMaximum(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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1271,7 +1239,7 @@ func Test_Cln_Premium(t *testing.T) { "--dev-bitcoind-poll=1", "--dev-fast-gossip", "--large-channels", - }, true, []byte("accept_all_peers=1\nswap_in_premium_rate_ppm=-10000\n"), + }, true, []byte("accept_all_peers=1\n"), ) defer func() { if t.Failed() { @@ -1307,30 +1275,40 @@ func Test_Cln_Premium(t *testing.T) { channelBalances = append(channelBalances, b) } + var premiumRatePPM int64 = -10000 + + var premiumRes interface{} + err := lightningds[0].Rpc.Request(&clightning.SetPremiumRateRequest{ + PeerID: lightningds[1].Id(), + Asset: premium.BTC.String(), + OperationType: premium.SwapIn.String(), + PremiumRatePPM: premiumRatePPM, + }, &premiumRes) + assert.NoError(t, err) + 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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - swapType: swap.SWAPTYPE_IN, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: -10000, - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), + swapInPremiumRate: premiumRatePPM, } asset := "btc" var response map[string]interface{} - err := lightningds[1].Rpc.Request(&clightning.SwapIn{ + err = lightningds[1].Rpc.Request(&clightning.SwapIn{ SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, @@ -1348,7 +1326,7 @@ func Test_Cln_Premium(t *testing.T) { "--dev-bitcoind-poll=1", "--dev-fast-gossip", "--large-channels", - }, true, []byte("accept_all_peers=1\nswap_out_premium_rate_ppm=-10000\n"), + }, true, []byte("accept_all_peers=1\n"), ) defer func() { if t.Failed() { @@ -1384,6 +1362,17 @@ func Test_Cln_Premium(t *testing.T) { channelBalances = append(channelBalances, b) } + var premiumRatePPM int64 = -10000 + + var premiumRes interface{} + err := lightningds[1].Rpc.Request(&clightning.SetPremiumRateRequest{ + PeerID: lightningds[0].Id(), + Asset: premium.BTC.String(), + OperationType: premium.SwapOut.String(), + PremiumRatePPM: premiumRatePPM, + }, &premiumRes) + assert.NoError(t, err) + params := &testParams{ swapAmt: channelBalances[0] / 2, scid: scid, @@ -1401,19 +1390,20 @@ func Test_Cln_Premium(t *testing.T) { csv: BitcoinCsv, swapType: swap.SWAPTYPE_OUT, premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: -10000, + swapOutPremiumRate: premiumRatePPM, } asset := "btc" // Swap out should fail as the premium is to high. var response map[string]interface{} - err := lightningds[0].Rpc.Request(&clightning.SwapOut{ + err = lightningds[0].Rpc.Request(&clightning.SwapOut{ SatAmt: params.swapAmt, ShortChannelId: params.scid, Asset: asset, PremiumLimit: params.premiumLimit}, &response) - assert.Error(t, err) + assert.NoError(t, err) + + preimageClaimTest(t, params) }) t.Run("exceed_limit", func(t *testing.T) { @@ -1456,24 +1446,22 @@ func Test_Cln_Premium(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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - swapType: swap.SWAPTYPE_IN, - premiumLimit: 1, - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: -1, } asset := "btc" diff --git a/test/bitcoin_lnd_test.go b/test/bitcoin_lnd_test.go index 47335a0f..67746364 100644 --- a/test/bitcoin_lnd_test.go +++ b/test/bitcoin_lnd_test.go @@ -10,7 +10,6 @@ import ( "time" "github.com/elementsproject/peerswap/peerswaprpc" - "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/testframework" "github.com/stretchr/testify/assert" @@ -70,23 +69,21 @@ func Test_OnlyOneActiveSwapPerChannelLnd(t *testing.T) { } params := &testParams{ - swapAmt: channelBalances[0] / 5, - 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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - 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), + swapAmt: channelBalances[0] / 5, + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -186,23 +183,21 @@ func Test_LndLnd_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -269,23 +264,21 @@ func Test_LndLnd_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -352,24 +345,22 @@ func Test_LndLnd_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -442,24 +433,22 @@ func Test_LndLnd_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -527,24 +516,22 @@ func Test_LndLnd_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -612,24 +599,22 @@ func Test_LndLnd_Bitcoin_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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -700,24 +685,22 @@ func Test_LndCln_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -782,24 +765,22 @@ func Test_LndCln_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -865,24 +846,22 @@ func Test_LndCln_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - makerPeerswap: peerswapd.DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + makerPeerswap: peerswapd.DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -953,24 +932,22 @@ func Test_LndCln_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1035,24 +1012,22 @@ func Test_LndCln_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1117,24 +1092,22 @@ func Test_LndCln_Bitcoin_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].(*testframework.CLightningNode).DaemonProcess, - chainRpc: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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].(*testframework.CLightningNode).DaemonProcess, + chainRpc: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1206,24 +1179,22 @@ func Test_LndLnd_ExcessiveAmount(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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -1291,23 +1262,21 @@ func Test_LndLnd_ExcessiveAmount(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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + swapType: swap.SWAPTYPE_IN, + premiumLimit: int64(channelBalances[0] / 10), } 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 0f10f757..cdbf1ec1 100644 --- a/test/liquid_cln_test.go +++ b/test/liquid_cln_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/elementsproject/peerswap/clightning" - "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/stretchr/testify/require" ) @@ -59,24 +58,22 @@ func Test_ClnCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -138,24 +135,22 @@ func Test_ClnCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -215,24 +210,22 @@ func Test_ClnCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -298,24 +291,22 @@ func Test_ClnCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -375,24 +366,22 @@ func Test_ClnCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -452,24 +441,22 @@ func Test_ClnCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -539,24 +526,22 @@ func Test_ClnLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -620,24 +605,22 @@ func Test_ClnLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -701,24 +684,22 @@ func Test_ClnLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -789,24 +770,22 @@ func Test_ClnLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -869,24 +848,22 @@ func Test_ClnLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -949,24 +926,22 @@ func Test_ClnLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" diff --git a/test/liquid_lnd_test.go b/test/liquid_lnd_test.go index c5f30270..d131904c 100644 --- a/test/liquid_lnd_test.go +++ b/test/liquid_lnd_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/elementsproject/peerswap/peerswaprpc" - "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/stretchr/testify/require" ) @@ -70,24 +69,22 @@ func Test_LndLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -158,24 +155,22 @@ func Test_LndLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -246,24 +241,22 @@ func Test_LndLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -340,24 +333,22 @@ func Test_LndLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -429,24 +420,22 @@ func Test_LndLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -518,24 +507,22 @@ func Test_LndLnd_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -611,24 +598,22 @@ func Test_LndCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -697,24 +682,22 @@ func Test_LndCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -783,24 +766,22 @@ func Test_LndCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -875,24 +856,22 @@ func Test_LndCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -961,24 +940,22 @@ func Test_LndCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" @@ -1047,24 +1024,22 @@ func Test_LndCln_Liquid_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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" diff --git a/test/lwk_cln_test.go b/test/lwk_cln_test.go index 33cc0ec9..8f722390 100644 --- a/test/lwk_cln_test.go +++ b/test/lwk_cln_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/elementsproject/peerswap/clightning" - "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/stretchr/testify/require" ) @@ -66,24 +65,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -148,24 +145,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -231,24 +226,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -318,24 +311,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -400,24 +391,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -483,24 +472,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -574,24 +561,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -659,24 +644,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -743,24 +726,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -833,24 +814,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -917,24 +896,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1001,24 +978,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1087,24 +1062,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1169,24 +1142,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1252,24 +1223,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1339,24 +1308,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1421,24 +1388,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1504,24 +1469,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1591,24 +1554,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" diff --git a/test/lwk_lnd_test.go b/test/lwk_lnd_test.go index e53dae69..b8ef904b 100644 --- a/test/lwk_lnd_test.go +++ b/test/lwk_lnd_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/elementsproject/peerswap/peerswaprpc" - "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/stretchr/testify/require" ) @@ -78,24 +77,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -174,24 +171,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -270,24 +265,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -372,24 +365,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -468,24 +459,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -564,24 +553,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -664,24 +651,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -758,24 +743,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -852,24 +835,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -952,24 +933,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1046,24 +1025,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" @@ -1140,24 +1117,22 @@ 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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.BtcSwapOut), + 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), } asset := "lbtc" diff --git a/test/recovery_test.go b/test/recovery_test.go index ad94b68a..c10a664b 100644 --- a/test/recovery_test.go +++ b/test/recovery_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/elementsproject/peerswap/clightning" - "github.com/elementsproject/peerswap/policy" "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/testframework" "github.com/stretchr/testify/require" @@ -59,24 +58,22 @@ func Test_RestoreFromPassedCSV(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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - swapType: swap.SWAPTYPE_OUT, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -193,24 +190,22 @@ func Test_Recover_PassedSwap_BTC(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: bitcoind.RpcProxy, - chaind: bitcoind, - confirms: BitcoinConfirms, - csv: BitcoinCsv, - 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), + 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: bitcoind.RpcProxy, + chaind: bitcoind, + confirms: BitcoinConfirms, + csv: BitcoinCsv, + swapType: swap.SWAPTYPE_OUT, + premiumLimit: int64(channelBalances[0] / 10), } asset := "btc" @@ -305,24 +300,22 @@ func Test_Recover_PassedSwap_LBTC(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, - premiumLimit: int64(channelBalances[0] / 10), - swapInPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapIn), - swapOutPremiumRate: policy.DefaultPolicy().GetPremiumRate(lightningds[0].Id(), policy.LbtcSwapOut), + 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), } asset := "lbtc" diff --git a/test/setup.go b/test/setup.go index c57779c3..9a87fb50 100644 --- a/test/setup.go +++ b/test/setup.go @@ -43,7 +43,19 @@ func clnclnSetupWithConfig(t *testing.T, fundAmt, pushAmt uint64, clnConf []stri // Get PeerSwap plugin path and test dir _, filename, _, _ := runtime.Caller(0) pathToPlugin := filepath.Join(filename, "..", "..", "out", "test-builds", "peerswap") - testDir := t.TempDir() + + // Use os.MkdirTemp() instead of t.TempDir() for the DataDir. + // The shorter temp paths avoid problems with long unix socket paths composed + // using the DataDir. + // See https://github.com/golang/go/issues/62614. + makeDataDir := func() string { + tempDir, err := os.MkdirTemp("", "cln-test-") + require.NoError(t, err, "os.MkdirTemp failed") + t.Cleanup(func() { os.RemoveAll(tempDir) }) + return tempDir + } + + testDir := makeDataDir() // Setup nodes (1 bitcoind, 2 lightningd) bitcoind, err := testframework.NewBitcoinNode(testDir, 1) diff --git a/test/testcases.go b/test/testcases.go index 5e54c0e8..683a6a24 100644 --- a/test/testcases.go +++ b/test/testcases.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/elementsproject/peerswap/policy" + "github.com/elementsproject/peerswap/premium" "github.com/elementsproject/peerswap/swap" "github.com/elementsproject/peerswap/testframework" "github.com/stretchr/testify/require" @@ -36,9 +36,9 @@ type testParams struct { func (p *testParams) premium() int64 { switch p.swapType { case swap.SWAPTYPE_IN: - return policy.NewPPM(p.swapInPremiumRate).Compute(p.swapAmt) + return premium.NewPPM(p.swapInPremiumRate).Compute(p.swapAmt) case swap.SWAPTYPE_OUT: - return policy.NewPPM(p.swapOutPremiumRate).Compute(p.swapAmt) + return premium.NewPPM(p.swapOutPremiumRate).Compute(p.swapAmt) default: return 0 }