@pear-protocol/symmio-client 0.3.13 → 0.3.15

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 CHANGED
@@ -19843,4 +19843,98 @@ declare function formatPrice(price: bigint, decimals: number, precision?: number
19843
19843
  */
19844
19844
  declare function applySlippage(price: bigint, slippagePercent: number, isLong: boolean): bigint;
19845
19845
 
19846
- export { type ADLAssurance, ALL_TRADING_SELECTORS, type Account, type AccountBalance, type AccumulatedFundingRate, type AddAccountParams, type AffiliateFeeConfig, AffiliateFeeLevel, type AggregatedPosition, type AllocateParams, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, type CancelQuoteParams, type ChainId, ClearingHouseABI, type ClearingHouseLiquidation, ClearingHouseLiquidationStatus, type ClosePositionParams, type CreateSiweMessageParams, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, type DeallocateParams, type DepositAndAllocateParams, type DepositParams, ERC20ABI, FALLBACK_CHAIN_ID, type InstantAuthToken, type InstantCloseParams, type InstantCloseResponse, InstantCloseStatus, type InstantErrorResponse, type InstantLoginParams, type InstantOpenParams, type InstantOpenResponse, type InsuranceVaultConfig, type InternalTransferParams, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, type Market, MultiAccountABI, type MuonBatchParams, type MuonBatchSig, MuonClient, type MuonClientConfig, type MuonDeallocateParams, type MuonQuoteParams, type MuonSingleUpnlAndPriceSig, type MuonSingleUpnlSig, type MuonSingleUpnlWithPendingBalanceSig, MuonVerifierABI, OrderType, PositionType, type PreparedTransaction, type Quote, QuoteStatus, type RegisterAffiliateParams, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, type SchnorrSign, type SendQuoteParams, type SetAffiliateFeeParams, SignatureStoreABI, type SiweMessageResult, SoftLiquidationLevel, type SoftLiquidationThreshold, SupportedChainId, type SymbolCategory, type SymbolType, SymmioDiamondABI, type SymmioSDKConfig, SymmioSDKError, type TransactionConfig, type TransactionReceipt, type TransactionResult, V3_CHAIN_IDS, type WithdrawParams, account as accountActions, admin as adminActions, allocate$1 as allocateActions, applySlippage, approval as approvalActions, calculateGasMargin, cancel as cancelActions, close as closeActions, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, instant as instantActions, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
19846
+ type SymmAccountNumericValue = string | number | bigint | null | undefined;
19847
+ type SymmAccountBalanceInfoLike = Record<string, unknown>;
19848
+ interface SymmAccountOverviewInput {
19849
+ balanceInfo: SymmAccountBalanceInfoLike;
19850
+ upnl?: SymmAccountNumericValue;
19851
+ netDeposited?: SymmAccountNumericValue;
19852
+ }
19853
+ interface SymmAccountOverview {
19854
+ allocatedBalance: string;
19855
+ upnl: string;
19856
+ equity: string;
19857
+ totalAccountValue: string;
19858
+ maintenanceMargin: string;
19859
+ accountHealthData?: unknown;
19860
+ totalLocked: string;
19861
+ marginUsed: string;
19862
+ totalPendingLocked: string;
19863
+ availableForOrder: string;
19864
+ availableMargin: string;
19865
+ availableBalance: string;
19866
+ netDeposited: string;
19867
+ notional: string;
19868
+ timestamp?: number;
19869
+ }
19870
+ interface SymmDepositWithdrawalTotals {
19871
+ deposit?: SymmAccountNumericValue;
19872
+ withdraw?: SymmAccountNumericValue;
19873
+ }
19874
+ type SymmAccountDataLike = Record<string, unknown>;
19875
+ declare function getSymmAccountData(response: unknown): SymmAccountDataLike | undefined;
19876
+ /**
19877
+ * Finds a single account's balance info from a core BalanceInfoResponse,
19878
+ * symm-pear hedger map, or a direct balance-info object.
19879
+ */
19880
+ declare function getSymmAccountBalanceInfo(response: unknown, accountAddress?: string): SymmAccountBalanceInfoLike | undefined;
19881
+ /**
19882
+ * Mirrors symm-pear's Account Overview math:
19883
+ * equity = allocated balance + uPnL
19884
+ * maintenance margin = locked CVA + locked LF
19885
+ * margin used = CVA + LF + party A MM
19886
+ */
19887
+ declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, netDeposited, }: SymmAccountOverviewInput): SymmAccountOverview;
19888
+ declare function computeSymmAccountOverviewFromData({ accountData, upnl, netDeposited, }: {
19889
+ accountData: SymmAccountDataLike;
19890
+ upnl?: SymmAccountNumericValue;
19891
+ netDeposited?: SymmAccountNumericValue;
19892
+ }): SymmAccountOverview;
19893
+ /**
19894
+ * Computes the symm-pear net-deposited display value from balance-history
19895
+ * subgraph totals. Inputs must be integer raw collateral units; USDC defaults
19896
+ * to 6 decimals.
19897
+ */
19898
+ declare function computeSymmNetDeposited(totals: SymmDepositWithdrawalTotals | null | undefined, decimals?: number): string;
19899
+
19900
+ type SymmPnlNumericValue = string | number | null | undefined;
19901
+ interface SymmPnlAssetLegLike {
19902
+ symbol?: string;
19903
+ quantity?: SymmPnlNumericValue;
19904
+ openedPrice?: SymmPnlNumericValue;
19905
+ opened_price?: SymmPnlNumericValue;
19906
+ currentPrice?: SymmPnlNumericValue;
19907
+ current_price?: SymmPnlNumericValue;
19908
+ }
19909
+ interface SymmPnlPositionLike {
19910
+ longAssets?: SymmPnlAssetLegLike[];
19911
+ shortAssets?: SymmPnlAssetLegLike[];
19912
+ unrealizedPnl?: SymmPnlNumericValue;
19913
+ unrealized_pnl?: SymmPnlNumericValue;
19914
+ }
19915
+ type SymmMarkPrices = Record<string, number | string | null | undefined>;
19916
+ interface SymmPositionPnlResult {
19917
+ upnl: number;
19918
+ missingSymbols: string[];
19919
+ positionsCount: number;
19920
+ legsCount: number;
19921
+ usedFallbackPositions: number;
19922
+ }
19923
+ declare function computeSymmPositionUpnl(position: SymmPnlPositionLike, markPrices?: SymmMarkPrices): SymmPositionPnlResult;
19924
+ declare function computeSymmPositionsUpnl(positions?: readonly SymmPnlPositionLike[], markPrices?: SymmMarkPrices): SymmPositionPnlResult;
19925
+ interface SymmUpnlWebSocketMessage {
19926
+ upnl: number;
19927
+ timestamp?: number;
19928
+ availableBalance: number;
19929
+ allocatedBalance: number;
19930
+ cva: number;
19931
+ lf: number;
19932
+ partyAmm: number;
19933
+ pendingPartyAmm: number;
19934
+ pendingCva: number;
19935
+ pendingLf: number;
19936
+ raw: unknown;
19937
+ }
19938
+ declare function normalizeSymmUpnlWebSocketMessage(raw: unknown): SymmUpnlWebSocketMessage | undefined;
19939
+
19940
+ export { type ADLAssurance, ALL_TRADING_SELECTORS, type Account, type AccountBalance, type AccumulatedFundingRate, type AddAccountParams, type AffiliateFeeConfig, AffiliateFeeLevel, type AggregatedPosition, type AllocateParams, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, type CancelQuoteParams, type ChainId, ClearingHouseABI, type ClearingHouseLiquidation, ClearingHouseLiquidationStatus, type ClosePositionParams, type CreateSiweMessageParams, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, type DeallocateParams, type DepositAndAllocateParams, type DepositParams, ERC20ABI, FALLBACK_CHAIN_ID, type InstantAuthToken, type InstantCloseParams, type InstantCloseResponse, InstantCloseStatus, type InstantErrorResponse, type InstantLoginParams, type InstantOpenParams, type InstantOpenResponse, type InsuranceVaultConfig, type InternalTransferParams, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, type Market, MultiAccountABI, type MuonBatchParams, type MuonBatchSig, MuonClient, type MuonClientConfig, type MuonDeallocateParams, type MuonQuoteParams, type MuonSingleUpnlAndPriceSig, type MuonSingleUpnlSig, type MuonSingleUpnlWithPendingBalanceSig, MuonVerifierABI, OrderType, PositionType, type PreparedTransaction, type Quote, QuoteStatus, type RegisterAffiliateParams, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, type SchnorrSign, type SendQuoteParams, type SetAffiliateFeeParams, SignatureStoreABI, type SiweMessageResult, SoftLiquidationLevel, type SoftLiquidationThreshold, SupportedChainId, type SymbolCategory, type SymbolType, type SymmAccountBalanceInfoLike, type SymmAccountDataLike, type SymmAccountNumericValue, type SymmAccountOverview, type SymmAccountOverviewInput, type SymmDepositWithdrawalTotals, type SymmMarkPrices, type SymmPnlAssetLegLike, type SymmPnlNumericValue, type SymmPnlPositionLike, type SymmPositionPnlResult, type SymmUpnlWebSocketMessage, SymmioDiamondABI, type SymmioSDKConfig, SymmioSDKError, type TransactionConfig, type TransactionReceipt, type TransactionResult, V3_CHAIN_IDS, type WithdrawParams, account as accountActions, admin as adminActions, allocate$1 as allocateActions, applySlippage, approval as approvalActions, calculateGasMargin, cancel as cancelActions, close as closeActions, computeSymmAccountOverview, computeSymmAccountOverviewFromData, computeSymmNetDeposited, computeSymmPositionUpnl, computeSymmPositionsUpnl, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, getSymmAccountData, instant as instantActions, normalizeSymmUpnlWebSocketMessage, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
package/dist/index.d.ts CHANGED
@@ -19843,4 +19843,98 @@ declare function formatPrice(price: bigint, decimals: number, precision?: number
19843
19843
  */
19844
19844
  declare function applySlippage(price: bigint, slippagePercent: number, isLong: boolean): bigint;
19845
19845
 
19846
- export { type ADLAssurance, ALL_TRADING_SELECTORS, type Account, type AccountBalance, type AccumulatedFundingRate, type AddAccountParams, type AffiliateFeeConfig, AffiliateFeeLevel, type AggregatedPosition, type AllocateParams, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, type CancelQuoteParams, type ChainId, ClearingHouseABI, type ClearingHouseLiquidation, ClearingHouseLiquidationStatus, type ClosePositionParams, type CreateSiweMessageParams, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, type DeallocateParams, type DepositAndAllocateParams, type DepositParams, ERC20ABI, FALLBACK_CHAIN_ID, type InstantAuthToken, type InstantCloseParams, type InstantCloseResponse, InstantCloseStatus, type InstantErrorResponse, type InstantLoginParams, type InstantOpenParams, type InstantOpenResponse, type InsuranceVaultConfig, type InternalTransferParams, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, type Market, MultiAccountABI, type MuonBatchParams, type MuonBatchSig, MuonClient, type MuonClientConfig, type MuonDeallocateParams, type MuonQuoteParams, type MuonSingleUpnlAndPriceSig, type MuonSingleUpnlSig, type MuonSingleUpnlWithPendingBalanceSig, MuonVerifierABI, OrderType, PositionType, type PreparedTransaction, type Quote, QuoteStatus, type RegisterAffiliateParams, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, type SchnorrSign, type SendQuoteParams, type SetAffiliateFeeParams, SignatureStoreABI, type SiweMessageResult, SoftLiquidationLevel, type SoftLiquidationThreshold, SupportedChainId, type SymbolCategory, type SymbolType, SymmioDiamondABI, type SymmioSDKConfig, SymmioSDKError, type TransactionConfig, type TransactionReceipt, type TransactionResult, V3_CHAIN_IDS, type WithdrawParams, account as accountActions, admin as adminActions, allocate$1 as allocateActions, applySlippage, approval as approvalActions, calculateGasMargin, cancel as cancelActions, close as closeActions, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, instant as instantActions, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
19846
+ type SymmAccountNumericValue = string | number | bigint | null | undefined;
19847
+ type SymmAccountBalanceInfoLike = Record<string, unknown>;
19848
+ interface SymmAccountOverviewInput {
19849
+ balanceInfo: SymmAccountBalanceInfoLike;
19850
+ upnl?: SymmAccountNumericValue;
19851
+ netDeposited?: SymmAccountNumericValue;
19852
+ }
19853
+ interface SymmAccountOverview {
19854
+ allocatedBalance: string;
19855
+ upnl: string;
19856
+ equity: string;
19857
+ totalAccountValue: string;
19858
+ maintenanceMargin: string;
19859
+ accountHealthData?: unknown;
19860
+ totalLocked: string;
19861
+ marginUsed: string;
19862
+ totalPendingLocked: string;
19863
+ availableForOrder: string;
19864
+ availableMargin: string;
19865
+ availableBalance: string;
19866
+ netDeposited: string;
19867
+ notional: string;
19868
+ timestamp?: number;
19869
+ }
19870
+ interface SymmDepositWithdrawalTotals {
19871
+ deposit?: SymmAccountNumericValue;
19872
+ withdraw?: SymmAccountNumericValue;
19873
+ }
19874
+ type SymmAccountDataLike = Record<string, unknown>;
19875
+ declare function getSymmAccountData(response: unknown): SymmAccountDataLike | undefined;
19876
+ /**
19877
+ * Finds a single account's balance info from a core BalanceInfoResponse,
19878
+ * symm-pear hedger map, or a direct balance-info object.
19879
+ */
19880
+ declare function getSymmAccountBalanceInfo(response: unknown, accountAddress?: string): SymmAccountBalanceInfoLike | undefined;
19881
+ /**
19882
+ * Mirrors symm-pear's Account Overview math:
19883
+ * equity = allocated balance + uPnL
19884
+ * maintenance margin = locked CVA + locked LF
19885
+ * margin used = CVA + LF + party A MM
19886
+ */
19887
+ declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, netDeposited, }: SymmAccountOverviewInput): SymmAccountOverview;
19888
+ declare function computeSymmAccountOverviewFromData({ accountData, upnl, netDeposited, }: {
19889
+ accountData: SymmAccountDataLike;
19890
+ upnl?: SymmAccountNumericValue;
19891
+ netDeposited?: SymmAccountNumericValue;
19892
+ }): SymmAccountOverview;
19893
+ /**
19894
+ * Computes the symm-pear net-deposited display value from balance-history
19895
+ * subgraph totals. Inputs must be integer raw collateral units; USDC defaults
19896
+ * to 6 decimals.
19897
+ */
19898
+ declare function computeSymmNetDeposited(totals: SymmDepositWithdrawalTotals | null | undefined, decimals?: number): string;
19899
+
19900
+ type SymmPnlNumericValue = string | number | null | undefined;
19901
+ interface SymmPnlAssetLegLike {
19902
+ symbol?: string;
19903
+ quantity?: SymmPnlNumericValue;
19904
+ openedPrice?: SymmPnlNumericValue;
19905
+ opened_price?: SymmPnlNumericValue;
19906
+ currentPrice?: SymmPnlNumericValue;
19907
+ current_price?: SymmPnlNumericValue;
19908
+ }
19909
+ interface SymmPnlPositionLike {
19910
+ longAssets?: SymmPnlAssetLegLike[];
19911
+ shortAssets?: SymmPnlAssetLegLike[];
19912
+ unrealizedPnl?: SymmPnlNumericValue;
19913
+ unrealized_pnl?: SymmPnlNumericValue;
19914
+ }
19915
+ type SymmMarkPrices = Record<string, number | string | null | undefined>;
19916
+ interface SymmPositionPnlResult {
19917
+ upnl: number;
19918
+ missingSymbols: string[];
19919
+ positionsCount: number;
19920
+ legsCount: number;
19921
+ usedFallbackPositions: number;
19922
+ }
19923
+ declare function computeSymmPositionUpnl(position: SymmPnlPositionLike, markPrices?: SymmMarkPrices): SymmPositionPnlResult;
19924
+ declare function computeSymmPositionsUpnl(positions?: readonly SymmPnlPositionLike[], markPrices?: SymmMarkPrices): SymmPositionPnlResult;
19925
+ interface SymmUpnlWebSocketMessage {
19926
+ upnl: number;
19927
+ timestamp?: number;
19928
+ availableBalance: number;
19929
+ allocatedBalance: number;
19930
+ cva: number;
19931
+ lf: number;
19932
+ partyAmm: number;
19933
+ pendingPartyAmm: number;
19934
+ pendingCva: number;
19935
+ pendingLf: number;
19936
+ raw: unknown;
19937
+ }
19938
+ declare function normalizeSymmUpnlWebSocketMessage(raw: unknown): SymmUpnlWebSocketMessage | undefined;
19939
+
19940
+ export { type ADLAssurance, ALL_TRADING_SELECTORS, type Account, type AccountBalance, type AccumulatedFundingRate, type AddAccountParams, type AffiliateFeeConfig, AffiliateFeeLevel, type AggregatedPosition, type AllocateParams, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, type CancelQuoteParams, type ChainId, ClearingHouseABI, type ClearingHouseLiquidation, ClearingHouseLiquidationStatus, type ClosePositionParams, type CreateSiweMessageParams, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, type DeallocateParams, type DepositAndAllocateParams, type DepositParams, ERC20ABI, FALLBACK_CHAIN_ID, type InstantAuthToken, type InstantCloseParams, type InstantCloseResponse, InstantCloseStatus, type InstantErrorResponse, type InstantLoginParams, type InstantOpenParams, type InstantOpenResponse, type InsuranceVaultConfig, type InternalTransferParams, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, type Market, MultiAccountABI, type MuonBatchParams, type MuonBatchSig, MuonClient, type MuonClientConfig, type MuonDeallocateParams, type MuonQuoteParams, type MuonSingleUpnlAndPriceSig, type MuonSingleUpnlSig, type MuonSingleUpnlWithPendingBalanceSig, MuonVerifierABI, OrderType, PositionType, type PreparedTransaction, type Quote, QuoteStatus, type RegisterAffiliateParams, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, type SchnorrSign, type SendQuoteParams, type SetAffiliateFeeParams, SignatureStoreABI, type SiweMessageResult, SoftLiquidationLevel, type SoftLiquidationThreshold, SupportedChainId, type SymbolCategory, type SymbolType, type SymmAccountBalanceInfoLike, type SymmAccountDataLike, type SymmAccountNumericValue, type SymmAccountOverview, type SymmAccountOverviewInput, type SymmDepositWithdrawalTotals, type SymmMarkPrices, type SymmPnlAssetLegLike, type SymmPnlNumericValue, type SymmPnlPositionLike, type SymmPositionPnlResult, type SymmUpnlWebSocketMessage, SymmioDiamondABI, type SymmioSDKConfig, SymmioSDKError, type TransactionConfig, type TransactionReceipt, type TransactionResult, V3_CHAIN_IDS, type WithdrawParams, account as accountActions, admin as adminActions, allocate$1 as allocateActions, applySlippage, approval as approvalActions, calculateGasMargin, cancel as cancelActions, close as closeActions, computeSymmAccountOverview, computeSymmAccountOverviewFromData, computeSymmNetDeposited, computeSymmPositionUpnl, computeSymmPositionsUpnl, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, getSymmAccountData, instant as instantActions, normalizeSymmUpnlWebSocketMessage, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
package/dist/index.js CHANGED
@@ -24687,6 +24687,387 @@ function applySlippage(price, slippagePercent, isLong) {
24687
24687
  return price - price * bps / 10000n;
24688
24688
  }
24689
24689
 
24690
+ // src/utils/account-overview.ts
24691
+ var BALANCE_INFO_KEYS = [
24692
+ "allocatedBalance",
24693
+ "allocated_balance",
24694
+ "cva",
24695
+ "lf",
24696
+ "partyAmm",
24697
+ "partyAMM",
24698
+ "party_a_mm",
24699
+ "mm",
24700
+ "lockedPartyAMM",
24701
+ "upnl"
24702
+ ];
24703
+ function isRecord(value) {
24704
+ return typeof value === "object" && value !== null;
24705
+ }
24706
+ function hasBalanceInfoShape(value) {
24707
+ return isRecord(value) && BALANCE_INFO_KEYS.some((key) => key in value);
24708
+ }
24709
+ function readValue(source, keys) {
24710
+ for (const key of keys) {
24711
+ if (key in source) {
24712
+ return source[key];
24713
+ }
24714
+ }
24715
+ return void 0;
24716
+ }
24717
+ function toNumber(value) {
24718
+ if (value === null || value === void 0 || value === "") {
24719
+ return 0;
24720
+ }
24721
+ if (typeof value === "bigint") {
24722
+ return Number(value);
24723
+ }
24724
+ const parsed = Number(value);
24725
+ return Number.isFinite(parsed) ? parsed : 0;
24726
+ }
24727
+ function toDisplayString(value) {
24728
+ if (Object.is(value, -0) || Math.abs(value) < Number.EPSILON) {
24729
+ return "0";
24730
+ }
24731
+ return String(value);
24732
+ }
24733
+ function readNumber(source, keys) {
24734
+ return toNumber(readValue(source, keys));
24735
+ }
24736
+ function readTimestamp(source) {
24737
+ const timestamp = readValue(source, ["timestamp"]);
24738
+ if (timestamp === void 0 || timestamp === null) {
24739
+ return void 0;
24740
+ }
24741
+ const parsed = Number(timestamp);
24742
+ return Number.isFinite(parsed) ? parsed : void 0;
24743
+ }
24744
+ function getSymmAccountData(response) {
24745
+ if (!isRecord(response)) {
24746
+ return void 0;
24747
+ }
24748
+ const data = response.data;
24749
+ if (isRecord(data)) {
24750
+ return data;
24751
+ }
24752
+ if ("equity" in response || "maintenanceMargin" in response || "availableForOrder" in response || "totalLocked" in response) {
24753
+ return response;
24754
+ }
24755
+ return void 0;
24756
+ }
24757
+ function getBalanceInfoContainer(response) {
24758
+ if (!isRecord(response)) {
24759
+ return void 0;
24760
+ }
24761
+ if (hasBalanceInfoShape(response)) {
24762
+ return response;
24763
+ }
24764
+ const data = response.data;
24765
+ if (isRecord(data)) {
24766
+ return data;
24767
+ }
24768
+ return response;
24769
+ }
24770
+ function getSymmAccountBalanceInfo(response, accountAddress) {
24771
+ const container = getBalanceInfoContainer(response);
24772
+ if (!container) {
24773
+ return void 0;
24774
+ }
24775
+ if (hasBalanceInfoShape(container)) {
24776
+ return container;
24777
+ }
24778
+ if (accountAddress) {
24779
+ const normalizedAddress = accountAddress.toLowerCase();
24780
+ const direct = container[accountAddress] ?? container[normalizedAddress];
24781
+ if (isRecord(direct) && hasBalanceInfoShape(direct)) {
24782
+ return direct;
24783
+ }
24784
+ const matchingEntry = Object.entries(container).find(
24785
+ ([key]) => key.toLowerCase() === normalizedAddress
24786
+ );
24787
+ if (isRecord(matchingEntry?.[1]) && hasBalanceInfoShape(matchingEntry[1])) {
24788
+ return matchingEntry[1];
24789
+ }
24790
+ }
24791
+ const values = Object.values(container);
24792
+ if (values.length === 1 && isRecord(values[0]) && hasBalanceInfoShape(values[0])) {
24793
+ return values[0];
24794
+ }
24795
+ return void 0;
24796
+ }
24797
+ function computeSymmAccountOverview({
24798
+ balanceInfo,
24799
+ upnl: upnlOverride,
24800
+ netDeposited
24801
+ }) {
24802
+ const allocatedBalance = readNumber(balanceInfo, [
24803
+ "allocatedBalance",
24804
+ "allocated_balance"
24805
+ ]);
24806
+ const cva = readNumber(balanceInfo, ["cva", "lockedCVA", "locked_cva"]);
24807
+ const lf = readNumber(balanceInfo, ["lf", "lockedLF", "locked_lf"]);
24808
+ const partyAmm = readNumber(balanceInfo, [
24809
+ "partyAmm",
24810
+ "partyAMM",
24811
+ "party_a_mm",
24812
+ "mm",
24813
+ "lockedPartyAMM",
24814
+ "locked_party_a_mm"
24815
+ ]);
24816
+ const pendingCva = readNumber(balanceInfo, [
24817
+ "pendingCva",
24818
+ "pending_cva",
24819
+ "pendingLockedCVA",
24820
+ "pending_locked_cva"
24821
+ ]);
24822
+ const pendingLf = readNumber(balanceInfo, [
24823
+ "pendingLf",
24824
+ "pending_lf",
24825
+ "pendingLockedLF",
24826
+ "pending_locked_lf"
24827
+ ]);
24828
+ const pendingPartyAmm = readNumber(balanceInfo, [
24829
+ "pendingPartyAmm",
24830
+ "pendingPartyAMM",
24831
+ "pending_party_a_mm",
24832
+ "pendingMm",
24833
+ "pending_mm",
24834
+ "pendingLockedPartyAMM",
24835
+ "pending_locked_party_a_mm"
24836
+ ]);
24837
+ const upnl = upnlOverride === void 0 ? readNumber(balanceInfo, ["upnl"]) : toNumber(upnlOverride);
24838
+ const computedTotalLocked = cva + lf + partyAmm;
24839
+ const totalLocked = readValue(
24840
+ balanceInfo,
24841
+ ["totalLocked", "total_locked"]
24842
+ ) === void 0 ? computedTotalLocked : readNumber(balanceInfo, ["totalLocked", "total_locked"]);
24843
+ const totalPendingLocked = readValue(balanceInfo, [
24844
+ "totalPendingLocked",
24845
+ "total_pending_locked"
24846
+ ]) === void 0 ? pendingCva + pendingLf + pendingPartyAmm : readNumber(balanceInfo, ["totalPendingLocked", "total_pending_locked"]);
24847
+ const maintenanceMargin = cva + lf;
24848
+ const equity = allocatedBalance + upnl;
24849
+ const availableForOrder = upnl >= 0 ? allocatedBalance + upnl - totalLocked - totalPendingLocked : allocatedBalance - cva - lf - totalPendingLocked - Math.max(Math.abs(upnl), partyAmm);
24850
+ const availableBalance = readNumber(balanceInfo, [
24851
+ "availableBalance",
24852
+ "available_balance"
24853
+ ]);
24854
+ const notional = readNumber(balanceInfo, ["notional"]);
24855
+ return {
24856
+ allocatedBalance: toDisplayString(allocatedBalance),
24857
+ upnl: toDisplayString(upnl),
24858
+ equity: toDisplayString(equity),
24859
+ totalAccountValue: toDisplayString(equity),
24860
+ maintenanceMargin: toDisplayString(maintenanceMargin),
24861
+ totalLocked: toDisplayString(totalLocked),
24862
+ marginUsed: toDisplayString(computedTotalLocked),
24863
+ totalPendingLocked: toDisplayString(totalPendingLocked),
24864
+ availableForOrder: toDisplayString(availableForOrder),
24865
+ availableMargin: toDisplayString(availableForOrder),
24866
+ availableBalance: toDisplayString(availableBalance),
24867
+ netDeposited: toDisplayString(toNumber(netDeposited)),
24868
+ notional: toDisplayString(notional),
24869
+ timestamp: readTimestamp(balanceInfo)
24870
+ };
24871
+ }
24872
+ function computeSymmAccountOverviewFromData({
24873
+ accountData,
24874
+ upnl,
24875
+ netDeposited
24876
+ }) {
24877
+ const equity = readNumber(accountData, ["equity"]);
24878
+ const maintenanceMargin = readNumber(accountData, [
24879
+ "maintenanceMargin",
24880
+ "maintenance_margin"
24881
+ ]);
24882
+ const availableForOrder = readNumber(accountData, [
24883
+ "availableForOrder",
24884
+ "available_for_order"
24885
+ ]);
24886
+ const totalLocked = readNumber(accountData, ["totalLocked", "total_locked"]);
24887
+ return {
24888
+ allocatedBalance: "0",
24889
+ upnl: toDisplayString(toNumber(upnl)),
24890
+ equity: toDisplayString(equity),
24891
+ totalAccountValue: toDisplayString(equity),
24892
+ maintenanceMargin: toDisplayString(maintenanceMargin),
24893
+ accountHealthData: accountData.accountHealthData,
24894
+ totalLocked: toDisplayString(totalLocked),
24895
+ marginUsed: toDisplayString(totalLocked),
24896
+ totalPendingLocked: "0",
24897
+ availableForOrder: toDisplayString(availableForOrder),
24898
+ availableMargin: toDisplayString(availableForOrder),
24899
+ availableBalance: toDisplayString(availableForOrder),
24900
+ netDeposited: toDisplayString(toNumber(netDeposited)),
24901
+ notional: "0"
24902
+ };
24903
+ }
24904
+ function computeSymmNetDeposited(totals, decimals = 6) {
24905
+ if (!totals) {
24906
+ return "0";
24907
+ }
24908
+ const deposit2 = parseRawCollateralUnits(totals.deposit);
24909
+ const withdraw2 = parseRawCollateralUnits(totals.withdraw);
24910
+ const value = deposit2 - withdraw2;
24911
+ const negative = value < 0n;
24912
+ const absolute = negative ? -value : value;
24913
+ const scale = 10n ** BigInt(decimals);
24914
+ const whole = absolute / scale;
24915
+ const fraction = absolute % scale;
24916
+ const fractionText = fraction.toString().padStart(decimals, "0").replace(/0+$/, "");
24917
+ const amount = fractionText ? `${whole}.${fractionText}` : whole.toString();
24918
+ return negative ? `-${amount}` : amount;
24919
+ }
24920
+ function parseRawCollateralUnits(value) {
24921
+ if (value === null || value === void 0 || value === "") {
24922
+ return 0n;
24923
+ }
24924
+ if (typeof value === "bigint") {
24925
+ return value;
24926
+ }
24927
+ if (typeof value === "number") {
24928
+ if (!Number.isSafeInteger(value)) {
24929
+ throw new Error("Raw collateral unit numbers must be safe integers");
24930
+ }
24931
+ return BigInt(value);
24932
+ }
24933
+ if (!/^-?\d+$/.test(value)) {
24934
+ throw new Error("Raw collateral unit strings must be base-10 integers");
24935
+ }
24936
+ return BigInt(value);
24937
+ }
24938
+
24939
+ // src/utils/account-pnl.ts
24940
+ function toNumber2(value) {
24941
+ if (value === null || value === void 0 || value === "") {
24942
+ return 0;
24943
+ }
24944
+ const parsed = Number(value);
24945
+ return Number.isFinite(parsed) ? parsed : 0;
24946
+ }
24947
+ function readOpenedPrice(leg) {
24948
+ return toNumber2(leg.openedPrice ?? leg.opened_price);
24949
+ }
24950
+ function readCurrentPrice(leg) {
24951
+ const parsed = Number(leg.currentPrice ?? leg.current_price);
24952
+ return Number.isFinite(parsed) ? parsed : void 0;
24953
+ }
24954
+ function readMarkPrice(leg, markPrices) {
24955
+ const symbol = leg.symbol?.trim().toUpperCase();
24956
+ if (symbol) {
24957
+ const markPrice = Number(markPrices[symbol]);
24958
+ if (Number.isFinite(markPrice)) {
24959
+ return markPrice;
24960
+ }
24961
+ }
24962
+ return readCurrentPrice(leg);
24963
+ }
24964
+ function getSymbol(leg) {
24965
+ return leg.symbol?.trim().toUpperCase() || void 0;
24966
+ }
24967
+ function computeLegUpnl(leg, side, markPrices) {
24968
+ const markPrice = readMarkPrice(leg, markPrices);
24969
+ if (markPrice === void 0) {
24970
+ return { upnl: 0, missingSymbol: getSymbol(leg) };
24971
+ }
24972
+ const quantity = toNumber2(leg.quantity);
24973
+ const openedPrice = readOpenedPrice(leg);
24974
+ const direction = side === "short" ? -1 : 1;
24975
+ return {
24976
+ upnl: quantity * (markPrice - openedPrice) * direction
24977
+ };
24978
+ }
24979
+ function computeSymmPositionUpnl(position, markPrices = {}) {
24980
+ const missingSymbols = /* @__PURE__ */ new Set();
24981
+ let upnl = 0;
24982
+ let legsCount = 0;
24983
+ for (const leg of position.longAssets ?? []) {
24984
+ legsCount += 1;
24985
+ const result = computeLegUpnl(leg, "long", markPrices);
24986
+ upnl += result.upnl;
24987
+ if (result.missingSymbol) missingSymbols.add(result.missingSymbol);
24988
+ }
24989
+ for (const leg of position.shortAssets ?? []) {
24990
+ legsCount += 1;
24991
+ const result = computeLegUpnl(leg, "short", markPrices);
24992
+ upnl += result.upnl;
24993
+ if (result.missingSymbol) missingSymbols.add(result.missingSymbol);
24994
+ }
24995
+ if (legsCount === 0) {
24996
+ return {
24997
+ upnl: toNumber2(position.unrealizedPnl ?? position.unrealized_pnl),
24998
+ missingSymbols: [],
24999
+ positionsCount: 1,
25000
+ legsCount,
25001
+ usedFallbackPositions: 1
25002
+ };
25003
+ }
25004
+ return {
25005
+ upnl,
25006
+ missingSymbols: Array.from(missingSymbols),
25007
+ positionsCount: 1,
25008
+ legsCount,
25009
+ usedFallbackPositions: 0
25010
+ };
25011
+ }
25012
+ function computeSymmPositionsUpnl(positions = [], markPrices = {}) {
25013
+ const missingSymbols = /* @__PURE__ */ new Set();
25014
+ let upnl = 0;
25015
+ let legsCount = 0;
25016
+ let usedFallbackPositions = 0;
25017
+ for (const position of positions) {
25018
+ const result = computeSymmPositionUpnl(position, markPrices);
25019
+ upnl += result.upnl;
25020
+ legsCount += result.legsCount;
25021
+ usedFallbackPositions += result.usedFallbackPositions;
25022
+ result.missingSymbols.forEach((symbol) => missingSymbols.add(symbol));
25023
+ }
25024
+ return {
25025
+ upnl,
25026
+ missingSymbols: Array.from(missingSymbols),
25027
+ positionsCount: positions.length,
25028
+ legsCount,
25029
+ usedFallbackPositions
25030
+ };
25031
+ }
25032
+ function readMessageNumber(message, keys) {
25033
+ for (const key of keys) {
25034
+ if (key in message) {
25035
+ return toNumber2(message[key]);
25036
+ }
25037
+ }
25038
+ return 0;
25039
+ }
25040
+ function normalizeSymmUpnlWebSocketMessage(raw) {
25041
+ if (typeof raw !== "object" || raw === null) {
25042
+ return void 0;
25043
+ }
25044
+ const message = raw;
25045
+ const timestamp = readMessageNumber(message, ["timestamp"]);
25046
+ return {
25047
+ upnl: readMessageNumber(message, ["upnl"]),
25048
+ timestamp: timestamp || void 0,
25049
+ availableBalance: readMessageNumber(message, [
25050
+ "availableBalance",
25051
+ "available_balance"
25052
+ ]),
25053
+ allocatedBalance: readMessageNumber(message, [
25054
+ "allocatedBalance",
25055
+ "allocated_balance"
25056
+ ]),
25057
+ cva: readMessageNumber(message, ["cva"]),
25058
+ lf: readMessageNumber(message, ["lf"]),
25059
+ partyAmm: readMessageNumber(message, ["partyAmm", "party_a_mm", "mm"]),
25060
+ pendingPartyAmm: readMessageNumber(message, [
25061
+ "pendingPartyAmm",
25062
+ "pending_party_a_mm",
25063
+ "pending_mm"
25064
+ ]),
25065
+ pendingCva: readMessageNumber(message, ["pendingCva", "pending_cva"]),
25066
+ pendingLf: readMessageNumber(message, ["pendingLf", "pending_lf"]),
25067
+ raw
25068
+ };
25069
+ }
25070
+
24690
25071
  exports.ALL_TRADING_SELECTORS = ALL_TRADING_SELECTORS;
24691
25072
  exports.AffiliateFeeLevel = AffiliateFeeLevel;
24692
25073
  exports.ApprovalState = ApprovalState;
@@ -24734,13 +25115,21 @@ exports.approvalActions = approval_exports;
24734
25115
  exports.calculateGasMargin = calculateGasMargin;
24735
25116
  exports.cancelActions = cancel_exports;
24736
25117
  exports.closeActions = close_exports;
25118
+ exports.computeSymmAccountOverview = computeSymmAccountOverview;
25119
+ exports.computeSymmAccountOverviewFromData = computeSymmAccountOverviewFromData;
25120
+ exports.computeSymmNetDeposited = computeSymmNetDeposited;
25121
+ exports.computeSymmPositionUpnl = computeSymmPositionUpnl;
25122
+ exports.computeSymmPositionsUpnl = computeSymmPositionsUpnl;
24737
25123
  exports.delegationActions = delegation_exports;
24738
25124
  exports.depositActions = deposit_exports;
24739
25125
  exports.encodeCall = encodeCall;
24740
25126
  exports.formatPrice = formatPrice;
24741
25127
  exports.fromWei = fromWei;
24742
25128
  exports.getAddress = getAddress;
25129
+ exports.getSymmAccountBalanceInfo = getSymmAccountBalanceInfo;
25130
+ exports.getSymmAccountData = getSymmAccountData;
24743
25131
  exports.instantActions = instant_exports;
25132
+ exports.normalizeSymmUpnlWebSocketMessage = normalizeSymmUpnlWebSocketMessage;
24744
25133
  exports.signatureActions = signature_exports;
24745
25134
  exports.statsActions = stats_exports;
24746
25135
  exports.toWei = toWei;