@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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"components": [
|
|
6
|
+
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
|
7
|
+
{ "internalType": "uint256", "name": "stopLossPriceD18", "type": "uint256" },
|
|
8
|
+
{ "internalType": "uint256", "name": "takeProfitPriceD18", "type": "uint256" },
|
|
9
|
+
{ "internalType": "address", "name": "user", "type": "address" },
|
|
10
|
+
{ "internalType": "address", "name": "pool", "type": "address" },
|
|
11
|
+
{ "internalType": "address", "name": "pricingAsset", "type": "address" }
|
|
12
|
+
],
|
|
13
|
+
"internalType": "struct IPoolLimitOrderManager.LimitOrderInfo",
|
|
14
|
+
"name": "limitOrderInfo",
|
|
15
|
+
"type": "tuple"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"name": "createLimitOrder",
|
|
19
|
+
"outputs": [],
|
|
20
|
+
"stateMutability": "nonpayable",
|
|
21
|
+
"type": "function"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"inputs": [
|
|
25
|
+
{
|
|
26
|
+
"components": [
|
|
27
|
+
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
|
28
|
+
{ "internalType": "uint256", "name": "stopLossPriceD18", "type": "uint256" },
|
|
29
|
+
{ "internalType": "uint256", "name": "takeProfitPriceD18", "type": "uint256" },
|
|
30
|
+
{ "internalType": "address", "name": "user", "type": "address" },
|
|
31
|
+
{ "internalType": "address", "name": "pool", "type": "address" },
|
|
32
|
+
{ "internalType": "address", "name": "pricingAsset", "type": "address" }
|
|
33
|
+
],
|
|
34
|
+
"internalType": "struct IPoolLimitOrderManager.LimitOrderInfo",
|
|
35
|
+
"name": "limitOrderInfo",
|
|
36
|
+
"type": "tuple"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"name": "modifyLimitOrder",
|
|
40
|
+
"outputs": [],
|
|
41
|
+
"stateMutability": "nonpayable",
|
|
42
|
+
"type": "function"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"inputs": [
|
|
46
|
+
{ "internalType": "address", "name": "pool_", "type": "address" }
|
|
47
|
+
],
|
|
48
|
+
"name": "deleteLimitOrder",
|
|
49
|
+
"outputs": [],
|
|
50
|
+
"stateMutability": "nonpayable",
|
|
51
|
+
"type": "function"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"inputs": [],
|
|
55
|
+
"name": "getAllLimitOrderIds",
|
|
56
|
+
"outputs": [
|
|
57
|
+
{ "internalType": "bytes32[]", "name": "", "type": "bytes32[]" }
|
|
58
|
+
],
|
|
59
|
+
"stateMutability": "view",
|
|
60
|
+
"type": "function"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"inputs": [
|
|
64
|
+
{ "internalType": "bytes32", "name": "orderId", "type": "bytes32" }
|
|
65
|
+
],
|
|
66
|
+
"name": "limitOrders",
|
|
67
|
+
"outputs": [
|
|
68
|
+
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
|
69
|
+
{ "internalType": "uint256", "name": "stopLossPriceD18", "type": "uint256" },
|
|
70
|
+
{ "internalType": "uint256", "name": "takeProfitPriceD18", "type": "uint256" },
|
|
71
|
+
{ "internalType": "address", "name": "user", "type": "address" },
|
|
72
|
+
{ "internalType": "address", "name": "pool", "type": "address" },
|
|
73
|
+
{ "internalType": "address", "name": "pricingAsset", "type": "address" }
|
|
74
|
+
],
|
|
75
|
+
"stateMutability": "view",
|
|
76
|
+
"type": "function"
|
|
77
|
+
}
|
|
78
|
+
]
|
package/src/config.ts
CHANGED
|
@@ -19,7 +19,8 @@ export const factoryAddress: AddressNetworkMap = {
|
|
|
19
19
|
[Network.ARBITRUM]: "0xfffb5fb14606eb3a548c113026355020ddf27535",
|
|
20
20
|
[Network.BASE]: "0x49Afe3abCf66CF09Fab86cb1139D8811C8afe56F",
|
|
21
21
|
[Network.ETHEREUM]: "0x96D33bCF84DdE326014248E2896F79bbb9c13D6d",
|
|
22
|
-
[Network.PLASMA]: "0xAec4975Fc8ad911464D2948D771488b30F6eEE87"
|
|
22
|
+
[Network.PLASMA]: "0xAec4975Fc8ad911464D2948D771488b30F6eEE87",
|
|
23
|
+
[Network.HYPERLIQUID]: "0xe91505e2ab653dd128c71e9690eeefd28cc5b333"
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
export const routerAddress: AddressDappNetworkMap = {
|
|
@@ -33,7 +34,7 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
33
34
|
[Dapp.UNISWAPV3]: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
34
35
|
[Dapp.ARRAKIS]: "0xc73fb100a995b33f9fa181d420f4c8d74506df66",
|
|
35
36
|
[Dapp.TOROS]: "0x45b90480D6F643dE2f128db091A357C3c90399f2",
|
|
36
|
-
[Dapp.ODOS]: "
|
|
37
|
+
[Dapp.ODOS]: "0x0D05a7D3448512B78fa8A9e46c4872C88C4a0D05",
|
|
37
38
|
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
|
|
38
39
|
},
|
|
39
40
|
[Network.OPTIMISM]: {
|
|
@@ -46,7 +47,7 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
46
47
|
[Dapp.VELODROMEV2]: "0xa062ae8a9c5e11aaa026fc2670b0d65ccc8b2858",
|
|
47
48
|
[Dapp.LYRA]: "0xCCE7819d65f348c64B7Beb205BA367b3fE33763B",
|
|
48
49
|
[Dapp.ARRAKIS]: "0x9ce88a56d120300061593eF7AD074A1B710094d5",
|
|
49
|
-
[Dapp.ODOS]: "
|
|
50
|
+
[Dapp.ODOS]: "0x0D05a7D3448512B78fa8A9e46c4872C88C4a0D05",
|
|
50
51
|
[Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
51
52
|
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
|
|
52
53
|
},
|
|
@@ -57,7 +58,7 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
57
58
|
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
58
59
|
[Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e",
|
|
59
60
|
[Dapp.TOROS]: "0xA5679C4272A056Bb83f039961fae7D99C48529F5",
|
|
60
|
-
[Dapp.ODOS]: "
|
|
61
|
+
[Dapp.ODOS]: "0x0D05a7D3448512B78fa8A9e46c4872C88C4a0D05",
|
|
61
62
|
[Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
62
63
|
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
|
|
63
64
|
},
|
|
@@ -66,13 +67,13 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
66
67
|
[Dapp.AERODROME]: "0xcF77a3Ba9A5CA399B7c97c74d54e5b1Beb874E43",
|
|
67
68
|
[Dapp.AAVEV3]: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5",
|
|
68
69
|
[Dapp.TOROS]: "0xf067575Eb60c7587C11e867907AA7284833704d1",
|
|
69
|
-
[Dapp.ODOS]: "
|
|
70
|
+
[Dapp.ODOS]: "0x0D05a7D3448512B78fa8A9e46c4872C88C4a0D05",
|
|
70
71
|
[Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
71
72
|
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
|
|
72
73
|
},
|
|
73
74
|
[Network.ETHEREUM]: {
|
|
74
75
|
[Dapp.AAVEV3]: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
|
|
75
|
-
[Dapp.ODOS]: "
|
|
76
|
+
[Dapp.ODOS]: "0x0D05a7D3448512B78fa8A9e46c4872C88C4a0D05",
|
|
76
77
|
[Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
77
78
|
[Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65",
|
|
78
79
|
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
|
|
@@ -81,6 +82,9 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
81
82
|
[Dapp.AAVEV3]: "0x925a2A7214Ed92428B5b1B090F80b25700095e12",
|
|
82
83
|
[Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
83
84
|
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
|
|
85
|
+
},
|
|
86
|
+
[Network.HYPERLIQUID]: {
|
|
87
|
+
[Dapp.HYPERLIQUID]: "0x6b9e773128f453f5c2c60935ee2de2cbc5390a24"
|
|
84
88
|
}
|
|
85
89
|
};
|
|
86
90
|
|
|
@@ -93,7 +97,8 @@ export const dappFactoryAddress: AddressDappNetworkMap = {
|
|
|
93
97
|
[Network.ARBITRUM]: {},
|
|
94
98
|
[Network.BASE]: {},
|
|
95
99
|
[Network.ETHEREUM]: {},
|
|
96
|
-
[Network.PLASMA]: {}
|
|
100
|
+
[Network.PLASMA]: {},
|
|
101
|
+
[Network.HYPERLIQUID]: {}
|
|
97
102
|
};
|
|
98
103
|
|
|
99
104
|
export const stakingAddress: AddressDappNetworkMap = {
|
|
@@ -115,7 +120,8 @@ export const stakingAddress: AddressDappNetworkMap = {
|
|
|
115
120
|
[Dapp.PANCAKECL]: "0xC6A2Db661D5a5690172d8eB0a7DEA2d3008665A3"
|
|
116
121
|
},
|
|
117
122
|
[Network.ETHEREUM]: {},
|
|
118
|
-
[Network.PLASMA]: {}
|
|
123
|
+
[Network.PLASMA]: {},
|
|
124
|
+
[Network.HYPERLIQUID]: {}
|
|
119
125
|
};
|
|
120
126
|
|
|
121
127
|
export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
@@ -138,7 +144,8 @@ export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
|
138
144
|
},
|
|
139
145
|
[Network.PLASMA]: {
|
|
140
146
|
[Dapp.AAVEV3]: "0x061D8e131F26512348ee5FA42e2DF1bA9d6505E9"
|
|
141
|
-
}
|
|
147
|
+
},
|
|
148
|
+
[Network.HYPERLIQUID]: {}
|
|
142
149
|
};
|
|
143
150
|
export const nonfungiblePositionManagerAddress: AddressDappNetworkMap = {
|
|
144
151
|
[Network.POLYGON]: {
|
|
@@ -159,7 +166,8 @@ export const nonfungiblePositionManagerAddress: AddressDappNetworkMap = {
|
|
|
159
166
|
[Dapp.PANCAKECL]: "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364"
|
|
160
167
|
},
|
|
161
168
|
[Network.ETHEREUM]: {},
|
|
162
|
-
[Network.PLASMA]: {}
|
|
169
|
+
[Network.PLASMA]: {},
|
|
170
|
+
[Network.HYPERLIQUID]: {}
|
|
163
171
|
};
|
|
164
172
|
|
|
165
173
|
export const networkChainIdMap: NetworkChainIdMap = {
|
|
@@ -168,7 +176,8 @@ export const networkChainIdMap: NetworkChainIdMap = {
|
|
|
168
176
|
[Network.ARBITRUM]: 42161,
|
|
169
177
|
[Network.BASE]: 8453,
|
|
170
178
|
[Network.ETHEREUM]: 1,
|
|
171
|
-
[Network.PLASMA]: 9745
|
|
179
|
+
[Network.PLASMA]: 9745,
|
|
180
|
+
[Network.HYPERLIQUID]: 999
|
|
172
181
|
};
|
|
173
182
|
|
|
174
183
|
export const balancerSubgraph: AddressNetworkMap = {
|
|
@@ -178,7 +187,8 @@ export const balancerSubgraph: AddressNetworkMap = {
|
|
|
178
187
|
[Network.ARBITRUM]: "",
|
|
179
188
|
[Network.BASE]: "",
|
|
180
189
|
[Network.ETHEREUM]: "",
|
|
181
|
-
[Network.PLASMA]: ""
|
|
190
|
+
[Network.PLASMA]: "",
|
|
191
|
+
[Network.HYPERLIQUID]: ""
|
|
182
192
|
};
|
|
183
193
|
|
|
184
194
|
export const multiCallAddress: AddressNetworkMap = {
|
|
@@ -187,7 +197,8 @@ export const multiCallAddress: AddressNetworkMap = {
|
|
|
187
197
|
[Network.ARBITRUM]: "",
|
|
188
198
|
[Network.BASE]: "",
|
|
189
199
|
[Network.ETHEREUM]: "",
|
|
190
|
-
[Network.PLASMA]: ""
|
|
200
|
+
[Network.PLASMA]: "",
|
|
201
|
+
[Network.HYPERLIQUID]: ""
|
|
191
202
|
};
|
|
192
203
|
|
|
193
204
|
export const lyraNetworkMap: LyraNetworkMap = {
|
|
@@ -234,3 +245,23 @@ export const flatMoneyContractAddresses: Readonly<Partial<
|
|
|
234
245
|
StableModule: "0xcD3657cB0E851b6a734c4D1e7FC2640Bcd9f6B2d"
|
|
235
246
|
}
|
|
236
247
|
};
|
|
248
|
+
|
|
249
|
+
export const limitOrderAddress: AddressNetworkMap = {
|
|
250
|
+
[Network.POLYGON]: "0xB71410736d2C8F2DAf30dA9D332dA10534d2624d",
|
|
251
|
+
[Network.OPTIMISM]: "0x3bFE2a472d2964Ea4070725b7Fb0A868b3f08b63",
|
|
252
|
+
[Network.ARBITRUM]: "0x26a687e8244f1866E9Aa2D400c8b9957Aa8e6Ad4",
|
|
253
|
+
[Network.BASE]: "0xFcBEc28c43E356693971a24bf3F2Fd7D965E2ebA",
|
|
254
|
+
[Network.ETHEREUM]: "0x95B19De479bc693721cab39Da98FfECE062f5Ea4",
|
|
255
|
+
[Network.PLASMA]: "",
|
|
256
|
+
[Network.HYPERLIQUID]: ""
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
export const OdosSwapFeeRecipient = {
|
|
260
|
+
[Network.POLYGON]: "0x090e7fbD87A673eE3D0B6ccACf0e1d94fB90DA59",
|
|
261
|
+
[Network.OPTIMISM]: "0x813123A13d01d3F07d434673Fdc89cBBA523f14d",
|
|
262
|
+
[Network.ARBITRUM]: "0xfbD2B4216f422DC1eEe1Cff4Fb64B726F099dEF5",
|
|
263
|
+
[Network.BASE]: "0x5619AD05b0253a7e647Bd2E4C01c7f40CEaB0879",
|
|
264
|
+
[Network.ETHEREUM]: "0xfbD2B4216f422DC1eEe1Cff4Fb64B726F099dEF5",
|
|
265
|
+
[Network.PLASMA]: "",
|
|
266
|
+
[Network.HYPERLIQUID]: ""
|
|
267
|
+
};
|
package/src/entities/pool.ts
CHANGED
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
nonfungiblePositionManagerAddress,
|
|
20
20
|
routerAddress,
|
|
21
21
|
stakingAddress,
|
|
22
|
-
SYNTHETIX_TRACKING_CODE
|
|
22
|
+
SYNTHETIX_TRACKING_CODE,
|
|
23
|
+
limitOrderAddress
|
|
23
24
|
} from "../config";
|
|
24
25
|
import {
|
|
25
26
|
Dapp,
|
|
@@ -31,7 +32,8 @@ import {
|
|
|
31
32
|
LyraOptionType,
|
|
32
33
|
LyraTradeType,
|
|
33
34
|
LyraPosition,
|
|
34
|
-
SDKOptions
|
|
35
|
+
SDKOptions,
|
|
36
|
+
LimitOrderInfo
|
|
35
37
|
} from "../types";
|
|
36
38
|
|
|
37
39
|
import { Utils } from "./utils";
|
|
@@ -57,8 +59,8 @@ import { getLyraOptionTxData } from "../services/lyra/trade";
|
|
|
57
59
|
import { getOptionPositions } from "../services/lyra/positions";
|
|
58
60
|
import { getDeadline } from "../utils/deadline";
|
|
59
61
|
import {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
getFuturesChangeMarginTxData,
|
|
63
|
+
getFuturesChangePositionTxData
|
|
62
64
|
} from "../services/futures";
|
|
63
65
|
import { getFuturesCancelOrderTxData } from "../services/futures/trade";
|
|
64
66
|
import { getOneInchSwapTxData } from "../services/oneInch";
|
|
@@ -86,7 +88,22 @@ import {
|
|
|
86
88
|
import { getOdosSwapTxData } from "../services/odos";
|
|
87
89
|
import { getPendleMintTxData, getPendleSwapTxData } from "../services/pendle";
|
|
88
90
|
import { getCompleteWithdrawalTxData } from "../services/toros/completeWithdrawal";
|
|
91
|
+
import {
|
|
92
|
+
getCreateLimitOrderTxData,
|
|
93
|
+
getModifyLimitOrderTxData,
|
|
94
|
+
getDeleteLimitOrderTxData,
|
|
95
|
+
getTorosLimitOrder,
|
|
96
|
+
hasActiveTorosLimitOrder
|
|
97
|
+
} from "../services/toros/limitOrder";
|
|
89
98
|
import { getKyberSwapTxData } from "../services/kyberSwap";
|
|
99
|
+
import {
|
|
100
|
+
getClosePositionHyperliquidTxData,
|
|
101
|
+
getDepositHyperliquidTxData,
|
|
102
|
+
getLimitOrderHyperliquidTxData,
|
|
103
|
+
getPerpToSpotHyperliquidTxData,
|
|
104
|
+
getWithdrawSpotHyperliquidTxData
|
|
105
|
+
} from "../services/hyperliquid";
|
|
106
|
+
import { CORE_WRITER_ADDRESS } from "../services/hyperliquid/constants";
|
|
90
107
|
|
|
91
108
|
export class Pool {
|
|
92
109
|
public readonly poolLogic: Contract;
|
|
@@ -2147,4 +2164,331 @@ export class Pool {
|
|
|
2147
2164
|
);
|
|
2148
2165
|
return tx;
|
|
2149
2166
|
}
|
|
2167
|
+
|
|
2168
|
+
/** Deposit USDC from EVM to a HyperCore trading dex via the CoreDepositWallet.
|
|
2169
|
+
* This bridges USDC on-chain to Hyperliquid for perp/spot trading.
|
|
2170
|
+
*
|
|
2171
|
+
* @param {BigNumber | string} amount USDC amount to deposit (6 decimals, e.g. "1000000" = 1 USDC)
|
|
2172
|
+
* @param {number} dexId Destination dex ID where USDC will be available (default 0)
|
|
2173
|
+
* - 0: Core Perp dex (standard perps like BTC, ETH)
|
|
2174
|
+
* - 1: xyz HIP-3 dex (builder perps like TSLA, GOLD)
|
|
2175
|
+
* @param {any} options Transaction options
|
|
2176
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2177
|
+
* @returns {Promise<any>} Transaction
|
|
2178
|
+
*/
|
|
2179
|
+
async depositHyperliquid(
|
|
2180
|
+
amount: BigNumber | string,
|
|
2181
|
+
dexId = 0,
|
|
2182
|
+
options: any = null,
|
|
2183
|
+
sdkOptions: SDKOptions = {
|
|
2184
|
+
estimateGas: false
|
|
2185
|
+
}
|
|
2186
|
+
): Promise<any> {
|
|
2187
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
2188
|
+
this,
|
|
2189
|
+
[
|
|
2190
|
+
routerAddress[this.network][Dapp.HYPERLIQUID],
|
|
2191
|
+
getDepositHyperliquidTxData(dexId, amount),
|
|
2192
|
+
options
|
|
2193
|
+
],
|
|
2194
|
+
sdkOptions
|
|
2195
|
+
);
|
|
2196
|
+
return tx;
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
/** Move USDC from a HyperCore trading dex to the Spot wallet.
|
|
2200
|
+
* Required before calling withdrawHyperliquid() to bridge USDC back to EVM.
|
|
2201
|
+
*
|
|
2202
|
+
* @param {number} dexId Source dex ID where USDC currently sits
|
|
2203
|
+
* - 0: Core Perp dex (standard perps like BTC, ETH)
|
|
2204
|
+
* - 1: xyz HIP-3 dex (builder perps like TSLA, GOLD)
|
|
2205
|
+
* @param {BigNumber | string} amount USDC amount to transfer (6 decimals, e.g. "1000000" = 1 USDC)
|
|
2206
|
+
* @param {any} options Transaction options
|
|
2207
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2208
|
+
* @returns {Promise<any>} Transaction
|
|
2209
|
+
*/
|
|
2210
|
+
|
|
2211
|
+
async perpToSpotHyperliquid(
|
|
2212
|
+
dexId: number,
|
|
2213
|
+
amount: BigNumber | string,
|
|
2214
|
+
options: any = null,
|
|
2215
|
+
sdkOptions: SDKOptions = {
|
|
2216
|
+
estimateGas: false
|
|
2217
|
+
}
|
|
2218
|
+
): Promise<any> {
|
|
2219
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
2220
|
+
this,
|
|
2221
|
+
[
|
|
2222
|
+
CORE_WRITER_ADDRESS,
|
|
2223
|
+
getPerpToSpotHyperliquidTxData(dexId, this.address, amount),
|
|
2224
|
+
options
|
|
2225
|
+
],
|
|
2226
|
+
sdkOptions
|
|
2227
|
+
);
|
|
2228
|
+
return tx;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
/** Withdraw USDC from Hyperliquid Spot wallet back to EVM.
|
|
2232
|
+
* USDC must be in the Spot wallet first — use perpToSpotHyperliquid() to move it from a trading dex.
|
|
2233
|
+
*
|
|
2234
|
+
* @param {BigNumber | string} amount USDC amount to withdraw (6 decimals, e.g. "1000000" = 1 USDC)
|
|
2235
|
+
* @param {any} options Transaction options
|
|
2236
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2237
|
+
* @returns {Promise<any>} Transaction
|
|
2238
|
+
*/
|
|
2239
|
+
|
|
2240
|
+
async withdrawHyperliquid(
|
|
2241
|
+
amount: BigNumber | string,
|
|
2242
|
+
options: any = null,
|
|
2243
|
+
sdkOptions: SDKOptions = {
|
|
2244
|
+
estimateGas: false
|
|
2245
|
+
}
|
|
2246
|
+
): Promise<any> {
|
|
2247
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
2248
|
+
this,
|
|
2249
|
+
[CORE_WRITER_ADDRESS, getWithdrawSpotHyperliquidTxData(amount), options],
|
|
2250
|
+
sdkOptions
|
|
2251
|
+
);
|
|
2252
|
+
return tx;
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
/** Open a market order on Hyperliquid
|
|
2256
|
+
* @param {number} assetId Asset id
|
|
2257
|
+
* @param {boolean} isLong Long or short (Note: Spot assets only support long positions)
|
|
2258
|
+
* @param {number} value Order value in base asset units (positive for opening/increasing,
|
|
2259
|
+
* negative for closing/reducing or selling spot)
|
|
2260
|
+
* @param {number } slippage Slippage tolerance in %
|
|
2261
|
+
* @param {any} options Transaction options
|
|
2262
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2263
|
+
* @returns {Promise<any>} Transaction
|
|
2264
|
+
*/
|
|
2265
|
+
async openMarketOrderHyperliquid(
|
|
2266
|
+
assetId: number,
|
|
2267
|
+
isLong: boolean,
|
|
2268
|
+
value: number,
|
|
2269
|
+
slippage = 0.5,
|
|
2270
|
+
options: any = null,
|
|
2271
|
+
sdkOptions: SDKOptions = {
|
|
2272
|
+
estimateGas: false
|
|
2273
|
+
}
|
|
2274
|
+
): Promise<any> {
|
|
2275
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
2276
|
+
this,
|
|
2277
|
+
[
|
|
2278
|
+
CORE_WRITER_ADDRESS,
|
|
2279
|
+
await getLimitOrderHyperliquidTxData(assetId, isLong, value, slippage),
|
|
2280
|
+
options
|
|
2281
|
+
],
|
|
2282
|
+
sdkOptions
|
|
2283
|
+
);
|
|
2284
|
+
return tx;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
/** Close a position on Hyperliquid
|
|
2288
|
+
* @param {number} assetId Asset id
|
|
2289
|
+
* @param {number} percentageToClose Percentage of position to close (0-100)
|
|
2290
|
+
* @param {number } slippage Slippage tolerance in %
|
|
2291
|
+
* @param {any} options Transaction options
|
|
2292
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2293
|
+
* @returns {Promise<any>} Transaction
|
|
2294
|
+
*/
|
|
2295
|
+
async closePositionHyperliquid(
|
|
2296
|
+
assetId: number,
|
|
2297
|
+
percentageToClose = 100,
|
|
2298
|
+
slippage = 0.5,
|
|
2299
|
+
options: any = null,
|
|
2300
|
+
sdkOptions: SDKOptions = {
|
|
2301
|
+
estimateGas: false
|
|
2302
|
+
}
|
|
2303
|
+
): Promise<any> {
|
|
2304
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
2305
|
+
this,
|
|
2306
|
+
[
|
|
2307
|
+
CORE_WRITER_ADDRESS,
|
|
2308
|
+
await getClosePositionHyperliquidTxData(
|
|
2309
|
+
assetId,
|
|
2310
|
+
percentageToClose,
|
|
2311
|
+
slippage,
|
|
2312
|
+
this.address
|
|
2313
|
+
),
|
|
2314
|
+
options
|
|
2315
|
+
],
|
|
2316
|
+
sdkOptions
|
|
2317
|
+
);
|
|
2318
|
+
return tx;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
/**
|
|
2322
|
+
* Approve the Toros vault token for the PoolLimitOrderManager
|
|
2323
|
+
* Must be called before createTorosLimitOrder
|
|
2324
|
+
* @param {string} vaultAddress Address of the Toros vault token to approve
|
|
2325
|
+
* @param {BigNumber | string} amount Amount to approve
|
|
2326
|
+
* @param {any} options Transaction options
|
|
2327
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2328
|
+
* @returns {Promise<any>} Transaction
|
|
2329
|
+
*/
|
|
2330
|
+
async approveTorosLimitOrder(
|
|
2331
|
+
vaultAddress: string,
|
|
2332
|
+
amount: BigNumber | string,
|
|
2333
|
+
options: any = null,
|
|
2334
|
+
sdkOptions: SDKOptions = { estimateGas: false }
|
|
2335
|
+
): Promise<any> {
|
|
2336
|
+
const managerAddress = limitOrderAddress[this.network];
|
|
2337
|
+
const iERC20 = new ethers.utils.Interface(IERC20.abi);
|
|
2338
|
+
const approveTxData = iERC20.encodeFunctionData("approve", [
|
|
2339
|
+
managerAddress,
|
|
2340
|
+
amount
|
|
2341
|
+
]);
|
|
2342
|
+
return getPoolTxOrGasEstimate(
|
|
2343
|
+
this,
|
|
2344
|
+
[vaultAddress, approveTxData, options],
|
|
2345
|
+
sdkOptions
|
|
2346
|
+
);
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
/**
|
|
2350
|
+
* Create a Toros limit order (stop-loss / take-profit)
|
|
2351
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
2352
|
+
* @param {BigNumber | string} amount Vault token amount (18 decimals)
|
|
2353
|
+
* @param {BigNumber | string | null | undefined} stopLossPriceD18 Stop-loss price in D18 (0 or null/undefined = disabled)
|
|
2354
|
+
* @param {BigNumber | string | null | undefined} takeProfitPriceD18 Take-profit price in D18 (MaxUint256 or null/undefined = disabled)
|
|
2355
|
+
* @param {string} pricingAsset Address of the pricing asset (e.g. USDC)
|
|
2356
|
+
* @param {any} options Transaction options
|
|
2357
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2358
|
+
* @returns {Promise<any>} Transaction
|
|
2359
|
+
*/
|
|
2360
|
+
async createTorosLimitOrder(
|
|
2361
|
+
vaultAddress: string,
|
|
2362
|
+
amount: BigNumber | string,
|
|
2363
|
+
stopLossPriceD18: BigNumber | string | null | undefined,
|
|
2364
|
+
takeProfitPriceD18: BigNumber | string | null | undefined,
|
|
2365
|
+
pricingAsset: string,
|
|
2366
|
+
options: any = null,
|
|
2367
|
+
sdkOptions: SDKOptions = { estimateGas: false }
|
|
2368
|
+
): Promise<any> {
|
|
2369
|
+
const managerAddress = limitOrderAddress[this.network];
|
|
2370
|
+
if (!managerAddress) {
|
|
2371
|
+
throw new Error(`Limit orders not supported on ${this.network}`);
|
|
2372
|
+
}
|
|
2373
|
+
const resolvedStopLoss =
|
|
2374
|
+
stopLossPriceD18 == null
|
|
2375
|
+
? BigNumber.from(0)
|
|
2376
|
+
: BigNumber.from(stopLossPriceD18);
|
|
2377
|
+
const resolvedTakeProfit =
|
|
2378
|
+
takeProfitPriceD18 == null
|
|
2379
|
+
? ethers.constants.MaxUint256
|
|
2380
|
+
: BigNumber.from(takeProfitPriceD18);
|
|
2381
|
+
const info: LimitOrderInfo = {
|
|
2382
|
+
amount: BigNumber.from(amount),
|
|
2383
|
+
stopLossPriceD18: resolvedStopLoss,
|
|
2384
|
+
takeProfitPriceD18: resolvedTakeProfit,
|
|
2385
|
+
user: this.address,
|
|
2386
|
+
pool: vaultAddress,
|
|
2387
|
+
pricingAsset
|
|
2388
|
+
};
|
|
2389
|
+
const txData = getCreateLimitOrderTxData(info);
|
|
2390
|
+
return getPoolTxOrGasEstimate(
|
|
2391
|
+
this,
|
|
2392
|
+
[managerAddress, txData, options],
|
|
2393
|
+
sdkOptions
|
|
2394
|
+
);
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
/**
|
|
2398
|
+
* Modify an existing Toros limit order
|
|
2399
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
2400
|
+
* @param {BigNumber | string} amount New vault token amount (18 decimals)
|
|
2401
|
+
* @param {BigNumber | string | null | undefined} stopLossPriceD18 New stop-loss price in D18 (0 or null/undefined = disabled)
|
|
2402
|
+
* @param {BigNumber | string | null | undefined} takeProfitPriceD18 New take-profit price in D18 (MaxUint256 or null/undefined = disabled)
|
|
2403
|
+
* @param {string} pricingAsset Address of the pricing asset
|
|
2404
|
+
* @param {any} options Transaction options
|
|
2405
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2406
|
+
* @returns {Promise<any>} Transaction
|
|
2407
|
+
*/
|
|
2408
|
+
async modifyTorosLimitOrder(
|
|
2409
|
+
vaultAddress: string,
|
|
2410
|
+
amount: BigNumber | string,
|
|
2411
|
+
stopLossPriceD18: BigNumber | string | null | undefined,
|
|
2412
|
+
takeProfitPriceD18: BigNumber | string | null | undefined,
|
|
2413
|
+
pricingAsset: string,
|
|
2414
|
+
options: any = null,
|
|
2415
|
+
sdkOptions: SDKOptions = { estimateGas: false }
|
|
2416
|
+
): Promise<any> {
|
|
2417
|
+
const managerAddress = limitOrderAddress[this.network];
|
|
2418
|
+
if (!managerAddress) {
|
|
2419
|
+
throw new Error(`Limit orders not supported on ${this.network}`);
|
|
2420
|
+
}
|
|
2421
|
+
const resolvedStopLoss =
|
|
2422
|
+
stopLossPriceD18 == null
|
|
2423
|
+
? BigNumber.from(0)
|
|
2424
|
+
: BigNumber.from(stopLossPriceD18);
|
|
2425
|
+
const resolvedTakeProfit =
|
|
2426
|
+
takeProfitPriceD18 == null
|
|
2427
|
+
? ethers.constants.MaxUint256
|
|
2428
|
+
: BigNumber.from(takeProfitPriceD18);
|
|
2429
|
+
const info: LimitOrderInfo = {
|
|
2430
|
+
amount: BigNumber.from(amount),
|
|
2431
|
+
stopLossPriceD18: resolvedStopLoss,
|
|
2432
|
+
takeProfitPriceD18: resolvedTakeProfit,
|
|
2433
|
+
user: this.address,
|
|
2434
|
+
pool: vaultAddress,
|
|
2435
|
+
pricingAsset
|
|
2436
|
+
};
|
|
2437
|
+
const txData = getModifyLimitOrderTxData(info);
|
|
2438
|
+
return getPoolTxOrGasEstimate(
|
|
2439
|
+
this,
|
|
2440
|
+
[managerAddress, txData, options],
|
|
2441
|
+
sdkOptions
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
/**
|
|
2446
|
+
* Delete an existing Toros limit order
|
|
2447
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
2448
|
+
* @param {any} options Transaction options
|
|
2449
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2450
|
+
* @returns {Promise<any>} Transaction
|
|
2451
|
+
*/
|
|
2452
|
+
async deleteTorosLimitOrder(
|
|
2453
|
+
vaultAddress: string,
|
|
2454
|
+
options: any = null,
|
|
2455
|
+
sdkOptions: SDKOptions = { estimateGas: false }
|
|
2456
|
+
): Promise<any> {
|
|
2457
|
+
const managerAddress = limitOrderAddress[this.network];
|
|
2458
|
+
if (!managerAddress) {
|
|
2459
|
+
throw new Error(`Limit orders not supported on ${this.network}`);
|
|
2460
|
+
}
|
|
2461
|
+
const txData = getDeleteLimitOrderTxData(vaultAddress);
|
|
2462
|
+
return getPoolTxOrGasEstimate(
|
|
2463
|
+
this,
|
|
2464
|
+
[managerAddress, txData, options],
|
|
2465
|
+
sdkOptions
|
|
2466
|
+
);
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
/**
|
|
2470
|
+
* Fetch a Toros limit order for a given user and vault
|
|
2471
|
+
* @param {string} userAddress Address of the order owner (the dHEDGE pool)
|
|
2472
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
2473
|
+
* @returns {Promise<LimitOrderInfo | null>} Order info, or null if none exists
|
|
2474
|
+
*/
|
|
2475
|
+
async getTorosLimitOrder(
|
|
2476
|
+
userAddress: string,
|
|
2477
|
+
vaultAddress: string
|
|
2478
|
+
): Promise<LimitOrderInfo | null> {
|
|
2479
|
+
return getTorosLimitOrder(this, userAddress, vaultAddress);
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
/**
|
|
2483
|
+
* Check whether an active Toros limit order exists for a given user and vault
|
|
2484
|
+
* @param {string} userAddress Address of the order owner (the dHEDGE pool)
|
|
2485
|
+
* @param {string} vaultAddress Address of the Toros vault token
|
|
2486
|
+
* @returns {Promise<boolean>}
|
|
2487
|
+
*/
|
|
2488
|
+
async hasActiveTorosLimitOrder(
|
|
2489
|
+
userAddress: string,
|
|
2490
|
+
vaultAddress: string
|
|
2491
|
+
): Promise<boolean> {
|
|
2492
|
+
return hasActiveTorosLimitOrder(this, userAddress, vaultAddress);
|
|
2493
|
+
}
|
|
2150
2494
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const USDC_TOKEN_ID = 0;
|
|
2
|
+
export const USDC_CORE_ADDRESS = "0x2000000000000000000000000000000000000000";
|
|
3
|
+
export const CORE_WRITER_ADDRESS = "0x3333333333333333333333333333333333333333";
|
|
4
|
+
export const PERP_DEX_ID = 0;
|
|
5
|
+
export const SPOT_DEX_ID = 4294967295; // max uint32;
|
|
6
|
+
export const HYPERLIQUID_VERSION = 1;
|
|
7
|
+
|
|
8
|
+
//Action IDs
|
|
9
|
+
export const SPOT_SEND_ACTION = 6;
|
|
10
|
+
export const SEND_ASSET_ACTION = 13;
|
|
11
|
+
export const LIMIT_ORDER_ACTION = 1;
|
|
12
|
+
|
|
13
|
+
//Order Time In Force options
|
|
14
|
+
export const LIMIT_ORDER_TIF_ALO = 1;
|
|
15
|
+
export const LIMIT_ORDER_TIF_GTC = 2;
|
|
16
|
+
export const LIMIT_ORDER_TIF_IOC = 3;
|
|
17
|
+
|
|
18
|
+
export const dexIdNameMap: { [key: number]: string } = {
|
|
19
|
+
0: "",
|
|
20
|
+
1: "xyz"
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const API_URL = "https://api.hyperliquid.xyz/info";
|