opentool 0.8.1 → 0.8.4
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/README.md +1 -1
- package/dist/adapters/hyperliquid/index.d.ts +77 -68
- package/dist/adapters/hyperliquid/index.js +282 -180
- package/dist/adapters/hyperliquid/index.js.map +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +83 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +322 -6
- package/dist/index.js +1210 -207
- package/dist/index.js.map +1 -1
- package/dist/store/index.d.ts +35 -1
- package/dist/store/index.js +61 -1
- package/dist/store/index.js.map +1 -1
- package/dist/{validate-uetwG5jo.d.ts → validate-BJ5-5n8h.d.ts} +1 -0
- package/dist/wallet/index.js +25 -15
- package/dist/wallet/index.js.map +1 -1
- package/package.json +7 -2
- package/templates/base/README.md +10 -0
- package/templates/base/metadata.ts +12 -0
- package/templates/base/package.json +23 -0
- package/templates/base/tools/aave-stake.ts +96 -0
- package/templates/base/tsconfig.json +14 -0
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ type ExchangeSignature = {
|
|
|
62
62
|
v: 27 | 28;
|
|
63
63
|
};
|
|
64
64
|
type HyperliquidExchangeResponse<T = unknown> = {
|
|
65
|
-
status:
|
|
65
|
+
status: string;
|
|
66
66
|
response?: {
|
|
67
67
|
type: string;
|
|
68
68
|
data?: T;
|
|
@@ -93,6 +93,72 @@ declare function createL1ActionHash(args: {
|
|
|
93
93
|
expiresAfter?: number | undefined;
|
|
94
94
|
}): `0x${string}`;
|
|
95
95
|
|
|
96
|
+
declare class HyperliquidInfoClient {
|
|
97
|
+
private readonly environment;
|
|
98
|
+
constructor(environment?: HyperliquidEnvironment);
|
|
99
|
+
meta(): Promise<any>;
|
|
100
|
+
metaAndAssetCtxs(): Promise<any>;
|
|
101
|
+
spotMeta(): Promise<any>;
|
|
102
|
+
spotMetaAndAssetCtxs(): Promise<any>;
|
|
103
|
+
assetCtxs(): Promise<any>;
|
|
104
|
+
spotAssetCtxs(): Promise<any>;
|
|
105
|
+
openOrders(user: `0x${string}`): Promise<any>;
|
|
106
|
+
frontendOpenOrders(user: `0x${string}`): Promise<any>;
|
|
107
|
+
orderStatus(user: `0x${string}`, oid: number | string): Promise<any>;
|
|
108
|
+
historicalOrders(user: `0x${string}`): Promise<any>;
|
|
109
|
+
userFills(user: `0x${string}`): Promise<any>;
|
|
110
|
+
userFillsByTime(user: `0x${string}`, startTime: number, endTime: number): Promise<any>;
|
|
111
|
+
userRateLimit(user: `0x${string}`): Promise<any>;
|
|
112
|
+
preTransferCheck(user: `0x${string}`, source: `0x${string}`): Promise<any>;
|
|
113
|
+
spotClearinghouseState(user: `0x${string}`): Promise<any>;
|
|
114
|
+
}
|
|
115
|
+
declare function fetchHyperliquidMeta(environment?: HyperliquidEnvironment): Promise<any>;
|
|
116
|
+
declare function fetchHyperliquidMetaAndAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
117
|
+
declare function fetchHyperliquidSpotMeta(environment?: HyperliquidEnvironment): Promise<any>;
|
|
118
|
+
declare function fetchHyperliquidSpotMetaAndAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
119
|
+
declare function fetchHyperliquidAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
120
|
+
declare function fetchHyperliquidSpotAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
121
|
+
declare function fetchHyperliquidOpenOrders(params: {
|
|
122
|
+
environment?: HyperliquidEnvironment;
|
|
123
|
+
user: `0x${string}`;
|
|
124
|
+
}): Promise<any>;
|
|
125
|
+
declare function fetchHyperliquidFrontendOpenOrders(params: {
|
|
126
|
+
environment?: HyperliquidEnvironment;
|
|
127
|
+
user: `0x${string}`;
|
|
128
|
+
}): Promise<any>;
|
|
129
|
+
declare function fetchHyperliquidOrderStatus(params: {
|
|
130
|
+
environment?: HyperliquidEnvironment;
|
|
131
|
+
user: `0x${string}`;
|
|
132
|
+
oid: number | string;
|
|
133
|
+
}): Promise<any>;
|
|
134
|
+
declare function fetchHyperliquidHistoricalOrders(params: {
|
|
135
|
+
environment?: HyperliquidEnvironment;
|
|
136
|
+
user: `0x${string}`;
|
|
137
|
+
}): Promise<any>;
|
|
138
|
+
declare function fetchHyperliquidUserFills(params: {
|
|
139
|
+
environment?: HyperliquidEnvironment;
|
|
140
|
+
user: `0x${string}`;
|
|
141
|
+
}): Promise<any>;
|
|
142
|
+
declare function fetchHyperliquidUserFillsByTime(params: {
|
|
143
|
+
environment?: HyperliquidEnvironment;
|
|
144
|
+
user: `0x${string}`;
|
|
145
|
+
startTime: number;
|
|
146
|
+
endTime: number;
|
|
147
|
+
}): Promise<any>;
|
|
148
|
+
declare function fetchHyperliquidUserRateLimit(params: {
|
|
149
|
+
environment?: HyperliquidEnvironment;
|
|
150
|
+
user: `0x${string}`;
|
|
151
|
+
}): Promise<any>;
|
|
152
|
+
declare function fetchHyperliquidPreTransferCheck(params: {
|
|
153
|
+
environment?: HyperliquidEnvironment;
|
|
154
|
+
user: `0x${string}`;
|
|
155
|
+
source: `0x${string}`;
|
|
156
|
+
}): Promise<any>;
|
|
157
|
+
declare function fetchHyperliquidSpotClearinghouseState(params: {
|
|
158
|
+
environment?: HyperliquidEnvironment;
|
|
159
|
+
user: `0x${string}`;
|
|
160
|
+
}): Promise<any>;
|
|
161
|
+
|
|
96
162
|
type CommonActionOptions = {
|
|
97
163
|
environment?: HyperliquidEnvironment;
|
|
98
164
|
vaultAddress?: `0x${string}` | undefined;
|
|
@@ -168,7 +234,16 @@ declare class HyperliquidExchangeClient {
|
|
|
168
234
|
token: string;
|
|
169
235
|
amount: string | number | bigint;
|
|
170
236
|
}): Promise<HyperliquidExchangeResponse<unknown>>;
|
|
237
|
+
setPortfolioMargin(params: {
|
|
238
|
+
enabled: boolean;
|
|
239
|
+
user?: `0x${string}`;
|
|
240
|
+
}): Promise<HyperliquidExchangeResponse<unknown>>;
|
|
171
241
|
}
|
|
242
|
+
declare function setHyperliquidPortfolioMargin(options: {
|
|
243
|
+
wallet: WalletFullContext;
|
|
244
|
+
enabled: boolean;
|
|
245
|
+
user?: `0x${string}`;
|
|
246
|
+
} & CommonActionOptions): Promise<HyperliquidExchangeResponse<unknown>>;
|
|
172
247
|
declare function cancelHyperliquidOrders(options: {
|
|
173
248
|
wallet: WalletFullContext;
|
|
174
249
|
cancels: CancelInput[];
|
|
@@ -233,72 +308,6 @@ declare function sendHyperliquidSpot(options: {
|
|
|
233
308
|
nonceSource?: NonceSource;
|
|
234
309
|
}): Promise<HyperliquidExchangeResponse<unknown>>;
|
|
235
310
|
|
|
236
|
-
declare class HyperliquidInfoClient {
|
|
237
|
-
private readonly environment;
|
|
238
|
-
constructor(environment?: HyperliquidEnvironment);
|
|
239
|
-
meta(): Promise<any>;
|
|
240
|
-
metaAndAssetCtxs(): Promise<any>;
|
|
241
|
-
spotMeta(): Promise<any>;
|
|
242
|
-
spotMetaAndAssetCtxs(): Promise<any>;
|
|
243
|
-
assetCtxs(): Promise<any>;
|
|
244
|
-
spotAssetCtxs(): Promise<any>;
|
|
245
|
-
openOrders(user: `0x${string}`): Promise<any>;
|
|
246
|
-
frontendOpenOrders(user: `0x${string}`): Promise<any>;
|
|
247
|
-
orderStatus(user: `0x${string}`, oid: number | string): Promise<any>;
|
|
248
|
-
historicalOrders(user: `0x${string}`): Promise<any>;
|
|
249
|
-
userFills(user: `0x${string}`): Promise<any>;
|
|
250
|
-
userFillsByTime(user: `0x${string}`, startTime: number, endTime: number): Promise<any>;
|
|
251
|
-
userRateLimit(user: `0x${string}`): Promise<any>;
|
|
252
|
-
preTransferCheck(user: `0x${string}`, source: `0x${string}`): Promise<any>;
|
|
253
|
-
spotClearinghouseState(user: `0x${string}`): Promise<any>;
|
|
254
|
-
}
|
|
255
|
-
declare function fetchHyperliquidMeta(environment?: HyperliquidEnvironment): Promise<any>;
|
|
256
|
-
declare function fetchHyperliquidMetaAndAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
257
|
-
declare function fetchHyperliquidSpotMeta(environment?: HyperliquidEnvironment): Promise<any>;
|
|
258
|
-
declare function fetchHyperliquidSpotMetaAndAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
259
|
-
declare function fetchHyperliquidAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
260
|
-
declare function fetchHyperliquidSpotAssetCtxs(environment?: HyperliquidEnvironment): Promise<any>;
|
|
261
|
-
declare function fetchHyperliquidOpenOrders(params: {
|
|
262
|
-
environment?: HyperliquidEnvironment;
|
|
263
|
-
user: `0x${string}`;
|
|
264
|
-
}): Promise<any>;
|
|
265
|
-
declare function fetchHyperliquidFrontendOpenOrders(params: {
|
|
266
|
-
environment?: HyperliquidEnvironment;
|
|
267
|
-
user: `0x${string}`;
|
|
268
|
-
}): Promise<any>;
|
|
269
|
-
declare function fetchHyperliquidOrderStatus(params: {
|
|
270
|
-
environment?: HyperliquidEnvironment;
|
|
271
|
-
user: `0x${string}`;
|
|
272
|
-
oid: number | string;
|
|
273
|
-
}): Promise<any>;
|
|
274
|
-
declare function fetchHyperliquidHistoricalOrders(params: {
|
|
275
|
-
environment?: HyperliquidEnvironment;
|
|
276
|
-
user: `0x${string}`;
|
|
277
|
-
}): Promise<any>;
|
|
278
|
-
declare function fetchHyperliquidUserFills(params: {
|
|
279
|
-
environment?: HyperliquidEnvironment;
|
|
280
|
-
user: `0x${string}`;
|
|
281
|
-
}): Promise<any>;
|
|
282
|
-
declare function fetchHyperliquidUserFillsByTime(params: {
|
|
283
|
-
environment?: HyperliquidEnvironment;
|
|
284
|
-
user: `0x${string}`;
|
|
285
|
-
startTime: number;
|
|
286
|
-
endTime: number;
|
|
287
|
-
}): Promise<any>;
|
|
288
|
-
declare function fetchHyperliquidUserRateLimit(params: {
|
|
289
|
-
environment?: HyperliquidEnvironment;
|
|
290
|
-
user: `0x${string}`;
|
|
291
|
-
}): Promise<any>;
|
|
292
|
-
declare function fetchHyperliquidPreTransferCheck(params: {
|
|
293
|
-
environment?: HyperliquidEnvironment;
|
|
294
|
-
user: `0x${string}`;
|
|
295
|
-
source: `0x${string}`;
|
|
296
|
-
}): Promise<any>;
|
|
297
|
-
declare function fetchHyperliquidSpotClearinghouseState(params: {
|
|
298
|
-
environment?: HyperliquidEnvironment;
|
|
299
|
-
user: `0x${string}`;
|
|
300
|
-
}): Promise<any>;
|
|
301
|
-
|
|
302
311
|
interface HyperliquidOrderOptions {
|
|
303
312
|
wallet: WalletFullContext;
|
|
304
313
|
orders: HyperliquidOrderIntent[];
|
|
@@ -411,4 +420,4 @@ declare const __hyperliquidInternals: {
|
|
|
411
420
|
splitSignature: typeof splitSignature;
|
|
412
421
|
};
|
|
413
422
|
|
|
414
|
-
export { HyperliquidApiError, type HyperliquidApproveBuilderFeeOptions, type HyperliquidApproveBuilderFeeResponse, HyperliquidBuilderApprovalError, type HyperliquidBuilderApprovalRecordInput, type HyperliquidBuilderFee, type HyperliquidClearinghouseState, type HyperliquidDepositResult, type HyperliquidEnvironment, HyperliquidExchangeClient, type HyperliquidExchangeResponse, type HyperliquidGrouping, HyperliquidGuardError, HyperliquidInfoClient, type HyperliquidOrderIntent, type HyperliquidOrderOptions, type HyperliquidOrderResponse, type HyperliquidOrderStatus, HyperliquidTermsError, type HyperliquidTermsRecordInput, type HyperliquidTriggerOptions, type HyperliquidTriggerType, type HyperliquidWithdrawResult, type NonceSource, __hyperliquidInternals, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, cancelAllHyperliquidOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, createHyperliquidSubAccount, createMonotonicNonceFactory, depositToHyperliquidBridge, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, getHyperliquidMaxBuilderFee, modifyHyperliquidOrder, placeHyperliquidOrder, placeHyperliquidTwapOrder, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, reserveHyperliquidRequestWeight, scheduleHyperliquidCancel, sendHyperliquidSpot, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, withdrawFromHyperliquid };
|
|
423
|
+
export { HyperliquidApiError, type HyperliquidApproveBuilderFeeOptions, type HyperliquidApproveBuilderFeeResponse, HyperliquidBuilderApprovalError, type HyperliquidBuilderApprovalRecordInput, type HyperliquidBuilderFee, type HyperliquidClearinghouseState, type HyperliquidDepositResult, type HyperliquidEnvironment, HyperliquidExchangeClient, type HyperliquidExchangeResponse, type HyperliquidGrouping, HyperliquidGuardError, HyperliquidInfoClient, type HyperliquidOrderIntent, type HyperliquidOrderOptions, type HyperliquidOrderResponse, type HyperliquidOrderStatus, HyperliquidTermsError, type HyperliquidTermsRecordInput, type HyperliquidTriggerOptions, type HyperliquidTriggerType, type HyperliquidWithdrawResult, type NonceSource, __hyperliquidInternals, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, cancelAllHyperliquidOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, createHyperliquidSubAccount, createMonotonicNonceFactory, depositToHyperliquidBridge, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, getHyperliquidMaxBuilderFee, modifyHyperliquidOrder, placeHyperliquidOrder, placeHyperliquidTwapOrder, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, reserveHyperliquidRequestWeight, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidPortfolioMargin, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, withdrawFromHyperliquid };
|
|
@@ -307,6 +307,37 @@ async function signApproveBuilderFee(args) {
|
|
|
307
307
|
});
|
|
308
308
|
return splitSignature(signatureHex);
|
|
309
309
|
}
|
|
310
|
+
async function signUserPortfolioMargin(args) {
|
|
311
|
+
const { wallet, action } = args;
|
|
312
|
+
const domain = {
|
|
313
|
+
name: "HyperliquidSignTransaction",
|
|
314
|
+
version: "1",
|
|
315
|
+
chainId: Number.parseInt(action.signatureChainId, 16),
|
|
316
|
+
verifyingContract: ZERO_ADDRESS
|
|
317
|
+
};
|
|
318
|
+
const message = {
|
|
319
|
+
enabled: action.enabled,
|
|
320
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
321
|
+
user: action.user,
|
|
322
|
+
nonce: BigInt(action.nonce)
|
|
323
|
+
};
|
|
324
|
+
const types = {
|
|
325
|
+
"HyperliquidTransaction:UserPortfolioMargin": [
|
|
326
|
+
{ name: "enabled", type: "bool" },
|
|
327
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
328
|
+
{ name: "user", type: "address" },
|
|
329
|
+
{ name: "nonce", type: "uint64" }
|
|
330
|
+
]
|
|
331
|
+
};
|
|
332
|
+
const signatureHex = await wallet.walletClient.signTypedData({
|
|
333
|
+
account: wallet.account,
|
|
334
|
+
domain,
|
|
335
|
+
types,
|
|
336
|
+
primaryType: "HyperliquidTransaction:UserPortfolioMargin",
|
|
337
|
+
message
|
|
338
|
+
});
|
|
339
|
+
return splitSignature(signatureHex);
|
|
340
|
+
}
|
|
310
341
|
function splitSignature(signature) {
|
|
311
342
|
const cleaned = signature.slice(2);
|
|
312
343
|
const rHex = `0x${cleaned.slice(0, 64)}`;
|
|
@@ -375,6 +406,181 @@ function assertPositiveNumber(value, label) {
|
|
|
375
406
|
}
|
|
376
407
|
}
|
|
377
408
|
|
|
409
|
+
// src/adapters/hyperliquid/info.ts
|
|
410
|
+
async function postInfo(environment, payload) {
|
|
411
|
+
const baseUrl = API_BASES[environment];
|
|
412
|
+
const response = await fetch(`${baseUrl}/info`, {
|
|
413
|
+
method: "POST",
|
|
414
|
+
headers: { "content-type": "application/json" },
|
|
415
|
+
body: JSON.stringify(payload)
|
|
416
|
+
});
|
|
417
|
+
const data = await response.json().catch(() => null);
|
|
418
|
+
if (!response.ok) {
|
|
419
|
+
throw new HyperliquidApiError(
|
|
420
|
+
"Hyperliquid info request failed.",
|
|
421
|
+
data ?? { status: response.status }
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
return data;
|
|
425
|
+
}
|
|
426
|
+
var HyperliquidInfoClient = class {
|
|
427
|
+
constructor(environment = "mainnet") {
|
|
428
|
+
this.environment = environment;
|
|
429
|
+
}
|
|
430
|
+
meta() {
|
|
431
|
+
return fetchHyperliquidMeta(this.environment);
|
|
432
|
+
}
|
|
433
|
+
metaAndAssetCtxs() {
|
|
434
|
+
return fetchHyperliquidMetaAndAssetCtxs(this.environment);
|
|
435
|
+
}
|
|
436
|
+
spotMeta() {
|
|
437
|
+
return fetchHyperliquidSpotMeta(this.environment);
|
|
438
|
+
}
|
|
439
|
+
spotMetaAndAssetCtxs() {
|
|
440
|
+
return fetchHyperliquidSpotMetaAndAssetCtxs(this.environment);
|
|
441
|
+
}
|
|
442
|
+
assetCtxs() {
|
|
443
|
+
return fetchHyperliquidAssetCtxs(this.environment);
|
|
444
|
+
}
|
|
445
|
+
spotAssetCtxs() {
|
|
446
|
+
return fetchHyperliquidSpotAssetCtxs(this.environment);
|
|
447
|
+
}
|
|
448
|
+
openOrders(user) {
|
|
449
|
+
return fetchHyperliquidOpenOrders({ user, environment: this.environment });
|
|
450
|
+
}
|
|
451
|
+
frontendOpenOrders(user) {
|
|
452
|
+
return fetchHyperliquidFrontendOpenOrders({
|
|
453
|
+
user,
|
|
454
|
+
environment: this.environment
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
orderStatus(user, oid) {
|
|
458
|
+
return fetchHyperliquidOrderStatus({
|
|
459
|
+
user,
|
|
460
|
+
oid,
|
|
461
|
+
environment: this.environment
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
historicalOrders(user) {
|
|
465
|
+
return fetchHyperliquidHistoricalOrders({
|
|
466
|
+
user,
|
|
467
|
+
environment: this.environment
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
userFills(user) {
|
|
471
|
+
return fetchHyperliquidUserFills({ user, environment: this.environment });
|
|
472
|
+
}
|
|
473
|
+
userFillsByTime(user, startTime, endTime) {
|
|
474
|
+
return fetchHyperliquidUserFillsByTime({
|
|
475
|
+
user,
|
|
476
|
+
startTime,
|
|
477
|
+
endTime,
|
|
478
|
+
environment: this.environment
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
userRateLimit(user) {
|
|
482
|
+
return fetchHyperliquidUserRateLimit({
|
|
483
|
+
user,
|
|
484
|
+
environment: this.environment
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
preTransferCheck(user, source) {
|
|
488
|
+
return fetchHyperliquidPreTransferCheck({
|
|
489
|
+
user,
|
|
490
|
+
source,
|
|
491
|
+
environment: this.environment
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
spotClearinghouseState(user) {
|
|
495
|
+
return fetchHyperliquidSpotClearinghouseState({
|
|
496
|
+
user,
|
|
497
|
+
environment: this.environment
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
async function fetchHyperliquidMeta(environment = "mainnet") {
|
|
502
|
+
return postInfo(environment, { type: "meta" });
|
|
503
|
+
}
|
|
504
|
+
async function fetchHyperliquidMetaAndAssetCtxs(environment = "mainnet") {
|
|
505
|
+
return postInfo(environment, { type: "metaAndAssetCtxs" });
|
|
506
|
+
}
|
|
507
|
+
async function fetchHyperliquidSpotMeta(environment = "mainnet") {
|
|
508
|
+
return postInfo(environment, { type: "spotMeta" });
|
|
509
|
+
}
|
|
510
|
+
async function fetchHyperliquidSpotMetaAndAssetCtxs(environment = "mainnet") {
|
|
511
|
+
return postInfo(environment, { type: "spotMetaAndAssetCtxs" });
|
|
512
|
+
}
|
|
513
|
+
async function fetchHyperliquidAssetCtxs(environment = "mainnet") {
|
|
514
|
+
return postInfo(environment, { type: "assetCtxs" });
|
|
515
|
+
}
|
|
516
|
+
async function fetchHyperliquidSpotAssetCtxs(environment = "mainnet") {
|
|
517
|
+
return postInfo(environment, { type: "spotAssetCtxs" });
|
|
518
|
+
}
|
|
519
|
+
async function fetchHyperliquidOpenOrders(params) {
|
|
520
|
+
const env = params.environment ?? "mainnet";
|
|
521
|
+
return postInfo(env, { type: "openOrders", user: normalizeAddress(params.user) });
|
|
522
|
+
}
|
|
523
|
+
async function fetchHyperliquidFrontendOpenOrders(params) {
|
|
524
|
+
const env = params.environment ?? "mainnet";
|
|
525
|
+
return postInfo(env, {
|
|
526
|
+
type: "frontendOpenOrders",
|
|
527
|
+
user: normalizeAddress(params.user)
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
async function fetchHyperliquidOrderStatus(params) {
|
|
531
|
+
const env = params.environment ?? "mainnet";
|
|
532
|
+
return postInfo(env, {
|
|
533
|
+
type: "orderStatus",
|
|
534
|
+
user: normalizeAddress(params.user),
|
|
535
|
+
oid: params.oid
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
async function fetchHyperliquidHistoricalOrders(params) {
|
|
539
|
+
const env = params.environment ?? "mainnet";
|
|
540
|
+
return postInfo(env, {
|
|
541
|
+
type: "historicalOrders",
|
|
542
|
+
user: normalizeAddress(params.user)
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
async function fetchHyperliquidUserFills(params) {
|
|
546
|
+
const env = params.environment ?? "mainnet";
|
|
547
|
+
return postInfo(env, {
|
|
548
|
+
type: "userFills",
|
|
549
|
+
user: normalizeAddress(params.user)
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
async function fetchHyperliquidUserFillsByTime(params) {
|
|
553
|
+
const env = params.environment ?? "mainnet";
|
|
554
|
+
return postInfo(env, {
|
|
555
|
+
type: "userFillsByTime",
|
|
556
|
+
user: normalizeAddress(params.user),
|
|
557
|
+
startTime: params.startTime,
|
|
558
|
+
endTime: params.endTime
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
async function fetchHyperliquidUserRateLimit(params) {
|
|
562
|
+
const env = params.environment ?? "mainnet";
|
|
563
|
+
return postInfo(env, {
|
|
564
|
+
type: "userRateLimit",
|
|
565
|
+
user: normalizeAddress(params.user)
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
async function fetchHyperliquidPreTransferCheck(params) {
|
|
569
|
+
const env = params.environment ?? "mainnet";
|
|
570
|
+
return postInfo(env, {
|
|
571
|
+
type: "preTransferCheck",
|
|
572
|
+
user: normalizeAddress(params.user),
|
|
573
|
+
source: normalizeAddress(params.source)
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
async function fetchHyperliquidSpotClearinghouseState(params) {
|
|
577
|
+
const env = params.environment ?? "mainnet";
|
|
578
|
+
return postInfo(env, {
|
|
579
|
+
type: "spotClearinghouseState",
|
|
580
|
+
user: normalizeAddress(params.user)
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
378
584
|
// src/adapters/hyperliquid/exchange.ts
|
|
379
585
|
var HyperliquidExchangeClient = class {
|
|
380
586
|
constructor(args) {
|
|
@@ -507,7 +713,58 @@ var HyperliquidExchangeClient = class {
|
|
|
507
713
|
...params
|
|
508
714
|
});
|
|
509
715
|
}
|
|
716
|
+
setPortfolioMargin(params) {
|
|
717
|
+
const base = {
|
|
718
|
+
wallet: this.wallet,
|
|
719
|
+
enabled: params.enabled,
|
|
720
|
+
environment: this.environment,
|
|
721
|
+
vaultAddress: this.vaultAddress,
|
|
722
|
+
expiresAfter: this.expiresAfter,
|
|
723
|
+
nonceSource: this.nonceSource
|
|
724
|
+
};
|
|
725
|
+
return setHyperliquidPortfolioMargin(
|
|
726
|
+
params.user ? { ...base, user: params.user } : base
|
|
727
|
+
);
|
|
728
|
+
}
|
|
510
729
|
};
|
|
730
|
+
async function setHyperliquidPortfolioMargin(options) {
|
|
731
|
+
const env = options.environment ?? "mainnet";
|
|
732
|
+
if (!options.wallet?.account || !options.wallet.walletClient) {
|
|
733
|
+
throw new Error(
|
|
734
|
+
"Wallet with signing capability is required for portfolio margin."
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
const nonce = options.nonce ?? options.walletNonceProvider?.() ?? options.wallet.nonceSource?.() ?? options.nonceSource?.() ?? Date.now();
|
|
738
|
+
const signatureChainId = getSignatureChainId(env);
|
|
739
|
+
const hyperliquidChain = HL_CHAIN_LABEL[env];
|
|
740
|
+
const user = normalizeAddress(
|
|
741
|
+
options.user ?? options.wallet.address
|
|
742
|
+
);
|
|
743
|
+
const action = {
|
|
744
|
+
type: "userPortfolioMargin",
|
|
745
|
+
enabled: Boolean(options.enabled),
|
|
746
|
+
hyperliquidChain,
|
|
747
|
+
signatureChainId,
|
|
748
|
+
user,
|
|
749
|
+
nonce
|
|
750
|
+
};
|
|
751
|
+
const signature = await signUserPortfolioMargin({
|
|
752
|
+
wallet: options.wallet,
|
|
753
|
+
action
|
|
754
|
+
});
|
|
755
|
+
const body = {
|
|
756
|
+
action,
|
|
757
|
+
nonce,
|
|
758
|
+
signature
|
|
759
|
+
};
|
|
760
|
+
if (options.vaultAddress) {
|
|
761
|
+
body.vaultAddress = normalizeAddress(options.vaultAddress);
|
|
762
|
+
}
|
|
763
|
+
if (typeof options.expiresAfter === "number") {
|
|
764
|
+
body.expiresAfter = options.expiresAfter;
|
|
765
|
+
}
|
|
766
|
+
return postExchange(env, body);
|
|
767
|
+
}
|
|
511
768
|
async function cancelHyperliquidOrders(options) {
|
|
512
769
|
options.cancels.forEach((c) => assertSymbol(c.symbol));
|
|
513
770
|
const action = {
|
|
@@ -830,192 +1087,37 @@ async function postExchange(env, body) {
|
|
|
830
1087
|
headers: { "content-type": "application/json" },
|
|
831
1088
|
body: JSON.stringify(body)
|
|
832
1089
|
});
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
return json;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// src/adapters/hyperliquid/info.ts
|
|
847
|
-
async function postInfo(environment, payload) {
|
|
848
|
-
const baseUrl = API_BASES[environment];
|
|
849
|
-
const response = await fetch(`${baseUrl}/info`, {
|
|
850
|
-
method: "POST",
|
|
851
|
-
headers: { "content-type": "application/json" },
|
|
852
|
-
body: JSON.stringify(payload)
|
|
853
|
-
});
|
|
854
|
-
const data = await response.json().catch(() => null);
|
|
1090
|
+
const text = await response.text().catch(() => "");
|
|
1091
|
+
const json = (() => {
|
|
1092
|
+
if (!text) return null;
|
|
1093
|
+
try {
|
|
1094
|
+
return JSON.parse(text);
|
|
1095
|
+
} catch {
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
})();
|
|
855
1099
|
if (!response.ok) {
|
|
856
|
-
throw new HyperliquidApiError(
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
return data;
|
|
862
|
-
}
|
|
863
|
-
var HyperliquidInfoClient = class {
|
|
864
|
-
constructor(environment = "mainnet") {
|
|
865
|
-
this.environment = environment;
|
|
866
|
-
}
|
|
867
|
-
meta() {
|
|
868
|
-
return fetchHyperliquidMeta(this.environment);
|
|
869
|
-
}
|
|
870
|
-
metaAndAssetCtxs() {
|
|
871
|
-
return fetchHyperliquidMetaAndAssetCtxs(this.environment);
|
|
872
|
-
}
|
|
873
|
-
spotMeta() {
|
|
874
|
-
return fetchHyperliquidSpotMeta(this.environment);
|
|
875
|
-
}
|
|
876
|
-
spotMetaAndAssetCtxs() {
|
|
877
|
-
return fetchHyperliquidSpotMetaAndAssetCtxs(this.environment);
|
|
878
|
-
}
|
|
879
|
-
assetCtxs() {
|
|
880
|
-
return fetchHyperliquidAssetCtxs(this.environment);
|
|
881
|
-
}
|
|
882
|
-
spotAssetCtxs() {
|
|
883
|
-
return fetchHyperliquidSpotAssetCtxs(this.environment);
|
|
884
|
-
}
|
|
885
|
-
openOrders(user) {
|
|
886
|
-
return fetchHyperliquidOpenOrders({ user, environment: this.environment });
|
|
887
|
-
}
|
|
888
|
-
frontendOpenOrders(user) {
|
|
889
|
-
return fetchHyperliquidFrontendOpenOrders({
|
|
890
|
-
user,
|
|
891
|
-
environment: this.environment
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
orderStatus(user, oid) {
|
|
895
|
-
return fetchHyperliquidOrderStatus({
|
|
896
|
-
user,
|
|
897
|
-
oid,
|
|
898
|
-
environment: this.environment
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
historicalOrders(user) {
|
|
902
|
-
return fetchHyperliquidHistoricalOrders({
|
|
903
|
-
user,
|
|
904
|
-
environment: this.environment
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
userFills(user) {
|
|
908
|
-
return fetchHyperliquidUserFills({ user, environment: this.environment });
|
|
909
|
-
}
|
|
910
|
-
userFillsByTime(user, startTime, endTime) {
|
|
911
|
-
return fetchHyperliquidUserFillsByTime({
|
|
912
|
-
user,
|
|
913
|
-
startTime,
|
|
914
|
-
endTime,
|
|
915
|
-
environment: this.environment
|
|
1100
|
+
throw new HyperliquidApiError("Hyperliquid exchange action failed.", {
|
|
1101
|
+
status: response.status,
|
|
1102
|
+
statusText: response.statusText,
|
|
1103
|
+
body: json ?? (text ? text : null)
|
|
916
1104
|
});
|
|
917
1105
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
}
|
|
924
|
-
preTransferCheck(user, source) {
|
|
925
|
-
return fetchHyperliquidPreTransferCheck({
|
|
926
|
-
user,
|
|
927
|
-
source,
|
|
928
|
-
environment: this.environment
|
|
1106
|
+
if (!json) {
|
|
1107
|
+
throw new HyperliquidApiError("Hyperliquid exchange action failed.", {
|
|
1108
|
+
status: response.status,
|
|
1109
|
+
statusText: response.statusText,
|
|
1110
|
+
body: text ? text : null
|
|
929
1111
|
});
|
|
930
1112
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
1113
|
+
if (json.status !== "ok") {
|
|
1114
|
+
throw new HyperliquidApiError("Hyperliquid exchange returned error.", {
|
|
1115
|
+
status: response.status,
|
|
1116
|
+
statusText: response.statusText,
|
|
1117
|
+
body: json
|
|
935
1118
|
});
|
|
936
1119
|
}
|
|
937
|
-
|
|
938
|
-
async function fetchHyperliquidMeta(environment = "mainnet") {
|
|
939
|
-
return postInfo(environment, { type: "meta" });
|
|
940
|
-
}
|
|
941
|
-
async function fetchHyperliquidMetaAndAssetCtxs(environment = "mainnet") {
|
|
942
|
-
return postInfo(environment, { type: "metaAndAssetCtxs" });
|
|
943
|
-
}
|
|
944
|
-
async function fetchHyperliquidSpotMeta(environment = "mainnet") {
|
|
945
|
-
return postInfo(environment, { type: "spotMeta" });
|
|
946
|
-
}
|
|
947
|
-
async function fetchHyperliquidSpotMetaAndAssetCtxs(environment = "mainnet") {
|
|
948
|
-
return postInfo(environment, { type: "spotMetaAndAssetCtxs" });
|
|
949
|
-
}
|
|
950
|
-
async function fetchHyperliquidAssetCtxs(environment = "mainnet") {
|
|
951
|
-
return postInfo(environment, { type: "assetCtxs" });
|
|
952
|
-
}
|
|
953
|
-
async function fetchHyperliquidSpotAssetCtxs(environment = "mainnet") {
|
|
954
|
-
return postInfo(environment, { type: "spotAssetCtxs" });
|
|
955
|
-
}
|
|
956
|
-
async function fetchHyperliquidOpenOrders(params) {
|
|
957
|
-
const env = params.environment ?? "mainnet";
|
|
958
|
-
return postInfo(env, { type: "openOrders", user: normalizeAddress(params.user) });
|
|
959
|
-
}
|
|
960
|
-
async function fetchHyperliquidFrontendOpenOrders(params) {
|
|
961
|
-
const env = params.environment ?? "mainnet";
|
|
962
|
-
return postInfo(env, {
|
|
963
|
-
type: "frontendOpenOrders",
|
|
964
|
-
user: normalizeAddress(params.user)
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
async function fetchHyperliquidOrderStatus(params) {
|
|
968
|
-
const env = params.environment ?? "mainnet";
|
|
969
|
-
return postInfo(env, {
|
|
970
|
-
type: "orderStatus",
|
|
971
|
-
user: normalizeAddress(params.user),
|
|
972
|
-
oid: params.oid
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
async function fetchHyperliquidHistoricalOrders(params) {
|
|
976
|
-
const env = params.environment ?? "mainnet";
|
|
977
|
-
return postInfo(env, {
|
|
978
|
-
type: "historicalOrders",
|
|
979
|
-
user: normalizeAddress(params.user)
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
async function fetchHyperliquidUserFills(params) {
|
|
983
|
-
const env = params.environment ?? "mainnet";
|
|
984
|
-
return postInfo(env, {
|
|
985
|
-
type: "userFills",
|
|
986
|
-
user: normalizeAddress(params.user)
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
async function fetchHyperliquidUserFillsByTime(params) {
|
|
990
|
-
const env = params.environment ?? "mainnet";
|
|
991
|
-
return postInfo(env, {
|
|
992
|
-
type: "userFillsByTime",
|
|
993
|
-
user: normalizeAddress(params.user),
|
|
994
|
-
startTime: params.startTime,
|
|
995
|
-
endTime: params.endTime
|
|
996
|
-
});
|
|
997
|
-
}
|
|
998
|
-
async function fetchHyperliquidUserRateLimit(params) {
|
|
999
|
-
const env = params.environment ?? "mainnet";
|
|
1000
|
-
return postInfo(env, {
|
|
1001
|
-
type: "userRateLimit",
|
|
1002
|
-
user: normalizeAddress(params.user)
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
async function fetchHyperliquidPreTransferCheck(params) {
|
|
1006
|
-
const env = params.environment ?? "mainnet";
|
|
1007
|
-
return postInfo(env, {
|
|
1008
|
-
type: "preTransferCheck",
|
|
1009
|
-
user: normalizeAddress(params.user),
|
|
1010
|
-
source: normalizeAddress(params.source)
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
async function fetchHyperliquidSpotClearinghouseState(params) {
|
|
1014
|
-
const env = params.environment ?? "mainnet";
|
|
1015
|
-
return postInfo(env, {
|
|
1016
|
-
type: "spotClearinghouseState",
|
|
1017
|
-
user: normalizeAddress(params.user)
|
|
1018
|
-
});
|
|
1120
|
+
return json;
|
|
1019
1121
|
}
|
|
1020
1122
|
|
|
1021
1123
|
// src/adapters/hyperliquid/index.ts
|
|
@@ -1406,6 +1508,6 @@ var __hyperliquidInternals = {
|
|
|
1406
1508
|
splitSignature
|
|
1407
1509
|
};
|
|
1408
1510
|
|
|
1409
|
-
export { HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, __hyperliquidInternals, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, cancelAllHyperliquidOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, createHyperliquidSubAccount, createMonotonicNonceFactory, depositToHyperliquidBridge, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, getHyperliquidMaxBuilderFee, modifyHyperliquidOrder, placeHyperliquidOrder, placeHyperliquidTwapOrder, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, reserveHyperliquidRequestWeight, scheduleHyperliquidCancel, sendHyperliquidSpot, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, withdrawFromHyperliquid };
|
|
1511
|
+
export { HyperliquidApiError, HyperliquidBuilderApprovalError, HyperliquidExchangeClient, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidTermsError, __hyperliquidInternals, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, cancelAllHyperliquidOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, createHyperliquidSubAccount, createMonotonicNonceFactory, depositToHyperliquidBridge, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, getHyperliquidMaxBuilderFee, modifyHyperliquidOrder, placeHyperliquidOrder, placeHyperliquidTwapOrder, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, reserveHyperliquidRequestWeight, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidPortfolioMargin, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, withdrawFromHyperliquid };
|
|
1410
1512
|
//# sourceMappingURL=index.js.map
|
|
1411
1513
|
//# sourceMappingURL=index.js.map
|