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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function OpenLongStats({
const { fiatPrice: zapTokenPrice } = useTokenFiatPrice({
// This hook should only be enabled if the token is a zap token.
// For testing purposes we are grabbing the token price from mainnet.
chainId: 1,
chainId: 707,
tokenAddress: activeToken.address,
enabled: isZapToken,
});
Expand All @@ -70,7 +70,7 @@ export function OpenLongStats({

const { fiatPrice: baseTokenPrice } = useTokenFiatPrice({
// For testing purposes on zaps we are grabbing the token price from mainnet.
chainId: isZapToken ? 1 : hyperdrive.chainId,
chainId: isZapToken ? 707 : hyperdrive.chainId,
tokenAddress: baseToken.address,
});
const { fixedApr } = useFixedRate({
Expand All @@ -79,7 +79,10 @@ export function OpenLongStats({
});

if (isZapToken && zapTokenPrice && baseTokenPrice) {
const fiatValueOfZapAmount = fixed(zapTokenPrice).mul(amountPaid, 6);
const fiatValueOfZapAmount = fixed(zapTokenPrice).mul(
amountPaid,
activeToken.decimals,
);
const zapAmountInBase = fiatValueOfZapAmount.div(baseTokenPrice);
const slipageAmount = parseFixed("0.005");
finalAmountPaid = parseFixed("1")
Expand All @@ -98,6 +101,7 @@ export function OpenLongStats({
const yieldAtMaturity = bondAmount - amountPaidInBase;
const termLengthMS = Number(hyperdrive.poolConfig.positionDuration * 1000n);
const numDays = convertMillisecondsToDays(termLengthMS);

return (
<div className="flex flex-row justify-between px-4 py-8">
<PrimaryStat
Expand All @@ -112,6 +116,7 @@ export function OpenLongStats({
rate: calculateAprFromPrice({
positionDuration:
hyperdrive.poolConfig.positionDuration || 0n,
// TODO: When zapping, the final amount paid should be converted to base
baseAmount: finalAmountPaid,
bondAmount: bondAmount,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function usePreviewOpenLong({
});

const appConfig = useAppConfigForConnectedChain();

const baseToken = getBaseToken({
appConfig,
hyperdriveAddress,
Expand All @@ -66,16 +67,15 @@ export function usePreviewOpenLong({
const { fiatPrice: zapTokenPrice } = useTokenFiatPrice({
// This hook should only be enabled if the token is a zap token.
// For testing purposes we are grabbing the token price from mainnet.
chainId: 1,
chainId: 707,
tokenAddress,
enabled: isZapToken,
});

const { fiatPrice: baseTokenPrice } = useTokenFiatPrice({
// For testing purposes on zaps we are grabbing the token price from mainnet.
chainId: isZapToken ? 1 : baseToken.chainId,
chainId: isZapToken ? 707 : baseToken.chainId,
tokenAddress: baseToken.address,
enabled: true,
});

const queryEnabled = amountIn !== undefined && !!readHyperdrive;
Expand All @@ -84,6 +84,7 @@ export function usePreviewOpenLong({
chainId: chainId,
query: { enabled: queryEnabled },
});

const { data, status, fetchStatus } = useQuery({
queryKey: makeQueryKey("previewOpenLong", {
chainId,
Expand All @@ -92,6 +93,8 @@ export function usePreviewOpenLong({
asBase,
blockNumber: blockNumber?.toString(),
tokenAddress,
baseTokenPrice: baseTokenPrice?.toString(),
zapTokenPrice: zapTokenPrice?.toString(),
}),
enabled: queryEnabled,
queryFn: queryEnabled
Expand All @@ -101,7 +104,7 @@ export function usePreviewOpenLong({
if (isZapToken) {
const zapToken = getToken({
appConfig,
chainId: 1,
chainId,
tokenAddress,
});
const fiatValueOfZapAmount =
Expand Down
Loading