Skip to content

Commit 3a78efc

Browse files
authored
Exclude BSE from LP Apy (#1811)
1 parent 44ca6d0 commit 3a78efc

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

apps/hyperdrive-trading/src/rewards/getYieldSourceRate.ts

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import { getRewardResolverQuery } from "src/ui/rewards/hooks/getRewardResolverQu
1919
export async function getYieldSourceRate({
2020
readHyperdrive,
2121
appConfig,
22+
excludeBigShortEnergy = false,
2223
}: {
2324
readHyperdrive: ReadHyperdrive;
25+
excludeBigShortEnergy?: boolean;
2426
appConfig: AppConfig;
2527
}): Promise<{ rate: bigint; ratePeriodDays: number; netRate: bigint }> {
2628
const hyperdriveChainId = await readHyperdrive.drift.getChainId();
@@ -57,11 +59,12 @@ export async function getYieldSourceRate({
5759
});
5860
return {
5961
rate: rateSinceInitialization,
60-
netRate: await calcNetRate(
61-
rateSinceInitialization,
62+
netRate: await calcNetRate({
63+
rate: rateSinceInitialization,
6264
appConfig,
6365
hyperdrive,
64-
),
66+
excludeBigShortEnergy,
67+
}),
6568
ratePeriodDays: daysSinceInitialization,
6669
};
6770
}
@@ -70,7 +73,12 @@ export async function getYieldSourceRate({
7073
blockRange: numBlocksForHistoricalRate,
7174
});
7275

73-
const netRate = await calcNetRate(rate, appConfig, hyperdrive);
76+
const netRate = await calcNetRate({
77+
rate,
78+
appConfig,
79+
hyperdrive,
80+
excludeBigShortEnergy,
81+
});
7482

7583
const yieldSource = getYieldSource({
7684
hyperdriveAddress: hyperdrive.address,
@@ -85,11 +93,17 @@ export async function getYieldSourceRate({
8593
};
8694
}
8795

88-
async function calcNetRate(
89-
rate: bigint,
90-
appConfig: AppConfig,
91-
hyperdrive: HyperdriveConfig,
92-
) {
96+
async function calcNetRate({
97+
rate,
98+
appConfig,
99+
hyperdrive,
100+
excludeBigShortEnergy,
101+
}: {
102+
rate: bigint;
103+
appConfig: AppConfig;
104+
excludeBigShortEnergy: boolean;
105+
hyperdrive: HyperdriveConfig;
106+
}) {
93107
let netRate = rate;
94108

95109
const rewardConfigs = getOpenShortRewardConfigs({
@@ -100,14 +114,23 @@ async function calcNetRate(
100114

101115
if (rewardConfigs?.length) {
102116
const rewards = await Promise.all(
103-
rewardConfigs.map((rewardConfig) =>
104-
queryClient.fetchQuery(
105-
getRewardResolverQuery({
106-
chainId: hyperdrive.chainId,
107-
rewardConfig,
108-
}),
117+
rewardConfigs
118+
.filter((rewardConfig) => {
119+
if (!excludeBigShortEnergy) {
120+
return true;
121+
}
122+
return (
123+
excludeBigShortEnergy && rewardConfig.id !== "bigShortEnergyRewards"
124+
);
125+
})
126+
.map((rewardConfig) =>
127+
queryClient.fetchQuery(
128+
getRewardResolverQuery({
129+
chainId: hyperdrive.chainId,
130+
rewardConfig,
131+
}),
132+
),
109133
),
110-
),
111134
);
112135

113136
rewards.flat().forEach((reward) => {

apps/hyperdrive-trading/src/ui/hyperdrive/lp/AddLiquidityForm/AddLiquidityForm.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function AddLiquidityForm({
129129
const lpSharePrice = !isBaseActiveToken
130130
? fixed(poolInfo?.lpSharePrice || 0n, baseToken.decimals).div(
131131
poolInfo?.vaultSharePrice || 0n,
132-
baseToken.decimals
132+
baseToken.decimals,
133133
).bigint
134134
: poolInfo?.lpSharePrice || 0n;
135135

@@ -219,7 +219,7 @@ export function AddLiquidityForm({
219219
balance:
220220
activeTokenPrice && depositAmountAsBigInt
221221
? fixed(depositAmountAsBigInt, activeToken.decimals).mul(
222-
activeTokenPrice
222+
activeTokenPrice,
223223
).bigint
224224
: 0n,
225225
decimals: activeToken.decimals,
@@ -318,7 +318,7 @@ export function AddLiquidityForm({
318318
disclaimer={(() => {
319319
if (
320320
previewAddLiquidityError?.message.includes(
321-
"Not enough lp shares minted."
321+
"Not enough lp shares minted.",
322322
)
323323
) {
324324
return (
@@ -505,6 +505,7 @@ function LpApyStat({ hyperdrive }: { hyperdrive: HyperdriveConfig }) {
505505
const { vaultRate, vaultRateStatus } = useYieldSourceRate({
506506
hyperdriveAddress: hyperdrive.address,
507507
chainId: hyperdrive.chainId,
508+
excludeBigShortEnergy: true,
508509
});
509510

510511
const yieldSource = getYieldSource({

apps/hyperdrive-trading/src/ui/vaults/queryKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface VaultQueryKeys {
55
vaultRate: {
66
chainId: number;
77
hyperdriveAddress: Address | undefined;
8+
excludeBigShortEnergy: boolean;
89
};
910
}
1011

apps/hyperdrive-trading/src/ui/vaults/useYieldSourceRate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import { Address } from "viem";
99
export function useYieldSourceRate({
1010
chainId,
1111
hyperdriveAddress,
12+
excludeBigShortEnergy = false,
1213
}: {
1314
chainId: number;
15+
excludeBigShortEnergy?: boolean;
1416
hyperdriveAddress: Address | undefined;
1517
}): {
1618
vaultRate:
@@ -36,14 +38,15 @@ export function useYieldSourceRate({
3638
queryKey: makeQueryKey2({
3739
namespace: "vaults",
3840
queryId: "vaultRate",
39-
params: { chainId, hyperdriveAddress },
41+
params: { chainId, hyperdriveAddress, excludeBigShortEnergy },
4042
}),
4143
enabled: queryEnabled,
4244
queryFn: queryEnabled
4345
? async () => {
4446
const { rate, ratePeriodDays, netRate } = await getYieldSourceRate({
4547
readHyperdrive,
4648
appConfig,
49+
excludeBigShortEnergy,
4750
});
4851
return {
4952
vaultRate: rate,

0 commit comments

Comments
 (0)