opentool 0.8.24 → 0.8.27
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/adapters/hyperliquid/index.d.ts +181 -3
- package/dist/adapters/hyperliquid/index.js +967 -17
- package/dist/adapters/hyperliquid/index.js.map +1 -1
- package/dist/cli/index.js +31 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +998 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/base/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2301,12 +2301,29 @@ function toApiDecimal(value) {
|
|
|
2301
2301
|
}
|
|
2302
2302
|
return asString;
|
|
2303
2303
|
}
|
|
2304
|
+
var NORMALIZED_HEX_PATTERN = /^0x[0-9a-f]+$/;
|
|
2305
|
+
var ADDRESS_HEX_LENGTH = 42;
|
|
2306
|
+
var CLOID_HEX_LENGTH = 34;
|
|
2304
2307
|
function normalizeHex(value) {
|
|
2305
|
-
const lower = value.toLowerCase();
|
|
2306
|
-
|
|
2308
|
+
const lower = value.trim().toLowerCase();
|
|
2309
|
+
if (!NORMALIZED_HEX_PATTERN.test(lower)) {
|
|
2310
|
+
throw new Error(`Invalid hex value: ${value}`);
|
|
2311
|
+
}
|
|
2312
|
+
return lower;
|
|
2307
2313
|
}
|
|
2308
2314
|
function normalizeAddress(value) {
|
|
2309
|
-
|
|
2315
|
+
const normalized = normalizeHex(value);
|
|
2316
|
+
if (normalized.length !== ADDRESS_HEX_LENGTH) {
|
|
2317
|
+
throw new Error(`Invalid address length: ${normalized}`);
|
|
2318
|
+
}
|
|
2319
|
+
return normalized;
|
|
2320
|
+
}
|
|
2321
|
+
function normalizeCloid(value) {
|
|
2322
|
+
const normalized = normalizeHex(value);
|
|
2323
|
+
if (normalized.length !== CLOID_HEX_LENGTH) {
|
|
2324
|
+
throw new Error(`Invalid cloid length: ${normalized}`);
|
|
2325
|
+
}
|
|
2326
|
+
return normalized;
|
|
2310
2327
|
}
|
|
2311
2328
|
async function signL1Action(args) {
|
|
2312
2329
|
const { wallet: wallet2, action, nonce, vaultAddress, expiresAfter, isTestnet } = args;
|
|
@@ -3049,8 +3066,8 @@ async function cancelHyperliquidOrdersByCloid(options) {
|
|
|
3049
3066
|
options,
|
|
3050
3067
|
options.cancels,
|
|
3051
3068
|
(idx, entry) => ({
|
|
3052
|
-
|
|
3053
|
-
|
|
3069
|
+
asset: idx,
|
|
3070
|
+
cloid: normalizeCloid(entry.cloid)
|
|
3054
3071
|
})
|
|
3055
3072
|
)
|
|
3056
3073
|
};
|
|
@@ -3061,10 +3078,10 @@ async function cancelAllHyperliquidOrders(options) {
|
|
|
3061
3078
|
return submitExchangeAction(options, action);
|
|
3062
3079
|
}
|
|
3063
3080
|
async function scheduleHyperliquidCancel(options) {
|
|
3064
|
-
if (options.time
|
|
3081
|
+
if (options.time != null) {
|
|
3065
3082
|
assertPositiveNumber(options.time, "time");
|
|
3066
3083
|
}
|
|
3067
|
-
const action = { type: "scheduleCancel", time: options.time };
|
|
3084
|
+
const action = options.time == null ? { type: "scheduleCancel" } : { type: "scheduleCancel", time: options.time };
|
|
3068
3085
|
return submitExchangeAction(options, action);
|
|
3069
3086
|
}
|
|
3070
3087
|
async function modifyHyperliquidOrder(options) {
|
|
@@ -3298,7 +3315,7 @@ async function buildOrder(intent, options) {
|
|
|
3298
3315
|
r: intent.reduceOnly ?? false,
|
|
3299
3316
|
t: limitOrTrigger,
|
|
3300
3317
|
...intent.clientId ? {
|
|
3301
|
-
c:
|
|
3318
|
+
c: normalizeCloid(intent.clientId)
|
|
3302
3319
|
} : {}
|
|
3303
3320
|
};
|
|
3304
3321
|
}
|
|
@@ -3345,6 +3362,32 @@ function assertPositiveDecimal(value, label) {
|
|
|
3345
3362
|
return;
|
|
3346
3363
|
}
|
|
3347
3364
|
assertString(value, label);
|
|
3365
|
+
if (!/^(?:\d+\.?\d*|\.\d+)$/.test(value.trim())) {
|
|
3366
|
+
throw new Error(`${label} must be a positive decimal string.`);
|
|
3367
|
+
}
|
|
3368
|
+
const numeric = Number(value);
|
|
3369
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
3370
|
+
throw new Error(`${label} must be positive.`);
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
function collectExchangeErrorMessages(payload) {
|
|
3374
|
+
if (!payload || typeof payload !== "object") return [];
|
|
3375
|
+
const root = payload;
|
|
3376
|
+
const messages = [];
|
|
3377
|
+
const statuses = root.response?.data?.statuses;
|
|
3378
|
+
if (Array.isArray(statuses)) {
|
|
3379
|
+
statuses.forEach((status, index) => {
|
|
3380
|
+
if (status && typeof status === "object" && "error" in status && typeof status.error === "string") {
|
|
3381
|
+
const errorText = status.error;
|
|
3382
|
+
messages.push(`status[${index}]: ${errorText}`);
|
|
3383
|
+
}
|
|
3384
|
+
});
|
|
3385
|
+
}
|
|
3386
|
+
const singleStatus = root.response?.data?.status;
|
|
3387
|
+
if (singleStatus && typeof singleStatus === "object" && "error" in singleStatus && typeof singleStatus.error === "string") {
|
|
3388
|
+
messages.push(singleStatus.error);
|
|
3389
|
+
}
|
|
3390
|
+
return messages;
|
|
3348
3391
|
}
|
|
3349
3392
|
async function postExchange(env, body) {
|
|
3350
3393
|
const response = await fetch(`${API_BASES[env]}/exchange`, {
|
|
@@ -3382,10 +3425,909 @@ async function postExchange(env, body) {
|
|
|
3382
3425
|
body: json
|
|
3383
3426
|
});
|
|
3384
3427
|
}
|
|
3428
|
+
const nestedErrors = collectExchangeErrorMessages(json);
|
|
3429
|
+
if (nestedErrors.length > 0) {
|
|
3430
|
+
throw new HyperliquidApiError("Hyperliquid exchange returned action errors.", {
|
|
3431
|
+
status: response.status,
|
|
3432
|
+
statusText: response.statusText,
|
|
3433
|
+
body: json,
|
|
3434
|
+
errors: nestedErrors
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
return json;
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
// src/adapters/hyperliquid/env.ts
|
|
3441
|
+
function resolveHyperliquidChain(environment) {
|
|
3442
|
+
return environment === "mainnet" ? "arbitrum" : "arbitrum-sepolia";
|
|
3443
|
+
}
|
|
3444
|
+
function resolveHyperliquidRpcEnvVar(environment) {
|
|
3445
|
+
return environment === "mainnet" ? "ARBITRUM_RPC_URL" : "ARBITRUM_SEPOLIA_RPC_URL";
|
|
3446
|
+
}
|
|
3447
|
+
function resolveHyperliquidChainConfig(environment, env = process.env) {
|
|
3448
|
+
const rpcVar = resolveHyperliquidRpcEnvVar(environment);
|
|
3449
|
+
const rpcUrl = env[rpcVar];
|
|
3450
|
+
return {
|
|
3451
|
+
chain: resolveHyperliquidChain(environment),
|
|
3452
|
+
...rpcUrl ? { rpcUrl } : {}
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
function resolveHyperliquidStoreNetwork(environment) {
|
|
3456
|
+
return environment === "mainnet" ? "hyperliquid" : "hyperliquid-testnet";
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
// src/adapters/hyperliquid/symbols.ts
|
|
3460
|
+
var UNKNOWN_SYMBOL2 = "UNKNOWN";
|
|
3461
|
+
function extractHyperliquidDex(symbol) {
|
|
3462
|
+
const idx = symbol.indexOf(":");
|
|
3463
|
+
if (idx <= 0) return null;
|
|
3464
|
+
const dex = symbol.slice(0, idx).trim().toLowerCase();
|
|
3465
|
+
return dex || null;
|
|
3466
|
+
}
|
|
3467
|
+
function normalizeSpotTokenName2(value) {
|
|
3468
|
+
const raw = (value ?? "").trim();
|
|
3469
|
+
if (!raw) return "";
|
|
3470
|
+
if (raw.endsWith("0") && raw.length > 1) {
|
|
3471
|
+
return raw.slice(0, -1);
|
|
3472
|
+
}
|
|
3473
|
+
return raw;
|
|
3474
|
+
}
|
|
3475
|
+
function normalizeHyperliquidBaseSymbol(value) {
|
|
3476
|
+
if (!value) return null;
|
|
3477
|
+
const trimmed = value.trim();
|
|
3478
|
+
if (!trimmed) return null;
|
|
3479
|
+
const withoutDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
3480
|
+
const base2 = withoutDex.split("-")[0] ?? withoutDex;
|
|
3481
|
+
const baseNoPair = base2.split("/")[0] ?? base2;
|
|
3482
|
+
const normalized = baseNoPair.trim().toUpperCase();
|
|
3483
|
+
if (!normalized || normalized === UNKNOWN_SYMBOL2) return null;
|
|
3484
|
+
return normalized;
|
|
3485
|
+
}
|
|
3486
|
+
function normalizeHyperliquidMetaSymbol(symbol) {
|
|
3487
|
+
const trimmed = symbol.trim();
|
|
3488
|
+
const noDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
3489
|
+
const noPair = noDex.split("-")[0] ?? noDex;
|
|
3490
|
+
return (noPair.split("/")[0] ?? noPair).trim();
|
|
3491
|
+
}
|
|
3492
|
+
function resolveHyperliquidPair(value) {
|
|
3493
|
+
if (!value) return null;
|
|
3494
|
+
const trimmed = value.trim();
|
|
3495
|
+
if (!trimmed) return null;
|
|
3496
|
+
const withoutDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
3497
|
+
if (withoutDex.includes("/")) {
|
|
3498
|
+
return withoutDex.toUpperCase();
|
|
3499
|
+
}
|
|
3500
|
+
if (withoutDex.includes("-")) {
|
|
3501
|
+
const [base2, ...rest] = withoutDex.split("-");
|
|
3502
|
+
const quote = rest.join("-").trim();
|
|
3503
|
+
if (!base2 || !quote) return null;
|
|
3504
|
+
return `${base2.toUpperCase()}/${quote.toUpperCase()}`;
|
|
3505
|
+
}
|
|
3506
|
+
return null;
|
|
3507
|
+
}
|
|
3508
|
+
function resolveHyperliquidProfileChain(environment) {
|
|
3509
|
+
return environment === "testnet" ? "hyperliquid-testnet" : "hyperliquid";
|
|
3510
|
+
}
|
|
3511
|
+
function buildHyperliquidProfileAssets(params) {
|
|
3512
|
+
const chain = resolveHyperliquidProfileChain(params.environment);
|
|
3513
|
+
return params.assets.map((asset) => {
|
|
3514
|
+
const symbols = asset.assetSymbols.map((symbol) => normalizeHyperliquidBaseSymbol(symbol)).filter((symbol) => Boolean(symbol));
|
|
3515
|
+
if (symbols.length === 0) return null;
|
|
3516
|
+
const explicitPair = typeof asset.pair === "string" ? resolveHyperliquidPair(asset.pair) : null;
|
|
3517
|
+
const derivedPair = symbols.length === 1 ? resolveHyperliquidPair(asset.assetSymbols[0] ?? symbols[0]) : null;
|
|
3518
|
+
const pair = explicitPair ?? derivedPair ?? void 0;
|
|
3519
|
+
const leverage = typeof asset.leverage === "number" && Number.isFinite(asset.leverage) && asset.leverage > 0 ? asset.leverage : void 0;
|
|
3520
|
+
const walletAddress = typeof asset.walletAddress === "string" && asset.walletAddress.trim().length > 0 ? asset.walletAddress.trim() : void 0;
|
|
3521
|
+
return {
|
|
3522
|
+
venue: "hyperliquid",
|
|
3523
|
+
chain,
|
|
3524
|
+
assetSymbols: symbols,
|
|
3525
|
+
...pair ? { pair } : {},
|
|
3526
|
+
...leverage ? { leverage } : {},
|
|
3527
|
+
...walletAddress ? { walletAddress } : {}
|
|
3528
|
+
};
|
|
3529
|
+
}).filter((asset) => asset !== null);
|
|
3530
|
+
}
|
|
3531
|
+
function parseSpotPairSymbol(symbol) {
|
|
3532
|
+
const trimmed = symbol.trim();
|
|
3533
|
+
if (!trimmed.includes("/")) return null;
|
|
3534
|
+
const [rawBase, rawQuote] = trimmed.split("/");
|
|
3535
|
+
const base2 = rawBase?.trim().toUpperCase() ?? "";
|
|
3536
|
+
const quote = rawQuote?.trim().toUpperCase() ?? "";
|
|
3537
|
+
if (!base2 || !quote) return null;
|
|
3538
|
+
return { base: base2, quote };
|
|
3539
|
+
}
|
|
3540
|
+
function isHyperliquidSpotSymbol(symbol) {
|
|
3541
|
+
return symbol.startsWith("@") || symbol.includes("/");
|
|
3542
|
+
}
|
|
3543
|
+
function resolveSpotMidCandidates(baseSymbol) {
|
|
3544
|
+
const base2 = baseSymbol.trim().toUpperCase();
|
|
3545
|
+
if (!base2) return [];
|
|
3546
|
+
const candidates = [base2];
|
|
3547
|
+
if (base2.startsWith("U") && base2.length > 1) {
|
|
3548
|
+
candidates.push(base2.slice(1));
|
|
3549
|
+
}
|
|
3550
|
+
return Array.from(new Set(candidates));
|
|
3551
|
+
}
|
|
3552
|
+
function resolveSpotTokenCandidates(value) {
|
|
3553
|
+
const normalized = normalizeSpotTokenName2(value).toUpperCase();
|
|
3554
|
+
if (!normalized) return [];
|
|
3555
|
+
const candidates = [normalized];
|
|
3556
|
+
if (normalized.startsWith("U") && normalized.length > 1) {
|
|
3557
|
+
candidates.push(normalized.slice(1));
|
|
3558
|
+
}
|
|
3559
|
+
return Array.from(new Set(candidates));
|
|
3560
|
+
}
|
|
3561
|
+
function resolveHyperliquidOrderSymbol(value) {
|
|
3562
|
+
if (!value) return null;
|
|
3563
|
+
const trimmed = value.trim();
|
|
3564
|
+
if (!trimmed) return null;
|
|
3565
|
+
if (trimmed.startsWith("@")) return trimmed;
|
|
3566
|
+
if (trimmed.includes(":")) {
|
|
3567
|
+
const [rawDex, ...restParts] = trimmed.split(":");
|
|
3568
|
+
const dex = rawDex.trim().toLowerCase();
|
|
3569
|
+
const rest = restParts.join(":");
|
|
3570
|
+
const base2 = rest.split("/")[0]?.split("-")[0] ?? rest;
|
|
3571
|
+
const normalizedBase = base2.trim().toUpperCase();
|
|
3572
|
+
if (!dex || !normalizedBase || normalizedBase === UNKNOWN_SYMBOL2) {
|
|
3573
|
+
return null;
|
|
3574
|
+
}
|
|
3575
|
+
return `${dex}:${normalizedBase}`;
|
|
3576
|
+
}
|
|
3577
|
+
const pair = resolveHyperliquidPair(trimmed);
|
|
3578
|
+
if (pair) return pair;
|
|
3579
|
+
return normalizeHyperliquidBaseSymbol(trimmed);
|
|
3580
|
+
}
|
|
3581
|
+
function resolveHyperliquidSymbol(asset, override) {
|
|
3582
|
+
const raw = override && override.trim().length > 0 ? override.trim() : asset.trim();
|
|
3583
|
+
if (!raw) return raw;
|
|
3584
|
+
if (raw.startsWith("@")) return raw;
|
|
3585
|
+
if (raw.includes(":")) {
|
|
3586
|
+
const [dexRaw, ...restParts] = raw.split(":");
|
|
3587
|
+
const dex = dexRaw.trim().toLowerCase();
|
|
3588
|
+
const rest = restParts.join(":");
|
|
3589
|
+
const base3 = rest.split("/")[0]?.split("-")[0] ?? rest;
|
|
3590
|
+
const normalizedBase = base3.trim().toUpperCase();
|
|
3591
|
+
if (!dex) return normalizedBase;
|
|
3592
|
+
return `${dex}:${normalizedBase}`;
|
|
3593
|
+
}
|
|
3594
|
+
if (raw.includes("/")) {
|
|
3595
|
+
return raw.toUpperCase();
|
|
3596
|
+
}
|
|
3597
|
+
if (raw.includes("-")) {
|
|
3598
|
+
const [base3, ...rest] = raw.split("-");
|
|
3599
|
+
const quote = rest.join("-").trim();
|
|
3600
|
+
if (base3 && quote) {
|
|
3601
|
+
return `${base3.toUpperCase()}/${quote.toUpperCase()}`;
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
const base2 = raw.split("-")[0] ?? raw;
|
|
3605
|
+
const baseNoPair = base2.split("/")[0] ?? base2;
|
|
3606
|
+
return baseNoPair.trim().toUpperCase();
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
// src/adapters/hyperliquid/order-utils.ts
|
|
3610
|
+
var MAX_HYPERLIQUID_PRICE_DECIMALS = 8;
|
|
3611
|
+
function countDecimals(value) {
|
|
3612
|
+
if (!Number.isFinite(value)) return 0;
|
|
3613
|
+
const s = value.toString();
|
|
3614
|
+
const [, dec = ""] = s.split(".");
|
|
3615
|
+
return dec.length;
|
|
3616
|
+
}
|
|
3617
|
+
function clampPriceDecimals(value) {
|
|
3618
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
3619
|
+
throw new Error("Price must be positive.");
|
|
3620
|
+
}
|
|
3621
|
+
const fixed = value.toFixed(MAX_HYPERLIQUID_PRICE_DECIMALS);
|
|
3622
|
+
return fixed.replace(/\.?0+$/, "");
|
|
3623
|
+
}
|
|
3624
|
+
function assertNumberString(value) {
|
|
3625
|
+
if (!/^-?(?:\d+\.?\d*|\.\d+)$/.test(value)) {
|
|
3626
|
+
throw new TypeError("Invalid decimal number string.");
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3629
|
+
function normalizeDecimalString(value) {
|
|
3630
|
+
return value.trim().replace(/^(-?)0+(?=\d)/, "$1").replace(/\.0*$|(\.\d+?)0+$/, "$1").replace(/^(-?)\./, "$10.").replace(/^-?$/, "0").replace(/^-0$/, "0");
|
|
3631
|
+
}
|
|
3632
|
+
var StringMath = {
|
|
3633
|
+
log10Floor(value) {
|
|
3634
|
+
const abs = value.startsWith("-") ? value.slice(1) : value;
|
|
3635
|
+
const num = Number(abs);
|
|
3636
|
+
if (!Number.isFinite(num) || num === 0) return -Infinity;
|
|
3637
|
+
const [intPart, fracPart = ""] = abs.split(".");
|
|
3638
|
+
if (Number(intPart) !== 0) {
|
|
3639
|
+
return intPart.replace(/^0+/, "").length - 1;
|
|
3640
|
+
}
|
|
3641
|
+
const leadingZeros = fracPart.match(/^0*/)?.[0]?.length ?? 0;
|
|
3642
|
+
return -(leadingZeros + 1);
|
|
3643
|
+
},
|
|
3644
|
+
multiplyByPow10(value, exp) {
|
|
3645
|
+
if (!Number.isInteger(exp)) {
|
|
3646
|
+
throw new RangeError("Exponent must be an integer.");
|
|
3647
|
+
}
|
|
3648
|
+
if (exp === 0) return normalizeDecimalString(value);
|
|
3649
|
+
const negative = value.startsWith("-");
|
|
3650
|
+
const abs = negative ? value.slice(1) : value;
|
|
3651
|
+
const [intRaw, fracRaw = ""] = abs.split(".");
|
|
3652
|
+
const intPart = intRaw || "0";
|
|
3653
|
+
let output;
|
|
3654
|
+
if (exp > 0) {
|
|
3655
|
+
if (exp >= fracRaw.length) {
|
|
3656
|
+
output = intPart + fracRaw + "0".repeat(exp - fracRaw.length);
|
|
3657
|
+
} else {
|
|
3658
|
+
output = `${intPart}${fracRaw.slice(0, exp)}.${fracRaw.slice(exp)}`;
|
|
3659
|
+
}
|
|
3660
|
+
} else {
|
|
3661
|
+
const absExp = -exp;
|
|
3662
|
+
if (absExp >= intPart.length) {
|
|
3663
|
+
output = `0.${"0".repeat(absExp - intPart.length)}${intPart}${fracRaw}`;
|
|
3664
|
+
} else {
|
|
3665
|
+
output = `${intPart.slice(0, -absExp)}.${intPart.slice(-absExp)}${fracRaw}`;
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
return normalizeDecimalString((negative ? "-" : "") + output);
|
|
3669
|
+
},
|
|
3670
|
+
trunc(value) {
|
|
3671
|
+
const index = value.indexOf(".");
|
|
3672
|
+
return index === -1 ? value : value.slice(0, index) || "0";
|
|
3673
|
+
},
|
|
3674
|
+
toPrecisionTruncate(value, precision) {
|
|
3675
|
+
if (!Number.isInteger(precision) || precision < 1) {
|
|
3676
|
+
throw new RangeError("Precision must be a positive integer.");
|
|
3677
|
+
}
|
|
3678
|
+
if (/^-?0+(\.0*)?$/.test(value)) return "0";
|
|
3679
|
+
const negative = value.startsWith("-");
|
|
3680
|
+
const abs = negative ? value.slice(1) : value;
|
|
3681
|
+
const magnitude = StringMath.log10Floor(abs);
|
|
3682
|
+
const shiftAmount = precision - magnitude - 1;
|
|
3683
|
+
const shifted = StringMath.multiplyByPow10(abs, shiftAmount);
|
|
3684
|
+
const truncated = StringMath.trunc(shifted);
|
|
3685
|
+
const shiftedBack = StringMath.multiplyByPow10(truncated, -shiftAmount);
|
|
3686
|
+
return normalizeDecimalString(negative ? `-${shiftedBack}` : shiftedBack);
|
|
3687
|
+
},
|
|
3688
|
+
toFixedTruncate(value, decimals) {
|
|
3689
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
3690
|
+
throw new RangeError("Decimals must be a non-negative integer.");
|
|
3691
|
+
}
|
|
3692
|
+
const matcher = new RegExp(`^-?(?:\\d+)?(?:\\.\\d{0,${decimals}})?`);
|
|
3693
|
+
const result = value.match(matcher)?.[0];
|
|
3694
|
+
if (!result) {
|
|
3695
|
+
throw new TypeError("Invalid number format.");
|
|
3696
|
+
}
|
|
3697
|
+
return normalizeDecimalString(result);
|
|
3698
|
+
}
|
|
3699
|
+
};
|
|
3700
|
+
function formatHyperliquidPrice(price, szDecimals, marketType = "perp") {
|
|
3701
|
+
const normalized = price.toString().trim();
|
|
3702
|
+
assertNumberString(normalized);
|
|
3703
|
+
if (/^-?\d+$/.test(normalized)) {
|
|
3704
|
+
return normalizeDecimalString(normalized);
|
|
3705
|
+
}
|
|
3706
|
+
const maxDecimals2 = Math.max((marketType === "perp" ? 6 : 8) - szDecimals, 0);
|
|
3707
|
+
const decimalsTrimmed = StringMath.toFixedTruncate(normalized, maxDecimals2);
|
|
3708
|
+
const sigFigTrimmed = StringMath.toPrecisionTruncate(decimalsTrimmed, 5);
|
|
3709
|
+
if (sigFigTrimmed === "0") {
|
|
3710
|
+
throw new RangeError("Price is too small and was truncated to 0.");
|
|
3711
|
+
}
|
|
3712
|
+
return sigFigTrimmed;
|
|
3713
|
+
}
|
|
3714
|
+
function formatHyperliquidSize(size, szDecimals) {
|
|
3715
|
+
const normalized = size.toString().trim();
|
|
3716
|
+
assertNumberString(normalized);
|
|
3717
|
+
const truncated = StringMath.toFixedTruncate(normalized, szDecimals);
|
|
3718
|
+
if (truncated === "0") {
|
|
3719
|
+
throw new RangeError("Size is too small and was truncated to 0.");
|
|
3720
|
+
}
|
|
3721
|
+
return truncated;
|
|
3722
|
+
}
|
|
3723
|
+
function formatHyperliquidOrderSize(value, szDecimals) {
|
|
3724
|
+
if (!Number.isFinite(value) || value <= 0) return "0";
|
|
3725
|
+
try {
|
|
3726
|
+
return formatHyperliquidSize(value, szDecimals);
|
|
3727
|
+
} catch {
|
|
3728
|
+
return "0";
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
function roundHyperliquidPriceToTick(price, tick, side) {
|
|
3732
|
+
if (!Number.isFinite(price) || price <= 0) {
|
|
3733
|
+
throw new Error("Price must be positive.");
|
|
3734
|
+
}
|
|
3735
|
+
if (!Number.isFinite(tick.tickDecimals) || tick.tickDecimals < 0) {
|
|
3736
|
+
throw new Error("tick.tickDecimals must be a non-negative number.");
|
|
3737
|
+
}
|
|
3738
|
+
if (tick.tickSizeInt <= 0n) {
|
|
3739
|
+
throw new Error("tick.tickSizeInt must be positive.");
|
|
3740
|
+
}
|
|
3741
|
+
const scale = 10 ** tick.tickDecimals;
|
|
3742
|
+
const scaled = BigInt(Math.round(price * scale));
|
|
3743
|
+
const tickSize = tick.tickSizeInt;
|
|
3744
|
+
const rounded = side === "sell" ? scaled / tickSize * tickSize : (scaled + tickSize - 1n) / tickSize * tickSize;
|
|
3745
|
+
const integer = Number(rounded) / scale;
|
|
3746
|
+
return clampPriceDecimals(integer);
|
|
3747
|
+
}
|
|
3748
|
+
function formatHyperliquidMarketablePrice(params) {
|
|
3749
|
+
const { mid, side, slippageBps, tick } = params;
|
|
3750
|
+
const decimals = countDecimals(mid);
|
|
3751
|
+
const factor = 10 ** decimals;
|
|
3752
|
+
const adjusted = mid * (side === "buy" ? 1 + slippageBps / 1e4 : 1 - slippageBps / 1e4);
|
|
3753
|
+
if (tick) {
|
|
3754
|
+
return roundHyperliquidPriceToTick(adjusted, tick, side);
|
|
3755
|
+
}
|
|
3756
|
+
const scaled = adjusted * factor;
|
|
3757
|
+
const rounded = side === "buy" ? Math.ceil(scaled) / factor : Math.floor(scaled) / factor;
|
|
3758
|
+
return clampPriceDecimals(rounded);
|
|
3759
|
+
}
|
|
3760
|
+
function extractHyperliquidOrderIds(responses) {
|
|
3761
|
+
const cloids = /* @__PURE__ */ new Set();
|
|
3762
|
+
const oids = /* @__PURE__ */ new Set();
|
|
3763
|
+
const push = (val, target) => {
|
|
3764
|
+
if (val === null || val === void 0) return;
|
|
3765
|
+
const str = String(val);
|
|
3766
|
+
if (str.length) target.add(str);
|
|
3767
|
+
};
|
|
3768
|
+
for (const res of responses) {
|
|
3769
|
+
const statuses = res?.response?.data?.statuses;
|
|
3770
|
+
if (!Array.isArray(statuses)) continue;
|
|
3771
|
+
for (const status of statuses) {
|
|
3772
|
+
const resting = status.resting;
|
|
3773
|
+
const filled = status.filled;
|
|
3774
|
+
push(resting?.cloid, cloids);
|
|
3775
|
+
push(resting?.oid, oids);
|
|
3776
|
+
push(filled?.cloid, cloids);
|
|
3777
|
+
push(filled?.oid, oids);
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
return {
|
|
3781
|
+
cloids: Array.from(cloids),
|
|
3782
|
+
oids: Array.from(oids)
|
|
3783
|
+
};
|
|
3784
|
+
}
|
|
3785
|
+
function resolveHyperliquidOrderRef(params) {
|
|
3786
|
+
const { response, fallbackCloid, fallbackOid, prefix = "hl-order", index = 0 } = params;
|
|
3787
|
+
const statuses = response?.response?.data?.statuses ?? [];
|
|
3788
|
+
if (Array.isArray(statuses)) {
|
|
3789
|
+
for (const status of statuses) {
|
|
3790
|
+
const filled = status && typeof status.filled === "object" ? status.filled : null;
|
|
3791
|
+
if (filled) {
|
|
3792
|
+
if (typeof filled.cloid === "string" && filled.cloid.trim().length > 0) {
|
|
3793
|
+
return filled.cloid;
|
|
3794
|
+
}
|
|
3795
|
+
if (typeof filled.oid === "number" || typeof filled.oid === "string" && filled.oid.trim().length > 0) {
|
|
3796
|
+
return String(filled.oid);
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
const resting = status && typeof status.resting === "object" ? status.resting : null;
|
|
3800
|
+
if (resting) {
|
|
3801
|
+
if (typeof resting.cloid === "string" && resting.cloid.trim().length > 0) {
|
|
3802
|
+
return resting.cloid;
|
|
3803
|
+
}
|
|
3804
|
+
if (typeof resting.oid === "number" || typeof resting.oid === "string" && resting.oid.trim().length > 0) {
|
|
3805
|
+
return String(resting.oid);
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
if (fallbackCloid && fallbackCloid.trim().length > 0) {
|
|
3811
|
+
return fallbackCloid;
|
|
3812
|
+
}
|
|
3813
|
+
if (fallbackOid && fallbackOid.trim().length > 0) {
|
|
3814
|
+
return fallbackOid;
|
|
3815
|
+
}
|
|
3816
|
+
return `${prefix}-${Date.now()}-${index}`;
|
|
3817
|
+
}
|
|
3818
|
+
function resolveHyperliquidErrorDetail(error) {
|
|
3819
|
+
if (error instanceof HyperliquidApiError) {
|
|
3820
|
+
return error.response ?? null;
|
|
3821
|
+
}
|
|
3822
|
+
if (error && typeof error === "object" && "response" in error) {
|
|
3823
|
+
return error.response ?? null;
|
|
3824
|
+
}
|
|
3825
|
+
return null;
|
|
3826
|
+
}
|
|
3827
|
+
|
|
3828
|
+
// src/adapters/hyperliquid/state-readers.ts
|
|
3829
|
+
function unwrapData(payload) {
|
|
3830
|
+
if (!payload || typeof payload !== "object") return null;
|
|
3831
|
+
if ("data" in payload) {
|
|
3832
|
+
const data = payload.data;
|
|
3833
|
+
if (data && typeof data === "object") {
|
|
3834
|
+
return data;
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
return payload;
|
|
3838
|
+
}
|
|
3839
|
+
function readHyperliquidNumber(value) {
|
|
3840
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
3841
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
3842
|
+
const parsed = Number(value);
|
|
3843
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
3844
|
+
}
|
|
3845
|
+
return null;
|
|
3846
|
+
}
|
|
3847
|
+
function readHyperliquidAccountValue(payload) {
|
|
3848
|
+
const data = unwrapData(payload);
|
|
3849
|
+
if (!data) return null;
|
|
3850
|
+
const candidates = [
|
|
3851
|
+
data?.marginSummary?.accountValue,
|
|
3852
|
+
data?.crossMarginSummary?.accountValue,
|
|
3853
|
+
data?.accountValue,
|
|
3854
|
+
data?.equity,
|
|
3855
|
+
data?.totalAccountValue,
|
|
3856
|
+
data?.marginSummary?.totalAccountValue
|
|
3857
|
+
];
|
|
3858
|
+
for (const value of candidates) {
|
|
3859
|
+
const parsed = readHyperliquidNumber(value);
|
|
3860
|
+
if (parsed !== null) return parsed;
|
|
3861
|
+
}
|
|
3862
|
+
return null;
|
|
3863
|
+
}
|
|
3864
|
+
function matchPerpCoin(params) {
|
|
3865
|
+
const coin = params.coin.toUpperCase();
|
|
3866
|
+
const target = params.target.toUpperCase();
|
|
3867
|
+
if (params.prefixMatch) return coin.startsWith(target);
|
|
3868
|
+
return coin === target;
|
|
3869
|
+
}
|
|
3870
|
+
function readHyperliquidPerpPositionSize(payload, symbol, options) {
|
|
3871
|
+
const data = unwrapData(payload);
|
|
3872
|
+
const rows = Array.isArray(data?.assetPositions) ? data.assetPositions : [];
|
|
3873
|
+
const base2 = symbol.split("-")[0]?.toUpperCase() ?? symbol.toUpperCase();
|
|
3874
|
+
const prefixMatch = options?.prefixMatch ?? false;
|
|
3875
|
+
for (const row of rows) {
|
|
3876
|
+
const position = row.position ?? row;
|
|
3877
|
+
const coin = typeof position?.coin === "string" ? position.coin : typeof row.coin === "string" ? row.coin : "";
|
|
3878
|
+
if (!matchPerpCoin({ coin, target: base2, prefixMatch })) continue;
|
|
3879
|
+
const size = position.szi ?? row.szi;
|
|
3880
|
+
const parsed = readHyperliquidNumber(size);
|
|
3881
|
+
return parsed ?? 0;
|
|
3882
|
+
}
|
|
3883
|
+
return 0;
|
|
3884
|
+
}
|
|
3885
|
+
function readHyperliquidPerpPosition(payload, symbol, options) {
|
|
3886
|
+
const data = unwrapData(payload);
|
|
3887
|
+
const rows = Array.isArray(data?.assetPositions) ? data.assetPositions : [];
|
|
3888
|
+
const target = symbol.split("-")[0]?.toUpperCase() ?? symbol.toUpperCase();
|
|
3889
|
+
const prefixMatch = options?.prefixMatch ?? false;
|
|
3890
|
+
for (const row of rows) {
|
|
3891
|
+
const position = row?.position ?? row;
|
|
3892
|
+
const coin = typeof position?.coin === "string" ? position.coin : typeof row?.coin === "string" ? row.coin : "";
|
|
3893
|
+
if (!matchPerpCoin({ coin, target, prefixMatch })) continue;
|
|
3894
|
+
const size = readHyperliquidNumber(position?.szi ?? row.szi) ?? 0;
|
|
3895
|
+
const positionValue = Math.abs(
|
|
3896
|
+
readHyperliquidNumber(position?.positionValue ?? row.positionValue) ?? 0
|
|
3897
|
+
);
|
|
3898
|
+
const unrealizedPnl = readHyperliquidNumber(
|
|
3899
|
+
position?.unrealizedPnl ?? row.unrealizedPnl
|
|
3900
|
+
);
|
|
3901
|
+
return { size, positionValue, unrealizedPnl };
|
|
3902
|
+
}
|
|
3903
|
+
return { size: 0, positionValue: 0, unrealizedPnl: null };
|
|
3904
|
+
}
|
|
3905
|
+
function readHyperliquidSpotBalanceSize(payload, symbol) {
|
|
3906
|
+
const data = unwrapData(payload);
|
|
3907
|
+
const rows = Array.isArray(data?.balances) ? data.balances : [];
|
|
3908
|
+
const base2 = symbol.split("/")[0]?.split("-")[0]?.toUpperCase() ?? symbol.toUpperCase();
|
|
3909
|
+
for (const row of rows) {
|
|
3910
|
+
const coin = typeof row?.coin === "string" ? row.coin : typeof row?.asset === "string" ? row.asset : "";
|
|
3911
|
+
if (coin.toUpperCase() !== base2) continue;
|
|
3912
|
+
const total = row.total ?? row.balance ?? row.szi;
|
|
3913
|
+
const parsed = readHyperliquidNumber(total);
|
|
3914
|
+
return parsed ?? 0;
|
|
3915
|
+
}
|
|
3916
|
+
return 0;
|
|
3917
|
+
}
|
|
3918
|
+
function readHyperliquidSpotBalance(payload, base2) {
|
|
3919
|
+
const data = unwrapData(payload);
|
|
3920
|
+
const balances = Array.isArray(data?.balances) ? data.balances : [];
|
|
3921
|
+
const target = base2.toUpperCase();
|
|
3922
|
+
for (const row of balances) {
|
|
3923
|
+
const coin = typeof row?.coin === "string" ? row.coin : "";
|
|
3924
|
+
if (coin.toUpperCase() !== target) continue;
|
|
3925
|
+
const total = readHyperliquidNumber(row?.total) ?? 0;
|
|
3926
|
+
const entryNtl = readHyperliquidNumber(row?.entryNtl);
|
|
3927
|
+
return { total, entryNtl };
|
|
3928
|
+
}
|
|
3929
|
+
return { total: 0, entryNtl: null };
|
|
3930
|
+
}
|
|
3931
|
+
function readHyperliquidSpotAccountValue(params) {
|
|
3932
|
+
const rows = Array.isArray(params.balances) ? params.balances : [];
|
|
3933
|
+
if (rows.length === 0) return null;
|
|
3934
|
+
let total = 0;
|
|
3935
|
+
let hasValue = false;
|
|
3936
|
+
for (const row of rows) {
|
|
3937
|
+
const coin = typeof row?.coin === "string" ? row.coin : typeof row?.asset === "string" ? row.asset : "";
|
|
3938
|
+
if (!coin) continue;
|
|
3939
|
+
const amount = readHyperliquidNumber(
|
|
3940
|
+
row.total ?? row.balance ?? row.szi
|
|
3941
|
+
);
|
|
3942
|
+
if (amount == null || amount === 0) continue;
|
|
3943
|
+
const price = params.pricesUsd.get(coin.toUpperCase());
|
|
3944
|
+
if (price == null || !Number.isFinite(price) || price <= 0) continue;
|
|
3945
|
+
total += amount * price;
|
|
3946
|
+
hasValue = true;
|
|
3947
|
+
}
|
|
3948
|
+
return hasValue ? total : null;
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
// src/adapters/hyperliquid/market-data.ts
|
|
3952
|
+
var META_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
3953
|
+
var allMidsCache = /* @__PURE__ */ new Map();
|
|
3954
|
+
function gcd(a, b) {
|
|
3955
|
+
let left = a < 0n ? -a : a;
|
|
3956
|
+
let right = b < 0n ? -b : b;
|
|
3957
|
+
while (right !== 0n) {
|
|
3958
|
+
const next = left % right;
|
|
3959
|
+
left = right;
|
|
3960
|
+
right = next;
|
|
3961
|
+
}
|
|
3962
|
+
return left;
|
|
3963
|
+
}
|
|
3964
|
+
function pow10(decimals) {
|
|
3965
|
+
let result = 1n;
|
|
3966
|
+
for (let i = 0; i < decimals; i += 1) {
|
|
3967
|
+
result *= 10n;
|
|
3968
|
+
}
|
|
3969
|
+
return result;
|
|
3970
|
+
}
|
|
3971
|
+
function maxDecimals(values) {
|
|
3972
|
+
let max = 0;
|
|
3973
|
+
for (const value of values) {
|
|
3974
|
+
const dot = value.indexOf(".");
|
|
3975
|
+
if (dot === -1) continue;
|
|
3976
|
+
const decimals = value.length - dot - 1;
|
|
3977
|
+
if (decimals > max) max = decimals;
|
|
3978
|
+
}
|
|
3979
|
+
return max;
|
|
3980
|
+
}
|
|
3981
|
+
function toScaledInt(value, decimals) {
|
|
3982
|
+
const trimmed = value.trim();
|
|
3983
|
+
const negative = trimmed.startsWith("-");
|
|
3984
|
+
const unsigned = negative ? trimmed.slice(1) : trimmed;
|
|
3985
|
+
const [intPart, fracPart = ""] = unsigned.split(".");
|
|
3986
|
+
const padded = fracPart.padEnd(decimals, "0").slice(0, decimals);
|
|
3987
|
+
const combined = `${intPart || "0"}${padded}`;
|
|
3988
|
+
const asInt = BigInt(combined || "0");
|
|
3989
|
+
return negative ? -asInt : asInt;
|
|
3990
|
+
}
|
|
3991
|
+
function formatScaledInt(value, decimals) {
|
|
3992
|
+
const negative = value < 0n;
|
|
3993
|
+
const absValue = negative ? -value : value;
|
|
3994
|
+
const scale = pow10(decimals);
|
|
3995
|
+
const integer = absValue / scale;
|
|
3996
|
+
const fraction = absValue % scale;
|
|
3997
|
+
if (decimals === 0) {
|
|
3998
|
+
return `${negative ? "-" : ""}${integer.toString()}`;
|
|
3999
|
+
}
|
|
4000
|
+
const fractionStr = fraction.toString().padStart(decimals, "0");
|
|
4001
|
+
return `${negative ? "-" : ""}${integer.toString()}.${fractionStr}`.replace(
|
|
4002
|
+
/\.?0+$/,
|
|
4003
|
+
""
|
|
4004
|
+
);
|
|
4005
|
+
}
|
|
4006
|
+
function resolveSpotSizeDecimals(meta, symbol) {
|
|
4007
|
+
const universe = meta.universe ?? [];
|
|
4008
|
+
const tokens2 = meta.tokens ?? [];
|
|
4009
|
+
if (!universe.length || !tokens2.length) {
|
|
4010
|
+
throw new Error(`Spot metadata unavailable for ${symbol}.`);
|
|
4011
|
+
}
|
|
4012
|
+
const tokenMap = /* @__PURE__ */ new Map();
|
|
4013
|
+
for (const token2 of tokens2) {
|
|
4014
|
+
const index = token2?.index;
|
|
4015
|
+
const szDecimals = typeof token2?.szDecimals === "number" ? token2.szDecimals : null;
|
|
4016
|
+
if (typeof index !== "number" || szDecimals == null) continue;
|
|
4017
|
+
tokenMap.set(index, {
|
|
4018
|
+
name: normalizeSpotTokenName2(token2?.name),
|
|
4019
|
+
szDecimals
|
|
4020
|
+
});
|
|
4021
|
+
}
|
|
4022
|
+
if (symbol.startsWith("@")) {
|
|
4023
|
+
const targetIndex = Number.parseInt(symbol.slice(1), 10);
|
|
4024
|
+
if (!Number.isFinite(targetIndex)) {
|
|
4025
|
+
throw new Error(`Invalid spot pair id: ${symbol}`);
|
|
4026
|
+
}
|
|
4027
|
+
for (let idx = 0; idx < universe.length; idx += 1) {
|
|
4028
|
+
const market = universe[idx];
|
|
4029
|
+
const marketIndex = typeof market?.index === "number" ? market.index : idx;
|
|
4030
|
+
if (marketIndex !== targetIndex) continue;
|
|
4031
|
+
const [baseIndex] = Array.isArray(market?.tokens) ? market.tokens : [];
|
|
4032
|
+
const baseToken = tokenMap.get(baseIndex ?? -1);
|
|
4033
|
+
if (!baseToken) break;
|
|
4034
|
+
return baseToken.szDecimals;
|
|
4035
|
+
}
|
|
4036
|
+
throw new Error(`Unknown spot pair id: ${symbol}`);
|
|
4037
|
+
}
|
|
4038
|
+
const pair = parseSpotPairSymbol(symbol);
|
|
4039
|
+
if (!pair) {
|
|
4040
|
+
throw new Error(`Invalid spot symbol: ${symbol}`);
|
|
4041
|
+
}
|
|
4042
|
+
const normalizedBase = normalizeSpotTokenName2(pair.base).toUpperCase();
|
|
4043
|
+
const normalizedQuote = normalizeSpotTokenName2(pair.quote).toUpperCase();
|
|
4044
|
+
for (const market of universe) {
|
|
4045
|
+
const [baseIndex, quoteIndex] = Array.isArray(market?.tokens) ? market.tokens : [];
|
|
4046
|
+
const baseToken = tokenMap.get(baseIndex ?? -1);
|
|
4047
|
+
const quoteToken = tokenMap.get(quoteIndex ?? -1);
|
|
4048
|
+
if (!baseToken || !quoteToken) continue;
|
|
4049
|
+
if (baseToken.name.toUpperCase() === normalizedBase && quoteToken.name.toUpperCase() === normalizedQuote) {
|
|
4050
|
+
return baseToken.szDecimals;
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
throw new Error(`No size decimals found for ${symbol}.`);
|
|
4054
|
+
}
|
|
4055
|
+
async function fetchHyperliquidAllMids(environment) {
|
|
4056
|
+
const cacheKey = environment;
|
|
4057
|
+
const cached = allMidsCache.get(cacheKey);
|
|
4058
|
+
if (cached && Date.now() - cached.fetchedAt < META_CACHE_TTL_MS) {
|
|
4059
|
+
return cached.mids;
|
|
4060
|
+
}
|
|
4061
|
+
const baseUrl = API_BASES[environment];
|
|
4062
|
+
const res = await fetch(`${baseUrl}/info`, {
|
|
4063
|
+
method: "POST",
|
|
4064
|
+
headers: { "content-type": "application/json" },
|
|
4065
|
+
body: JSON.stringify({ type: "allMids" })
|
|
4066
|
+
});
|
|
4067
|
+
const json = await res.json().catch(() => null);
|
|
4068
|
+
if (!res.ok || !json || typeof json !== "object") {
|
|
4069
|
+
throw new Error(`Failed to load Hyperliquid mid prices (${res.status}).`);
|
|
4070
|
+
}
|
|
4071
|
+
allMidsCache.set(cacheKey, { fetchedAt: Date.now(), mids: json });
|
|
3385
4072
|
return json;
|
|
3386
4073
|
}
|
|
4074
|
+
async function fetchHyperliquidTickSize(params) {
|
|
4075
|
+
return fetchHyperliquidTickSizeForCoin(params.environment, params.symbol);
|
|
4076
|
+
}
|
|
4077
|
+
async function fetchHyperliquidSpotTickSize(params) {
|
|
4078
|
+
if (!Number.isFinite(params.marketIndex)) {
|
|
4079
|
+
throw new Error("Hyperliquid spot market index is invalid.");
|
|
4080
|
+
}
|
|
4081
|
+
return fetchHyperliquidTickSizeForCoin(
|
|
4082
|
+
params.environment,
|
|
4083
|
+
`@${params.marketIndex}`
|
|
4084
|
+
);
|
|
4085
|
+
}
|
|
4086
|
+
async function fetchHyperliquidTickSizeForCoin(environment, coin) {
|
|
4087
|
+
const base2 = API_BASES[environment];
|
|
4088
|
+
const res = await fetch(`${base2}/info`, {
|
|
4089
|
+
method: "POST",
|
|
4090
|
+
headers: { "content-type": "application/json" },
|
|
4091
|
+
body: JSON.stringify({ type: "l2Book", coin })
|
|
4092
|
+
});
|
|
4093
|
+
if (!res.ok) {
|
|
4094
|
+
throw new Error(`Hyperliquid l2Book failed for ${coin}`);
|
|
4095
|
+
}
|
|
4096
|
+
const data = await res.json().catch(() => null);
|
|
4097
|
+
const levels = Array.isArray(data?.levels) ? data?.levels ?? [] : [];
|
|
4098
|
+
const prices = levels.flatMap(
|
|
4099
|
+
(side) => Array.isArray(side) ? side.map((entry) => String(entry?.px ?? "")) : []
|
|
4100
|
+
).filter((px) => px.length > 0);
|
|
4101
|
+
if (prices.length < 2) {
|
|
4102
|
+
throw new Error(`Hyperliquid l2Book missing price levels for ${coin}`);
|
|
4103
|
+
}
|
|
4104
|
+
const decimals = maxDecimals(prices);
|
|
4105
|
+
const scaled = prices.map((px) => toScaledInt(px, decimals));
|
|
4106
|
+
const unique = Array.from(new Set(scaled.map((v) => v.toString()))).map((v) => BigInt(v)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
4107
|
+
let tick = 0n;
|
|
4108
|
+
for (let i = 1; i < unique.length; i += 1) {
|
|
4109
|
+
const diff = unique[i] - unique[i - 1];
|
|
4110
|
+
if (diff <= 0n) continue;
|
|
4111
|
+
tick = tick === 0n ? diff : gcd(tick, diff);
|
|
4112
|
+
}
|
|
4113
|
+
if (tick === 0n) {
|
|
4114
|
+
tick = 1n;
|
|
4115
|
+
}
|
|
4116
|
+
return { tickSizeInt: tick, tickDecimals: decimals };
|
|
4117
|
+
}
|
|
4118
|
+
async function fetchHyperliquidPerpMarketInfo(params) {
|
|
4119
|
+
const data = await fetchHyperliquidMetaAndAssetCtxs(params.environment);
|
|
4120
|
+
const universe = data?.[0]?.universe ?? [];
|
|
4121
|
+
const contexts = data?.[1] ?? [];
|
|
4122
|
+
const target = normalizeHyperliquidMetaSymbol(params.symbol).toUpperCase();
|
|
4123
|
+
const idx = universe.findIndex(
|
|
4124
|
+
(entry) => normalizeHyperliquidMetaSymbol(entry?.name ?? "").toUpperCase() === target
|
|
4125
|
+
);
|
|
4126
|
+
if (idx < 0) {
|
|
4127
|
+
throw new Error(`Unknown Hyperliquid perp asset: ${params.symbol}`);
|
|
4128
|
+
}
|
|
4129
|
+
const ctx = contexts[idx] ?? null;
|
|
4130
|
+
const price = readHyperliquidNumber(ctx?.markPx ?? ctx?.midPx ?? ctx?.oraclePx);
|
|
4131
|
+
if (!price || price <= 0) {
|
|
4132
|
+
throw new Error(`No perp price available for ${params.symbol}`);
|
|
4133
|
+
}
|
|
4134
|
+
const fundingRate = readHyperliquidNumber(ctx?.funding);
|
|
4135
|
+
const szDecimals = readHyperliquidNumber(universe[idx]?.szDecimals);
|
|
4136
|
+
if (szDecimals == null) {
|
|
4137
|
+
throw new Error(`No size decimals available for ${params.symbol}`);
|
|
4138
|
+
}
|
|
4139
|
+
return {
|
|
4140
|
+
symbol: params.symbol,
|
|
4141
|
+
price,
|
|
4142
|
+
fundingRate,
|
|
4143
|
+
szDecimals
|
|
4144
|
+
};
|
|
4145
|
+
}
|
|
4146
|
+
async function fetchHyperliquidSpotMarketInfo(params) {
|
|
4147
|
+
const mids = params.mids === void 0 ? await fetchHyperliquidAllMids(params.environment).catch(() => null) : params.mids;
|
|
4148
|
+
const data = await fetchHyperliquidSpotMetaAndAssetCtxs(params.environment);
|
|
4149
|
+
const universe = data?.[0]?.universe ?? [];
|
|
4150
|
+
const tokens2 = data?.[0]?.tokens ?? [];
|
|
4151
|
+
const contexts = data?.[1] ?? [];
|
|
4152
|
+
const tokenMap = /* @__PURE__ */ new Map();
|
|
4153
|
+
for (const token2 of tokens2) {
|
|
4154
|
+
const index = token2?.index;
|
|
4155
|
+
const szDecimals = readHyperliquidNumber(token2?.szDecimals);
|
|
4156
|
+
if (typeof index !== "number" || szDecimals == null) continue;
|
|
4157
|
+
tokenMap.set(index, {
|
|
4158
|
+
name: normalizeSpotTokenName2(token2?.name),
|
|
4159
|
+
szDecimals
|
|
4160
|
+
});
|
|
4161
|
+
}
|
|
4162
|
+
const baseCandidates = resolveSpotTokenCandidates(params.base);
|
|
4163
|
+
const quoteCandidates = resolveSpotTokenCandidates(params.quote);
|
|
4164
|
+
const normalizedBase = normalizeSpotTokenName2(params.base).toUpperCase();
|
|
4165
|
+
const normalizedQuote = normalizeSpotTokenName2(params.quote).toUpperCase();
|
|
4166
|
+
for (let idx = 0; idx < universe.length; idx += 1) {
|
|
4167
|
+
const market = universe[idx];
|
|
4168
|
+
const [baseIndex, quoteIndex] = Array.isArray(market?.tokens) ? market.tokens : [];
|
|
4169
|
+
const baseToken = tokenMap.get(baseIndex ?? -1);
|
|
4170
|
+
const quoteToken = tokenMap.get(quoteIndex ?? -1);
|
|
4171
|
+
if (!baseToken || !quoteToken) continue;
|
|
4172
|
+
const marketBaseCandidates = resolveSpotTokenCandidates(baseToken.name);
|
|
4173
|
+
const marketQuoteCandidates = resolveSpotTokenCandidates(quoteToken.name);
|
|
4174
|
+
if (baseCandidates.some((candidate) => marketBaseCandidates.includes(candidate)) && quoteCandidates.some((candidate) => marketQuoteCandidates.includes(candidate))) {
|
|
4175
|
+
const contextIndex = typeof market?.index === "number" ? market.index : idx;
|
|
4176
|
+
const ctx = (contextIndex >= 0 && contextIndex < contexts.length ? contexts[contextIndex] : null) ?? contexts[idx] ?? null;
|
|
4177
|
+
let price = null;
|
|
4178
|
+
if (mids) {
|
|
4179
|
+
for (const candidate of resolveSpotMidCandidates(baseToken.name)) {
|
|
4180
|
+
const mid = readHyperliquidNumber(mids[candidate]);
|
|
4181
|
+
if (mid != null && mid > 0) {
|
|
4182
|
+
price = mid;
|
|
4183
|
+
break;
|
|
4184
|
+
}
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
if (!price || price <= 0) {
|
|
4188
|
+
price = readHyperliquidNumber(ctx?.markPx ?? ctx?.midPx ?? ctx?.oraclePx);
|
|
4189
|
+
}
|
|
4190
|
+
if (!price || price <= 0) {
|
|
4191
|
+
throw new Error(
|
|
4192
|
+
`No spot price available for ${normalizedBase}/${normalizedQuote}`
|
|
4193
|
+
);
|
|
4194
|
+
}
|
|
4195
|
+
const marketIndex = typeof market?.index === "number" ? market.index : idx;
|
|
4196
|
+
return {
|
|
4197
|
+
symbol: `${baseToken.name.toUpperCase()}/${quoteToken.name.toUpperCase()}`,
|
|
4198
|
+
base: baseToken.name.toUpperCase(),
|
|
4199
|
+
quote: quoteToken.name.toUpperCase(),
|
|
4200
|
+
assetId: 1e4 + marketIndex,
|
|
4201
|
+
marketIndex,
|
|
4202
|
+
price,
|
|
4203
|
+
szDecimals: baseToken.szDecimals
|
|
4204
|
+
};
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
throw new Error(`Unknown Hyperliquid spot market: ${normalizedBase}/${normalizedQuote}`);
|
|
4208
|
+
}
|
|
4209
|
+
async function fetchHyperliquidSizeDecimals(params) {
|
|
4210
|
+
const { symbol, environment } = params;
|
|
4211
|
+
if (isHyperliquidSpotSymbol(symbol)) {
|
|
4212
|
+
const meta2 = await fetchHyperliquidSpotMeta(environment);
|
|
4213
|
+
return resolveSpotSizeDecimals(meta2, symbol);
|
|
4214
|
+
}
|
|
4215
|
+
const meta = await fetchHyperliquidMeta(environment);
|
|
4216
|
+
const universe = Array.isArray(meta?.universe) ? meta.universe : [];
|
|
4217
|
+
const normalized = normalizeHyperliquidMetaSymbol(symbol).toUpperCase();
|
|
4218
|
+
const match = universe.find(
|
|
4219
|
+
(entry) => normalizeHyperliquidMetaSymbol(entry?.name ?? "").toUpperCase() === normalized
|
|
4220
|
+
);
|
|
4221
|
+
if (!match || typeof match.szDecimals !== "number") {
|
|
4222
|
+
throw new Error(`No size decimals found for ${symbol}.`);
|
|
4223
|
+
}
|
|
4224
|
+
return match.szDecimals;
|
|
4225
|
+
}
|
|
4226
|
+
function buildHyperliquidSpotUsdPriceMap(params) {
|
|
4227
|
+
const universe = params.meta.universe ?? [];
|
|
4228
|
+
const tokens2 = params.meta.tokens ?? [];
|
|
4229
|
+
const tokenMap = /* @__PURE__ */ new Map();
|
|
4230
|
+
for (const token2 of tokens2) {
|
|
4231
|
+
const index = token2?.index;
|
|
4232
|
+
if (typeof index !== "number") continue;
|
|
4233
|
+
tokenMap.set(index, normalizeSpotTokenName2(token2?.name).toUpperCase());
|
|
4234
|
+
}
|
|
4235
|
+
const prices = /* @__PURE__ */ new Map();
|
|
4236
|
+
prices.set("USDC", 1);
|
|
4237
|
+
for (let idx = 0; idx < universe.length; idx += 1) {
|
|
4238
|
+
const market = universe[idx];
|
|
4239
|
+
const [baseIndex, quoteIndex] = Array.isArray(market?.tokens) ? market.tokens : [];
|
|
4240
|
+
const base2 = tokenMap.get(baseIndex ?? -1);
|
|
4241
|
+
const quote = tokenMap.get(quoteIndex ?? -1);
|
|
4242
|
+
if (!base2 || !quote) continue;
|
|
4243
|
+
if (quote !== "USDC") continue;
|
|
4244
|
+
const contextIndex = typeof market?.index === "number" ? market.index : idx;
|
|
4245
|
+
const ctx = (contextIndex >= 0 && contextIndex < params.ctxs.length ? params.ctxs[contextIndex] : null) ?? params.ctxs[idx] ?? null;
|
|
4246
|
+
let price = null;
|
|
4247
|
+
if (params.mids) {
|
|
4248
|
+
for (const candidate of resolveSpotMidCandidates(base2)) {
|
|
4249
|
+
const mid = readHyperliquidNumber(params.mids[candidate]);
|
|
4250
|
+
if (mid != null && mid > 0) {
|
|
4251
|
+
price = mid;
|
|
4252
|
+
break;
|
|
4253
|
+
}
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
if (!price || price <= 0) {
|
|
4257
|
+
price = readHyperliquidNumber(ctx?.markPx ?? ctx?.midPx ?? ctx?.oraclePx);
|
|
4258
|
+
}
|
|
4259
|
+
if (!price || price <= 0) continue;
|
|
4260
|
+
prices.set(base2, price);
|
|
4261
|
+
}
|
|
4262
|
+
return prices;
|
|
4263
|
+
}
|
|
4264
|
+
async function fetchHyperliquidSpotUsdPriceMap(environment) {
|
|
4265
|
+
const [spotMetaAndCtxs, mids] = await Promise.all([
|
|
4266
|
+
fetchHyperliquidSpotMetaAndAssetCtxs(environment),
|
|
4267
|
+
fetchHyperliquidAllMids(environment).catch(() => null)
|
|
4268
|
+
]);
|
|
4269
|
+
const [metaRaw, ctxsRaw] = spotMetaAndCtxs;
|
|
4270
|
+
const meta = {
|
|
4271
|
+
universe: Array.isArray(metaRaw?.universe) ? metaRaw.universe : [],
|
|
4272
|
+
tokens: Array.isArray(metaRaw?.tokens) ? metaRaw.tokens : []
|
|
4273
|
+
};
|
|
4274
|
+
const ctxs = Array.isArray(ctxsRaw) ? ctxsRaw : [];
|
|
4275
|
+
return buildHyperliquidSpotUsdPriceMap({ meta, ctxs, mids });
|
|
4276
|
+
}
|
|
4277
|
+
async function fetchHyperliquidSpotAccountValue(params) {
|
|
4278
|
+
const pricesUsd = await fetchHyperliquidSpotUsdPriceMap(params.environment);
|
|
4279
|
+
return readHyperliquidSpotAccountValue({
|
|
4280
|
+
balances: params.balances,
|
|
4281
|
+
pricesUsd
|
|
4282
|
+
});
|
|
4283
|
+
}
|
|
4284
|
+
var __hyperliquidMarketDataInternals = {
|
|
4285
|
+
maxDecimals,
|
|
4286
|
+
toScaledInt,
|
|
4287
|
+
formatScaledInt
|
|
4288
|
+
};
|
|
3387
4289
|
|
|
3388
4290
|
// src/adapters/hyperliquid/index.ts
|
|
4291
|
+
function assertPositiveDecimalInput(value, label) {
|
|
4292
|
+
if (typeof value === "number") {
|
|
4293
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
4294
|
+
throw new Error(`${label} must be a positive number.`);
|
|
4295
|
+
}
|
|
4296
|
+
return;
|
|
4297
|
+
}
|
|
4298
|
+
if (typeof value === "bigint") {
|
|
4299
|
+
if (value <= 0n) {
|
|
4300
|
+
throw new Error(`${label} must be positive.`);
|
|
4301
|
+
}
|
|
4302
|
+
return;
|
|
4303
|
+
}
|
|
4304
|
+
const trimmed = value.trim();
|
|
4305
|
+
if (!trimmed.length) {
|
|
4306
|
+
throw new Error(`${label} must be a non-empty string.`);
|
|
4307
|
+
}
|
|
4308
|
+
if (!/^(?:\d+\.?\d*|\.\d+)$/.test(trimmed)) {
|
|
4309
|
+
throw new Error(`${label} must be a positive decimal string.`);
|
|
4310
|
+
}
|
|
4311
|
+
const numeric = Number(trimmed);
|
|
4312
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
4313
|
+
throw new Error(`${label} must be positive.`);
|
|
4314
|
+
}
|
|
4315
|
+
}
|
|
4316
|
+
function normalizePositiveDecimalString(raw, label) {
|
|
4317
|
+
const trimmed = raw.trim();
|
|
4318
|
+
if (!trimmed.length) {
|
|
4319
|
+
throw new Error(`${label} must be a non-empty decimal string.`);
|
|
4320
|
+
}
|
|
4321
|
+
if (!/^(?:\d+\.?\d*|\.\d+)$/.test(trimmed)) {
|
|
4322
|
+
throw new Error(`${label} must be a positive decimal string.`);
|
|
4323
|
+
}
|
|
4324
|
+
const normalized = trimmed.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
|
|
4325
|
+
const numeric = Number(normalized);
|
|
4326
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
4327
|
+
throw new Error(`${label} must be positive.`);
|
|
4328
|
+
}
|
|
4329
|
+
return normalized;
|
|
4330
|
+
}
|
|
3389
4331
|
async function placeHyperliquidOrder(options) {
|
|
3390
4332
|
const {
|
|
3391
4333
|
wallet: wallet2,
|
|
@@ -3409,6 +4351,11 @@ async function placeHyperliquidOrder(options) {
|
|
|
3409
4351
|
const resolvedBaseUrl = API_BASES[inferredEnvironment];
|
|
3410
4352
|
const preparedOrders = await Promise.all(
|
|
3411
4353
|
orders.map(async (intent) => {
|
|
4354
|
+
assertPositiveDecimalInput(intent.price, "price");
|
|
4355
|
+
assertPositiveDecimalInput(intent.size, "size");
|
|
4356
|
+
if (intent.trigger) {
|
|
4357
|
+
assertPositiveDecimalInput(intent.trigger.triggerPx, "triggerPx");
|
|
4358
|
+
}
|
|
3412
4359
|
const assetIndex = await resolveHyperliquidAssetIndex({
|
|
3413
4360
|
symbol: intent.symbol,
|
|
3414
4361
|
baseUrl: resolvedBaseUrl,
|
|
@@ -3434,7 +4381,7 @@ async function placeHyperliquidOrder(options) {
|
|
|
3434
4381
|
r: intent.reduceOnly ?? false,
|
|
3435
4382
|
t: limitOrTrigger,
|
|
3436
4383
|
...intent.clientId ? {
|
|
3437
|
-
c:
|
|
4384
|
+
c: normalizeCloid(intent.clientId)
|
|
3438
4385
|
} : {}
|
|
3439
4386
|
};
|
|
3440
4387
|
return order;
|
|
@@ -3503,7 +4450,9 @@ async function placeHyperliquidOrder(options) {
|
|
|
3503
4450
|
}
|
|
3504
4451
|
const statuses = json.response?.data?.statuses ?? [];
|
|
3505
4452
|
const errorStatuses = statuses.filter(
|
|
3506
|
-
(entry) =>
|
|
4453
|
+
(entry) => Boolean(
|
|
4454
|
+
entry && typeof entry === "object" && "error" in entry && typeof entry.error === "string"
|
|
4455
|
+
)
|
|
3507
4456
|
);
|
|
3508
4457
|
if (errorStatuses.length) {
|
|
3509
4458
|
const message = errorStatuses.map((entry) => entry.error).join(", ");
|
|
@@ -3557,10 +4506,11 @@ async function depositToHyperliquidBridge(options) {
|
|
|
3557
4506
|
}
|
|
3558
4507
|
async function withdrawFromHyperliquid(options) {
|
|
3559
4508
|
const { environment, amount, destination, wallet: wallet2 } = options;
|
|
3560
|
-
const
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
4509
|
+
const normalizedAmount = normalizePositiveDecimalString(
|
|
4510
|
+
amount,
|
|
4511
|
+
"Withdraw amount"
|
|
4512
|
+
);
|
|
4513
|
+
const parsedAmount = Number.parseFloat(normalizedAmount);
|
|
3564
4514
|
if (!wallet2.account || !wallet2.walletClient || !wallet2.publicClient) {
|
|
3565
4515
|
throw new Error(
|
|
3566
4516
|
"Wallet client and public client are required for withdraw."
|
|
@@ -3580,7 +4530,7 @@ async function withdrawFromHyperliquid(options) {
|
|
|
3580
4530
|
const message = {
|
|
3581
4531
|
hyperliquidChain,
|
|
3582
4532
|
destination: normalizedDestination,
|
|
3583
|
-
amount:
|
|
4533
|
+
amount: normalizedAmount,
|
|
3584
4534
|
time
|
|
3585
4535
|
};
|
|
3586
4536
|
const types = {
|
|
@@ -3605,7 +4555,7 @@ async function withdrawFromHyperliquid(options) {
|
|
|
3605
4555
|
signatureChainId,
|
|
3606
4556
|
hyperliquidChain,
|
|
3607
4557
|
destination: normalizedDestination,
|
|
3608
|
-
amount:
|
|
4558
|
+
amount: normalizedAmount,
|
|
3609
4559
|
time: nonce
|
|
3610
4560
|
},
|
|
3611
4561
|
nonce,
|
|
@@ -5852,6 +6802,29 @@ var SUPPORTED_EXTENSIONS = [
|
|
|
5852
6802
|
".mjs",
|
|
5853
6803
|
".cjs"
|
|
5854
6804
|
];
|
|
6805
|
+
var MIN_TEMPLATE_CONFIG_VERSION = 2;
|
|
6806
|
+
function normalizeTemplateConfigVersion(value) {
|
|
6807
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
6808
|
+
return value;
|
|
6809
|
+
}
|
|
6810
|
+
if (typeof value !== "string") {
|
|
6811
|
+
return null;
|
|
6812
|
+
}
|
|
6813
|
+
const trimmed = value.trim();
|
|
6814
|
+
if (!trimmed) {
|
|
6815
|
+
return null;
|
|
6816
|
+
}
|
|
6817
|
+
if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
6818
|
+
const numeric = Number.parseFloat(trimmed);
|
|
6819
|
+
return Number.isFinite(numeric) ? numeric : null;
|
|
6820
|
+
}
|
|
6821
|
+
const majorMatch = /^v?(\d+)(?:\..*)?$/i.exec(trimmed);
|
|
6822
|
+
if (!majorMatch) {
|
|
6823
|
+
return null;
|
|
6824
|
+
}
|
|
6825
|
+
const major = Number.parseInt(majorMatch[1], 10);
|
|
6826
|
+
return Number.isFinite(major) ? major : null;
|
|
6827
|
+
}
|
|
5855
6828
|
async function validateCommand(options) {
|
|
5856
6829
|
console.log("\u{1F50D} Validating OpenTool metadata...");
|
|
5857
6830
|
try {
|
|
@@ -6003,9 +6976,15 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
6003
6976
|
}
|
|
6004
6977
|
const record = templateConfigRaw;
|
|
6005
6978
|
const version = record.version;
|
|
6006
|
-
|
|
6979
|
+
const normalizedTemplateConfigVersion = normalizeTemplateConfigVersion(version);
|
|
6980
|
+
if (normalizedTemplateConfigVersion === null) {
|
|
6981
|
+
throw new Error(
|
|
6982
|
+
`${file}: profile.templateConfig.version must be a numeric string or number.`
|
|
6983
|
+
);
|
|
6984
|
+
}
|
|
6985
|
+
if (normalizedTemplateConfigVersion < MIN_TEMPLATE_CONFIG_VERSION) {
|
|
6007
6986
|
throw new Error(
|
|
6008
|
-
`${file}: profile.templateConfig.version must be
|
|
6987
|
+
`${file}: profile.templateConfig.version must be >= ${MIN_TEMPLATE_CONFIG_VERSION}.`
|
|
6009
6988
|
);
|
|
6010
6989
|
}
|
|
6011
6990
|
const schema2 = record.schema;
|
|
@@ -6331,6 +7310,6 @@ function timestamp() {
|
|
|
6331
7310
|
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
|
|
6332
7311
|
}
|
|
6333
7312
|
|
|
6334
|
-
export { AIAbortError, AIError, AIFetchError, AIResponseError, DEFAULT_BASE_URL, DEFAULT_CHAIN, DEFAULT_FACILITATOR, DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, DEFAULT_MODEL, DEFAULT_TIMEOUT_MS, DEFAULT_TOKENS, HTTP_METHODS2 as HTTP_METHODS, HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, PAYMENT_HEADERS, POLYMARKET_CHAIN_ID, POLYMARKET_CLOB_AUTH_DOMAIN, POLYMARKET_CLOB_DOMAIN, POLYMARKET_ENDPOINTS, POLYMARKET_EXCHANGE_ADDRESSES, PolymarketApiError, PolymarketAuthError, PolymarketExchangeClient, PolymarketInfoClient, SUPPORTED_CURRENCIES, StoreError, WEBSEARCH_TOOL_DEFINITION, WEBSEARCH_TOOL_NAME, X402BrowserClient, X402Client, X402PaymentRequiredError, __hyperliquidInternals, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, buildHmacSignature, buildHyperliquidMarketIdentity, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllHyperliquidOrders, cancelAllPolymarketOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, chains, computeHyperliquidMarketIocLimitPrice, createAIClient, createDevServer, createHyperliquidSubAccount, createMcpAdapter, createMonotonicNonceFactory, createPolymarketApiKey, createStdioServer, defineX402Payment, depositToHyperliquidBridge, derivePolymarketApiKey, ensureTextContent, executeTool, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPrice, fetchPolymarketPriceHistory, flattenMessageContent, generateMetadata, generateMetadataCommand, generateText, getHyperliquidMaxBuilderFee, getModelConfig, getMyPerformance, getMyTools, getRpcUrl, getX402PaymentContext, isStreamingSupported, isToolCallingSupported, listModels, loadAndValidateTools, modifyHyperliquidOrder, normalizeModelName, normalizeNumberArrayish, normalizeStringArrayish, payX402, payX402WithWallet, placeHyperliquidOrder, placeHyperliquidTwapOrder, placePolymarketOrder, postAgentDigest, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, registry, requireX402Payment, reserveHyperliquidRequestWeight, resolveConfig2 as resolveConfig, resolveExchangeAddress, resolveHyperliquidAbstractionFromMode, resolvePolymarketBaseUrl, resolveRuntimePath, resolveToolset, responseToToolResponse, retrieve, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidAccountAbstractionMode, setHyperliquidDexAbstraction, setHyperliquidPortfolioMargin, store, streamText, tokens, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, validateCommand, wallet, walletToolkit, withX402Payment, withdrawFromHyperliquid };
|
|
7313
|
+
export { AIAbortError, AIError, AIFetchError, AIResponseError, DEFAULT_BASE_URL, DEFAULT_CHAIN, DEFAULT_FACILITATOR, DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, DEFAULT_MODEL, DEFAULT_TIMEOUT_MS, DEFAULT_TOKENS, HTTP_METHODS2 as HTTP_METHODS, HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, PAYMENT_HEADERS, POLYMARKET_CHAIN_ID, POLYMARKET_CLOB_AUTH_DOMAIN, POLYMARKET_CLOB_DOMAIN, POLYMARKET_ENDPOINTS, POLYMARKET_EXCHANGE_ADDRESSES, PolymarketApiError, PolymarketAuthError, PolymarketExchangeClient, PolymarketInfoClient, SUPPORTED_CURRENCIES, StoreError, WEBSEARCH_TOOL_DEFINITION, WEBSEARCH_TOOL_NAME, X402BrowserClient, X402Client, X402PaymentRequiredError, __hyperliquidInternals, __hyperliquidMarketDataInternals, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, buildHmacSignature, buildHyperliquidMarketIdentity, buildHyperliquidProfileAssets, buildHyperliquidSpotUsdPriceMap, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllHyperliquidOrders, cancelAllPolymarketOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, chains, computeHyperliquidMarketIocLimitPrice, createAIClient, createDevServer, createHyperliquidSubAccount, createMcpAdapter, createMonotonicNonceFactory, createPolymarketApiKey, createStdioServer, defineX402Payment, depositToHyperliquidBridge, derivePolymarketApiKey, ensureTextContent, executeTool, extractHyperliquidDex, extractHyperliquidOrderIds, fetchHyperliquidAllMids, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPerpMarketInfo, fetchHyperliquidPreTransferCheck, fetchHyperliquidSizeDecimals, fetchHyperliquidSpotAccountValue, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMarketInfo, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidSpotTickSize, fetchHyperliquidSpotUsdPriceMap, fetchHyperliquidTickSize, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPrice, fetchPolymarketPriceHistory, flattenMessageContent, formatHyperliquidMarketablePrice, formatHyperliquidOrderSize, formatHyperliquidPrice, formatHyperliquidSize, generateMetadata, generateMetadataCommand, generateText, getHyperliquidMaxBuilderFee, getModelConfig, getMyPerformance, getMyTools, getRpcUrl, getX402PaymentContext, isHyperliquidSpotSymbol, isStreamingSupported, isToolCallingSupported, listModels, loadAndValidateTools, modifyHyperliquidOrder, normalizeHyperliquidBaseSymbol, normalizeHyperliquidMetaSymbol, normalizeModelName, normalizeNumberArrayish, normalizeSpotTokenName2 as normalizeSpotTokenName, normalizeStringArrayish, parseSpotPairSymbol, payX402, payX402WithWallet, placeHyperliquidOrder, placeHyperliquidTwapOrder, placePolymarketOrder, postAgentDigest, readHyperliquidAccountValue, readHyperliquidNumber, readHyperliquidPerpPosition, readHyperliquidPerpPositionSize, readHyperliquidSpotAccountValue, readHyperliquidSpotBalance, readHyperliquidSpotBalanceSize, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, registry, requireX402Payment, reserveHyperliquidRequestWeight, resolveConfig2 as resolveConfig, resolveExchangeAddress, resolveHyperliquidAbstractionFromMode, resolveHyperliquidChain, resolveHyperliquidChainConfig, resolveHyperliquidErrorDetail, resolveHyperliquidOrderRef, resolveHyperliquidOrderSymbol, resolveHyperliquidPair, resolveHyperliquidProfileChain, resolveHyperliquidRpcEnvVar, resolveHyperliquidStoreNetwork, resolveHyperliquidSymbol, resolvePolymarketBaseUrl, resolveRuntimePath, resolveSpotMidCandidates, resolveSpotTokenCandidates, resolveToolset, responseToToolResponse, retrieve, roundHyperliquidPriceToTick, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidAccountAbstractionMode, setHyperliquidDexAbstraction, setHyperliquidPortfolioMargin, store, streamText, tokens, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, validateCommand, wallet, walletToolkit, withX402Payment, withdrawFromHyperliquid };
|
|
6335
7314
|
//# sourceMappingURL=index.js.map
|
|
6336
7315
|
//# sourceMappingURL=index.js.map
|