kaleido-cli 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,855 @@
1
+ """Lightning channel commands — list, open, close, and LSP orders."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ from typing import Annotated
7
+
8
+ import typer
9
+ from kaleido_sdk import (
10
+ ChannelOrderResponse,
11
+ LspInfoResponse,
12
+ NetworkInfoResponse,
13
+ RateDecisionRequest,
14
+ RateDecisionResponse,
15
+ )
16
+ from kaleido_sdk.rln import (
17
+ CloseChannelRequest,
18
+ ListChannelsResponse,
19
+ OpenChannelRequest,
20
+ OpenChannelResponse,
21
+ SendBtcRequest,
22
+ SendPaymentRequest,
23
+ )
24
+
25
+ from kaleido_cli.context import get_client
26
+ from kaleido_cli.output import (
27
+ is_interactive,
28
+ is_json_mode,
29
+ output_collection,
30
+ output_model,
31
+ print_error,
32
+ print_info,
33
+ print_json,
34
+ print_success,
35
+ )
36
+ from kaleido_cli.utils.channel_orders import (
37
+ CHANNEL_ORDER_HTTP_TIMEOUT,
38
+ _attach_client_asset_quote,
39
+ _autofill_refund_address,
40
+ _can_pay_channel_order,
41
+ _channel_wallet_payment_summary,
42
+ _create_channel_order,
43
+ _ensure_lsp_peer_connected,
44
+ _estimate_channel_order_fees,
45
+ _get_channel_order,
46
+ _print_channel_order_fees,
47
+ _print_lsp_info,
48
+ _resolve_channel_fee_estimate_params,
49
+ _resolve_channel_order_params,
50
+ _timed_step,
51
+ )
52
+ from kaleido_cli.utils.errors import raise_cli_error
53
+ from kaleido_cli.utils.prompts import (
54
+ require_option_when_set,
55
+ resolve_accept_reject,
56
+ resolve_optional_text,
57
+ resolve_required_int,
58
+ resolve_required_text,
59
+ )
60
+
61
+
62
+ def _resolve_channel_order_payment_method(onchain: bool, offchain: bool) -> str:
63
+ if is_interactive() and not onchain and not offchain:
64
+ choice = typer.prompt(
65
+ "Pay with [O]nchain funds or [L]ightning/off-chain funds?",
66
+ default="L",
67
+ )
68
+ return "onchain" if choice.strip().upper().startswith("O") else "offchain"
69
+
70
+ if onchain == offchain:
71
+ print_error("Specify exactly one of --onchain or --offchain in non-interactive mode.")
72
+ raise typer.Exit(1)
73
+
74
+ return "onchain" if onchain else "offchain"
75
+
76
+
77
+ def _access_token_args(access_token: str | None) -> str:
78
+ if not access_token:
79
+ return ""
80
+ return f" --access-token {access_token}"
81
+
82
+
83
+ channel_app = typer.Typer(
84
+ no_args_is_help=True,
85
+ rich_markup_mode="rich",
86
+ help="Manage Lightning channels — list, open, close, and place LSP orders.",
87
+ )
88
+ order_app = typer.Typer(
89
+ no_args_is_help=True,
90
+ rich_markup_mode="rich",
91
+ help="LSP-backed channel order flow: create, inspect, pay, decide, and estimate fees.",
92
+ )
93
+ lsp_app = typer.Typer(
94
+ no_args_is_help=True,
95
+ rich_markup_mode="rich",
96
+ help="Inspect Kaleidoswap LSP metadata and network details.",
97
+ )
98
+
99
+ channel_app.add_typer(order_app, name="order")
100
+ channel_app.add_typer(lsp_app, name="lsp")
101
+
102
+
103
+ @channel_app.command("list")
104
+ def channel_list() -> None:
105
+ """List Lightning channels."""
106
+ asyncio.run(_channel_list())
107
+
108
+
109
+ async def _channel_list() -> None:
110
+ try:
111
+ client = get_client(require_node=True)
112
+ resp: ListChannelsResponse = await client.rln.list_channels()
113
+ if is_json_mode():
114
+ print_json(resp.model_dump())
115
+ return
116
+ output_collection(
117
+ "Channels",
118
+ [c for c in (resp.channels or [])],
119
+ item_title="Channel Details — {index}",
120
+ empty_msg="No channels.",
121
+ )
122
+ except Exception as e:
123
+ raise_cli_error(e)
124
+
125
+
126
+ @channel_app.command(
127
+ "open",
128
+ epilog=(
129
+ "[bold]Examples[/bold]\n\n"
130
+ " Plain BTC channel (100 000 sat):\n"
131
+ " [cyan]kaleido channel open 03abc...@peer.host:9735 --capacity 100000[/cyan]\n\n"
132
+ " Push 10 000 msat to the remote side on open:\n"
133
+ " [cyan]kaleido channel open 03abc...@peer.host:9735 --capacity 100000 --push-msat 10000[/cyan]\n\n"
134
+ " RGB colored channel (attach USDT):\n"
135
+ " [cyan]kaleido channel open 03abc...@peer.host:9735 --capacity 100000 \\'\n"
136
+ " --asset-id rgb:abc... --asset-amount 5000[/cyan]\n\n"
137
+ " Private channel:\n"
138
+ " [cyan]kaleido channel open 03abc...@peer.host:9735 --capacity 100000 --private[/cyan]\n\n"
139
+ "[dim]Peer format: pubkey@host:port[/dim]"
140
+ ),
141
+ )
142
+ def channel_open(
143
+ peer: Annotated[
144
+ str | None,
145
+ typer.Argument(help="Peer in [green]pubkey@host:port[/green] format."),
146
+ ] = None,
147
+ capacity: Annotated[
148
+ int | None,
149
+ typer.Option("--capacity", "-c", help="Channel capacity in satoshis."),
150
+ ] = None,
151
+ push_msat: Annotated[
152
+ int,
153
+ typer.Option("--push-msat", help="Millisatoshis to push to the remote side on open."),
154
+ ] = 0,
155
+ asset_id: Annotated[
156
+ str | None,
157
+ typer.Option("--asset-id", help="RGB asset ID to attach (creates a colored channel)."),
158
+ ] = None,
159
+ asset_amount: Annotated[
160
+ int | None,
161
+ typer.Option("--asset-amount", help="Amount of RGB asset to place in the channel."),
162
+ ] = None,
163
+ push_asset_amount: Annotated[
164
+ int | None,
165
+ typer.Option(
166
+ "--push-asset-amount",
167
+ help="RGB asset amount to push to the remote side when opening the channel.",
168
+ ),
169
+ ] = None,
170
+ public: Annotated[
171
+ bool,
172
+ typer.Option(
173
+ "--public/--private",
174
+ help="Announce the channel publicly (default) or keep it private.",
175
+ ),
176
+ ] = True,
177
+ with_anchors: Annotated[
178
+ bool,
179
+ typer.Option(
180
+ "--with-anchors/--without-anchors",
181
+ help="Enable or disable anchor outputs for the channel.",
182
+ ),
183
+ ] = False,
184
+ fee_base_msat: Annotated[
185
+ int | None,
186
+ typer.Option("--fee-base-msat", help="Optional base routing fee for the channel."),
187
+ ] = None,
188
+ fee_proportional_millionths: Annotated[
189
+ int | None,
190
+ typer.Option(
191
+ "--fee-proportional-millionths",
192
+ help="Optional proportional routing fee for the channel.",
193
+ ),
194
+ ] = None,
195
+ temporary_channel_id: Annotated[
196
+ str | None,
197
+ typer.Option("--temporary-channel-id", help="Optional temporary channel ID override."),
198
+ ] = None,
199
+ ) -> None:
200
+ """Open a Lightning channel to a peer."""
201
+ require_option_when_set(
202
+ asset_id,
203
+ "--asset-id",
204
+ **{
205
+ "--asset-amount": asset_amount,
206
+ "--push-asset-amount": push_asset_amount,
207
+ },
208
+ )
209
+
210
+ resolved_peer = resolve_required_text(peer, "Peer (pubkey@host:port)", "PEER argument")
211
+ resolved_capacity = resolve_required_int(capacity, "Channel capacity (satoshis)", "--capacity")
212
+
213
+ if is_interactive():
214
+ push_msat = typer.prompt("[OPTIONAL] Push msat to remote side", default=push_msat, type=int)
215
+ if asset_id is None and typer.confirm("Attach an RGB asset?", default=False):
216
+ asset_id = typer.prompt("Asset ID (rgb:...)")
217
+ asset_amount = typer.prompt("Asset amount", type=int)
218
+ public = typer.confirm("Announce channel publicly?", default=True)
219
+
220
+ # Parse pubkey@host:port
221
+ if "@" in resolved_peer:
222
+ pubkey, addr = resolved_peer.split("@", 1)
223
+ else:
224
+ pubkey = resolved_peer
225
+ if is_interactive():
226
+ addr = typer.prompt("Peer address (host:port)")
227
+ else:
228
+ print_error("Peer must be in pubkey@host:port format in non-interactive mode.")
229
+ raise typer.Exit(1)
230
+
231
+ asyncio.run(
232
+ _channel_open(
233
+ pubkey,
234
+ addr,
235
+ resolved_capacity,
236
+ push_msat,
237
+ asset_id,
238
+ asset_amount,
239
+ push_asset_amount,
240
+ public,
241
+ with_anchors,
242
+ fee_base_msat,
243
+ fee_proportional_millionths,
244
+ temporary_channel_id,
245
+ )
246
+ )
247
+
248
+
249
+ async def _channel_open(
250
+ pubkey: str,
251
+ addr: str,
252
+ capacity: int,
253
+ push_msat: int,
254
+ asset_id: str | None,
255
+ asset_amount: int | None,
256
+ push_asset_amount: int | None,
257
+ public: bool,
258
+ with_anchors: bool,
259
+ fee_base_msat: int | None,
260
+ fee_proportional_millionths: int | None,
261
+ temporary_channel_id: str | None,
262
+ ) -> None:
263
+ try:
264
+ client = get_client(require_node=True)
265
+ body = OpenChannelRequest(
266
+ peer_pubkey_and_opt_addr=f"{pubkey}@{addr}",
267
+ capacity_sat=capacity,
268
+ push_msat=push_msat,
269
+ asset_id=asset_id,
270
+ asset_amount=asset_amount,
271
+ push_asset_amount=push_asset_amount,
272
+ public=public,
273
+ with_anchors=with_anchors,
274
+ fee_base_msat=fee_base_msat,
275
+ fee_proportional_millionths=fee_proportional_millionths,
276
+ temporary_channel_id=temporary_channel_id,
277
+ )
278
+ resp: OpenChannelResponse = await client.rln.open_channel(body)
279
+ if is_json_mode():
280
+ print_json(resp.model_dump())
281
+ else:
282
+ print_success(
283
+ f"Channel opening initiated. Temporary channel ID: {resp.temporary_channel_id}"
284
+ )
285
+ except Exception as e:
286
+ raise_cli_error(e)
287
+
288
+
289
+ @channel_app.command(
290
+ "close",
291
+ epilog=(
292
+ "[bold]Examples[/bold]\n\n"
293
+ " Cooperative close:\n"
294
+ " [cyan]kaleido channel close <channel-id> --peer 03abc...[/cyan]\n\n"
295
+ " Force close (unilateral, use only if peer is unresponsive):\n"
296
+ " [cyan]kaleido channel close <channel-id> --peer 03abc... --force[/cyan]\n\n"
297
+ "[dim]Use 'kaleido channel list' to find channel IDs.[/dim]"
298
+ ),
299
+ )
300
+ def channel_close(
301
+ channel_id: Annotated[
302
+ str | None,
303
+ typer.Argument(help="Channel ID to close (from 'kaleido channel list')."),
304
+ ] = None,
305
+ peer_pubkey: Annotated[
306
+ str | None,
307
+ typer.Option("--peer", help="Pubkey of the channel peer."),
308
+ ] = None,
309
+ force: Annotated[
310
+ bool,
311
+ typer.Option("--force", help="Force (unilateral) close. Use only if peer is offline."),
312
+ ] = False,
313
+ ) -> None:
314
+ """Close a Lightning channel."""
315
+ resolved_channel_id = resolve_required_text(
316
+ channel_id,
317
+ "Channel ID (from 'kaleido channel list')",
318
+ "CHANNEL_ID argument",
319
+ )
320
+ resolved_peer_pubkey = resolve_required_text(peer_pubkey, "Peer pubkey", "--peer")
321
+
322
+ asyncio.run(_channel_close(resolved_channel_id, resolved_peer_pubkey, force))
323
+
324
+
325
+ async def _channel_close(channel_id: str, peer_pubkey: str, force: bool) -> None:
326
+ try:
327
+ client = get_client(require_node=True)
328
+ await client.rln.close_channel(
329
+ CloseChannelRequest(
330
+ channel_id=channel_id,
331
+ peer_pubkey=peer_pubkey,
332
+ force=force,
333
+ )
334
+ )
335
+ print_success("Channel close initiated.")
336
+ except Exception as e:
337
+ raise_cli_error(e)
338
+
339
+
340
+ # ---------------------------------------------------------------------------
341
+ # LSP Order Commands
342
+ # ---------------------------------------------------------------------------
343
+
344
+
345
+ @order_app.command(
346
+ "create",
347
+ epilog=(
348
+ "[bold]Examples[/bold]\n\n"
349
+ " Create a basic channel order:\n"
350
+ " [cyan]kaleido channel order create --lsp-balance 1000000 --client-balance 500000[/cyan]\n\n"
351
+ " RGB colored channel order:\n"
352
+ " [cyan]kaleido channel order create --lsp-balance 1000000 --client-balance 500000 \\'\n"
353
+ " --asset-id rgb:xyz... --lsp-asset-amount 5000 --client-asset-amount 2000[/cyan]\n\n"
354
+ " With custom confirmations and refund address:\n"
355
+ " [cyan]kaleido channel order create --lsp-balance 1000000 --client-balance 500000 \\'\n"
356
+ " --confirmations 3 --refund-address bc1q...[/cyan]"
357
+ ),
358
+ )
359
+ def channel_order_create(
360
+ client_pubkey: Annotated[
361
+ str | None,
362
+ typer.Argument(help="Client Lightning node public key. Defaults to local node pubkey."),
363
+ ] = None,
364
+ lsp_balance_sat: Annotated[
365
+ int | None,
366
+ typer.Option("--lsp-balance", help="LSP's balance in the channel (satoshis)."),
367
+ ] = None,
368
+ client_balance_sat: Annotated[
369
+ int | None,
370
+ typer.Option("--client-balance", help="Client's balance in the channel (satoshis)."),
371
+ ] = None,
372
+ required_channel_confirmations: Annotated[
373
+ int,
374
+ typer.Option(
375
+ "--confirmations",
376
+ help="Required confirmations before channel is considered open.",
377
+ ),
378
+ ] = 6,
379
+ funding_confirms_within_blocks: Annotated[
380
+ int,
381
+ typer.Option(
382
+ "--funding-within",
383
+ help="Number of blocks within which funding must confirm.",
384
+ ),
385
+ ] = 144,
386
+ channel_expiry_blocks: Annotated[
387
+ int,
388
+ typer.Option("--expiry-blocks", help="Channel expiry in blocks (must be at least 1)."),
389
+ ] = 1,
390
+ refund_onchain_address: Annotated[
391
+ str | None,
392
+ typer.Option(
393
+ "--refund-address",
394
+ help="Bitcoin address for refunds. Defaults to a local node address.",
395
+ ),
396
+ ] = None,
397
+ announce_channel: Annotated[
398
+ bool,
399
+ typer.Option("--announce/--private", help="Announce channel publicly."),
400
+ ] = True,
401
+ asset_id: Annotated[
402
+ str | None,
403
+ typer.Option("--asset-id", help="RGB asset ID for colored channel."),
404
+ ] = None,
405
+ lsp_asset_amount: Annotated[
406
+ int | None,
407
+ typer.Option(
408
+ "--lsp-asset-amount", help="LSP's RGB asset amount. Required with --asset-id."
409
+ ),
410
+ ] = None,
411
+ client_asset_amount: Annotated[
412
+ int | None,
413
+ typer.Option("--client-asset-amount", help="Client's RGB asset amount."),
414
+ ] = None,
415
+ email: Annotated[str | None, typer.Option("--email", help="Contact email.")] = None,
416
+ yes: Annotated[
417
+ bool,
418
+ typer.Option("--yes", "-y", help="Accept an automatically fetched RFQ price."),
419
+ ] = False,
420
+ ) -> None:
421
+ """Create an LSP channel order."""
422
+ asyncio.run(
423
+ _channel_order_create_flow(
424
+ client_pubkey=client_pubkey,
425
+ lsp_balance_sat=lsp_balance_sat,
426
+ client_balance_sat=client_balance_sat,
427
+ required_channel_confirmations=required_channel_confirmations,
428
+ funding_confirms_within_blocks=funding_confirms_within_blocks,
429
+ channel_expiry_blocks=channel_expiry_blocks,
430
+ refund_onchain_address=refund_onchain_address,
431
+ announce_channel=announce_channel,
432
+ asset_id=asset_id,
433
+ lsp_asset_amount=lsp_asset_amount,
434
+ client_asset_amount=client_asset_amount,
435
+ email=email,
436
+ yes=yes,
437
+ )
438
+ )
439
+
440
+
441
+ async def _channel_order_create_flow(
442
+ *,
443
+ client_pubkey: str | None,
444
+ lsp_balance_sat: int | None,
445
+ client_balance_sat: int | None,
446
+ required_channel_confirmations: int,
447
+ funding_confirms_within_blocks: int,
448
+ channel_expiry_blocks: int,
449
+ refund_onchain_address: str | None,
450
+ announce_channel: bool,
451
+ asset_id: str | None,
452
+ lsp_asset_amount: int | None,
453
+ client_asset_amount: int | None,
454
+ email: str | None,
455
+ yes: bool,
456
+ ) -> None:
457
+ try:
458
+ client = get_client(
459
+ require_node=True,
460
+ timeout=CHANNEL_ORDER_HTTP_TIMEOUT,
461
+ max_retries=0,
462
+ )
463
+ node_info = await _timed_step("Fetching local node info", client.rln.get_node_info())
464
+ lsp_info = await _timed_step("Fetching LSP info", client.maker.get_lsp_info())
465
+ params = _resolve_channel_order_params(
466
+ client_pubkey=client_pubkey,
467
+ default_client_pubkey=node_info.pubkey,
468
+ lsp_info=lsp_info,
469
+ lsp_balance_sat=lsp_balance_sat,
470
+ client_balance_sat=client_balance_sat,
471
+ required_channel_confirmations=required_channel_confirmations,
472
+ funding_confirms_within_blocks=funding_confirms_within_blocks,
473
+ channel_expiry_blocks=channel_expiry_blocks,
474
+ refund_onchain_address=refund_onchain_address,
475
+ announce_channel=announce_channel,
476
+ asset_id=asset_id,
477
+ lsp_asset_amount=lsp_asset_amount,
478
+ client_asset_amount=client_asset_amount,
479
+ email=email,
480
+ )
481
+ await _autofill_refund_address(client, params)
482
+ await _attach_client_asset_quote(client, params, yes=yes)
483
+ await _ensure_lsp_peer_connected(client, lsp_info)
484
+ resp: ChannelOrderResponse = await _timed_step(
485
+ "Submitting LSP channel order",
486
+ _create_channel_order(client, params),
487
+ )
488
+ if is_json_mode():
489
+ print_json(resp.model_dump())
490
+ else:
491
+ print_success(f"LSP order created: {resp.order_id}")
492
+ output_model(resp, title="Channel Order")
493
+ access_token_args = _access_token_args(resp.access_token)
494
+ print_info(
495
+ "Inspect the order with: "
496
+ f"kaleido channel order get {resp.order_id}{access_token_args}"
497
+ )
498
+ if _can_pay_channel_order(resp):
499
+ print_info(
500
+ "Pay from local wallet funds with: "
501
+ f"kaleido channel order pay {resp.order_id}{access_token_args}"
502
+ )
503
+ except typer.Exit:
504
+ raise
505
+ except Exception as e:
506
+ raise_cli_error(e)
507
+
508
+
509
+ @order_app.command(
510
+ "get",
511
+ epilog=(
512
+ "[bold]Examples[/bold]\n\n"
513
+ " Get order status:\n"
514
+ " [cyan]kaleido channel order get <order-id> --access-token <token>[/cyan]"
515
+ ),
516
+ )
517
+ def channel_order_get(
518
+ order_id: Annotated[str | None, typer.Argument(help="LSP order ID.")] = None,
519
+ access_token: Annotated[
520
+ str | None,
521
+ typer.Option("--access-token", help="Optional access token returned for the order."),
522
+ ] = None,
523
+ ) -> None:
524
+ """Get the status and details of an LSP channel order."""
525
+ resolved_order_id = resolve_required_text(order_id, "LSP order ID", "ORDER_ID argument")
526
+ resolved_access_token = resolve_optional_text(access_token, "Access token")
527
+
528
+ asyncio.run(_channel_order_get(resolved_order_id, resolved_access_token))
529
+
530
+
531
+ async def _channel_order_get(order_id: str, access_token: str) -> None:
532
+ try:
533
+ client = get_client()
534
+ resp: ChannelOrderResponse = await _get_channel_order(client, order_id, access_token)
535
+ if is_json_mode():
536
+ print_json(resp.model_dump())
537
+ else:
538
+ output_model(resp, title=f"Order {order_id}")
539
+ except Exception as e:
540
+ raise_cli_error(e)
541
+
542
+
543
+ @order_app.command(
544
+ "pay",
545
+ epilog=(
546
+ "[bold]Examples[/bold]\n\n"
547
+ " Pay an order with onchain BTC from the local wallet:\n"
548
+ " [cyan]kaleido channel order pay <order-id> --access-token <token> --onchain[/cyan]\n\n"
549
+ " Pay an order with the Lightning invoice from the local wallet:\n"
550
+ " [cyan]kaleido channel order pay <order-id> --access-token <token> --offchain[/cyan]\n\n"
551
+ " Non-interactive payment:\n"
552
+ " [cyan]kaleido channel order pay <order-id> --access-token <token> --onchain --yes[/cyan]"
553
+ ),
554
+ )
555
+ def channel_order_pay(
556
+ order_id: Annotated[str | None, typer.Argument(help="LSP order ID.")] = None,
557
+ access_token: Annotated[
558
+ str | None,
559
+ typer.Option("--access-token", help="Optional access token returned for the order."),
560
+ ] = None,
561
+ onchain: Annotated[
562
+ bool,
563
+ typer.Option("--onchain", help="Pay the order using onchain BTC from the local wallet."),
564
+ ] = False,
565
+ offchain: Annotated[
566
+ bool,
567
+ typer.Option(
568
+ "--offchain", help="Pay the order using the Lightning invoice from the local wallet."
569
+ ),
570
+ ] = False,
571
+ fee_rate: Annotated[
572
+ int,
573
+ typer.Option("--fee-rate", help="Onchain fee rate in sat/vbyte when using --onchain."),
574
+ ] = 1,
575
+ yes: Annotated[
576
+ bool,
577
+ typer.Option("--yes", "-y", help="Pay the order invoice without confirmation."),
578
+ ] = False,
579
+ ) -> None:
580
+ """Pay an LSP channel order with local wallet funds."""
581
+ resolved_order_id = resolve_required_text(order_id, "LSP order ID", "ORDER_ID argument")
582
+ resolved_access_token = resolve_optional_text(access_token, "Access token")
583
+ payment_method = _resolve_channel_order_payment_method(onchain, offchain)
584
+ asyncio.run(
585
+ _channel_order_pay(
586
+ resolved_order_id,
587
+ resolved_access_token,
588
+ payment_method=payment_method,
589
+ fee_rate=fee_rate,
590
+ yes=yes,
591
+ )
592
+ )
593
+
594
+
595
+ async def _channel_order_pay(
596
+ order_id: str,
597
+ access_token: str,
598
+ *,
599
+ payment_method: str,
600
+ fee_rate: int,
601
+ yes: bool,
602
+ ) -> None:
603
+ try:
604
+ client = get_client(
605
+ require_node=True,
606
+ timeout=CHANNEL_ORDER_HTTP_TIMEOUT,
607
+ max_retries=0,
608
+ )
609
+ order = await _timed_step(
610
+ f"Fetching LSP order {order_id}",
611
+ _get_channel_order(client, order_id, access_token),
612
+ )
613
+ if is_json_mode():
614
+ if not yes:
615
+ print_error("--yes is required in JSON mode to pay the order.")
616
+ raise typer.Exit(1)
617
+ else:
618
+ output_model(_channel_wallet_payment_summary(order), title="Wallet Payment")
619
+ if not _can_pay_channel_order(order):
620
+ if is_json_mode():
621
+ print_json(order.model_dump())
622
+ else:
623
+ print_info(
624
+ "This order is not awaiting a wallet payment. Current payment state: "
625
+ f"{order.payment.bolt11.state}"
626
+ )
627
+ output_model(order, title=f"Order {order_id}")
628
+ return
629
+ if is_interactive() and not yes:
630
+ if payment_method == "onchain":
631
+ confirmed = typer.confirm(
632
+ (
633
+ "Pay this order with onchain BTC "
634
+ f"({order.payment.onchain.order_total_sat} sat to "
635
+ f"{order.payment.onchain.address})?"
636
+ ),
637
+ default=False,
638
+ )
639
+ else:
640
+ confirmed = typer.confirm(
641
+ (
642
+ "Pay this order from local wallet Lightning funds "
643
+ f"({order.payment.bolt11.order_total_sat} sat + "
644
+ f"{order.payment.bolt11.fee_total_sat} sat fee)?"
645
+ ),
646
+ default=False,
647
+ )
648
+ if not confirmed:
649
+ print_error("Channel order payment cancelled.")
650
+ raise typer.Exit(0)
651
+ elif not yes:
652
+ print_error("--yes is required in non-interactive mode to pay the order.")
653
+ raise typer.Exit(1)
654
+
655
+ if payment_method == "onchain":
656
+ payment_result = await _timed_step(
657
+ "Sending onchain BTC for order",
658
+ client.rln.send_btc(
659
+ SendBtcRequest(
660
+ amount=order.payment.onchain.order_total_sat,
661
+ address=order.payment.onchain.address,
662
+ fee_rate=fee_rate,
663
+ skip_sync=False,
664
+ )
665
+ ),
666
+ )
667
+ else:
668
+ payment_result = await _timed_step(
669
+ "Paying order invoice from local wallet funds",
670
+ client.rln.send_payment(SendPaymentRequest(invoice=order.payment.bolt11.invoice)),
671
+ )
672
+ refreshed_order = await _timed_step(
673
+ f"Refreshing LSP order {order_id}",
674
+ _get_channel_order(client, order_id, access_token),
675
+ )
676
+ if is_json_mode():
677
+ print_json(
678
+ {
679
+ "payment": payment_result.model_dump(),
680
+ "order": refreshed_order.model_dump(),
681
+ }
682
+ )
683
+ else:
684
+ print_success(
685
+ f"{'Onchain' if payment_method == 'onchain' else 'Offchain'} payment submitted for order {order_id}"
686
+ )
687
+ output_model(payment_result, title="Payment Result")
688
+ output_model(refreshed_order, title=f"Order {order_id}")
689
+ except typer.Exit:
690
+ raise
691
+ except Exception as e:
692
+ raise_cli_error(e)
693
+
694
+
695
+ @order_app.command(
696
+ "decide",
697
+ epilog=(
698
+ "[bold]Examples[/bold]\n\n"
699
+ " Accept an order:\n"
700
+ " [cyan]kaleido channel order decide <order-id> --access-token <token> --accept[/cyan]\n\n"
701
+ " Reject an order:\n"
702
+ " [cyan]kaleido channel order decide <order-id> --access-token <token> --reject[/cyan]"
703
+ ),
704
+ )
705
+ def channel_order_decide(
706
+ order_id: Annotated[str | None, typer.Argument(help="LSP order ID.")] = None,
707
+ accept: Annotated[bool, typer.Option("--accept", help="Accept the order.")] = False,
708
+ reject: Annotated[bool, typer.Option("--reject", help="Reject the order.")] = False,
709
+ access_token: Annotated[
710
+ str,
711
+ typer.Option("--access-token", help="Optional access token returned for the order."),
712
+ ] = "",
713
+ ) -> None:
714
+ """Submit a rate decision for an LSP channel order."""
715
+ resolved_order_id = resolve_required_text(order_id, "LSP order ID", "ORDER_ID argument")
716
+
717
+ accept = resolve_accept_reject(accept, reject, "Accept this order?")
718
+
719
+ resolved_access_token = resolve_optional_text(access_token, "Access token")
720
+
721
+ asyncio.run(_channel_order_decide(resolved_order_id, accept, resolved_access_token))
722
+
723
+
724
+ async def _channel_order_decide(order_id: str, accept: bool, access_token: str) -> None:
725
+ try:
726
+ client = get_client()
727
+ body = RateDecisionRequest(
728
+ order_id=order_id,
729
+ access_token=access_token,
730
+ accept_new_rate=accept,
731
+ )
732
+ resp: RateDecisionResponse = await client.maker.submit_lsp_rate_decision(body)
733
+ if is_json_mode():
734
+ print_json(resp.model_dump())
735
+ else:
736
+ action = "accepted" if accept else "rejected"
737
+ print_success(f"Order {order_id} {action}")
738
+ output_model(resp, title="Rate Decision Response")
739
+ except Exception as e:
740
+ raise_cli_error(e)
741
+
742
+
743
+ @order_app.command(
744
+ "estimate-fees",
745
+ epilog=(
746
+ "[bold]Examples[/bold]\n\n"
747
+ " Estimate fees for a channel:\n"
748
+ " [cyan]kaleido channel order estimate-fees --lsp-balance 1000000 --client-balance 500000[/cyan]\n\n"
749
+ " Estimate fees for an RGB-backed channel:\n"
750
+ " [cyan]kaleido channel order estimate-fees --lsp-balance 1000000 --client-balance 500000 \\\n"
751
+ " --asset-id rgb:xyz... --lsp-asset-amount 5000 --client-asset-amount 2000[/cyan]"
752
+ ),
753
+ )
754
+ def channel_estimate_fees(
755
+ lsp_balance_sat: Annotated[
756
+ int | None,
757
+ typer.Option("--lsp-balance", help="LSP's balance in the channel (satoshis)."),
758
+ ] = None,
759
+ client_balance_sat: Annotated[
760
+ int | None,
761
+ typer.Option("--client-balance", help="Client's balance in the channel (satoshis)."),
762
+ ] = None,
763
+ asset_id: Annotated[
764
+ str | None,
765
+ typer.Option("--asset-id", help="RGB asset ID for colored channel."),
766
+ ] = None,
767
+ lsp_asset_amount: Annotated[
768
+ int | None,
769
+ typer.Option(
770
+ "--lsp-asset-amount", help="LSP's RGB asset amount. Required with --asset-id."
771
+ ),
772
+ ] = None,
773
+ client_asset_amount: Annotated[
774
+ int | None,
775
+ typer.Option("--client-asset-amount", help="Client's RGB asset amount."),
776
+ ] = None,
777
+ channel_expiry_blocks: Annotated[
778
+ int,
779
+ typer.Option("--expiry-blocks", help="Channel expiry in blocks (must be at least 1)."),
780
+ ] = 1,
781
+ token: Annotated[str | None, typer.Option("--token", help="Authentication token.")] = None,
782
+ rfq_id: Annotated[
783
+ str | None,
784
+ typer.Option("--rfq-id", help="Request for quote ID."),
785
+ ] = None,
786
+ ) -> None:
787
+ """Estimate fees for opening an LSP channel."""
788
+ params = _resolve_channel_fee_estimate_params(
789
+ lsp_balance_sat=lsp_balance_sat,
790
+ client_balance_sat=client_balance_sat,
791
+ channel_expiry_blocks=channel_expiry_blocks,
792
+ token=token,
793
+ asset_id=asset_id,
794
+ lsp_asset_amount=lsp_asset_amount,
795
+ client_asset_amount=client_asset_amount,
796
+ rfq_id=rfq_id,
797
+ )
798
+
799
+ asyncio.run(_channel_estimate_fees_flow(params))
800
+
801
+
802
+ async def _channel_estimate_fees_flow(params) -> None:
803
+ try:
804
+ client = get_client()
805
+ resp = await _estimate_channel_order_fees(client, params)
806
+ if is_json_mode():
807
+ print_json(resp.model_dump())
808
+ else:
809
+ _print_channel_order_fees(resp, title="Estimated Fees")
810
+ except typer.Exit:
811
+ raise
812
+ except Exception as e:
813
+ raise_cli_error(e)
814
+
815
+
816
+ @lsp_app.command(
817
+ "info",
818
+ epilog=" [cyan]kaleido channel lsp info[/cyan] Show LSP capabilities and options.",
819
+ )
820
+ def channel_lsp_info() -> None:
821
+ """Show LSP information and available channel options."""
822
+ asyncio.run(_channel_lsp_info())
823
+
824
+
825
+ async def _channel_lsp_info() -> None:
826
+ try:
827
+ client = get_client()
828
+ resp: LspInfoResponse = await client.maker.get_lsp_info()
829
+ if is_json_mode():
830
+ print_json(resp.model_dump())
831
+ else:
832
+ _print_lsp_info(resp)
833
+ except Exception as e:
834
+ raise_cli_error(e)
835
+
836
+
837
+ @lsp_app.command(
838
+ "network-info",
839
+ epilog=" [cyan]kaleido channel lsp network-info[/cyan] Show LSP network/node information.",
840
+ )
841
+ def channel_lsp_network_info() -> None:
842
+ """Show LSP Lightning network information."""
843
+ asyncio.run(_channel_lsp_network_info())
844
+
845
+
846
+ async def _channel_lsp_network_info() -> None:
847
+ try:
848
+ client = get_client()
849
+ resp: NetworkInfoResponse = await client.maker.get_lsp_network_info()
850
+ if is_json_mode():
851
+ print_json(resp.model_dump())
852
+ else:
853
+ output_model(resp, title="LSP Network Info")
854
+ except Exception as e:
855
+ raise_cli_error(e)