@pear-protocol/exchanges-sdk 0.17.0 → 0.18.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/README.md +30 -0
- package/dist/client/lighter/rest.js +12 -1
- package/dist/helper/hyperliquid/helper.js +64 -3
- package/dist/helper/index.js +2 -0
- package/dist/helper/lighter/helper.js +39 -15
- package/dist/helper/lighter/subaccount.helper.js +118 -0
- package/dist/helper/subaccount.types.js +1 -0
- package/dist/index.d.ts +269 -49
- package/dist/sdk.js +28 -6
- package/dist/status/hyperliquid/status.js +3 -3
- package/dist/syncer/base.js +1 -21
- package/dist/syncer/hyperliquid/syncer.js +2 -1
- package/dist/syncer/lighter/syncer.js +4 -4
- package/dist/tracker/base.js +4 -0
- package/dist/tracker/equity.js +13 -0
- package/dist/tracker/hyperliquid/balance.js +29 -5
- package/dist/tracker/hyperliquid/decimal.js +5 -1
- package/dist/tracker/hyperliquid/mapper.js +69 -1
- package/dist/tracker/hyperliquid/tracker.js +52 -24
- package/dist/tracker/index.js +24 -1
- package/dist/tracker/lighter/mapper.js +20 -1
- package/dist/tracker/lighter/tracker.js +29 -14
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { HttpTypes, Connector, BinanceCredentialsDTO, BybitCredentialsDTO, OkxCr
|
|
|
2
2
|
import PearSDK from '@pear-protocol/core-sdk';
|
|
3
3
|
import { ProxyConfig } from '@pear-protocol/utils';
|
|
4
4
|
import { WebSocket } from 'partysocket';
|
|
5
|
+
import { AbstractWallet } from '@nktkas/hyperliquid/signing';
|
|
5
6
|
import { WalletClient, Transport, Chain, Account } from 'viem';
|
|
6
7
|
import { z } from 'zod';
|
|
7
8
|
|
|
@@ -245,41 +246,6 @@ declare class OkxExchangeWs extends ExchangeWs {
|
|
|
245
246
|
}): Promise<OkxExchangeWs>;
|
|
246
247
|
}
|
|
247
248
|
|
|
248
|
-
type ExchangeWsByConnector = {
|
|
249
|
-
binance: BinanceExchangeWs;
|
|
250
|
-
bybit: BybitExchangeWs;
|
|
251
|
-
okx: OkxExchangeWs;
|
|
252
|
-
hyperliquid: HyperliquidExchangeWs;
|
|
253
|
-
lighter: LighterExchangeWs;
|
|
254
|
-
lighter_rhc: LighterExchangeWs;
|
|
255
|
-
};
|
|
256
|
-
/**
|
|
257
|
-
* Hyperliquid's account channels are public, so its socket needs no credentials; every other venue
|
|
258
|
-
* still requires them. The tuple keeps the check whole, so a connector not known to be Hyperliquid
|
|
259
|
-
* (a `Connector` union) still requires them too.
|
|
260
|
-
*/
|
|
261
|
-
type CreateExchangeWsConfig<E extends Connector = Connector> = {
|
|
262
|
-
demo: boolean;
|
|
263
|
-
} & ([E] extends ['hyperliquid'] ? {
|
|
264
|
-
credentials?: SupportedCredentials;
|
|
265
|
-
} : {
|
|
266
|
-
credentials: SupportedCredentials;
|
|
267
|
-
});
|
|
268
|
-
declare function createExchangeWs<E extends Connector>(exchange: E, config: CreateExchangeWsConfig<E>): Promise<ExchangeWsByConnector[E]>;
|
|
269
|
-
|
|
270
|
-
interface HyperliquidHelper {
|
|
271
|
-
checkAccountActivation(userAddress: `0x${string}`): Promise<boolean>;
|
|
272
|
-
checkApiWallet(params: CheckApiWalletParams): Promise<boolean>;
|
|
273
|
-
checkBuilderFeeApproval(userAddress: `0x${string}`, builderAddress: `0x${string}`, requiredFeeTenthsBps?: number): Promise<boolean>;
|
|
274
|
-
}
|
|
275
|
-
type CheckApiWalletParams = {
|
|
276
|
-
userAddress: `0x${string}`;
|
|
277
|
-
agentWalletAddress: `0x${string}`;
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
/** Creates Hyperliquid approval checks for the selected network. */
|
|
281
|
-
declare function createHyperliquidHelper(demo?: boolean): HyperliquidHelper;
|
|
282
|
-
|
|
283
249
|
type LighterRawTrade = {
|
|
284
250
|
trade_id: number;
|
|
285
251
|
trade_id_str?: string;
|
|
@@ -311,6 +277,12 @@ type ApiKey = {
|
|
|
311
277
|
public_key: string;
|
|
312
278
|
transaction_time: number;
|
|
313
279
|
};
|
|
280
|
+
type LighterAccountMetadata = {
|
|
281
|
+
account_index: number;
|
|
282
|
+
name: string;
|
|
283
|
+
description: string;
|
|
284
|
+
created_at: number;
|
|
285
|
+
};
|
|
314
286
|
/**
|
|
315
287
|
* The three account tiers Lighter offers, spelled the way the venue spells them.
|
|
316
288
|
*
|
|
@@ -430,6 +402,62 @@ type LighterUserReferrals = {
|
|
|
430
402
|
nextCursor: string | null;
|
|
431
403
|
};
|
|
432
404
|
|
|
405
|
+
type ExchangeWsByConnector = {
|
|
406
|
+
binance: BinanceExchangeWs;
|
|
407
|
+
bybit: BybitExchangeWs;
|
|
408
|
+
okx: OkxExchangeWs;
|
|
409
|
+
hyperliquid: HyperliquidExchangeWs;
|
|
410
|
+
lighter: LighterExchangeWs;
|
|
411
|
+
lighter_rhc: LighterExchangeWs;
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Hyperliquid's account channels are public, so its socket needs no credentials; every other venue
|
|
415
|
+
* still requires them. The tuple keeps the check whole, so a connector not known to be Hyperliquid
|
|
416
|
+
* (a `Connector` union) still requires them too.
|
|
417
|
+
*/
|
|
418
|
+
type CreateExchangeWsConfig<E extends Connector = Connector> = {
|
|
419
|
+
demo: boolean;
|
|
420
|
+
} & ([E] extends ['hyperliquid'] ? {
|
|
421
|
+
credentials?: SupportedCredentials;
|
|
422
|
+
} : {
|
|
423
|
+
credentials: SupportedCredentials;
|
|
424
|
+
});
|
|
425
|
+
declare function createExchangeWs<E extends Connector>(exchange: E, config: CreateExchangeWsConfig<E>): Promise<ExchangeWsByConnector[E]>;
|
|
426
|
+
|
|
427
|
+
type SubAccountTransferDirection = 'main-to-subaccount' | 'subaccount-to-main';
|
|
428
|
+
|
|
429
|
+
interface HyperliquidHelper {
|
|
430
|
+
checkAccountActivation(userAddress: `0x${string}`): Promise<boolean>;
|
|
431
|
+
createSubAccount(wallet: AbstractWallet, params: CreateHyperliquidSubAccountParams): Promise<CreateHyperliquidSubAccountResult>;
|
|
432
|
+
transferSubAccount(wallet: AbstractWallet, params: HyperliquidSubAccountTransferParams): Promise<void>;
|
|
433
|
+
listSubAccounts(userAddress: `0x${string}`): Promise<HyperliquidSubAccountSummary[]>;
|
|
434
|
+
checkApiWallet(params: CheckApiWalletParams): Promise<boolean>;
|
|
435
|
+
checkBuilderFeeApproval(userAddress: `0x${string}`, builderAddress: `0x${string}`, requiredFeeTenthsBps?: number): Promise<boolean>;
|
|
436
|
+
}
|
|
437
|
+
type CreateHyperliquidSubAccountParams = {
|
|
438
|
+
name: string;
|
|
439
|
+
};
|
|
440
|
+
type CreateHyperliquidSubAccountResult = {
|
|
441
|
+
subAccountAddress: `0x${string}`;
|
|
442
|
+
};
|
|
443
|
+
type HyperliquidSubAccountTransferParams = {
|
|
444
|
+
subAccountAddress: `0x${string}`;
|
|
445
|
+
direction: SubAccountTransferDirection;
|
|
446
|
+
/** Positive human-readable USDC amount with at most six fractional digits. */
|
|
447
|
+
amount: string;
|
|
448
|
+
};
|
|
449
|
+
type HyperliquidSubAccountSummary = {
|
|
450
|
+
name: string;
|
|
451
|
+
subAccountUser: `0x${string}`;
|
|
452
|
+
};
|
|
453
|
+
type CheckApiWalletParams = {
|
|
454
|
+
userAddress: `0x${string}`;
|
|
455
|
+
agentWalletAddress: `0x${string}`;
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
/** Creates Hyperliquid account-management helpers for the selected network. */
|
|
459
|
+
declare function createHyperliquidHelper(demo?: boolean): HyperliquidHelper;
|
|
460
|
+
|
|
433
461
|
/** Shares one live Lighter auth token per account without crossing rotated credentials. */
|
|
434
462
|
|
|
435
463
|
type LighterAuthCredentials = {
|
|
@@ -555,6 +583,53 @@ declare function getAssetDecimals(assetId: number): number;
|
|
|
555
583
|
type ConnectWalletParams = {
|
|
556
584
|
accountIndex: number;
|
|
557
585
|
};
|
|
586
|
+
type CreateLighterSubAccountParams = {
|
|
587
|
+
mainAccountIndex: number;
|
|
588
|
+
/** API key index registered on `mainAccountIndex`. */
|
|
589
|
+
apiKeyIndex: number;
|
|
590
|
+
/** API private key registered on `mainAccountIndex`. */
|
|
591
|
+
apiPrivateKey: string;
|
|
592
|
+
};
|
|
593
|
+
type CreateLighterSubAccountResult = {
|
|
594
|
+
txHash: string;
|
|
595
|
+
};
|
|
596
|
+
/** Creates, discovers, and names a subaccount owned by this L1 address. */
|
|
597
|
+
type CreateNamedLighterSubAccountParams = CreateLighterSubAccountParams & {
|
|
598
|
+
l1Address: string;
|
|
599
|
+
name: string;
|
|
600
|
+
description?: string;
|
|
601
|
+
};
|
|
602
|
+
/** Creation completes after the indexed subaccount receives its display metadata. */
|
|
603
|
+
type CreateNamedLighterSubAccountResult = CreateLighterSubAccountResult & {
|
|
604
|
+
subAccountIndex: number;
|
|
605
|
+
};
|
|
606
|
+
type SetLighterSubAccountMetadataParams = {
|
|
607
|
+
mainAccountIndex: number;
|
|
608
|
+
subAccountIndex: number;
|
|
609
|
+
/** Display name shown by Lighter for the target subaccount. */
|
|
610
|
+
name: string;
|
|
611
|
+
description?: string;
|
|
612
|
+
/** API key index registered on `mainAccountIndex`. */
|
|
613
|
+
apiKeyIndex: number;
|
|
614
|
+
/** API private key registered on `mainAccountIndex`. */
|
|
615
|
+
apiPrivateKey: string;
|
|
616
|
+
};
|
|
617
|
+
type LighterSubAccountTransferParams = {
|
|
618
|
+
/** L1 address that owns both accounts; Core refuses the transfer unless Lighter agrees. */
|
|
619
|
+
l1Address: string;
|
|
620
|
+
mainAccountIndex: number;
|
|
621
|
+
subAccountIndex: number;
|
|
622
|
+
direction: SubAccountTransferDirection;
|
|
623
|
+
/** Positive human-readable collateral amount (USDC on Lighter, USDG on RHC) with at most six fractional digits. */
|
|
624
|
+
amount: string;
|
|
625
|
+
/** API key index registered on the source account selected by `direction`. */
|
|
626
|
+
apiKeyIndex: number;
|
|
627
|
+
/** API private key registered on the source account selected by `direction`. */
|
|
628
|
+
apiPrivateKey: string;
|
|
629
|
+
};
|
|
630
|
+
type LighterSubAccountTransferResult = {
|
|
631
|
+
txHash: string;
|
|
632
|
+
};
|
|
558
633
|
/** The Lighter book a Fun.xyz deposit funds. */
|
|
559
634
|
type FunxyzMarket = 'perps' | 'spot';
|
|
560
635
|
/** What a Fun.xyz deposit is denominated in at its source. Fun.xyz converts ETH to USDC on arrival. */
|
|
@@ -986,8 +1061,13 @@ type LighterUserReferralsParams = {
|
|
|
986
1061
|
interface LighterHelper {
|
|
987
1062
|
checkOnboarding(l1Address: string): Promise<LighterOnboardingStatus>;
|
|
988
1063
|
lookupAccount(l1Address: string): Promise<LighterLookupResult>;
|
|
1064
|
+
fetchAccountMetadata(params: FetchLighterAccountMetadataParams): Promise<FetchLighterAccountMetadataResult>;
|
|
989
1065
|
checkIntegratorApproval(accountIndex: number, integratorAccountIndex: number, requirements?: IntegratorApprovalRequirements, authToken?: string): Promise<boolean>;
|
|
990
1066
|
connectWallet(walletClient: WalletClientWithAccount, params: ConnectWalletParams): Promise<ConnectWalletResult>;
|
|
1067
|
+
createSubAccount(params: CreateLighterSubAccountParams): Promise<CreateLighterSubAccountResult>;
|
|
1068
|
+
createNamedSubAccount(params: CreateNamedLighterSubAccountParams): Promise<CreateNamedLighterSubAccountResult>;
|
|
1069
|
+
setSubAccountMetadata(params: SetLighterSubAccountMetadataParams): Promise<void>;
|
|
1070
|
+
transferSubAccount(params: LighterSubAccountTransferParams): Promise<LighterSubAccountTransferResult>;
|
|
991
1071
|
approveIntegrator(walletClient: WalletClientWithAccount, params: ApproveIntegratorParams): Promise<ApproveIntegratorResult>;
|
|
992
1072
|
changeAccountTier(params: ChangeAccountTierParams): Promise<ChangeAccountTierResult>;
|
|
993
1073
|
listCctpDepositNetworks(): Promise<LighterDepositNetwork[]>;
|
|
@@ -1044,6 +1124,17 @@ type LighterLookupResult = {
|
|
|
1044
1124
|
mainAccountIndex: number;
|
|
1045
1125
|
subAccountIndexes: number[];
|
|
1046
1126
|
};
|
|
1127
|
+
type FetchLighterAccountMetadataParams = {
|
|
1128
|
+
l1Address: string;
|
|
1129
|
+
/** Account whose API key authenticates the lookup; its own family is returned. */
|
|
1130
|
+
accountIndex: number;
|
|
1131
|
+
apiKeyIndex: number;
|
|
1132
|
+
apiPrivateKey: string;
|
|
1133
|
+
};
|
|
1134
|
+
type FetchLighterAccountMetadataResult = {
|
|
1135
|
+
/** Full Lighter account metadata (name, description, created_at, …) by account index. */
|
|
1136
|
+
accounts: Record<number, LighterAccountMetadata>;
|
|
1137
|
+
};
|
|
1047
1138
|
|
|
1048
1139
|
/**
|
|
1049
1140
|
* Functional Lighter deposit operations that route through the Fun.xyz bridge.
|
|
@@ -1075,6 +1166,7 @@ declare function readFunxyzChainSource(chainId: number): FunxyzDepositSource;
|
|
|
1075
1166
|
declare const MIN_USER_API_KEY_INDEX = 4;
|
|
1076
1167
|
declare const MAX_API_KEY_INDEX = 254;
|
|
1077
1168
|
declare function findAvailableApiKeyIndex(apiKeys: ReadonlyArray<Pick<ApiKey, 'api_key_index'>>): number;
|
|
1169
|
+
/** Creates Lighter account-management helpers backed by the Pear Core signing boundary. */
|
|
1078
1170
|
declare function createLighterHelper(sdk: PearSDK, demo?: boolean): LighterHelper;
|
|
1079
1171
|
/**
|
|
1080
1172
|
* The helper for Lighter's Robinhood Chain deployment: the shared surface plus its own deposit.
|
|
@@ -1085,6 +1177,15 @@ declare function createLighterHelper(sdk: PearSDK, demo?: boolean): LighterHelpe
|
|
|
1085
1177
|
*/
|
|
1086
1178
|
declare function createLighterRhcHelper(sdk: PearSDK, demo?: boolean): LighterRhcHelper;
|
|
1087
1179
|
|
|
1180
|
+
/**
|
|
1181
|
+
* Converts a human-readable collateral amount to safe six-decimal integer units.
|
|
1182
|
+
*
|
|
1183
|
+
* Every collateral this SDK moves is a six-decimal stablecoin, but the deployments name it
|
|
1184
|
+
* differently — zkLighter margins in USDC, Robinhood Chain in USDG — so the caller names the asset
|
|
1185
|
+
* a rejection should mention. The scaling itself is deployment-blind.
|
|
1186
|
+
*/
|
|
1187
|
+
declare function parseCollateralAmount(amount: string, assetSymbol: string): number;
|
|
1188
|
+
|
|
1088
1189
|
type ExchangeHelperMap = {
|
|
1089
1190
|
hyperliquid: HyperliquidHelper;
|
|
1090
1191
|
lighter: LighterHelper;
|
|
@@ -1296,7 +1397,7 @@ type UserFillsByTimeResponse = {
|
|
|
1296
1397
|
* Address of the liquidated user.
|
|
1297
1398
|
* @pattern ^0x[a-fA-F0-9]{40}$
|
|
1298
1399
|
*/
|
|
1299
|
-
liquidatedUser
|
|
1400
|
+
liquidatedUser?: `0x${string}`;
|
|
1300
1401
|
/**
|
|
1301
1402
|
* Mark price at the time of liquidation.
|
|
1302
1403
|
* @pattern ^[0-9]+(\.[0-9]+)?$
|
|
@@ -1424,6 +1525,13 @@ declare const AccountBalance: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1424
1525
|
crossMaintenanceMargin: z.ZodString;
|
|
1425
1526
|
withdrawable: z.ZodString;
|
|
1426
1527
|
}, z.core.$strip>>;
|
|
1528
|
+
spotHoldings: z.ZodArray<z.ZodObject<{
|
|
1529
|
+
asset: z.ZodString;
|
|
1530
|
+
token: z.ZodNumber;
|
|
1531
|
+
total: z.ZodString;
|
|
1532
|
+
hold: z.ZodString;
|
|
1533
|
+
entryNotional: z.ZodNullable<z.ZodString>;
|
|
1534
|
+
}, z.core.$strip>>;
|
|
1427
1535
|
}, z.core.$strip>, z.ZodObject<{
|
|
1428
1536
|
totalEquity: z.ZodNullable<z.ZodString>;
|
|
1429
1537
|
withdrawableBalance: z.ZodNullable<z.ZodString>;
|
|
@@ -1454,6 +1562,13 @@ declare const AccountBalance: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1454
1562
|
crossMaintenanceMargin: z.ZodString;
|
|
1455
1563
|
withdrawable: z.ZodString;
|
|
1456
1564
|
}, z.core.$strip>>;
|
|
1565
|
+
spotHoldings: z.ZodArray<z.ZodObject<{
|
|
1566
|
+
asset: z.ZodString;
|
|
1567
|
+
token: z.ZodNumber;
|
|
1568
|
+
total: z.ZodString;
|
|
1569
|
+
hold: z.ZodString;
|
|
1570
|
+
entryNotional: z.ZodNullable<z.ZodString>;
|
|
1571
|
+
}, z.core.$strip>>;
|
|
1457
1572
|
}, z.core.$strip>, z.ZodObject<{
|
|
1458
1573
|
totalEquity: z.ZodNullable<z.ZodString>;
|
|
1459
1574
|
withdrawableBalance: z.ZodNullable<z.ZodString>;
|
|
@@ -1495,6 +1610,13 @@ declare const AccountBalance: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1495
1610
|
crossMaintenanceMargin: z.ZodString;
|
|
1496
1611
|
withdrawable: z.ZodString;
|
|
1497
1612
|
}, z.core.$strip>>;
|
|
1613
|
+
spotHoldings: z.ZodArray<z.ZodObject<{
|
|
1614
|
+
asset: z.ZodString;
|
|
1615
|
+
token: z.ZodNumber;
|
|
1616
|
+
total: z.ZodString;
|
|
1617
|
+
hold: z.ZodString;
|
|
1618
|
+
entryNotional: z.ZodNullable<z.ZodString>;
|
|
1619
|
+
}, z.core.$strip>>;
|
|
1498
1620
|
}, z.core.$strip>, z.ZodObject<{
|
|
1499
1621
|
totalEquity: z.ZodNullable<z.ZodString>;
|
|
1500
1622
|
withdrawableBalance: z.ZodNullable<z.ZodString>;
|
|
@@ -1666,6 +1788,24 @@ declare const AccountBalance: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1666
1788
|
}, z.core.$strip>], "accountMode">;
|
|
1667
1789
|
type AccountBalance = z.infer<typeof AccountBalance>;
|
|
1668
1790
|
|
|
1791
|
+
declare const PublicExchangeAccount: z.ZodObject<{
|
|
1792
|
+
connector: z.ZodEnum<{
|
|
1793
|
+
hyperliquid: "hyperliquid";
|
|
1794
|
+
binance: "binance";
|
|
1795
|
+
bybit: "bybit";
|
|
1796
|
+
okx: "okx";
|
|
1797
|
+
lighter: "lighter";
|
|
1798
|
+
lighter_rhc: "lighter_rhc";
|
|
1799
|
+
}>;
|
|
1800
|
+
exchangeIdentifier: z.ZodString;
|
|
1801
|
+
}, z.core.$strip>;
|
|
1802
|
+
type PublicExchangeAccount = z.infer<typeof PublicExchangeAccount>;
|
|
1803
|
+
declare const TradingEquity: z.ZodObject<{
|
|
1804
|
+
tradingEquityUsd: z.ZodString;
|
|
1805
|
+
timestamp: z.ZodNumber;
|
|
1806
|
+
}, z.core.$strip>;
|
|
1807
|
+
type TradingEquity = z.infer<typeof TradingEquity>;
|
|
1808
|
+
|
|
1669
1809
|
/**
|
|
1670
1810
|
* The primitives every account-balance variant is built from: decimal string formats, the
|
|
1671
1811
|
* `accountMode` union tag, and the four core fields every venue fills in every mode.
|
|
@@ -1813,6 +1953,7 @@ interface AccountTracker {
|
|
|
1813
1953
|
start(): Promise<void>;
|
|
1814
1954
|
disconnect(): Promise<void>;
|
|
1815
1955
|
snapshot(): Promise<AccountSnapshot>;
|
|
1956
|
+
tradingEquity(): Promise<TradingEquity>;
|
|
1816
1957
|
snapshotAssets(coins: string[]): Promise<AssetSnapshotMap>;
|
|
1817
1958
|
readonly isConnected: boolean;
|
|
1818
1959
|
readonly isInitialized: boolean;
|
|
@@ -1835,6 +1976,8 @@ declare abstract class BaseAccountTracker implements AccountTracker {
|
|
|
1835
1976
|
private positionListeners;
|
|
1836
1977
|
private assetEntries;
|
|
1837
1978
|
constructor(config: AccountTrackerConfig);
|
|
1979
|
+
/** Only public account venues implement credential-free trading equity. */
|
|
1980
|
+
tradingEquity(): Promise<TradingEquity>;
|
|
1838
1981
|
snapshotAssets(coins: string[]): Promise<AssetSnapshotMap>;
|
|
1839
1982
|
disconnect(): Promise<void>;
|
|
1840
1983
|
get isInitialized(): boolean;
|
|
@@ -2131,6 +2274,24 @@ declare const HyperliquidDexState: z.ZodObject<{
|
|
|
2131
2274
|
withdrawable: z.ZodString;
|
|
2132
2275
|
}, z.core.$strip>;
|
|
2133
2276
|
type HyperliquidDexState = z.infer<typeof HyperliquidDexState>;
|
|
2277
|
+
/**
|
|
2278
|
+
* One spot holding as the venue lists it, in the coin's own units and in every account mode.
|
|
2279
|
+
*
|
|
2280
|
+
* The whole spot wallet, not the dex collateral tokens alone: a PURR or HYPE holding gets a row in
|
|
2281
|
+
* Standard and Unified as well as in Portfolio Margin. The row set is the venue's own — every coin
|
|
2282
|
+
* where `total ≠ 0` OR `hold ≠ 0` — so a coin that empties leaves the list rather than reading zero.
|
|
2283
|
+
*
|
|
2284
|
+
* Quantities only, NEVER priced: valuing the wallet is the variant's own equity scalar's job, and
|
|
2285
|
+
* that scalar reports `null` for a holding it cannot price instead of guessing.
|
|
2286
|
+
*/
|
|
2287
|
+
declare const HyperliquidSpotHolding: z.ZodObject<{
|
|
2288
|
+
asset: z.ZodString;
|
|
2289
|
+
token: z.ZodNumber;
|
|
2290
|
+
total: z.ZodString;
|
|
2291
|
+
hold: z.ZodString;
|
|
2292
|
+
entryNotional: z.ZodNullable<z.ZodString>;
|
|
2293
|
+
}, z.core.$strip>;
|
|
2294
|
+
type HyperliquidSpotHolding = z.infer<typeof HyperliquidSpotHolding>;
|
|
2134
2295
|
declare const HyperliquidStandardBalance: z.ZodObject<{
|
|
2135
2296
|
totalEquity: z.ZodNullable<z.ZodString>;
|
|
2136
2297
|
withdrawableBalance: z.ZodNullable<z.ZodString>;
|
|
@@ -2161,6 +2322,13 @@ declare const HyperliquidStandardBalance: z.ZodObject<{
|
|
|
2161
2322
|
crossMaintenanceMargin: z.ZodString;
|
|
2162
2323
|
withdrawable: z.ZodString;
|
|
2163
2324
|
}, z.core.$strip>>;
|
|
2325
|
+
spotHoldings: z.ZodArray<z.ZodObject<{
|
|
2326
|
+
asset: z.ZodString;
|
|
2327
|
+
token: z.ZodNumber;
|
|
2328
|
+
total: z.ZodString;
|
|
2329
|
+
hold: z.ZodString;
|
|
2330
|
+
entryNotional: z.ZodNullable<z.ZodString>;
|
|
2331
|
+
}, z.core.$strip>>;
|
|
2164
2332
|
}, z.core.$strip>;
|
|
2165
2333
|
type HyperliquidStandardBalance = z.infer<typeof HyperliquidStandardBalance>;
|
|
2166
2334
|
declare const HyperliquidUnifiedBalance: z.ZodObject<{
|
|
@@ -2193,6 +2361,13 @@ declare const HyperliquidUnifiedBalance: z.ZodObject<{
|
|
|
2193
2361
|
crossMaintenanceMargin: z.ZodString;
|
|
2194
2362
|
withdrawable: z.ZodString;
|
|
2195
2363
|
}, z.core.$strip>>;
|
|
2364
|
+
spotHoldings: z.ZodArray<z.ZodObject<{
|
|
2365
|
+
asset: z.ZodString;
|
|
2366
|
+
token: z.ZodNumber;
|
|
2367
|
+
total: z.ZodString;
|
|
2368
|
+
hold: z.ZodString;
|
|
2369
|
+
entryNotional: z.ZodNullable<z.ZodString>;
|
|
2370
|
+
}, z.core.$strip>>;
|
|
2196
2371
|
}, z.core.$strip>;
|
|
2197
2372
|
type HyperliquidUnifiedBalance = z.infer<typeof HyperliquidUnifiedBalance>;
|
|
2198
2373
|
/**
|
|
@@ -2271,13 +2446,39 @@ declare const HyperliquidPortfolioMarginBalance: z.ZodObject<{
|
|
|
2271
2446
|
crossMaintenanceMargin: z.ZodString;
|
|
2272
2447
|
withdrawable: z.ZodString;
|
|
2273
2448
|
}, z.core.$strip>>;
|
|
2449
|
+
spotHoldings: z.ZodArray<z.ZodObject<{
|
|
2450
|
+
asset: z.ZodString;
|
|
2451
|
+
token: z.ZodNumber;
|
|
2452
|
+
total: z.ZodString;
|
|
2453
|
+
hold: z.ZodString;
|
|
2454
|
+
entryNotional: z.ZodNullable<z.ZodString>;
|
|
2455
|
+
}, z.core.$strip>>;
|
|
2274
2456
|
}, z.core.$strip>;
|
|
2275
2457
|
type HyperliquidPortfolioMarginBalance = z.infer<typeof HyperliquidPortfolioMarginBalance>;
|
|
2276
2458
|
|
|
2277
|
-
|
|
2278
|
-
|
|
2459
|
+
/**
|
|
2460
|
+
* Hyperliquid's two read paths: the live WebSocket tracker and the one-shot REST snapshot.
|
|
2461
|
+
*
|
|
2462
|
+
* Both fill the same `HyperliquidBalanceContext` and hand it to the same mapper, which is what
|
|
2463
|
+
* makes "same account state, same balance" true across two different transports. The tracker takes
|
|
2464
|
+
* every CHANGING value off a channel — `allDexsClearinghouseState`, `spotState`, `webData3`,
|
|
2465
|
+
* `allMids`, `activeAssetData` — including vault equity, which rides `webData3`, save one:
|
|
2466
|
+
* Portfolio Margin's health factor and reserve rates ride no channel, so it polls them while the
|
|
2467
|
+
* account is in that mode. Its other REST reads are the static dex metadata, read at `start()`, and
|
|
2468
|
+
* the staking position, which the venue publishes on no channel at all: read at `start()` too, then
|
|
2469
|
+
* again on the first spot frame and after spot HYPE rises while the account holds staked HYPE,
|
|
2470
|
+
* rate-limited to one minute with a known queue and five minutes without one.
|
|
2471
|
+
*
|
|
2472
|
+
* The snapshot has no channels, so it reads the same figures over REST — vault equity from
|
|
2473
|
+
* `userVaultEquities`, which was measured equal to the `webData3` figure on ten live accounts.
|
|
2474
|
+
*/
|
|
2475
|
+
|
|
2476
|
+
type HyperliquidAccountTrackerConfig = AccountTrackerConfig & ({
|
|
2477
|
+
account: Pick<TradeAccount, 'exchangeIdentifier'>;
|
|
2478
|
+
} | {
|
|
2479
|
+
/** The address whose state is read without credentials. */
|
|
2279
2480
|
address: `0x${string}`;
|
|
2280
|
-
};
|
|
2481
|
+
});
|
|
2281
2482
|
declare class HyperliquidAccountTracker extends BaseAccountTracker {
|
|
2282
2483
|
private readonly address;
|
|
2283
2484
|
private ws;
|
|
@@ -2326,6 +2527,8 @@ declare class HyperliquidAccountTracker extends BaseAccountTracker {
|
|
|
2326
2527
|
* per-asset headroom without opening a socket.
|
|
2327
2528
|
*/
|
|
2328
2529
|
snapshot(): Promise<AccountSnapshot>;
|
|
2530
|
+
/** Value trading holdings with the same account reads and pricing used by snapshots. */
|
|
2531
|
+
tradingEquity(): Promise<TradingEquity>;
|
|
2329
2532
|
/**
|
|
2330
2533
|
* Stateless one-shot per-asset settings read via the `activeAssetData` info request (the REST
|
|
2331
2534
|
* twin of the live WS subscription), one request per coin fired in parallel — the info endpoint
|
|
@@ -2357,6 +2560,10 @@ declare class HyperliquidAccountTracker extends BaseAccountTracker {
|
|
|
2357
2560
|
private onSocketClosed;
|
|
2358
2561
|
private routeRaw;
|
|
2359
2562
|
private handle;
|
|
2563
|
+
/** Share the public account-mode and spot valuation inputs across one-shot reads. */
|
|
2564
|
+
private fetchAccountState;
|
|
2565
|
+
/** Retain each DEX's collateral identity when reading separate perpetual wallets. */
|
|
2566
|
+
private fetchPerpStates;
|
|
2360
2567
|
private loadPerpMetas;
|
|
2361
2568
|
/** Reads `activeAssetData` for each coin in parallel, dropping the coins the venue refuses. */
|
|
2362
2569
|
private fetchActiveAssetEvents;
|
|
@@ -2504,13 +2711,17 @@ type LighterUnifiedBalance = z.infer<typeof LighterUnifiedBalance>;
|
|
|
2504
2711
|
declare const LIGHTER_QUOTE_ASSETS: Record<LighterConnector, string>;
|
|
2505
2712
|
|
|
2506
2713
|
type LighterAccountTrackerConfig = AccountTrackerConfig & {
|
|
2507
|
-
/** Null leaves the tier unread: `/accountLimits` is authenticated and only Core mints a token. */
|
|
2508
|
-
sdk: PearSDK | null;
|
|
2509
2714
|
/** The Lighter deployment this account lives on; hosts and collateral follow it. */
|
|
2510
2715
|
connector: LighterConnector;
|
|
2511
|
-
account: TradeAccount
|
|
2716
|
+
account: Pick<TradeAccount, 'exchangeIdentifier'>;
|
|
2717
|
+
} & ({
|
|
2718
|
+
access: 'public';
|
|
2719
|
+
} | {
|
|
2720
|
+
access?: 'authenticated';
|
|
2721
|
+
/** Null leaves the tier unread: `/accountLimits` is authenticated and only Core mints a token. */
|
|
2722
|
+
sdk: PearSDK | null;
|
|
2512
2723
|
credentials: SupportedCredentials;
|
|
2513
|
-
};
|
|
2724
|
+
});
|
|
2514
2725
|
/** Told the account's tier, or told there is no answer yet. */
|
|
2515
2726
|
type AccountTierCallback = (tier: LighterAccountTier | null) => void;
|
|
2516
2727
|
declare class LighterAccountTracker extends BaseAccountTracker {
|
|
@@ -2518,8 +2729,6 @@ declare class LighterAccountTracker extends BaseAccountTracker {
|
|
|
2518
2729
|
private readonly connector;
|
|
2519
2730
|
private readonly quoteAsset;
|
|
2520
2731
|
private readonly accountIdentifier;
|
|
2521
|
-
private readonly apiKeyIndex;
|
|
2522
|
-
private readonly apiPrivateKey;
|
|
2523
2732
|
private readonly creds;
|
|
2524
2733
|
private ws;
|
|
2525
2734
|
private messageListenerId;
|
|
@@ -2564,6 +2773,8 @@ declare class LighterAccountTracker extends BaseAccountTracker {
|
|
|
2564
2773
|
refreshAccountTier(): Promise<void>;
|
|
2565
2774
|
/** Stateless one-shot account read — authenticated for connected accounts, and no websocket. */
|
|
2566
2775
|
snapshot(): Promise<AccountSnapshot>;
|
|
2776
|
+
/** Reuse the snapshot read path and let the mapper include open PnL exactly once. */
|
|
2777
|
+
tradingEquity(): Promise<TradingEquity>;
|
|
2567
2778
|
/**
|
|
2568
2779
|
* Stateless one-shot per-asset settings read, keyed by market id (the same identifier the live
|
|
2569
2780
|
* trackAsset path uses). One public `GET /api/v1/account` covers every market the account holds
|
|
@@ -2621,7 +2832,7 @@ declare class LighterAccountTracker extends BaseAccountTracker {
|
|
|
2621
2832
|
private fetchPrimaryAccount;
|
|
2622
2833
|
/** Reads market context under the same account identity as the snapshot that consumes it. */
|
|
2623
2834
|
private fetchMarkets;
|
|
2624
|
-
/**
|
|
2835
|
+
/** Public access has no credentials; connected accounts reuse their cached auth token. */
|
|
2625
2836
|
private retrieveAuthToken;
|
|
2626
2837
|
/** Requires credentials for private WebSocket channels even when REST is in verifier mode. */
|
|
2627
2838
|
private retrieveRequiredAuthToken;
|
|
@@ -2863,12 +3074,16 @@ declare class OkxAccountTracker extends BaseAccountTracker {
|
|
|
2863
3074
|
private performWithdrawableRefresh;
|
|
2864
3075
|
}
|
|
2865
3076
|
|
|
2866
|
-
type CreateAccountTrackerConfig = AccountTrackerConfig & {
|
|
3077
|
+
type CreateAccountTrackerConfig = AccountTrackerConfig & ({
|
|
3078
|
+
access: 'public';
|
|
3079
|
+
account: PublicExchangeAccount;
|
|
3080
|
+
} | {
|
|
3081
|
+
access?: 'authenticated';
|
|
2867
3082
|
/** Lighter only: null there leaves the account's tier unread. */
|
|
2868
3083
|
sdk: PearSDK | null;
|
|
2869
3084
|
account: TradeAccount;
|
|
2870
3085
|
credentials: SupportedCredentials;
|
|
2871
|
-
};
|
|
3086
|
+
});
|
|
2872
3087
|
declare function createAccountTracker(exchange: Connector, config: CreateAccountTrackerConfig): AccountTracker;
|
|
2873
3088
|
|
|
2874
3089
|
declare class ExchangesSDK {
|
|
@@ -2877,6 +3092,8 @@ declare class ExchangesSDK {
|
|
|
2877
3092
|
private throttle;
|
|
2878
3093
|
private hyperliquidPerpDexNames;
|
|
2879
3094
|
constructor(config: ExchangesSDKConfig);
|
|
3095
|
+
/** Value public trading holdings and open PnL without connecting or retrieving credentials. */
|
|
3096
|
+
tradingEquity(account: PublicExchangeAccount): Promise<TradingEquity>;
|
|
2880
3097
|
connect(tradeAccountId: string): Promise<ExchangeConnection>;
|
|
2881
3098
|
/**
|
|
2882
3099
|
* Options come in per call rather than at construction: the approval targets live in the
|
|
@@ -2885,6 +3102,9 @@ declare class ExchangesSDK {
|
|
|
2885
3102
|
*/
|
|
2886
3103
|
status(connection: ExchangeConnection, options?: ConnectOptions): Promise<AccountStatus>;
|
|
2887
3104
|
createTracker(connection: ExchangeConnection): AccountTracker;
|
|
3105
|
+
createTracker(account: PublicExchangeAccount, options: {
|
|
3106
|
+
access: 'public';
|
|
3107
|
+
}): AccountTracker;
|
|
2888
3108
|
/**
|
|
2889
3109
|
* A read-only tracker for any address, built without `connect()`: Hyperliquid answers account
|
|
2890
3110
|
* state for an address with no credentials, so none are fetched and no trade account is needed.
|
|
@@ -2898,4 +3118,4 @@ declare class ExchangesSDK {
|
|
|
2898
3118
|
private fetchCredentials;
|
|
2899
3119
|
}
|
|
2900
3120
|
|
|
2901
|
-
export { ACCOUNT_MODE_LABELS, ASSET_DECIMALS, AccountBalance, AccountBalanceCore, type AccountHealthStatus, AccountMode, type AccountPosition, type AccountSnapshot, type AccountStatus, type AccountSyncer, type AccountSyncerConfig, type AccountTierCallback, type AccountTracker, type AccountTrackerConfig, type AccountWarningReason, type ApiKey, type ApproveIntegratorParams, type ApproveIntegratorResult, AssetId, type AssetSnapshotMap, type BalanceCallback, BaseAccountSyncer, BaseAccountTracker, BaseWs, BinanceAccountSyncer, BinanceAccountTracker, type BinanceAccountTrackerConfig, BinanceExchangeWs, BinanceMultiAssetBalance, BinanceSingleAssetBalance, BinanceUserDataWs, type BinanceUserDataWsConfig, BinanceWsApi, type BinanceWsApiConfig, BybitAccountSyncer, BybitAccountTracker, type BybitAccountTrackerConfig, BybitExchangeWs, BybitIsolatedMarginBalance, BybitPortfolioMarginBalance, BybitRegularMarginBalance, BybitWs, type BybitWsConfig, type CctpDepositAddressParams, type CctpDepositAddressResult, type CctpDepositHistorySettlement, type CctpDepositParams, type CctpDepositRegistrationSettlement, type CctpDepositResult, type CctpDepositSettlement, type ChangeAccountTierParams, type ChangeAccountTierResult, type CheckApiWalletParams, type CloseListener, CollateralBalance, type ConnectOptions, type ConnectWalletParams, type ConnectWalletResult, type CreateAccountTrackerConfig, type CreateExchangeWsConfig, DecimalString, type EthereumDepositParams, type EthereumDepositResult, type ExchangeConnection, type ExchangeHelperExchange, type ExchangeHelperMap, type ExchangeState, ExchangeWs, type ExchangeWsByConnector, ExchangesSDK, type ExchangesSDKConfig, FUNXYZ_DEPOSIT_MINIMUMS_USD, FUNXYZ_ETHEREUM_MAINNET_CHAIN_ID, FUNXYZ_EVM_CHAIN_NAMES, type FastWithdrawParams, type FastWithdrawResult, type FillSyncOutcome, type FundingSyncOutcome, type FunxyzAccountState, type FunxyzAsset, type FunxyzDepositAddressParams, type FunxyzDepositAddressResult, type FunxyzDepositCredit, type FunxyzDepositParams, type FunxyzDepositResult, type FunxyzDepositSettlement, type FunxyzDepositSource, type FunxyzMarket, HyperliquidAccountSyncer, HyperliquidAccountTracker, type HyperliquidAccountTrackerConfig, HyperliquidBorrowLendReserve, HyperliquidDexState, HyperliquidExchangeWs, type HyperliquidHelper, HyperliquidPortfolioMarginBalance, HyperliquidPortfolioMarginCollateral, HyperliquidStandardBalance, HyperliquidUnifiedBalance, HyperliquidWs, type IntegratorApprovalRequirements, L2_ASSET_DECIMALS, LIGHTER_NATIVE_USDC_ADDRESSES, LIGHTER_QUOTE_ASSETS, LIGHTER_RHC_CHAIN_ID, LIGHTER_RHC_USDG_ADDRESS, LIGHTER_RHC_USDG_DECIMALS, LIGHTER_USDC_DECIMALS, LighterAccountSyncer, type LighterAccountSyncerConfig, type LighterAccountTier, LighterAccountTracker, type LighterAccountTrackerConfig, type LighterApplyReferralCodeParams, type LighterAuthCredentials, LighterClassicBalance, type LighterConnector, type LighterDeposit, type LighterDepositAddressParams, type LighterDepositAddressResult, type LighterDepositCredit, type LighterDepositHistoryParams, type LighterDepositNetwork, type LighterDepositPage, type LighterDepositParams, type LighterDepositProgress, type LighterDepositResult, type LighterDepositStatus, type LighterDepositWalletAdapter, LighterExchangeWs, type LighterHelper, type LighterLookupResult, type LighterOnboardingStatus, type LighterReferral, type LighterReferralTotals, type LighterReferralTradeStats, LighterRhcAssetId, type LighterRhcDepositAddressParams, type LighterRhcDepositAddressResult, type LighterRhcDepositParams, type LighterRhcDepositResult, type LighterRhcDepositWallet, type LighterRhcHelper, type LighterSharedHelper, LighterUnifiedBalance, type LighterUserReferrals, type LighterUserReferralsParams, type LighterWithdraw, type LighterWithdrawHistoryParams, type LighterWithdrawPage, type LighterWithdrawStatus, type LighterWithdrawType, LighterWs, type ListExternalFillsParams, type ListExternalFundingParams, type ListExternalPositionsParams, MAX_API_KEY_INDEX, MIN_LIGHTER_CCTP_DEPOSIT_USDC, MIN_LIGHTER_FAST_WITHDRAW_COLLATERAL, MIN_LIGHTER_RHC_DEPOSIT_USDG, MIN_USER_API_KEY_INDEX, MarginMode, type MessageListener, OkxAccountSyncer, OkxAccountTracker, type OkxAccountTrackerConfig, OkxExchangeWs, OkxFuturesBalance, OkxMultiCurrencyMarginBalance, OkxPortfolioMarginBalance, OkxSpotBalance, OkxWs, type OkxWsConfig, type OpenListener, type PositionsCallback, type PublicTrackerConfig, RouteType, Side, SignedDecimalString, type StateUpdate, type SupportedCredentials, type SyncerThrottle, type TrackedAssetCallback, type TrackedAssetInfo, type WalletClientWithAccount, type WithdrawParams, type WithdrawResult, type WsMessage, createAccountSyncer, createAccountTracker, createExchangeWs, createHyperliquidHelper, createLighterHelper, createLighterRhcHelper, findAvailableApiKeyIndex, getAssetDecimals, getLighterNativeUsdcAddress, listFunxyzTransferableChains, readFunxyzChainSource, readFunxyzMinimumUsd, retrieveLighterAuthToken, usdcAbi };
|
|
3121
|
+
export { ACCOUNT_MODE_LABELS, ASSET_DECIMALS, AccountBalance, AccountBalanceCore, type AccountHealthStatus, AccountMode, type AccountPosition, type AccountSnapshot, type AccountStatus, type AccountSyncer, type AccountSyncerConfig, type AccountTierCallback, type AccountTracker, type AccountTrackerConfig, type AccountWarningReason, type ApiKey, type ApproveIntegratorParams, type ApproveIntegratorResult, AssetId, type AssetSnapshotMap, type BalanceCallback, BaseAccountSyncer, BaseAccountTracker, BaseWs, BinanceAccountSyncer, BinanceAccountTracker, type BinanceAccountTrackerConfig, BinanceExchangeWs, BinanceMultiAssetBalance, BinanceSingleAssetBalance, BinanceUserDataWs, type BinanceUserDataWsConfig, BinanceWsApi, type BinanceWsApiConfig, BybitAccountSyncer, BybitAccountTracker, type BybitAccountTrackerConfig, BybitExchangeWs, BybitIsolatedMarginBalance, BybitPortfolioMarginBalance, BybitRegularMarginBalance, BybitWs, type BybitWsConfig, type CctpDepositAddressParams, type CctpDepositAddressResult, type CctpDepositHistorySettlement, type CctpDepositParams, type CctpDepositRegistrationSettlement, type CctpDepositResult, type CctpDepositSettlement, type ChangeAccountTierParams, type ChangeAccountTierResult, type CheckApiWalletParams, type CloseListener, CollateralBalance, type ConnectOptions, type ConnectWalletParams, type ConnectWalletResult, type CreateAccountTrackerConfig, type CreateExchangeWsConfig, type CreateHyperliquidSubAccountParams, type CreateHyperliquidSubAccountResult, type CreateLighterSubAccountParams, type CreateLighterSubAccountResult, type CreateNamedLighterSubAccountParams, type CreateNamedLighterSubAccountResult, DecimalString, type EthereumDepositParams, type EthereumDepositResult, type ExchangeConnection, type ExchangeHelperExchange, type ExchangeHelperMap, type ExchangeState, ExchangeWs, type ExchangeWsByConnector, ExchangesSDK, type ExchangesSDKConfig, FUNXYZ_DEPOSIT_MINIMUMS_USD, FUNXYZ_ETHEREUM_MAINNET_CHAIN_ID, FUNXYZ_EVM_CHAIN_NAMES, type FastWithdrawParams, type FastWithdrawResult, type FetchLighterAccountMetadataParams, type FetchLighterAccountMetadataResult, type FillSyncOutcome, type FundingSyncOutcome, type FunxyzAccountState, type FunxyzAsset, type FunxyzDepositAddressParams, type FunxyzDepositAddressResult, type FunxyzDepositCredit, type FunxyzDepositParams, type FunxyzDepositResult, type FunxyzDepositSettlement, type FunxyzDepositSource, type FunxyzMarket, HyperliquidAccountSyncer, HyperliquidAccountTracker, type HyperliquidAccountTrackerConfig, HyperliquidBorrowLendReserve, HyperliquidDexState, HyperliquidExchangeWs, type HyperliquidHelper, HyperliquidPortfolioMarginBalance, HyperliquidPortfolioMarginCollateral, HyperliquidSpotHolding, HyperliquidStandardBalance, type HyperliquidSubAccountSummary, type HyperliquidSubAccountTransferParams, HyperliquidUnifiedBalance, HyperliquidWs, type IntegratorApprovalRequirements, L2_ASSET_DECIMALS, LIGHTER_NATIVE_USDC_ADDRESSES, LIGHTER_QUOTE_ASSETS, LIGHTER_RHC_CHAIN_ID, LIGHTER_RHC_USDG_ADDRESS, LIGHTER_RHC_USDG_DECIMALS, LIGHTER_USDC_DECIMALS, type LighterAccountMetadata, LighterAccountSyncer, type LighterAccountSyncerConfig, type LighterAccountTier, LighterAccountTracker, type LighterAccountTrackerConfig, type LighterApplyReferralCodeParams, type LighterAuthCredentials, LighterClassicBalance, type LighterConnector, type LighterDeposit, type LighterDepositAddressParams, type LighterDepositAddressResult, type LighterDepositCredit, type LighterDepositHistoryParams, type LighterDepositNetwork, type LighterDepositPage, type LighterDepositParams, type LighterDepositProgress, type LighterDepositResult, type LighterDepositStatus, type LighterDepositWalletAdapter, LighterExchangeWs, type LighterHelper, type LighterLookupResult, type LighterOnboardingStatus, type LighterReferral, type LighterReferralTotals, type LighterReferralTradeStats, LighterRhcAssetId, type LighterRhcDepositAddressParams, type LighterRhcDepositAddressResult, type LighterRhcDepositParams, type LighterRhcDepositResult, type LighterRhcDepositWallet, type LighterRhcHelper, type LighterSharedHelper, type LighterSubAccountTransferParams, type LighterSubAccountTransferResult, LighterUnifiedBalance, type LighterUserReferrals, type LighterUserReferralsParams, type LighterWithdraw, type LighterWithdrawHistoryParams, type LighterWithdrawPage, type LighterWithdrawStatus, type LighterWithdrawType, LighterWs, type ListExternalFillsParams, type ListExternalFundingParams, type ListExternalPositionsParams, MAX_API_KEY_INDEX, MIN_LIGHTER_CCTP_DEPOSIT_USDC, MIN_LIGHTER_FAST_WITHDRAW_COLLATERAL, MIN_LIGHTER_RHC_DEPOSIT_USDG, MIN_USER_API_KEY_INDEX, MarginMode, type MessageListener, OkxAccountSyncer, OkxAccountTracker, type OkxAccountTrackerConfig, OkxExchangeWs, OkxFuturesBalance, OkxMultiCurrencyMarginBalance, OkxPortfolioMarginBalance, OkxSpotBalance, OkxWs, type OkxWsConfig, type OpenListener, type PositionsCallback, PublicExchangeAccount, type PublicTrackerConfig, RouteType, type SetLighterSubAccountMetadataParams, Side, SignedDecimalString, type StateUpdate, type SubAccountTransferDirection, type SupportedCredentials, type SyncerThrottle, type TrackedAssetCallback, type TrackedAssetInfo, TradingEquity, type WalletClientWithAccount, type WithdrawParams, type WithdrawResult, type WsMessage, createAccountSyncer, createAccountTracker, createExchangeWs, createHyperliquidHelper, createLighterHelper, createLighterRhcHelper, findAvailableApiKeyIndex, getAssetDecimals, getLighterNativeUsdcAddress, listFunxyzTransferableChains, parseCollateralAmount, readFunxyzChainSource, readFunxyzMinimumUsd, retrieveLighterAuthToken, usdcAbi };
|
package/dist/sdk.js
CHANGED
|
@@ -2,7 +2,8 @@ import { configureProxy } from '@pear-protocol/utils';
|
|
|
2
2
|
import { createExchangeHelper } from './helper/factory';
|
|
3
3
|
import { checkAccountStatus } from './status';
|
|
4
4
|
import { createAccountSyncer } from './syncer';
|
|
5
|
-
import {
|
|
5
|
+
import { createAccountTracker } from './tracker';
|
|
6
|
+
import { PublicExchangeAccount } from './tracker/equity';
|
|
6
7
|
|
|
7
8
|
var __defProp = Object.defineProperty;
|
|
8
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -21,6 +22,12 @@ class ExchangesSDK {
|
|
|
21
22
|
this.hyperliquidPerpDexNames = config.hyperliquidPerpDexNames;
|
|
22
23
|
if (config.proxy) configureProxy(config.proxy);
|
|
23
24
|
}
|
|
25
|
+
/** Value public trading holdings and open PnL without connecting or retrieving credentials. */
|
|
26
|
+
async tradingEquity(account) {
|
|
27
|
+
return await this.createTracker(account, {
|
|
28
|
+
access: "public"
|
|
29
|
+
}).tradingEquity();
|
|
30
|
+
}
|
|
24
31
|
async connect(tradeAccountId) {
|
|
25
32
|
return this.fetchCredentials(tradeAccountId);
|
|
26
33
|
}
|
|
@@ -39,8 +46,19 @@ class ExchangesSDK {
|
|
|
39
46
|
demo: this.demo
|
|
40
47
|
});
|
|
41
48
|
}
|
|
42
|
-
createTracker(
|
|
43
|
-
|
|
49
|
+
createTracker(account, options) {
|
|
50
|
+
if (options?.access === "public") {
|
|
51
|
+
const identity = PublicExchangeAccount.parse(account);
|
|
52
|
+
return createAccountTracker(identity.connector, {
|
|
53
|
+
access: "public",
|
|
54
|
+
account: identity,
|
|
55
|
+
demo: this.demo
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if ("credentials" in account) {
|
|
59
|
+
return this.buildTracker(account);
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Authenticated trackers require an exchange connection");
|
|
44
62
|
}
|
|
45
63
|
/**
|
|
46
64
|
* A read-only tracker for any address, built without `connect()`: Hyperliquid answers account
|
|
@@ -49,10 +67,14 @@ class ExchangesSDK {
|
|
|
49
67
|
createPublicTracker(config) {
|
|
50
68
|
switch (config.connector) {
|
|
51
69
|
case "hyperliquid":
|
|
52
|
-
return
|
|
70
|
+
return createAccountTracker("hyperliquid", {
|
|
71
|
+
access: "public",
|
|
72
|
+
account: {
|
|
73
|
+
connector: "hyperliquid",
|
|
74
|
+
exchangeIdentifier: config.address
|
|
75
|
+
},
|
|
53
76
|
demo: this.demo,
|
|
54
|
-
onError: config.onError
|
|
55
|
-
address: config.address
|
|
77
|
+
onError: config.onError
|
|
56
78
|
});
|
|
57
79
|
}
|
|
58
80
|
}
|
|
@@ -16,8 +16,8 @@ async function checkHyperliquidAccountStatus(config) {
|
|
|
16
16
|
exchange: "hyperliquid",
|
|
17
17
|
demo: config.demo
|
|
18
18
|
});
|
|
19
|
-
const metadata = config.account.metadata;
|
|
20
|
-
const approvalAddress = metadata
|
|
19
|
+
const metadata = config.account.connector === "hyperliquid" ? config.account.metadata : void 0;
|
|
20
|
+
const approvalAddress = metadata?.isSubaccount === true ? metadata.mainAccountAddress : config.account.exchangeIdentifier;
|
|
21
21
|
try {
|
|
22
22
|
const abstraction = await fetchUserAbstraction(config.account.exchangeIdentifier, config.demo);
|
|
23
23
|
const supportedAccountMode = abstraction === HyperliquidAccountType.DEFAULT || abstraction === HyperliquidAccountType.DISABLED || abstraction === HyperliquidAccountType.UNIFIED_ACCOUNT || abstraction === HyperliquidAccountType.PORTFOLIO_MARGIN;
|
|
@@ -27,7 +27,7 @@ async function checkHyperliquidAccountStatus(config) {
|
|
|
27
27
|
} catch {
|
|
28
28
|
reasons.push("hyperliquid_account_mode_check_failed");
|
|
29
29
|
}
|
|
30
|
-
if (!metadata
|
|
30
|
+
if (!metadata) {
|
|
31
31
|
reasons.push("hyperliquid_api_wallet_invalid");
|
|
32
32
|
} else {
|
|
33
33
|
try {
|
package/dist/syncer/base.js
CHANGED
|
@@ -82,7 +82,7 @@ class BaseAccountSyncer {
|
|
|
82
82
|
firstSyncStartedAt
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
// Phase C: Compute the sync payload and post
|
|
85
|
+
// Phase C: Compute the sync payload and post the applicables to the create endpoint.
|
|
86
86
|
async computeAndPostSync(state, snapshot) {
|
|
87
87
|
const { openPositions, entryBySymbol, provisionalFills, watermark } = state;
|
|
88
88
|
const { exchangePositions, externalFills, firstSyncStartedAt } = snapshot;
|
|
@@ -100,26 +100,6 @@ class BaseAccountSyncer {
|
|
|
100
100
|
if (!payload) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
|
-
if (payload.reconcilables) {
|
|
104
|
-
const reconcileBytes = new Blob([
|
|
105
|
-
JSON.stringify(payload.reconcilables)
|
|
106
|
-
]).size;
|
|
107
|
-
if (reconcileBytes > 50 * 1024) {
|
|
108
|
-
await this.sdk.core.sync.fills.reconcileBulk(payload.reconcilables);
|
|
109
|
-
} else {
|
|
110
|
-
await this.sdk.core.sync.fills.reconcile(payload.reconcilables);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (payload.confirmables) {
|
|
114
|
-
const confirmBytes = new Blob([
|
|
115
|
-
JSON.stringify(payload.confirmables)
|
|
116
|
-
]).size;
|
|
117
|
-
if (confirmBytes > 50 * 1024) {
|
|
118
|
-
await this.sdk.core.sync.fills.confirmBulk(payload.confirmables);
|
|
119
|
-
} else {
|
|
120
|
-
await this.sdk.core.sync.fills.confirm(payload.confirmables);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
103
|
const { firstSyncTrim } = payload;
|
|
124
104
|
let meta = {
|
|
125
105
|
...payload.meta,
|