Skip to content

Commit

Permalink
Fix APR * 100 bug on Borrow Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Feb 6, 2024
1 parent 6154852 commit e5341fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions earn/src/components/lend/BorrowingWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SendTransactionResult } from '@wagmi/core';
import TokenIcon from 'shared/lib/components/common/TokenIcon';
import { Display, Text } from 'shared/lib/components/common/Typography';
import { GREY_600, GREY_700 } from 'shared/lib/data/constants/Colors';
import { GN } from 'shared/lib/data/GoodNumber';
import useSafeState from 'shared/lib/data/hooks/UseSafeState';
import { Token } from 'shared/lib/data/Token';
import { formatTokenAmount, roundPercentage } from 'shared/lib/util/Numbers';
Expand All @@ -20,7 +21,6 @@ import HealthGauge from '../common/HealthGauge';
import BorrowModal from './modal/BorrowModal';
import UpdateBorrowerModal from './modal/UpdateBorrowerModal';
import UpdateCollateralModal from './modal/UpdateCollateralModal';
import { GN } from 'shared/lib/data/GoodNumber';

const SECONDARY_COLOR = 'rgba(130, 160, 182, 1)';
const SECONDARY_COLOR_LIGHT = 'rgba(130, 160, 182, 0.1)';
Expand Down Expand Up @@ -403,14 +403,14 @@ export default function BorrowingWidget(props: BorrowingWidgetProps) {
let aprText = '';
if (isSelected && hoveredPair !== null) {
const pair = hoveredPair;
const apr = pair[entry.token.equals(pair.token0) ? 'kitty0Info' : 'kitty1Info'].borrowAPR;
const apr = pair[entry.token.equals(pair.token0) ? 'kitty0Info' : 'kitty1Info'].borrowAPR * 100;
aprText = `${Math.round(apr * 100) / 100}%`;
} else {
let minApr = Infinity;
let maxApr = -Infinity;

entry.matchingPairs.forEach((pair) => {
const apr = pair[entry.token.equals(pair.token0) ? 'kitty0Info' : 'kitty1Info'].borrowAPR;
const apr = pair[entry.token.equals(pair.token0) ? 'kitty0Info' : 'kitty1Info'].borrowAPR * 100;
minApr = Math.min(minApr, apr);
maxApr = Math.max(maxApr, apr);
});
Expand Down
2 changes: 1 addition & 1 deletion earn/src/components/lend/modal/BorrowModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default function BorrowModal(props: BorrowModalProps) {
const numericLenderTotalAssets = isBorrowingToken0 ? kitty0Info.totalSupply : kitty1Info.totalSupply;
const lenderTotalAssets = GN.fromNumber(numericLenderTotalAssets, selectedBorrow.decimals);

const lenderUtilization = isBorrowingToken0 ? kitty0Info.utilization / 100 : kitty1Info.utilization / 100;
const lenderUtilization = isBorrowingToken0 ? kitty0Info.utilization : kitty1Info.utilization;
const lenderUsedAssets = GN.fromNumber(numericLenderTotalAssets * lenderUtilization, selectedBorrow.decimals);

const remainingAvailableAssets = lenderTotalAssets.sub(lenderUsedAssets).sub(borrowAmount);
Expand Down
2 changes: 2 additions & 0 deletions earn/src/data/MarketInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Address } from 'wagmi';

import { convertBigNumbersForReturnContexts } from '../util/Multicall';

// TODO: This is completely unnecessary. All info is available in `lendingPairs` (just need to refactor for GN)
export type MarketInfo = {
lender0: Address;
lender1: Address;
Expand All @@ -32,6 +33,7 @@ export type Market = {
token1Decimals: number;
};

// TODO: This is completely unnecessary. All info is available in `lendingPairs` (just need to refactor for GN)
export async function fetchMarketInfos(
markets: Market[],
chainId: number,
Expand Down

0 comments on commit e5341fe

Please sign in to comment.