From 5ca2180760cafae36464bb0c5f4037879576c207 Mon Sep 17 00:00:00 2001 From: idiom-bytes Date: Wed, 22 Oct 2025 13:47:10 -0700 Subject: [PATCH] setting up withdraw example --- examples/multi_sig_withdraw.py | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/multi_sig_withdraw.py diff --git a/examples/multi_sig_withdraw.py b/examples/multi_sig_withdraw.py new file mode 100644 index 00000000..f090c408 --- /dev/null +++ b/examples/multi_sig_withdraw.py @@ -0,0 +1,56 @@ +import example_utils + +from hyperliquid.utils import constants +from hyperliquid.utils.signing import WITHDRAW_SIGN_TYPES, get_timestamp_ms, sign_multi_sig_user_signed_action_payload + + +def main(): + address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) + multi_sig_wallets = example_utils.setup_multi_sig_wallets() + + # The outer signer is required to be an authorized user or an agent of the authorized user of the multi-sig user. + + # Address of the multi-sig user that the action will be executed for + # Executing the action requires at least the specified threshold of signatures + # required for that multi-sig user + multi_sig_user = "0x0000000000000000000000000000000000000005" + + # Address to withdraw funds to (can be different from the multi-sig user) + destination_address = "0x0000000000000000000000000000000000000000" + + timestamp = get_timestamp_ms() + + # Define the multi-sig inner action - in this case, withdrawing from bridge + action = { + "type": "withdraw3", + "signatureChainId": "0x66eee", + "hyperliquidChain": "Testnet", + "destination": destination_address, + "amount": "2.0", + "time": timestamp, + } + signatures = [] + + # Collect signatures from each wallet in multi_sig_wallets. Each wallet must belong to a user. + for wallet in multi_sig_wallets: + # Sign the action with each wallet + signature = sign_multi_sig_user_signed_action_payload( + wallet, + action, + exchange.base_url == constants.MAINNET_API_URL, + WITHDRAW_SIGN_TYPES, + "HyperliquidTransaction:Withdraw", + multi_sig_user, + address, + ) + signatures.append(signature) + + # Execute the multi-sig withdrawal with all collected signatures + # This will only succeed if enough valid signatures are provided + # Note: The amount received will be reduced by the withdrawal fee + multi_sig_result = exchange.multi_sig(multi_sig_user, action, signatures, timestamp) + print(multi_sig_result) + + +if __name__ == "__main__": + main()