multi: parse and propagate auction type field for orders

This commit is contained in:
positiveblue 2022-09-22 07:30:32 -07:00
parent d1b9a63da5
commit 7669c7ffde
No known key found for this signature in database
GPG key ID: 4FFF2510928804DC
4 changed files with 45 additions and 2 deletions

View file

@ -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[:],

View file

@ -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
}

View file

@ -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)

View file

@ -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)