diff --git a/client.go b/client.go index 2422656..008f6c1 100644 --- a/client.go +++ b/client.go @@ -353,11 +353,14 @@ func (s *Client) LoopOutQuote(ctx context.Context, return nil, ErrSwapAmountTooHigh } - logger.Infof("Offchain swap destination: %x", terms.SwapPaymentDest) + quote, err := s.Server.GetLoopOutQuote(ctx, request.Amount) + if err != nil { + return nil, err + } - swapFee := swap.CalcFee( - request.Amount, terms.SwapFeeBase, terms.SwapFeeRate, - ) + logger.Infof("Offchain swap destination: %x", quote.SwapPaymentDest) + + swapFee := quote.SwapFee // Generate dummy p2wsh address for fee estimation. The p2wsh address // type is chosen because it adds the most weight of all output types @@ -379,9 +382,11 @@ func (s *Client) LoopOutQuote(ctx context.Context, } return &LoopOutQuote{ - SwapFee: swapFee, - MinerFee: minerFee, - PrepayAmount: btcutil.Amount(terms.PrepayAmt), + SwapFee: swapFee, + MinerFee: minerFee, + PrepayAmount: btcutil.Amount(quote.PrepayAmount), + SwapPaymentDest: quote.SwapPaymentDest, + CltvDelta: quote.CltvDelta, }, nil } @@ -465,10 +470,12 @@ func (s *Client) LoopInQuote(ctx context.Context, return nil, ErrSwapAmountTooHigh } - // Calculate swap fee. - swapFee := terms.SwapFeeBase + - request.Amount*btcutil.Amount(terms.SwapFeeRate)/ - btcutil.Amount(swap.FeeRateTotalParts) + quote, err := s.Server.GetLoopInQuote(ctx, request.Amount) + if err != nil { + return nil, err + } + + swapFee := quote.SwapFee // We don't calculate the on-chain fee if the HTLC is going to be // published externally. @@ -478,7 +485,7 @@ func (s *Client) LoopInQuote(ctx context.Context, MinerFee: 0, }, nil } - + // Get estimate for miner fee. minerFee, err := s.lndServices.Client.EstimateFeeToP2WSH( ctx, request.Amount, request.HtlcConfTarget, @@ -488,8 +495,9 @@ func (s *Client) LoopInQuote(ctx context.Context, } return &LoopInQuote{ - SwapFee: swapFee, - MinerFee: minerFee, + SwapFee: swapFee, + MinerFee: minerFee, + CltvDelta: quote.CltvDelta, }, nil } diff --git a/cmd/loopd/swapclient_server.go b/cmd/loopd/swapclient_server.go index 30cec13..a05626a 100644 --- a/cmd/loopd/swapclient_server.go +++ b/cmd/loopd/swapclient_server.go @@ -267,9 +267,11 @@ func (s *swapClientServer) LoopOutQuote(ctx context.Context, } return &looprpc.QuoteResponse{ - MinerFee: int64(quote.MinerFee), - PrepayAmt: int64(quote.PrepayAmount), - SwapFee: int64(quote.SwapFee), + MinerFee: int64(quote.MinerFee), + PrepayAmt: int64(quote.PrepayAmount), + SwapFee: int64(quote.SwapFee), + SwapPaymentDest: quote.SwapPaymentDest[:], + CltvDelta: quote.CltvDelta, }, nil } diff --git a/interface.go b/interface.go index fadc2b8..b3d646d 100644 --- a/interface.go +++ b/interface.go @@ -105,6 +105,17 @@ type LoopOutQuoteRequest struct { // final cltv delta values for the off-chain payments. } +// LoopOutTerms are the server terms on which it executes swaps. +type LoopOutTerms struct { + // MinSwapAmount is the minimum amount that the server requires for a + // swap. + MinSwapAmount btcutil.Amount + + // MaxSwapAmount is the maximum amount that the server accepts for a + // swap. + MaxSwapAmount btcutil.Amount +} + // LoopOutQuote contains estimates for the fees making up the total swap cost // for the client. type LoopOutQuote struct { @@ -118,27 +129,6 @@ type LoopOutQuote struct { // MinerFee is an estimate of the on-chain fee that needs to be paid to // sweep the htlc. MinerFee btcutil.Amount -} - -// LoopOutTerms are the server terms on which it executes swaps. -type LoopOutTerms struct { - // SwapFeeBase is the fixed per-swap base fee. - SwapFeeBase btcutil.Amount - - // SwapFeeRate is the variable fee in parts per million. - SwapFeeRate int64 - - // PrepayAmt is the fixed part of the swap fee that needs to be - // prepaid. - PrepayAmt btcutil.Amount - - // MinSwapAmount is the minimum amount that the server requires for a - // swap. - MinSwapAmount btcutil.Amount - - // MaxSwapAmount is the maximum amount that the server accepts for a - // swap. - MaxSwapAmount btcutil.Amount // Time lock delta relative to current block height that swap server // will accept on the swap initiation call. @@ -185,12 +175,6 @@ type LoopInRequest struct { // LoopInTerms are the server terms on which it executes charge swaps. type LoopInTerms struct { - // SwapFeeBase is the fixed per-swap base fee. - SwapFeeBase btcutil.Amount - - // SwapFeeRate is the variable fee in parts per million. - SwapFeeRate int64 - // MinSwapAmount is the minimum amount that the server requires for a // swap. MinSwapAmount btcutil.Amount @@ -198,10 +182,6 @@ type LoopInTerms struct { // MaxSwapAmount is the maximum amount that the server accepts for a // swap. MaxSwapAmount btcutil.Amount - - // Time lock delta relative to current block height that swap server - // will accept on the swap initiation call. - CltvDelta int32 } // In contains status information for a loop in swap. @@ -239,6 +219,10 @@ type LoopInQuote struct { // MinerFee is an estimate of the on-chain fee that needs to be paid to // sweep the htlc. MinerFee btcutil.Amount + + // Time lock delta relative to current block height that swap server + // will accept on the swap initiation call. + CltvDelta int32 } // SwapInfoKit contains common swap info fields. diff --git a/loopin.go b/loopin.go index e7874a1..229718f 100644 --- a/loopin.go +++ b/loopin.go @@ -60,14 +60,12 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig, // Request current server loop in terms and use these to calculate the // swap fee that we should subtract from the swap amount in the payment // request that we send to the server. - quote, err := cfg.server.GetLoopInTerms(globalCtx) + quote, err := cfg.server.GetLoopInQuote(globalCtx, request.Amount) if err != nil { return nil, fmt.Errorf("loop in terms: %v", err) } - swapFee := swap.CalcFee( - request.Amount, quote.SwapFeeBase, quote.SwapFeeRate, - ) + swapFee := quote.SwapFee if swapFee > request.MaxSwapFee { logger.Warnf("Swap fee %v exceeding maximum of %v", diff --git a/looprpc/server.pb.go b/looprpc/server.pb.go index 43036ff..b084aaf 100644 --- a/looprpc/server.pb.go +++ b/looprpc/server.pb.go @@ -142,6 +142,8 @@ func (m *ServerLoopOutResponse) GetExpiry() int32 { } type ServerLoopOutQuoteRequest struct { + /// The swap amount. If zero, a quote for a maximum amt swap will be given. + Amt uint64 `protobuf:"varint,1,opt,name=amt,proto3" json:"amt,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -172,13 +174,22 @@ func (m *ServerLoopOutQuoteRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ServerLoopOutQuoteRequest proto.InternalMessageInfo +func (m *ServerLoopOutQuoteRequest) GetAmt() uint64 { + if m != nil { + return m.Amt + } + return 0 +} + type ServerLoopOutQuote struct { - SwapPaymentDest string `protobuf:"bytes,1,opt,name=swap_payment_dest,json=swapPaymentDest,proto3" json:"swap_payment_dest,omitempty"` - SwapFeeBase int64 `protobuf:"varint,2,opt,name=swap_fee_base,json=swapFeeBase,proto3" json:"swap_fee_base,omitempty"` - SwapFeeRate int64 `protobuf:"varint,3,opt,name=swap_fee_rate,json=swapFeeRate,proto3" json:"swap_fee_rate,omitempty"` + SwapPaymentDest string `protobuf:"bytes,1,opt,name=swap_payment_dest,json=swapPaymentDest,proto3" json:"swap_payment_dest,omitempty"` + /// The total estimated swap fee given the quote amt. + SwapFee int64 `protobuf:"varint,2,opt,name=swap_fee,json=swapFee,proto3" json:"swap_fee,omitempty"` + /// Deprecated, total swap fee given quote amt is calculated in swap_fee. + SwapFeeRate int64 `protobuf:"varint,3,opt,name=swap_fee_rate,json=swapFeeRate,proto3" json:"swap_fee_rate,omitempty"` // Deprecated: Do not use. PrepayAmt uint64 `protobuf:"varint,4,opt,name=prepay_amt,json=prepayAmt,proto3" json:"prepay_amt,omitempty"` - MinSwapAmount uint64 `protobuf:"varint,5,opt,name=min_swap_amount,json=minSwapAmount,proto3" json:"min_swap_amount,omitempty"` - MaxSwapAmount uint64 `protobuf:"varint,6,opt,name=max_swap_amount,json=maxSwapAmount,proto3" json:"max_swap_amount,omitempty"` + MinSwapAmount uint64 `protobuf:"varint,5,opt,name=min_swap_amount,json=minSwapAmount,proto3" json:"min_swap_amount,omitempty"` // Deprecated: Do not use. + MaxSwapAmount uint64 `protobuf:"varint,6,opt,name=max_swap_amount,json=maxSwapAmount,proto3" json:"max_swap_amount,omitempty"` // Deprecated: Do not use. CltvDelta int32 `protobuf:"varint,7,opt,name=cltv_delta,json=cltvDelta,proto3" json:"cltv_delta,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -217,13 +228,14 @@ func (m *ServerLoopOutQuote) GetSwapPaymentDest() string { return "" } -func (m *ServerLoopOutQuote) GetSwapFeeBase() int64 { +func (m *ServerLoopOutQuote) GetSwapFee() int64 { if m != nil { - return m.SwapFeeBase + return m.SwapFee } return 0 } +// Deprecated: Do not use. func (m *ServerLoopOutQuote) GetSwapFeeRate() int64 { if m != nil { return m.SwapFeeRate @@ -238,6 +250,7 @@ func (m *ServerLoopOutQuote) GetPrepayAmt() uint64 { return 0 } +// Deprecated: Do not use. func (m *ServerLoopOutQuote) GetMinSwapAmount() uint64 { if m != nil { return m.MinSwapAmount @@ -245,6 +258,7 @@ func (m *ServerLoopOutQuote) GetMinSwapAmount() uint64 { return 0 } +// Deprecated: Do not use. func (m *ServerLoopOutQuote) GetMaxSwapAmount() uint64 { if m != nil { return m.MaxSwapAmount @@ -259,6 +273,84 @@ func (m *ServerLoopOutQuote) GetCltvDelta() int32 { return 0 } +type ServerLoopOutTermsRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ServerLoopOutTermsRequest) Reset() { *m = ServerLoopOutTermsRequest{} } +func (m *ServerLoopOutTermsRequest) String() string { return proto.CompactTextString(m) } +func (*ServerLoopOutTermsRequest) ProtoMessage() {} +func (*ServerLoopOutTermsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ad098daeda4239f7, []int{4} +} + +func (m *ServerLoopOutTermsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ServerLoopOutTermsRequest.Unmarshal(m, b) +} +func (m *ServerLoopOutTermsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ServerLoopOutTermsRequest.Marshal(b, m, deterministic) +} +func (m *ServerLoopOutTermsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ServerLoopOutTermsRequest.Merge(m, src) +} +func (m *ServerLoopOutTermsRequest) XXX_Size() int { + return xxx_messageInfo_ServerLoopOutTermsRequest.Size(m) +} +func (m *ServerLoopOutTermsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ServerLoopOutTermsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ServerLoopOutTermsRequest proto.InternalMessageInfo + +type ServerLoopOutTerms struct { + MinSwapAmount uint64 `protobuf:"varint,1,opt,name=min_swap_amount,json=minSwapAmount,proto3" json:"min_swap_amount,omitempty"` + MaxSwapAmount uint64 `protobuf:"varint,2,opt,name=max_swap_amount,json=maxSwapAmount,proto3" json:"max_swap_amount,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ServerLoopOutTerms) Reset() { *m = ServerLoopOutTerms{} } +func (m *ServerLoopOutTerms) String() string { return proto.CompactTextString(m) } +func (*ServerLoopOutTerms) ProtoMessage() {} +func (*ServerLoopOutTerms) Descriptor() ([]byte, []int) { + return fileDescriptor_ad098daeda4239f7, []int{5} +} + +func (m *ServerLoopOutTerms) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ServerLoopOutTerms.Unmarshal(m, b) +} +func (m *ServerLoopOutTerms) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ServerLoopOutTerms.Marshal(b, m, deterministic) +} +func (m *ServerLoopOutTerms) XXX_Merge(src proto.Message) { + xxx_messageInfo_ServerLoopOutTerms.Merge(m, src) +} +func (m *ServerLoopOutTerms) XXX_Size() int { + return xxx_messageInfo_ServerLoopOutTerms.Size(m) +} +func (m *ServerLoopOutTerms) XXX_DiscardUnknown() { + xxx_messageInfo_ServerLoopOutTerms.DiscardUnknown(m) +} + +var xxx_messageInfo_ServerLoopOutTerms proto.InternalMessageInfo + +func (m *ServerLoopOutTerms) GetMinSwapAmount() uint64 { + if m != nil { + return m.MinSwapAmount + } + return 0 +} + +func (m *ServerLoopOutTerms) GetMaxSwapAmount() uint64 { + if m != nil { + return m.MaxSwapAmount + } + return 0 +} + type ServerLoopInRequest struct { SenderKey []byte `protobuf:"bytes,1,opt,name=sender_key,json=senderKey,proto3" json:"sender_key,omitempty"` SwapHash []byte `protobuf:"bytes,2,opt,name=swap_hash,json=swapHash,proto3" json:"swap_hash,omitempty"` @@ -273,7 +365,7 @@ func (m *ServerLoopInRequest) Reset() { *m = ServerLoopInRequest{} } func (m *ServerLoopInRequest) String() string { return proto.CompactTextString(m) } func (*ServerLoopInRequest) ProtoMessage() {} func (*ServerLoopInRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ad098daeda4239f7, []int{4} + return fileDescriptor_ad098daeda4239f7, []int{6} } func (m *ServerLoopInRequest) XXX_Unmarshal(b []byte) error { @@ -334,7 +426,7 @@ func (m *ServerLoopInResponse) Reset() { *m = ServerLoopInResponse{} } func (m *ServerLoopInResponse) String() string { return proto.CompactTextString(m) } func (*ServerLoopInResponse) ProtoMessage() {} func (*ServerLoopInResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad098daeda4239f7, []int{5} + return fileDescriptor_ad098daeda4239f7, []int{7} } func (m *ServerLoopInResponse) XXX_Unmarshal(b []byte) error { @@ -370,6 +462,8 @@ func (m *ServerLoopInResponse) GetExpiry() int32 { } type ServerLoopInQuoteRequest struct { + /// The swap amount. If zero, a quote for a maximum amt swap will be given. + Amt uint64 `protobuf:"varint,1,opt,name=amt,proto3" json:"amt,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -379,7 +473,7 @@ func (m *ServerLoopInQuoteRequest) Reset() { *m = ServerLoopInQuoteReque func (m *ServerLoopInQuoteRequest) String() string { return proto.CompactTextString(m) } func (*ServerLoopInQuoteRequest) ProtoMessage() {} func (*ServerLoopInQuoteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ad098daeda4239f7, []int{6} + return fileDescriptor_ad098daeda4239f7, []int{8} } func (m *ServerLoopInQuoteRequest) XXX_Unmarshal(b []byte) error { @@ -400,11 +494,18 @@ func (m *ServerLoopInQuoteRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ServerLoopInQuoteRequest proto.InternalMessageInfo +func (m *ServerLoopInQuoteRequest) GetAmt() uint64 { + if m != nil { + return m.Amt + } + return 0 +} + type ServerLoopInQuoteResponse struct { - SwapFeeBase int64 `protobuf:"varint,1,opt,name=swap_fee_base,json=swapFeeBase,proto3" json:"swap_fee_base,omitempty"` - SwapFeeRate int64 `protobuf:"varint,2,opt,name=swap_fee_rate,json=swapFeeRate,proto3" json:"swap_fee_rate,omitempty"` - MinSwapAmount uint64 `protobuf:"varint,4,opt,name=min_swap_amount,json=minSwapAmount,proto3" json:"min_swap_amount,omitempty"` - MaxSwapAmount uint64 `protobuf:"varint,5,opt,name=max_swap_amount,json=maxSwapAmount,proto3" json:"max_swap_amount,omitempty"` + SwapFee int64 `protobuf:"varint,1,opt,name=swap_fee,json=swapFee,proto3" json:"swap_fee,omitempty"` + SwapFeeRate int64 `protobuf:"varint,2,opt,name=swap_fee_rate,json=swapFeeRate,proto3" json:"swap_fee_rate,omitempty"` // Deprecated: Do not use. + MinSwapAmount uint64 `protobuf:"varint,4,opt,name=min_swap_amount,json=minSwapAmount,proto3" json:"min_swap_amount,omitempty"` // Deprecated: Do not use. + MaxSwapAmount uint64 `protobuf:"varint,5,opt,name=max_swap_amount,json=maxSwapAmount,proto3" json:"max_swap_amount,omitempty"` // Deprecated: Do not use. CltvDelta int32 `protobuf:"varint,6,opt,name=cltv_delta,json=cltvDelta,proto3" json:"cltv_delta,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -415,7 +516,7 @@ func (m *ServerLoopInQuoteResponse) Reset() { *m = ServerLoopInQuoteResp func (m *ServerLoopInQuoteResponse) String() string { return proto.CompactTextString(m) } func (*ServerLoopInQuoteResponse) ProtoMessage() {} func (*ServerLoopInQuoteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad098daeda4239f7, []int{7} + return fileDescriptor_ad098daeda4239f7, []int{9} } func (m *ServerLoopInQuoteResponse) XXX_Unmarshal(b []byte) error { @@ -436,13 +537,14 @@ func (m *ServerLoopInQuoteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ServerLoopInQuoteResponse proto.InternalMessageInfo -func (m *ServerLoopInQuoteResponse) GetSwapFeeBase() int64 { +func (m *ServerLoopInQuoteResponse) GetSwapFee() int64 { if m != nil { - return m.SwapFeeBase + return m.SwapFee } return 0 } +// Deprecated: Do not use. func (m *ServerLoopInQuoteResponse) GetSwapFeeRate() int64 { if m != nil { return m.SwapFeeRate @@ -450,6 +552,7 @@ func (m *ServerLoopInQuoteResponse) GetSwapFeeRate() int64 { return 0 } +// Deprecated: Do not use. func (m *ServerLoopInQuoteResponse) GetMinSwapAmount() uint64 { if m != nil { return m.MinSwapAmount @@ -457,6 +560,7 @@ func (m *ServerLoopInQuoteResponse) GetMinSwapAmount() uint64 { return 0 } +// Deprecated: Do not use. func (m *ServerLoopInQuoteResponse) GetMaxSwapAmount() uint64 { if m != nil { return m.MaxSwapAmount @@ -471,56 +575,144 @@ func (m *ServerLoopInQuoteResponse) GetCltvDelta() int32 { return 0 } +type ServerLoopInTermsRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ServerLoopInTermsRequest) Reset() { *m = ServerLoopInTermsRequest{} } +func (m *ServerLoopInTermsRequest) String() string { return proto.CompactTextString(m) } +func (*ServerLoopInTermsRequest) ProtoMessage() {} +func (*ServerLoopInTermsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ad098daeda4239f7, []int{10} +} + +func (m *ServerLoopInTermsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ServerLoopInTermsRequest.Unmarshal(m, b) +} +func (m *ServerLoopInTermsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ServerLoopInTermsRequest.Marshal(b, m, deterministic) +} +func (m *ServerLoopInTermsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ServerLoopInTermsRequest.Merge(m, src) +} +func (m *ServerLoopInTermsRequest) XXX_Size() int { + return xxx_messageInfo_ServerLoopInTermsRequest.Size(m) +} +func (m *ServerLoopInTermsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ServerLoopInTermsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ServerLoopInTermsRequest proto.InternalMessageInfo + +type ServerLoopInTerms struct { + MinSwapAmount uint64 `protobuf:"varint,1,opt,name=min_swap_amount,json=minSwapAmount,proto3" json:"min_swap_amount,omitempty"` + MaxSwapAmount uint64 `protobuf:"varint,2,opt,name=max_swap_amount,json=maxSwapAmount,proto3" json:"max_swap_amount,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ServerLoopInTerms) Reset() { *m = ServerLoopInTerms{} } +func (m *ServerLoopInTerms) String() string { return proto.CompactTextString(m) } +func (*ServerLoopInTerms) ProtoMessage() {} +func (*ServerLoopInTerms) Descriptor() ([]byte, []int) { + return fileDescriptor_ad098daeda4239f7, []int{11} +} + +func (m *ServerLoopInTerms) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ServerLoopInTerms.Unmarshal(m, b) +} +func (m *ServerLoopInTerms) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ServerLoopInTerms.Marshal(b, m, deterministic) +} +func (m *ServerLoopInTerms) XXX_Merge(src proto.Message) { + xxx_messageInfo_ServerLoopInTerms.Merge(m, src) +} +func (m *ServerLoopInTerms) XXX_Size() int { + return xxx_messageInfo_ServerLoopInTerms.Size(m) +} +func (m *ServerLoopInTerms) XXX_DiscardUnknown() { + xxx_messageInfo_ServerLoopInTerms.DiscardUnknown(m) +} + +var xxx_messageInfo_ServerLoopInTerms proto.InternalMessageInfo + +func (m *ServerLoopInTerms) GetMinSwapAmount() uint64 { + if m != nil { + return m.MinSwapAmount + } + return 0 +} + +func (m *ServerLoopInTerms) GetMaxSwapAmount() uint64 { + if m != nil { + return m.MaxSwapAmount + } + return 0 +} + func init() { proto.RegisterType((*ServerLoopOutRequest)(nil), "looprpc.ServerLoopOutRequest") proto.RegisterType((*ServerLoopOutResponse)(nil), "looprpc.ServerLoopOutResponse") proto.RegisterType((*ServerLoopOutQuoteRequest)(nil), "looprpc.ServerLoopOutQuoteRequest") proto.RegisterType((*ServerLoopOutQuote)(nil), "looprpc.ServerLoopOutQuote") + proto.RegisterType((*ServerLoopOutTermsRequest)(nil), "looprpc.ServerLoopOutTermsRequest") + proto.RegisterType((*ServerLoopOutTerms)(nil), "looprpc.ServerLoopOutTerms") proto.RegisterType((*ServerLoopInRequest)(nil), "looprpc.ServerLoopInRequest") proto.RegisterType((*ServerLoopInResponse)(nil), "looprpc.ServerLoopInResponse") proto.RegisterType((*ServerLoopInQuoteRequest)(nil), "looprpc.ServerLoopInQuoteRequest") proto.RegisterType((*ServerLoopInQuoteResponse)(nil), "looprpc.ServerLoopInQuoteResponse") + proto.RegisterType((*ServerLoopInTermsRequest)(nil), "looprpc.ServerLoopInTermsRequest") + proto.RegisterType((*ServerLoopInTerms)(nil), "looprpc.ServerLoopInTerms") } func init() { proto.RegisterFile("server.proto", fileDescriptor_ad098daeda4239f7) } var fileDescriptor_ad098daeda4239f7 = []byte{ - // 557 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xeb, 0x6e, 0xda, 0x4c, - 0x14, 0x94, 0xcd, 0x25, 0x1f, 0x07, 0x48, 0xbe, 0x6e, 0x2f, 0x72, 0x21, 0x54, 0xc4, 0x52, 0x2b, - 0xd4, 0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5d, 0x6d, 0x48, 0xae, 0x21, 0x35, 0x53, 0x74, - 0x4d, 0xeb, 0x00, 0x48, 0x64, 0x63, 0xab, 0xb9, 0x64, 0x34, 0xd5, 0x52, 0x44, 0x2b, 0x7e, 0x01, - 0x55, 0x5c, 0x8a, 0x28, 0x59, 0x79, 0xe5, 0xae, 0xd3, 0xab, 0x04, 0xf6, 0x9b, 0xdf, 0x86, 0x97, - 0x39, 0x65, 0x97, 0x33, 0xae, 0xd0, 0x3a, 0xe1, 0xff, 0x76, 0x81, 0xec, 0x4f, 0xc9, 0x5b, 0x78, - 0x62, 0x44, 0x0b, 0xba, 0x8a, 0x91, 0xa9, 0x70, 0x8c, 0x52, 0x59, 0xe5, 0x47, 0x7a, 0xf0, 0x35, - 0xc5, 0xcf, 0xb5, 0x99, 0x3e, 0x34, 0x0d, 0xf7, 0x3b, 0x62, 0x78, 0x4d, 0x65, 0x2a, 0xbe, 0x94, - 0xde, 0xf0, 0x23, 0xe2, 0x07, 0x2a, 0x31, 0xc7, 0x49, 0xa8, 0x42, 0xa3, 0x7e, 0xcb, 0x09, 0xa8, - 0x32, 0xd7, 0xb3, 0x2e, 0x68, 0x6f, 0xcb, 0xc6, 0xdb, 0x5a, 0x8a, 0x9c, 0xc5, 0x8a, 0xbc, 0x81, - 0xa3, 0x38, 0x62, 0xa1, 0x39, 0x86, 0xc6, 0x7c, 0xc6, 0x94, 0x57, 0x31, 0x9c, 0x66, 0x1c, 0xb1, - 0xab, 0x05, 0x15, 0x67, 0x06, 0x34, 0x3c, 0xba, 0xcc, 0xf1, 0xaa, 0x96, 0x47, 0x97, 0x19, 0x5e, - 0x07, 0x60, 0x34, 0x55, 0xf3, 0x70, 0x8c, 0x53, 0x45, 0xbd, 0x03, 0x63, 0x59, 0x4d, 0x23, 0xe7, - 0x1a, 0xf0, 0x7f, 0x39, 0xf0, 0x74, 0x6b, 0xcc, 0x80, 0xad, 0xab, 0x93, 0x0f, 0xc1, 0xd9, 0x0d, - 0xe1, 0xdf, 0x6a, 0xb3, 0x57, 0x8e, 0xf2, 0x5e, 0x39, 0xfc, 0xcb, 0x6c, 0x87, 0xb5, 0x8e, 0x6d, - 0xaf, 0x1e, 0xea, 0xf0, 0xb6, 0x11, 0x6e, 0xae, 0x11, 0x2d, 0xf0, 0xb2, 0x47, 0xe6, 0x0a, 0x71, - 0xeb, 0x64, 0xeb, 0xb2, 0x19, 0xda, 0xa5, 0x7b, 0x59, 0x3b, 0x8f, 0xc8, 0xda, 0xdd, 0xcf, 0xba, - 0x20, 0xcc, 0xf2, 0x23, 0xc3, 0xac, 0x3c, 0x1c, 0x66, 0x75, 0x27, 0xcc, 0x77, 0xb7, 0x2e, 0x80, - 0x66, 0xa7, 0x17, 0x23, 0x43, 0x38, 0xfc, 0x82, 0x0b, 0x5b, 0x78, 0x8d, 0x93, 0x4e, 0xdf, 0x3e, - 0x28, 0xfd, 0xa2, 0xf7, 0xa2, 0xf5, 0xea, 0xae, 0xb1, 0xb5, 0x65, 0x08, 0x8d, 0xdc, 0xdf, 0xc7, - 0x2f, 0xe6, 0x67, 0x8d, 0x6e, 0xb5, 0xef, 0xe1, 0x90, 0x0b, 0x68, 0x5a, 0x85, 0x03, 0x63, 0x07, - 0x39, 0x2e, 0x60, 0x6f, 0x4a, 0xd9, 0xea, 0xdc, 0x31, 0xb5, 0xf2, 0xbe, 0x41, 0x3d, 0x13, 0x26, - 0x39, 0x29, 0x64, 0xe7, 0xc4, 0xf9, 0xf7, 0x51, 0xd2, 0x53, 0xaf, 0xab, 0xe6, 0x8d, 0x7d, 0xff, - 0x37, 0x00, 0x00, 0xff, 0xff, 0x25, 0x8b, 0xb7, 0x4e, 0x9a, 0x05, 0x00, 0x00, + // 641 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x6b, 0x4e, 0xdb, 0x4c, + 0x14, 0x95, 0xed, 0x10, 0xbe, 0x5c, 0x12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0x61, 0x3e, 0x4f, 0x4d, 0x0a, 0x75, 0x83, + 0x33, 0x58, 0xc9, 0x1b, 0xbc, 0x53, 0xc3, 0x2d, 0x5e, 0x4c, 0xbf, 0xdf, 0x4c, 0x21, 0x67, 0xd0, + 0x33, 0xfb, 0x9e, 0xaa, 0xeb, 0x20, 0x5b, 0xb5, 0xe4, 0xac, 0xd5, 0xa0, 0xa1, 0x6a, 0x96, 0xbd, + 0xca, 0xb4, 0x69, 0xa9, 0xf5, 0xda, 0x0a, 0xab, 0x7a, 0xf7, 0x51, 0x74, 0xd7, 0xcf, 0x6d, 0xf5, + 0x83, 0xf9, 0xf6, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xf9, 0x2f, 0x6f, 0x67, 0x07, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -535,8 +727,10 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type SwapServerClient interface { + LoopOutTerms(ctx context.Context, in *ServerLoopOutTermsRequest, opts ...grpc.CallOption) (*ServerLoopOutTerms, error) NewLoopOutSwap(ctx context.Context, in *ServerLoopOutRequest, opts ...grpc.CallOption) (*ServerLoopOutResponse, error) LoopOutQuote(ctx context.Context, in *ServerLoopOutQuoteRequest, opts ...grpc.CallOption) (*ServerLoopOutQuote, error) + LoopInTerms(ctx context.Context, in *ServerLoopInTermsRequest, opts ...grpc.CallOption) (*ServerLoopInTerms, error) NewLoopInSwap(ctx context.Context, in *ServerLoopInRequest, opts ...grpc.CallOption) (*ServerLoopInResponse, error) LoopInQuote(ctx context.Context, in *ServerLoopInQuoteRequest, opts ...grpc.CallOption) (*ServerLoopInQuoteResponse, error) } @@ -549,6 +743,15 @@ func NewSwapServerClient(cc *grpc.ClientConn) SwapServerClient { return &swapServerClient{cc} } +func (c *swapServerClient) LoopOutTerms(ctx context.Context, in *ServerLoopOutTermsRequest, opts ...grpc.CallOption) (*ServerLoopOutTerms, error) { + out := new(ServerLoopOutTerms) + err := c.cc.Invoke(ctx, "/looprpc.SwapServer/LoopOutTerms", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *swapServerClient) NewLoopOutSwap(ctx context.Context, in *ServerLoopOutRequest, opts ...grpc.CallOption) (*ServerLoopOutResponse, error) { out := new(ServerLoopOutResponse) err := c.cc.Invoke(ctx, "/looprpc.SwapServer/NewLoopOutSwap", in, out, opts...) @@ -567,6 +770,15 @@ func (c *swapServerClient) LoopOutQuote(ctx context.Context, in *ServerLoopOutQu return out, nil } +func (c *swapServerClient) LoopInTerms(ctx context.Context, in *ServerLoopInTermsRequest, opts ...grpc.CallOption) (*ServerLoopInTerms, error) { + out := new(ServerLoopInTerms) + err := c.cc.Invoke(ctx, "/looprpc.SwapServer/LoopInTerms", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *swapServerClient) NewLoopInSwap(ctx context.Context, in *ServerLoopInRequest, opts ...grpc.CallOption) (*ServerLoopInResponse, error) { out := new(ServerLoopInResponse) err := c.cc.Invoke(ctx, "/looprpc.SwapServer/NewLoopInSwap", in, out, opts...) @@ -587,8 +799,10 @@ func (c *swapServerClient) LoopInQuote(ctx context.Context, in *ServerLoopInQuot // SwapServerServer is the server API for SwapServer service. type SwapServerServer interface { + LoopOutTerms(context.Context, *ServerLoopOutTermsRequest) (*ServerLoopOutTerms, error) NewLoopOutSwap(context.Context, *ServerLoopOutRequest) (*ServerLoopOutResponse, error) LoopOutQuote(context.Context, *ServerLoopOutQuoteRequest) (*ServerLoopOutQuote, error) + LoopInTerms(context.Context, *ServerLoopInTermsRequest) (*ServerLoopInTerms, error) NewLoopInSwap(context.Context, *ServerLoopInRequest) (*ServerLoopInResponse, error) LoopInQuote(context.Context, *ServerLoopInQuoteRequest) (*ServerLoopInQuoteResponse, error) } @@ -597,6 +811,24 @@ func RegisterSwapServerServer(s *grpc.Server, srv SwapServerServer) { s.RegisterService(&_SwapServer_serviceDesc, srv) } +func _SwapServer_LoopOutTerms_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ServerLoopOutTermsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SwapServerServer).LoopOutTerms(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/looprpc.SwapServer/LoopOutTerms", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SwapServerServer).LoopOutTerms(ctx, req.(*ServerLoopOutTermsRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _SwapServer_NewLoopOutSwap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ServerLoopOutRequest) if err := dec(in); err != nil { @@ -633,6 +865,24 @@ func _SwapServer_LoopOutQuote_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _SwapServer_LoopInTerms_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ServerLoopInTermsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SwapServerServer).LoopInTerms(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/looprpc.SwapServer/LoopInTerms", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SwapServerServer).LoopInTerms(ctx, req.(*ServerLoopInTermsRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _SwapServer_NewLoopInSwap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ServerLoopInRequest) if err := dec(in); err != nil { @@ -673,6 +923,10 @@ var _SwapServer_serviceDesc = grpc.ServiceDesc{ ServiceName: "looprpc.SwapServer", HandlerType: (*SwapServerServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "LoopOutTerms", + Handler: _SwapServer_LoopOutTerms_Handler, + }, { MethodName: "NewLoopOutSwap", Handler: _SwapServer_NewLoopOutSwap_Handler, @@ -681,6 +935,10 @@ var _SwapServer_serviceDesc = grpc.ServiceDesc{ MethodName: "LoopOutQuote", Handler: _SwapServer_LoopOutQuote_Handler, }, + { + MethodName: "LoopInTerms", + Handler: _SwapServer_LoopInTerms_Handler, + }, { MethodName: "NewLoopInSwap", Handler: _SwapServer_NewLoopInSwap_Handler, diff --git a/looprpc/server.proto b/looprpc/server.proto index 8e503c1..dd1ca10 100644 --- a/looprpc/server.proto +++ b/looprpc/server.proto @@ -5,10 +5,14 @@ import "google/api/annotations.proto"; package looprpc; service SwapServer { + rpc LoopOutTerms(ServerLoopOutTermsRequest) returns (ServerLoopOutTerms); + rpc NewLoopOutSwap(ServerLoopOutRequest) returns (ServerLoopOutResponse); - + rpc LoopOutQuote(ServerLoopOutQuoteRequest) returns (ServerLoopOutQuote); + rpc LoopInTerms(ServerLoopInTermsRequest) returns (ServerLoopInTerms); + rpc NewLoopInSwap(ServerLoopInRequest) returns (ServerLoopInResponse); rpc LoopInQuote(ServerLoopInQuoteRequest) returns (ServerLoopInQuoteResponse); @@ -33,24 +37,36 @@ message ServerLoopOutResponse { } message ServerLoopOutQuoteRequest { + /// The swap amount. If zero, a quote for a maximum amt swap will be given. + uint64 amt = 1; } message ServerLoopOutQuote { string swap_payment_dest = 1; - int64 swap_fee_base = 2; + /// The total estimated swap fee given the quote amt. + int64 swap_fee = 2; - int64 swap_fee_rate = 3; + /// Deprecated, total swap fee given quote amt is calculated in swap_fee. + int64 swap_fee_rate = 3 [deprecated = true]; uint64 prepay_amt = 4; - uint64 min_swap_amount = 5; + uint64 min_swap_amount = 5 [deprecated = true]; - uint64 max_swap_amount = 6; + uint64 max_swap_amount = 6 [deprecated = true]; int32 cltv_delta = 7; } +message ServerLoopOutTermsRequest { +} + +message ServerLoopOutTerms { + uint64 min_swap_amount = 1; + uint64 max_swap_amount = 2; +} + message ServerLoopInRequest { bytes sender_key = 1; bytes swap_hash = 2; @@ -64,12 +80,22 @@ message ServerLoopInResponse { } message ServerLoopInQuoteRequest { + /// The swap amount. If zero, a quote for a maximum amt swap will be given. + uint64 amt = 1; } message ServerLoopInQuoteResponse { - int64 swap_fee_base = 1; - int64 swap_fee_rate = 2; - uint64 min_swap_amount = 4; - uint64 max_swap_amount = 5; + int64 swap_fee = 1; + int64 swap_fee_rate = 2 [deprecated=true]; + uint64 min_swap_amount = 4 [deprecated=true]; + uint64 max_swap_amount = 5 [deprecated=true]; int32 cltv_delta = 6; } + +message ServerLoopInTermsRequest { +} + +message ServerLoopInTerms { + uint64 min_swap_amount = 1; + uint64 max_swap_amount = 2; +} diff --git a/server_mock_test.go b/server_mock_test.go index 9c59fe6..44cc555 100644 --- a/server_mock_test.go +++ b/server_mock_test.go @@ -21,8 +21,7 @@ var ( testLoopOutOnChainCltvDelta = int32(30) testChargeOnChainCltvDelta = int32(100) testCltvDelta = 50 - testSwapFeeBase = btcutil.Amount(21) - testSwapFeeRate = int64(100) + testSwapFee = btcutil.Amount(210) testInvoiceExpiry = 180 * time.Second testFixedPrepayAmount = btcutil.Amount(100) testMinSwapAmount = btcutil.Amount(10000) @@ -45,6 +44,8 @@ type serverMock struct { swapHash lntypes.Hash } +var _ swapServerClient = (*serverMock)(nil) + func newServerMock() *serverMock { return &serverMock{ expectedSwapAmt: 50000, @@ -94,16 +95,22 @@ func (s *serverMock) NewLoopOutSwap(ctx context.Context, func (s *serverMock) GetLoopOutTerms(ctx context.Context) ( *LoopOutTerms, error) { + return &LoopOutTerms{ + MinSwapAmount: testMinSwapAmount, + MaxSwapAmount: testMaxSwapAmount, + }, nil +} + +func (s *serverMock) GetLoopOutQuote(ctx context.Context, amt btcutil.Amount) ( + *LoopOutQuote, error) { + dest := [33]byte{1, 2, 3} - return &LoopOutTerms{ - SwapFeeBase: testSwapFeeBase, - SwapFeeRate: testSwapFeeRate, + return &LoopOutQuote{ + SwapFee: testSwapFee, SwapPaymentDest: dest, CltvDelta: testLoopOutOnChainCltvDelta, - MinSwapAmount: testMinSwapAmount, - MaxSwapAmount: testMaxSwapAmount, - PrepayAmt: testFixedPrepayAmount, + PrepayAmount: testFixedPrepayAmount, }, nil } @@ -154,10 +161,16 @@ func (s *serverMock) GetLoopInTerms(ctx context.Context) ( *LoopInTerms, error) { return &LoopInTerms{ - SwapFeeBase: testSwapFeeBase, - SwapFeeRate: testSwapFeeRate, - CltvDelta: testChargeOnChainCltvDelta, MinSwapAmount: testMinSwapAmount, MaxSwapAmount: testMaxSwapAmount, }, nil } + +func (s *serverMock) GetLoopInQuote(ctx context.Context, amt btcutil.Amount) ( + *LoopInQuote, error) { + + return &LoopInQuote{ + SwapFee: testSwapFee, + CltvDelta: testChargeOnChainCltvDelta, + }, nil +} diff --git a/swap_server_client.go b/swap_server_client.go index 466ea64..527cc0d 100644 --- a/swap_server_client.go +++ b/swap_server_client.go @@ -20,9 +20,15 @@ type swapServerClient interface { GetLoopOutTerms(ctx context.Context) ( *LoopOutTerms, error) + GetLoopOutQuote(ctx context.Context, amt btcutil.Amount) ( + *LoopOutQuote, error) + GetLoopInTerms(ctx context.Context) ( *LoopInTerms, error) + GetLoopInQuote(ctx context.Context, amt btcutil.Amount) ( + *LoopInQuote, error) + NewLoopOutSwap(ctx context.Context, swapHash lntypes.Hash, amount btcutil.Amount, receiverKey [33]byte) ( @@ -39,6 +45,8 @@ type grpcSwapServerClient struct { conn *grpc.ClientConn } +var _ swapServerClient = (*grpcSwapServerClient)(nil) + func newSwapServerClient(address string, insecure bool) (*grpcSwapServerClient, error) { @@ -58,10 +66,30 @@ func newSwapServerClient(address string, func (s *grpcSwapServerClient) GetLoopOutTerms(ctx context.Context) ( *LoopOutTerms, error) { + rpcCtx, rpcCancel := context.WithTimeout(ctx, serverRPCTimeout) + defer rpcCancel() + terms, err := s.server.LoopOutTerms(rpcCtx, + &looprpc.ServerLoopOutTermsRequest{}, + ) + if err != nil { + return nil, err + } + + return &LoopOutTerms{ + MinSwapAmount: btcutil.Amount(terms.MinSwapAmount), + MaxSwapAmount: btcutil.Amount(terms.MaxSwapAmount), + }, nil +} + +func (s *grpcSwapServerClient) GetLoopOutQuote(ctx context.Context, + amt btcutil.Amount) (*LoopOutQuote, error) { + rpcCtx, rpcCancel := context.WithTimeout(ctx, serverRPCTimeout) defer rpcCancel() quoteResp, err := s.server.LoopOutQuote(rpcCtx, - &looprpc.ServerLoopOutQuoteRequest{}, + &looprpc.ServerLoopOutQuoteRequest{ + Amt: uint64(amt), + }, ) if err != nil { return nil, err @@ -77,12 +105,9 @@ func (s *grpcSwapServerClient) GetLoopOutTerms(ctx context.Context) ( var destArray [33]byte copy(destArray[:], dest) - return &LoopOutTerms{ - MinSwapAmount: btcutil.Amount(quoteResp.MinSwapAmount), - MaxSwapAmount: btcutil.Amount(quoteResp.MaxSwapAmount), - PrepayAmt: btcutil.Amount(quoteResp.PrepayAmt), - SwapFeeBase: btcutil.Amount(quoteResp.SwapFeeBase), - SwapFeeRate: quoteResp.SwapFeeRate, + return &LoopOutQuote{ + PrepayAmount: btcutil.Amount(quoteResp.PrepayAmt), + SwapFee: btcutil.Amount(quoteResp.SwapFee), CltvDelta: quoteResp.CltvDelta, SwapPaymentDest: destArray, }, nil @@ -93,19 +118,36 @@ func (s *grpcSwapServerClient) GetLoopInTerms(ctx context.Context) ( rpcCtx, rpcCancel := context.WithTimeout(ctx, serverRPCTimeout) defer rpcCancel() - quoteResp, err := s.server.LoopInQuote(rpcCtx, - &looprpc.ServerLoopInQuoteRequest{}, + terms, err := s.server.LoopInTerms(rpcCtx, + &looprpc.ServerLoopInTermsRequest{}, ) if err != nil { return nil, err } return &LoopInTerms{ - MinSwapAmount: btcutil.Amount(quoteResp.MinSwapAmount), - MaxSwapAmount: btcutil.Amount(quoteResp.MaxSwapAmount), - SwapFeeBase: btcutil.Amount(quoteResp.SwapFeeBase), - SwapFeeRate: quoteResp.SwapFeeRate, - CltvDelta: quoteResp.CltvDelta, + MinSwapAmount: btcutil.Amount(terms.MinSwapAmount), + MaxSwapAmount: btcutil.Amount(terms.MaxSwapAmount), + }, nil +} + +func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context, + amt btcutil.Amount) (*LoopInQuote, error) { + + rpcCtx, rpcCancel := context.WithTimeout(ctx, serverRPCTimeout) + defer rpcCancel() + quoteResp, err := s.server.LoopInQuote(rpcCtx, + &looprpc.ServerLoopInQuoteRequest{ + Amt: uint64(amt), + }, + ) + if err != nil { + return nil, err + } + + return &LoopInQuote{ + SwapFee: btcutil.Amount(quoteResp.SwapFee), + CltvDelta: quoteResp.CltvDelta, }, nil }