From ed9dadcb9fe5e7bb3fa9df8515b9382d67ae75df Mon Sep 17 00:00:00 2001 From: Hayden Shively <17186559+haydenshively@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:58:11 -0600 Subject: [PATCH] Fix --- .../src/components/markets/modal/BorrowModal.tsx | 16 ++-------------- .../markets/modal/BorrowModalUniswap.tsx | 16 ++-------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/earn/src/components/markets/modal/BorrowModal.tsx b/earn/src/components/markets/modal/BorrowModal.tsx index a14a5319..c0f9ec9c 100644 --- a/earn/src/components/markets/modal/BorrowModal.tsx +++ b/earn/src/components/markets/modal/BorrowModal.tsx @@ -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'; @@ -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({ diff --git a/earn/src/components/markets/modal/BorrowModalUniswap.tsx b/earn/src/components/markets/modal/BorrowModalUniswap.tsx index 5360aa0e..f177c9c3 100644 --- a/earn/src/components/markets/modal/BorrowModalUniswap.tsx +++ b/earn/src/components/markets/modal/BorrowModalUniswap.tsx @@ -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; @@ -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({