@pear-protocol/symmio-client 0.3.0 → 0.3.2
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/react/index.d.mts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +251 -155
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +251 -155
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +193 -0
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +194 -1
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { createContext, useContext, useMemo, useCallback, useRef, useEffect } from 'react';
|
|
3
3
|
import { createSymmSDK, isAuthExpiredError, isNetworkError, isInsufficientMarginError, isRateLimitedError, isTimeoutError } from '@pear-protocol/symm-core';
|
|
4
4
|
import { create } from 'zustand';
|
|
5
|
-
import { jsx } from 'react/jsx-runtime';
|
|
6
5
|
import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
|
|
6
|
+
import { jsx } from 'react/jsx-runtime';
|
|
7
7
|
import { SiweMessage } from 'siwe';
|
|
8
8
|
import { isAddress, encodeFunctionData } from 'viem';
|
|
9
9
|
|
|
@@ -488,6 +488,193 @@ function useBinanceWs(params) {
|
|
|
488
488
|
};
|
|
489
489
|
}, [symmCoreClient, chainId, subscribeSymbol, unsubscribeSymbol]);
|
|
490
490
|
}
|
|
491
|
+
|
|
492
|
+
// src/react/query-keys.ts
|
|
493
|
+
var symmKeys = {
|
|
494
|
+
all: ["symm"],
|
|
495
|
+
balancesRoot: ["symm", "balances"],
|
|
496
|
+
accountSummaryRoot: ["symm", "accountSummary"],
|
|
497
|
+
accountDataRoot: ["symm", "accountData"],
|
|
498
|
+
approvalRoot: ["symm", "approval"],
|
|
499
|
+
positionsRoot: ["symm", "positions"],
|
|
500
|
+
openOrdersRoot: ["symm", "openOrders"],
|
|
501
|
+
tradeHistoryRoot: ["symm", "tradeHistory"],
|
|
502
|
+
portfolioRoot: ["symm", "portfolio"],
|
|
503
|
+
tpslOrdersRoot: ["symm", "tpslOrders"],
|
|
504
|
+
twapOrdersRoot: ["symm", "twapOrders"],
|
|
505
|
+
triggerOrdersRoot: ["symm", "triggerOrders"],
|
|
506
|
+
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
507
|
+
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
508
|
+
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
509
|
+
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
510
|
+
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
511
|
+
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
512
|
+
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
513
|
+
auth: (accountAddress, chainId, signerAddress) => ["symm", "auth", accountAddress, chainId, signerAddress],
|
|
514
|
+
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
515
|
+
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
516
|
+
positions: (params) => ["symm", "positions", params],
|
|
517
|
+
openOrders: (params) => ["symm", "openOrders", params],
|
|
518
|
+
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
519
|
+
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
520
|
+
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
521
|
+
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
522
|
+
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
523
|
+
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
524
|
+
markets: (chainId, search, pageSize) => ["symm", "markets", chainId, search, pageSize],
|
|
525
|
+
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
526
|
+
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
527
|
+
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
528
|
+
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
529
|
+
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
530
|
+
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
531
|
+
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
532
|
+
portfolio: (params) => ["symm", "portfolio", params],
|
|
533
|
+
notifications: (params) => ["symm", "notifications", params],
|
|
534
|
+
unreadCount: (params) => ["symm", "unreadCount", params],
|
|
535
|
+
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
536
|
+
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
537
|
+
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
538
|
+
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
539
|
+
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
540
|
+
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
541
|
+
};
|
|
542
|
+
var useSymmWsStore = create((set) => ({
|
|
543
|
+
isConnected: false,
|
|
544
|
+
setConnected: (isConnected) => set({ isConnected })
|
|
545
|
+
}));
|
|
546
|
+
|
|
547
|
+
// src/react/hooks/use-symm-ws.ts
|
|
548
|
+
function asUnsubscribeFn(value) {
|
|
549
|
+
return typeof value === "function" ? value : null;
|
|
550
|
+
}
|
|
551
|
+
function useSymmWs(params = {}) {
|
|
552
|
+
const ctx = useContext(SymmContext);
|
|
553
|
+
const queryClient = useQueryClient();
|
|
554
|
+
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
555
|
+
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
556
|
+
const symmCoreClient = params.symmCoreClient ?? ctx?.symmCoreClient ?? null;
|
|
557
|
+
const accountAddress = params.accountAddress ?? ctx?.address;
|
|
558
|
+
const chainId = params.chainId ?? ctx?.chainId ?? 42161;
|
|
559
|
+
useEffect(() => {
|
|
560
|
+
if (!symmCoreClient || !accountAddress) {
|
|
561
|
+
setConnected(false);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const ws = symmCoreClient.ws;
|
|
565
|
+
const addr = accountAddress;
|
|
566
|
+
const unsubscribers = [];
|
|
567
|
+
let cancelled = false;
|
|
568
|
+
const removeOnConnect = ws.onConnect(() => {
|
|
569
|
+
setConnected(true);
|
|
570
|
+
});
|
|
571
|
+
const removeOnDisconnect = ws.onDisconnect(() => {
|
|
572
|
+
setConnected(false);
|
|
573
|
+
});
|
|
574
|
+
const removeOnError = asUnsubscribeFn(ws.onError?.(() => {
|
|
575
|
+
}));
|
|
576
|
+
const removeOnWelcome = asUnsubscribeFn(ws.onWelcome?.(() => {
|
|
577
|
+
}));
|
|
578
|
+
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
579
|
+
if (removeOnError) unsubscribers.push(removeOnError);
|
|
580
|
+
if (removeOnWelcome) unsubscribers.push(removeOnWelcome);
|
|
581
|
+
const positionsUnsub = asUnsubscribeFn(
|
|
582
|
+
ws.subscribeToPositions(addr, chainId, () => {
|
|
583
|
+
queryClient.invalidateQueries({
|
|
584
|
+
queryKey: symmKeys.positionsRoot
|
|
585
|
+
});
|
|
586
|
+
})
|
|
587
|
+
);
|
|
588
|
+
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
589
|
+
const openOrdersUnsub = asUnsubscribeFn(
|
|
590
|
+
ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
591
|
+
queryClient.invalidateQueries({
|
|
592
|
+
queryKey: symmKeys.openOrdersRoot
|
|
593
|
+
});
|
|
594
|
+
})
|
|
595
|
+
);
|
|
596
|
+
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
597
|
+
const tradesUnsub = asUnsubscribeFn(
|
|
598
|
+
ws.subscribeToTrades(addr, chainId, () => {
|
|
599
|
+
queryClient.invalidateQueries({
|
|
600
|
+
queryKey: symmKeys.tradeHistoryRoot
|
|
601
|
+
});
|
|
602
|
+
})
|
|
603
|
+
);
|
|
604
|
+
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
605
|
+
const accountSummaryUnsub = asUnsubscribeFn(
|
|
606
|
+
ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
607
|
+
queryClient.invalidateQueries({
|
|
608
|
+
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
609
|
+
});
|
|
610
|
+
queryClient.invalidateQueries({
|
|
611
|
+
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
612
|
+
});
|
|
613
|
+
})
|
|
614
|
+
);
|
|
615
|
+
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
616
|
+
const notificationsUnsub = asUnsubscribeFn(
|
|
617
|
+
ws.subscribeToNotifications(addr, chainId, () => {
|
|
618
|
+
queryClient.invalidateQueries({
|
|
619
|
+
queryKey: symmKeys.notifications({ accountAddress, chainId })
|
|
620
|
+
});
|
|
621
|
+
queryClient.invalidateQueries({
|
|
622
|
+
queryKey: symmKeys.unreadCount({ accountAddress, chainId })
|
|
623
|
+
});
|
|
624
|
+
})
|
|
625
|
+
);
|
|
626
|
+
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
627
|
+
const tpslUnsub = asUnsubscribeFn(
|
|
628
|
+
ws.subscribeToTpsl(addr, chainId, () => {
|
|
629
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.tpslOrdersRoot });
|
|
630
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
|
|
631
|
+
})
|
|
632
|
+
);
|
|
633
|
+
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
634
|
+
const twapUnsub = asUnsubscribeFn(
|
|
635
|
+
ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
636
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.twapOrdersRoot });
|
|
637
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
|
|
638
|
+
})
|
|
639
|
+
);
|
|
640
|
+
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
641
|
+
const triggerOrdersUnsub = asUnsubscribeFn(
|
|
642
|
+
ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
643
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.triggerOrdersRoot });
|
|
644
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
|
|
645
|
+
})
|
|
646
|
+
);
|
|
647
|
+
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
648
|
+
const executionsUnsub = asUnsubscribeFn(
|
|
649
|
+
ws.subscribeToExecutions(addr, chainId, () => {
|
|
650
|
+
queryClient.invalidateQueries({
|
|
651
|
+
queryKey: symmKeys.positionsRoot
|
|
652
|
+
});
|
|
653
|
+
queryClient.invalidateQueries({
|
|
654
|
+
queryKey: symmKeys.portfolioRoot
|
|
655
|
+
});
|
|
656
|
+
})
|
|
657
|
+
);
|
|
658
|
+
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
659
|
+
void ws.connect().then(() => {
|
|
660
|
+
if (cancelled) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
}).catch(() => {
|
|
664
|
+
if (cancelled) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
setConnected(false);
|
|
668
|
+
});
|
|
669
|
+
return () => {
|
|
670
|
+
cancelled = true;
|
|
671
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
672
|
+
ws.disconnect();
|
|
673
|
+
setConnected(false);
|
|
674
|
+
};
|
|
675
|
+
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
676
|
+
return { isConnected };
|
|
677
|
+
}
|
|
491
678
|
function SymmProvider({
|
|
492
679
|
chainId = 42161,
|
|
493
680
|
address,
|
|
@@ -520,6 +707,11 @@ function SymmProvider({
|
|
|
520
707
|
symmCoreClient,
|
|
521
708
|
chainId
|
|
522
709
|
});
|
|
710
|
+
useSymmWs({
|
|
711
|
+
symmCoreClient,
|
|
712
|
+
accountAddress: address,
|
|
713
|
+
chainId
|
|
714
|
+
});
|
|
523
715
|
return /* @__PURE__ */ jsx(SymmContext.Provider, { value, children });
|
|
524
716
|
}
|
|
525
717
|
|
|
@@ -702,57 +894,6 @@ async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress
|
|
|
702
894
|
return cachedToken;
|
|
703
895
|
}
|
|
704
896
|
|
|
705
|
-
// src/react/query-keys.ts
|
|
706
|
-
var symmKeys = {
|
|
707
|
-
all: ["symm"],
|
|
708
|
-
balancesRoot: ["symm", "balances"],
|
|
709
|
-
accountSummaryRoot: ["symm", "accountSummary"],
|
|
710
|
-
accountDataRoot: ["symm", "accountData"],
|
|
711
|
-
approvalRoot: ["symm", "approval"],
|
|
712
|
-
positionsRoot: ["symm", "positions"],
|
|
713
|
-
openOrdersRoot: ["symm", "openOrders"],
|
|
714
|
-
tradeHistoryRoot: ["symm", "tradeHistory"],
|
|
715
|
-
portfolioRoot: ["symm", "portfolio"],
|
|
716
|
-
tpslOrdersRoot: ["symm", "tpslOrders"],
|
|
717
|
-
twapOrdersRoot: ["symm", "twapOrders"],
|
|
718
|
-
triggerOrdersRoot: ["symm", "triggerOrders"],
|
|
719
|
-
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
720
|
-
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
721
|
-
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
722
|
-
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
723
|
-
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
724
|
-
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
725
|
-
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
726
|
-
auth: (accountAddress, chainId, signerAddress) => ["symm", "auth", accountAddress, chainId, signerAddress],
|
|
727
|
-
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
728
|
-
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
729
|
-
positions: (params) => ["symm", "positions", params],
|
|
730
|
-
openOrders: (params) => ["symm", "openOrders", params],
|
|
731
|
-
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
732
|
-
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
733
|
-
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
734
|
-
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
735
|
-
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
736
|
-
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
737
|
-
markets: (chainId, search, pageSize) => ["symm", "markets", chainId, search, pageSize],
|
|
738
|
-
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
739
|
-
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
740
|
-
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
741
|
-
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
742
|
-
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
743
|
-
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
744
|
-
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
745
|
-
portfolio: (params) => ["symm", "portfolio", params],
|
|
746
|
-
notifications: (params) => ["symm", "notifications", params],
|
|
747
|
-
unreadCount: (params) => ["symm", "unreadCount", params],
|
|
748
|
-
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
749
|
-
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
750
|
-
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
751
|
-
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
752
|
-
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
753
|
-
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
754
|
-
};
|
|
755
|
-
|
|
756
897
|
// src/react/auth-cache.ts
|
|
757
898
|
function getAuthQueryData(queryClient, accountAddress, chainId, signerAddress) {
|
|
758
899
|
return queryClient.getQueryData(
|
|
@@ -822,12 +963,6 @@ function clearAuthState(queryClient, accountAddress, chainId, signerAddress) {
|
|
|
822
963
|
}
|
|
823
964
|
|
|
824
965
|
// src/react/hooks/use-symm-auth.ts
|
|
825
|
-
function logSymmAuth(event, details) {
|
|
826
|
-
if (typeof window === "undefined") {
|
|
827
|
-
return;
|
|
828
|
-
}
|
|
829
|
-
console.log("[symm-auth]", event, details ?? {});
|
|
830
|
-
}
|
|
831
966
|
function useSymmAuth(params) {
|
|
832
967
|
const context = useSymmContext();
|
|
833
968
|
const queryClient = useQueryClient();
|
|
@@ -841,20 +976,10 @@ function useSymmAuth(params) {
|
|
|
841
976
|
async (accountAddress, options) => {
|
|
842
977
|
const resolvedAccountAddress = accountAddress ?? activeAccountAddress;
|
|
843
978
|
if (!resolvedAccountAddress) {
|
|
844
|
-
logSymmAuth("refresh:skip-no-active-account", {
|
|
845
|
-
signerAddress: address,
|
|
846
|
-
chainId
|
|
847
|
-
});
|
|
848
979
|
return null;
|
|
849
980
|
}
|
|
850
981
|
if (!walletClient || !address) return null;
|
|
851
982
|
try {
|
|
852
|
-
logSymmAuth("refresh:fetch-start", {
|
|
853
|
-
signerAddress: address,
|
|
854
|
-
accountAddress: resolvedAccountAddress,
|
|
855
|
-
chainId,
|
|
856
|
-
force: options?.force ?? false
|
|
857
|
-
});
|
|
858
983
|
const tokenEntry = await resolveAuthTokenEntry({
|
|
859
984
|
queryClient,
|
|
860
985
|
walletClient,
|
|
@@ -865,20 +990,9 @@ function useSymmAuth(params) {
|
|
|
865
990
|
force: options?.force
|
|
866
991
|
});
|
|
867
992
|
const token2 = tokenEntry?.token ?? null;
|
|
868
|
-
logSymmAuth("refresh:fetch-success", {
|
|
869
|
-
signerAddress: address,
|
|
870
|
-
accountAddress: resolvedAccountAddress,
|
|
871
|
-
chainId
|
|
872
|
-
});
|
|
873
993
|
return token2;
|
|
874
994
|
} catch (error) {
|
|
875
995
|
clearPersistedAuthState(resolvedAccountAddress, chainId);
|
|
876
|
-
logSymmAuth("refresh:fetch-failed", {
|
|
877
|
-
signerAddress: address,
|
|
878
|
-
accountAddress: resolvedAccountAddress,
|
|
879
|
-
chainId,
|
|
880
|
-
error: error instanceof Error ? error.message : String(error)
|
|
881
|
-
});
|
|
882
996
|
return null;
|
|
883
997
|
}
|
|
884
998
|
},
|
|
@@ -2126,9 +2240,53 @@ function useSymmApproveMutation(params, options) {
|
|
|
2126
2240
|
}
|
|
2127
2241
|
});
|
|
2128
2242
|
}
|
|
2243
|
+
function splitTradeHookArgs(paramsOrOptions, options) {
|
|
2244
|
+
if (paramsOrOptions && "mutation" in paramsOrOptions) {
|
|
2245
|
+
return {
|
|
2246
|
+
params: {},
|
|
2247
|
+
options: paramsOrOptions
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
return {
|
|
2251
|
+
params: paramsOrOptions ?? {},
|
|
2252
|
+
options
|
|
2253
|
+
};
|
|
2254
|
+
}
|
|
2255
|
+
function useResolveTradeAuthToken(params = {}) {
|
|
2256
|
+
const context = useSymmContext();
|
|
2257
|
+
const queryClient = useQueryClient();
|
|
2258
|
+
const address = params.address ?? context.address;
|
|
2259
|
+
const chainId = params.chainId ?? context.chainId;
|
|
2260
|
+
return useCallback(
|
|
2261
|
+
async (providedAuthToken, accountAddress, overrideChainId) => {
|
|
2262
|
+
const resolvedChainId = overrideChainId ?? chainId;
|
|
2263
|
+
if (providedAuthToken) {
|
|
2264
|
+
return providedAuthToken;
|
|
2265
|
+
}
|
|
2266
|
+
const resolvedAccountAddress = accountAddress ?? address;
|
|
2267
|
+
if (!resolvedAccountAddress) {
|
|
2268
|
+
return null;
|
|
2269
|
+
}
|
|
2270
|
+
const inMemoryToken = getAuthTokenFromRuntimeCache(
|
|
2271
|
+
queryClient,
|
|
2272
|
+
resolvedAccountAddress,
|
|
2273
|
+
resolvedChainId,
|
|
2274
|
+
address
|
|
2275
|
+
);
|
|
2276
|
+
if (inMemoryToken) {
|
|
2277
|
+
return inMemoryToken;
|
|
2278
|
+
}
|
|
2279
|
+
return null;
|
|
2280
|
+
},
|
|
2281
|
+
[address, chainId, queryClient]
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
// src/react/hooks/use-symm-cancel-close.ts
|
|
2129
2286
|
function useSymmCancelClose(options) {
|
|
2130
2287
|
const { symmCoreClient, chainId, address } = useSymmContext();
|
|
2131
2288
|
const queryClient = useQueryClient();
|
|
2289
|
+
const resolveAuthToken = useResolveTradeAuthToken({ address, chainId });
|
|
2132
2290
|
return useMutation({
|
|
2133
2291
|
...withSymmMutationConfig(options?.mutation, {
|
|
2134
2292
|
onSuccess: () => {
|
|
@@ -2145,14 +2303,12 @@ function useSymmCancelClose(options) {
|
|
|
2145
2303
|
if (!symmCoreClient) {
|
|
2146
2304
|
throw new Error("symm-core client not available");
|
|
2147
2305
|
}
|
|
2148
|
-
const resolvedAccountAddress = accountAddress ?? address;
|
|
2149
2306
|
const resolvedChainId = overrideChainId ?? chainId;
|
|
2150
|
-
const resolvedAuthToken =
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
resolvedChainId
|
|
2154
|
-
|
|
2155
|
-
) : null);
|
|
2307
|
+
const resolvedAuthToken = await resolveAuthToken(
|
|
2308
|
+
authToken,
|
|
2309
|
+
accountAddress,
|
|
2310
|
+
resolvedChainId
|
|
2311
|
+
);
|
|
2156
2312
|
if (!resolvedAuthToken) {
|
|
2157
2313
|
throw new Error("auth token is required to cancel a pending close");
|
|
2158
2314
|
}
|
|
@@ -2167,6 +2323,7 @@ function useSymmCancelClose(options) {
|
|
|
2167
2323
|
function useSymmCloseOrder(options) {
|
|
2168
2324
|
const { symmCoreClient, address, chainId } = useSymmContext();
|
|
2169
2325
|
const queryClient = useQueryClient();
|
|
2326
|
+
const resolveAuthToken = useResolveTradeAuthToken({ address, chainId });
|
|
2170
2327
|
return useMutation({
|
|
2171
2328
|
...withSymmMutationConfig(options?.mutation, {
|
|
2172
2329
|
onSuccess: () => {
|
|
@@ -2179,16 +2336,17 @@ function useSymmCloseOrder(options) {
|
|
|
2179
2336
|
throw new Error("symm-core client not available");
|
|
2180
2337
|
}
|
|
2181
2338
|
const typedRequest = request;
|
|
2182
|
-
const
|
|
2339
|
+
const authToken = await resolveAuthToken(
|
|
2340
|
+
typedRequest.authToken,
|
|
2341
|
+
typedRequest.accountAddress
|
|
2342
|
+
);
|
|
2343
|
+
if (!authToken) {
|
|
2344
|
+
throw new Error("auth token is required to close an order");
|
|
2345
|
+
}
|
|
2183
2346
|
return symmCoreClient.orders.close(request.id, {
|
|
2184
2347
|
kind: request.kind,
|
|
2185
2348
|
type: request.type,
|
|
2186
|
-
authToken
|
|
2187
|
-
queryClient,
|
|
2188
|
-
resolvedAccountAddress,
|
|
2189
|
-
chainId,
|
|
2190
|
-
address
|
|
2191
|
-
) ?? void 0 : void 0)
|
|
2349
|
+
authToken
|
|
2192
2350
|
});
|
|
2193
2351
|
}
|
|
2194
2352
|
});
|
|
@@ -25298,64 +25456,6 @@ function useSymmBalances(params) {
|
|
|
25298
25456
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25299
25457
|
});
|
|
25300
25458
|
}
|
|
25301
|
-
function logTradeAuth(event, details) {
|
|
25302
|
-
if (typeof window === "undefined") {
|
|
25303
|
-
return;
|
|
25304
|
-
}
|
|
25305
|
-
console.debug("[symm-trade]", event, details ?? {});
|
|
25306
|
-
}
|
|
25307
|
-
function splitTradeHookArgs(paramsOrOptions, options) {
|
|
25308
|
-
if (paramsOrOptions && "mutation" in paramsOrOptions) {
|
|
25309
|
-
return {
|
|
25310
|
-
params: {},
|
|
25311
|
-
options: paramsOrOptions
|
|
25312
|
-
};
|
|
25313
|
-
}
|
|
25314
|
-
return {
|
|
25315
|
-
params: paramsOrOptions ?? {},
|
|
25316
|
-
options
|
|
25317
|
-
};
|
|
25318
|
-
}
|
|
25319
|
-
function useResolveTradeAuthToken(params = {}) {
|
|
25320
|
-
const context = useSymmContext();
|
|
25321
|
-
const queryClient = useQueryClient();
|
|
25322
|
-
const address = params.address ?? context.address;
|
|
25323
|
-
const chainId = params.chainId ?? context.chainId;
|
|
25324
|
-
return useCallback(
|
|
25325
|
-
async (providedAuthToken, accountAddress) => {
|
|
25326
|
-
if (providedAuthToken) {
|
|
25327
|
-
logTradeAuth("resolve-auth:provided", {
|
|
25328
|
-
accountAddress,
|
|
25329
|
-
chainId
|
|
25330
|
-
});
|
|
25331
|
-
return providedAuthToken;
|
|
25332
|
-
}
|
|
25333
|
-
const resolvedAccountAddress = accountAddress ?? address;
|
|
25334
|
-
if (!resolvedAccountAddress) {
|
|
25335
|
-
return null;
|
|
25336
|
-
}
|
|
25337
|
-
const inMemoryToken = getAuthTokenFromRuntimeCache(
|
|
25338
|
-
queryClient,
|
|
25339
|
-
resolvedAccountAddress,
|
|
25340
|
-
chainId,
|
|
25341
|
-
address
|
|
25342
|
-
);
|
|
25343
|
-
if (inMemoryToken) {
|
|
25344
|
-
logTradeAuth("resolve-auth:store-hit", {
|
|
25345
|
-
accountAddress: resolvedAccountAddress,
|
|
25346
|
-
chainId
|
|
25347
|
-
});
|
|
25348
|
-
return inMemoryToken;
|
|
25349
|
-
}
|
|
25350
|
-
logTradeAuth("resolve-auth:miss", {
|
|
25351
|
-
accountAddress: resolvedAccountAddress,
|
|
25352
|
-
chainId
|
|
25353
|
-
});
|
|
25354
|
-
return null;
|
|
25355
|
-
},
|
|
25356
|
-
[address, chainId, queryClient]
|
|
25357
|
-
);
|
|
25358
|
-
}
|
|
25359
25459
|
function useSymmOpenBasketMutation(options) {
|
|
25360
25460
|
const { symmCoreClient } = useSymmContext();
|
|
25361
25461
|
const queryClient = useQueryClient();
|
|
@@ -26919,10 +27019,6 @@ function getSymmErrorMessage(error) {
|
|
|
26919
27019
|
if (error instanceof Error) return error.message;
|
|
26920
27020
|
return "An unexpected error occurred.";
|
|
26921
27021
|
}
|
|
26922
|
-
var useSymmWsStore = create((set) => ({
|
|
26923
|
-
isConnected: false,
|
|
26924
|
-
setConnected: (isConnected) => set({ isConnected })
|
|
26925
|
-
}));
|
|
26926
27022
|
|
|
26927
27023
|
export { SymmProvider, getSymmErrorMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountData, useSymmAccountSummary, useSymmAccountsApi, useSymmAccountsLength, useSymmAccountsQuery, useSymmAccountsWithPositions, useSymmAllocateCollateralMutation, useSymmApprovalQuery, useSymmApproveMutation, useSymmAuth, useSymmAvailableMargin, useSymmBalances, useSymmCancelClose, useSymmCancelOpenMutation, useSymmCancelTpslMutation, useSymmCancelTwapOrderMutation, useSymmChartCandles, useSymmChartSelection, useSymmClearTriggerConfigMutation, useSymmCloseAllPositionsMutation, useSymmCloseOrder, useSymmClosePositionMutation, useSymmContext, useSymmCoreClient, useSymmCreateAccountMutation, useSymmDeallocateCollateralMutation, useSymmDelegateAccessMutation, useSymmDelegation, useSymmDepositAndAllocateMutation, useSymmDepositMutation, useSymmEditAccountNameMutation, useSymmFunding, useSymmFundingHistory, useSymmFundingPayments, useSymmHedgerMarketById, useSymmHedgerMarketBySymbol, useSymmHedgerMarkets, useSymmInstantTradeEnsureReadyMutation, useSymmInstantTradeExecuteMutation, useSymmInternalTransferCollateralMutation, useSymmLockedParams, useSymmMarkReadNotificationMutation, useSymmMarkets, useSymmNotificationsQuery, useSymmOpenBasketMutation, useSymmOpenOrders, useSymmPendingIds, useSymmPendingInstantOpens, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmProposeRevokeDelegationMutation, useSymmRevokeDelegationMutation, useSymmSetTpslMutation, useSymmSetTriggerConfigMutation, useSymmSignTermsMutation, useSymmSignatureQuery, useSymmTokenMarkPrice, useSymmTokenSelectionMarkets, useSymmTokenSelectionMetadata, useSymmTpslOrders, useSymmTradeHistory, useSymmTriggerConfigQuery, useSymmTriggerOrders, useSymmTwapOrder, useSymmTwapOrdersQuery, useSymmUnreadCountQuery, useSymmUpdatePositionMutation, useSymmWithdraw, useSymmWsStore };
|
|
26928
27024
|
//# sourceMappingURL=index.mjs.map
|