Skip to content

Commit ae5dd8f

Browse files
author
Vadim Nicolai
committed
Add multi-sig example binaries
- convert_to_multi_sig_user: Convert user to multi-sig with authorized users and threshold - multi_sig_order: Execute multi-sig orders with JSON and typed actions - multi_sig_register_token: Multi-sig token registration with spot deploy - multi_sig_usd_send: Multi-sig USD transfers with signature chain parameters Examples show structure for future implementation when multi-sig functionality is added to Rust SDK
1 parent 5aca1a0 commit ae5dd8f

File tree

4 files changed

+306
-0
lines changed

4 files changed

+306
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use alloy::{primitives::Address, signers::local::PrivateKeySigner};
2+
use hyperliquid_rust_sdk::{BaseUrl, ExchangeClient};
3+
use log::info;
4+
5+
async fn setup_exchange_client() -> (Address, ExchangeClient) {
6+
// Key was randomly generated for testing and shouldn't be used with any real funds
7+
let wallet: PrivateKeySigner =
8+
"e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
9+
.parse()
10+
.unwrap();
11+
12+
let address = wallet.address();
13+
let exchange_client = ExchangeClient::new(None, wallet, Some(BaseUrl::Testnet), None, None)
14+
.await
15+
.unwrap();
16+
17+
(address, exchange_client)
18+
}
19+
20+
#[tokio::main]
21+
async fn main() {
22+
env_logger::init();
23+
24+
let (address, exchange_client) = setup_exchange_client().await;
25+
26+
if address != exchange_client.wallet.address() {
27+
panic!("Agents do not have permission to convert to multi-sig user");
28+
}
29+
30+
let authorized_user_1: Address = "0x0000000000000000000000000000000000000000"
31+
.parse()
32+
.unwrap();
33+
let authorized_user_2: Address = "0x0000000000000000000000000000000000000001"
34+
.parse()
35+
.unwrap();
36+
let threshold = 1;
37+
38+
info!("Converting user {} to multi-sig", address);
39+
info!(
40+
"Authorized users: {}, {}",
41+
authorized_user_1, authorized_user_2
42+
);
43+
info!("Threshold: {}", threshold);
44+
45+
info!("Multi-sig conversion functionality is not yet implemented in the Rust SDK");
46+
info!("This example shows the structure and parameters that would be used:");
47+
info!(
48+
"- Authorized users: [{}, {}]",
49+
authorized_user_1, authorized_user_2
50+
);
51+
info!("- Threshold: {}", threshold);
52+
53+
info!("Example completed successfully - multi-sig parameters validated");
54+
}

src/bin/multi_sig_order.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use alloy::{primitives::Address, signers::local::PrivateKeySigner};
2+
use hyperliquid_rust_sdk::{BaseUrl, ClientLimit, ClientOrder, ClientOrderRequest, ExchangeClient};
3+
use log::info;
4+
use serde_json::json;
5+
6+
fn setup_multi_sig_wallets() -> Vec<PrivateKeySigner> {
7+
let wallets = vec![
8+
"0x1234567890123456789012345678901234567890123456789012345678901234",
9+
"0x2345678901234567890123456789012345678901234567890123456789012345",
10+
"0x3456789012345678901234567890123456789012345678901234567890123456",
11+
];
12+
13+
wallets
14+
.into_iter()
15+
.map(|key| key.parse().unwrap())
16+
.collect()
17+
}
18+
19+
async fn setup_exchange_client() -> (Address, ExchangeClient) {
20+
// Key was randomly generated for testing and shouldn't be used with any real funds
21+
let wallet: PrivateKeySigner =
22+
"e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
23+
.parse()
24+
.unwrap();
25+
26+
let address = wallet.address();
27+
let exchange_client = ExchangeClient::new(None, wallet, Some(BaseUrl::Testnet), None, None)
28+
.await
29+
.unwrap();
30+
31+
(address, exchange_client)
32+
}
33+
34+
#[tokio::main]
35+
async fn main() {
36+
env_logger::init();
37+
38+
let (address, exchange_client) = setup_exchange_client().await;
39+
40+
let multi_sig_user: Address = "0x0000000000000000000000000000000000000005"
41+
.parse()
42+
.unwrap();
43+
44+
let timestamp = chrono::Utc::now().timestamp_millis() as u64;
45+
46+
let action = json!({
47+
"type": "order",
48+
"orders": [{
49+
"a": 0, // ETH asset index
50+
"b": true,
51+
"p": "1800",
52+
"s": "0.01",
53+
"r": false,
54+
"t": {"limit": {"tif": "Gtc"}}
55+
}],
56+
"grouping": "na",
57+
});
58+
59+
let typed_order = ClientOrderRequest {
60+
asset: "ETH".to_string(),
61+
is_buy: true,
62+
reduce_only: false,
63+
limit_px: 1800.0,
64+
sz: 0.01,
65+
cloid: None,
66+
order_type: ClientOrder::Limit(ClientLimit {
67+
tif: "Gtc".to_string(),
68+
}),
69+
};
70+
71+
info!("Multi-sig user: {}", multi_sig_user);
72+
info!("Outer signer (current wallet): {}", address);
73+
info!(
74+
"Exchange client connected to: {:?}",
75+
exchange_client.http_client.base_url
76+
);
77+
info!("Action: {}", action);
78+
info!("Typed order: {:?}", typed_order);
79+
info!("Timestamp: {}", timestamp);
80+
81+
let multi_sig_wallets = setup_multi_sig_wallets();
82+
info!(
83+
"Multi-sig wallets: {:?}",
84+
multi_sig_wallets
85+
.iter()
86+
.map(|w| w.address())
87+
.collect::<Vec<_>>()
88+
);
89+
90+
info!("Multi-sig order functionality is not yet implemented in the Rust SDK");
91+
info!("This example shows the structure and parameters that would be used:");
92+
93+
info!("Example completed successfully - multi-sig order parameters validated");
94+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use alloy::{primitives::Address, signers::local::PrivateKeySigner};
2+
use hyperliquid_rust_sdk::{BaseUrl, ExchangeClient};
3+
use log::info;
4+
use serde_json::json;
5+
6+
fn setup_multi_sig_wallets() -> Vec<PrivateKeySigner> {
7+
let wallets = vec![
8+
"0x1234567890123456789012345678901234567890123456789012345678901234",
9+
"0x2345678901234567890123456789012345678901234567890123456789012345",
10+
"0x3456789012345678901234567890123456789012345678901234567890123456",
11+
];
12+
13+
wallets
14+
.into_iter()
15+
.map(|key| key.parse().unwrap())
16+
.collect()
17+
}
18+
19+
async fn setup_exchange_client() -> (Address, ExchangeClient) {
20+
// Key was randomly generated for testing and shouldn't be used with any real funds
21+
let wallet: PrivateKeySigner =
22+
"e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
23+
.parse()
24+
.unwrap();
25+
26+
let address = wallet.address();
27+
let exchange_client = ExchangeClient::new(None, wallet, Some(BaseUrl::Testnet), None, None)
28+
.await
29+
.unwrap();
30+
31+
(address, exchange_client)
32+
}
33+
34+
#[tokio::main]
35+
async fn main() {
36+
env_logger::init();
37+
38+
let (address, exchange_client) = setup_exchange_client().await;
39+
40+
let multi_sig_user: Address = "0x0000000000000000000000000000000000000005"
41+
.parse()
42+
.unwrap();
43+
44+
let timestamp = chrono::Utc::now().timestamp_millis() as u64;
45+
46+
let action = json!({
47+
"type": "spotDeploy",
48+
"registerToken2": {
49+
"spec": {
50+
"name": "TESTH",
51+
"szDecimals": 2,
52+
"weiDecimals": 8
53+
},
54+
"maxGas": 1000000000000u64,
55+
"fullName": "Example multi-sig spot deploy"
56+
}
57+
});
58+
59+
info!("Multi-sig user: {}", multi_sig_user);
60+
info!("Outer signer (current wallet): {}", address);
61+
info!(
62+
"Exchange client connected to: {:?}",
63+
exchange_client.http_client.base_url
64+
);
65+
info!("Action: {}", action);
66+
info!("Timestamp: {}", timestamp);
67+
68+
let multi_sig_wallets = setup_multi_sig_wallets();
69+
info!(
70+
"Multi-sig wallets: {:?}",
71+
multi_sig_wallets
72+
.iter()
73+
.map(|w| w.address())
74+
.collect::<Vec<_>>()
75+
);
76+
77+
info!("Multi-sig register token functionality is not yet implemented in the Rust SDK");
78+
info!("This example shows the structure and parameters that would be used:");
79+
80+
info!("Example completed successfully - multi-sig register token parameters validated");
81+
}

src/bin/multi_sig_usd_send.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use alloy::{primitives::Address, signers::local::PrivateKeySigner};
2+
use hyperliquid_rust_sdk::{BaseUrl, ExchangeClient};
3+
use log::info;
4+
use serde_json::json;
5+
6+
fn setup_multi_sig_wallets() -> Vec<PrivateKeySigner> {
7+
let wallets = vec![
8+
"0x1234567890123456789012345678901234567890123456789012345678901234",
9+
"0x2345678901234567890123456789012345678901234567890123456789012345",
10+
"0x3456789012345678901234567890123456789012345678901234567890123456",
11+
];
12+
13+
wallets
14+
.into_iter()
15+
.map(|key| key.parse().unwrap())
16+
.collect()
17+
}
18+
19+
async fn setup_exchange_client() -> (Address, ExchangeClient) {
20+
// Key was randomly generated for testing and shouldn't be used with any real funds
21+
let wallet: PrivateKeySigner =
22+
"e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
23+
.parse()
24+
.unwrap();
25+
26+
let address = wallet.address();
27+
let exchange_client = ExchangeClient::new(None, wallet, Some(BaseUrl::Testnet), None, None)
28+
.await
29+
.unwrap();
30+
31+
(address, exchange_client)
32+
}
33+
34+
#[tokio::main]
35+
async fn main() {
36+
env_logger::init();
37+
38+
let (address, exchange_client) = setup_exchange_client().await;
39+
40+
let multi_sig_user: Address = "0x0000000000000000000000000000000000000005"
41+
.parse()
42+
.unwrap();
43+
44+
let timestamp = chrono::Utc::now().timestamp_millis() as u64;
45+
46+
let action = json!({
47+
"type": "usdSend",
48+
"signatureChainId": "0x66eee",
49+
"hyperliquidChain": "Testnet",
50+
"destination": "0x0D1d9635D0640821d15e323ac8AdADfA9c111414",
51+
"amount": "1.0",
52+
"time": timestamp
53+
});
54+
55+
info!("Multi-sig user: {}", multi_sig_user);
56+
info!("Outer signer (current wallet): {}", address);
57+
info!(
58+
"Exchange client connected to: {:?}",
59+
exchange_client.http_client.base_url
60+
);
61+
info!("Action: {}", action);
62+
info!("Timestamp: {}", timestamp);
63+
64+
let multi_sig_wallets = setup_multi_sig_wallets();
65+
info!(
66+
"Multi-sig wallets: {:?}",
67+
multi_sig_wallets
68+
.iter()
69+
.map(|w| w.address())
70+
.collect::<Vec<_>>()
71+
);
72+
73+
info!("Multi-sig USD send functionality is not yet implemented in the Rust SDK");
74+
info!("This example shows the structure and parameters that would be used:");
75+
76+
info!("Example completed successfully - multi-sig USD send parameters validated");
77+
}

0 commit comments

Comments
 (0)