Skip to content

Commit

Permalink
Merge pull request #923 from spectrum-finance/fix-apr
Browse files Browse the repository at this point in the history
fix: fix APR
  • Loading branch information
yasha-black authored Oct 2, 2023
2 parents 25cf908 + 2fb1db4 commit b46efb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const AprTooltipContent: FC<LbspTooltipContentProps> = ({ aprs, totalApr }) => {
</Flex.Item>
{aprs.map((apr, index) => {
return (
<Flex.Item key={`${index}-apr-row`} display="flex" marginBottom={1}>
<Flex.Item key={`${index}-apr-row`} display="flex">
<Flex.Item marginRight={1} justify="space-between">
<Typography.Body tooltip size="small">
{apr.name}
Expand All @@ -61,18 +61,6 @@ const AprTooltipContent: FC<LbspTooltipContentProps> = ({ aprs, totalApr }) => {
</Flex.Item>
);
})}

<Flex.Item>
<Typography.Body
size="small"
style={{ color: 'var(--spectrum-hint-text)' }}
>
<Trans>
SPF APR is calculated according to the current price on the Ergo
market
</Trans>
</Typography.Body>
</Flex.Item>
</Flex>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { applicationConfig } from '../../../../../../../../applicationConfig';
import { AmmPool } from '../../../../../../../../common/models/AmmPool';
import { Currency } from '../../../../../../../../common/models/Currency';
import { appTick$ } from '../../../../../../../../common/streams/appTick';
import { getAmmPoolById } from '../../../../../../../../gateway/api/ammPools.ts';
import { spfAsset } from '../../../../../../../../network/ergo/api/networkAsset/networkAsset';
import {
isLbspAmmPool,
Expand Down Expand Up @@ -58,6 +59,12 @@ const adaUsdRate$ = appTick$.pipe(
);
adaUsdRate$.subscribe();

const spfPrice$ = getAmmPoolById(applicationConfig.spfPoolId).pipe(
map((ammPool) => {
return ammPool?.pool.priceY;
}),
);

const getLbspMultiplier = (ammPool: AmmPool) => {
if (isLbspAmmPool(ammPool.id)) {
return LBSP_MULTIPLIER;
Expand All @@ -72,11 +79,18 @@ const getLbspMultiplier = (ammPool: AmmPool) => {
};

export const calculateLbspApr = (ammPool: AmmPool): Observable<number> => {
return combineLatest([spfUsdRate$, adaUsdRate$]).pipe(
map(([spfUsdRate, adaUsdRate]) => {
return combineLatest([spfPrice$, adaUsdRate$]).pipe(
map(([price, adaUsdRate]) => {
const spfPriceUsd = math.evaluate!(
`${Number(price?.numerator)}/${Number(
price?.denominator,
)}*${adaUsdRate}`,
).toFixed(6);

const lbspMult = getLbspMultiplier(ammPool);

return math.evaluate!(
`(${LBSP_COEFFICIENT} * ${lbspMult} * ${spfUsdRate}) / ${adaUsdRate} * ${EPOCHS_PER_YEAR} * 100`,
`((${LBSP_COEFFICIENT} * ${lbspMult} * ${spfPriceUsd}) / ${adaUsdRate} * ${EPOCHS_PER_YEAR} * 100)/2`,
).toFixed(2);
}),
map((res) => (res ? Number(res) : 0)),
Expand Down

0 comments on commit b46efb8

Please sign in to comment.