Skip to content

Commit

Permalink
nest-interface-readFunction-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
NeelClaudel committed Oct 26, 2023
1 parent 4e02404 commit 41c83e7
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 152 deletions.
2 changes: 1 addition & 1 deletion packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const Header = () => {
<NavLink href="/">Home</NavLink>
</li>
<li>
<NavLink href="/">
<NavLink href="/nestDashboard">
<CurrencyDollarIcon className="h-4 w-4" />
$NEST
</NavLink>
Expand Down
129 changes: 77 additions & 52 deletions packages/nextjs/components/nest/NestEnginefunction.tsx
Original file line number Diff line number Diff line change
@@ -1,86 +1,111 @@
import { Address } from "../scaffold-eth";
import { ETHToPrice } from "./EthToPrice";
//import { Address } from "../scaffold-eth";
//import { ETHToPrice } from "./EthToPrice";
//import { Token } from "@uniswap/sdk-core";
//import humanizeDuration from "humanize-duration";
import { formatEther } from "viem";
//import { formatEther } from "viem";
import { useAccount } from "wagmi";
import { useAccountBalance, useDeployedContractInfo, useScaffoldContractRead } from "~~/hooks/scaffold-eth";
import { getTargetNetwork } from "~~/utils/scaffold-eth";

//import { getTargetNetwork } from "~~/utils/scaffold-eth";

export const NestEngineFunction = ({ address }: { address?: string }) => {
const { address: connectedAddress } = useAccount();
const { data: NESTEngineContract } = useDeployedContractInfo("NESTEngine");
const { data: NestStableCoinContact } = useDeployedContractInfo("NestStableCoin");
const { balance: nestEngineContractBalance } = useAccountBalance(NESTEngineContract?.address);
const { balance: nestStableCoinContractBalance } = useAccountBalance(NestStableCoinContact?.address);
const { data: NESTEngineContact } = useDeployedContractInfo("NESTEngine");
useAccountBalance(NESTEngineContract?.address);
useAccountBalance(NESTEngineContact?.address);

const configuredNetwork = getTargetNetwork();
// const configuredNetwork = getTargetNetwork();

// Contract Read Actions
const { data: collateralPrice } = useScaffoldContractRead({
const { data: getPrecision } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getCollateralTokenPriceFeed",
args: [address],
functionName: "getPrecision",
watch: true,
});

const { data: getAdditionalFeedPrecision } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getAdditionalFeedPrecision",
watch: true,
});

const { data: getLiquidationThreshold } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getLiquidationThreshold",
watch: true,
});

const { data: yourBalance } = useScaffoldContractRead({
contractName: "NestStableCoin",
functionName: "balanceOf",
args: [connectedAddress],
const { data: getLiquidationBonus } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getLiquidationBonus",
watch: true,
});
const { data: symbol } = useScaffoldContractRead({
contractName: "NestStableCoin",
functionName: "symbol",

const { data: getLiquidationPrecision } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getLiquidationPrecision",
watch: true,
});

const { data: getMinHealthFactor } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getMinHealthFactor",
watch: true,
});

const { data: getCollateralTokenPriceFeed } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getCollateralTokenPriceFeed",
args: [address],
watch: true,
});
const { data: nestTotalSupply } = useScaffoldContractRead({
contractName: "NestStableCoin",
functionName: "totalSupply",

const { data: getNest } = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getNest",
watch: true,
});

// Contract Write Actions
/*
const { writeAsync: depositCollateralAndMintNest } = useScaffoldContractWrite({
contractName: "NESTEngine",
functionName: "depositCollateralAndMintNest",
args: [],
});
*/
return (
<>
<div className="flex items-center flex-col flex-grow w-full px-4 gap-12">
<div className="flex flex-col items-center w-1/2">
<div className="flex items-center flex-col flex-grow pt-10">Your Connected Address {connectedAddress}</div>
<div className="flex items-center flex-col flex-grow pt-10">
Welcome <Address address={connectedAddress} />
Collateral Price Feed {getCollateralTokenPriceFeed ? getCollateralTokenPriceFeed.toString() : ""}
</div>
<div className="flex items-center flex-col flex-grow pt-10">
Your $NEST Balance In ETH :{" "}
<span>
{yourBalance ? formatEther(yourBalance) : 0} {configuredNetwork.nativeCurrency.symbol}
</span>
Minimum Health Factor {getMinHealthFactor ? getMinHealthFactor.toString() : ""}
</div>
<div className="flex items-center flex-col flex-grow pt-10">
Minimum Health Factor {getMinHealthFactor ? getMinHealthFactor.toString() : ""}
</div>
<div className="flex items-center flex-col flex-grow pt-10">Get Nest {getNest ? getNest.toString() : ""}</div>
<div className="flex items-center flex-col flex-grow pt-10">
Get Precision : {getPrecision ? getPrecision.toString() : ""}
</div>
<div className="flex items-center flex-col flex-grow pt-10">
Liquidation Precision : {getLiquidationPrecision ? getLiquidationPrecision.toString() : ""}
</div>
<div className="flex items-center flex-col flex-grow pt-10">
Get Additional Feed Precision : {getAdditionalFeedPrecision ? getAdditionalFeedPrecision.toString() : ""}
</div>
<div className="flex items-center flex-col flex-grow pt-10">
Liquidation Bonus : {getLiquidationBonus ? getLiquidationBonus.toString() : ""}
</div>
<div className="flex items-center flex-col flex-grow pt-10">
Get Liquidation Threshold : {getLiquidationThreshold ? getLiquidationThreshold.toString() : ""}
</div>
</div>
<div className="flex items-center flex-col flex-grow pt-10">
${symbol} Total Supply : <span>{nestTotalSupply ? formatEther(nestTotalSupply) : 0}</span>
</div>
</div>
<div className="flex flex-col items-center shrink-0 w-full">
<p className="block text-xl mt-0 mb-1 font-semibold">Total Staked</p>
<div className="flex space-x-2">
{<ETHToPrice value={nestEngineContractBalance != null ? nestEngineContractBalance.toString() : undefined} />}
<span>/</span>
{<ETHToPrice value={collateralPrice ? formatEther(BigInt(collateralPrice)) : undefined} />}
</div>
</div>
<div className="flex flex-col items-center shrink-0 w-full">
<p className="block text-xl mt-0 mb-1 font-semibold">Total Staked</p>
<div className="flex space-x-2">
{<ETHToPrice value={nestEngineContractBalance != null ? nestEngineContractBalance.toString() : undefined} />}
<span>/</span>
{<ETHToPrice value={collateralPrice ? formatEther(BigInt(collateralPrice)) : undefined} />}
</div>
</div>
<div className="flex items-center">
<ETHToPrice
value={nestStableCoinContractBalance != null ? nestStableCoinContractBalance.toString() : undefined}
className="text-[1rem]"
/>
<p className="block m-0 text-lg -ml-1">staked !!</p>
</div>
</>
);
Expand Down
123 changes: 24 additions & 99 deletions packages/nextjs/components/nest/NestStablecoinFunction.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//import { Address } from "../scaffold-eth";
import { Address } from "../scaffold-eth";
import { ETHToPrice } from "./EthToPrice";
//import { Token } from "@uniswap/sdk-core";
//import humanizeDuration from "humanize-duration";
import { formatEther } from "viem";
import { useAccount } from "wagmi";
import { Balance } from "~~/components/scaffold-eth";
import { useAccountBalance, useDeployedContractInfo, useScaffoldContractRead } from "~~/hooks/scaffold-eth";
import { getTargetNetwork } from "~~/utils/scaffold-eth";

export const NestStablecoinFunction = ({ address }: { address?: string }) => {
const { address: connectedAddress } = useAccount();
const { data: NESTEngineContract } = useDeployedContractInfo("NESTEngine");
const { data: NestStableCoinContact } = useDeployedContractInfo("NestStableCoin");
const { balance: nestEngineContractBalance } = useAccountBalance(NESTEngineContract?.address);
const { balance: nestStableCoinContractBalance } = useAccountBalance(NestStableCoinContact?.address);
useAccountBalance(NESTEngineContract?.address);
useAccountBalance(NestStableCoinContact?.address);

const configuredNetwork = getTargetNetwork();

// Contract Read Actions
const { data: collateralPrice } = useScaffoldContractRead({
const {} = useScaffoldContractRead({
contractName: "NESTEngine",
functionName: "getCollateralTokenPriceFeed",
args: [address],
Expand Down Expand Up @@ -48,13 +48,13 @@ export const NestStablecoinFunction = ({ address }: { address?: string }) => {
functionName: "totalSupply",
watch: true,
});
/*
const { data: isStakingCompleted } = useScaffoldContractRead({

const { data: contractName } = useScaffoldContractRead({
contractName: "NestStableCoin",
functionName: "completed",
functionName: "name",
watch: true,
});
/*
// Contract Write Actions
const { writeAsync: stakeETH } = useScaffoldContractWrite({
contractName: "NESTEngine",
Expand All @@ -72,111 +72,36 @@ export const NestStablecoinFunction = ({ address }: { address?: string }) => {
*/
return (
<>
{/* User Infos */}
<div className="flex items-center flex-col flex-grow w-full px-4 gap-12">
<div className="flex flex-col items-center w-1/2">
<div className="flex items-center flex-col flex-grow pt-10">
Welcome <Address address={connectedAddress} />
Welcome to your {contractName} ${symbol} Dashboard <Address address={connectedAddress} />
</div>
<div className="flex items-center flex-col flex-grow pt-10">
Your $NEST Balance In ETH :{" "}
<span>
{yourBalance ? formatEther(yourBalance) : 0} {configuredNetwork.nativeCurrency.symbol}
</span>
</div>
</div>
<div className="flex items-center flex-col flex-grow pt-10">
${symbol} Total Supply : <span>{nestTotalSupply ? formatEther(nestTotalSupply) : 0}</span>
</div>
</div>
<div className="flex flex-col items-center shrink-0 w-full">
<p className="block text-xl mt-0 mb-1 font-semibold">Total Staked</p>
<div className="flex space-x-2">
{<ETHToPrice value={nestEngineContractBalance != null ? nestEngineContractBalance.toString() : undefined} />}
<span>/</span>
{<ETHToPrice value={collateralPrice ? formatEther(BigInt(collateralPrice)) : undefined} />}
</div>
</div>
<div className="flex flex-col items-center shrink-0 w-full">
<p className="block text-xl mt-0 mb-1 font-semibold">Total Staked</p>
<div className="flex space-x-2">
{<ETHToPrice value={nestEngineContractBalance != null ? nestEngineContractBalance.toString() : undefined} />}
<span>/</span>
{<ETHToPrice value={collateralPrice ? formatEther(BigInt(collateralPrice)) : undefined} />}
</div>
</div>
<div className="flex items-center">
<ETHToPrice
value={nestStableCoinContractBalance != null ? nestStableCoinContractBalance.toString() : undefined}
className="text-[1rem]"
/>
<p className="block m-0 text-lg -ml-1">staked !!</p>
</div>
</>
);
};

/* <div className="flex items-center flex-col flex-grow w-full px-4 gap-12">
{isStakingCompleted && (
<div className="flex flex-col items-center gap-2 bg-base-100 shadow-lg shadow-secondary border-8 border-secondary rounded-xl p-6 mt-12 w-full max-w-lg">
<p className="block m-0 font-semibold">
{" "}
🎉 &nbsp; Staking App triggered `ExampleExternalContract` &nbsp; 🎉{" "}
</p>
<div className="flex items-center">
<ETHToPrice
value={nestStableCoinContractBalance != null ? nestStableCoinContractBalance.toString() : undefined}
className="text-[1rem]"
/>
<p className="block m-0 text-lg -ml-1">staked !!</p>
</div>
</div>
)}
<div
className={`flex flex-col items-center space-y-8 bg-base-100 shadow-lg shadow-secondary border-8 border-secondary rounded-xl p-6 w-full max-w-lg ${
!isStakingCompleted ? "mt-24" : ""
}`}
>
<div className="flex flex-col w-full items-center">
<p className="block text-2xl mt-0 mb-2 font-semibold">NEST Contract</p>
<Address address={address} size="xl" />
</div>
<div className="flex items-start justify-around w-full">
<div className="flex flex-col items-center justify-center w-1/2">
<p className="block text-xl mt-0 mb-1 font-semibold">Time Left</p>
<p className="m-0 p-0">{timeLeft ? `${humanizeDuration(Number(timeLeft) * 1000)}` : 0}</p>
</div>
<div className="flex flex-col items-center w-1/2">
<p className="block text-xl mt-0 mb-1 font-semibold">You Staked</p>
<div className="flex items-center flex-col flex-grow pt-10">
Your $ETH/$USD Balance, click to switch :{" "}
<span>
{yourBalance ? formatEther(yourBalance) : 0} {configuredNetwork.nativeCurrency.symbol}
<Balance address={connectedAddress} />
</span>
</div>
</div>
<div className="flex flex-col items-center shrink-0 w-full">
<p className="block text-xl mt-0 mb-1 font-semibold">Total Staked</p>
<div className="flex space-x-2">
{
<ETHToPrice
value={nestEngineContractBalance != null ? nestEngineContractBalance.toString() : undefined}
/>
}
<span>/</span>
{<ETHToPrice value={collateralPrice ? formatEther(BigInt(collateralPrice)) : undefined} />}
</div>
</div>
<div className="flex flex-col space-y-5">
<div className="flex space-x-7">
<button className="btn btn-primary" onClick={() => execute()}>
Execute!
</button>
<button className="btn btn-primary" onClick={() => withdrawETH()}>
Withdraw
</button>
</div>
<br />
{/* Token Infos */}
<div className="flex items-center flex-col flex-grow w-full px-4 gap-12">
<div className="flex flex-col items-center w-1/2">
<div className="flex items-center flex-col flex-grow pt-10">
${symbol} Total Supply : <span>{nestTotalSupply ? formatEther(nestTotalSupply) : 0}</span>
</div>
<button className="btn btn-primary" onClick={() => stakeETH()}>
🥩 Stake 0.5 ether!
</button>
</div>
</div>
</div>
*/
<br />
</>
);
};
20 changes: 20 additions & 0 deletions packages/nextjs/pages/nestDashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { NextPage } from "next";
import { MetaHeader } from "~~/components/MetaHeader";
import { NestStablecoinFunction } from "~~/components/nest";
import { NestEngineFunction } from "~~/components/nest/NestEnginefunction";

const NestDashboard: NextPage = () => {
return (
<>
{" "}
<MetaHeader
title="$NEST Manager | Nest Stablecoin"
description="Manage your $NEST Vault and your $NEST Stablecoin"
/>
<NestStablecoinFunction />
<NestEngineFunction />
</>
);
};

export default NestDashboard;

0 comments on commit 41c83e7

Please sign in to comment.