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 #3224 from OlympusDAO/finiteCoolerApprovals
add finite consolidation approvals, support cross clearing house consolidation
- Loading branch information
Showing
10 changed files
with
786 additions
and
273 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
19 changes: 19 additions & 0 deletions
19
src/views/Lending/Cooler/hooks/useCheckConsolidatorActive.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,19 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { COOLER_CONSOLIDATION_ADDRESSES } from "src/constants/addresses"; | ||
import { useTestableNetworks } from "src/hooks/useTestableNetworks"; | ||
import { CoolerConsolidation__factory } from "src/typechain"; | ||
import { useProvider } from "wagmi"; | ||
|
||
export const useCheckConsolidatorActive = () => { | ||
const networks = useTestableNetworks(); | ||
const provider = useProvider(); | ||
|
||
return useQuery({ | ||
queryKey: ["consolidatorActive"], | ||
queryFn: async () => { | ||
const contract = CoolerConsolidation__factory.connect(COOLER_CONSOLIDATION_ADDRESSES[networks.MAINNET], provider); | ||
const isActive = await contract.isActive(); | ||
return isActive; | ||
}, | ||
}); | ||
}; |
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
44 changes: 44 additions & 0 deletions
44
src/views/Lending/Cooler/hooks/useGetConsolidationAllowances.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,44 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
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 } from "wagmi"; | ||
|
||
export const useGetConsolidationAllowances = ({ | ||
clearingHouseAddress, | ||
coolerAddress, | ||
loanIds, | ||
}: { | ||
clearingHouseAddress: string; | ||
coolerAddress: string; | ||
loanIds: number[]; | ||
}) => { | ||
const provider = useProvider(); | ||
const networks = useTestableNetworks(); | ||
|
||
console.log("useGetConsolidationAllowances", clearingHouseAddress, coolerAddress, loanIds); | ||
|
||
const { data, isFetched, isLoading } = useQuery( | ||
["useGetConsolidationAllowances", clearingHouseAddress, coolerAddress], | ||
async () => { | ||
try { | ||
const contractAddress = COOLER_CONSOLIDATION_CONTRACT.addresses[networks.MAINNET]; | ||
const contract = CoolerConsolidation__factory.connect(contractAddress, provider); | ||
const requiredApprovals = await contract.requiredApprovals(clearingHouseAddress, coolerAddress, loanIds); | ||
const totalDebtWithFee = requiredApprovals[3].add(requiredApprovals[4]); | ||
return { | ||
consolidatedLoanCollateral: new DecimalBigNumber(requiredApprovals[1], 18), | ||
totalDebtWithFee: new DecimalBigNumber(totalDebtWithFee, 18), | ||
}; | ||
} catch { | ||
return { | ||
consolidatedLoanCollateral: new DecimalBigNumber("0", 18), | ||
totalDebtWithFee: new DecimalBigNumber("0", 18), | ||
}; | ||
} | ||
}, | ||
{ enabled: !!coolerAddress }, | ||
); | ||
return { data, isFetched, isLoading }; | ||
}; |
Oops, something went wrong.