From b1b2bc2963ef393bcbc3d1df765967c0d1a3360c Mon Sep 17 00:00:00 2001 From: bojan07 Date: Mon, 2 Oct 2023 02:01:59 -0700 Subject: [PATCH] feat: apply diamond to home page --- .../dapp/components/redeem/lib/use-prices.ts | 22 +++++++++++-------- packages/dapp/pages/index.tsx | 10 ++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/dapp/components/redeem/lib/use-prices.ts b/packages/dapp/components/redeem/lib/use-prices.ts index cf4df037d..fb15312dd 100644 --- a/packages/dapp/components/redeem/lib/use-prices.ts +++ b/packages/dapp/components/redeem/lib/use-prices.ts @@ -1,20 +1,24 @@ -import useDeployedContracts from "@/components/lib/hooks/contracts/use-deployed-contracts"; -import useManagerManaged from "@/components/lib/hooks/contracts/use-manager-managed"; +import { getIMetaPoolContract } from "@/components/utils/contracts"; +import useProtocolContracts from "@/components/lib/hooks/contracts/use-protocol-contracts"; +import useWeb3 from "@/components/lib/hooks/use-web-3"; import { BigNumber, utils } from "ethers"; import { useEffect, useState } from "react"; const usePrices = (): [BigNumber | null, BigNumber | null, () => Promise] => { - const deployedContracts = useDeployedContracts(); - const managedContracts = useManagerManaged(); + const protocolContracts = useProtocolContracts(); + const { provider } = useWeb3(); const [twapPrice, setTwapPrice] = useState(null); const [spotPrice, setSpotPrice] = useState(null); async function refreshPrices() { - if (managedContracts && deployedContracts) { - const dollarTokenAddress = await deployedContracts.manager.dollarTokenAddress(); - const newTwapPrice = await managedContracts.dollarTwapOracle.consult(dollarTokenAddress); - const newSpotPrice = await managedContracts.dollarMetapool["get_dy(int128,int128,uint256)"](0, 1, utils.parseEther("1")); + if (protocolContracts && provider) { + const dollarTokenAddress = protocolContracts.managerFacet && await protocolContracts.managerFacet.dollarTokenAddress(); + const newTwapPrice = protocolContracts.twapOracleDollar3poolFacet && await protocolContracts.twapOracleDollar3poolFacet.consult(dollarTokenAddress); + + const dollar3poolMarket = protocolContracts.managerFacet && await protocolContracts.managerFacet.stableSwapMetaPoolAddress(); + const dollarMetapool = getIMetaPoolContract(dollar3poolMarket, provider) + const newSpotPrice = await dollarMetapool["get_dy(int128,int128,uint256)"](0, 1, utils.parseEther("1")); setTwapPrice(newTwapPrice); setSpotPrice(newSpotPrice); } @@ -22,7 +26,7 @@ const usePrices = (): [BigNumber | null, BigNumber | null, () => Promise] useEffect(() => { refreshPrices(); - }, [managedContracts, deployedContracts]); + }, [protocolContracts, provider]); return [twapPrice, spotPrice, refreshPrices]; }; diff --git a/packages/dapp/pages/index.tsx b/packages/dapp/pages/index.tsx index 7dd1f428f..6003cdfbc 100644 --- a/packages/dapp/pages/index.tsx +++ b/packages/dapp/pages/index.tsx @@ -2,7 +2,7 @@ import { ethers } from "ethers"; import { FC, useState } from "react"; import "@uniswap/widgets/fonts.css"; -import useManagerManaged from "@/components/lib/hooks/contracts/use-manager-managed"; +import useProtocolContracts from "@/components/lib/hooks/contracts/use-protocol-contracts"; import useEffectAsync from "@/components/lib/hooks/use-effect-async"; import DollarPrice from "@/components/redeem/dollar-price"; import { fetchData } from "@/components/utils/local-data"; @@ -12,10 +12,10 @@ const WalletConnectionWall = dynamic(() => import("@/components/ui/wallet-connec const index: FC = (): JSX.Element => { const [twapPrice, setTwapPrice] = useState(null); - const managedContracts = useManagerManaged(); + const protocolContracts = useProtocolContracts(); useEffectAsync(async () => { - if (managedContracts != null) { + if (protocolContracts != null) { try { console.log(twapPrice, "priced in "); } catch (error) { @@ -23,10 +23,10 @@ const index: FC = (): JSX.Element => { setTwapPrice(null); } } else { - console.log("managedContracts is null"); + console.log("protocolContracts is null"); setTwapPrice(null); } - }, [managedContracts]); + }, [protocolContracts]); if (process.env.DEBUG === "true") { fetchData();