opentool 0.15.0 → 0.16.0
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/browser.d.ts +1 -1
- package/dist/adapters/hyperliquid/browser.js +273 -248
- package/dist/adapters/hyperliquid/browser.js.map +1 -1
- package/dist/adapters/hyperliquid/index.d.ts +2 -2
- package/dist/adapters/hyperliquid/index.js +277 -252
- package/dist/adapters/hyperliquid/index.js.map +1 -1
- package/dist/{browser-DSwtpkyr.d.ts → browser-CY6nxlxO.d.ts} +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +277 -252
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/base/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { D as DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, a as DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS, H as HyperliquidAbstraction, b as HyperliquidAccountMode, c as HyperliquidApiError,
|
|
1
|
+
export { D as DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, a as DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS, H as HyperliquidAbstraction, b as HyperliquidAccountMode, c as HyperliquidApiError, b2 as HyperliquidApproveBuilderFeeOptions, b3 as HyperliquidApproveBuilderFeeResponse, d as HyperliquidApproximateLiquidationParams, g as HyperliquidBuilderApprovalError, h as HyperliquidBuilderFee, b4 as HyperliquidClearinghouseState, b5 as HyperliquidDepositResult, i as HyperliquidEnvironment, j as HyperliquidExchangeClient, k as HyperliquidExchangeResponse, l as HyperliquidGrouping, m as HyperliquidGuardError, o as HyperliquidInfoClient, p as HyperliquidMarketIdentityInput, r as HyperliquidOrderIntent, b6 as HyperliquidOrderOptions, b7 as HyperliquidOrderResponse, b8 as HyperliquidOrderStatus, s as HyperliquidParsedSymbol, t as HyperliquidParsedSymbolKind, v as HyperliquidPlaceOrderWithTpSlOptions, w as HyperliquidPlacePositionTpSlOptions, B as HyperliquidTermsError, E as HyperliquidTimeInForce, F as HyperliquidTpSlExecutionType, G as HyperliquidTpSlLegInput, I as HyperliquidTriggerOptions, J as HyperliquidTriggerType, b9 as HyperliquidWithdrawResult, M as MarketIdentity, ba as approveHyperliquidBuilderFee, K as batchModifyHyperliquidOrders, L as buildHyperliquidMarketIdentity, N as buildHyperliquidProfileAssets, P as cancelAllHyperliquidOrders, Q as cancelHyperliquidOrders, R as cancelHyperliquidOrdersByCloid, S as cancelHyperliquidTwapOrder, T as computeHyperliquidMarketIocLimitPrice, bb as createHyperliquidActionHash, U as createHyperliquidSubAccount, V as createMonotonicNonceFactory, bc as depositToHyperliquidBridge, W as estimateHyperliquidLiquidationPrice, X as extractHyperliquidDex, $ as fetchHyperliquidAssetCtxs, bd as fetchHyperliquidClearinghouseState, a2 as fetchHyperliquidFrontendOpenOrders, a3 as fetchHyperliquidHistoricalOrders, a4 as fetchHyperliquidMeta, a5 as fetchHyperliquidMetaAndAssetCtxs, a6 as fetchHyperliquidOpenOrders, a7 as fetchHyperliquidOrderStatus, a9 as fetchHyperliquidPreTransferCheck, aa as fetchHyperliquidSizeDecimals, ac as fetchHyperliquidSpotAssetCtxs, ad as fetchHyperliquidSpotClearinghouseState, af as fetchHyperliquidSpotMeta, ag as fetchHyperliquidSpotMetaAndAssetCtxs, aj as fetchHyperliquidTickSize, ak as fetchHyperliquidUserFills, al as fetchHyperliquidUserFillsByTime, am as fetchHyperliquidUserRateLimit, an as formatHyperliquidMarketablePrice, ap as formatHyperliquidPrice, aq as formatHyperliquidSize, be as getHyperliquidMaxBuilderFee, ar as isHyperliquidSpotSymbol, as as modifyHyperliquidOrder, at as normalizeHyperliquidBaseSymbol, av as normalizeHyperliquidMetaSymbol, aw as normalizeSpotTokenName, ax as parseHyperliquidSymbol, ay as parseSpotPairSymbol, bf as placeHyperliquidOrder, az as placeHyperliquidOrderWithTpSl, aA as placeHyperliquidPositionTpSl, aB as placeHyperliquidTwapOrder, aC as reserveHyperliquidRequestWeight, aD as resolveHyperliquidAbstractionFromMode, aF as resolveHyperliquidLeverageMode, aG as resolveHyperliquidMarketDataCoin, aI as resolveHyperliquidOrderSymbol, aJ as resolveHyperliquidPair, aK as resolveHyperliquidPerpSymbol, aL as resolveHyperliquidProfileChain, aM as resolveHyperliquidSpotSymbol, aN as resolveHyperliquidSymbol, aO as resolveSpotMidCandidates, aP as resolveSpotTokenCandidates, aR as scheduleHyperliquidCancel, aS as sendHyperliquidSpot, aT as setHyperliquidAccountAbstractionMode, aU as setHyperliquidDexAbstraction, aV as setHyperliquidPortfolioMargin, aW as supportsHyperliquidBuilderFee, aX as transferHyperliquidSubAccount, aY as updateHyperliquidIsolatedMargin, aZ as updateHyperliquidLeverage, bg as withdrawFromHyperliquid } from '../../browser-CY6nxlxO.js';
|
|
2
2
|
import '../../types-BaTmu0gS.js';
|
|
3
3
|
import 'viem';
|
|
4
4
|
import 'viem/accounts';
|
|
@@ -1574,6 +1574,272 @@ async function postExchange(env, body) {
|
|
|
1574
1574
|
}
|
|
1575
1575
|
return json;
|
|
1576
1576
|
}
|
|
1577
|
+
|
|
1578
|
+
// src/adapters/hyperliquid/symbols.ts
|
|
1579
|
+
var UNKNOWN_SYMBOL2 = "UNKNOWN";
|
|
1580
|
+
function extractHyperliquidDex(symbol) {
|
|
1581
|
+
const idx = symbol.indexOf(":");
|
|
1582
|
+
if (idx <= 0) return null;
|
|
1583
|
+
const dex = symbol.slice(0, idx).trim().toLowerCase();
|
|
1584
|
+
return dex || null;
|
|
1585
|
+
}
|
|
1586
|
+
function parseHyperliquidSymbol(value) {
|
|
1587
|
+
if (!value) return null;
|
|
1588
|
+
const trimmed = value.trim();
|
|
1589
|
+
if (!trimmed) return null;
|
|
1590
|
+
if (trimmed.startsWith("@")) {
|
|
1591
|
+
return {
|
|
1592
|
+
raw: trimmed,
|
|
1593
|
+
kind: "spotIndex",
|
|
1594
|
+
normalized: trimmed,
|
|
1595
|
+
routeTicker: trimmed,
|
|
1596
|
+
displaySymbol: trimmed,
|
|
1597
|
+
base: null,
|
|
1598
|
+
quote: null,
|
|
1599
|
+
pair: null,
|
|
1600
|
+
dex: null,
|
|
1601
|
+
leverageMode: "cross"
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
const dex = extractHyperliquidDex(trimmed);
|
|
1605
|
+
const pair = resolveHyperliquidPair(trimmed);
|
|
1606
|
+
const base = normalizeHyperliquidBaseSymbol(trimmed);
|
|
1607
|
+
if (dex) {
|
|
1608
|
+
if (!base) return null;
|
|
1609
|
+
return {
|
|
1610
|
+
raw: trimmed,
|
|
1611
|
+
kind: "perp",
|
|
1612
|
+
normalized: `${dex}:${base}`,
|
|
1613
|
+
routeTicker: `${dex}:${base}`,
|
|
1614
|
+
displaySymbol: `${dex.toUpperCase()}:${base}-USDC`,
|
|
1615
|
+
base,
|
|
1616
|
+
quote: null,
|
|
1617
|
+
pair: null,
|
|
1618
|
+
dex,
|
|
1619
|
+
leverageMode: "isolated"
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
if (pair) {
|
|
1623
|
+
const [pairBase, pairQuote] = pair.split("/");
|
|
1624
|
+
return {
|
|
1625
|
+
raw: trimmed,
|
|
1626
|
+
kind: "spot",
|
|
1627
|
+
normalized: pair,
|
|
1628
|
+
routeTicker: pair.replace("/", "-"),
|
|
1629
|
+
displaySymbol: pair.replace("/", "-"),
|
|
1630
|
+
base: pairBase ?? null,
|
|
1631
|
+
quote: pairQuote ?? null,
|
|
1632
|
+
pair,
|
|
1633
|
+
dex: null,
|
|
1634
|
+
leverageMode: "cross"
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
if (!base) return null;
|
|
1638
|
+
return {
|
|
1639
|
+
raw: trimmed,
|
|
1640
|
+
kind: "perp",
|
|
1641
|
+
normalized: base,
|
|
1642
|
+
routeTicker: base,
|
|
1643
|
+
displaySymbol: `${base}-USDC`,
|
|
1644
|
+
base,
|
|
1645
|
+
quote: null,
|
|
1646
|
+
pair: null,
|
|
1647
|
+
dex: null,
|
|
1648
|
+
leverageMode: "cross"
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
function normalizeSpotTokenName2(value) {
|
|
1652
|
+
const raw = (value ?? "").trim();
|
|
1653
|
+
if (!raw) return "";
|
|
1654
|
+
if (raw.endsWith("0") && raw.length > 1) {
|
|
1655
|
+
return raw.slice(0, -1);
|
|
1656
|
+
}
|
|
1657
|
+
return raw;
|
|
1658
|
+
}
|
|
1659
|
+
function canonicalizeHyperliquidTokenCase(value) {
|
|
1660
|
+
const trimmed = value.trim();
|
|
1661
|
+
if (!trimmed) return "";
|
|
1662
|
+
return trimmed === trimmed.toLowerCase() ? trimmed.toUpperCase() : trimmed;
|
|
1663
|
+
}
|
|
1664
|
+
function normalizeHyperliquidBaseSymbol(value) {
|
|
1665
|
+
if (!value) return null;
|
|
1666
|
+
const trimmed = value.trim();
|
|
1667
|
+
if (!trimmed) return null;
|
|
1668
|
+
const withoutDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
1669
|
+
const base = withoutDex.split("-")[0] ?? withoutDex;
|
|
1670
|
+
const baseNoPair = base.split("/")[0] ?? base;
|
|
1671
|
+
const normalized = canonicalizeHyperliquidTokenCase(baseNoPair);
|
|
1672
|
+
if (!normalized || normalized === UNKNOWN_SYMBOL2) return null;
|
|
1673
|
+
return normalized;
|
|
1674
|
+
}
|
|
1675
|
+
function normalizeHyperliquidMetaSymbol(symbol) {
|
|
1676
|
+
const trimmed = symbol.trim();
|
|
1677
|
+
const noDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
1678
|
+
const noPair = noDex.split("-")[0] ?? noDex;
|
|
1679
|
+
return (noPair.split("/")[0] ?? noPair).trim();
|
|
1680
|
+
}
|
|
1681
|
+
function resolveHyperliquidPair(value) {
|
|
1682
|
+
if (!value) return null;
|
|
1683
|
+
const trimmed = value.trim();
|
|
1684
|
+
if (!trimmed) return null;
|
|
1685
|
+
const withoutDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
1686
|
+
if (withoutDex.includes("/")) {
|
|
1687
|
+
const [base, ...rest] = withoutDex.split("/");
|
|
1688
|
+
const quote = rest.join("/").trim();
|
|
1689
|
+
if (!base || !quote) return null;
|
|
1690
|
+
return `${canonicalizeHyperliquidTokenCase(base)}/${canonicalizeHyperliquidTokenCase(quote)}`;
|
|
1691
|
+
}
|
|
1692
|
+
if (withoutDex.includes("-")) {
|
|
1693
|
+
const [base, ...rest] = withoutDex.split("-");
|
|
1694
|
+
const quote = rest.join("-").trim();
|
|
1695
|
+
if (!base || !quote) return null;
|
|
1696
|
+
return `${canonicalizeHyperliquidTokenCase(base)}/${canonicalizeHyperliquidTokenCase(quote)}`;
|
|
1697
|
+
}
|
|
1698
|
+
return null;
|
|
1699
|
+
}
|
|
1700
|
+
function resolveHyperliquidLeverageMode(symbol) {
|
|
1701
|
+
return symbol.includes(":") ? "isolated" : "cross";
|
|
1702
|
+
}
|
|
1703
|
+
function resolveHyperliquidProfileChain(environment) {
|
|
1704
|
+
return environment === "testnet" ? "hyperliquid-testnet" : "hyperliquid";
|
|
1705
|
+
}
|
|
1706
|
+
function buildHyperliquidProfileAssets(params) {
|
|
1707
|
+
const chain = resolveHyperliquidProfileChain(params.environment);
|
|
1708
|
+
return params.assets.map((asset) => {
|
|
1709
|
+
const symbols = asset.assetSymbols.map((symbol) => normalizeHyperliquidBaseSymbol(symbol)).filter((symbol) => Boolean(symbol));
|
|
1710
|
+
if (symbols.length === 0) return null;
|
|
1711
|
+
const explicitPair = typeof asset.pair === "string" ? resolveHyperliquidPair(asset.pair) : null;
|
|
1712
|
+
const derivedPair = symbols.length === 1 ? resolveHyperliquidPair(asset.assetSymbols[0] ?? symbols[0]) : null;
|
|
1713
|
+
const pair = explicitPair ?? derivedPair ?? void 0;
|
|
1714
|
+
const leverage = typeof asset.leverage === "number" && Number.isFinite(asset.leverage) && asset.leverage > 0 ? asset.leverage : void 0;
|
|
1715
|
+
const walletAddress = typeof asset.walletAddress === "string" && asset.walletAddress.trim().length > 0 ? asset.walletAddress.trim() : void 0;
|
|
1716
|
+
return {
|
|
1717
|
+
venue: "hyperliquid",
|
|
1718
|
+
chain,
|
|
1719
|
+
assetSymbols: symbols,
|
|
1720
|
+
...pair ? { pair } : {},
|
|
1721
|
+
...leverage ? { leverage } : {},
|
|
1722
|
+
...walletAddress ? { walletAddress } : {}
|
|
1723
|
+
};
|
|
1724
|
+
}).filter((asset) => asset !== null);
|
|
1725
|
+
}
|
|
1726
|
+
function parseSpotPairSymbol(symbol) {
|
|
1727
|
+
const trimmed = symbol.trim();
|
|
1728
|
+
if (!trimmed.includes("/")) return null;
|
|
1729
|
+
const [rawBase, rawQuote] = trimmed.split("/");
|
|
1730
|
+
const base = rawBase?.trim().toUpperCase() ?? "";
|
|
1731
|
+
const quote = rawQuote?.trim().toUpperCase() ?? "";
|
|
1732
|
+
if (!base || !quote) return null;
|
|
1733
|
+
return { base, quote };
|
|
1734
|
+
}
|
|
1735
|
+
function isHyperliquidSpotSymbol(symbol) {
|
|
1736
|
+
const trimmed = symbol.trim();
|
|
1737
|
+
if (!trimmed) return false;
|
|
1738
|
+
if (trimmed.startsWith("@") || trimmed.includes("/")) return true;
|
|
1739
|
+
if (trimmed.includes(":")) return false;
|
|
1740
|
+
return resolveHyperliquidPair(trimmed) !== null;
|
|
1741
|
+
}
|
|
1742
|
+
function resolveHyperliquidMarketDataCoin(value) {
|
|
1743
|
+
if (!value) return null;
|
|
1744
|
+
const trimmed = value.trim();
|
|
1745
|
+
if (!trimmed) return null;
|
|
1746
|
+
if (trimmed.startsWith("@")) return trimmed;
|
|
1747
|
+
const pair = resolveHyperliquidPair(trimmed);
|
|
1748
|
+
if (pair && !extractHyperliquidDex(trimmed)) {
|
|
1749
|
+
return pair;
|
|
1750
|
+
}
|
|
1751
|
+
return trimmed;
|
|
1752
|
+
}
|
|
1753
|
+
function supportsHyperliquidBuilderFee(params) {
|
|
1754
|
+
if (!isHyperliquidSpotSymbol(params.symbol)) {
|
|
1755
|
+
return true;
|
|
1756
|
+
}
|
|
1757
|
+
return params.side === "sell";
|
|
1758
|
+
}
|
|
1759
|
+
function resolveSpotMidCandidates(baseSymbol) {
|
|
1760
|
+
const base = baseSymbol.trim().toUpperCase();
|
|
1761
|
+
if (!base) return [];
|
|
1762
|
+
const candidates = [base];
|
|
1763
|
+
if (base.startsWith("U") && base.length > 1) {
|
|
1764
|
+
candidates.push(base.slice(1));
|
|
1765
|
+
}
|
|
1766
|
+
return Array.from(new Set(candidates));
|
|
1767
|
+
}
|
|
1768
|
+
function resolveSpotTokenCandidates(value) {
|
|
1769
|
+
const normalized = normalizeSpotTokenName2(value).toUpperCase();
|
|
1770
|
+
if (!normalized) return [];
|
|
1771
|
+
const candidates = [normalized];
|
|
1772
|
+
if (normalized.startsWith("U") && normalized.length > 1) {
|
|
1773
|
+
candidates.push(normalized.slice(1));
|
|
1774
|
+
}
|
|
1775
|
+
return Array.from(new Set(candidates));
|
|
1776
|
+
}
|
|
1777
|
+
function resolveHyperliquidOrderSymbol(value) {
|
|
1778
|
+
if (!value) return null;
|
|
1779
|
+
const trimmed = value.trim();
|
|
1780
|
+
if (!trimmed) return null;
|
|
1781
|
+
if (trimmed.startsWith("@")) return trimmed;
|
|
1782
|
+
if (trimmed.includes(":")) {
|
|
1783
|
+
const [rawDex, ...restParts] = trimmed.split(":");
|
|
1784
|
+
const dex = rawDex.trim().toLowerCase();
|
|
1785
|
+
const rest = restParts.join(":");
|
|
1786
|
+
const normalizedBase = normalizeHyperliquidBaseSymbol(rest);
|
|
1787
|
+
if (!dex || !normalizedBase || normalizedBase === UNKNOWN_SYMBOL2) {
|
|
1788
|
+
return null;
|
|
1789
|
+
}
|
|
1790
|
+
return `${dex}:${normalizedBase}`;
|
|
1791
|
+
}
|
|
1792
|
+
const pair = resolveHyperliquidPair(trimmed);
|
|
1793
|
+
if (pair) return pair;
|
|
1794
|
+
return normalizeHyperliquidBaseSymbol(trimmed);
|
|
1795
|
+
}
|
|
1796
|
+
function resolveHyperliquidSymbol(asset, override) {
|
|
1797
|
+
const raw = override && override.trim().length > 0 ? override.trim() : asset.trim();
|
|
1798
|
+
if (!raw) return raw;
|
|
1799
|
+
if (raw.startsWith("@")) return raw;
|
|
1800
|
+
if (raw.includes(":")) {
|
|
1801
|
+
const [dexRaw, ...restParts] = raw.split(":");
|
|
1802
|
+
const dex = dexRaw.trim().toLowerCase();
|
|
1803
|
+
const rest = restParts.join(":");
|
|
1804
|
+
const normalizedBase = normalizeHyperliquidBaseSymbol(rest) ?? canonicalizeHyperliquidTokenCase(rest);
|
|
1805
|
+
if (!dex) return normalizedBase;
|
|
1806
|
+
return `${dex}:${normalizedBase}`;
|
|
1807
|
+
}
|
|
1808
|
+
if (raw.includes("/")) {
|
|
1809
|
+
return resolveHyperliquidPair(raw) ?? raw;
|
|
1810
|
+
}
|
|
1811
|
+
if (raw.includes("-")) {
|
|
1812
|
+
return resolveHyperliquidPair(raw) ?? raw;
|
|
1813
|
+
}
|
|
1814
|
+
return normalizeHyperliquidBaseSymbol(raw) ?? canonicalizeHyperliquidTokenCase(raw);
|
|
1815
|
+
}
|
|
1816
|
+
function resolveHyperliquidPerpSymbol(asset) {
|
|
1817
|
+
const raw = asset.trim();
|
|
1818
|
+
if (!raw) return raw;
|
|
1819
|
+
const dex = extractHyperliquidDex(raw);
|
|
1820
|
+
const base = normalizeHyperliquidBaseSymbol(raw) ?? raw.toUpperCase();
|
|
1821
|
+
return dex ? `${dex}:${base}` : base;
|
|
1822
|
+
}
|
|
1823
|
+
function resolveHyperliquidSpotSymbol(asset, defaultQuote = "USDC") {
|
|
1824
|
+
const quote = defaultQuote.trim().toUpperCase() || "USDC";
|
|
1825
|
+
const raw = asset.trim().toUpperCase();
|
|
1826
|
+
if (!raw) {
|
|
1827
|
+
return { symbol: raw, base: raw, quote };
|
|
1828
|
+
}
|
|
1829
|
+
const pair = resolveHyperliquidPair(raw);
|
|
1830
|
+
if (pair) {
|
|
1831
|
+
const [base2, pairQuote] = pair.split("/");
|
|
1832
|
+
return {
|
|
1833
|
+
symbol: pair,
|
|
1834
|
+
base: base2?.trim() ?? raw,
|
|
1835
|
+
quote: pairQuote?.trim() ?? quote
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
const base = normalizeHyperliquidBaseSymbol(raw) ?? raw;
|
|
1839
|
+
return { symbol: `${base}/${quote}`, base, quote };
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
// src/adapters/hyperliquid/actions.ts
|
|
1577
1843
|
function resolveRequiredNonce(params) {
|
|
1578
1844
|
if (typeof params.nonce === "number") {
|
|
1579
1845
|
return params.nonce;
|
|
@@ -1680,12 +1946,14 @@ async function placeHyperliquidOrder(options) {
|
|
|
1680
1946
|
const action = {
|
|
1681
1947
|
type: "order",
|
|
1682
1948
|
orders: preparedOrders,
|
|
1683
|
-
grouping
|
|
1684
|
-
|
|
1949
|
+
grouping
|
|
1950
|
+
};
|
|
1951
|
+
if (orders.every((intent) => supportsHyperliquidBuilderFee(intent))) {
|
|
1952
|
+
action.builder = {
|
|
1685
1953
|
b: normalizeAddress(BUILDER_CODE.address),
|
|
1686
1954
|
f: BUILDER_CODE.fee
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1689
1957
|
const effectiveNonce = resolveRequiredNonce({
|
|
1690
1958
|
nonce,
|
|
1691
1959
|
nonceSource: options.nonceSource,
|
|
@@ -1951,249 +2219,6 @@ async function getHyperliquidMaxBuilderFee(params) {
|
|
|
1951
2219
|
function createHyperliquidActionHash(params) {
|
|
1952
2220
|
return createL1ActionHash(params);
|
|
1953
2221
|
}
|
|
1954
|
-
|
|
1955
|
-
// src/adapters/hyperliquid/symbols.ts
|
|
1956
|
-
var UNKNOWN_SYMBOL2 = "UNKNOWN";
|
|
1957
|
-
function extractHyperliquidDex(symbol) {
|
|
1958
|
-
const idx = symbol.indexOf(":");
|
|
1959
|
-
if (idx <= 0) return null;
|
|
1960
|
-
const dex = symbol.slice(0, idx).trim().toLowerCase();
|
|
1961
|
-
return dex || null;
|
|
1962
|
-
}
|
|
1963
|
-
function parseHyperliquidSymbol(value) {
|
|
1964
|
-
if (!value) return null;
|
|
1965
|
-
const trimmed = value.trim();
|
|
1966
|
-
if (!trimmed) return null;
|
|
1967
|
-
if (trimmed.startsWith("@")) {
|
|
1968
|
-
return {
|
|
1969
|
-
raw: trimmed,
|
|
1970
|
-
kind: "spotIndex",
|
|
1971
|
-
normalized: trimmed,
|
|
1972
|
-
routeTicker: trimmed,
|
|
1973
|
-
displaySymbol: trimmed,
|
|
1974
|
-
base: null,
|
|
1975
|
-
quote: null,
|
|
1976
|
-
pair: null,
|
|
1977
|
-
dex: null,
|
|
1978
|
-
leverageMode: "cross"
|
|
1979
|
-
};
|
|
1980
|
-
}
|
|
1981
|
-
const dex = extractHyperliquidDex(trimmed);
|
|
1982
|
-
const pair = resolveHyperliquidPair(trimmed);
|
|
1983
|
-
const base = normalizeHyperliquidBaseSymbol(trimmed);
|
|
1984
|
-
if (dex) {
|
|
1985
|
-
if (!base) return null;
|
|
1986
|
-
return {
|
|
1987
|
-
raw: trimmed,
|
|
1988
|
-
kind: "perp",
|
|
1989
|
-
normalized: `${dex}:${base}`,
|
|
1990
|
-
routeTicker: `${dex}:${base}`,
|
|
1991
|
-
displaySymbol: `${dex.toUpperCase()}:${base}-USDC`,
|
|
1992
|
-
base,
|
|
1993
|
-
quote: null,
|
|
1994
|
-
pair: null,
|
|
1995
|
-
dex,
|
|
1996
|
-
leverageMode: "isolated"
|
|
1997
|
-
};
|
|
1998
|
-
}
|
|
1999
|
-
if (pair) {
|
|
2000
|
-
const [pairBase, pairQuote] = pair.split("/");
|
|
2001
|
-
return {
|
|
2002
|
-
raw: trimmed,
|
|
2003
|
-
kind: "spot",
|
|
2004
|
-
normalized: pair,
|
|
2005
|
-
routeTicker: pair.replace("/", "-"),
|
|
2006
|
-
displaySymbol: pair.replace("/", "-"),
|
|
2007
|
-
base: pairBase ?? null,
|
|
2008
|
-
quote: pairQuote ?? null,
|
|
2009
|
-
pair,
|
|
2010
|
-
dex: null,
|
|
2011
|
-
leverageMode: "cross"
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
if (!base) return null;
|
|
2015
|
-
return {
|
|
2016
|
-
raw: trimmed,
|
|
2017
|
-
kind: "perp",
|
|
2018
|
-
normalized: base,
|
|
2019
|
-
routeTicker: base,
|
|
2020
|
-
displaySymbol: `${base}-USDC`,
|
|
2021
|
-
base,
|
|
2022
|
-
quote: null,
|
|
2023
|
-
pair: null,
|
|
2024
|
-
dex: null,
|
|
2025
|
-
leverageMode: "cross"
|
|
2026
|
-
};
|
|
2027
|
-
}
|
|
2028
|
-
function normalizeSpotTokenName2(value) {
|
|
2029
|
-
const raw = (value ?? "").trim();
|
|
2030
|
-
if (!raw) return "";
|
|
2031
|
-
if (raw.endsWith("0") && raw.length > 1) {
|
|
2032
|
-
return raw.slice(0, -1);
|
|
2033
|
-
}
|
|
2034
|
-
return raw;
|
|
2035
|
-
}
|
|
2036
|
-
function normalizeHyperliquidBaseSymbol(value) {
|
|
2037
|
-
if (!value) return null;
|
|
2038
|
-
const trimmed = value.trim();
|
|
2039
|
-
if (!trimmed) return null;
|
|
2040
|
-
const withoutDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
2041
|
-
const base = withoutDex.split("-")[0] ?? withoutDex;
|
|
2042
|
-
const baseNoPair = base.split("/")[0] ?? base;
|
|
2043
|
-
const normalized = baseNoPair.trim().toUpperCase();
|
|
2044
|
-
if (!normalized || normalized === UNKNOWN_SYMBOL2) return null;
|
|
2045
|
-
return normalized;
|
|
2046
|
-
}
|
|
2047
|
-
function normalizeHyperliquidMetaSymbol(symbol) {
|
|
2048
|
-
const trimmed = symbol.trim();
|
|
2049
|
-
const noDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
2050
|
-
const noPair = noDex.split("-")[0] ?? noDex;
|
|
2051
|
-
return (noPair.split("/")[0] ?? noPair).trim();
|
|
2052
|
-
}
|
|
2053
|
-
function resolveHyperliquidPair(value) {
|
|
2054
|
-
if (!value) return null;
|
|
2055
|
-
const trimmed = value.trim();
|
|
2056
|
-
if (!trimmed) return null;
|
|
2057
|
-
const withoutDex = trimmed.includes(":") ? trimmed.split(":").slice(1).join(":") : trimmed;
|
|
2058
|
-
if (withoutDex.includes("/")) {
|
|
2059
|
-
return withoutDex.toUpperCase();
|
|
2060
|
-
}
|
|
2061
|
-
if (withoutDex.includes("-")) {
|
|
2062
|
-
const [base, ...rest] = withoutDex.split("-");
|
|
2063
|
-
const quote = rest.join("-").trim();
|
|
2064
|
-
if (!base || !quote) return null;
|
|
2065
|
-
return `${base.toUpperCase()}/${quote.toUpperCase()}`;
|
|
2066
|
-
}
|
|
2067
|
-
return null;
|
|
2068
|
-
}
|
|
2069
|
-
function resolveHyperliquidLeverageMode(symbol) {
|
|
2070
|
-
return symbol.includes(":") ? "isolated" : "cross";
|
|
2071
|
-
}
|
|
2072
|
-
function resolveHyperliquidProfileChain(environment) {
|
|
2073
|
-
return environment === "testnet" ? "hyperliquid-testnet" : "hyperliquid";
|
|
2074
|
-
}
|
|
2075
|
-
function buildHyperliquidProfileAssets(params) {
|
|
2076
|
-
const chain = resolveHyperliquidProfileChain(params.environment);
|
|
2077
|
-
return params.assets.map((asset) => {
|
|
2078
|
-
const symbols = asset.assetSymbols.map((symbol) => normalizeHyperliquidBaseSymbol(symbol)).filter((symbol) => Boolean(symbol));
|
|
2079
|
-
if (symbols.length === 0) return null;
|
|
2080
|
-
const explicitPair = typeof asset.pair === "string" ? resolveHyperliquidPair(asset.pair) : null;
|
|
2081
|
-
const derivedPair = symbols.length === 1 ? resolveHyperliquidPair(asset.assetSymbols[0] ?? symbols[0]) : null;
|
|
2082
|
-
const pair = explicitPair ?? derivedPair ?? void 0;
|
|
2083
|
-
const leverage = typeof asset.leverage === "number" && Number.isFinite(asset.leverage) && asset.leverage > 0 ? asset.leverage : void 0;
|
|
2084
|
-
const walletAddress = typeof asset.walletAddress === "string" && asset.walletAddress.trim().length > 0 ? asset.walletAddress.trim() : void 0;
|
|
2085
|
-
return {
|
|
2086
|
-
venue: "hyperliquid",
|
|
2087
|
-
chain,
|
|
2088
|
-
assetSymbols: symbols,
|
|
2089
|
-
...pair ? { pair } : {},
|
|
2090
|
-
...leverage ? { leverage } : {},
|
|
2091
|
-
...walletAddress ? { walletAddress } : {}
|
|
2092
|
-
};
|
|
2093
|
-
}).filter((asset) => asset !== null);
|
|
2094
|
-
}
|
|
2095
|
-
function parseSpotPairSymbol(symbol) {
|
|
2096
|
-
const trimmed = symbol.trim();
|
|
2097
|
-
if (!trimmed.includes("/")) return null;
|
|
2098
|
-
const [rawBase, rawQuote] = trimmed.split("/");
|
|
2099
|
-
const base = rawBase?.trim().toUpperCase() ?? "";
|
|
2100
|
-
const quote = rawQuote?.trim().toUpperCase() ?? "";
|
|
2101
|
-
if (!base || !quote) return null;
|
|
2102
|
-
return { base, quote };
|
|
2103
|
-
}
|
|
2104
|
-
function isHyperliquidSpotSymbol(symbol) {
|
|
2105
|
-
return symbol.startsWith("@") || symbol.includes("/");
|
|
2106
|
-
}
|
|
2107
|
-
function resolveSpotMidCandidates(baseSymbol) {
|
|
2108
|
-
const base = baseSymbol.trim().toUpperCase();
|
|
2109
|
-
if (!base) return [];
|
|
2110
|
-
const candidates = [base];
|
|
2111
|
-
if (base.startsWith("U") && base.length > 1) {
|
|
2112
|
-
candidates.push(base.slice(1));
|
|
2113
|
-
}
|
|
2114
|
-
return Array.from(new Set(candidates));
|
|
2115
|
-
}
|
|
2116
|
-
function resolveSpotTokenCandidates(value) {
|
|
2117
|
-
const normalized = normalizeSpotTokenName2(value).toUpperCase();
|
|
2118
|
-
if (!normalized) return [];
|
|
2119
|
-
const candidates = [normalized];
|
|
2120
|
-
if (normalized.startsWith("U") && normalized.length > 1) {
|
|
2121
|
-
candidates.push(normalized.slice(1));
|
|
2122
|
-
}
|
|
2123
|
-
return Array.from(new Set(candidates));
|
|
2124
|
-
}
|
|
2125
|
-
function resolveHyperliquidOrderSymbol(value) {
|
|
2126
|
-
if (!value) return null;
|
|
2127
|
-
const trimmed = value.trim();
|
|
2128
|
-
if (!trimmed) return null;
|
|
2129
|
-
if (trimmed.startsWith("@")) return trimmed;
|
|
2130
|
-
if (trimmed.includes(":")) {
|
|
2131
|
-
const [rawDex, ...restParts] = trimmed.split(":");
|
|
2132
|
-
const dex = rawDex.trim().toLowerCase();
|
|
2133
|
-
const rest = restParts.join(":");
|
|
2134
|
-
const base = rest.split("/")[0]?.split("-")[0] ?? rest;
|
|
2135
|
-
const normalizedBase = base.trim().toUpperCase();
|
|
2136
|
-
if (!dex || !normalizedBase || normalizedBase === UNKNOWN_SYMBOL2) {
|
|
2137
|
-
return null;
|
|
2138
|
-
}
|
|
2139
|
-
return `${dex}:${normalizedBase}`;
|
|
2140
|
-
}
|
|
2141
|
-
const pair = resolveHyperliquidPair(trimmed);
|
|
2142
|
-
if (pair) return pair;
|
|
2143
|
-
return normalizeHyperliquidBaseSymbol(trimmed);
|
|
2144
|
-
}
|
|
2145
|
-
function resolveHyperliquidSymbol(asset, override) {
|
|
2146
|
-
const raw = override && override.trim().length > 0 ? override.trim() : asset.trim();
|
|
2147
|
-
if (!raw) return raw;
|
|
2148
|
-
if (raw.startsWith("@")) return raw;
|
|
2149
|
-
if (raw.includes(":")) {
|
|
2150
|
-
const [dexRaw, ...restParts] = raw.split(":");
|
|
2151
|
-
const dex = dexRaw.trim().toLowerCase();
|
|
2152
|
-
const rest = restParts.join(":");
|
|
2153
|
-
const base2 = rest.split("/")[0]?.split("-")[0] ?? rest;
|
|
2154
|
-
const normalizedBase = base2.trim().toUpperCase();
|
|
2155
|
-
if (!dex) return normalizedBase;
|
|
2156
|
-
return `${dex}:${normalizedBase}`;
|
|
2157
|
-
}
|
|
2158
|
-
if (raw.includes("/")) {
|
|
2159
|
-
return raw.toUpperCase();
|
|
2160
|
-
}
|
|
2161
|
-
if (raw.includes("-")) {
|
|
2162
|
-
const [base2, ...rest] = raw.split("-");
|
|
2163
|
-
const quote = rest.join("-").trim();
|
|
2164
|
-
if (base2 && quote) {
|
|
2165
|
-
return `${base2.toUpperCase()}/${quote.toUpperCase()}`;
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
const base = raw.split("-")[0] ?? raw;
|
|
2169
|
-
const baseNoPair = base.split("/")[0] ?? base;
|
|
2170
|
-
return baseNoPair.trim().toUpperCase();
|
|
2171
|
-
}
|
|
2172
|
-
function resolveHyperliquidPerpSymbol(asset) {
|
|
2173
|
-
const raw = asset.trim();
|
|
2174
|
-
if (!raw) return raw;
|
|
2175
|
-
const dex = extractHyperliquidDex(raw);
|
|
2176
|
-
const base = normalizeHyperliquidBaseSymbol(raw) ?? raw.toUpperCase();
|
|
2177
|
-
return dex ? `${dex}:${base}` : base;
|
|
2178
|
-
}
|
|
2179
|
-
function resolveHyperliquidSpotSymbol(asset, defaultQuote = "USDC") {
|
|
2180
|
-
const quote = defaultQuote.trim().toUpperCase() || "USDC";
|
|
2181
|
-
const raw = asset.trim().toUpperCase();
|
|
2182
|
-
if (!raw) {
|
|
2183
|
-
return { symbol: raw, base: raw, quote };
|
|
2184
|
-
}
|
|
2185
|
-
const pair = resolveHyperliquidPair(raw);
|
|
2186
|
-
if (pair) {
|
|
2187
|
-
const [base2, pairQuote] = pair.split("/");
|
|
2188
|
-
return {
|
|
2189
|
-
symbol: pair,
|
|
2190
|
-
base: base2?.trim() ?? raw,
|
|
2191
|
-
quote: pairQuote?.trim() ?? quote
|
|
2192
|
-
};
|
|
2193
|
-
}
|
|
2194
|
-
const base = normalizeHyperliquidBaseSymbol(raw) ?? raw;
|
|
2195
|
-
return { symbol: `${base}/${quote}`, base, quote };
|
|
2196
|
-
}
|
|
2197
2222
|
function gcd(a, b) {
|
|
2198
2223
|
let left = a < 0n ? -a : a;
|
|
2199
2224
|
let right = b < 0n ? -b : b;
|
|
@@ -2758,6 +2783,6 @@ function estimateHyperliquidLiquidationPrice(params) {
|
|
|
2758
2783
|
return liquidationPrice;
|
|
2759
2784
|
}
|
|
2760
2785
|
|
|
2761
|
-
export { DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS, HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, buildHyperliquidMarketIdentity, buildHyperliquidProfileAssets, cancelAllHyperliquidOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, computeHyperliquidMarketIocLimitPrice, createHyperliquidActionHash, createHyperliquidSubAccount, createMonotonicNonceFactory, depositToHyperliquidBridge, estimateHyperliquidLiquidationPrice, extractHyperliquidDex, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSizeDecimals, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidTickSize, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, formatHyperliquidMarketablePrice, formatHyperliquidPrice, formatHyperliquidSize, getHyperliquidMaxBuilderFee, isHyperliquidSpotSymbol, modifyHyperliquidOrder, normalizeHyperliquidBaseSymbol, normalizeHyperliquidMetaSymbol, normalizeSpotTokenName2 as normalizeSpotTokenName, parseHyperliquidSymbol, parseSpotPairSymbol, placeHyperliquidOrder, placeHyperliquidOrderWithTpSl, placeHyperliquidPositionTpSl, placeHyperliquidTwapOrder, reserveHyperliquidRequestWeight, resolveHyperliquidAbstractionFromMode, resolveHyperliquidLeverageMode, resolveHyperliquidOrderSymbol, resolveHyperliquidPair, resolveHyperliquidPerpSymbol, resolveHyperliquidProfileChain, resolveHyperliquidSpotSymbol, resolveHyperliquidSymbol, resolveSpotMidCandidates, resolveSpotTokenCandidates, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidAccountAbstractionMode, setHyperliquidDexAbstraction, setHyperliquidPortfolioMargin, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, withdrawFromHyperliquid };
|
|
2786
|
+
export { DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS, HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, buildHyperliquidMarketIdentity, buildHyperliquidProfileAssets, cancelAllHyperliquidOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, computeHyperliquidMarketIocLimitPrice, createHyperliquidActionHash, createHyperliquidSubAccount, createMonotonicNonceFactory, depositToHyperliquidBridge, estimateHyperliquidLiquidationPrice, extractHyperliquidDex, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSizeDecimals, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidTickSize, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, formatHyperliquidMarketablePrice, formatHyperliquidPrice, formatHyperliquidSize, getHyperliquidMaxBuilderFee, isHyperliquidSpotSymbol, modifyHyperliquidOrder, normalizeHyperliquidBaseSymbol, normalizeHyperliquidMetaSymbol, normalizeSpotTokenName2 as normalizeSpotTokenName, parseHyperliquidSymbol, parseSpotPairSymbol, placeHyperliquidOrder, placeHyperliquidOrderWithTpSl, placeHyperliquidPositionTpSl, placeHyperliquidTwapOrder, reserveHyperliquidRequestWeight, resolveHyperliquidAbstractionFromMode, resolveHyperliquidLeverageMode, resolveHyperliquidMarketDataCoin, resolveHyperliquidOrderSymbol, resolveHyperliquidPair, resolveHyperliquidPerpSymbol, resolveHyperliquidProfileChain, resolveHyperliquidSpotSymbol, resolveHyperliquidSymbol, resolveSpotMidCandidates, resolveSpotTokenCandidates, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidAccountAbstractionMode, setHyperliquidDexAbstraction, setHyperliquidPortfolioMargin, supportsHyperliquidBuilderFee, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, withdrawFromHyperliquid };
|
|
2762
2787
|
//# sourceMappingURL=browser.js.map
|
|
2763
2788
|
//# sourceMappingURL=browser.js.map
|