@pear-protocol/symmio-client 0.2.5 → 0.2.6

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.
@@ -22,13 +22,13 @@ var symmKeys = {
22
22
  accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
23
23
  accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
24
24
  accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
25
- accountData: (address, chainId) => ["symm", "accountData", address, chainId],
25
+ accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
26
26
  signature: (address, chainId) => ["symm", "signature", address, chainId],
27
- approval: (owner, spender, chainId) => ["symm", "approval", owner, spender, chainId],
27
+ approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
28
28
  balances: (address, chainId) => ["symm", "balances", address, chainId],
29
- positions: (address, chainId) => ["symm", "positions", address, chainId],
30
- openOrders: (address, chainId) => ["symm", "openOrders", address, chainId],
31
- tradeHistory: (address, chainId) => ["symm", "tradeHistory", address, chainId],
29
+ positions: (params) => ["symm", "positions", params],
30
+ openOrders: (params) => ["symm", "openOrders", params],
31
+ tradeHistory: (params) => ["symm", "tradeHistory", params],
32
32
  tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
33
33
  tpslOrdersList: (params) => ["symm", "tpslOrders", params],
34
34
  twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
@@ -42,7 +42,7 @@ var symmKeys = {
42
42
  fundingRates: (chainId) => ["symm", "fundingRates", chainId],
43
43
  fundingPayments: (params) => ["symm", "fundingPayments", params],
44
44
  fundingHistory: (params) => ["symm", "fundingHistory", params],
45
- portfolio: (address, chainId) => ["symm", "portfolio", address, chainId],
45
+ portfolio: (params) => ["symm", "portfolio", params],
46
46
  notifications: (address, chainId) => ["symm", "notifications", address, chainId],
47
47
  unreadCount: (address, chainId) => ["symm", "unreadCount", address, chainId],
48
48
  availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
@@ -58,10 +58,8 @@ function asUnsubscribeFn(value) {
58
58
  return typeof value === "function" ? value : null;
59
59
  }
60
60
  function useSymmWs(params) {
61
- const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
62
61
  const queryClient = useQueryClient();
63
- const { accountAddress } = params;
64
- const chainId = params.chainId ?? ctxChainId;
62
+ const { symmCoreClient, accountAddress, chainId } = params;
65
63
  const [isConnected, setIsConnected] = useState(false);
66
64
  useEffect(() => {
67
65
  if (!symmCoreClient || !accountAddress) {
@@ -76,19 +74,19 @@ function useSymmWs(params) {
76
74
  unsubscribers.push(removeOnConnect, removeOnDisconnect);
77
75
  const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {
78
76
  queryClient.invalidateQueries({
79
- queryKey: symmKeys.positions(accountAddress, chainId)
77
+ queryKey: ["symm", "positions"]
80
78
  });
81
79
  }));
82
80
  if (positionsUnsub) unsubscribers.push(positionsUnsub);
83
81
  const openOrdersUnsub = asUnsubscribeFn(ws.subscribeToOpenOrders(addr, chainId, () => {
84
82
  queryClient.invalidateQueries({
85
- queryKey: symmKeys.openOrders(accountAddress, chainId)
83
+ queryKey: ["symm", "openOrders"]
86
84
  });
87
85
  }));
88
86
  if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
89
87
  const tradesUnsub = asUnsubscribeFn(ws.subscribeToTrades(addr, chainId, () => {
90
88
  queryClient.invalidateQueries({
91
- queryKey: symmKeys.tradeHistory(accountAddress, chainId)
89
+ queryKey: ["symm", "tradeHistory"]
92
90
  });
93
91
  }));
94
92
  if (tradesUnsub) unsubscribers.push(tradesUnsub);
@@ -127,10 +125,10 @@ function useSymmWs(params) {
127
125
  if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
128
126
  const executionsUnsub = asUnsubscribeFn(ws.subscribeToExecutions(addr, chainId, () => {
129
127
  queryClient.invalidateQueries({
130
- queryKey: symmKeys.positions(accountAddress, chainId)
128
+ queryKey: ["symm", "positions"]
131
129
  });
132
130
  queryClient.invalidateQueries({
133
- queryKey: symmKeys.portfolio(accountAddress, chainId)
131
+ queryKey: ["symm", "portfolio"]
134
132
  });
135
133
  }));
136
134
  if (executionsUnsub) unsubscribers.push(executionsUnsub);
@@ -165,7 +163,7 @@ function SymmProvider({
165
163
  });
166
164
  }, [chainId, symmCoreConfig.apiUrl, symmCoreConfig.wsUrl]);
167
165
  const resolvedAuthToken = authToken ?? accessToken;
168
- useSymmWs({ chainId });
166
+ useSymmWs({ symmCoreClient, accountAddress: address, chainId });
169
167
  const value = useMemo(
170
168
  () => ({
171
169
  symmCoreClient,
@@ -1396,7 +1394,7 @@ function useSymmApproval(params) {
1396
1394
  const internalEnabled = !!publicClient && !!owner && !!resolvedSpender && !!resolvedToken;
1397
1395
  const approvalQuery = useQuery({
1398
1396
  ...params.query,
1399
- queryKey: symmKeys.approval(owner, resolvedSpender, chainId),
1397
+ queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken),
1400
1398
  queryFn: async () => {
1401
1399
  const [allowanceVal, balanceVal] = await Promise.all([
1402
1400
  getAllowance(publicClient, resolvedToken, owner, resolvedSpender),
@@ -1414,7 +1412,7 @@ function useSymmApproval(params) {
1414
1412
  },
1415
1413
  onSuccess: () => {
1416
1414
  queryClient.invalidateQueries({
1417
- queryKey: symmKeys.approval(owner, resolvedSpender, chainId)
1415
+ queryKey: symmKeys.approval(owner, resolvedSpender, chainId, resolvedToken)
1418
1416
  });
1419
1417
  }
1420
1418
  });
@@ -24549,7 +24547,7 @@ function useSymmAccountData(params) {
24549
24547
  const internalEnabled = !!symmCoreClient && !!address;
24550
24548
  const query = useQuery({
24551
24549
  ...params.query,
24552
- queryKey: symmKeys.accountData(address, chainId),
24550
+ queryKey: symmKeys.accountData(address, chainId, upnl),
24553
24551
  queryFn: () => symmCoreClient.accounts.getData({
24554
24552
  address,
24555
24553
  chainId,
@@ -24639,13 +24637,17 @@ function useSymmTrade() {
24639
24637
  }
24640
24638
  function useSymmPositions(params) {
24641
24639
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
24642
- const { accountAddress, mainAddress, address } = params;
24643
- const resolvedAddress = address ?? mainAddress;
24640
+ const { accountAddress, address } = params;
24641
+ const resolvedAddress = accountAddress ? void 0 : address;
24644
24642
  const chainId = params.chainId ?? ctxChainId;
24645
24643
  const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
24646
24644
  const query = useQuery({
24647
24645
  ...params.query,
24648
- queryKey: symmKeys.positions(accountAddress ?? resolvedAddress, chainId),
24646
+ queryKey: symmKeys.positions({
24647
+ accountAddress,
24648
+ address: resolvedAddress,
24649
+ chainId
24650
+ }),
24649
24651
  queryFn: () => symmCoreClient.positions.getOpen({
24650
24652
  accountAddress,
24651
24653
  address: resolvedAddress,
@@ -24661,15 +24663,19 @@ function useSymmPositions(params) {
24661
24663
  }
24662
24664
  function useSymmOpenOrders(params) {
24663
24665
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
24664
- const { accountAddress, mainAddress } = params;
24666
+ const { accountAddress, address } = params;
24667
+ const resolvedAddress = accountAddress ? void 0 : address;
24665
24668
  const chainId = params.chainId ?? ctxChainId;
24666
- const internalEnabled = !!symmCoreClient && !!(accountAddress || mainAddress);
24669
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
24667
24670
  const query = useQuery({
24668
24671
  ...params.query,
24669
- queryKey: symmKeys.openOrders(accountAddress ?? mainAddress, chainId),
24672
+ queryKey: symmKeys.openOrders({
24673
+ accountAddress,
24674
+ address: resolvedAddress,
24675
+ chainId
24676
+ }),
24670
24677
  queryFn: () => symmCoreClient.orders.list({
24671
- address: accountAddress,
24672
- mainAddress,
24678
+ address: accountAddress ?? resolvedAddress,
24673
24679
  chainId
24674
24680
  }),
24675
24681
  enabled: internalEnabled && (params.query?.enabled ?? true)
@@ -24682,17 +24688,25 @@ function useSymmOpenOrders(params) {
24682
24688
  }
24683
24689
  function useSymmTradeHistory(params) {
24684
24690
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
24685
- const { accountAddress, mainAddress } = params;
24691
+ const { accountAddress, address } = params;
24692
+ const resolvedAddress = accountAddress ? void 0 : address;
24686
24693
  const chainId = params.chainId ?? ctxChainId;
24687
- const internalEnabled = !!symmCoreClient && !!(accountAddress || mainAddress);
24694
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
24688
24695
  const query = useQuery({
24689
24696
  ...params.query,
24690
- queryKey: symmKeys.tradeHistory(accountAddress ?? mainAddress, chainId),
24691
- queryFn: () => symmCoreClient.positions.getTradeHistory({
24697
+ queryKey: symmKeys.tradeHistory({
24692
24698
  accountAddress,
24693
- mainAddress,
24699
+ address: resolvedAddress,
24694
24700
  chainId
24695
24701
  }),
24702
+ queryFn: () => {
24703
+ const request = {
24704
+ accountAddress,
24705
+ address: resolvedAddress,
24706
+ chainId
24707
+ };
24708
+ return symmCoreClient.positions.getTradeHistory(request);
24709
+ },
24696
24710
  enabled: internalEnabled && (params.query?.enabled ?? true)
24697
24711
  });
24698
24712
  return {
@@ -24728,12 +24742,12 @@ function useSymmTpsl() {
24728
24742
  }
24729
24743
  function useSymmTpslOrders(params) {
24730
24744
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
24731
- const { accountAddress, mainAddress, positionId, type, status } = params;
24745
+ const { accountAddress, address, positionId, type, status } = params;
24746
+ const resolvedAddress = accountAddress ? void 0 : address;
24732
24747
  const chainId = params.chainId ?? ctxChainId;
24733
- const internalEnabled = !!symmCoreClient && !!(accountAddress || mainAddress || positionId);
24748
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress || positionId);
24734
24749
  const request = {
24735
- address: accountAddress,
24736
- mainAddress,
24750
+ address: accountAddress ?? resolvedAddress,
24737
24751
  positionId,
24738
24752
  type,
24739
24753
  status,
@@ -24743,7 +24757,7 @@ function useSymmTpslOrders(params) {
24743
24757
  ...params.query,
24744
24758
  queryKey: symmKeys.tpslOrdersList({
24745
24759
  accountAddress,
24746
- mainAddress,
24760
+ address: resolvedAddress,
24747
24761
  positionId,
24748
24762
  type,
24749
24763
  status,
@@ -24762,15 +24776,15 @@ function useSymmTpslOrders(params) {
24762
24776
  function useSymmTwap(params) {
24763
24777
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
24764
24778
  const queryClient = useQueryClient();
24765
- const { accountAddress, mainAddress } = params;
24779
+ const { accountAddress, address } = params;
24780
+ const resolvedAddress = accountAddress ? void 0 : address;
24766
24781
  const chainId = params.chainId ?? ctxChainId;
24767
- const internalEnabled = !!symmCoreClient && !!(accountAddress || mainAddress);
24782
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
24768
24783
  const query = useQuery({
24769
24784
  ...params.query,
24770
- queryKey: symmKeys.twapOrders(accountAddress ?? mainAddress, chainId),
24785
+ queryKey: symmKeys.twapOrders(accountAddress ?? resolvedAddress, chainId),
24771
24786
  queryFn: () => symmCoreClient.orders.getTwapOrders({
24772
- address: accountAddress,
24773
- mainAddress,
24787
+ address: accountAddress ?? resolvedAddress,
24774
24788
  chainId
24775
24789
  }),
24776
24790
  enabled: internalEnabled && (params.query?.enabled ?? true)
@@ -24839,12 +24853,12 @@ function useSymmTriggerConfig(params) {
24839
24853
  }
24840
24854
  function useSymmTriggerOrders(params) {
24841
24855
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
24842
- const { accountAddress, mainAddress, status, limit, offset } = params;
24856
+ const { accountAddress, address, status, limit, offset } = params;
24857
+ const resolvedAddress = accountAddress ? void 0 : address;
24843
24858
  const chainId = params.chainId ?? ctxChainId;
24844
- const internalEnabled = !!symmCoreClient && !!(accountAddress || mainAddress);
24859
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
24845
24860
  const request = {
24846
- address: accountAddress,
24847
- mainAddress,
24861
+ address: accountAddress ?? resolvedAddress,
24848
24862
  chainId,
24849
24863
  status,
24850
24864
  limit,
@@ -24854,7 +24868,7 @@ function useSymmTriggerOrders(params) {
24854
24868
  ...params.query,
24855
24869
  queryKey: symmKeys.triggerOrders({
24856
24870
  accountAddress,
24857
- mainAddress,
24871
+ address: resolvedAddress,
24858
24872
  chainId,
24859
24873
  status,
24860
24874
  limit,
@@ -25071,17 +25085,25 @@ function useSymmFundingPayments(params) {
25071
25085
  }
25072
25086
  function useSymmPortfolio(params) {
25073
25087
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
25074
- const { accountAddress, mainAddress } = params;
25088
+ const { accountAddress, address } = params;
25089
+ const resolvedAddress = accountAddress ? void 0 : address;
25075
25090
  const chainId = params.chainId ?? ctxChainId;
25076
- const internalEnabled = !!symmCoreClient && !!(accountAddress || mainAddress);
25091
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
25077
25092
  const query = useQuery({
25078
25093
  ...params.query,
25079
- queryKey: symmKeys.portfolio(accountAddress ?? mainAddress, chainId),
25080
- queryFn: () => symmCoreClient.portfolio.getMetrics({
25094
+ queryKey: symmKeys.portfolio({
25081
25095
  accountAddress,
25082
- mainAddress,
25096
+ address: resolvedAddress,
25083
25097
  chainId
25084
25098
  }),
25099
+ queryFn: () => {
25100
+ const request = {
25101
+ accountAddress,
25102
+ address: resolvedAddress,
25103
+ chainId
25104
+ };
25105
+ return symmCoreClient.portfolio.getMetrics(request);
25106
+ },
25085
25107
  enabled: internalEnabled && (params.query?.enabled ?? true)
25086
25108
  });
25087
25109
  return {