9
9
"github.com/btcsuite/btcd/btcutil"
10
10
"github.com/lightninglabs/loop"
11
11
"github.com/lightninglabs/loop/looprpc"
12
+ "github.com/lightninglabs/taproot-assets/rfqmath"
13
+ "github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
14
+ "github.com/lightningnetwork/lnd/lnwire"
12
15
"github.com/lightningnetwork/lnd/routing/route"
13
16
"github.com/urfave/cli"
14
17
)
@@ -268,7 +271,19 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
268
271
totalFee := resp .HtlcSweepFeeSat + resp .SwapFeeSat
269
272
270
273
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 )
271
282
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:" ,
272
287
resp .AssetRfqInfo .MaxSwapAssetAmt ,
273
288
resp .AssetRfqInfo .AssetName )
274
289
} else {
@@ -288,7 +303,17 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
288
303
fmt .Printf (satAmtFmt , "Estimated total fee:" , totalFee )
289
304
fmt .Println ()
290
305
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
+ }
291
313
fmt .Printf (assetAmtFmt , "No show penalty (prepay):" ,
314
+ assetAmtPrepay ,
315
+ resp .AssetRfqInfo .AssetName )
316
+ fmt .Printf (assetAmtFmt , "Limit no show penalty (prepay):" ,
292
317
resp .AssetRfqInfo .MaxPrepayAssetAmt ,
293
318
resp .AssetRfqInfo .AssetName )
294
319
} else {
@@ -302,3 +327,33 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
302
327
time .Unix (int64 (req .SwapPublicationDeadline ), 0 ),
303
328
)
304
329
}
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 (assetRate )
337
+ if err != nil {
338
+ return 0 , err
339
+ }
340
+
341
+ msatAmt := lnwire .MilliSatoshi ((amt * 1000 ))
342
+
343
+ assetAmt := rfqmath .MilliSatoshiToUnits (msatAmt , * askAssetRate )
344
+
345
+ return assetAmt .ToUint64 (), nil
346
+ }
347
+
348
+ // unmarshalFixedPoint converts an RPC FixedPoint to a BigIntFixedPoint.
349
+ func unmarshalFixedPoint (fp * looprpc.FixedPoint ) (* rfqmath.BigIntFixedPoint ,
350
+ error ) {
351
+
352
+ // convert the looprpc.FixedPoint to a rfqrpc.FixedPoint
353
+ rfqrpcFP := & rfqrpc.FixedPoint {
354
+ Coefficient : fp .Coefficient ,
355
+ Scale : fp .Scale ,
356
+ }
357
+
358
+ return rfqrpc .UnmarshalFixedPoint (rfqrpcFP )
359
+ }
0 commit comments