From 7669c7ffdef3ad597601fd770cc25604206ea3ab Mon Sep 17 00:00:00 2001 From: positiveblue Date: Thu, 22 Sep 2022 07:30:32 -0700 Subject: [PATCH] multi: parse and propagate auction type field for orders --- auctioneer/client.go | 12 +++++++++++- order/interfaces.go | 8 ++++++++ order/rpc_parse.go | 2 ++ rpcserver.go | 25 ++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/auctioneer/client.go b/auctioneer/client.go index 0ef1fda..d73c76b 100644 --- a/auctioneer/client.go +++ b/auctioneer/client.go @@ -431,11 +431,21 @@ func (c *Client) SubmitOrder(ctx context.Context, o order.Order, return fmt.Errorf("unhandled channel type %v", c) } + var auctionType auctioneerrpc.AuctionType + switch o.Details().AuctionType { + case order.BTCInboundLiquidity: + auctionType = auctioneerrpc.AuctionType_AUCTION_TYPE_BTC_INBOUND_LIQUIDITY + case order.BTCOutboundLiquidity: + auctionType = auctioneerrpc.AuctionType_AUCTION_TYPE_BTC_OUTBOUND_LIQUIDITY + } + minChanAmt := uint64(o.Details().MinUnitsMatch.ToSatoshis()) + details := &auctioneerrpc.ServerOrder{ TraderKey: o.Details().AcctKey[:], + AuctionType: auctionType, RateFixed: o.Details().FixedRate, Amt: uint64(o.Details().Amt), - MinChanAmt: uint64(o.Details().MinUnitsMatch.ToSatoshis()), + MinChanAmt: minChanAmt, OrderNonce: nonce[:], OrderSig: serverParams.RawSig, MultiSigKey: serverParams.MultiSigKey[:], diff --git a/order/interfaces.go b/order/interfaces.go index 64a8ee6..b8d7489 100644 --- a/order/interfaces.go +++ b/order/interfaces.go @@ -850,6 +850,14 @@ func (b *Bid) ValidateSelfChanBalance() error { "match must be equal to the order amount in units") } + if b.AuctionType == BTCOutboundLiquidity && + b.SelfChanBalance < BaseSupplyUnit { + + return fmt.Errorf("to participate in the outbound liquidity " + + "market the self chan balance should be at least " + + "100k sats") + } + return nil } diff --git a/order/rpc_parse.go b/order/rpc_parse.go index 0624a20..dda121c 100644 --- a/order/rpc_parse.go +++ b/order/rpc_parse.go @@ -73,6 +73,7 @@ func ParseRPCOrder(version, leaseDuration uint32, } copy(kit.AcctKey[:], details.TraderKey) + kit.AuctionType = AuctionType(details.AuctionType) kit.Version = Version(version) kit.FixedRate = details.RateFixed kit.Amt = btcutil.Amount(details.Amt) @@ -205,6 +206,7 @@ func ParseRPCServerOrder(version uint32, details *auctioneerrpc.ServerOrder, copy(nonce[:], details.OrderNonce) kit := NewKit(nonce) + kit.AuctionType = AuctionType(details.AuctionType) kit.Version = Version(version) kit.FixedRate = details.RateFixed kit.Amt = btcutil.Amount(details.Amt) diff --git a/rpcserver.go b/rpcserver.go index 7bcf4b3..ebe7665 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1341,6 +1341,14 @@ func (s *rpcServer) validateOrder(o order.Order, acct *account.Account, } } + if castOrder.AuctionType == order.BTCOutboundLiquidity && + castOrder.MinUnitsMatch == 0 { + + return fmt.Errorf("min chan amount must be greater " + + "than zero for participating in the outbound " + + "liquidity market") + } + case *order.Bid: if castOrder.ZeroConfChannel { if !batchVersion.SupportsZeroConfChannels() { @@ -1392,6 +1400,13 @@ func (s *rpcServer) validateOrder(o order.Order, acct *account.Account, "the same time") } + if o.Details().AuctionType == order.BTCOutboundLiquidity && + o.Details().Units != 1 { + + return fmt.Errorf("to participate in the outbound liquidity " + + "market the order amt should be exactly 100k sats") + } + return nil } @@ -2330,11 +2345,19 @@ func (s *rpcServer) prepareLeasesResponse(ctx context.Context, clearingPrice = batch.ClearingPrices[duration] } + premiumAmt := chanAmt + auctionType := ourOrder.Details().AuctionType + if auctionType == order.BTCOutboundLiquidity { + premiumAmt += btcutil.Amount( + selfChanBalance, + ) + } + // Calculate the premium paid/received to/from // the maker/taker and the execution fee paid // to the auctioneer and tally them. premium := clearingPrice.LumpSumPremium( - chanAmt, bidDuration, + premiumAmt, bidDuration, ) exeFee := batch.ExecutionFee.BaseFee() + batch.ExecutionFee.ExecutionFee(chanAmt)