Skip to content

Commit eeadc03

Browse files
author
ffranr
authored
Merge pull request #1156 from lightninglabs/rfq-rm-rate-tick
Remove remaining instances of "rate tick" from RFQ systems
2 parents 36a85b6 + 07ac6a4 commit eeadc03

19 files changed

+537
-540
lines changed

docs/examples/basic-price-oracle/main.go

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This example demonstrates a basic RPC price oracle server that implements the
2-
// QueryRateTick RPC method. The server listens on localhost:8095 and returns a
3-
// rate tick for a given transaction type, subject asset, and payment asset. The
4-
// rate tick is the exchange rate between the subject asset and the payment
2+
// QueryAssetRates RPC method. The server listens on localhost:8095 and returns
3+
// the asset rates for a given transaction type, subject asset, and payment
54
// asset.
65
package main
76

@@ -103,10 +102,10 @@ func isSupportedSubjectAsset(subjectAsset *oraclerpc.AssetSpecifier) bool {
103102
return false
104103
}
105104

106-
// getRateTick returns a rate tick for a given transaction type and subject
107-
// asset max amount.
108-
func getRateTick(transactionType oraclerpc.TransactionType,
109-
subjectAssetMaxAmount uint64) (oraclerpc.RateTick, error) {
105+
// getAssetRates returns the asset rates for a given transaction type and
106+
// subject asset max amount.
107+
func getAssetRates(transactionType oraclerpc.TransactionType,
108+
subjectAssetMaxAmount uint64) (oraclerpc.AssetRates, error) {
110109

111110
// Determine the rate based on the transaction type.
112111
var subjectAssetRate rfqmath.BigIntFixedPoint
@@ -142,61 +141,61 @@ func getRateTick(transactionType oraclerpc.TransactionType,
142141
subjectAssetRate,
143142
)
144143
if err != nil {
145-
return oraclerpc.RateTick{}, err
144+
return oraclerpc.AssetRates{}, err
146145
}
147146

148147
// Marshal payment asset rate to RPC format.
149148
rpcPaymentAssetToBtcRate, err := oraclerpc.MarshalBigIntFixedPoint(
150149
rfqmsg.MilliSatPerBtc,
151150
)
152151
if err != nil {
153-
return oraclerpc.RateTick{}, err
152+
return oraclerpc.AssetRates{}, err
154153
}
155154

156-
return oraclerpc.RateTick{
155+
return oraclerpc.AssetRates{
157156
SubjectAssetRate: rpcSubjectAssetToBtcRate,
158157
PaymentAssetRate: rpcPaymentAssetToBtcRate,
159158
ExpiryTimestamp: uint64(expiry),
160159
}, nil
161160
}
162161

163-
// QueryRateTick queries the rate tick for a given transaction type, subject
164-
// asset, and payment asset. The rate tick is the exchange rate between the
165-
// subject asset and the payment asset.
162+
// QueryAssetRates queries the asset rates for a given transaction type, subject
163+
// asset, and payment asset. An asset rate is the number of asset units per
164+
// BTC.
166165
//
167166
// Example use case:
168167
//
169168
// Alice is trying to pay an invoice by spending an asset. Alice therefore
170169
// requests that Bob (her asset channel counterparty) purchase the asset from
171170
// her. Bob's payment, in BTC, will pay the invoice.
172171
//
173-
// Alice requests a bid quote from Bob. Her request includes a rate tick
174-
// hint (ask). Alice get the rate tick hint by calling this endpoint. She sets:
172+
// Alice requests a bid quote from Bob. Her request includes an asset rates hint
173+
// (ask). Alice obtains the asset rates hint by calling this endpoint. She sets:
175174
// - `SubjectAsset` to the asset she is trying to sell.
176175
// - `SubjectAssetMaxAmount` to the max channel asset outbound.
177176
// - `PaymentAsset` to BTC.
178177
// - `TransactionType` to SALE.
179-
// - `RateTickHint` to nil.
178+
// - `AssetRateHint` to nil.
180179
//
181-
// Bob calls this endpoint to get the bid quote rate tick that he will send as a
182-
// response to Alice's request. He sets:
180+
// Bob calls this endpoint to get the bid quote asset rates that he will send as
181+
// a response to Alice's request. He sets:
183182
// - `SubjectAsset` to the asset that Alice is trying to sell.
184183
// - `SubjectAssetMaxAmount` to the value given in Alice's quote request.
185184
// - `PaymentAsset` to BTC.
186185
// - `TransactionType` to PURCHASE.
187-
// - `RateTickHint` to the value given in Alice's quote request.
188-
func (p *RpcPriceOracleServer) QueryRateTick(_ context.Context,
189-
req *oraclerpc.QueryRateTickRequest) (
190-
*oraclerpc.QueryRateTickResponse, error) {
186+
// - `AssetRateHint` to the value given in Alice's quote request.
187+
func (p *RpcPriceOracleServer) QueryAssetRates(_ context.Context,
188+
req *oraclerpc.QueryAssetRatesRequest) (
189+
*oraclerpc.QueryAssetRatesResponse, error) {
191190

192191
// Ensure that the payment asset is BTC. We only support BTC as the
193192
// payment asset in this example.
194193
if !oraclerpc.IsAssetBtc(req.PaymentAsset) {
195194
logrus.Infof("Payment asset is not BTC: %v", req.PaymentAsset)
196195

197-
return &oraclerpc.QueryRateTickResponse{
198-
Result: &oraclerpc.QueryRateTickResponse_Error{
199-
Error: &oraclerpc.QueryRateTickErrResponse{
196+
return &oraclerpc.QueryAssetRatesResponse{
197+
Result: &oraclerpc.QueryAssetRatesResponse_Error{
198+
Error: &oraclerpc.QueryAssetRatesErrResponse{
200199
Message: "unsupported payment asset, " +
201200
"only BTC is supported",
202201
},
@@ -215,55 +214,55 @@ func (p *RpcPriceOracleServer) QueryRateTick(_ context.Context,
215214
logrus.Infof("Unsupported subject asset ID str: %v\n",
216215
req.SubjectAsset)
217216

218-
return &oraclerpc.QueryRateTickResponse{
219-
Result: &oraclerpc.QueryRateTickResponse_Error{
220-
Error: &oraclerpc.QueryRateTickErrResponse{
217+
return &oraclerpc.QueryAssetRatesResponse{
218+
Result: &oraclerpc.QueryAssetRatesResponse_Error{
219+
Error: &oraclerpc.QueryAssetRatesErrResponse{
221220
Message: "unsupported subject asset",
222221
},
223222
},
224223
}, nil
225224
}
226225

227-
// Determine which rate tick to return.
226+
// Determine which asset rate to return.
228227
var (
229-
rateTick oraclerpc.RateTick
230-
err error
228+
assetRates oraclerpc.AssetRates
229+
err error
231230
)
232231

233-
if req.RateTickHint != nil {
234-
// If a rate tick hint is provided, return it as the rate tick.
235-
// In doing so, we effectively accept the rate tick proposed by
236-
// our peer.
232+
if req.AssetRatesHint != nil {
233+
// If the asset rates hint is provided, return it as the asset
234+
// rate. In doing so, we effectively accept the asset rates
235+
// proposed by our peer.
237236
logrus.Info("Suggested asset to BTC rate provided, " +
238237
"returning rate as accepted rate")
239238

240-
rateTick = oraclerpc.RateTick{
241-
SubjectAssetRate: req.RateTickHint.SubjectAssetRate,
242-
PaymentAssetRate: req.RateTickHint.PaymentAssetRate,
243-
ExpiryTimestamp: req.RateTickHint.ExpiryTimestamp,
239+
assetRates = oraclerpc.AssetRates{
240+
SubjectAssetRate: req.AssetRatesHint.SubjectAssetRate,
241+
PaymentAssetRate: req.AssetRatesHint.PaymentAssetRate,
242+
ExpiryTimestamp: req.AssetRatesHint.ExpiryTimestamp,
244243
}
245244
} else {
246-
// If a rate tick hint is not provided, fetch a rate tick from
247-
// our internal system.
245+
// If an asset rates hint is not provided, fetch asset rates
246+
// from our internal system.
248247
logrus.Info("Suggested asset to BTC rate not provided, " +
249248
"querying internal system for rate")
250249

251-
rateTick, err = getRateTick(
250+
assetRates, err = getAssetRates(
252251
req.TransactionType, req.SubjectAssetMaxAmount,
253252
)
254253
if err != nil {
255254
return nil, err
256255
}
257256
}
258257

259-
logrus.Infof("QueryRateTick returning rate (subject_asset_rate=%v, "+
260-
"payment_asset_rate=%v)", rateTick.SubjectAssetRate,
261-
rateTick.PaymentAssetRate)
258+
logrus.Infof("QueryAssetRates returning rates (subject_asset_rate=%v, "+
259+
"payment_asset_rate=%v)", assetRates.SubjectAssetRate,
260+
assetRates.PaymentAssetRate)
262261

263-
return &oraclerpc.QueryRateTickResponse{
264-
Result: &oraclerpc.QueryRateTickResponse_Success{
265-
Success: &oraclerpc.QueryRateTickSuccessResponse{
266-
RateTick: &rateTick,
262+
return &oraclerpc.QueryAssetRatesResponse{
263+
Result: &oraclerpc.QueryAssetRatesResponse_Ok{
264+
Ok: &oraclerpc.QueryAssetRatesOkResponse{
265+
AssetRates: &assetRates,
267266
},
268267
},
269268
}, nil

rfq/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,9 +922,9 @@ var _ fn.Event = (*PeerAcceptedBuyQuoteEvent)(nil)
922922
type QuoteRespStatus uint8
923923

924924
const (
925-
// InvalidRateTickQuoteRespStatus indicates that the rate tick in the
926-
// quote response is invalid.
927-
InvalidRateTickQuoteRespStatus QuoteRespStatus = 0
925+
// InvalidAssetRatesQuoteRespStatus indicates that the asset rates in
926+
// the quote response is invalid.
927+
InvalidAssetRatesQuoteRespStatus QuoteRespStatus = 0
928928

929929
// InvalidExpiryQuoteRespStatus indicates that the expiry in the quote
930930
// response is invalid.

rfq/negotiator.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
)
1717

1818
const (
19-
// minRateTickExpiryLifetime is the minimum rate tick expiry lifetime in
20-
// seconds.
21-
minRateTickExpiryLifetime = 60
19+
// minAssetRatesExpiryLifetime is the minimum asset rates expiry
20+
// lifetime in seconds.
21+
minAssetRatesExpiryLifetime = 60
2222

2323
// DefaultAcceptPriceDeviationPpm is the default price deviation in
2424
// parts per million that is accepted by the RFQ negotiator.
@@ -517,7 +517,7 @@ func (n *Negotiator) HandleIncomingBuyAccept(msg rfqmsg.BuyAccept,
517517
// TODO(ffranr): Sanity check the buy accept quote expiry
518518
// timestamp given the expiry timestamp provided by the price
519519
// oracle.
520-
if !expiryWithinBounds(msg.Expiry, minRateTickExpiryLifetime) {
520+
if !expiryWithinBounds(msg.Expiry, minAssetRatesExpiryLifetime) {
521521
// The expiry time is not within the acceptable bounds.
522522
log.Debugf("Buy accept quote expiry time is not within "+
523523
"acceptable bounds (expiry=%d)", msg.Expiry)
@@ -616,7 +616,7 @@ func (n *Negotiator) HandleIncomingBuyAccept(msg rfqmsg.BuyAccept,
616616
// can inform the peer that the quote response has not
617617
// validated successfully.
618618
invalidQuoteRespEvent := NewInvalidQuoteRespEvent(
619-
&msg, InvalidRateTickQuoteRespStatus,
619+
&msg, InvalidAssetRatesQuoteRespStatus,
620620
)
621621
finalise(
622622
msg, fn.Some[InvalidQuoteRespEvent](
@@ -642,7 +642,7 @@ func (n *Negotiator) HandleIncomingSellAccept(msg rfqmsg.SellAccept,
642642
//
643643
// TODO(ffranr): Sanity check the quote expiry timestamp given
644644
// the expiry timestamp provided by the price oracle.
645-
if !expiryWithinBounds(msg.Expiry, minRateTickExpiryLifetime) {
645+
if !expiryWithinBounds(msg.Expiry, minAssetRatesExpiryLifetime) {
646646
// The expiry time is not within the acceptable bounds.
647647
log.Debugf("Sell accept quote expiry time is not within "+
648648
"acceptable bounds (expiry=%d)", msg.Expiry)
@@ -740,7 +740,7 @@ func (n *Negotiator) HandleIncomingSellAccept(msg rfqmsg.SellAccept,
740740
// can inform the peer that the quote response has not
741741
// validated successfully.
742742
invalidQuoteRespEvent := NewInvalidQuoteRespEvent(
743-
&msg, InvalidRateTickQuoteRespStatus,
743+
&msg, InvalidAssetRatesQuoteRespStatus,
744744
)
745745
finalise(
746746
msg, fn.Some[InvalidQuoteRespEvent](

0 commit comments

Comments
 (0)