HIP-3 部署者操作
部署和运营由部署者部署的永续合约 dex 的 API 涉及以下 L1 操作:
// 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>;
};
在以下示例中,feeScale 即 SetDeployerFees 中的 scale 字段。假设正的普通用户费率为 1 个单位且为非对齐抵押品(x = y = 1)。userFeeToProtocol 和 userFeeToDeployer 是向用户收取的相应费用单位。
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 |
如何查询永续合约部署拍卖的状态,参见 https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-information-about-the-perp-deploy-auction。
Open interest caps
由部署者部署的永续合约市场受两类持仓上限(open interest cap)约束:名义上限(持仓绝对规模乘以标记价格之和)和规模上限(持仓绝对规模之和)。
名义持仓上限在 DEX 内所有资产的总持仓上执行,同时也在单资产级别执行。永续合约部署者可以为每个资产设置自定义持仓上限,详见 https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-3-deployer-actions。
以规模计的持仓上限仅在单资产级别执行。以规模计的持仓上限目前为每资产恒定的 1B,因此合理的默认做法是将 szDecimals 设置为使最小规模增量在初始标记价格下相当于 $1-10。
Backstop liquidator
后备清算者地址为 0x4000000000000000000000000000000000000000 + {dex_index}。例如,第一个 HIP-3 DEX 的后备清算者地址为 0x4000000000000000000000000000000000000001。
Node user clearinghouse states
节点标志 --write-user-clearinghouse-states <dex> 会将指定 HIP-3 DEX 的清算所状态按小时写入文件,路径为 ~/hl/data/dex_user_clearinghouse_states/hourly/<date>/<hour>,其中 date 为 YYYYMMDD。每行是一个 JSON 数组 [time, messages],其中 time 是区块时间,messages 要么是该 DEX 上所有用户的单个快照,要么是按用户区分的差分列表:
["2026-09-24T09:00:00.123", [{ "Snapshot": { "0xUSER_A": <clearinghouseState> } }]]
["2026-09-24T09:00:03.456", [{ "Diff": ["0xUSER_A", <clearinghouseState>] }]]
每个 <clearinghouseState> 的格式与该 DEX 的 clearinghouseState info 请求响应相同,以该交易场所的抵押品代币计价。它只计入用户在指定 DEX 上的状态,因此跨 DEX 共享的抵押品(例如通过用户抽象)不包含在内,且 liquidationPx 恒为 null。每个文件的第一行以及节点启动后写入的第一行是快照。其余各行包含清算所状态发生变化的用户的差分,且忽略 time:该场所每次预言机更新时会包含每一个这样的用户,而在发生成交、清算、资金费用支付或转入/转出该场所的划转时,只包含涉及的用户。
HIP-3* (testnet-only)
Star actions
创建 HIP-3 交易场所时,可以通过在 PerpDexSchemaInput 中设置 isStar: true 将其指定为 HIP-3*。该可选布尔值默认为 false。HIP-3* 在 HIP-3 规范之上启用了若干功能,包括许可名单和代理用户操作。
Operations
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 } };
{
"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— 由用户地址和应用于该用户的一个代理操作组成的二元组。setOracle— 更新预言机价格,如下文 Oracle 部分所述。
Proxy operations
modifyApproval—{ "modifyApproval": true }将用户加入许可名单,false则移除该用户并清除其标志。移除一个未被批准的用户是空操作(no-op)。重新批准一个已批准的用户是空操作并保留该用户的标志。被移除后再次获得批准的用户将从默认标志开始。modifyBackstopLiquidatorApproval—{ "modifyBackstopLiquidatorApproval": true }允许用户通过hip3LiquidatorTransfer向该场所的后备清算者充值和从中提币;false则撤销此权限。用户必须已通过modifyApproval获得批准。setReduceOnly—{ "setReduceOnly": true }将已批准的用户限制为只能在该场所减仓。该用户只能下只减仓订单和 TWAP、将订单改为只减仓订单以及撤单。{ "setReduceOnly": false }恢复完整交易权限。cancel—{ "cancel": { "cancels": [{ "a": <asset>, "o": <oid> }] } },即标准的cancelexchange action 负载。按 oid 撤销该用户的挂单。cancelAll—{ "cancelAll": { "assets": null } }撤销该用户在此场所的所有挂单和 TWAP。{ "cancelAll": { "assets": [<asset>, ...] } }仅撤销所列资产的挂单和 TWAP。列表必须包含 1-10 个条目。order—{ "order": { "orders": [...], "grouping": "na" } },即标准的orderexchange action 负载。每笔订单必须是只减仓订单("r": true)。sendAsset—{ "sendAsset": { "destination": "0xUSER_C", "amount": "100.0" } }。将抵押品从被代理用户在该 DEX 上的账户划转至destination在同一场所的账户。
Oracle
HIP-3* 场所通过 setOracle star 操作部署操作更新价格。oraclePxs 是按 key 排序的资产与现货预言机价格的列表。外部永续合约价格和标记价格根据部署者的现货预言机价格输入在链上推导得出。
- 外部永续合约价格根据主 dex 中同名的资产推导,计价单位换算为 USDC。例如,
test:BTC使用BTC的外部永续合约价格。 - 标记价格在链上按以下价格的中位数计算:
- 经中间价相对预言机价格的溢价指数移动平均调整后的预言机价格,
- 外部永续合约价格,以及
- 本地标记价格(最优买价、最优卖价、最近成交价的中位数)。
如果这三个价格中只有两个可用,则会加入本地标记价格的指数移动平均作为第三个输入。
Permissions
对于 HIP-3*,SubDeployerInput.variant 还接受下表所示的对象。
| Operation | Deployer | Sub-deployer grant |
|---|---|---|
modifyApproval |
yes | { "hip3Star": "modifyApproval" } |
modifyBackstopLiquidatorApproval |
yes | { "hip3Star": "modifyBackstopLiquidatorApproval" } |
setReduceOnly |
yes | { "hip3Star": "setReduceOnly" } |
cancel |
yes | { "hip3Star": "cancel" } |
cancelAll |
yes | { "hip3Star": "cancelAll" } |
order |
yes | { "hip3Star": "order" } |
sendAsset |
yes | { "hip3Star": "sendAsset" } |
setOracle |
yes | { "hip3Star": "setOracle" } |
每项授权仅覆盖其自身的操作。例如,modifyApproval 授权不允许 modifyBackstopLiquidatorApproval、setReduceOnly 或 sendAsset。同样,常规的 "setOracle" 授权(包括授予 oracleUpdater 的授权)不允许执行 setOracle star 操作。
User star state
userStarState info 请求返回用户在其已获批准的每个 HIP-3* 场所上的批准状态。对于此后已移除该用户批准的场所,状态为 null。
{ "type": "userStarState", "user": "0xUSER_A" }
{
"dexToState": {
"test": {
"isReduceOnly": false,
"isBackstopLiquidatorDepositAllowed": true
},
"demo": null
}
}