Skip to content

Commit 3ad503f

Browse files
authored
Version 0.16.0 (#170)
1 parent d09e538 commit 3ad503f

File tree

9 files changed

+84
-25
lines changed

9 files changed

+84
-25
lines changed

examples/basic_send_asset.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import example_utils
2+
3+
from hyperliquid.utils import constants
4+
5+
SOURCE_DEX = ""
6+
DESTINATION_DEX = "test"
7+
8+
9+
def main():
10+
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
11+
12+
if exchange.account_address != exchange.wallet.address:
13+
raise Exception("Agents do not have permission to perform internal transfers")
14+
15+
# Transfer 1.23 USDC from SOURCE_DEX to the zero address on DESTINATION_DEX for demonstration purposes
16+
# Note that the collateral token for SOURCE_DEX and DESTINATION_DEX must match
17+
transfer_result = exchange.send_asset(
18+
"0x0000000000000000000000000000000000000000", SOURCE_DEX, DESTINATION_DEX, "USDC", 1.23
19+
)
20+
print(transfer_result)
21+
22+
23+
if __name__ == "__main__":
24+
main()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import example_utils
2+
3+
from hyperliquid.utils import constants
4+
5+
DUMMY_DEX = "test"
6+
COLLATERAL_TOKEN = "USDC" # nosec
7+
8+
9+
def main():
10+
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
11+
12+
# Transfer 1.23 USDC from spot wallet to perp wallet
13+
transfer_result = exchange.send_asset(address, "spot", DUMMY_DEX, COLLATERAL_TOKEN, 1.23)
14+
print(transfer_result)
15+
16+
# Transfer 1.23 collateral token from perp wallet back to spot wallet
17+
transfer_result = exchange.send_asset(address, DUMMY_DEX, "spot", COLLATERAL_TOKEN, 1.23)
18+
print(transfer_result)
19+
20+
21+
if __name__ == "__main__":
22+
main()

examples/multi_sig_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def main():
3636
exchange.base_url == constants.MAINNET_API_URL,
3737
None,
3838
timestamp,
39+
exchange.expires_after,
3940
multi_sig_user,
4041
address,
41-
exchange.expires_after,
4242
)
4343
signatures.append(signature)
4444

examples/multi_sig_register_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def main():
3939
exchange.base_url == constants.MAINNET_API_URL,
4040
None,
4141
timestamp,
42+
exchange.expires_after,
4243
multi_sig_user,
4344
address,
44-
exchange.expires_after,
4545
)
4646
signatures.append(signature)
4747

examples/perp_deploy.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
def main():
1616
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
1717

18+
# get perp deploy auction status which includes auction start and gas information
19+
perp_deploy_auction_status = info.query_perp_deploy_auction_status()
20+
print("perp deploy auction status:", perp_deploy_auction_status)
21+
1822
# Step 1: Registering a Perp Dex and Assets
1923
#
2024
# Takes part in the perp deploy auction and if successful, registers asset "TEST0".
@@ -50,10 +54,12 @@ def main():
5054
f"{DUMMY_DEX}:TEST0": "12.0",
5155
f"{DUMMY_DEX}:TEST1": "1.0",
5256
},
53-
{
54-
f"{DUMMY_DEX}:TEST1": "3.0",
55-
f"{DUMMY_DEX}:TEST0": "14.0",
56-
},
57+
[
58+
{
59+
f"{DUMMY_DEX}:TEST1": "3.0",
60+
f"{DUMMY_DEX}:TEST0": "14.0",
61+
}
62+
],
5763
)
5864
print("set oracle result:", set_oracle_result)
5965

hyperliquid/exchange.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
sign_convert_to_multi_sig_user_action,
2727
sign_l1_action,
2828
sign_multi_sig_action,
29-
sign_perp_dex_class_transfer_action,
29+
sign_send_asset_action,
3030
sign_spot_transfer_action,
3131
sign_token_delegate_action,
3232
sign_usd_class_transfer_action,
@@ -456,21 +456,25 @@ def usd_class_transfer(self, amount: float, to_perp: bool) -> Any:
456456
timestamp,
457457
)
458458

459-
def perp_dex_class_transfer(self, dex: str, token: str, amount: float, to_perp: bool) -> Any:
459+
def send_asset(self, destination: str, source_dex: str, destination_dex: str, token: str, amount: float) -> Any:
460+
"""
461+
For the default perp dex use the empty string "" as name. For spot use "spot".
462+
Token must match the collateral token if transferring to or from a perp dex.
463+
"""
460464
timestamp = get_timestamp_ms()
461465
str_amount = str(amount)
462-
if self.vault_address:
463-
str_amount += f" subaccount:{self.vault_address}"
464466

465467
action = {
466-
"type": "PerpDexClassTransfer",
467-
"dex": dex,
468+
"type": "sendAsset",
469+
"destination": destination,
470+
"sourceDex": source_dex,
471+
"destinationDex": destination_dex,
468472
"token": token,
469473
"amount": str_amount,
470-
"toPerp": to_perp,
474+
"fromSubAccount": self.vault_address if self.vault_address else "",
471475
"nonce": timestamp,
472476
}
473-
signature = sign_perp_dex_class_transfer_action(self.wallet, action, self.base_url == MAINNET_API_URL)
477+
signature = sign_send_asset_action(self.wallet, action, self.base_url == MAINNET_API_URL)
474478
return self._post_action(
475479
action,
476480
signature,
@@ -917,13 +921,11 @@ def perp_deploy_set_oracle(
917921
self,
918922
dex: str,
919923
oracle_pxs: Dict[str, str],
920-
mark_pxs: Optional[Dict[str, str]],
924+
all_mark_pxs: List[Dict[str, str]],
921925
) -> Any:
922926
timestamp = get_timestamp_ms()
923927
oracle_pxs_wire = sorted(list(oracle_pxs.items()))
924-
mark_pxs_wire = None
925-
if mark_pxs is not None:
926-
mark_pxs_wire = sorted(list(mark_pxs.items()))
928+
mark_pxs_wire = [sorted(list(mark_pxs.items())) for mark_pxs in all_mark_pxs]
927929
action = {
928930
"type": "perpDeploy",
929931
"setOracle": {

hyperliquid/info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ def query_sub_accounts(self, user: str) -> Any:
598598
def query_user_to_multi_sig_signers(self, multi_sig_user: str) -> Any:
599599
return self.post("/info", {"type": "userToMultiSigSigners", "user": multi_sig_user})
600600

601+
def query_perp_deploy_auction_status(self) -> Any:
602+
return self.post("/info", {"type": "perpDeployAuctionStatus"})
603+
601604
def _remap_coin_subscription(self, subscription: Subscription) -> None:
602605
if (
603606
subscription["type"] == "l2Book"

hyperliquid/utils/signing.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@
104104
{"name": "nonce", "type": "uint64"},
105105
]
106106

107-
PERP_DEX_CLASS_TRANSFER_SIGN_TYPES = [
107+
SEND_ASSET_SIGN_TYPES = [
108108
{"name": "hyperliquidChain", "type": "string"},
109-
{"name": "dex", "type": "string"},
109+
{"name": "destination", "type": "string"},
110+
{"name": "sourceDex", "type": "string"},
111+
{"name": "destinationDex", "type": "string"},
110112
{"name": "token", "type": "string"},
111113
{"name": "amount", "type": "string"},
112-
{"name": "toPerp", "type": "bool"},
114+
{"name": "fromSubAccount", "type": "string"},
113115
{"name": "nonce", "type": "uint64"},
114116
]
115117

@@ -350,12 +352,12 @@ def sign_usd_class_transfer_action(wallet, action, is_mainnet):
350352
)
351353

352354

353-
def sign_perp_dex_class_transfer_action(wallet, action, is_mainnet):
355+
def sign_send_asset_action(wallet, action, is_mainnet):
354356
return sign_user_signed_action(
355357
wallet,
356358
action,
357-
PERP_DEX_CLASS_TRANSFER_SIGN_TYPES,
358-
"HyperliquidTransaction:PerpDexClassTransfer",
359+
SEND_ASSET_SIGN_TYPES,
360+
"HyperliquidTransaction:SendAsset",
359361
is_mainnet,
360362
)
361363

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "hyperliquid-python-sdk"
8-
version = "0.15.0"
8+
version = "0.16.0"
99
description = "SDK for Hyperliquid API trading with Python."
1010
readme = "README.md"
1111
authors = ["Hyperliquid <[email protected]>"]

0 commit comments

Comments
 (0)