diff --git a/tee-worker/omni-executor/Cargo.lock b/tee-worker/omni-executor/Cargo.lock index efd1303bd1..e3559ac695 100644 --- a/tee-worker/omni-executor/Cargo.lock +++ b/tee-worker/omni-executor/Cargo.lock @@ -5291,7 +5291,7 @@ dependencies = [ [[package]] name = "hyperliquid_rust_sdk" version = "0.6.0" -source = "git+https://github.com/BillyWooo/hyperliquid-rust-sdk?branch=usdClassTransfer_sendAsset#74973595c6ad81d2539356dc813592b450c7eb54" +source = "git+https://github.com/BillyWooo/hyperliquid-rust-sdk?branch=fork_new_feature#aa6887692561dce5bf2187d401d543c3c921add3" dependencies = [ "alloy", "chrono", diff --git a/tee-worker/omni-executor/Cargo.toml b/tee-worker/omni-executor/Cargo.toml index 0654fe486c..720e181339 100644 --- a/tee-worker/omni-executor/Cargo.toml +++ b/tee-worker/omni-executor/Cargo.toml @@ -57,7 +57,7 @@ hex = "0.4" hex-literal = "0.4" hmac = "0.12.1" http = "1.3.1" -hyperliquid_rust_sdk = { git = "https://github.com/BillyWooo/hyperliquid-rust-sdk", branch = "usdClassTransfer_sendAsset" } +hyperliquid_rust_sdk = { git = "https://github.com/BillyWooo/hyperliquid-rust-sdk", branch = "fork_new_feature" } jsonrpsee = { version = "0.24.9", features = ["server"] } jsonwebtoken = "9.3.0" libsecp256k1 = "0.7.1" diff --git a/tee-worker/omni-executor/rpc-server/src/methods/omni/get_hyperliquid_signature_data.rs b/tee-worker/omni-executor/rpc-server/src/methods/omni/get_hyperliquid_signature_data.rs index 76bde601ab..8fc6aac9b0 100644 --- a/tee-worker/omni-executor/rpc-server/src/methods/omni/get_hyperliquid_signature_data.rs +++ b/tee-worker/omni-executor/rpc-server/src/methods/omni/get_hyperliquid_signature_data.rs @@ -11,7 +11,9 @@ use executor_core::intent_executor::IntentExecutor; use executor_primitives::{ to_omni_auth, utils::hex::hex_encode, ChainId, ClientAuth, Identity, UserAuth, UserId, }; -use hyperliquid_rust_sdk::{ApproveAgent, ApproveBuilderFee, Eip712, SendAsset, Withdraw3}; +use hyperliquid_rust_sdk::{ + ApproveAgent, ApproveBuilderFee, Eip712, SendAsset, UserDexAbstraction, Withdraw3, +}; use jsonrpsee::{types::ErrorObject, RpcModule}; use pumpx::pubkey_to_address; use serde::{Deserialize, Serialize}; @@ -52,6 +54,10 @@ pub enum HyperliquidActionType { amount: String, from_sub_account: String, }, + UserDexAbstraction { + user: String, + enabled: bool, + }, } #[derive(Serialize, Clone)] @@ -74,6 +80,7 @@ pub enum HyperliquidAction { Withdraw3(Withdraw3), ApproveBuilderFee(ApproveBuilderFee), SendAsset(SendAsset), + UserDexAbstraction(UserDexAbstraction), } fn is_testnet_chain(chain_id: ChainId) -> bool { @@ -343,6 +350,19 @@ pub fn register_get_hyperliquid_signature_data< generate_eip712_signature(&ctx, &action, omni_account.as_ref()).await?; (HyperliquidAction::SendAsset(action), signature) }, + HyperliquidActionType::UserDexAbstraction { user, enabled } => { + let action = UserDexAbstraction { + signature_chain_id: params.chain_id, + hyperliquid_chain, + user: validate_ethereum_address(&user, "user") + .map_err(|e| e.to_error_object())?, + enabled, + nonce, + }; + let signature = + generate_eip712_signature(&ctx, &action, omni_account.as_ref()).await?; + (HyperliquidAction::UserDexAbstraction(action), signature) + }, }; Ok(GetHyperliquidSignatureDataResponse { @@ -644,6 +664,55 @@ mod tests { )); } + #[test] + fn test_user_dex_abstraction_action_signature() { + let action = UserDexAbstraction { + signature_chain_id: 1, + hyperliquid_chain: "Mainnet".to_string(), + user: Address::from_str("0x1234567890123456789012345678901234567890").unwrap(), + enabled: true, + nonce: 1234567890, + }; + + // Test domain generation + let domain = action.domain(); + assert_eq!(domain.name, Some("HyperliquidSignTransaction".into())); + assert_eq!(domain.version, Some("1".into())); + assert_eq!(domain.chain_id, Some(alloy::primitives::U256::from(1))); + + // Test struct hash generation + let struct_hash = action.struct_hash(); + assert_eq!(struct_hash.len(), 32); + + // Test EIP-712 signing hash generation + let signing_hash = action.eip712_signing_hash(); + assert_eq!(signing_hash.len(), 32); + } + + #[test] + fn test_params_deserialization_user_dex_abstraction() { + let json = r#"{ + "user_id": {"type": "email", "value": "test@example.com"}, + "user_auth": {"type": "email", "value": "123456"}, + "client_id": "test_client", + "action_type": { + "type": "user_dex_abstraction", + "user": "0x742d35Cc6634C0532925a3b844Bc9e7595f02A10", + "enabled": true + }, + "chain_id": 42161 + }"#; + + let params: GetHyperliquidSignatureDataParams = serde_json::from_str(json).unwrap(); + + assert!(matches!( + params.action_type, + HyperliquidActionType::UserDexAbstraction { user, enabled } + if user == "0x742d35Cc6634C0532925a3b844Bc9e7595f02A10" && enabled == true + )); + assert_eq!(params.chain_id, 42161); + } + #[test] fn test_is_testnet_chain() { // Test mainnet chain IDs