opentool 0.9.0 → 0.10.1
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 +1 -1
- package/dist/adapters/hyperliquid/index.js +32 -102
- package/dist/adapters/hyperliquid/index.js.map +1 -1
- package/dist/ai/index.js +9 -22
- package/dist/ai/index.js.map +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +54 -105
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +92 -243
- package/dist/index.js.map +1 -1
- package/dist/store/index.js +7 -21
- package/dist/store/index.js.map +1 -1
- package/dist/{types-BVLpaY4O.d.ts → types-3w880w_t.d.ts} +2 -2
- package/dist/{validate-3WEA0Ezt.d.ts → validate-BgNU5laL.d.ts} +1 -1
- package/dist/viem/index.d.ts +1 -0
- package/dist/viem/index.js +3 -0
- package/dist/viem/index.js.map +1 -0
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.js +7 -37
- package/dist/wallet/index.js.map +1 -1
- package/dist/x402/index.js +12 -4
- package/dist/x402/index.js.map +1 -1
- package/package.json +21 -16
- package/templates/base/package.json +2 -2
|
@@ -6,11 +6,7 @@ import { hexToBytes, concatBytes, bytesToHex } from '@noble/hashes/utils';
|
|
|
6
6
|
// src/adapters/hyperliquid/index.ts
|
|
7
7
|
|
|
8
8
|
// src/store/index.ts
|
|
9
|
-
var STORE_EVENT_LEVELS = [
|
|
10
|
-
"decision",
|
|
11
|
-
"execution",
|
|
12
|
-
"lifecycle"
|
|
13
|
-
];
|
|
9
|
+
var STORE_EVENT_LEVELS = ["decision", "execution", "lifecycle"];
|
|
14
10
|
var STORE_EVENT_LEVEL_SET = new Set(STORE_EVENT_LEVELS);
|
|
15
11
|
var MARKET_REQUIRED_ACTIONS = [
|
|
16
12
|
"swap",
|
|
@@ -77,7 +73,7 @@ var resolveEventLevel = (input) => {
|
|
|
77
73
|
return null;
|
|
78
74
|
};
|
|
79
75
|
var normalizeStoreInput = (input) => {
|
|
80
|
-
const metadata = { ...input.metadata
|
|
76
|
+
const metadata = { ...input.metadata };
|
|
81
77
|
const eventLevel = resolveEventLevel({ ...input, metadata });
|
|
82
78
|
if (eventLevel) {
|
|
83
79
|
metadata.eventLevel = eventLevel;
|
|
@@ -96,9 +92,7 @@ function resolveConfig(options) {
|
|
|
96
92
|
throw new StoreError("BASE_URL is required to store activity events");
|
|
97
93
|
}
|
|
98
94
|
if (!apiKey) {
|
|
99
|
-
throw new StoreError(
|
|
100
|
-
"OPENPOND_API_KEY is required to store activity events"
|
|
101
|
-
);
|
|
95
|
+
throw new StoreError("OPENPOND_API_KEY is required to store activity events");
|
|
102
96
|
}
|
|
103
97
|
const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
|
|
104
98
|
const fetchFn = options?.fetchFn ?? globalThis.fetch;
|
|
@@ -113,15 +107,11 @@ async function store(input, options) {
|
|
|
113
107
|
const eventLevel = normalizedInput.eventLevel;
|
|
114
108
|
const normalizedAction = normalizeAction(normalizedInput.action);
|
|
115
109
|
if (mode === "backtest" && !normalizedInput.backtestRunId) {
|
|
116
|
-
throw new StoreError(
|
|
117
|
-
`backtestRunId is required when mode is "backtest"`
|
|
118
|
-
);
|
|
110
|
+
throw new StoreError(`backtestRunId is required when mode is "backtest"`);
|
|
119
111
|
}
|
|
120
112
|
if (eventLevel === "execution" || eventLevel === "lifecycle") {
|
|
121
113
|
if (!normalizedAction || !EXECUTION_ACTIONS_SET.has(normalizedAction)) {
|
|
122
|
-
throw new StoreError(
|
|
123
|
-
`eventLevel "${eventLevel}" requires an execution action`
|
|
124
|
-
);
|
|
114
|
+
throw new StoreError(`eventLevel "${eventLevel}" requires an execution action`);
|
|
125
115
|
}
|
|
126
116
|
}
|
|
127
117
|
if (eventLevel === "execution" && !hasMarketIdentity(normalizedInput.market)) {
|
|
@@ -375,9 +365,7 @@ async function getUniverse(args) {
|
|
|
375
365
|
const response = await args.fetcher(`${args.baseUrl}/info`, {
|
|
376
366
|
method: "POST",
|
|
377
367
|
headers: { "content-type": "application/json" },
|
|
378
|
-
body: JSON.stringify(
|
|
379
|
-
dexKey ? { type: "meta", dex: dexKey } : { type: "meta" }
|
|
380
|
-
)
|
|
368
|
+
body: JSON.stringify(dexKey ? { type: "meta", dex: dexKey } : { type: "meta" })
|
|
381
369
|
});
|
|
382
370
|
const json = await response.json().catch(() => null);
|
|
383
371
|
if (!response.ok || !json?.universe) {
|
|
@@ -415,9 +403,7 @@ async function getSpotMeta(args) {
|
|
|
415
403
|
function resolveAssetIndex(symbol, universe) {
|
|
416
404
|
const [raw] = symbol.split("-");
|
|
417
405
|
const target = raw.trim();
|
|
418
|
-
const index = universe.findIndex(
|
|
419
|
-
(entry) => entry.name.toUpperCase() === target.toUpperCase()
|
|
420
|
-
);
|
|
406
|
+
const index = universe.findIndex((entry) => entry.name.toUpperCase() === target.toUpperCase());
|
|
421
407
|
if (index === -1) {
|
|
422
408
|
throw new Error(`Unknown Hyperliquid asset symbol: ${symbol}`);
|
|
423
409
|
}
|
|
@@ -447,9 +433,7 @@ async function getPerpDexs(args) {
|
|
|
447
433
|
async function resolveDexIndex(args) {
|
|
448
434
|
const dexs = await getPerpDexs(args);
|
|
449
435
|
const target = args.dex.trim().toLowerCase();
|
|
450
|
-
const index = dexs.findIndex(
|
|
451
|
-
(entry) => entry?.name?.toLowerCase() === target
|
|
452
|
-
);
|
|
436
|
+
const index = dexs.findIndex((entry) => entry?.name?.toLowerCase() === target);
|
|
453
437
|
if (index === -1) {
|
|
454
438
|
throw new Error(`Unknown Hyperliquid perp dex: ${args.dex}`);
|
|
455
439
|
}
|
|
@@ -636,15 +620,7 @@ async function signL1Action(args) {
|
|
|
636
620
|
return splitSignature(signatureHex);
|
|
637
621
|
}
|
|
638
622
|
async function signSpotSend(args) {
|
|
639
|
-
const {
|
|
640
|
-
wallet,
|
|
641
|
-
hyperliquidChain,
|
|
642
|
-
signatureChainId,
|
|
643
|
-
destination,
|
|
644
|
-
token,
|
|
645
|
-
amount,
|
|
646
|
-
time
|
|
647
|
-
} = args;
|
|
623
|
+
const { wallet, hyperliquidChain, signatureChainId, destination, token, amount, time } = args;
|
|
648
624
|
const domain = {
|
|
649
625
|
name: "HyperliquidSignTransaction",
|
|
650
626
|
version: "1",
|
|
@@ -1053,9 +1029,7 @@ var HyperliquidExchangeClient = class {
|
|
|
1053
1029
|
this.expiresAfter = args.expiresAfter;
|
|
1054
1030
|
const resolvedNonceSource = args.walletNonceProvider ?? args.wallet.nonceSource ?? args.nonceSource;
|
|
1055
1031
|
if (!resolvedNonceSource) {
|
|
1056
|
-
throw new Error(
|
|
1057
|
-
"Wallet nonce source is required for Hyperliquid exchange actions."
|
|
1058
|
-
);
|
|
1032
|
+
throw new Error("Wallet nonce source is required for Hyperliquid exchange actions.");
|
|
1059
1033
|
}
|
|
1060
1034
|
this.nonceSource = resolvedNonceSource;
|
|
1061
1035
|
}
|
|
@@ -1185,9 +1159,7 @@ var HyperliquidExchangeClient = class {
|
|
|
1185
1159
|
expiresAfter: this.expiresAfter,
|
|
1186
1160
|
nonceSource: this.nonceSource
|
|
1187
1161
|
};
|
|
1188
|
-
return setHyperliquidDexAbstraction(
|
|
1189
|
-
params.user ? { ...base, user: params.user } : base
|
|
1190
|
-
);
|
|
1162
|
+
return setHyperliquidDexAbstraction(params.user ? { ...base, user: params.user } : base);
|
|
1191
1163
|
}
|
|
1192
1164
|
setAccountAbstractionMode(params) {
|
|
1193
1165
|
const base = {
|
|
@@ -1211,24 +1183,18 @@ var HyperliquidExchangeClient = class {
|
|
|
1211
1183
|
expiresAfter: this.expiresAfter,
|
|
1212
1184
|
nonceSource: this.nonceSource
|
|
1213
1185
|
};
|
|
1214
|
-
return setHyperliquidPortfolioMargin(
|
|
1215
|
-
params.user ? { ...base, user: params.user } : base
|
|
1216
|
-
);
|
|
1186
|
+
return setHyperliquidPortfolioMargin(params.user ? { ...base, user: params.user } : base);
|
|
1217
1187
|
}
|
|
1218
1188
|
};
|
|
1219
1189
|
async function setHyperliquidPortfolioMargin(options) {
|
|
1220
1190
|
const env = options.environment ?? "mainnet";
|
|
1221
1191
|
if (!options.wallet?.account || !options.wallet.walletClient) {
|
|
1222
|
-
throw new Error(
|
|
1223
|
-
"Wallet with signing capability is required for portfolio margin."
|
|
1224
|
-
);
|
|
1192
|
+
throw new Error("Wallet with signing capability is required for portfolio margin.");
|
|
1225
1193
|
}
|
|
1226
1194
|
const nonce = options.nonce ?? options.walletNonceProvider?.() ?? options.wallet.nonceSource?.() ?? options.nonceSource?.() ?? Date.now();
|
|
1227
1195
|
const signatureChainId = getSignatureChainId(env);
|
|
1228
1196
|
const hyperliquidChain = HL_CHAIN_LABEL[env];
|
|
1229
|
-
const user = normalizeAddress(
|
|
1230
|
-
options.user ?? options.wallet.address
|
|
1231
|
-
);
|
|
1197
|
+
const user = normalizeAddress(options.user ?? options.wallet.address);
|
|
1232
1198
|
const action = {
|
|
1233
1199
|
type: "userPortfolioMargin",
|
|
1234
1200
|
enabled: Boolean(options.enabled),
|
|
@@ -1257,16 +1223,12 @@ async function setHyperliquidPortfolioMargin(options) {
|
|
|
1257
1223
|
async function setHyperliquidDexAbstraction(options) {
|
|
1258
1224
|
const env = options.environment ?? "mainnet";
|
|
1259
1225
|
if (!options.wallet?.account || !options.wallet.walletClient) {
|
|
1260
|
-
throw new Error(
|
|
1261
|
-
"Wallet with signing capability is required for dex abstraction."
|
|
1262
|
-
);
|
|
1226
|
+
throw new Error("Wallet with signing capability is required for dex abstraction.");
|
|
1263
1227
|
}
|
|
1264
1228
|
const nonce = options.nonce ?? options.walletNonceProvider?.() ?? options.wallet.nonceSource?.() ?? options.nonceSource?.() ?? Date.now();
|
|
1265
1229
|
const signatureChainId = getSignatureChainId(env);
|
|
1266
1230
|
const hyperliquidChain = HL_CHAIN_LABEL[env];
|
|
1267
|
-
const user = normalizeAddress(
|
|
1268
|
-
options.user ?? options.wallet.address
|
|
1269
|
-
);
|
|
1231
|
+
const user = normalizeAddress(options.user ?? options.wallet.address);
|
|
1270
1232
|
const action = {
|
|
1271
1233
|
type: "userDexAbstraction",
|
|
1272
1234
|
enabled: Boolean(options.enabled),
|
|
@@ -1295,16 +1257,12 @@ async function setHyperliquidDexAbstraction(options) {
|
|
|
1295
1257
|
async function setHyperliquidAccountAbstractionMode(options) {
|
|
1296
1258
|
const env = options.environment ?? "mainnet";
|
|
1297
1259
|
if (!options.wallet?.account || !options.wallet.walletClient) {
|
|
1298
|
-
throw new Error(
|
|
1299
|
-
"Wallet with signing capability is required for account abstraction mode."
|
|
1300
|
-
);
|
|
1260
|
+
throw new Error("Wallet with signing capability is required for account abstraction mode.");
|
|
1301
1261
|
}
|
|
1302
1262
|
const nonce = options.nonce ?? options.walletNonceProvider?.() ?? options.wallet.nonceSource?.() ?? options.nonceSource?.() ?? Date.now();
|
|
1303
1263
|
const signatureChainId = getSignatureChainId(env);
|
|
1304
1264
|
const hyperliquidChain = HL_CHAIN_LABEL[env];
|
|
1305
|
-
const user = normalizeAddress(
|
|
1306
|
-
options.user ?? options.wallet.address
|
|
1307
|
-
);
|
|
1265
|
+
const user = normalizeAddress(options.user ?? options.wallet.address);
|
|
1308
1266
|
const abstraction = resolveHyperliquidAbstractionFromMode(options.mode);
|
|
1309
1267
|
const action = {
|
|
1310
1268
|
type: "userSetAbstraction",
|
|
@@ -1346,14 +1304,10 @@ async function cancelHyperliquidOrdersByCloid(options) {
|
|
|
1346
1304
|
options.cancels.forEach((c) => assertSymbol(c.symbol));
|
|
1347
1305
|
const action = {
|
|
1348
1306
|
type: "cancelByCloid",
|
|
1349
|
-
cancels: await withAssetIndexes(
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
asset: idx,
|
|
1354
|
-
cloid: normalizeCloid(entry.cloid)
|
|
1355
|
-
})
|
|
1356
|
-
)
|
|
1307
|
+
cancels: await withAssetIndexes(options, options.cancels, (idx, entry) => ({
|
|
1308
|
+
asset: idx,
|
|
1309
|
+
cloid: normalizeCloid(entry.cloid)
|
|
1310
|
+
}))
|
|
1357
1311
|
};
|
|
1358
1312
|
return submitExchangeAction(options, action);
|
|
1359
1313
|
}
|
|
@@ -2304,10 +2258,7 @@ function formatScaledInt(value, decimals) {
|
|
|
2304
2258
|
return `${negative ? "-" : ""}${integer.toString()}`;
|
|
2305
2259
|
}
|
|
2306
2260
|
const fractionStr = fraction.toString().padStart(decimals, "0");
|
|
2307
|
-
return `${negative ? "-" : ""}${integer.toString()}.${fractionStr}`.replace(
|
|
2308
|
-
/\.?0+$/,
|
|
2309
|
-
""
|
|
2310
|
-
);
|
|
2261
|
+
return `${negative ? "-" : ""}${integer.toString()}.${fractionStr}`.replace(/\.?0+$/, "");
|
|
2311
2262
|
}
|
|
2312
2263
|
function resolveSpotSizeDecimals(meta, symbol) {
|
|
2313
2264
|
const universe = meta.universe ?? [];
|
|
@@ -2415,10 +2366,7 @@ async function fetchHyperliquidSpotTickSize(params) {
|
|
|
2415
2366
|
if (!Number.isFinite(params.marketIndex)) {
|
|
2416
2367
|
throw new Error("Hyperliquid spot market index is invalid.");
|
|
2417
2368
|
}
|
|
2418
|
-
return fetchHyperliquidTickSizeForCoin(
|
|
2419
|
-
params.environment,
|
|
2420
|
-
`@${params.marketIndex}`
|
|
2421
|
-
);
|
|
2369
|
+
return fetchHyperliquidTickSizeForCoin(params.environment, `@${params.marketIndex}`);
|
|
2422
2370
|
}
|
|
2423
2371
|
async function fetchHyperliquidTickSizeForCoin(environment, coin) {
|
|
2424
2372
|
const base = API_BASES[environment];
|
|
@@ -2432,9 +2380,7 @@ async function fetchHyperliquidTickSizeForCoin(environment, coin) {
|
|
|
2432
2380
|
}
|
|
2433
2381
|
const data = await res.json().catch(() => null);
|
|
2434
2382
|
const levels = Array.isArray(data?.levels) ? data?.levels ?? [] : [];
|
|
2435
|
-
const prices = levels.flatMap(
|
|
2436
|
-
(side) => Array.isArray(side) ? side.map((entry) => String(entry?.px ?? "")) : []
|
|
2437
|
-
).filter((px) => px.length > 0);
|
|
2383
|
+
const prices = levels.flatMap((side) => Array.isArray(side) ? side.map((entry) => String(entry?.px ?? "")) : []).filter((px) => px.length > 0);
|
|
2438
2384
|
if (prices.length < 2) {
|
|
2439
2385
|
throw new Error(`Hyperliquid l2Book missing price levels for ${coin}`);
|
|
2440
2386
|
}
|
|
@@ -2525,9 +2471,7 @@ async function fetchHyperliquidSpotMarketInfo(params) {
|
|
|
2525
2471
|
price = readHyperliquidNumber(ctx?.markPx ?? ctx?.midPx ?? ctx?.oraclePx);
|
|
2526
2472
|
}
|
|
2527
2473
|
if (!price || price <= 0) {
|
|
2528
|
-
throw new Error(
|
|
2529
|
-
`No spot price available for ${normalizedBase}/${normalizedQuote}`
|
|
2530
|
-
);
|
|
2474
|
+
throw new Error(`No spot price available for ${normalizedBase}/${normalizedQuote}`);
|
|
2531
2475
|
}
|
|
2532
2476
|
const marketIndex = typeof market?.index === "number" ? market.index : idx;
|
|
2533
2477
|
return {
|
|
@@ -2677,9 +2621,7 @@ async function placeHyperliquidOrder(options) {
|
|
|
2677
2621
|
} = options;
|
|
2678
2622
|
const effectiveBuilder = BUILDER_CODE;
|
|
2679
2623
|
if (!wallet?.account || !wallet.walletClient) {
|
|
2680
|
-
throw new Error(
|
|
2681
|
-
"Hyperliquid order signing requires a wallet with signing capabilities."
|
|
2682
|
-
);
|
|
2624
|
+
throw new Error("Hyperliquid order signing requires a wallet with signing capabilities.");
|
|
2683
2625
|
}
|
|
2684
2626
|
if (!orders.length) {
|
|
2685
2627
|
throw new Error("At least one order is required.");
|
|
@@ -2793,10 +2735,7 @@ async function placeHyperliquidOrder(options) {
|
|
|
2793
2735
|
);
|
|
2794
2736
|
if (errorStatuses.length) {
|
|
2795
2737
|
const message = errorStatuses.map((entry) => entry.error).join(", ");
|
|
2796
|
-
throw new HyperliquidApiError(
|
|
2797
|
-
message || "Hyperliquid rejected the order.",
|
|
2798
|
-
json
|
|
2799
|
-
);
|
|
2738
|
+
throw new HyperliquidApiError(message || "Hyperliquid rejected the order.", json);
|
|
2800
2739
|
}
|
|
2801
2740
|
return json;
|
|
2802
2741
|
}
|
|
@@ -2816,9 +2755,7 @@ async function depositToHyperliquidBridge(options) {
|
|
|
2816
2755
|
const usdcAddress = getUsdcAddress(environment);
|
|
2817
2756
|
const amountUnits = parseUnits(amount, 6);
|
|
2818
2757
|
if (!wallet.walletClient || !wallet.publicClient) {
|
|
2819
|
-
throw new Error(
|
|
2820
|
-
"Wallet client and public client are required for deposit."
|
|
2821
|
-
);
|
|
2758
|
+
throw new Error("Wallet client and public client are required for deposit.");
|
|
2822
2759
|
}
|
|
2823
2760
|
const walletClient = wallet.walletClient;
|
|
2824
2761
|
const publicClient = wallet.publicClient;
|
|
@@ -2843,15 +2780,10 @@ async function depositToHyperliquidBridge(options) {
|
|
|
2843
2780
|
}
|
|
2844
2781
|
async function withdrawFromHyperliquid(options) {
|
|
2845
2782
|
const { environment, amount, destination, wallet } = options;
|
|
2846
|
-
const normalizedAmount = normalizePositiveDecimalString(
|
|
2847
|
-
amount,
|
|
2848
|
-
"Withdraw amount"
|
|
2849
|
-
);
|
|
2783
|
+
const normalizedAmount = normalizePositiveDecimalString(amount, "Withdraw amount");
|
|
2850
2784
|
const parsedAmount = Number.parseFloat(normalizedAmount);
|
|
2851
2785
|
if (!wallet.account || !wallet.walletClient || !wallet.publicClient) {
|
|
2852
|
-
throw new Error(
|
|
2853
|
-
"Wallet client and public client are required for withdraw."
|
|
2854
|
-
);
|
|
2786
|
+
throw new Error("Wallet client and public client are required for withdraw.");
|
|
2855
2787
|
}
|
|
2856
2788
|
const signatureChainId = getSignatureChainId(environment);
|
|
2857
2789
|
const hyperliquidChain = HL_CHAIN_LABEL[environment];
|
|
@@ -2934,9 +2866,7 @@ async function fetchHyperliquidClearinghouseState(params) {
|
|
|
2934
2866
|
async function approveHyperliquidBuilderFee(options) {
|
|
2935
2867
|
const { environment, wallet, nonce, signatureChainId } = options;
|
|
2936
2868
|
if (!wallet?.account || !wallet.walletClient) {
|
|
2937
|
-
throw new Error(
|
|
2938
|
-
"Hyperliquid builder approval requires a wallet with signing capabilities."
|
|
2939
|
-
);
|
|
2869
|
+
throw new Error("Hyperliquid builder approval requires a wallet with signing capabilities.");
|
|
2940
2870
|
}
|
|
2941
2871
|
const maxFeeRateValue = BUILDER_CODE.fee / 1e3;
|
|
2942
2872
|
const formattedPercent = `${maxFeeRateValue}%`;
|