Skip to content

Commit 9cefd9d

Browse files
Add in Evm User Modify method for exchange client (#114)
- currently the rust sdk lags the python sdk for quite a few endpoints w/ evm user modify being especially painful - simple PR adds in the user modify method for big blocks on HL EVM - this has been tested live and works for HL mainnet
1 parent 4e8af41 commit 9cefd9d

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

src/bin/using_big_blocks.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use ethers::signers::LocalWallet;
2+
use hyperliquid_rust_sdk::{BaseUrl, ExchangeClient};
3+
use log::info;
4+
5+
#[tokio::main]
6+
async fn main() {
7+
env_logger::init();
8+
// Key was randomly generated for testing and shouldn't be used with any real funds
9+
let wallet: LocalWallet = "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
10+
.parse()
11+
.unwrap();
12+
13+
let exchange_client = ExchangeClient::new(None, wallet.clone(), Some(BaseUrl::Testnet), None, None)
14+
.await
15+
.unwrap();
16+
17+
let res = exchange_client
18+
.enable_big_blocks(false, Some(&wallet))
19+
.await
20+
.unwrap();
21+
info!("enable big blocks : {res:?}");
22+
}

src/exchange/actions.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ pub struct SetReferrer {
296296
pub code: String,
297297
}
298298

299+
#[derive(Serialize, Deserialize, Debug, Clone)]
300+
#[serde(rename_all = "camelCase")]
301+
pub struct EvmUserModify {
302+
pub using_big_blocks: bool,
303+
}
304+
305+
299306
#[derive(Serialize, Deserialize, Debug, Clone)]
300307
#[serde(rename_all = "camelCase")]
301308
pub struct ApproveBuilderFee {

src/exchange/exchange_client.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::collections::HashMap;
3030

3131
use super::cancel::ClientCancelRequestCloid;
3232
use super::order::{MarketCloseParams, MarketOrderParams};
33-
use super::{BuilderInfo, ClientLimit, ClientOrder};
33+
use super::{BuilderInfo, ClientLimit, ClientOrder, EvmUserModify};
3434

3535
#[derive(Debug)]
3636
pub struct ExchangeClient {
@@ -68,6 +68,7 @@ pub enum Actions {
6868
SpotSend(SpotSend),
6969
SetReferrer(SetReferrer),
7070
ApproveBuilderFee(ApproveBuilderFee),
71+
EvmUserModify(EvmUserModify),
7172
}
7273

7374
impl Actions {
@@ -149,6 +150,26 @@ impl ExchangeClient {
149150
serde_json::from_str(output).map_err(|e| Error::JsonParse(e.to_string()))
150151
}
151152

153+
pub async fn enable_big_blocks(
154+
&self,
155+
using_big_blocks: bool,
156+
wallet: Option<&LocalWallet>,
157+
) -> Result<ExchangeResponseStatus> {
158+
let wallet = wallet.unwrap_or(&self.wallet);
159+
160+
let timestamp = next_nonce();
161+
162+
let action = Actions::EvmUserModify(EvmUserModify {
163+
using_big_blocks,
164+
});
165+
let connection_id = action.hash(timestamp, self.vault_address)?;
166+
let action = serde_json::to_value(&action).map_err(|e| Error::JsonParse(e.to_string()))?;
167+
let is_mainnet = self.http_client.is_mainnet();
168+
let signature = sign_l1_action(wallet, connection_id, is_mainnet)?;
169+
170+
self.post(action, signature, timestamp).await
171+
}
172+
152173
pub async fn usdc_transfer(
153174
&self,
154175
amount: &str,

0 commit comments

Comments
 (0)