
# Thao tác triển khai HIP-3 {#hip-3-deployer-actions}

API để triển khai và vận hành dexs triển khai vĩnh viễn của người xây dựng liên quan đến các hành động L1 sau:

```typescript
// IMPORTANT: All lists of tuples should be lexographically sorted before signing
type PerpDeployAction =
  | {
      type: "perpDeploy";
      registerAsset2: RegisterAsset2;
    }
  | {
      type: "perpDeploy";
      registerAsset: RegisterAsset;
    }
  | {
      type: "perpDeploy";
      setOracle: SetOracle;
    }
  | {
      type: "perpDeploy";
      setFundingMultipliers: SetFundingMultipliers;
    }
  | {
      type: "perpDeploy";
      setFundingInterestRates: SetFundingInterestRates;
    }
  | {
      type: "perpDeploy";
      setFundingClamps: SetFundingClamps;
    }
  | {
      type: "perpDeploy";
      haltTrading: { coin: string; isHalted: boolean };
    }
  | {
      type: "perpDeploy";
      insertMarginTable: InsertMarginTable;
    }
  | {
      type: "perpDeploy";
      setMarginTableIds: SetMarginTableIds;
    }
  | {
      type: "perpDeploy";
      setFeeRecipient: { dex: string; feeRecipient: address };
    }
  | {
      type: "perpDeploy";
      setOpenInterestCaps: SetOpenInterestCaps;
    }
  | {
      type: "perpDeploy";
      setSubDeployers: { dex: string; subDeployers: Array<SubDeployerInput> };
    }
  | {
      type: "perpDeploy";
      setMarginModes: SetMarginModes;
    }
  | {
      type: "perpDeploy";
      setDeployerFees: SetDeployerFees;
    }
  | {
      type: "perpDeploy";
      setPerpAnnotation: SetPerpAnnotation;
    }
  | {
      type: "perpDeploy";
      disableDex: string;
    };

// User-signed action to transfer collateral between the user's DEX account and its backstop liquidator.
// ntl must be positive and a multiple of 1_000_000_000.
type Hip3LiquidatorTransferAction = {
  type: "hip3LiquidatorTransfer";
  dex: string;
  ntl: number; // Integer amount in millionths of a collateral token: 1_000_000_000 = 1,000 tokens
  isDeposit: boolean; // true deposits; false withdraws
};

/**
 * RegisterAsset2 can be called to initialize a new dex and register an asset at the same time.
 * If schema is not provided, then RegisterAsset can be called multiple times to register additional assets
 * for the provided dex.
 * @param maxGas - Max gas in native token wei. If not provided, then uses current deploy auction price.
 * If the max gas is 0, then a reserve deployment will be used.
 * A reserve deployment allows deployment at the current price of the gas auction, even if it has ended.
 * Currently, 7 reserve deployments are allowed.
 * IMPORTANT: A reserve deployment will be used regardless of whether the auction has completed, so deployers should query the auction status first.
 * @param assetRequest - Contains new asset listing parameters. See RegisterAssetRequest2 below for details.
 * @param dex - Name of the perp dex (2-4 lowercase characters)
 * @param schema - Contains new perp dex parameters. See PerpDexSchemaInput below for details.
 */
type RegisterAsset2 = {
  maxGas?: number;
  assetRequest: RegisterAssetRequest2;
  dex: string;
  schema?: PerpDexSchemaInput;
};

// Same as RegisterAsset2 but uses RegisterAssetRequest
type RegisterAsset = {
  maxGas?: number;
  assetRequest: RegisterAssetRequest;
  dex: string;
  schema?: PerpDexSchemaInput;
};

type RegisterAssetRequest2 = {
  coin: string;
  szDecimals: number;
  oraclePx: string;
  marginTableId: number;
  marginMode: "strictIsolated" | "noCross" | "normal"; // strictIsolated does not allow withdrawing of isolated margin from open positions
};

type RegisterAssetRequest = {
  coin: string;
  szDecimals: number;
  oraclePx: string;
  marginTableId: number;
  onlyIsolated: boolean;
};

/**
 * The markPxs outer list can be length 0, 1, or 2. The median of these inputs
 * along with the local mark price (median(best bid, best ask, last trade price))
 * is used as the new mark price update.
 *
 * SetOracle can be called multiple times but there must be at least 2.5 seconds between calls.
 *
 * Stale mark prices will be updated to the local mark price after 10 seconds of no updates.
 * This fallback counts as an update for purposes of the maximal update frequency.
 * This fallback behavior should not be relied upon. Deployers are expected to call setOracle every 3 seconds even with no changes.
 *
 * All prices are clamped to 10x the start of day value.
 * markPx moves are clamped to 1% from previous markPx.
 * markPx cannot be updated such that open interest would be 10x the open interest cap.
 * @param dex - Name of the perp dex
 * @param oraclePxs - A list (sorted by key) of asset and oracle prices.
 * @param markPxs - An outer list of inner lists (inner list sorted by key) of asset and mark prices.
 * @param externalPerpPxs - A list (sorted by key) of asset and external prices which prevent sudden mark price deviations.
 * Ideally externally determined by deployer, but could fall back to an EMA of recent mark prices.
 * Must include all assets.
 */
type SetOracle = {
  dex: string;
  oraclePxs: Array<[string, string]>;
  markPxs: Array<Array<[string, string]>>;
  externalPerpPxs: Array<[string, string]>;
};

/**
 * @param fullName - Full name of the perp dex
 * @param collateralToken - Collateral token index
 * @param oracleUpdater - User to update oracles. If not provided, then deployer is assumed to be oracle updater.
 */
type PerpDexSchemaInput = {
  fullName: string;
  collateralToken: int;
  oracleUpdater?: string;
};

/**
 * A sorted list of asset and funding multiplier.
 * Multipliers must be between 0 and 10 and are used to scale the funding rate.
 */
type SetFundingMultipliers = Array<[string, string]>;

/**
 * A sorted list of asset and 8 hour interest rate.
 * Interest rates must be between -0.01 and 0.01 and are used as the interest rate
 * component in the funding calculation.
 */
type SetFundingInterestRates = Array<[string, string]>;

/**
 * A sorted list of asset and 8 hour funding clamp.
 * Clamps must be between 0 and 0.01 and bound how far the funding rate can move away from the
 * average premium toward the interest rate. Defaults to 0.0003.
 */
type SetFundingClamps = Array<[string, string]>;

/**
 * A sorted of asset and margin table ids.
 * Margin table ids must be non-zero.
 */
type SetMarginTableIds = Array<[string, number]>;

/**
 * Inserts margin table to dex
 */
type InsertMarginTable = {
  dex: string;
  marginTable: RawMarginTable;
};

/**
 * marginTiers must be sorted in order of increasing lower bound and decreasing maxLeverage
 * marginTiers has a maximum length of 3.
 */
type RawMarginTable = {
  description: string;
  marginTiers: Array<RawMarginTier>;
};

/**
 * lowerBound is a position notional value above which the leverage is constrained by maxLeverage
 */
type RawMarginTier = {
  lowerBound: int;
  maxLeverage: MaxLeverage;
};

/**
 * Max leverage is in the range [1, 50]
 */
type MaxLeverage = number;

/**
 * A sorted list of asset and open interest cap notionals.
 * Open interest caps must be at least the maximum of 1_000_000 (1 size unit of collateral asset) or half of the current open interest.
 * null removes the custom cap for an asset.
 */
type SetOpenInterestCaps = Array<[string, number | null]>;

/**
 * A modification to sub-deployer permissions
 */
type SubDeployerInput = {
  variant: string; // corresponds to a variant of PerpDeployAction. For example, "haltTrading" or "setOracle"
  user: String;
  allowed: boolean; // add or remove the subDeployer from the authorized set for the action variant
};

// A sorted list of (coin, marginMode). See RegisterAssetRequest2 for margin mode definitions.
type SetMarginModes = Array<[string, "strictIsolated" | "noCross" | "normal"]>;

// Let the user normal rate be `x`. Let the user rate be `y` after accounting for aligned quote collateral.
// In other words, `x = y` for non-aligned collateral.
// User pays or receives rebate `P + D` where `P` goes to protocol and `D` goes to deployer.
// If `x > 0` and `scale < 1`, `P = y` and `D = scale * x`
// If `x > 0` and `scale > 1`, `P = y * scale` and `D = x * scale`
// If `x < 0` and `scale < 1`, `P = y / (1 + scale)` and `D = y * scale / (1 + scale)`
// If `x < 0` and `scale > 1`, `P = y / 2` and `D = y / 2`
// On Mainnet, rate limited to one change per 30 days.
// Note that there are currently no aligned quote assets on mainnet.
type SetDeployerFees = Array<
  [
    string,
    {
      scale: string; // Decimal string in [0.0, 3.0], or [0.0, 10.0) when growthMode is true
      growthMode: boolean;
    },
  ]
>;

// category <= 15 characters
// description <= 400 characters
// displayName <= 9 characters
// <= 2 keywords, each keyword <= 10 characters
type SetPerpAnnotation = {
  coin: string;
  category: string;
  description: string;
  displayName: string | null;
  keywords: Array<string>;
};
```

Đối với các ví dụ dưới đây, `feeScale` là trường `scale` trong `SetDeployerFees`. Giả sử mức phí người dùng bình thường dương của đơn vị 1 và tài sản thế chấp không liên kết (`x = y = 1` ). `userFeeToProtocol` và `userFeeToDeployer` là các đơn vị phí thu được tính cho người dùng.

| `growthMode` | `feeScale` | `userFeeToProtocol` | `userFeeToDeployer` |
| ------------ | ---------- | ------------------- | ------------------- |
| `false` | `"0"` | `1` | `0` |
| `false` | `"0.5"` | `1` | `0.5` |
| `false` | `"1"` | `1` | `1` |
| `false` | `"3"` | `3` | `3` |
| `true` | `"0"` | `0.1` | `0` |
| `true` | `"0.5"` | `0.1` | `0.05` |
| `true` | `"1"` | `0.1` | `0.1` |
| `true` | `"3.01"` | `0.301` | `0.301` |
| `true` | `"9.99"` | `0.999` | `0.999` |

Xem <https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-information-about-the-perp-deploy-auction> để biết cách truy vấn hợp đồng vĩnh cửu triển khai tình trạng đấu giá.

#### Giới hạn lãi suất mở {#open-interest-caps}

Thị trường hợp đồng vĩnh cửu được xây dựng-triển khai phải tuân theo hai loại caps lợi ích mở: khái niệm (tổng kích thước vị trí tuyệt đối nhân với giá đánh dấu) và kích thước (tổng kích thước vị trí tuyệt đối).

Các mức trần lãi mở danh nghĩa được thi hành trên tổng lãi mở tổng cộng trên tất cả các tài sản trong DEX, cũng như trên mỗi tài sản.Người triển khai perp có thể thiết lập một mức trần lãi mở tuỳ chỉnh cho mỗi tài sản, được ghi trong <https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-3-deployer-actions>.

Quy tắc lãi suất mở có chỉ định kích thước chỉ được thực thi cho mỗi tài sản. Quy tắc lãi suất mở có chỉ định kích thước hiện là 1B không đổi cho mỗi tài sản, vì vậy một mặc định hợp lý sẽ là đặt `szDecimals` sao cho gia tăng kích thước tối thiểu là $1-10 với giá mark ban đầu.

#### Bộ thanh khoản backstop {#backstop-liquidator}

Địa chỉ thanh lý quay lại là `0x4000000000000000000000000000000000000000 + {dex_index}`. Ví dụ: HIP-3 DEX đầu tiên có địa chỉ thanh lý quay lại là `0x4000000000000000000000000000000000000001`.

#### Trạng thái của Node user clearinghouse {#node-user-clearinghouse-states}

Cờ nút `--write-user-clearinghouse-states <dex>` viết các trạng thái bù trừ cho HIP-3 DEX có tên cho các tệp hàng giờ tại `~/hl/data/dex_user_clearinghouse_states/hourly/<date>/<hour>`, trong đó `date` là `YYYYMMDD`.Mỗi dòng là một mảng JSON `[time, messages]`, trong đó `time` là thời gian khối và `messages` là một ảnh chụp nhanh duy nhất của mọi người dùng trên DEX hoặc danh sách các khác biệt cho mỗi người dùng:

```json
["2026-09-24T09:00:00.123", [{ "Snapshot": { "0xUSER_A": <clearinghouseState> } }]]
["2026-09-24T09:00:03.456", [{ "Diff": ["0xUSER_A", <clearinghouseState>] }]]
```

Mỗi `<clearinghouseState>` có cùng định dạng với phản hồi yêu cầu thông tin `clearinghouseState` cho DEX đó, có tên trong thẻ bài phụ của địa điểm.Nó chỉ tài khoản cho trạng thái của người dùng trên DEX có tên, vì vậy tài sản phụ được chia sẻ trên các DEX (ví dụ thông qua sự trừu tượng của người dùng) không được bao gồm và `liquidationPx` luôn là `null`. dòng đầu tiên của mỗi tệp và dòng đầu tiên được viết sau khi nút bắt đầu, là một ảnh chụp nhanh.Các dòng khác chứa các khác biệt cho người dùng có trạng thái thanh toán bù trừ đã thay đổi, bỏ qua `time`: mọi người dùng như vậy trên bản cập nhật oracle cho địa điểm, hoặc chỉ những người dùng liên quan đến điền đầy, thanh lý, thanh toán tài trợ hoặc chuyển vào hoặc ra khỏi địa điểm.

## HIP-3\* (testnet-only)

### Hành động của sao {#star-actions}

Có thể chỉ định một DEX HIP-3 là HIP-3\* ngay khi tạo bằng cách đặt `isStar: true` trong `PerpDexSchemaInput`. Trường boolean tùy chọn này mặc định là `false`. HIP-3\* bổ sung một số tính năng ngoài đặc tả HIP-3, gồm

#### Hoạt động {#operations}

```typescript
type Hip3StarAction = {
  type: "perpDeploy";
  star: { dex: string; operation: Hip3StarOperation };
};

type Hip3StarOperation =
  | { proxy: [address, Hip3StarProxyOperation] }
  | { setOracle: { oraclePxs: Array<[string, string]> } };

// CancelAction and OrderAction are the standard exchange actions.
type Hip3StarProxyOperation =
  | { modifyApproval: boolean }
  | { modifyBackstopLiquidatorApproval: boolean }
  | { setReduceOnly: boolean }
  | { cancel: Omit<CancelAction, "type"> }
  | { cancelAll: { assets?: Array<number> | null } }
  | { order: Omit<OrderAction, "type"> }
  | { sendAsset: { destination: address; amount: string } };
```

```json
{
  "type": "perpDeploy",
  "star": {
    "dex": "test",
    "operation": { "proxy": ["0xUSER_A", { "modifyApproval": true }] }
  }
}
{
  "type": "perpDeploy",
  "star": {
    "dex": "test",
    "operation": { "proxy": ["0xUSER_B", { "cancelAll": { "assets": [100001, 100002] } }] }
  }
}
{
  "type": "perpDeploy",
  "star": {
    "dex": "test",
    "operation": { "setOracle": { "oraclePxs": [["test:BTC", "100000.0"], ["test:ETH", "4000.0"]] } }
  }
}
```

* **`proxy`** là một cặp gồm địa chỉ người dùng và thao tác ủy quyền áp dụng cho người đó.
* **`setOracle`** cập nhật giá oracle theo phần Oracle bên dưới.

#### Thao tác ủy nhiệm {#proxy-operations}

* **`modifyApproval`** — `{ "modifyApproval": true }` adds the user to the allowlist, `false` gỡ bỏ chúng và xóa bỏ cờ của chúng. Gỡ bỏ người dùng không được chấp thuận là không bật. Phê duyệt lại người dùng được chấp thuận là không bật và giữ lại các cờ của người dùng. Người dùng bị gỡ bỏ được chấp thuận lại bắt đầu với các cờ mặc định.
* **`modifyBackstopLiquidatorApproval`**. `{ "modifyBackstopLiquidatorApproval": true }` cho phép người dùng nạp hoặc rút tiền từ cơ chế thanh lý dự phòng của DEX qua `hip3LiquidatorTransfer`. Đặt `false` để thu hồi quyền này. Trước đó, người dùng phải được phê duyệt qua `modifyApproval`.
* **`setReduceOnly`** — `{ "setReduceOnly": true }` hạn chế người dùng được phê duyệt giảm vị trí của họ tại địa điểm. Người dùng chỉ có thể đặt lệnh chỉ-giảm và TWAP, sửa đổi lệnh thành lệnh chỉ-giảm và hủy. `{ "setReduceOnly": false }` restores full trading.
* **`cancel`**. `{ "cancel": { "cancels": [{ "a": <asset>, "o": <oid> }] } }` là payload chuẩn của thao tác giao dịch `cancel`. Dùng để hủy các lệnh đang chờ của người dùng theo oid.
* **`cancelAll`**. `{ "cancelAll": { "assets": null } }` hủy tất cả lệnh đang chờ và lệnh TWAP của người dùng trên DEX này. `{ "cancelAll": { "assets": [<asset>, ...] } }` chỉ hủy lệnh đang chờ và lệnh TWAP của các tài sản liệt kê. Danh sách phải có từ 1 đến 10 mục.
* **`order`**. `{ "order": { "orders": [...], "grouping": "na" } }` là payload chuẩn của thao tác giao dịch `order`. Mọi lệnh phải ở chế độ chỉ giảm vị thế (`"r": true`).
* **`sendAsset`** — `{ "sendAsset": { "destination": "0xUSER_C", "amount": "100.0" } }`. Moves collateral from the proxied user's account on the DEX tới `destination`'s account on the same venue.

#### Oracle

HIP-3\* venues update prices with the `setOracle` star operation deploy action. `oraclePxs` là một danh sách (phân loại theo khóa) giá tài sản và giá nhà tiên tri điểm. Giá của đối tượng bên ngoài và giá đánh dấu có nguồn gốc trên chuỗi dựa trên đầu vào giá nhà tiên tri điểm của người triển khai.

* **-Giá tội phạm bên ngoài ** được tính từ tài sản dex chính cùng tên, có mệnh giá chuyển đổi thành USDC. Ví dụ: `test:BTC` sử dụng giá tội phạm bên ngoài là `BTC`.
* **Giá đánh dấu** được tính toán onchain là trung vị của:

  1. giá oracle được điều chỉnh bởi một trung bình trượt mũ của phí bảo hiểm của giá giữa so với giá oracle,
  2. Giá ngoại phạm, và
  3. Giá mark địa phương (trung bình (giá chào mua tốt nhất, giá chào mua tốt nhất, giá giao dịch cuối cùng)).

  Nếu chỉ có sẵn hai trong số các mức giá này, trung bình động theo cấp số nhân của giá mark địa phương được thêm vào làm đầu vào thứ ba.

#### Quyền hạn {#permissions}

Cho HIP-3\*, `SubDeployerInput.variant` also accepts the objects shown below.

| Thao tác | Người triển khai | Trợ cấp nhân viên bán thời gian |
| ---------------------------------- | -------- | ---------------------------------------------------- |
| `modifyApproval` | có | `{ "hip3Star": "modifyApproval" }` |
| `modifyBackstopLiquidatorApproval` | có | `{ "hip3Star": "modifyBackstopLiquidatorApproval" }` |
| `setReduceOnly` | có | `{ "hip3Star": "setReduceOnly" }` |
| `cancel` | có | `{ "hip3Star": "cancel" }` |
| `cancelAll` | có | `{ "hip3Star": "cancelAll" }` |
| `order` | có | `{ "hip3Star": "order" }` |
| `sendAsset` | có | `{ "hip3Star": "sendAsset" }` |
| `setOracle` | có | `{ "hip3Star": "setOracle" }` |

Mỗi khoản trợ cấp chỉ bao gồm hoạt động của riêng nó.Ví dụ, khoản trợ cấp `modifyApproval` không cho phép `modifyBackstopLiquidatorApproval`, `setReduceOnly` hoặc `sendAsset`.Ngoài ra, khoản trợ cấp `"setOracle"` thông thường, bao gồm cả khoản được trao cho `oracleUpdater`, không cho phép hoạt động của ngôi sao `setOracle`.

### Trạng thái sao người dùng {#user-star-state}

Các `userStarState` info request returns a user's approval state on every HIP-3\* venue where the user has been approved. The state is `null` on venues that have since removed the user's approval.

```json
{ "type": "userStarState", "user": "0xUSER_A" }
```

```json
{
  "dexToState": {
    "test": {
      "isReduceOnly": false,
      "isBackstopLiquidatorDepositAllowed": true
    },
    "demo": null
  }
}
```