Skip to content

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/exchange/actions.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,22 @@ impl Eip712 for SpotSend {
293293

294294
#[derive(Serialize, Deserialize, Debug, Clone)]
295295
#[serde(rename_all = "camelCase")]
296-
pub struct SpotUser {
297-
pub class_transfer: ClassTransfer,
296+
pub struct UsdClassTransfer {
297+
pub hyperliquid_chain: String,
298+
pub amount: String,
299+
pub to_perp: bool,
300+
pub nonce: u64,
298301
}
299302

300-
#[derive(Serialize, Deserialize, Debug, Clone)]
301-
#[serde(rename_all = "camelCase")]
302-
pub struct ClassTransfer {
303-
pub usdc: u64,
304-
pub to_perp: bool,
303+
impl UsdClassTransfer {
304+
pub fn new(hyperliquid_chain: HyperliquidChain, amount: String, to_perp: bool) -> Self {
305+
Self {
306+
hyperliquid_chain: hyperliquid_chain.action_chain_name(),
307+
amount,
308+
to_perp,
309+
nonce: next_nonce(),
310+
}
311+
}
305312
}
306313

307314
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]

src/exchange/exchange_client.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::{
1919
sign_l1_action, sign_multi_sig_action, sign_multi_sig_l1_action_payload, sign_typed_data,
2020
sign_typed_data_multi_sig,
2121
},
22-
BulkCancelCloid, ClassTransfer, Error, ExchangeResponseStatus, HyperliquidChain,
23-
MultiSigExtension, SpotSend, SpotUser, VaultTransfer, Withdraw3,
22+
BulkCancelCloid, Error, ExchangeResponseStatus, HyperliquidChain, MultiSigExtension, SpotSend,
23+
UsdClassTransfer, VaultTransfer, Withdraw3,
2424
};
2525
use alloy::{
2626
hex,
@@ -123,7 +123,7 @@ pub enum Actions {
123123
BatchModify(BulkModify),
124124
ApproveAgent(ApproveAgent),
125125
Withdraw3(Withdraw3),
126-
SpotUser(SpotUser),
126+
UsdClassTransfer(UsdClassTransfer),
127127
SendAsset(SendAsset),
128128
VaultTransfer(VaultTransfer),
129129
SpotSend(SpotSend),
@@ -237,7 +237,7 @@ impl ExchangeClient {
237237
| Actions::Withdraw3(_)
238238
| Actions::SpotSend(_)
239239
| Actions::SendAsset(_)
240-
| Actions::SpotUser(_)
240+
| Actions::UsdClassTransfer(_)
241241
)
242242
}
243243

@@ -322,19 +322,19 @@ impl ExchangeClient {
322322

323323
pub async fn class_transfer(
324324
&self,
325-
usdc: f64,
325+
amount: f64,
326326
to_perp: bool,
327327
wallet: Option<&PrivateKeySigner>,
328328
) -> Result<ExchangeResponseStatus> {
329-
// payload expects usdc without decimals
330-
let usdc = (usdc * 1e6).round() as u64;
331329
let wallet = wallet.unwrap_or(&self.wallet);
332330

333331
let timestamp = next_nonce();
334332

335-
let action = Actions::SpotUser(SpotUser {
336-
class_transfer: ClassTransfer { usdc, to_perp },
337-
});
333+
let action = Actions::UsdClassTransfer(UsdClassTransfer::new(
334+
self.http_client.chain,
335+
amount.to_string(),
336+
to_perp,
337+
));
338338
let connection_id = action.hash(timestamp, self.vault_address, self.expires_after)?;
339339
let is_mainnet = self.http_client.is_mainnet();
340340
let signature = sign_l1_action(wallet, connection_id, is_mainnet)?;

0 commit comments

Comments
 (0)