Skip to content

Commit

Permalink
Merge pull request #44 from burrowHQ/apy-optimization
Browse files Browse the repository at this point in the history
burrow apy optimization
  • Loading branch information
xieqiancaosissi authored Mar 8, 2024
2 parents e53884a + c609f09 commit 66fe9f2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
10 changes: 0 additions & 10 deletions api/get-liquidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,12 @@ export async function getLiquidations(
d.RepaidAssets?.forEach((a) => {
const tokenId = a.token_id;
const asset = assets?.data?.[tokenId];
// if (!asset && nearTokens.includes(tokenId)) {
// asset = assets?.data?.[nearTokenId];
// }

// if (asset?.metadata) {
// standardizeAsset({ ...asset.metadata });
// }
a.data = asset;
});

d.LiquidatedAssets?.forEach((a) => {
const tokenId = a.token_id;
const asset = assets?.data?.[tokenId];
// if (!asset && nearTokens.includes(tokenId)) {
// asset = assets?.data?.[nearTokenId];
// }
a.data = asset;
});
if (d.isRead === false) {
Expand Down
17 changes: 3 additions & 14 deletions components/Rewards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import TokenIcon from "../TokenIcon";
import HtmlTooltip from "../common/html-tooltip";
import { useNetLiquidityRewards, useProRataNetLiquidityReward } from "../../hooks/useRewards";
import { toInternationalCurrencySystem_number } from "../../utils/uiNumber";
import { nearNativeTokens } from "../../utils/index";
import { nearMetadata } from "../Assets";

interface Props {
rewards?: IReward[];
Expand Down Expand Up @@ -233,11 +231,10 @@ const RewardV2 = ({ metadata, rewards, config, tokenId }) => {
const amount = isCompact
? millify(Number(rewardAmount), { precision: PERCENT_DIGITS })
: formatRewardAmount(Number(rewardAmount));
const processed_icon = icon || nearNativeTokens.includes(token_id) ? nearMetadata.icon : "";
return (
<div className="flex items-center gap-1">
<Stack key={1} direction="row" alignItems="center" spacing={1}>
<img className="w-4 h-4 rounded-full" alt="" src={processed_icon} />
<img className="w-4 h-4 rounded-full" alt="" src={icon} />
</Stack>
<Typography key={2} fontSize="0.75rem" textAlign="right">
{amount} / day
Expand All @@ -254,11 +251,7 @@ const TotalDailyRewards = ({ poolRewards, netLiquidityRewards, tokenId }) => {
const { metadata, rewards, config } = poolRewards;
const { decimals, icon, token_id } = metadata;
poolDailyRewards = shrinkToken(rewards.reward_per_day || 0, decimals + config.extra_decimals);
if (icon) {
src = icon;
} else if (nearNativeTokens.includes(token_id)) {
src = nearMetadata.icon;
}
src = icon;
}
if (netLiquidityRewards) {
const { metadata, rewards, config } = netLiquidityRewards;
Expand All @@ -267,11 +260,7 @@ const TotalDailyRewards = ({ poolRewards, netLiquidityRewards, tokenId }) => {
rewards.reward_per_day || 0,
decimals + config.extra_decimals,
);
if (icon) {
src = icon;
} else if (nearNativeTokens.includes(token_id)) {
src = nearMetadata.icon;
}
src = icon;
}
const netLiquidityDailyRewardsForToken = useProRataNetLiquidityReward(
tokenId,
Expand Down
16 changes: 14 additions & 2 deletions screens/Market/APYCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import TokenIcon from "../../components/TokenIcon";
import { useExtraAPY } from "../../hooks/useExtraAPY";
import { useAPY } from "../../hooks/useAPY";
import { format_apy } from "../../utils/uiNumber";
import { getAssets } from "../../redux/assetsSelectors";
import { useAppSelector } from "../../redux/hooks";

export const APYCell = ({
baseAPY,
Expand Down Expand Up @@ -53,13 +55,20 @@ const ToolTip = ({
excludeNetApy,
}) => {
const [showTooltip, setShowTooltip] = useState(false);
const assets = useAppSelector(getAssets);
// suppose only one reward
const netTvlFarmTokenId = (Object.keys(assets?.netTvlFarm || {}) || [])[0];
const { computeRewardAPY, computeStakingRewardAPY, netLiquidityAPY, netTvlMultiplier } =
useExtraAPY({
tokenId,
isBorrow,
onlyMarket,
});

function getNetTvlFarmRewardIcon() {
const asset = assets.data[netTvlFarmTokenId];
const icon = asset?.metadata?.icon;
return icon;
}
return (
<HtmlTooltip
open={showTooltip}
Expand All @@ -77,7 +86,10 @@ const ToolTip = ({
Net Liquidity APY
</Typography>,
<Typography fontSize="0.75rem" color="#fff" textAlign="right" key={1}>
{format_apy(netLiquidityAPY * netTvlMultiplier)}
<div className="flex items-center justify-end gap-1.5">
<img className="w-4 h-4 rounded-full" alt="" src={getNetTvlFarmRewardIcon()} />
{format_apy(netLiquidityAPY * netTvlMultiplier)}
</div>
</Typography>,
]}
{list.map(({ rewards, metadata, price, config }) => {
Expand Down
4 changes: 2 additions & 2 deletions screens/TokenDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { ConnectWalletButton } from "../../components/Header/WalletButton";
import { OuterLinkConfig } from "./config";
import { APYCell } from "../Market/APYCell";
import { RewardsV2 } from "../../components/Rewards";
import getConfig from "../../utils/config";
import getConfig, { incentiveTokens } from "../../utils/config";
import InterestRateChart, { LabelText } from "./interestRateChart";
import TokenBorrowSuppliesChart from "./tokenBorrowSuppliesChart";
import { useTokenDetails } from "../../hooks/useTokenDetails";
Expand Down Expand Up @@ -794,7 +794,7 @@ function YouSupplied() {
baseAPY={tokenRow.supplyApy}
page="deposit"
tokenId={tokenRow.tokenId}
excludeNetApy
excludeNetApy={!incentiveTokens.includes(tokenRow.tokenId)}
/>
}
/>
Expand Down
5 changes: 5 additions & 0 deletions transformers/asstets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IAssetDetailed, IMetadata } from "../interfaces/asset";
import { transformAssetFarms } from "./farms";
import { Assets } from "../redux/assetState";
import { nearMetadata } from "../components/Assets";
import { nearNativeTokens } from "../utils";

export function transformAssets({
assets,
Expand All @@ -12,6 +14,9 @@ export function transformAssets({
const data = assets.reduce((map, asset) => {
const assetMetadata = metadata.find((m) => m.token_id === asset.token_id) as IMetadata;
if (!assetMetadata || !asset.config) return map;
if (!assetMetadata?.icon && nearNativeTokens.includes(assetMetadata?.token_id)) {
assetMetadata.icon = nearMetadata.icon;
}
map[asset.token_id] = {
metadata: assetMetadata,
...asset,
Expand Down

0 comments on commit 66fe9f2

Please sign in to comment.