@pear-protocol/symmio-client 0.3.13 → 0.3.14
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.d.mts +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +207 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +205 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +232 -2
- package/dist/react/index.d.ts +232 -2
- package/dist/react/index.js +242 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +239 -3
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +1 -1
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +1 -1
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -576,7 +576,7 @@ var symmKeys = {
|
|
|
576
576
|
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
577
577
|
auth: (accountAddress, chainId, signerAddress) => ["symm", "auth", accountAddress, chainId, signerAddress],
|
|
578
578
|
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
579
|
-
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
579
|
+
balances: (address, chainId, multiAccountAddress) => multiAccountAddress === void 0 ? ["symm", "balances", address, chainId] : ["symm", "balances", address, chainId, multiAccountAddress],
|
|
580
580
|
positions: (params) => ["symm", "positions", params],
|
|
581
581
|
openOrders: (params) => ["symm", "openOrders", params],
|
|
582
582
|
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
@@ -25640,7 +25640,7 @@ function useSymmBalances(params) {
|
|
|
25640
25640
|
const internalEnabled = !!symmCoreClient && !!userAddress;
|
|
25641
25641
|
return useQuery({
|
|
25642
25642
|
...params.query,
|
|
25643
|
-
queryKey: symmKeys.balances(userAddress, chainId),
|
|
25643
|
+
queryKey: symmKeys.balances(userAddress, chainId, multiAccountAddress),
|
|
25644
25644
|
queryFn: () => symmCoreClient.accounts.getBalanceInfo({
|
|
25645
25645
|
userAddress,
|
|
25646
25646
|
chainId,
|
|
@@ -25649,6 +25649,242 @@ function useSymmBalances(params) {
|
|
|
25649
25649
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25650
25650
|
});
|
|
25651
25651
|
}
|
|
25652
|
+
|
|
25653
|
+
// src/utils/account-overview.ts
|
|
25654
|
+
var BALANCE_INFO_KEYS = [
|
|
25655
|
+
"allocatedBalance",
|
|
25656
|
+
"allocated_balance",
|
|
25657
|
+
"cva",
|
|
25658
|
+
"lf",
|
|
25659
|
+
"partyAmm",
|
|
25660
|
+
"partyAMM",
|
|
25661
|
+
"party_a_mm",
|
|
25662
|
+
"mm",
|
|
25663
|
+
"lockedPartyAMM",
|
|
25664
|
+
"upnl"
|
|
25665
|
+
];
|
|
25666
|
+
function isRecord(value) {
|
|
25667
|
+
return typeof value === "object" && value !== null;
|
|
25668
|
+
}
|
|
25669
|
+
function hasBalanceInfoShape(value) {
|
|
25670
|
+
return isRecord(value) && BALANCE_INFO_KEYS.some((key) => key in value);
|
|
25671
|
+
}
|
|
25672
|
+
function readValue(source, keys) {
|
|
25673
|
+
for (const key of keys) {
|
|
25674
|
+
if (key in source) {
|
|
25675
|
+
return source[key];
|
|
25676
|
+
}
|
|
25677
|
+
}
|
|
25678
|
+
return void 0;
|
|
25679
|
+
}
|
|
25680
|
+
function toNumber(value) {
|
|
25681
|
+
if (value === null || value === void 0 || value === "") {
|
|
25682
|
+
return 0;
|
|
25683
|
+
}
|
|
25684
|
+
if (typeof value === "bigint") {
|
|
25685
|
+
return Number(value);
|
|
25686
|
+
}
|
|
25687
|
+
const parsed = Number(value);
|
|
25688
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
25689
|
+
}
|
|
25690
|
+
function toDisplayString(value) {
|
|
25691
|
+
if (Object.is(value, -0) || Math.abs(value) < Number.EPSILON) {
|
|
25692
|
+
return "0";
|
|
25693
|
+
}
|
|
25694
|
+
return String(value);
|
|
25695
|
+
}
|
|
25696
|
+
function readNumber(source, keys) {
|
|
25697
|
+
return toNumber(readValue(source, keys));
|
|
25698
|
+
}
|
|
25699
|
+
function readTimestamp(source) {
|
|
25700
|
+
const timestamp = readValue(source, ["timestamp"]);
|
|
25701
|
+
if (timestamp === void 0 || timestamp === null) {
|
|
25702
|
+
return void 0;
|
|
25703
|
+
}
|
|
25704
|
+
const parsed = Number(timestamp);
|
|
25705
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
25706
|
+
}
|
|
25707
|
+
function getBalanceInfoContainer(response) {
|
|
25708
|
+
if (!isRecord(response)) {
|
|
25709
|
+
return void 0;
|
|
25710
|
+
}
|
|
25711
|
+
if (hasBalanceInfoShape(response)) {
|
|
25712
|
+
return response;
|
|
25713
|
+
}
|
|
25714
|
+
const data = response.data;
|
|
25715
|
+
if (isRecord(data)) {
|
|
25716
|
+
return data;
|
|
25717
|
+
}
|
|
25718
|
+
return response;
|
|
25719
|
+
}
|
|
25720
|
+
function getSymmAccountBalanceInfo(response, accountAddress) {
|
|
25721
|
+
const container = getBalanceInfoContainer(response);
|
|
25722
|
+
if (!container) {
|
|
25723
|
+
return void 0;
|
|
25724
|
+
}
|
|
25725
|
+
if (hasBalanceInfoShape(container)) {
|
|
25726
|
+
return container;
|
|
25727
|
+
}
|
|
25728
|
+
if (accountAddress) {
|
|
25729
|
+
const normalizedAddress = accountAddress.toLowerCase();
|
|
25730
|
+
const direct = container[accountAddress] ?? container[normalizedAddress];
|
|
25731
|
+
if (isRecord(direct) && hasBalanceInfoShape(direct)) {
|
|
25732
|
+
return direct;
|
|
25733
|
+
}
|
|
25734
|
+
const matchingEntry = Object.entries(container).find(
|
|
25735
|
+
([key]) => key.toLowerCase() === normalizedAddress
|
|
25736
|
+
);
|
|
25737
|
+
if (isRecord(matchingEntry?.[1]) && hasBalanceInfoShape(matchingEntry[1])) {
|
|
25738
|
+
return matchingEntry[1];
|
|
25739
|
+
}
|
|
25740
|
+
}
|
|
25741
|
+
const values = Object.values(container);
|
|
25742
|
+
if (values.length === 1 && isRecord(values[0]) && hasBalanceInfoShape(values[0])) {
|
|
25743
|
+
return values[0];
|
|
25744
|
+
}
|
|
25745
|
+
return void 0;
|
|
25746
|
+
}
|
|
25747
|
+
function computeSymmAccountOverview({
|
|
25748
|
+
balanceInfo,
|
|
25749
|
+
upnl: upnlOverride,
|
|
25750
|
+
netDeposited
|
|
25751
|
+
}) {
|
|
25752
|
+
const allocatedBalance = readNumber(balanceInfo, [
|
|
25753
|
+
"allocatedBalance",
|
|
25754
|
+
"allocated_balance"
|
|
25755
|
+
]);
|
|
25756
|
+
const cva = readNumber(balanceInfo, ["cva", "lockedCVA", "locked_cva"]);
|
|
25757
|
+
const lf = readNumber(balanceInfo, ["lf", "lockedLF", "locked_lf"]);
|
|
25758
|
+
const partyAmm = readNumber(balanceInfo, [
|
|
25759
|
+
"partyAmm",
|
|
25760
|
+
"partyAMM",
|
|
25761
|
+
"party_a_mm",
|
|
25762
|
+
"mm",
|
|
25763
|
+
"lockedPartyAMM",
|
|
25764
|
+
"locked_party_a_mm"
|
|
25765
|
+
]);
|
|
25766
|
+
const pendingCva = readNumber(balanceInfo, [
|
|
25767
|
+
"pendingCva",
|
|
25768
|
+
"pending_cva",
|
|
25769
|
+
"pendingLockedCVA",
|
|
25770
|
+
"pending_locked_cva"
|
|
25771
|
+
]);
|
|
25772
|
+
const pendingLf = readNumber(balanceInfo, [
|
|
25773
|
+
"pendingLf",
|
|
25774
|
+
"pending_lf",
|
|
25775
|
+
"pendingLockedLF",
|
|
25776
|
+
"pending_locked_lf"
|
|
25777
|
+
]);
|
|
25778
|
+
const pendingPartyAmm = readNumber(balanceInfo, [
|
|
25779
|
+
"pendingPartyAmm",
|
|
25780
|
+
"pendingPartyAMM",
|
|
25781
|
+
"pending_party_a_mm",
|
|
25782
|
+
"pendingMm",
|
|
25783
|
+
"pending_mm",
|
|
25784
|
+
"pendingLockedPartyAMM",
|
|
25785
|
+
"pending_locked_party_a_mm"
|
|
25786
|
+
]);
|
|
25787
|
+
const upnl = upnlOverride === void 0 ? readNumber(balanceInfo, ["upnl"]) : toNumber(upnlOverride);
|
|
25788
|
+
const computedTotalLocked = cva + lf + partyAmm;
|
|
25789
|
+
const totalLocked = readValue(
|
|
25790
|
+
balanceInfo,
|
|
25791
|
+
["totalLocked", "total_locked"]
|
|
25792
|
+
) === void 0 ? computedTotalLocked : readNumber(balanceInfo, ["totalLocked", "total_locked"]);
|
|
25793
|
+
const totalPendingLocked = readValue(balanceInfo, [
|
|
25794
|
+
"totalPendingLocked",
|
|
25795
|
+
"total_pending_locked"
|
|
25796
|
+
]) === void 0 ? pendingCva + pendingLf + pendingPartyAmm : readNumber(balanceInfo, ["totalPendingLocked", "total_pending_locked"]);
|
|
25797
|
+
const maintenanceMargin = cva + lf;
|
|
25798
|
+
const equity = allocatedBalance + upnl;
|
|
25799
|
+
const availableForOrder = upnl >= 0 ? allocatedBalance + upnl - totalLocked - totalPendingLocked : allocatedBalance - cva - lf - totalPendingLocked - Math.max(Math.abs(upnl), partyAmm);
|
|
25800
|
+
const availableBalance = readNumber(balanceInfo, [
|
|
25801
|
+
"availableBalance",
|
|
25802
|
+
"available_balance"
|
|
25803
|
+
]);
|
|
25804
|
+
const notional = readNumber(balanceInfo, ["notional"]);
|
|
25805
|
+
return {
|
|
25806
|
+
allocatedBalance: toDisplayString(allocatedBalance),
|
|
25807
|
+
upnl: toDisplayString(upnl),
|
|
25808
|
+
equity: toDisplayString(equity),
|
|
25809
|
+
totalAccountValue: toDisplayString(equity),
|
|
25810
|
+
maintenanceMargin: toDisplayString(maintenanceMargin),
|
|
25811
|
+
totalLocked: toDisplayString(totalLocked),
|
|
25812
|
+
marginUsed: toDisplayString(computedTotalLocked),
|
|
25813
|
+
totalPendingLocked: toDisplayString(totalPendingLocked),
|
|
25814
|
+
availableForOrder: toDisplayString(availableForOrder),
|
|
25815
|
+
availableMargin: toDisplayString(availableForOrder),
|
|
25816
|
+
availableBalance: toDisplayString(availableBalance),
|
|
25817
|
+
netDeposited: toDisplayString(toNumber(netDeposited)),
|
|
25818
|
+
notional: toDisplayString(notional),
|
|
25819
|
+
timestamp: readTimestamp(balanceInfo)
|
|
25820
|
+
};
|
|
25821
|
+
}
|
|
25822
|
+
function computeSymmNetDeposited(totals, decimals = 6) {
|
|
25823
|
+
if (!totals) {
|
|
25824
|
+
return "0";
|
|
25825
|
+
}
|
|
25826
|
+
const deposit2 = parseRawCollateralUnits(totals.deposit);
|
|
25827
|
+
const withdraw2 = parseRawCollateralUnits(totals.withdraw);
|
|
25828
|
+
const value = deposit2 - withdraw2;
|
|
25829
|
+
const negative = value < 0n;
|
|
25830
|
+
const absolute = negative ? -value : value;
|
|
25831
|
+
const scale = 10n ** BigInt(decimals);
|
|
25832
|
+
const whole = absolute / scale;
|
|
25833
|
+
const fraction = absolute % scale;
|
|
25834
|
+
const fractionText = fraction.toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
25835
|
+
const amount = fractionText ? `${whole}.${fractionText}` : whole.toString();
|
|
25836
|
+
return negative ? `-${amount}` : amount;
|
|
25837
|
+
}
|
|
25838
|
+
function parseRawCollateralUnits(value) {
|
|
25839
|
+
if (value === null || value === void 0 || value === "") {
|
|
25840
|
+
return 0n;
|
|
25841
|
+
}
|
|
25842
|
+
if (typeof value === "bigint") {
|
|
25843
|
+
return value;
|
|
25844
|
+
}
|
|
25845
|
+
if (typeof value === "number") {
|
|
25846
|
+
if (!Number.isSafeInteger(value)) {
|
|
25847
|
+
throw new Error("Raw collateral unit numbers must be safe integers");
|
|
25848
|
+
}
|
|
25849
|
+
return BigInt(value);
|
|
25850
|
+
}
|
|
25851
|
+
if (!/^-?\d+$/.test(value)) {
|
|
25852
|
+
throw new Error("Raw collateral unit strings must be base-10 integers");
|
|
25853
|
+
}
|
|
25854
|
+
return BigInt(value);
|
|
25855
|
+
}
|
|
25856
|
+
|
|
25857
|
+
// src/react/hooks/use-symm-account-overview.ts
|
|
25858
|
+
function useSymmAccountOverview(params) {
|
|
25859
|
+
const {
|
|
25860
|
+
userAddress,
|
|
25861
|
+
accountAddress,
|
|
25862
|
+
multiAccountAddress,
|
|
25863
|
+
upnl,
|
|
25864
|
+
netDeposited
|
|
25865
|
+
} = params;
|
|
25866
|
+
const query = useSymmBalances({
|
|
25867
|
+
userAddress,
|
|
25868
|
+
multiAccountAddress,
|
|
25869
|
+
chainId: params.chainId,
|
|
25870
|
+
query: params.query
|
|
25871
|
+
});
|
|
25872
|
+
const data = useMemo(() => {
|
|
25873
|
+
if (query.data === void 0) {
|
|
25874
|
+
return void 0;
|
|
25875
|
+
}
|
|
25876
|
+
const balanceInfo = getSymmAccountBalanceInfo(
|
|
25877
|
+
query.data,
|
|
25878
|
+
accountAddress ?? userAddress
|
|
25879
|
+
);
|
|
25880
|
+
return {
|
|
25881
|
+
response: query.data,
|
|
25882
|
+
balanceInfo,
|
|
25883
|
+
overview: balanceInfo ? computeSymmAccountOverview({ balanceInfo, upnl, netDeposited }) : void 0
|
|
25884
|
+
};
|
|
25885
|
+
}, [accountAddress, netDeposited, query.data, upnl, userAddress]);
|
|
25886
|
+
return { ...query, data };
|
|
25887
|
+
}
|
|
25652
25888
|
function useSymmOpenBasketMutation(options) {
|
|
25653
25889
|
const { symmCoreClient } = useSymmContext();
|
|
25654
25890
|
const queryClient = useQueryClient();
|
|
@@ -27221,6 +27457,6 @@ function getSymmErrorMessage(error) {
|
|
|
27221
27457
|
return "An unexpected error occurred.";
|
|
27222
27458
|
}
|
|
27223
27459
|
|
|
27224
|
-
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 };
|
|
27460
|
+
export { SymmProvider, computeSymmAccountOverview, computeSymmNetDeposited, getSymmAccountBalanceInfo, getSymmErrorMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountData, useSymmAccountOverview, 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 };
|
|
27225
27461
|
//# sourceMappingURL=index.mjs.map
|
|
27226
27462
|
//# sourceMappingURL=index.mjs.map
|