Skip to content

Commit 67902e1

Browse files
authored
Merge pull request #284 from hyperliquid-dex/add-multi-sig-convert-to-normal-user-example
Add convert multi-sig to normal user example
2 parents b4d2d1b + 185057e commit 67902e1

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import example_utils
2+
3+
from hyperliquid.utils import constants
4+
from hyperliquid.utils.signing import (
5+
CONVERT_TO_MULTI_SIG_USER_SIGN_TYPES,
6+
get_timestamp_ms,
7+
sign_multi_sig_user_signed_action_payload,
8+
)
9+
10+
11+
def main():
12+
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
13+
multi_sig_wallets = example_utils.setup_multi_sig_wallets()
14+
15+
# The outer signer is required to be an authorized user or an agent of the authorized user of the multi-sig user.
16+
17+
# Address of the multi-sig user that the action will be executed for
18+
# Executing the action requires at least the specified threshold of signatures
19+
# required for that multi-sig user
20+
multi_sig_user = "0x0000000000000000000000000000000000000005"
21+
22+
timestamp = get_timestamp_ms()
23+
24+
# Define the multi-sig inner action - in this case, converting multi-sig user to normal user
25+
action = {
26+
"type": "convertToMultiSigUser",
27+
"signatureChainId": "0x66eee",
28+
"hyperliquidChain": "Testnet",
29+
"signers": "null",
30+
"nonce": timestamp,
31+
}
32+
signatures = []
33+
34+
# Collect signatures from each wallet in multi_sig_wallets. Each wallet must belong to a user.
35+
for wallet in multi_sig_wallets:
36+
# Sign the action with each wallet
37+
signature = sign_multi_sig_user_signed_action_payload(
38+
wallet,
39+
action,
40+
exchange.base_url == constants.MAINNET_API_URL,
41+
CONVERT_TO_MULTI_SIG_USER_SIGN_TYPES,
42+
"HyperliquidTransaction:ConvertToMultiSigUser",
43+
multi_sig_user,
44+
address,
45+
)
46+
signatures.append(signature)
47+
48+
# Execute the multi-sig action with all collected signatures
49+
# This will only succeed if enough valid signatures are provided
50+
multi_sig_result = exchange.multi_sig(multi_sig_user, action, signatures, timestamp)
51+
print(multi_sig_result)
52+
53+
54+
if __name__ == "__main__":
55+
main()

0 commit comments

Comments
 (0)