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
5 changes: 4 additions & 1 deletion examples/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
Fill in your secret key e.g. 0x0000000000000000000000000000000000000000000000000000000000000000
If you are using an Agent/API Wallet you MUST also specify the public address of your account, not the
address of the Agent/API Wallet.
Otherwise, feel free to leave it blank and it will be automatically derived from the secret key.
Otherwise, feel free to leave it blank and it will be automatically derived from the secret key. Alternatively,
you can specify a local `keystore_path` which will prompt you for the keystore password interactively.
Note: If both `secret_key` and `keystore_path` are provided, the `secret_key` will take precedence.

You can also populate the "multi_sig" section with the secret keys of the authorized user wallets that you
wish to sign multi-sig actions for.
",
"keystore_path": "",
"secret_key": "",
"account_address": "",
"multi_sig": {
Expand Down
22 changes: 21 additions & 1 deletion examples/example_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getpass
import json
import os

Expand All @@ -12,7 +13,7 @@ def setup(base_url=None, skip_ws=False, perp_dexs=None):
config_path = os.path.join(os.path.dirname(__file__), "config.json")
with open(config_path) as f:
config = json.load(f)
account: LocalAccount = eth_account.Account.from_key(config["secret_key"])
account: LocalAccount = eth_account.Account.from_key(get_secret_key(config))
address = config["account_address"]
if address == "":
address = account.address
Expand All @@ -32,6 +33,25 @@ def setup(base_url=None, skip_ws=False, perp_dexs=None):
return address, info, exchange


def get_secret_key(config):
if config["secret_key"]:
secret_key = config["secret_key"]
else:
keystore_path = config["keystore_path"]
keystore_path = os.path.expanduser(keystore_path)
if not os.path.isabs(keystore_path):
keystore_path = os.path.join(os.path.dirname(__file__), keystore_path)
if not os.path.exists(keystore_path):
raise FileNotFoundError(f"Keystore file not found: {keystore_path}")
if not os.path.isfile(keystore_path):
raise ValueError(f"Keystore path is not a file: {keystore_path}")
with open(keystore_path) as f:
keystore = json.load(f)
password = getpass.getpass("Enter keystore password: ")
secret_key = eth_account.Account.decrypt(keystore, password)
return secret_key


def setup_multi_sig_wallets():
config_path = os.path.join(os.path.dirname(__file__), "config.json")
with open(config_path) as f:
Expand Down