Skip to content
Merged
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
12 changes: 2 additions & 10 deletions src/bin/multi_sig_signature_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn demonstrate_signature_collection() -> Result<()> {
info!("Signer 2 address: {}", signer2_wallet.address());

// Both signers create the same SendAsset action
let send_asset = create_send_asset(multi_sig_user, outer_signer, destination, amount, nonce);
let send_asset = create_send_asset(destination, amount, nonce);

// Signer 1 signs
let sig1 = sign_multi_sig_user_signed_action_single(&signer1_wallet, &send_asset)?;
Expand Down Expand Up @@ -115,13 +115,7 @@ fn demonstrate_signature_collection() -> Result<()> {
}

/// Create a SendAsset action - must be identical for all signers
fn create_send_asset(
multi_sig_user: alloy::primitives::Address,
outer_signer: alloy::primitives::Address,
destination: &str,
amount: &str,
nonce: u64,
) -> SendAsset {
fn create_send_asset(destination: &str, amount: &str, nonce: u64) -> SendAsset {
SendAsset {
signature_chain_id: 421614,
hyperliquid_chain: "Testnet".to_string(),
Expand All @@ -132,8 +126,6 @@ fn create_send_asset(
amount: amount.to_string(),
from_sub_account: "".to_string(),
nonce,
payload_multi_sig_user: Some(format!("{:#x}", multi_sig_user).to_lowercase()),
outer_signer: Some(format!("{:#x}", outer_signer).to_lowercase()),
}
}

Expand Down
33 changes: 2 additions & 31 deletions src/exchange/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ pub struct SendAsset {
pub amount: String,
pub from_sub_account: String,
pub nonce: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub payload_multi_sig_user: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub outer_signer: Option<String>,
}

impl Eip712 for SendAsset {
Expand All @@ -222,31 +218,7 @@ impl Eip712 for SendAsset {
}

fn struct_hash(&self) -> B256 {
if self.payload_multi_sig_user.is_some() && self.outer_signer.is_some() {
let multi_sig_user: Address = self
.payload_multi_sig_user
.as_ref()
.unwrap()
.parse()
.unwrap();
let outer_signer: Address = self.outer_signer.as_ref().unwrap().parse().unwrap();

let items = (
keccak256("HyperliquidTransaction:SendAsset(string hyperliquidChain,address payloadMultiSigUser,address outerSigner,string destination,string sourceDex,string destinationDex,string token,string amount,string fromSubAccount,uint64 nonce)"),
keccak256(&self.hyperliquid_chain),
multi_sig_user,
outer_signer,
keccak256(&self.destination),
keccak256(&self.source_dex),
keccak256(&self.destination_dex),
keccak256(&self.token),
keccak256(&self.amount),
keccak256(&self.from_sub_account),
&self.nonce,
);
keccak256(items.abi_encode())
} else {
let items = (
let items = (
keccak256("HyperliquidTransaction:SendAsset(string hyperliquidChain,string destination,string sourceDex,string destinationDex,string token,string amount,string fromSubAccount,uint64 nonce)"),
keccak256(&self.hyperliquid_chain),
keccak256(&self.destination),
Expand All @@ -257,8 +229,7 @@ impl Eip712 for SendAsset {
keccak256(&self.from_sub_account),
&self.nonce,
);
keccak256(items.abi_encode())
}
keccak256(items.abi_encode())
}
}

Expand Down
18 changes: 0 additions & 18 deletions src/exchange/exchange_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ impl ExchangeClient {
amount: amount.to_string(),
from_sub_account,
nonce: timestamp,
payload_multi_sig_user: None,
outer_signer: None,
};

let signature = sign_typed_data(&send_asset, wallet)?;
Expand Down Expand Up @@ -1206,8 +1204,6 @@ impl ExchangeClient {
amount: amount.to_string(),
from_sub_account: "".to_string(),
nonce: timestamp,
payload_multi_sig_user: Some(format!("{:#x}", multi_sig_user).to_lowercase()),
outer_signer: Some(format!("{:#x}", self.wallet.address()).to_lowercase()),
};

let signatures = sign_typed_data_multi_sig(&send_asset, wallets)?;
Expand Down Expand Up @@ -1249,8 +1245,6 @@ impl ExchangeClient {
amount: amount.to_string(),
from_sub_account: "".to_string(),
nonce: timestamp,
payload_multi_sig_user: Some(format!("{:#x}", multi_sig_user).to_lowercase()),
outer_signer: Some(format!("{:#x}", self.wallet.address()).to_lowercase()),
};

let signatures = sign_typed_data_multi_sig(&send_asset, wallets)?;
Expand Down Expand Up @@ -1299,8 +1293,6 @@ impl ExchangeClient {
/// amount: "100".to_string(),
/// from_sub_account: "".to_string(),
/// nonce: 123456789,
/// payload_multi_sig_user: Some(format!("{:#x}", multi_sig_user).to_lowercase()),
/// outer_signer: Some("0x...".to_lowercase()),
/// };
///
/// let sig1 = sign_multi_sig_user_signed_action_single(&wallet1, &send_asset)?;
Expand Down Expand Up @@ -1340,8 +1332,6 @@ impl ExchangeClient {
amount: amount.to_string(),
from_sub_account: "".to_string(),
nonce: timestamp,
payload_multi_sig_user: Some(format!("{:#x}", multi_sig_user).to_lowercase()),
outer_signer: Some(format!("{:#x}", self.wallet.address()).to_lowercase()),
};

let mut action =
Expand Down Expand Up @@ -1391,8 +1381,6 @@ impl ExchangeClient {
amount: amount.to_string(),
from_sub_account: "".to_string(),
nonce: timestamp,
payload_multi_sig_user: Some(format!("{:#x}", multi_sig_user).to_lowercase()),
outer_signer: Some(format!("{:#x}", self.wallet.address()).to_lowercase()),
};

let mut action =
Expand Down Expand Up @@ -1659,8 +1647,6 @@ mod tests {
amount: "100".to_string(),
from_sub_account: "".to_string(),
nonce: 1583838,
payload_multi_sig_user: None,
outer_signer: None,
};

let mainnet_signature = sign_typed_data(&mainnet_send, &wallet)?;
Expand All @@ -1675,8 +1661,6 @@ mod tests {
amount: "50".to_string(),
from_sub_account: "".to_string(),
nonce: 1583838,
payload_multi_sig_user: None,
outer_signer: None,
};

let testnet_signature = sign_typed_data(&testnet_send, &wallet)?;
Expand All @@ -1692,8 +1676,6 @@ mod tests {
amount: "100".to_string(),
from_sub_account: "0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd".to_string(),
nonce: 1583838,
payload_multi_sig_user: None,
outer_signer: None,
};

let vault_signature = sign_typed_data(&vault_send, &wallet)?;
Expand Down