@pear-protocol/symmio-client 0.1.8 → 0.1.10
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.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +28 -5
- package/dist/react/index.d.ts +28 -5
- package/dist/react/index.js +202 -119
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +202 -121
- package/dist/react/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -639,6 +639,28 @@ declare function useSymmAvailableMargin(params: {
|
|
|
639
639
|
}, Error>>;
|
|
640
640
|
};
|
|
641
641
|
|
|
642
|
+
declare function useSymmAccountSummary(params: {
|
|
643
|
+
userAddress?: Address;
|
|
644
|
+
chainId?: number;
|
|
645
|
+
query?: SymmQueryConfig;
|
|
646
|
+
}): {
|
|
647
|
+
accounts: node_modules__pear_protocol_symm_core_dist_types.AccountSummaryItem[];
|
|
648
|
+
total: number;
|
|
649
|
+
isLoading: boolean;
|
|
650
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<node_modules__pear_protocol_symm_core_dist_types.AccountSummaryResponse, Error>>;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
declare function useSymmAccountData(params: {
|
|
654
|
+
address?: Address;
|
|
655
|
+
upnl?: string;
|
|
656
|
+
chainId?: number;
|
|
657
|
+
query?: SymmQueryConfig;
|
|
658
|
+
}): {
|
|
659
|
+
accountData: node_modules__pear_protocol_symm_core_dist_types.AccountDataInfo | null;
|
|
660
|
+
isLoading: boolean;
|
|
661
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<node_modules__pear_protocol_symm_core_dist_types.AccountDataResponse, Error>>;
|
|
662
|
+
};
|
|
663
|
+
|
|
642
664
|
declare function useSymmBalances(params: {
|
|
643
665
|
userAddress?: Address;
|
|
644
666
|
chainId?: number;
|
|
@@ -833,14 +855,14 @@ interface UseSymmTokenSelectionMetadataReturn {
|
|
|
833
855
|
priceRatio24h: number;
|
|
834
856
|
sumNetFunding: number;
|
|
835
857
|
}
|
|
858
|
+
interface UseSymmTokenSelectionMetadataOptions {
|
|
859
|
+
enabled?: boolean;
|
|
860
|
+
}
|
|
836
861
|
/**
|
|
837
862
|
* Fetches Binance market data for selected SYMM chart tokens and derives
|
|
838
863
|
* chart header metrics (price ratio, weighted ratio, etc.).
|
|
839
864
|
*/
|
|
840
|
-
declare function useSymmTokenSelectionMetadata(selection: SymmChartSelection, options?:
|
|
841
|
-
enabled?: boolean;
|
|
842
|
-
query?: SymmQueryConfig;
|
|
843
|
-
}): UseSymmTokenSelectionMetadataReturn;
|
|
865
|
+
declare function useSymmTokenSelectionMetadata(selection: SymmChartSelection, options?: UseSymmTokenSelectionMetadataOptions): UseSymmTokenSelectionMetadataReturn;
|
|
844
866
|
|
|
845
867
|
/**
|
|
846
868
|
* Candle interval type matching the chart system.
|
|
@@ -910,6 +932,7 @@ declare const symmKeys: {
|
|
|
910
932
|
all: readonly ["symm"];
|
|
911
933
|
accounts: (address?: Address) => readonly ["symm", "accounts", `0x${string}` | undefined];
|
|
912
934
|
accountSummary: (address?: Address, chainId?: number) => readonly ["symm", "accountSummary", `0x${string}` | undefined, number | undefined];
|
|
935
|
+
accountData: (address?: Address, chainId?: number) => readonly ["symm", "accountData", `0x${string}` | undefined, number | undefined];
|
|
913
936
|
signature: (address?: Address) => readonly ["symm", "signature", `0x${string}` | undefined];
|
|
914
937
|
approval: (owner?: Address, spender?: Address) => readonly ["symm", "approval", `0x${string}` | undefined, `0x${string}` | undefined];
|
|
915
938
|
balances: (address?: Address, chainId?: number) => readonly ["symm", "balances", `0x${string}` | undefined, number | undefined];
|
|
@@ -931,4 +954,4 @@ declare const symmKeys: {
|
|
|
931
954
|
|
|
932
955
|
declare function getSymmErrorMessage(error: unknown): string;
|
|
933
956
|
|
|
934
|
-
export { type SymmChartSelection, type SymmChartSelectionInput, type SymmChartTokenSelection, type SymmContextValue, type SymmDelegationState, type SymmInstantTradeActionArgs, type SymmInstantTradeRequest, type SymmPerformanceOverlay, SymmProvider, type SymmProviderProps, type SymmQueryConfig, type SymmTokenMetadata, type UseSymmChartCandlesReturn, type UseSymmDelegationParams, type UseSymmHedgerMarketsParams, type UseSymmTokenSelectionMetadataReturn, getSymmErrorMessage, symmKeys, useSymmAccounts, useSymmApproval, useSymmAuth, useSymmAvailableMargin, useSymmBalances, useSymmChartCandles, useSymmChartSelection, useSymmCollateral, useSymmContext, useSymmCoreClient, useSymmDelegation, useSymmDeposit, useSymmFunding, useSymmHedgerMarkets, useSymmInstantTrade, useSymmMarkets, useSymmNotifications, useSymmOpenOrders, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmSignature, useSymmTokenSelectionMetadata, useSymmTpsl, useSymmTrade, useSymmTradeHistory, useSymmTwap, useSymmWithdraw, useSymmWs, useSymmioClient };
|
|
957
|
+
export { type SymmChartSelection, type SymmChartSelectionInput, type SymmChartTokenSelection, type SymmContextValue, type SymmDelegationState, type SymmInstantTradeActionArgs, type SymmInstantTradeRequest, type SymmPerformanceOverlay, SymmProvider, type SymmProviderProps, type SymmQueryConfig, type SymmTokenMetadata, type UseSymmChartCandlesReturn, type UseSymmDelegationParams, type UseSymmHedgerMarketsParams, type UseSymmTokenSelectionMetadataReturn, getSymmErrorMessage, symmKeys, useSymmAccountData, useSymmAccountSummary, useSymmAccounts, useSymmApproval, useSymmAuth, useSymmAvailableMargin, useSymmBalances, useSymmChartCandles, useSymmChartSelection, useSymmCollateral, useSymmContext, useSymmCoreClient, useSymmDelegation, useSymmDeposit, useSymmFunding, useSymmHedgerMarkets, useSymmInstantTrade, useSymmMarkets, useSymmNotifications, useSymmOpenOrders, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmSignature, useSymmTokenSelectionMetadata, useSymmTpsl, useSymmTrade, useSymmTradeHistory, useSymmTwap, useSymmWithdraw, useSymmWs, useSymmioClient };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -639,6 +639,28 @@ declare function useSymmAvailableMargin(params: {
|
|
|
639
639
|
}, Error>>;
|
|
640
640
|
};
|
|
641
641
|
|
|
642
|
+
declare function useSymmAccountSummary(params: {
|
|
643
|
+
userAddress?: Address;
|
|
644
|
+
chainId?: number;
|
|
645
|
+
query?: SymmQueryConfig;
|
|
646
|
+
}): {
|
|
647
|
+
accounts: node_modules__pear_protocol_symm_core_dist_types.AccountSummaryItem[];
|
|
648
|
+
total: number;
|
|
649
|
+
isLoading: boolean;
|
|
650
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<node_modules__pear_protocol_symm_core_dist_types.AccountSummaryResponse, Error>>;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
declare function useSymmAccountData(params: {
|
|
654
|
+
address?: Address;
|
|
655
|
+
upnl?: string;
|
|
656
|
+
chainId?: number;
|
|
657
|
+
query?: SymmQueryConfig;
|
|
658
|
+
}): {
|
|
659
|
+
accountData: node_modules__pear_protocol_symm_core_dist_types.AccountDataInfo | null;
|
|
660
|
+
isLoading: boolean;
|
|
661
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<node_modules__pear_protocol_symm_core_dist_types.AccountDataResponse, Error>>;
|
|
662
|
+
};
|
|
663
|
+
|
|
642
664
|
declare function useSymmBalances(params: {
|
|
643
665
|
userAddress?: Address;
|
|
644
666
|
chainId?: number;
|
|
@@ -833,14 +855,14 @@ interface UseSymmTokenSelectionMetadataReturn {
|
|
|
833
855
|
priceRatio24h: number;
|
|
834
856
|
sumNetFunding: number;
|
|
835
857
|
}
|
|
858
|
+
interface UseSymmTokenSelectionMetadataOptions {
|
|
859
|
+
enabled?: boolean;
|
|
860
|
+
}
|
|
836
861
|
/**
|
|
837
862
|
* Fetches Binance market data for selected SYMM chart tokens and derives
|
|
838
863
|
* chart header metrics (price ratio, weighted ratio, etc.).
|
|
839
864
|
*/
|
|
840
|
-
declare function useSymmTokenSelectionMetadata(selection: SymmChartSelection, options?:
|
|
841
|
-
enabled?: boolean;
|
|
842
|
-
query?: SymmQueryConfig;
|
|
843
|
-
}): UseSymmTokenSelectionMetadataReturn;
|
|
865
|
+
declare function useSymmTokenSelectionMetadata(selection: SymmChartSelection, options?: UseSymmTokenSelectionMetadataOptions): UseSymmTokenSelectionMetadataReturn;
|
|
844
866
|
|
|
845
867
|
/**
|
|
846
868
|
* Candle interval type matching the chart system.
|
|
@@ -910,6 +932,7 @@ declare const symmKeys: {
|
|
|
910
932
|
all: readonly ["symm"];
|
|
911
933
|
accounts: (address?: Address) => readonly ["symm", "accounts", `0x${string}` | undefined];
|
|
912
934
|
accountSummary: (address?: Address, chainId?: number) => readonly ["symm", "accountSummary", `0x${string}` | undefined, number | undefined];
|
|
935
|
+
accountData: (address?: Address, chainId?: number) => readonly ["symm", "accountData", `0x${string}` | undefined, number | undefined];
|
|
913
936
|
signature: (address?: Address) => readonly ["symm", "signature", `0x${string}` | undefined];
|
|
914
937
|
approval: (owner?: Address, spender?: Address) => readonly ["symm", "approval", `0x${string}` | undefined, `0x${string}` | undefined];
|
|
915
938
|
balances: (address?: Address, chainId?: number) => readonly ["symm", "balances", `0x${string}` | undefined, number | undefined];
|
|
@@ -931,4 +954,4 @@ declare const symmKeys: {
|
|
|
931
954
|
|
|
932
955
|
declare function getSymmErrorMessage(error: unknown): string;
|
|
933
956
|
|
|
934
|
-
export { type SymmChartSelection, type SymmChartSelectionInput, type SymmChartTokenSelection, type SymmContextValue, type SymmDelegationState, type SymmInstantTradeActionArgs, type SymmInstantTradeRequest, type SymmPerformanceOverlay, SymmProvider, type SymmProviderProps, type SymmQueryConfig, type SymmTokenMetadata, type UseSymmChartCandlesReturn, type UseSymmDelegationParams, type UseSymmHedgerMarketsParams, type UseSymmTokenSelectionMetadataReturn, getSymmErrorMessage, symmKeys, useSymmAccounts, useSymmApproval, useSymmAuth, useSymmAvailableMargin, useSymmBalances, useSymmChartCandles, useSymmChartSelection, useSymmCollateral, useSymmContext, useSymmCoreClient, useSymmDelegation, useSymmDeposit, useSymmFunding, useSymmHedgerMarkets, useSymmInstantTrade, useSymmMarkets, useSymmNotifications, useSymmOpenOrders, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmSignature, useSymmTokenSelectionMetadata, useSymmTpsl, useSymmTrade, useSymmTradeHistory, useSymmTwap, useSymmWithdraw, useSymmWs, useSymmioClient };
|
|
957
|
+
export { type SymmChartSelection, type SymmChartSelectionInput, type SymmChartTokenSelection, type SymmContextValue, type SymmDelegationState, type SymmInstantTradeActionArgs, type SymmInstantTradeRequest, type SymmPerformanceOverlay, SymmProvider, type SymmProviderProps, type SymmQueryConfig, type SymmTokenMetadata, type UseSymmChartCandlesReturn, type UseSymmDelegationParams, type UseSymmHedgerMarketsParams, type UseSymmTokenSelectionMetadataReturn, getSymmErrorMessage, symmKeys, useSymmAccountData, useSymmAccountSummary, useSymmAccounts, useSymmApproval, useSymmAuth, useSymmAvailableMargin, useSymmBalances, useSymmChartCandles, useSymmChartSelection, useSymmCollateral, useSymmContext, useSymmCoreClient, useSymmDelegation, useSymmDeposit, useSymmFunding, useSymmHedgerMarkets, useSymmInstantTrade, useSymmMarkets, useSymmNotifications, useSymmOpenOrders, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmSignature, useSymmTokenSelectionMetadata, useSymmTpsl, useSymmTrade, useSymmTradeHistory, useSymmTwap, useSymmWithdraw, useSymmWs, useSymmioClient };
|
package/dist/react/index.js
CHANGED
|
@@ -23767,11 +23767,11 @@ function prepareGrantRole(symmioDiamond, account, role, grantee) {
|
|
|
23767
23767
|
const data = viem.encodeFunctionData({
|
|
23768
23768
|
abi: SymmioDiamondABI,
|
|
23769
23769
|
functionName: "grantRole",
|
|
23770
|
-
args: [
|
|
23770
|
+
args: [grantee, role]
|
|
23771
23771
|
});
|
|
23772
23772
|
return {
|
|
23773
23773
|
functionName: "grantRole",
|
|
23774
|
-
args: [
|
|
23774
|
+
args: [grantee, role],
|
|
23775
23775
|
config: { account, to: symmioDiamond, data, value: 0n }
|
|
23776
23776
|
};
|
|
23777
23777
|
}
|
|
@@ -23780,11 +23780,11 @@ function prepareRevokeRole(symmioDiamond, account, role, revokee) {
|
|
|
23780
23780
|
const data = viem.encodeFunctionData({
|
|
23781
23781
|
abi: SymmioDiamondABI,
|
|
23782
23782
|
functionName: "revokeRole",
|
|
23783
|
-
args: [
|
|
23783
|
+
args: [revokee, role]
|
|
23784
23784
|
});
|
|
23785
23785
|
return {
|
|
23786
23786
|
functionName: "revokeRole",
|
|
23787
|
-
args: [
|
|
23787
|
+
args: [revokee, role],
|
|
23788
23788
|
config: { account, to: symmioDiamond, data, value: 0n }
|
|
23789
23789
|
};
|
|
23790
23790
|
}
|
|
@@ -24362,6 +24362,16 @@ function SymmProvider({
|
|
|
24362
24362
|
const [accessToken, setAccessToken] = react.useState(null);
|
|
24363
24363
|
const prevAddressRef = react.useRef(address);
|
|
24364
24364
|
const prevChainRef = react.useRef(chainId);
|
|
24365
|
+
const {
|
|
24366
|
+
multiAccountAddress,
|
|
24367
|
+
symmioDiamondAddress,
|
|
24368
|
+
collateralAddress,
|
|
24369
|
+
clearingHouseAddress,
|
|
24370
|
+
signatureStoreAddress,
|
|
24371
|
+
muonBaseUrls,
|
|
24372
|
+
muonAppName
|
|
24373
|
+
} = symmioConfig ?? {};
|
|
24374
|
+
const muonBaseUrlsKey = muonBaseUrls?.join(",");
|
|
24365
24375
|
const symmioClient = react.useMemo(() => {
|
|
24366
24376
|
if (!publicClient || !walletClient || !address) return null;
|
|
24367
24377
|
return new SymmioSDK({
|
|
@@ -24370,30 +24380,65 @@ function SymmProvider({
|
|
|
24370
24380
|
walletClient,
|
|
24371
24381
|
config: symmioConfig
|
|
24372
24382
|
});
|
|
24373
|
-
}, [
|
|
24374
|
-
|
|
24375
|
-
|
|
24376
|
-
|
|
24377
|
-
|
|
24378
|
-
|
|
24379
|
-
|
|
24380
|
-
|
|
24381
|
-
|
|
24382
|
-
|
|
24383
|
-
|
|
24384
|
-
|
|
24385
|
-
|
|
24386
|
-
|
|
24387
|
-
|
|
24388
|
-
|
|
24389
|
-
|
|
24390
|
-
|
|
24391
|
-
|
|
24392
|
-
|
|
24393
|
-
|
|
24394
|
-
|
|
24395
|
-
|
|
24396
|
-
|
|
24383
|
+
}, [
|
|
24384
|
+
publicClient,
|
|
24385
|
+
walletClient,
|
|
24386
|
+
address,
|
|
24387
|
+
chainId,
|
|
24388
|
+
multiAccountAddress,
|
|
24389
|
+
symmioDiamondAddress,
|
|
24390
|
+
collateralAddress,
|
|
24391
|
+
clearingHouseAddress,
|
|
24392
|
+
signatureStoreAddress,
|
|
24393
|
+
muonBaseUrlsKey,
|
|
24394
|
+
muonAppName
|
|
24395
|
+
]);
|
|
24396
|
+
react.useEffect(() => {
|
|
24397
|
+
console.log("[SymmProvider] symmioClient prerequisites", {
|
|
24398
|
+
address,
|
|
24399
|
+
walletChainId,
|
|
24400
|
+
configChainId,
|
|
24401
|
+
resolvedChainId: chainId,
|
|
24402
|
+
hasPublicClient: !!publicClient,
|
|
24403
|
+
hasWalletClient: !!walletClient,
|
|
24404
|
+
hasAddress: !!address,
|
|
24405
|
+
symmioClientBuilt: !!symmioClient
|
|
24406
|
+
});
|
|
24407
|
+
}, [
|
|
24408
|
+
address,
|
|
24409
|
+
walletChainId,
|
|
24410
|
+
configChainId,
|
|
24411
|
+
chainId,
|
|
24412
|
+
publicClient,
|
|
24413
|
+
walletClient,
|
|
24414
|
+
symmioClient
|
|
24415
|
+
]);
|
|
24416
|
+
const refreshAuth = react.useCallback(
|
|
24417
|
+
async (accountAddress) => {
|
|
24418
|
+
if (!walletClient || !address) return null;
|
|
24419
|
+
const resolvedAccountAddress = accountAddress ?? address;
|
|
24420
|
+
const cached = getCachedToken(resolvedAccountAddress, chainId);
|
|
24421
|
+
if (cached) {
|
|
24422
|
+
setAccessToken(cached);
|
|
24423
|
+
return cached;
|
|
24424
|
+
}
|
|
24425
|
+
try {
|
|
24426
|
+
const token = await fetchAccessToken(
|
|
24427
|
+
walletClient,
|
|
24428
|
+
address,
|
|
24429
|
+
resolvedAccountAddress,
|
|
24430
|
+
chainId,
|
|
24431
|
+
siweDomain
|
|
24432
|
+
);
|
|
24433
|
+
setAccessToken(token);
|
|
24434
|
+
return token;
|
|
24435
|
+
} catch {
|
|
24436
|
+
setAccessToken(null);
|
|
24437
|
+
return null;
|
|
24438
|
+
}
|
|
24439
|
+
},
|
|
24440
|
+
[walletClient, address, chainId, siweDomain]
|
|
24441
|
+
);
|
|
24397
24442
|
react.useEffect(() => {
|
|
24398
24443
|
const previousAddress = prevAddressRef.current;
|
|
24399
24444
|
const previousChainId = prevChainRef.current;
|
|
@@ -24474,6 +24519,7 @@ var symmKeys = {
|
|
|
24474
24519
|
all: ["symm"],
|
|
24475
24520
|
accounts: (address) => ["symm", "accounts", address],
|
|
24476
24521
|
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
24522
|
+
accountData: (address, chainId) => ["symm", "accountData", address, chainId],
|
|
24477
24523
|
signature: (address) => ["symm", "signature", address],
|
|
24478
24524
|
approval: (owner, spender) => ["symm", "approval", owner, spender],
|
|
24479
24525
|
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
@@ -24537,6 +24583,7 @@ function useSymmDelegation(params) {
|
|
|
24537
24583
|
function invalidateBalances(qc) {
|
|
24538
24584
|
qc.invalidateQueries({ queryKey: ["symm", "balances"] });
|
|
24539
24585
|
qc.invalidateQueries({ queryKey: ["symm", "accountSummary"] });
|
|
24586
|
+
qc.invalidateQueries({ queryKey: ["symm", "accountData"] });
|
|
24540
24587
|
qc.invalidateQueries({ queryKey: ["symm", "portfolio"] });
|
|
24541
24588
|
}
|
|
24542
24589
|
function invalidatePositions(qc) {
|
|
@@ -24876,6 +24923,50 @@ function useSymmAvailableMargin(params) {
|
|
|
24876
24923
|
refetch: query.refetch
|
|
24877
24924
|
};
|
|
24878
24925
|
}
|
|
24926
|
+
function useSymmAccountSummary(params) {
|
|
24927
|
+
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24928
|
+
const { userAddress } = params;
|
|
24929
|
+
const chainId = params.chainId ?? ctxChainId;
|
|
24930
|
+
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
24931
|
+
const query = reactQuery.useQuery({
|
|
24932
|
+
...params.query,
|
|
24933
|
+
queryKey: symmKeys.accountSummary(userAddress, chainId),
|
|
24934
|
+
queryFn: () => symmCoreClient.accounts.getSummary({
|
|
24935
|
+
userAddress,
|
|
24936
|
+
chainId
|
|
24937
|
+
}),
|
|
24938
|
+
enabled: internalEnabled && (params.query?.enabled ?? true),
|
|
24939
|
+
staleTime: params.query?.staleTime ?? 1e4
|
|
24940
|
+
});
|
|
24941
|
+
return {
|
|
24942
|
+
accounts: query.data?.data?.accounts ?? [],
|
|
24943
|
+
total: query.data?.data?.total ?? 0,
|
|
24944
|
+
isLoading: query.isLoading,
|
|
24945
|
+
refetch: query.refetch
|
|
24946
|
+
};
|
|
24947
|
+
}
|
|
24948
|
+
function useSymmAccountData(params) {
|
|
24949
|
+
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24950
|
+
const { address, upnl } = params;
|
|
24951
|
+
const chainId = params.chainId ?? ctxChainId;
|
|
24952
|
+
const internalEnabled = !!symmCoreClient && !!address;
|
|
24953
|
+
const query = reactQuery.useQuery({
|
|
24954
|
+
...params.query,
|
|
24955
|
+
queryKey: symmKeys.accountData(address, chainId),
|
|
24956
|
+
queryFn: () => symmCoreClient.accounts.getData({
|
|
24957
|
+
address,
|
|
24958
|
+
chainId,
|
|
24959
|
+
upnl
|
|
24960
|
+
}),
|
|
24961
|
+
enabled: internalEnabled && (params.query?.enabled ?? true),
|
|
24962
|
+
staleTime: params.query?.staleTime ?? 1e4
|
|
24963
|
+
});
|
|
24964
|
+
return {
|
|
24965
|
+
accountData: query.data?.data ?? null,
|
|
24966
|
+
isLoading: query.isLoading,
|
|
24967
|
+
refetch: query.refetch
|
|
24968
|
+
};
|
|
24969
|
+
}
|
|
24879
24970
|
function useSymmBalances(params) {
|
|
24880
24971
|
const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
|
|
24881
24972
|
const { userAddress, multiAccountAddress } = params;
|
|
@@ -25795,137 +25886,128 @@ function getBinanceWsManager() {
|
|
|
25795
25886
|
}
|
|
25796
25887
|
|
|
25797
25888
|
// src/react/hooks/use-symm-token-selection-metadata.ts
|
|
25798
|
-
|
|
25799
|
-
var EMPTY_MARK_PRICES = {};
|
|
25800
|
-
async function fetchTokenMetadata(symbol) {
|
|
25889
|
+
async function fetchTickerSnapshot(symbol) {
|
|
25801
25890
|
const resolution = resolveBinanceSymbol(symbol);
|
|
25802
25891
|
if (!resolution.binanceSymbol) return null;
|
|
25803
25892
|
const ticker = await fetch24hrTicker(resolution.binanceSymbol);
|
|
25804
25893
|
if (!ticker) return null;
|
|
25805
25894
|
return {
|
|
25806
|
-
|
|
25807
|
-
prevDayPrice: ticker.prevClosePrice
|
|
25895
|
+
prevClosePrice: ticker.prevClosePrice
|
|
25808
25896
|
};
|
|
25809
25897
|
}
|
|
25810
|
-
function
|
|
25811
|
-
|
|
25812
|
-
const
|
|
25813
|
-
const priceChange24h = liveMarkPrice - snapshot.prevDayPrice;
|
|
25814
|
-
const priceChange24hPercent = snapshot.prevDayPrice !== 0 ? (liveMarkPrice - snapshot.prevDayPrice) / snapshot.prevDayPrice * 100 : 0;
|
|
25898
|
+
function toSymmTokenMetadata(currentPrice, prevDayPrice) {
|
|
25899
|
+
const priceChange24h = currentPrice - prevDayPrice;
|
|
25900
|
+
const priceChange24hPercent = prevDayPrice !== 0 ? (currentPrice - prevDayPrice) / prevDayPrice * 100 : 0;
|
|
25815
25901
|
return {
|
|
25816
|
-
currentPrice
|
|
25817
|
-
prevDayPrice
|
|
25902
|
+
currentPrice,
|
|
25903
|
+
prevDayPrice,
|
|
25818
25904
|
priceChange24h,
|
|
25819
25905
|
priceChange24hPercent,
|
|
25820
25906
|
netFunding: 0,
|
|
25821
|
-
|
|
25907
|
+
// SYMM funding integration deferred
|
|
25908
|
+
markPrice: currentPrice
|
|
25822
25909
|
};
|
|
25823
25910
|
}
|
|
25824
|
-
function useSymmTokenSelectionMetadata(selection, options) {
|
|
25911
|
+
function useSymmTokenSelectionMetadata(selection, options = {}) {
|
|
25825
25912
|
const { longTokens, shortTokens, selectedSymbols } = selection;
|
|
25913
|
+
const { enabled = true } = options;
|
|
25826
25914
|
const unsupportedSymbols = react.useMemo(
|
|
25827
25915
|
() => getUnsupportedBinanceSymbols(selectedSymbols),
|
|
25828
25916
|
[selectedSymbols]
|
|
25829
25917
|
);
|
|
25830
25918
|
const isUnsupported = unsupportedSymbols.length > 0;
|
|
25831
25919
|
const unavailableReason = isUnsupported ? `Binance market data is unavailable for ${unsupportedSymbols.join(", ")}.` : null;
|
|
25832
|
-
const externalEnabled = options?.enabled ?? true;
|
|
25833
|
-
const internalEnabled = externalEnabled && selectedSymbols.length > 0 && !isUnsupported;
|
|
25834
|
-
const [liveMarkPrices, setLiveMarkPrices] = react.useState(EMPTY_MARK_PRICES);
|
|
25835
25920
|
const symbolsKey = [...selectedSymbols].sort().join(",");
|
|
25836
|
-
const
|
|
25837
|
-
|
|
25838
|
-
|
|
25839
|
-
|
|
25921
|
+
const symbolToBinanceMap = react.useMemo(
|
|
25922
|
+
() => new Map(
|
|
25923
|
+
selectedSymbols.map(
|
|
25924
|
+
(symbol) => [symbol, resolveBinanceSymbol(symbol).binanceSymbol]
|
|
25925
|
+
).filter((entry) => !!entry[1])
|
|
25926
|
+
),
|
|
25927
|
+
[selectedSymbols]
|
|
25928
|
+
);
|
|
25929
|
+
const [liveMarkPrices, setLiveMarkPrices] = react.useState(
|
|
25930
|
+
{}
|
|
25931
|
+
);
|
|
25840
25932
|
const query = reactQuery.useQuery({
|
|
25841
|
-
|
|
25842
|
-
queryKey: symmKeys.chartMetadata(symbolsKey, positionKey),
|
|
25933
|
+
queryKey: ["symm", "chart-metadata", symbolsKey],
|
|
25843
25934
|
queryFn: async () => {
|
|
25844
25935
|
const allSymbols = [
|
|
25845
25936
|
...longTokens.map((t) => ({ symbol: t.symbol, side: "long" })),
|
|
25846
|
-
...shortTokens.map((t) => ({
|
|
25937
|
+
...shortTokens.map((t) => ({
|
|
25938
|
+
symbol: t.symbol,
|
|
25939
|
+
side: "short"
|
|
25940
|
+
}))
|
|
25847
25941
|
];
|
|
25848
25942
|
const results = await Promise.all(
|
|
25849
|
-
allSymbols.map(async ({ symbol
|
|
25943
|
+
allSymbols.map(async ({ symbol }) => ({
|
|
25850
25944
|
symbol,
|
|
25851
|
-
|
|
25852
|
-
metadata: await fetchTokenMetadata(symbol)
|
|
25945
|
+
ticker: await fetchTickerSnapshot(symbol)
|
|
25853
25946
|
}))
|
|
25854
25947
|
);
|
|
25855
|
-
const
|
|
25856
|
-
const
|
|
25857
|
-
|
|
25858
|
-
if (side === "long") longMeta[symbol] = metadata;
|
|
25859
|
-
else shortMeta[symbol] = metadata;
|
|
25948
|
+
const tickerSnapshots = {};
|
|
25949
|
+
for (const { symbol, ticker } of results) {
|
|
25950
|
+
tickerSnapshots[symbol] = ticker;
|
|
25860
25951
|
}
|
|
25861
|
-
return {
|
|
25952
|
+
return { tickerSnapshots };
|
|
25862
25953
|
},
|
|
25863
|
-
enabled:
|
|
25864
|
-
staleTime:
|
|
25865
|
-
|
|
25954
|
+
enabled: enabled && selectedSymbols.length > 0 && !isUnsupported,
|
|
25955
|
+
staleTime: Infinity,
|
|
25956
|
+
gcTime: 5 * 6e4
|
|
25866
25957
|
});
|
|
25867
25958
|
react.useEffect(() => {
|
|
25868
|
-
if (!
|
|
25869
|
-
setLiveMarkPrices(
|
|
25959
|
+
if (!enabled || isUnsupported || selectedSymbols.length === 0) {
|
|
25960
|
+
setLiveMarkPrices({});
|
|
25870
25961
|
return;
|
|
25871
25962
|
}
|
|
25872
|
-
|
|
25873
|
-
|
|
25874
|
-
symbol
|
|
25875
|
-
|
|
25876
|
-
|
|
25877
|
-
setLiveMarkPrices((previous) => {
|
|
25878
|
-
const nextEntries = activeSymbols.map(({ symbol }) => [symbol, previous[symbol]]).filter(([, value]) => value != null);
|
|
25879
|
-
return Object.fromEntries(nextEntries);
|
|
25880
|
-
});
|
|
25881
|
-
const unsubscribers = activeSymbols.map(({ symbol, binanceSymbol }) => wsManager.subscribeMarkPrice(binanceSymbol, (data) => {
|
|
25882
|
-
setLiveMarkPrices((previous) => {
|
|
25883
|
-
const current = previous[symbol];
|
|
25884
|
-
if (current?.markPrice === data.markPrice && current?.indexPrice === data.indexPrice && current?.time === data.time) {
|
|
25885
|
-
return previous;
|
|
25963
|
+
setLiveMarkPrices((current) => {
|
|
25964
|
+
const next = {};
|
|
25965
|
+
for (const symbol of selectedSymbols) {
|
|
25966
|
+
if (current[symbol] != null) {
|
|
25967
|
+
next[symbol] = current[symbol];
|
|
25886
25968
|
}
|
|
25887
|
-
|
|
25888
|
-
|
|
25889
|
-
|
|
25890
|
-
|
|
25891
|
-
|
|
25892
|
-
|
|
25969
|
+
}
|
|
25970
|
+
return next;
|
|
25971
|
+
});
|
|
25972
|
+
const wsManager = getBinanceWsManager();
|
|
25973
|
+
const unsubscribes = Array.from(symbolToBinanceMap.entries()).map(
|
|
25974
|
+
([symbol, binanceSymbol]) => wsManager.subscribeMarkPrice(binanceSymbol, (data) => {
|
|
25975
|
+
setLiveMarkPrices((current) => {
|
|
25976
|
+
if (current[symbol] === data.markPrice) return current;
|
|
25977
|
+
return {
|
|
25978
|
+
...current,
|
|
25979
|
+
[symbol]: data.markPrice
|
|
25980
|
+
};
|
|
25981
|
+
});
|
|
25982
|
+
})
|
|
25983
|
+
);
|
|
25893
25984
|
return () => {
|
|
25894
|
-
|
|
25985
|
+
for (const unsubscribe of unsubscribes) {
|
|
25986
|
+
unsubscribe();
|
|
25987
|
+
}
|
|
25895
25988
|
};
|
|
25896
|
-
}, [
|
|
25989
|
+
}, [enabled, isUnsupported, selectedSymbols, symbolToBinanceMap]);
|
|
25897
25990
|
return react.useMemo(() => {
|
|
25898
|
-
|
|
25899
|
-
|
|
25900
|
-
|
|
25901
|
-
|
|
25902
|
-
|
|
25903
|
-
|
|
25904
|
-
|
|
25905
|
-
|
|
25906
|
-
shortTokensMetadata: EMPTY_TOKEN_METADATA,
|
|
25907
|
-
weightedRatio: 0,
|
|
25908
|
-
weightedRatio24h: 0,
|
|
25909
|
-
priceRatio: 0,
|
|
25910
|
-
priceRatio24h: 0,
|
|
25911
|
-
sumNetFunding: 0
|
|
25912
|
-
};
|
|
25991
|
+
const tickerSnapshots = query.data?.tickerSnapshots ?? {};
|
|
25992
|
+
const longMeta = {};
|
|
25993
|
+
const shortMeta = {};
|
|
25994
|
+
const isLoading = query.isLoading;
|
|
25995
|
+
for (const token of longTokens) {
|
|
25996
|
+
const currentPrice = liveMarkPrices[token.symbol];
|
|
25997
|
+
const ticker = tickerSnapshots[token.symbol];
|
|
25998
|
+
longMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.prevClosePrice) : null;
|
|
25913
25999
|
}
|
|
25914
|
-
const
|
|
25915
|
-
|
|
25916
|
-
|
|
25917
|
-
|
|
25918
|
-
|
|
26000
|
+
for (const token of shortTokens) {
|
|
26001
|
+
const currentPrice = liveMarkPrices[token.symbol];
|
|
26002
|
+
const ticker = tickerSnapshots[token.symbol];
|
|
26003
|
+
shortMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.prevClosePrice) : null;
|
|
26004
|
+
}
|
|
26005
|
+
const allLongReady = longTokens.every(
|
|
26006
|
+
(t) => longMeta[t.symbol]?.currentPrice != null
|
|
25919
26007
|
);
|
|
25920
|
-
const
|
|
25921
|
-
|
|
25922
|
-
token.symbol,
|
|
25923
|
-
createLiveMetadata(token.symbol, query.data?.shortMeta?.[token.symbol], liveMarkPrices)
|
|
25924
|
-
])
|
|
26008
|
+
const allShortReady = shortTokens.every(
|
|
26009
|
+
(t) => shortMeta[t.symbol]?.currentPrice != null
|
|
25925
26010
|
);
|
|
25926
|
-
const isLoading = query.isLoading;
|
|
25927
|
-
const allLongReady = longTokens.every((t) => longMeta[t.symbol]?.currentPrice != null);
|
|
25928
|
-
const allShortReady = shortTokens.every((t) => shortMeta[t.symbol]?.currentPrice != null);
|
|
25929
26011
|
const isPriceDataReady = !isLoading && !isUnsupported && (selectedSymbols.length === 0 || allLongReady && allShortReady);
|
|
25930
26012
|
const metricInput = {
|
|
25931
26013
|
longTokens,
|
|
@@ -25953,16 +26035,15 @@ function useSymmTokenSelectionMetadata(selection, options) {
|
|
|
25953
26035
|
sumNetFunding
|
|
25954
26036
|
};
|
|
25955
26037
|
}, [
|
|
25956
|
-
externalEnabled,
|
|
25957
26038
|
isUnsupported,
|
|
25958
26039
|
longTokens,
|
|
25959
|
-
liveMarkPrices,
|
|
25960
26040
|
query.data,
|
|
25961
26041
|
query.isLoading,
|
|
25962
26042
|
shortTokens,
|
|
25963
26043
|
unavailableReason,
|
|
25964
26044
|
unsupportedSymbols,
|
|
25965
|
-
selectedSymbols.length
|
|
26045
|
+
selectedSymbols.length,
|
|
26046
|
+
liveMarkPrices
|
|
25966
26047
|
]);
|
|
25967
26048
|
}
|
|
25968
26049
|
|
|
@@ -26348,6 +26429,8 @@ function getSymmErrorMessage(error) {
|
|
|
26348
26429
|
exports.SymmProvider = SymmProvider;
|
|
26349
26430
|
exports.getSymmErrorMessage = getSymmErrorMessage;
|
|
26350
26431
|
exports.symmKeys = symmKeys;
|
|
26432
|
+
exports.useSymmAccountData = useSymmAccountData;
|
|
26433
|
+
exports.useSymmAccountSummary = useSymmAccountSummary;
|
|
26351
26434
|
exports.useSymmAccounts = useSymmAccounts;
|
|
26352
26435
|
exports.useSymmApproval = useSymmApproval;
|
|
26353
26436
|
exports.useSymmAuth = useSymmAuth;
|