@dhedge/v2-sdk 2.1.4 → 2.1.6
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.
- package/README.md +180 -45
- package/dist/config.d.ts +10 -0
- package/dist/entities/pool.d.ts +110 -1
- package/dist/services/hyperliquid/constants.d.ts +16 -0
- package/dist/services/hyperliquid/index.d.ts +6 -0
- package/dist/services/hyperliquid/marketData.d.ts +12 -0
- package/dist/services/hyperliquid/positionData.d.ts +1 -0
- package/dist/services/odos/index.d.ts +15 -1
- package/dist/services/toros/limitOrder.d.ts +8 -0
- package/dist/test/constants.d.ts +7 -0
- package/dist/test/wallet.d.ts +1 -0
- package/dist/types.d.ts +12 -2
- package/dist/v2-sdk.cjs.development.js +4256 -1335
- package/dist/v2-sdk.cjs.development.js.map +1 -1
- package/dist/v2-sdk.cjs.production.min.js +1 -1
- package/dist/v2-sdk.cjs.production.min.js.map +1 -1
- package/dist/v2-sdk.esm.js +5007 -2087
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/abi/hyperliquid/ICoreDepositWallet.json +130 -0
- package/src/abi/hyperliquid/ICoreWriter.json +1 -0
- package/src/abi/odos/OdosRouterV3.json +1351 -0
- package/src/abi/toros/IPoolLimitOrderManager.json +78 -0
- package/src/config.ts +44 -13
- package/src/entities/pool.ts +348 -4
- package/src/services/hyperliquid/constants.ts +23 -0
- package/src/services/hyperliquid/index.ts +176 -0
- package/src/services/hyperliquid/marketData.ts +157 -0
- package/src/services/hyperliquid/positionData.ts +33 -0
- package/src/services/odos/index.ts +97 -13
- package/src/services/toros/completeWithdrawal.ts +1 -1
- package/src/services/toros/initWithdrawal.ts +1 -1
- package/src/services/toros/limitOrder.ts +86 -0
- package/src/services/toros/swapData.ts +83 -12
- package/src/test/constants.ts +10 -3
- package/src/test/hyperliquid.test.ts +107 -0
- package/src/test/odos.test.ts +43 -12
- package/src/test/pool.test.ts +37 -45
- package/src/test/torosLimitOrder.test.ts +130 -0
- package/src/test/wallet.ts +2 -1
- package/src/types.ts +13 -2
package/README.md
CHANGED
|
@@ -34,18 +34,18 @@ yarn add @dhedge/v2-sdk
|
|
|
34
34
|
<a href="#initial-setup">Initial setup</a>
|
|
35
35
|
</li>
|
|
36
36
|
<li>
|
|
37
|
-
<a href="#general-
|
|
37
|
+
<a href="#general-vault-management">General Vault Management</a>
|
|
38
38
|
<ul>
|
|
39
|
-
<li><a href="#1-create-
|
|
40
|
-
<li><a href="#2-load-
|
|
41
|
-
<li><a href="#3-get-
|
|
42
|
-
<li><a href="#4-change-
|
|
39
|
+
<li><a href="#1-create-a-vault">Create a vault</a></li>
|
|
40
|
+
<li><a href="#2-load-a-vault">Load a vault</a></li>
|
|
41
|
+
<li><a href="#3-get-vault-composition">Get vault composition</a></li>
|
|
42
|
+
<li><a href="#4-change-vault-assets-enabledisable">Change vault assets</a></li>
|
|
43
43
|
<li><a href="#5-set-trader">Set trader</a></li>
|
|
44
44
|
<li><a href="#6-approve-asset-for-deposit">Approve asset for deposit</a></li>
|
|
45
|
-
<li><a href="#7-deposit-asset-into-
|
|
46
|
-
<li><a href="#8-withdraw-from-
|
|
47
|
-
<li><a href="#9-approve-
|
|
48
|
-
<li><a href="#10-trade-
|
|
45
|
+
<li><a href="#7-deposit-asset-into-a-vault">Deposit asset into a vault</a></li>
|
|
46
|
+
<li><a href="#8-withdraw-from-a-vault">Withdraw from a vault</a></li>
|
|
47
|
+
<li><a href="#9-approve-vault-asset-for-trading--staking)">Approve vault asset for trading & staking</a></li>
|
|
48
|
+
<li><a href="#10-trade-vault-assets">Trade vault assets</a></li>
|
|
49
49
|
</ul>
|
|
50
50
|
</li>
|
|
51
51
|
<li>
|
|
@@ -77,13 +77,24 @@ yarn add @dhedge/v2-sdk
|
|
|
77
77
|
|
|
78
78
|
---
|
|
79
79
|
|
|
80
|
-
If you want to use
|
|
81
|
-
Then you need to copy .env.example file to .env and set your API key there.
|
|
80
|
+
If you want to use aggregators such as 1Inch or Odos, copy `.env.example` to `.env` and configure the API keys you need.
|
|
82
81
|
|
|
83
82
|
```
|
|
84
83
|
ONEINCH_API_KEY=YOUR_API_KEY_FROM_1INCH
|
|
84
|
+
ODOS_API_KEY=YOUR_ODOS_API_KEY
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
- `ONEINCH_API_KEY` is required for `Dapp.ONEINCH`
|
|
88
|
+
- `ODOS_API_KEY` is required for `Dapp.ODOS`
|
|
89
|
+
- `ODOS_API_KEY` can also be required by `completeTorosWithdrawal(...)` when a Toros withdrawal needs Odos-backed swap data
|
|
90
|
+
|
|
91
|
+
To get started:
|
|
92
|
+
|
|
93
|
+
- get a 1inch API key from the [1inch Developer Portal](https://docs.1inch.io/docs/aggregation-protocol/introduction)
|
|
94
|
+
- get an Odos API key via the [Odos developer docs](https://docs.odos.xyz/build/api-docs), and make sure it is valid for the Odos endpoint configured by this SDK
|
|
95
|
+
- place the keys in a `.env` file at the project root before calling aggregator-backed methods
|
|
96
|
+
- if a required key is missing, the SDK will fail before transaction submission
|
|
97
|
+
|
|
87
98
|
Initialize the sdk with an [ethers wallet](https://docs.ethers.io/v5/api/signer/#Wallet) and the network.
|
|
88
99
|
|
|
89
100
|
```ts
|
|
@@ -98,20 +109,74 @@ const walletWithProvider = new ethers.Wallet(privateKey, provider);
|
|
|
98
109
|
const dhedge = new Dhedge(walletWithProvider, Network.POLYGON);
|
|
99
110
|
```
|
|
100
111
|
|
|
112
|
+
In dHEDGE product language these are usually called vaults. In the SDK and smart contracts, many classes and methods still use the older `pool` naming, so both terms may appear in the code examples below.
|
|
113
|
+
|
|
114
|
+
Important notes:
|
|
115
|
+
|
|
116
|
+
- `Dhedge` expects a provider-connected `ethers.Wallet`. Read-only providers are not enough for state-changing calls.
|
|
117
|
+
- The wallet you pass in is the account that signs transactions. In most cases this is the pool manager wallet.
|
|
118
|
+
- `loadPool(address)` assumes the address is a dHEDGE pool and resolves the manager contract automatically.
|
|
119
|
+
- `loadPool(address, false)` can be used when you want to work with a non-dHEDGE contract that should execute directly from the signer.
|
|
120
|
+
|
|
121
|
+
#### Execution model
|
|
122
|
+
|
|
123
|
+
By default, manager actions are executed through `pool.poolLogic.execTransaction(...)`.
|
|
124
|
+
|
|
125
|
+
If you set a separate trader account with `pool.setTrader(...)`, you can estimate or send transactions from the trader wallet by using `sdkOptions.useTraderAddressAsFrom`.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const tx = await pool.trade(
|
|
129
|
+
Dapp.ONEINCH,
|
|
130
|
+
"USDC_TOKEN_ADDRESS",
|
|
131
|
+
"WETH_TOKEN_ADDRESS",
|
|
132
|
+
"1000000",
|
|
133
|
+
0.5,
|
|
134
|
+
null,
|
|
135
|
+
{
|
|
136
|
+
estimateGas: true,
|
|
137
|
+
useTraderAddressAsFrom: true,
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Simulation and tx data
|
|
143
|
+
|
|
144
|
+
Most manager methods accept `sdkOptions` as the last argument.
|
|
145
|
+
|
|
146
|
+
- `true` is shorthand for `{ estimateGas: true }`
|
|
147
|
+
- `{ estimateGas: true }` returns `{ gas, gasEstimationError, to, txData, minAmountOut }`
|
|
148
|
+
- `{ onlyGetTxData: true }` returns `{ to, txData, minAmountOut }` without sending a transaction
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const result = await pool.trade(
|
|
152
|
+
Dapp.ONEINCH,
|
|
153
|
+
"USDC_TOKEN_ADDRESS",
|
|
154
|
+
"WETH_TOKEN_ADDRESS",
|
|
155
|
+
"1000000",
|
|
156
|
+
0.5,
|
|
157
|
+
null,
|
|
158
|
+
{ estimateGas: true }
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
if (result.gasEstimationError) {
|
|
162
|
+
console.error(result.gasEstimationError)
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
101
166
|
<br>
|
|
102
167
|
|
|
103
|
-
### General
|
|
168
|
+
### General Vault Management
|
|
104
169
|
|
|
105
170
|
---
|
|
106
171
|
|
|
107
|
-
#### 1. Create a
|
|
172
|
+
#### 1. Create a vault
|
|
108
173
|
|
|
109
174
|
USDC and DAI enabled assets, but only USDC available for deposit.
|
|
110
175
|
|
|
111
176
|
```ts
|
|
112
177
|
const usdcTokenAddress = "USDC_TOKEN_ADDRESS"
|
|
113
178
|
const daiTokenAddress = "DAI_TOKEN_ADDRESS"
|
|
114
|
-
const
|
|
179
|
+
const vault = await dhedge.createPool(
|
|
115
180
|
"Day Ralio",
|
|
116
181
|
"Awesome Fund",
|
|
117
182
|
"DRAF",
|
|
@@ -121,23 +186,45 @@ const pool = await dhedge.createPool(
|
|
|
121
186
|
],
|
|
122
187
|
10
|
|
123
188
|
)
|
|
124
|
-
console.log("created
|
|
189
|
+
console.log("created vault with address", vault.address)
|
|
125
190
|
```
|
|
126
191
|
|
|
127
|
-
#### 2. Load
|
|
192
|
+
#### 2. Load a vault
|
|
128
193
|
|
|
129
194
|
```ts
|
|
130
|
-
const
|
|
131
|
-
const
|
|
195
|
+
const vaultAddress = "YOUR_VAULT_ADDRESS"
|
|
196
|
+
const vault = await dhedge.loadPool(vaultAddress)
|
|
132
197
|
```
|
|
133
198
|
|
|
134
|
-
|
|
199
|
+
Validate a vault address before loading it:
|
|
135
200
|
|
|
136
201
|
```ts
|
|
137
|
-
const
|
|
202
|
+
const isValidVault = await dhedge.validatePool(vaultAddress)
|
|
203
|
+
if (!isValidVault) throw new Error("invalid dHEDGE vault address")
|
|
138
204
|
```
|
|
139
205
|
|
|
140
|
-
####
|
|
206
|
+
#### 3. Get vault composition
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
const composition = await vault.getComposition();
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`getComposition()` returns raw on-chain values:
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
[
|
|
216
|
+
{
|
|
217
|
+
asset: "0x...",
|
|
218
|
+
isDeposit: true,
|
|
219
|
+
balance: BigNumber,
|
|
220
|
+
rate: BigNumber,
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
You will usually need to fetch token decimals and symbols separately before displaying vault holdings to users.
|
|
226
|
+
|
|
227
|
+
#### 4. Change vault assets (enable/disable)
|
|
141
228
|
|
|
142
229
|
Change pool assets to allow DAI for deposits. Also enable WETH as an asset, but shouldn't be allowed as deposit.
|
|
143
230
|
|
|
@@ -147,7 +234,7 @@ const enabledAssets = [
|
|
|
147
234
|
{ asset: "DAI_TOKEN_ADDRESS", isDeposit: true },
|
|
148
235
|
{ asset: "WETH_TOKEN_ADDRESS", isDeposit: false },
|
|
149
236
|
]
|
|
150
|
-
const tx = await
|
|
237
|
+
const tx = await vault.changeAssets(enabledAssets)
|
|
151
238
|
```
|
|
152
239
|
|
|
153
240
|
#### 5. Set trader
|
|
@@ -155,59 +242,66 @@ const tx = await pool.changeAssets(enabledAssets)
|
|
|
155
242
|
Set an account with trading permissions
|
|
156
243
|
|
|
157
244
|
```ts
|
|
158
|
-
const tx = await
|
|
245
|
+
const tx = await vault.setTrader("TRADER_ACCOUNT_ADDRESS")
|
|
159
246
|
```
|
|
160
247
|
|
|
161
248
|
#### 6. Approve asset for deposit
|
|
162
249
|
|
|
163
|
-
Before depositing an asset into a
|
|
250
|
+
Before depositing an asset into a vault, the user wallet must approve the vault to transfer that asset.
|
|
164
251
|
|
|
165
|
-
Approve unlimited amount of USDC to deposit into
|
|
252
|
+
Approve unlimited amount of USDC to deposit into a vault.
|
|
166
253
|
|
|
167
254
|
```ts
|
|
168
|
-
const tx = await
|
|
255
|
+
const tx = await vault.approveDeposit("USDC_TOKEN_ADDRESS", ethers.constants.MaxUint256);
|
|
169
256
|
```
|
|
170
257
|
|
|
171
|
-
#### 7. Deposit asset into
|
|
258
|
+
#### 7. Deposit asset into a vault
|
|
172
259
|
|
|
173
|
-
Deposit 1 USDC into
|
|
260
|
+
Deposit 1 USDC into a vault
|
|
174
261
|
|
|
175
262
|
```ts
|
|
176
263
|
const usdcDepositAmount = "100000"
|
|
177
|
-
const tx = await
|
|
264
|
+
const tx = await vault.deposit("USDC_TOKEN_ADDRESS", usdcDepositAmount);
|
|
178
265
|
```
|
|
179
266
|
|
|
180
|
-
#### 8. Withdraw from
|
|
267
|
+
#### 8. Withdraw from a vault
|
|
181
268
|
|
|
182
|
-
Withdraw 1.00002975
|
|
269
|
+
Withdraw 1.00002975 vault tokens. Note that this cannot be called if set as Trader account
|
|
183
270
|
|
|
184
271
|
```ts
|
|
185
272
|
const poolTokensWithdrawAmount = "1000029750000000000"
|
|
186
|
-
const tx = await
|
|
273
|
+
const tx = await vault.withdraw(poolTokensWithdrawAmount);
|
|
187
274
|
```
|
|
188
275
|
|
|
189
|
-
#### 9. Approve
|
|
276
|
+
#### 9. Approve vault asset for trading & staking
|
|
190
277
|
|
|
191
|
-
Before
|
|
278
|
+
Before the vault can trade or stake an asset on an external protocol, the vault must approve that protocol router or staking contract.
|
|
192
279
|
|
|
193
280
|
Approve unlimited amount of USDC to trade on Sushiswap
|
|
194
281
|
|
|
195
282
|
```ts
|
|
196
|
-
const tx = await
|
|
283
|
+
const tx = await vault.approve(
|
|
197
284
|
Dapp.SUSHISWAP,
|
|
198
285
|
"USDC_TOKEN_ADDRESS",
|
|
199
286
|
ethers.constants.MaxInt256
|
|
200
287
|
)
|
|
201
288
|
```
|
|
202
289
|
|
|
203
|
-
|
|
290
|
+
Approval model summary:
|
|
291
|
+
|
|
292
|
+
- `approveDeposit(asset, amount)` approves from the user wallet to the vault
|
|
293
|
+
- `approve(dapp, asset, amount)` approves from the vault to a protocol router
|
|
294
|
+
- `approveStaking(dapp, asset, amount)` approves from the vault to a staking contract
|
|
295
|
+
- `approveSpender(spender, asset, amount)` is available for custom integrations
|
|
204
296
|
|
|
205
|
-
|
|
297
|
+
#### 10. Trade vault assets
|
|
298
|
+
|
|
299
|
+
Trade 1 USDC into DAI on Sushiswap (other options depend on network and configured API keys, and can include TOROS, QUICKSWAP, BALANCER, ONEINCH, and ODOS)
|
|
206
300
|
|
|
207
301
|
```ts
|
|
208
302
|
const amountIn = "1000000"
|
|
209
303
|
const slippage = 0.5
|
|
210
|
-
const tx = await
|
|
304
|
+
const tx = await vault.trade(
|
|
211
305
|
Dapp.SUSHISWAP,
|
|
212
306
|
"USDC_TOKEN_ADDRESS",
|
|
213
307
|
"DAI_TOKEN_ADDRESS",
|
|
@@ -216,21 +310,62 @@ const tx = await pool.trade(
|
|
|
216
310
|
)
|
|
217
311
|
```
|
|
218
312
|
|
|
219
|
-
####
|
|
220
|
-
|
|
221
|
-
|
|
313
|
+
#### Toros mint flow
|
|
314
|
+
|
|
315
|
+
Minting a Toros token uses `vault.trade(...)`, but it is not a generic token-to-token swap. The input asset must be a valid deposit asset for the underlying Toros vault.
|
|
316
|
+
|
|
222
317
|
```ts
|
|
223
|
-
|
|
318
|
+
await vault.approve(
|
|
319
|
+
Dapp.TOROS,
|
|
320
|
+
"USDC_TOKEN_ADDRESS",
|
|
321
|
+
ethers.constants.MaxUint256
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
const tx = await vault.trade(
|
|
325
|
+
Dapp.TOROS,
|
|
326
|
+
"USDC_TOKEN_ADDRESS",
|
|
327
|
+
"TOROS_TOKEN_ADDRESS",
|
|
328
|
+
"100000000",
|
|
329
|
+
slippage
|
|
330
|
+
)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
#### Toros redeem flow
|
|
334
|
+
|
|
335
|
+
Redeeming a Toros token has more prerequisites than a normal trade:
|
|
336
|
+
|
|
337
|
+
- newly minted Toros or dHEDGE vault tokens may be subject to a cooldown before redemption can be initiated
|
|
338
|
+
- while that cooldown is active, redemption cannot be initiated
|
|
339
|
+
- before initiating redemption, the vault must approve the Toros token for the Toros router
|
|
340
|
+
- after redemption is initiated, some Toros withdrawals require a second completion step
|
|
341
|
+
- `completeTorosWithdrawal(...)` can require `ODOS_API_KEY` when Odos-backed swap data is needed
|
|
342
|
+
|
|
343
|
+
1. Approve the Toros token for redemption:
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
await vault.approve(
|
|
347
|
+
Dapp.TOROS,
|
|
348
|
+
"TOROS_TOKEN_ADDRESS",
|
|
349
|
+
ethers.constants.MaxUint256
|
|
350
|
+
)
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
2. Initiate the redemption:
|
|
354
|
+
|
|
355
|
+
```ts
|
|
356
|
+
const tx = await vault.trade(
|
|
224
357
|
Dapp.TOROS,
|
|
225
358
|
"TOROS_TOKEN_ADDRESS",
|
|
226
359
|
"USDC_TOKEN_ADDRESS",
|
|
227
|
-
|
|
360
|
+
"100000000",
|
|
228
361
|
slippage
|
|
229
362
|
)
|
|
230
363
|
```
|
|
231
|
-
|
|
364
|
+
|
|
365
|
+
3. Complete the withdrawal when required by the product flow:
|
|
366
|
+
|
|
232
367
|
```ts
|
|
233
|
-
const tx = await
|
|
368
|
+
const tx = await vault.completeTorosWithdrawal(
|
|
234
369
|
"USDC_TOKEN_ADDRESS",
|
|
235
370
|
slippage
|
|
236
371
|
)
|
package/dist/config.d.ts
CHANGED
|
@@ -20,3 +20,13 @@ export declare const flatMoneyContractAddresses: Readonly<Partial<Record<Network
|
|
|
20
20
|
StableModule: string;
|
|
21
21
|
COLLATERAL: string;
|
|
22
22
|
}>>>;
|
|
23
|
+
export declare const limitOrderAddress: AddressNetworkMap;
|
|
24
|
+
export declare const OdosSwapFeeRecipient: {
|
|
25
|
+
polygon: string;
|
|
26
|
+
optimism: string;
|
|
27
|
+
arbitrum: string;
|
|
28
|
+
base: string;
|
|
29
|
+
ethereum: string;
|
|
30
|
+
plasma: string;
|
|
31
|
+
hyperliquid: string;
|
|
32
|
+
};
|
package/dist/entities/pool.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Contract, ethers, Wallet, BigNumber, BigNumberish } from "ethers";
|
|
2
|
-
import { Dapp, FundComposition, AssetEnabled, Network, LyraOptionMarket, LyraOptionType, LyraTradeType, LyraPosition, SDKOptions } from "../types";
|
|
2
|
+
import { Dapp, FundComposition, AssetEnabled, Network, LyraOptionMarket, LyraOptionType, LyraTradeType, LyraPosition, SDKOptions, LimitOrderInfo } from "../types";
|
|
3
3
|
import { Utils } from "./utils";
|
|
4
4
|
export declare class Pool {
|
|
5
5
|
readonly poolLogic: Contract;
|
|
@@ -574,4 +574,113 @@ export declare class Pool {
|
|
|
574
574
|
* @returns {Promise<any>} Transaction
|
|
575
575
|
*/
|
|
576
576
|
mintPendle(assetFrom: string, pt: string, amountIn: BigNumber | string, slippage?: number, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
577
|
+
/** Deposit USDC from EVM to a HyperCore trading dex via the CoreDepositWallet.
|
|
578
|
+
* This bridges USDC on-chain to Hyperliquid for perp/spot trading.
|
|
579
|
+
*
|
|
580
|
+
* @param {BigNumber | string} amount USDC amount to deposit (6 decimals, e.g. "1000000" = 1 USDC)
|
|
581
|
+
* @param {number} dexId Destination dex ID where USDC will be available (default 0)
|
|
582
|
+
* - 0: Core Perp dex (standard perps like BTC, ETH)
|
|
583
|
+
* - 1: xyz HIP-3 dex (builder perps like TSLA, GOLD)
|
|
584
|
+
* @param {any} options Transaction options
|
|
585
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
586
|
+
* @returns {Promise<any>} Transaction
|
|
587
|
+
*/
|
|
588
|
+
depositHyperliquid(amount: BigNumber | string, dexId?: number, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
589
|
+
/** Move USDC from a HyperCore trading dex to the Spot wallet.
|
|
590
|
+
* Required before calling withdrawHyperliquid() to bridge USDC back to EVM.
|
|
591
|
+
*
|
|
592
|
+
* @param {number} dexId Source dex ID where USDC currently sits
|
|
593
|
+
* - 0: Core Perp dex (standard perps like BTC, ETH)
|
|
594
|
+
* - 1: xyz HIP-3 dex (builder perps like TSLA, GOLD)
|
|
595
|
+
* @param {BigNumber | string} amount USDC amount to transfer (6 decimals, e.g. "1000000" = 1 USDC)
|
|
596
|
+
* @param {any} options Transaction options
|
|
597
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
598
|
+
* @returns {Promise<any>} Transaction
|
|
599
|
+
*/
|
|
600
|
+
perpToSpotHyperliquid(dexId: number, amount: BigNumber | string, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
601
|
+
/** Withdraw USDC from Hyperliquid Spot wallet back to EVM.
|
|
602
|
+
* USDC must be in the Spot wallet first — use perpToSpotHyperliquid() to move it from a trading dex.
|
|
603
|
+
*
|
|
604
|
+
* @param {BigNumber | string} amount USDC amount to withdraw (6 decimals, e.g. "1000000" = 1 USDC)
|
|
605
|
+
* @param {any} options Transaction options
|
|
606
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
607
|
+
* @returns {Promise<any>} Transaction
|
|
608
|
+
*/
|
|
609
|
+
withdrawHyperliquid(amount: BigNumber | string, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
610
|
+
/** Open a market order on Hyperliquid
|
|
611
|
+
* @param {number} assetId Asset id
|
|
612
|
+
* @param {boolean} isLong Long or short (Note: Spot assets only support long positions)
|
|
613
|
+
* @param {number} value Order value in base asset units (positive for opening/increasing,
|
|
614
|
+
* negative for closing/reducing or selling spot)
|
|
615
|
+
* @param {number } slippage Slippage tolerance in %
|
|
616
|
+
* @param {any} options Transaction options
|
|
617
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
618
|
+
* @returns {Promise<any>} Transaction
|
|
619
|
+
*/
|
|
620
|
+
openMarketOrderHyperliquid(assetId: number, isLong: boolean, value: number, slippage?: number, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
621
|
+
/** Close a position on Hyperliquid
|
|
622
|
+
* @param {number} assetId Asset id
|
|
623
|
+
* @param {number} percentageToClose Percentage of position to close (0-100)
|
|
624
|
+
* @param {number } slippage Slippage tolerance in %
|
|
625
|
+
* @param {any} options Transaction options
|
|
626
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
627
|
+
* @returns {Promise<any>} Transaction
|
|
628
|
+
*/
|
|
629
|
+
closePositionHyperliquid(assetId: number, percentageToClose?: number, slippage?: number, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
630
|
+
/**
|
|
631
|
+
* Approve the Toros vault token for the PoolLimitOrderManager
|
|
632
|
+
* Must be called before createTorosLimitOrder
|
|
633
|
+
* @param {string} vaultAddress Address of the Toros vault token to approve
|
|
634
|
+
* @param {BigNumber | string} amount Amount to approve
|
|
635
|
+
* @param {any} options Transaction options
|
|
636
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
637
|
+
* @returns {Promise<any>} Transaction
|
|
638
|
+
*/
|
|
639
|
+
approveTorosLimitOrder(vaultAddress: string, amount: BigNumber | string, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
640
|
+
/**
|
|
641
|
+
* Create a Toros limit order (stop-loss / take-profit)
|
|
642
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
643
|
+
* @param {BigNumber | string} amount Vault token amount (18 decimals)
|
|
644
|
+
* @param {BigNumber | string | null | undefined} stopLossPriceD18 Stop-loss price in D18 (0 or null/undefined = disabled)
|
|
645
|
+
* @param {BigNumber | string | null | undefined} takeProfitPriceD18 Take-profit price in D18 (MaxUint256 or null/undefined = disabled)
|
|
646
|
+
* @param {string} pricingAsset Address of the pricing asset (e.g. USDC)
|
|
647
|
+
* @param {any} options Transaction options
|
|
648
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
649
|
+
* @returns {Promise<any>} Transaction
|
|
650
|
+
*/
|
|
651
|
+
createTorosLimitOrder(vaultAddress: string, amount: BigNumber | string, stopLossPriceD18: BigNumber | string | null | undefined, takeProfitPriceD18: BigNumber | string | null | undefined, pricingAsset: string, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
652
|
+
/**
|
|
653
|
+
* Modify an existing Toros limit order
|
|
654
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
655
|
+
* @param {BigNumber | string} amount New vault token amount (18 decimals)
|
|
656
|
+
* @param {BigNumber | string | null | undefined} stopLossPriceD18 New stop-loss price in D18 (0 or null/undefined = disabled)
|
|
657
|
+
* @param {BigNumber | string | null | undefined} takeProfitPriceD18 New take-profit price in D18 (MaxUint256 or null/undefined = disabled)
|
|
658
|
+
* @param {string} pricingAsset Address of the pricing asset
|
|
659
|
+
* @param {any} options Transaction options
|
|
660
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
661
|
+
* @returns {Promise<any>} Transaction
|
|
662
|
+
*/
|
|
663
|
+
modifyTorosLimitOrder(vaultAddress: string, amount: BigNumber | string, stopLossPriceD18: BigNumber | string | null | undefined, takeProfitPriceD18: BigNumber | string | null | undefined, pricingAsset: string, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
664
|
+
/**
|
|
665
|
+
* Delete an existing Toros limit order
|
|
666
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
667
|
+
* @param {any} options Transaction options
|
|
668
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
669
|
+
* @returns {Promise<any>} Transaction
|
|
670
|
+
*/
|
|
671
|
+
deleteTorosLimitOrder(vaultAddress: string, options?: any, sdkOptions?: SDKOptions): Promise<any>;
|
|
672
|
+
/**
|
|
673
|
+
* Fetch a Toros limit order for a given user and vault
|
|
674
|
+
* @param {string} userAddress Address of the order owner (the dHEDGE pool)
|
|
675
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
676
|
+
* @returns {Promise<LimitOrderInfo | null>} Order info, or null if none exists
|
|
677
|
+
*/
|
|
678
|
+
getTorosLimitOrder(userAddress: string, vaultAddress: string): Promise<LimitOrderInfo | null>;
|
|
679
|
+
/**
|
|
680
|
+
* Check whether an active Toros limit order exists for a given user and vault
|
|
681
|
+
* @param {string} userAddress Address of the order owner (the dHEDGE pool)
|
|
682
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
683
|
+
* @returns {Promise<boolean>}
|
|
684
|
+
*/
|
|
685
|
+
hasActiveTorosLimitOrder(userAddress: string, vaultAddress: string): Promise<boolean>;
|
|
577
686
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const USDC_TOKEN_ID = 0;
|
|
2
|
+
export declare const USDC_CORE_ADDRESS = "0x2000000000000000000000000000000000000000";
|
|
3
|
+
export declare const CORE_WRITER_ADDRESS = "0x3333333333333333333333333333333333333333";
|
|
4
|
+
export declare const PERP_DEX_ID = 0;
|
|
5
|
+
export declare const SPOT_DEX_ID = 4294967295;
|
|
6
|
+
export declare const HYPERLIQUID_VERSION = 1;
|
|
7
|
+
export declare const SPOT_SEND_ACTION = 6;
|
|
8
|
+
export declare const SEND_ASSET_ACTION = 13;
|
|
9
|
+
export declare const LIMIT_ORDER_ACTION = 1;
|
|
10
|
+
export declare const LIMIT_ORDER_TIF_ALO = 1;
|
|
11
|
+
export declare const LIMIT_ORDER_TIF_GTC = 2;
|
|
12
|
+
export declare const LIMIT_ORDER_TIF_IOC = 3;
|
|
13
|
+
export declare const dexIdNameMap: {
|
|
14
|
+
[key: number]: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const API_URL = "https://api.hyperliquid.xyz/info";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
export declare const getDepositHyperliquidTxData: (dexId: number, amount: ethers.BigNumber | string) => string;
|
|
3
|
+
export declare const getWithdrawSpotHyperliquidTxData: (amount: ethers.BigNumber | string) => string;
|
|
4
|
+
export declare const getPerpToSpotHyperliquidTxData: (dexId: number, receiver: string, amount: ethers.BigNumber | string) => string;
|
|
5
|
+
export declare const getLimitOrderHyperliquidTxData: (assetId: number, isLong: boolean, changeAmount: number, slippage: number) => Promise<string>;
|
|
6
|
+
export declare const getClosePositionHyperliquidTxData: (assetId: number, percentageToClose: number, slippage: number, poolAddress: string) => Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const perpDexIndex: (assetId: number) => number;
|
|
2
|
+
export declare const spotAssetIndex: (assetId: number) => number;
|
|
3
|
+
export declare const isSpotAsset: (assetId: number) => boolean;
|
|
4
|
+
export declare const getMidPrice: (assetId: number, assetName: string) => Promise<number>;
|
|
5
|
+
export declare const getAssetInfo: (assetId: number) => Promise<{
|
|
6
|
+
assetName: string;
|
|
7
|
+
szDecimals: number;
|
|
8
|
+
baseTokenName?: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const calculatePrice: (isSpotAsset: boolean, szDecimals: number, midPrice: number, isBuy: boolean, slippage: number) => string;
|
|
11
|
+
export declare const calculateSize: (szDecimals: number, value: number, price: number) => string;
|
|
12
|
+
export declare const scaleSize: (szDecimals: number, positionSize: number, percentageToClose: number) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPositionSize: (assetId: number, isSpot: boolean, assetName: string, user: string) => Promise<number>;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { ethers } from "../..";
|
|
2
2
|
import { Pool } from "../../entities";
|
|
3
|
-
export declare const odosBaseUrl = "https://api.odos.xyz/sor";
|
|
3
|
+
export declare const odosBaseUrl = "https://enterprise-api.odos.xyz/sor";
|
|
4
|
+
export interface SwapTokenInfo {
|
|
5
|
+
inputToken: string;
|
|
6
|
+
inputAmount: ethers.BigNumber;
|
|
7
|
+
inputReceiver: string;
|
|
8
|
+
outputToken: string;
|
|
9
|
+
outputQuote: ethers.BigNumber;
|
|
10
|
+
outputMin: ethers.BigNumber;
|
|
11
|
+
outputReceiver: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SwapReferralInfo {
|
|
14
|
+
code: ethers.BigNumber;
|
|
15
|
+
fee: ethers.BigNumber;
|
|
16
|
+
feeRecipient: string;
|
|
17
|
+
}
|
|
4
18
|
export declare function getOdosSwapTxData(pool: Pool, assetFrom: string, assetTo: string, amountIn: ethers.BigNumber | string, slippage: number): Promise<{
|
|
5
19
|
swapTxData: string;
|
|
6
20
|
minAmountOut: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Pool } from "../..";
|
|
2
|
+
import { LimitOrderInfo } from "../../types";
|
|
3
|
+
export declare function getLimitOrderId(userAddress: string, vaultAddress: string): string;
|
|
4
|
+
export declare function getCreateLimitOrderTxData(info: LimitOrderInfo): string;
|
|
5
|
+
export declare function getModifyLimitOrderTxData(info: LimitOrderInfo): string;
|
|
6
|
+
export declare function getDeleteLimitOrderTxData(vaultAddress: string): string;
|
|
7
|
+
export declare function getTorosLimitOrder(pool: Pool, userAddress: string, vaultAddress: string): Promise<LimitOrderInfo | null>;
|
|
8
|
+
export declare function hasActiveTorosLimitOrder(pool: Pool, userAddress: string, vaultAddress: string): Promise<boolean>;
|
package/dist/test/constants.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare const TEST_POOL: {
|
|
|
20
20
|
base: string;
|
|
21
21
|
ethereum: string;
|
|
22
22
|
plasma: string;
|
|
23
|
+
hyperliquid: string;
|
|
23
24
|
};
|
|
24
25
|
export declare const CONTRACT_ADDRESS: {
|
|
25
26
|
polygon: {
|
|
@@ -137,6 +138,10 @@ export declare const CONTRACT_ADDRESS: {
|
|
|
137
138
|
USDT: string;
|
|
138
139
|
USDE: string;
|
|
139
140
|
};
|
|
141
|
+
hyperliquid: {
|
|
142
|
+
USDC: string;
|
|
143
|
+
WETH: string;
|
|
144
|
+
};
|
|
140
145
|
};
|
|
141
146
|
export declare const MAX_AMOUNT: ethers.BigNumber;
|
|
142
147
|
export declare const USDC_BALANCEOF_SLOT: {
|
|
@@ -146,6 +151,7 @@ export declare const USDC_BALANCEOF_SLOT: {
|
|
|
146
151
|
base: number;
|
|
147
152
|
ethereum: number;
|
|
148
153
|
plasma: number;
|
|
154
|
+
hyperliquid: number;
|
|
149
155
|
};
|
|
150
156
|
export declare const WETH_BALANCEOF_SLOT: {
|
|
151
157
|
optimism: number;
|
|
@@ -154,4 +160,5 @@ export declare const WETH_BALANCEOF_SLOT: {
|
|
|
154
160
|
base: number;
|
|
155
161
|
ethereum: number;
|
|
156
162
|
plasma: number;
|
|
163
|
+
hyperliquid: number;
|
|
157
164
|
};
|
package/dist/test/wallet.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export declare enum Network {
|
|
|
6
6
|
ARBITRUM = "arbitrum",
|
|
7
7
|
BASE = "base",
|
|
8
8
|
ETHEREUM = "ethereum",
|
|
9
|
-
PLASMA = "plasma"
|
|
9
|
+
PLASMA = "plasma",
|
|
10
|
+
HYPERLIQUID = "hyperliquid"
|
|
10
11
|
}
|
|
11
12
|
export declare enum Dapp {
|
|
12
13
|
SUSHISWAP = "sushiswap",
|
|
@@ -31,7 +32,8 @@ export declare enum Dapp {
|
|
|
31
32
|
COMPOUNDV3 = "compoundV3",
|
|
32
33
|
ODOS = "odos",
|
|
33
34
|
PENDLE = "pendle",
|
|
34
|
-
KYBERSWAP = "kyberswap"
|
|
35
|
+
KYBERSWAP = "kyberswap",
|
|
36
|
+
HYPERLIQUID = "hyperliquid"
|
|
35
37
|
}
|
|
36
38
|
export declare enum Transaction {
|
|
37
39
|
SWAP = "swapExactTokensForTokens",
|
|
@@ -97,3 +99,11 @@ export declare type SDKOptions = {
|
|
|
97
99
|
onlyGetTxData?: boolean;
|
|
98
100
|
useTraderAddressAsFrom?: boolean;
|
|
99
101
|
} | boolean;
|
|
102
|
+
export declare type LimitOrderInfo = {
|
|
103
|
+
amount: BigNumber;
|
|
104
|
+
stopLossPriceD18: BigNumber;
|
|
105
|
+
takeProfitPriceD18: BigNumber;
|
|
106
|
+
user: string;
|
|
107
|
+
pool: string;
|
|
108
|
+
pricingAsset: string;
|
|
109
|
+
};
|