Last active
May 26, 2025 03:44
-
-
Save Shuri2060/c9f48d43d0809f7b6385382fbccd80f0 to your computer and use it in GitHub Desktop.
Hyperliquid Spot Deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### Used this code to launch all 3 tokens on HL. Yoinked from my notebook, lmk if there are any issues | |
| ##### Need to install | |
| # python = "^3.10" | |
| # hyperliquid-python-sdk = "^0.3.0". # current latest is "^0.6.0", either version should still be fine | |
| # (I only use the signing function from HL package, you could implement it yourself) | |
| ##### I'm active on the HL Discord https://discord.gg/Hyperliquid | |
| ##### Twitter: https://x.com/Shuri2060_defi | https://x.com/XULIAN_on_hl | |
| ### Example file will use $XULIAN parameters https://app.hyperliquid.xyz/explorer/token/0x6cc648be7e4c38a8c7fcd8bfa6714127 | |
| import eth_account | |
| from generate_payload import * | |
| from deploy_spot import * | |
| ### | |
| IS_MAINNET = False | |
| url = 'https://api.hyperliquid.xyz' if IS_MAINNET else 'https://api.hyperliquid-testnet.xyz' | |
| agent = eth_account.Account.from_key("0x???") | |
| ### | |
| def all_in_one(IS_MAINNET, agent, url, action, nonce): # defined this for sake of this gist | |
| # feel free to print(action) and print(payload) | |
| payload = exchange_sign_payload(IS_MAINNET, action, nonce, agent) | |
| resp = exchange_post(url, payload) | |
| print(resp.content) | |
| return resp | |
| ### Step 1 | |
| # win auction / grab ticker | |
| action = registerToken("XULIAN", 0, 5, 40000_000000) | |
| all_in_one(IS_MAINNET, agent, url, action, time_ms()) | |
| ### | |
| token = ... # Token Index, you will know this after Step 1 | |
| ### Step 2 | |
| # configure balances. This tx can be sent multiple times | |
| action = userGenesisAction( | |
| token, | |
| [ | |
| ["0x942f00b378FDB388bFAe1723ea3b7953B2ae6969".lower(), "6942000000000"], # wallet | |
| ["0xffffffffffffffffffffffffffffffffffffffff".lower(), "27768000000000"], # HIP2 | |
| ], | |
| [ | |
| [1, "6942000000000"], # to Token Indexed 1 | |
| [5, "27768000000000"], # to Token Indexed 5 | |
| ], | |
| ) | |
| all_in_one(IS_MAINNET, agent, url, action, time_ms()) | |
| ### Step 3 | |
| # launches spot pair | |
| action = registerSpotAction(token) | |
| all_in_one(IS_MAINNET, agent, url, action, time_ms()) | |
| ### | |
| spot = ... # spot index, you will know this after Step 3 | |
| asset_pair = 10000 + spot | |
| ### Step 5 | |
| # triggers Genesis, token balance will appear on airdropped accounts. This is the airdrop snapshot. | |
| action = genesisAction(token, "69420000000000") | |
| all_in_one(IS_MAINNET, agent, url, action, time_ms()) | |
| ### Step 4 | |
| # this is sent after Step 5, oddly enough. It is the final tx that enables trading on the pair. | |
| # this is what I presigned to create the $BIGBEN decentralized launching mechanism. Details in https://discord.com/channels/1029781241702129716/1240866754733932554/1256082898897997936 | |
| action = registerHyperliquidityAction(spot, "0.00001441", "69420.0", 4000) | |
| all_in_one(IS_MAINNET, agent, url, action, time_ms()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Refer to docs for param shapes / checks | |
| # https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-1-and-hip-2-assets | |
| # https://hyperliquid.gitbook.io/hyperliquid-docs/hyperliquid-improvement-proposals-hips/frontend-checks | |
| def registerToken(name: str, szDecimals: int, weiDecimals: int, maxGasE6: int, fullName: str | None = None): | |
| registerToken2 = { | |
| "spec": { | |
| "name": name, | |
| "szDecimals": szDecimals, | |
| "weiDecimals": weiDecimals, | |
| }, | |
| "maxGas": maxGasE6, | |
| } | |
| if fullName is not None: | |
| registerToken2["fullName"] = fullName | |
| return { | |
| "type": "spotDeploy", | |
| "registerToken2": registerToken2, | |
| } | |
| def userGenesisAction(token: int, user: list, anchor: list): | |
| return { | |
| "type": "spotDeploy", | |
| "userGenesis": { | |
| "token": token, | |
| "userAndWei": user, | |
| "existingTokenAndWei": anchor, | |
| }, | |
| } | |
| def registerSpotAction(baseToken: int, quoteToken: int = 0): | |
| return { | |
| "type": "spotDeploy", | |
| "registerSpot": { | |
| "tokens": [ | |
| baseToken, | |
| quoteToken, | |
| ], | |
| }, | |
| } | |
| def genesisAction(token: int, maxSupply: str): | |
| return { | |
| "type": "spotDeploy", | |
| "genesis": { | |
| "token": token, | |
| "maxSupply": maxSupply, | |
| }, | |
| } | |
| def registerHyperliquidityAction(spot: int, startPx: str, orderSz: str, nOrders: int, nSeededLevels: int | None = None): | |
| registerHyperliquidity = { | |
| "spot": spot, | |
| "startPx": startPx, | |
| "orderSz": orderSz, | |
| "nOrders": nOrders, | |
| } | |
| if nSeededLevels is not None: | |
| registerHyperliquidity["nSeededLevels"] = nSeededLevels | |
| return { | |
| "type": "spotDeploy", | |
| "registerHyperliquidity": registerHyperliquidity, | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import time | |
| import json | |
| from eth_account.signers.local import LocalAccount | |
| from hyperliquid.utils.signing import sign_l1_action | |
| def time_ms(): | |
| return int(time.time_ns() * 1e-6) | |
| def exchange_sign_payload(is_mainnet: bool, action: dict, nonce: int, wallet: LocalAccount, subaccount: str = None): | |
| signature = sign_l1_action( | |
| wallet=wallet, | |
| action=action, | |
| active_pool=subaccount, | |
| nonce=nonce, | |
| is_mainnet=is_mainnet, | |
| ) | |
| return { | |
| "action": action, | |
| "nonce": nonce, | |
| "signature": signature, | |
| "vaultAddress": subaccount, | |
| } | |
| def exchange_post(url, payload): | |
| return requests.post(url + "/exchange", json=payload) |
Author
Author
changed twitter handle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implemented breaking change to deploy API for
registerSpot