From a7383837f1ee4bf154f2fae1aa61c3291ffe0faf Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 17 Sep 2025 14:31:27 +1000 Subject: [PATCH] Add in example for validator delisting vote. Update the utils file to allow filenames to be specified for ease of testing --- .gitignore | 2 +- examples/example_utils.py | 8 ++-- examples/multi_sig_validator_delist_vote.py | 52 +++++++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 examples/multi_sig_validator_delist_vote.py diff --git a/.gitignore b/.gitignore index 6f887c8f..f382b4d8 100644 --- a/.gitignore +++ b/.gitignore @@ -188,7 +188,7 @@ target/ # pyenv .python-version -# poetry +# poetry / python virtual environment .venv # pipenv diff --git a/examples/example_utils.py b/examples/example_utils.py index 390a5433..b6a035f7 100644 --- a/examples/example_utils.py +++ b/examples/example_utils.py @@ -9,8 +9,8 @@ from hyperliquid.info import Info -def setup(base_url=None, skip_ws=False, perp_dexs=None): - config_path = os.path.join(os.path.dirname(__file__), "config.json") +def setup(base_url=None, skip_ws=False, perp_dexs=None, file_name="config.json"): + config_path = os.path.join(os.path.dirname(__file__), file_name) with open(config_path) as f: config = json.load(f) account: LocalAccount = eth_account.Account.from_key(get_secret_key(config)) @@ -52,8 +52,8 @@ def get_secret_key(config): return secret_key -def setup_multi_sig_wallets(): - config_path = os.path.join(os.path.dirname(__file__), "config.json") +def setup_multi_sig_wallets(file_name="config.json"): + config_path = os.path.join(os.path.dirname(__file__), file_name) with open(config_path) as f: config = json.load(f) diff --git a/examples/multi_sig_validator_delist_vote.py b/examples/multi_sig_validator_delist_vote.py new file mode 100644 index 00000000..4c16366e --- /dev/null +++ b/examples/multi_sig_validator_delist_vote.py @@ -0,0 +1,52 @@ +import example_utils + +from hyperliquid.utils import constants +from hyperliquid.utils.signing import sign_multi_sig_l1_action_payload, get_timestamp_ms + +def main(): + address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True, perp_dexs=None, file_name="config.json") + multi_sig_wallets = example_utils.setup_multi_sig_wallets(file_name="config.json") + + # 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" + + timestamp = get_timestamp_ms() + + # Perp name to delist + prep_name = "" + + # Define the multi-sig inner action + action = { + "type": "validatorL1Vote", + "D": prep_name + } + + 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_l1_action_payload( + wallet, + action, + exchange.base_url == constants.MAINNET_API_URL, + None, + timestamp, + exchange.expires_after, + multi_sig_user, + address, + ) + signatures.append(signature) + + # Execute the multi-sig action with all collected signatures + # This will only succeed if enough valid signatures are provided + multi_sig_result = exchange.multi_sig(multi_sig_user, action, signatures, timestamp) + print(multi_sig_result) + + +if __name__ == "__main__": + main()