@pear-protocol/symmio-client 0.3.11 → 0.3.12

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.
@@ -8552,12 +8552,16 @@ declare function useSymmBalances(params: {
8552
8552
  }): _tanstack_react_query.UseQueryResult<node_modules__pear_protocol_symm_core_dist_types.BalanceInfoResponse, Error>;
8553
8553
 
8554
8554
  type SymmTradeAuthParams = {
8555
+ accountAddress?: Address;
8555
8556
  address?: Address;
8556
8557
  chainId?: number;
8557
8558
  };
8558
8559
 
8559
8560
  type OpenBasketMutationRequest = WithOptionalAuthToken<OpenBasketPositionRequest>;
8560
- type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest>;
8561
+ type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest> & {
8562
+ accountAddress?: Address;
8563
+ chainId?: number;
8564
+ };
8561
8565
  type CloseAllPositionsMutationRequest = WithOptionalAuthToken<Parameters<NonNullable<ReturnType<typeof useSymmContext>['symmCoreClient']>['positions']['closeAll']>[0]>;
8562
8566
  type UpdatePositionMutationRequest = WithOptionalAuthToken<UpdatePositionRequest>;
8563
8567
  /**
@@ -8575,9 +8579,7 @@ declare function useSymmClosePositionMutation(paramsOrOptions?: SymmTradeAuthPar
8575
8579
  mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
8576
8580
  }, maybeOptions?: {
8577
8581
  mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
8578
- }): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, Omit<ClosePositionRequest, "authToken"> & {
8579
- authToken?: string | undefined;
8580
- }, unknown>;
8582
+ }): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, ClosePositionMutationRequest, unknown>;
8581
8583
  /**
8582
8584
  * Use case: Close all open positions for the provided request scope.
8583
8585
  */
@@ -8552,12 +8552,16 @@ declare function useSymmBalances(params: {
8552
8552
  }): _tanstack_react_query.UseQueryResult<node_modules__pear_protocol_symm_core_dist_types.BalanceInfoResponse, Error>;
8553
8553
 
8554
8554
  type SymmTradeAuthParams = {
8555
+ accountAddress?: Address;
8555
8556
  address?: Address;
8556
8557
  chainId?: number;
8557
8558
  };
8558
8559
 
8559
8560
  type OpenBasketMutationRequest = WithOptionalAuthToken<OpenBasketPositionRequest>;
8560
- type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest>;
8561
+ type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest> & {
8562
+ accountAddress?: Address;
8563
+ chainId?: number;
8564
+ };
8561
8565
  type CloseAllPositionsMutationRequest = WithOptionalAuthToken<Parameters<NonNullable<ReturnType<typeof useSymmContext>['symmCoreClient']>['positions']['closeAll']>[0]>;
8562
8566
  type UpdatePositionMutationRequest = WithOptionalAuthToken<UpdatePositionRequest>;
8563
8567
  /**
@@ -8575,9 +8579,7 @@ declare function useSymmClosePositionMutation(paramsOrOptions?: SymmTradeAuthPar
8575
8579
  mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
8576
8580
  }, maybeOptions?: {
8577
8581
  mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
8578
- }): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, Omit<ClosePositionRequest, "authToken"> & {
8579
- authToken?: string | undefined;
8580
- }, unknown>;
8582
+ }): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, ClosePositionMutationRequest, unknown>;
8581
8583
  /**
8582
8584
  * Use case: Close all open positions for the provided request scope.
8583
8585
  */
@@ -833,28 +833,54 @@ async function login(chainId, params) {
833
833
  var TOKEN_STORAGE_PREFIX = "symm_access_token";
834
834
  var TOKEN_STORAGE_VERSION = 1;
835
835
  function cacheKey(address, chainId) {
836
- return `${address}:${chainId}`;
836
+ return `${address.toLowerCase()}:${chainId}`;
837
837
  }
838
838
  function storageKey(address, chainId) {
839
839
  return `${TOKEN_STORAGE_PREFIX}:${TOKEN_STORAGE_VERSION}:${cacheKey(address, chainId)}`;
840
840
  }
841
+ function findStorageKey(address, chainId) {
842
+ const canonicalKey = storageKey(address, chainId);
843
+ if (typeof window === "undefined") return canonicalKey;
844
+ if (window.localStorage.getItem(canonicalKey) != null) {
845
+ return canonicalKey;
846
+ }
847
+ const normalizedKey = canonicalKey.toLowerCase();
848
+ for (let index = 0; index < window.localStorage.length; index += 1) {
849
+ const key = window.localStorage.key(index);
850
+ if (key?.toLowerCase() === normalizedKey) {
851
+ return key;
852
+ }
853
+ }
854
+ return canonicalKey;
855
+ }
856
+ function removeStoredTokenKeys(address, chainId) {
857
+ if (typeof window === "undefined") return;
858
+ const normalizedKey = storageKey(address, chainId).toLowerCase();
859
+ for (let index = window.localStorage.length - 1; index >= 0; index -= 1) {
860
+ const key = window.localStorage.key(index);
861
+ if (key?.toLowerCase() === normalizedKey) {
862
+ window.localStorage.removeItem(key);
863
+ }
864
+ }
865
+ }
841
866
  function getCachedTokenEntry(address, chainId) {
842
867
  if (typeof window === "undefined") return null;
868
+ const key = findStorageKey(address, chainId);
843
869
  try {
844
- const raw = window.localStorage.getItem(storageKey(address, chainId));
870
+ const raw = window.localStorage.getItem(key);
845
871
  if (!raw) return null;
846
872
  const parsed = JSON.parse(raw);
847
873
  if (!parsed || typeof parsed.token !== "string" || typeof parsed.expiresAt !== "number") {
848
- window.localStorage.removeItem(storageKey(address, chainId));
874
+ window.localStorage.removeItem(key);
849
875
  return null;
850
876
  }
851
877
  if (Date.now() >= parsed.expiresAt) {
852
- window.localStorage.removeItem(storageKey(address, chainId));
878
+ window.localStorage.removeItem(key);
853
879
  return null;
854
880
  }
855
881
  return parsed;
856
882
  } catch {
857
- window.localStorage.removeItem(storageKey(address, chainId));
883
+ window.localStorage.removeItem(key);
858
884
  return null;
859
885
  }
860
886
  }
@@ -869,9 +895,7 @@ function writeStoredToken(address, chainId, cached) {
869
895
  }
870
896
  }
871
897
  function clearCachedToken(address, chainId) {
872
- if (typeof window !== "undefined") {
873
- window.localStorage.removeItem(storageKey(address, chainId));
874
- }
898
+ removeStoredTokenKeys(address, chainId);
875
899
  }
876
900
  async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress, chainId, domain) {
877
901
  const resolvedDomain = domain ?? (typeof window !== "undefined" ? window.location.hostname : "localhost");
@@ -905,7 +929,7 @@ async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress
905
929
  return cachedToken;
906
930
  }
907
931
  function authStoreKey(accountAddress, chainId, signerAddress) {
908
- return `${accountAddress}:${chainId}:${signerAddress ?? ""}`;
932
+ return `${accountAddress.toLowerCase()}:${chainId}:${signerAddress?.toLowerCase() ?? ""}`;
909
933
  }
910
934
  function getEntryFromSnapshot(state, accountAddress, chainId, signerAddress) {
911
935
  const signerScoped = state.entries[authStoreKey(accountAddress, chainId, signerAddress)];
@@ -2346,14 +2370,15 @@ function splitTradeHookArgs(paramsOrOptions, options) {
2346
2370
  function useResolveTradeAuthToken(params = {}) {
2347
2371
  const context = useSymmContext();
2348
2372
  const address = params.address ?? context.address;
2373
+ const defaultAccountAddress = params.accountAddress ?? address;
2349
2374
  const chainId = params.chainId ?? context.chainId;
2350
2375
  return react.useCallback(
2351
- async (providedAuthToken, accountAddress, overrideChainId) => {
2376
+ async (providedAuthToken, requestAccountAddress, overrideChainId) => {
2352
2377
  const resolvedChainId = overrideChainId ?? chainId;
2353
2378
  if (providedAuthToken) {
2354
2379
  return providedAuthToken;
2355
2380
  }
2356
- const resolvedAccountAddress = accountAddress ?? address;
2381
+ const resolvedAccountAddress = requestAccountAddress ?? defaultAccountAddress;
2357
2382
  if (!resolvedAccountAddress) {
2358
2383
  return null;
2359
2384
  }
@@ -2367,7 +2392,7 @@ function useResolveTradeAuthToken(params = {}) {
2367
2392
  }
2368
2393
  return null;
2369
2394
  },
2370
- [address, chainId]
2395
+ [address, defaultAccountAddress, chainId]
2371
2396
  );
2372
2397
  }
2373
2398
 
@@ -25616,7 +25641,8 @@ function useSymmClosePositionMutation(paramsOrOptions, maybeOptions) {
25616
25641
  const typedRequest = request;
25617
25642
  const authToken = await resolveAuthToken(
25618
25643
  typedRequest.authToken,
25619
- typedRequest.accountAddress
25644
+ typedRequest.accountAddress,
25645
+ typedRequest.chainId
25620
25646
  );
25621
25647
  if (!authToken) {
25622
25648
  throw new Error("auth token is required to close a position");