UNPKG

@parcl-finance/product-sdk

Version:

TypeScript SDK for interacting with Parcl's product APIs

692 lines 32.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatStakingBalances = exports.formatReferralsUserUi = exports.formatReferralsUser = exports.formatAvailableOpenInterest = exports.formatMargins = exports.formatPnLValue = exports.formatPnLInfo = exports.formatOpenInterestDistribution = exports.formatBaseAssetV2 = exports.formatBaseAsset = exports.formatPriceFeed = exports.formatParclInfo = exports.formatPointsLeaderboardPosition = exports.formatPointsLeaderboard = exports.formatMarginTransferHistoryEventsV2 = exports.formatMarginTransferHistoryEvents = exports.formatLpHistoryEventsV2 = exports.formatLpHistoryEvents = exports.formatTradeHistoryEventsV2 = exports.formatTradeHistoryEvents = exports.formatLiquidationEventV2 = exports.formatLiquidationHistory = exports.formatContestLeaderboardPosition = exports.formatContestLeaderboard = exports.formatTimestampV2 = exports.formatTimestamp = exports.formatSettlementRequestInfo = exports.formatRemoveLiquidityQuote = exports.formatAddLiquidityQuote = exports.formatPositionModificationLimitsQuote = exports.formatModifyPositionQuote = exports.formatLpPositionsInfo = exports.formatLpPositionInfo = exports.formatLpAccountInfo = exports.formatPosition = exports.formatMarginAccountInfo = exports.formatMarginAccountsInfo = exports.formatFundingRateAprs = exports.formatMarketInfo = exports.formatExchangeInfo = exports.parseSize = exports.formatSize = exports.parseCollateralAmount = exports.formatPrclAmount = exports.formatCollateralAmount = exports.formatPrice = exports.formatPercent = exports.parseAmount = exports.formatAmount = void 0; const decimal_js_1 = require("decimal.js"); const expo_1 = require("../constants/expo"); function formatAmount(amount, expo) { return new decimal_js_1.Decimal(amount).div(10 ** expo).toString(); } exports.formatAmount = formatAmount; function parseAmount(amount, expo) { return new decimal_js_1.Decimal(amount).mul(10 ** expo).toString(); } exports.parseAmount = parseAmount; function formatPercent(percent) { return new decimal_js_1.Decimal(percent).mul(100).toString(); } exports.formatPercent = formatPercent; function formatPrice(price) { return formatAmount(price, expo_1.PRICE_EXPO); } exports.formatPrice = formatPrice; function formatCollateralAmount(collateralAmount) { return formatAmount(collateralAmount, expo_1.USDC_EXPO); } exports.formatCollateralAmount = formatCollateralAmount; function formatPrclAmount(prclAmount) { return formatAmount(prclAmount, expo_1.PRCL_EXPO); } exports.formatPrclAmount = formatPrclAmount; function parseCollateralAmount(collateralAmount) { return parseAmount(collateralAmount, expo_1.USDC_EXPO); } exports.parseCollateralAmount = parseCollateralAmount; function formatSize(size) { return formatAmount(size, expo_1.SIZE_EXPO); } exports.formatSize = formatSize; function parseSize(size) { return parseAmount(size, expo_1.SIZE_EXPO); } exports.parseSize = parseSize; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatExchangeInfo(info) { return { address: info.address, tvl: formatCollateralAmount(info.tvl), balance: formatCollateralAmount(info.balance), marginBalance: formatCollateralAmount(info.marginBalance), lpBalance: formatCollateralAmount(info.lpBalance), lpShares: formatCollateralAmount(info.lpShares), requiredMinimumBalance: formatCollateralAmount(info.requiredMinimumBalance), requiredMinimumBalancePercent: formatPercent(info.requiredMinimumBalancePercent), openInterest: formatCollateralAmount(info.openInterest), unrealizedPnl: formatCollateralAmount(info.unrealizedPnl), sharePrice: formatPrice(info.sharePrice), availableOpenInterest: formatAvailableOpenInterest(info.availableOpenInterest), openInterestDistribution: formatOpenInterestDistribution(info.openInterestDistribution), minLpDuration: info.minLpDuration, settlementDelay: info.settlementDelay, protocolFeeRate: formatPercent(info.protocolFeeRate), specification: info.specification, cumulativeNotionalVolume: info.cumulativeNotionalVolume === null ? null : info.cumulativeNotionalVolume, cumulativeLpFee: info.cumulativeLpFee === null ? null : formatCollateralAmount(info.cumulativeLpFee), lpYield: info.lpYield === null ? null : formatYield(info.lpYield), }; } exports.formatExchangeInfo = formatExchangeInfo; function formatYield(yieldObj) { return { apr: formatPercent(yieldObj.apr), apy: formatPercent(yieldObj.apy), }; } // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatMarketInfo(info) { return { address: info.address, id: info.id, specification: info.specification, metadata: { market: info.metadata.market, marketId: info.metadata.marketId, name: info.metadata.name, state: info.metadata.state, country: info.metadata.country, parclId: info.metadata.parclId, isNew: false, tradable: info.metadata.tradable, symbol: info.metadata.symbol, category: info.metadata.category, currency: info.metadata.currency, metric: info.metadata.metric, pythTokenId: info.metadata.pythTokenId, }, openInterest: formatBaseAsset(info.openInterest), skew: formatBaseAsset(info.skew), openInterestDistribution: formatOpenInterestDistribution(info.openInterestDistribution), fundingRate: formatPercent(info.fundingRate), fundingVelocity: formatPercent(info.fundingVelocity), indexPrice: formatPrice(info.indexPrice), marketPrice: formatPrice(info.marketPrice), maxLeverageMultiple: info.maxLeverageMultiple, availableOpenInterest: formatAvailableOpenInterest(info.availableOpenInterest), makerFeeRate: formatPercent(info.makerFeeRate), takerFeeRate: formatPercent(info.takerFeeRate), maxFundingVelocity: formatPercent(info.maxFundingVelocity), fundingRateAprs: formatFundingRateAprs(info.fundingRateAprs), paused: info.paused, }; } exports.formatMarketInfo = formatMarketInfo; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatFundingRateAprs(aprs) { return { oneHour: formatPercent(aprs.oneHour), eightHour: formatPercent(aprs.eightHour), oneDay: formatPercent(aprs.oneDay), oneYear: formatPercent(aprs.oneYear), }; } exports.formatFundingRateAprs = formatFundingRateAprs; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatMarginAccountsInfo(info) { const openInterestInfoByMarket = {}; for (const [key, value] of Object.entries(info.openInterestInfoByMarket)) { openInterestInfoByMarket[key] = { pnlInfo: formatPnLInfo(value.pnlInfo), pnlInfoIndexPrice: formatPnLInfo(info.pnlInfoIndexPrice), pnlInfoFullClose: formatPnLInfo(info.pnlInfoFullClose), openInterest: formatBaseAsset(value.openInterest), openInterestDistribution: formatOpenInterestDistribution(value.openInterestDistribution), }; } return { pnlInfo: formatPnLInfo(info.pnlInfo), pnlInfoIndexPrice: formatPnLInfo(info.pnlInfoIndexPrice), pnlInfoFullClose: formatPnLInfo(info.pnlInfoFullClose), marginCollateral: formatCollateralAmount(info.marginCollateral), openInterest: formatBaseAsset(info.openInterest), openInterestDistribution: formatOpenInterestDistribution(info.openInterestDistribution), marginAccounts: info.marginAccounts.map( // eslint-disable-next-line @typescript-eslint/no-explicit-any (info) => formatMarginAccountInfo(info)), openInterestInfoByMarket, }; } exports.formatMarginAccountsInfo = formatMarginAccountsInfo; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatMarginAccountInfo(info) { return { address: info.address, name: info.name, id: info.id, marginCollateral: formatCollateralAmount(info.marginCollateral), leverageMultiple: info.leverageMultiple, healthRatio: formatPercent(info.healthRatio), canClose: info.canClose, canLiquidate: info.canLiquidate, inLiquidation: info.inLiquidation, wasRecentlyLiquidated: info.wasRecentlyLiquidated, margins: formatMargins(info.margins), pnlInfo: formatPnLInfo(info.pnlInfo), pnlInfoIndexPrice: formatPnLInfo(info.pnlInfoIndexPrice), pnlInfoFullClose: formatPnLInfo(info.pnlInfoFullClose), openInterest: formatBaseAsset(info.openInterest), openInterestDistribution: formatOpenInterestDistribution(info.openInterestDistribution), positions: info.positions.map( // eslint-disable-next-line @typescript-eslint/no-explicit-any (position) => formatPosition(position)), }; } exports.formatMarginAccountInfo = formatMarginAccountInfo; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatPosition(position) { return { openInterest: formatBaseAsset(position.openInterest), side: position.side, pnlInfo: formatPnLInfo(position.pnlInfo), pnlInfoIndexPrice: formatPnLInfo(position.pnlInfoIndexPrice), pnlInfoFullClose: formatPnLInfo(position.pnlInfoFullClose), lastInteractionPrice: formatPrice(position.lastInteractionPrice), lastInteractionFundingPerUnit: position.lastInteractionFundingPerUnit, marketId: position.marketId, initialMarginRatio: formatPercent(position.initialMarginRatio), maintenanceMarginRatio: formatPercent(position.maintenanceMarginRatio), accruedFundingEstimateOneHour: formatCollateralAmount(position.accruedFundingEstimateOneHour), totalRequiredMargin: formatCollateralAmount(position.totalRequiredMargin), }; } exports.formatPosition = formatPosition; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatLpAccountInfo(info) { return { address: info.address, liquidity: formatCollateralAmount(info.liquidity), shares: formatCollateralAmount(info.shares), stake: formatPercent(info.stake), minLpDurationMaturity: info.minLpDurationMaturity === null ? null : formatTimestamp(info.minLpDurationMaturity), lastAddLiquidityTimestamp: formatTimestamp(info.lastAddLiquidityTimestamp), maxRemovableShares: formatCollateralAmount(info.maxRemovableShares), minLpDurationElapsed: info.minLpDurationElapsed, shareValue: formatCollateralAmount(info.shareValue), delegate: info.delegate, canClose: info.canClose, canUpgrade: info.canUpgrade, }; } exports.formatLpAccountInfo = formatLpAccountInfo; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatLpPositionInfo(info) { return { id: info.id, address: info.address, liquidity: formatCollateralAmount(info.liquidity), shares: formatCollateralAmount(info.shares), maturity: formatTimestamp(info.maturity), maxRemovableShares: formatCollateralAmount(info.maxRemovableShares), hasReachedMaturity: info.hasReachedMaturity, shareValue: formatCollateralAmount(info.shareValue), sharePrice: info.sharePrice === null ? null : formatPrice(info.sharePrice), pnl: formatPnLValue(info.pnl), points: info.points, canClose: info.canClose, }; } exports.formatLpPositionInfo = formatLpPositionInfo; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatLpPositionsInfo(info) { return { liquidity: formatCollateralAmount(info.liquidity), shares: formatCollateralAmount(info.shares), shareValue: formatCollateralAmount(info.shareValue), // eslint-disable-next-line @typescript-eslint/no-explicit-any positions: info.positions.map((info) => formatLpPositionInfo(info)), pnl: formatPnLValue(info.pnl), points: info.points, }; } exports.formatLpPositionsInfo = formatLpPositionsInfo; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatModifyPositionQuote(quote) { return { openInterestDelta: formatBaseAsset(quote.openInterestDelta), positionInitialMarginRatio: formatPercent(quote.positionInitialMarginRatio), positionMaintenanceMarginRatio: formatPercent(quote.positionMaintenanceMarginRatio), fillPrice: formatPrice(quote.fillPrice), indexPrice: formatPrice(quote.indexPrice), priceImpact: formatPercent(quote.priceImpact), tradeFee: formatCollateralAmount(quote.tradeFee), liquidationPrice: quote.liquidationPrice === null ? null : formatPrice(quote.liquidationPrice), leverageMultiple: quote.leverageMultiple === null ? null : quote.leverageMultiple, pointsQuote: quote.pointsQuote, accruedFundingEstimateOneHour: formatCollateralAmount(quote.accruedFundingEstimateOneHour), }; } exports.formatModifyPositionQuote = formatModifyPositionQuote; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatPositionModificationLimitsQuote(quote) { return { marketId: quote.marketId, maxPositionModification: { openInterestDelta: formatBaseAsset(quote.maxPositionModification.openInterestDelta), leverageMultiple: quote.maxPositionModification.leverageMultiple, }, minPositionModification: { openInterestDelta: formatBaseAsset(quote.minPositionModification.openInterestDelta), leverageMultiple: quote.minPositionModification.leverageMultiple, }, }; } exports.formatPositionModificationLimitsQuote = formatPositionModificationLimitsQuote; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatAddLiquidityQuote(quote) { return { shares: formatCollateralAmount(quote.shares), maturity: formatTimestamp(quote.maturity), pointsQuote: quote.pointsQuote, }; } exports.formatAddLiquidityQuote = formatAddLiquidityQuote; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatRemoveLiquidityQuote(quote) { return { liquidity: formatCollateralAmount(quote.liquidity), shares: formatCollateralAmount(quote.shares), sharePrice: formatPrice(quote.sharePrice), pointsQuote: quote.pointsQuote, }; } exports.formatRemoveLiquidityQuote = formatRemoveLiquidityQuote; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatSettlementRequestInfo(info) { return { address: info.address, id: info.id, maturity: formatTimestamp(info.maturity), amount: formatCollateralAmount(info.amount), keeperTip: formatCollateralAmount(info.keeperTip), exchange: info.exchange, owner: info.owner, ownerTokenAccount: info.ownerTokenAccount, }; } exports.formatSettlementRequestInfo = formatSettlementRequestInfo; function formatTimestamp(timestamp) { return new Date(Number(timestamp) * 10 ** 3); } exports.formatTimestamp = formatTimestamp; function formatTimestampV2(timestamp) { if (timestamp === null) return null; return new Date(timestamp); } exports.formatTimestampV2 = formatTimestampV2; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatContestLeaderboard(leaderboard) { return leaderboard.map( // eslint-disable-next-line @typescript-eslint/no-explicit-any (userSnapshot) => formatUserContestSnapshot(userSnapshot)); } exports.formatContestLeaderboard = formatContestLeaderboard; function formatContestLeaderboardPosition( // eslint-disable-next-line @typescript-eslint/no-explicit-any leaderboardPosition) { return { index: leaderboardPosition.index, row: formatUserContestSnapshot(leaderboardPosition.row), }; } exports.formatContestLeaderboardPosition = formatContestLeaderboardPosition; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatLiquidationHistory(history) { const formattedHistory = {}; for (const exchangeId in history) { formattedHistory[exchangeId] = {}; for (const marginAccountId in history[exchangeId]) { formattedHistory[exchangeId][marginAccountId] = {}; for (const liquidationStartedAt in history[exchangeId][marginAccountId]) { const liquidation = history[exchangeId][marginAccountId][liquidationStartedAt]; formattedHistory[exchangeId][marginAccountId][liquidationStartedAt] = { slot: liquidation.slot, signature: liquidation.signature, exchangeId: liquidation.exchangeId, owner: liquidation.owner, marginAccountId: liquidation.marginAccountId, liquidatedMargin: formatCollateralAmount(liquidation.liquidatedMargin), liquidationStartedAt: liquidation.liquidationStartedAt, maxLiquidationFee: formatCollateralAmount(liquidation.maxLiquidationFee), totalOpenInterest: formatBaseAsset(liquidation.totalOpenInterest), // eslint-disable-next-line @typescript-eslint/no-explicit-any positionLiquidations: liquidation.positionLiquidations.map((positionLiquidation) => formatPositionLiquidation(positionLiquidation)), }; } } } return formattedHistory; } exports.formatLiquidationHistory = formatLiquidationHistory; function formatLiquidationEventV2(history) { return history.map((event) => ({ slot: event.slot, signature: event.signature, marginAccountId: event.marginAccountId, liquidatedMargin: formatCollateralAmount(event.liquidatedMargin), liquidationStartedAt: formatTimestampV2(event.liquidationStartedAt), marketId: event.marketId, amountLiquidated: formatCollateralAmount(event.amountLiquidated), amountLiquidatedNotional: formatCollateralAmount(event.amountLiquidatedNotional), indexPrice: formatCollateralAmount(event.indexPrice), })); } exports.formatLiquidationEventV2 = formatLiquidationEventV2; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatTradeHistoryEvents(events) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return events.map((event) => ({ timestamp: formatTimestamp(event.timestamp), exchangeId: event.exchangeId, marginAccountId: event.marginAccountId, marketId: event.marketId, tradeKind: event.tradeKind, side: event.side, fillPrice: formatPrice(event.fillPrice), indexPrice: formatPrice(event.indexPrice), openInterestDelta: formatBaseAsset(event.openInterestDelta), newOpenInterest: formatBaseAsset(event.newOpenInterest), tradeFee: formatCollateralAmount(event.tradeFee), pnl: formatCollateralAmount(event.pnl), pricePerformance: formatCollateralAmount(event.pricePerformance || 0), fundingPerformance: formatCollateralAmount(event.fundingPerformance || 0), signature: event.signature, slot: event.slot, })); } exports.formatTradeHistoryEvents = formatTradeHistoryEvents; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatTradeHistoryEventsV2(events) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return events.map((event) => ({ timestamp: formatTimestampV2(event.timestamp), exchangeId: event.exchangeId, marginAccountId: event.marginAccountId, marketId: event.marketId, tradeKind: event.tradeKind, side: event.side, fillPrice: formatPrice(event.fillPrice), indexPrice: formatPrice(event.indexPrice), openInterestDelta: formatBaseAssetV2(event.openInterestDelta), newOpenInterest: formatBaseAssetV2(event.newOpenInterest), tradeFee: formatCollateralAmount(event.tradeFee), pnl: formatCollateralAmount(event.pnl), pricePerformance: formatCollateralAmount(event.pricePerformance || 0), fundingPerformance: formatCollateralAmount(event.fundingPerformance || 0), signature: event.signature, slot: event.slot, })); } exports.formatTradeHistoryEventsV2 = formatTradeHistoryEventsV2; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatLpHistoryEvents(events) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return events.map((event) => ({ timestamp: formatTimestamp(event.timestamp), signature: event.signature, slot: event.slot, exchangeId: event.exchangeId, modifyLiquidityKind: event.modifyLiquidityKind, liquidity: formatCollateralAmount(event.liquidity), shares: formatCollateralAmount(event.shares), sharePrice: formatPrice(event.sharePrice), newLiquidityAmount: event.newLiquidityAmount === null ? null : formatCollateralAmount(event.newLiquidityAmount), newSharesAmount: event.newSharesAmount === null ? null : formatCollateralAmount(event.newSharesAmount), lpPositionId: event.lpPositionId, maturity: event.maturity === null ? null : formatTimestamp(event.maturity), })); } exports.formatLpHistoryEvents = formatLpHistoryEvents; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatLpHistoryEventsV2(events) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return events.map((event) => ({ timestamp: formatTimestampV2(event.timestamp), signature: event.signature, slot: event.slot, exchangeId: event.exchangeId, modifyLiquidityKind: event.modifyLiquidityKind, liquidity: formatCollateralAmount(event.liquidity), shares: formatCollateralAmount(event.shares), sharePrice: formatPrice(event.sharePrice), newLiquidityAmount: event.newLiquidityAmount === null ? null : formatCollateralAmount(event.newLiquidityAmount), newSharesAmount: event.newSharesAmount === null ? null : formatCollateralAmount(event.newSharesAmount), lpPositionId: event.lpPositionId, maturity: event.maturity === null ? null : formatTimestampV2(event.maturity), })); } exports.formatLpHistoryEventsV2 = formatLpHistoryEventsV2; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatMarginTransferHistoryEvents(events) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return events.map((event) => ({ timestamp: formatTimestamp(event.timestamp), exchangeId: event.exchangeId, marginAccountId: event.marginAccountId, marginTransferKind: event.marginTransferKind, margin: formatCollateralAmount(event.margin), signature: event.signature, slot: event.slot, settlementRequestMaturity: event.settlementRequestMaturity === null ? null : formatTimestamp(event.settlementRequestMaturity), })); } exports.formatMarginTransferHistoryEvents = formatMarginTransferHistoryEvents; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatMarginTransferHistoryEventsV2(events) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return events.map((event) => ({ timestamp: formatTimestampV2(event.timestamp), exchangeId: event.exchangeId, marginAccountId: event.marginAccountId, marginTransferKind: event.marginTransferKind, margin: formatCollateralAmount(event.margin), signature: event.signature, slot: event.slot, settlementRequestMaturity: event.settlementRequestMaturity === null ? null : formatTimestampV2(event.settlementRequestMaturity), })); } exports.formatMarginTransferHistoryEventsV2 = formatMarginTransferHistoryEventsV2; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatPositionLiquidation(positionLiquidation) { return { slot: positionLiquidation.slot, signature: positionLiquidation.signature, exchangeId: positionLiquidation.exchangeId, owner: positionLiquidation.owner, marginAccountId: positionLiquidation.marginAccountId, liquidator: positionLiquidation.liquidator, liquidatorMarginAccountId: positionLiquidation.liquidatorMarginAccountId, liquidatedMargin: positionLiquidation.liquidatedMargin === null ? null : formatCollateralAmount(positionLiquidation.liquidatedMargin), liquidationStartedAt: positionLiquidation.liquidationStartedAt, maxLiquidationFee: positionLiquidation.maxLiquidationFee === null ? null : formatCollateralAmount(positionLiquidation.maxLiquidationFee), liquidationFee: formatCollateralAmount(positionLiquidation.liquidationFee), marketId: positionLiquidation.marketId, amountLiquidated: formatSize(positionLiquidation.amountLiquidated), amountLiquidatedNotional: formatCollateralAmount(positionLiquidation.amountLiquidatedNotional), newPositionSize: formatSize(positionLiquidation.newPositionSize), indexPrice: formatPrice(positionLiquidation.indexPrice), }; } // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatUserContestSnapshot(snapshot) { return { user: snapshot.user, tokenChange: snapshot.tokenChange, percentChange: snapshot.percentChange, positionCount: snapshot.positionCount, collateralAmount: snapshot.collateralAmount, openInterest: snapshot.openInterest, annualizedReturn: snapshot.annualizedReturn, assetDash: snapshot.assetDash === null ? false : snapshot.assetDash, }; } // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatPointsLeaderboard(leaderboard) { return leaderboard.map( // eslint-disable-next-line @typescript-eslint/no-explicit-any (userSnapshot) => formatUserPointsSnapshot(userSnapshot)); } exports.formatPointsLeaderboard = formatPointsLeaderboard; function formatPointsLeaderboardPosition(leaderboardPosition) { return { index: leaderboardPosition.index, row: formatUserPointsSnapshot(leaderboardPosition.row), }; } exports.formatPointsLeaderboardPosition = formatPointsLeaderboardPosition; function formatUserPointsSnapshot(snapshot) { return { user: snapshot.user, points: snapshot.points, tradingPoints: snapshot.tradingPoints, lpPoints: snapshot.lpPoints, referralPoints: snapshot.referralPoints, referredBoost: snapshot.referredBoost, firstHoaBoost: snapshot.firstHoaBoost, additionalHoaBoost: snapshot.additionalHoaBoost, snapshotBoosts: snapshot.snapshotBoosts, }; } function formatParclInfo(info) { return { ...info, priceFeedStats: info.priceFeedStats, totalArea: info.totalArea, totalPop: info.totalPop, medianAge: info.medianAge, medianIncome: info.medianIncome, financials: info.financials, currentInventory: info.currentInventory, state: info.state, priceHistory: formatPriceFeed(info.priceHistory), absorptionRateHistory: info.absorptionRateHistory, salesHistory: info.salesHistory, listingsHistory: info.listingsHistory, }; } exports.formatParclInfo = formatParclInfo; function formatPriceFeed(priceFeed) { return priceFeed.map((epoch) => ({ ...epoch, date: epoch.date + "T00:00:00" })); } exports.formatPriceFeed = formatPriceFeed; function formatBaseAsset(info) { return { size: formatSize(info.size), notional: formatCollateralAmount(info.notional), }; } exports.formatBaseAsset = formatBaseAsset; function formatBaseAssetV2(info) { return { size: formatSize(info.size), notional: formatPrice(info.notional), }; } exports.formatBaseAssetV2 = formatBaseAssetV2; function formatOpenInterestDistribution(openInterestDistribution) { return { long: { size: formatSize(openInterestDistribution.long.size), notional: formatCollateralAmount(openInterestDistribution.long.notional), percent: formatPercent(openInterestDistribution.long.percent), }, short: { size: formatSize(openInterestDistribution.short.size), notional: formatCollateralAmount(openInterestDistribution.short.notional), percent: formatPercent(openInterestDistribution.short.percent), }, }; } exports.formatOpenInterestDistribution = formatOpenInterestDistribution; function formatPnLInfo(info) { return { totalPnl: formatPnLValue(info.totalPnl), priceComponent: formatPnLValue(info.priceComponent), accruedFunding: formatPnLValue(info.accruedFunding), }; } exports.formatPnLInfo = formatPnLInfo; function formatPnLValue(value) { return { value: formatCollateralAmount(value.value), percentChange: formatPercent(value.percentChange), }; } exports.formatPnLValue = formatPnLValue; function formatMargins(margins) { return { availableMargin: formatCollateralAmount(margins.availableMargin), totalRequiredMargin: formatCollateralAmount(margins.totalRequiredMargin), totalRequiredMarginRatio: formatPercent(margins.totalRequiredMarginRatio), requiredInitialMargin: formatCollateralAmount(margins.requiredInitialMargin), requiredMaintenanceMargin: formatCollateralAmount(margins.requiredMaintenanceMargin), requiredLiquidationFeeMargin: formatCollateralAmount(margins.requiredLiquidationFeeMargin), accumulatedLiquidationFees: formatCollateralAmount(margins.accumulatedLiquidationFees), }; } exports.formatMargins = formatMargins; function formatAvailableOpenInterest(availableOpenInterest) { return { long: formatBaseAsset(availableOpenInterest.long), short: formatBaseAsset(availableOpenInterest.short), }; } exports.formatAvailableOpenInterest = formatAvailableOpenInterest; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatReferralsUser(referralsUser) { return { userId: referralsUser.userId, participatedAt: referralsUser.participatedAt, code: referralsUser.code, referralList: referralsUser.referralList, referredAt: referralsUser.referredAt, referredBy: referralsUser.referredBy, referredByCode: referralsUser.referredByCode, }; } exports.formatReferralsUser = formatReferralsUser; // eslint-disable-next-line @typescript-eslint/no-explicit-any function formatReferralsUserUi(referralsUser) { return { userId: referralsUser.userId, participatedAt: referralsUser.participatedAt, code: referralsUser.code, referralList: referralsUser.referralList, referredAt: referralsUser.referredAt, referredBy: referralsUser.referredBy, referredByCode: referralsUser.referredByCode, referralPoints: referralsUser.referralPoints, referredCount: referralsUser.referredCount, }; } exports.formatReferralsUserUi = formatReferralsUserUi; function formatStakingBalances(stakingBalances) { const formattedStakingBalances = { lockingPrclBalance: stakingBalances.locked.locking, lockedPrclBalance: stakingBalances.locked.locked, unlockingPrclBalance: stakingBalances.locked.preunlocking, unlockedPrclBalance: stakingBalances.withdrawable, unlockingSchedule: stakingBalances.locked.unlockingSchedule.map((locked) => { return { amount: locked.amount, epoch: locked.epoch, }; }), unvestedTotalPrclBalance: stakingBalances.unvested.total, unvestedLockingPrclBalance: stakingBalances.unvested.locking, unvestedLockedPrclBalance: stakingBalances.unvested.locked, unvestedPreUnlockingPrclBalance: stakingBalances.unvested.preunlocking, unvestedUnlockingPrclBalance: stakingBalances.unvested.unlocking, unvestedUnlockedPrclBalance: stakingBalances.unvested.unlocked, isAccountFull: stakingBalances.isAccountFull, }; return formattedStakingBalances; } exports.formatStakingBalances = formatStakingBalances; //# sourceMappingURL=responseFormatters.js.map