Skip to content

Commit 020f7bf

Browse files
authored
Show effective short apr in preview (#1165)
* show short apr after open * adds short apr after open * Rename label * updates per comments
1 parent f715579 commit 020f7bf

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

apps/hyperdrive-trading/src/ui/hyperdrive/shorts/OpenShortPreview/OpenShortPreview.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { LabelValue } from "src/ui/base/components/LabelValue";
1414
import { formatBalance } from "src/ui/base/formatting/formatBalance";
1515
import { formatDate } from "src/ui/base/formatting/formatDate";
1616
import { useFixedRate } from "src/ui/hyperdrive/longs/hooks/useFixedRate";
17+
import { useShortRate } from "src/ui/hyperdrive/shorts/hooks/useShortRate";
18+
import { useYieldSourceRate } from "src/ui/vaults/useYieldSourceRate";
1719
interface OpenShortPreviewProps {
1820
hyperdrive: HyperdriveConfig;
1921
tokenIn: TokenConfig<any>;
@@ -40,6 +42,16 @@ export function OpenShortPreview({
4042
});
4143
const { fixedApr } = useFixedRate(hyperdrive.address);
4244
const termLengthMS = Number(hyperdrive.poolConfig.positionDuration * 1000n);
45+
const { vaultRate } = useYieldSourceRate({
46+
hyperdriveAddress: hyperdrive.address,
47+
});
48+
const { shortApr, shortRateStatus } = useShortRate({
49+
bondAmount: shortSize,
50+
hyperdriveAddress: hyperdrive.address,
51+
timestamp: BigInt(Math.floor(Date.now() / 1000)),
52+
variableApy: vaultRate?.vaultRate,
53+
});
54+
4355
return (
4456
<div className="flex flex-col gap-3">
4557
<LabelValue
@@ -101,6 +113,26 @@ export function OpenShortPreview({
101113
)
102114
}
103115
/>
116+
<LabelValue
117+
label="Net Short Rate"
118+
value={
119+
shortRateStatus === "loading" ? (
120+
<Skeleton width={100} />
121+
) : (
122+
<span
123+
className={classNames(
124+
"daisy-tooltip daisy-tooltip-top daisy-tooltip-left cursor-help before:border",
125+
{
126+
"border-b border-dashed border-current": spotRateAfterOpen,
127+
},
128+
)}
129+
data-tip="The annualized return on shorts assuming the current yield source rate stays the same for one year"
130+
>
131+
{shortApr ? `${shortApr.formatted}% APR` : "-"}
132+
</span>
133+
)
134+
}
135+
/>
104136
<div className="flex flex-col gap-3">
105137
<h6 className="font-medium">Market Impact</h6>
106138
<LabelValue

0 commit comments

Comments
 (0)