Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: apply diamond to home and market pages #800

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions packages/dapp/components/redeem/lib/use-prices.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
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<void>] => {
const deployedContracts = useDeployedContracts();
const managedContracts = useManagerManaged();
const protocolContracts = useProtocolContracts();
const { provider } = useWeb3();

const [twapPrice, setTwapPrice] = useState<BigNumber | null>(null);
const [spotPrice, setSpotPrice] = useState<BigNumber | null>(null);

async function refreshPrices() {
bojan07 marked this conversation as resolved.
Show resolved Hide resolved
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"));
setTwapPrice(newTwapPrice);
setSpotPrice(newSpotPrice);
try {
if(!protocolContracts || !provider) {
return;
}

if(protocolContracts.managerFacet && protocolContracts.twapOracleDollar3poolFacet) {
const dollarTokenAddress = await protocolContracts.managerFacet.dollarTokenAddress();
const newTwapPrice = await protocolContracts.twapOracleDollar3poolFacet.consult(dollarTokenAddress);
const dollar3poolMarket = 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);
}

} catch (error) {
console.log("Error in refreshPrices: ", error)
}
}

useEffect(() => {
refreshPrices();
}, [managedContracts, deployedContracts]);
}, [protocolContracts, provider]);

return [twapPrice, spotPrice, refreshPrices];
};
Expand Down
10 changes: 5 additions & 5 deletions packages/dapp/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -12,21 +12,21 @@ const WalletConnectionWall = dynamic(() => import("@/components/ui/wallet-connec

const index: FC = (): JSX.Element => {
const [twapPrice, setTwapPrice] = useState<ethers.BigNumber | null>(null);
const managedContracts = useManagerManaged();
const protocolContracts = useProtocolContracts();

useEffectAsync(async () => {
if (managedContracts != null) {
if (protocolContracts != null) {
try {
console.log(twapPrice, "priced in ");
} catch (error) {
console.log("Error occurred while executing contract call", error);
setTwapPrice(null);
}
} else {
console.log("managedContracts is null");
console.log("protocolContracts is null");
setTwapPrice(null);
}
}, [managedContracts]);
}, [protocolContracts]);

if (process.env.DEBUG === "true") {
fetchData();
Expand Down
Loading