@@ -3,12 +3,15 @@ package main
33import (
44 "context"
55 "fmt"
6+ "math/big"
67 "os"
78 "time"
89
910 "github.com/btcsuite/btcd/btcutil"
1011 "github.com/lightninglabs/loop"
1112 "github.com/lightninglabs/loop/looprpc"
13+ "github.com/lightninglabs/taproot-assets/rfqmath"
14+ "github.com/lightningnetwork/lnd/lnwire"
1215 "github.com/lightningnetwork/lnd/routing/route"
1316 "github.com/urfave/cli"
1417)
@@ -268,7 +271,19 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
268271 totalFee := resp .HtlcSweepFeeSat + resp .SwapFeeSat
269272
270273 if resp .AssetRfqInfo != nil {
274+ assetAmtSwap , err := getAssetAmt (
275+ req .Amt , resp .AssetRfqInfo .SwapAssetRate ,
276+ )
277+ if err != nil {
278+ fmt .Printf ("Error converting asset amount: %v\n " , err )
279+ return
280+ }
281+ exchangeRate := float64 (assetAmtSwap ) / float64 (req .Amt )
271282 fmt .Printf (assetAmtFmt , "Send off-chain:" ,
283+ assetAmtSwap , resp .AssetRfqInfo .AssetName )
284+ fmt .Printf (rateFmt , "Exchange rate:" ,
285+ exchangeRate , resp .AssetRfqInfo .AssetName )
286+ fmt .Printf (assetAmtFmt , "Limit Send off-chain:" ,
272287 resp .AssetRfqInfo .MaxSwapAssetAmt ,
273288 resp .AssetRfqInfo .AssetName )
274289 } else {
@@ -288,7 +303,17 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
288303 fmt .Printf (satAmtFmt , "Estimated total fee:" , totalFee )
289304 fmt .Println ()
290305 if resp .AssetRfqInfo != nil {
306+ assetAmtPrepay , err := getAssetAmt (
307+ resp .PrepayAmtSat , resp .AssetRfqInfo .PrepayAssetRate ,
308+ )
309+ if err != nil {
310+ fmt .Printf ("Error converting asset amount: %v\n " , err )
311+ return
312+ }
291313 fmt .Printf (assetAmtFmt , "No show penalty (prepay):" ,
314+ assetAmtPrepay ,
315+ resp .AssetRfqInfo .AssetName )
316+ fmt .Printf (assetAmtFmt , "Limit no show penalty (prepay):" ,
292317 resp .AssetRfqInfo .MaxPrepayAssetAmt ,
293318 resp .AssetRfqInfo .AssetName )
294319 } else {
@@ -302,3 +327,43 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
302327 time .Unix (int64 (req .SwapPublicationDeadline ), 0 ),
303328 )
304329}
330+
331+ // getAssetAmt returns the asset amount for the given amount in satoshis and
332+ // the asset rate.
333+ func getAssetAmt (amt int64 , assetRate * looprpc.FixedPoint ) (
334+ uint64 , error ) {
335+
336+ askAssetRate , err := unmarshalFixedPoint (
337+ assetRate ,
338+ )
339+ if err != nil {
340+ return 0 , err
341+ }
342+ msatAmt := lnwire .MilliSatoshi (
343+ (amt * 1000 ),
344+ )
345+ assetAmt := rfqmath .MilliSatoshiToUnits (
346+ msatAmt , * askAssetRate ,
347+ )
348+
349+ return assetAmt .ToUint64 (), nil
350+ }
351+
352+ // unmarshalFixedPoint converts an RPC FixedPoint to a BigIntFixedPoint.
353+ func unmarshalFixedPoint (fp * looprpc.FixedPoint ) (* rfqmath.BigIntFixedPoint ,
354+ error ) {
355+ // Return an error is the scale component of the fixed point is greater
356+ // than the max value of uint8.
357+ if fp .Scale > 255 {
358+ return nil , fmt .Errorf ("scale value overflow: %v" , fp .Scale )
359+ }
360+ scale := uint8 (fp .Scale )
361+
362+ cBigInt := new (big.Int )
363+ cBigInt .SetString (fp .Coefficient , 10 )
364+
365+ return & rfqmath.BigIntFixedPoint {
366+ Coefficient : rfqmath .NewBigInt (cBigInt ),
367+ Scale : scale ,
368+ }, nil
369+ }
0 commit comments