@dhedge/v2-sdk 2.1.6 → 2.1.7
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/dist/entities/pool.d.ts +11 -0
- package/dist/services/hyperliquid/index.d.ts +1 -1
- package/dist/v2-sdk.cjs.development.js +146 -93
- 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 +146 -93
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/entities/pool.ts +37 -3
- package/src/services/hyperliquid/index.ts +8 -6
package/package.json
CHANGED
package/src/entities/pool.ts
CHANGED
|
@@ -100,10 +100,13 @@ import {
|
|
|
100
100
|
getClosePositionHyperliquidTxData,
|
|
101
101
|
getDepositHyperliquidTxData,
|
|
102
102
|
getLimitOrderHyperliquidTxData,
|
|
103
|
-
|
|
103
|
+
getSendAssetHyperliquidTxData,
|
|
104
104
|
getWithdrawSpotHyperliquidTxData
|
|
105
105
|
} from "../services/hyperliquid";
|
|
106
|
-
import {
|
|
106
|
+
import {
|
|
107
|
+
CORE_WRITER_ADDRESS,
|
|
108
|
+
SPOT_DEX_ID
|
|
109
|
+
} from "../services/hyperliquid/constants";
|
|
107
110
|
|
|
108
111
|
export class Pool {
|
|
109
112
|
public readonly poolLogic: Contract;
|
|
@@ -2220,7 +2223,38 @@ export class Pool {
|
|
|
2220
2223
|
this,
|
|
2221
2224
|
[
|
|
2222
2225
|
CORE_WRITER_ADDRESS,
|
|
2223
|
-
|
|
2226
|
+
getSendAssetHyperliquidTxData(dexId, SPOT_DEX_ID, this.address, amount),
|
|
2227
|
+
options
|
|
2228
|
+
],
|
|
2229
|
+
sdkOptions
|
|
2230
|
+
);
|
|
2231
|
+
return tx;
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
/** Move USDC from HyperCore spot wallet to a trading dex.
|
|
2235
|
+
*
|
|
2236
|
+
* @param {number} dexId Destination dex ID where USDC will be moved to
|
|
2237
|
+
* - 0: Core Perp dex (standard perps like BTC, ETH)
|
|
2238
|
+
* - 1: xyz HIP-3 dex (builder perps like TSLA, GOLD)
|
|
2239
|
+
* @param {BigNumber | string} amount USDC amount to transfer (6 decimals, e.g. "1000000" = 1 USDC)
|
|
2240
|
+
* @param {any} options Transaction options
|
|
2241
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2242
|
+
* @returns {Promise<any>} Transaction
|
|
2243
|
+
*/
|
|
2244
|
+
|
|
2245
|
+
async spotToPerpHyperliquid(
|
|
2246
|
+
dexId: number,
|
|
2247
|
+
amount: BigNumber | string,
|
|
2248
|
+
options: any = null,
|
|
2249
|
+
sdkOptions: SDKOptions = {
|
|
2250
|
+
estimateGas: false
|
|
2251
|
+
}
|
|
2252
|
+
): Promise<any> {
|
|
2253
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
2254
|
+
this,
|
|
2255
|
+
[
|
|
2256
|
+
CORE_WRITER_ADDRESS,
|
|
2257
|
+
getSendAssetHyperliquidTxData(SPOT_DEX_ID, dexId, this.address, amount),
|
|
2224
2258
|
options
|
|
2225
2259
|
],
|
|
2226
2260
|
sdkOptions
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
LIMIT_ORDER_ACTION,
|
|
7
7
|
LIMIT_ORDER_TIF_IOC,
|
|
8
8
|
SEND_ASSET_ACTION,
|
|
9
|
-
SPOT_DEX_ID,
|
|
10
9
|
SPOT_SEND_ACTION,
|
|
11
10
|
USDC_CORE_ADDRESS,
|
|
12
11
|
USDC_TOKEN_ID
|
|
@@ -50,12 +49,15 @@ export const getWithdrawSpotHyperliquidTxData = (
|
|
|
50
49
|
);
|
|
51
50
|
return coreWriter.encodeFunctionData("sendRawAction", [rawTXData]);
|
|
52
51
|
};
|
|
53
|
-
export const
|
|
54
|
-
|
|
52
|
+
export const getSendAssetHyperliquidTxData = (
|
|
53
|
+
sourceDex: number,
|
|
54
|
+
destinationDex: number,
|
|
55
55
|
receiver: string,
|
|
56
56
|
amount: ethers.BigNumber | string
|
|
57
57
|
): string => {
|
|
58
|
-
|
|
58
|
+
// Convert 6-decimal EVM USDC to 8-decimal HyperCore USDC (spot, main perp, and xyz)
|
|
59
|
+
// Transfer USDC between dexes (perp, spot, xyz)
|
|
60
|
+
const coreAmount = ethers.BigNumber.from(amount).mul(100);
|
|
59
61
|
//From Perp to Spot
|
|
60
62
|
const innerEncoded = ethers.utils.defaultAbiCoder.encode(
|
|
61
63
|
//destination, subAccount, sourceDex, destinationDex, token, amount
|
|
@@ -63,8 +65,8 @@ export const getPerpToSpotHyperliquidTxData = (
|
|
|
63
65
|
[
|
|
64
66
|
receiver,
|
|
65
67
|
ethers.constants.AddressZero,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
sourceDex,
|
|
69
|
+
destinationDex,
|
|
68
70
|
USDC_TOKEN_ID,
|
|
69
71
|
coreAmount
|
|
70
72
|
]
|