@pear-protocol/exchanges-sdk 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,30 +7,9 @@ import { WalletClient, Transport, Chain, Account } from 'viem';
7
7
  import { z } from 'zod';
8
8
 
9
9
  type SupportedCredentials = HttpTypes.ExchangeCredentialsResponse['credentials'];
10
- /**
11
- * Optional pacing seam around the syncer's exchange info requests. The SDK stays
12
- * rate-limit-agnostic: it only exposes when a request starts, what it returned,
13
- * and when it failed — the caller owns all budget math and waiting.
14
- */
15
- type SyncerThrottle = {
16
- /** Awaited before the request fires; the caller blocks here until its budget allows the call. */
17
- beforeRequest(requestType: string): Promise<void>;
18
- /** Called after a successful response; `itemCount` is the response array length (0 for object responses). */
19
- afterRequest(requestType: string, itemCount: number): void;
20
- /** Called when the request threw, before the error propagates; lets the caller inspect rate-limit rejections. */
21
- afterRequestError(requestType: string, error: unknown): void;
22
- };
23
10
  type ExchangesSDKConfig = {
24
11
  sdk: PearSDK;
25
12
  demo?: boolean;
26
- /** Optional pacing seam around the syncer's exchange info requests; absent = unthrottled (current behavior). */
27
- throttle?: SyncerThrottle;
28
- /**
29
- * Optional pre-fetched Hyperliquid perp-dex names ('' = the main dex). The list is
30
- * global (identical for every account), so a batch caller fetches it once per run and
31
- * passes it here; absent = the syncer fetches it per sync (current behavior).
32
- */
33
- hyperliquidPerpDexNames?: string[];
34
13
  /**
35
14
  * Optional forward-proxy for the exchange REST calls. When enabled, requests are re-pointed at
36
15
  * `proxy.url` with the original venue host in `X-Proxy-Target`. Injected here because the SDK
@@ -248,30 +227,6 @@ declare class OkxExchangeWs extends ExchangeWs {
248
227
  }): Promise<OkxExchangeWs>;
249
228
  }
250
229
 
251
- type LighterRawTrade = {
252
- trade_id: number;
253
- trade_id_str?: string;
254
- type: 'trade' | 'liquidation' | 'deleverage' | 'market-settlement' | string;
255
- market_id: number;
256
- size: string;
257
- price: string;
258
- usd_amount: string;
259
- ask_client_id_str?: string;
260
- bid_client_id_str?: string;
261
- ask_account_id: number;
262
- bid_account_id: number;
263
- is_maker_ask: boolean;
264
- timestamp: number;
265
- taker_fee?: number;
266
- taker_position_size_before?: string;
267
- maker_fee?: number;
268
- maker_position_size_before?: string;
269
- taker_position_sign_changed?: boolean;
270
- maker_position_sign_changed?: boolean;
271
- integrator_taker_fee?: number;
272
- integrator_maker_fee?: number;
273
- };
274
-
275
230
  type ApiKey = {
276
231
  account_index: number;
277
232
  api_key_index: number;
@@ -1196,303 +1151,6 @@ type ExchangeHelperMap = {
1196
1151
  };
1197
1152
  type ExchangeHelperExchange = keyof ExchangeHelperMap;
1198
1153
 
1199
- interface AccountSyncerConfig {
1200
- sdk: PearSDK;
1201
- connector: Connector;
1202
- account: TradeAccount;
1203
- credentials: SupportedCredentials;
1204
- demo: boolean;
1205
- /** Optional pacing seam around the exchange info requests; absent = unthrottled (current behavior). */
1206
- throttle?: SyncerThrottle;
1207
- /** Optional pre-fetched Hyperliquid perp-dex names ('' = the main dex); absent = fetched per sync. */
1208
- hyperliquidPerpDexNames?: string[];
1209
- }
1210
- /**
1211
- * Outcome of one fill sync cycle, so batch/cron callers can tell a completed
1212
- * cycle apart from one that must be retried:
1213
- * - `synced`: the cycle posted, or there was nothing to post.
1214
- * - `deferred`: the server answered 409 SYNC_CREATE_*; the watermark did not
1215
- * advance, so a later cycle retries the same window.
1216
- * - `aborted`: the exchange fetch failed; nothing was posted.
1217
- */
1218
- type FillSyncOutcome = 'synced' | 'deferred' | 'aborted';
1219
- /**
1220
- * Outcome of one funding sync cycle. Funding has no server deferral contract,
1221
- * so the union is narrower than {@link FillSyncOutcome}:
1222
- * - `synced`: the cycle posted, or there were no new payments.
1223
- * - `aborted`: the exchange funding fetch failed; nothing was posted.
1224
- * A failed post still throws — only the exchange fetch is guarded.
1225
- */
1226
- type FundingSyncOutcome = 'synced' | 'aborted';
1227
- interface AccountSyncer {
1228
- synchronizeFills(): Promise<FillSyncOutcome>;
1229
- synchronizeFunding(): Promise<FundingSyncOutcome>;
1230
- }
1231
- interface ListExternalFillsParams {
1232
- since: Date;
1233
- instruments: HttpTypes.InstrumentLite[];
1234
- openPositions: HttpTypes.OpenPositionLite[];
1235
- provisionalFills: HttpTypes.ProvisionalFill[];
1236
- }
1237
- interface ListExternalPositionsParams {
1238
- instruments: HttpTypes.InstrumentLite[];
1239
- }
1240
- interface ListExternalFundingParams {
1241
- since: Date;
1242
- instruments: HttpTypes.InstrumentLite[];
1243
- }
1244
- declare abstract class BaseAccountSyncer<ExternalFill> implements AccountSyncer {
1245
- protected sdk: PearSDK;
1246
- protected connector: Connector;
1247
- protected account: TradeAccount;
1248
- protected credentials: SupportedCredentials;
1249
- protected demo: boolean;
1250
- protected throttle: SyncerThrottle | undefined;
1251
- constructor(config: AccountSyncerConfig);
1252
- /**
1253
- * Fetch the account's currently-open positions from the exchange, normalized
1254
- * to BASE units (contractSize applied). The exchange position API is the
1255
- * source of truth for current exposure. Account-wide; no symbol scoping.
1256
- * Hedge-mode (LONG/SHORT legs on one symbol) is rejected — skipped this cycle.
1257
- */
1258
- protected abstract listExternalPositions(params: ListExternalPositionsParams): Promise<HttpTypes.ExternalPosition[]>;
1259
- protected abstract listExternalFills(params: ListExternalFillsParams): Promise<HttpTypes.UnknownExternalFill[]>;
1260
- /**
1261
- * Fetch the account's historical funding payments since the watermark,
1262
- * applied-rate-only and mapped to instrument ids. Account-wide, no symbol scoping.
1263
- */
1264
- protected abstract listExternalFunding(params: ListExternalFundingParams): Promise<HttpTypes.FundingPaymentEntry[]>;
1265
- protected abstract isReduceOnly(fill: ExternalFill): boolean;
1266
- private loadPearState;
1267
- /**
1268
- * Global per-symbol cost-basis entry of existing open positions, derived from each
1269
- * position's assigned ledger and remaining exposure. One call per open position today —
1270
- * can collapse to a single endpoint later.
1271
- */
1272
- private loadEntryBySymbol;
1273
- private snapshotExchange;
1274
- private computeAndPostSync;
1275
- /**
1276
- * Pull historical funding payments since the funding watermark and post them.
1277
- * Independent of the fill sync cycle (`synchronizeFills`) — funding rows are
1278
- * immutable and upsert idempotently, so this is driven on its own cadence.
1279
- */
1280
- synchronizeFunding(): Promise<FundingSyncOutcome>;
1281
- synchronizeFills(): Promise<FillSyncOutcome>;
1282
- }
1283
-
1284
- interface BinanceRawUserTrade {
1285
- buyer: boolean;
1286
- commission: string;
1287
- commissionAsset: string;
1288
- id: number;
1289
- maker: boolean;
1290
- orderId: number;
1291
- price: string;
1292
- qty: string;
1293
- quoteQty: string;
1294
- realizedPnl: string;
1295
- side: 'BUY' | 'SELL';
1296
- positionSide: string;
1297
- symbol: string;
1298
- time: number;
1299
- }
1300
-
1301
- declare class BinanceAccountSyncer extends BaseAccountSyncer<BinanceRawUserTrade> {
1302
- private readonly creds;
1303
- constructor(config: AccountSyncerConfig);
1304
- protected listExternalPositions({ instruments, }: ListExternalPositionsParams): Promise<HttpTypes.ExternalPosition[]>;
1305
- protected listExternalFills({ since, instruments, openPositions, provisionalFills, }: ListExternalFillsParams): Promise<HttpTypes.UnknownExternalFill[]>;
1306
- protected listExternalFunding(_params: ListExternalFundingParams): Promise<HttpTypes.FundingPaymentEntry[]>;
1307
- protected isReduceOnly(rawFill: BinanceRawUserTrade): boolean;
1308
- private collectRequestedInstrumentIds;
1309
- private mapOrdersBySymbolOrderId;
1310
- private orderKey;
1311
- }
1312
-
1313
- interface BybitRawExecution {
1314
- symbol: string;
1315
- orderId: string;
1316
- orderLinkId: string;
1317
- side: 'Buy' | 'Sell';
1318
- execFee: string;
1319
- execId: string;
1320
- execPrice: string;
1321
- execQty: string;
1322
- execTime: string;
1323
- execType: string;
1324
- closedSize: string;
1325
- }
1326
-
1327
- declare class BybitAccountSyncer extends BaseAccountSyncer<BybitRawExecution> {
1328
- private readonly creds;
1329
- constructor(config: AccountSyncerConfig);
1330
- protected listExternalPositions({ instruments, }: ListExternalPositionsParams): Promise<HttpTypes.ExternalPosition[]>;
1331
- protected listExternalFills({ since }: ListExternalFillsParams): Promise<HttpTypes.UnknownExternalFill[]>;
1332
- protected listExternalFunding(_params: ListExternalFundingParams): Promise<HttpTypes.FundingPaymentEntry[]>;
1333
- protected isReduceOnly(rawFill: BybitRawExecution): boolean;
1334
- }
1335
-
1336
- declare function createAccountSyncer(exchange: Connector, config: AccountSyncerConfig): AccountSyncer;
1337
-
1338
- type UserFillsByTimeResponse = {
1339
- /** Asset symbol. */
1340
- coin: string;
1341
- /**
1342
- * Price.
1343
- * @pattern ^[0-9]+(\.[0-9]+)?$
1344
- */
1345
- px: string;
1346
- /**
1347
- * Size.
1348
- * @pattern ^[0-9]+(\.[0-9]+)?$
1349
- */
1350
- sz: string;
1351
- /** Order side ("B" = Bid/Buy, "A" = Ask/Sell). */
1352
- side: 'B' | 'A';
1353
- /** Timestamp when the trade occurred (in ms since epoch). */
1354
- time: number;
1355
- /**
1356
- * Start position size.
1357
- * @pattern ^-?[0-9]+(\.[0-9]+)?$
1358
- */
1359
- startPosition: string;
1360
- /** Direction indicator for frontend display. */
1361
- dir: string;
1362
- /**
1363
- * Realized PnL.
1364
- * @pattern ^-?[0-9]+(\.[0-9]+)?$
1365
- */
1366
- closedPnl: string;
1367
- /**
1368
- * L1 transaction hash.
1369
- * @pattern ^0x[a-fA-F0-9]{64}$
1370
- */
1371
- hash: `0x${string}`;
1372
- /** Order ID. */
1373
- oid: number;
1374
- /** Indicates if the fill was a taker order. */
1375
- crossed: boolean;
1376
- /**
1377
- * Fee charged or rebate received (negative indicates rebate).
1378
- * @pattern ^-?[0-9]+(\.[0-9]+)?$
1379
- */
1380
- fee: string;
1381
- /**
1382
- * Optional fee charged by the UI builder.
1383
- * @pattern ^-?[0-9]+(\.[0-9]+)?$
1384
- */
1385
- builderFee?: string;
1386
- /** Unique transaction identifier for a partial fill of an order. */
1387
- tid: number;
1388
- /** Token in which the fee is denominated (e.g., "USDC"). */
1389
- feeToken: string;
1390
- /** ID of the TWAP. */
1391
- twapId: number | null;
1392
- /**
1393
- * Client Order ID.
1394
- * @pattern ^0x[a-fA-F0-9]{32}$
1395
- */
1396
- cloid?: `0x${string}`;
1397
- /** Liquidation details. */
1398
- liquidation?: {
1399
- /**
1400
- * Address of the liquidated user.
1401
- * @pattern ^0x[a-fA-F0-9]{40}$
1402
- */
1403
- liquidatedUser?: `0x${string}`;
1404
- /**
1405
- * Mark price at the time of liquidation.
1406
- * @pattern ^[0-9]+(\.[0-9]+)?$
1407
- */
1408
- markPx: string;
1409
- /** Liquidation method. */
1410
- method: 'market' | 'backstop';
1411
- };
1412
- };
1413
-
1414
- type HyperliquidRawFill = UserFillsByTimeResponse;
1415
- declare class HyperliquidAccountSyncer extends BaseAccountSyncer<HyperliquidRawFill> {
1416
- private readonly address;
1417
- private readonly perpDexNames;
1418
- constructor(config: AccountSyncerConfig);
1419
- protected listExternalPositions({ instruments, }: ListExternalPositionsParams): Promise<HttpTypes.ExternalPosition[]>;
1420
- protected listExternalFills({ since, instruments, }: ListExternalFillsParams): Promise<HttpTypes.UnknownExternalFill[]>;
1421
- protected listExternalFunding({ since, instruments, }: ListExternalFundingParams): Promise<HttpTypes.FundingPaymentEntry[]>;
1422
- protected isReduceOnly(rawFill: HyperliquidRawFill): boolean;
1423
- /** Fetch the perp-dex descriptors and reduce them to unique dex names ('' = the main dex). */
1424
- private fetchPerpDexNames;
1425
- /**
1426
- * Route one info request through the optional throttle seam: gate before the
1427
- * call, report the response size after, surface a failure before it propagates.
1428
- */
1429
- private fetchInfoGated;
1430
- }
1431
-
1432
- type RawFill$1 = LighterRawTrade;
1433
- /** The syncer config narrowed to the deployments this syncer serves. */
1434
- type LighterAccountSyncerConfig = AccountSyncerConfig & {
1435
- connector: LighterConnector;
1436
- };
1437
- declare class LighterAccountSyncer extends BaseAccountSyncer<RawFill$1> {
1438
- /**
1439
- * Narrows the connector the base constructor already assigned from the config. Declared, not
1440
- * assigned: the deployment has exactly one source, so no caller can hand in a second value.
1441
- */
1442
- protected connector: LighterConnector;
1443
- private readonly accountIndex;
1444
- private readonly apiKeyIndex;
1445
- private readonly apiPrivateKey;
1446
- constructor(config: LighterAccountSyncerConfig);
1447
- /** Returns this account's shared Lighter auth token. */
1448
- private retrieveAuthToken;
1449
- protected listExternalPositions({ instruments, }: ListExternalPositionsParams): Promise<HttpTypes.ExternalPosition[]>;
1450
- protected listExternalFills({ since, instruments, }: ListExternalFillsParams): Promise<HttpTypes.UnknownExternalFill[]>;
1451
- protected listExternalFunding({ since, instruments, }: ListExternalFundingParams): Promise<HttpTypes.FundingPaymentEntry[]>;
1452
- protected isReduceOnly(rawFill: RawFill$1): boolean;
1453
- private getAccountSide;
1454
- /** The client order id on our side of the fill, or null when Lighter reports none. */
1455
- private getClientOrderId;
1456
- private isMaker;
1457
- private getPositionSizeBefore;
1458
- /** Signed like the rate: positive is a cost, a negative rate a maker rebate (#748). */
1459
- private getTradeFee;
1460
- /** The integrator's cut, which the wire carries unsigned. */
1461
- private getIntegratorFee;
1462
- /** Prevents testnet reads from silently minting a mainnet auth token. */
1463
- private assertAuthenticatedSyncAvailable;
1464
- private feeTickToAmount;
1465
- }
1466
-
1467
- interface OkxRawFill {
1468
- instType: string;
1469
- instId: string;
1470
- tradeId: string;
1471
- ordId: string;
1472
- clOrdId: string;
1473
- billId: string;
1474
- fillPx: string;
1475
- fillSz: string;
1476
- side: 'buy' | 'sell';
1477
- posSide: string;
1478
- execType: string;
1479
- fee: string;
1480
- feeCcy: string;
1481
- fillTime: string;
1482
- ts: string;
1483
- }
1484
-
1485
- type RawFill = OkxRawFill;
1486
- declare class OkxAccountSyncer extends BaseAccountSyncer<RawFill> {
1487
- private readonly creds;
1488
- constructor(config: AccountSyncerConfig);
1489
- protected listExternalPositions({ instruments, }: ListExternalPositionsParams): Promise<HttpTypes.ExternalPosition[]>;
1490
- protected listExternalFills({ since, instruments, }: ListExternalFillsParams): Promise<HttpTypes.UnknownExternalFill[]>;
1491
- protected listExternalFunding(_params: ListExternalFundingParams): Promise<HttpTypes.FundingPaymentEntry[]>;
1492
- protected isReduceOnly(rawFill: RawFill): boolean;
1493
- private contractsToBase;
1494
- }
1495
-
1496
1154
  /**
1497
1155
  * The account balance a consumer receives, as one discriminated union over `accountMode`.
1498
1156
  *
@@ -3095,8 +2753,6 @@ declare function createAccountTracker(exchange: Connector, config: CreateAccount
3095
2753
  declare class ExchangesSDK {
3096
2754
  private sdk;
3097
2755
  private demo;
3098
- private throttle;
3099
- private hyperliquidPerpDexNames;
3100
2756
  constructor(config: ExchangesSDKConfig);
3101
2757
  /** Value public trading holdings and open PnL without connecting or retrieving credentials. */
3102
2758
  tradingEquity(account: PublicExchangeAccount): Promise<TradingEquity>;
@@ -3119,9 +2775,8 @@ declare class ExchangesSDK {
3119
2775
  snapshot(tradeAccountId: string): Promise<AccountSnapshot>;
3120
2776
  snapshotAssets(tradeAccountId: string, coins: string[]): Promise<AssetSnapshotMap>;
3121
2777
  createHelper<E extends ExchangeHelperExchange>(exchange: E): ExchangeHelperMap[E];
3122
- createSyncer(connection: ExchangeConnection): AccountSyncer;
3123
2778
  private buildTracker;
3124
2779
  private fetchCredentials;
3125
2780
  }
3126
2781
 
3127
- 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 };
2782
+ export { ACCOUNT_MODE_LABELS, ASSET_DECIMALS, AccountBalance, AccountBalanceCore, type AccountHealthStatus, AccountMode, type AccountPosition, type AccountSnapshot, type AccountStatus, type AccountTierCallback, type AccountTracker, type AccountTrackerConfig, type AccountWarningReason, type ApiKey, type ApproveIntegratorParams, type ApproveIntegratorResult, AssetId, type AssetSnapshotMap, type BalanceCallback, BaseAccountTracker, BaseWs, BinanceAccountTracker, type BinanceAccountTrackerConfig, BinanceExchangeWs, BinanceMultiAssetBalance, BinanceSingleAssetBalance, BinanceUserDataWs, type BinanceUserDataWsConfig, BinanceWsApi, type BinanceWsApiConfig, 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 FunxyzAccountState, type FunxyzAsset, type FunxyzDepositAddressParams, type FunxyzDepositAddressResult, type FunxyzDepositCredit, type FunxyzDepositParams, type FunxyzDepositResult, type FunxyzDepositSettlement, type FunxyzDepositSource, type FunxyzMarket, 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, 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, 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, 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 TrackedAssetCallback, type TrackedAssetInfo, TradingEquity, type WalletClientWithAccount, type WithdrawParams, type WithdrawResult, type WsMessage, createAccountTracker, createExchangeWs, createHyperliquidHelper, createLighterHelper, createLighterRhcHelper, findAvailableApiKeyIndex, getAssetDecimals, getLighterNativeUsdcAddress, listFunxyzTransferableChains, parseCollateralAmount, readFunxyzChainSource, readFunxyzMinimumUsd, retrieveLighterAuthToken, usdcAbi };
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './client';
2
2
  export * from './helper';
3
3
  export * from './sdk';
4
- export * from './syncer';
5
4
  export * from './tracker';
6
5
  export * from './types';
package/dist/sdk.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { configureProxy } from '@pear-protocol/utils';
2
2
  import { createExchangeHelper } from './helper/factory';
3
3
  import { checkAccountStatus } from './status';
4
- import { createAccountSyncer } from './syncer';
5
4
  import { createAccountTracker } from './tracker';
6
5
  import { PublicExchangeAccount } from './tracker/equity';
7
6
 
@@ -13,13 +12,9 @@ class ExchangesSDK {
13
12
  }
14
13
  sdk;
15
14
  demo;
16
- throttle;
17
- hyperliquidPerpDexNames;
18
15
  constructor(config) {
19
16
  this.sdk = config.sdk;
20
17
  this.demo = config.demo ?? false;
21
- this.throttle = config.throttle;
22
- this.hyperliquidPerpDexNames = config.hyperliquidPerpDexNames;
23
18
  if (config.proxy) configureProxy(config.proxy);
24
19
  }
25
20
  /** Value public trading holdings and open PnL without connecting or retrieving credentials. */
@@ -107,17 +102,6 @@ class ExchangesSDK {
107
102
  });
108
103
  }
109
104
  }
110
- createSyncer(connection) {
111
- return createAccountSyncer(connection.connector, {
112
- sdk: this.sdk,
113
- connector: connection.connector,
114
- account: connection.account,
115
- credentials: connection.credentials,
116
- demo: this.demo,
117
- throttle: this.throttle,
118
- hyperliquidPerpDexNames: this.hyperliquidPerpDexNames
119
- });
120
- }
121
105
  buildTracker(connection) {
122
106
  return createAccountTracker(connection.connector, {
123
107
  // Lighter's tier read is authenticated, and Core is what mints the token for it.
@@ -19,11 +19,9 @@ function checkAccountStatus(exchange, config) {
19
19
  case "lighter":
20
20
  case "lighter_rhc":
21
21
  return checkLighterAccountStatus(config, exchange);
22
- default: {
23
- const _exhaustive = exchange;
24
- throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
25
- }
26
22
  }
23
+ const unsupported = exchange;
24
+ throw new Error(`Unsupported exchange: ${String(unsupported)}`);
27
25
  }
28
26
  __name(checkAccountStatus, "checkAccountStatus");
29
27
 
@@ -25,9 +25,6 @@ function toWithdrawable(raw, coins) {
25
25
  }
26
26
  __name(toWithdrawable, "toWithdrawable");
27
27
  function buildBalance(raw, accountMode, withdrawable, timestamp) {
28
- if (accountMode === null) {
29
- return null;
30
- }
31
28
  const core = {
32
29
  totalEquity: decimalOrNull(raw.totalEquity),
33
30
  withdrawableBalance: withdrawable.total,
@@ -37,6 +34,8 @@ function buildBalance(raw, accountMode, withdrawable, timestamp) {
37
34
  timestamp
38
35
  };
39
36
  switch (accountMode) {
37
+ case null:
38
+ return null;
40
39
  case "bybit:isolatedMargin":
41
40
  return {
42
41
  accountMode,
@@ -89,10 +89,9 @@ function emptyClearinghouseSummary() {
89
89
  }
90
90
  __name(emptyClearinghouseSummary, "emptyClearinghouseSummary");
91
91
  function mapBalance(context) {
92
- if (!context.accountType) {
93
- return null;
94
- }
95
92
  switch (context.accountType) {
93
+ case null:
94
+ return null;
96
95
  case HyperliquidAccountType.DEFAULT:
97
96
  case HyperliquidAccountType.DISABLED:
98
97
  return mapStandardBalance(context);
@@ -111,11 +110,10 @@ function mapTradingEquity(mode, spot, prices, states, timestamp) {
111
110
  if (valuation.unpricedCoins.length > 0) {
112
111
  throw new Error(`Cannot price Hyperliquid holdings: ${valuation.unpricedCoins.join(", ")}`);
113
112
  }
114
- if (mode === null) {
115
- throw new Error("Unsupported Hyperliquid account mode");
116
- }
117
113
  let equity = parse(valuation.equity);
118
114
  switch (mode) {
115
+ case null:
116
+ throw new Error("Unsupported Hyperliquid account mode");
119
117
  case HyperliquidAccountType.UNIFIED_ACCOUNT:
120
118
  case HyperliquidAccountType.PORTFOLIO_MARGIN:
121
119
  break;
@@ -80,11 +80,9 @@ function createAccountTracker(exchange, config) {
80
80
  account: config.account,
81
81
  credentials: config.credentials
82
82
  });
83
- default: {
84
- const _exhaustive = exchange;
85
- throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
86
- }
87
83
  }
84
+ const unsupported = exchange;
85
+ throw new Error(`Unsupported exchange: ${String(unsupported)}`);
88
86
  }
89
87
  __name(createAccountTracker, "createAccountTracker");
90
88
 
@@ -38,11 +38,10 @@ function mergeRawCoins(existing, incoming) {
38
38
  }
39
39
  __name(mergeRawCoins, "mergeRawCoins");
40
40
  function buildBalance(raw, accountMode, withdrawable, timestamp) {
41
- if (accountMode === null) {
42
- return null;
43
- }
44
41
  const perCollateral = toCollateralRows(raw.details ?? [], withdrawable.byCurrency);
45
42
  switch (accountMode) {
43
+ case null:
44
+ return null;
46
45
  case "okx:spot":
47
46
  return {
48
47
  accountMode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/exchanges-sdk",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Pear Protocol Exchanges SDK",
5
5
  "private": false,
6
6
  "type": "module",
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@nktkas/hyperliquid": "0.33.2",
31
- "@pear-protocol/core-sdk": "^2.16.0",
32
- "@pear-protocol/types": "^2.24.0",
33
- "@pear-protocol/utils": "^1.6.0",
31
+ "@pear-protocol/core-sdk": "^2.18.0",
32
+ "@pear-protocol/types": "^2.27.0",
33
+ "@pear-protocol/utils": "^1.7.0",
34
34
  "bignumber.js": "^11.1.1",
35
35
  "partysocket": "^1.0.3",
36
36
  "viem": "^2.48.8",