hyperliquid 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6baba398ac6a839785cea71c83f96b7a7e339f200604288f9920f25b5a49ed0
4
- data.tar.gz: 0b1961c8b84802e88730421516d27b58e5e14bb055ac190a82e2c0881c692333
3
+ metadata.gz: c7969eed04a0b822b7be2c29c3ab57f97f077eaf8ed245bc48cb4916fd6b5836
4
+ data.tar.gz: d37e1acbf31a1e26454071ede7c83fcccf842bf9524835def63a652e77fff1af
5
5
  SHA512:
6
- metadata.gz: a7f8886eede6df8fcde833b490733def438945d115c4d3664d397c037d97c5e785e13793885e984baeaf696f156f1f59f614c8f5d0f384e47cbc7d1b1d85708e
7
- data.tar.gz: 518cdc5f65b6fd3de3c15a96bf6e67049af1c5935e9a67a9e56b01d45d43984506d9e30804ec01a9723fe2ff9e1306b2ee32bbb1959dfead2a4f6b036c2c2d49
6
+ metadata.gz: 1a7bc66c9acd82975bb1e5929d2f4b77469c5e52b3c9824f7ce5306ad642c1e065531d6f4c20134cdab85c350b2f694736c5a414ee6e7a564d35abc658ed1074
7
+ data.tar.gz: 9898cba2cbf564dff73f950a29423dd5f42ab2fddf62458418d365546893dabdc5f3ddf159f1af31c7e6254ff02aeaa1a77ca0c63f6198931ee291319daaab82
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.8
1
+ 3.4.9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  ## [Ruby Hyperliquid SDK Changelog]
2
2
 
3
+ ## [1.4.0] - 2026-05-05
4
+
5
+ ### New Exchange actions
6
+
7
+ - `Exchange#send_to_evm_with_data(destination:, token:, amount:, data:, ...)` — user-signed; transfers Core assets to HyperEVM with arbitrary calldata for `ICoreReceiveWithData` contracts. Adds `SEND_TO_EVM_WITH_DATA_TYPES` (first user-signed action using `bytes`). Includes signature-parity regression specs against captured `eth_account` fixtures to lock down eth gem's `bytes` handling.
8
+ - `Exchange#agent_send_asset(...)` — agent-signed counterpart to `send_asset` (destination must equal the agent's principal).
9
+ - `Exchange#hip3_liquidator_transfer(dex:, usdc:, to_dex:)` — deposit/withdraw to an HIP-3 DEX backstop in 1e-6 quote-token units.
10
+ - `Exchange#borrow_lend(token:, action:, amount:, is_isolated:)` — HIP-2 supply/withdraw/repay/borrow (L1 action). Companion to the four HIP-2 info methods. `amount` is nullable for full-position ops.
11
+ - `Exchange#sub_account_modify(sub_account_user:, name:)` — rename a sub-account (L1 action).
12
+ - `Exchange#link_staking_user(staking_user:, ...)` — link staking + trading accounts for fee discount (user-signed EIP-712). Adds `LINK_STAKING_USER_TYPES`.
13
+
14
+ ## [1.3.0] - 2026-04-30
15
+
16
+ ### New transport
17
+
18
+ - Explorer RPC connection (`rpc.hyperliquid.xyz` / `rpc.hyperliquid-testnet.xyz`, endpoint `/explorer`). `Client` gains optional `explorer_base_url:` and `target: :explorer` routing, with a lazily-built second Faraday connection sharing the default retry/timeout config. The SDK wires this up automatically based on `testnet:`.
19
+ - New `Hyperliquid::ConfigurationError` raised when `target: :explorer` is used on a client constructed without an explorer URL.
20
+
21
+ ### New Info endpoints
22
+
23
+ - `Info#tx_details(hash)` — explorer `txDetails` lookup
24
+ - `Info#user_details(user)` — explorer `userDetails` lookup
25
+
26
+ ### New Exchange actions
27
+
28
+ - `Exchange#claim_rewards` — L1 `claimRewards`
29
+ - `Exchange#set_display_name(display_name:)` — L1 `setDisplayName` (max 20 chars; `""` clears)
30
+ - `Exchange#register_referrer(code:)` — L1 `registerReferrer`
31
+ - `Exchange#top_up_isolated_only_margin(coin:, leverage:, vault_address:)` — L1 `topUpIsolatedOnlyMargin`
32
+ - `Exchange#vault_modify(vault_address:, allow_deposits:, always_close_on_withdraw:)` — L1 `vaultModify`
33
+ - `Exchange#vault_distribute(vault_address:, usd:)` — L1 `vaultDistribute`
34
+
3
35
  ## [1.2.0] - 2026-04-27
4
36
 
5
37
  ### New Info endpoints
data/CLAUDE.md CHANGED
@@ -50,6 +50,7 @@ Hyperliquid.new(...)
50
50
 
51
51
  - **Info path**: method builds `{ type: 'someType', ... }` body → `Client` POSTs to `/info` → parsed JSON returned.
52
52
  - **Exchange path**: method builds action payload → `Signer` generates EIP-712 signature over msgpack-encoded action → `Client` POSTs signed payload to `/exchange` → parsed JSON returned.
53
+ - **Explorer RPC path** (`tx_details`, `user_details`): a separate base URL (`rpc.hyperliquid.xyz` / `rpc.hyperliquid-testnet.xyz`) with endpoint `/explorer`. `Client` holds a second Faraday connection for this, built lazily on first use; methods opt in via `client.post(EXPLORER_ENDPOINT, body, target: :explorer)`. The SDK wires this up automatically based on `testnet:`. Calling `target: :explorer` on a `Client` constructed without `explorer_base_url:` raises `ConfigurationError`. Don't add a public connection accessor — `target:` is the contract.
53
54
  - **WebSocket path**: `WS::Client` manages a persistent WSS connection with subscription tracking, automatic reconnection (exp backoff, 30s cap), 50s ping keepalive, and a bounded message queue (1024, drops oldest on overflow). Subscriptions are identified by a canonical key and dispatched via callbacks on a dedicated thread.
54
55
 
55
56
  ### Signing (Python SDK Parity)
@@ -62,6 +63,8 @@ The signing chain in `lib/hyperliquid/signing/` must exactly match the official
62
63
 
63
64
  Any change to signing must maintain parity with the Python SDK or transactions will be rejected by the exchange.
64
65
 
66
+ User-signed actions (`usd_send`, `withdraw_from_bridge`, `send_to_evm_with_data`, etc.) use direct EIP-712 typed-data signing with the `HyperliquidSignTransaction` domain (chain ID 421614) — not the phantom-agent flow. Each has a typed-data spec in `Signing::EIP712`. The `eth` gem's typed-data signer handles primitive types (`string`, `uint*`, `address`, `bool`) and dynamic `bytes` correctly — `send_to_evm_with_data` was the first to use `bytes`, and its spec includes a fixture-based signature parity test against `eth_account` to lock that in. When adding new user-signed actions with non-string types, add a similar fixture to catch eth-gem regressions.
67
+
65
68
  ### Numeric Conversion
66
69
 
67
70
  - **`float_to_wire`** (in Exchange): converts to string with 8-decimal precision, validates rounding tolerance (`1e-12`), normalizes trailing zeros. No scientific notation.
@@ -21,17 +21,24 @@ module Hyperliquid
21
21
  }.freeze
22
22
 
23
23
  # Initialize a new HTTP client
24
- # @param base_url [String] The base URL for the API
24
+ # @param base_url [String] The base URL for the default API (info/exchange)
25
25
  # @param timeout [Integer] Request timeout in seconds (default: Constants::DEFAULT_TIMEOUT)
26
26
  # @param retry_enabled [Boolean] Whether to enable retry logic (default: false)
27
- def initialize(base_url:, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false)
27
+ # @param explorer_base_url [String, nil] Optional base URL for the explorer RPC (used by
28
+ # tx_details / user_details). When nil, calls with target: :explorer raise ConfigurationError.
29
+ def initialize(base_url:, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false,
30
+ explorer_base_url: nil)
28
31
  @retry_enabled = retry_enabled
29
- @connection = build_connection(base_url, timeout)
32
+ @timeout = timeout
33
+ @explorer_base_url = explorer_base_url
34
+ @connection = build_connection(base_url)
35
+ @explorer_connection = nil
30
36
  end
31
37
 
32
38
  # Make a POST request to the API
33
39
  # @param endpoint [String] The API endpoint to make the request to
34
40
  # @param body [Hash] The request body as a hash (default: {})
41
+ # @param target [Symbol] Which connection to use; :default (info/exchange) or :explorer (RPC)
35
42
  # @return [Hash, String] The parsed JSON response or raw response body
36
43
  # @raise [NetworkError] When connection fails
37
44
  # @raise [TimeoutError] When request times out
@@ -41,8 +48,10 @@ module Hyperliquid
41
48
  # @raise [RateLimitError] When API returns 429 status
42
49
  # @raise [ServerError] When API returns 5xx status
43
50
  # @raise [ClientError] When API returns unexpected status
44
- def post(endpoint, body = {})
45
- response = @connection.post(endpoint) do |req|
51
+ # @raise [ConfigurationError] When target: :explorer is requested but no explorer_base_url was configured
52
+ def post(endpoint, body = {}, target: :default)
53
+ connection = connection_for(target)
54
+ response = connection.post(endpoint) do |req|
46
55
  req.headers['Content-Type'] = 'application/json'
47
56
  req.body = body.to_json unless body.empty?
48
57
  end
@@ -60,9 +69,24 @@ module Hyperliquid
60
69
 
61
70
  private
62
71
 
63
- def build_connection(base_url, timeout)
72
+ def connection_for(target)
73
+ case target
74
+ when :default
75
+ @connection
76
+ when :explorer
77
+ unless @explorer_base_url
78
+ raise ConfigurationError,
79
+ 'Explorer RPC URL not configured; pass explorer_base_url: when constructing the Client'
80
+ end
81
+ @explorer_connection ||= build_connection(@explorer_base_url)
82
+ else
83
+ raise ArgumentError, "Unknown post target: #{target.inspect} (expected :default or :explorer)"
84
+ end
85
+ end
86
+
87
+ def build_connection(base_url)
64
88
  Faraday.new(url: base_url) do |conn|
65
- conn.options.timeout = timeout
89
+ conn.options.timeout = @timeout
66
90
  conn.options.read_timeout = Constants::DEFAULT_READ_TIMEOUT
67
91
  conn.request :retry, DEFAULT_RETRY_OPTIONS if @retry_enabled
68
92
  end
@@ -7,9 +7,14 @@ module Hyperliquid
7
7
  MAINNET_API_URL = 'https://api.hyperliquid.xyz'
8
8
  TESTNET_API_URL = 'https://api.hyperliquid-testnet.xyz'
9
9
 
10
+ # Explorer RPC URLs (used by Info#tx_details and Info#user_details)
11
+ MAINNET_RPC_URL = 'https://rpc.hyperliquid.xyz'
12
+ TESTNET_RPC_URL = 'https://rpc.hyperliquid-testnet.xyz'
13
+
10
14
  # API endpoints
11
15
  INFO_ENDPOINT = '/info'
12
16
  EXCHANGE_ENDPOINT = '/exchange'
17
+ EXPLORER_ENDPOINT = '/explorer'
13
18
 
14
19
  # WebSocket
15
20
  WS_ENDPOINT = '/ws'
@@ -38,4 +38,8 @@ module Hyperliquid
38
38
 
39
39
  # Error for WebSocket issues
40
40
  class WebSocketError < Error; end
41
+
42
+ # Error for SDK configuration issues (e.g. calling an explorer-only method
43
+ # on a Client that wasn't configured with an explorer_base_url)
44
+ class ConfigurationError < Error; end
41
45
  end
@@ -793,6 +793,266 @@ module Hyperliquid
793
793
  post_action(action, signature, nonce, nil)
794
794
  end
795
795
 
796
+ # Claim accrued referral-program rewards (`claimRewards` L1 action).
797
+ # @return [Hash] Exchange response
798
+ def claim_rewards
799
+ nonce = timestamp_ms
800
+ action = { type: 'claimRewards' }
801
+ signature = @signer.sign_l1_action(
802
+ action, nonce,
803
+ expires_after: @expires_after
804
+ )
805
+ post_action(action, signature, nonce, nil)
806
+ end
807
+
808
+ # Set the leaderboard display name (`setDisplayName` L1 action).
809
+ # Pass an empty string to remove the existing display name.
810
+ # @param display_name [String] Display name (max 20 characters)
811
+ # @return [Hash] Exchange response
812
+ def set_display_name(display_name:)
813
+ nonce = timestamp_ms
814
+ action = { type: 'setDisplayName', displayName: display_name }
815
+ signature = @signer.sign_l1_action(
816
+ action, nonce,
817
+ expires_after: @expires_after
818
+ )
819
+ post_action(action, signature, nonce, nil)
820
+ end
821
+
822
+ # Register a new referral code for this account (`registerReferrer` L1 action).
823
+ # Distinct from `set_referrer`, which records a referrer the account was referred *by*.
824
+ # @param code [String] Referral code to create (1–20 characters)
825
+ # @return [Hash] Exchange response
826
+ def register_referrer(code:)
827
+ nonce = timestamp_ms
828
+ action = { type: 'registerReferrer', code: code }
829
+ signature = @signer.sign_l1_action(
830
+ action, nonce,
831
+ expires_after: @expires_after
832
+ )
833
+ post_action(action, signature, nonce, nil)
834
+ end
835
+
836
+ # Top up isolated margin to target a specific leverage (`topUpIsolatedOnlyMargin` L1 action).
837
+ # @param coin [String] Asset symbol (perps only)
838
+ # @param leverage [String, Numeric] Target leverage (sent as float string per protocol)
839
+ # @param vault_address [String, nil] Vault address if acting on behalf of a vault
840
+ # @return [Hash] Exchange response
841
+ def top_up_isolated_only_margin(coin:, leverage:, vault_address: nil)
842
+ nonce = timestamp_ms
843
+ action = {
844
+ type: 'topUpIsolatedOnlyMargin',
845
+ asset: asset_index(coin),
846
+ leverage: leverage.to_s
847
+ }
848
+ signature = @signer.sign_l1_action(
849
+ action, nonce,
850
+ vault_address: vault_address,
851
+ expires_after: @expires_after
852
+ )
853
+ post_action(action, signature, nonce, vault_address)
854
+ end
855
+
856
+ # Modify a vault's configuration (`vaultModify` L1 action).
857
+ # Only the vault leader may submit this. Either flag may be omitted (sent as null).
858
+ # @param vault_address [String] Vault address being modified
859
+ # @param allow_deposits [Boolean, nil] Allow follower deposits (nil = unchanged)
860
+ # @param always_close_on_withdraw [Boolean, nil] Always close positions on withdrawal (nil = unchanged)
861
+ # @return [Hash] Exchange response
862
+ def vault_modify(vault_address:, allow_deposits: nil, always_close_on_withdraw: nil)
863
+ nonce = timestamp_ms
864
+ action = {
865
+ type: 'vaultModify',
866
+ vaultAddress: vault_address,
867
+ allowDeposits: allow_deposits,
868
+ alwaysCloseOnWithdraw: always_close_on_withdraw
869
+ }
870
+ signature = @signer.sign_l1_action(
871
+ action, nonce,
872
+ expires_after: @expires_after
873
+ )
874
+ post_action(action, signature, nonce, nil)
875
+ end
876
+
877
+ # Distribute funds from a vault to followers (`vaultDistribute` L1 action).
878
+ # Only the vault leader may submit this. Pass `usd: 0` to close the vault.
879
+ # @param vault_address [String] Vault address
880
+ # @param usd [Numeric] USD amount to distribute (scaled to integer cents-of-cents internally)
881
+ # @return [Hash] Exchange response
882
+ def vault_distribute(vault_address:, usd:)
883
+ nonce = timestamp_ms
884
+ action = {
885
+ type: 'vaultDistribute',
886
+ vaultAddress: vault_address,
887
+ usd: float_to_usd_int(usd)
888
+ }
889
+ signature = @signer.sign_l1_action(
890
+ action, nonce,
891
+ expires_after: @expires_after
892
+ )
893
+ post_action(action, signature, nonce, nil)
894
+ end
895
+
896
+ # Borrow, lend, supply, or withdraw HIP-2 borrow/lend assets (`borrowLend` L1 action).
897
+ # Companion to the four HIP-2 info methods (`borrow_lend_user_state` etc.).
898
+ # @param operation [String] One of 'supply', 'withdraw', 'repay', 'borrow'
899
+ # @param token [Integer] HIP-2 token ID (e.g. 0 for USDC)
900
+ # @param amount [String, Numeric, nil] Amount to operate on; pass nil to use the full position
901
+ # @param vault_address [String, nil] Vault address if acting on behalf of a vault
902
+ # @return [Hash] Exchange response
903
+ def borrow_lend(operation:, token:, amount: nil, vault_address: nil)
904
+ nonce = timestamp_ms
905
+ action = {
906
+ type: 'borrowLend',
907
+ operation: operation,
908
+ token: token,
909
+ amount: amount&.to_s
910
+ }
911
+ signature = @signer.sign_l1_action(
912
+ action, nonce,
913
+ vault_address: vault_address,
914
+ expires_after: @expires_after
915
+ )
916
+ post_action(action, signature, nonce, vault_address)
917
+ end
918
+
919
+ # Rename a sub-account (`subAccountModify` L1 action).
920
+ # @param sub_account_user [String] Sub-account wallet address to rename
921
+ # @param name [String] New sub-account name (1–16 characters)
922
+ # @return [Hash] Exchange response
923
+ def sub_account_modify(sub_account_user:, name:)
924
+ nonce = timestamp_ms
925
+ action = {
926
+ type: 'subAccountModify',
927
+ subAccountUser: sub_account_user,
928
+ name: name
929
+ }
930
+ signature = @signer.sign_l1_action(
931
+ action, nonce,
932
+ expires_after: @expires_after
933
+ )
934
+ post_action(action, signature, nonce, nil)
935
+ end
936
+
937
+ # Link a staking account to a trading account for fee-discount attribution
938
+ # (`linkStakingUser` user-signed action).
939
+ # The trading user initiates with `is_finalize: false`; the staking user finalizes
940
+ # the permanent link with `is_finalize: true`. The `user` field is the *other*
941
+ # account address in each direction.
942
+ # @param user [String] The counterpart account address (staking address when initiating, trading when finalizing)
943
+ # @param is_finalize [Boolean] False = trading user initiates, true = staking user finalizes
944
+ # @return [Hash] Exchange response
945
+ def link_staking_user(user:, is_finalize:)
946
+ nonce = timestamp_ms
947
+ action = {
948
+ type: 'linkStakingUser',
949
+ signatureChainId: '0x66eee',
950
+ hyperliquidChain: Signing::EIP712.hyperliquid_chain(testnet: @testnet),
951
+ user: user,
952
+ isFinalize: is_finalize,
953
+ nonce: nonce
954
+ }
955
+ signature = @signer.sign_user_signed_action(
956
+ { user: user, isFinalize: is_finalize, nonce: nonce },
957
+ 'HyperliquidTransaction:LinkStakingUser',
958
+ Signing::EIP712::LINK_STAKING_USER_TYPES
959
+ )
960
+ post_action(action, signature, nonce, nil)
961
+ end
962
+
963
+ # Move assets between DEX instances on behalf of an agent's principal
964
+ # (`agentSendAsset` L1 action). Unlike `send_asset` (which is user-signed),
965
+ # this is signed by an agent and the destination must equal the agent's
966
+ # principal address. `source_dex`/`destination_dex` accept "" (default USDC
967
+ # perp DEX) and "spot" (spot trading) per protocol convention.
968
+ # @param destination [String] Destination wallet address (must match the agent's principal)
969
+ # @param source_dex [String] Source DEX identifier
970
+ # @param destination_dex [String] Destination DEX identifier
971
+ # @param token [String] Token in "tokenName:tokenId" format
972
+ # @param amount [String, Numeric] Amount to send
973
+ # @param from_sub_account [String] Source sub-account address, or empty string for the principal
974
+ # @return [Hash] Exchange response
975
+ def agent_send_asset(destination:, source_dex:, destination_dex:, token:, amount:,
976
+ from_sub_account: '')
977
+ nonce = timestamp_ms
978
+ action = {
979
+ type: 'agentSendAsset',
980
+ destination: destination,
981
+ sourceDex: source_dex,
982
+ destinationDex: destination_dex,
983
+ token: token,
984
+ amount: amount.to_s,
985
+ fromSubAccount: from_sub_account,
986
+ nonce: nonce
987
+ }
988
+ signature = @signer.sign_l1_action(
989
+ action, nonce,
990
+ expires_after: @expires_after
991
+ )
992
+ post_action(action, signature, nonce, nil)
993
+ end
994
+
995
+ # Deposit to or withdraw from an HIP-3 DEX's backstop liquidator
996
+ # (`hip3LiquidatorTransfer` L1 action). `ntl` is denominated in 1e-6 quote
997
+ # tokens and the protocol requires it to be a multiple of 1_000_000_000
998
+ # (i.e. $1,000 increments).
999
+ # @param dex [String] HIP-3 DEX identifier
1000
+ # @param ntl [Integer] Notional amount in 1e-6 quote tokens (multiple of 1_000_000_000)
1001
+ # @param is_deposit [Boolean] True to deposit into the backstop, false to withdraw
1002
+ # @return [Hash] Exchange response
1003
+ def hip3_liquidator_transfer(dex:, ntl:, is_deposit:)
1004
+ nonce = timestamp_ms
1005
+ action = { type: 'hip3LiquidatorTransfer', dex: dex, ntl: ntl, isDeposit: is_deposit }
1006
+ signature = @signer.sign_l1_action(
1007
+ action, nonce,
1008
+ expires_after: @expires_after
1009
+ )
1010
+ post_action(action, signature, nonce, nil)
1011
+ end
1012
+
1013
+ # Transfer an asset from Core to HyperEVM with an arbitrary calldata payload
1014
+ # (`sendToEvmWithData` user-signed action). Intended for `ICoreReceiveWithData`
1015
+ # contracts that react atomically to the deposit. `data` accepts a hex string
1016
+ # ('0x' or '0x...'); the EIP-712 signer hashes it as `bytes`.
1017
+ # `destination_recipient` is NOT lowercased — `address_encoding` may be
1018
+ # 'base58' for non-EVM target chains, where lowercasing would corrupt the value.
1019
+ # @param token [String] Token symbol (e.g. "USDC")
1020
+ # @param amount [String, Numeric] Amount as UnsignedDecimal (NOT wei); coerced via to_s
1021
+ # @param source_dex [String] Source DEX identifier (e.g. "spot")
1022
+ # @param destination_recipient [String] Recipient address on the destination chain (hex or base58)
1023
+ # @param address_encoding [String] One of 'hex' or 'base58'
1024
+ # @param destination_chain_id [Integer] Target EVM chain id (e.g. 998 for HyperEVM testnet)
1025
+ # @param gas_limit [Integer] Gas limit for the destination EVM call
1026
+ # @param data [String] ABI calldata hex string ('0x' for empty payload)
1027
+ # @return [Hash] Exchange response
1028
+ def send_to_evm_with_data(token:, amount:, source_dex:, destination_recipient:,
1029
+ address_encoding:, destination_chain_id:, gas_limit:, data: '0x')
1030
+ nonce = timestamp_ms
1031
+ action = {
1032
+ type: 'sendToEvmWithData',
1033
+ signatureChainId: '0x66eee',
1034
+ hyperliquidChain: Signing::EIP712.hyperliquid_chain(testnet: @testnet),
1035
+ token: token,
1036
+ amount: amount.to_s,
1037
+ sourceDex: source_dex,
1038
+ destinationRecipient: destination_recipient,
1039
+ addressEncoding: address_encoding,
1040
+ destinationChainId: destination_chain_id.to_i,
1041
+ gasLimit: gas_limit.to_i,
1042
+ data: data,
1043
+ nonce: nonce
1044
+ }
1045
+ signature = @signer.sign_user_signed_action(
1046
+ { token: token, amount: amount.to_s, sourceDex: source_dex,
1047
+ destinationRecipient: destination_recipient, addressEncoding: address_encoding,
1048
+ destinationChainId: destination_chain_id.to_i, gasLimit: gas_limit.to_i,
1049
+ data: data, nonce: nonce },
1050
+ 'HyperliquidTransaction:SendToEvmWithData',
1051
+ Signing::EIP712::SEND_TO_EVM_WITH_DATA_TYPES
1052
+ )
1053
+ post_action(action, signature, nonce, nil)
1054
+ end
1055
+
796
1056
  # Clear the asset metadata cache
797
1057
  # Call this if metadata has been updated
798
1058
  def reload_metadata!
@@ -631,6 +631,32 @@ module Hyperliquid
631
631
  body[:endTime] = end_time if end_time
632
632
  @client.post(Constants::INFO_ENDPOINT, body)
633
633
  end
634
+
635
+ # ============================
636
+ # Info: Explorer RPC
637
+ # ============================
638
+ # The methods below are routed via a separate base URL (the explorer RPC) rather
639
+ # than the canonical /info endpoint. They require the Client to have been
640
+ # constructed with explorer_base_url:; the SDK does this automatically based on
641
+ # the testnet: flag.
642
+
643
+ # Retrieve transaction details by transaction hash
644
+ # @param hash [String] Transaction hash (66-char 0x-prefixed hex)
645
+ # @return [Hash] Hash with type ('txDetails') and tx (transaction details)
646
+ def tx_details(hash)
647
+ @client.post(Constants::EXPLORER_ENDPOINT, { type: 'txDetails', hash: hash }, target: :explorer)
648
+ end
649
+
650
+ # Retrieve a user's transaction history from the explorer
651
+ # @param user [String] Wallet address
652
+ # @return [Hash] Hash with type ('userDetails') and txs (Array of transaction details)
653
+ def user_details(user)
654
+ @client.post(
655
+ Constants::EXPLORER_ENDPOINT,
656
+ { type: 'userDetails', user: user.downcase },
657
+ target: :explorer
658
+ )
659
+ end
634
660
  end
635
661
  # rubocop:enable Metrics/ClassLength
636
662
  end
@@ -121,6 +121,30 @@ module Hyperliquid
121
121
  ]
122
122
  }.freeze
123
123
 
124
+ LINK_STAKING_USER_TYPES = {
125
+ 'HyperliquidTransaction:LinkStakingUser': [
126
+ { name: :hyperliquidChain, type: 'string' },
127
+ { name: :user, type: 'address' },
128
+ { name: :isFinalize, type: 'bool' },
129
+ { name: :nonce, type: 'uint64' }
130
+ ]
131
+ }.freeze
132
+
133
+ SEND_TO_EVM_WITH_DATA_TYPES = {
134
+ 'HyperliquidTransaction:SendToEvmWithData': [
135
+ { name: :hyperliquidChain, type: 'string' },
136
+ { name: :token, type: 'string' },
137
+ { name: :amount, type: 'string' },
138
+ { name: :sourceDex, type: 'string' },
139
+ { name: :destinationRecipient, type: 'string' },
140
+ { name: :addressEncoding, type: 'string' },
141
+ { name: :destinationChainId, type: 'uint32' },
142
+ { name: :gasLimit, type: 'uint64' },
143
+ { name: :data, type: 'bytes' },
144
+ { name: :nonce, type: 'uint64' }
145
+ ]
146
+ }.freeze
147
+
124
148
  class << self
125
149
  # Domain for L1 actions (orders, cancels, leverage, etc.)
126
150
  # @return [Hash] EIP-712 domain configuration
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hyperliquid
4
- VERSION = '1.2.0'
4
+ VERSION = '1.4.0'
5
5
  end
data/lib/hyperliquid.rb CHANGED
@@ -46,7 +46,13 @@ module Hyperliquid
46
46
  def initialize(testnet: false, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false,
47
47
  private_key: nil, expires_after: nil)
48
48
  base_url = testnet ? Constants::TESTNET_API_URL : Constants::MAINNET_API_URL
49
- client = Client.new(base_url: base_url, timeout: timeout, retry_enabled: retry_enabled)
49
+ explorer_base_url = testnet ? Constants::TESTNET_RPC_URL : Constants::MAINNET_RPC_URL
50
+ client = Client.new(
51
+ base_url: base_url,
52
+ timeout: timeout,
53
+ retry_enabled: retry_enabled,
54
+ explorer_base_url: explorer_base_url
55
+ )
50
56
 
51
57
  @info = Info.new(client)
52
58
  @testnet = testnet
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Test 15: Explorer RPC (tx_details + user_details)
5
+ #
6
+ # Calls the explorer RPC for the wallet's recent transactions:
7
+ # 1. user_details(wallet_address) -> list of recent txs
8
+ # 2. tx_details(first tx hash) -> full details of one tx
9
+ #
10
+ # Requires HYPERLIQUID_PRIVATE_KEY (used to derive wallet address; no signing).
11
+ # A wallet with no testnet activity at all will produce a soft warning rather
12
+ # than fail — explorer testnet endpoint occasionally has its own state quirks.
13
+ #
14
+ # Usage:
15
+ # HYPERLIQUID_PRIVATE_KEY=0x... ruby scripts/test_15_explorer.rb
16
+
17
+ require_relative 'test_helpers'
18
+
19
+ separator('TEST 15: Explorer RPC (tx_details + user_details)')
20
+
21
+ sdk = build_sdk
22
+
23
+ begin
24
+ user_details_resp = sdk.info.user_details(sdk.exchange.address)
25
+ rescue Hyperliquid::Error => e
26
+ puts red("user_details FAILED: #{e.class}: #{e.message}")
27
+ exit 1
28
+ end
29
+
30
+ unless user_details_resp.is_a?(Hash) && user_details_resp['type'] == 'userDetails'
31
+ puts red("user_details: unexpected response shape: #{user_details_resp.inspect}")
32
+ exit 1
33
+ end
34
+
35
+ txs = user_details_resp['txs'] || []
36
+ puts green("user_details OK: #{txs.length} txs returned")
37
+
38
+ if txs.empty?
39
+ puts 'No txs on this wallet — skipping tx_details lookup.'
40
+ test_passed('Test 15 explorer RPC')
41
+ exit 0
42
+ end
43
+
44
+ first_hash = txs.first['hash']
45
+ unless first_hash.is_a?(String) && first_hash.start_with?('0x')
46
+ puts red("First tx hash missing or malformed: #{first_hash.inspect}")
47
+ exit 1
48
+ end
49
+
50
+ puts "Looking up tx_details for #{first_hash}..."
51
+ begin
52
+ tx_resp = sdk.info.tx_details(first_hash)
53
+ rescue Hyperliquid::Error => e
54
+ puts red("tx_details FAILED: #{e.class}: #{e.message}")
55
+ exit 1
56
+ end
57
+
58
+ unless tx_resp.is_a?(Hash) && tx_resp['type'] == 'txDetails'
59
+ puts red("tx_details: unexpected response shape: #{tx_resp.inspect}")
60
+ exit 1
61
+ end
62
+
63
+ tx = tx_resp['tx']
64
+ unless tx.is_a?(Hash) && tx['hash'] == first_hash
65
+ puts red("tx_details: hash mismatch or missing tx: #{tx.inspect}")
66
+ exit 1
67
+ end
68
+
69
+ puts green("tx_details OK: action=#{tx.dig('action', 'type')} time=#{tx['time']}")
70
+
71
+ test_passed('Test 15 explorer RPC')
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Test 16: sendToEvmWithData (user-signed exchange action)
5
+ #
6
+ # Mirrors the TS SDK's `tests/api/exchange/sendToEvmWithData.test.ts`:
7
+ # 1. Top up spot USDC by 2 (via usd_class_transfer perp -> spot).
8
+ # 2. Submit one real sendToEvmWithData action sending 1 USDC to 0x...01
9
+ # on HyperEVM testnet (chain 998) with empty calldata.
10
+ # 3. Assert response is { status: 'ok', response: { type: 'default' } }.
11
+ #
12
+ # This funds-moving test sends 1 testnet USDC to 0x...01 (effectively burned —
13
+ # no contract is there to redirect it). Same bar the TS SDK uses for its own
14
+ # test suite.
15
+ #
16
+ # Skips with a warning if the wallet is on unified account (usd_class_transfer
17
+ # is disabled in that mode and the top-up cannot run).
18
+ #
19
+ # Usage:
20
+ # HYPERLIQUID_PRIVATE_KEY=0x... ruby scripts/test_16_send_to_evm_with_data.rb
21
+
22
+ require_relative 'test_helpers'
23
+
24
+ sdk = build_sdk
25
+ separator('TEST 16: sendToEvmWithData')
26
+
27
+ abstraction = sdk.info.user_abstraction(sdk.exchange.address)
28
+ if abstraction == 'unifiedAccount'
29
+ puts "SKIPPED: Wallet has unified account active (abstraction=#{abstraction.inspect})."
30
+ puts ' usd_class_transfer top-up step is disabled by the exchange when balances are unified.'
31
+ test_passed('Test 16 sendToEvmWithData')
32
+ exit 0
33
+ end
34
+
35
+ puts 'Topping up spot USDC by $2 (perp -> spot)...'
36
+ top_up = sdk.exchange.usd_class_transfer(amount: '2', to_perp: false)
37
+ dump_status(top_up)
38
+ if api_error?(top_up)
39
+ puts red('Top-up failed; aborting before sendToEvmWithData.')
40
+ test_passed('Test 16 sendToEvmWithData')
41
+ exit 1
42
+ end
43
+ puts green('Top-up successful.')
44
+ puts
45
+
46
+ wait_with_countdown(WAIT_SECONDS, 'Waiting before sendToEvmWithData...')
47
+
48
+ puts 'Sending 1 USDC to 0x...01 on HyperEVM testnet (chain 998) with empty calldata...'
49
+ result = sdk.exchange.send_to_evm_with_data(
50
+ token: 'USDC',
51
+ amount: '1',
52
+ source_dex: 'spot',
53
+ destination_recipient: '0x0000000000000000000000000000000000000001',
54
+ address_encoding: 'hex',
55
+ destination_chain_id: 998,
56
+ gas_limit: 200_000,
57
+ data: '0x'
58
+ )
59
+
60
+ if api_error?(result)
61
+ puts red("sendToEvmWithData FAILED: #{result.inspect}")
62
+ test_passed('Test 16 sendToEvmWithData')
63
+ exit 1
64
+ end
65
+
66
+ unless result.is_a?(Hash) && result['status'] == 'ok'
67
+ $test_failed = true
68
+ puts red("Unexpected status: #{result.inspect}")
69
+ end
70
+
71
+ response_type = result.dig('response', 'type')
72
+ unless response_type == 'default'
73
+ $test_failed = true
74
+ puts red("Expected response.type 'default', got: #{response_type.inspect}")
75
+ end
76
+
77
+ puts green("sendToEvmWithData OK: status=ok, response.type=#{response_type}") unless $test_failed
78
+
79
+ test_passed('Test 16 sendToEvmWithData')
data/scripts/test_all.rb CHANGED
@@ -32,7 +32,9 @@ SCRIPTS = [
32
32
  'test_11_builder_fee.rb',
33
33
  'test_12_staking.rb',
34
34
  'test_13_ws_l2_book.rb',
35
- 'test_14_ws_candle.rb'
35
+ 'test_14_ws_candle.rb',
36
+ 'test_15_explorer.rb',
37
+ 'test_16_send_to_evm_with_data.rb'
36
38
  ].freeze
37
39
 
38
40
  def green(text)
@@ -22,7 +22,8 @@ SCRIPTS = [
22
22
  'test_10_vault.rb',
23
23
  'test_11_builder_fee.rb',
24
24
  'test_13_ws_l2_book.rb',
25
- 'test_14_ws_candle.rb'
25
+ 'test_14_ws_candle.rb',
26
+ 'test_15_explorer.rb'
26
27
  ].freeze
27
28
 
28
29
  def green(text)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperliquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - carter2099
@@ -129,6 +129,8 @@ files:
129
129
  - scripts/test_12_staking.rb
130
130
  - scripts/test_13_ws_l2_book.rb
131
131
  - scripts/test_14_ws_candle.rb
132
+ - scripts/test_15_explorer.rb
133
+ - scripts/test_16_send_to_evm_with_data.rb
132
134
  - scripts/test_all.rb
133
135
  - scripts/test_automated.rb
134
136
  - scripts/test_helpers.rb