opentool 0.13.0 → 0.15.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 +2 -100
- package/dist/adapters/hyperliquid/browser.js +847 -14
- package/dist/adapters/hyperliquid/browser.js.map +1 -1
- package/dist/adapters/hyperliquid/index.d.ts +4 -184
- package/dist/adapters/hyperliquid/index.js +591 -45
- package/dist/adapters/hyperliquid/index.js.map +1 -1
- package/dist/adapters/polymarket/index.d.ts +1 -1
- package/dist/browser-DSwtpkyr.d.ts +701 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +591 -45
- package/dist/index.js.map +1 -1
- package/dist/{types-DKohXZes.d.ts → types-BaTmu0gS.d.ts} +1 -1
- package/dist/wallet/browser.d.ts +1 -1
- package/dist/wallet/browser.js +3 -2
- package/dist/wallet/browser.js.map +1 -1
- package/dist/wallet/index.d.ts +2 -2
- package/package.json +1 -1
- package/templates/base/package.json +1 -1
- package/dist/exchange-XC9MHmxJ.d.ts +0 -360
package/dist/index.js
CHANGED
|
@@ -1987,11 +1987,31 @@ function computeHyperliquidMarketIocLimitPrice(params) {
|
|
|
1987
1987
|
const slippage = bps / 1e4;
|
|
1988
1988
|
const multiplier = params.side === "buy" ? 1 + slippage : 1 - slippage;
|
|
1989
1989
|
const price = params.markPrice * multiplier;
|
|
1990
|
-
|
|
1990
|
+
const precision = Math.max(0, Math.min(12, Math.floor(decimals)));
|
|
1991
|
+
const factor = 10 ** precision;
|
|
1992
|
+
const scaled = price * factor;
|
|
1993
|
+
const directionalRounded = params.side === "buy" ? Math.ceil(scaled) / factor : Math.floor(scaled) / factor;
|
|
1994
|
+
return formatRoundedDecimal(directionalRounded, precision);
|
|
1991
1995
|
}
|
|
1992
1996
|
var HyperliquidApiError = class extends Error {
|
|
1993
1997
|
constructor(message, response) {
|
|
1994
|
-
|
|
1998
|
+
const responseRecord = response && typeof response === "object" ? response : null;
|
|
1999
|
+
const explicitErrors = Array.isArray(responseRecord?.errors) ? responseRecord.errors.filter(
|
|
2000
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
2001
|
+
) : [];
|
|
2002
|
+
const bodyStatuses = responseRecord?.body && typeof responseRecord.body === "object" && responseRecord.body !== null && "response" in responseRecord.body ? (responseRecord.body.response?.data?.statuses ?? []).map((status) => typeof status?.error === "string" ? status.error : null).filter((entry) => Boolean(entry && entry.trim().length > 0)) : [];
|
|
2003
|
+
const singleStatusError = responseRecord?.body && typeof responseRecord.body === "object" && responseRecord.body !== null && "response" in responseRecord.body ? responseRecord.body.response?.data?.status?.error : null;
|
|
2004
|
+
const details = Array.from(
|
|
2005
|
+
new Set(
|
|
2006
|
+
[
|
|
2007
|
+
...explicitErrors,
|
|
2008
|
+
...bodyStatuses,
|
|
2009
|
+
typeof singleStatusError === "string" ? singleStatusError : null
|
|
2010
|
+
].filter((entry) => Boolean(entry && entry.trim().length > 0))
|
|
2011
|
+
)
|
|
2012
|
+
);
|
|
2013
|
+
const enrichedMessage = details.length > 0 ? `${message} ${details.join(" | ")}` : message;
|
|
2014
|
+
super(enrichedMessage);
|
|
1995
2015
|
this.response = response;
|
|
1996
2016
|
this.name = "HyperliquidApiError";
|
|
1997
2017
|
}
|
|
@@ -2219,7 +2239,14 @@ async function resolveHyperliquidAssetIndex(args) {
|
|
|
2219
2239
|
}
|
|
2220
2240
|
function toApiDecimal(value) {
|
|
2221
2241
|
if (typeof value === "string") {
|
|
2222
|
-
|
|
2242
|
+
const trimmed = value.trim();
|
|
2243
|
+
if (!trimmed.length) {
|
|
2244
|
+
throw new Error("Decimal strings must be non-empty.");
|
|
2245
|
+
}
|
|
2246
|
+
if (!/^-?(?:\d+\.?\d*|\.\d+)$/.test(trimmed)) {
|
|
2247
|
+
throw new Error("Decimal strings must be plain base-10 numbers.");
|
|
2248
|
+
}
|
|
2249
|
+
return trimmed.replace(/^(-?)0+(?=\d)/, "$1").replace(/\.0*$|(\.\d+?)0+$/, "$1").replace(/^(-?)\./, "$10.").replace(/^-?$/, "0").replace(/^-0$/, "0");
|
|
2223
2250
|
}
|
|
2224
2251
|
if (typeof value === "bigint") {
|
|
2225
2252
|
return value.toString();
|
|
@@ -3055,7 +3082,7 @@ async function placeHyperliquidTwapOrder(options) {
|
|
|
3055
3082
|
symbol: twap.symbol,
|
|
3056
3083
|
baseUrl: API_BASES[env],
|
|
3057
3084
|
environment: env,
|
|
3058
|
-
fetcher: fetch
|
|
3085
|
+
fetcher: (...args) => fetch(...args)
|
|
3059
3086
|
});
|
|
3060
3087
|
const action = {
|
|
3061
3088
|
type: "twapOrder",
|
|
@@ -3077,7 +3104,7 @@ async function cancelHyperliquidTwapOrder(options) {
|
|
|
3077
3104
|
symbol: options.cancel.symbol,
|
|
3078
3105
|
baseUrl: API_BASES[env],
|
|
3079
3106
|
environment: env,
|
|
3080
|
-
fetcher: fetch
|
|
3107
|
+
fetcher: (...args) => fetch(...args)
|
|
3081
3108
|
});
|
|
3082
3109
|
const action = {
|
|
3083
3110
|
type: "twapCancel",
|
|
@@ -3094,7 +3121,7 @@ async function updateHyperliquidLeverage(options) {
|
|
|
3094
3121
|
symbol: options.input.symbol,
|
|
3095
3122
|
baseUrl: API_BASES[env],
|
|
3096
3123
|
environment: env,
|
|
3097
|
-
fetcher: fetch
|
|
3124
|
+
fetcher: (...args) => fetch(...args)
|
|
3098
3125
|
});
|
|
3099
3126
|
const action = {
|
|
3100
3127
|
type: "updateLeverage",
|
|
@@ -3112,7 +3139,7 @@ async function updateHyperliquidIsolatedMargin(options) {
|
|
|
3112
3139
|
symbol: options.input.symbol,
|
|
3113
3140
|
baseUrl: API_BASES[env],
|
|
3114
3141
|
environment: env,
|
|
3115
|
-
fetcher: fetch
|
|
3142
|
+
fetcher: (...args) => fetch(...args)
|
|
3116
3143
|
});
|
|
3117
3144
|
const action = {
|
|
3118
3145
|
type: "updateIsolatedMargin",
|
|
@@ -3227,7 +3254,7 @@ async function withAssetIndexes(options, entries, mapper) {
|
|
|
3227
3254
|
symbol: entry.symbol,
|
|
3228
3255
|
baseUrl: API_BASES[env],
|
|
3229
3256
|
environment: env,
|
|
3230
|
-
fetcher: fetch
|
|
3257
|
+
fetcher: (...args) => fetch(...args)
|
|
3231
3258
|
});
|
|
3232
3259
|
return mapper(assetIndex, entry);
|
|
3233
3260
|
})
|
|
@@ -3242,7 +3269,7 @@ async function buildOrder(intent, options) {
|
|
|
3242
3269
|
symbol: intent.symbol,
|
|
3243
3270
|
baseUrl: API_BASES[env],
|
|
3244
3271
|
environment: env,
|
|
3245
|
-
fetcher: fetch
|
|
3272
|
+
fetcher: (...args) => fetch(...args)
|
|
3246
3273
|
});
|
|
3247
3274
|
const limitOrTrigger = intent.trigger ? mapTrigger(intent.trigger) : {
|
|
3248
3275
|
limit: {
|
|
@@ -3406,6 +3433,71 @@ function extractHyperliquidDex(symbol) {
|
|
|
3406
3433
|
const dex = symbol.slice(0, idx).trim().toLowerCase();
|
|
3407
3434
|
return dex || null;
|
|
3408
3435
|
}
|
|
3436
|
+
function parseHyperliquidSymbol(value) {
|
|
3437
|
+
if (!value) return null;
|
|
3438
|
+
const trimmed = value.trim();
|
|
3439
|
+
if (!trimmed) return null;
|
|
3440
|
+
if (trimmed.startsWith("@")) {
|
|
3441
|
+
return {
|
|
3442
|
+
raw: trimmed,
|
|
3443
|
+
kind: "spotIndex",
|
|
3444
|
+
normalized: trimmed,
|
|
3445
|
+
routeTicker: trimmed,
|
|
3446
|
+
displaySymbol: trimmed,
|
|
3447
|
+
base: null,
|
|
3448
|
+
quote: null,
|
|
3449
|
+
pair: null,
|
|
3450
|
+
dex: null,
|
|
3451
|
+
leverageMode: "cross"
|
|
3452
|
+
};
|
|
3453
|
+
}
|
|
3454
|
+
const dex = extractHyperliquidDex(trimmed);
|
|
3455
|
+
const pair = resolveHyperliquidPair(trimmed);
|
|
3456
|
+
const base2 = normalizeHyperliquidBaseSymbol(trimmed);
|
|
3457
|
+
if (dex) {
|
|
3458
|
+
if (!base2) return null;
|
|
3459
|
+
return {
|
|
3460
|
+
raw: trimmed,
|
|
3461
|
+
kind: "perp",
|
|
3462
|
+
normalized: `${dex}:${base2}`,
|
|
3463
|
+
routeTicker: `${dex}:${base2}`,
|
|
3464
|
+
displaySymbol: `${dex.toUpperCase()}:${base2}-USDC`,
|
|
3465
|
+
base: base2,
|
|
3466
|
+
quote: null,
|
|
3467
|
+
pair: null,
|
|
3468
|
+
dex,
|
|
3469
|
+
leverageMode: "isolated"
|
|
3470
|
+
};
|
|
3471
|
+
}
|
|
3472
|
+
if (pair) {
|
|
3473
|
+
const [pairBase, pairQuote] = pair.split("/");
|
|
3474
|
+
return {
|
|
3475
|
+
raw: trimmed,
|
|
3476
|
+
kind: "spot",
|
|
3477
|
+
normalized: pair,
|
|
3478
|
+
routeTicker: pair.replace("/", "-"),
|
|
3479
|
+
displaySymbol: pair.replace("/", "-"),
|
|
3480
|
+
base: pairBase ?? null,
|
|
3481
|
+
quote: pairQuote ?? null,
|
|
3482
|
+
pair,
|
|
3483
|
+
dex: null,
|
|
3484
|
+
leverageMode: "cross"
|
|
3485
|
+
};
|
|
3486
|
+
}
|
|
3487
|
+
if (!base2) return null;
|
|
3488
|
+
return {
|
|
3489
|
+
raw: trimmed,
|
|
3490
|
+
kind: "perp",
|
|
3491
|
+
normalized: base2,
|
|
3492
|
+
routeTicker: base2,
|
|
3493
|
+
displaySymbol: `${base2}-USDC`,
|
|
3494
|
+
base: base2,
|
|
3495
|
+
quote: null,
|
|
3496
|
+
pair: null,
|
|
3497
|
+
dex: null,
|
|
3498
|
+
leverageMode: "cross"
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3409
3501
|
function normalizeSpotTokenName2(value) {
|
|
3410
3502
|
const raw = (value ?? "").trim();
|
|
3411
3503
|
if (!raw) return "";
|
|
@@ -3721,20 +3813,10 @@ function planHyperliquidTrade(params) {
|
|
|
3721
3813
|
}
|
|
3722
3814
|
|
|
3723
3815
|
// src/adapters/hyperliquid/order-utils.ts
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
if (!Number.isFinite(value)) return 0;
|
|
3727
|
-
const s = value.toString();
|
|
3728
|
-
const [, dec = ""] = s.split(".");
|
|
3816
|
+
function countDecimalPlaces(value) {
|
|
3817
|
+
const [, dec = ""] = value.split(".");
|
|
3729
3818
|
return dec.length;
|
|
3730
3819
|
}
|
|
3731
|
-
function clampPriceDecimals(value) {
|
|
3732
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
3733
|
-
throw new Error("Price must be positive.");
|
|
3734
|
-
}
|
|
3735
|
-
const fixed = value.toFixed(MAX_HYPERLIQUID_PRICE_DECIMALS);
|
|
3736
|
-
return fixed.replace(/\.?0+$/, "");
|
|
3737
|
-
}
|
|
3738
3820
|
function assertNumberString(value) {
|
|
3739
3821
|
if (!/^-?(?:\d+\.?\d*|\.\d+)$/.test(value)) {
|
|
3740
3822
|
throw new TypeError("Invalid decimal number string.");
|
|
@@ -3785,6 +3867,29 @@ var StringMath = {
|
|
|
3785
3867
|
const index = value.indexOf(".");
|
|
3786
3868
|
return index === -1 ? value : value.slice(0, index) || "0";
|
|
3787
3869
|
},
|
|
3870
|
+
roundInteger(value, mode) {
|
|
3871
|
+
const normalized = normalizeDecimalString(value);
|
|
3872
|
+
const negative = normalized.startsWith("-");
|
|
3873
|
+
if (negative) {
|
|
3874
|
+
throw new RangeError("Directional rounding only supports positive values.");
|
|
3875
|
+
}
|
|
3876
|
+
const [intPartRaw, fracPart = ""] = normalized.split(".");
|
|
3877
|
+
const intPart = intPartRaw.replace(/^0+(?=\d)/, "") || "0";
|
|
3878
|
+
const hasFraction = /[1-9]/.test(fracPart);
|
|
3879
|
+
if (!hasFraction) return intPart;
|
|
3880
|
+
if (mode === "down") return intPart;
|
|
3881
|
+
const digits = intPart.split("");
|
|
3882
|
+
let carry = 1;
|
|
3883
|
+
for (let idx = digits.length - 1; idx >= 0 && carry > 0; idx -= 1) {
|
|
3884
|
+
const next = Number(digits[idx] ?? "0") + carry;
|
|
3885
|
+
digits[idx] = String(next % 10);
|
|
3886
|
+
carry = next >= 10 ? 1 : 0;
|
|
3887
|
+
}
|
|
3888
|
+
if (carry > 0) {
|
|
3889
|
+
digits.unshift("1");
|
|
3890
|
+
}
|
|
3891
|
+
return digits.join("").replace(/^0+(?=\d)/, "") || "0";
|
|
3892
|
+
},
|
|
3788
3893
|
toPrecisionTruncate(value, precision) {
|
|
3789
3894
|
if (!Number.isInteger(precision) || precision < 1) {
|
|
3790
3895
|
throw new RangeError("Precision must be a positive integer.");
|
|
@@ -3811,6 +3916,41 @@ var StringMath = {
|
|
|
3811
3916
|
return normalizeDecimalString(result);
|
|
3812
3917
|
}
|
|
3813
3918
|
};
|
|
3919
|
+
function ceilDiv(numerator, denominator) {
|
|
3920
|
+
if (denominator <= 0n) {
|
|
3921
|
+
throw new RangeError("Denominator must be positive.");
|
|
3922
|
+
}
|
|
3923
|
+
return (numerator + denominator - 1n) / denominator;
|
|
3924
|
+
}
|
|
3925
|
+
function scaleDecimalToInt(value, decimals, mode) {
|
|
3926
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
3927
|
+
throw new RangeError("Decimals must be a non-negative integer.");
|
|
3928
|
+
}
|
|
3929
|
+
const normalized = normalizeDecimalString(value);
|
|
3930
|
+
assertNumberString(normalized);
|
|
3931
|
+
const negative = normalized.startsWith("-");
|
|
3932
|
+
if (negative) {
|
|
3933
|
+
throw new RangeError("Only positive values are supported.");
|
|
3934
|
+
}
|
|
3935
|
+
const shifted = StringMath.multiplyByPow10(normalized, decimals);
|
|
3936
|
+
const rounded = StringMath.roundInteger(shifted, mode);
|
|
3937
|
+
return BigInt(rounded);
|
|
3938
|
+
}
|
|
3939
|
+
function formatScaledDecimal(value, decimals) {
|
|
3940
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
3941
|
+
throw new RangeError("Decimals must be a non-negative integer.");
|
|
3942
|
+
}
|
|
3943
|
+
const negative = value < 0n;
|
|
3944
|
+
const abs = negative ? -value : value;
|
|
3945
|
+
const raw = abs.toString();
|
|
3946
|
+
if (decimals === 0) {
|
|
3947
|
+
return `${negative ? "-" : ""}${raw}`;
|
|
3948
|
+
}
|
|
3949
|
+
const padded = raw.padStart(decimals + 1, "0");
|
|
3950
|
+
const intPart = padded.slice(0, -decimals) || "0";
|
|
3951
|
+
const fracPart = padded.slice(-decimals);
|
|
3952
|
+
return normalizeDecimalString(`${negative ? "-" : ""}${intPart}.${fracPart}`);
|
|
3953
|
+
}
|
|
3814
3954
|
function formatHyperliquidPrice(price, szDecimals, marketType = "perp") {
|
|
3815
3955
|
const normalized = price.toString().trim();
|
|
3816
3956
|
assertNumberString(normalized);
|
|
@@ -3843,33 +3983,52 @@ function formatHyperliquidOrderSize(value, szDecimals) {
|
|
|
3843
3983
|
}
|
|
3844
3984
|
}
|
|
3845
3985
|
function roundHyperliquidPriceToTick(price, tick, side) {
|
|
3846
|
-
if (!Number.isFinite(price) || price <= 0) {
|
|
3847
|
-
throw new Error("Price must be positive.");
|
|
3848
|
-
}
|
|
3849
3986
|
if (!Number.isFinite(tick.tickDecimals) || tick.tickDecimals < 0) {
|
|
3850
3987
|
throw new Error("tick.tickDecimals must be a non-negative number.");
|
|
3851
3988
|
}
|
|
3852
3989
|
if (tick.tickSizeInt <= 0n) {
|
|
3853
3990
|
throw new Error("tick.tickSizeInt must be positive.");
|
|
3854
3991
|
}
|
|
3855
|
-
const
|
|
3856
|
-
|
|
3992
|
+
const normalized = normalizeDecimalString(price.toString());
|
|
3993
|
+
assertNumberString(normalized);
|
|
3994
|
+
if (Number.parseFloat(normalized) <= 0) {
|
|
3995
|
+
throw new Error("Price must be positive.");
|
|
3996
|
+
}
|
|
3997
|
+
const scaled = scaleDecimalToInt(
|
|
3998
|
+
normalized,
|
|
3999
|
+
tick.tickDecimals,
|
|
4000
|
+
side === "buy" ? "up" : "down"
|
|
4001
|
+
);
|
|
3857
4002
|
const tickSize = tick.tickSizeInt;
|
|
3858
4003
|
const rounded = side === "sell" ? scaled / tickSize * tickSize : (scaled + tickSize - 1n) / tickSize * tickSize;
|
|
3859
|
-
|
|
3860
|
-
return clampPriceDecimals(integer);
|
|
4004
|
+
return formatScaledDecimal(rounded, tick.tickDecimals);
|
|
3861
4005
|
}
|
|
3862
4006
|
function formatHyperliquidMarketablePrice(params) {
|
|
3863
4007
|
const { mid, side, slippageBps, tick } = params;
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
4008
|
+
if (!Number.isFinite(mid) || mid <= 0) {
|
|
4009
|
+
throw new Error("mid must be a positive number.");
|
|
4010
|
+
}
|
|
4011
|
+
if (!Number.isFinite(slippageBps) || slippageBps < 0) {
|
|
4012
|
+
throw new Error("slippageBps must be a non-negative number.");
|
|
4013
|
+
}
|
|
4014
|
+
const midString = normalizeDecimalString(mid.toString());
|
|
4015
|
+
const baseDecimals = countDecimalPlaces(midString);
|
|
4016
|
+
const workDecimals = Math.max(baseDecimals + 4, tick?.tickDecimals ?? 0, 8);
|
|
4017
|
+
const scaledMid = scaleDecimalToInt(midString, workDecimals, "down");
|
|
4018
|
+
const slippageNumerator = BigInt(
|
|
4019
|
+
side === "buy" ? 1e4 + slippageBps : 1e4 - slippageBps
|
|
4020
|
+
);
|
|
4021
|
+
const adjustedScaled = side === "buy" ? ceilDiv(scaledMid * slippageNumerator, 10000n) : scaledMid * slippageNumerator / 10000n;
|
|
4022
|
+
const adjusted = formatScaledDecimal(adjustedScaled, workDecimals);
|
|
3867
4023
|
if (tick) {
|
|
3868
4024
|
return roundHyperliquidPriceToTick(adjusted, tick, side);
|
|
3869
4025
|
}
|
|
3870
|
-
const
|
|
3871
|
-
|
|
3872
|
-
|
|
4026
|
+
const roundedScaled = scaleDecimalToInt(
|
|
4027
|
+
adjusted,
|
|
4028
|
+
baseDecimals,
|
|
4029
|
+
side === "buy" ? "up" : "down"
|
|
4030
|
+
);
|
|
4031
|
+
return formatScaledDecimal(roundedScaled, baseDecimals);
|
|
3873
4032
|
}
|
|
3874
4033
|
function extractHyperliquidOrderIds(responses) {
|
|
3875
4034
|
const cloids = /* @__PURE__ */ new Set();
|
|
@@ -4463,6 +4622,393 @@ var __hyperliquidMarketDataInternals = {
|
|
|
4463
4622
|
toScaledInt,
|
|
4464
4623
|
formatScaledInt
|
|
4465
4624
|
};
|
|
4625
|
+
function resolveRequiredNonce(params) {
|
|
4626
|
+
if (typeof params.nonce === "number") {
|
|
4627
|
+
return params.nonce;
|
|
4628
|
+
}
|
|
4629
|
+
const resolved = params.nonceSource?.() ?? params.wallet?.nonceSource?.();
|
|
4630
|
+
if (resolved === void 0) {
|
|
4631
|
+
throw new Error(`${params.action} requires an explicit nonce or wallet nonce source.`);
|
|
4632
|
+
}
|
|
4633
|
+
return resolved;
|
|
4634
|
+
}
|
|
4635
|
+
function assertPositiveDecimalInput(value, label) {
|
|
4636
|
+
if (typeof value === "number") {
|
|
4637
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
4638
|
+
throw new Error(`${label} must be a positive number.`);
|
|
4639
|
+
}
|
|
4640
|
+
return;
|
|
4641
|
+
}
|
|
4642
|
+
if (typeof value === "bigint") {
|
|
4643
|
+
if (value <= 0n) {
|
|
4644
|
+
throw new Error(`${label} must be positive.`);
|
|
4645
|
+
}
|
|
4646
|
+
return;
|
|
4647
|
+
}
|
|
4648
|
+
const trimmed = value.trim();
|
|
4649
|
+
if (!trimmed.length) {
|
|
4650
|
+
throw new Error(`${label} must be a non-empty string.`);
|
|
4651
|
+
}
|
|
4652
|
+
if (!/^(?:\d+\.?\d*|\.\d+)$/.test(trimmed)) {
|
|
4653
|
+
throw new Error(`${label} must be a positive decimal string.`);
|
|
4654
|
+
}
|
|
4655
|
+
const numeric = Number(trimmed);
|
|
4656
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
4657
|
+
throw new Error(`${label} must be positive.`);
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
async function placeHyperliquidOrder(options) {
|
|
4661
|
+
const {
|
|
4662
|
+
wallet: wallet2,
|
|
4663
|
+
orders,
|
|
4664
|
+
grouping = "na",
|
|
4665
|
+
environment,
|
|
4666
|
+
vaultAddress,
|
|
4667
|
+
expiresAfter,
|
|
4668
|
+
nonce
|
|
4669
|
+
} = options;
|
|
4670
|
+
if (!wallet2?.account || !wallet2.walletClient) {
|
|
4671
|
+
throw new Error("Hyperliquid order signing requires a wallet with signing capabilities.");
|
|
4672
|
+
}
|
|
4673
|
+
if (!orders.length) {
|
|
4674
|
+
throw new Error("At least one order is required.");
|
|
4675
|
+
}
|
|
4676
|
+
const inferredEnvironment = environment ?? "mainnet";
|
|
4677
|
+
const resolvedBaseUrl = API_BASES[inferredEnvironment];
|
|
4678
|
+
const preparedOrders = await Promise.all(
|
|
4679
|
+
orders.map(async (intent) => {
|
|
4680
|
+
assertPositiveDecimalInput(intent.price, "price");
|
|
4681
|
+
assertPositiveDecimalInput(intent.size, "size");
|
|
4682
|
+
if (intent.trigger) {
|
|
4683
|
+
assertPositiveDecimalInput(intent.trigger.triggerPx, "triggerPx");
|
|
4684
|
+
}
|
|
4685
|
+
const assetIndex = await resolveHyperliquidAssetIndex({
|
|
4686
|
+
symbol: intent.symbol,
|
|
4687
|
+
baseUrl: resolvedBaseUrl,
|
|
4688
|
+
environment: inferredEnvironment,
|
|
4689
|
+
fetcher: (...args) => fetch(...args)
|
|
4690
|
+
});
|
|
4691
|
+
const order = {
|
|
4692
|
+
a: assetIndex,
|
|
4693
|
+
b: intent.side === "buy",
|
|
4694
|
+
p: toApiDecimal(intent.price),
|
|
4695
|
+
s: toApiDecimal(intent.size),
|
|
4696
|
+
r: intent.reduceOnly ?? false,
|
|
4697
|
+
t: intent.trigger ? {
|
|
4698
|
+
trigger: {
|
|
4699
|
+
isMarket: Boolean(intent.trigger.isMarket),
|
|
4700
|
+
triggerPx: toApiDecimal(intent.trigger.triggerPx),
|
|
4701
|
+
tpsl: intent.trigger.tpsl
|
|
4702
|
+
}
|
|
4703
|
+
} : {
|
|
4704
|
+
limit: {
|
|
4705
|
+
tif: intent.tif ?? "Ioc"
|
|
4706
|
+
}
|
|
4707
|
+
},
|
|
4708
|
+
...intent.clientId ? { c: normalizeCloid(intent.clientId) } : {}
|
|
4709
|
+
};
|
|
4710
|
+
return order;
|
|
4711
|
+
})
|
|
4712
|
+
);
|
|
4713
|
+
const action = {
|
|
4714
|
+
type: "order",
|
|
4715
|
+
orders: preparedOrders,
|
|
4716
|
+
grouping,
|
|
4717
|
+
builder: {
|
|
4718
|
+
b: normalizeAddress(BUILDER_CODE.address),
|
|
4719
|
+
f: BUILDER_CODE.fee
|
|
4720
|
+
}
|
|
4721
|
+
};
|
|
4722
|
+
const effectiveNonce = resolveRequiredNonce({
|
|
4723
|
+
nonce,
|
|
4724
|
+
nonceSource: options.nonceSource,
|
|
4725
|
+
wallet: wallet2,
|
|
4726
|
+
action: "Hyperliquid order submission"
|
|
4727
|
+
});
|
|
4728
|
+
const signature = await signL1Action({
|
|
4729
|
+
wallet: wallet2,
|
|
4730
|
+
action,
|
|
4731
|
+
nonce: effectiveNonce,
|
|
4732
|
+
...vaultAddress ? { vaultAddress } : {},
|
|
4733
|
+
...typeof expiresAfter === "number" ? { expiresAfter } : {},
|
|
4734
|
+
isTestnet: inferredEnvironment === "testnet"
|
|
4735
|
+
});
|
|
4736
|
+
const body = {
|
|
4737
|
+
action,
|
|
4738
|
+
nonce: effectiveNonce,
|
|
4739
|
+
signature
|
|
4740
|
+
};
|
|
4741
|
+
if (vaultAddress) {
|
|
4742
|
+
body.vaultAddress = normalizeAddress(vaultAddress);
|
|
4743
|
+
}
|
|
4744
|
+
if (typeof expiresAfter === "number") {
|
|
4745
|
+
body.expiresAfter = expiresAfter;
|
|
4746
|
+
}
|
|
4747
|
+
const response = await fetch(`${resolvedBaseUrl}/exchange`, {
|
|
4748
|
+
method: "POST",
|
|
4749
|
+
headers: { "content-type": "application/json" },
|
|
4750
|
+
body: JSON.stringify(body)
|
|
4751
|
+
});
|
|
4752
|
+
const rawText = await response.text().catch(() => null);
|
|
4753
|
+
let parsed = null;
|
|
4754
|
+
if (rawText && rawText.length) {
|
|
4755
|
+
try {
|
|
4756
|
+
parsed = JSON.parse(rawText);
|
|
4757
|
+
} catch {
|
|
4758
|
+
parsed = rawText;
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
const json = parsed && typeof parsed === "object" && "status" in parsed ? parsed : null;
|
|
4762
|
+
if (!response.ok || !json) {
|
|
4763
|
+
const detail = parsed?.error ?? parsed?.message ?? (typeof parsed === "string" ? parsed : rawText);
|
|
4764
|
+
const suffix = detail ? ` Detail: ${detail}` : "";
|
|
4765
|
+
throw new HyperliquidApiError(
|
|
4766
|
+
`Failed to submit Hyperliquid order.${suffix}`,
|
|
4767
|
+
parsed ?? rawText ?? { status: response.status }
|
|
4768
|
+
);
|
|
4769
|
+
}
|
|
4770
|
+
if (json.status !== "ok") {
|
|
4771
|
+
const detail = parsed?.error ?? rawText;
|
|
4772
|
+
throw new HyperliquidApiError(
|
|
4773
|
+
detail ? `Hyperliquid API returned an error status: ${detail}` : "Hyperliquid API returned an error status.",
|
|
4774
|
+
json
|
|
4775
|
+
);
|
|
4776
|
+
}
|
|
4777
|
+
const statuses = json.response?.data?.statuses ?? [];
|
|
4778
|
+
const errorStatuses = statuses.filter(
|
|
4779
|
+
(entry) => Boolean(
|
|
4780
|
+
entry && typeof entry === "object" && "error" in entry && typeof entry.error === "string"
|
|
4781
|
+
)
|
|
4782
|
+
);
|
|
4783
|
+
if (errorStatuses.length) {
|
|
4784
|
+
const message = errorStatuses.map((entry) => entry.error).join(", ");
|
|
4785
|
+
throw new HyperliquidApiError(message || "Hyperliquid rejected the order.", json);
|
|
4786
|
+
}
|
|
4787
|
+
return json;
|
|
4788
|
+
}
|
|
4789
|
+
|
|
4790
|
+
// src/adapters/hyperliquid/tpsl.ts
|
|
4791
|
+
var DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS = 1e3;
|
|
4792
|
+
function toDecimalInput(value, label) {
|
|
4793
|
+
if (typeof value === "bigint") {
|
|
4794
|
+
if (value <= 0n) {
|
|
4795
|
+
throw new Error(`${label} must be positive.`);
|
|
4796
|
+
}
|
|
4797
|
+
return value.toString();
|
|
4798
|
+
}
|
|
4799
|
+
return value;
|
|
4800
|
+
}
|
|
4801
|
+
function toPositiveNumber(value, label) {
|
|
4802
|
+
if (typeof value === "bigint") {
|
|
4803
|
+
if (value <= 0n) {
|
|
4804
|
+
throw new Error(`${label} must be positive.`);
|
|
4805
|
+
}
|
|
4806
|
+
return Number(value);
|
|
4807
|
+
}
|
|
4808
|
+
const numeric = typeof value === "number" ? value : Number.parseFloat(value.toString().trim());
|
|
4809
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
4810
|
+
throw new Error(`${label} must be positive.`);
|
|
4811
|
+
}
|
|
4812
|
+
return numeric;
|
|
4813
|
+
}
|
|
4814
|
+
function normalizeExecutionType(value) {
|
|
4815
|
+
return value ?? "market";
|
|
4816
|
+
}
|
|
4817
|
+
function resolveTriggerDirection(params) {
|
|
4818
|
+
const isLong = params.parentSide === "buy";
|
|
4819
|
+
if (params.leg === "tp") {
|
|
4820
|
+
if (isLong && params.triggerPx <= params.referencePrice) {
|
|
4821
|
+
throw new Error("Take profit trigger must be above the current price for long positions.");
|
|
4822
|
+
}
|
|
4823
|
+
if (!isLong && params.triggerPx >= params.referencePrice) {
|
|
4824
|
+
throw new Error("Take profit trigger must be below the current price for short positions.");
|
|
4825
|
+
}
|
|
4826
|
+
return;
|
|
4827
|
+
}
|
|
4828
|
+
if (isLong && params.triggerPx >= params.referencePrice) {
|
|
4829
|
+
throw new Error("Stop loss trigger must be below the current price for long positions.");
|
|
4830
|
+
}
|
|
4831
|
+
if (!isLong && params.triggerPx <= params.referencePrice) {
|
|
4832
|
+
throw new Error("Stop loss trigger must be above the current price for short positions.");
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
async function buildTpSlChildOrder(params) {
|
|
4836
|
+
const marketType = isHyperliquidSpotSymbol(params.symbol) ? "spot" : "perp";
|
|
4837
|
+
const [szDecimals, tick] = await Promise.all([
|
|
4838
|
+
fetchHyperliquidSizeDecimals({
|
|
4839
|
+
environment: params.environment,
|
|
4840
|
+
symbol: params.symbol
|
|
4841
|
+
}),
|
|
4842
|
+
fetchHyperliquidTickSize({
|
|
4843
|
+
environment: params.environment,
|
|
4844
|
+
symbol: params.symbol
|
|
4845
|
+
}).catch(() => null)
|
|
4846
|
+
]);
|
|
4847
|
+
const childSide = params.parentSide === "buy" ? "sell" : "buy";
|
|
4848
|
+
const triggerPxNumeric = toPositiveNumber(params.leg.triggerPx, `${params.legType} triggerPx`);
|
|
4849
|
+
resolveTriggerDirection({
|
|
4850
|
+
leg: params.legType,
|
|
4851
|
+
parentSide: params.parentSide,
|
|
4852
|
+
referencePrice: params.referencePrice,
|
|
4853
|
+
triggerPx: triggerPxNumeric
|
|
4854
|
+
});
|
|
4855
|
+
const execution = normalizeExecutionType(params.leg.execution);
|
|
4856
|
+
const size = formatHyperliquidSize(toDecimalInput(params.size, "size"), szDecimals);
|
|
4857
|
+
const triggerPx = formatHyperliquidPrice(triggerPxNumeric, szDecimals, marketType);
|
|
4858
|
+
const explicitLimitPrice = params.leg.price != null ? toDecimalInput(params.leg.price, `${params.legType} price`) : null;
|
|
4859
|
+
const explicitLimitPriceNumeric = explicitLimitPrice != null ? toPositiveNumber(explicitLimitPrice, `${params.legType} price`) : null;
|
|
4860
|
+
if (execution === "limit" && explicitLimitPriceNumeric == null) {
|
|
4861
|
+
throw new Error(`${params.legType} limit price is required for limit execution.`);
|
|
4862
|
+
}
|
|
4863
|
+
if (execution === "limit" && explicitLimitPriceNumeric != null) {
|
|
4864
|
+
if (childSide === "sell" && explicitLimitPriceNumeric > triggerPxNumeric) {
|
|
4865
|
+
throw new Error(`${params.legType} sell limit price must be at or below the trigger price.`);
|
|
4866
|
+
}
|
|
4867
|
+
if (childSide === "buy" && explicitLimitPriceNumeric < triggerPxNumeric) {
|
|
4868
|
+
throw new Error(`${params.legType} buy limit price must be at or above the trigger price.`);
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4871
|
+
const price = execution === "limit" ? formatHyperliquidPrice(
|
|
4872
|
+
explicitLimitPrice,
|
|
4873
|
+
szDecimals,
|
|
4874
|
+
marketType
|
|
4875
|
+
) : formatHyperliquidMarketablePrice({
|
|
4876
|
+
mid: triggerPxNumeric,
|
|
4877
|
+
side: childSide,
|
|
4878
|
+
slippageBps: params.triggerMarketSlippageBps,
|
|
4879
|
+
tick
|
|
4880
|
+
});
|
|
4881
|
+
return {
|
|
4882
|
+
symbol: params.symbol,
|
|
4883
|
+
side: childSide,
|
|
4884
|
+
price,
|
|
4885
|
+
size,
|
|
4886
|
+
reduceOnly: true,
|
|
4887
|
+
trigger: {
|
|
4888
|
+
triggerPx,
|
|
4889
|
+
isMarket: execution === "market",
|
|
4890
|
+
tpsl: params.legType
|
|
4891
|
+
},
|
|
4892
|
+
...params.leg.clientId ? { clientId: params.leg.clientId } : {}
|
|
4893
|
+
};
|
|
4894
|
+
}
|
|
4895
|
+
async function buildAttachedTpSlOrders(params) {
|
|
4896
|
+
const referencePrice = toPositiveNumber(params.referencePrice, "referencePrice");
|
|
4897
|
+
const legs = await Promise.all(
|
|
4898
|
+
[
|
|
4899
|
+
params.takeProfit ? buildTpSlChildOrder({
|
|
4900
|
+
symbol: params.symbol,
|
|
4901
|
+
parentSide: params.parentSide,
|
|
4902
|
+
size: params.size,
|
|
4903
|
+
referencePrice,
|
|
4904
|
+
legType: "tp",
|
|
4905
|
+
leg: params.takeProfit,
|
|
4906
|
+
environment: params.environment,
|
|
4907
|
+
triggerMarketSlippageBps: params.triggerMarketSlippageBps
|
|
4908
|
+
}) : null,
|
|
4909
|
+
params.stopLoss ? buildTpSlChildOrder({
|
|
4910
|
+
symbol: params.symbol,
|
|
4911
|
+
parentSide: params.parentSide,
|
|
4912
|
+
size: params.size,
|
|
4913
|
+
referencePrice,
|
|
4914
|
+
legType: "sl",
|
|
4915
|
+
leg: params.stopLoss,
|
|
4916
|
+
environment: params.environment,
|
|
4917
|
+
triggerMarketSlippageBps: params.triggerMarketSlippageBps
|
|
4918
|
+
}) : null
|
|
4919
|
+
]
|
|
4920
|
+
);
|
|
4921
|
+
return legs.filter((entry) => Boolean(entry));
|
|
4922
|
+
}
|
|
4923
|
+
async function placeHyperliquidOrderWithTpSl(options) {
|
|
4924
|
+
const env = options.environment ?? "mainnet";
|
|
4925
|
+
const childOrders = await buildAttachedTpSlOrders({
|
|
4926
|
+
symbol: options.parent.symbol,
|
|
4927
|
+
parentSide: options.parent.side,
|
|
4928
|
+
size: options.parent.size,
|
|
4929
|
+
referencePrice: options.referencePrice,
|
|
4930
|
+
takeProfit: options.takeProfit ?? null,
|
|
4931
|
+
stopLoss: options.stopLoss ?? null,
|
|
4932
|
+
environment: env,
|
|
4933
|
+
triggerMarketSlippageBps: options.triggerMarketSlippageBps ?? DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS
|
|
4934
|
+
});
|
|
4935
|
+
return placeHyperliquidOrder({
|
|
4936
|
+
wallet: options.wallet,
|
|
4937
|
+
orders: [options.parent, ...childOrders],
|
|
4938
|
+
grouping: options.grouping ?? "normalTpsl",
|
|
4939
|
+
environment: env,
|
|
4940
|
+
...options.vaultAddress ? { vaultAddress: options.vaultAddress } : {},
|
|
4941
|
+
...typeof options.expiresAfter === "number" ? { expiresAfter: options.expiresAfter } : {},
|
|
4942
|
+
...typeof options.nonce === "number" ? { nonce: options.nonce } : {},
|
|
4943
|
+
...options.nonceSource ? { nonceSource: options.nonceSource } : {}
|
|
4944
|
+
});
|
|
4945
|
+
}
|
|
4946
|
+
async function placeHyperliquidPositionTpSl(options) {
|
|
4947
|
+
const env = options.environment ?? "mainnet";
|
|
4948
|
+
const parentSide = options.positionSide === "long" ? "buy" : "sell";
|
|
4949
|
+
const childOrders = await buildAttachedTpSlOrders({
|
|
4950
|
+
symbol: options.symbol,
|
|
4951
|
+
parentSide,
|
|
4952
|
+
size: options.size,
|
|
4953
|
+
referencePrice: options.referencePrice,
|
|
4954
|
+
takeProfit: options.takeProfit ?? null,
|
|
4955
|
+
stopLoss: options.stopLoss ?? null,
|
|
4956
|
+
environment: env,
|
|
4957
|
+
triggerMarketSlippageBps: options.triggerMarketSlippageBps ?? DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS
|
|
4958
|
+
});
|
|
4959
|
+
if (childOrders.length === 0) {
|
|
4960
|
+
throw new Error("At least one TP or SL order is required.");
|
|
4961
|
+
}
|
|
4962
|
+
return placeHyperliquidOrder({
|
|
4963
|
+
wallet: options.wallet,
|
|
4964
|
+
orders: childOrders,
|
|
4965
|
+
grouping: options.grouping ?? "positionTpsl",
|
|
4966
|
+
environment: env,
|
|
4967
|
+
...options.vaultAddress ? { vaultAddress: options.vaultAddress } : {},
|
|
4968
|
+
...typeof options.expiresAfter === "number" ? { expiresAfter: options.expiresAfter } : {},
|
|
4969
|
+
...typeof options.nonce === "number" ? { nonce: options.nonce } : {},
|
|
4970
|
+
...options.nonceSource ? { nonceSource: options.nonceSource } : {}
|
|
4971
|
+
});
|
|
4972
|
+
}
|
|
4973
|
+
|
|
4974
|
+
// src/adapters/hyperliquid/risk-utils.ts
|
|
4975
|
+
function toFinitePositive(value) {
|
|
4976
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
4977
|
+
}
|
|
4978
|
+
function estimateMaintenanceLeverage(maxLeverage) {
|
|
4979
|
+
const normalized = toFinitePositive(maxLeverage);
|
|
4980
|
+
if (!normalized) return null;
|
|
4981
|
+
return normalized * 2;
|
|
4982
|
+
}
|
|
4983
|
+
function estimateHyperliquidLiquidationPrice(params) {
|
|
4984
|
+
const entryPrice = toFinitePositive(params.entryPrice);
|
|
4985
|
+
const notionalUsd = toFinitePositive(params.notionalUsd);
|
|
4986
|
+
const leverage = toFinitePositive(params.leverage);
|
|
4987
|
+
const maintenanceLeverage = estimateMaintenanceLeverage(params.maxLeverage);
|
|
4988
|
+
if (!entryPrice || !notionalUsd || !leverage || !maintenanceLeverage) {
|
|
4989
|
+
return null;
|
|
4990
|
+
}
|
|
4991
|
+
const size = notionalUsd / entryPrice;
|
|
4992
|
+
if (!Number.isFinite(size) || size <= 0) {
|
|
4993
|
+
return null;
|
|
4994
|
+
}
|
|
4995
|
+
const isolatedMargin = notionalUsd / leverage;
|
|
4996
|
+
const marginAvailable = params.marginMode === "cross" ? Math.max(
|
|
4997
|
+
toFinitePositive(params.availableCollateralUsd ?? 0) ?? isolatedMargin,
|
|
4998
|
+
isolatedMargin
|
|
4999
|
+
) : isolatedMargin;
|
|
5000
|
+
const sideSign = params.side === "buy" ? 1 : -1;
|
|
5001
|
+
const maintenanceFactor = 1 / maintenanceLeverage;
|
|
5002
|
+
const denominator = 1 - maintenanceFactor * sideSign;
|
|
5003
|
+
if (!Number.isFinite(denominator) || denominator <= 0) {
|
|
5004
|
+
return null;
|
|
5005
|
+
}
|
|
5006
|
+
const liquidationPrice = entryPrice - sideSign * (marginAvailable / size) / denominator;
|
|
5007
|
+
if (!Number.isFinite(liquidationPrice) || liquidationPrice <= 0) {
|
|
5008
|
+
return null;
|
|
5009
|
+
}
|
|
5010
|
+
return liquidationPrice;
|
|
5011
|
+
}
|
|
4466
5012
|
|
|
4467
5013
|
// src/adapters/hyperliquid/utils.ts
|
|
4468
5014
|
var DEFAULT_HYPERLIQUID_CADENCE_CRON = {
|
|
@@ -4537,7 +5083,7 @@ function resolveHyperliquidCadenceFromResolution(resolution) {
|
|
|
4537
5083
|
}
|
|
4538
5084
|
|
|
4539
5085
|
// src/adapters/hyperliquid/index.ts
|
|
4540
|
-
function
|
|
5086
|
+
function resolveRequiredNonce2(params) {
|
|
4541
5087
|
if (typeof params.nonce === "number") {
|
|
4542
5088
|
return params.nonce;
|
|
4543
5089
|
}
|
|
@@ -4547,7 +5093,7 @@ function resolveRequiredNonce(params) {
|
|
|
4547
5093
|
}
|
|
4548
5094
|
return resolved;
|
|
4549
5095
|
}
|
|
4550
|
-
function
|
|
5096
|
+
function assertPositiveDecimalInput2(value, label) {
|
|
4551
5097
|
if (typeof value === "number") {
|
|
4552
5098
|
if (!Number.isFinite(value) || value <= 0) {
|
|
4553
5099
|
throw new Error(`${label} must be a positive number.`);
|
|
@@ -4587,7 +5133,7 @@ function normalizePositiveDecimalString(raw, label) {
|
|
|
4587
5133
|
}
|
|
4588
5134
|
return normalized;
|
|
4589
5135
|
}
|
|
4590
|
-
async function
|
|
5136
|
+
async function placeHyperliquidOrder2(options) {
|
|
4591
5137
|
const {
|
|
4592
5138
|
wallet: wallet2,
|
|
4593
5139
|
orders,
|
|
@@ -4608,16 +5154,16 @@ async function placeHyperliquidOrder(options) {
|
|
|
4608
5154
|
const resolvedBaseUrl = API_BASES[inferredEnvironment];
|
|
4609
5155
|
const preparedOrders = await Promise.all(
|
|
4610
5156
|
orders.map(async (intent) => {
|
|
4611
|
-
|
|
4612
|
-
|
|
5157
|
+
assertPositiveDecimalInput2(intent.price, "price");
|
|
5158
|
+
assertPositiveDecimalInput2(intent.size, "size");
|
|
4613
5159
|
if (intent.trigger) {
|
|
4614
|
-
|
|
5160
|
+
assertPositiveDecimalInput2(intent.trigger.triggerPx, "triggerPx");
|
|
4615
5161
|
}
|
|
4616
5162
|
const assetIndex = await resolveHyperliquidAssetIndex({
|
|
4617
5163
|
symbol: intent.symbol,
|
|
4618
5164
|
baseUrl: resolvedBaseUrl,
|
|
4619
5165
|
environment: inferredEnvironment,
|
|
4620
|
-
fetcher: fetch
|
|
5166
|
+
fetcher: (...args) => fetch(...args)
|
|
4621
5167
|
});
|
|
4622
5168
|
const limitOrTrigger = intent.trigger ? {
|
|
4623
5169
|
trigger: {
|
|
@@ -4655,7 +5201,7 @@ async function placeHyperliquidOrder(options) {
|
|
|
4655
5201
|
f: effectiveBuilder.fee
|
|
4656
5202
|
};
|
|
4657
5203
|
}
|
|
4658
|
-
const effectiveNonce =
|
|
5204
|
+
const effectiveNonce = resolveRequiredNonce2({
|
|
4659
5205
|
nonce,
|
|
4660
5206
|
nonceSource: options.nonceSource,
|
|
4661
5207
|
wallet: wallet2,
|
|
@@ -4776,7 +5322,7 @@ async function withdrawFromHyperliquid(options) {
|
|
|
4776
5322
|
chainId: Number.parseInt(signatureChainId, 16),
|
|
4777
5323
|
verifyingContract: ZERO_ADDRESS
|
|
4778
5324
|
};
|
|
4779
|
-
const nonce =
|
|
5325
|
+
const nonce = resolveRequiredNonce2({
|
|
4780
5326
|
nonce: options.nonce,
|
|
4781
5327
|
nonceSource: options.nonceSource,
|
|
4782
5328
|
wallet: wallet2,
|
|
@@ -4862,7 +5408,7 @@ async function approveHyperliquidBuilderFee(options) {
|
|
|
4862
5408
|
const inferredEnvironment = environment ?? "mainnet";
|
|
4863
5409
|
const resolvedBaseUrl = API_BASES[inferredEnvironment];
|
|
4864
5410
|
const maxFeeRate = formattedPercent;
|
|
4865
|
-
const effectiveNonce =
|
|
5411
|
+
const effectiveNonce = resolveRequiredNonce2({
|
|
4866
5412
|
nonce,
|
|
4867
5413
|
nonceSource: options.nonceSource,
|
|
4868
5414
|
wallet: wallet2,
|
|
@@ -6844,6 +7390,6 @@ function buildBacktestDecisionSeriesInput(request) {
|
|
|
6844
7390
|
};
|
|
6845
7391
|
}
|
|
6846
7392
|
|
|
6847
|
-
export { AIAbortError, AIError, AIFetchError, AIResponseError, BACKTEST_DECISION_MODE, DEFAULT_BASE_URL, DEFAULT_CHAIN, DEFAULT_FACILITATOR, DEFAULT_HYPERLIQUID_CADENCE_CRON, DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, DEFAULT_MODEL, DEFAULT_OPENPOND_GATEWAY_URL2 as DEFAULT_OPENPOND_GATEWAY_URL, DEFAULT_TIMEOUT_MS, DEFAULT_TOKENS, HTTP_METHODS2 as HTTP_METHODS, HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, NewsSignalClient, 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, backtestDecisionRequestSchema, batchModifyHyperliquidOrders, buildBacktestDecisionSeriesInput, buildHmacSignature, buildHyperliquidMarketIdentity, buildHyperliquidProfileAssets, buildHyperliquidSpotUsdPriceMap, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllHyperliquidOrders, cancelAllPolymarketOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, chains, clampHyperliquidAbs, clampHyperliquidFloat, clampHyperliquidInt, computeHyperliquidMarketIocLimitPrice, createAIClient, createDevServer, createHyperliquidSubAccount, createMcpAdapter, createMonotonicNonceFactory, createPolymarketApiKey, createStdioServer, defineX402Payment, depositToHyperliquidBridge, derivePolymarketApiKey, ensureTextContent, estimateCountBack, evaluateNewsContinuationGate, executeTool, extractHyperliquidDex, extractHyperliquidOrderIds, fetchHyperliquidAllMids, fetchHyperliquidAssetCtxs, fetchHyperliquidBars, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPerpMarketInfo, fetchHyperliquidPreTransferCheck, fetchHyperliquidSizeDecimals, fetchHyperliquidSpotAccountValue, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMarketInfo, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidSpotTickSize, fetchHyperliquidSpotUsdPriceMap, fetchHyperliquidTickSize, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, fetchNewsEventSignal, fetchNewsPropositionSignal, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPrice, fetchPolymarketPriceHistory, flattenMessageContent, formatHyperliquidMarketablePrice, formatHyperliquidOrderSize, formatHyperliquidPrice, formatHyperliquidSize, generateText, getHyperliquidMaxBuilderFee, getModelConfig, getMyPerformance, getMyTools, getRpcUrl, getX402PaymentContext, isHyperliquidSpotSymbol, isStreamingSupported, isToolCallingSupported, listModels, modifyHyperliquidOrder, normalizeHyperliquidBaseSymbol, normalizeHyperliquidDcaEntries, normalizeHyperliquidIndicatorBars, normalizeHyperliquidMetaSymbol, normalizeModelName, normalizeNumberArrayish, normalizeSpotTokenName2 as normalizeSpotTokenName, normalizeStringArrayish, parseHyperliquidJson, parseSpotPairSymbol, parseTimeToSeconds, payX402, payX402WithWallet, placeHyperliquidOrder, placeHyperliquidTwapOrder, placePolymarketOrder, planHyperliquidTrade, postAgentDigest, readHyperliquidAccountValue, readHyperliquidNumber, readHyperliquidPerpPosition, readHyperliquidPerpPositionSize, readHyperliquidSpotAccountValue, readHyperliquidSpotBalance, readHyperliquidSpotBalanceSize, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, registry, requireX402Payment, reserveHyperliquidRequestWeight, resolutionToSeconds, resolveBacktestAccountValueUsd, resolveBacktestMode, resolveBacktestWindow, resolveConfig2 as resolveConfig, resolveExchangeAddress, resolveHyperliquidAbstractionFromMode, resolveHyperliquidBudgetUsd, resolveHyperliquidCadenceCron, resolveHyperliquidCadenceFromResolution, resolveHyperliquidChain, resolveHyperliquidChainConfig, resolveHyperliquidDcaSymbolEntries, resolveHyperliquidErrorDetail, resolveHyperliquidHourlyInterval, resolveHyperliquidIntervalCron, resolveHyperliquidLeverageMode, resolveHyperliquidMaxPerRunUsd, resolveHyperliquidOrderRef, resolveHyperliquidOrderSymbol, resolveHyperliquidPair, resolveHyperliquidPerpSymbol, resolveHyperliquidProfileChain, resolveHyperliquidRpcEnvVar, resolveHyperliquidScheduleEvery, resolveHyperliquidScheduleUnit, resolveHyperliquidSpotSymbol, resolveHyperliquidStoreNetwork, resolveHyperliquidSymbol, resolveHyperliquidTargetSize, resolveNewsGatewayBase, resolvePolymarketBaseUrl, resolveRuntimePath, resolveSpotMidCandidates, resolveSpotTokenCandidates, resolveToolset, responseToToolResponse, retrieve, roundHyperliquidPriceToTick, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidAccountAbstractionMode, setHyperliquidDexAbstraction, setHyperliquidPortfolioMargin, store, streamText, tokens, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, wallet, walletToolkit, withX402Payment, withdrawFromHyperliquid };
|
|
7393
|
+
export { AIAbortError, AIError, AIFetchError, AIResponseError, BACKTEST_DECISION_MODE, DEFAULT_BASE_URL, DEFAULT_CHAIN, DEFAULT_FACILITATOR, DEFAULT_HYPERLIQUID_CADENCE_CRON, DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, DEFAULT_HYPERLIQUID_TPSL_MARKET_SLIPPAGE_BPS, DEFAULT_MODEL, DEFAULT_OPENPOND_GATEWAY_URL2 as DEFAULT_OPENPOND_GATEWAY_URL, DEFAULT_TIMEOUT_MS, DEFAULT_TOKENS, HTTP_METHODS2 as HTTP_METHODS, HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, NewsSignalClient, 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, backtestDecisionRequestSchema, batchModifyHyperliquidOrders, buildBacktestDecisionSeriesInput, buildHmacSignature, buildHyperliquidMarketIdentity, buildHyperliquidProfileAssets, buildHyperliquidSpotUsdPriceMap, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllHyperliquidOrders, cancelAllPolymarketOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, chains, clampHyperliquidAbs, clampHyperliquidFloat, clampHyperliquidInt, computeHyperliquidMarketIocLimitPrice, createAIClient, createDevServer, createHyperliquidSubAccount, createMcpAdapter, createMonotonicNonceFactory, createPolymarketApiKey, createStdioServer, defineX402Payment, depositToHyperliquidBridge, derivePolymarketApiKey, ensureTextContent, estimateCountBack, estimateHyperliquidLiquidationPrice, evaluateNewsContinuationGate, executeTool, extractHyperliquidDex, extractHyperliquidOrderIds, fetchHyperliquidAllMids, fetchHyperliquidAssetCtxs, fetchHyperliquidBars, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPerpMarketInfo, fetchHyperliquidPreTransferCheck, fetchHyperliquidSizeDecimals, fetchHyperliquidSpotAccountValue, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMarketInfo, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidSpotTickSize, fetchHyperliquidSpotUsdPriceMap, fetchHyperliquidTickSize, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, fetchNewsEventSignal, fetchNewsPropositionSignal, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPrice, fetchPolymarketPriceHistory, flattenMessageContent, formatHyperliquidMarketablePrice, formatHyperliquidOrderSize, formatHyperliquidPrice, formatHyperliquidSize, generateText, getHyperliquidMaxBuilderFee, getModelConfig, getMyPerformance, getMyTools, getRpcUrl, getX402PaymentContext, isHyperliquidSpotSymbol, isStreamingSupported, isToolCallingSupported, listModels, modifyHyperliquidOrder, normalizeHyperliquidBaseSymbol, normalizeHyperliquidDcaEntries, normalizeHyperliquidIndicatorBars, normalizeHyperliquidMetaSymbol, normalizeModelName, normalizeNumberArrayish, normalizeSpotTokenName2 as normalizeSpotTokenName, normalizeStringArrayish, parseHyperliquidJson, parseHyperliquidSymbol, parseSpotPairSymbol, parseTimeToSeconds, payX402, payX402WithWallet, placeHyperliquidOrder2 as placeHyperliquidOrder, placeHyperliquidOrderWithTpSl, placeHyperliquidPositionTpSl, placeHyperliquidTwapOrder, placePolymarketOrder, planHyperliquidTrade, postAgentDigest, readHyperliquidAccountValue, readHyperliquidNumber, readHyperliquidPerpPosition, readHyperliquidPerpPositionSize, readHyperliquidSpotAccountValue, readHyperliquidSpotBalance, readHyperliquidSpotBalanceSize, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, registry, requireX402Payment, reserveHyperliquidRequestWeight, resolutionToSeconds, resolveBacktestAccountValueUsd, resolveBacktestMode, resolveBacktestWindow, resolveConfig2 as resolveConfig, resolveExchangeAddress, resolveHyperliquidAbstractionFromMode, resolveHyperliquidBudgetUsd, resolveHyperliquidCadenceCron, resolveHyperliquidCadenceFromResolution, resolveHyperliquidChain, resolveHyperliquidChainConfig, resolveHyperliquidDcaSymbolEntries, resolveHyperliquidErrorDetail, resolveHyperliquidHourlyInterval, resolveHyperliquidIntervalCron, resolveHyperliquidLeverageMode, resolveHyperliquidMaxPerRunUsd, resolveHyperliquidOrderRef, resolveHyperliquidOrderSymbol, resolveHyperliquidPair, resolveHyperliquidPerpSymbol, resolveHyperliquidProfileChain, resolveHyperliquidRpcEnvVar, resolveHyperliquidScheduleEvery, resolveHyperliquidScheduleUnit, resolveHyperliquidSpotSymbol, resolveHyperliquidStoreNetwork, resolveHyperliquidSymbol, resolveHyperliquidTargetSize, resolveNewsGatewayBase, resolvePolymarketBaseUrl, resolveRuntimePath, resolveSpotMidCandidates, resolveSpotTokenCandidates, resolveToolset, responseToToolResponse, retrieve, roundHyperliquidPriceToTick, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidAccountAbstractionMode, setHyperliquidDexAbstraction, setHyperliquidPortfolioMargin, store, streamText, tokens, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, wallet, walletToolkit, withX402Payment, withdrawFromHyperliquid };
|
|
6848
7394
|
//# sourceMappingURL=index.js.map
|
|
6849
7395
|
//# sourceMappingURL=index.js.map
|