Skip to content

Commit dfd6e9f

Browse files
authored
Vault USD transfer (#56)
1 parent e7c98ae commit dfd6e9f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

examples/basic_vault_transfer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from hyperliquid.utils import constants
2+
import example_utils
3+
4+
5+
def main():
6+
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
7+
testnet_HLP_vault = "0xa15099a30bbf2e68942d6f4c43d70d04faeab0a0"
8+
9+
# Transfer 5 usd to the HLP Vault for demonstration purposes
10+
transfer_result = exchange.vault_usd_transfer(testnet_HLP_vault, True, 5_000_000)
11+
print(transfer_result)
12+
13+
14+
if __name__ == "__main__":
15+
main()

hyperliquid/exchange.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,23 @@ def sub_account_transfer(self, sub_account_user: str, is_deposit: bool, usd: int
427427
signature,
428428
timestamp,
429429
)
430+
431+
def vault_usd_transfer(self, vault_address: str, is_deposit: bool, usd: int) -> Any:
432+
timestamp = get_timestamp_ms()
433+
vault_transfer_action = {
434+
"type": "vaultTransfer",
435+
"vaultAddress": vault_address,
436+
"isDeposit": is_deposit,
437+
"usd": usd}
438+
is_mainnet = self.base_url == MAINNET_API_URL
439+
signature = sign_l1_action(self.wallet, vault_transfer_action, None, timestamp, is_mainnet)
440+
return (
441+
self._post_action(
442+
vault_transfer_action,
443+
signature,
444+
timestamp,
445+
)
446+
)
430447

431448
def usd_transfer(self, amount: float, destination: str) -> Any:
432449
timestamp = get_timestamp_ms()

0 commit comments

Comments
 (0)