@pear-protocol/exchanges-sdk 0.9.1 → 0.10.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.
@@ -63,9 +63,11 @@ __name(createCctpDepositIntentAddress, "createCctpDepositIntentAddress");
63
63
  async function fetchDepositHistory(params, demo = false) {
64
64
  const query = new URLSearchParams({
65
65
  account_index: params.accountIndex.toString(),
66
- l1_address: params.l1Address,
67
- filter: "all"
66
+ l1_address: params.l1Address
68
67
  });
68
+ if (params.cursor) {
69
+ query.set("cursor", params.cursor);
70
+ }
69
71
  const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/deposit/history?${query.toString()}`, params.authToken);
70
72
  const data = await readLighterResponse(response, "/deposit/history");
71
73
  const deposits = [];
@@ -88,9 +90,48 @@ async function fetchDepositHistory(params, demo = false) {
88
90
  l1TxHash: typeof deposit.l1_tx_hash === "string" ? deposit.l1_tx_hash : ""
89
91
  });
90
92
  }
91
- return deposits;
93
+ return {
94
+ deposits,
95
+ nextCursor: readHistoryCursor(data.cursor)
96
+ };
92
97
  }
93
98
  __name(fetchDepositHistory, "fetchDepositHistory");
99
+ async function fetchWithdrawHistory(params, demo = false) {
100
+ const query = new URLSearchParams({
101
+ account_index: params.accountIndex.toString()
102
+ });
103
+ if (params.cursor) {
104
+ query.set("cursor", params.cursor);
105
+ }
106
+ const response = await authenticatedLighterFetch(`${getLighterBaseUrl(demo)}/api/v1/withdraw/history?${query.toString()}`, params.authToken);
107
+ const data = await readLighterResponse(response, "/withdraw/history");
108
+ const withdraws = [];
109
+ for (const withdraw of data.withdraws ?? []) {
110
+ if (typeof withdraw !== "object" || withdraw === null) {
111
+ continue;
112
+ }
113
+ if (typeof withdraw.id !== "string" || typeof withdraw.amount !== "string" || !isLighterWithdrawStatus(withdraw.status) || !isLighterWithdrawType(withdraw.type)) {
114
+ continue;
115
+ }
116
+ if (typeof withdraw.timestamp !== "number" || !Number.isSafeInteger(withdraw.timestamp)) {
117
+ continue;
118
+ }
119
+ withdraws.push({
120
+ id: withdraw.id,
121
+ assetId: typeof withdraw.asset_id === "number" ? withdraw.asset_id : -1,
122
+ amount: withdraw.amount,
123
+ timestamp: withdraw.timestamp,
124
+ status: withdraw.status,
125
+ type: withdraw.type,
126
+ l1TxHash: typeof withdraw.l1_tx_hash === "string" ? withdraw.l1_tx_hash : ""
127
+ });
128
+ }
129
+ return {
130
+ withdraws,
131
+ nextCursor: readHistoryCursor(data.cursor)
132
+ };
133
+ }
134
+ __name(fetchWithdrawHistory, "fetchWithdrawHistory");
94
135
  async function fetchApiKeys(accountIndex, demo = false) {
95
136
  const url = `${getLighterBaseUrl(demo)}/api/v1/apikeys?account_index=${accountIndex}`;
96
137
  const response = await proxyFetch(url);
@@ -283,6 +324,38 @@ function isLighterDepositStatus(value) {
283
324
  return value === "failed" || value === "pending" || value === "completed" || value === "claimable";
284
325
  }
285
326
  __name(isLighterDepositStatus, "isLighterDepositStatus");
327
+ function isLighterWithdrawStatus(value) {
328
+ return value === "failed" || value === "pending" || value === "claimable" || value === "refunded" || value === "completed";
329
+ }
330
+ __name(isLighterWithdrawStatus, "isLighterWithdrawStatus");
331
+ function isLighterWithdrawType(value) {
332
+ return value === "secure" || value === "fast";
333
+ }
334
+ __name(isLighterWithdrawType, "isLighterWithdrawType");
335
+ function readHistoryCursor(cursor) {
336
+ if (typeof cursor !== "string" || cursor.length === 0) {
337
+ return null;
338
+ }
339
+ if (isSpentHistoryCursor(cursor)) {
340
+ return null;
341
+ }
342
+ return cursor;
343
+ }
344
+ __name(readHistoryCursor, "readHistoryCursor");
345
+ function isSpentHistoryCursor(cursor) {
346
+ let decoded;
347
+ try {
348
+ decoded = JSON.parse(atob(cursor));
349
+ } catch {
350
+ return false;
351
+ }
352
+ if (typeof decoded !== "object" || decoded === null) {
353
+ return false;
354
+ }
355
+ const indexes = Object.values(decoded).filter((value) => typeof value === "number");
356
+ return indexes.length > 0 && indexes.every((index) => index < 0);
357
+ }
358
+ __name(isSpentHistoryCursor, "isSpentHistoryCursor");
286
359
  async function readLighterResponse(response, endpoint, acceptedCodes = [
287
360
  200
288
361
  ]) {
@@ -302,4 +375,4 @@ async function readLighterResponse(response, endpoint, acceptedCodes = [
302
375
  }
303
376
  __name(readLighterResponse, "readLighterResponse");
304
377
 
305
- export { createCctpDepositIntentAddress, fetchAccount, fetchAccountLimits, fetchAccountMetadata, fetchAccountsByL1Address, fetchApiKeys, fetchAssetDetails, fetchDepositHistory, fetchDepositNetworks, fetchOrderBookDetails, fetchPositionFundingSince, fetchPublicAccount, fetchPublicOrderBookDetails, fetchTradesSince };
378
+ export { createCctpDepositIntentAddress, fetchAccount, fetchAccountLimits, fetchAccountMetadata, fetchAccountsByL1Address, fetchApiKeys, fetchAssetDetails, fetchDepositHistory, fetchDepositNetworks, fetchOrderBookDetails, fetchPositionFundingSince, fetchPublicAccount, fetchPublicOrderBookDetails, fetchTradesSince, fetchWithdrawHistory };
@@ -167,11 +167,12 @@ async function watchCctpDeposit(ownerAddress, txHash, watch, onProgress, sdk, de
167
167
  let deposits;
168
168
  try {
169
169
  const authToken = await retrieveLighterAuthToken(sdk, watch, demo);
170
- deposits = await fetchDepositHistory({
170
+ const page = await fetchDepositHistory({
171
171
  accountIndex: watch.accountIndex,
172
172
  l1Address: ownerAddress,
173
173
  authToken
174
174
  }, demo);
175
+ deposits = page.deposits;
175
176
  } catch {
176
177
  continue;
177
178
  }
@@ -5,6 +5,7 @@ import { resolveAssetDecimals } from './asset-decimals.helper';
5
5
  import { listCctpDepositNetworks } from './cctp-deposit.helper';
6
6
  import { createDepositAddressForRoute, depositThroughRoute } from './deposit.helper';
7
7
  import { writeWithdraw } from './ethereum';
8
+ import { readWithdrawHistory, readDepositHistory } from './history.helper';
8
9
  import { LIGHTER_ACCOUNT_NOT_REGISTERED_CODE, readOnboardingStatus } from './onboarding.helper';
9
10
  import { MIN_LIGHTER_FAST_WITHDRAW_USDC } from './types';
10
11
 
@@ -189,6 +190,14 @@ function createLighterHelper(sdk, demo = false) {
189
190
  return {
190
191
  txHash
191
192
  };
193
+ },
194
+ /** Reads one page of the account's deposit history, newest first. */
195
+ async getDepositHistory(params) {
196
+ return readDepositHistory(sdk, params, demo);
197
+ },
198
+ /** Reads one page of the account's withdrawal history, newest first. */
199
+ async getWithdrawHistory(params) {
200
+ return readWithdrawHistory(sdk, params, demo);
192
201
  }
193
202
  };
194
203
  return helper;
@@ -0,0 +1,26 @@
1
+ import { fetchDepositHistory, fetchWithdrawHistory } from '../../client/lighter/rest';
2
+ import { retrieveLighterAuthToken } from './auth-token.helper';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ async function readDepositHistory(sdk, params, demo) {
7
+ const authToken = await retrieveLighterAuthToken(sdk, params.credentials, demo);
8
+ return fetchDepositHistory({
9
+ accountIndex: params.credentials.accountIndex,
10
+ l1Address: params.l1Address,
11
+ authToken,
12
+ cursor: params.cursor
13
+ }, demo);
14
+ }
15
+ __name(readDepositHistory, "readDepositHistory");
16
+ async function readWithdrawHistory(sdk, params, demo) {
17
+ const authToken = await retrieveLighterAuthToken(sdk, params.credentials, demo);
18
+ return fetchWithdrawHistory({
19
+ accountIndex: params.credentials.accountIndex,
20
+ authToken,
21
+ cursor: params.cursor
22
+ }, demo);
23
+ }
24
+ __name(readWithdrawHistory, "readWithdrawHistory");
25
+
26
+ export { readDepositHistory, readWithdrawHistory };
package/dist/index.d.ts CHANGED
@@ -279,11 +279,46 @@ type LighterDeposit = {
279
279
  assetId: number;
280
280
  /** Human-readable amount Lighter credited; the intent record never carries this. */
281
281
  amount: string;
282
- /** Unix seconds since epoch, matching Lighter's deposit-history wire format. */
282
+ /** Unix MILLISECONDS since epoch. Lighter's OpenAPI example shows seconds; mainnet sends ms. */
283
283
  timestamp: number;
284
284
  status: LighterDepositStatus;
285
285
  l1TxHash: string;
286
286
  };
287
+ /** One page of deposits, newest first, and the cursor that reads the page before it. */
288
+ type LighterDepositPage = {
289
+ deposits: LighterDeposit[];
290
+ /** Null once Lighter holds no older page. */
291
+ nextCursor: string | null;
292
+ };
293
+ /**
294
+ * The states Lighter reports for a withdrawal.
295
+ *
296
+ * A secure withdrawal stops at `claimable` and never reads `completed`: reaching L1 is a separate
297
+ * claim Lighter usually makes on the owner's behalf, and the history does not report it. Read the
298
+ * mainnet contract's `getPendingBalance()` to learn whether a claimable withdrawal has been paid.
299
+ * Only a fast withdrawal through Arbitrum reaches `completed` here.
300
+ */
301
+ type LighterWithdrawStatus = 'failed' | 'pending' | 'claimable' | 'refunded' | 'completed';
302
+ /** Which withdrawal path carried the funds, which decides how far its status can travel. */
303
+ type LighterWithdrawType = 'secure' | 'fast';
304
+ /** One withdrawal in Lighter's per-account history, paid out or still in flight. */
305
+ type LighterWithdraw = {
306
+ id: string;
307
+ assetId: number;
308
+ /** Human-readable amount Lighter debited, in the asset's own units. */
309
+ amount: string;
310
+ /** Unix MILLISECONDS since epoch. Lighter's OpenAPI example shows seconds; mainnet sends ms. */
311
+ timestamp: number;
312
+ status: LighterWithdrawStatus;
313
+ type: LighterWithdrawType;
314
+ l1TxHash: string;
315
+ };
316
+ /** One page of withdrawals, newest first, and the cursor that reads the page before it. */
317
+ type LighterWithdrawPage = {
318
+ withdraws: LighterWithdraw[];
319
+ /** Null once Lighter holds no older page. */
320
+ nextCursor: string | null;
321
+ };
287
322
 
288
323
  /** Shares one live Lighter auth token per account without crossing rotated credentials. */
289
324
 
@@ -690,6 +725,20 @@ type FastWithdrawResult = {
690
725
  /** Integer USDC units Lighter charged on top of the amount. */
691
726
  fee: number;
692
727
  };
728
+ type LighterDepositHistoryParams = {
729
+ /** Signs the read, and its `accountIndex` names the account whose deposits come back. */
730
+ credentials: LighterAuthCredentials;
731
+ /** The L1 address owning that account; Lighter's deposit history requires both identifiers. */
732
+ l1Address: string;
733
+ /** The `nextCursor` of the page just read; omit to read the newest page. */
734
+ cursor?: string;
735
+ };
736
+ type LighterWithdrawHistoryParams = {
737
+ /** Signs the read, and its `accountIndex` names the account whose withdrawals come back. */
738
+ credentials: LighterAuthCredentials;
739
+ /** The `nextCursor` of the page just read; omit to read the newest page. */
740
+ cursor?: string;
741
+ };
693
742
  /**
694
743
  * The next action an L1 address must take before it can hold a Lighter trade account.
695
744
  *
@@ -721,6 +770,10 @@ interface LighterHelper {
721
770
  }>>;
722
771
  fastWithdraw(walletClient: WalletClientWithAccount, params: FastWithdrawParams): Promise<FastWithdrawResult>;
723
772
  withdraw(walletClient: WalletClientWithAccount, params: WithdrawParams): Promise<WithdrawResult>;
773
+ /** Reads one page of the account's deposit history, newest first. */
774
+ getDepositHistory(params: LighterDepositHistoryParams): Promise<LighterDepositPage>;
775
+ /** Reads one page of the account's withdrawal history, newest first. */
776
+ getWithdrawHistory(params: LighterWithdrawHistoryParams): Promise<LighterWithdrawPage>;
724
777
  }
725
778
  type LighterLookupResult = {
726
779
  mainAccountIndex: number;
@@ -2550,4 +2603,4 @@ declare class ExchangesSDK {
2550
2603
  private fetchCredentials;
2551
2604
  }
2552
2605
 
2553
- 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, BasketLeg, 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 CappedBasketLeg, 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 LighterAuthCredentials, LighterClassicBalance, type LighterDeposit, type LighterDepositAddressParams, type LighterDepositAddressResult, type LighterDepositCredit, type LighterDepositNetwork, type LighterDepositParams, type LighterDepositProgress, type LighterDepositResult, type LighterDepositWalletAdapter, LighterExchangeWs, type LighterHelper, type LighterLookupResult, type LighterOnboardingStatus, LighterUnifiedBalance, 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 MaxBasketSizeCalculation, MaxBasketSizeInput, MaxBasketSizeResult, 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 TrackedAssetCallback, type TrackedAssetInfo, type WalletClientWithAccount, type WithdrawParams, type WithdrawResult, type WsMessage, computeMaxBasketSize, createAccountSyncer, createAccountTracker, createExchangeWs, createHyperliquidHelper, createLighterHelper, findAvailableApiKeyIndex, getAssetDecimals, getLighterNativeUsdcAddress, listFunxyzTransferableChains, readFunxyzChainSource, readFunxyzMinimumUsd, retrieveLighterAuthToken, usdcAbi };
2606
+ 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, BasketLeg, 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 CappedBasketLeg, 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 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, LighterUnifiedBalance, 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 MaxBasketSizeCalculation, MaxBasketSizeInput, MaxBasketSizeResult, 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 TrackedAssetCallback, type TrackedAssetInfo, type WalletClientWithAccount, type WithdrawParams, type WithdrawResult, type WsMessage, computeMaxBasketSize, createAccountSyncer, createAccountTracker, createExchangeWs, createHyperliquidHelper, createLighterHelper, findAvailableApiKeyIndex, getAssetDecimals, getLighterNativeUsdcAddress, listFunxyzTransferableChains, readFunxyzChainSource, readFunxyzMinimumUsd, retrieveLighterAuthToken, usdcAbi };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/exchanges-sdk",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Pear Protocol Exchanges SDK",
5
5
  "private": false,
6
6
  "type": "module",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@pear-protocol/core-sdk": "^1.19.0",
31
- "@pear-protocol/types": "^1.29.0",
31
+ "@pear-protocol/types": "^1.30.0",
32
32
  "@pear-protocol/utils": "^0.5.3",
33
33
  "bignumber.js": "^11.1.1",
34
34
  "partysocket": "^1.0.3",