Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Feb 23, 2024
1 parent 3d11f4f commit ed9dadc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
16 changes: 2 additions & 14 deletions earn/src/components/markets/modal/BorrowModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { ChainContext } from '../../../App';
import { computeLTV } from '../../../data/BalanceSheet';
import { BorrowerNft, fetchListOfBorrowerNfts } from '../../../data/BorrowerNft';
import { LendingPair } from '../../../data/LendingPair';
import { RateModel, yieldPerSecondToAPR } from '../../../data/RateModel';

const MAX_BORROW_PERCENTAGE = 0.8;
const SECONDARY_COLOR = '#CCDFED';
Expand Down Expand Up @@ -204,19 +203,8 @@ export default function BorrowModal(props: BorrowModalProps) {
const estimatedApr = useMemo(() => {
const { kitty0Info, kitty1Info } = selectedLendingPair;

const numericLenderTotalAssets = (isBorrowingToken0 ? kitty0Info.totalAssets : kitty1Info.totalAssets).toNumber();
const lenderTotalAssets = GN.fromNumber(numericLenderTotalAssets, selectedBorrow.decimals);

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

const remainingAvailableAssets = lenderTotalAssets.sub(lenderUsedAssets).sub(borrowAmount);
const newUtilization = lenderTotalAssets.isGtZero()
? 1 - remainingAvailableAssets.div(lenderTotalAssets).toNumber()
: 0;

return yieldPerSecondToAPR(RateModel.computeYieldPerSecond(newUtilization)) * 100;
}, [selectedLendingPair, selectedBorrow, isBorrowingToken0, borrowAmount]);
return (isBorrowingToken0 ? kitty0Info : kitty1Info).hypotheticalBorrowAPR(borrowAmount) * 100;
}, [selectedLendingPair, isBorrowingToken0, borrowAmount]);

// The NFT index we will use if minting
const { data: nextNftPtrIdx } = useContractRead({
Expand Down
16 changes: 2 additions & 14 deletions earn/src/components/markets/modal/BorrowModalUniswap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { ChainContext } from '../../../App';
import { maxBorrowAndWithdraw } from '../../../data/BalanceSheet';
import { LendingPair } from '../../../data/LendingPair';
import { Assets } from '../../../data/MarginAccount';
import { RateModel, yieldPerSecondToAPR } from '../../../data/RateModel';
import { UniswapNFTPosition, zip } from '../../../data/Uniswap';

const MAX_BORROW_PERCENTAGE = 0.8;
Expand Down Expand Up @@ -183,19 +182,8 @@ export default function BorrowModalUniswap(props: BorrowModalProps) {
const estimatedApr = useMemo(() => {
const { kitty0Info, kitty1Info } = selectedLendingPair;

const numericLenderTotalAssets = (isBorrowingToken0 ? kitty0Info.totalAssets : kitty1Info.totalAssets).toNumber();
const lenderTotalAssets = GN.fromNumber(numericLenderTotalAssets, selectedBorrow.decimals);

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

const remainingAvailableAssets = lenderTotalAssets.sub(lenderUsedAssets).sub(borrowAmount);
const newUtilization = lenderTotalAssets.isGtZero()
? 1 - remainingAvailableAssets.div(lenderTotalAssets).toNumber()
: 0;

return yieldPerSecondToAPR(RateModel.computeYieldPerSecond(newUtilization)) * 100;
}, [selectedLendingPair, selectedBorrow, isBorrowingToken0, borrowAmount]);
return (isBorrowingToken0 ? kitty0Info : kitty1Info).hypotheticalBorrowAPR(borrowAmount) * 100;
}, [selectedLendingPair, isBorrowingToken0, borrowAmount]);

// The NFT index we will use if minting
const { data: nextNftPtrIdx } = useContractRead({
Expand Down

0 comments on commit ed9dadc

Please sign in to comment.