From 73e19b308f4f622d6ce28ca0aedddfdd3c37a110 Mon Sep 17 00:00:00 2001 From: bojan07 Date: Wed, 18 Oct 2023 05:05:11 -0400 Subject: [PATCH] chore: removed replaced hook files related to contracts --- .../contracts/use-deployed-contracts.tsx | 23 ---- .../hooks/contracts/use-manager-managed.tsx | 102 ------------------ 2 files changed, 125 deletions(-) delete mode 100644 packages/dapp/components/lib/hooks/contracts/use-deployed-contracts.tsx delete mode 100644 packages/dapp/components/lib/hooks/contracts/use-manager-managed.tsx diff --git a/packages/dapp/components/lib/hooks/contracts/use-deployed-contracts.tsx b/packages/dapp/components/lib/hooks/contracts/use-deployed-contracts.tsx deleted file mode 100644 index 26233a071..000000000 --- a/packages/dapp/components/lib/hooks/contracts/use-deployed-contracts.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { getCreditNftManagerContract, getUbiquityManagerContract } from "@/components/utils/contracts"; -import { useMemo } from "react"; -import useDeployedAddress from "../use-deployed-address"; -import useWeb3Provider from "../use-web-3-provider"; - -export type DeployedContracts = ReturnType | null; -const useDeployedContracts = () => { - const provider = useWeb3Provider(); - // cspell: disable-next-line - const [addr1, addr2] = useDeployedAddress("UbiquityAlgorithmicDollarManager", "CreditNftManager"); - return useMemo( - () => - addr1 && addr2 && provider - ? { - manager: getUbiquityManagerContract(addr1, provider), - creditNftManager: getCreditNftManagerContract(addr2, provider), - } - : null, - [addr1, addr2, provider] - ); -}; - -export default useDeployedContracts; diff --git a/packages/dapp/components/lib/hooks/contracts/use-manager-managed.tsx b/packages/dapp/components/lib/hooks/contracts/use-manager-managed.tsx deleted file mode 100644 index 99fad5dc5..000000000 --- a/packages/dapp/components/lib/hooks/contracts/use-manager-managed.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import { - getStakingShareContract, - getStakingV2Contract, - getCreditNftContract, - getDollarMintCalculatorContract, - getERC20Contract, - getINftsForDollarsCalculatorContract, - getIMetaPoolContract, - getIUARForDollarsCalculatorContract, - getMasterChefV2Contract, - getSushiSwapPoolContract, - getTWAPOracleContract, - getDollarContract, - getCreditContract, - getUbiquityFormulasContract, - getGovernanceContract, - getUniswapV2PairContract, -} from "@/components/utils/contracts"; -import { ManagerFacet } from "types"; -import { createContext, useContext, useEffect, useState } from "react"; -import { ChildrenShim } from "../children-shim-d"; -import useWeb3, { PossibleProviders } from "../use-web-3"; -import useDeployedContracts from "./use-deployed-contracts"; - -export type ManagedContracts = Awaited> | null; -export const ManagedContractsContext = createContext(null); - -export const ManagedContractsContextProvider: React.FC = ({ children }) => { - const { provider } = useWeb3(); - const deployedContracts = useDeployedContracts(); - const [managedContracts, setManagedContracts] = useState(null); - - useEffect(() => { - if (deployedContracts && provider) { - (async () => { - setManagedContracts(await connectManagerContracts(deployedContracts.manager, provider)); - })(); - } - }, [deployedContracts, provider]); - - return {children}; -}; - -async function connectManagerContracts(manager: ManagerFacet, provider: NonNullable) { - // 4 - const [ - dollarToken, - dollar3poolMarket, - twapOracle, - dollarMintCalc, - creditToken, - governanceToken, - _3crvToken, - stakingToken, - creditNft, - staking, - masterChef, - sushiSwapPool, - ubiquityFormulas, - creditCalculator, - ] = await Promise.all([ - manager.dollarTokenAddress(), - manager.stableSwapMetaPoolAddress(), - manager.twapOracleAddress(), - manager.dollarMintCalculatorAddress(), - manager.creditTokenAddress(), - manager.governanceTokenAddress(), - manager.curve3PoolTokenAddress(), - manager.stakingShareAddress(), - manager.creditNftAddress(), - manager.stakingContractAddress(), - manager.masterChefAddress(), - manager.sushiSwapPoolAddress(), - manager.formulasAddress(), - manager.creditCalculatorAddress(), - ]); - const creditNftCalculator = manager.address; - const sushiSwapPoolContract = getSushiSwapPoolContract(sushiSwapPool, provider); - - const governanceMarket = getUniswapV2PairContract(await sushiSwapPoolContract.pair(), provider); - - return { - dollarToken: getDollarContract(dollarToken, provider), - dollarMetapool: getIMetaPoolContract(dollar3poolMarket, provider), - dollarTwapOracle: getTWAPOracleContract(twapOracle, provider), - dollarMintCalculator: getDollarMintCalculatorContract(dollarMintCalc, provider), - creditToken: getCreditContract(creditToken, provider), - governanceToken: getGovernanceContract(governanceToken, provider), - _3crvToken: getERC20Contract(_3crvToken, provider), - stakingToken: getStakingShareContract(stakingToken, provider), - creditNft: getCreditNftContract(creditNft, provider), - staking: getStakingV2Contract(staking, provider), - masterChef: getMasterChefV2Contract(masterChef, provider), - sushiSwapPool: sushiSwapPoolContract, - governanceMarket: governanceMarket, - ubiquityFormulas: getUbiquityFormulasContract(ubiquityFormulas, provider), - creditNftCalculator: getINftsForDollarsCalculatorContract(creditNftCalculator, provider), - creditCalculator: getIUARForDollarsCalculatorContract(creditCalculator, provider), - }; -} - -export default () => useContext(ManagedContractsContext);