@continuumdao/ctm-mpc-defi 0.2.48 → 0.2.49

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.
Files changed (63) hide show
  1. package/dist/agent/catalog.cjs +1083 -4
  2. package/dist/agent/catalog.cjs.map +1 -1
  3. package/dist/agent/catalog.d.ts +1191 -7
  4. package/dist/agent/catalog.js +1047 -5
  5. package/dist/agent/catalog.js.map +1 -1
  6. package/dist/agent/skills/derive/SKILL.md +112 -0
  7. package/dist/agent/skills/hyperliquid/SKILL.md +22 -2
  8. package/dist/chains/evm/index.d.ts +118 -6
  9. package/dist/chains/near/index.d.ts +7 -1
  10. package/dist/chains/solana/index.d.ts +7 -1
  11. package/dist/core/index.cjs +2 -1
  12. package/dist/core/index.cjs.map +1 -1
  13. package/dist/core/index.d.ts +138 -7
  14. package/dist/core/index.js +2 -1
  15. package/dist/core/index.js.map +1 -1
  16. package/dist/index.cjs +2 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.ts +848 -16
  19. package/dist/index.js +2 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/protocols/evm/aave-v4/index.d.ts +600 -6
  22. package/dist/protocols/evm/aerodrome/index.cjs.map +1 -1
  23. package/dist/protocols/evm/aerodrome/index.d.ts +125 -5
  24. package/dist/protocols/evm/aerodrome/index.js.map +1 -1
  25. package/dist/protocols/evm/arcus/index.d.ts +66 -2
  26. package/dist/protocols/evm/circle-cctp/index.d.ts +71 -2
  27. package/dist/protocols/evm/compound-v3/index.d.ts +52 -1
  28. package/dist/protocols/evm/continuum-dao/index.d.ts +56 -1
  29. package/dist/protocols/evm/curve-dao/index.d.ts +66 -2
  30. package/dist/protocols/evm/derive/index.cjs +2655 -0
  31. package/dist/protocols/evm/derive/index.cjs.map +1 -0
  32. package/dist/protocols/evm/derive/index.d.ts +859 -0
  33. package/dist/protocols/evm/derive/index.js +2536 -0
  34. package/dist/protocols/evm/derive/index.js.map +1 -0
  35. package/dist/protocols/evm/ethena/index.d.ts +52 -1
  36. package/dist/protocols/evm/euler-v2/index.d.ts +115 -16
  37. package/dist/protocols/evm/gmx/index.d.ts +66 -2
  38. package/dist/protocols/evm/hyperliquid/index.cjs +545 -267
  39. package/dist/protocols/evm/hyperliquid/index.cjs.map +1 -1
  40. package/dist/protocols/evm/hyperliquid/index.d.ts +152 -7
  41. package/dist/protocols/evm/hyperliquid/index.js +535 -269
  42. package/dist/protocols/evm/hyperliquid/index.js.map +1 -1
  43. package/dist/protocols/evm/lido/index.d.ts +52 -1
  44. package/dist/protocols/evm/maple/index.d.ts +52 -1
  45. package/dist/protocols/evm/morpho/index.d.ts +115 -4
  46. package/dist/protocols/evm/pendle/index.cjs +2 -1
  47. package/dist/protocols/evm/pendle/index.cjs.map +1 -1
  48. package/dist/protocols/evm/pendle/index.d.ts +125 -5
  49. package/dist/protocols/evm/pendle/index.js +2 -1
  50. package/dist/protocols/evm/pendle/index.js.map +1 -1
  51. package/dist/protocols/evm/permit2/index.d.ts +14 -1
  52. package/dist/protocols/evm/sky/index.d.ts +52 -1
  53. package/dist/protocols/evm/uniswap-v4/index.d.ts +78 -4
  54. package/dist/protocols/evm/venice/index.d.ts +52 -1
  55. package/package.json +7 -2
  56. package/dist/buildBatch-tsEUVn_a.d.ts +0 -45
  57. package/dist/eip712Multisign-6oNIlObj.d.ts +0 -39
  58. package/dist/envelope-Cm-llShH.d.ts +0 -37
  59. package/dist/merklDistributor-CdqtZC9N.d.ts +0 -65
  60. package/dist/multisign-Dr0j9fHm.d.ts +0 -489
  61. package/dist/registry-BvsXh0-r.d.ts +0 -8
  62. package/dist/types-RJpoU4Pc.d.ts +0 -34
  63. package/dist/types-lIfv59N1.d.ts +0 -63
@@ -1,6 +1,6 @@
1
- import { parseAbi, encodeAbiParameters, keccak256, getAddress, parseUnits, encodeFunctionData, hashTypedData, defineChain, createPublicClient, parseGwei, serializeTransaction, stringToHex, http } from 'viem';
2
- import { fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
3
1
  import { encode } from '@msgpack/msgpack';
2
+ import { parseAbi, keccak256, encodeAbiParameters, getAddress, parseUnits, encodeFunctionData, hashTypedData, defineChain, createPublicClient, parseGwei, serializeTransaction, stringToHex, http } from 'viem';
3
+ import { fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
4
4
 
5
5
  // src/core/registry.ts
6
6
  var modules = [];
@@ -63,6 +63,340 @@ var HYPERLIQUID_MAX_CANDLE_LIMIT = 200;
63
63
  var HYPERLIQUID_MAX_OHLCV_BARS = 2e3;
64
64
  var HYPERLIQUID_DEFAULT_LOOKBACK_DAYS = 14;
65
65
  var HYPERLIQUID_MAX_LOOKBACK_DAYS = 90;
66
+ var EXCHANGE_DOMAIN = {
67
+ name: "Exchange",
68
+ version: "1",
69
+ chainId: 1337,
70
+ verifyingContract: "0x0000000000000000000000000000000000000000"
71
+ };
72
+ var AGENT_TYPES = {
73
+ Agent: [
74
+ { name: "source", type: "string" },
75
+ { name: "connectionId", type: "bytes32" }
76
+ ]
77
+ };
78
+ function adjustMsgpackValue(value) {
79
+ if (Array.isArray(value)) return value.map(adjustMsgpackValue);
80
+ if (typeof value === "object" && value !== null) {
81
+ const result = {};
82
+ for (const key of Object.keys(value)) {
83
+ const entry = value[key];
84
+ if (entry !== void 0) result[key] = adjustMsgpackValue(entry);
85
+ }
86
+ return result;
87
+ }
88
+ if (typeof value === "number" && Number.isInteger(value) && (value >= 4294967296 || value < -2147483648)) {
89
+ return BigInt(value);
90
+ }
91
+ return value;
92
+ }
93
+ function toUint64Bytes(n) {
94
+ const bytes = new Uint8Array(8);
95
+ new DataView(bytes.buffer).setBigUint64(0, BigInt(n));
96
+ return bytes;
97
+ }
98
+ function concatBytes(...parts) {
99
+ const total = parts.reduce((sum, p) => sum + p.length, 0);
100
+ const out = new Uint8Array(total);
101
+ let offset = 0;
102
+ for (const p of parts) {
103
+ out.set(p, offset);
104
+ offset += p.length;
105
+ }
106
+ return out;
107
+ }
108
+ function hexToBytes(hex) {
109
+ const h = hex.startsWith("0x") ? hex.slice(2) : hex;
110
+ const bytes = new Uint8Array(h.length / 2);
111
+ for (let i = 0; i < bytes.length; i++) {
112
+ bytes[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
113
+ }
114
+ return bytes;
115
+ }
116
+ function createHyperliquidL1ActionHash(args) {
117
+ const { action, nonce, vaultAddress, expiresAfter } = args;
118
+ const actionBytes = encode(adjustMsgpackValue(action));
119
+ const nonceBytes = toUint64Bytes(nonce);
120
+ const vaultMarker = vaultAddress ? new Uint8Array([1]) : new Uint8Array([0]);
121
+ const vaultBytes = vaultAddress ? hexToBytes(vaultAddress) : new Uint8Array();
122
+ const expiresMarker = expiresAfter !== void 0 ? new Uint8Array([0]) : new Uint8Array();
123
+ const expiresBytes = expiresAfter !== void 0 ? toUint64Bytes(expiresAfter) : new Uint8Array();
124
+ const bytes = concatBytes(actionBytes, nonceBytes, vaultMarker, vaultBytes, expiresMarker, expiresBytes);
125
+ return keccak256(bytes);
126
+ }
127
+ function buildHyperliquidAgentTypedData(args) {
128
+ const connectionId = createHyperliquidL1ActionHash(args);
129
+ const source = args.isTestnet ? "b" : "a";
130
+ return {
131
+ domain: EXCHANGE_DOMAIN,
132
+ types: AGENT_TYPES,
133
+ primaryType: "Agent",
134
+ message: {
135
+ source,
136
+ connectionId
137
+ },
138
+ connectionId,
139
+ nonce: args.nonce,
140
+ action: args.action
141
+ };
142
+ }
143
+ function buildHyperliquidUpdateLeverageAction(args) {
144
+ const leverage = Math.trunc(args.leverage);
145
+ if (!Number.isFinite(leverage) || leverage < 1) {
146
+ throw new Error("leverage must be a positive integer");
147
+ }
148
+ return {
149
+ type: "updateLeverage",
150
+ asset: args.asset,
151
+ isCross: args.isCross !== false,
152
+ leverage
153
+ };
154
+ }
155
+ function parseHyperliquidBorrowLendAmount(amountHuman) {
156
+ if (amountHuman == null) return null;
157
+ const trimmed = String(amountHuman).trim();
158
+ if (!trimmed || trimmed.toLowerCase() === "max") return null;
159
+ return hyperliquidFloatToWire(trimmed);
160
+ }
161
+ function buildHyperliquidBorrowLendAction(args) {
162
+ const operation = args.operation;
163
+ if (operation !== "supply" && operation !== "withdraw" && operation !== "repay" && operation !== "borrow") {
164
+ throw new Error("operation must be supply, withdraw, repay, or borrow");
165
+ }
166
+ const token = Math.trunc(args.token);
167
+ if (!Number.isFinite(token) || token < 0) {
168
+ throw new Error("token must be a non-negative integer token index");
169
+ }
170
+ return {
171
+ type: "borrowLend",
172
+ operation,
173
+ token,
174
+ amount: args.amount
175
+ };
176
+ }
177
+ function hyperliquidFloatToWire(value) {
178
+ const n = typeof value === "number" ? value : Number.parseFloat(String(value).trim());
179
+ if (!Number.isFinite(n)) throw new Error("Invalid Hyperliquid wire number.");
180
+ const rounded = n.toFixed(8);
181
+ if (Math.abs(Number.parseFloat(rounded) - n) >= 1e-12) {
182
+ throw new Error(`Hyperliquid wire value ${value} has too many decimal places.`);
183
+ }
184
+ const normalized = Number(rounded === "-0" ? "0" : rounded);
185
+ return String(normalized);
186
+ }
187
+ function hyperliquidL1TifFromKey(tif) {
188
+ const key = String(tif ?? "gtc").trim().toLowerCase();
189
+ if (key === "alo") return "Alo";
190
+ if (key === "ioc") return "Ioc";
191
+ if (key === "gtc") return "Gtc";
192
+ throw new Error(`Unknown time-in-force: ${tif}. Use alo, gtc, or ioc.`);
193
+ }
194
+ function buildHyperliquidLimitOrderWire(args) {
195
+ return {
196
+ a: args.asset,
197
+ b: args.isBuy,
198
+ p: hyperliquidFloatToWire(args.limitPxHuman),
199
+ s: hyperliquidFloatToWire(args.szHuman),
200
+ r: Boolean(args.reduceOnly),
201
+ t: { limit: { tif: hyperliquidL1TifFromKey(args.tif) } }
202
+ };
203
+ }
204
+ function buildHyperliquidTriggerOrderWire(args) {
205
+ const mode = args.tpslExecMode ?? "limit_at_trigger";
206
+ const triggerPx = hyperliquidFloatToWire(args.triggerPxHuman);
207
+ const limitPx = mode === "market" ? triggerPx : hyperliquidFloatToWire(args.limitPxHuman ?? args.triggerPxHuman);
208
+ return {
209
+ a: args.asset,
210
+ b: args.isBuy,
211
+ p: limitPx,
212
+ s: hyperliquidFloatToWire(args.szHuman),
213
+ r: true,
214
+ t: {
215
+ trigger: {
216
+ isMarket: mode === "market",
217
+ triggerPx,
218
+ tpsl: args.tpsl
219
+ }
220
+ }
221
+ };
222
+ }
223
+ function validateHyperliquidTpslGeometry(args) {
224
+ const entry = Number.parseFloat(String(args.entryPxHuman).trim());
225
+ const tp = args.takeProfitTriggerPxHuman?.trim() != null && args.takeProfitTriggerPxHuman.trim() !== "" ? Number.parseFloat(args.takeProfitTriggerPxHuman.trim()) : null;
226
+ const sl = args.stopLossTriggerPxHuman?.trim() != null && args.stopLossTriggerPxHuman.trim() !== "" ? Number.parseFloat(args.stopLossTriggerPxHuman.trim()) : null;
227
+ if (!Number.isFinite(entry)) throw new Error("Invalid entry limit price for TP/SL validation.");
228
+ if (tp != null && !Number.isFinite(tp)) throw new Error("Invalid take-profit trigger price.");
229
+ if (sl != null && !Number.isFinite(sl)) throw new Error("Invalid stop-loss trigger price.");
230
+ if (args.isBuy) {
231
+ if (sl != null && sl >= entry) {
232
+ throw new Error("Long stop-loss must be below entry price.");
233
+ }
234
+ if (tp != null && tp <= entry) {
235
+ throw new Error("Long take-profit must be above entry price.");
236
+ }
237
+ } else {
238
+ if (sl != null && sl <= entry) {
239
+ throw new Error("Short stop-loss must be above entry price.");
240
+ }
241
+ if (tp != null && tp >= entry) {
242
+ throw new Error("Short take-profit must be below entry price.");
243
+ }
244
+ }
245
+ }
246
+ function buildHyperliquidNormalTpslOrderWires(args) {
247
+ validateHyperliquidTpslGeometry({
248
+ isBuy: args.isBuy,
249
+ entryPxHuman: args.limitPxHuman,
250
+ takeProfitTriggerPxHuman: args.takeProfitTriggerPxHuman,
251
+ stopLossTriggerPxHuman: args.stopLossTriggerPxHuman
252
+ });
253
+ const orders = [
254
+ buildHyperliquidLimitOrderWire({
255
+ asset: args.asset,
256
+ isBuy: args.isBuy,
257
+ limitPxHuman: args.limitPxHuman,
258
+ szHuman: args.szHuman,
259
+ tif: args.tif
260
+ })
261
+ ];
262
+ const closeIsBuy = !args.isBuy;
263
+ const tp = args.takeProfitTriggerPxHuman?.trim();
264
+ const sl = args.stopLossTriggerPxHuman?.trim();
265
+ if (tp) {
266
+ orders.push(
267
+ buildHyperliquidTriggerOrderWire({
268
+ asset: args.asset,
269
+ isBuy: closeIsBuy,
270
+ szHuman: args.szHuman,
271
+ triggerPxHuman: tp,
272
+ tpsl: "tp",
273
+ tpslExecMode: args.tpslExecMode
274
+ })
275
+ );
276
+ }
277
+ if (sl) {
278
+ orders.push(
279
+ buildHyperliquidTriggerOrderWire({
280
+ asset: args.asset,
281
+ isBuy: closeIsBuy,
282
+ szHuman: args.szHuman,
283
+ triggerPxHuman: sl,
284
+ tpsl: "sl",
285
+ tpslExecMode: args.tpslExecMode
286
+ })
287
+ );
288
+ }
289
+ return orders;
290
+ }
291
+ function buildHyperliquidOrderAction(args) {
292
+ return {
293
+ type: "order",
294
+ orders: args.orders,
295
+ grouping: args.grouping ?? "na"
296
+ };
297
+ }
298
+ var TRAILING_PCT_DECIMALS = 4;
299
+ function parseHyperliquidTrailingOffsetType(value) {
300
+ const key = String(value ?? "percentage").trim().toLowerCase();
301
+ if (key === "price" || key === "px" || key === "distance") return "price";
302
+ if (key === "percentage" || key === "percent" || key === "pct" || key === "%") return "percentage";
303
+ throw new Error("trailingOffsetType must be price or percentage.");
304
+ }
305
+ function hyperliquidTrailingPercentToWire(value) {
306
+ const raw = typeof value === "number" ? String(value) : String(value).trim();
307
+ const stripped = raw.endsWith("%") ? raw.slice(0, -1).trim() : raw;
308
+ const n = Number.parseFloat(stripped);
309
+ if (!Number.isFinite(n) || n <= 0) {
310
+ throw new Error("Trailing retracement percentage must be greater than zero.");
311
+ }
312
+ return `${n.toFixed(TRAILING_PCT_DECIMALS)}%`;
313
+ }
314
+ function buildHyperliquidTrailingRetracement(args) {
315
+ const offset = String(args.offsetHuman ?? "").trim();
316
+ if (!offset) throw new Error("trailingOffsetHuman is required.");
317
+ if (args.offsetType === "percentage") {
318
+ return { pct: hyperliquidTrailingPercentToWire(offset) };
319
+ }
320
+ const px = hyperliquidFloatToWire(offset);
321
+ if (Number.parseFloat(px) <= 0) {
322
+ throw new Error("Trailing retracement distance must be greater than zero.");
323
+ }
324
+ return { px };
325
+ }
326
+ var HYPERLIQUID_TRAILING_ACTIVATION_PX_ERROR = "Invalid trailing activation price.";
327
+ var POSITIVE_DECIMAL_RE = /^\d+(\.\d+)?$/;
328
+ function parseHyperliquidTrailingActivationPx(value) {
329
+ if (value == null) return null;
330
+ const raw = String(value).trim().replace(/,/g, "");
331
+ if (!raw) return null;
332
+ if (!POSITIVE_DECIMAL_RE.test(raw)) {
333
+ throw new Error(HYPERLIQUID_TRAILING_ACTIVATION_PX_ERROR);
334
+ }
335
+ const px = Number.parseFloat(raw);
336
+ if (!Number.isFinite(px) || px <= 0) {
337
+ throw new Error(HYPERLIQUID_TRAILING_ACTIVATION_PX_ERROR);
338
+ }
339
+ hyperliquidFloatToWire(raw);
340
+ return raw;
341
+ }
342
+ function isHyperliquidTrailingActivationPxHuman(value) {
343
+ try {
344
+ parseHyperliquidTrailingActivationPx(value);
345
+ return true;
346
+ } catch {
347
+ return false;
348
+ }
349
+ }
350
+ function validateHyperliquidTrailingStopParams(args) {
351
+ buildHyperliquidTrailingRetracement({
352
+ offsetType: args.offsetType,
353
+ offsetHuman: args.offsetHuman
354
+ });
355
+ parseHyperliquidTrailingActivationPx(args.activationPxHuman);
356
+ }
357
+ function parseHyperliquidTrailingStopParams(args) {
358
+ const offset = args.trailingOffsetHuman?.trim();
359
+ if (!offset) return null;
360
+ const params = {
361
+ offsetType: parseHyperliquidTrailingOffsetType(args.trailingOffsetType),
362
+ offsetHuman: offset,
363
+ activationPxHuman: args.trailingActivationPxHuman?.trim() || void 0
364
+ };
365
+ validateHyperliquidTrailingStopParams(params);
366
+ return params;
367
+ }
368
+ function buildHyperliquidTrailingStopAction(args) {
369
+ const asset = Math.trunc(args.asset);
370
+ if (!Number.isFinite(asset) || asset < 0) {
371
+ throw new Error("asset must be a non-negative integer.");
372
+ }
373
+ const retracement = buildHyperliquidTrailingRetracement({
374
+ offsetType: args.offsetType,
375
+ offsetHuman: args.offsetHuman
376
+ });
377
+ const activation = parseHyperliquidTrailingActivationPx(args.activationPxHuman);
378
+ return {
379
+ type: "trailingStop",
380
+ asset,
381
+ isBuy: Boolean(args.isBuy),
382
+ sz: hyperliquidFloatToWire(args.szHuman),
383
+ reduceOnly: Boolean(args.reduceOnly),
384
+ retracement,
385
+ activationPx: activation ? hyperliquidFloatToWire(activation) : null
386
+ };
387
+ }
388
+ function parseHyperliquidTrailingTriggerCondition(triggerCondition) {
389
+ const text = String(triggerCondition ?? "").trim();
390
+ if (!text) return null;
391
+ const retracement = text.match(/(?:^|,\s*)retracement\s+([^,]+)/i)?.[1]?.trim();
392
+ if (!retracement) return null;
393
+ const activationRaw = text.match(/(?:^|,\s*)activation\s+(?:above|below)\s+([^,]+)/i)?.[1]?.trim();
394
+ const bestMatch = text.match(/(?:^|,\s*)best\s+([^,]+)/i);
395
+ const bestRaw = bestMatch?.[1]?.trim();
396
+ const bestPx = bestRaw && bestRaw.toLowerCase() !== "waiting" && Number.isFinite(Number.parseFloat(bestRaw)) ? bestRaw : null;
397
+ const activationPx = activationRaw && Number.isFinite(Number.parseFloat(activationRaw)) ? activationRaw : null;
398
+ return { retracement, activationPx, bestPx };
399
+ }
66
400
 
67
401
  // src/protocols/evm/hyperliquid/api.ts
68
402
  async function hyperliquidInfoPost(chainId, body) {
@@ -341,6 +675,12 @@ async function hyperliquidFetchActiveAssetData(args) {
341
675
  }
342
676
  };
343
677
  }
678
+ function enrichHyperliquidFrontendOpenOrder(order) {
679
+ const parsed = order.trailingStop ?? parseHyperliquidTrailingTriggerCondition(order.triggerCondition);
680
+ const looksTrailing = parsed != null || String(order.orderType ?? "").toLowerCase().includes("trailing");
681
+ if (!looksTrailing) return order;
682
+ return { ...order, trailingStop: parsed ?? order.trailingStop ?? null };
683
+ }
344
684
  async function hyperliquidFetchOpenOrders(args) {
345
685
  const req = { type: "openOrders", user: args.user };
346
686
  if (args.dex?.trim()) req.dex = args.dex.trim();
@@ -351,7 +691,7 @@ async function hyperliquidFetchFrontendOpenOrders(args) {
351
691
  const req = { type: "frontendOpenOrders", user: args.user };
352
692
  if (args.dex?.trim()) req.dex = args.dex.trim();
353
693
  const orders = await hyperliquidInfoPost(args.chainId, req);
354
- return { orders: orders ?? [] };
694
+ return { orders: (orders ?? []).map(enrichHyperliquidFrontendOpenOrder) };
355
695
  }
356
696
  async function hyperliquidFetchUserVaultEquities(args) {
357
697
  const rows = await hyperliquidInfoPost(args.chainId, {
@@ -820,7 +1160,7 @@ async function hyperliquidFetchPositionDisplayRows(args) {
820
1160
  return { rows };
821
1161
  }
822
1162
  async function hyperliquidFetchOrdersForExecutor(args) {
823
- return hyperliquidFetchOpenOrders({
1163
+ return hyperliquidFetchFrontendOpenOrders({
824
1164
  chainId: args.chainId,
825
1165
  user: args.executorAddress.trim().toLowerCase(),
826
1166
  dex: args.dex
@@ -1505,308 +1845,203 @@ function buildEip712Multisign(args) {
1505
1845
  legs
1506
1846
  });
1507
1847
  }
1508
- var EXCHANGE_DOMAIN = {
1509
- name: "Exchange",
1510
- version: "1",
1511
- chainId: 1337,
1512
- verifyingContract: "0x0000000000000000000000000000000000000000"
1513
- };
1514
- var AGENT_TYPES = {
1515
- Agent: [
1516
- { name: "source", type: "string" },
1517
- { name: "connectionId", type: "bytes32" }
1518
- ]
1519
- };
1520
- function adjustMsgpackValue(value) {
1521
- if (Array.isArray(value)) return value.map(adjustMsgpackValue);
1522
- if (typeof value === "object" && value !== null) {
1523
- const result = {};
1524
- for (const key of Object.keys(value)) {
1525
- const entry = value[key];
1526
- if (entry !== void 0) result[key] = adjustMsgpackValue(entry);
1527
- }
1528
- return result;
1529
- }
1530
- if (typeof value === "number" && Number.isInteger(value) && (value >= 4294967296 || value < -2147483648)) {
1531
- return BigInt(value);
1532
- }
1533
- return value;
1534
- }
1535
- function toUint64Bytes(n) {
1536
- const bytes = new Uint8Array(8);
1537
- new DataView(bytes.buffer).setBigUint64(0, BigInt(n));
1538
- return bytes;
1539
- }
1540
- function concatBytes(...parts) {
1541
- const total = parts.reduce((sum, p) => sum + p.length, 0);
1542
- const out = new Uint8Array(total);
1543
- let offset = 0;
1544
- for (const p of parts) {
1545
- out.set(p, offset);
1546
- offset += p.length;
1547
- }
1548
- return out;
1549
- }
1550
- function hexToBytes(hex) {
1551
- const h = hex.startsWith("0x") ? hex.slice(2) : hex;
1552
- const bytes = new Uint8Array(h.length / 2);
1553
- for (let i = 0; i < bytes.length; i++) {
1554
- bytes[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
1555
- }
1556
- return bytes;
1557
- }
1558
- function createHyperliquidL1ActionHash(args) {
1559
- const { action, nonce, vaultAddress, expiresAfter } = args;
1560
- const actionBytes = encode(adjustMsgpackValue(action));
1561
- const nonceBytes = toUint64Bytes(nonce);
1562
- const vaultMarker = vaultAddress ? new Uint8Array([1]) : new Uint8Array([0]);
1563
- const vaultBytes = vaultAddress ? hexToBytes(vaultAddress) : new Uint8Array();
1564
- const expiresMarker = expiresAfter !== void 0 ? new Uint8Array([0]) : new Uint8Array();
1565
- const expiresBytes = expiresAfter !== void 0 ? toUint64Bytes(expiresAfter) : new Uint8Array();
1566
- const bytes = concatBytes(actionBytes, nonceBytes, vaultMarker, vaultBytes, expiresMarker, expiresBytes);
1567
- return keccak256(bytes);
1568
- }
1569
- function buildHyperliquidAgentTypedData(args) {
1570
- const connectionId = createHyperliquidL1ActionHash(args);
1571
- const source = args.isTestnet ? "b" : "a";
1572
- return {
1573
- domain: EXCHANGE_DOMAIN,
1574
- types: AGENT_TYPES,
1575
- primaryType: "Agent",
1576
- message: {
1577
- source,
1578
- connectionId
1579
- },
1580
- connectionId,
1848
+
1849
+ // src/protocols/evm/hyperliquid/exchangeMultisign.ts
1850
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1851
+ function hyperliquidExchangeLeg(args) {
1852
+ const isTestnet = args.chainId === 998;
1853
+ const typed = buildHyperliquidAgentTypedData({
1854
+ action: args.action,
1581
1855
  nonce: args.nonce,
1582
- action: args.action
1583
- };
1584
- }
1585
- function buildHyperliquidUpdateLeverageAction(args) {
1586
- const leverage = Math.trunc(args.leverage);
1587
- if (!Number.isFinite(leverage) || leverage < 1) {
1588
- throw new Error("leverage must be a positive integer");
1589
- }
1856
+ isTestnet
1857
+ });
1590
1858
  return {
1591
- type: "updateLeverage",
1592
- asset: args.asset,
1593
- isCross: args.isCross !== false,
1594
- leverage
1859
+ typedData: {
1860
+ domain: typed.domain,
1861
+ types: typed.types,
1862
+ primaryType: typed.primaryType,
1863
+ message: typed.message
1864
+ },
1865
+ delivery: {
1866
+ kind: "hyperliquid_exchange",
1867
+ chainId: args.chainId,
1868
+ isTestnet,
1869
+ action: args.action,
1870
+ nonce: args.nonce
1871
+ },
1872
+ audit: {
1873
+ ...args.audit,
1874
+ nonce: args.nonce,
1875
+ connectionId: typed.connectionId
1876
+ }
1595
1877
  };
1596
1878
  }
1597
- function parseHyperliquidBorrowLendAmount(amountHuman) {
1598
- if (amountHuman == null) return null;
1599
- const trimmed = String(amountHuman).trim();
1600
- if (!trimmed || trimmed.toLowerCase() === "max") return null;
1601
- return hyperliquidFloatToWire(trimmed);
1879
+ function resolveTrailingForLimit(args) {
1880
+ return parseHyperliquidTrailingStopParams({
1881
+ trailingOffsetHuman: args.trailingOffsetHuman,
1882
+ trailingOffsetType: args.trailingOffsetType,
1883
+ trailingActivationPxHuman: args.trailingActivationPxHuman
1884
+ });
1602
1885
  }
1603
- function buildHyperliquidBorrowLendAction(args) {
1604
- const operation = args.operation;
1605
- if (operation !== "supply" && operation !== "withdraw" && operation !== "repay" && operation !== "borrow") {
1606
- throw new Error("operation must be supply, withdraw, repay, or borrow");
1607
- }
1608
- const token = Math.trunc(args.token);
1609
- if (!Number.isFinite(token) || token < 0) {
1610
- throw new Error("token must be a non-negative integer token index");
1886
+ async function buildHyperliquidLimitOrderWithTpslMultisign(args) {
1887
+ const marketKind = args.marketKind ?? "perp";
1888
+ const trailing = resolveTrailingForLimit(args);
1889
+ const tp = args.takeProfitTriggerPxHuman?.trim();
1890
+ const sl = args.stopLossTriggerPxHuman?.trim();
1891
+ if (trailing && sl) {
1892
+ throw new Error("Cannot combine a trailing stop with a fixed stopLossTriggerPxHuman.");
1611
1893
  }
1612
- return {
1613
- type: "borrowLend",
1614
- operation,
1615
- token,
1616
- amount: args.amount
1617
- };
1618
- }
1619
- function hyperliquidFloatToWire(value) {
1620
- const n = typeof value === "number" ? value : Number.parseFloat(String(value).trim());
1621
- if (!Number.isFinite(n)) throw new Error("Invalid Hyperliquid wire number.");
1622
- const rounded = n.toFixed(8);
1623
- if (Math.abs(Number.parseFloat(rounded) - n) >= 1e-12) {
1624
- throw new Error(`Hyperliquid wire value ${value} has too many decimal places.`);
1894
+ if (!tp && !sl && !trailing) {
1895
+ throw new Error(
1896
+ "At least one of takeProfitTriggerPxHuman, stopLossTriggerPxHuman, or trailingOffsetHuman is required for L1 bracket orders."
1897
+ );
1625
1898
  }
1626
- const normalized = Number(rounded === "-0" ? "0" : rounded);
1627
- return String(normalized);
1628
- }
1629
- function hyperliquidL1TifFromKey(tif) {
1630
- const key = String(tif ?? "gtc").trim().toLowerCase();
1631
- if (key === "alo") return "Alo";
1632
- if (key === "ioc") return "Ioc";
1633
- if (key === "gtc") return "Gtc";
1634
- throw new Error(`Unknown time-in-force: ${tif}. Use alo, gtc, or ioc.`);
1635
- }
1636
- function buildHyperliquidLimitOrderWire(args) {
1637
- return {
1638
- a: args.asset,
1639
- b: args.isBuy,
1640
- p: hyperliquidFloatToWire(args.limitPxHuman),
1641
- s: hyperliquidFloatToWire(args.szHuman),
1642
- r: Boolean(args.reduceOnly),
1643
- t: { limit: { tif: hyperliquidL1TifFromKey(args.tif) } }
1644
- };
1645
- }
1646
- function buildHyperliquidTriggerOrderWire(args) {
1647
- const mode = args.tpslExecMode ?? "limit_at_trigger";
1648
- const triggerPx = hyperliquidFloatToWire(args.triggerPxHuman);
1649
- const limitPx = mode === "market" ? triggerPx : hyperliquidFloatToWire(args.limitPxHuman ?? args.triggerPxHuman);
1650
- return {
1651
- a: args.asset,
1652
- b: args.isBuy,
1653
- p: limitPx,
1654
- s: hyperliquidFloatToWire(args.szHuman),
1655
- r: true,
1656
- t: {
1657
- trigger: {
1658
- isMarket: mode === "market",
1659
- triggerPx,
1660
- tpsl: args.tpsl
1661
- }
1662
- }
1663
- };
1664
- }
1665
- function validateHyperliquidTpslGeometry(args) {
1666
- const entry = Number.parseFloat(String(args.entryPxHuman).trim());
1667
- const tp = args.takeProfitTriggerPxHuman?.trim() != null && args.takeProfitTriggerPxHuman.trim() !== "" ? Number.parseFloat(args.takeProfitTriggerPxHuman.trim()) : null;
1668
- const sl = args.stopLossTriggerPxHuman?.trim() != null && args.stopLossTriggerPxHuman.trim() !== "" ? Number.parseFloat(args.stopLossTriggerPxHuman.trim()) : null;
1669
- if (!Number.isFinite(entry)) throw new Error("Invalid entry limit price for TP/SL validation.");
1670
- if (tp != null && !Number.isFinite(tp)) throw new Error("Invalid take-profit trigger price.");
1671
- if (sl != null && !Number.isFinite(sl)) throw new Error("Invalid stop-loss trigger price.");
1672
- if (args.isBuy) {
1673
- if (sl != null && sl >= entry) {
1674
- throw new Error("Long stop-loss must be below entry price.");
1675
- }
1676
- if (tp != null && tp <= entry) {
1677
- throw new Error("Long take-profit must be above entry price.");
1678
- }
1679
- } else {
1680
- if (sl != null && sl <= entry) {
1681
- throw new Error("Short stop-loss must be above entry price.");
1682
- }
1683
- if (tp != null && tp >= entry) {
1684
- throw new Error("Short take-profit must be below entry price.");
1685
- }
1899
+ if (trailing && marketKind !== "perp") {
1900
+ throw new Error("Trailing stops are available for perp markets only.");
1686
1901
  }
1687
- }
1688
- function buildHyperliquidNormalTpslOrderWires(args) {
1689
- validateHyperliquidTpslGeometry({
1690
- isBuy: args.isBuy,
1691
- entryPxHuman: args.limitPxHuman,
1692
- takeProfitTriggerPxHuman: args.takeProfitTriggerPxHuman,
1693
- stopLossTriggerPxHuman: args.stopLossTriggerPxHuman
1902
+ const { asset } = await hyperliquidResolveAsset({
1903
+ chainId: args.chainId,
1904
+ coin: args.coin,
1905
+ marketKind,
1906
+ dex: args.dex
1694
1907
  });
1695
- const orders = [
1908
+ const hasFixedTpsl = Boolean(tp || sl);
1909
+ const orderWires = hasFixedTpsl ? buildHyperliquidNormalTpslOrderWires({
1910
+ asset,
1911
+ isBuy: args.isBuy,
1912
+ limitPxHuman: args.limitPxHuman,
1913
+ szHuman: args.szHuman,
1914
+ tif: args.tif,
1915
+ takeProfitTriggerPxHuman: tp || void 0,
1916
+ stopLossTriggerPxHuman: sl || void 0,
1917
+ tpslExecMode: args.tpslExecMode
1918
+ }) : [
1696
1919
  buildHyperliquidLimitOrderWire({
1697
- asset: args.asset,
1920
+ asset,
1698
1921
  isBuy: args.isBuy,
1699
1922
  limitPxHuman: args.limitPxHuman,
1700
1923
  szHuman: args.szHuman,
1701
1924
  tif: args.tif
1702
1925
  })
1703
1926
  ];
1704
- const closeIsBuy = !args.isBuy;
1705
- const tp = args.takeProfitTriggerPxHuman?.trim();
1706
- const sl = args.stopLossTriggerPxHuman?.trim();
1707
- if (tp) {
1708
- orders.push(
1709
- buildHyperliquidTriggerOrderWire({
1710
- asset: args.asset,
1711
- isBuy: closeIsBuy,
1712
- szHuman: args.szHuman,
1713
- triggerPxHuman: tp,
1714
- tpsl: "tp",
1715
- tpslExecMode: args.tpslExecMode
1716
- })
1717
- );
1718
- }
1719
- if (sl) {
1720
- orders.push(
1721
- buildHyperliquidTriggerOrderWire({
1722
- asset: args.asset,
1723
- isBuy: closeIsBuy,
1927
+ const grouping = hasFixedTpsl ? "normalTpsl" : "na";
1928
+ const orderAction = buildHyperliquidOrderAction({
1929
+ orders: orderWires,
1930
+ grouping
1931
+ });
1932
+ const nonce = args.nonce ?? Date.now();
1933
+ const legs = [
1934
+ hyperliquidExchangeLeg({
1935
+ action: orderAction,
1936
+ nonce,
1937
+ chainId: args.chainId,
1938
+ audit: {
1939
+ protocol: "hyperliquid",
1940
+ action: hasFixedTpsl ? "limitOrderWithTpsl" : "limitOrderWithTrailingStop",
1941
+ coin: args.coin,
1942
+ marketKind,
1943
+ asset,
1944
+ isBuy: args.isBuy,
1945
+ limitPxHuman: args.limitPxHuman,
1724
1946
  szHuman: args.szHuman,
1725
- triggerPxHuman: sl,
1726
- tpsl: "sl",
1727
- tpslExecMode: args.tpslExecMode
1947
+ takeProfitTriggerPxHuman: tp ?? null,
1948
+ stopLossTriggerPxHuman: sl ?? null,
1949
+ tpslExecMode: hasFixedTpsl ? args.tpslExecMode ?? "limit_at_trigger" : null,
1950
+ grouping,
1951
+ trailingOffsetHuman: trailing?.offsetHuman ?? null,
1952
+ trailingOffsetType: trailing?.offsetType ?? null,
1953
+ trailingActivationPxHuman: trailing?.activationPxHuman ?? null
1954
+ }
1955
+ })
1956
+ ];
1957
+ if (trailing) {
1958
+ const trailingAction = buildHyperliquidTrailingStopAction({
1959
+ asset,
1960
+ isBuy: !args.isBuy,
1961
+ szHuman: args.szHuman,
1962
+ reduceOnly: true,
1963
+ offsetType: trailing.offsetType,
1964
+ offsetHuman: trailing.offsetHuman,
1965
+ activationPxHuman: trailing.activationPxHuman
1966
+ });
1967
+ legs.push(
1968
+ hyperliquidExchangeLeg({
1969
+ action: trailingAction,
1970
+ nonce: nonce + 1,
1971
+ chainId: args.chainId,
1972
+ audit: {
1973
+ protocol: "hyperliquid",
1974
+ action: "trailingStop",
1975
+ coin: args.coin,
1976
+ marketKind,
1977
+ asset,
1978
+ isBuy: trailingAction.isBuy,
1979
+ szHuman: args.szHuman,
1980
+ reduceOnly: true,
1981
+ trailingOffsetHuman: trailing.offsetHuman,
1982
+ trailingOffsetType: trailing.offsetType,
1983
+ trailingActivationPxHuman: trailing.activationPxHuman ?? null
1984
+ }
1728
1985
  })
1729
1986
  );
1730
1987
  }
1731
- return orders;
1732
- }
1733
- function buildHyperliquidOrderAction(args) {
1734
- return {
1735
- type: "order",
1736
- orders: args.orders,
1737
- grouping: args.grouping ?? "na"
1738
- };
1988
+ return buildEip712Multisign({
1989
+ keyGen: args.keyGen,
1990
+ purposeText: args.purposeText,
1991
+ destinationChainID: String(args.chainId),
1992
+ destinationAddress: ZERO_ADDRESS,
1993
+ legs
1994
+ });
1739
1995
  }
1740
-
1741
- // src/protocols/evm/hyperliquid/exchangeMultisign.ts
1742
- var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1743
- async function buildHyperliquidLimitOrderWithTpslMultisign(args) {
1744
- const marketKind = args.marketKind ?? "perp";
1996
+ async function buildHyperliquidTrailingStopMultisign(args) {
1997
+ const trailing = parseHyperliquidTrailingStopParams({
1998
+ trailingOffsetHuman: args.trailingOffsetHuman,
1999
+ trailingOffsetType: args.trailingOffsetType,
2000
+ trailingActivationPxHuman: args.trailingActivationPxHuman
2001
+ });
2002
+ if (!trailing) {
2003
+ throw new Error("trailingOffsetHuman is required for a trailing stop.");
2004
+ }
1745
2005
  const { asset } = await hyperliquidResolveAsset({
1746
2006
  chainId: args.chainId,
1747
2007
  coin: args.coin,
1748
- marketKind,
2008
+ marketKind: "perp",
1749
2009
  dex: args.dex
1750
2010
  });
1751
- const tp = args.takeProfitTriggerPxHuman?.trim();
1752
- const sl = args.stopLossTriggerPxHuman?.trim();
1753
- if (!tp && !sl) {
1754
- throw new Error("At least one of takeProfitTriggerPxHuman or stopLossTriggerPxHuman is required for bracket orders.");
1755
- }
1756
- const orderWires = buildHyperliquidNormalTpslOrderWires({
2011
+ const action = buildHyperliquidTrailingStopAction({
1757
2012
  asset,
1758
2013
  isBuy: args.isBuy,
1759
- limitPxHuman: args.limitPxHuman,
1760
2014
  szHuman: args.szHuman,
1761
- tif: args.tif,
1762
- takeProfitTriggerPxHuman: tp || void 0,
1763
- stopLossTriggerPxHuman: sl || void 0,
1764
- tpslExecMode: args.tpslExecMode
1765
- });
1766
- const action = buildHyperliquidOrderAction({
1767
- orders: orderWires,
1768
- grouping: "normalTpsl"
2015
+ reduceOnly: args.reduceOnly !== false,
2016
+ offsetType: trailing.offsetType,
2017
+ offsetHuman: trailing.offsetHuman,
2018
+ activationPxHuman: trailing.activationPxHuman
1769
2019
  });
1770
2020
  const nonce = args.nonce ?? Date.now();
1771
- const isTestnet = args.chainId === 998;
1772
- const typed = buildHyperliquidAgentTypedData({ action, nonce, isTestnet });
1773
2021
  return buildEip712Multisign({
1774
2022
  keyGen: args.keyGen,
1775
2023
  purposeText: args.purposeText,
1776
2024
  destinationChainID: String(args.chainId),
1777
2025
  destinationAddress: ZERO_ADDRESS,
1778
2026
  legs: [
1779
- {
1780
- typedData: {
1781
- domain: typed.domain,
1782
- types: typed.types,
1783
- primaryType: typed.primaryType,
1784
- message: typed.message
1785
- },
1786
- delivery: {
1787
- kind: "hyperliquid_exchange",
1788
- chainId: args.chainId,
1789
- isTestnet,
1790
- action,
1791
- nonce
1792
- },
2027
+ hyperliquidExchangeLeg({
2028
+ action,
2029
+ nonce,
2030
+ chainId: args.chainId,
1793
2031
  audit: {
1794
2032
  protocol: "hyperliquid",
1795
- action: "limitOrderWithTpsl",
2033
+ action: "trailingStop",
1796
2034
  coin: args.coin,
1797
- marketKind,
2035
+ marketKind: "perp",
1798
2036
  asset,
1799
- isBuy: args.isBuy,
1800
- limitPxHuman: args.limitPxHuman,
2037
+ isBuy: action.isBuy,
1801
2038
  szHuman: args.szHuman,
1802
- takeProfitTriggerPxHuman: tp ?? null,
1803
- stopLossTriggerPxHuman: sl ?? null,
1804
- tpslExecMode: args.tpslExecMode ?? "limit_at_trigger",
1805
- grouping: "normalTpsl",
1806
- nonce,
1807
- connectionId: typed.connectionId
2039
+ reduceOnly: action.reduceOnly,
2040
+ trailingOffsetHuman: trailing.offsetHuman,
2041
+ trailingOffsetType: trailing.offsetType,
2042
+ trailingActivationPxHuman: trailing.activationPxHuman ?? null
1808
2043
  }
1809
- }
2044
+ })
1810
2045
  ]
1811
2046
  });
1812
2047
  }
@@ -1915,7 +2150,9 @@ async function buildHyperliquidBorrowLendMultisign(args) {
1915
2150
 
1916
2151
  // src/protocols/evm/hyperliquid/multisign.ts
1917
2152
  function hasHyperliquidBracketTpsl(args) {
1918
- return Boolean(args.takeProfitTriggerPxHuman?.trim() || args.stopLossTriggerPxHuman?.trim());
2153
+ return Boolean(
2154
+ args.takeProfitTriggerPxHuman?.trim() || args.stopLossTriggerPxHuman?.trim() || args.trailingOffsetHuman?.trim()
2155
+ );
1919
2156
  }
1920
2157
  async function buildCoreWriterMultisign(common, data, signatureMeta) {
1921
2158
  const step = coreWriterStep(data);
@@ -1943,7 +2180,14 @@ async function buildCoreWriterMultisign(common, data, signatureMeta) {
1943
2180
  async function buildEvmMultisignBodyHyperliquidLimitOrderBatch(args) {
1944
2181
  if (hasHyperliquidBracketTpsl(args)) {
1945
2182
  if (args.reduceOnly) {
1946
- throw new Error("reduceOnly cannot be combined with takeProfitTriggerPxHuman or stopLossTriggerPxHuman.");
2183
+ throw new Error("reduceOnly cannot be combined with takeProfitTriggerPxHuman, stopLossTriggerPxHuman, or a trailing stop.");
2184
+ }
2185
+ if (args.trailingOffsetHuman?.trim()) {
2186
+ parseHyperliquidTrailingStopParams({
2187
+ trailingOffsetHuman: args.trailingOffsetHuman,
2188
+ trailingOffsetType: args.trailingOffsetType,
2189
+ trailingActivationPxHuman: args.trailingActivationPxHuman
2190
+ });
1947
2191
  }
1948
2192
  return buildHyperliquidLimitOrderWithTpslMultisign({
1949
2193
  keyGen: args.keyGen,
@@ -1958,7 +2202,10 @@ async function buildEvmMultisignBodyHyperliquidLimitOrderBatch(args) {
1958
2202
  tif: args.tif,
1959
2203
  takeProfitTriggerPxHuman: args.takeProfitTriggerPxHuman,
1960
2204
  stopLossTriggerPxHuman: args.stopLossTriggerPxHuman,
1961
- tpslExecMode: args.tpslExecMode
2205
+ tpslExecMode: args.tpslExecMode,
2206
+ trailingOffsetHuman: args.trailingOffsetHuman,
2207
+ trailingOffsetType: args.trailingOffsetType,
2208
+ trailingActivationPxHuman: args.trailingActivationPxHuman
1962
2209
  });
1963
2210
  }
1964
2211
  const marketKind = args.marketKind ?? "perp";
@@ -2322,7 +2569,7 @@ function hyperliquidOrderClosesPosition(position, orderSide) {
2322
2569
  return position.isLong ? side === "A" : side === "B";
2323
2570
  }
2324
2571
  function hyperliquidOrderCountsAsPendingClose(order) {
2325
- return Boolean(order.reduceOnly) || Boolean(order.isTrigger);
2572
+ return Boolean(order.reduceOnly) || Boolean(order.isTrigger) || Boolean(order.trailingStop) || String(order.orderType ?? "").toLowerCase().includes("trailing");
2326
2573
  }
2327
2574
  function hyperliquidPendingCloseForPosition(args) {
2328
2575
  const positionSize = parsePositiveSize(args.position.size);
@@ -2379,7 +2626,26 @@ var hyperliquidProtocolModule = {
2379
2626
  dex: { type: "string", required: false, description: "HIP-3 dex name when applicable" },
2380
2627
  takeProfitTriggerPxHuman: { type: "string", required: false, description: "TP trigger \u2014 enables L1 bracket with SL" },
2381
2628
  stopLossTriggerPxHuman: { type: "string", required: false, description: "SL trigger \u2014 enables L1 bracket with TP" },
2382
- tpslExecMode: { type: "string", required: false, description: "limit_at_trigger (default) or market" }
2629
+ tpslExecMode: { type: "string", required: false, description: "limit_at_trigger (default) or market" },
2630
+ trailingOffsetHuman: { type: "string", required: false, description: "Trailing retracement \u2014 EIP-712 trailingStop (cannot combine with SL)" },
2631
+ trailingOffsetType: { type: "string", required: false, description: "price or percentage" },
2632
+ trailingActivationPxHuman: { type: "string", required: false, description: "Optional activation mark price" }
2633
+ }
2634
+ },
2635
+ {
2636
+ id: "hyperliquid.trailingStop",
2637
+ protocolId: HYPERLIQUID_PROTOCOL_ID,
2638
+ chainCategory: "evm",
2639
+ description: "Place a Hyperliquid perp trailing stop via L1 trailingStop action (EIP-712 /exchange)",
2640
+ commonParams: ["keyGen", "purposeText"],
2641
+ params: {
2642
+ coin: { type: "string", required: true, description: "Perp coin" },
2643
+ isBuy: { type: "boolean", required: true, description: "false closes a long / opens a short" },
2644
+ szHuman: { type: "string", required: true, description: "Size in coin units" },
2645
+ trailingOffsetHuman: { type: "string", required: true, description: "Retracement distance or percent" },
2646
+ trailingOffsetType: { type: "string", required: false, description: "price or percentage (default)" },
2647
+ trailingActivationPxHuman: { type: "string", required: false, description: "Optional activation mark price" },
2648
+ reduceOnly: { type: "boolean", required: false, description: "true (default) reduces a position" }
2383
2649
  }
2384
2650
  },
2385
2651
  {
@@ -2532,6 +2798,6 @@ var hyperliquidProtocolModule = {
2532
2798
  };
2533
2799
  registerProtocolModule(hyperliquidProtocolModule);
2534
2800
 
2535
- export { HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID, HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID, HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS, HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC, HYPERLIQUID_CORE_WRITER_ADDRESS, HYPERLIQUID_CORE_WRITER_GAS_FALLBACK, HYPERLIQUID_DEFAULT_CANDLE_LIMIT, HYPERLIQUID_DEFAULT_LOOKBACK_DAYS, HYPERLIQUID_DEFAULT_OHLCV_INTERVAL, HYPERLIQUID_HLP_VAULT_ADDRESS, HYPERLIQUID_HYPEREVM_USDC_MAINNET, HYPERLIQUID_HYPEREVM_USDC_TESTNET, HYPERLIQUID_INTERVAL_MS, HYPERLIQUID_MAX_CANDLE_LIMIT, HYPERLIQUID_MAX_LOOKBACK_DAYS, HYPERLIQUID_MAX_OHLCV_BARS, HYPERLIQUID_PROTOCOL_ID, HYPERLIQUID_SPOT_ASSET_OFFSET, HYPERLIQUID_SUPPORTED_CHAIN_IDS, HYPERLIQUID_TIF, HYPERLIQUID_USER_SIGNED_DOMAIN, HYPERLIQUID_USER_SIGNED_SIGNATURE_CHAIN_ID, HYPERLIQUID_WITHDRAW_SIGN_TYPES, buildCoreWriterCancelByCloidCalldata, buildCoreWriterCancelByOidCalldata, buildCoreWriterLimitOrderCalldata, buildCoreWriterStakingDepositCalldata, buildCoreWriterStakingWithdrawCalldata, buildCoreWriterTokenDelegateCalldata, buildCoreWriterUsdClassTransferCalldata, buildCoreWriterVaultTransferCalldata, buildEvmMultisignBodyHyperliquidBridgeDepositBatch, buildEvmMultisignBodyHyperliquidCancelBatch, buildEvmMultisignBodyHyperliquidCloseBatch, buildEvmMultisignBodyHyperliquidDelegateBatch, buildEvmMultisignBodyHyperliquidDelegateOnlyBatch, buildEvmMultisignBodyHyperliquidLimitOrderBatch, buildEvmMultisignBodyHyperliquidStakeDepositBatch, buildEvmMultisignBodyHyperliquidStakeWithdrawBatch, buildEvmMultisignBodyHyperliquidUndelegateBatch, buildEvmMultisignBodyHyperliquidUsdClassTransferBatch, buildEvmMultisignBodyHyperliquidVaultDepositBatch, buildEvmMultisignBodyHyperliquidVaultWithdrawBatch, buildHyperliquidAgentTypedData, buildHyperliquidBorrowLendAction, buildHyperliquidBorrowLendMultisign, buildHyperliquidBridgeWithdrawMultisign, buildHyperliquidLimitOrderWire, buildHyperliquidLimitOrderWithTpslMultisign, buildHyperliquidNormalTpslOrderWires, buildHyperliquidOrderAction, buildHyperliquidTriggerOrderWire, buildHyperliquidUpdateLeverageAction, buildHyperliquidUpdateLeverageMultisign, buildHyperliquidWithdraw3Action, buildHyperliquidWithdraw3TypedData, coreWriterStep, createHyperliquidL1ActionHash, hyperliquidApiBaseUrl, hyperliquidBridgeArbitrumChainId, hyperliquidBridgeConfig, hyperliquidCanonicalLendCoin, hyperliquidCollectAllPerpMarkets, hyperliquidCollectHip3StockMarkets, hyperliquidCollectNativePerpMarkets, hyperliquidEncodePx8, hyperliquidEncodeUsd6, hyperliquidEncodeWei8, hyperliquidFetchActiveAssetData, hyperliquidFetchAllBorrowLendReserveStates, hyperliquidFetchAllMids, hyperliquidFetchBorrowLendReserveState, hyperliquidFetchBorrowLendUserState, hyperliquidFetchCandles, hyperliquidFetchClearinghouseState, hyperliquidFetchDelegations, hyperliquidFetchDelegationsForExecutor, hyperliquidFetchDexList, hyperliquidFetchFrontendOpenOrders, hyperliquidFetchLendMarketsSummary, hyperliquidFetchLendPositionsSummary, hyperliquidFetchMarketSnapshot, hyperliquidFetchMarketSnapshotSummary, hyperliquidFetchMarketsSummary, hyperliquidFetchOhlcvRange, hyperliquidFetchOhlcvSummary, hyperliquidFetchOpenContextSummary, hyperliquidFetchOpenMarketContext, hyperliquidFetchOpenOrders, hyperliquidFetchOpenOrdersSummary, hyperliquidFetchOrdersForExecutor, hyperliquidFetchPerpAssetContext, hyperliquidFetchPerpConciseAnnotations, hyperliquidFetchPerpMeta, hyperliquidFetchPositionDisplayRows, hyperliquidFetchPositionsForExecutor, hyperliquidFetchSpotClearinghouseState, hyperliquidFetchSpotMeta, hyperliquidFetchSpotTokens, hyperliquidFetchStakingSummary, hyperliquidFetchStakingSummaryForExecutor, hyperliquidFetchStockMarketsSummary, hyperliquidFetchUsdClassBalances, hyperliquidFetchUsdClassBalancesSummary, hyperliquidFetchUserAbstraction, hyperliquidFetchUserVaultEquities, hyperliquidFetchUserVaultEquitiesSummary, hyperliquidFetchVaultApysSummary, hyperliquidFetchVaultCatalogSummary, hyperliquidFetchVaultSummaries, hyperliquidFloatToWire, hyperliquidInferDexFromCoin, hyperliquidIsSpotAssetId, hyperliquidL1TifFromKey, hyperliquidLendRoleFromLtv, hyperliquidManualBorrowEnabled, hyperliquidMarketSymbol, hyperliquidOrderClosesPosition, hyperliquidOrderCountsAsPendingClose, hyperliquidPendingCloseByCoin, hyperliquidPendingCloseForPosition, hyperliquidProtocolModule, hyperliquidResolveAsset, hyperliquidResolveLendTokenForChain, hyperliquidResolveOhlcvWindow, hyperliquidResolvePerpAsset, hyperliquidResolvePerpMarket, hyperliquidResolveSpotAsset, hyperliquidResolveSpotToken, hyperliquidResolveTif, hyperliquidSearchMarkets, hyperliquidSearchMarketsSummary, hyperliquidVaultStatsUrl, isHyperliquidBridgeArbitrumChainSupported, isHyperliquidBridgeArbitrumUsdcRow, isHyperliquidChainSupported, isHyperliquidHyperEvmUsdcRow, mapHyperliquidLendMarketRows, parseHyperliquidBorrowLendAmount, parseHyperliquidBorrowLendReserveTuples, parseHyperliquidBorrowLendUserState, validateHyperliquidTpslGeometry };
2801
+ export { HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID, HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID, HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS, HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC, HYPERLIQUID_CORE_WRITER_ADDRESS, HYPERLIQUID_CORE_WRITER_GAS_FALLBACK, HYPERLIQUID_DEFAULT_CANDLE_LIMIT, HYPERLIQUID_DEFAULT_LOOKBACK_DAYS, HYPERLIQUID_DEFAULT_OHLCV_INTERVAL, HYPERLIQUID_HLP_VAULT_ADDRESS, HYPERLIQUID_HYPEREVM_USDC_MAINNET, HYPERLIQUID_HYPEREVM_USDC_TESTNET, HYPERLIQUID_INTERVAL_MS, HYPERLIQUID_MAX_CANDLE_LIMIT, HYPERLIQUID_MAX_LOOKBACK_DAYS, HYPERLIQUID_MAX_OHLCV_BARS, HYPERLIQUID_PROTOCOL_ID, HYPERLIQUID_SPOT_ASSET_OFFSET, HYPERLIQUID_SUPPORTED_CHAIN_IDS, HYPERLIQUID_TIF, HYPERLIQUID_TRAILING_ACTIVATION_PX_ERROR, HYPERLIQUID_USER_SIGNED_DOMAIN, HYPERLIQUID_USER_SIGNED_SIGNATURE_CHAIN_ID, HYPERLIQUID_WITHDRAW_SIGN_TYPES, buildCoreWriterCancelByCloidCalldata, buildCoreWriterCancelByOidCalldata, buildCoreWriterLimitOrderCalldata, buildCoreWriterStakingDepositCalldata, buildCoreWriterStakingWithdrawCalldata, buildCoreWriterTokenDelegateCalldata, buildCoreWriterUsdClassTransferCalldata, buildCoreWriterVaultTransferCalldata, buildEvmMultisignBodyHyperliquidBridgeDepositBatch, buildEvmMultisignBodyHyperliquidCancelBatch, buildEvmMultisignBodyHyperliquidCloseBatch, buildEvmMultisignBodyHyperliquidDelegateBatch, buildEvmMultisignBodyHyperliquidDelegateOnlyBatch, buildEvmMultisignBodyHyperliquidLimitOrderBatch, buildEvmMultisignBodyHyperliquidStakeDepositBatch, buildEvmMultisignBodyHyperliquidStakeWithdrawBatch, buildEvmMultisignBodyHyperliquidUndelegateBatch, buildEvmMultisignBodyHyperliquidUsdClassTransferBatch, buildEvmMultisignBodyHyperliquidVaultDepositBatch, buildEvmMultisignBodyHyperliquidVaultWithdrawBatch, buildHyperliquidAgentTypedData, buildHyperliquidBorrowLendAction, buildHyperliquidBorrowLendMultisign, buildHyperliquidBridgeWithdrawMultisign, buildHyperliquidLimitOrderWire, buildHyperliquidLimitOrderWithTpslMultisign, buildHyperliquidNormalTpslOrderWires, buildHyperliquidOrderAction, buildHyperliquidTrailingRetracement, buildHyperliquidTrailingStopAction, buildHyperliquidTrailingStopMultisign, buildHyperliquidTriggerOrderWire, buildHyperliquidUpdateLeverageAction, buildHyperliquidUpdateLeverageMultisign, buildHyperliquidWithdraw3Action, buildHyperliquidWithdraw3TypedData, coreWriterStep, createHyperliquidL1ActionHash, enrichHyperliquidFrontendOpenOrder, hyperliquidApiBaseUrl, hyperliquidBridgeArbitrumChainId, hyperliquidBridgeConfig, hyperliquidCanonicalLendCoin, hyperliquidCollectAllPerpMarkets, hyperliquidCollectHip3StockMarkets, hyperliquidCollectNativePerpMarkets, hyperliquidEncodePx8, hyperliquidEncodeUsd6, hyperliquidEncodeWei8, hyperliquidFetchActiveAssetData, hyperliquidFetchAllBorrowLendReserveStates, hyperliquidFetchAllMids, hyperliquidFetchBorrowLendReserveState, hyperliquidFetchBorrowLendUserState, hyperliquidFetchCandles, hyperliquidFetchClearinghouseState, hyperliquidFetchDelegations, hyperliquidFetchDelegationsForExecutor, hyperliquidFetchDexList, hyperliquidFetchFrontendOpenOrders, hyperliquidFetchLendMarketsSummary, hyperliquidFetchLendPositionsSummary, hyperliquidFetchMarketSnapshot, hyperliquidFetchMarketSnapshotSummary, hyperliquidFetchMarketsSummary, hyperliquidFetchOhlcvRange, hyperliquidFetchOhlcvSummary, hyperliquidFetchOpenContextSummary, hyperliquidFetchOpenMarketContext, hyperliquidFetchOpenOrders, hyperliquidFetchOpenOrdersSummary, hyperliquidFetchOrdersForExecutor, hyperliquidFetchPerpAssetContext, hyperliquidFetchPerpConciseAnnotations, hyperliquidFetchPerpMeta, hyperliquidFetchPositionDisplayRows, hyperliquidFetchPositionsForExecutor, hyperliquidFetchSpotClearinghouseState, hyperliquidFetchSpotMeta, hyperliquidFetchSpotTokens, hyperliquidFetchStakingSummary, hyperliquidFetchStakingSummaryForExecutor, hyperliquidFetchStockMarketsSummary, hyperliquidFetchUsdClassBalances, hyperliquidFetchUsdClassBalancesSummary, hyperliquidFetchUserAbstraction, hyperliquidFetchUserVaultEquities, hyperliquidFetchUserVaultEquitiesSummary, hyperliquidFetchVaultApysSummary, hyperliquidFetchVaultCatalogSummary, hyperliquidFetchVaultSummaries, hyperliquidFloatToWire, hyperliquidInferDexFromCoin, hyperliquidIsSpotAssetId, hyperliquidL1TifFromKey, hyperliquidLendRoleFromLtv, hyperliquidManualBorrowEnabled, hyperliquidMarketSymbol, hyperliquidOrderClosesPosition, hyperliquidOrderCountsAsPendingClose, hyperliquidPendingCloseByCoin, hyperliquidPendingCloseForPosition, hyperliquidProtocolModule, hyperliquidResolveAsset, hyperliquidResolveLendTokenForChain, hyperliquidResolveOhlcvWindow, hyperliquidResolvePerpAsset, hyperliquidResolvePerpMarket, hyperliquidResolveSpotAsset, hyperliquidResolveSpotToken, hyperliquidResolveTif, hyperliquidSearchMarkets, hyperliquidSearchMarketsSummary, hyperliquidTrailingPercentToWire, hyperliquidVaultStatsUrl, isHyperliquidBridgeArbitrumChainSupported, isHyperliquidBridgeArbitrumUsdcRow, isHyperliquidChainSupported, isHyperliquidHyperEvmUsdcRow, isHyperliquidTrailingActivationPxHuman, mapHyperliquidLendMarketRows, parseHyperliquidBorrowLendAmount, parseHyperliquidBorrowLendReserveTuples, parseHyperliquidBorrowLendUserState, parseHyperliquidTrailingActivationPx, parseHyperliquidTrailingOffsetType, parseHyperliquidTrailingStopParams, parseHyperliquidTrailingTriggerCondition, validateHyperliquidTpslGeometry, validateHyperliquidTrailingStopParams };
2536
2802
  //# sourceMappingURL=index.js.map
2537
2803
  //# sourceMappingURL=index.js.map