Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire up variable apys in points card #1693

Merged
merged 4 commits into from
Dec 18, 2024
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "ms-vsliveshare.vsliveshare"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export function useUnpausedPools(): {
appConfig: appConfigForConnectedChain,
});

const rewards = !rewardsFn ? [] : await rewardsFn(publicClient);
const rewards = !rewardsFn
? []
: await rewardsFn(publicClient).catch(() => []);

return { ...hyperdrive, rewards };
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { fixed } from "@delvtech/fixed-point-wasm";
import { fixed, parseFixed } from "@delvtech/fixed-point-wasm";
import {
getYieldSource,
HyperdriveConfig,
PointMultiplierReward,
} from "@delvtech/hyperdrive-appconfig";
import { Link, useSearch } from "@tanstack/react-router";
import { ReactElement, ReactNode } from "react";
import Skeleton from "react-loading-skeleton";
import { formatRate } from "src/base/formatRate";
import { calculateMarketYieldMultiplier } from "src/hyperdrive/calculateMarketYieldMultiplier";
import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain";
import { Well } from "src/ui/base/components/Well/Well";
import { useCurrentLongPrice } from "src/ui/hyperdrive/longs/hooks/useCurrentLongPrice";
import { useLpApy } from "src/ui/hyperdrive/lp/hooks/useLpApy";
import { AssetStack } from "src/ui/markets/AssetStack";
import { usePoolsList } from "src/ui/markets/hooks/usePoolsList";
import {
MARKET_DETAILS_ROUTE,
POINTS_MARKETS_ROUTE,
} from "src/ui/markets/routes";
import { useRewards } from "src/ui/rewards/useRewards";
import { useYieldSourceRate } from "src/ui/vaults/useYieldSourceRate";
import { useAccount } from "wagmi";

Expand Down Expand Up @@ -110,7 +116,27 @@ function PointsMarketCardBanner({
}: {
hyperdrive: HyperdriveConfig;
}) {
const multipliers = [{ multiplier: "64x", label: "SPIN Rewards" }];
const { rewards } = useRewards(hyperdrive);
const { longPrice } = useCurrentLongPrice({
chainId: hyperdrive.chainId,
hyperdriveAddress: hyperdrive.address,
});
const pointRewards = rewards?.filter(
({ type }) => type === "pointMultiplier",
) as PointMultiplierReward[] | undefined;

const multipliers =
longPrice && pointRewards
? pointRewards.map(({ pointMultiplier, pointTokenLabel }) => {
const capitalMultiplier = calculateMarketYieldMultiplier(longPrice);
return {
multiplier: capitalMultiplier
.mul(parseFixed(pointMultiplier))
.format({ decimals: 0 }),
label: pointTokenLabel,
};
})
: [];
return (
<div className="flex w-full items-center justify-between rounded-xl bg-base-200 p-5">
<div className="flex w-full flex-col items-center justify-center gap-1.5">
Expand All @@ -124,7 +150,7 @@ function PointsMarketCardBanner({
className="flex w-full flex-col items-center justify-center gap-1.5"
>
<div className="font-chakraPetch text-h4 font-medium">
{multiplier}
{multiplier}x
</div>
<p className="font-medium text-neutral-content sm:text-sm">
{label}
Expand All @@ -139,11 +165,11 @@ function PointsMarketCardBanner({

function PointsMarketTable({ hyperdrive }: { hyperdrive: HyperdriveConfig }) {
const { address: account } = useAccount();
const { lpApy } = useLpApy({
const { lpApy, lpApyStatus } = useLpApy({
chainId: hyperdrive.chainId,
hyperdriveAddress: hyperdrive.address,
});
const { vaultRate } = useYieldSourceRate({
const { vaultRate, vaultRateStatus } = useYieldSourceRate({
chainId: hyperdrive.chainId,
hyperdriveAddress: hyperdrive.address,
});
Expand Down Expand Up @@ -212,8 +238,24 @@ function PointsMarketTable({ hyperdrive }: { hyperdrive: HyperdriveConfig }) {
col1={
<span className="text-sm text-neutral-content">Variable APY</span>
}
col2={<span className="mr-5 text-sm">13.84%</span>}
col3={<span className="mr-3 text-sm">13.84%</span>}
col2={
<span className="mr-5 text-sm">
{vaultRateStatus !== "success" ? (
<Skeleton width={100} />
) : (
formatRate({ rate: vaultRate!.netVaultRate })
)}
</span>
}
col3={
<span className="mr-3 text-sm">
{lpApyStatus !== "success" ? (
<Skeleton width={100} />
) : (
formatRate({ rate: lpApy!.netLpApy! })
)}
</span>
}
/>
<PointsMarketRow
col1={
Expand Down
5 changes: 3 additions & 2 deletions packages/hyperdrive-appconfig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export type { YieldSourceConfig, YieldSourceId } from "src/yieldSources/types";
export { getRewardsFn } from "src/rewards/selectors";
export type {
AnyReward,
ApyReward,
InfoReward,
TokenAmountReward as NonTransferableTokenReward,
PointMultiplierReward,
RewardsResolver,
ApyReward as TransferableTokenReward,
TokenAmountReward,
} from "src/rewards/types";

// protocols
Expand Down
Loading