Skip to content

Commit a0f5fcb

Browse files
authored
Merge pull request #1 from second-state/fix/cargo-fmt-lint
fix: resolve all cargo fmt lint issues
2 parents 1888ab6 + f2528c1 commit a0f5fcb

6 files changed

Lines changed: 124 additions & 107 deletions

File tree

src/coinbase.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ pub async fn create_deposit_address(
285285
account_id: &str,
286286
) -> Result<serde_json::Value> {
287287
let ts = timestamp();
288-
let path = format!(
289-
"/v2/accounts/{}/addresses",
290-
account_id
291-
);
288+
let path = format!("/v2/accounts/{}/addresses", account_id);
292289
let signature = sign_request(api_secret, &ts, "POST", &path, "{}");
293290
let url = format!("{}{}", BASE_URL, path);
294291

src/commands/deposit.rs

Lines changed: 76 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ pub async fn run(
4040
deposit_unit(asset, json_out).await
4141
}
4242
}
43-
other => bail!("Unsupported exchange '{}'. Use: hyperliquid, binance, coinbase", other),
43+
other => bail!(
44+
"Unsupported exchange '{}'. Use: hyperliquid, binance, coinbase",
45+
other
46+
),
4447
}
4548
}
4649

@@ -60,9 +63,14 @@ async fn deposit_unit(asset: &str, json_out: bool) -> Result<()> {
6063
let chain = unit::native_chain(&asset_lower).unwrap();
6164
let min = unit::minimum_amount(&asset_lower).unwrap_or("unknown");
6265

63-
let resp =
64-
unit::generate_address(chain, "hyperliquid", &asset_lower, &cfg.address, cfg.testnet)
65-
.await?;
66+
let resp = unit::generate_address(
67+
chain,
68+
"hyperliquid",
69+
&asset_lower,
70+
&cfg.address,
71+
cfg.testnet,
72+
)
73+
.await?;
6674

6775
let fees = unit::estimate_fees(cfg.testnet).await.ok();
6876

@@ -116,8 +124,10 @@ async fn deposit_unit(asset: &str, json_out: bool) -> Result<()> {
116124
);
117125
}
118126
if let Some(fee) = f.get(chain).and_then(|c| c.get(&key_fee)) {
119-
let fee_str =
120-
unit::format_amount(&fee.as_f64().unwrap_or(0.0).to_string(), &asset.to_lowercase());
127+
let fee_str = unit::format_amount(
128+
&fee.as_f64().unwrap_or(0.0).to_string(),
129+
&asset.to_lowercase(),
130+
);
121131
println!(" {} {}", "Est. fee: ".dimmed(), fee_str);
122132
}
123133
}
@@ -126,10 +136,7 @@ async fn deposit_unit(asset: &str, json_out: bool) -> Result<()> {
126136
" {} This address is permanent — send any amount, any time.",
127137
"ℹ".blue()
128138
);
129-
println!(
130-
" {} Track status: fintool bridge-status",
131-
"ℹ".blue()
132-
);
139+
println!(" {} Track status: fintool bridge-status", "ℹ".blue());
133140
println!();
134141
}
135142

@@ -172,10 +179,7 @@ async fn deposit_usdc_hl(
172179
.as_deref()
173180
.unwrap_or(&quote.input_amount);
174181
let fill_time = quote.expected_fill_time.unwrap_or(0);
175-
let needs_approval = quote
176-
.approval_txns
177-
.as_ref()
178-
.is_some_and(|a| !a.is_empty());
182+
let needs_approval = quote.approval_txns.as_ref().is_some_and(|a| !a.is_empty());
179183

180184
if dry_run {
181185
// Quote-only mode
@@ -225,24 +229,25 @@ async fn deposit_usdc_hl(
225229
println!(" {} ~{}s", "Fill time: ".dimmed(), fill_time);
226230
println!(" {} {}", "HL address: ".dimmed(), cfg.address.cyan());
227231
println!();
228-
println!(
229-
" {} Remove --dry-run to execute.",
230-
"ℹ".blue()
231-
);
232+
println!(" {} Remove --dry-run to execute.", "ℹ".blue());
232233
println!();
233234
}
234235
return Ok(());
235236
}
236237

237238
// Execute mode
238-
eprintln!("Executing USDC bridge: {} → Arbitrum → Hyperliquid...", source.name());
239+
eprintln!(
240+
"Executing USDC bridge: {} → Arbitrum → Hyperliquid...",
241+
source.name()
242+
);
239243

240244
let provider_url = source.rpc_url();
241245
let arb_provider_url = bridge::RPC_ARBITRUM;
242246

243247
// Build ethers provider + signer for source chain
244-
let source_provider = ethers::providers::Provider::<ethers::providers::Http>::try_from(provider_url)
245-
.context("Failed to connect to source chain RPC")?;
248+
let source_provider =
249+
ethers::providers::Provider::<ethers::providers::Http>::try_from(provider_url)
250+
.context("Failed to connect to source chain RPC")?;
246251
let source_wallet = cfg
247252
.private_key
248253
.parse::<ethers::signers::LocalWallet>()
@@ -258,8 +263,14 @@ async fn deposit_usdc_hl(
258263
for (i, atx) in approval_txns.iter().enumerate() {
259264
eprintln!(" Sending approval tx {}/{}...", i + 1, approval_txns.len());
260265
let tx = ethers::types::TransactionRequest::new()
261-
.to(atx.to.parse::<ethers::types::Address>().context("Invalid approval address")?)
262-
.data(hex::decode(atx.data.strip_prefix("0x").unwrap_or(&atx.data)).context("Invalid approval data")?)
266+
.to(atx
267+
.to
268+
.parse::<ethers::types::Address>()
269+
.context("Invalid approval address")?)
270+
.data(
271+
hex::decode(atx.data.strip_prefix("0x").unwrap_or(&atx.data))
272+
.context("Invalid approval data")?,
273+
)
263274
.chain_id(source.chain_id());
264275

265276
let pending = source_client
@@ -272,10 +283,7 @@ async fn deposit_usdc_hl(
272283
.context("Approval tx failed")?
273284
.ok_or_else(|| anyhow::anyhow!("Approval tx dropped"))?;
274285

275-
eprintln!(
276-
" ✅ Approval tx confirmed: {:?}",
277-
receipt.transaction_hash
278-
);
286+
eprintln!(" ✅ Approval tx confirmed: {:?}", receipt.transaction_hash);
279287
}
280288
}
281289

@@ -289,8 +297,21 @@ async fn deposit_usdc_hl(
289297
.unwrap_or_default();
290298

291299
let bridge_tx = ethers::types::TransactionRequest::new()
292-
.to(quote.swap_tx.to.parse::<ethers::types::Address>().context("Invalid bridge address")?)
293-
.data(hex::decode(quote.swap_tx.data.strip_prefix("0x").unwrap_or(&quote.swap_tx.data)).context("Invalid bridge data")?)
300+
.to(quote
301+
.swap_tx
302+
.to
303+
.parse::<ethers::types::Address>()
304+
.context("Invalid bridge address")?)
305+
.data(
306+
hex::decode(
307+
quote
308+
.swap_tx
309+
.data
310+
.strip_prefix("0x")
311+
.unwrap_or(&quote.swap_tx.data),
312+
)
313+
.context("Invalid bridge data")?,
314+
)
294315
.value(bridge_value)
295316
.chain_id(source.chain_id());
296317

@@ -308,17 +329,15 @@ async fn deposit_usdc_hl(
308329
eprintln!(" ✅ Bridge tx confirmed: {}", bridge_tx_hash);
309330

310331
// Step 4: Wait for Across relayer to fill on Arbitrum
311-
eprintln!(
312-
" Waiting for Across relayer (~{}s)...",
313-
fill_time.max(5)
314-
);
332+
eprintln!(" Waiting for Across relayer (~{}s)...", fill_time.max(5));
315333
tokio::time::sleep(tokio::time::Duration::from_secs(fill_time.max(10))).await;
316334

317335
// Step 5: Send USDC from Arbitrum address to HL Bridge2
318336
eprintln!(" Sending USDC to HL Bridge2 on Arbitrum...");
319337

320-
let arb_provider = ethers::providers::Provider::<ethers::providers::Http>::try_from(arb_provider_url)
321-
.context("Failed to connect to Arbitrum RPC")?;
338+
let arb_provider =
339+
ethers::providers::Provider::<ethers::providers::Http>::try_from(arb_provider_url)
340+
.context("Failed to connect to Arbitrum RPC")?;
322341
let arb_wallet = cfg
323342
.private_key
324343
.parse::<ethers::signers::LocalWallet>()
@@ -332,7 +351,9 @@ async fn deposit_usdc_hl(
332351
// ERC-20 transfer USDC to HL Bridge2
333352
let transfer_data = bridge::encode_erc20_transfer(bridge::HL_BRIDGE2_MAINNET, output_amount)?;
334353
let hl_deposit_tx = ethers::types::TransactionRequest::new()
335-
.to(bridge::USDC_ARBITRUM.parse::<ethers::types::Address>().context("Invalid USDC address")?)
354+
.to(bridge::USDC_ARBITRUM
355+
.parse::<ethers::types::Address>()
356+
.context("Invalid USDC address")?)
336357
.data(transfer_data)
337358
.chain_id(bridge::ARBITRUM_CHAIN_ID);
338359

@@ -395,25 +416,24 @@ async fn deposit_usdc_hl(
395416
// ── Binance deposit address ──────────────────────────────────────────
396417

397418
async fn deposit_binance(asset: &str, network: Option<&str>, json_out: bool) -> Result<()> {
398-
let (api_key, api_secret) = config::binance_credentials()
399-
.ok_or_else(|| anyhow::anyhow!("Binance API keys not configured in ~/.fintool/config.toml"))?;
419+
let (api_key, api_secret) = config::binance_credentials().ok_or_else(|| {
420+
anyhow::anyhow!("Binance API keys not configured in ~/.fintool/config.toml")
421+
})?;
400422

401423
let client = reqwest::Client::new();
402424

403425
// Map common chain names to Binance network codes
404-
let binance_network: Option<String> = network.map(|n| {
405-
match n.to_lowercase().as_str() {
406-
"ethereum" | "eth" | "mainnet" | "erc20" => "ETH".to_string(),
407-
"base" => "BASE".to_string(),
408-
"arbitrum" | "arb" => "ARBITRUM".to_string(),
409-
"solana" | "sol" => "SOL".to_string(),
410-
"bitcoin" | "btc" => "BTC".to_string(),
411-
"bsc" | "bnb" => "BSC".to_string(),
412-
"polygon" | "matic" => "MATIC".to_string(),
413-
"optimism" | "op" => "OPTIMISM".to_string(),
414-
"avalanche" | "avax" => "AVAXC".to_string(),
415-
_ => n.to_uppercase(),
416-
}
426+
let binance_network: Option<String> = network.map(|n| match n.to_lowercase().as_str() {
427+
"ethereum" | "eth" | "mainnet" | "erc20" => "ETH".to_string(),
428+
"base" => "BASE".to_string(),
429+
"arbitrum" | "arb" => "ARBITRUM".to_string(),
430+
"solana" | "sol" => "SOL".to_string(),
431+
"bitcoin" | "btc" => "BTC".to_string(),
432+
"bsc" | "bnb" => "BSC".to_string(),
433+
"polygon" | "matic" => "MATIC".to_string(),
434+
"optimism" | "op" => "OPTIMISM".to_string(),
435+
"avalanche" | "avax" => "AVAXC".to_string(),
436+
_ => n.to_uppercase(),
417437
});
418438

419439
let resp = binance::get_deposit_address(
@@ -448,11 +468,7 @@ async fn deposit_binance(asset: &str, network: Option<&str>, json_out: bool) ->
448468
println!("{}", serde_json::to_string_pretty(&out)?);
449469
} else {
450470
println!("{}", "━".repeat(50).dimmed());
451-
println!(
452-
" {} {} → Binance",
453-
"Deposit".green().bold(),
454-
coin.cyan()
455-
);
471+
println!(" {} {} → Binance", "Deposit".green().bold(), coin.cyan());
456472
println!("{}", "━".repeat(50).dimmed());
457473
println!();
458474
if let Some(net) = binance_network.as_deref() {
@@ -474,8 +490,9 @@ async fn deposit_binance(asset: &str, network: Option<&str>, json_out: bool) ->
474490
// ── Coinbase deposit address ─────────────────────────────────────────
475491

476492
async fn deposit_coinbase(asset: &str, json_out: bool) -> Result<()> {
477-
let (api_key, api_secret) = config::coinbase_credentials()
478-
.ok_or_else(|| anyhow::anyhow!("Coinbase API keys not configured in ~/.fintool/config.toml"))?;
493+
let (api_key, api_secret) = config::coinbase_credentials().ok_or_else(|| {
494+
anyhow::anyhow!("Coinbase API keys not configured in ~/.fintool/config.toml")
495+
})?;
479496

480497
let client = reqwest::Client::new();
481498

@@ -510,9 +527,7 @@ async fn deposit_coinbase(asset: &str, json_out: bool) -> Result<()> {
510527
.or_else(|| resp["address"].as_str())
511528
.unwrap_or("unknown");
512529

513-
let network = resp["data"]["network"]
514-
.as_str()
515-
.unwrap_or("");
530+
let network = resp["data"]["network"].as_str().unwrap_or("");
516531

517532
if json_out {
518533
let mut out = json!({

src/commands/perp.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,17 @@ pub async fn buy(
7171

7272
// Check if this is a HIP-3 asset (commodities, stocks)
7373
if let Some((dex, asset_name)) = resolve_hip3_asset(&symbol) {
74-
return hip3_perp_buy(&dex, &asset_name, &symbol, price_f, size, amount_usdc, &cfg, json_output).await;
74+
return hip3_perp_buy(
75+
&dex,
76+
&asset_name,
77+
&symbol,
78+
price_f,
79+
size,
80+
amount_usdc,
81+
&cfg,
82+
json_output,
83+
)
84+
.await;
7585
}
7686

7787
if !json_output {

0 commit comments

Comments
 (0)