Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/exchange/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,34 @@ pub struct ScheduleCancel {
#[serde(rename_all = "camelCase")]
pub struct ClaimRewards;

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UserDexAbstraction {
#[serde(serialize_with = "serialize_hex")]
pub signature_chain_id: u64,
pub hyperliquid_chain: String,
pub user: Address,
pub enabled: bool,
pub nonce: u64,
}

impl Eip712 for UserDexAbstraction {
fn domain(&self) -> Eip712Domain {
eip_712_domain(self.signature_chain_id)
}

fn struct_hash(&self) -> B256 {
let items = (
keccak256("HyperliquidTransaction:UserDexAbstraction(string hyperliquidChain,address user,bool enabled,uint64 nonce)"),
keccak256(&self.hyperliquid_chain),
&self.user,
self.enabled,
&self.nonce,
);
keccak256(items.abi_encode())
}
}

impl Eip712 for ApproveBuilderFee {
fn domain(&self) -> Eip712Domain {
eip_712_domain(self.signature_chain_id)
Expand Down
34 changes: 33 additions & 1 deletion src/exchange/exchange_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
actions::{
ApproveAgent, ApproveBuilderFee, BulkCancel, BulkModify, BulkOrder, ClaimRewards,
EvmUserModify, ScheduleCancel, SendAsset, SetReferrer, UpdateIsolatedMargin,
UpdateLeverage, UsdSend,
UpdateLeverage, UsdSend, UserDexAbstraction,
},
cancel::{CancelRequest, CancelRequestCloid, ClientCancelRequestCloid},
modify::{ClientModifyRequest, ModifyRequest},
Expand Down Expand Up @@ -82,6 +82,7 @@ pub enum Actions {
EvmUserModify(EvmUserModify),
ScheduleCancel(ScheduleCancel),
ClaimRewards(ClaimRewards),
UserDexAbstraction(UserDexAbstraction),
}

impl Actions {
Expand Down Expand Up @@ -867,6 +868,37 @@ impl ExchangeClient {

self.post(action, signature, timestamp).await
}

pub async fn user_dex_abstraction(
&self,
user: Address,
enabled: bool,
wallet: Option<&PrivateKeySigner>,
) -> Result<ExchangeResponseStatus> {
let wallet = wallet.unwrap_or(&self.wallet);

let hyperliquid_chain = if self.http_client.is_mainnet() {
"Mainnet".to_string()
} else {
"Testnet".to_string()
};

let timestamp = next_nonce();

let user_dex_abstraction = UserDexAbstraction {
signature_chain_id: 421614,
hyperliquid_chain,
user,
enabled,
nonce: timestamp,
};

let signature = sign_typed_data(&user_dex_abstraction, wallet)?;
let action = serde_json::to_value(Actions::UserDexAbstraction(user_dex_abstraction))
.map_err(|e| Error::JsonParse(e.to_string()))?;

self.post(action, signature, timestamp).await
}
}

fn round_to_decimals(value: f64, decimals: u32) -> f64 {
Expand Down
Loading