generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3264 from OlympusDAO/develop
[Release] - Cooler Consolidation UX Updates/Balance Checks, Emission Manager Stats
- Loading branch information
Showing
4 changed files
with
241 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/views/Lending/Cooler/hooks/useGetWalletFundsRequired.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { COOLER_CONSOLIDATION_CONTRACT } from "src/constants/contracts"; | ||
import { DecimalBigNumber } from "src/helpers/DecimalBigNumber/DecimalBigNumber"; | ||
import { useTestableNetworks } from "src/hooks/useTestableNetworks"; | ||
import { CoolerConsolidation__factory } from "src/typechain"; | ||
import { useProvider, useQuery } from "wagmi"; | ||
|
||
export const useGetWalletFundsRequired = ({ | ||
clearingHouseAddress, | ||
coolerAddress, | ||
loanIds, | ||
}: { | ||
clearingHouseAddress: string; | ||
coolerAddress: string; | ||
loanIds: number[]; | ||
}) => { | ||
const provider = useProvider(); | ||
const networks = useTestableNetworks(); | ||
|
||
const { data, isFetched, isLoading } = useQuery( | ||
["useGetWalletFundsRequired", clearingHouseAddress, coolerAddress], | ||
async () => { | ||
try { | ||
const contractAddress = COOLER_CONSOLIDATION_CONTRACT.addresses[networks.MAINNET]; | ||
const contract = CoolerConsolidation__factory.connect(contractAddress, provider); | ||
const requiredDebtInWallet = await contract.fundsRequired(clearingHouseAddress, coolerAddress, loanIds); | ||
const requiredCollateralInWallet = await contract.collateralRequired( | ||
clearingHouseAddress, | ||
coolerAddress, | ||
loanIds, | ||
); | ||
return { | ||
totalDebtNeededInWallet: new DecimalBigNumber(requiredDebtInWallet.interest, 18), | ||
totalCollateralNeededInWallet: new DecimalBigNumber(requiredCollateralInWallet.additionalCollateral, 18), | ||
}; | ||
} catch { | ||
return { | ||
totalDebtNeededInWallet: new DecimalBigNumber("0", 18), | ||
totalCollateralNeededInWallet: new DecimalBigNumber("0", 18), | ||
}; | ||
} | ||
}, | ||
{ enabled: !!coolerAddress }, | ||
); | ||
return { data, isFetched, isLoading }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters