Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-queens-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/hyperdrive-js-core": patch
---

Return bigint instead of number for getLpApy
12 changes: 9 additions & 3 deletions apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useLpApy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { findHyperdriveConfig } from "@hyperdrive/appconfig";
import { useQuery } from "@tanstack/react-query";
import { formatRate } from "src/base/formatRate";
import { makeQueryKey } from "src/base/makeQueryKey";
import { isForkChain } from "src/chains/isForkChain";
import { useAppConfig } from "src/ui/appconfig/useAppConfig";
Expand All @@ -15,7 +16,7 @@ export function useLpApy({
hyperdriveAddress: Address;
chainId: number;
}): {
lpApy: number | undefined;
lpApy: { lpApy: bigint; formatted: string } | undefined;
lpApyStatus: "error" | "success" | "loading";
} {
const { poolInfo: currentPoolInfo } = usePoolInfo({
Expand Down Expand Up @@ -49,20 +50,25 @@ export function useLpApy({
appConfig.yieldSources[hyperdrive.yieldSource]
.historicalRatePeriod,
);
return readHyperdrive.getLpApy({
const { lpApy } = await readHyperdrive.getLpApy({
fromBlock: [31337].includes(chainId)
? // local devnets don't have a lot of blocks, so start from the beginning
1n
: // Appconfig tells us how many days to look back for historical rates
blockNumber - numBlocksForHistoricalRate,
});

return {
lpApy,
formatted: formatRate(lpApy),
};
}
: undefined,
enabled: queryEnabled,
});

return {
lpApy: data?.lpApy,
lpApy: data,
lpApyStatus: status,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ export function AddLiquidityForm({
<PrimaryStat
label="LP APY"
value={
isNewPool || lpApy == undefined ? (
isNewPool || lpApy === undefined ? (
<div className="flex gap-2">✨New✨</div>
) : (
`${(lpApy * 100).toFixed(2) === "-0.00" ? "0.00" : (lpApy * 100).toFixed(2)}%`
`${lpApy.formatted === "-0.00" ? "0.00" : lpApy.formatted}%`
)
}
tooltipContent="The annual percentage yield projection for providing liquidity."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ export function YieldStats({
<span className="flex flex-row">✨New✨</span>
) : (
`${
(lpApy * 100).toFixed(2) === "-0.00"
? "0.00"
: (lpApy * 100).toFixed(2)
lpApy.formatted === "-0.00" ? "0.00" : lpApy.formatted
}%`
)}{" "}
</span>
Expand Down
4 changes: 1 addition & 3 deletions apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,13 @@ export function PoolRow({
isLoading={lpApyStatus === "loading"}
isNew={isLpApyNew}
value={
// TODO: Fix useLpApy to have the same interface as
// useYieldSourceRate and useFixedRate
lpApy && !isLpApyNew ? (
<RewardsTooltip
positionType="lp"
chainId={hyperdrive.chainId}
hyperdriveAddress={hyperdrive.address}
>
<PercentLabel value={`${(lpApy * 100).toFixed(2)}`} />
<PercentLabel value={`${lpApy.formatted}`} />
</RewardsTooltip>
) : (
"-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ export class ReadHyperdrive extends ReadModel {
}: {
fromBlock: bigint;
options?: ContractReadOptions;
}): Promise<{ lpApy: number }> {
}): Promise<{ lpApy: bigint }> {
// If the 24 hour rate doesn't exist, assume the pool was initialized less
// than 24 hours before and try to get the all-time rate until toBlock
const { blockNumber: initializationBlock } =
Expand Down Expand Up @@ -695,7 +695,7 @@ export class ReadHyperdrive extends ReadModel {
endPrice: currentLpSharePrice,
timeFrame,
}),
).toNumber();
).bigint;

return { lpApy };
}
Expand Down