@pear-protocol/symmio-client 0.3.14 → 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
@@ -19856,6 +19856,7 @@ interface SymmAccountOverview {
19856
19856
  equity: string;
19857
19857
  totalAccountValue: string;
19858
19858
  maintenanceMargin: string;
19859
+ accountHealthData?: unknown;
19859
19860
  totalLocked: string;
19860
19861
  marginUsed: string;
19861
19862
  totalPendingLocked: string;
@@ -19870,6 +19871,8 @@ interface SymmDepositWithdrawalTotals {
19870
19871
  deposit?: SymmAccountNumericValue;
19871
19872
  withdraw?: SymmAccountNumericValue;
19872
19873
  }
19874
+ type SymmAccountDataLike = Record<string, unknown>;
19875
+ declare function getSymmAccountData(response: unknown): SymmAccountDataLike | undefined;
19873
19876
  /**
19874
19877
  * Finds a single account's balance info from a core BalanceInfoResponse,
19875
19878
  * symm-pear hedger map, or a direct balance-info object.
@@ -19882,6 +19885,11 @@ declare function getSymmAccountBalanceInfo(response: unknown, accountAddress?: s
19882
19885
  * margin used = CVA + LF + party A MM
19883
19886
  */
19884
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;
19885
19893
  /**
19886
19894
  * Computes the symm-pear net-deposited display value from balance-history
19887
19895
  * subgraph totals. Inputs must be integer raw collateral units; USDC defaults
@@ -19889,4 +19897,44 @@ declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, n
19889
19897
  */
19890
19898
  declare function computeSymmNetDeposited(totals: SymmDepositWithdrawalTotals | null | undefined, decimals?: number): string;
19891
19899
 
19892
- 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 SymmAccountNumericValue, type SymmAccountOverview, type SymmAccountOverviewInput, type SymmDepositWithdrawalTotals, 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, computeSymmNetDeposited, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, instant as instantActions, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
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
@@ -19856,6 +19856,7 @@ interface SymmAccountOverview {
19856
19856
  equity: string;
19857
19857
  totalAccountValue: string;
19858
19858
  maintenanceMargin: string;
19859
+ accountHealthData?: unknown;
19859
19860
  totalLocked: string;
19860
19861
  marginUsed: string;
19861
19862
  totalPendingLocked: string;
@@ -19870,6 +19871,8 @@ interface SymmDepositWithdrawalTotals {
19870
19871
  deposit?: SymmAccountNumericValue;
19871
19872
  withdraw?: SymmAccountNumericValue;
19872
19873
  }
19874
+ type SymmAccountDataLike = Record<string, unknown>;
19875
+ declare function getSymmAccountData(response: unknown): SymmAccountDataLike | undefined;
19873
19876
  /**
19874
19877
  * Finds a single account's balance info from a core BalanceInfoResponse,
19875
19878
  * symm-pear hedger map, or a direct balance-info object.
@@ -19882,6 +19885,11 @@ declare function getSymmAccountBalanceInfo(response: unknown, accountAddress?: s
19882
19885
  * margin used = CVA + LF + party A MM
19883
19886
  */
19884
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;
19885
19893
  /**
19886
19894
  * Computes the symm-pear net-deposited display value from balance-history
19887
19895
  * subgraph totals. Inputs must be integer raw collateral units; USDC defaults
@@ -19889,4 +19897,44 @@ declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, n
19889
19897
  */
19890
19898
  declare function computeSymmNetDeposited(totals: SymmDepositWithdrawalTotals | null | undefined, decimals?: number): string;
19891
19899
 
19892
- 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 SymmAccountNumericValue, type SymmAccountOverview, type SymmAccountOverviewInput, type SymmDepositWithdrawalTotals, 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, computeSymmNetDeposited, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, instant as instantActions, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
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
@@ -24741,6 +24741,19 @@ function readTimestamp(source) {
24741
24741
  const parsed = Number(timestamp);
24742
24742
  return Number.isFinite(parsed) ? parsed : void 0;
24743
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
+ }
24744
24757
  function getBalanceInfoContainer(response) {
24745
24758
  if (!isRecord(response)) {
24746
24759
  return void 0;
@@ -24856,6 +24869,38 @@ function computeSymmAccountOverview({
24856
24869
  timestamp: readTimestamp(balanceInfo)
24857
24870
  };
24858
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
+ }
24859
24904
  function computeSymmNetDeposited(totals, decimals = 6) {
24860
24905
  if (!totals) {
24861
24906
  return "0";
@@ -24891,6 +24936,138 @@ function parseRawCollateralUnits(value) {
24891
24936
  return BigInt(value);
24892
24937
  }
24893
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
+
24894
25071
  exports.ALL_TRADING_SELECTORS = ALL_TRADING_SELECTORS;
24895
25072
  exports.AffiliateFeeLevel = AffiliateFeeLevel;
24896
25073
  exports.ApprovalState = ApprovalState;
@@ -24939,7 +25116,10 @@ exports.calculateGasMargin = calculateGasMargin;
24939
25116
  exports.cancelActions = cancel_exports;
24940
25117
  exports.closeActions = close_exports;
24941
25118
  exports.computeSymmAccountOverview = computeSymmAccountOverview;
25119
+ exports.computeSymmAccountOverviewFromData = computeSymmAccountOverviewFromData;
24942
25120
  exports.computeSymmNetDeposited = computeSymmNetDeposited;
25121
+ exports.computeSymmPositionUpnl = computeSymmPositionUpnl;
25122
+ exports.computeSymmPositionsUpnl = computeSymmPositionsUpnl;
24943
25123
  exports.delegationActions = delegation_exports;
24944
25124
  exports.depositActions = deposit_exports;
24945
25125
  exports.encodeCall = encodeCall;
@@ -24947,7 +25127,9 @@ exports.formatPrice = formatPrice;
24947
25127
  exports.fromWei = fromWei;
24948
25128
  exports.getAddress = getAddress;
24949
25129
  exports.getSymmAccountBalanceInfo = getSymmAccountBalanceInfo;
25130
+ exports.getSymmAccountData = getSymmAccountData;
24950
25131
  exports.instantActions = instant_exports;
25132
+ exports.normalizeSymmUpnlWebSocketMessage = normalizeSymmUpnlWebSocketMessage;
24951
25133
  exports.signatureActions = signature_exports;
24952
25134
  exports.statsActions = stats_exports;
24953
25135
  exports.toWei = toWei;