Skip to content
Open
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
17 changes: 16 additions & 1 deletion hyperliquid/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
sign_token_delegate_action,
sign_usd_class_transfer_action,
sign_usd_transfer_action,
sign_withdraw_from_bridge_action,
sign_withdraw_from_bridge_action, sign_staking_to_spot_transfer_action,
)
from hyperliquid.utils.types import (
Any,
Expand Down Expand Up @@ -1113,3 +1113,18 @@ def noop(self, nonce):
self.wallet, action, self.vault_address, nonce, self.expires_after, self.base_url == MAINNET_API_URL
)
return self._post_action(action, signature, nonce)

def staking_to_spot_transfer(self, wei: int) -> Any:
timestamp = get_timestamp_ms()
action = {
"wei": wei,
"nonce": timestamp,
"type": "cWithdraw",
}
is_mainnet = self.base_url == MAINNET_API_URL
signature = sign_staking_to_spot_transfer_action(self.wallet, action, is_mainnet)
return self._post_action(
action,
signature,
timestamp,
)
15 changes: 15 additions & 0 deletions hyperliquid/utils/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@
{"name": "nonce", "type": "uint64"},
]

STAKING_TO_SPOT_TRANSFER_SIGN_TYPES = [
{"name": "hyperliquidChain", "type": "string"},
{"name": "wei", "type": "uint64"},
{"name": "nonce", "type": "uint64"},
]


def order_type_to_wire(order_type: OrderType) -> OrderTypeWire:
if "limit" in order_type:
Expand Down Expand Up @@ -488,3 +494,12 @@ def order_wires_to_order_action(order_wires, builder=None):
if builder:
action["builder"] = builder
return action

def sign_staking_to_spot_transfer_action(wallet, action, is_mainnet):
return sign_user_signed_action(
wallet,
action,
STAKING_TO_SPOT_TRANSFER_SIGN_TYPES,
"HyperliquidTransaction:CWithdraw",
is_mainnet,
)