@pear-protocol/exchanges-sdk 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -176,9 +176,17 @@ declare class HyperliquidExchangeWs extends ExchangeWs {
176
176
  }): Promise<HyperliquidExchangeWs>;
177
177
  }
178
178
 
179
+ /**
180
+ * The connector values that are deployments of the Lighter stack. The deployments share the
181
+ * protocol but nothing else — hosts, account indices, and market indices are all per-deployment —
182
+ * so every Lighter code path in this SDK names the deployment it reads instead of assuming one.
183
+ */
184
+ type LighterConnector = Extract<Connector, 'lighter' | 'lighter_rhc'>;
185
+
179
186
  declare class LighterWs extends BaseWs {
187
+ private readonly connector;
180
188
  private readonly demo;
181
- constructor(demo?: boolean);
189
+ constructor(connector: LighterConnector, demo?: boolean);
182
190
  protected getWsUrl(): string;
183
191
  protected getPingIntervalMs(): number;
184
192
  protected buildPingMessage(): WsMessage;
@@ -188,10 +196,13 @@ declare class LighterWs extends BaseWs {
188
196
 
189
197
  declare class LighterExchangeWs extends ExchangeWs {
190
198
  main: LighterWs;
191
- readonly exchange: "lighter";
192
- constructor(main: LighterWs);
199
+ readonly exchange: LighterConnector;
200
+ /** Binds the socket bundle to the deployment that opened it, so consumers can tell them apart. */
201
+ constructor(exchange: LighterConnector, main: LighterWs);
193
202
  protected connections(): BaseWs[];
194
- static create(config?: {
203
+ /** Opens the deployment's stream and returns the bundle only once it is connected. */
204
+ static create(config: {
205
+ connector: LighterConnector;
195
206
  demo: boolean;
196
207
  }): Promise<LighterExchangeWs>;
197
208
  }
@@ -227,6 +238,7 @@ type ExchangeWsByConnector = {
227
238
  okx: OkxExchangeWs;
228
239
  hyperliquid: HyperliquidExchangeWs;
229
240
  lighter: LighterExchangeWs;
241
+ lighter_rhc: LighterExchangeWs;
230
242
  };
231
243
  type CreateExchangeWsConfig = {
232
244
  demo: boolean;
@@ -405,7 +417,7 @@ type LighterAuthCredentials = {
405
417
  apiPrivateKey: string;
406
418
  };
407
419
  /** Returns a live token while coalescing concurrent signing requests. */
408
- declare function retrieveLighterAuthToken(sdk: PearSDK, credentials: LighterAuthCredentials, demo: boolean): Promise<string>;
420
+ declare function retrieveLighterAuthToken(sdk: PearSDK, connector: LighterConnector, credentials: LighterAuthCredentials, demo: boolean): Promise<string>;
409
421
 
410
422
  type WalletClientWithAccount = WalletClient<Transport, Chain | undefined, Account>;
411
423
 
@@ -458,6 +470,13 @@ declare const usdcAbi: readonly [{
458
470
  /** Names native USDC for a source chain this SDK can transfer from safely. */
459
471
  declare function getLighterNativeUsdcAddress(chainId: number): `0x${string}` | undefined;
460
472
 
473
+ /**
474
+ * Asset indices on Lighter's Robinhood Chain deployment that this SDK names. Only the collateral is
475
+ * needed today — RHC's equity assets are read by index and shown as such until a flow needs them.
476
+ */
477
+ declare const LighterRhcAssetId: {
478
+ readonly USDG: 3;
479
+ };
461
480
  declare const AssetId: {
462
481
  readonly ETH: 1;
463
482
  readonly LIT: 2;
@@ -476,7 +495,30 @@ declare const RouteType: {
476
495
  };
477
496
  type RouteType = (typeof RouteType)[keyof typeof RouteType];
478
497
  declare const MIN_LIGHTER_CCTP_DEPOSIT_USDC = "5";
479
- declare const MIN_LIGHTER_FAST_WITHDRAW_USDC = "4";
498
+ /**
499
+ * Fast-withdraw floor per deployment, in that deployment's own collateral.
500
+ *
501
+ * Lighter documents the zkLighter floor as "Fast Withdrawal (USDC only, 4 USDC minimum)" and
502
+ * publishes no floor for Robinhood Chain; `/api/v1/fastwithdraw/info` reports `withdraw_limit`
503
+ * and `max_withdrawal_amount` but no minimum, so the value cannot be read from the venue either.
504
+ * Robinhood Chain therefore carries zkLighter's number until the venue states its own — correcting
505
+ * it is one line here, and the venue rejects a short transfer regardless.
506
+ */
507
+ declare const MIN_LIGHTER_FAST_WITHDRAW_COLLATERAL: Record<LighterConnector, string>;
508
+ declare const MIN_LIGHTER_RHC_DEPOSIT_USDG = "1";
509
+ /**
510
+ * Robinhood Chain's EVM chain id — the chain a deposit is sent on, not the id the signer signs
511
+ * under. Read from Lighter's own deposit network list at runtime; this constant only lets a caller
512
+ * configure a wallet for the chain before any read has happened.
513
+ */
514
+ declare const LIGHTER_RHC_CHAIN_ID = 4663;
515
+ /**
516
+ * USDG on Robinhood Chain, as `assetDetails` reports its `l1_address` for asset index 3, verified
517
+ * on chain to answer `USDG` and six decimals. A deposit transfers this token and nothing else.
518
+ */
519
+ declare const LIGHTER_RHC_USDG_ADDRESS: "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168";
520
+ /** USDG carries six decimals, matching the venue's own units. */
521
+ declare const LIGHTER_RHC_USDG_DECIMALS = 6;
480
522
  /** Lighter L2/base-amount precision (`assetDetails.decimals`). */
481
523
  declare const L2_ASSET_DECIMALS: Record<number, number>;
482
524
  /**
@@ -640,7 +682,7 @@ type CctpDepositParams = {
640
682
  connectedAddress: `0x${string}` | undefined;
641
683
  /** A `chainId` from `listCctpDepositNetworks()`; the connected wallet must already be on it. */
642
684
  chainId: number;
643
- /** Positive human-readable USDC amount with at most six fractional digits. */
685
+ /** Positive human-readable collateral amount (USDC on zkLighter, USDG on RHC), at most six fractional digits. */
644
686
  amount: string;
645
687
  /** Supplies wallet transport operations without coupling the SDK to Wagmi. */
646
688
  wallet: LighterDepositWalletAdapter;
@@ -749,6 +791,65 @@ type FunxyzDepositAddressResult = {
749
791
  credits: FunxyzDepositCredit;
750
792
  };
751
793
  type LighterDepositAddressResult = CctpDepositAddressResult | FunxyzDepositAddressResult;
794
+ /**
795
+ * What minting a Robinhood Chain deposit address needs.
796
+ *
797
+ * No route tag and no chain id: Robinhood Chain offers exactly one deposit method on exactly one
798
+ * chain, so there is nothing to select. A second of either would be a new contract, not a new field.
799
+ */
800
+ type LighterRhcDepositAddressParams = {
801
+ /** The L1 owner whose Lighter account receives funds, not necessarily the sender. */
802
+ ownerAddress: `0x${string}`;
803
+ };
804
+ /**
805
+ * Wallet transport a Robinhood Chain deposit borrows from its caller.
806
+ *
807
+ * Separate from `LighterDepositWalletAdapter`, which reads native USDC: this deployment moves USDG
808
+ * on its own chain, so the token is named rather than inferred from a chain id.
809
+ */
810
+ type LighterRhcDepositWallet = {
811
+ /** Reads one ERC-20 balance for an owner on one chain. */
812
+ readTokenBalance: (chainId: number, token: `0x${string}`, ownerAddress: `0x${string}`) => Promise<bigint>;
813
+ /** Moves the connector to the chain and returns a wallet client bound to it. */
814
+ retrieveWallet: (chainId: number) => Promise<WalletClientWithAccount>;
815
+ /** Resolves once the chain has mined the transfer, throwing when it reverted. */
816
+ confirmTransaction: (chainId: number, txHash: string) => Promise<void>;
817
+ };
818
+ /** What sending USDG from the connected wallet into a Robinhood Chain account needs. */
819
+ type LighterRhcDepositParams = {
820
+ /** The L1 owner whose Lighter account receives funds. */
821
+ ownerAddress: `0x${string}`;
822
+ /** The wallet currently connected in the browser, which must be the owner. */
823
+ connectedAddress: `0x${string}` | undefined;
824
+ /** Positive human-readable USDG amount with at most six fractional digits. */
825
+ amount: string;
826
+ wallet: LighterRhcDepositWallet;
827
+ /** Receives transfer-confirmation and Lighter-settlement state changes. */
828
+ onProgress: (progress: LighterDepositProgress) => void;
829
+ /** Cancels the settlement watch; the transfer itself is already on chain. */
830
+ signal?: AbortSignal;
831
+ /** Caps the settlement watch; defaults to the shared one-hour limit. */
832
+ settlementTimeoutMs?: number;
833
+ };
834
+ /** What a submitted Robinhood Chain deposit reports back. */
835
+ type LighterRhcDepositResult = {
836
+ txHash: string;
837
+ /** The address the transfer was sent to, which keeps crediting this owner. */
838
+ intentAddress: `0x${string}`;
839
+ chainId: number;
840
+ };
841
+ /**
842
+ * The address USDG is sent to, and the chain it must arrive on.
843
+ *
844
+ * Persistent, unlike a CCTP intent: Lighter binds it to the address that generated it and returns
845
+ * the same one on every request, so there is no expiry for a caller to race.
846
+ */
847
+ type LighterRhcDepositAddressResult = {
848
+ /** Send at least `MIN_LIGHTER_RHC_DEPOSIT_USDG` in USDG on `chainId` to this address. */
849
+ intentAddress: `0x${string}`;
850
+ /** The chain the address credits from, as Lighter's own deposit network list names it. */
851
+ chainId: number;
852
+ };
752
853
  type WithdrawParams = {
753
854
  accountIndex: number;
754
855
  assetId: number;
@@ -890,6 +991,34 @@ interface LighterHelper {
890
991
  /** Reads one page of the owner's referral record, including the code that referred them. */
891
992
  getUserReferrals(params: LighterUserReferralsParams): Promise<LighterUserReferrals>;
892
993
  }
994
+ /**
995
+ * Everything both Lighter deployments share.
996
+ *
997
+ * What it leaves out is what zkLighter wires to its own bridges and Ethereum contracts: the CCTP
998
+ * and Fun.xyz deposit routes, and the gateway withdrawal. Robinhood Chain runs none of them, so
999
+ * they are absent at the type level rather than refused at runtime.
1000
+ */
1001
+ type LighterSharedHelper = Omit<LighterHelper, 'listCctpDepositNetworks' | 'deposit' | 'createDepositAddress' | 'withdraw' | 'listUdaDeposits'>;
1002
+ /**
1003
+ * The helper surface for Lighter's Robinhood Chain deployment.
1004
+ *
1005
+ * The shared surface plus the one deposit method RHC has of its own. Its on-chain withdrawal still
1006
+ * has no equivalent here: that is RHC's own gateway contract, which this SDK does not yet call.
1007
+ */
1008
+ type LighterRhcHelper = LighterSharedHelper & {
1009
+ /**
1010
+ * Mints the persistent address that credits this owner's Robinhood Chain account.
1011
+ *
1012
+ * Deliberately not zkLighter's route-tagged `createDepositAddress`: the two deployments share no
1013
+ * deposit route, so a caller cannot pass a `cctp` or `funxyz` route here by mistake.
1014
+ */
1015
+ createDepositAddress(params: LighterRhcDepositAddressParams): Promise<LighterRhcDepositAddressResult>;
1016
+ /**
1017
+ * Sends USDG from the connected wallet into this owner's account, and follows it until Lighter
1018
+ * registers the account. Also not zkLighter's route-tagged `deposit`: Robinhood Chain has one way in.
1019
+ */
1020
+ deposit(params: LighterRhcDepositParams): Promise<LighterRhcDepositResult>;
1021
+ };
893
1022
  type LighterLookupResult = {
894
1023
  mainAccountIndex: number;
895
1024
  subAccountIndexes: number[];
@@ -926,10 +1055,19 @@ declare const MIN_USER_API_KEY_INDEX = 4;
926
1055
  declare const MAX_API_KEY_INDEX = 254;
927
1056
  declare function findAvailableApiKeyIndex(apiKeys: ReadonlyArray<Pick<ApiKey, 'api_key_index'>>): number;
928
1057
  declare function createLighterHelper(sdk: PearSDK, demo?: boolean): LighterHelper;
1058
+ /**
1059
+ * The helper for Lighter's Robinhood Chain deployment: the shared surface plus its own deposit.
1060
+ *
1061
+ * zkLighter's bridge deposits and gateway withdrawal stay absent — they are wired to contracts
1062
+ * Robinhood Chain does not run. RHC funds instead through an intent address, and its on-chain
1063
+ * withdrawal is still the venue's own front end.
1064
+ */
1065
+ declare function createLighterRhcHelper(sdk: PearSDK, demo?: boolean): LighterRhcHelper;
929
1066
 
930
1067
  type ExchangeHelperMap = {
931
1068
  hyperliquid: HyperliquidHelper;
932
1069
  lighter: LighterHelper;
1070
+ lighter_rhc: LighterRhcHelper;
933
1071
  };
934
1072
  type ExchangeHelperExchange = keyof ExchangeHelperMap;
935
1073
 
@@ -1167,11 +1305,20 @@ declare class HyperliquidAccountSyncer extends BaseAccountSyncer<HyperliquidRawF
1167
1305
  }
1168
1306
 
1169
1307
  type RawFill$1 = LighterRawTrade;
1308
+ /** The syncer config narrowed to the deployments this syncer serves. */
1309
+ type LighterAccountSyncerConfig = AccountSyncerConfig & {
1310
+ connector: LighterConnector;
1311
+ };
1170
1312
  declare class LighterAccountSyncer extends BaseAccountSyncer<RawFill$1> {
1313
+ /**
1314
+ * Narrows the connector the base constructor already assigned from the config. Declared, not
1315
+ * assigned: the deployment has exactly one source, so no caller can hand in a second value.
1316
+ */
1317
+ protected connector: LighterConnector;
1171
1318
  private readonly accountIndex;
1172
1319
  private readonly apiKeyIndex;
1173
1320
  private readonly apiPrivateKey;
1174
- constructor(config: AccountSyncerConfig);
1321
+ constructor(config: LighterAccountSyncerConfig);
1175
1322
  /** Returns this account's shared Lighter auth token. */
1176
1323
  private retrieveAuthToken;
1177
1324
  protected listExternalPositions({ instruments, }: ListExternalPositionsParams): Promise<HttpTypes.ExternalPosition[]>;
@@ -2236,9 +2383,17 @@ declare const LighterUnifiedBalance: z.ZodObject<{
2236
2383
  }, z.core.$strip>;
2237
2384
  type LighterUnifiedBalance = z.infer<typeof LighterUnifiedBalance>;
2238
2385
 
2386
+ /**
2387
+ * The collateral asset each Lighter deployment margins perps in, as the venue names it in account
2388
+ * payloads. Everything else about the balance model is identical across deployments.
2389
+ */
2390
+ declare const LIGHTER_QUOTE_ASSETS: Record<LighterConnector, string>;
2391
+
2239
2392
  type LighterAccountTrackerConfig = AccountTrackerConfig & {
2240
2393
  /** Null leaves the tier unread: `/accountLimits` is authenticated and only Core mints a token. */
2241
2394
  sdk: PearSDK | null;
2395
+ /** The Lighter deployment this account lives on; hosts and collateral follow it. */
2396
+ connector: LighterConnector;
2242
2397
  account: TradeAccount;
2243
2398
  credentials: SupportedCredentials;
2244
2399
  };
@@ -2246,6 +2401,8 @@ type LighterAccountTrackerConfig = AccountTrackerConfig & {
2246
2401
  type AccountTierCallback = (tier: LighterAccountTier | null) => void;
2247
2402
  declare class LighterAccountTracker extends BaseAccountTracker {
2248
2403
  private readonly sdk;
2404
+ private readonly connector;
2405
+ private readonly quoteAsset;
2249
2406
  private readonly accountIdentifier;
2250
2407
  private readonly apiKeyIndex;
2251
2408
  private readonly apiPrivateKey;
@@ -2621,4 +2778,4 @@ declare class ExchangesSDK {
2621
2778
  private fetchCredentials;
2622
2779
  }
2623
2780
 
2624
- 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, 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, HyperliquidDexState, HyperliquidExchangeWs, type HyperliquidHelper, HyperliquidPortfolioMarginBalance, HyperliquidPortfolioMarginCollateral, HyperliquidStandardBalance, HyperliquidUnifiedBalance, HyperliquidWs, type IntegratorApprovalRequirements, L2_ASSET_DECIMALS, LIGHTER_NATIVE_USDC_ADDRESSES, LIGHTER_USDC_DECIMALS, LighterAccountSyncer, type LighterAccountTier, LighterAccountTracker, type LighterAccountTrackerConfig, type LighterApplyReferralCodeParams, type LighterAuthCredentials, LighterClassicBalance, 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, 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_USDC, MIN_USER_API_KEY_INDEX, MarginMode, type MessageListener, OkxAccountSyncer, OkxAccountTracker, type OkxAccountTrackerConfig, OkxExchangeWs, OkxFuturesBalance, OkxMultiCurrencyMarginBalance, OkxPortfolioMarginBalance, OkxSpotBalance, OkxWs, type OkxWsConfig, type OpenListener, type PositionsCallback, 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, findAvailableApiKeyIndex, getAssetDecimals, getLighterNativeUsdcAddress, listFunxyzTransferableChains, readFunxyzChainSource, readFunxyzMinimumUsd, retrieveLighterAuthToken, usdcAbi };
2781
+ 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, 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, 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, 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 };
package/dist/sdk.js CHANGED
@@ -63,6 +63,12 @@ class ExchangesSDK {
63
63
  sdk: this.sdk,
64
64
  demo: this.demo
65
65
  });
66
+ case "lighter_rhc":
67
+ return createExchangeHelper({
68
+ exchange: "lighter_rhc",
69
+ sdk: this.sdk,
70
+ demo: this.demo
71
+ });
66
72
  }
67
73
  }
68
74
  createSyncer(connection) {
@@ -17,7 +17,8 @@ function checkAccountStatus(exchange, config) {
17
17
  case "hyperliquid":
18
18
  return checkHyperliquidAccountStatus(config);
19
19
  case "lighter":
20
- return checkLighterAccountStatus(config);
20
+ case "lighter_rhc":
21
+ return checkLighterAccountStatus(config, exchange);
21
22
  default: {
22
23
  const _exhaustive = exchange;
23
24
  throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
@@ -5,7 +5,7 @@ import { warningStatus } from '../base';
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- async function checkLighterAccountStatus(config) {
8
+ async function checkLighterAccountStatus(config, connector) {
9
9
  const reasons = [];
10
10
  const options = config.statusOptions;
11
11
  const integratorAccountIndex = options?.integratorAccountIndex;
@@ -20,25 +20,25 @@ async function checkLighterAccountStatus(config) {
20
20
  reasons.push("lighter_api_key_invalid");
21
21
  } else {
22
22
  try {
23
- const token = await retrieveLighterAuthToken(config.sdk, {
23
+ const token = await retrieveLighterAuthToken(config.sdk, connector, {
24
24
  accountIndex,
25
25
  apiKeyIndex: credentials.api_key_index,
26
26
  apiPrivateKey: credentials.api_private_key
27
27
  }, config.demo);
28
- await fetchAccountMetadata(accountIndex, token, config.demo);
28
+ await fetchAccountMetadata(accountIndex, token, connector, config.demo);
29
29
  } catch {
30
30
  reasons.push("lighter_api_key_invalid");
31
31
  }
32
32
  }
33
33
  if (integratorAccountIndex !== void 0 && integratorMinPerpsMakerFee !== void 0 && integratorMinPerpsTakerFee !== void 0) {
34
34
  try {
35
- const token = await retrieveLighterAuthToken(config.sdk, {
35
+ const token = await retrieveLighterAuthToken(config.sdk, connector, {
36
36
  accountIndex,
37
37
  apiKeyIndex: credentials.api_key_index,
38
38
  apiPrivateKey: credentials.api_private_key
39
39
  }, config.demo);
40
40
  const helper = createExchangeHelper({
41
- exchange: "lighter",
41
+ exchange: connector,
42
42
  sdk: config.sdk,
43
43
  demo: config.demo
44
44
  });
@@ -17,7 +17,11 @@ function createAccountSyncer(exchange, config) {
17
17
  case "hyperliquid":
18
18
  return new HyperliquidAccountSyncer(config);
19
19
  case "lighter":
20
- return new LighterAccountSyncer(config);
20
+ case "lighter_rhc":
21
+ return new LighterAccountSyncer({
22
+ ...config,
23
+ connector: exchange
24
+ });
21
25
  default: {
22
26
  const _exhaustive = exchange;
23
27
  throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
@@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- function toFundingPaymentEntries(events, instrumentIds) {
5
+ function toFundingPaymentEntries(events, instrumentIds, connector) {
6
6
  return events.reduce((entries, event) => {
7
7
  const instrumentId = event.market_id.toString();
8
8
  if (!instrumentIds.has(instrumentId)) {
@@ -13,7 +13,7 @@ function toFundingPaymentEntries(events, instrumentIds) {
13
13
  const signedSize = event.position_side === "short" ? unsignedSize.negated() : unsignedSize;
14
14
  const fundingPerUnit = signedSize.isZero() ? "0" : new BigNumber(event.change).div(signedSize).toFixed();
15
15
  entries.push({
16
- connector: "lighter",
16
+ connector,
17
17
  instrumentId,
18
18
  fundingRate: event.rate,
19
19
  notional: event.change,
@@ -23,7 +23,7 @@ class LighterAccountSyncer extends BaseAccountSyncer {
23
23
  }
24
24
  /** Returns this account's shared Lighter auth token. */
25
25
  async retrieveAuthToken() {
26
- return retrieveLighterAuthToken(this.sdk, {
26
+ return retrieveLighterAuthToken(this.sdk, this.connector, {
27
27
  accountIndex: this.accountIndex,
28
28
  apiKeyIndex: this.apiKeyIndex,
29
29
  apiPrivateKey: this.apiPrivateKey
@@ -36,7 +36,7 @@ class LighterAccountSyncer extends BaseAccountSyncer {
36
36
  instrument.precision.quantity.contractSize
37
37
  ]));
38
38
  const token = await this.retrieveAuthToken();
39
- const response = await fetchAccount(this.accountIndex, token, this.demo, this.throttle);
39
+ const response = await fetchAccount(this.accountIndex, token, this.connector, this.demo, this.throttle);
40
40
  const rawPositions = response.accounts?.[0]?.positions ?? [];
41
41
  return rawPositions.reduce((positions, rawPosition) => {
42
42
  const instrumentId = rawPosition.market_id.toString();
@@ -59,7 +59,7 @@ class LighterAccountSyncer extends BaseAccountSyncer {
59
59
  async listExternalFills({ since, instruments }) {
60
60
  this.assertAuthenticatedSyncAvailable();
61
61
  const token = await this.retrieveAuthToken();
62
- const trades = await fetchTradesSince(this.accountIndex, token, since, this.demo, this.throttle);
62
+ const trades = await fetchTradesSince(this.accountIndex, token, since, this.connector, this.demo, this.throttle);
63
63
  const instrumentIds = new Set(instruments.map((instrument) => instrument.id));
64
64
  return trades.toSorted((a, b) => a.timestamp - b.timestamp).reduce((fills, rawFill) => {
65
65
  const instrumentId = rawFill.market_id.toString();
@@ -71,7 +71,7 @@ class LighterAccountSyncer extends BaseAccountSyncer {
71
71
  if (!accountSide) return fills;
72
72
  const side = accountSide === "ask" ? "SELL" : "BUY";
73
73
  fills.push({
74
- connector: "lighter",
74
+ connector: this.connector,
75
75
  exchangeFillId: rawFill.trade_id_str ?? rawFill.trade_id.toString(),
76
76
  cloid: this.getClientOrderId(rawFill, accountSide),
77
77
  symbol: instrumentId,
@@ -92,9 +92,9 @@ class LighterAccountSyncer extends BaseAccountSyncer {
92
92
  async listExternalFunding({ since, instruments }) {
93
93
  this.assertAuthenticatedSyncAvailable();
94
94
  const token = await this.retrieveAuthToken();
95
- const fundingEvents = await fetchPositionFundingSince(this.accountIndex, token, since, this.demo, this.throttle);
95
+ const fundingEvents = await fetchPositionFundingSince(this.accountIndex, token, since, this.connector, this.demo, this.throttle);
96
96
  const instrumentIds = new Set(instruments.map((instrument) => instrument.id));
97
- return toFundingPaymentEntries(fundingEvents, instrumentIds);
97
+ return toFundingPaymentEntries(fundingEvents, instrumentIds, this.connector);
98
98
  }
99
99
  isReduceOnly(rawFill) {
100
100
  if (rawFill.type === "liquidation" || rawFill.type === "deleverage" || rawFill.type === "market-settlement") {
@@ -15,6 +15,7 @@ export { BinanceMultiAssetBalance, BinanceSingleAssetBalance } from './binance/b
15
15
  export { BybitIsolatedMarginBalance, BybitPortfolioMarginBalance, BybitRegularMarginBalance } from './bybit/balance';
16
16
  export { HyperliquidDexState, HyperliquidPortfolioMarginBalance, HyperliquidPortfolioMarginCollateral, HyperliquidStandardBalance, HyperliquidUnifiedBalance } from './hyperliquid/balance';
17
17
  export { LighterClassicBalance, LighterUnifiedBalance } from './lighter/balance';
18
+ export { LIGHTER_QUOTE_ASSETS } from './lighter/const';
18
19
  export { OkxFuturesBalance, OkxMultiCurrencyMarginBalance, OkxPortfolioMarginBalance, OkxSpotBalance } from './okx/balance';
19
20
  export * from './types';
20
21
 
@@ -48,8 +49,10 @@ function createAccountTracker(exchange, config) {
48
49
  credentials: config.credentials
49
50
  });
50
51
  case "lighter":
52
+ case "lighter_rhc":
51
53
  return new LighterAccountTracker({
52
54
  sdk: config.sdk,
55
+ connector: exchange,
53
56
  demo: config.demo,
54
57
  onError: config.onError,
55
58
  account: config.account,
@@ -1,3 +1,6 @@
1
- const QUOTE_ASSET = "USDC";
1
+ const LIGHTER_QUOTE_ASSETS = {
2
+ lighter: "USDC",
3
+ lighter_rhc: "USDG"
4
+ };
2
5
 
3
- export { QUOTE_ASSET };
6
+ export { LIGHTER_QUOTE_ASSETS };
@@ -1,6 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { positionKey } from '../utils';
3
- import { QUOTE_ASSET } from './const';
4
3
  import { LighterAccountType } from './types';
5
4
 
6
5
  var __defProp = Object.defineProperty;
@@ -19,8 +18,8 @@ function mapLiveBalance(stats, assets, positions, markets, timestamp) {
19
18
  const heldAssets = Array.from(assets);
20
19
  const risks = toPositionRisks(openPositions, markets.perpByMarketId);
21
20
  const crossEquity = toDecimal(stats.cross.portfolio_value);
22
- const equity = toEquitySplit(heldAssets, markets.spotPriceBySymbol);
23
- const perCollateral = toCollateralRows(heldAssets, stats.total.available_balance);
21
+ const equity = toEquitySplit(heldAssets, markets.spotPriceBySymbol, markets.quoteAsset);
22
+ const perCollateral = toCollateralRows(heldAssets, stats.total.available_balance, markets.quoteAsset);
24
23
  const crossMaintenance = asMarginRequirement(sumMaintenance(risks, "cross"));
25
24
  const isolatedMaintenance = asMarginRequirement(sumMaintenance(risks, "isolated"));
26
25
  return toLighterBalance({
@@ -51,8 +50,8 @@ function mapRestBalance(account, markets, timestamp) {
51
50
  const crossEquity = toDecimal(account.cross_asset_value);
52
51
  const crossMaintenance = toDecimal(account.cross_maintenance_margin_requirement);
53
52
  const isolatedMaintenance = asMarginRequirement(sumMaintenance(risks, "isolated"));
54
- const equity = toEquitySplit(assets, markets.spotPriceBySymbol);
55
- const perCollateral = toCollateralRows(assets, account.available_balance);
53
+ const equity = toEquitySplit(assets, markets.spotPriceBySymbol, markets.quoteAsset);
54
+ const perCollateral = toCollateralRows(assets, account.available_balance, markets.quoteAsset);
56
55
  return toLighterBalance({
57
56
  accountMode: ACCOUNT_MODE_BY_TYPE[toLighterAccountType(account.account_trading_mode)],
58
57
  equity,
@@ -119,10 +118,10 @@ function mapMarketDefaultAssetInfo(market) {
119
118
  };
120
119
  }
121
120
  __name(mapMarketDefaultAssetInfo, "mapMarketDefaultAssetInfo");
122
- function buildSpotPriceIndex(spotMarkets) {
121
+ function buildSpotPriceIndex(spotMarkets, quoteAsset) {
123
122
  const priceBySymbol = /* @__PURE__ */ new Map([
124
123
  [
125
- QUOTE_ASSET,
124
+ quoteAsset,
126
125
  "1"
127
126
  ]
128
127
  ]);
@@ -206,11 +205,11 @@ function toLighterBalance(figures) {
206
205
  }
207
206
  }
208
207
  __name(toLighterBalance, "toLighterBalance");
209
- function toEquitySplit(assets, priceBySymbol) {
208
+ function toEquitySplit(assets, priceBySymbol, quoteAsset) {
210
209
  let perpetuals = new BigNumber(0);
211
210
  let spot = new BigNumber(0);
212
211
  for (const asset of assets) {
213
- if (asset.symbol === QUOTE_ASSET) {
212
+ if (asset.symbol === quoteAsset) {
214
213
  perpetuals = sumOf([
215
214
  perpetuals,
216
215
  toDecimal(asset.margin_balance)
@@ -240,14 +239,14 @@ function toEquitySplit(assets, priceBySymbol) {
240
239
  };
241
240
  }
242
241
  __name(toEquitySplit, "toEquitySplit");
243
- function toCollateralRows(assets, availableBalance) {
242
+ function toCollateralRows(assets, availableBalance, quoteAsset) {
244
243
  const rows = [];
245
244
  for (const asset of assets) {
246
245
  const held = heldAmount(asset);
247
246
  if (held === null || held.isZero()) {
248
247
  continue;
249
248
  }
250
- rows.push(toCollateralRow(asset.symbol, held, availableBalance));
249
+ rows.push(toCollateralRow(asset.symbol, held, availableBalance, quoteAsset));
251
250
  }
252
251
  rows.sort(byAssetName);
253
252
  return rows;
@@ -260,8 +259,8 @@ function heldAmount(asset) {
260
259
  ]);
261
260
  }
262
261
  __name(heldAmount, "heldAmount");
263
- function toCollateralRow(asset, held, availableBalance) {
264
- if (asset !== QUOTE_ASSET) {
262
+ function toCollateralRow(asset, held, availableBalance, quoteAsset) {
263
+ if (asset !== quoteAsset) {
265
264
  return {
266
265
  asset,
267
266
  equity: held.toFixed(),