Skip to content

Commit

Permalink
feat: update stats
Browse files Browse the repository at this point in the history
  • Loading branch information
borcherd committed Dec 13, 2024
1 parent d600590 commit b66e53b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ export const Stats = ({ activePool, accountSummary, simulationResult, actionTxns
{stats && (
<dl className={cn("grid grid-cols-2 gap-y-2 pt-6 text-xs")}>
{stats.map((stat, idx) => (
<ActionStatItem key={idx} label={stat.label}>
<ActionStatItem
key={idx}
label={stat.label}
classNames={cn(
stat.color &&
(stat.color === "SUCCESS"
? "text-success"
: stat.color === "ALERT"
? "text-alert-foreground"
: "text-destructive-foreground")
)}
>
<stat.value />
</ActionStatItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,41 @@ export function generateTradeStats(props: generateTradeStatsProps) {
value: () => <>{tokenPriceFormatter(props.extendedPool.tokenBank.info.state.price)}</>,
});

// simulation stat
if (props.simulationResult) {
const simStats = getSimulationStats(props.simulationResult, props.extendedPool);
const currentLiquidationPrice =
props.extendedPool.tokenBank.isActive &&
props.extendedPool.tokenBank.position.liquidationPrice &&
props.extendedPool.tokenBank.position.liquidationPrice > 0.01
? usdFormatter.format(props.extendedPool.tokenBank.position.liquidationPrice)
: null;
const simulatedLiqPrice = simStats?.liquidationPrice ? usdFormatter.format(simStats?.liquidationPrice) : null;
const showLiqComparison = currentLiquidationPrice && simulatedLiqPrice;
stats.push({
label: "Liquidation price",
value: () => (
<>
{currentLiquidationPrice && <span>{currentLiquidationPrice}</span>}
{showLiqComparison && <IconArrowRight width={12} height={12} />}
{simulatedLiqPrice && <span>{simulatedLiqPrice}</span>}
</>
),
});
}

// platform fee stat
const platformFeeBps = props.actionTxns?.actionQuote?.platformFee
? Number(props.actionTxns.actionQuote.platformFee?.feeBps)
: undefined;
if (platformFeeBps) {
stats.push({
label: "Platform fee",
value: () => <>{percentFormatter.format(platformFeeBps / 10000)}</>,
});
}

// price impact stat
const priceImpactPct = props.actionTxns?.actionQuote
? Number(props.actionTxns.actionQuote.priceImpactPct)
: undefined;
if (priceImpactPct) {
stats.push({
label: "Price impact",
color: priceImpactPct > 0.05 ? "DESTRUCTIVE" : priceImpactPct > 0.01 ? "ALERT" : "SUCCESS",
value: () => <>{percentFormatter.format(priceImpactPct)}</>,
});
if (props.actionTxns) {
// slippage stat
const slippageBps = props.actionTxns?.actionQuote?.slippageBps;
if (slippageBps) {
stats.push({
label: "Slippage",
color: slippageBps > 500 ? "ALERT" : "SUCCESS",
value: () => <>{percentFormatter.format(slippageBps / 10000)}</>,
});
}

// platform fee stat
const platformFeeBps = props.actionTxns?.actionQuote?.platformFee
? Number(props.actionTxns.actionQuote.platformFee?.feeBps)
: undefined;

if (platformFeeBps) {
stats.push({
label: "Platform fee",
value: () => <>{percentFormatter.format(platformFeeBps / 10000)}</>,
});
}

// price impact stat
const priceImpactPct = props.actionTxns?.actionQuote
? Number(props.actionTxns.actionQuote.priceImpactPct)
: undefined;

if (priceImpactPct !== undefined) {
stats.push({
label: "Price impact",
color: priceImpactPct > 0.05 ? "DESTRUCTIVE" : priceImpactPct > 0.01 ? "ALERT" : "SUCCESS",
value: () => <>{percentFormatter.format(priceImpactPct)}</>,
});
}
}

// oracle stat
Expand All @@ -94,31 +85,6 @@ export function generateTradeStats(props: generateTradeStatsProps) {
),
});

const accountSummary = props.accountSummary;
if (accountSummary) {
// total deposits stat
stats.push({
label: "Total deposits",
value: () => (
<>
{props.extendedPool.tokenBank.info.state.totalDeposits.toFixed(2)}{" "}
{props.extendedPool.tokenBank.meta.tokenSymbol}
</>
),
});

// total borrows stat
stats.push({
label: "Total borrows",
value: () => (
<>
{props.extendedPool.tokenBank.info.state.totalBorrows.toFixed(2)}{" "}
{props.extendedPool.tokenBank.meta.tokenSymbol}
</>
),
});
}

return stats;
}

Expand Down

0 comments on commit b66e53b

Please sign in to comment.