|
| 1 | +# Example script to deploy HIP-1 and HIP-2 assets |
| 2 | +# See https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-1-and-hip-2-assets |
| 3 | +# for the spec. |
| 4 | +# |
| 5 | +# IMPORTANT: Replace any arguments for the exchange calls below to match your deployment requirements. |
| 6 | + |
| 7 | +import example_utils |
| 8 | + |
| 9 | +from hyperliquid.utils import constants |
| 10 | + |
| 11 | + |
| 12 | +def main(): |
| 13 | + address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) |
| 14 | + |
| 15 | + # Step 1: Registering the Token |
| 16 | + # |
| 17 | + # Takes part in the spot deploy auction and if successful, registers token "TEST0" |
| 18 | + # with sz_decimals 2 and wei_decimals 8. |
| 19 | + # The max gas is $1M USDC and represents the max amount to be paid for the spot deploy auction. |
| 20 | + register_token_result = exchange.spot_deploy_register_token("TEST0", 2, 8, 1000000000000, "Test token example") |
| 21 | + print(register_token_result) |
| 22 | + # If registration is successful, a token index will be returned. This token index is required for |
| 23 | + # later steps in the spot deploy process. |
| 24 | + if register_token_result["status"] == "ok": |
| 25 | + token = register_token_result["response"]["data"] |
| 26 | + else: |
| 27 | + return |
| 28 | + |
| 29 | + # Step 2: User Genesis |
| 30 | + # |
| 31 | + # User genesis can be called multiple times to associate balances to specific users and/or |
| 32 | + # tokens for genesis. |
| 33 | + # |
| 34 | + # Associate 100000000000000 wei with user 0x0000000000000000000000000000000000000001 |
| 35 | + # Associate 100000000000000 wei with hyperliquidity |
| 36 | + user_genesis_result = exchange.spot_deploy_user_genesis( |
| 37 | + token, |
| 38 | + [ |
| 39 | + ("0x0000000000000000000000000000000000000001", "100000000000000"), |
| 40 | + ("0xffffffffffffffffffffffffffffffffffffffff", "100000000000000"), |
| 41 | + ], |
| 42 | + [], |
| 43 | + ) |
| 44 | + print(user_genesis_result) |
| 45 | + # No-op |
| 46 | + user_genesis_result = exchange.spot_deploy_user_genesis(token, [], []) |
| 47 | + print(user_genesis_result) |
| 48 | + # Distribute 100000000000000 wei on a weighted basis to all holders of token with index 1 |
| 49 | + user_genesis_result = exchange.spot_deploy_user_genesis(token, [], [(1, "100000000000000")]) |
| 50 | + print(user_genesis_result) |
| 51 | + |
| 52 | + # Step 3: Genesis |
| 53 | + # |
| 54 | + # Finalize genesis. The max supply of 300000000000000 wei needs to match the total |
| 55 | + # allocation above from user genesis. |
| 56 | + # |
| 57 | + # "noHyperliquidity" can also be set to disable hyperliquidity. In that case, no balance |
| 58 | + # should be associated with hyperliquidity from step 2 (user genesis). |
| 59 | + genesis_result = exchange.spot_deploy_genesis(token, "300000000000000", False) |
| 60 | + print(genesis_result) |
| 61 | + |
| 62 | + # Step 4: Register Spot |
| 63 | + # |
| 64 | + # Register the spot pair (TEST0/USDC) given base and quote token indices. 0 represents USDC. |
| 65 | + # The base token is the first token in the pair and the quote token is the second token. |
| 66 | + register_spot_result = exchange.spot_deploy_register_spot(token, 0) |
| 67 | + print(register_spot_result) |
| 68 | + # If registration is successful, a spot index will be returned. This spot index is required for |
| 69 | + # registering hyperliquidity. |
| 70 | + if register_token_result["status"] == "ok": |
| 71 | + spot = register_token_result["response"]["data"] |
| 72 | + else: |
| 73 | + return |
| 74 | + |
| 75 | + # Step 5: Register Hyperliquidity |
| 76 | + # |
| 77 | + # Registers hyperliquidity for the spot pair. In this example, hyperliquidity is registered |
| 78 | + # with a starting price of $2, an order size of 4, and 100 total orders. |
| 79 | + # |
| 80 | + # This step is required even if "noHyperliquidity" was set to True. |
| 81 | + # If "noHyperliquidity" was set to True during step 3 (genesis), then "n_orders" is required to be 0. |
| 82 | + register_hyperliquidity_result = exchange.spot_deploy_register_hyperliquidity(spot, 2.0, 4.0, 100, None) |
| 83 | + print(register_hyperliquidity_result) |
| 84 | + |
| 85 | + |
| 86 | +if __name__ == "__main__": |
| 87 | + main() |
0 commit comments