You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "How to deposit and withdraw from Hyperliquid to any Relay Chain"
3
+
description: "How to deposit and withdraw from Hyperliquid to any Relay chain"
4
4
---
5
5
6
-
Relay supports depositing & withdrawing to Hyperliquid (Hypercore) perpsUSDC from any supported chain. To try it today, use the [Relay App](https://relay.link/bridge/hyperliquid). Relay also has complete support for HyperEVM, which can be accessed using our main quote flow with `chainId=999`. This document details how to deposit and withdraw from Hyperliquid within your app.
6
+
Relay supports depositing and withdrawing Hyperliquid (Hypercore) perpsUSDC from any supported chain. To try it today, use the [Relay App](https://relay.link/bridge/hyperliquid). Relay also provides complete support for HyperEVM, which can be accessed using the standard quote flow with `chainId=999`. This document details how to integrate Hyperliquid deposits and withdrawals into your application.
7
7
8
8
# API Access
9
9
10
-
Hyperliquid can be accessed using the standard Relay API flow, with the following properties. To get started, check out the[**execution steps**](https://docs.relay.link/references/api/step-execution) of our API. Then when you’re ready to swap, head over to the[**Get Quote**](https://docs.relay.link/references/api/get-quote)API endpoint.
10
+
Hyperliquid can be accessed using the standard Relay API flow. To get started, review the[**execution steps**](https://docs.relay.link/references/api/step-execution) documentation. When you're ready to execute swaps, refer to the[**Get Quote**](https://docs.relay.link/references/api/get-quote)API endpoint.
|Withdraw from Hyperliquid | protocolVersion | v2 | Required for withdrawals |
19
+
|| fromChainId | 1337| Hyperliquid Chain ID|
20
20
21
-
These params define the necessary parameters for Hyperliquid interactions. All other required API parameters are still necessary. _`*** for withdrawals protocolVersion:v2 is a required param.`_
21
+
These parameters are specific to Hyperliquid interactions. All other standard API parameters remain required. Note that `protocolVersion: v2` is mandatory for withdrawals.
22
22
23
23
## Currency Addresses
24
24
@@ -29,118 +29,264 @@ These params define the necessary parameters for Hyperliquid interactions. All o
-The address of non-Spot and non-Perps currencies (eg. currencies on HIP-3 DEXs) is determined by appending the hex-encoded DEX name at the end of the corresponding Spot currency address used by the DEX. For example, `USDC` on the `xyz` DEX is represented as `0x6d1e7cde53ba9467b783cb7c530ce05478797a`, where `0x6d1e7cde53ba9467b783cb7c530ce054` is the address of Spot USDC and `78797a` is the hex representation of “xyz”.
32
+
-For currencies on HIP-3 DEXs (non-Spot and non-Perps), append the hex-encoded DEX name to the corresponding Spot currency address. For example, `USDC` on the `xyz` DEX is represented as `0x6d1e7cde53ba9467b783cb7c530ce05478797a`, where `0x6d1e7cde53ba9467b783cb7c530ce054` is the Spot USDC address and `78797a` is the hex representation of "xyz".
33
33
34
-
## Interacting with Hyperliquid to Initiate Withdrawals
34
+
## Withdrawals from Hyperliquid
35
35
36
-
In order to facilitate withdrawals from hyperliquid in your application, you need to query users balances, and submit hyperliquid transactions.
36
+
Hyperliquid withdrawals use a two-step signature flow. The v2 implementation leverages the unique nonce associated with every Hyperliquid transfer to map deposits to request IDs. This requires two signatures:
37
37
38
-
### Getting Hyperliquid Balances
38
+
1.**Authorize**: Sign a nonce-mapping message that associates a specific nonce with a request ID
39
+
2.**Deposit**: Sign and submit the Hyperliquid transfer transaction using the same nonce
39
40
40
-
You can use the [Hyperliquid info API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint) to get balances. Make sure to pass in `clearinghouseState` as the `type`. Then you can read the `withdrawable` property which should be a USD value in human readable format.
41
+
<Warning>
42
+
The deposit transaction must use the exact same nonce from the authorization signature. If the nonces don't match, Relay cannot associate the transfer with the request ID.
43
+
</Warning>
41
44
42
-
### Submitting Hyperliquid Tx
45
+
### Getting Hyperliquid Balances
43
46
44
-
Once you verify that your address has a usdc perps balance you must sign a message proving ownership over the account and verifying an amount of USDC perps that can be withdrawn. The Relay SDK already handles this for you but here’s a step by step guide on how to do this yourself.
47
+
Use the [Hyperliquid info API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint) to query balances. Pass `clearinghouseState` as the `type` parameter, then read the `withdrawable` property, which returns a USD value in human-readable format.
45
48
46
-
1. You’ll need to take the quote (which returns a transaction step) and convert this into signature data:
The response includes two steps that must be executed in order.
69
+
70
+
### Step 1: Authorize (Nonce-Mapping Signature)
71
+
72
+
The first step (`id: authorize`) requires signing an EIP-712 message that maps the nonce to the request ID. This signature can be executed on any EVM chain.
73
+
74
+
<Note>
75
+
When signing on a different chain than the default, update both `item.data.sign.domain.chainId` and `item.data.post.body.signatureChainId` to match the chain ID where the user signs the message.
76
+
</Note>
77
+
78
+
Example authorize step response:
79
+
80
+
```json
49
81
{
50
-
domain: {
51
-
name: 'HyperliquidSignTransaction',
52
-
version: '1',
53
-
chainId: chainId, //This will be the active chain id for the wallet
After signing, post the signature to the `/authorize` endpoint as specified in `item.data.post`.
83
134
84
-
-`domain` - static except for the `chainId`.
85
-
-`chainId` is the active chain id in the connected wallet. This is the chain id that will sign the message. Next up is the types. These are also static and can be hardcoded.
86
-
-`primaryType` should match the name of the first type.
87
-
-`value`dynamic execution data
88
-
-`signatureChainId` is the hex representation of the aforementioned active chain id.
The second step (`id: deposit`) requires signing and submitting the actual Hyperliquid transfer. The API response includes `eip712Types` and `eip712PrimaryType` to simplify constructing the signature data.
94
138
95
-
The amount can also be retrieved in a similar fashion:
Finally we generate a time, this is used to avoid collisions in Hyperliquid, which recommends using the current UTC millisecond time. The data must then be signed and submitted. The signature should be compliant with eip712:
189
+
### Constructing the Signature Data
103
190
104
-
```jsx
191
+
To sign the deposit step, you need to convert it into EIP-712 signature data. Extract the necessary fields from the step response and construct the signature object:
105
192
106
-
import { useWalletClient } from'wagmi'
107
-
...
108
-
constwalletClient=useWalletClient()
109
-
//All of these fields were already populated above
if (response.status!==200||response.data?.status!=='ok') {
281
+
thrownewError('Failed to submit transaction to Hyperliquid')
282
+
}
142
283
```
143
284
144
-
You must parse the signature into parts (r, s, v). Also make sure that the v is a number and not a BigInt/BigNumber. Use the same data you used when signing, it should match exactly the data you signed. The successful response should be a 200 and the data.status should be an `“ok”`.
285
+
Important considerations:
286
+
287
+
- Parse the signature into its component parts (`r`, `s`, `v`)
288
+
- Ensure `v` is a `Number`, not a `BigInt`
289
+
- The action data must exactly match what was signed
290
+
- A successful response returns status `200` with `data.status: "ok"`
145
291
146
-
To see an [example](https://github.com/reservoirprotocol/relay-kit/blob/main/packages/sdk/src/utils/hyperliquid.ts) you can have a look at our publicly available SDK.
292
+
For a complete implementation example, refer to our [publicly available SDK](https://github.com/reservoirprotocol/relay-kit/blob/main/packages/sdk/src/utils/hyperliquid.ts).
0 commit comments