Skip to content

Commit 6e3bfc6

Browse files
committed
fmt
1 parent 325f12c commit 6e3bfc6

2 files changed

Lines changed: 28 additions & 101 deletions

File tree

src/hypercore/http.rs

Lines changed: 26 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,20 @@ use alloy::{
4949
signers::{Signer, SignerSync},
5050
};
5151
use anyhow::{Context, Result, anyhow};
52-
53-
use super::ApiError;
5452
use chrono::{DateTime, Utc};
5553
use rust_decimal::{Decimal, prelude::ToPrimitive};
5654
use serde::Deserialize;
5755
use url::Url;
5856

59-
use super::{AssetTarget, signing::*};
57+
use super::{ApiError, AssetTarget, signing::*};
6058
use crate::hypercore::{
6159
ActionError, ApiAgent, Builder, CandleInterval, Chain, Cloid, Dex, GossipPriorityAuctionStatus,
6260
Market, MultiSigConfig, OidOrCloid, OutcomeMeta, PerpMarket, Signature, SpotMarket, SpotToken,
6361
api::{
6462
Action, ActionRequest, ApproveAgent, ApproveBuilderFee, ConvertToMultiSigUser,
6563
GossipPriorityBid, Hip3LiquidatorTransferAction, OkResponse, Response, SignersConfig,
66-
TokenDelegateAction, TwapOrderParams, UsdClassTransferAction, UpdateIsolatedMargin,
67-
UpdateLeverage,
68-
VaultTransfer, Withdraw3Action,
64+
TokenDelegateAction, TwapOrderParams, UpdateIsolatedMargin, UpdateLeverage,
65+
UsdClassTransferAction, VaultTransfer, Withdraw3Action,
6966
},
7067
mainnet_url, testnet_url,
7168
types::{
@@ -406,8 +403,7 @@ impl Client {
406403
return Err(ApiError(format!("[{label}] HTTP {status} body={text}")).into());
407404
}
408405

409-
serde_json::from_str(&text)
410-
.with_context(|| format!("[{label}] body={text}"))
406+
serde_json::from_str(&text).with_context(|| format!("[{label}] body={text}"))
411407
}
412408

413409
/// Returns all open orders for a user.
@@ -1651,9 +1647,7 @@ impl Client {
16511647
let future =
16521648
self.sign_and_send_sync(signer, send.into_action(self.chain), nonce, None, None);
16531649

1654-
async move {
1655-
future.await?.into_default()
1656-
}
1650+
async move { future.await?.into_default() }
16571651
}
16581652

16591653
/// Agent-signed send asset.
@@ -1672,9 +1666,7 @@ impl Client {
16721666
) -> impl Future<Output = Result<()>> + Send + 'static {
16731667
let future = self.sign_and_send_sync(signer, send.into_action(), nonce, None, None);
16741668

1675-
async move {
1676-
future.await?.into_default()
1677-
}
1669+
async move { future.await?.into_default() }
16781670
}
16791671

16801672
/// Send a spot token to another address (spot-to-spot transfer).
@@ -1698,9 +1690,7 @@ impl Client {
16981690
let future =
16991691
self.sign_and_send_sync(signer, send.into_action(self.chain), nonce, None, None);
17001692

1701-
async move {
1702-
future.await?.into_default()
1703-
}
1693+
async move { future.await?.into_default() }
17041694
}
17051695

17061696
/// Update leverage for a perpetual asset.
@@ -2092,8 +2082,7 @@ impl Client {
20922082
return Err(ApiError(format!("HTTP {status} body={text}")).into());
20932083
}
20942084

2095-
let parsed = serde_json::from_str(&text)
2096-
.with_context(|| format!("body={text}"))?;
2085+
let parsed = serde_json::from_str(&text).with_context(|| format!("body={text}"))?;
20972086

20982087
Ok(parsed)
20992088
}
@@ -2145,17 +2134,13 @@ impl Client {
21452134
return Err(ApiError(format!("HTTP {status} body={text}")).into());
21462135
}
21472136

2148-
let parsed = serde_json::from_str(&text)
2149-
.with_context(|| format!("body={text}"))?;
2137+
let parsed = serde_json::from_str(&text).with_context(|| format!("body={text}"))?;
21502138

21512139
Ok(parsed)
21522140
}
21532141

21542142
/// Returns combined perpetual metadata and asset contexts.
2155-
pub async fn meta_and_asset_ctxs(
2156-
&self,
2157-
dex: Option<String>,
2158-
) -> Result<serde_json::Value> {
2143+
pub async fn meta_and_asset_ctxs(&self, dex: Option<String>) -> Result<serde_json::Value> {
21592144
let req = InfoRequest::MetaAndAssetCtxs { dex };
21602145
self.send_info_request("meta_and_asset_ctxs", &req).await
21612146
}
@@ -2213,10 +2198,7 @@ impl Client {
22132198
}
22142199

22152200
/// Returns coins at open interest cap.
2216-
pub async fn perps_at_open_interest_cap(
2217-
&self,
2218-
dex: Option<String>,
2219-
) -> Result<Vec<String>> {
2201+
pub async fn perps_at_open_interest_cap(&self, dex: Option<String>) -> Result<Vec<String>> {
22202202
let req = InfoRequest::PerpsAtOpenInterestCap { dex };
22212203
self.send_info_request("perps_at_open_interest_cap", &req)
22222204
.await
@@ -2230,11 +2212,7 @@ impl Client {
22302212
}
22312213

22322214
/// Returns user leverage and trade-size limits for a specific asset.
2233-
pub async fn active_asset_data(
2234-
&self,
2235-
user: Address,
2236-
coin: String,
2237-
) -> Result<ActiveAssetData> {
2215+
pub async fn active_asset_data(&self, user: Address, coin: String) -> Result<ActiveAssetData> {
22382216
let req = InfoRequest::ActiveAssetData { user, coin };
22392217
self.send_info_request("active_asset_data", &req).await
22402218
}
@@ -2346,8 +2324,7 @@ impl Client {
23462324
/// Returns borrow/lend user state.
23472325
pub async fn borrow_lend_user_state(&self, user: Address) -> Result<serde_json::Value> {
23482326
let req = InfoRequest::BorrowLendUserState { user };
2349-
self.send_info_request("borrow_lend_user_state", &req)
2350-
.await
2327+
self.send_info_request("borrow_lend_user_state", &req).await
23512328
}
23522329

23532330
/// Returns borrow/lend reserve state for a specific token.
@@ -2410,13 +2387,7 @@ impl Client {
24102387
expires_after: Option<DateTime<Utc>>,
24112388
) -> Result<Response> {
24122389
let action = Action::TwapOrder { twap: params };
2413-
let req = action.sign_sync(
2414-
signer,
2415-
nonce,
2416-
vault_address,
2417-
expires_after,
2418-
self.chain,
2419-
)?;
2390+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
24202391
self.send(req).await
24212392
}
24222393

@@ -2430,14 +2401,11 @@ impl Client {
24302401
vault_address: Option<Address>,
24312402
expires_after: Option<DateTime<Utc>>,
24322403
) -> Result<Response> {
2433-
let action = Action::TwapCancel { a: asset, t: twap_id };
2434-
let req = action.sign_sync(
2435-
signer,
2436-
nonce,
2437-
vault_address,
2438-
expires_after,
2439-
self.chain,
2440-
)?;
2404+
let action = Action::TwapCancel {
2405+
a: asset,
2406+
t: twap_id,
2407+
};
2408+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
24412409
self.send(req).await
24422410
}
24432411

@@ -2458,13 +2426,7 @@ impl Client {
24582426
amount,
24592427
time: nonce,
24602428
});
2461-
let req = action.sign_sync(
2462-
signer,
2463-
nonce,
2464-
vault_address,
2465-
expires_after,
2466-
self.chain,
2467-
)?;
2429+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
24682430
self.send(req).await?.into_default()
24692431
}
24702432

@@ -2485,13 +2447,7 @@ impl Client {
24852447
to_perp,
24862448
nonce,
24872449
});
2488-
let req = action.sign_sync(
2489-
signer,
2490-
nonce,
2491-
vault_address,
2492-
expires_after,
2493-
self.chain,
2494-
)?;
2450+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
24952451
self.send(req).await?.into_default()
24962452
}
24972453

@@ -2505,13 +2461,7 @@ impl Client {
25052461
expires_after: Option<DateTime<Utc>>,
25062462
) -> Result<()> {
25072463
let action = Action::CDeposit { wei };
2508-
let req = action.sign_sync(
2509-
signer,
2510-
nonce,
2511-
vault_address,
2512-
expires_after,
2513-
self.chain,
2514-
)?;
2464+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
25152465
self.send(req).await?.into_default()
25162466
}
25172467

@@ -2525,13 +2475,7 @@ impl Client {
25252475
expires_after: Option<DateTime<Utc>>,
25262476
) -> Result<()> {
25272477
let action = Action::CWithdraw { wei };
2528-
let req = action.sign_sync(
2529-
signer,
2530-
nonce,
2531-
vault_address,
2532-
expires_after,
2533-
self.chain,
2534-
)?;
2478+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
25352479
self.send(req).await?.into_default()
25362480
}
25372481

@@ -2551,13 +2495,7 @@ impl Client {
25512495
is_undelegate,
25522496
wei,
25532497
});
2554-
let req = action.sign_sync(
2555-
signer,
2556-
nonce,
2557-
vault_address,
2558-
expires_after,
2559-
self.chain,
2560-
)?;
2498+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
25612499
self.send(req).await?.into_default()
25622500
}
25632501

@@ -2571,13 +2509,7 @@ impl Client {
25712509
expires_after: Option<DateTime<Utc>>,
25722510
) -> Result<()> {
25732511
let action = Action::ReserveRequestWeight { weight };
2574-
let req = action.sign_sync(
2575-
signer,
2576-
nonce,
2577-
vault_address,
2578-
expires_after,
2579-
self.chain,
2580-
)?;
2512+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
25812513
self.send(req).await?.into_default()
25822514
}
25832515

@@ -2597,13 +2529,7 @@ impl Client {
25972529
ntl,
25982530
is_deposit,
25992531
});
2600-
let req = action.sign_sync(
2601-
signer,
2602-
nonce,
2603-
vault_address,
2604-
expires_after,
2605-
self.chain,
2606-
)?;
2532+
let req = action.sign_sync(signer, nonce, vault_address, expires_after, self.chain)?;
26072533
self.send(req).await?.into_default()
26082534
}
26092535
}

src/hypercore/types/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5051,10 +5051,11 @@ mod tests {
50515051
}
50525052

50535053
mod info_request_serialization {
5054-
use super::*;
50555054
use alloy::primitives::address;
50565055
use either::Either;
50575056

5057+
use super::*;
5058+
50585059
const USER: Address = address!("0x0000000000000000000000000000000000001234");
50595060
const BUILDER: Address = address!("0x0000000000000000000000000000000000005678");
50605061

0 commit comments

Comments
 (0)