Skip to content

Commit 82493f4

Browse files
committed
Merge #48: Fixed financial aspect of managing Options
24f4564 Fixed financial aspect of the managing Options (Kyryl R) Pull request description: After this change user (taker) will be offered USD alongside Grantor token Top commit has no ACKs. Tree-SHA512: 6d7385490206f2478a8f20772fca987af90d794f02d5364aa84392578d5c760b1e7cb223b5f3f70618bb905b7dd26124040e9823dab6aeb5d75ff331f7537376
2 parents bbdd34d + 24f4564 commit 82493f4

File tree

20 files changed

+1095
-493
lines changed

20 files changed

+1095
-493
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ anyhow = { version = "1.0.100" }
1919

2020
tracing = { version = "0.1.41" }
2121

22-
contracts = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "1a692a6", package = "contracts" }
23-
cli-helper = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "1a692a6", package = "cli" }
24-
simplicityhl-core = { version = "0.3.4", features = ["encoding"] }
22+
contracts = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "61616fb", package = "contracts" }
23+
cli-helper = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "61616fb", package = "cli" }
24+
simplicityhl-core = { version = "0.4.0", features = ["encoding"] }
2525

2626
simplicityhl = { version = "0.4.0" }
2727

crates/cli-client/src/cli/browse.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::cli::Cli;
2-
use crate::cli::interactive::{
3-
SwapDisplay, TokenDisplay, format_relative_time, format_settlement_asset, truncate_with_ellipsis,
4-
};
5-
use crate::cli::tables::{display_swap_table, display_token_table};
2+
use crate::cli::interactive::{TokenDisplay, format_relative_time, format_settlement_asset, truncate_with_ellipsis};
3+
use crate::cli::option_offer::ActiveOptionOfferDisplay;
4+
use crate::cli::tables::{display_active_option_offers_table, display_token_table};
65
use crate::config::Config;
76
use crate::error::Error;
87

9-
use options_relay::{OptionCreatedEvent, SwapCreatedEvent};
8+
use options_relay::{OptionCreatedEvent, OptionOfferCreatedEvent};
109
use simplicityhl::elements::AssetId;
1110
use simplicityhl::elements::hex::ToHex;
1211
use simplicityhl_core::LIQUID_TESTNET_BITCOIN_ASSET;
@@ -15,7 +14,7 @@ impl Cli {
1514
pub(crate) async fn run_browse(&self, config: Config) -> Result<(), Error> {
1615
let client = self.get_read_only_client(&config).await?;
1716

18-
println!("Browsing available options and swaps from NOSTR...");
17+
println!("Browsing available options and option offers from NOSTR...");
1918
println!();
2019

2120
let options_results = client.fetch_options(config.address_params()).await?;
@@ -47,32 +46,33 @@ impl Cli {
4746

4847
println!();
4948

50-
let swaps_results = client.fetch_swaps(config.address_params()).await?;
51-
let valid_swaps: Vec<SwapCreatedEvent> = swaps_results.into_iter().filter_map(Result::ok).collect();
49+
let offers_results = client.fetch_option_offers(config.address_params()).await?;
50+
let valid_offers: Vec<OptionOfferCreatedEvent> = offers_results.into_iter().filter_map(Result::ok).collect();
5251

53-
println!("Available Swaps (from NOSTR):");
54-
println!("-----------------------------");
52+
println!("Available Option Offers (from NOSTR):");
53+
println!("-------------------------------------");
5554

56-
if valid_swaps.is_empty() {
57-
println!(" (No swaps found)");
55+
if valid_offers.is_empty() {
56+
println!(" (No option offers found)");
5857
} else {
59-
let swap_displays: Vec<SwapDisplay> = valid_swaps
58+
let offer_displays: Vec<ActiveOptionOfferDisplay> = valid_offers
6059
.iter()
6160
.enumerate()
6261
.map(|(idx, event)| {
63-
let args = &event.swap_args;
64-
SwapDisplay {
62+
let args = &event.option_offer_args;
63+
ActiveOptionOfferDisplay {
6564
index: idx + 1,
6665
offering: format_asset_amount(args.collateral_per_contract(), args.get_collateral_asset_id()),
66+
price: args.collateral_per_contract().to_string(),
6767
wants: format_settlement_asset(&args.get_settlement_asset_id()),
6868
expires: format_relative_time(i64::from(args.expiry_time())),
6969
seller: truncate_with_ellipsis(&event.pubkey.to_hex(), 12),
7070
}
7171
})
7272
.collect();
7373

74-
display_swap_table(&swap_displays);
75-
println!(" (Note: Actual availability shown in `swap take` after syncing)");
74+
display_active_option_offers_table(&offer_displays);
75+
println!(" (Note: Actual availability shown in `option-offer take` after syncing)");
7676
}
7777

7878
client.disconnect().await;
@@ -81,7 +81,7 @@ impl Cli {
8181
println!("To interact with these offers:");
8282
println!(" 1. Run `sync nostr` to sync events to your local wallet");
8383
println!(" 2. Run `sync spent` to update UTXO status from blockchain");
84-
println!(" 3. Run `swap take` to take a swap offer");
84+
println!(" 3. Run `option-offer take` to take an option offer");
8585

8686
Ok(())
8787
}

crates/cli-client/src/cli/commands.rs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub enum Command {
2121
command: OptionCommand,
2222
},
2323

24-
/// Swap lifecycle (create, take, cancel, withdraw)
25-
Swap {
24+
/// Option Offer lifecycle (create, take, cancel, withdraw)
25+
OptionOffer {
2626
#[command(subcommand)]
27-
command: SwapCommand,
27+
command: OptionOfferCommand,
2828
},
2929

3030
/// Fetch options/swaps from NOSTR, sync to coin-store, display
@@ -242,23 +242,32 @@ pub enum OptionCommand {
242242
},
243243
}
244244

245-
/// Swap lifecycle commands
245+
/// Option Offer lifecycle commands
246246
#[derive(Debug, Subcommand)]
247-
pub enum SwapCommand {
248-
/// Create a swap offer (offer Grantor Token for premium)
247+
pub enum OptionOfferCommand {
248+
/// Create an option offer (deposit collateral + premium for settlement)
249249
Create {
250-
/// Grantor token outpoint (interactive selection if not provided)
250+
/// Collateral asset ID to deposit (interactive selection if not provided)
251251
#[arg(long)]
252-
grantor_token: Option<OutPoint>,
253-
/// Premium asset ID (defaults to native LBTC)
252+
collateral_asset: Option<AssetId>,
253+
/// Amount of collateral to deposit (prompted if not provided)
254+
#[arg(long)]
255+
collateral_amount: Option<u64>,
256+
/// Premium asset ID (interactive selection if not provided, excludes contract tokens)
254257
#[arg(long)]
255258
premium_asset: Option<AssetId>,
256-
/// Premium amount
259+
/// Total premium amount to deposit (used to calculate `premium_per_collateral`)
260+
#[arg(long)]
261+
premium_amount: Option<u64>,
262+
/// Settlement asset ID (interactive selection if not provided, excludes contract tokens)
257263
#[arg(long)]
258-
premium_amount: u64,
259-
/// Expiry time (defaults to same as option)
264+
settlement_asset: Option<AssetId>,
265+
/// Total settlement amount expected (used to calculate `collateral_per_contract`)
260266
#[arg(long)]
261-
expiry: Option<String>,
267+
settlement_amount: Option<u64>,
268+
/// Expiry time as Unix timestamp or duration (e.g., +30d)
269+
#[arg(long)]
270+
expiry: String,
262271
/// Fee amount in satoshis (auto-estimated if not specified)
263272
#[arg(long)]
264273
fee: Option<u64>,
@@ -267,11 +276,11 @@ pub enum SwapCommand {
267276
broadcast: bool,
268277
},
269278

270-
/// Take a swap offer (atomic swap: premium for Grantor Token)
279+
/// Take an option offer (pay settlement to receive collateral + premium)
271280
Take {
272-
/// Swap event ID from NOSTR (interactive selection if not provided)
281+
/// Offer event ID from NOSTR (interactive selection if not provided)
273282
#[arg(long)]
274-
swap_event: Option<String>,
283+
offer_event: Option<String>,
275284
/// Fee amount in satoshis (auto-estimated if not specified)
276285
#[arg(long)]
277286
fee: Option<u64>,
@@ -280,11 +289,11 @@ pub enum SwapCommand {
280289
broadcast: bool,
281290
},
282291

283-
/// Cancel a swap offer after expiry (reclaim collateral if no one took it)
292+
/// Cancel an option offer after expiry (reclaim collateral + premium)
284293
Cancel {
285-
/// Swap event ID from NOSTR (interactive selection if not provided)
294+
/// Offer event ID from NOSTR (interactive selection if not provided)
286295
#[arg(long)]
287-
swap_event: Option<String>,
296+
offer_event: Option<String>,
288297
/// Fee amount in satoshis (auto-estimated if not specified)
289298
#[arg(long)]
290299
fee: Option<u64>,
@@ -293,11 +302,11 @@ pub enum SwapCommand {
293302
broadcast: bool,
294303
},
295304

296-
/// Withdraw settlement after swap was taken (claim your payment)
305+
/// Withdraw settlement after offer was taken (claim your payment)
297306
Withdraw {
298-
/// Swap event ID from NOSTR (interactive selection if not provided)
307+
/// Offer event ID from NOSTR (interactive selection if not provided)
299308
#[arg(long)]
300-
swap_event: Option<String>,
309+
offer_event: Option<String>,
301310
/// Fee amount in satoshis (auto-estimated if not specified)
302311
#[arg(long)]
303312
fee: Option<u64>,

0 commit comments

Comments
 (0)