Skip to content

Commit

Permalink
rfq+rfqmsg: use new AssetRate type in NewBuyRequest func argument
Browse files Browse the repository at this point in the history
As a result of this change the price oracle's quote expiry value is
used in the request constructor.
  • Loading branch information
ffranr committed Oct 30, 2024
1 parent c93957c commit 0c9f87b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
11 changes: 7 additions & 4 deletions rfq/negotiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ func (n *Negotiator) HandleOutgoingBuyOrder(buyOrder BuyOrder) error {
// We calculate a proposed bid price for our peer's
// consideration. If a price oracle is not specified we will
// skip this step.
var assetRateBid fn.Option[rfqmath.BigIntFixedPoint]
var assetRateHint fn.Option[rfqmsg.AssetRate]

if n.cfg.PriceOracle != nil {
// Query the price oracle for a bid price.
rate, _, err := n.queryBidFromPriceOracle(
rate, expiryUnix, err := n.queryBidFromPriceOracle(
*buyOrder.Peer, buyOrder.AssetID,
buyOrder.AssetGroupKey, buyOrder.MinAssetAmount,
fn.None[rfqmsg.AssetRate](),
Expand All @@ -180,13 +180,16 @@ func (n *Negotiator) HandleOutgoingBuyOrder(buyOrder BuyOrder) error {
"request: %v", err)
}

assetRateBid = fn.Some[rfqmath.BigIntFixedPoint](*rate)
expiry := time.Unix(int64(expiryUnix), 0)
assetRateHint = fn.Some[rfqmsg.AssetRate](
rfqmsg.NewAssetRate(*rate, expiry),
)
}

request, err := rfqmsg.NewBuyRequest(
*buyOrder.Peer, buyOrder.AssetID,
buyOrder.AssetGroupKey, buyOrder.MinAssetAmount,
assetRateBid,
assetRateHint,
)
if err != nil {
err := fmt.Errorf("unable to create buy request "+
Expand Down
10 changes: 1 addition & 9 deletions rfqmsg/buy_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/rfqmath"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/tlv"
)
Expand Down Expand Up @@ -52,21 +51,14 @@ type BuyRequest struct {
// NewBuyRequest creates a new asset buy quote request.
func NewBuyRequest(peer route.Vertex, assetID *asset.ID,
assetGroupKey *btcec.PublicKey, assetAmount uint64,
rateHint fn.Option[rfqmath.BigIntFixedPoint]) (*BuyRequest, error) {
assetRateHint fn.Option[AssetRate]) (*BuyRequest, error) {

id, err := NewID()
if err != nil {
return nil, fmt.Errorf("unable to generate random "+
"quote request id: %w", err)
}

// Construct a suggested asset rate if a rate hint is provided.
var assetRateHint fn.Option[AssetRate]
rateHint.WhenSome(func(rate rfqmath.BigIntFixedPoint) {
expiry := time.Now().Add(DefaultQuoteLifetime).UTC()
assetRateHint = fn.Some(NewAssetRate(rate, expiry))
})

return &BuyRequest{
Peer: peer,
Version: latestBuyRequestVersion,
Expand Down

0 comments on commit 0c9f87b

Please sign in to comment.