@rabby-wallet/hyperliquid-sdk 1.0.9 → 1.0.10

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.
@@ -1,4 +1,4 @@
1
- import type { OrderResponse, CancelResponse, ExchangeClientConfig, PlaceOrderParams, MultiOrderParams, CancelOrderParams, ModifyOrderParams, WithdrawParams, ApproveBuilderFeeParams, PrepareApproveBuilderFeeResult, SendApproveParams, MarketOrderParams, UpdateLeverageParams, BindTpslByOrderIdParams } from '../types';
1
+ import type { OrderResponse, CancelResponse, ExchangeClientConfig, PlaceOrderParams, MultiOrderParams, CancelOrderParams, ModifyOrderParams, WithdrawParams, ApproveBuilderFeeParams, PrepareApproveBuilderFeeResult, SendApproveParams, MarketOrderParams, UpdateLeverageParams, BindTpslByOrderIdParams, UpdateIsolatedMarginParams } from '../types';
2
2
  /**
3
3
  * Client for executing trades on Hyperliquid (perpetuals only)
4
4
  * Only includes essential trading APIs as specified
@@ -67,6 +67,7 @@ export declare class ExchangeClient {
67
67
  * Modify an existing order
68
68
  */
69
69
  modifyOrder(params: ModifyOrderParams): Promise<any>;
70
+ updateIsolatedMargin(params: UpdateIsolatedMarginParams): Promise<any>;
70
71
  /**
71
72
  * Set referrer for 10% fee
72
73
  */
@@ -438,6 +438,24 @@ class ExchangeClient {
438
438
  });
439
439
  });
440
440
  }
441
+ updateIsolatedMargin(params) {
442
+ return __awaiter(this, void 0, void 0, function* () {
443
+ const nonce = Date.now();
444
+ const assetIndex = yield this.symbolConversion.getAssetIndex(params.coin);
445
+ const action = {
446
+ type: constants_1.ExchangeType.UPDATE_ISOLATED_MARGIN,
447
+ asset: assetIndex,
448
+ isBuy: true,
449
+ ntli: (0, number_1.floatToInt)(params.value, 6), // 6 decimals
450
+ };
451
+ const signature = (0, signer_1.signL1AgentAction)(this.getAgentPrivateKey(), action, this.isTestnet, nonce);
452
+ return this.httpClient.exchange({
453
+ action,
454
+ nonce,
455
+ signature,
456
+ });
457
+ });
458
+ }
441
459
  /**
442
460
  * Set referrer for 10% fee
443
461
  */
@@ -393,6 +393,10 @@ export interface CancelOrderParams {
393
393
  coin: string;
394
394
  oid: OrderId;
395
395
  }
396
+ export interface UpdateIsolatedMarginParams {
397
+ coin: string;
398
+ value: number;
399
+ }
396
400
  export interface ModifyOrderParams {
397
401
  oid: OrderId;
398
402
  coin: string;
@@ -10,3 +10,4 @@
10
10
  * @returns The normalized string without trailing zeros
11
11
  */
12
12
  export declare function removeTrailingZeros(value: string): string;
13
+ export declare function floatToInt(x: number, power: number): number;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeTrailingZeros = removeTrailingZeros;
4
+ exports.floatToInt = floatToInt;
4
5
  /**
5
6
  * Removes trailing zeros from a string representation of a number.
6
7
  * This is useful when working with price and size fields directly.
@@ -20,3 +21,10 @@ function removeTrailingZeros(value) {
20
21
  return '0';
21
22
  return normalized;
22
23
  }
24
+ function floatToInt(x, power) {
25
+ const withDecimals = x * Math.pow(10, power);
26
+ if (Math.abs(Math.round(withDecimals) - withDecimals) >= 1e-3) {
27
+ throw new Error(`floatToInt causes rounding: ${x}`);
28
+ }
29
+ return Math.round(withDecimals);
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/hyperliquid-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Simplified Hyperliquid Perpetuals Trading SDK for Frontend Applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",