Skip to content

Commit

Permalink
fix negative value issue for the TVL
Browse files Browse the repository at this point in the history
  • Loading branch information
brianshattuck committed Jan 17, 2025
1 parent 4183f40 commit 6c6fb94
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/hooks/v3/useV3Farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,28 @@ export const useMerklFarms = () => {
}
return false;
});
const almTVL =
let almTVL =
(item.tvl ?? 0) -
filteredALMs.reduce((total: number, alm: any) => total + alm.almTVL, 0);

// if almTVL is less than 0, it means some tokens are not invested.
// In this case, it should be recalculated by positions.
if (almTVL < 0) {
almTVL =
(item.tvl ?? 0) -
filteredALMs.reduce((total: number, alm: any) => {
const investedBalance = alm.positions.reduce(
(acc, p) => (acc += p.tvl),
0,
);
return (total += investedBalance);
}, 0);
}
const alms = filteredALMs
.concat([
{
almAddress: item.pool,
almTVL: almTVL < 0 ? 0 : almTVL,
almTVL: almTVL,
almAPR: item?.meanAPR ?? 0,
label: item?.ammName,
},
Expand Down

0 comments on commit 6c6fb94

Please sign in to comment.