Skip to content

Commit

Permalink
Merge pull request #305 from stabilitydao/dev-leaf
Browse files Browse the repository at this point in the history
VsHold reestimation
  • Loading branch information
a17 authored Nov 12, 2024
2 parents fdc79aa + 31e25bb commit 88006c1
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 191 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stability-ui",
"type": "module",
"version": "0.13.22-alpha",
"version": "0.13.23-alpha",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
Expand Down
6 changes: 3 additions & 3 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ const IL = {
},
TPF: {
rate: 1,
title: "UNKNOWN YET",
desc: "This is a new strategy with new protocols and pools. The impermanent losses will be indicated later, after data collection and analysis.",
color: "#C0BCC9",
title: "MEDIUM",
desc: "Significant impermanent loss was noted during rebalancing with this ALM in volatile pools.",
color: "#F5DA5B",
},
TPF_STABLE: {
rate: 0,
Expand Down
70 changes: 28 additions & 42 deletions src/layouts/AppStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
const fee = vault?.almFee?.income || 0;

if (daysFromLastHardWork < 3) {
dailyFarmApr = vault.apr?.income24h
? Number(vault.apr?.income24h)
dailyFarmApr = vault.income?.apr24h
? Number(vault.income?.apr24h)
: 0;

weeklyFarmApr = vault.apr?.incomeWeek
? Number(vault.apr?.incomeWeek)
weeklyFarmApr = vault.income?.aprWeek
? Number(vault.income?.aprWeek)
: 0;

if (underlying) {
Expand Down Expand Up @@ -302,13 +302,13 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
if (!dailyAPR) dailyAPR = 0;
}

APR = (Number(vault?.apr?.incomeLatest) + Number(dailyAPR)).toFixed(
APR = (Number(vault?.income?.aprLatest) + Number(dailyAPR)).toFixed(
2
);

APY = calculateAPY(APR).toFixed(2);

APRWithoutFees = Number(vault?.apr?.incomeLatest).toFixed(2) || "0";
APRWithoutFees = Number(vault?.income?.aprLatest).toFixed(2) || "0";

///////
const dailyTotalAPRWithFees =
Expand All @@ -319,25 +319,25 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
APRArray = {
latest: String(APR),
daily: determineAPR(
vault.apr?.income24h,
vault?.income.apr24h,
dailyTotalAPRWithFees,
APR
),
weekly: determineAPR(
vault.apr?.incomeWeek,
vault?.income.aprWeek,
weeklyTotalAPRWithFees,
APR
),
};
APYArray = {
latest: APY,
daily: determineAPR(
vault.apr?.income24h,
vault?.income.apr24h,
calculateAPY(dailyTotalAPRWithFees).toFixed(2),
APY
),
weekly: determineAPR(
vault.apr?.incomeWeek,
vault?.income.aprWeek,
calculateAPY(weeklyTotalAPRWithFees).toFixed(2),
APY
),
Expand All @@ -355,12 +355,12 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
farmAPR = {
latest: APRWithoutFees,
daily: determineAPR(
vault.apr?.income24h,
vault?.income.apr24h,
dailyFarmApr,
APRWithoutFees
),
weekly: determineAPR(
vault.apr?.incomeWeek,
vault?.income.aprWeek,
weeklyFarmApr,
APRWithoutFees
),
Expand Down Expand Up @@ -393,32 +393,22 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
}

///// VS HODL

const vaultCreated = vault.created as number;

const lifetimeVsHoldAPR =
vault.apr?.vsHoldLifetime &&
getTimeDifference(vaultCreated)?.days >= 3
? Number(vault.apr?.vsHoldLifetime).toFixed(2)
: 0;

const currentTime = Math.floor(Date.now() / 1000);

const differenceInSecondsFromCreation = currentTime - vaultCreated;

const secondsInADay = 60 * 60 * 24;
const daysFromCreation = getTimeDifference(vaultCreated)?.days;

const daysFromCreation = Math.round(
differenceInSecondsFromCreation / secondsInADay
);
const vsHoldAPR =
vault.vsHold?.lifetime && daysFromCreation >= 3
? Number(vault.vsHold?.lifetime).toFixed(2)
: 0;

const vsHoldAPR = (
(Number(lifetimeVsHoldAPR) / 365) *
Number(daysFromCreation)
).toFixed(2);
const lifetimeVsHoldAPR =
vault.vsHold?.aprLifetime && daysFromCreation >= 3
? Number(vault.vsHold?.aprLifetime).toFixed(2)
: 0;

let lifetimeTokensHold: THoldData[] = [];
if (vault.apr?.vsHoldAssetsLifetime && prices) {
if (vault.vsHold?.lifetimeAssets && prices) {
lifetimeTokensHold = strategyAssets.map(
(asset: string, index: number) => {
const price = vault?.assetsPricesLast?.[index]
Expand All @@ -435,26 +425,22 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
const priceDifference =
((price - priceOnCreation) / priceOnCreation) * 100;

const yearPercentDiff =
Number(vault.apr?.vsHoldAssetsLifetime[index]) || 0;

const percentDiff = (yearPercentDiff / 365) * daysFromCreation;

return {
symbol: getTokenData(asset)?.symbol || "",
initPrice: priceOnCreation.toFixed(2),
price: price.toFixed(2),
priceDifference: priceDifference.toFixed(2),
latestAPR: percentDiff.toFixed(2),
APR: yearPercentDiff.toFixed(2),
latestAPR:
Number(vault.vsHold?.lifetimeAssets[index]).toFixed(2) || "0",
APR:
Number(vault.vsHold?.aprAssetsLifetime[index]).toFixed(2) ||
"0",
};
}
);
}

const isVsActive =
getTimeDifference(vaultCreated).days > 2 &&
!!Number(vault.sharePrice);
const isVsActive = daysFromCreation > 2 && !!Number(vault.sharePrice);

/////***** YEARN PROTOCOLS *****/////
let yearnProtocols: TYearnProtocol[] = [];
Expand Down
6 changes: 1 addition & 5 deletions src/modules/Vault/components/InfoBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,7 @@ const InfoBar: React.FC<IProps> = memo(({ network, vault }) => {
<div className="w-full md:w-1/3 ">
<FieldValue
name="VS HODL APR"
value={
vault.symbol != "C-CVR-P-TPF"
? vault.lifetimeVsHoldAPR + "%"
: "-"
}
value={vault.lifetimeVsHoldAPR + "%"}
testId="infoBarVSHodlAPR"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Vault/components/YieldBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const YieldBar: React.FC<IProps> = memo(({ vault }) => {
</table>
)}

{!!vault.lifetimeTokensHold && vault.symbol != "C-CVR-P-TPF" && (
{!!vault.lifetimeTokensHold && (
<table className="font-manrope w-full mt-5">
<thead className="bg-accent-950 text-neutral-600 h-[36px]">
<tr className="text-[14px] uppercase">
Expand Down
171 changes: 82 additions & 89 deletions src/modules/Vaults/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -931,104 +931,97 @@ const Vaults = (): JSX.Element => {
className={`whitespace-nowrap w-full text-end flex items-center justify-end gap-[2px] ${
vault.lifetimeVsHoldAPR < 0 &&
getTimeDifference(vault.created).days >= 3 &&
vault.symbol != "C-CVR-P-TPF" &&
"text-[#eb7979]"
}`}
>
{getTimeDifference(vault.created).days >= 3 &&
vault.symbol != "C-CVR-P-TPF"
{getTimeDifference(vault.created).days >= 3
? `${vault.lifetimeVsHoldAPR}%`
: "-"}
</p>
{vault.symbol != "C-CVR-P-TPF" ? (
<div className="visible__tooltip !w-[450px]">
<table className="table table-auto w-full rounded-lg">
<thead className="bg-[#0b0e11]">
<tr className="text-[16px] text-[#8f8f8f] uppercase">
<th></th>
<th>
{getTimeDifference(vault.created).days}{" "}
days
</th>
<th className="text-right">est Annual</th>
</tr>
</thead>
<tbody data-testid="vsHoldAPRTable">
<tr className="hover:bg-[#2B3139]">
<td className="text-left">VAULT VS HODL</td>

{vault.isVsActive ? (
<td
className={`text-right ${
vault.vsHoldAPR < 0 &&
"text-[#eb7979]"
}`}
>
{vault.vsHoldAPR}%
</td>
) : (
<td className="text-right">-</td>
)}

{vault.isVsActive ? (
<td
className={`text-right ${
vault.lifetimeVsHoldAPR < 0 &&
"text-[#eb7979]"
}`}
>
{vault.lifetimeVsHoldAPR}%
</td>
) : (
<td className="text-right">-</td>
)}
</tr>

{vault.lifetimeTokensHold.map(
(aprsData: THoldData, index: number) => (
<tr
key={aprsData?.symbol + index}
className="hover:bg-[#2B3139]"
>
<td className="text-left">
VAULT VS {aprsData?.symbol} HODL
</td>
<div className="visible__tooltip !w-[450px]">
<table className="table table-auto w-full rounded-lg">
<thead className="bg-[#0b0e11]">
<tr className="text-[16px] text-[#8f8f8f] uppercase">
<th></th>
<th>
{getTimeDifference(vault.created).days} days
</th>
<th className="text-right">est Annual</th>
</tr>
</thead>
<tbody data-testid="vsHoldAPRTable">
<tr className="hover:bg-[#2B3139]">
<td className="text-left">VAULT VS HODL</td>

{vault.isVsActive ? (
<td
className={`text-right ${
vault.vsHoldAPR < 0 && "text-[#eb7979]"
}`}
>
{vault.vsHoldAPR}%
</td>
) : (
<td className="text-right">-</td>
)}

{vault.isVsActive ? (
<td
className={`text-right ${
Number(aprsData.latestAPR) < 0 &&
"text-[#eb7979]"
}`}
>
{aprsData.latestAPR}%
</td>
) : (
<td className="text-right">-</td>
)}

{vault.isVsActive ? (
<td
className={`text-right ${
Number(aprsData.latestAPR) < 0 &&
"text-[#eb7979]"
}`}
>
{aprsData.APR}%
</td>
) : (
<td className="text-right">-</td>
)}
</tr>
)
{vault.isVsActive ? (
<td
className={`text-right ${
vault.lifetimeVsHoldAPR < 0 &&
"text-[#eb7979]"
}`}
>
{vault.lifetimeVsHoldAPR}%
</td>
) : (
<td className="text-right">-</td>
)}
</tbody>
</table>
<i></i>
</div>
) : (
""
)}
</tr>

{vault.lifetimeTokensHold.map(
(aprsData: THoldData, index: number) => (
<tr
key={aprsData?.symbol + index}
className="hover:bg-[#2B3139]"
>
<td className="text-left">
VAULT VS {aprsData?.symbol} HODL
</td>

{vault.isVsActive ? (
<td
className={`text-right ${
Number(aprsData.latestAPR) < 0 &&
"text-[#eb7979]"
}`}
>
{aprsData.latestAPR}%
</td>
) : (
<td className="text-right">-</td>
)}

{vault.isVsActive ? (
<td
className={`text-right ${
Number(aprsData.latestAPR) < 0 &&
"text-[#eb7979]"
}`}
>
{aprsData.APR}%
</td>
) : (
<td className="text-right">-</td>
)}
</tr>
)
)}
</tbody>
</table>
<i></i>
</div>
</td>
<td className="px-2 min-[1130px]:px-4 py-2 whitespace-nowrap">
<div className="flex items-center justify-center">
Expand Down
Loading

0 comments on commit 88006c1

Please sign in to comment.